@botuyo/chat-widget-standalone 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/botuyo-chat.es.js +34 -1
- package/dist/botuyo-chat.es.js.map +1 -1
- package/dist/botuyo-chat.umd.js +1 -1
- package/dist/botuyo-chat.umd.js.map +1 -1
- package/dist/{chunk-audio-C4Q6VB-1.js → chunk-audio-74FRtdfK.js} +2 -2
- package/dist/{chunk-audio-C4Q6VB-1.js.map → chunk-audio-74FRtdfK.js.map} +1 -1
- package/dist/{chunk-chat-ui-DmqgsaBa.js → chunk-chat-ui-C_pd6dbW.js} +49 -49
- package/dist/{chunk-chat-ui-DmqgsaBa.js.map → chunk-chat-ui-C_pd6dbW.js.map} +1 -1
- package/dist/{chunk-gallery-Ca7lW3V4.js → chunk-gallery-B5mW4cu-.js} +2 -2
- package/dist/{chunk-gallery-Ca7lW3V4.js.map → chunk-gallery-B5mW4cu-.js.map} +1 -1
- package/dist/standalone.d.ts +5 -0
- package/dist/standalone.d.ts.map +1 -1
- package/dist/stats-umd.html +1 -1
- package/dist/stats.html +1 -1
- package/package.json +8 -6
- package/dist/ChatWidget-3m1RqH_c.js +0 -33
- package/dist/ChatWidget-3m1RqH_c.js.map +0 -1
package/dist/botuyo-chat.es.js
CHANGED
|
@@ -1,2 +1,35 @@
|
|
|
1
|
-
import{r as e,
|
|
1
|
+
import{r as e,j as t,c as n,R as r}from"./vendor-react-CtfcjTlq.js";import{u as o,g as s,e as i,f as a,D as c,c as u,X as d,M as l,l as p,m as f,t as h,h as m,i as g,j as y,k as v,n as b}from"./chunk-chat-ui-C_pd6dbW.js";import{o as w}from"./chunk-chat-ui-C_pd6dbW.js";import{l as _}from"./vendor-socket-DMqyM-90.js";function k({isOpen:n,onClick:r,unreadCount:f=0,primaryColor:h,logoUrl:m,starterPrompt:g,position:y="bottom-right",emotion:v="default",avatars:b={},styles:w,promptPersistence:_="session",avatarScale:k=1}){const{t:z}=o("extracted"),x=s({primaryColor:h}),E=w?.launcher?.bg,S=i(),{triggerHaptic:O,getGlowClass:C}=a(),I=S.launcherPulse&&!1!==w?.launcher?.pulse,[$,N]=e.useState(!1),[T,j]=e.useState(!1),[A,M]=e.useState(!1),[P,Z]=e.useState(!1),F="bottom-right"===y,D="chat_launcher_prompt_state",R=e.useMemo(()=>b[v]||b.default||m||c,[v,b,m]);e.useEffect(()=>{Z(!1)},[R]),e.useEffect(()=>{const e=Object.values(b).filter(e=>!!e);m&&e.push(m),e.forEach(e=>{(new Image).src=e})},[b,m]),e.useEffect(()=>{"forever"===_&&"dismissed"===localStorage.getItem(D)&&M(!0)},[_]);const L=e.useCallback(()=>{j(!0),setTimeout(()=>N(!1),500),"always"!==_&&(M(!0),"forever"===_&&localStorage.setItem(D,"dismissed"))},[_]);return e.useEffect(()=>{if("always"!==_&&A||!g||n)return void N(!1);const e=setTimeout(()=>{N(!0),j(!1)},2e3),t=setTimeout(()=>L(),12e3);return()=>{clearTimeout(e),clearTimeout(t)}},[g,n,A,_,L]),/* @__PURE__ */t.jsxs("div",{className:u("flex items-center w-fit transition-all duration-500",F?"flex-row ml-auto":"flex-row-reverse mr-auto"),children:[
|
|
2
|
+
/* @__PURE__ */t.jsx("div",{className:u("transition-all duration-700 ease-in-out flex items-center",$?u("opacity-100 translate-x-0 w-auto max-w-[350px]",F?"mr-4":"ml-4"):"opacity-0 translate-x-8 w-0 max-w-0 overflow-hidden"),children:/* @__PURE__ */t.jsxs("div",{className:u("relative px-5 py-3.5 shadow-soft-xl border flex items-center gap-3",w?.radius?.card||"rounded-[20px]",T&&"opacity-0 scale-95 transition-all duration-300",!$&&"hidden"),style:{width:"max-content",maxWidth:"280px",backgroundColor:"hsl(var(--background))",color:"hsl(var(--foreground))",borderColor:"hsl(var(--border))"},children:[
|
|
3
|
+
/* @__PURE__ */t.jsx("span",{className:"text-sm font-semibold leading-tight tracking-tight whitespace-nowrap",children:g}),
|
|
4
|
+
/* @__PURE__ */t.jsx("button",{onClick:e=>{e.stopPropagation(),L()},className:"text-muted-foreground hover:text-foreground transition-colors p-1 rounded-full hover:bg-muted shrink-0",children:/* @__PURE__ */t.jsx(d,{className:"h-3.5 w-3.5 stroke-[2.5]"})}),
|
|
5
|
+
/* @__PURE__ */t.jsx("div",{className:u("absolute top-1/2 -translate-y-1/2 w-0 h-0 border-[7px] border-transparent",F?"right-[-14px] border-l-background":"left-[-14px] border-r-background")}),
|
|
6
|
+
/* @__PURE__ */t.jsx("div",{className:u("absolute top-1/2 -translate-y-1/2 w-0 h-0 border-[7px] border-transparent -z-10",F?"right-[-15px] border-l-border":"left-[-15px] border-r-border")})]})}),
|
|
7
|
+
/* @__PURE__ */t.jsxs("div",{className:"relative flex items-center justify-center shrink-0",children:[!n&&I&&/* @__PURE__ */t.jsx("span",{className:"absolute inset-0 flex items-center justify-center",children:/* @__PURE__ */t.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-20",style:{backgroundColor:x}})}),
|
|
8
|
+
/* @__PURE__ */t.jsxs("button",{type:"button",onClick:()=>{p.debug("Launcher handleMainAction called, isOpen:",n),O(),M(!0),"forever"===_&&localStorage.setItem(D,"dismissed"),r()},className:u("relative z-10 h-14 w-14 sm:h-16 sm:w-16","flex items-center justify-center text-white transition-all duration-500","hover:scale-110 active:scale-95 shadow-soft-xl cursor-pointer",!n&&"hover:rotate-6",!n&&S.enabled&&"animate-glow-pulse",w?.radius?.button||"rounded-full",E,C()),style:{backgroundColor:x||"hsl(160, 84%, 39%)","--primary-glow":`${x}66`},"aria-label":n?"Cerrar chat":"Abrir chat",children:[
|
|
9
|
+
/* @__PURE__ */t.jsxs("div",{className:"relative h-full w-full flex items-center justify-center overflow-hidden rounded-inherit",children:[
|
|
10
|
+
/* @__PURE__ */t.jsx("div",{className:u("absolute inset-0 transition-all duration-500 flex items-center justify-center",n?"opacity-0 scale-50 rotate-90":"opacity-100 scale-100 rotate-0"),children:R&&!P?/* @__PURE__ */t.jsx("img",{src:R,alt:z("assistant"),className:"w-full h-full object-cover",style:{transform:`scale(${k})`},onError:()=>Z(!0)},R):/* @__PURE__ */t.jsx(l,{className:"h-7 w-7 sm:h-8 sm:w-8 fill-current"})}),
|
|
11
|
+
/* @__PURE__ */t.jsx("div",{className:u("absolute inset-0 transition-all duration-500 flex items-center justify-center bg-black/5 dark:bg-white/10",n?"opacity-100 scale-100 rotate-0":"opacity-0 scale-50 -rotate-90"),children:/* @__PURE__ */t.jsx(d,{className:"h-7 w-7 sm:h-8 sm:w-8 stroke-[2.5]"})})]}),!n&&f>0&&/* @__PURE__ */t.jsx("div",{className:"absolute -top-1 -right-1 z-20 flex h-6 w-6 items-center justify-center bg-destructive text-destructive-foreground rounded-full border-2 border-background text-[10px] font-black shadow-soft-md tabular-nums",children:f>9?"9+":f})]})]})]})}class z extends e.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){p.error("ErrorBoundary caught error:",e,t),this.props.onError?.(e,t)}handleReset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError?this.props.fallback?this.props.fallback:/* @__PURE__ */t.jsxs("div",{className:"flex flex-col items-center justify-center p-8 bg-background text-center",children:[
|
|
12
|
+
/* @__PURE__ */t.jsx("div",{className:"text-6xl mb-4",children:"⚠️"}),
|
|
13
|
+
/* @__PURE__ */t.jsx("h2",{className:"text-xl font-bold text-foreground mb-2",children:"Algo salió mal"}),
|
|
14
|
+
/* @__PURE__ */t.jsx("p",{className:"text-sm text-muted-foreground mb-6 max-w-md",children:this.state.error?.message||"Ocurrió un error inesperado"}),
|
|
15
|
+
/* @__PURE__ */t.jsx("button",{onClick:this.handleReset,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg font-medium hover:opacity-90 transition-opacity",children:"Intentar de nuevo"})]}):this.props.children}}const x={bubble:"rounded-2xl",image:"rounded-xl",button:"rounded-xl",card:"rounded-2xl"},E={bg:"bg-muted/50 dark:bg-muted/20",text:"text-foreground",border:"border-border/50"},S={text:"text-primary-foreground"};const O=(e,t)=>t.some(t=>e instanceof t);let C,I;const $=/* @__PURE__ */new WeakMap,N=/* @__PURE__ */new WeakMap,T=/* @__PURE__ */new WeakMap;let j={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return $.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return P(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function A(e){j=e(j)}function M(e){return"function"==typeof e?(t=e,(I||(I=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(Z(this),e),P(this.request)}:function(...e){return P(t.apply(Z(this),e))}):(e instanceof IDBTransaction&&function(e){if($.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)});$.set(e,t)}(e),O(e,C||(C=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,j):e);var t}function P(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(P(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)});return T.set(t,e),t}(e);if(N.has(e))return N.get(e);const t=M(e);return t!==e&&(N.set(e,t),T.set(t,e)),t}const Z=e=>T.get(e),F=["get","getKey","getAll","getAllKeys","count"],D=["put","add","delete","clear"],R=/* @__PURE__ */new Map;function L(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(R.get(t))return R.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=D.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!F.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let i=s.store;return r&&(i=i.index(t.shift())),(await Promise.all([i[n](...t),o&&s.done]))[0]};return R.set(t,s),s}A(e=>({...e,get:(t,n,r)=>L(t,n)||e.get(t,n,r),has:(t,n)=>!!L(t,n)||e.has(t,n)}));const U=["continue","continuePrimaryKey","advance"],W={},B=/* @__PURE__ */new WeakMap,J=/* @__PURE__ */new WeakMap,V={get(e,t){if(!U.includes(t))return e[t];let n=W[t];return n||(n=W[t]=function(...e){B.set(this,J.get(this)[t](...e))}),n}};async function*q(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,V);for(J.set(n,t),T.set(n,Z(t));t;)yield n,t=await(B.get(n)||t.continue()),B.delete(n)}function G(e,t){return t===Symbol.asyncIterator&&O(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&O(e,[IDBIndex,IDBObjectStore])}A(e=>({...e,get:(t,n,r)=>G(t,n)?q:e.get(t,n,r),has:(t,n)=>G(t,n)||e.has(t,n)}));const K=new class{db=null;DB_NAME="botuyo-chat";DB_VERSION=1;async init(){try{this.db=await function(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,t),a=P(i);return r&&i.addEventListener("upgradeneeded",e=>{r(P(i.result),e.oldVersion,e.newVersion,P(i.transaction),e)}),n&&i.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{s&&e.addEventListener("close",()=>s()),o&&e.addEventListener("versionchange",e=>o(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}(this.DB_NAME,this.DB_VERSION,{upgrade(e){e.objectStoreNames.contains("messages")||e.createObjectStore("messages",{keyPath:"id"}).createIndex("by-timestamp","timestamp"),e.objectStoreNames.contains("metadata")||e.createObjectStore("metadata")}}),p.info("IndexedDB initialized")}catch(e){throw p.error("Failed to initialize IndexedDB:",e),e}}async saveMessage(e){this.db||await this.init();try{await this.db.put("messages",e)}catch(t){p.error("Failed to save message:",t)}}async saveMessages(e){this.db||await this.init();try{const t=this.db.transaction("messages","readwrite");await Promise.all([...e.map(e=>t.store.put(e)),t.done])}catch(t){p.error("Failed to save messages:",t)}}async getMessages(e=100){this.db||await this.init();try{return(await this.db.getAllFromIndex("messages","by-timestamp")).slice(-e)}catch(t){return p.error("Failed to get messages:",t),[]}}async getMessage(e){this.db||await this.init();try{return await this.db.get("messages",e)}catch(t){return void p.error("Failed to get message:",t)}}async deleteMessage(e){this.db||await this.init();try{await this.db.delete("messages",e)}catch(t){p.error("Failed to delete message:",t)}}async clearMessages(){this.db||await this.init();try{await this.db.clear("messages"),p.info("Messages cleared from IndexedDB")}catch(e){p.error("Failed to clear messages:",e)}}async setMetadata(e){this.db||await this.init();try{await this.db.put("metadata",e,"chat-metadata")}catch(t){p.error("Failed to set metadata:",t)}}async getMetadata(){this.db||await this.init();try{return await this.db.get("metadata","chat-metadata")}catch(e){return p.error("Failed to get metadata:",e),null}}async clearAll(){this.db||await this.init();try{await Promise.all([this.db.clear("messages"),this.db.clear("metadata")]),p.info("All data cleared from IndexedDB")}catch(e){p.error("Failed to clear all data:",e)}}async migrateFromLocalStorage(){try{const e="botuyo_chat_v1",t=localStorage.getItem(e);if(!t)return;const n=JSON.parse(t);if(n.messages&&Array.isArray(n.messages)){const e=n.messages.map(e=>({...e,timestamp:new Date(e.timestamp)}));await this.saveMessages(e),p.info(`Migrated ${e.length} messages from localStorage`)}n.sessionId&&await this.setMetadata({sessionId:n.sessionId}),localStorage.removeItem(e),p.info("Migration from localStorage completed")}catch(e){p.error("Failed to migrate from localStorage:",e)}}},H="botuyo_chat_v1",Y={isOpen:!1,isConnected:!1,isTyping:!1,messages:[],error:null,sessionId:null};function X(e,t){switch(t.type){case"TOGGLE_WINDOW":return{...e,isOpen:!e.isOpen};case"OPEN_WINDOW":return{...e,isOpen:!0};case"CLOSE_WINDOW":return{...e,isOpen:!1};case"SET_CONNECTED":return{...e,isConnected:t.payload};case"SET_TYPING":return{...e,isTyping:t.payload};case"ADD_MESSAGE":{if(e.messages.some(e=>e.id===t.payload.id))return e;const n=[...e.messages,t.payload],r="bot"===t.payload.sender;return{...e,messages:n,isTyping:!r&&e.isTyping}}case"SET_MESSAGES":return{...e,messages:[...t.payload]};case"SET_ERROR":return{...e,error:t.payload};case"SET_SESSION_ID":return{...e,sessionId:t.payload};case"CLEAR_CHAT":return{...Y,isOpen:e.isOpen};case"RESTORE_SESSION":return{...e,...t.payload,isConnected:!1,isTyping:!1,error:null};default:return e}}function Q(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:i,traits:/* @__PURE__ */new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const o=i.prototype,s=Object.keys(o);for(let e=0;e<s.length;e++){const t=s[e];t in n||(n[t]=o[t].bind(n))}}const o=n?.Parent??Object;class s extends o{}function i(e){var t;const o=n?.Parent?new s:this;r(o,e),(t=o._zod).deferred??(t.deferred=[]);for(const n of o._zod.deferred)n();return o}return Object.defineProperty(s,"name",{value:e}),Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class ee extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class te extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const ne={};function re(e){return ne}function oe(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function se(e,t){return"bigint"==typeof t?t.toString():t}function ie(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function ae(e){return null==e}function ce(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const ue=/* @__PURE__ */Symbol("evaluating");function de(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==ue)return void 0===r&&(r=ue,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function le(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function pe(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function fe(e){return JSON.stringify(e)}const he="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function me(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const ge=ie(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function ye(e){if(!1===me(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==me(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function ve(e){return ye(e)?{...e}:Array.isArray(e)?[...e]:e}const be=/* @__PURE__ */new Set(["string","number","symbol"]);function we(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _e(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function ke(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const ze={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function xe(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function Ee(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Se(e){return"string"==typeof e?e:e?.message}function Oe(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=Se(e.inst?._zod.def?.error?.(e))??Se(t?.error?.(e))??Se(n.customError?.(e))??Se(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Ce(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Ie(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const $e=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,se,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Ne=Q("$ZodError",$e),Te=Q("$ZodError",$e,{Parent:Error}),je=e=>(t,n,r,o)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new ee;if(i.issues.length){const t=new(o?.Err??e)(i.issues.map(e=>Oe(e,s,re())));throw he(t,o?.callee),t}return i.value},Ae=e=>async(t,n,r,o)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const t=new(o?.Err??e)(i.issues.map(e=>Oe(e,s,re())));throw he(t,o?.callee),t}return i.value},Me=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new ee;return s.issues.length?{success:!1,error:new(e??Ne)(s.issues.map(e=>Oe(e,o,re())))}:{success:!0,data:s.value}},Pe=/* @__PURE__ */Me(Te),Ze=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(e=>Oe(e,o,re())))}:{success:!0,data:s.value}},Fe=/* @__PURE__ */Ze(Te),De=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return je(e)(t,n,o)},Re=e=>(t,n,r)=>je(e)(t,n,r),Le=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ae(e)(t,n,o)},Ue=e=>async(t,n,r)=>Ae(e)(t,n,r),We=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Me(e)(t,n,o)},Be=e=>(t,n,r)=>Me(e)(t,n,r),Je=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ze(e)(t,n,o)},Ve=e=>async(t,n,r)=>Ze(e)(t,n,r),qe=/^[cC][^\s-]{8,}$/,Ge=/^[0-9a-z]+$/,Ke=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,He=/^[0-9a-vA-V]{20}$/,Ye=/^[A-Za-z0-9]{27}$/,Xe=/^[a-zA-Z0-9_-]{21}$/,Qe=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,et=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,tt=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,nt=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,rt=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ot=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,st=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,it=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,at=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,ct=/^[A-Za-z0-9_-]*$/,ut=/^\+[1-9]\d{6,14}$/,dt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",lt=/* @__PURE__ */new RegExp(`^${dt}$`);function pt(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const ft=/^-?\d+$/,ht=/^-?\d+(?:\.\d+)?$/,mt=/^[^A-Z]*$/,gt=/^[^a-z]*$/,yt=/* @__PURE__ */Q("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),vt={number:"number",bigint:"bigint",object:"date"},bt=/* @__PURE__ */Q("$ZodCheckLessThan",(e,t)=>{yt.init(e,t);const n=vt[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),wt=/* @__PURE__ */Q("$ZodCheckGreaterThan",(e,t)=>{yt.init(e,t);const n=vt[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),_t=/* @__PURE__ */Q("$ZodCheckMultipleOf",(e,t)=>{yt.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(0===o&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(o=Number.parseInt(e[1]))}const s=n>o?n:o;return Number.parseInt(e.toFixed(s).replace(".",""))%Number.parseInt(t.toFixed(s).replace(".",""))/10**s}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),kt=/* @__PURE__ */Q("$ZodCheckNumberFormat",(e,t)=>{yt.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,s]=ze[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=o,r.maximum=s,n&&(r.pattern=ft)}),e._zod.check=i=>{const a=i.value;if(n){if(!Number.isInteger(a))return void i.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});if(!Number.isSafeInteger(a))return void(a>0?i.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):i.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}))}a<o&&i.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),a>s&&i.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}}),zt=/* @__PURE__ */Q("$ZodCheckMaxLength",(e,t)=>{var n;yt.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!ae(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const o=Ce(r);n.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),xt=/* @__PURE__ */Q("$ZodCheckMinLength",(e,t)=>{var n;yt.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!ae(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const o=Ce(r);n.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Et=/* @__PURE__ */Q("$ZodCheckLengthEquals",(e,t)=>{var n;yt.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!ae(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,o=r.length;if(o===t.length)return;const s=Ce(r),i=o>t.length;n.issues.push({origin:s,...i?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),St=/* @__PURE__ */Q("$ZodCheckStringFormat",(e,t)=>{var n,r;yt.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=/* @__PURE__ */new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Ot=/* @__PURE__ */Q("$ZodCheckRegex",(e,t)=>{St.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Ct=/* @__PURE__ */Q("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=mt),St.init(e,t)}),It=/* @__PURE__ */Q("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=gt),St.init(e,t)}),$t=/* @__PURE__ */Q("$ZodCheckIncludes",(e,t)=>{yt.init(e,t);const n=we(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=/* @__PURE__ */new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Nt=/* @__PURE__ */Q("$ZodCheckStartsWith",(e,t)=>{yt.init(e,t);const n=new RegExp(`^${we(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=/* @__PURE__ */new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Tt=/* @__PURE__ */Q("$ZodCheckEndsWith",(e,t)=>{yt.init(e,t);const n=new RegExp(`.*${we(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=/* @__PURE__ */new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),jt=/* @__PURE__ */Q("$ZodCheckOverwrite",(e,t)=>{yt.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class At{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const o of r)this.content.push(o)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Mt={major:4,minor:3,patch:6},Pt=/* @__PURE__ */Q("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Mt;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const t of o._zod.onattach)t(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,o=xe(e);for(const s of t){if(s._zod.def.when){if(!s._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,i=s._zod.check(e);if(i instanceof Promise&&!1===n?.async)throw new ee;if(r||i instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await i,e.issues.length!==t&&(o||(o=xe(e,t)))});else{if(e.issues.length===t)continue;o||(o=xe(e,t))}}return r?r.then(()=>e):e},n=(n,o,s)=>{if(xe(n))return n.aborted=!0,n;const i=t(o,r,s);if(i instanceof Promise){if(!1===s.async)throw new ee;return i.then(t=>e._zod.parse(t,s))}return e._zod.parse(i,s)};e._zod.run=(o,s)=>{if(s.skipChecks)return e._zod.parse(o,s);if("backward"===s.direction){const t=e._zod.parse({value:o.value,issues:[]},{...s,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,o,s)):n(t,o,s)}const i=e._zod.parse(o,s);if(i instanceof Promise){if(!1===s.async)throw new ee;return i.then(e=>t(e,r,s))}return t(i,r,s)}}de(e,"~standard",()=>({validate:t=>{try{const n=Pe(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return Fe(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}))}),Zt=/* @__PURE__ */Q("$ZodString",(e,t)=>{var n;Pt.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(o){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Ft=/* @__PURE__ */Q("$ZodStringFormat",(e,t)=>{St.init(e,t),Zt.init(e,t)}),Dt=/* @__PURE__ */Q("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=et),Ft.init(e,t)}),Rt=/* @__PURE__ */Q("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=tt(e))}else t.pattern??(t.pattern=tt());Ft.init(e,t)}),Lt=/* @__PURE__ */Q("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=nt),Ft.init(e,t)}),Ut=/* @__PURE__ */Q("$ZodURL",(e,t)=>{Ft.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(t.normalize?n.value=o.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Wt=/* @__PURE__ */Q("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Ft.init(e,t)}),Bt=/* @__PURE__ */Q("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Xe),Ft.init(e,t)}),Jt=/* @__PURE__ */Q("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=qe),Ft.init(e,t)}),Vt=/* @__PURE__ */Q("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Ge),Ft.init(e,t)}),qt=/* @__PURE__ */Q("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Ke),Ft.init(e,t)}),Gt=/* @__PURE__ */Q("$ZodXID",(e,t)=>{t.pattern??(t.pattern=He),Ft.init(e,t)}),Kt=/* @__PURE__ */Q("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Ye),Ft.init(e,t)}),Ht=/* @__PURE__ */Q("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=pt({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${dt}T(?:${r})$`)}(t)),Ft.init(e,t)}),Yt=/* @__PURE__ */Q("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=lt),Ft.init(e,t)}),Xt=/* @__PURE__ */Q("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${pt(t)}$`)),Ft.init(e,t)}),Qt=/* @__PURE__ */Q("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Qe),Ft.init(e,t)}),en=/* @__PURE__ */Q("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=rt),Ft.init(e,t),e._zod.bag.format="ipv4"}),tn=/* @__PURE__ */Q("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=ot),Ft.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),nn=/* @__PURE__ */Q("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=st),Ft.init(e,t)}),rn=/* @__PURE__ */Q("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=it),Ft.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function on(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const sn=/* @__PURE__ */Q("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=at),Ft.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{on(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}}),an=/* @__PURE__ */Q("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=ct),Ft.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!ct.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return on(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),cn=/* @__PURE__ */Q("$ZodE164",(e,t)=>{t.pattern??(t.pattern=ut),Ft.init(e,t)}),un=/* @__PURE__ */Q("$ZodJWT",(e,t)=>{Ft.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&"JWT"!==o?.typ||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),dn=/* @__PURE__ */Q("$ZodNumber",(e,t)=>{Pt.init(e,t),e._zod.pattern=e._zod.bag.pattern??ht,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(i){}const o=n.value;if("number"==typeof o&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s="number"==typeof o?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),n}}),ln=/* @__PURE__ */Q("$ZodNumberFormat",(e,t)=>{kt.init(e,t),dn.init(e,t)}),pn=/* @__PURE__ */Q("$ZodAny",(e,t)=>{Pt.init(e,t),e._zod.parse=e=>e}),fn=/* @__PURE__ */Q("$ZodUnknown",(e,t)=>{Pt.init(e,t),e._zod.parse=e=>e}),hn=/* @__PURE__ */Q("$ZodNever",(e,t)=>{Pt.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function mn(e,t,n){e.issues.length&&t.issues.push(...Ee(n,e.issues)),t.value[n]=e.value}const gn=/* @__PURE__ */Q("$ZodArray",(e,t)=>{Pt.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const s=[];for(let e=0;e<o.length;e++){const i=o[e],a=t.element._zod.run({value:i,issues:[]},r);a instanceof Promise?s.push(a.then(t=>mn(t,n,e))):mn(a,n,e)}return s.length?Promise.all(s).then(()=>n):n}});function yn(e,t,n,r,o){if(e.issues.length){if(o&&!(n in r))return;t.issues.push(...Ee(n,e.issues))}void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function vn(e){const t=Object.keys(e.shape);for(const o of t)if(!e.shape?.[o]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${o}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function bn(e,t,n,r,o,s){const i=[],a=o.keySet,c=o.catchall._zod,u=c.def.type,d="optional"===c.optout;for(const l in t){if(a.has(l))continue;if("never"===u){i.push(l);continue}const o=c.run({value:t[l],issues:[]},r);o instanceof Promise?e.push(o.then(e=>yn(e,n,l,t,d))):yn(o,n,l,t,d)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const wn=/* @__PURE__ */Q("$ZodObject",(e,t)=>{Pt.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=ie(()=>vn(t));de(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=/* @__PURE__ */new Set);for(const e of r.values)n[t].add(e)}}return n});const o=me,s=t.catchall;let i;e._zod.parse=(t,n)=>{i??(i=r.value);const a=t.value;if(!o(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=i.shape;for(const e of i.keys){const r=u[e],o="optional"===r._zod.optout,s=r._zod.run({value:a[e],issues:[]},n);s instanceof Promise?c.push(s.then(n=>yn(n,t,e,a,o))):yn(s,t,e,a,o)}return s?bn(c,a,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),_n=/* @__PURE__ */Q("$ZodObjectJIT",(e,t)=>{wn.init(e,t);const n=e._zod.parse,r=ie(()=>vn(t));let o;const s=me,i=!ne.jitless,a=i&&ge.value,c=t.catchall;let u;e._zod.parse=(d,l)=>{u??(u=r.value);const p=d.value;return s(p)?i&&a&&!1===l?.async&&!0!==l.jitless?(o||(o=(e=>{const t=new At(["shape","payload","ctx"]),n=r.value,o=e=>{const t=fe(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const s=/* @__PURE__ */Object.create(null);let i=0;for(const r of n.keys)s[r]="key_"+i++;t.write("const newResult = {};");for(const r of n.keys){const n=s[r],i=fe(r),a=e[r],c="optional"===a?._zod?.optout;t.write(`const ${n} = ${o(r)};`),c?t.write(`\n if (${n}.issues.length) {\n if (${i} in input) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${i}, ...iss.path] : [${i}]\n })));\n }\n }\n \n if (${n}.value === undefined) {\n if (${i} in input) {\n newResult[${i}] = undefined;\n }\n } else {\n newResult[${i}] = ${n}.value;\n }\n \n `):t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${i}, ...iss.path] : [${i}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${i} in input) {\n newResult[${i}] = undefined;\n }\n } else {\n newResult[${i}] = ${n}.value;\n }\n \n `)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,n)=>a(e,t,n)})(t.shape)),d=o(d,l),c?bn([],p,d,l,u,e):d):n(d,l):(d.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),d)}});function kn(e,t,n,r){for(const s of e)if(0===s.issues.length)return t.value=s.value,t;const o=e.filter(e=>!xe(e));return 1===o.length?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Oe(e,r,re())))}),t)}const zn=/* @__PURE__ */Q("$ZodUnion",(e,t)=>{Pt.init(e,t),de(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),de(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),de(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),de(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>ce(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(o,s)=>{if(n)return r(o,s);let i=!1;const a=[];for(const e of t.options){const t=e._zod.run({value:o.value,issues:[]},s);if(t instanceof Promise)a.push(t),i=!0;else{if(0===t.issues.length)return t;a.push(t)}}return i?Promise.all(a).then(t=>kn(t,o,e,s)):kn(a,o,e,s)}}),xn=/* @__PURE__ */Q("$ZodIntersection",(e,t)=>{Pt.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,o=t.left._zod.run({value:r,issues:[]},n),s=t.right._zod.run({value:r,issues:[]},n);return o instanceof Promise||s instanceof Promise?Promise.all([o,s]).then(([t,n])=>Sn(e,t,n)):Sn(e,o,s)}});function En(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(ye(e)&&ye(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),o={...e,...t};for(const s of r){const n=En(e[s],t[s]);if(!n.valid)return{valid:!1,mergeErrorPath:[s,...n.mergeErrorPath]};o[s]=n.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=En(e[r],t[r]);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Sn(e,t,n){const r=/* @__PURE__ */new Map;let o;for(const a of t.issues)if("unrecognized_keys"===a.code){o??(o=a);for(const e of a.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(a);for(const a of n.issues)if("unrecognized_keys"===a.code)for(const e of a.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(a);const s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length&&o&&e.issues.push({...o,keys:s}),xe(e))return e;const i=En(t.value,n.value);if(!i.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(i.mergeErrorPath)}`);return e.value=i.data,e}const On=/* @__PURE__ */Q("$ZodEnum",(e,t)=>{Pt.init(e,t);const n=oe(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>be.has(typeof e)).map(e=>"string"==typeof e?we(e):e.toString()).join("|")})$`),e._zod.parse=(t,o)=>{const s=t.value;return r.has(s)||t.issues.push({code:"invalid_value",values:n,input:s,inst:e}),t}}),Cn=/* @__PURE__ */Q("$ZodTransform",(e,t)=>{Pt.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new te(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(e=>(n.value=e,n));if(o instanceof Promise)throw new ee;return n.value=o,n}});function In(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const $n=/* @__PURE__ */Q("$ZodOptional",(e,t)=>{Pt.init(e,t),e._zod.optin="optional",e._zod.optout="optional",de(e._zod,"values",()=>t.innerType._zod.values?/* @__PURE__ */new Set([...t.innerType._zod.values,void 0]):void 0),de(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${ce(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>In(t,e.value)):In(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),Nn=/* @__PURE__ */Q("$ZodExactOptional",(e,t)=>{$n.init(e,t),de(e._zod,"values",()=>t.innerType._zod.values),de(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Tn=/* @__PURE__ */Q("$ZodNullable",(e,t)=>{Pt.init(e,t),de(e._zod,"optin",()=>t.innerType._zod.optin),de(e._zod,"optout",()=>t.innerType._zod.optout),de(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${ce(e.source)}|null)$`):void 0}),de(e._zod,"values",()=>t.innerType._zod.values?/* @__PURE__ */new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),jn=/* @__PURE__ */Q("$ZodDefault",(e,t)=>{Pt.init(e,t),e._zod.optin="optional",de(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>An(e,t)):An(r,t)}});function An(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Mn=/* @__PURE__ */Q("$ZodPrefault",(e,t)=>{Pt.init(e,t),e._zod.optin="optional",de(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Pn=/* @__PURE__ */Q("$ZodNonOptional",(e,t)=>{Pt.init(e,t),de(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(t=>Zn(t,e)):Zn(o,e)}});function Zn(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Fn=/* @__PURE__ */Q("$ZodCatch",(e,t)=>{Pt.init(e,t),de(e._zod,"optin",()=>t.innerType._zod.optin),de(e._zod,"optout",()=>t.innerType._zod.optout),de(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Oe(e,n,re()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Oe(e,n,re()))},input:e.value}),e.issues=[]),e)}}),Dn=/* @__PURE__ */Q("$ZodPipe",(e,t)=>{Pt.init(e,t),de(e._zod,"values",()=>t.in._zod.values),de(e._zod,"optin",()=>t.in._zod.optin),de(e._zod,"optout",()=>t.out._zod.optout),de(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Rn(e,t.in,n)):Rn(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Rn(e,t.out,n)):Rn(r,t.out,n)}});function Rn(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Ln=/* @__PURE__ */Q("$ZodReadonly",(e,t)=>{Pt.init(e,t),de(e._zod,"propValues",()=>t.innerType._zod.propValues),de(e._zod,"values",()=>t.innerType._zod.values),de(e._zod,"optin",()=>t.innerType?._zod?.optin),de(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Un):Un(r)}});function Un(e){return e.value=Object.freeze(e.value),e}const Wn=/* @__PURE__ */Q("$ZodCustom",(e,t)=>{yt.init(e,t),Pt.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(t=>Bn(t,n,r,e));Bn(o,n,r,e)}});function Bn(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Ie(e))}}var Jn;(Jn=globalThis).__zod_globalRegistry??(Jn.__zod_globalRegistry=new class{constructor(){this._map=/* @__PURE__ */new WeakMap,this._idmap=/* @__PURE__ */new Map}add(e,...t){const n=t[0];return this._map.set(e,n),n&&"object"==typeof n&&"id"in n&&this._idmap.set(n.id,e),this}clear(){return this._map=/* @__PURE__ */new WeakMap,this._idmap=/* @__PURE__ */new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}});const Vn=globalThis.__zod_globalRegistry;function qn(e,t){return new e({type:"string",...ke(t)})}function Gn(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ke(t)})}function Kn(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...ke(t)})}function Hn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...ke(t)})}function Yn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...ke(t)})}function Xn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...ke(t)})}function Qn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...ke(t)})}function er(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...ke(t)})}function tr(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...ke(t)})}function nr(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...ke(t)})}function rr(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...ke(t)})}function or(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...ke(t)})}function sr(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...ke(t)})}function ir(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...ke(t)})}function ar(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...ke(t)})}function cr(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...ke(t)})}function ur(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...ke(t)})}function dr(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...ke(t)})}function lr(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...ke(t)})}function pr(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...ke(t)})}function fr(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...ke(t)})}function hr(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...ke(t)})}function mr(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...ke(t)})}function gr(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...ke(t)})}function yr(e,t){return new e({type:"string",format:"date",check:"string_format",...ke(t)})}function vr(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...ke(t)})}function br(e,t){return new e({type:"string",format:"duration",check:"string_format",...ke(t)})}function wr(e,t){return new e({type:"number",checks:[],...ke(t)})}function _r(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...ke(t)})}function kr(e){return new e({type:"any"})}function zr(e){return new e({type:"unknown"})}function xr(e,t){return new e({type:"never",...ke(t)})}function Er(e,t){return new bt({check:"less_than",...ke(t),value:e,inclusive:!1})}function Sr(e,t){return new bt({check:"less_than",...ke(t),value:e,inclusive:!0})}function Or(e,t){return new wt({check:"greater_than",...ke(t),value:e,inclusive:!1})}function Cr(e,t){return new wt({check:"greater_than",...ke(t),value:e,inclusive:!0})}function Ir(e,t){return new _t({check:"multiple_of",...ke(t),value:e})}function $r(e,t){return new zt({check:"max_length",...ke(t),maximum:e})}function Nr(e,t){return new xt({check:"min_length",...ke(t),minimum:e})}function Tr(e,t){return new Et({check:"length_equals",...ke(t),length:e})}function jr(e,t){return new Ot({check:"string_format",format:"regex",...ke(t),pattern:e})}function Ar(e){return new Ct({check:"string_format",format:"lowercase",...ke(e)})}function Mr(e){return new It({check:"string_format",format:"uppercase",...ke(e)})}function Pr(e,t){return new $t({check:"string_format",format:"includes",...ke(t),includes:e})}function Zr(e,t){return new Nt({check:"string_format",format:"starts_with",...ke(t),prefix:e})}function Fr(e,t){return new Tt({check:"string_format",format:"ends_with",...ke(t),suffix:e})}function Dr(e){return new jt({check:"overwrite",tx:e})}function Rr(e){/* @__PURE__ */
|
|
16
|
+
return Dr(t=>t.normalize(e))}function Lr(){/* @__PURE__ */
|
|
17
|
+
return Dr(e=>e.trim())}function Ur(){/* @__PURE__ */
|
|
18
|
+
return Dr(e=>e.toLowerCase())}function Wr(){/* @__PURE__ */
|
|
19
|
+
return Dr(e=>e.toUpperCase())}function Br(){/* @__PURE__ */
|
|
20
|
+
return Dr(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e))}function Jr(e,t,n){return new e({type:"array",element:t,...ke(n)})}function Vr(e,t,n){return new e({type:"custom",check:"custom",fn:t,...ke(n)})}function qr(e){const t=/* @__PURE__ */Gr(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Ie(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Ie(r))}},e(n.value,n)));return t}function Gr(e,t){const n=new yt({check:"custom",...ke(t)});return n._zod.check=e,n}function Kr(e){let t=e?.target??"draft-2020-12";return"draft-4"===t&&(t="draft-04"),"draft-7"===t&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??Vn,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:/* @__PURE__ */new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function Hr(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,s=t.seen.get(e);if(s)return s.count++,n.schemaPath.includes(e)&&(s.cycle=n.path),s.schema;const i={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,i);const a=e._zod.toJSONSchema?.();if(a)i.schema=a;else{const r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,r);else{const n=i.schema,s=t.processors[o.type];if(!s)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);s(e,t,n,r)}const s=e._zod.parent;s&&(i.ref||(i.ref=s),Hr(s,t,r),t.seen.get(s).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(i.schema,c),"input"===t.io&&Qr(e)&&(delete i.schema.examples,delete i.schema.default),"input"===t.io&&i.schema._prefault&&((r=i.schema).default??(r.default=i.schema._prefault)),delete i.schema._prefault,t.seen.get(e).schema}function Yr(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=/* @__PURE__ */new Map;for(const s of e.seen.entries()){const t=e.metadataRegistry.get(s[0])?.id;if(t){const e=r.get(t);if(e&&e!==s[0])throw new Error(`Duplicate schema id "${t}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(t,s[0])}}const o=t=>{if(t[1].schema.$ref)return;const r=t[1],{ref:o,defId:s}=(t=>{const r="draft-2020-12"===e.target?"$defs":"definitions";if(e.external){const n=e.external.registry.get(t[0])?.id,o=e.external.uri??(e=>e);if(n)return{ref:o(n)};const s=t[1].defId??t[1].schema.id??"schema"+e.counter++;return t[1].defId=s,{defId:s,ref:`${o("__shared")}#/${r}/${s}`}}if(t[1]===n)return{ref:"#"};const o=`#/${r}/`,s=t[1].schema.id??"__schema"+e.counter++;return{defId:s,ref:o+s}})(t);r.def={...r.schema},s&&(r.defId=s);const i=r.schema;for(const e in i)delete i[e];i.$ref=o};if("throw"===e.cycles)for(const s of e.seen.entries()){const e=s[1];if(e.cycle)throw new Error(`Cycle detected: #/${e.cycle?.join("/")}/<root>\n\nSet the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const s of e.seen.entries()){const n=s[1];if(t===s[0]){o(s);continue}if(e.external){const n=e.external.registry.get(s[0])?.id;if(t!==s[0]&&n){o(s);continue}}const r=e.metadataRegistry.get(s[0])?.id;(r||n.cycle||n.count>1&&"ref"===e.reused)&&o(s)}}function Xr(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=t=>{const n=e.seen.get(t);if(null===n.ref)return;const o=n.def??n.schema,s={...o},i=n.ref;if(n.ref=null,i){r(i);const n=e.seen.get(i),a=n.schema;if(!a.$ref||"draft-07"!==e.target&&"draft-04"!==e.target&&"openapi-3.0"!==e.target?Object.assign(o,a):(o.allOf=o.allOf??[],o.allOf.push(a)),Object.assign(o,s),t._zod.parent===i)for(const e in o)"$ref"!==e&&"allOf"!==e&&(e in s||delete o[e]);if(a.$ref&&n.def)for(const e in o)"$ref"!==e&&"allOf"!==e&&e in n.def&&JSON.stringify(o[e])===JSON.stringify(n.def[e])&&delete o[e]}const a=t._zod.parent;if(a&&a!==i){r(a);const t=e.seen.get(a);if(t?.schema.$ref&&(o.$ref=t.schema.$ref,t.def))for(const e in o)"$ref"!==e&&"allOf"!==e&&e in t.def&&JSON.stringify(o[e])===JSON.stringify(t.def[e])&&delete o[e]}e.override({zodSchema:t,jsonSchema:o,path:n.path??[]})};for(const a of[...e.seen.entries()].reverse())r(a[0]);const o={};if("draft-2020-12"===e.target?o.$schema="https://json-schema.org/draft/2020-12/schema":"draft-07"===e.target?o.$schema="http://json-schema.org/draft-07/schema#":"draft-04"===e.target?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const n=e.external.registry.get(t)?.id;if(!n)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(n)}Object.assign(o,n.def??n.schema);const s=e.external?.defs??{};for(const a of e.seen.entries()){const e=a[1];e.def&&e.defId&&(s[e.defId]=e.def)}e.external||Object.keys(s).length>0&&("draft-2020-12"===e.target?o.$defs=s:o.definitions=s);try{const n=JSON.parse(JSON.stringify(o));return Object.defineProperty(n,"~standard",{value:{...t["~standard"],jsonSchema:{input:eo(t,"input",e.processors),output:eo(t,"output",e.processors)}},enumerable:!1,writable:!1}),n}catch(i){throw new Error("Error converting schema to JSON.")}}function Qr(e,t){const n=t??{seen:/* @__PURE__ */new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if("transform"===r.type)return!0;if("array"===r.type)return Qr(r.element,n);if("set"===r.type)return Qr(r.valueType,n);if("lazy"===r.type)return Qr(r.getter(),n);if("promise"===r.type||"optional"===r.type||"nonoptional"===r.type||"nullable"===r.type||"readonly"===r.type||"default"===r.type||"prefault"===r.type)return Qr(r.innerType,n);if("intersection"===r.type)return Qr(r.left,n)||Qr(r.right,n);if("record"===r.type||"map"===r.type)return Qr(r.keyType,n)||Qr(r.valueType,n);if("pipe"===r.type)return Qr(r.in,n)||Qr(r.out,n);if("object"===r.type){for(const e in r.shape)if(Qr(r.shape[e],n))return!0;return!1}if("union"===r.type){for(const e of r.options)if(Qr(e,n))return!0;return!1}if("tuple"===r.type){for(const e of r.items)if(Qr(e,n))return!0;return!(!r.rest||!Qr(r.rest,n))}return!1}const eo=(e,t,n={})=>r=>{const{libraryOptions:o,target:s}=r??{},i=Kr({...o??{},target:s,io:t,processors:n});return Hr(e,i),Yr(i,e),Xr(i,e)},to={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},no=(e,t,n,r)=>{const o=e._zod.def;Hr(o.innerType,t,r),t.seen.get(e).ref=o.innerType},ro=/* @__PURE__ */Q("ZodISODateTime",(e,t)=>{Ht.init(e,t),Eo.init(e,t)}),oo=/* @__PURE__ */Q("ZodISODate",(e,t)=>{Yt.init(e,t),Eo.init(e,t)}),so=/* @__PURE__ */Q("ZodISOTime",(e,t)=>{Xt.init(e,t),Eo.init(e,t)}),io=/* @__PURE__ */Q("ZodISODuration",(e,t)=>{Qt.init(e,t),Eo.init(e,t)}),ao=Q("ZodError",(e,t)=>{Ne.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=e=>{for(const o of e.issues)if("invalid_union"===o.code&&o.errors.length)o.errors.map(e=>r({issues:e}));else if("invalid_key"===o.code)r({issues:o.issues});else if("invalid_element"===o.code)r({issues:o.issues});else if(0===o.path.length)n._errors.push(t(o));else{let e=n,r=0;for(;r<o.path.length;){const n=o.path[r];r===o.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(o))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,se,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,se,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),co=/* @__PURE__ */je(ao),uo=/* @__PURE__ */Ae(ao),lo=/* @__PURE__ */Me(ao),po=/* @__PURE__ */Ze(ao),fo=/* @__PURE__ */De(ao),ho=/* @__PURE__ */Re(ao),mo=/* @__PURE__ */Le(ao),go=/* @__PURE__ */Ue(ao),yo=/* @__PURE__ */We(ao),vo=/* @__PURE__ */Be(ao),bo=/* @__PURE__ */Je(ao),wo=/* @__PURE__ */Ve(ao),_o=/* @__PURE__ */Q("ZodType",(e,t)=>(Pt.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:eo(e,"input"),output:eo(e,"output")}}),e.toJSONSchema=((e,t={})=>n=>{const r=Kr({...n,processors:t});return Hr(e,r),Yr(r,e),Xr(r,e)})(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(pe(t,{checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>_e(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>co(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>lo(e,t,n),e.parseAsync=async(t,n)=>uo(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>po(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>fo(e,t,n),e.decode=(t,n)=>ho(e,t,n),e.encodeAsync=async(t,n)=>mo(e,t,n),e.decodeAsync=async(t,n)=>go(e,t,n),e.safeEncode=(t,n)=>yo(e,t,n),e.safeDecode=(t,n)=>vo(e,t,n),e.safeEncodeAsync=async(t,n)=>bo(e,t,n),e.safeDecodeAsync=async(t,n)=>wo(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){/* @__PURE__ */
|
|
21
|
+
return Vr(vs,e,t)}(t,n)),e.superRefine=t=>e.check(/* @__PURE__ */qr(t)),e.overwrite=t=>e.check(/* @__PURE__ */Dr(t)),e.optional=()=>as(e),e.exactOptional=()=>new cs({type:"optional",innerType:e}),e.nullable=()=>ds(e),e.nullish=()=>as(ds(e)),e.nonoptional=t=>function(e,t){return new fs({type:"nonoptional",innerType:e,...ke(t)})}(e,t),e.array=()=>/* @__PURE__ */Jr(Qo,e,void 0),e.or=t=>new ts({type:"union",options:[e,t],...ke(void 0)}),e.and=t=>new ns({type:"intersection",left:e,right:t}),e.transform=t=>gs(e,new ss({type:"transform",transform:t})),e.default=t=>{return n=t,new ls({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():ve(n)}});var n},e.prefault=t=>{return n=t,new ps({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():ve(n)}});var n},e.catch=t=>{return new hs({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>gs(e,t),e.readonly=()=>new ys({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return Vn.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>Vn.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return Vn.get(e);const n=e.clone();return Vn.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),ko=/* @__PURE__ */Q("_ZodString",(e,t)=>{Zt.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n;r.type="string";const{minimum:o,maximum:s,format:i,patterns:a,contentEncoding:c}=e._zod.bag;if("number"==typeof o&&(r.minLength=o),"number"==typeof s&&(r.maxLength=s),i&&(r.format=to[i]??i,""===r.format&&delete r.format,"time"===i&&delete r.format),c&&(r.contentEncoding=c),a&&a.size>0){const e=[...a];1===e.length?r.pattern=e[0].source:e.length>1&&(r.allOf=[...e.map(e=>({..."draft-07"===t.target||"draft-04"===t.target||"openapi-3.0"===t.target?{type:"string"}:{},pattern:e.source}))])}})(e,t,n);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(/* @__PURE__ */jr(...t)),e.includes=(...t)=>e.check(/* @__PURE__ */Pr(...t)),e.startsWith=(...t)=>e.check(/* @__PURE__ */Zr(...t)),e.endsWith=(...t)=>e.check(/* @__PURE__ */Fr(...t)),e.min=(...t)=>e.check(/* @__PURE__ */Nr(...t)),e.max=(...t)=>e.check(/* @__PURE__ */$r(...t)),e.length=(...t)=>e.check(/* @__PURE__ */Tr(...t)),e.nonempty=(...t)=>e.check(/* @__PURE__ */Nr(1,...t)),e.lowercase=t=>e.check(/* @__PURE__ */Ar(t)),e.uppercase=t=>e.check(/* @__PURE__ */Mr(t)),e.trim=()=>e.check(/* @__PURE__ */Lr()),e.normalize=(...t)=>e.check(/* @__PURE__ */Rr(...t)),e.toLowerCase=()=>e.check(/* @__PURE__ */Ur()),e.toUpperCase=()=>e.check(/* @__PURE__ */Wr()),e.slugify=()=>e.check(/* @__PURE__ */Br())}),zo=/* @__PURE__ */Q("ZodString",(e,t)=>{Zt.init(e,t),ko.init(e,t),e.email=t=>e.check(/* @__PURE__ */Gn(So,t)),e.url=t=>e.check(/* @__PURE__ */er(Io,t)),e.jwt=t=>e.check(/* @__PURE__ */mr(Bo,t)),e.emoji=t=>e.check(/* @__PURE__ */tr($o,t)),e.guid=t=>e.check(/* @__PURE__ */Kn(Oo,t)),e.uuid=t=>e.check(/* @__PURE__ */Hn(Co,t)),e.uuidv4=t=>e.check(/* @__PURE__ */Yn(Co,t)),e.uuidv6=t=>e.check(/* @__PURE__ */Xn(Co,t)),e.uuidv7=t=>e.check(/* @__PURE__ */Qn(Co,t)),e.nanoid=t=>e.check(/* @__PURE__ */nr(No,t)),e.guid=t=>e.check(/* @__PURE__ */Kn(Oo,t)),e.cuid=t=>e.check(/* @__PURE__ */rr(To,t)),e.cuid2=t=>e.check(/* @__PURE__ */or(jo,t)),e.ulid=t=>e.check(/* @__PURE__ */sr(Ao,t)),e.base64=t=>e.check(/* @__PURE__ */pr(Lo,t)),e.base64url=t=>e.check(/* @__PURE__ */fr(Uo,t)),e.xid=t=>e.check(/* @__PURE__ */ir(Mo,t)),e.ksuid=t=>e.check(/* @__PURE__ */ar(Po,t)),e.ipv4=t=>e.check(/* @__PURE__ */cr(Zo,t)),e.ipv6=t=>e.check(/* @__PURE__ */ur(Fo,t)),e.cidrv4=t=>e.check(/* @__PURE__ */dr(Do,t)),e.cidrv6=t=>e.check(/* @__PURE__ */lr(Ro,t)),e.e164=t=>e.check(/* @__PURE__ */hr(Wo,t)),e.datetime=t=>e.check(function(e){/* @__PURE__ */
|
|
22
|
+
return gr(ro,e)}(t)),e.date=t=>e.check(function(e){/* @__PURE__ */
|
|
23
|
+
return yr(oo,e)}(t)),e.time=t=>e.check(function(e){/* @__PURE__ */
|
|
24
|
+
return vr(so,e)}(t)),e.duration=t=>e.check(function(e){/* @__PURE__ */
|
|
25
|
+
return br(io,e)}(t))});function xo(e){/* @__PURE__ */
|
|
26
|
+
return qn(zo,e)}const Eo=/* @__PURE__ */Q("ZodStringFormat",(e,t)=>{Ft.init(e,t),ko.init(e,t)}),So=/* @__PURE__ */Q("ZodEmail",(e,t)=>{Lt.init(e,t),Eo.init(e,t)}),Oo=/* @__PURE__ */Q("ZodGUID",(e,t)=>{Dt.init(e,t),Eo.init(e,t)}),Co=/* @__PURE__ */Q("ZodUUID",(e,t)=>{Rt.init(e,t),Eo.init(e,t)}),Io=/* @__PURE__ */Q("ZodURL",(e,t)=>{Ut.init(e,t),Eo.init(e,t)}),$o=/* @__PURE__ */Q("ZodEmoji",(e,t)=>{Wt.init(e,t),Eo.init(e,t)}),No=/* @__PURE__ */Q("ZodNanoID",(e,t)=>{Bt.init(e,t),Eo.init(e,t)}),To=/* @__PURE__ */Q("ZodCUID",(e,t)=>{Jt.init(e,t),Eo.init(e,t)}),jo=/* @__PURE__ */Q("ZodCUID2",(e,t)=>{Vt.init(e,t),Eo.init(e,t)}),Ao=/* @__PURE__ */Q("ZodULID",(e,t)=>{qt.init(e,t),Eo.init(e,t)}),Mo=/* @__PURE__ */Q("ZodXID",(e,t)=>{Gt.init(e,t),Eo.init(e,t)}),Po=/* @__PURE__ */Q("ZodKSUID",(e,t)=>{Kt.init(e,t),Eo.init(e,t)}),Zo=/* @__PURE__ */Q("ZodIPv4",(e,t)=>{en.init(e,t),Eo.init(e,t)}),Fo=/* @__PURE__ */Q("ZodIPv6",(e,t)=>{tn.init(e,t),Eo.init(e,t)}),Do=/* @__PURE__ */Q("ZodCIDRv4",(e,t)=>{nn.init(e,t),Eo.init(e,t)}),Ro=/* @__PURE__ */Q("ZodCIDRv6",(e,t)=>{rn.init(e,t),Eo.init(e,t)}),Lo=/* @__PURE__ */Q("ZodBase64",(e,t)=>{sn.init(e,t),Eo.init(e,t)}),Uo=/* @__PURE__ */Q("ZodBase64URL",(e,t)=>{an.init(e,t),Eo.init(e,t)}),Wo=/* @__PURE__ */Q("ZodE164",(e,t)=>{cn.init(e,t),Eo.init(e,t)}),Bo=/* @__PURE__ */Q("ZodJWT",(e,t)=>{un.init(e,t),Eo.init(e,t)}),Jo=/* @__PURE__ */Q("ZodNumber",(e,t)=>{dn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n,{minimum:o,maximum:s,format:i,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u}=e._zod.bag;"string"==typeof i&&i.includes("int")?r.type="integer":r.type="number","number"==typeof u&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.minimum=u,r.exclusiveMinimum=!0):r.exclusiveMinimum=u),"number"==typeof o&&(r.minimum=o,"number"==typeof u&&"draft-04"!==t.target&&(u>=o?delete r.minimum:delete r.exclusiveMinimum)),"number"==typeof c&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.maximum=c,r.exclusiveMaximum=!0):r.exclusiveMaximum=c),"number"==typeof s&&(r.maximum=s,"number"==typeof c&&"draft-04"!==t.target&&(c<=s?delete r.maximum:delete r.exclusiveMaximum)),"number"==typeof a&&(r.multipleOf=a)})(e,t,n),e.gt=(t,n)=>e.check(/* @__PURE__ */Or(t,n)),e.gte=(t,n)=>e.check(/* @__PURE__ */Cr(t,n)),e.min=(t,n)=>e.check(/* @__PURE__ */Cr(t,n)),e.lt=(t,n)=>e.check(/* @__PURE__ */Er(t,n)),e.lte=(t,n)=>e.check(/* @__PURE__ */Sr(t,n)),e.max=(t,n)=>e.check(/* @__PURE__ */Sr(t,n)),e.int=t=>e.check(Go(t)),e.safe=t=>e.check(Go(t)),e.positive=t=>e.check(/* @__PURE__ */Or(0,t)),e.nonnegative=t=>e.check(/* @__PURE__ */Cr(0,t)),e.negative=t=>e.check(/* @__PURE__ */Er(0,t)),e.nonpositive=t=>e.check(/* @__PURE__ */Sr(0,t)),e.multipleOf=(t,n)=>e.check(/* @__PURE__ */Ir(t,n)),e.step=(t,n)=>e.check(/* @__PURE__ */Ir(t,n)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Vo(e){/* @__PURE__ */
|
|
27
|
+
return wr(Jo,e)}const qo=/* @__PURE__ */Q("ZodNumberFormat",(e,t)=>{ln.init(e,t),Jo.init(e,t)});function Go(e){/* @__PURE__ */
|
|
28
|
+
return _r(qo,e)}const Ko=/* @__PURE__ */Q("ZodAny",(e,t)=>{pn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}}),Ho=/* @__PURE__ */Q("ZodUnknown",(e,t)=>{fn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function Yo(){/* @__PURE__ */
|
|
29
|
+
return zr(Ho)}const Xo=/* @__PURE__ */Q("ZodNever",(e,t)=>{hn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.not={}})(0,0,t)}),Qo=/* @__PURE__ */Q("ZodArray",(e,t)=>{gn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,s=e._zod.def,{minimum:i,maximum:a}=e._zod.bag;"number"==typeof i&&(o.minItems=i),"number"==typeof a&&(o.maxItems=a),o.type="array",o.items=Hr(s.element,t,{...r,path:[...r.path,"items"]})})(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(/* @__PURE__ */Nr(t,n)),e.nonempty=t=>e.check(/* @__PURE__ */Nr(1,t)),e.max=(t,n)=>e.check(/* @__PURE__ */$r(t,n)),e.length=(t,n)=>e.check(/* @__PURE__ */Tr(t,n)),e.unwrap=()=>e.element}),es=/* @__PURE__ */Q("ZodObject",(e,t)=>{_n.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,s=e._zod.def;o.type="object",o.properties={};const i=s.shape;for(const u in i)o.properties[u]=Hr(i[u],t,{...r,path:[...r.path,"properties",u]});const a=new Set(Object.keys(i)),c=new Set([...a].filter(e=>{const n=s.shape[e]._zod;return"input"===t.io?void 0===n.optin:void 0===n.optout}));c.size>0&&(o.required=Array.from(c)),"never"===s.catchall?._zod.def.type?o.additionalProperties=!1:s.catchall?s.catchall&&(o.additionalProperties=Hr(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):"output"===t.io&&(o.additionalProperties=!1)})(e,t,n,r),de(e,"shape",()=>t.shape),e.keyof=()=>os(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Yo()}),e.loose=()=>e.clone({...e._zod.def,catchall:Yo()}),e.strict=()=>e.clone({...e._zod.def,catchall:/* @__PURE__ */xr(Xo,void 0)}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!ye(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const n=e._zod.def.shape;for(const e in t)if(void 0!==Object.getOwnPropertyDescriptor(n,e))throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=pe(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return le(this,"shape",n),n}});return _e(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!ye(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=pe(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return le(this,"shape",n),n}});return _e(e,n)}(e,t),e.merge=t=>function(e,t){const n=pe(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return le(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return _e(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return _e(e,pe(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return le(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const o=pe(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return le(this,"shape",r),r},checks:[]});return _e(e,o)}(e,t),e.partial=(...t)=>function(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=pe(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)o[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return le(this,"shape",o),o},checks:[]});return _e(t,o)}(is,e,t[0]),e.required=(...t)=>function(e,t,n){const r=pe(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in o))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)o[t]=new e({type:"nonoptional",innerType:r[t]});return le(this,"shape",o),o}});return _e(t,r)}(fs,e,t[0])}),ts=/* @__PURE__ */Q("ZodUnion",(e,t)=>{zn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s=!1===o.inclusive,i=o.options.map((e,n)=>Hr(e,t,{...r,path:[...r.path,s?"oneOf":"anyOf",n]}));s?n.oneOf=i:n.anyOf=i})(e,t,n,r),e.options=t.options}),ns=/* @__PURE__ */Q("ZodIntersection",(e,t)=>{xn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s=Hr(o.left,t,{...r,path:[...r.path,"allOf",0]}),i=Hr(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=e=>"allOf"in e&&1===Object.keys(e).length,c=[...a(s)?s.allOf:[s],...a(i)?i.allOf:[i]];n.allOf=c})(e,t,n,r)}),rs=/* @__PURE__ */Q("ZodEnum",(e,t)=>{On.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=oe(e._zod.def.entries);r.every(e=>"number"==typeof e)&&(n.type="number"),r.every(e=>"string"==typeof e)&&(n.type="string"),n.enum=r})(e,0,n),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const o={};for(const s of e){if(!n.has(s))throw new Error(`Key ${s} not found in enum`);o[s]=t.entries[s]}return new rs({...t,checks:[],...ke(r),entries:o})},e.exclude=(e,r)=>{const o={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete o[t]}return new rs({...t,checks:[],...ke(r),entries:o})}});function os(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new rs({type:"enum",entries:n,...ke(t)})}const ss=/* @__PURE__ */Q("ZodTransform",(e,t)=>{Cn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Transforms cannot be represented in JSON Schema")})(0,e),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new te(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(Ie(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push(Ie(t))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(e=>(n.value=e,n)):(n.value=o,n)}}),is=/* @__PURE__ */Q("ZodOptional",(e,t)=>{$n.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>no(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});function as(e){return new is({type:"optional",innerType:e})}const cs=/* @__PURE__ */Q("ZodExactOptional",(e,t)=>{Nn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>no(e,t,0,r),e.unwrap=()=>e._zod.def.innerType}),us=/* @__PURE__ */Q("ZodNullable",(e,t)=>{Tn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s=Hr(o.innerType,t,r),i=t.seen.get(e);"openapi-3.0"===t.target?(i.ref=o.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ds(e){return new us({type:"nullable",innerType:e})}const ls=/* @__PURE__ */Q("ZodDefault",(e,t)=>{jn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Hr(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap}),ps=/* @__PURE__ */Q("ZodPrefault",(e,t)=>{Mn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Hr(o.innerType,t,r),t.seen.get(e).ref=o.innerType,"input"===t.io&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),fs=/* @__PURE__ */Q("ZodNonOptional",(e,t)=>{Pn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Hr(o.innerType,t,r),t.seen.get(e).ref=o.innerType})(e,t,0,r),e.unwrap=()=>e._zod.def.innerType}),hs=/* @__PURE__ */Q("ZodCatch",(e,t)=>{Fn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;let s;Hr(o.innerType,t,r),t.seen.get(e).ref=o.innerType;try{s=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=s})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap}),ms=/* @__PURE__ */Q("ZodPipe",(e,t)=>{Dn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s="input"===t.io?"transform"===o.in._zod.def.type?o.out:o.in:o.out;Hr(s,t,r),t.seen.get(e).ref=s})(e,t,0,r),e.in=t.in,e.out=t.out});function gs(e,t){return new ms({type:"pipe",in:e,out:t})}const ys=/* @__PURE__ */Q("ZodReadonly",(e,t)=>{Ln.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Hr(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.readOnly=!0})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),vs=/* @__PURE__ */Q("ZodCustom",(e,t)=>{Wn.init(e,t),_o.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Custom types cannot be represented in JSON Schema")})(0,e)}),bs="chat_device_id";function ws(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}const _s=function(){const e={type:"object",shape:{id:xo().optional(),type:os(["text","image","audio","location","system"]).default("text"),content:xo().optional(),imageUrl:xo().url().optional(),audioUrl:xo().url().optional(),latitude:Vo().optional(),longitude:Vo().optional(),timestamp:xo().optional(),sender:os(["bot","user","system"]).optional(),emotion:/* @__PURE__ */kr(Ko).optional()}??{},...ke(void 0)};return new es(e)}();class ks{queue=[];endpoint;apiKey;flushInterval=null;isFlushing=!1;isDisabled=!1;MAX_QUEUE_SIZE=100;FLUSH_INTERVAL_MS=3e4;BATCH_SIZE=10;constructor(e,t){this.endpoint=e,this.apiKey=t,this.startAutoFlush()}startAutoFlush(){this.flushInterval=setInterval(()=>{!this.isDisabled&&this.queue.length>0&&this.flush()},this.FLUSH_INTERVAL_MS)}trackOpen(){this.track("chat_opened")}trackClose(){this.track("chat_closed")}trackMessageSent(e){this.track("message_sent",{type:e})}trackMessageReceived(e,t){this.track("message_received",{type:e,latency:t})}trackError(e,t){this.track("error",{error:e,context:t})}trackConnectionStatus(e){this.track("connection_status",{isConnected:e})}trackFeatureUsed(e){this.track("feature_used",{feature:e})}trackTypingStarted(){this.track("typing_started")}trackAttachmentSent(e,t){this.track("attachment_sent",{type:e,size:t})}track(e,t){this.isDisabled||(this.queue.push({event:e,properties:{...t,userAgent:"undefined"!=typeof navigator?navigator.userAgent:void 0,url:"undefined"!=typeof window?window.location.href:void 0},timestamp:Date.now()}),this.queue.length>=this.BATCH_SIZE&&this.flush(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE),p.warn("Analytics queue overflow, dropping old events")))}async flush(){if(this.isDisabled||0===this.queue.length||this.isFlushing)return;this.isFlushing=!0;const e=[...this.queue];this.queue=[];try{const t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:JSON.stringify({events:e}),keepalive:!0});t.ok?p.debug(`Analytics: Flushed ${e.length} events`):(this.isDisabled=!0,this.queue=[],p.debug(`Analytics disabled: endpoint returned ${t.status}`))}catch(t){this.isDisabled=!0,this.queue=[],p.debug("Analytics disabled due to network error")}finally{this.isFlushing=!1}}destroy(){this.flushInterval&&clearInterval(this.flushInterval),this.flush()}}let zs=null,xs=null;function Es(e){zs=e}function Ss(e){xs=e}const Os=e.createContext(null);function Cs({children:n,defaultLocale:r,initialState:o,onStateChange:s,...i}){const[a,c]=e.useState(o?.isOpen??!1),[u,d]=e.useState(0),l=e.useCallback(()=>{c(!0),d(0),s?.(!0)},[s]),f=e.useCallback(()=>{c(!1),s?.(!1)},[s]),h=e.useCallback(()=>{c(e=>{const t=!e;return t&&d(0),s?.(t),t})},[s]),m=e.useCallback(e=>{zs?(zs(e),p.debug("ChatWidgetProvider sendMessage:",e)):p.warn("sendMessage called but no handler registered")},[]),y=e.useCallback(()=>{xs?(xs(),p.debug("ChatWidgetProvider clearMessages called")):p.warn("clearMessages called but no handler registered")},[]),v={isOpen:a,open:l,close:f,toggle:h,sendMessage:m,clearMessages:y,unreadCount:u},b=e.useCallback((e,t)=>{"message:received"!==e||a||d(e=>e+1),i.onEvent?.(e,t)},[a,i]);/* @__PURE__ */
|
|
30
|
+
return t.jsx(g,{defaultLocale:r,children:/* @__PURE__ */t.jsxs(Os.Provider,{value:v,children:[n,
|
|
31
|
+
/* @__PURE__ */t.jsx(Ts,{...i,onStateChange:e=>{c(e),e&&d(0),s?.(e)},onEvent:b})]})})}function Is(){const t=e.useContext(Os);if(!t)throw new Error("useChatWidget must be used within a ChatWidgetProvider. Wrap your app with <ChatWidgetProvider>...</ChatWidgetProvider>");return t}const $s=e=>new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=e=>n(e)});function Ns(t){const{apiKey:n,apiBaseUrl:r,pageContext:s,includeSEOMetadata:i=!1,theme:a,userContext:u,onLogin:d,onNavigate:l,onEvent:f,onStateChange:g,onThemeUpdate:y}=t,[v,b]=e.useState(0),w=e.useRef(0),{t:k}=o(),z=function(t,n,r=!0){const o=e.useRef(null);return e.useEffect(()=>{if(!r||!t||!n)return;const e=`${t}/analytics`;o.current=new ks(e,n);const s=()=>o.current?.flush(),i=()=>{"hidden"===document.visibilityState&&o.current?.flush()};return window.addEventListener("beforeunload",s),window.addEventListener("visibilitychange",i),()=>{window.removeEventListener("beforeunload",s),window.removeEventListener("visibilitychange",i),o.current?.destroy()}},[t,n,r]),{trackOpen:e.useCallback(()=>{o.current?.trackOpen()},[]),trackClose:e.useCallback(()=>{o.current?.trackClose()},[]),trackMessageSent:e.useCallback(e=>{o.current?.trackMessageSent(e)},[]),trackMessageReceived:e.useCallback((e,t)=>{o.current?.trackMessageReceived(e,t)},[]),trackError:e.useCallback((e,t)=>{o.current?.trackError(e,t)},[]),trackConnectionStatus:e.useCallback(e=>{o.current?.trackConnectionStatus(e)},[]),trackFeatureUsed:e.useCallback(e=>{o.current?.trackFeatureUsed(e)},[])}}(r,n,!0),x=function({enabled:t=!0,soundEnabled:n=!0,desktopEnabled:r=!0,botName:o="Asistente",logoUrl:s,notificationSoundUrl:i}={}){const[a,u]=e.useState("default"),d=e.useRef(null),l=s||c,f=i||m;e.useEffect(()=>{n&&"undefined"!=typeof window&&(d.current=new Audio(f),d.current.volume=.3)},[n,f]),e.useEffect(()=>{"undefined"!=typeof window&&"Notification"in window&&u(Notification.permission)},[]);const h=e.useCallback(async()=>{if("undefined"==typeof window||!("Notification"in window))return p.warn("Notifications API not available"),!1;try{const e=await Notification.requestPermission();return u(e),p.info("Notification permission:",e),"granted"===e}catch(e){return p.error("Error requesting notification permission:",e),!1}},[]),g=e.useCallback(e=>{if(t&&r&&"granted"===a&&("undefined"==typeof document||!document.hasFocus()))try{const t=`Nuevo mensaje de ${o}`;let n="Mensaje recibido";"text"===e.type&&"content"in e?n=e.content?.slice(0,100)||"Mensaje recibido":"image"===e.type?n="📷 Imagen":"audio"===e.type?n="🎵 Audio":"location"===e.type&&(n="📍 Ubicación");const r=new Notification(t,{body:n,icon:l,tag:"chat-message",requireInteraction:!1,silent:!1});r.onclick=()=>{window.focus(),r.close()},setTimeout(()=>r.close(),5e3)}catch(n){p.error("Error showing notification:",n)}},[t,r,a,o,l]),y=e.useCallback(()=>{if(t&&n&&("undefined"==typeof document||!document.hasFocus()))try{d.current?.play().catch(e=>{p.debug("Audio playback blocked:",e)})}catch(e){p.error("Error playing sound:",e)}},[t,n]),v=e.useCallback(e=>{g(e),y()},[g,y]);return{permission:a,requestPermission:h,notify:g,playSound:y,notifyWithSound:v}}({enabled:!0,soundEnabled:!0,desktopEnabled:!0,botName:a?.botName||"Asistente",logoUrl:a?.logoUrl}),E=function(t=10,n=6e4){const r=e.useRef([]);return{isAllowed:e.useCallback(()=>{const e=Date.now();return r.current=r.current.filter(t=>e-t<n),!(r.current.length>=t||(r.current.push(e),0))},[t,n]),getRemainingAttempts:e.useCallback(()=>{const e=Date.now();return r.current=r.current.filter(t=>e-t<n),Math.max(0,t-r.current.length)},[t,n]),getTimeUntilReset:e.useCallback(()=>{if(0===r.current.length)return 0;const e=Date.now(),t=r.current[0],o=n-(e-t);return Math.max(0,o)},[n]),reset:e.useCallback(()=>{r.current=[]},[])}}(10,6e4),{state:S,actions:O}=function(){const[t,n]=e.useReducer(X,Y),[r,o]=e.useState(!1);e.useEffect(()=>{"undefined"==typeof window||r||(async()=>{try{await K.migrateFromLocalStorage();const e=await K.getMessages(100),t=await K.getMetadata();if(e.length>0||t){const r={messages:e.map(e=>({...e,timestamp:new Date(e.timestamp)})),sessionId:t?.sessionId||null,isOpen:t?.isOpen||!1};n({type:"RESTORE_SESSION",payload:r})}}catch(e){p.warn("Chat: Error rehydrating from IndexedDB",e);try{const e=localStorage.getItem(H);if(e){const t=JSON.parse(e);t.messages&&(t.messages=t.messages.map(e=>({...e,timestamp:new Date(e.timestamp)}))),n({type:"RESTORE_SESSION",payload:t})}}catch(t){p.error("Chat: Fallback rehydration failed",t)}}finally{o(!0)}})()},[r]),e.useEffect(()=>{if(!r)return;const e=setTimeout(async()=>{try{await K.saveMessages(t.messages),await K.setMetadata({isOpen:t.isOpen,sessionId:t.sessionId})}catch(e){p.error("Chat Persistence Error:",e);try{const e={isOpen:t.isOpen,messages:t.messages,sessionId:t.sessionId};localStorage.setItem(H,JSON.stringify(e))}catch(n){p.error("Chat: Fallback persistence failed",n)}}},500);return()=>clearTimeout(e)},[t.isOpen,t.messages,t.sessionId,r]);const s=e.useCallback(e=>{n({type:"ADD_MESSAGE",payload:e})},[]),i=e.useCallback(()=>n({type:"TOGGLE_WINDOW"}),[]),a=e.useCallback(()=>n({type:"OPEN_WINDOW"}),[]),c=e.useCallback(()=>n({type:"CLOSE_WINDOW"}),[]),u=e.useCallback(e=>n({type:"SET_CONNECTED",payload:e}),[]),d=e.useCallback(e=>n({type:"SET_TYPING",payload:e}),[]),l=e.useCallback(e=>n({type:"SET_MESSAGES",payload:e}),[]),f=e.useCallback(e=>n({type:"SET_ERROR",payload:e}),[]),h=e.useCallback(e=>n({type:"SET_SESSION_ID",payload:e}),[]),m=e.useCallback(()=>{localStorage.removeItem(H),n({type:"CLEAR_CHAT"})},[]),g=e.useCallback(()=>{n({type:"SET_MESSAGES",payload:[]})},[]);return{state:t,isHydrated:r,actions:{toggleWindow:i,openWindow:a,closeWindow:c,setConnected:u,setTyping:d,addMessage:s,setMessages:l,setError:f,setSessionId:h,clearChat:m,clearMessages:g}}}(),C=function(t=!1){const n="undefined"!=typeof window?window.location.pathname:"",r=e.useMemo(()=>n,[n]),[o,s]=e.useState({});return e.useEffect(()=>{if(!t)return void s({});const e=setTimeout(()=>{const e=function(){if("undefined"==typeof window)return{};const e={};e.title=document.title,document.querySelectorAll("meta").forEach(t=>{const n=t.getAttribute("name"),r=t.getAttribute("property"),o=t.getAttribute("content");if(o){if(n)switch(n){case"description":e.description=o;break;case"keywords":e.keywords=o.split(",").map(e=>e.trim());break;case"author":e.author=o}if(r){if(r.startsWith("og:")){const t=r.replace("og:","og_");e[t]=o}if(r.startsWith("twitter:")){const t=r.replace("twitter:","twitter_");e[t]=o}}}});try{const t=document.querySelectorAll('script[type="application/ld+json"]');if(t.length>0){const n=[];t.forEach(e=>{try{const t=JSON.parse(e.textContent||"");n.push(t)}catch{}}),n.length>0&&(e.structuredData=n)}}catch{}return e}();s(e)},100);return()=>clearTimeout(e)},[r,t]),t&&Object.keys(o).length>0?o:void 0}(i),I=function(t){const{apiKey:n,apiBaseUrl:r,pageContext:o,userContext:s}=t,i=e.useRef(t);e.useEffect(()=>{i.current=t},[t]);const a=e.useRef(null),[c,u]=e.useState(!1),[d,l]=e.useState(!1),f=e.useRef(function(){try{const e=localStorage.getItem(bs);if(e)return e;const t=ws();return localStorage.setItem(bs,t),t}catch{return p.warn("localStorage not available, using session-only device ID"),ws()}}()),m=e.useRef(o);e.useEffect(()=>{m.current=o},[o]);const g=e.useCallback(e=>{const t=_s.safeParse(e),n=t.success&&t.data.id?t.data.id:`msg-${Math.random().toString(36).slice(2,11)}`,r=t.success&&t.data.sender?t.data.sender:"bot",o=t.success&&t.data.timestamp?new Date(t.data.timestamp):/* @__PURE__ */new Date,s=t.success?t.data:{type:"text"};switch(s.type){case"image":return{id:n,type:"image",sender:r,timestamp:o,imageUrl:s.imageUrl||s.content||"",altText:"Imagen enviada"};case"audio":return{id:n,type:"audio",sender:r,timestamp:o,content:s.audioUrl||s.content||""};case"location":return{id:n,type:"location",sender:r,timestamp:o,latitude:Number(s.latitude||0),longitude:Number(s.longitude||0),name:s.content||"Ubicación compartida"};case"system":return{id:n,type:"system",sender:"system",timestamp:o,content:String(s.content||"")};default:return{id:n,type:"text",sender:r,timestamp:o,content:String(s.content||"Sin contenido"),emotion:s.emotion}}},[]),y=e.useCallback(()=>{if(!n||!r)return;if(a.current?.connected)return;u(!0);const e=_(`${r}/webchat`,{auth:{apiKey:n,deviceId:f.current,token:s?.token,metadata:s?.metadata},transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:5,reconnectionDelay:1e3,extraHeaders:{"bypass-tunnel-reminder":"true","X-Tunnel-Skip-Anti-Phishing-Page":"true"}});e.on("connect",()=>{u(!1),l(!0),i.current.onConnected(`temp-${Date.now()}`,void 0)}),e.on("disconnect",e=>{u(!1),l(!1),i.current.onDisconnected()}),e.on("connect_error",e=>{u(!1),i.current.onError(`Error de conexión: ${e.message}`)}),e.on("connection_ack",e=>{i.current.onConnected(e.sessionId,e.config)}),e.on("bot_message",e=>{try{i.current.onMessage(g(e))}catch(t){p.error("ChatSocket Error processing bot_message:",t)}}),e.on("chat_history",e=>{e.messages&&Array.isArray(e.messages)&&e.messages.forEach(e=>{try{i.current.onMessage(g(e))}catch(t){p.debug("Error processing history message:",t)}}),i.current.onEvent&&i.current.onEvent("history_loaded",e)}),e.on("bot_typing",e=>i.current.onTyping(e)),e.on("auth_success",e=>{i.current.onLogin&&i.current.onLogin(e),e.theme&&i.current.onThemeUpdate&&i.current.onThemeUpdate(e.theme)}),a.current=e},[n,r]),v=e.useCallback(()=>{a.current&&(a.current.disconnect(),a.current=null,l(!1))},[]),b=e.useRef(y);b.current=y,e.useEffect(()=>(b.current(),()=>{a.current&&(a.current.disconnect(),a.current=null)}),[]);const w=e.useRef([]),k=e.useRef([]),z=e.useCallback(()=>`msg_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,[]),x=e.useCallback(()=>{if(a.current?.connected)for(;w.current.length>0;){const e=w.current.shift();a.current.emit("user_message",e)}},[]);e.useEffect(()=>{d&&x()},[d,x]),e.useEffect(()=>{if(!d)return;const e=setInterval(()=>{const e=Date.now();k.current=k.current.filter(t=>e<t.nextRetryAt||(t.attempts>=t.maxAttempts?(i.current.onEvent?.("message_failed",{id:t.id,payload:t.payload}),p.error("Message failed after max retries:",t.id),!1):!a.current?.connected||(a.current.emit("user_message",t.payload,e=>{e?.success&&i.current.onEvent?.("message_sent",{id:t.id})}),t.attempts++,t.nextRetryAt=e+1e3*Math.pow(2,t.attempts),t.attempts<t.maxAttempts)))},500);return()=>clearInterval(e)},[d]);const E=e.useCallback((e,t="text")=>{const n=z(),r={...m.current,currentUrl:"undefined"!=typeof window?window.location.href:void 0,sentAt:/* @__PURE__ */(new Date).toISOString(),deviceId:f.current},o={id:n,content:e.trim(),type:t,metadata:r};return a.current?.connected?(a.current.emit("user_message",o,e=>{!1!==e?.success&&e?i.current.onEvent?.("message_sent",{id:n}):(k.current.push({id:n,payload:o,attempts:0,maxAttempts:3,nextRetryAt:Date.now()+1e3}),i.current.onEvent?.("message_retry_queued",{id:n}))}),n):(w.current.push(o),i.current.onEvent?.("queued_message",{id:n,payload:o}),n)},[z]),S=e.useMemo(()=>h(e=>{a.current?.emit("typing",e)},250),[]);return{isConnected:d,isConnecting:c,sendMessage:E,sendTyping:S,requestHistory:e.useCallback(()=>{a.current?.emit("request_history")},[]),reconnect:y,disconnect:v}}({apiKey:n,apiBaseUrl:r,pageContext:e.useMemo(()=>C?{...s||{},seo:{...C||{}}}:s,[s,C]),userContext:u,onMessage:e.useCallback(e=>{const t=Date.now(),n=w.current>0?t-w.current:void 0;w.current=t,O.addMessage(e),z.trackMessageReceived(e.type,n),S.isOpen||"bot"!==e.sender||(b(e=>e+1),x.notifyWithSound(e))},[O,S.isOpen,z,x]),onConnected:e.useCallback((e,t)=>{O.setConnected(!0),O.setSessionId(e),z.trackConnectionStatus(!0),t&&f&&f("backend_config",t)},[O,f,z]),onDisconnected:e.useCallback(()=>{O.setConnected(!1),z.trackConnectionStatus(!1)},[O,z]),onTyping:e.useCallback(e=>O.setTyping(e),[O]),onError:e.useCallback(e=>{O.setError(e),z.trackError(e)},[O,z]),onLogin:d,onNavigate:l,onEvent:f,onThemeUpdate:y}),$=e.useCallback(()=>{p.debug("ChatWidget handleToggle called, current isOpen:",S.isOpen),S.isOpen?(O.closeWindow(),z.trackClose(),g?.(!1),p.debug("ChatWidget Closing window")):(O.openWindow(),b(0),z.trackOpen(),g?.(!0),p.debug("ChatWidget Opening window"))},[S.isOpen,O,g,z]),N=e.useCallback(e=>{if(!E.isAllowed()){const e=E.getTimeUntilReset(),t=Math.ceil(e/1e3);return void O.setError(k("rate_limit_exceeded")+` Espera ${t}s.`)}const t={id:`temp-${Date.now()}-${Math.random()}`,type:"text",sender:"user",timestamp:/* @__PURE__ */new Date,content:e};O.addMessage(t),z.trackMessageSent("text"),I.sendMessage(e,"text")},[O,I,E,z,k]),T=e.useCallback(async(e,t)=>{let n;n="audio"===t?{id:`temp-${Date.now()}-${Math.random()}`,type:"audio",sender:"user",timestamp:/* @__PURE__ */new Date,content:URL.createObjectURL(e)}:"image"===t?{id:`temp-${Date.now()}-${Math.random()}`,type:"image",sender:"user",timestamp:/* @__PURE__ */new Date,imageUrl:URL.createObjectURL(e)}:{id:`temp-${Date.now()}-${Math.random()}`,type:"text",sender:"user",timestamp:/* @__PURE__ */new Date,content:`📎 ${e.name}`},O.addMessage(n);const r=await $s(e);I.sendMessage(r,t)},[O,I]),j=e.useCallback(e=>{const t={id:`temp-${Date.now()}-${Math.random()}`,type:"location",sender:"user",timestamp:/* @__PURE__ */new Date,latitude:e.latitude,longitude:e.longitude,name:"Mi ubicación"};O.addMessage(t),I.sendMessage(JSON.stringify(e),"location")},[O,I]);e.useEffect(()=>{const e=()=>{S.isOpen||O.openWindow()},t=()=>{S.isOpen&&O.closeWindow()},n=()=>{S.isOpen?O.closeWindow():O.openWindow()},r=e=>{e.detail?.message&&N(e.detail.message)};return window.addEventListener("botuyo-chat:open",e),window.addEventListener("botuyo-chat:close",t),window.addEventListener("botuyo-chat:toggle",n),window.addEventListener("botuyo-chat:send-message",r),()=>{window.removeEventListener("botuyo-chat:open",e),window.removeEventListener("botuyo-chat:close",t),window.removeEventListener("botuyo-chat:toggle",n),window.removeEventListener("botuyo-chat:send-message",r)}},[S.isOpen,O,N]),e.useEffect(()=>(Es(N),()=>Es(null)),[N]);const A=e.useCallback(()=>{O.clearMessages(),p.info("Chat history cleared")},[O]);e.useEffect(()=>(Ss(A),()=>Ss(null)),[A]);const M=e.useMemo(()=>{if(S.isTyping)return"thinking";const e=[...S.messages].reverse().find(e=>"bot"===e.sender&&"text"===e.type);return"text"===e?.type&&e.emotion?e.emotion:"default"},[S.isTyping,S.messages]);return{state:S,actions:O,unreadCount:v,currentBotEmotion:M,isConnected:I.isConnected,handleToggle:$,handleSendText:N,handleSendAttachment:T,handleSendLocation:j}}function Ts(n){const{apiKey:r,apiBaseUrl:o,pageContext:s,includeSEOMetadata:i=!1,theme:a,mediaConfig:c,userContext:d,onLogin:l,onNavigate:p,onEvent:h,onStateChange:m,onVoiceCall:g}=n,w=e.useRef(null),_=y();!function(t){const[n,r]=e.useState(!1);e.useEffect(()=>{let e=null;const n=()=>{if(!t.current)return;const e=!!t.current.parentElement?.closest(".dark"),n=!!document.getElementById("botuyo-chat-widget-root")?.classList.contains("dark"),o=document.getElementById("botuyo-chat-widget-root"),s=!!o?.parentElement?.closest(".dark"),i=document.documentElement.classList.contains("dark"),a=document.body.classList.contains("dark"),c=window.matchMedia("(prefers-color-scheme: dark)").matches,u=e||n||s||i||a||c;t.current&&(u?t.current.classList.add("dark"):t.current.classList.remove("dark")),r(u)};n();const o=window.matchMedia("(prefers-color-scheme: dark)"),s=()=>n();o.addEventListener("change",s);const i=new MutationObserver(()=>{n()}),a=document.getElementById("botuyo-chat-widget-root");a&&(i.observe(a,{attributes:!0,attributeFilter:["class"]}),a.parentElement&&(i.observe(a.parentElement,{attributes:!0,attributeFilter:["class"],childList:!0}),e=a.parentElement)),i.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),i.observe(document.body,{attributes:!0,attributeFilter:["class"]});let c=t.current?.parentElement;for(;c;)i.observe(c,{attributes:!0,attributeFilter:["class"]}),c=c.parentElement;const u=setInterval(()=>{const t=document.getElementById("botuyo-chat-widget-root");t&&t.parentElement!==e&&(e&&t.parentElement&&(i.observe(t.parentElement,{attributes:!0,attributeFilter:["class"],childList:!0}),e=t.parentElement),n())},100);return()=>{i.disconnect(),o.removeEventListener("change",s),clearInterval(u)}},[t])}(w);const[O,C]=e.useState(),{mergedTheme:I,mergedStyles:$,getContainerStyle:N}=function(t,n){const r=function(){const[t,n]=e.useState(()=>"undefined"!=typeof window&&(window.matchMedia("(prefers-contrast: high)").matches||window.matchMedia("(prefers-contrast: more)").matches));return e.useEffect(()=>{const e=window.matchMedia("(prefers-contrast: high)"),t=window.matchMedia("(prefers-contrast: more)"),r=e=>{n(e.matches)};return e.addEventListener("change",r),t.addEventListener("change",r),()=>{e.removeEventListener("change",r),t.removeEventListener("change",r)}},[]),t}(),o=e.useMemo(()=>{const e=f(t,n);return r?{...e,primaryColor:"#000000",cssVariables:{...e.cssVariables,background:"#FFFFFF",foreground:"#000000",card:"#FFFFFF",cardForeground:"#000000",primary:"#000000",primaryForeground:"#FFFFFF",muted:"#F5F5F5",mutedForeground:"#000000",border:"#000000"}}:e},[t,n,r]),s=e.useMemo(()=>({radius:{...x,...t?.bubbleStyles?.radius},bot:{...E,...t?.bubbleStyles?.bot},user:{...S,...t?.bubbleStyles?.user},launcher:{...t?.bubbleStyles?.launcher},mapCard:{...t?.bubbleStyles?.mapCard}}),[t?.bubbleStyles]);return{mergedTheme:o,mergedStyles:s,getContainerStyle:(e,t,n)=>({"--chat-primary":o.primaryColor,zIndex:e?2147483647:9999,position:"fixed",top:t&&e?0:"auto",left:t&&e?0:"bottom-left"===n?"24px":"auto",right:t&&e?0:"bottom-right"!==n&&n?"auto":"24px",bottom:t&&e?0:"100px",width:t&&e?"100%":"auto",height:t&&e?"100%":"auto"})}}(a,O),{state:T,actions:j,unreadCount:A,currentBotEmotion:M,isConnected:P,handleToggle:Z,handleSendText:F,handleSendAttachment:D,handleSendLocation:R}=Ns({apiKey:r,apiBaseUrl:o,pageContext:s,includeSEOMetadata:i,theme:a,userContext:d,onLogin:l,onNavigate:p,onEvent:h,onStateChange:m,onThemeUpdate:C}),L=e.useCallback(e=>{e.stopPropagation()},[]),U=N(T.isOpen,_,a?.position),W=e.useMemo(()=>{if(!I.cssVariables)return{};const e={},t=I.cssVariables;return t.background&&(e["--background"]=t.background),t.foreground&&(e["--foreground"]=t.foreground),t.card&&(e["--card"]=t.card),t.cardForeground&&(e["--card-foreground"]=t.cardForeground),t.primary&&(e["--primary"]=t.primary),t.primaryForeground&&(e["--primary-foreground"]=t.primaryForeground),t.muted&&(e["--muted"]=t.muted),t.mutedForeground&&(e["--muted-foreground"]=t.mutedForeground),t.border&&(e["--border"]=t.border),t.destructive&&(e["--destructive"]=t.destructive),t.radius&&(e["--radius"]=t.radius),t.spacing1&&(e["--spacing-1"]=t.spacing1),t.spacing2&&(e["--spacing-2"]=t.spacing2),t.spacing3&&(e["--spacing-3"]=t.spacing3),t.spacing4&&(e["--spacing-4"]=t.spacing4),t.spacing5&&(e["--spacing-5"]=t.spacing5),t.spacing6&&(e["--spacing-6"]=t.spacing6),t.spacing8&&(e["--spacing-8"]=t.spacing8),e},[I.cssVariables]);/* @__PURE__ */
|
|
32
|
+
return t.jsx(v,{animations:a?.animations,effects:a?.effects,children:/* @__PURE__ */t.jsxs("div",{ref:w,id:"botuyo-chat-widget",className:u("botuyo-chat-widget flex flex-col",!_&&("bottom-left"===a?.position?"items-start":"items-end")),style:{...U,...W,pointerEvents:"auto",backgroundColor:"transparent"},"data-animations-disabled":!1===a?.animations?.enabled?"true":void 0,"data-effects-glassmorphism":!1===a?.effects?.glassmorphism?"false":void 0,"data-effects-shadows":!1===a?.effects?.softShadows?"false":void 0,children:[
|
|
33
|
+
/* @__PURE__ */t.jsx("div",{className:u("transition-all duration-400 ease-[cubic-bezier(0.34,1.56,0.64,1)]",_?"bottom-left"===a?.position?"origin-bottom-left":"origin-bottom-right":"origin-bottom",T.isOpen?"opacity-100 scale-100 h-full w-full translate-y-0 pointer-events-auto":"opacity-0 scale-[0.85] pointer-events-none translate-y-8 h-0 w-0"),style:{pointerEvents:T.isOpen?"auto":"none"},onMouseDown:L,onTouchStart:L,children:/* @__PURE__ */t.jsx(z,{children:/* @__PURE__ */t.jsx(b,{isOpen:T.isOpen,isConnected:P,isTyping:T.isTyping,messages:T.messages,onClose:()=>j.closeWindow(),onSendMessage:F,onSendAttachment:D,onSendLocation:R,botName:a?.botName,logoUrl:a?.logoUrl,welcomeMessage:a?.welcomeMessage,inputPlaceholder:a?.inputPlaceholder,primaryColor:a?.primaryColor,position:a?.position,bubbleStyles:$,avatars:a?.avatars,mediaConfig:c,theme:I,onVoiceCall:g})})}),
|
|
34
|
+
/* @__PURE__ */t.jsx("div",{className:u(T.isOpen?"hidden":"block",!_&&"mt-4"),style:{pointerEvents:"auto"},onMouseDown:L,onTouchStart:L,children:/* @__PURE__ */t.jsx(k,{isOpen:T.isOpen,onClick:Z,unreadCount:A,position:a?.position||"bottom-right",primaryColor:a?.primaryColor,logoUrl:a?.logoUrl,starterPrompt:a?.starterPrompt,avatars:a?.avatars,emotion:M,styles:$,promptPersistence:a?.promptPersistence,avatarScale:a?.avatarScale})})]})})}const js=/* @__PURE__ */Object.freeze(/* @__PURE__ */Object.defineProperty({__proto__:null,ChatWidget:Ts},Symbol.toStringTag,{value:"Module"})),As=e.lazy(()=>Promise.resolve().then(()=>js).then(e=>({default:e.ChatWidget})));class Ms{root=null;container=null;config=null;init(e){return this.config=e,this.render(),this}render(){if(!this.config)return void console.error("[BotUyoChat] No configuration provided");if(this.container||(this.container=document.createElement("div"),this.container.id="botuyo-chat-widget-root",this.container.style.position="fixed",this.container.style.zIndex="999999",document.body.appendChild(this.container)),this.config.theme?.cssVariables){const e=this.config.theme.cssVariables,t={background:e.background,foreground:e.foreground,card:e.card,cardForeground:e.cardForeground,primary:e.primary,primaryForeground:e.primaryForeground,muted:e.muted,mutedForeground:e.mutedForeground,border:e.border,destructive:e.destructive,radius:e.radius,spacing1:e.spacing1,spacing2:e.spacing2,spacing3:e.spacing3,spacing4:e.spacing4,spacing5:e.spacing5,spacing6:e.spacing6,spacing8:e.spacing8};Object.entries(t).forEach(([e,t])=>{void 0!==t&&this.container.style.setProperty(`--${e}`,t)})}this.root||(this.root=n.createRoot(this.container));const t={apiKey:this.config.apiKey,apiBaseUrl:this.config.apiBaseUrl,theme:{primaryColor:"#10b981",botName:"Asistente Virtual",position:"bottom-right",welcomeMessage:"¡Hola! 👋 ¿En qué puedo ayudarte?",inputPlaceholder:"Escribe tu mensaje...",borderRadius:"0.75rem",launcherBorderRadius:"50%",...this.config.theme},userContext:this.config.userContext,pageContext:this.config.pageContext,includeSEOMetadata:this.config.includeSEOMetadata??!1,mediaConfig:this.config.mediaConfig,onNavigate:this.config.onNavigate,onLogin:this.config.onLogin,onEvent:this.config.onEvent,onStateChange:this.config.onStateChange,onVoiceCall:this.config.onVoiceCall},o=r.createElement(e.Suspense,{fallback:r.createElement("div",{style:{position:"fixed",bottom:"24px",right:"24px",width:"60px",height:"60px",borderRadius:"50%",backgroundColor:t.theme?.primaryColor||"#10b981",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",cursor:"wait"}},r.createElement("div",{style:{width:"24px",height:"24px",border:"3px solid rgba(255, 255, 255, 0.3)",borderTopColor:"#fff",borderRadius:"50%",animation:"spin 1s linear infinite"}}))},r.createElement(As,t));this.root.render(r.createElement(g,{defaultLocale:this.config.theme?.defaultLocale,children:o})),console.log("[BotUyoChat] Widget initialized",t)}update(e){this.config?(this.config={...this.config,...e,theme:{...this.config.theme,...e.theme}},this.render()):console.error("[BotUyoChat] Widget not initialized")}destroy(){this.root&&(this.root.unmount(),this.root=null),this.container&&this.container.parentNode&&(this.container.parentNode.removeChild(this.container),this.container=null),this.config=null,console.log("[BotUyoChat] Widget destroyed")}open(){window.dispatchEvent(new CustomEvent("botuyo-chat:open"))}close(){window.dispatchEvent(new CustomEvent("botuyo-chat:close"))}sendMessage(e){window.dispatchEvent(new CustomEvent("botuyo-chat:send-message",{detail:{message:e}}))}getState(){return null}}const Ps=new Ms;window.BotUyoChat=Ps;export{Ms as BotUyoChatWidget,Ts as ChatWidget,Cs as ChatWidgetProvider,g as LanguageProvider,Ps as default,Is as useChatWidget,w as useLanguage};
|
|
2
35
|
//# sourceMappingURL=botuyo-chat.es.js.map
|