@liforma/client 0.4.0 → 0.4.2

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.
Files changed (121) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/next/index.js +1101 -4239
  3. package/dist/next/index.js.map +1 -1
  4. package/dist/next/next/createLiformaSessionRouteHandler.d.ts +3 -2
  5. package/dist/next/next/createLiformaSessionRouteHandler.d.ts.map +1 -1
  6. package/dist/next/react/ExperienceThumbnail.d.ts +1 -0
  7. package/dist/next/react/ExperienceThumbnail.d.ts.map +1 -1
  8. package/dist/next/thumbnail/styles.d.ts.map +1 -1
  9. package/dist/next/thumbnail/toGalleryThumbUrl.d.ts.map +1 -1
  10. package/dist/next/thumbnail/types.d.ts +2 -0
  11. package/dist/next/thumbnail/types.d.ts.map +1 -1
  12. package/dist/next/v2/api/mintPublicSession.d.ts +23 -17
  13. package/dist/next/v2/api/mintPublicSession.d.ts.map +1 -1
  14. package/dist/next/v2/api/sessionEndpointRequest.d.ts +10 -5
  15. package/dist/next/v2/api/sessionEndpointRequest.d.ts.map +1 -1
  16. package/dist/next/v2/embed/iframeHost.d.ts +8 -2
  17. package/dist/next/v2/embed/iframeHost.d.ts.map +1 -1
  18. package/dist/next/v2/embed/protocol.d.ts +20 -0
  19. package/dist/next/v2/embed/protocol.d.ts.map +1 -1
  20. package/dist/next/v2/errors/LiformaError.d.ts +23 -0
  21. package/dist/next/v2/errors/LiformaError.d.ts.map +1 -0
  22. package/dist/next/v2/experience.d.ts +59 -53
  23. package/dist/next/v2/experience.d.ts.map +1 -1
  24. package/dist/next/v2/experienceEvents.d.ts +22 -13
  25. package/dist/next/v2/experienceEvents.d.ts.map +1 -1
  26. package/dist/next/v2/types/sessionLaunch.d.ts +66 -0
  27. package/dist/next/v2/types/sessionLaunch.d.ts.map +1 -0
  28. package/dist/next/v2/types/sessionManifest.d.ts +8 -0
  29. package/dist/next/v2/types/sessionManifest.d.ts.map +1 -1
  30. package/dist/next/widget/mountExperienceWidget.d.ts.map +1 -1
  31. package/dist/next/widget/types.d.ts +6 -1
  32. package/dist/next/widget/types.d.ts.map +1 -1
  33. package/dist/npm/index.js +951 -4090
  34. package/dist/npm/index.js.map +1 -1
  35. package/dist/npm/thumbnail/styles.d.ts.map +1 -1
  36. package/dist/npm/thumbnail/toGalleryThumbUrl.d.ts.map +1 -1
  37. package/dist/npm/thumbnail/types.d.ts +2 -0
  38. package/dist/npm/thumbnail/types.d.ts.map +1 -1
  39. package/dist/npm/v2/api/mintPublicSession.d.ts +23 -17
  40. package/dist/npm/v2/api/mintPublicSession.d.ts.map +1 -1
  41. package/dist/npm/v2/api/sessionEndpointRequest.d.ts +10 -5
  42. package/dist/npm/v2/api/sessionEndpointRequest.d.ts.map +1 -1
  43. package/dist/npm/v2/embed/iframeHost.d.ts +8 -2
  44. package/dist/npm/v2/embed/iframeHost.d.ts.map +1 -1
  45. package/dist/npm/v2/embed/protocol.d.ts +20 -0
  46. package/dist/npm/v2/embed/protocol.d.ts.map +1 -1
  47. package/dist/npm/v2/errors/LiformaError.d.ts +23 -0
  48. package/dist/npm/v2/errors/LiformaError.d.ts.map +1 -0
  49. package/dist/npm/v2/experience.d.ts +59 -53
  50. package/dist/npm/v2/experience.d.ts.map +1 -1
  51. package/dist/npm/v2/experienceEvents.d.ts +22 -13
  52. package/dist/npm/v2/experienceEvents.d.ts.map +1 -1
  53. package/dist/npm/v2/index.d.ts +4 -1
  54. package/dist/npm/v2/index.d.ts.map +1 -1
  55. package/dist/npm/v2/liforma-experience-thumbnail.d.ts.map +1 -1
  56. package/dist/npm/v2/liforma-experience-widget.d.ts.map +1 -1
  57. package/dist/npm/v2/liforma-experience.d.ts.map +1 -1
  58. package/dist/npm/v2/npm.d.ts +5 -2
  59. package/dist/npm/v2/npm.d.ts.map +1 -1
  60. package/dist/npm/v2/types/index.d.ts +2 -0
  61. package/dist/npm/v2/types/index.d.ts.map +1 -1
  62. package/dist/npm/v2/types/sessionLaunch.d.ts +66 -0
  63. package/dist/npm/v2/types/sessionLaunch.d.ts.map +1 -0
  64. package/dist/npm/v2/types/sessionManifest.d.ts +8 -0
  65. package/dist/npm/v2/types/sessionManifest.d.ts.map +1 -1
  66. package/dist/npm/v2/types/sessionManifestSchema.d.ts +7 -0
  67. package/dist/npm/v2/types/sessionManifestSchema.d.ts.map +1 -1
  68. package/dist/npm/widget/mountExperienceWidget.d.ts.map +1 -1
  69. package/dist/npm/widget/types.d.ts +6 -1
  70. package/dist/npm/widget/types.d.ts.map +1 -1
  71. package/dist/react/component/experienceComponentLaunch.d.ts +1 -0
  72. package/dist/react/component/experienceComponentLaunch.d.ts.map +1 -1
  73. package/dist/react/component/experienceComponentRuntime.d.ts +10 -2
  74. package/dist/react/component/experienceComponentRuntime.d.ts.map +1 -1
  75. package/dist/react/component/experienceComponentTypes.d.ts +24 -13
  76. package/dist/react/component/experienceComponentTypes.d.ts.map +1 -1
  77. package/dist/react/index.js +1251 -4378
  78. package/dist/react/index.js.map +1 -1
  79. package/dist/react/react/Experience.d.ts.map +1 -1
  80. package/dist/react/react/ExperienceThumbnail.d.ts +1 -0
  81. package/dist/react/react/ExperienceThumbnail.d.ts.map +1 -1
  82. package/dist/react/thumbnail/styles.d.ts.map +1 -1
  83. package/dist/react/thumbnail/toGalleryThumbUrl.d.ts.map +1 -1
  84. package/dist/react/thumbnail/types.d.ts +2 -0
  85. package/dist/react/thumbnail/types.d.ts.map +1 -1
  86. package/dist/react/v2/api/mintPublicSession.d.ts +23 -17
  87. package/dist/react/v2/api/mintPublicSession.d.ts.map +1 -1
  88. package/dist/react/v2/api/sessionEndpointRequest.d.ts +10 -5
  89. package/dist/react/v2/api/sessionEndpointRequest.d.ts.map +1 -1
  90. package/dist/react/v2/embed/iframeHost.d.ts +8 -2
  91. package/dist/react/v2/embed/iframeHost.d.ts.map +1 -1
  92. package/dist/react/v2/embed/protocol.d.ts +20 -0
  93. package/dist/react/v2/embed/protocol.d.ts.map +1 -1
  94. package/dist/react/v2/errors/LiformaError.d.ts +23 -0
  95. package/dist/react/v2/errors/LiformaError.d.ts.map +1 -0
  96. package/dist/react/v2/experience.d.ts +59 -53
  97. package/dist/react/v2/experience.d.ts.map +1 -1
  98. package/dist/react/v2/experienceEvents.d.ts +22 -13
  99. package/dist/react/v2/experienceEvents.d.ts.map +1 -1
  100. package/dist/react/v2/types/sessionLaunch.d.ts +66 -0
  101. package/dist/react/v2/types/sessionLaunch.d.ts.map +1 -0
  102. package/dist/react/v2/types/sessionManifest.d.ts +8 -0
  103. package/dist/react/v2/types/sessionManifest.d.ts.map +1 -1
  104. package/dist/react/widget/mountExperienceWidget.d.ts.map +1 -1
  105. package/dist/react/widget/types.d.ts +6 -1
  106. package/dist/react/widget/types.d.ts.map +1 -1
  107. package/dist/sdk/v2/client.js +36 -76
  108. package/dist/sdk/v2/client.js.map +1 -1
  109. package/dist/svelte/Experience.svelte +54 -44
  110. package/dist/svelte/Experience.svelte.d.ts +2 -1
  111. package/dist/svelte/ExperienceThumbnail.svelte +8 -1
  112. package/dist/svelte/ExperienceThumbnail.svelte.d.ts +1 -0
  113. package/package.json +3 -1
  114. package/dist/next/v2/speechOnlyManifest.d.ts +0 -7
  115. package/dist/next/v2/speechOnlyManifest.d.ts.map +0 -1
  116. package/dist/next/v2/types/sessionManifestSchema.d.ts +0 -183
  117. package/dist/next/v2/types/sessionManifestSchema.d.ts.map +0 -1
  118. package/dist/react/v2/speechOnlyManifest.d.ts +0 -7
  119. package/dist/react/v2/speechOnlyManifest.d.ts.map +0 -1
  120. package/dist/react/v2/types/sessionManifestSchema.d.ts +0 -183
  121. package/dist/react/v2/types/sessionManifestSchema.d.ts.map +0 -1
@@ -1,67 +1,4 @@
1
- var Liforma=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(){if(globalThis.__LIFORMA_STACK===`local`)return!0;if(typeof location>`u`)return!1;try{return new URLSearchParams(location.search).get(`stack`)===`local`}catch{return!1}}var n=`https://api.liforma.ai`,r=`http://localhost:3001`;function i(){let e=globalThis.__LIFORMA_API_BASE_URL;if(e?.trim())return e.trim().replace(/\/$/,``);if(typeof document>`u`)return null;let t=(document.querySelector(`script[data-liforma-sdk][src*="client.js"]`)??document.querySelector(`script[src*="/sdk/v2/client.js"]`))?.getAttribute(`data-api-base-url`)?.trim();return t?t.replace(/\/$/,``):null}function a(){return i()||(t()?r:n)}function o(e,t){let n=e.trim();if(!n)throw Error(`sessionEndpoint must not be empty.`);if(typeof location>`u`)throw Error(`sessionEndpoint is only available in a browser.`);let r=new URL(n,location.href);if(r.origin!==location.origin)throw Error(`sessionEndpoint must be same-origin.`);let i=t.experienceId.trim();if(!i)throw Error(`sessionEndpoint requires experienceId.`);return{url:r.toString(),init:{method:`POST`,credentials:`same-origin`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({experienceId:i,...t.language?{language:t.language}:{},...t.mode?{mode:t.mode}:{},...t.responseMode?{responseMode:t.responseMode}:{},...t.speechInputMode?{speechInputMode:t.speechInputMode}:{},...t.startButton?{startButton:t.startButton}:{},...t.speechOnly===void 0?{}:{speechOnly:t.speechOnly}})}}}var s;function c(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var l=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},u=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(s=globalThis).__zod_globalConfig??(s.__zod_globalConfig={});var d=globalThis.__zod_globalConfig;function f(e){return e&&Object.assign(d,e),d}function p(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function m(e,t){return typeof t==`bigint`?t.toString():t}function h(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}throw Error(`cached value already set`)}}}function g(e){return e==null}function _(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function ee(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}var v=Symbol(`evaluating`);function y(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==v)return r===void 0&&(r=v,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function b(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function x(...e){let t={};for(let n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function te(e){return JSON.stringify(e)}function S(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var C=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var T=h(()=>{if(d.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function E(e){if(w(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(w(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function ne(e){return E(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var re=new Set([`string`,`number`,`symbol`]);function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function O(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function k(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function A(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var ie={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function j(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return O(e,x(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return b(this,`shape`,e),e},checks:[]}))}function ae(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return O(e,x(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return b(this,`shape`,r),r},checks:[]}))}function oe(e,t){if(!E(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return O(e,x(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return b(this,`shape`,n),n}}))}function M(e,t){if(!E(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return O(e,x(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return b(this,`shape`,n),n}}))}function se(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return O(e,x(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return b(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function ce(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return O(t,x(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return b(this,`shape`,i),i},checks:[]}))}function le(e,t,n){return O(t,x(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return b(this,`shape`,i),i}}))}function N(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function ue(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function P(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function de(e){return typeof e==`string`?e:e?.message}function F(e,t,n){let r=e.message?e.message:de(e.inst?._zod.def?.error?.(e))??de(t?.error?.(e))??de(n.customError?.(e))??de(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function fe(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function pe(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var me=(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,m,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},I=c(`$ZodError`,me),he=c(`$ZodError`,me,{Parent:Error});function ge(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function _e(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}var ve=e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new l;if(o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>F(e,a,f())));throw C(t,i?.callee),t}return o.value},L=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>F(e,a,f())));throw C(t,i?.callee),t}return o.value},ye=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new l;return a.issues.length?{success:!1,error:new(e??I)(a.issues.map(e=>F(e,i,f())))}:{success:!0,data:a.value}},be=ye(he),xe=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>F(e,i,f())))}:{success:!0,data:a.value}},Se=xe(he),Ce=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ve(e)(t,n,i)},R=e=>(t,n,r)=>ve(e)(t,n,r),we=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return L(e)(t,n,i)},Te=e=>async(t,n,r)=>L(e)(t,n,r),Ee=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return ye(e)(t,n,i)},De=e=>(t,n,r)=>ye(e)(t,n,r),Oe=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return xe(e)(t,n,i)},ke=e=>async(t,n,r)=>xe(e)(t,n,r),Ae=/^[cC][0-9a-z]{6,}$/,je=/^[0-9a-z]+$/,Me=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Ne=/^[0-9a-vA-V]{20}$/,Pe=/^[A-Za-z0-9]{27}$/,Fe=/^[a-zA-Z0-9_-]{21}$/,Ie=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Le=/^([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})$/,Re=e=>e?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)$/,ze=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Be=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function Ve(){return new RegExp(Be,`u`)}var He=/^(?:(?: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])$/,Ue=/^(([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}|:))$/,We=/^((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])$/,Ge=/^(([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])$/,Ke=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,qe=/^[A-Za-z0-9_-]*$/,Je=/^https?$/,Ye=/^\+[1-9]\d{6,14}$/,Xe=`(?:(?:\\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])))`,Ze=RegExp(`^${Xe}$`);function Qe(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function $e(e){return RegExp(`^${Qe(e)}$`)}function et(e){let t=Qe({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Xe}T(?:${r})$`)}var tt=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},nt=/^-?\d+$/,rt=/^-?\d+(?:\.\d+)?$/,it=/^(?:true|false)$/i,at=/^[^A-Z]*$/,ot=/^[^a-z]*$/,z=c(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),st={number:`number`,bigint:`bigint`,object:`date`},ct=c(`$ZodCheckLessThan`,(e,t)=>{z.init(e,t);let n=st[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;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:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),lt=c(`$ZodCheckGreaterThan`,(e,t)=>{z.init(e,t);let n=st[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;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:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),ut=c(`$ZodCheckMultipleOf`,(e,t)=>{z.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 Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):ee(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),dt=c(`$ZodCheckNumberFormat`,(e,t)=>{z.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=ie[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=nt)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),ft=c(`$ZodCheckMaxLength`,(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!g(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=fe(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),pt=c(`$ZodCheckMinLength`,(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!g(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=fe(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),mt=c(`$ZodCheckLengthEquals`,(e,t)=>{var n;z.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!g(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=fe(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),ht=c(`$ZodCheckStringFormat`,(e,t)=>{var n,r;z.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=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=()=>{})}),gt=c(`$ZodCheckRegex`,(e,t)=>{ht.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})}}),_t=c(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=at,ht.init(e,t)}),vt=c(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=ot,ht.init(e,t)}),yt=c(`$ZodCheckIncludes`,(e,t)=>{z.init(e,t);let n=D(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=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})}}),bt=c(`$ZodCheckStartsWith`,(e,t)=>{z.init(e,t);let n=RegExp(`^${D(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=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})}}),xt=c(`$ZodCheckEndsWith`,(e,t)=>{z.init(e,t);let n=RegExp(`.*${D(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=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})}}),St=c(`$ZodCheckOverwrite`,(e,t)=>{z.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),Ct=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
2
- `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
3
- `))}},wt={major:4,minor:4,patch:3},B=c(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=wt;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=N(e),i;for(let a of t){if(a._zod.def.when){if(ue(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new l;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=N(e,t))});else{if(e.issues.length===t)continue;r||=N(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(N(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new l;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new l;return o.then(e=>t(e,r,a))}return t(o,r,a)}}y(e,`~standard`,()=>({validate:t=>{try{let n=be(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Se(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),Tt=c(`$ZodString`,(e,t)=>{B.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??tt(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),V=c(`$ZodStringFormat`,(e,t)=>{ht.init(e,t),Tt.init(e,t)}),Et=c(`$ZodGUID`,(e,t)=>{t.pattern??=Le,V.init(e,t)}),Dt=c(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Re(e)}else t.pattern??=Re();V.init(e,t)}),Ot=c(`$ZodEmail`,(e,t)=>{t.pattern??=ze,V.init(e,t)}),kt=c(`$ZodURL`,(e,t)=>{V.init(e,t),e._zod.check=n=>{try{let r=n.value.trim();if(!t.normalize&&t.protocol?.source===Je.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}let i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.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(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),At=c(`$ZodEmoji`,(e,t)=>{t.pattern??=Ve(),V.init(e,t)}),jt=c(`$ZodNanoID`,(e,t)=>{t.pattern??=Fe,V.init(e,t)}),Mt=c(`$ZodCUID`,(e,t)=>{t.pattern??=Ae,V.init(e,t)}),Nt=c(`$ZodCUID2`,(e,t)=>{t.pattern??=je,V.init(e,t)}),Pt=c(`$ZodULID`,(e,t)=>{t.pattern??=Me,V.init(e,t)}),Ft=c(`$ZodXID`,(e,t)=>{t.pattern??=Ne,V.init(e,t)}),It=c(`$ZodKSUID`,(e,t)=>{t.pattern??=Pe,V.init(e,t)}),Lt=c(`$ZodISODateTime`,(e,t)=>{t.pattern??=et(t),V.init(e,t)}),Rt=c(`$ZodISODate`,(e,t)=>{t.pattern??=Ze,V.init(e,t)}),zt=c(`$ZodISOTime`,(e,t)=>{t.pattern??=$e(t),V.init(e,t)}),Bt=c(`$ZodISODuration`,(e,t)=>{t.pattern??=Ie,V.init(e,t)}),Vt=c(`$ZodIPv4`,(e,t)=>{t.pattern??=He,V.init(e,t),e._zod.bag.format=`ipv4`}),Ht=c(`$ZodIPv6`,(e,t)=>{t.pattern??=Ue,V.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})}}}),Ut=c(`$ZodCIDRv4`,(e,t)=>{t.pattern??=We,V.init(e,t)}),Wt=c(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Ge,V.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function Gt(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var Kt=c(`$ZodBase64`,(e,t)=>{t.pattern??=Ke,V.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Gt(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function qt(e){if(!qe.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Gt(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var Jt=c(`$ZodBase64URL`,(e,t)=>{t.pattern??=qe,V.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{qt(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Yt=c(`$ZodE164`,(e,t)=>{t.pattern??=Ye,V.init(e,t)});function Xt(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var Zt=c(`$ZodJWT`,(e,t)=>{V.init(e,t),e._zod.check=n=>{Xt(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Qt=c(`$ZodNumber`,(e,t)=>{B.init(e,t),e._zod.pattern=e._zod.bag.pattern??rt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),$t=c(`$ZodNumberFormat`,(e,t)=>{dt.init(e,t),Qt.init(e,t)}),en=c(`$ZodBoolean`,(e,t)=>{B.init(e,t),e._zod.pattern=it,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),tn=c(`$ZodUnknown`,(e,t)=>{B.init(e,t),e._zod.parse=e=>e}),nn=c(`$ZodNever`,(e,t)=>{B.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function rn(e,t,n){e.issues.length&&t.issues.push(...P(n,e.issues)),t.value[n]=e.value}var an=c(`$ZodArray`,(e,t)=>{B.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>rn(t,n,e))):rn(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function on(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...P(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function sn(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=A(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function cn(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>on(e,n,i,t,u,d))):on(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}var ln=c(`$ZodObject`,(e,t)=>{if(B.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=h(()=>sn(t));y(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=w,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>on(n,t,e,s,r,i))):on(a,t,e,s,r,i)}return i?cn(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),un=c(`$ZodObjectJIT`,(e,t)=>{ln.init(e,t);let n=e._zod.parse,r=h(()=>sn(t)),i=e=>{let t=new Ct([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=te(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=te(r),s=e[r],c=s?._zod?.optin===`optional`,l=s?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),c&&l?t.write(`
4
- if (${n}.issues.length) {
5
- if (${o} in input) {
6
- payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
7
- ...iss,
8
- path: iss.path ? [${o}, ...iss.path] : [${o}]
9
- })));
10
- }
11
- }
12
-
13
- if (${n}.value === undefined) {
14
- if (${o} in input) {
15
- newResult[${o}] = undefined;
16
- }
17
- } else {
18
- newResult[${o}] = ${n}.value;
19
- }
20
-
21
- `):c?t.write(`
22
- if (${n}.issues.length) {
23
- payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
24
- ...iss,
25
- path: iss.path ? [${o}, ...iss.path] : [${o}]
26
- })));
27
- }
28
-
29
- if (${n}.value === undefined) {
30
- if (${o} in input) {
31
- newResult[${o}] = undefined;
32
- }
33
- } else {
34
- newResult[${o}] = ${n}.value;
35
- }
36
-
37
- `):t.write(`
38
- const ${n}_present = ${o} in input;
39
- if (${n}.issues.length) {
40
- payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
41
- ...iss,
42
- path: iss.path ? [${o}, ...iss.path] : [${o}]
43
- })));
44
- }
45
- if (!${n}_present && !${n}.issues.length) {
46
- payload.issues.push({
47
- code: "invalid_type",
48
- expected: "nonoptional",
49
- input: undefined,
50
- path: [${o}]
51
- });
52
- }
53
-
54
- if (${n}_present) {
55
- if (${n}.value === undefined) {
56
- newResult[${o}] = undefined;
57
- } else {
58
- newResult[${o}] = ${n}.value;
59
- }
60
- }
61
-
62
- `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=w,s=!d.jitless,c=s&&T.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?cn([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function dn(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!N(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>F(e,r,f())))}),t)}var fn=c(`$ZodUnion`,(e,t)=>{B.init(e,t),y(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),y(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),y(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),y(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>_(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>dn(t,r,e,i)):dn(o,r,e,i)}}),pn=c(`$ZodIntersection`,(e,t)=>{B.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>hn(e,t,n)):hn(e,i,a)}});function mn(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(E(e)&&E(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=mn(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=mn(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function hn(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),N(e))return e;let o=mn(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var gn=c(`$ZodRecord`,(e,t)=>{B.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!E(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>F(e,r,f())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...P(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...P(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&rt.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>F(e,r,f())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...P(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...P(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),_n=c(`$ZodEnum`,(e,t)=>{B.init(e,t);let n=p(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>re.has(typeof e)).map(e=>typeof e==`string`?D(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),vn=c(`$ZodLiteral`,(e,t)=>{if(B.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?D(e):e?D(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),yn=c(`$ZodTransform`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new u(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n.fallback=!0,n));if(i instanceof Promise)throw new l;return n.value=i,n.fallback=!0,n}});function bn(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var xn=c(`$ZodOptional`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,y(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),y(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${_(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>bn(e,r)):bn(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Sn=c(`$ZodExactOptional`,(e,t)=>{xn.init(e,t),y(e._zod,`values`,()=>t.innerType._zod.values),y(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Cn=c(`$ZodNullable`,(e,t)=>{B.init(e,t),y(e._zod,`optin`,()=>t.innerType._zod.optin),y(e._zod,`optout`,()=>t.innerType._zod.optout),y(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${_(e.source)}|null)$`):void 0}),y(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),wn=c(`$ZodDefault`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,y(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Tn(e,t)):Tn(r,t)}});function Tn(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var En=c(`$ZodPrefault`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,y(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Dn=c(`$ZodNonOptional`,(e,t)=>{B.init(e,t),y(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>On(t,e)):On(i,e)}});function On(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var kn=c(`$ZodCatch`,(e,t)=>{B.init(e,t),e._zod.optin=`optional`,y(e._zod,`optout`,()=>t.innerType._zod.optout),y(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let 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=>F(e,n,f()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>F(e,n,f()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),An=c(`$ZodPipe`,(e,t)=>{B.init(e,t),y(e._zod,`values`,()=>t.in._zod.values),y(e._zod,`optin`,()=>t.in._zod.optin),y(e._zod,`optout`,()=>t.out._zod.optout),y(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>jn(e,t.in,n)):jn(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>jn(e,t.out,n)):jn(r,t.out,n)}});function jn(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var Mn=c(`$ZodReadonly`,(e,t)=>{B.init(e,t),y(e._zod,`propValues`,()=>t.innerType._zod.propValues),y(e._zod,`values`,()=>t.innerType._zod.values),y(e._zod,`optin`,()=>t.innerType?._zod?.optin),y(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Nn):Nn(r)}});function Nn(e){return e.value=Object.freeze(e.value),e}var Pn=c(`$ZodCustom`,(e,t)=>{z.init(e,t),B.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Fn(t,n,r,e));Fn(i,n,r,e)}});function Fn(e,t,n,r){if(!e){let 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(pe(e))}}var In,Ln=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let 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)}};function Rn(){return new Ln}(In=globalThis).__zod_globalRegistry??(In.__zod_globalRegistry=Rn());var zn=globalThis.__zod_globalRegistry;function Bn(e,t){return new e({type:`string`,...k(t)})}function Vn(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...k(t)})}function Hn(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...k(t)})}function Un(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...k(t)})}function Wn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...k(t)})}function Gn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...k(t)})}function Kn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...k(t)})}function qn(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...k(t)})}function Jn(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...k(t)})}function Yn(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...k(t)})}function Xn(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...k(t)})}function Zn(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...k(t)})}function Qn(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...k(t)})}function $n(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...k(t)})}function er(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...k(t)})}function tr(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...k(t)})}function nr(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...k(t)})}function rr(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...k(t)})}function ir(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...k(t)})}function ar(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...k(t)})}function or(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...k(t)})}function sr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...k(t)})}function cr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...k(t)})}function lr(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...k(t)})}function ur(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...k(t)})}function dr(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...k(t)})}function fr(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...k(t)})}function pr(e,t){return new e({type:`number`,checks:[],...k(t)})}function mr(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...k(t)})}function hr(e,t){return new e({type:`boolean`,...k(t)})}function gr(e){return new e({type:`unknown`})}function _r(e,t){return new e({type:`never`,...k(t)})}function vr(e,t){return new ct({check:`less_than`,...k(t),value:e,inclusive:!1})}function yr(e,t){return new ct({check:`less_than`,...k(t),value:e,inclusive:!0})}function br(e,t){return new lt({check:`greater_than`,...k(t),value:e,inclusive:!1})}function xr(e,t){return new lt({check:`greater_than`,...k(t),value:e,inclusive:!0})}function Sr(e,t){return new ut({check:`multiple_of`,...k(t),value:e})}function Cr(e,t){return new ft({check:`max_length`,...k(t),maximum:e})}function wr(e,t){return new pt({check:`min_length`,...k(t),minimum:e})}function Tr(e,t){return new mt({check:`length_equals`,...k(t),length:e})}function Er(e,t){return new gt({check:`string_format`,format:`regex`,...k(t),pattern:e})}function Dr(e){return new _t({check:`string_format`,format:`lowercase`,...k(e)})}function Or(e){return new vt({check:`string_format`,format:`uppercase`,...k(e)})}function kr(e,t){return new yt({check:`string_format`,format:`includes`,...k(t),includes:e})}function Ar(e,t){return new bt({check:`string_format`,format:`starts_with`,...k(t),prefix:e})}function jr(e,t){return new xt({check:`string_format`,format:`ends_with`,...k(t),suffix:e})}function Mr(e){return new St({check:`overwrite`,tx:e})}function Nr(e){return Mr(t=>t.normalize(e))}function Pr(){return Mr(e=>e.trim())}function Fr(){return Mr(e=>e.toLowerCase())}function Ir(){return Mr(e=>e.toUpperCase())}function Lr(){return Mr(e=>S(e))}function Rr(e,t,n){return new e({type:`array`,element:t,...k(n)})}function zr(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...k(n)})}function Br(e,t){let n=Vr(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(pe(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(pe(r))}},e(t.value,t)),t);return n}function Vr(e,t){let n=new z({check:`custom`,...k(t)});return n._zod.check=e,n}function Hr(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??zn,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function H(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,H(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&U(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Ur(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
63
-
64
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Wr(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Kr(t,`input`,e.processors),output:Kr(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function U(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return U(r.element,n);if(r.type===`set`)return U(r.valueType,n);if(r.type===`lazy`)return U(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return U(r.innerType,n);if(r.type===`intersection`)return U(r.left,n)||U(r.right,n);if(r.type===`record`||r.type===`map`)return U(r.keyType,n)||U(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:U(r.in,n)||U(r.out,n);if(r.type===`object`){for(let e in r.shape)if(U(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(U(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(U(e,n))return!0;return!!(r.rest&&U(r.rest,n))}return!1}var Gr=(e,t={})=>n=>{let r=Hr({...n,processors:t});return H(e,r),Ur(r,e),Wr(r,e)},Kr=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Hr({...i??{},target:a,io:t,processors:n});return H(e,o),Ur(o,e),Wr(o,e)},qr={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Jr=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=qr[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Yr=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},Xr=(e,t,n,r)=>{n.type=`boolean`},Zr=(e,t,n,r)=>{n.not={}},Qr=(e,t,n,r)=>{let i=e._zod.def,a=p(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},$r=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0)if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a},ei=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},ti=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},ni=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=H(a.element,t,{...r,path:[...r.path,`items`]})},ri=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=H(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=H(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},ii=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>H(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},ai=(e,t,n,r)=>{let i=e._zod.def,a=H(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=H(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},oi=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=H(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else (t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=H(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=H(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},si=(e,t,n,r)=>{let i=e._zod.def,a=H(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},ci=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},li=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},ui=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},di=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},fi=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;H(o,t,r);let s=t.seen.get(e);s.ref=o},pi=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},mi=(e,t,n,r)=>{let i=e._zod.def;H(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},hi=c(`ZodISODateTime`,(e,t)=>{Lt.init(e,t),q.init(e,t)});function gi(e){return lr(hi,e)}var _i=c(`ZodISODate`,(e,t)=>{Rt.init(e,t),q.init(e,t)});function vi(e){return ur(_i,e)}var yi=c(`ZodISOTime`,(e,t)=>{zt.init(e,t),q.init(e,t)});function bi(e){return dr(yi,e)}var xi=c(`ZodISODuration`,(e,t)=>{Bt.init(e,t),q.init(e,t)});function Si(e){return fr(xi,e)}var W=c(`ZodError`,(e,t)=>{I.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>_e(e,t)},flatten:{value:t=>ge(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,m,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,m,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),Ci=ve(W),wi=L(W),Ti=ye(W),Ei=xe(W),Di=Ce(W),Oi=R(W),ki=we(W),Ai=Te(W),ji=Ee(W),Mi=De(W),Ni=Oe(W),Pi=ke(W),Fi=new WeakMap;function Ii(e,t,n){let r=Object.getPrototypeOf(e),i=Fi.get(r);if(i||(i=new Set,Fi.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var G=c(`ZodType`,(e,t)=>(B.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Kr(e,`input`),output:Kr(e,`output`)}}),e.toJSONSchema=Gr(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>Ci(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Ti(e,t,n),e.parseAsync=async(t,n)=>wi(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ei(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>Di(e,t,n),e.decode=(t,n)=>Oi(e,t,n),e.encodeAsync=async(t,n)=>ki(e,t,n),e.decodeAsync=async(t,n)=>Ai(e,t,n),e.safeEncode=(t,n)=>ji(e,t,n),e.safeDecode=(t,n)=>Mi(e,t,n),e.safeEncodeAsync=async(t,n)=>Ni(e,t,n),e.safeDecodeAsync=async(t,n)=>Pi(e,t,n),Ii(e,`ZodType`,{check(...e){let t=this.def;return this.clone(x(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return O(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(qa(e,t))},superRefine(e,t){return this.check(Ja(e,t))},overwrite(e){return this.check(Mr(e))},optional(){return ka(this)},exactOptional(){return ja(this)},nullable(){return Na(this)},nullish(){return ka(Na(this))},nonoptional(e){return za(this,e)},array(){return ha(this)},or(e){return va([this,e])},and(e){return ba(this,e)},transform(e){return Ua(this,Da(e))},default(e){return Fa(this,e)},prefault(e){return La(this,e)},catch(e){return Va(this,e)},pipe(e){return Ua(this,e)},readonly(){return Ga(this)},describe(e){let t=this.clone();return zn.add(t,{description:e}),t},meta(...e){if(e.length===0)return zn.get(this);let t=this.clone();return zn.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return zn.get(e)?.description},configurable:!0}),e)),Li=c(`_ZodString`,(e,t)=>{Tt.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jr(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,Ii(e,`_ZodString`,{regex(...e){return this.check(Er(...e))},includes(...e){return this.check(kr(...e))},startsWith(...e){return this.check(Ar(...e))},endsWith(...e){return this.check(jr(...e))},min(...e){return this.check(wr(...e))},max(...e){return this.check(Cr(...e))},length(...e){return this.check(Tr(...e))},nonempty(...e){return this.check(wr(1,...e))},lowercase(e){return this.check(Dr(e))},uppercase(e){return this.check(Or(e))},trim(){return this.check(Pr())},normalize(...e){return this.check(Nr(...e))},toLowerCase(){return this.check(Fr())},toUpperCase(){return this.check(Ir())},slugify(){return this.check(Lr())}})}),Ri=c(`ZodString`,(e,t)=>{Tt.init(e,t),Li.init(e,t),e.email=t=>e.check(Vn(zi,t)),e.url=t=>e.check(qn(Hi,t)),e.jwt=t=>e.check(cr(ra,t)),e.emoji=t=>e.check(Jn(Ui,t)),e.guid=t=>e.check(Hn(Bi,t)),e.uuid=t=>e.check(Un(Vi,t)),e.uuidv4=t=>e.check(Wn(Vi,t)),e.uuidv6=t=>e.check(Gn(Vi,t)),e.uuidv7=t=>e.check(Kn(Vi,t)),e.nanoid=t=>e.check(Yn(Wi,t)),e.guid=t=>e.check(Hn(Bi,t)),e.cuid=t=>e.check(Xn(Gi,t)),e.cuid2=t=>e.check(Zn(Ki,t)),e.ulid=t=>e.check(Qn(qi,t)),e.base64=t=>e.check(ar(ea,t)),e.base64url=t=>e.check(or(ta,t)),e.xid=t=>e.check($n(Ji,t)),e.ksuid=t=>e.check(er(Yi,t)),e.ipv4=t=>e.check(tr(Xi,t)),e.ipv6=t=>e.check(nr(Zi,t)),e.cidrv4=t=>e.check(rr(Qi,t)),e.cidrv6=t=>e.check(ir($i,t)),e.e164=t=>e.check(sr(na,t)),e.datetime=t=>e.check(gi(t)),e.date=t=>e.check(vi(t)),e.time=t=>e.check(bi(t)),e.duration=t=>e.check(Si(t))});function K(e){return Bn(Ri,e)}var q=c(`ZodStringFormat`,(e,t)=>{V.init(e,t),Li.init(e,t)}),zi=c(`ZodEmail`,(e,t)=>{Ot.init(e,t),q.init(e,t)}),Bi=c(`ZodGUID`,(e,t)=>{Et.init(e,t),q.init(e,t)}),Vi=c(`ZodUUID`,(e,t)=>{Dt.init(e,t),q.init(e,t)}),Hi=c(`ZodURL`,(e,t)=>{kt.init(e,t),q.init(e,t)}),Ui=c(`ZodEmoji`,(e,t)=>{At.init(e,t),q.init(e,t)}),Wi=c(`ZodNanoID`,(e,t)=>{jt.init(e,t),q.init(e,t)}),Gi=c(`ZodCUID`,(e,t)=>{Mt.init(e,t),q.init(e,t)}),Ki=c(`ZodCUID2`,(e,t)=>{Nt.init(e,t),q.init(e,t)}),qi=c(`ZodULID`,(e,t)=>{Pt.init(e,t),q.init(e,t)}),Ji=c(`ZodXID`,(e,t)=>{Ft.init(e,t),q.init(e,t)}),Yi=c(`ZodKSUID`,(e,t)=>{It.init(e,t),q.init(e,t)}),Xi=c(`ZodIPv4`,(e,t)=>{Vt.init(e,t),q.init(e,t)}),Zi=c(`ZodIPv6`,(e,t)=>{Ht.init(e,t),q.init(e,t)}),Qi=c(`ZodCIDRv4`,(e,t)=>{Ut.init(e,t),q.init(e,t)}),$i=c(`ZodCIDRv6`,(e,t)=>{Wt.init(e,t),q.init(e,t)}),ea=c(`ZodBase64`,(e,t)=>{Kt.init(e,t),q.init(e,t)}),ta=c(`ZodBase64URL`,(e,t)=>{Jt.init(e,t),q.init(e,t)}),na=c(`ZodE164`,(e,t)=>{Yt.init(e,t),q.init(e,t)}),ra=c(`ZodJWT`,(e,t)=>{Zt.init(e,t),q.init(e,t)}),ia=c(`ZodNumber`,(e,t)=>{Qt.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yr(e,t,n,r),Ii(e,`ZodNumber`,{gt(e,t){return this.check(br(e,t))},gte(e,t){return this.check(xr(e,t))},min(e,t){return this.check(xr(e,t))},lt(e,t){return this.check(vr(e,t))},lte(e,t){return this.check(yr(e,t))},max(e,t){return this.check(yr(e,t))},int(e){return this.check(sa(e))},safe(e){return this.check(sa(e))},positive(e){return this.check(br(0,e))},nonnegative(e){return this.check(xr(0,e))},negative(e){return this.check(vr(0,e))},nonpositive(e){return this.check(yr(0,e))},multipleOf(e,t){return this.check(Sr(e,t))},step(e,t){return this.check(Sr(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function aa(e){return pr(ia,e)}var oa=c(`ZodNumberFormat`,(e,t)=>{$t.init(e,t),ia.init(e,t)});function sa(e){return mr(oa,e)}var ca=c(`ZodBoolean`,(e,t)=>{en.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xr(e,t,n,r)});function la(e){return hr(ca,e)}var ua=c(`ZodUnknown`,(e,t)=>{tn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function da(){return gr(ua)}var fa=c(`ZodNever`,(e,t)=>{nn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zr(e,t,n,r)});function pa(e){return _r(fa,e)}var ma=c(`ZodArray`,(e,t)=>{an.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ni(e,t,n,r),e.element=t.element,Ii(e,`ZodArray`,{min(e,t){return this.check(wr(e,t))},nonempty(e){return this.check(wr(1,e))},max(e,t){return this.check(Cr(e,t))},length(e,t){return this.check(Tr(e,t))},unwrap(){return this.element}})});function ha(e,t){return Rr(ma,e,t)}var ga=c(`ZodObject`,(e,t)=>{un.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ri(e,t,n,r),y(e,`shape`,()=>t.shape),Ii(e,`ZodObject`,{keyof(){return Y(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:da()})},loose(){return this.clone({...this._zod.def,catchall:da()})},strict(){return this.clone({...this._zod.def,catchall:pa()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return oe(this,e)},safeExtend(e){return M(this,e)},merge(e){return se(this,e)},pick(e){return j(this,e)},omit(e){return ae(this,e)},partial(...e){return ce(Oa,this,e[0])},required(...e){return le(Ra,this,e[0])}})});function J(e,t){return new ga({type:`object`,shape:e??{},...k(t)})}var _a=c(`ZodUnion`,(e,t)=>{fn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ii(e,t,n,r),e.options=t.options});function va(e,t){return new _a({type:`union`,options:e,...k(t)})}var ya=c(`ZodIntersection`,(e,t)=>{pn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ai(e,t,n,r)});function ba(e,t){return new ya({type:`intersection`,left:e,right:t})}var xa=c(`ZodRecord`,(e,t)=>{gn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>oi(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Sa(e,t,n){return!t||!t._zod?new xa({type:`record`,keyType:K(),valueType:e,...k(t)}):new xa({type:`record`,keyType:e,valueType:t,...k(n)})}var Ca=c(`ZodEnum`,(e,t)=>{_n.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qr(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Ca({...t,checks:[],...k(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Ca({...t,checks:[],...k(r),entries:i})}});function Y(e,t){return new Ca({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...k(t)})}var wa=c(`ZodLiteral`,(e,t)=>{vn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$r(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Ta(e,t){return new wa({type:`literal`,values:Array.isArray(e)?e:[e],...k(t)})}var Ea=c(`ZodTransform`,(e,t)=>{yn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ti(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new u(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(pe(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(pe(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function Da(e){return new Ea({type:`transform`,transform:e})}var Oa=c(`ZodOptional`,(e,t)=>{xn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ka(e){return new Oa({type:`optional`,innerType:e})}var Aa=c(`ZodExactOptional`,(e,t)=>{Sn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>mi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ja(e){return new Aa({type:`optional`,innerType:e})}var Ma=c(`ZodNullable`,(e,t)=>{Cn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>si(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Na(e){return new Ma({type:`nullable`,innerType:e})}var Pa=c(`ZodDefault`,(e,t)=>{wn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>li(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Fa(e,t){return new Pa({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ne(t)}})}var Ia=c(`ZodPrefault`,(e,t)=>{En.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ui(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function La(e,t){return new Ia({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ne(t)}})}var Ra=c(`ZodNonOptional`,(e,t)=>{Dn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ci(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function za(e,t){return new Ra({type:`nonoptional`,innerType:e,...k(t)})}var Ba=c(`ZodCatch`,(e,t)=>{kn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>di(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Va(e,t){return new Ba({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Ha=c(`ZodPipe`,(e,t)=>{An.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>fi(e,t,n,r),e.in=t.in,e.out=t.out});function Ua(e,t){return new Ha({type:`pipe`,in:e,out:t})}var Wa=c(`ZodReadonly`,(e,t)=>{Mn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>pi(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Ga(e){return new Wa({type:`readonly`,innerType:e})}var Ka=c(`ZodCustom`,(e,t)=>{Pn.init(e,t),G.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ei(e,t,n,r)});function qa(e,t={}){return zr(Ka,e,t)}function Ja(e,t){return Br(e,t)}var Ya=J({visible:la().optional(),style:Y([`icon`,`text`]).optional(),label:K().nullable().optional(),position:K().optional()}).nullable().optional(),Xa=J({returnUrl:K().optional(),navigateOnClose:la().optional()}).optional(),Za=J({label:K().min(1).max(80).optional(),ariaLabel:K().min(1).max(120).optional(),placement:Y([`center`,`bottom-center`,`bottom-left`,`bottom-right`]).optional(),variant:Y([`primary`,`secondary`,`minimal`]).optional(),appearance:J({backgroundColor:K().min(1).max(64).optional(),textColor:K().min(1).max(64).optional(),borderColor:K().min(1).max(64).optional(),borderRadiusPx:aa().min(0).max(999).optional(),size:Y([`small`,`medium`,`large`]).optional(),shadow:Y([`none`,`soft`,`strong`]).optional()}).optional()}),Qa=J({characterId:K().min(1),displayName:K().min(1),avatarId:K().min(1),voiceId:K().min(1),sttLang:K().min(1),agentId:K().min(1),appearance:J({costume:K().optional(),costumeClothes:K().optional(),hair:K().optional()}).optional()}),$a=J({cx:aa(),cy:aa(),scale:aa(),distanceM:aa()}),eo=J({type:Ta(`image`),layers:ha(K()),assets:Sa(K(),Sa(K(),K()))}),to=Y([`browser`,`cloud`]),no=J({placement:to,provider:K().min(1),model:K().min(1).optional(),config:Sa(K(),da()).default({})}),ro=J({stt:no,llm:no,tts:no,animation:J({enabled:la(),placement:to.optional(),source:Y([`azureViseme`,`speechToAnimation`,`none`]),provider:K().min(1).optional(),model:K().min(1).optional(),config:Sa(K(),da()).default({})})}),io=J({schemaVersion:Ta(1),sessionId:K().min(1),experienceId:K().min(1),expiresAt:K().min(1),sessionToken:K().min(1),experience:J({title:K(),slug:K(),mode:Y([`conversation`,`presenter`]),responseMode:Y([`managed`,`custom`,`manual`]),speechInputMode:Y([`auto`,`manual`,`off`]),startButton:Za.optional(),openingMessage:K().optional()}),transport:J({type:Ta(`http`),config:J({apiBaseUrl:K().min(1)})}),runtime:J({cdnBaseUrl:K().min(1),input:Ta(`browserStt`),renderer:Ta(`morph2d`)}),pipeline:ro.optional(),capabilities:ha(K()),characters:ha(Qa).min(1),activeCharacterId:K().min(1),location:J({locationId:K(),title:K(),scene:eo.optional(),placement:$a.optional(),metersPerDepth:aa().positive().optional(),hasZoomVariant:la().optional()}).optional(),world:J({worldId:K(),rulesetVersion:aa()}).optional(),state:J({schemaVersion:Ta(1),values:Sa(K(),da())}),tools:ha(da()),integration:Xa,closeButton:Ya,billing:J({payer:Ta(`creator`),meterId:K()}).optional(),language:Y([`en`,`es`]).optional(),languagePackRevision:K().optional(),processorId:K().optional()}).superRefine((e,t)=>{let n=e.activeCharacterId;e.characters.some(e=>e.characterId===n)||t.addIssue({code:`custom`,message:`activeCharacterId must reference a character in characters[]`,path:[`activeCharacterId`]})});function ao(e){if(!e||typeof e!=`object`)return e;let t={...e},n=t.experience;if(!n||typeof n!=`object`)return t;let r={...n},i=r.mode===`presenter`?`presenter`:`conversation`;return r.responseMode===void 0&&(r.responseMode=i===`presenter`?`manual`:`managed`),r.speechInputMode===void 0&&(r.speechInputMode=i===`presenter`?`manual`:`auto`),t.experience=r,t}function oo(e){return e.issues.map(e=>`${e.path.length>0?e.path.join(`.`):`(root)`}: ${e.message}`).join(`; `)}function so(e){let t=io.safeParse(ao(e));if(!t.success)throw Error(`Invalid Session Manifest from Liforma API — ${oo(t.error)}`);return t.data}function co(e){return e.sessionToken.trim().length>0}function lo(){try{if(typeof globalThis.location?.origin==`string`&&globalThis.location.origin)return globalThis.location.origin}catch{}}function uo(e,t,n){let r;try{r=JSON.parse(n)}catch{}let i=lo(),a=r?.message?.trim(),o=r?.code;if(o===`origin_not_allowed`||/^Origin not allowed/i.test(a??``)&&i){if(a&&a.includes(e)&&a.includes(`allowed origin`))return a;let t=r?.origin??i??`(unknown origin)`;return`Your origin ${t} is not an allowed origin for experience ${e}. If you own this experience, sign in to the Liforma developer portal (app.liforma.ai), open Workspace → Settings → Origins, add ${t} to the list of allowed origins, and ensure “Allow public client-only embeds” is enabled.`}return o===`browser_embeds_disabled`||/^Browser embeds are not enabled/i.test(a??``)?a&&a.includes(`Allow public client-only embeds`)?a:`Browser embeds are not enabled for experience ${e}. If you own this experience, sign in to the Liforma developer portal (app.liforma.ai), open Workspace → Settings → Origins, and enable “Allow public client-only embeds”.`:o===`experience_unavailable`||/^Experience is not available\.?$/i.test(a??``)||/^Unknown experience\.?$/i.test(a??``)?a&&a.includes(`No playable experience found`)?a:`No playable experience found for “${e}”. Check that the experience id is correct (it should look like exp_…), and that the experience exists and is published in the Liforma developer portal (app.liforma.ai). Deleted, archived, and unpublished experiences cannot be started from a browser embed.`:a||n.trim().slice(0,500)||`Public session mint failed (${t})`}async function fo(e,t){let n=a(),r={experienceId:e};t?.language&&(r.language=t.language),t?.mode&&(r.mode=t.mode),t?.responseMode&&(r.responseMode=t.responseMode),t?.speechInputMode&&(r.speechInputMode=t.speechInputMode),t?.startButton&&(r.startButton=t.startButton),t?.speechOnly!==void 0&&(r.speechOnly=t.speechOnly);let i=await fetch(`${n}/v1/public-sessions`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let t=await i.text();throw Error(uo(e,i.status,t))}let o;try{o=await i.json()}catch{throw Error(`Public session mint returned invalid JSON.`)}return so(o)}async function po(e,t){let n=o(e,t),r=new AbortController,i=()=>r.abort(t.signal?.reason);t.signal?.aborted?i():t.signal?.addEventListener(`abort`,i,{once:!0});let a=globalThis.setTimeout(()=>r.abort(new DOMException(`Session endpoint timed out.`,`TimeoutError`)),t.timeoutMs??3e4),s;try{s=await fetch(n.url,{...n.init,signal:r.signal})}finally{globalThis.clearTimeout(a),t.signal?.removeEventListener(`abort`,i)}if(!s.ok){let e=await s.text(),t=e.slice(0,500)||`Session endpoint failed (${s.status})`;try{let n=JSON.parse(e);n.message&&(t=n.message)}catch{}throw Error(t)}if(!s.headers.get(`content-type`)?.toLowerCase().includes(`application/json`))throw Error(`Session endpoint must return a JSON Session Manifest.`);let c;try{c=await s.json()}catch{throw Error(`Session endpoint returned invalid JSON.`)}return so(c)}function mo(e){return typeof e!=`object`||!e?!1:typeof e[Symbol.asyncIterator]==`function`}function ho(e){if(typeof e==`string`){let t=e.trim();if(!t)throw Error(`conversationProcessor returned empty text.`);return{text:t}}let t=e.text.trim();if(!t)throw Error(`conversationProcessor returned empty text.`);return{text:t,...e.characterId?{characterId:e.characterId}:{},...e.behavior?{behavior:e.behavior}:{}}}async function go(e,t){let n=await e(t);return mo(n)?{kind:`stream`,stream:n}:{kind:`complete`,speech:ho(n)}}var _o=`3002`;function vo(e){let t=new URL(e);return t.hostname===`localhost`||t.hostname===`127.0.0.1`?`Cannot connect to the Liforma player at ${e} — nothing is listening on port ${t.port||_o}. Start the player dev server in player.liforma.ai (npm run dev).`:`Cannot connect to the Liforma player at ${e}. The embed did not load; check your network connection and player URL configuration.`}async function yo(e,t){try{await fetch(e,{method:`GET`,mode:`no-cors`,signal:AbortSignal.timeout(8e3)})}catch{throw Error(vo(t))}}function bo(e,t,n,r){try{r&&r.length>0?e.postMessage(t,n,r):e.postMessage(t,n)}catch(e){throw e instanceof DOMException&&e.name===`SecurityError`?Error(vo(n),{cause:e}):e}}var xo=new Set([1,2]);function So(e){return typeof e==`number`&&xo.has(e)}var Co=new Set([`close`,`stateUpdate`,`commandResult`,`userTranscript`,`characterSpeechStarted`,`characterSpeechEnded`,`conversationUpdate`,`listeningState`,`userSpeechStarted`,`userSpeechEnded`,`modeChange`,`message`,`started`,`widgetReady`,`widgetExpand`,`widgetCollapse`,`widgetAudioSettings`,`widgetDragStart`,`widgetDragMove`,`widgetDragEnd`]);function wo(e){if(!e||typeof e!=`object`)return null;let t=e;if(!So(t.schemaVersion)||!t.type||!Co.has(t.type))return null;if(t.type===`widgetReady`||t.type===`widgetExpand`||t.type===`widgetCollapse`)return t;if(t.type===`widgetAudioSettings`){let e=t.payload;return!e||typeof e!=`object`||typeof e.open!=`boolean`?null:t}if(t.type===`widgetDragStart`||t.type===`widgetDragEnd`){let e=t.payload;return!e||typeof e!=`object`||typeof e.pointerId!=`number`||!Number.isFinite(e.pointerId)?null:t}if(t.type===`widgetDragMove`){let e=t.payload;if(!e||typeof e!=`object`)return null;let{pointerId:n,dx:r,dy:i}=e;return typeof n!=`number`||!Number.isFinite(n)||typeof r!=`number`||!Number.isFinite(r)||typeof i!=`number`||!Number.isFinite(i)?null:t}return!t.payload||typeof t.payload!=`object`?null:t}function To(e){return{type:`manifest`,schemaVersion:2,payload:{manifest:e}}}function Eo(){return{type:`parentHello`,schemaVersion:2}}function Do(e){return{type:`widgetSetChrome`,schemaVersion:2,payload:{mode:e}}}function Oo(){return{type:`widgetToggleAudioSettings`,schemaVersion:2,payload:{}}}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`cmd_${crypto.randomUUID().replace(/-/g,``).slice(0,12)}`:`cmd_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}var ko=3e4;function Ao(e){let t=e.container;getComputedStyle(t).position===`static`&&(t.style.position=`relative`);let n=document.createElement(`iframe`);n.src=e.src,n.title=`Liforma experience`,n.setAttribute(`allow`,`microphone; autoplay; clipboard-read; clipboard-write`),n.style.cssText=e.transparent?`display:block;position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;`:`display:block;position:absolute;inset:0;width:100%;height:100%;border:0;background:#030508;`,e.transparent&&n.setAttribute(`allowtransparency`,`true`);let r=!1,i=new Map,a=new Promise((t,r)=>{let i=()=>{o(),yo(e.src,e.playerOrigin).then(t,r)},a=()=>{o(),r(Error(vo(e.playerOrigin)))},o=()=>{n.removeEventListener(`load`,i),n.removeEventListener(`error`,a)};n.addEventListener(`load`,i),n.addEventListener(`error`,a)}),o=t=>{if(r||t.source!==n.contentWindow||t.origin!==e.playerOrigin)return;let a=wo(t.data);if(a)switch(a.type){case`close`:e.onClose?.(a.payload);break;case`stateUpdate`:e.onStateUpdate?.(a.payload.state);break;case`commandResult`:{let e=i.get(a.payload.correlationId);if(!e)return;i.delete(a.payload.correlationId),a.payload.ok?e.resolve(a.payload.result):e.reject(Error(a.payload.error??`Command failed.`));break}case`userTranscript`:e.onUserTranscript?.(a.payload);break;case`characterSpeechStarted`:e.onCharacterSpeechStarted?.(a.payload);break;case`characterSpeechEnded`:e.onCharacterSpeechEnded?.(a.payload);break;case`conversationUpdate`:e.onConversationUpdate?.(a.payload.conversation);break;case`listeningState`:e.onListeningState?.(a.payload.listening);break;case`userSpeechStarted`:e.onUserSpeechStarted?.(a.payload);break;case`userSpeechEnded`:e.onUserSpeechEnded?.(a.payload);break;case`modeChange`:e.onModeChange?.(a.payload.mode);break;case`message`:e.onMessage?.(a.payload);break;case`started`:e.onStarted?.(a.payload);break;case`widgetReady`:e.onWidgetReady?.();break;case`widgetExpand`:e.onWidgetExpand?.();break;case`widgetCollapse`:e.onWidgetCollapse?.();break;case`widgetAudioSettings`:e.onWidgetAudioSettings?.(a.payload.open);break;case`widgetDragStart`:e.onWidgetDragStart?.(a.payload);break;case`widgetDragMove`:e.onWidgetDragMove?.(a.payload);break;case`widgetDragEnd`:e.onWidgetDragEnd?.(a.payload);break}};if(window.addEventListener(`message`,o),t.replaceChildren(n),t.clientHeight<2&&!t.style.minHeight){let e=getComputedStyle(t).minHeight;(e===`0px`||e===`auto`)&&(t.style.minHeight=`480px`)}let s=(t,i)=>{if(r)return;let a=n.contentWindow;if(!a)throw Error(vo(e.playerOrigin));bo(a,t,e.playerOrigin,i)},c=(e,t=12e4,n)=>{let r=e.type!==`parentHello`&&e.payload&&`correlationId`in e.payload?e.payload.correlationId:X();return e.type!==`parentHello`&&e.payload&&`correlationId`in e.payload||e.type!==`parentHello`&&e.payload&&(e.payload.correlationId=r),new Promise((a,o)=>{i.set(r,{resolve:e=>a(e),reject:o}),s(e,n),setTimeout(()=>{i.has(r)&&(i.delete(r),o(Error(`Timed out waiting for player command result.`)))},t)})};return{waitForLoad(){return a},postParentHello(){s(Eo())},postManifest(t){if(r)return;let i=n.contentWindow;if(!i)throw Error(`Liforma embed iframe is not ready.`);let a=To(t),o=()=>{r||bo(i,a,e.playerOrigin)};o();for(let e=1;e<=12;e+=1)window.setTimeout(o,e*75)},postWidgetSetChrome(e){s(Do(e))},postWidgetToggleAudioSettings(){s(Oo())},speak(e){return c({type:`speak`,schemaVersion:2,payload:{correlationId:X(),text:e.text,...e.characterId?{characterId:e.characterId}:{},...e.behavior?{behavior:e.behavior}:{}}})},startListening(){return c({type:`startListening`,schemaVersion:2,payload:{correlationId:X()}})},stopListening(){return c({type:`stopListening`,schemaVersion:2,payload:{correlationId:X()}})},listenOnce(e){return c({type:`listenOnce`,schemaVersion:2,payload:{correlationId:X(),...e?.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}})},async speakProcessorStream(e,t){let n=X(),r=X(),i=(await c({type:`speakStreamStart`,schemaVersion:2,payload:{correlationId:n,...t?.characterId?{characterId:t.characterId}:{},...t?.behavior?{behavior:t.behavior}:{}}})).streamId;try{for await(let n of e){if(t?.signal?.aborted)throw new DOMException(`Processor stream aborted.`,`AbortError`);n&&s({type:`speakStreamChunk`,schemaVersion:2,payload:{streamId:i,text:n}})}if(t?.signal?.aborted)throw new DOMException(`Processor stream aborted.`,`AbortError`);return await c({type:`speakStreamEnd`,schemaVersion:2,payload:{correlationId:r,streamId:i}})}catch(e){try{await c({type:`speakStreamEnd`,schemaVersion:2,payload:{correlationId:r,streamId:i}})}catch{}throw e}},speechPlay(e){let t=X(),n=[];return(e.source.kind===`pcm`||e.source.kind===`encoded`)&&n.push(e.source.data),c({type:`speechPlay`,schemaVersion:2,payload:{correlationId:t,source:e.source,...e.characterId?{characterId:e.characterId}:{},...e.transcript===void 0?{}:{transcript:e.transcript},...e.history?{history:e.history}:{},...e.queue?{queue:e.queue}:{}}},12e4,n)},speechUtteranceBegin(e){return c({type:`speechUtteranceBegin`,schemaVersion:2,payload:{correlationId:X(),utteranceId:e.utteranceId,format:e.format,queue:e.queue,...e.characterId?{characterId:e.characterId}:{},...e.transcript===void 0?{}:{transcript:e.transcript}}})},speechUtteranceWrite(e){return c({type:`speechUtteranceWrite`,schemaVersion:2,payload:{correlationId:X(),utteranceId:e.utteranceId,audio:e.audio,byteLength:e.byteLength}},ko,[e.audio])},speechUtteranceSetTranscript(e){return c({type:`speechUtteranceSetTranscript`,schemaVersion:2,payload:{correlationId:X(),utteranceId:e.utteranceId,transcript:e.transcript}})},speechUtteranceClose(e){return c({type:`speechUtteranceClose`,schemaVersion:2,payload:{correlationId:X(),utteranceId:e.utteranceId,...e.transcript===void 0?{}:{transcript:e.transcript},...e.history?{history:e.history}:{}}})},speechUtteranceCancel(e){return c({type:`speechUtteranceCancel`,schemaVersion:2,payload:{correlationId:X(),utteranceId:e.utteranceId}})},speechInterrupt(e){return c({type:`speechInterrupt`,schemaVersion:2,payload:{correlationId:X(),...e}})},getConversation(){return c({type:`getConversation`,schemaVersion:2,payload:{correlationId:X()}})},destroy(){if(!r){r=!0;for(let e of i.values())e.reject(Error(`Iframe host destroyed.`));i.clear(),window.removeEventListener(`message`,o),n.remove()}}}}function jo(e){let t,n=!1,r=!1,i=()=>{r||!n||t===void 0||(r=!0,e(t))};return{setValue(e){t=e,i()},markReady(){n=!0,i()}}}var Mo=`https://player.liforma.ai/embed`,No=`http://localhost:3002/embed`;function Po(){let e=globalThis.__LIFORMA_PLAYER_EMBED_URL;if(e?.trim())return e.trim().replace(/\/$/,``);if(typeof document>`u`)return null;let t=(document.querySelector(`script[data-liforma-sdk][src*="client.js"]`)??document.querySelector(`script[src*="/sdk/v2/client.js"]`))?.getAttribute(`data-player-embed-url`)?.trim();return t?t.replace(/\/$/,``):null}function Fo(){let e=Po();return e?e.endsWith(`/embed`)?e:`${e}/embed`:t()?No:Mo}function Io(e,t,n,r,i,a,o){let s=(e??Fo()).replace(/\/$/,``),c=s.endsWith(`/embed`)?s:`${s}/embed`,l=new URL(c),u=n?.trim();u&&l.searchParams.set(`locationId`,u);let d=r?.trim();return d&&l.searchParams.set(`avatarId`,d),i===`face`&&l.searchParams.set(`fit`,`face`),a===`widget`&&l.searchParams.set(`ui`,`widget`),o&&l.searchParams.set(`close`,`1`),t&&l.searchParams.set(`debug`,`true`),Lo(l.toString())}function Lo(e){if(typeof location>`u`)return e;let t=new URL(e);return t.searchParams.set(`parentOrigin`,location.origin),t.toString()}function Ro(e){return new URL(e).origin}function zo(e){let t=e.filter(e=>e!==`avatar`);return t.includes(`voice`)?t:[`voice`,...t]}function Bo(e){return so({...e,capabilities:zo(e.capabilities),pipeline:{...e.pipeline,animation:{enabled:!1,source:`none`,config:{}}},location:{locationId:e.location?.locationId?.trim()||`speech-only`,title:e.location?.title?.trim()||``}})}function Vo(){return{ready:new Set,started:new Set,userTranscript:new Set,userSpeechStarted:new Set,userSpeechEnded:new Set,characterSpeechStarted:new Set,characterSpeechEnded:new Set,conversationUpdate:new Set,message:new Set,listeningState:new Set,modeChange:new Set,conversationProcessorError:new Set}}function Ho(e,t,n){return e[t].add(n),()=>e[t].delete(n)}function Z(e,t,n){for(let r of e[t])r(n)}function Uo(e){for(let t of Object.keys(e))e[t].clear()}function Wo(e){return`data`in e&&`format`in e&&e.format!=null&&!(`track`in e)}function Go(e){return`url`in e&&typeof e.url==`string`}function Ko(e){if(!(`track`in e))return!1;let t=e.track;return typeof t!=`object`||!t?!1:typeof MediaStreamTrack<`u`&&t instanceof MediaStreamTrack?!0:`kind`in t&&`readyState`in t}function qo(e){return!Wo(e)&&!Go(e)&&!Ko(e)&&`encoding`in e&&typeof e.encoding==`string`}var Jo=[8e3,16e3,22050,24e3,44100,48e3],Yo={MAX_CHUNK_BYTES:64*1024,RECOMMENDED_CHUNK_MS_MIN:20,RECOMMENDED_CHUNK_MS_MAX:200,MAX_BUFFERED_AUDIO_MS:8e3,PLAYBACK_JITTER_BUFFER_MS:150,PLAYBACK_JITTER_BUFFER_MS_MIN:80,PLAYBACK_JITTER_BUFFER_MS_MAX:250,MAX_UTTERANCE_DURATION_MS:9e4,MAX_PENDING_WRITES:8,DEFAULT_WRITE_TIMEOUT_MS:5e3},Xo=class extends Error{operation;requiredCapability;name=`UnsupportedSpeechOperationError`;constructor(e,t){super(`Speech operation "${e}" requires capability "${t}".`),this.operation=e,this.requiredCapability=t}},Zo=class extends Error{name=`SpeechUtteranceClosedError`;constructor(e=`Cannot write to a closed or cancelled speech utterance.`){super(e)}},Q=class extends Error{name=`SpeechRuntimeError`;constructor(e,t){super(e,t)}},Qo=class extends Error{name=`SpeechBufferTimeoutError`;constructor(e=`Timed out waiting for speech buffer capacity.`){super(e)}};function $o(e=`none`){return{mode:e,trackedDurationMs:0,fallbackDurationMs:0}}function es(e){return Jo.includes(e)}function ts(e){if(e.encoding!==`pcm_s16le`)throw new Q(`Unsupported audio encoding: ${e.encoding}`);if(e.channels!==1)throw new Q(`Unsupported channel count: ${e.channels}`);if(!es(e.sampleRate))throw new Q(`Unsupported sample rate: ${e.sampleRate}`)}function ns(e){if(Wo(e)){ts(e.format);return}if(Go(e)){if(!e.url.trim())throw new Q(`Audio URL must be non-empty.`);if(e.sampleRate!==void 0&&!es(e.sampleRate))throw new Q(`Unsupported sample rate: ${e.sampleRate}`);return}if(Ko(e)){if(e.track.kind!==`audio`)throw new Q(`speech.play track must be an audio MediaStreamTrack.`);if(e.sampleRate!==void 0&&!es(e.sampleRate))throw new Q(`Unsupported sample rate: ${e.sampleRate}`);return}if(qo(e)){let t=e.encoding.trim().toLowerCase();if(!t)throw new Q(`Encoded audio MIME type is required.`);if(t===`pcm_s16le`)throw new Q(`Use format: { encoding: "pcm_s16le", … } for raw PCM.`);if(e.sampleRate!==void 0&&!es(e.sampleRate))throw new Q(`Unsupported sample rate: ${e.sampleRate}`);return}throw new Q(`Unsupported speech.play audio shape.`)}function rs(e){if(e.format)return ts(e.format),e.format;if(e.track){let t={encoding:`pcm_s16le`,sampleRate:e.sampleRate??24e3,channels:1};return ts(t),t}throw new Q(`createUtterance requires format or track.`)}function is(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function as(e){return e===`replace-active`||e===`replace-all`?`interrupt`:`enqueue`}function os(e){let t=new Uint8Array(e.length*2),n=new DataView(t.buffer);for(let t=0;t<e.length;t++){let r=Math.max(-1,Math.min(1,e[t]));n.setInt16(t*2,r<0?r*32768:r*32767,!0)}return t}function ss(e,t,n,r,i){let a=-.5*e+1.5*t-1.5*n+.5*r,o=e-2.5*t+2*n-.5*r,s=-.5*e+.5*n,c=t;return((a*i+o)*i+s)*i+c}function cs(e,t){if(!(e>0)||!(t>0))throw Error(`Resampler rates must be positive`);if(e===t)return{fromRate:e,toRate:t,push(e){return e},flush(){return new Float32Array}};let n=e/t,r=new Float32Array,i=0;return{fromRate:e,toRate:t,push(e){if(e.length===0)return new Float32Array;let t=new Float32Array(r.length+e.length);if(t.set(r),t.set(e,r.length),r=t,r.length<4)return new Float32Array;let a=[];for(;i+2<r.length-1;){let e=Math.floor(i),t=i-e,o=Math.max(0,e-1),s=Math.min(r.length-1,e+1),c=Math.min(r.length-1,e+2);a.push(ss(r[o],r[e],r[s],r[c],t)),i+=n}let o=Math.max(0,Math.floor(i)-1);return o>0&&(r=r.subarray(o),i-=o),a.length?Float32Array.from(a):new Float32Array},flush(){return r.length===0?new Float32Array:(r=new Float32Array,i=0,new Float32Array)}}}var ls=`liforma-pcm-capture`,us=`
1
+ var Liforma=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(){if(globalThis.__LIFORMA_STACK===`local`)return!0;if(typeof location>`u`)return!1;try{return new URLSearchParams(location.search).get(`stack`)===`local`}catch{return!1}}var n=`https://api.liforma.ai`,r=`http://localhost:3001`;function i(){let e=globalThis.__LIFORMA_API_BASE_URL;if(e?.trim())return e.trim().replace(/\/$/,``);if(typeof document>`u`)return null;let t=(document.querySelector(`script[data-liforma-sdk][src*="client.js"]`)??document.querySelector(`script[src*="/sdk/v2/client.js"]`))?.getAttribute(`data-api-base-url`)?.trim();return t?t.replace(/\/$/,``):null}function a(){return i()||(t()?r:n)}var o=class extends Error{code;requestId;status;details;constructor(e,t){super(e,t?.cause===void 0?void 0:{cause:t.cause}),this.name=`LiformaError`,this.code=t?.code?.trim()||`UNKNOWN`,this.requestId=t?.requestId?.trim()||void 0,this.status=t?.status,this.details=t?.details}};function s(e){if(!(!e||typeof e!=`object`||Array.isArray(e)))return e}function c(e,t,n){let r=n?.get(`Liforma-Request-Id`)?.trim()||void 0,i;try{i=JSON.parse(t)}catch{}let a=i?.error&&typeof i.error==`object`?i.error:void 0,c=a?.code??i?.code,l=a?.message??i?.message,u=a?.requestId??i?.requestId??r,d=typeof c==`string`&&c.trim()?c.trim():`HTTP_ERROR`,f=typeof l==`string`&&l.trim()?l.trim():t.trim().slice(0,500)||`Request failed (${e})`,p=typeof u==`string`&&u.trim()?u.trim():r,{code:m,message:h,requestId:g,..._}=s(a)??s(i)??{};return new o(f,{code:d,requestId:p,status:e,details:Object.keys(_).length>0?_:void 0})}function l(e){let t=e.locale?.trim();if(t)return t;let n=e.language?.trim();if(n)return n;if(typeof navigator<`u`&&navigator.language?.trim())return navigator.language.trim()}function u(e){let t=e.secondaryLocale?.trim(),n=e.learningLocale?.trim();if(t&&n&&t!==n)throw Error(`secondaryLocale and learningLocale disagree; pass only one or make them equal.`);return t||n||void 0}function d(e,t){let n=e.trim();if(!n)throw Error(`sessionEndpoint must not be empty.`);if(typeof location>`u`)throw Error(`sessionEndpoint is only available in a browser.`);let r=new URL(n,location.href);if(r.origin!==location.origin)throw Error(`sessionEndpoint must be same-origin.`);let i=t.experienceId.trim();if(!i)throw Error(`sessionEndpoint requires experienceId.`);let a=l(t),o=u(t),s=t.idempotencyKey?.trim();return{url:r.toString(),init:{method:`POST`,credentials:`same-origin`,headers:{Accept:`application/json`,"Content-Type":`application/json`,...s?{"Idempotency-Key":s}:{}},body:JSON.stringify({experienceId:i,...a?{locale:a}:{},...o?{secondaryLocale:o}:{},...t.mode?{mode:t.mode}:{},...t.speechInputMode?{speechInputMode:t.speechInputMode}:{},...t.speechOnly===void 0?{}:{speechOnly:t.speechOnly}})}}}function f(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function p(e){return typeof e==`boolean`}function m(e){if(!f(e))return null;let t=e.speech,n=e.conversation,r=e.avatar,i=e.tools;return!f(t)||!f(n)||!f(r)||!f(i)||!p(t.input)||!p(t.output)||!p(t.externalAudio)||!p(n.managed)||!p(r.enabled)||!p(i.enabled)?null:{speech:{input:t.input,output:t.output,externalAudio:t.externalAudio},conversation:{managed:n.managed},avatar:{enabled:r.enabled},tools:{enabled:i.enabled}}}function h(e){return!f(e)||!p(e.avatar)||!p(e.speechInput)||!p(e.speechOutput)||!p(e.tools)||!p(e.externalAudio)?null:{speech:{input:e.speechInput,output:e.speechOutput,externalAudio:e.externalAudio},conversation:{managed:!0},avatar:{enabled:e.avatar},tools:{enabled:e.tools}}}function g(e){return m(e)??h(e)}function _(e){if(!f(e))throw Error(`Session Launch response is missing session.`);let t=typeof e.id==`string`?e.id.trim():``,n=typeof e.experienceId==`string`?e.experienceId.trim():``,r=typeof e.experienceRevisionId==`string`?e.experienceRevisionId.trim():``,i=typeof e.expiresAt==`string`?e.expiresAt.trim():``,a=typeof e.locale==`string`?e.locale.trim():``,o=typeof e.secondaryLocale==`string`&&e.secondaryLocale.trim()?e.secondaryLocale.trim():void 0,s=e.mode===`conversation`||e.mode===`presenter`?e.mode:null,c=g(e.capabilities),l=ee(e.localeVoiceFallbacks),u=e.status===`active`||e.status===`ended`?e.status:void 0,d=typeof e.createdAt==`string`&&e.createdAt.trim()?e.createdAt.trim():void 0;if(!t||!n||!r||!i||!a||!s||!c)throw Error(`Session Launch response has an invalid session object.`);return{id:t,experienceId:n,experienceRevisionId:r,expiresAt:i,locale:a,...o?{secondaryLocale:o}:{},mode:s,capabilities:c,...l?{localeVoiceFallbacks:l}:{},...u?{status:u}:{},...d?{createdAt:d}:{}}}function ee(e){if(!Array.isArray(e)||e.length===0)return;let t=[];for(let n of e){if(!f(n))continue;let e=n.axis===`locale`||n.axis===`secondaryLocale`?n.axis:null,r=typeof n.requested==`string`?n.requested.trim():``,i=typeof n.resolved==`string`?n.resolved.trim():``;!e||!r||!i||n.reason!==`voice_unsupported`||t.push({axis:e,requested:r,resolved:i,reason:`voice_unsupported`})}return t.length>0?t:void 0}function v(e){let t=e.localeVoiceFallbacks;if(t?.length)for(let e of t){let t=e.axis===`secondaryLocale`?`secondaryLocale`:`locale`;console.warn(`[liforma] Session ${t} fell back to ${e.resolved} because the voice does not support ${e.requested}.`)}}function y(e){if(!f(e))throw Error(`Session Launch response must be a JSON object.`);let t=typeof e.launch==`string`?e.launch.trim():``;if(!t)throw Error(`Session Launch response is missing launch.`);let n=_(e.session);return v(n),{session:n,launch:t}}function b(){try{if(typeof globalThis.location?.origin==`string`&&globalThis.location.origin)return globalThis.location.origin}catch{}}function x(e){return e?e.trim().toUpperCase().replace(/-/g,`_`):``}function te(e,t){let n=b(),r=x(t.code),i=t.message.trim(),a=t.details??{};if(r===`ORIGIN_NOT_ALLOWED`||/^Origin not allowed/i.test(i)&&n){if(i.includes(e)&&i.includes(`allowed origin`))return t;let r=typeof a.origin==`string`&&a.origin||n||`(unknown origin)`;return new o(`Your origin ${r} is not an allowed origin for experience ${e}. If you own this experience, sign in to the Liforma developer portal (app.liforma.ai), open Workspace → Settings → Origins, add ${r} to the list of allowed origins, and ensure “Allow public client-only embeds” is enabled.`,{code:`ORIGIN_NOT_ALLOWED`,requestId:t.requestId,status:t.status,details:a})}return r===`BROWSER_EMBEDS_DISABLED`||/^Browser embeds are not enabled/i.test(i)?i.includes(`Allow public client-only embeds`)?t:new o(`Browser embeds are not enabled for experience ${e}. If you own this experience, sign in to the Liforma developer portal (app.liforma.ai), open Workspace → Settings → Origins, and enable “Allow public client-only embeds”.`,{code:`BROWSER_EMBEDS_DISABLED`,requestId:t.requestId,status:t.status,details:a}):r===`EXPERIENCE_UNAVAILABLE`||/^Experience is not available\.?$/i.test(i)||/^Unknown experience\.?$/i.test(i)?i.includes(`No playable experience found`)?t:new o(`No playable experience found for “${e}”. Check that the experience id is correct (it should look like exp_…), and that the experience exists and is published in the Liforma developer portal (app.liforma.ai). Deleted, archived, and unpublished experiences cannot be started from a browser embed.`,{code:`EXPERIENCE_UNAVAILABLE`,requestId:t.requestId,status:t.status,details:a}):t}function S(e){let t=e?.locale?.trim();if(t)return t;let n=e?.language?.trim();if(n)return n;if(typeof navigator<`u`&&navigator.language?.trim())return navigator.language.trim()}function C(e){let t=e?.secondaryLocale?.trim(),n=e?.learningLocale?.trim();if(t&&n&&t!==n)throw new o(`secondaryLocale and learningLocale disagree; pass only one or make them equal.`,{code:`INVALID_BODY`});return t||n||void 0}function w(e,t){let n={experienceId:e},r=S(t);r&&(n.locale=r);let i=C(t);return i&&(n.secondaryLocale=i),t?.mode&&(n.mode=t.mode),t?.speechInputMode&&(n.speechInputMode=t.speechInputMode),t?.speechOnly!==void 0&&(n.speechOnly=t.speechOnly),n}async function T(e,t){let n=a(),r=t?.idempotencyKey?.trim(),i=await fetch(`${n}/v1/browser-sessions`,{method:`POST`,headers:{"Content-Type":`application/json`,...r?{"Idempotency-Key":r}:{}},body:JSON.stringify(w(e,t))});if(!i.ok){let t=await i.text();throw te(e,c(i.status,t,i.headers))}let s;try{s=await i.json()}catch{throw new o(`Browser session mint returned invalid JSON.`,{code:`INVALID_RESPONSE`,status:i.status,requestId:i.headers.get(`Liforma-Request-Id`)??void 0})}return y(s)}async function E(e,t){let n=d(e,t),r=new AbortController,i=()=>r.abort(t.signal?.reason);t.signal?.aborted?i():t.signal?.addEventListener(`abort`,i,{once:!0});let a=globalThis.setTimeout(()=>r.abort(new DOMException(`Session endpoint timed out.`,`TimeoutError`)),t.timeoutMs??3e4),s;try{s=await fetch(n.url,{...n.init,signal:r.signal})}finally{globalThis.clearTimeout(a),t.signal?.removeEventListener(`abort`,i)}if(!s.ok){let e=await s.text();throw c(s.status,e,s.headers)}if(!s.headers.get(`content-type`)?.toLowerCase().includes(`application/json`))throw new o(`Session endpoint must return a JSON Session Launch response.`,{code:`INVALID_RESPONSE`,status:s.status,requestId:s.headers.get(`Liforma-Request-Id`)??void 0});let l;try{l=await s.json()}catch{throw new o(`Session endpoint returned invalid JSON.`,{code:`INVALID_RESPONSE`,status:s.status,requestId:s.headers.get(`Liforma-Request-Id`)??void 0})}return y(l)}function ne(e){return typeof e!=`object`||!e?!1:typeof e[Symbol.asyncIterator]==`function`}function D(e){if(typeof e==`string`){let t=e.trim();if(!t)throw Error(`conversationProcessor returned empty text.`);return{text:t}}let t=e.text.trim();if(!t)throw Error(`conversationProcessor returned empty text.`);return{text:t,...e.characterId?{characterId:e.characterId}:{},...e.behavior?{behavior:e.behavior}:{}}}async function re(e,t){let n=await e(t);return ne(n)?{kind:`stream`,stream:n}:{kind:`complete`,speech:D(n)}}var O=`3002`;function k(e){let t=new URL(e);return t.hostname===`localhost`||t.hostname===`127.0.0.1`?`Cannot connect to the Liforma player at ${e} — nothing is listening on port ${t.port||O}. Start the player dev server in player.liforma.ai (npm run dev).`:`Cannot connect to the Liforma player at ${e}. The embed did not load; check your network connection and player URL configuration.`}async function A(e,t){try{await fetch(e,{method:`GET`,mode:`no-cors`,signal:AbortSignal.timeout(8e3)})}catch{throw Error(k(t))}}function j(e,t,n,r){try{r&&r.length>0?e.postMessage(t,n,r):e.postMessage(t,n)}catch(e){throw e instanceof DOMException&&e.name===`SecurityError`?Error(k(n),{cause:e}):e}}var M=new Set([1,2]);function ie(e){return typeof e==`number`&&M.has(e)}var ae=new Set([`close`,`stateUpdate`,`commandResult`,`userTranscript`,`characterSpeechStarted`,`characterSpeechEnded`,`conversationUpdate`,`listeningState`,`userSpeechStarted`,`userSpeechEnded`,`modeChange`,`activityChange`,`message`,`started`,`widgetReady`,`widgetExpand`,`widgetCollapse`,`widgetAudioSettings`,`widgetDragStart`,`widgetDragMove`,`widgetDragEnd`]);function N(e){if(!e||typeof e!=`object`)return null;let t=e;if(!ie(t.schemaVersion)||!t.type||!ae.has(t.type))return null;if(t.type===`widgetReady`||t.type===`widgetExpand`||t.type===`widgetCollapse`)return t;if(t.type===`widgetAudioSettings`){let e=t.payload;return!e||typeof e!=`object`||typeof e.open!=`boolean`?null:t}if(t.type===`widgetDragStart`||t.type===`widgetDragEnd`){let e=t.payload;return!e||typeof e!=`object`||typeof e.pointerId!=`number`||!Number.isFinite(e.pointerId)?null:t}if(t.type===`widgetDragMove`){let e=t.payload;if(!e||typeof e!=`object`)return null;let{pointerId:n,dx:r,dy:i}=e;return typeof n!=`number`||!Number.isFinite(n)||typeof r!=`number`||!Number.isFinite(r)||typeof i!=`number`||!Number.isFinite(i)?null:t}return!t.payload||typeof t.payload!=`object`?null:t}function P(e,t,n){let r=e.trim();if(!r)throw Error(`createLaunchMessage requires a non-empty launch string.`);return{type:`launch`,schemaVersion:2,payload:{launch:r,...t===void 0?{}:{session:t},...n?{startButton:n}:{}}}}function oe(){return{type:`parentHello`,schemaVersion:2}}function se(e){return{type:`widgetSetChrome`,schemaVersion:2,payload:{mode:e}}}function F(){return{type:`widgetToggleAudioSettings`,schemaVersion:2,payload:{}}}function I(e){return e}function L(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`cmd_${crypto.randomUUID().replace(/-/g,``).slice(0,12)}`:`cmd_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}var ce=3e4;function le(e){let t=e.container;getComputedStyle(t).position===`static`&&(t.style.position=`relative`);let n=document.createElement(`iframe`);n.src=e.src,n.title=`Liforma experience`,n.setAttribute(`allow`,`microphone; autoplay; clipboard-read; clipboard-write`),n.style.cssText=e.transparent?`display:block;position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;`:`display:block;position:absolute;inset:0;width:100%;height:100%;border:0;background:#030508;`,e.transparent&&n.setAttribute(`allowtransparency`,`true`);let r=!1,i=new Map,a=new Promise((t,r)=>{let i=()=>{o(),A(e.src,e.playerOrigin).then(t,r)},a=()=>{o(),r(Error(k(e.playerOrigin)))},o=()=>{n.removeEventListener(`load`,i),n.removeEventListener(`error`,a)};n.addEventListener(`load`,i),n.addEventListener(`error`,a)}),o=t=>{if(r||t.source!==n.contentWindow||t.origin!==e.playerOrigin)return;let a=N(t.data);if(a)switch(a.type){case`close`:e.onClose?.(a.payload);break;case`stateUpdate`:e.onPlayerStatusChange?.(a.payload.state),e.onStateUpdate?.(a.payload.state);break;case`commandResult`:{let e=i.get(a.payload.correlationId);if(!e)return;i.delete(a.payload.correlationId),a.payload.ok?e.resolve(a.payload.result):e.reject(Error(a.payload.error??`Command failed.`));break}case`userTranscript`:e.onUserTranscript?.(a.payload);break;case`characterSpeechStarted`:e.onCharacterSpeechStarted?.(a.payload);break;case`characterSpeechEnded`:e.onCharacterSpeechEnded?.(a.payload);break;case`conversationUpdate`:e.onConversationUpdate?.(a.payload.conversation);break;case`listeningState`:e.onListeningState?.(a.payload.listening);break;case`userSpeechStarted`:e.onUserSpeechStarted?.(a.payload);break;case`userSpeechEnded`:e.onUserSpeechEnded?.(a.payload);break;case`modeChange`:e.onActivityChange?.(I(a.payload.mode));break;case`activityChange`:e.onActivityChange?.(a.payload.activity);break;case`message`:e.onMessage?.(a.payload);break;case`started`:e.onStarted?.(a.payload);break;case`widgetReady`:e.onWidgetReady?.();break;case`widgetExpand`:e.onWidgetExpand?.();break;case`widgetCollapse`:e.onWidgetCollapse?.();break;case`widgetAudioSettings`:e.onWidgetAudioSettings?.(a.payload.open);break;case`widgetDragStart`:e.onWidgetDragStart?.(a.payload);break;case`widgetDragMove`:e.onWidgetDragMove?.(a.payload);break;case`widgetDragEnd`:e.onWidgetDragEnd?.(a.payload);break}};if(window.addEventListener(`message`,o),t.replaceChildren(n),t.clientHeight<2&&!t.style.minHeight){let e=getComputedStyle(t).minHeight;(e===`0px`||e===`auto`)&&(t.style.minHeight=`480px`)}let s=(t,i)=>{if(r)return;let a=n.contentWindow;if(!a)throw Error(k(e.playerOrigin));j(a,t,e.playerOrigin,i)},c=(e,t=12e4,n)=>{let r=e.type!==`parentHello`&&e.payload&&`correlationId`in e.payload?e.payload.correlationId:L();return e.type!==`parentHello`&&e.payload&&`correlationId`in e.payload||e.type!==`parentHello`&&e.payload&&(e.payload.correlationId=r),new Promise((a,o)=>{i.set(r,{resolve:e=>a(e),reject:o}),s(e,n),setTimeout(()=>{i.has(r)&&(i.delete(r),o(Error(`Timed out waiting for player command result.`)))},t)})};return{waitForLoad(){return a},postParentHello(){s(oe())},postLaunch(t,i,a){if(r)return;let o=n.contentWindow;if(!o)throw Error(`Liforma embed iframe is not ready.`);let s=P(t,i,a),c=()=>{r||j(o,s,e.playerOrigin)};c();for(let e=1;e<=12;e+=1)window.setTimeout(c,e*75)},postManifest(e){if(typeof e==`string`){this.postLaunch(e);return}if(e&&typeof e==`object`&&typeof e.launch==`string`){let t=String(e.launch),n=e.session;this.postLaunch(t,n);return}throw Error(`postManifest is deprecated; use postLaunch with an opaque launch string from SessionLaunchResponse.`)},postWidgetSetChrome(e){s(se(e))},postWidgetToggleAudioSettings(){s(F())},speak(e){return c({type:`speak`,schemaVersion:2,payload:{correlationId:L(),text:e.text,...e.characterId?{characterId:e.characterId}:{},...e.behavior?{behavior:e.behavior}:{}}})},startListening(){return c({type:`startListening`,schemaVersion:2,payload:{correlationId:L()}})},stopListening(){return c({type:`stopListening`,schemaVersion:2,payload:{correlationId:L()}})},listenOnce(e){return c({type:`listenOnce`,schemaVersion:2,payload:{correlationId:L(),...e?.timeoutMs===void 0?{}:{timeoutMs:e.timeoutMs}}})},async speakProcessorStream(e,t){let n=L(),r=L(),i=(await c({type:`speakStreamStart`,schemaVersion:2,payload:{correlationId:n,...t?.characterId?{characterId:t.characterId}:{},...t?.behavior?{behavior:t.behavior}:{}}})).streamId;try{for await(let n of e){if(t?.signal?.aborted)throw new DOMException(`Processor stream aborted.`,`AbortError`);n&&s({type:`speakStreamChunk`,schemaVersion:2,payload:{streamId:i,text:n}})}if(t?.signal?.aborted)throw new DOMException(`Processor stream aborted.`,`AbortError`);return await c({type:`speakStreamEnd`,schemaVersion:2,payload:{correlationId:r,streamId:i}})}catch(e){try{await c({type:`speakStreamEnd`,schemaVersion:2,payload:{correlationId:r,streamId:i}})}catch{}throw e}},speechPlay(e){let t=L(),n=[];return(e.source.kind===`pcm`||e.source.kind===`encoded`)&&n.push(e.source.data),c({type:`speechPlay`,schemaVersion:2,payload:{correlationId:t,source:e.source,...e.characterId?{characterId:e.characterId}:{},...e.transcript===void 0?{}:{transcript:e.transcript},...e.history?{history:e.history}:{},...e.queue?{queue:e.queue}:{}}},12e4,n)},speechUtteranceBegin(e){return c({type:`speechUtteranceBegin`,schemaVersion:2,payload:{correlationId:L(),utteranceId:e.utteranceId,format:e.format,queue:e.queue,...e.characterId?{characterId:e.characterId}:{},...e.transcript===void 0?{}:{transcript:e.transcript}}})},speechUtteranceWrite(e){return c({type:`speechUtteranceWrite`,schemaVersion:2,payload:{correlationId:L(),utteranceId:e.utteranceId,audio:e.audio,byteLength:e.byteLength}},ce,[e.audio])},speechUtteranceSetTranscript(e){return c({type:`speechUtteranceSetTranscript`,schemaVersion:2,payload:{correlationId:L(),utteranceId:e.utteranceId,transcript:e.transcript}})},speechUtteranceClose(e){return c({type:`speechUtteranceClose`,schemaVersion:2,payload:{correlationId:L(),utteranceId:e.utteranceId,...e.transcript===void 0?{}:{transcript:e.transcript},...e.history?{history:e.history}:{}}})},speechUtteranceCancel(e){return c({type:`speechUtteranceCancel`,schemaVersion:2,payload:{correlationId:L(),utteranceId:e.utteranceId}})},speechInterrupt(e){return c({type:`speechInterrupt`,schemaVersion:2,payload:{correlationId:L(),...e}})},getConversation(){return c({type:`getConversation`,schemaVersion:2,payload:{correlationId:L()}})},destroy(){if(!r){r=!0;for(let e of i.values())e.reject(Error(`Iframe host destroyed.`));i.clear(),window.removeEventListener(`message`,o),n.remove()}}}}function ue(e){let t,n=!1,r=!1,i=()=>{r||!n||t===void 0||(r=!0,e(t))};return{setValue(e){t=e,i()},markReady(){n=!0,i()}}}var de=`https://player.liforma.ai/embed`,fe=`http://localhost:3002/embed`;function R(){let e=globalThis.__LIFORMA_PLAYER_EMBED_URL;if(e?.trim())return e.trim().replace(/\/$/,``);if(typeof document>`u`)return null;let t=(document.querySelector(`script[data-liforma-sdk][src*="client.js"]`)??document.querySelector(`script[src*="/sdk/v2/client.js"]`))?.getAttribute(`data-player-embed-url`)?.trim();return t?t.replace(/\/$/,``):null}function pe(){let e=R();return e?e.endsWith(`/embed`)?e:`${e}/embed`:t()?fe:de}function me(e,t,n,r,i,a,o){let s=(e??pe()).replace(/\/$/,``),c=s.endsWith(`/embed`)?s:`${s}/embed`,l=new URL(c),u=n?.trim();u&&l.searchParams.set(`locationId`,u);let d=r?.trim();return d&&l.searchParams.set(`avatarId`,d),i===`face`&&l.searchParams.set(`fit`,`face`),a===`widget`&&l.searchParams.set(`ui`,`widget`),o&&l.searchParams.set(`close`,`1`),t&&l.searchParams.set(`debug`,`true`),he(l.toString())}function he(e){if(typeof location>`u`)return e;let t=new URL(e);return t.searchParams.set(`parentOrigin`,location.origin),t.toString()}function ge(e){return new URL(e).origin}function z(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`evt_${crypto.randomUUID().replace(/-/g,``).slice(0,12)}`:`evt_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}function _e(e,t,n){return{id:z(),type:e,sessionId:t,timestamp:new Date().toISOString(),data:n}}function ve(){return{ready:new Set,started:new Set,userTranscript:new Set,userSpeechStarted:new Set,userSpeechEnded:new Set,characterSpeechStarted:new Set,characterSpeechEnded:new Set,conversationUpdate:new Set,message:new Set,listeningState:new Set,activityChange:new Set,conversationProcessorError:new Set}}function ye(e,t,n){return e[t].add(n),()=>e[t].delete(n)}function be(e,t,n){for(let r of e[t])r(n)}function xe(e){for(let t of Object.keys(e))e[t].clear()}function B(e){return`data`in e&&`format`in e&&e.format!=null&&!(`track`in e)}function V(e){return`url`in e&&typeof e.url==`string`}function H(e){if(!(`track`in e))return!1;let t=e.track;return typeof t!=`object`||!t?!1:typeof MediaStreamTrack<`u`&&t instanceof MediaStreamTrack?!0:`kind`in t&&`readyState`in t}function Se(e){return!B(e)&&!V(e)&&!H(e)&&`encoding`in e&&typeof e.encoding==`string`}var Ce=[8e3,16e3,22050,24e3,44100,48e3],U={MAX_CHUNK_BYTES:64*1024,RECOMMENDED_CHUNK_MS_MIN:20,RECOMMENDED_CHUNK_MS_MAX:200,MAX_BUFFERED_AUDIO_MS:8e3,PLAYBACK_JITTER_BUFFER_MS:150,PLAYBACK_JITTER_BUFFER_MS_MIN:80,PLAYBACK_JITTER_BUFFER_MS_MAX:250,MAX_UTTERANCE_DURATION_MS:9e4,MAX_PENDING_WRITES:8,DEFAULT_WRITE_TIMEOUT_MS:5e3},we=class extends Error{operation;requiredCapability;name=`UnsupportedSpeechOperationError`;constructor(e,t){super(`Speech operation "${e}" requires capability "${t}".`),this.operation=e,this.requiredCapability=t}},W=class extends Error{name=`SpeechUtteranceClosedError`;constructor(e=`Cannot write to a closed or cancelled speech utterance.`){super(e)}},G=class extends Error{name=`SpeechRuntimeError`;constructor(e,t){super(e,t)}},Te=class extends Error{name=`SpeechBufferTimeoutError`;constructor(e=`Timed out waiting for speech buffer capacity.`){super(e)}};function Ee(e=`none`){return{mode:e,trackedDurationMs:0,fallbackDurationMs:0}}function K(e){return Ce.includes(e)}function De(e){if(e.encoding!==`pcm_s16le`)throw new G(`Unsupported audio encoding: ${e.encoding}`);if(e.channels!==1)throw new G(`Unsupported channel count: ${e.channels}`);if(!K(e.sampleRate))throw new G(`Unsupported sample rate: ${e.sampleRate}`)}function q(e){if(B(e)){De(e.format);return}if(V(e)){if(!e.url.trim())throw new G(`Audio URL must be non-empty.`);if(e.sampleRate!==void 0&&!K(e.sampleRate))throw new G(`Unsupported sample rate: ${e.sampleRate}`);return}if(H(e)){if(e.track.kind!==`audio`)throw new G(`speech.play track must be an audio MediaStreamTrack.`);if(e.sampleRate!==void 0&&!K(e.sampleRate))throw new G(`Unsupported sample rate: ${e.sampleRate}`);return}if(Se(e)){let t=e.encoding.trim().toLowerCase();if(!t)throw new G(`Encoded audio MIME type is required.`);if(t===`pcm_s16le`)throw new G(`Use format: { encoding: "pcm_s16le", … } for raw PCM.`);if(e.sampleRate!==void 0&&!K(e.sampleRate))throw new G(`Unsupported sample rate: ${e.sampleRate}`);return}throw new G(`Unsupported speech.play audio shape.`)}function Oe(e){if(e.format)return De(e.format),e.format;if(e.track){let t={encoding:`pcm_s16le`,sampleRate:e.sampleRate??24e3,channels:1};return De(t),t}throw new G(`createUtterance requires format or track.`)}function J(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function ke(e){return e===`replace-active`||e===`replace-all`?`interrupt`:`enqueue`}function Ae(e){let t=new Uint8Array(e.length*2),n=new DataView(t.buffer);for(let t=0;t<e.length;t++){let r=Math.max(-1,Math.min(1,e[t]));n.setInt16(t*2,r<0?r*32768:r*32767,!0)}return t}function je(e,t,n,r,i){let a=-.5*e+1.5*t-1.5*n+.5*r,o=e-2.5*t+2*n-.5*r,s=-.5*e+.5*n,c=t;return((a*i+o)*i+s)*i+c}function Me(e,t){if(!(e>0)||!(t>0))throw Error(`Resampler rates must be positive`);if(e===t)return{fromRate:e,toRate:t,push(e){return e},flush(){return new Float32Array}};let n=e/t,r=new Float32Array,i=0;return{fromRate:e,toRate:t,push(e){if(e.length===0)return new Float32Array;let t=new Float32Array(r.length+e.length);if(t.set(r),t.set(e,r.length),r=t,r.length<4)return new Float32Array;let a=[];for(;i+2<r.length-1;){let e=Math.floor(i),t=i-e,o=Math.max(0,e-1),s=Math.min(r.length-1,e+1),c=Math.min(r.length-1,e+2);a.push(je(r[o],r[e],r[s],r[c],t)),i+=n}let o=Math.max(0,Math.floor(i)-1);return o>0&&(r=r.subarray(o),i-=o),a.length?Float32Array.from(a):new Float32Array},flush(){return r.length===0?new Float32Array:(r=new Float32Array,i=0,new Float32Array)}}}var Ne=`liforma-pcm-capture`,Pe=`
65
2
  class LiformaPcmCaptureProcessor extends AudioWorkletProcessor {
66
3
  process(inputs) {
67
4
  const ch = inputs[0] && inputs[0][0];
@@ -73,8 +10,8 @@ class LiformaPcmCaptureProcessor extends AudioWorkletProcessor {
73
10
  return true;
74
11
  }
75
12
  }
76
- registerProcessor('${ls}', LiformaPcmCaptureProcessor);
77
- `,ds=null;function fs(){return ds||=URL.createObjectURL(new Blob([us],{type:`application/javascript`})),ds}function ps(){return window.AudioContext||window.webkitAudioContext||null}async function ms(e){let{mediaStream:t,targetSampleRate:n,onPcm:r,shouldSend:i,onLog:a}=e,o=ps();if(!o)throw Error(`Web Audio is required for audio capture`);let s=new o,c=s.createMediaStreamSource(t),l=s.createGain();l.gain.value=0;let u=s.sampleRate,d=cs(u,n),f=!1,p=!1,m=e=>{if(f||i&&!i())return;let t=d.push(e);t.length!==0&&r(os(t))},h=()=>void 0;return await(async()=>{if(typeof s.audioWorklet?.addModule!=`function`)return!1;try{await s.audioWorklet.addModule(fs());let e=new AudioWorkletNode(s,ls,{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1]});return e.port.onmessage=e=>{e.data instanceof Float32Array&&m(e.data)},c.connect(e),e.connect(l),l.connect(s.destination),h=()=>{e.port.onmessage=null;try{e.disconnect()}catch{}try{c.disconnect()}catch{}try{l.disconnect()}catch{}},p=!0,!0}catch{return!1}})()?a?.(`Mic/track capture via AudioWorklet at ${u} Hz → ${n} Hz`):((()=>{let e=s.createScriptProcessor?.bind(s);if(!e)throw Error(`Neither AudioWorklet nor ScriptProcessor is available`);let t=e(4096,1,1);t.onaudioprocess=e=>{m(e.inputBuffer.getChannelData(0))},c.connect(t),t.connect(l),l.connect(s.destination),h=()=>{t.onaudioprocess=null;try{t.disconnect()}catch{}try{c.disconnect()}catch{}try{l.disconnect()}catch{}},p=!1})(),a?.(`Mic/track capture via ScriptProcessor at ${u} Hz → ${n} Hz`,`warn`)),s.state===`suspended`&&await s.resume().catch(()=>void 0),{fromSampleRate:u,usingWorklet:p,stop(){f||(f=!0,d.flush(),h(),s.close().catch(()=>void 0))}}}async function hs(e){let{track:t,utterance:n,sampleRate:r,signal:i}=e;if(typeof MediaStreamTrack>`u`||!(t instanceof MediaStreamTrack))throw new Q(`MediaStreamTrack is not available in this environment.`);if(t.kind!==`audio`)throw new Q(`speech.play track must be an audio MediaStreamTrack.`);if(t.readyState===`ended`||i?.aborted)return;let a=new MediaStream([t]),o=Promise.resolve(),s=!1,c=null,l=()=>{s||(s=!0,c?.stop(),c=null)};try{c=await ms({mediaStream:a,targetSampleRate:r,shouldSend:()=>!s&&!i?.aborted,onPcm:e=>{if(s||i?.aborted)return;let t=is(e);o=o.then(async()=>{if(s||i?.aborted)return;let e=0;for(;e<t.byteLength;){let r=Math.min(e+Yo.MAX_CHUNK_BYTES,t.byteLength);if((r-e)%2==1&&--r,r<=e)break;let i=t.subarray(e,r);e=r,i.byteLength!==0&&await n.write(i)}}).catch(()=>{l()})}})}catch(e){throw l(),new Q(`MediaStreamTrack capture failed: ${e instanceof Error?e.message:String(e)}`)}await new Promise(e=>{let r=()=>{l(),o.finally(e)};t.addEventListener(`ended`,r,{once:!0}),i?.addEventListener(`abort`,()=>{n.cancel().catch(()=>void 0),r()},{once:!0}),(t.readyState===`ended`||i?.aborted)&&r()})}async function gs(e,t){if(Ko(e))throw new Q(`MediaStreamTrack play is handled on the host before embed.`);if(Wo(e)){let t=is(e.data);if(t.byteLength&1)throw new Q(`PCM byte length must be even.`);return{kind:`pcm`,data:t.slice().buffer,format:e.format}}if(Go(e))return{kind:`url`,url:e.url.trim(),...e.sampleRate===void 0?{}:{sampleRate:e.sampleRate}};if(!qo(e))throw new Q(`Unsupported speech.play audio shape.`);let n;if(typeof Blob<`u`&&e.data instanceof Blob){if(t?.aborted)throw new DOMException(`Play aborted.`,`AbortError`);n=new Uint8Array(await e.data.arrayBuffer())}else n=is(e.data);return{kind:`encoded`,data:n.slice().buffer,encoding:e.encoding.trim(),...e.sampleRate===void 0?{}:{sampleRate:e.sampleRate}}}function _s(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`utt_${crypto.randomUUID().replace(/-/g,``).slice(0,12)}`:`utt_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}function vs(e,t=`completed`){return{utteranceId:e.speechId,characterId:e.characterId,status:t,durationMs:e.durationMs,transcript:e.text,animation:{mode:`tracked`,trackedDurationMs:e.durationMs,fallbackDurationMs:0}}}function ys(e){return e instanceof Error?e:new Q(String(e))}function bs(e){return e instanceof DOMException&&e.name===`AbortError`||e instanceof Error&&e.name===`AbortError`}var xs=class{id;characterId;result;format;host;signal;settleResolve;settleReject;settled=!1;closed=!1;writeChain=Promise.resolve();pendingWriteCount=0;pendingWriteWaiters=[];bufferedMs=0;sampleRate;beginPromise;constructor(e){this.id=e.id,this.characterId=e.characterId,this.format=e.format,this.host=e.host,this.signal=e.signal,this.sampleRate=e.format.sampleRate,this.result=new Promise((e,t)=>{this.settleResolve=e,this.settleReject=t}),this.result.catch(()=>void 0);let t=this.requireHost();this.beginPromise=t.speechUtteranceBegin({utteranceId:this.id,format:this.format,characterId:this.characterId,queue:e.queue,...e.transcript===void 0?{}:{transcript:e.transcript}}).catch(e=>{throw this.fail(ys(e)),ys(e)}),this.signal?.addEventListener(`abort`,()=>{this.cancel()},{once:!0})}async write(e,t){if(this.closed||this.settled||(await this.beginPromise.catch(()=>void 0),this.closed||this.settled))throw new Zo;let n=is(e);if(n.byteLength&1)throw new Q(`PCM chunk byte length must be even (complete s16 samples).`);if(n.byteLength>Yo.MAX_CHUNK_BYTES)throw new Q(`PCM chunk exceeds MAX_CHUNK_BYTES (${Yo.MAX_CHUNK_BYTES}).`);if(n.byteLength===0)return;let r=t?.timeoutMs??Yo.DEFAULT_WRITE_TIMEOUT_MS;await this.acquireWriteSlot(r);let i=n.byteLength/2/this.sampleRate*1e3;if(this.bufferedMs+i>Yo.MAX_UTTERANCE_DURATION_MS)throw this.releaseWriteSlot(),new Q(`Utterance exceeds MAX_UTTERANCE_DURATION_MS.`);let a=async()=>{if(this.closed||this.settled)throw new Zo;let e=this.requireHost(),t=n.slice(),i=e.speechUtteranceWrite({utteranceId:this.id,audio:t.buffer,byteLength:t.byteLength}),a=await Promise.race([i,new Promise((e,t)=>{setTimeout(()=>t(new Qo),r)})]);this.bufferedMs=Math.max(0,a.bufferedMs)},o=this.writeChain.then(a,a);this.writeChain=o.then(()=>void 0,()=>void 0);try{await o}finally{this.releaseWriteSlot()}}async setTranscript(e){if(this.closed||this.settled||(await this.beginPromise.catch(()=>void 0),this.closed||this.settled))throw new Zo;await this.requireHost().speechUtteranceSetTranscript({utteranceId:this.id,transcript:e})}async close(e){if(this.settled)return this.result;this.closed=!0,await this.beginPromise.catch(()=>void 0),await this.writeChain.catch(()=>void 0);try{let t=await this.requireHost().speechUtteranceClose({utteranceId:this.id,transcript:e?.transcript,history:e?.history??`none`});return this.resolve(t),t}catch(e){let t=ys(e);throw this.fail(t),t}}async cancel(){if(this.settled)return this.result;this.closed=!0;try{let e=this.host.getIframeHost();if(e){let t=await e.speechUtteranceCancel({utteranceId:this.id});return this.resolve(t),t}let t={utteranceId:this.id,characterId:this.characterId,status:`cancelled`,durationMs:0,animation:$o(`none`)};return this.resolve(t),t}catch(e){let t=ys(e);throw this.fail(t),t}}adoptExternalResult(e){this.resolve(e)}requireHost(){let e=this.host.getIframeHost();if(!e)throw new Q(`Speech session is not attached.`);return e}resolve(e){this.settled||(this.settled=!0,this.settleResolve(Object.freeze(e)),this.flushWriteWaiters(new Zo))}fail(e){this.settled||(this.settled=!0,this.settleReject(e),this.flushWriteWaiters(e))}async acquireWriteSlot(e){if(this.pendingWriteCount<Yo.MAX_PENDING_WRITES){this.pendingWriteCount+=1;return}await new Promise((t,n)=>{let r=setTimeout(()=>{n(new Qo)},e);this.pendingWriteWaiters.push({resolve:()=>{clearTimeout(r),this.pendingWriteCount+=1,t()},reject:e=>{clearTimeout(r),n(e)}})})}releaseWriteSlot(){this.pendingWriteCount=Math.max(0,this.pendingWriteCount-1),this.pendingWriteWaiters.shift()?.resolve()}flushWriteWaiters(e){for(;this.pendingWriteWaiters.length>0;)this.pendingWriteWaiters.shift()?.reject(e)}};function Ss(e){let t=null,n=(t,n)=>{if(!e.getCapabilities()[n])throw new Xo(t,n)},r={async speak(r){if(e.assertSessionStarted(),n(`speak`,`textSpeech`),r.signal?.aborted)throw new DOMException(`Speak aborted.`,`AbortError`);let i=as(r.queue??`append`);i===`interrupt`&&(e.onProcessorInterrupt?.(),t&&=(t.cancel(),null));let a=e.getIframeHost();if(!a)throw new Q(`Speech session is not attached.`);let o=a.speak({text:r.text,characterId:r.characterId,behavior:i});if(r.signal){let t=r.signal;return await new Promise((n,i)=>{let s=()=>{a.speechInterrupt({scope:`active`}).catch(()=>void 0),i(new DOMException(`Speak aborted.`,`AbortError`))};if(t.aborted){s();return}t.addEventListener(`abort`,s,{once:!0}),o.then(e=>{t.removeEventListener(`abort`,s),n(vs(e,`completed`))},a=>{if(t.removeEventListener(`abort`,s),bs(a)){n({utteranceId:`utt_interrupted`,characterId:r.characterId??e.getActiveCharacterId(),status:`interrupted`,durationMs:0,transcript:r.text,animation:$o(`none`)});return}i(ys(a))})})}try{return vs(await o,`completed`)}catch(t){if(bs(t))return{utteranceId:`utt_interrupted`,characterId:r.characterId??e.getActiveCharacterId(),status:`interrupted`,durationMs:0,transcript:r.text,animation:$o(`none`)};throw ys(t)}},async play(i){if(e.assertSessionStarted(),n(`play`,`externalSpeechAudio`),ns(i.audio),i.signal?.aborted)throw new DOMException(`Play aborted.`,`AbortError`);let a=i.queue??`append`;if((a===`replace-active`||a===`replace-all`)&&(e.onProcessorInterrupt?.(),t&&=(t.cancel(),null)),Ko(i.audio)){let e=i.audio.sampleRate??24e3;return r.createUtterance({format:{encoding:`pcm_s16le`,sampleRate:e,channels:1},track:i.audio.track,characterId:i.characterId,queue:a===`append`?`replace-active`:a,signal:i.signal}).result}let o=e.getIframeHost();if(!o)throw new Q(`Speech session is not attached.`);let s=await gs(i.audio,i.signal);return o.speechPlay({source:s,characterId:i.characterId,transcript:i.transcript,history:i.history??`none`,queue:a,signal:i.signal})},createUtterance(r){e.assertSessionStarted(),n(`createUtterance`,`externalSpeechAudio`);let i=rs(r);if(r.track&&r.track.kind!==`audio`)throw new Q(`createUtterance track must be an audio MediaStreamTrack.`);let a=r.queue??`replace-active`;if(a!==`replace-active`&&a!==`replace-all`)throw new Q(`createUtterance queue must be replace-active or replace-all.`);e.onProcessorInterrupt?.(),t&&=(t.cancel(),null);let o=new xs({id:_s(),characterId:r.characterId??e.getActiveCharacterId(),format:i,queue:a,host:e,...r.transcript===void 0?{}:{transcript:r.transcript},signal:r.signal});return t=o,o.result.finally(()=>{t===o&&(t=null)}),r.track&&(async()=>{try{if(await hs({track:r.track,utterance:o,sampleRate:i.sampleRate,signal:r.signal}),r.signal?.aborted)return;await o.close({history:`none`})}catch{await o.cancel().catch(()=>void 0)}})(),o},async interrupt(n){e.assertSessionStarted(),e.onProcessorInterrupt?.();let r=e.getIframeHost();if(!r)return[];let i=await r.speechInterrupt(n??{scope:`active`});if(t){let e=i.find(e=>e.utteranceId===t.id);e&&t.adoptExternalResult(e),t=null}return i}};return r}function Cs(e,t){return t?so({...e,experience:{...e.experience,startButton:t}}):e}var ws=class e{launch;conversationProcessor;iframeHost=null;attachInFlight=null;endpointAbortController=null;processorAbortController=null;processorChain=Promise.resolve();resolvedManifest;closed=!1;attached=!1;closeHandlers=[];eventRegistry=Vo();readyEvent=null;startedEvent=null;conversationCache=[];speech;constructor(e){this.launch=e,this.conversationProcessor=e.conversationProcessor??null,this.resolvedManifest=e.kind===`manifest`?e.manifest:null,this.speech=Ss({getIframeHost:()=>this.iframeHost,assertSessionStarted:()=>this.assertSessionStarted(),getCapabilities:()=>Ts(this.resolvedManifest),getActiveCharacterId:()=>this.resolvedManifest?.activeCharacterId??`character_unknown`,onProcessorInterrupt:()=>{this.processorAbortController?.abort(),this.processorAbortController=null}})}static async startSession(t){if(`sessionEndpoint`in t)return new e({kind:`sessionEndpoint`,experienceId:t.experienceId,sessionEndpoint:t.sessionEndpoint,language:t.language,locationId:t.locationId,avatarId:t.avatarId,embedBaseUrl:t.embedBaseUrl,debug:t.debug,mode:t.mode,responseMode:t.responseMode,speechInputMode:t.speechInputMode,startButton:t.startButton,speechOnly:t.speechOnly,fit:t.fit,ui:t.ui,onStart:t.onStart,onUserTranscript:t.onUserTranscript,conversationProcessor:t.conversationProcessor});if(`experienceId`in t)return new e({kind:`public`,experienceId:t.experienceId,language:t.language,locationId:t.locationId,avatarId:t.avatarId,embedBaseUrl:t.embedBaseUrl,debug:t.debug,mode:t.mode,responseMode:t.responseMode,speechInputMode:t.speechInputMode,startButton:t.startButton,speechOnly:t.speechOnly,fit:t.fit,ui:t.ui,onStart:t.onStart,onUserTranscript:t.onUserTranscript,conversationProcessor:t.conversationProcessor});let n=so(t.manifest);if(co(n)&&!t.acceptCredentialExposure)throw Error(`Credential-bearing Session Manifest requires acceptCredentialExposure: true. Prefer experienceId, sessionEndpoint, or client-side mint instead of SSR page data.`);return new e({kind:`manifest`,manifest:t.speechOnly?Bo(n):n,embedBaseUrl:t.embedBaseUrl,debug:t.debug,startButton:t.startButton,speechOnly:t.speechOnly,fit:t.fit,ui:t.ui,onStart:t.onStart,onUserTranscript:t.onUserTranscript,conversationProcessor:t.conversationProcessor})}getManifest(){return this.resolvedManifest}on(e,t){let n=Ho(this.eventRegistry,e,t);return e===`ready`&&this.readyEvent&&queueMicrotask(()=>t(this.readyEvent)),e===`started`&&this.startedEvent&&queueMicrotask(()=>t(this.startedEvent)),n}async attach(e){if(this.closed)throw Error(`Session has ended.`);if(!e.container)throw Error(`Experience.attach requires a DOM container element.`);return this.attached&&this.iframeHost?this.createPlayerFacade():(this.attachInFlight||=this.attachInternal(e).finally(()=>{this.attachInFlight=null}),this.attachInFlight)}async attachInternal(e){if(this.closed)throw Error(`Session has ended.`);if(this.attached&&this.iframeHost)return this.createPlayerFacade();this.iframeHost&&=(this.iframeHost.destroy(),null);let t=this.launch.embedBaseUrl??Fo(),n=this.launch.debug===!0,r=this.launch.speechOnly===!0,i=Io(t,n,r||this.launch.kind===`manifest`?void 0:this.launch.locationId,r||this.launch.kind===`manifest`?void 0:this.launch.avatarId,this.launch.fit,this.launch.ui,e.showClose===!0),a=Ro(i),o=null,s=new Promise(e=>{o=e}),c=null,l=new Promise(e=>{c=e}),u=jo(e=>{this.readyEvent||(this.readyEvent={manifest:e},Z(this.eventRegistry,`ready`,this.readyEvent))}),d=this.launch.onUserTranscript,f=Ao({container:e.container,src:i,playerOrigin:a,transparent:this.launch.ui===`widget`,onClose:e=>{for(let t of this.closeHandlers)t(e)},onStateUpdate:t=>{e.onStateUpdate?.(t),t===`loading`&&o&&(o(),o=null),t===`ready`&&c&&(c(),c=null),t===`ready`&&u.markReady()},onUserTranscript:e=>{Z(this.eventRegistry,`userTranscript`,e),d?.(e),this.queueProcessorTurn(e)},onUserSpeechStarted:e=>{Z(this.eventRegistry,`userSpeechStarted`,e)},onUserSpeechEnded:e=>{Z(this.eventRegistry,`userSpeechEnded`,e)},onCharacterSpeechStarted:e=>{Z(this.eventRegistry,`characterSpeechStarted`,e)},onCharacterSpeechEnded:e=>{Z(this.eventRegistry,`characterSpeechEnded`,e)},onListeningState:e=>{Z(this.eventRegistry,`listeningState`,e)},onModeChange:e=>{Z(this.eventRegistry,`modeChange`,e)},onMessage:e=>{Z(this.eventRegistry,`message`,e)},onStarted:e=>{this.startedEvent||(this.startedEvent=e,Z(this.eventRegistry,`started`,e),this.launch.onStart?.(e))},onConversationUpdate:e=>{this.conversationCache=e,Z(this.eventRegistry,`conversationUpdate`,e)},onWidgetReady:()=>e.onWidgetReady?.(),onWidgetExpand:()=>e.onWidgetExpand?.(),onWidgetCollapse:()=>e.onWidgetCollapse?.(),onWidgetAudioSettings:t=>e.onWidgetAudioSettings?.(t),onWidgetDragStart:t=>e.onWidgetDragStart?.(t),onWidgetDragMove:t=>e.onWidgetDragMove?.(t),onWidgetDragEnd:t=>e.onWidgetDragEnd?.(t)});this.iframeHost=f;let p=this.resolveMintInteraction(),m=this.launch.kind===`sessionEndpoint`?(this.endpointAbortController=new AbortController,po(this.launch.sessionEndpoint,{experienceId:this.launch.experienceId,language:this.launch.language,mode:p.mode,responseMode:p.responseMode,speechInputMode:p.speechInputMode,startButton:this.launch.startButton,speechOnly:this.launch.speechOnly,signal:this.endpointAbortController.signal})):this.launch.kind===`public`?fo(this.launch.experienceId,{language:this.launch.language,mode:p.mode,responseMode:p.responseMode,speechInputMode:p.speechInputMode,startButton:this.launch.startButton,speechOnly:this.launch.speechOnly}):Promise.resolve(this.launch.kind===`manifest`?this.launch.manifest:null),h;try{[,h]=await Promise.all([f.waitForLoad(),m])}catch(e){throw f.destroy(),this.iframeHost===f&&(this.iframeHost=null),e}finally{this.endpointAbortController=null}if(f.postParentHello(),h){let e=Cs(h,this.launch.startButton);this.launch.speechOnly&&(e=Bo(e)),this.assertBrowserCustomManifest(e),this.resolvedManifest=e,f.postManifest(e),u.setValue(e)}return await Promise.race([s,new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out waiting for player loading UI.`)),12e4)})]),await Promise.race([l,new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out waiting for player ready state.`)),12e4)})]),this.attached=!0,this.createPlayerFacade()}async startListening(){this.assertSessionStarted(),await this.iframeHost.startListening()}async stopListening(){return this.assertSessionStarted(),this.iframeHost.stopListening()}async listenOnce(e){return this.assertSessionStarted(),this.iframeHost.listenOnce({timeoutMs:e?.timeoutMs})}getConversation(){return this.conversationCache}setWidgetChrome(e){this.iframeHost?.postWidgetSetChrome(e)}toggleAudioSettings(){this.iframeHost?.postWidgetToggleAudioSettings()}getLastTurn(){if(this.conversationCache.length===0)return[];let e=this.conversationCache[this.conversationCache.length-1].turnId;return this.conversationCache.filter(t=>t.turnId===e)}async end(){this.close()}destroy(){this.closed||(this.closed=!0,this.processorAbortController?.abort(),this.processorAbortController=null,this.endpointAbortController?.abort(),this.endpointAbortController=null,this.attachInFlight=null,this.iframeHost?.destroy(),this.iframeHost=null,Uo(this.eventRegistry),this.readyEvent=null,this.startedEvent=null,this.closeHandlers.length=0,this.attached=!1)}resolveMintInteraction(){if(this.launch.kind===`manifest`)return{};let e=this.conversationProcessor!==null;return{mode:this.launch.mode,responseMode:e?`custom`:this.launch.responseMode,speechInputMode:this.launch.speechInputMode}}assertBrowserCustomManifest(e){if(this.conversationProcessor){if(e.experience.responseMode!==`custom`)throw Error(`conversationProcessor requires responseMode custom in the Session Manifest.`);if(e.processorId)throw Error(`Browser conversationProcessor cannot be used with a registered processorId.`)}}queueProcessorTurn(e){if(!e.isFinal||!e.text.trim()||!this.conversationProcessor)return;let t=this.conversationProcessor;this.processorAbortController?.abort(),this.processorAbortController=new AbortController;let n=this.processorAbortController.signal;this.processorChain=this.processorChain.then(async()=>{if(!n.aborted)try{let r=await go(t,{utteranceId:e.utteranceId,text:e.text,conversation:this.conversationCache,signal:n});if(n.aborted)return;if(r.kind===`complete`){let e=r.speech;await this.speech.speak({text:e.text,...e.characterId?{characterId:e.characterId}:{},queue:e.behavior===`interrupt`?`replace-active`:`append`});return}await this.iframeHost.speakProcessorStream(r.stream,{signal:n})}catch(t){if(n.aborted)return;let r=t instanceof Error?t.message:String(t);Z(this.eventRegistry,`conversationProcessorError`,{utteranceId:e.utteranceId,message:r})}})}assertAttached(){if(!this.attached||!this.iframeHost)throw Error(`Call Experience.attach() before using speech APIs.`)}assertSessionStarted(){if(this.assertAttached(),!this.startedEvent)throw Error(`Session has not started. Wait for the player start button and the started event before using speak() or listening APIs.`)}close(){this.closed||(this.closed=!0,this.endpointAbortController?.abort(),this.endpointAbortController=null,this.attachInFlight=null,this.iframeHost?.destroy(),this.iframeHost=null,this.attached=!1)}createPlayerFacade(){return{close:()=>{this.close()},destroy:()=>{this.destroy()},on:(e,t)=>{e===`close`&&this.closeHandlers.push(t)}}}};function Ts(e){let t=e?.capabilities??[],n=t.includes(`textSpeech`),r=t.includes(`externalSpeechAudio`);return!n&&!r?{textSpeech:!0,externalSpeechAudio:!0}:{textSpeech:n,externalSpeechAudio:r}}function Es(e,t){let n=e.trim();if(!n)return null;if(/^https?:\/\//i.test(n))try{return new URL(n)}catch{return null}let r=t.replace(/\/$/,``),i=n.startsWith(`/`)?n:`/${n}`;try{return new URL(i,`${r}/`)}catch{return null}}function Ds(e){try{if(document.referrer){let e=new URL(document.referrer);if(e.origin===window.location.origin&&e.pathname!==window.location.pathname)return`${e.pathname}${e.search}${e.hash}`}}catch{}return e}function Os(e,t=`/meet`){if(e.reason!==`user`)return;let n=Es(e.returnUrl?.trim()||Ds(t),window.location.origin);n?.protocol.startsWith(`http`)&&window.location.assign(n.toString())}var ks=/\b(exp_[A-Za-z0-9][A-Za-z0-9_-]{2,127})\b/,As=/(?:Your origin|origin)\s+(\S+)\s+is not an allowed origin/i;function js(e){return e instanceof Error?e.message:String(e)}function Ms(){try{if(typeof globalThis.location?.origin==`string`&&globalThis.location.origin)return globalThis.location.origin}catch{}}function Ns(e){return ks.exec(e)?.[1]}function Ps(e){return As.exec(e)?.[1]}function Fs(e,t){let n=js(e).trim()||`Unknown error`,r=t?.experienceId?.trim()||Ns(n)||void 0,i=t?.origin?.trim()||Ps(n)||Ms()||void 0;return/No playable experience found/i.test(n)||/^Experience is not available\.?$/i.test(n)||/^Unknown experience\.?$/i.test(n)||/experience_unavailable/i.test(n)?{kind:`not_found`,title:`The application tried to load an avatar experience that doesn’t exist.`,detail:`Experience with id ${r??`the requested experience`} does not exist`,technicalMessage:n,experienceId:r,origin:i}:/origin_not_allowed/i.test(n)||/is not an allowed origin/i.test(n)||/^Origin not allowed/i.test(n)?{kind:`origin_not_allowed`,title:`The application tried to load an avatar experience from a website that isn’t allowed.`,detail:`Origin ${i??`this page`} is not allowed for experience ${r??`the requested experience`}`,technicalMessage:n,experienceId:r,origin:i}:/browser_embeds_disabled/i.test(n)||/^Browser embeds are not enabled/i.test(n)?{kind:`browser_embeds_disabled`,title:`The application tried to load an avatar experience that isn’t enabled for browser embeds.`,detail:`Browser embeds are not enabled for experience ${r??`the requested experience`}`,technicalMessage:n,experienceId:r,origin:i}:{kind:`generic`,title:`This avatar experience couldn’t be started.`,detail:n,technicalMessage:n,experienceId:r,origin:i}}var Is=`liforma-experience-load-error-styles`;function Ls(){if(typeof document>`u`||document.getElementById(`liforma-experience-load-error-styles`))return;let e=document.createElement(`style`);e.id=Is,e.textContent=Rs,document.head.append(e)}var Rs=`
13
+ registerProcessor('${Ne}', LiformaPcmCaptureProcessor);
14
+ `,Fe=null;function Ie(){return Fe||=URL.createObjectURL(new Blob([Pe],{type:`application/javascript`})),Fe}function Le(){return window.AudioContext||window.webkitAudioContext||null}async function Re(e){let{mediaStream:t,targetSampleRate:n,onPcm:r,shouldSend:i,onLog:a}=e,o=Le();if(!o)throw Error(`Web Audio is required for audio capture`);let s=new o,c=s.createMediaStreamSource(t),l=s.createGain();l.gain.value=0;let u=s.sampleRate,d=Me(u,n),f=!1,p=!1,m=e=>{if(f||i&&!i())return;let t=d.push(e);t.length!==0&&r(Ae(t))},h=()=>void 0;return await(async()=>{if(typeof s.audioWorklet?.addModule!=`function`)return!1;try{await s.audioWorklet.addModule(Ie());let e=new AudioWorkletNode(s,Ne,{numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1]});return e.port.onmessage=e=>{e.data instanceof Float32Array&&m(e.data)},c.connect(e),e.connect(l),l.connect(s.destination),h=()=>{e.port.onmessage=null;try{e.disconnect()}catch{}try{c.disconnect()}catch{}try{l.disconnect()}catch{}},p=!0,!0}catch{return!1}})()?a?.(`Mic/track capture via AudioWorklet at ${u} Hz → ${n} Hz`):((()=>{let e=s.createScriptProcessor?.bind(s);if(!e)throw Error(`Neither AudioWorklet nor ScriptProcessor is available`);let t=e(4096,1,1);t.onaudioprocess=e=>{m(e.inputBuffer.getChannelData(0))},c.connect(t),t.connect(l),l.connect(s.destination),h=()=>{t.onaudioprocess=null;try{t.disconnect()}catch{}try{c.disconnect()}catch{}try{l.disconnect()}catch{}},p=!1})(),a?.(`Mic/track capture via ScriptProcessor at ${u} Hz → ${n} Hz`,`warn`)),s.state===`suspended`&&await s.resume().catch(()=>void 0),{fromSampleRate:u,usingWorklet:p,stop(){f||(f=!0,d.flush(),h(),s.close().catch(()=>void 0))}}}async function ze(e){let{track:t,utterance:n,sampleRate:r,signal:i}=e;if(typeof MediaStreamTrack>`u`||!(t instanceof MediaStreamTrack))throw new G(`MediaStreamTrack is not available in this environment.`);if(t.kind!==`audio`)throw new G(`speech.play track must be an audio MediaStreamTrack.`);if(t.readyState===`ended`||i?.aborted)return;let a=new MediaStream([t]),o=Promise.resolve(),s=!1,c=null,l=()=>{s||(s=!0,c?.stop(),c=null)};try{c=await Re({mediaStream:a,targetSampleRate:r,shouldSend:()=>!s&&!i?.aborted,onPcm:e=>{if(s||i?.aborted)return;let t=J(e);o=o.then(async()=>{if(s||i?.aborted)return;let e=0;for(;e<t.byteLength;){let r=Math.min(e+U.MAX_CHUNK_BYTES,t.byteLength);if((r-e)%2==1&&--r,r<=e)break;let i=t.subarray(e,r);e=r,i.byteLength!==0&&await n.write(i)}}).catch(()=>{l()})}})}catch(e){throw l(),new G(`MediaStreamTrack capture failed: ${e instanceof Error?e.message:String(e)}`)}await new Promise(e=>{let r=()=>{l(),o.finally(e)};t.addEventListener(`ended`,r,{once:!0}),i?.addEventListener(`abort`,()=>{n.cancel().catch(()=>void 0),r()},{once:!0}),(t.readyState===`ended`||i?.aborted)&&r()})}async function Be(e,t){if(H(e))throw new G(`MediaStreamTrack play is handled on the host before embed.`);if(B(e)){let t=J(e.data);if(t.byteLength&1)throw new G(`PCM byte length must be even.`);return{kind:`pcm`,data:t.slice().buffer,format:e.format}}if(V(e))return{kind:`url`,url:e.url.trim(),...e.sampleRate===void 0?{}:{sampleRate:e.sampleRate}};if(!Se(e))throw new G(`Unsupported speech.play audio shape.`);let n;if(typeof Blob<`u`&&e.data instanceof Blob){if(t?.aborted)throw new DOMException(`Play aborted.`,`AbortError`);n=new Uint8Array(await e.data.arrayBuffer())}else n=J(e.data);return{kind:`encoded`,data:n.slice().buffer,encoding:e.encoding.trim(),...e.sampleRate===void 0?{}:{sampleRate:e.sampleRate}}}function Ve(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`utt_${crypto.randomUUID().replace(/-/g,``).slice(0,12)}`:`utt_${Date.now().toString(36)}${Math.random().toString(36).slice(2,8)}`}function He(e,t=`completed`){return{utteranceId:e.speechId,characterId:e.characterId,status:t,durationMs:e.durationMs,transcript:e.text,animation:{mode:`tracked`,trackedDurationMs:e.durationMs,fallbackDurationMs:0}}}function Y(e){return e instanceof Error?e:new G(String(e))}function Ue(e){return e instanceof DOMException&&e.name===`AbortError`||e instanceof Error&&e.name===`AbortError`}var We=class{id;characterId;result;format;host;signal;settleResolve;settleReject;settled=!1;closed=!1;writeChain=Promise.resolve();pendingWriteCount=0;pendingWriteWaiters=[];bufferedMs=0;sampleRate;beginPromise;constructor(e){this.id=e.id,this.characterId=e.characterId,this.format=e.format,this.host=e.host,this.signal=e.signal,this.sampleRate=e.format.sampleRate,this.result=new Promise((e,t)=>{this.settleResolve=e,this.settleReject=t}),this.result.catch(()=>void 0);let t=this.requireHost();this.beginPromise=t.speechUtteranceBegin({utteranceId:this.id,format:this.format,characterId:this.characterId,queue:e.queue,...e.transcript===void 0?{}:{transcript:e.transcript}}).catch(e=>{throw this.fail(Y(e)),Y(e)}),this.signal?.addEventListener(`abort`,()=>{this.cancel()},{once:!0})}async write(e,t){if(this.closed||this.settled||(await this.beginPromise.catch(()=>void 0),this.closed||this.settled))throw new W;let n=J(e);if(n.byteLength&1)throw new G(`PCM chunk byte length must be even (complete s16 samples).`);if(n.byteLength>U.MAX_CHUNK_BYTES)throw new G(`PCM chunk exceeds MAX_CHUNK_BYTES (${U.MAX_CHUNK_BYTES}).`);if(n.byteLength===0)return;let r=t?.timeoutMs??U.DEFAULT_WRITE_TIMEOUT_MS;await this.acquireWriteSlot(r);let i=n.byteLength/2/this.sampleRate*1e3;if(this.bufferedMs+i>U.MAX_UTTERANCE_DURATION_MS)throw this.releaseWriteSlot(),new G(`Utterance exceeds MAX_UTTERANCE_DURATION_MS.`);let a=async()=>{if(this.closed||this.settled)throw new W;let e=this.requireHost(),t=n.slice(),i=e.speechUtteranceWrite({utteranceId:this.id,audio:t.buffer,byteLength:t.byteLength}),a=await Promise.race([i,new Promise((e,t)=>{setTimeout(()=>t(new Te),r)})]);this.bufferedMs=Math.max(0,a.bufferedMs)},o=this.writeChain.then(a,a);this.writeChain=o.then(()=>void 0,()=>void 0);try{await o}finally{this.releaseWriteSlot()}}async setTranscript(e){if(this.closed||this.settled||(await this.beginPromise.catch(()=>void 0),this.closed||this.settled))throw new W;await this.requireHost().speechUtteranceSetTranscript({utteranceId:this.id,transcript:e})}async close(e){if(this.settled)return this.result;this.closed=!0,await this.beginPromise.catch(()=>void 0),await this.writeChain.catch(()=>void 0);try{let t=await this.requireHost().speechUtteranceClose({utteranceId:this.id,transcript:e?.transcript,history:e?.history??`none`});return this.resolve(t),t}catch(e){let t=Y(e);throw this.fail(t),t}}async cancel(){if(this.settled)return this.result;this.closed=!0;try{let e=this.host.getIframeHost();if(e){let t=await e.speechUtteranceCancel({utteranceId:this.id});return this.resolve(t),t}let t={utteranceId:this.id,characterId:this.characterId,status:`cancelled`,durationMs:0,animation:Ee(`none`)};return this.resolve(t),t}catch(e){let t=Y(e);throw this.fail(t),t}}adoptExternalResult(e){this.resolve(e)}requireHost(){let e=this.host.getIframeHost();if(!e)throw new G(`Speech session is not attached.`);return e}resolve(e){this.settled||(this.settled=!0,this.settleResolve(Object.freeze(e)),this.flushWriteWaiters(new W))}fail(e){this.settled||(this.settled=!0,this.settleReject(e),this.flushWriteWaiters(e))}async acquireWriteSlot(e){if(this.pendingWriteCount<U.MAX_PENDING_WRITES){this.pendingWriteCount+=1;return}await new Promise((t,n)=>{let r=setTimeout(()=>{n(new Te)},e);this.pendingWriteWaiters.push({resolve:()=>{clearTimeout(r),this.pendingWriteCount+=1,t()},reject:e=>{clearTimeout(r),n(e)}})})}releaseWriteSlot(){this.pendingWriteCount=Math.max(0,this.pendingWriteCount-1),this.pendingWriteWaiters.shift()?.resolve()}flushWriteWaiters(e){for(;this.pendingWriteWaiters.length>0;)this.pendingWriteWaiters.shift()?.reject(e)}};function Ge(e){let t=null,n=(t,n)=>{if(!e.getCapabilities()[n])throw new we(t,n)},r={async speak(r){if(e.assertSessionStarted(),n(`speak`,`textSpeech`),r.signal?.aborted)throw new DOMException(`Speak aborted.`,`AbortError`);let i=ke(r.queue??`append`);i===`interrupt`&&(e.onProcessorInterrupt?.(),t&&=(t.cancel(),null));let a=e.getIframeHost();if(!a)throw new G(`Speech session is not attached.`);let o=a.speak({text:r.text,characterId:r.characterId,behavior:i});if(r.signal){let t=r.signal;return await new Promise((n,i)=>{let s=()=>{a.speechInterrupt({scope:`active`}).catch(()=>void 0),i(new DOMException(`Speak aborted.`,`AbortError`))};if(t.aborted){s();return}t.addEventListener(`abort`,s,{once:!0}),o.then(e=>{t.removeEventListener(`abort`,s),n(He(e,`completed`))},a=>{if(t.removeEventListener(`abort`,s),Ue(a)){n({utteranceId:`utt_interrupted`,characterId:r.characterId??e.getActiveCharacterId(),status:`interrupted`,durationMs:0,transcript:r.text,animation:Ee(`none`)});return}i(Y(a))})})}try{return He(await o,`completed`)}catch(t){if(Ue(t))return{utteranceId:`utt_interrupted`,characterId:r.characterId??e.getActiveCharacterId(),status:`interrupted`,durationMs:0,transcript:r.text,animation:Ee(`none`)};throw Y(t)}},async play(i){if(e.assertSessionStarted(),n(`play`,`externalSpeechAudio`),q(i.audio),i.signal?.aborted)throw new DOMException(`Play aborted.`,`AbortError`);let a=i.queue??`append`;if((a===`replace-active`||a===`replace-all`)&&(e.onProcessorInterrupt?.(),t&&=(t.cancel(),null)),H(i.audio)){let e=i.audio.sampleRate??24e3;return r.createUtterance({format:{encoding:`pcm_s16le`,sampleRate:e,channels:1},track:i.audio.track,characterId:i.characterId,queue:a===`append`?`replace-active`:a,signal:i.signal}).result}let o=e.getIframeHost();if(!o)throw new G(`Speech session is not attached.`);let s=await Be(i.audio,i.signal);return o.speechPlay({source:s,characterId:i.characterId,transcript:i.transcript,history:i.history??`none`,queue:a,signal:i.signal})},createUtterance(r){e.assertSessionStarted(),n(`createUtterance`,`externalSpeechAudio`);let i=Oe(r);if(r.track&&r.track.kind!==`audio`)throw new G(`createUtterance track must be an audio MediaStreamTrack.`);let a=r.queue??`replace-active`;if(a!==`replace-active`&&a!==`replace-all`)throw new G(`createUtterance queue must be replace-active or replace-all.`);e.onProcessorInterrupt?.(),t&&=(t.cancel(),null);let o=new We({id:Ve(),characterId:r.characterId??e.getActiveCharacterId(),format:i,queue:a,host:e,...r.transcript===void 0?{}:{transcript:r.transcript},signal:r.signal});return t=o,o.result.finally(()=>{t===o&&(t=null)}),r.track&&(async()=>{try{if(await ze({track:r.track,utterance:o,sampleRate:i.sampleRate,signal:r.signal}),r.signal?.aborted)return;await o.close({history:`none`})}catch{await o.cancel().catch(()=>void 0)}})(),o},async interrupt(n){e.assertSessionStarted(),e.onProcessorInterrupt?.();let r=e.getIframeHost();if(!r)return[];let i=await r.speechInterrupt(n??{scope:`active`});if(t){let e=i.find(e=>e.utteranceId===t.id);e&&t.adoptExternalResult(e),t=null}return i}};return r}function Ke(e){return!!(e.showClose===!0||e.returnUrl?.trim()||e.closeButton===!0||e.closeButton&&typeof e.closeButton==`object`&&e.closeButton.visible!==!1)}var qe=class e{bootstrap;conversationProcessor;iframeHost=null;attachInFlight=null;endpointAbortController=null;processorAbortController=null;processorChain=Promise.resolve();resolvedSession;launchToken;attachReturnUrl=null;closed=!1;attached=!1;closeHandlers=[];eventRegistry=ve();readyEnvelope=null;startedEnvelope=null;conversationCache=[];speech;constructor(e){this.bootstrap=e,this.conversationProcessor=e.conversationProcessor??null,this.resolvedSession=e.kind===`launch`?e.session??null:null,this.launchToken=e.kind===`launch`?e.launch:null,this.speech=Ge({getIframeHost:()=>this.iframeHost,assertSessionStarted:()=>this.assertSessionStarted(),getCapabilities:()=>Je(this.resolvedSession),getActiveCharacterId:()=>`character_unknown`,onProcessorInterrupt:()=>{this.processorAbortController?.abort(),this.processorAbortController=null}})}static async startSession(t){if(`launch`in t&&typeof t.launch==`string`){let n=t.launch.trim();if(!n)throw Error(`StartSessionOptions.launch must be a non-empty string.`);return new e({kind:`launch`,launch:n,session:t.session,embedBaseUrl:t.embedBaseUrl,debug:t.debug,speechOnly:t.speechOnly,ui:t.ui,onStart:t.onStart,onUserTranscript:t.onUserTranscript,conversationProcessor:t.conversationProcessor})}if(`sessionEndpoint`in t)return new e({kind:`sessionEndpoint`,experienceId:t.experienceId,sessionEndpoint:t.sessionEndpoint,locale:t.locale,secondaryLocale:t.secondaryLocale,learningLocale:t.learningLocale,language:t.language,locationId:t.locationId,avatarId:t.avatarId,embedBaseUrl:t.embedBaseUrl,debug:t.debug,mode:t.mode,speechInputMode:t.speechInputMode,speechOnly:t.speechOnly,ui:t.ui,onStart:t.onStart,onUserTranscript:t.onUserTranscript,conversationProcessor:t.conversationProcessor});if(`experienceId`in t)return new e({kind:`public`,experienceId:t.experienceId,locale:t.locale,secondaryLocale:t.secondaryLocale,learningLocale:t.learningLocale,language:t.language,locationId:t.locationId,avatarId:t.avatarId,embedBaseUrl:t.embedBaseUrl,debug:t.debug,mode:t.mode,speechInputMode:t.speechInputMode,speechOnly:t.speechOnly,ui:t.ui,onStart:t.onStart,onUserTranscript:t.onUserTranscript,conversationProcessor:t.conversationProcessor});throw Error(`Experience.startSession requires experienceId, sessionEndpoint, or launch.`)}getSession(){return this.resolvedSession}getManifest(){return null}on(e,t){let n=ye(this.eventRegistry,e,t);return e===`ready`&&this.readyEnvelope&&queueMicrotask(()=>t(this.readyEnvelope)),e===`started`&&this.startedEnvelope&&queueMicrotask(()=>t(this.startedEnvelope)),n}async attach(e){if(this.closed)throw Error(`Session has ended.`);if(!e.container)throw Error(`Experience.attach requires a DOM container element.`);return this.attached&&this.iframeHost?this.createPlayerFacade():(this.attachInFlight||=this.attachInternal(e).finally(()=>{this.attachInFlight=null}),this.attachInFlight)}async attachInternal(e){if(this.closed)throw Error(`Session has ended.`);if(this.attached&&this.iframeHost)return this.createPlayerFacade();this.iframeHost&&=(this.iframeHost.destroy(),null),this.attachReturnUrl=e.returnUrl?.trim()||null;let t=this.bootstrap.embedBaseUrl??pe(),n=this.bootstrap.debug===!0,r=this.bootstrap.speechOnly===!0,i=me(t,n,r||this.bootstrap.kind===`launch`?void 0:this.bootstrap.locationId,r||this.bootstrap.kind===`launch`?void 0:this.bootstrap.avatarId,e.fit,this.bootstrap.ui,Ke(e)),a=ge(i),o=null,s=new Promise(e=>{o=e}),c=null,l=new Promise(e=>{c=e}),u=ue(e=>{this.readyEnvelope||=(this.resolvedSession=e,this.emitWrapped(`ready`,{session:e}))}),d=this.bootstrap.onUserTranscript,f=le({container:e.container,src:i,playerOrigin:a,transparent:this.bootstrap.ui===`widget`,onClose:e=>{let t=e.returnUrl||!this.attachReturnUrl?e:{...e,returnUrl:this.attachReturnUrl};for(let e of this.closeHandlers)e(t)},onPlayerStatusChange:t=>{e.onPlayerStatusChange?.(t),e.onStateUpdate?.(t),t===`loading`&&o&&(o(),o=null),t===`ready`&&c&&(c(),c=null),t===`ready`&&u.markReady()},onUserTranscript:e=>{this.emitWrapped(`userTranscript`,e),d?.(e),this.queueProcessorTurn(e)},onUserSpeechStarted:e=>{this.emitWrapped(`userSpeechStarted`,e)},onUserSpeechEnded:e=>{this.emitWrapped(`userSpeechEnded`,e)},onCharacterSpeechStarted:e=>{this.emitWrapped(`characterSpeechStarted`,e)},onCharacterSpeechEnded:e=>{this.emitWrapped(`characterSpeechEnded`,e)},onListeningState:e=>{this.emitWrapped(`listeningState`,e)},onActivityChange:e=>{this.emitWrapped(`activityChange`,e)},onMessage:e=>{this.emitWrapped(`message`,e)},onStarted:e=>{this.startedEnvelope||(this.startedEnvelope=this.emitWrapped(`started`,e),this.bootstrap.onStart?.(e))},onConversationUpdate:e=>{this.conversationCache=e,this.emitWrapped(`conversationUpdate`,e)},onWidgetReady:()=>e.onWidgetReady?.(),onWidgetExpand:()=>e.onWidgetExpand?.(),onWidgetCollapse:()=>e.onWidgetCollapse?.(),onWidgetAudioSettings:t=>e.onWidgetAudioSettings?.(t),onWidgetDragStart:t=>e.onWidgetDragStart?.(t),onWidgetDragMove:t=>e.onWidgetDragMove?.(t),onWidgetDragEnd:t=>e.onWidgetDragEnd?.(t)});this.iframeHost=f;let p=this.resolveMintInteraction(),m=this.bootstrap.kind===`sessionEndpoint`?(this.endpointAbortController=new AbortController,E(this.bootstrap.sessionEndpoint,{experienceId:this.bootstrap.experienceId,locale:this.bootstrap.locale,secondaryLocale:this.bootstrap.secondaryLocale,learningLocale:this.bootstrap.learningLocale,language:this.bootstrap.language,mode:p.mode,speechInputMode:p.speechInputMode,speechOnly:this.bootstrap.speechOnly,signal:this.endpointAbortController.signal})):this.bootstrap.kind===`public`?T(this.bootstrap.experienceId,{locale:this.bootstrap.locale,secondaryLocale:this.bootstrap.secondaryLocale,learningLocale:this.bootstrap.learningLocale,language:this.bootstrap.language,mode:p.mode,speechInputMode:p.speechInputMode,speechOnly:this.bootstrap.speechOnly}):Promise.resolve(this.bootstrap.session?{session:this.bootstrap.session,launch:this.bootstrap.launch}:null),h;try{[,h]=await Promise.all([f.waitForLoad(),m])}catch(e){throw f.destroy(),this.iframeHost===f&&(this.iframeHost=null),e}finally{this.endpointAbortController=null}f.postParentHello();let g=h?.launch??(this.bootstrap.kind===`launch`?this.bootstrap.launch:null),_=h?.session??(this.bootstrap.kind===`launch`?this.bootstrap.session:void 0);if(!g)throw f.destroy(),this.iframeHost===f&&(this.iframeHost=null),Error(`Session Launch response did not include a launch token.`);return this.launchToken=g,_?(this.resolvedSession=_,this.bootstrap.kind===`launch`&&v(_),f.postLaunch(g,_,e.startButton),u.setValue(_)):f.postLaunch(g,void 0,e.startButton),await Promise.race([s,new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out waiting for player loading UI.`)),12e4)})]),await Promise.race([l,new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out waiting for player ready state.`)),12e4)})]),this.attached=!0,this.createPlayerFacade()}async startListening(){this.assertSessionStarted(),await this.iframeHost.startListening()}async stopListening(){return this.assertSessionStarted(),this.iframeHost.stopListening()}async listenOnce(e){return this.assertSessionStarted(),this.iframeHost.listenOnce({timeoutMs:e?.timeoutMs})}getConversation(){return this.conversationCache}setWidgetChrome(e){this.iframeHost?.postWidgetSetChrome(e)}toggleAudioSettings(){this.iframeHost?.postWidgetToggleAudioSettings()}getLastTurn(){if(this.conversationCache.length===0)return[];let e=this.conversationCache[this.conversationCache.length-1].turnId;return this.conversationCache.filter(t=>t.turnId===e)}async end(){this.close()}destroy(){this.closed||(this.closed=!0,this.processorAbortController?.abort(),this.processorAbortController=null,this.endpointAbortController?.abort(),this.endpointAbortController=null,this.attachInFlight=null,this.iframeHost?.destroy(),this.iframeHost=null,xe(this.eventRegistry),this.readyEnvelope=null,this.startedEnvelope=null,this.closeHandlers.length=0,this.attached=!1)}resolveMintInteraction(){return this.bootstrap.kind===`launch`?{}:{mode:this.bootstrap.mode,speechInputMode:this.bootstrap.speechInputMode}}getSessionId(){return this.resolvedSession?.id??``}emitWrapped(e,t){let n=_e(e,this.getSessionId(),t);return be(this.eventRegistry,e,n),n}queueProcessorTurn(e){if(!e.isFinal||!e.text.trim()||!this.conversationProcessor)return;let t=this.conversationProcessor;this.processorAbortController?.abort(),this.processorAbortController=new AbortController;let n=this.processorAbortController.signal;this.processorChain=this.processorChain.then(async()=>{if(!n.aborted)try{let r=await re(t,{utteranceId:e.utteranceId,text:e.text,conversation:this.conversationCache,signal:n});if(n.aborted)return;if(r.kind===`complete`){let e=r.speech;await this.speech.speak({text:e.text,...e.characterId?{characterId:e.characterId}:{},queue:e.behavior===`interrupt`?`replace-active`:`append`});return}await this.iframeHost.speakProcessorStream(r.stream,{signal:n})}catch(t){if(n.aborted)return;let r=t instanceof Error?t.message:String(t);this.emitWrapped(`conversationProcessorError`,{utteranceId:e.utteranceId,message:r})}})}assertAttached(){if(!this.attached||!this.iframeHost)throw Error(`Call Experience.attach() before using speech APIs.`)}assertSessionStarted(){if(this.assertAttached(),!this.startedEnvelope)throw Error(`Session has not started. Wait for the player start button and the started event before using speak() or listening APIs.`)}close(){this.closed||(this.closed=!0,this.endpointAbortController?.abort(),this.endpointAbortController=null,this.attachInFlight=null,this.iframeHost?.destroy(),this.iframeHost=null,this.attached=!1)}createPlayerFacade(){return{close:()=>{this.close()},destroy:()=>{this.destroy()},on:(e,t)=>{e===`close`&&this.closeHandlers.push(t)}}}};function Je(e){return e?{textSpeech:e.capabilities.speech.output,externalSpeechAudio:e.capabilities.speech.externalAudio}:{textSpeech:!0,externalSpeechAudio:!0}}function Ye(e,t){let n=e.trim();if(!n)return null;if(/^https?:\/\//i.test(n))try{return new URL(n)}catch{return null}let r=t.replace(/\/$/,``),i=n.startsWith(`/`)?n:`/${n}`;try{return new URL(i,`${r}/`)}catch{return null}}function Xe(e){try{if(document.referrer){let e=new URL(document.referrer);if(e.origin===window.location.origin&&e.pathname!==window.location.pathname)return`${e.pathname}${e.search}${e.hash}`}}catch{}return e}function Ze(e,t=`/meet`){if(e.reason!==`user`)return;let n=Ye(e.returnUrl?.trim()||Xe(t),window.location.origin);n?.protocol.startsWith(`http`)&&window.location.assign(n.toString())}var Qe=/\b(exp_[A-Za-z0-9][A-Za-z0-9_-]{2,127})\b/,$e=/(?:Your origin|origin)\s+(\S+)\s+is not an allowed origin/i;function et(e){return e instanceof Error?e.message:String(e)}function tt(){try{if(typeof globalThis.location?.origin==`string`&&globalThis.location.origin)return globalThis.location.origin}catch{}}function nt(e){return Qe.exec(e)?.[1]}function rt(e){return $e.exec(e)?.[1]}function it(e,t){let n=et(e).trim()||`Unknown error`,r=t?.experienceId?.trim()||nt(n)||void 0,i=t?.origin?.trim()||rt(n)||tt()||void 0;return/No playable experience found/i.test(n)||/^Experience is not available\.?$/i.test(n)||/^Unknown experience\.?$/i.test(n)||/experience_unavailable/i.test(n)?{kind:`not_found`,title:`The application tried to load an avatar experience that doesn’t exist.`,detail:`Experience with id ${r??`the requested experience`} does not exist`,technicalMessage:n,experienceId:r,origin:i}:/origin_not_allowed/i.test(n)||/is not an allowed origin/i.test(n)||/^Origin not allowed/i.test(n)?{kind:`origin_not_allowed`,title:`The application tried to load an avatar experience from a website that isn’t allowed.`,detail:`Origin ${i??`this page`} is not allowed for experience ${r??`the requested experience`}`,technicalMessage:n,experienceId:r,origin:i}:/browser_embeds_disabled/i.test(n)||/^Browser embeds are not enabled/i.test(n)?{kind:`browser_embeds_disabled`,title:`The application tried to load an avatar experience that isn’t enabled for browser embeds.`,detail:`Browser embeds are not enabled for experience ${r??`the requested experience`}`,technicalMessage:n,experienceId:r,origin:i}:{kind:`generic`,title:`This avatar experience couldn’t be started.`,detail:n,technicalMessage:n,experienceId:r,origin:i}}var at=`liforma-experience-load-error-styles`;function ot(){if(typeof document>`u`||document.getElementById(`liforma-experience-load-error-styles`))return;let e=document.createElement(`style`);e.id=at,e.textContent=st,document.head.append(e)}var st=`
78
15
  .liforma-loading-screen {
79
16
  inset: 0;
80
17
  z-index: 20;
@@ -173,7 +110,7 @@ registerProcessor('${ls}', LiformaPcmCaptureProcessor);
173
110
  .liforma-loading-error-detail[hidden] {
174
111
  display: none;
175
112
  }
176
- `;function zs(e,t){Ls();let n=t,r=!1,i=document.createElement(`div`);i.className=`liforma-loading-screen liforma-loading-screen-absolute`,i.setAttribute(`role`,`alert`),i.setAttribute(`aria-live`,`assertive`);let a=document.createElement(`div`);a.className=`liforma-loading-card liforma-loading-card-error`;let o=document.createElement(`p`);o.className=`liforma-loading-kicker`,o.textContent=`Avatar experience`;let s=document.createElement(`p`);s.className=`liforma-loading-error-title`;let c=document.createElement(`button`);c.type=`button`,c.className=`liforma-loading-error-advanced`;let l=document.createElement(`p`);l.className=`liforma-loading-error-detail`,c.addEventListener(`click`,()=>{r=!r,u()}),a.append(o,s,c,l),i.append(a),e.append(i);function u(){s.textContent=n.title,l.textContent=n.detail,l.hidden=!r,c.textContent=r?`Hide details`:`Advanced`,c.setAttribute(`aria-expanded`,r?`true`:`false`)}return u(),{root:i,setPresentation(e){n=e,r=!1,u()},remove(){i.remove()}}}var Bs=`liforma-experience`;function Vs(e){let t=e?.trim();return t===`conversation`||t===`presenter`?t:void 0}function Hs(e){let t=e?.trim();return t===`auto`||t===`manual`||t===`off`?t:void 0}function Us(e){let t=e?.trim();return t===`full`||t===`face`?t:void 0}var Ws=class extends HTMLElement{host=null;errorHost=null;errorOverlay=null;experience=null;bootstrapGeneration=0;static get observedAttributes(){return[`experience-id`,`language`,`session-endpoint`,`speech-only`,`mode`,`speech-input-mode`,`fit`]}connectedCallback(){this.style.display=`block`,this.style.position=`relative`,this.style.overflow=`hidden`,this.style.width||(this.style.width=`100%`),this.style.height||(this.style.height=`100%`);let e=getComputedStyle(this).minHeight;!this.style.minHeight&&(e===`0px`||e===`auto`)&&(this.style.minHeight=`480px`),this.errorHost||(this.errorHost=document.createElement(`div`),this.errorHost.style.cssText=`position:absolute;inset:0;z-index:20;pointer-events:none;`,this.append(this.errorHost)),this.host||(this.host=document.createElement(`div`),this.host.style.cssText=`position:absolute;inset:0;overflow:hidden;`,this.append(this.host)),this.bootstrap()}disconnectedCallback(){this.bootstrapGeneration+=1,this.experience?.destroy(),this.experience=null,this.clearError()}attributeChangedCallback(e,t,n){e!==`experience-id`&&e!==`language`&&e!==`session-endpoint`&&e!==`speech-only`&&e!==`mode`&&e!==`speech-input-mode`&&e!==`fit`||t===n||!this.isConnected||(this.bootstrapGeneration+=1,this.experience?.destroy(),this.experience=null,this.clearError(),this.host&&this.host.replaceChildren(),this.bootstrap())}async bootstrap(){let e=this.getAttribute(`experience-id`)?.trim(),t=this.getAttribute(`session-endpoint`)?.trim(),n=this.getAttribute(`language`)?.trim(),r=n===`es`||n===`en`?n:void 0,i=this.getAttribute(`speech-only`)===`true`,a=Vs(this.getAttribute(`mode`)),o=Hs(this.getAttribute(`speech-input-mode`)),s=Us(this.getAttribute(`fit`));if(!e||!this.host)return;let c=++this.bootstrapGeneration;this.clearError();try{let n=await ws.startSession(t?{experienceId:e,sessionEndpoint:t,language:r,speechOnly:i,mode:a,speechInputMode:o,fit:s}:{experienceId:e,language:r,speechOnly:i,mode:a,speechInputMode:o,fit:s});if(c!==this.bootstrapGeneration){n.destroy();return}this.experience=n;let l=await n.attach({container:this.host});if(c!==this.bootstrapGeneration){n.destroy(),this.experience=null;return}l.on(`close`,e=>{this.dispatchEvent(new CustomEvent(`close`,{detail:e,bubbles:!0})),Os(e)})}catch(t){if(c!==this.bootstrapGeneration)return;this.showError(t,e),console.error(`[liforma-experience]`,t),this.experience?.destroy(),this.experience=null}}showError(e,t){this.clearError(),this.errorHost&&(this.errorHost.style.pointerEvents=`auto`,this.errorOverlay=zs(this.errorHost,Fs(e,{experienceId:t})))}clearError(){this.errorOverlay?.remove(),this.errorOverlay=null,this.errorHost&&(this.errorHost.style.pointerEvents=`none`,this.errorHost.replaceChildren())}};typeof customElements<`u`&&!customElements.get(Bs)&&customElements.define(Bs,Ws);var Gs=/(\/avatars\/[^/]+\/)(\d+)(\/)/i,Ks=/(-)(\d+x\d+)(\.webp)(\?|$)/i;function qs(e){let t=e.trim();if(!t)return t;let n=t.replace(Gs,(e,t,n,r)=>n===`256`?`${t}${n}${r}`:`${t}256${r}`);return n=n.replace(Ks,(e,t,n,r,i)=>n===`256x256`?`${t}${n}${r}${i}`:`${t}256x256${r}${i}`),n}function Js(e){let t=e.avatarImage?.trim()||e.galleryThumb?.avatarImage?.trim()||``;if(!t)return null;let n=e.backgroundImage?.trim()||e.galleryThumb?.backgroundImage?.trim()||``,r=e.foregroundImage?.trim()||e.galleryThumb?.foregroundImage?.trim()||``,i=e.fallbackImage?.trim()||``;return{avatarImage:qs(t),...n?{backgroundImage:qs(n)}:{},...r?{foregroundImage:qs(r)}:{},...i?{fallbackImage:qs(i)}:{}}}var Ys=`https://player.liforma.ai`,Xs=`http://localhost:3002`;function Zs(e){return e.href?.trim()?`anchor`:e.hasClickHandler?`button`:e.experienceId?.trim()?`anchor`:`presentational`}function Qs(e){let n=e?.trim();return n?n.replace(/\/$/,``):t()?Xs:Ys}function $s(e){let t=e.experienceId.trim(),n=Qs(e.playerBaseUrl),r=new URL(`${n}/${encodeURIComponent(t)}`),i=e.returnUrl?.trim();return i&&r.searchParams.set(`returnUrl`,i),r.toString()}function ec(e){let t=e.href?.trim();if(t)return t;let n=e.experienceId?.trim();if(!n)return;let r=e.returnUrl?.trim();return!r&&e.useCurrentPageAsReturnUrl&&typeof window<`u`&&(r=window.location.href),$s({experienceId:n,...r?{returnUrl:r}:{},playerBaseUrl:e.playerBaseUrl})}function tc(){return typeof window>`u`?!1:window.matchMedia(`(hover: none), (pointer: coarse)`).matches}var nc=0,rc=[];function ic(){return tc()?4:1/0}function ac(){return tc()?160:0}function oc(){let e=ic();for(;nc<e&&rc.length>0;){let e=rc.shift();if(!e||e.cancelled)continue;nc+=1,e.start();let t=ac();if(t<=0){nc=Math.max(0,nc-1);continue}window.setTimeout(()=>{nc=Math.max(0,nc-1),oc()},t)}}function sc(e){if(!tc())return e(),()=>{};let t={start:e,cancelled:!1};return rc.push(t),oc(),()=>{t.cancelled=!0}}function cc(){return tc()?`96px 0px`:`280px 0px`}function lc(e){let t=e.trim().split(/\s+/)[0]??`0px`,n=Number.parseFloat(t);return Number.isFinite(n)?Math.abs(n):280}function uc(e,t){if(typeof window>`u`)return!1;let n=e.getBoundingClientRect();return n.bottom>=-t&&n.top<=window.innerHeight+t}function dc(e,t){let{onVisibleChange:n}=t,r=t.rootMargin??cc(),i=lc(r),a=!1,o=!1,s=null,c=()=>{o||(s?.(),s=sc(()=>{s=null,o=!0,n(!0)}))},l=e=>{if(e!==a){if(a=e,e){c();return}s?.(),s=null,n(!1)}};if(typeof IntersectionObserver>`u`)return c(),()=>{s?.(),s=null};let u=new IntersectionObserver(e=>{l(e.some(e=>e.isIntersecting))},{root:null,rootMargin:r,threshold:0});return u.observe(e),uc(e,i)&&l(!0),()=>{s?.(),s=null,u.disconnect()}}function fc(e,t){let n=()=>t();return e.complete?queueMicrotask(n):(e.addEventListener(`load`,n,{once:!0}),e.addEventListener(`error`,n,{once:!0})),()=>{e.removeEventListener(`load`,n),e.removeEventListener(`error`,n)}}function pc(){return typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?!1:window.matchMedia(`(hover: none), (pointer: coarse)`).matches}function mc(e,t){return((e.top+e.height/2)/Math.max(t,1)-.5)*2}var hc=new Set,gc=!1,_c=0;function vc(){if(_c=0,hc.size===0||typeof window>`u`)return;let e=window.innerHeight;for(let t of hc){if(t.pointerActive?.())continue;let n=t.element.getBoundingClientRect();n.bottom<-64||n.top>e+64||t.onParallax(mc(n,e))}}function yc(){_c===0&&(_c=requestAnimationFrame(vc))}function bc(){gc||typeof window>`u`||(gc=!0,window.addEventListener(`scroll`,yc,{passive:!0}),window.addEventListener(`resize`,yc,{passive:!0}))}function xc(){hc.size>0||!gc||typeof window>`u`||(gc=!1,_c!==0&&(cancelAnimationFrame(_c),_c=0),window.removeEventListener(`scroll`,yc),window.removeEventListener(`resize`,yc))}function Sc(e,t){if(!pc())return()=>{};let n={element:e,onParallax:t.onParallax,pointerActive:t.pointerActive};return hc.add(n),bc(),n.pointerActive?.()||t.onParallax(mc(e.getBoundingClientRect(),window.innerHeight)),()=>{hc.delete(n),xc()}}function Cc(e){let t=0,n=0,r=!1,i=!1,a=!1,o=()=>{let a=r||i;e.classList.toggle(`liforma-et--parallax`,a),e.classList.toggle(`liforma-et--scroll-parallax`,i),e.style.setProperty(`--liforma-et-parallax-x`,String(t)),e.style.setProperty(`--liforma-et-parallax-y`,String(n))},s=Sc(e,{onParallax:e=>{i=!0,a||(t=e,n=0,o())},pointerActive:()=>a}),c=r=>{if(i)return;let a=e.getBoundingClientRect();a.width<=0||a.height<=0||(t=((r.clientX-a.left)/a.width-.5)*2,n=((r.clientY-a.top)/a.height-.5)*2,o())},l=e=>{a=!0,e.pointerType===`mouse`&&(r=!0),o()},u=()=>{let s=a;a=!1,r=!1,i&&s?(t=mc(e.getBoundingClientRect(),window.innerHeight),n=0):i||(t=0,n=0),o()},d=e=>{e.pointerType===`mouse`&&(r=!0,o())},f=()=>{a||(r=!1,i||(t=0,n=0),o())};return e.addEventListener(`pointermove`,c),e.addEventListener(`pointerdown`,l),e.addEventListener(`pointerup`,u),e.addEventListener(`pointercancel`,u),e.addEventListener(`pointerenter`,d),e.addEventListener(`pointerleave`,f),()=>{s(),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerdown`,l),e.removeEventListener(`pointerup`,u),e.removeEventListener(`pointercancel`,u),e.removeEventListener(`pointerenter`,d),e.removeEventListener(`pointerleave`,f),e.classList.remove(`liforma-et--parallax`,`liforma-et--scroll-parallax`),e.style.removeProperty(`--liforma-et-parallax-x`),e.style.removeProperty(`--liforma-et-parallax-y`)}}var wc=`.liforma-et {
113
+ `;function ct(e,t){ot();let n=t,r=!1,i=document.createElement(`div`);i.className=`liforma-loading-screen liforma-loading-screen-absolute`,i.setAttribute(`role`,`alert`),i.setAttribute(`aria-live`,`assertive`);let a=document.createElement(`div`);a.className=`liforma-loading-card liforma-loading-card-error`;let o=document.createElement(`p`);o.className=`liforma-loading-kicker`,o.textContent=`Avatar experience`;let s=document.createElement(`p`);s.className=`liforma-loading-error-title`;let c=document.createElement(`button`);c.type=`button`,c.className=`liforma-loading-error-advanced`;let l=document.createElement(`p`);l.className=`liforma-loading-error-detail`,c.addEventListener(`click`,()=>{r=!r,u()}),a.append(o,s,c,l),i.append(a),e.append(i);function u(){s.textContent=n.title,l.textContent=n.detail,l.hidden=!r,c.textContent=r?`Hide details`:`Advanced`,c.setAttribute(`aria-expanded`,r?`true`:`false`)}return u(),{root:i,setPresentation(e){n=e,r=!1,u()},remove(){i.remove()}}}var lt=`liforma-experience`;function ut(e){let t=e?.trim();return t===`conversation`||t===`presenter`?t:void 0}function dt(e){let t=e?.trim();return t===`auto`||t===`manual`||t===`off`?t:void 0}function ft(e){let t=e?.trim();return t===`full`||t===`face`?t:void 0}var pt=class e extends HTMLElement{host=null;errorHost=null;errorOverlay=null;experience=null;bootstrapGeneration=0;static get observedAttributes(){return[`experience-id`,`locale`,`language`,`secondary-locale`,`learning-locale`,`session-endpoint`,`speech-only`,`mode`,`speech-input-mode`,`fit`]}connectedCallback(){this.style.display=`block`,this.style.position=`relative`,this.style.overflow=`hidden`,this.style.width||(this.style.width=`100%`),this.style.height||(this.style.height=`100%`);let e=getComputedStyle(this).minHeight;!this.style.minHeight&&(e===`0px`||e===`auto`)&&(this.style.minHeight=`480px`),this.errorHost||(this.errorHost=document.createElement(`div`),this.errorHost.style.cssText=`position:absolute;inset:0;z-index:20;pointer-events:none;`,this.append(this.errorHost)),this.host||(this.host=document.createElement(`div`),this.host.style.cssText=`position:absolute;inset:0;overflow:hidden;`,this.append(this.host)),this.bootstrap()}disconnectedCallback(){this.bootstrapGeneration+=1,this.experience?.destroy(),this.experience=null,this.clearError()}attributeChangedCallback(t,n,r){e.observedAttributes.includes(t)&&(n===r||!this.isConnected||(this.bootstrapGeneration+=1,this.experience?.destroy(),this.experience=null,this.clearError(),this.host&&this.host.replaceChildren(),this.bootstrap()))}async bootstrap(){let e=this.getAttribute(`experience-id`)?.trim(),t=this.getAttribute(`session-endpoint`)?.trim(),n=this.getAttribute(`locale`)?.trim()||void 0,r=this.getAttribute(`language`)?.trim()||void 0,i=this.getAttribute(`secondary-locale`)?.trim()||void 0,a=this.getAttribute(`learning-locale`)?.trim()||void 0,o=this.getAttribute(`speech-only`)===`true`,s=ut(this.getAttribute(`mode`)),c=dt(this.getAttribute(`speech-input-mode`)),l=ft(this.getAttribute(`fit`));if(!e||!this.host)return;let u=++this.bootstrapGeneration;this.clearError();try{let d={experienceId:e,locale:n,language:r,secondaryLocale:i,learningLocale:a,speechOnly:o,mode:s,speechInputMode:c},f=await qe.startSession(t?{...d,sessionEndpoint:t}:d);if(u!==this.bootstrapGeneration){f.destroy();return}this.experience=f;let p=await f.attach({container:this.host,...l?{fit:l}:{}});if(u!==this.bootstrapGeneration){f.destroy(),this.experience=null;return}p.on(`close`,e=>{this.dispatchEvent(new CustomEvent(`close`,{detail:e,bubbles:!0})),Ze(e)})}catch(t){if(u!==this.bootstrapGeneration)return;this.showError(t,e),console.error(`[liforma-experience]`,t),this.experience?.destroy(),this.experience=null}}showError(e,t){this.clearError(),this.errorHost&&(this.errorHost.style.pointerEvents=`auto`,this.errorOverlay=ct(this.errorHost,it(e,{experienceId:t})))}clearError(){this.errorOverlay?.remove(),this.errorOverlay=null,this.errorHost&&(this.errorHost.style.pointerEvents=`none`,this.errorHost.replaceChildren())}};typeof customElements<`u`&&!customElements.get(lt)&&customElements.define(lt,pt);var mt=/(\/avatars\/[^/]+\/)(\d+)(\/)/i,ht=/_CH(\.webp)/i,gt=/(-)(\d+x\d+)(\.webp)(\?|$)/i;function _t(e){let t=e.trim();if(!t)return t;let n=t.replace(mt,(e,t,n,r)=>n===`256`?`${t}${n}${r}`:`${t}256${r}`);return n=n.replace(ht,`_neutral$1`),n=n.replace(gt,(e,t,n,r,i)=>n===`256x256`?`${t}${n}${r}${i}`:`${t}256x256${r}${i}`),n}function vt(e){let t=e.avatarImage?.trim()||e.galleryThumb?.avatarImage?.trim()||``;if(!t)return null;let n=e.backgroundImage?.trim()||e.galleryThumb?.backgroundImage?.trim()||``,r=e.foregroundImage?.trim()||e.galleryThumb?.foregroundImage?.trim()||``,i=e.fallbackImage?.trim()||``;return{avatarImage:_t(t),...n?{backgroundImage:_t(n)}:{},...r?{foregroundImage:_t(r)}:{},...i?{fallbackImage:_t(i)}:{}}}var yt=`https://player.liforma.ai`,bt=`http://localhost:3002`;function xt(e){return e.href?.trim()?`anchor`:e.hasClickHandler?`button`:e.experienceId?.trim()?`anchor`:`presentational`}function St(e){let n=e?.trim();return n?n.replace(/\/$/,``):t()?bt:yt}function Ct(e){let t=e.experienceId.trim(),n=St(e.playerBaseUrl),r=new URL(`${n}/${encodeURIComponent(t)}`),i=e.returnUrl?.trim();return i&&r.searchParams.set(`returnUrl`,i),r.toString()}function wt(e){let t=e.href?.trim();if(t)return t;let n=e.experienceId?.trim();if(!n)return;let r=e.returnUrl?.trim();return!r&&e.useCurrentPageAsReturnUrl&&typeof window<`u`&&(r=window.location.href),Ct({experienceId:n,...r?{returnUrl:r}:{},playerBaseUrl:e.playerBaseUrl})}function Tt(){return typeof window>`u`?!1:window.matchMedia(`(hover: none), (pointer: coarse)`).matches}var X=0,Et=[];function Dt(){return Tt()?4:1/0}function Ot(){return Tt()?160:0}function kt(){let e=Dt();for(;X<e&&Et.length>0;){let e=Et.shift();if(!e||e.cancelled)continue;X+=1,e.start();let t=Ot();if(t<=0){X=Math.max(0,X-1);continue}window.setTimeout(()=>{X=Math.max(0,X-1),kt()},t)}}function At(e){if(!Tt())return e(),()=>{};let t={start:e,cancelled:!1};return Et.push(t),kt(),()=>{t.cancelled=!0}}function jt(){return Tt()?`96px 0px`:`280px 0px`}function Mt(e){let t=e.trim().split(/\s+/)[0]??`0px`,n=Number.parseFloat(t);return Number.isFinite(n)?Math.abs(n):280}function Nt(e,t){if(typeof window>`u`)return!1;let n=e.getBoundingClientRect();return n.bottom>=-t&&n.top<=window.innerHeight+t}function Pt(e,t){let{onVisibleChange:n}=t,r=t.rootMargin??jt(),i=Mt(r),a=!1,o=!1,s=null,c=()=>{o||(s?.(),s=At(()=>{s=null,o=!0,n(!0)}))},l=e=>{if(e!==a){if(a=e,e){c();return}s?.(),s=null,n(!1)}};if(typeof IntersectionObserver>`u`)return c(),()=>{s?.(),s=null};let u=new IntersectionObserver(e=>{l(e.some(e=>e.isIntersecting))},{root:null,rootMargin:r,threshold:0});return u.observe(e),Nt(e,i)&&l(!0),()=>{s?.(),s=null,u.disconnect()}}function Ft(e,t){let n=()=>t();return e.complete?queueMicrotask(n):(e.addEventListener(`load`,n,{once:!0}),e.addEventListener(`error`,n,{once:!0})),()=>{e.removeEventListener(`load`,n),e.removeEventListener(`error`,n)}}function It(){return typeof window>`u`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?!1:window.matchMedia(`(hover: none), (pointer: coarse)`).matches}function Lt(e,t){return((e.top+e.height/2)/Math.max(t,1)-.5)*2}var Rt=new Set,zt=!1,Z=0;function Bt(){if(Z=0,Rt.size===0||typeof window>`u`)return;let e=window.innerHeight;for(let t of Rt){if(t.pointerActive?.())continue;let n=t.element.getBoundingClientRect();n.bottom<-64||n.top>e+64||t.onParallax(Lt(n,e))}}function Vt(){Z===0&&(Z=requestAnimationFrame(Bt))}function Ht(){zt||typeof window>`u`||(zt=!0,window.addEventListener(`scroll`,Vt,{passive:!0}),window.addEventListener(`resize`,Vt,{passive:!0}))}function Ut(){Rt.size>0||!zt||typeof window>`u`||(zt=!1,Z!==0&&(cancelAnimationFrame(Z),Z=0),window.removeEventListener(`scroll`,Vt),window.removeEventListener(`resize`,Vt))}function Wt(e,t){if(!It())return()=>{};let n={element:e,onParallax:t.onParallax,pointerActive:t.pointerActive};return Rt.add(n),Ht(),n.pointerActive?.()||t.onParallax(Lt(e.getBoundingClientRect(),window.innerHeight)),()=>{Rt.delete(n),Ut()}}function Gt(e){let t=0,n=0,r=!1,i=!1,a=!1,o=()=>{let a=r||i;e.classList.toggle(`liforma-et--parallax`,a),e.classList.toggle(`liforma-et--scroll-parallax`,i),e.style.setProperty(`--liforma-et-parallax-x`,String(t)),e.style.setProperty(`--liforma-et-parallax-y`,String(n))},s=Wt(e,{onParallax:e=>{i=!0,a||(t=e,n=0,o())},pointerActive:()=>a}),c=r=>{if(i)return;let a=e.getBoundingClientRect();a.width<=0||a.height<=0||(t=((r.clientX-a.left)/a.width-.5)*2,n=((r.clientY-a.top)/a.height-.5)*2,o())},l=e=>{a=!0,e.pointerType===`mouse`&&(r=!0),o()},u=()=>{let s=a;a=!1,r=!1,i&&s?(t=Lt(e.getBoundingClientRect(),window.innerHeight),n=0):i||(t=0,n=0),o()},d=e=>{e.pointerType===`mouse`&&(r=!0,o())},f=()=>{a||(r=!1,i||(t=0,n=0),o())};return e.addEventListener(`pointermove`,c),e.addEventListener(`pointerdown`,l),e.addEventListener(`pointerup`,u),e.addEventListener(`pointercancel`,u),e.addEventListener(`pointerenter`,d),e.addEventListener(`pointerleave`,f),()=>{s(),e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerdown`,l),e.removeEventListener(`pointerup`,u),e.removeEventListener(`pointercancel`,u),e.removeEventListener(`pointerenter`,d),e.removeEventListener(`pointerleave`,f),e.classList.remove(`liforma-et--parallax`,`liforma-et--scroll-parallax`),e.style.removeProperty(`--liforma-et-parallax-x`),e.style.removeProperty(`--liforma-et-parallax-y`)}}var Kt=`.liforma-et {
177
114
  --liforma-et-parallax-x: 0;
178
115
  --liforma-et-parallax-y: 0;
179
116
  --liforma-et-bg-scale: 1;
@@ -261,8 +198,8 @@ button.liforma-et {
261
198
  display: block;
262
199
  width: 100%;
263
200
  height: 100%;
264
- object-fit: cover;
265
- object-position: 50% 30%;
201
+ object-fit: contain;
202
+ object-position: center bottom;
266
203
  transform: scale(var(--liforma-et-avatar-scale))
267
204
  translate(
268
205
  calc(var(--liforma-et-parallax-x) * var(--liforma-et-avatar-shift)),
@@ -274,9 +211,24 @@ button.liforma-et {
274
211
  transform 160ms ease;
275
212
  }
276
213
 
277
- .liforma-et--scene .liforma-et__avatar {
278
- object-fit: contain;
279
- object-position: center bottom;
214
+ /* Gallery plates are typically square in a square tile — contain vs cover is a no-op
215
+ without a zoom. Scale the whole scene from the upper third so Face matches
216
+ player fit (location + avatar crop together). */
217
+ .liforma-et--fit-face {
218
+ --liforma-et-avatar-scale: 1.85;
219
+ --liforma-et-bg-scale: 1.85;
220
+ --liforma-et-fg-scale: 1.85;
221
+ }
222
+
223
+ .liforma-et--fit-face .liforma-et__avatar,
224
+ .liforma-et--fit-face .liforma-et__background,
225
+ .liforma-et--fit-face .liforma-et__foreground {
226
+ transform-origin: 50% 18%;
227
+ }
228
+
229
+ .liforma-et--fit-face .liforma-et__avatar {
230
+ object-fit: cover;
231
+ object-position: 50% 18%;
280
232
  }
281
233
 
282
234
  .liforma-et__foreground {
@@ -315,8 +267,10 @@ button.liforma-et {
315
267
  will-change: transform;
316
268
  }
317
269
 
318
- .liforma-et--parallax:not(.liforma-et--scene) {
319
- --liforma-et-avatar-scale: 1.05;
270
+ .liforma-et--parallax.liforma-et--fit-face {
271
+ --liforma-et-avatar-scale: 1.95;
272
+ --liforma-et-bg-scale: 1.95;
273
+ --liforma-et-fg-scale: 1.95;
320
274
  --liforma-et-avatar-shift: 0px;
321
275
  }
322
276
 
@@ -340,12 +294,18 @@ button.liforma-et {
340
294
  --liforma-et-avatar-shift: 0px;
341
295
  }
342
296
 
297
+ .liforma-et--parallax.liforma-et--fit-face {
298
+ --liforma-et-avatar-scale: 1.85;
299
+ --liforma-et-bg-scale: 1.85;
300
+ --liforma-et-fg-scale: 1.85;
301
+ }
302
+
343
303
  .liforma-et__background,
344
304
  .liforma-et__foreground,
345
305
  .liforma-et__avatar {
346
306
  transition: none;
347
307
  }
348
- }`,Tc=!1;function Ec(e){if(typeof document>`u`||Tc)return;if(document.querySelector(`style[data-liforma-et]`)){Tc=!0;return}let t=document.createElement(`style`);t.setAttribute(`data-liforma-et`,``),t.textContent=e,document.head.appendChild(t),Tc=!0}var Dc=`liforma-experience-thumbnail`;function Oc(e){if(e?.trim())try{let t=JSON.parse(e);if(t&&typeof t.avatarImage==`string`)return t}catch{}}var kc=class extends HTMLElement{static get observedAttributes(){return[`experience-id`,`gallery-thumb`,`avatar-image`,`background-image`,`foreground-image`,`fallback-image`,`alt`,`href`,`target`,`rel`,`return-url`,`player-base-url`,`parallax`,`lazy`]}#e=null;#t=[];#n=!1;#r=!1;#i=!1;#a=!1;#o=0;#s=0;#c=!1;#l=!1;#u=!1;#d=!1;connectedCallback(){this.#m()}disconnectedCallback(){this.#f()}attributeChangedCallback(){this.isConnected&&this.#m()}#f(){for(let e of this.#t)e();this.#t=[],this.#e=null}#p(e,t){if(!this.hasAttribute(e))return t;let n=this.getAttribute(e);return n===null||n===``||n===`true`?!0:n===`false`?!1:t}#m(){this.#f();let e=this.shadowRoot??this.attachShadow({mode:`open`}),t=document.createElement(`style`);t.textContent=wc,e.replaceChildren(t);let n=this.getAttribute(`alt`)?.trim()||`Experience`,r=this.getAttribute(`href`),i=this.getAttribute(`experience-id`),a=Zs({href:r,hasClickHandler:this.hasAttribute(`onclick`)||typeof this.onclick==`function`,experienceId:i}),o=Js({galleryThumb:Oc(this.getAttribute(`gallery-thumb`)),avatarImage:this.getAttribute(`avatar-image`)??void 0,backgroundImage:this.getAttribute(`background-image`)??void 0,foregroundImage:this.getAttribute(`foreground-image`)??void 0,fallbackImage:this.getAttribute(`fallback-image`)??void 0});if(!o)return;let s=this.#p(`parallax`,!0),c=this.#p(`lazy`,!0);this.#n=!c;let l=a===`anchor`&&!r?.trim()&&!!i?.trim(),u=ec({href:r??void 0,experienceId:i??void 0,returnUrl:this.getAttribute(`return-url`)??void 0,playerBaseUrl:this.getAttribute(`player-base-url`)??void 0,useCurrentPageAsReturnUrl:l&&!this.getAttribute(`return-url`)?.trim()}),d;if(a===`anchor`&&u){let e=document.createElement(`a`);e.href=u;let t=this.getAttribute(`target`),n=this.getAttribute(`rel`);t&&(e.target=t),n&&(e.rel=n),d=e}else if(a===`button`){let e=document.createElement(`button`);e.type=`button`,d=e}else d=document.createElement(`div`),d.setAttribute(`role`,`img`);d.className=`liforma-et`,d.setAttribute(`aria-label`,n),this.#e=d,e.appendChild(d);let f=()=>{let e=!!o.backgroundImage,t=s&&(this.#r||this.#a),n=this.#n&&(this.#u||this.#l||this.#d);d.className=[`liforma-et`,e?`liforma-et--scene`:``,t?`liforma-et--parallax`:``,this.#a?`liforma-et--scroll-parallax`:``,this.#n&&!n?`liforma-et--loading`:``,n?`liforma-et--revealed`:``].filter(Boolean).join(` `),d.style.setProperty(`--liforma-et-parallax-x`,String(this.#o)),d.style.setProperty(`--liforma-et-parallax-y`,String(this.#s))},p=document.createElement(`span`);p.className=`liforma-et__placeholder`,p.setAttribute(`aria-hidden`,`true`),d.appendChild(p);let m=()=>{if(!this.#n)return;let e=this.#c&&o.fallbackImage?o.fallbackImage:o.avatarImage;if(o.backgroundImage&&!d.querySelector(`.liforma-et__background`)){let e=document.createElement(`img`);e.className=`liforma-et__background liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=o.backgroundImage,this.#t.push(fc(e,()=>{this.#l=!0,e.classList.add(`liforma-et__media--ready`),f()})),d.appendChild(e)}let t=d.querySelector(`.liforma-et__avatar`);if(t||(t=document.createElement(`img`),t.className=`liforma-et__avatar liforma-et__media`,t.alt=``,t.decoding=`async`,t.addEventListener(`error`,()=>{o.fallbackImage&&!this.#c?(this.#c=!0,t.src=o.fallbackImage):(this.#u=!0,f())}),this.#t.push(fc(t,()=>{this.#u=!0,t.classList.add(`liforma-et__media--ready`),f()})),d.appendChild(t)),t.src!==e&&(t.src=e),o.foregroundImage&&!d.querySelector(`.liforma-et__foreground`)){let e=document.createElement(`img`);e.className=`liforma-et__foreground liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=o.foregroundImage,this.#t.push(fc(e,()=>{this.#d=!0,e.classList.add(`liforma-et__media--ready`),f()})),d.appendChild(e)}f()};if(c?this.#t.push(dc(d,{onVisibleChange:e=>{e&&(this.#n=!0,m(),f())}})):m(),s){this.#t.push(Sc(d,{onParallax:e=>{this.#a=!0,this.#i||(this.#o=e,this.#s=0,f())},pointerActive:()=>this.#i}));let e=e=>{if(this.#a)return;let t=d.getBoundingClientRect();t.width<=0||t.height<=0||(this.#o=((e.clientX-t.left)/t.width-.5)*2,this.#s=((e.clientY-t.top)/t.height-.5)*2,f())},t=e=>{this.#i=!0,e.pointerType===`mouse`&&(this.#r=!0),f()},n=()=>{let e=this.#i;this.#i=!1,this.#r=!1,this.#a&&e?(this.#o=mc(d.getBoundingClientRect(),window.innerHeight),this.#s=0):this.#a||(this.#o=0,this.#s=0),f()};d.addEventListener(`pointermove`,e),d.addEventListener(`pointerdown`,t),d.addEventListener(`pointerup`,n),d.addEventListener(`pointercancel`,n),d.addEventListener(`pointerenter`,e=>{e.pointerType===`mouse`&&(this.#r=!0,f())}),d.addEventListener(`pointerleave`,()=>{this.#i||(this.#r=!1,this.#a||(this.#o=0,this.#s=0),f())}),this.#t.push(()=>{d.removeEventListener(`pointermove`,e),d.removeEventListener(`pointerdown`,t),d.removeEventListener(`pointerup`,n),d.removeEventListener(`pointercancel`,n)})}d.addEventListener(`click`,e=>{if(l&&!this.getAttribute(`return-url`)?.trim()){let t=ec({experienceId:i??void 0,playerBaseUrl:this.getAttribute(`player-base-url`)??void 0,useCurrentPageAsReturnUrl:!0});t&&e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),window.location.assign(t))}}),f()}};customElements.get(Dc)||customElements.define(Dc,kc);function Ac(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.avatarImage==`string`?t.avatarImage.trim():``;return n?{avatarImage:n,...typeof t.backgroundImage==`string`&&t.backgroundImage.trim()?{backgroundImage:t.backgroundImage.trim()}:{},...typeof t.foregroundImage==`string`&&t.foregroundImage.trim()?{foregroundImage:t.foregroundImage.trim()}:{}}:null}async function jc(e,t){let n=e.trim();if(!n)throw Error(`Experience preview requires experienceId.`);let r=(t?.apiBaseUrl??a()).replace(/\/$/,``),i=await fetch(`${r}/v1/experiences/${encodeURIComponent(n)}/preview`,{method:`GET`,headers:{Accept:`application/json`},signal:t?.signal});if(!i.ok){let e=`Experience preview failed (${i.status})`;try{let t=await i.json();t.message?.trim()&&(e=t.message.trim())}catch{}throw Error(e)}let o;try{o=await i.json()}catch{throw Error(`Experience preview returned invalid JSON.`)}if(!o||typeof o!=`object`)throw Error(`Experience preview returned an invalid payload.`);let s=o,c=typeof s.experienceId==`string`?s.experienceId.trim():n,l=typeof s.title==`string`?s.title.trim():``,u=Ac(s.galleryThumb);if(!u)throw Error(`Experience preview is missing gallery thumb images.`);return{experienceId:c||n,title:l||c||n,galleryThumb:u}}var Mc=`(min-width: 768px)`,Nc=24,Pc=.5,Fc=1200,Ic=.85,Lc=9/16;function Rc(){if(typeof window>`u`)return 800;let e=window.screen?.availHeight;return typeof e==`number`&&e>0?e:window.innerHeight}function zc(e=typeof window<`u`?window.innerWidth:1280,t=typeof window<`u`?window.innerHeight:800,n=Nc,r=typeof window<`u`?Rc():800){let i=Math.max(160,Math.min(t-n*2,t*Ic)),a=Math.max(120,e-n*2),o=Math.min(r*Pc,Fc,i),s=o*Lc;return s>a&&(s=a,o=s/Lc,o>i&&(o=i,s=o*Lc)),{width:Math.round(s),height:Math.round(o)}}function Bc(e,t=typeof window<`u`?window.innerWidth:1280,n=typeof window<`u`?window.innerHeight:800,r=Nc){return{left:Math.max(r,t-e.width-r),top:Math.max(r,n-e.height-r)}}function Vc(e,t,n,r=typeof window<`u`?window.innerWidth:1280,i=typeof window<`u`?window.innerHeight:800,a=Nc){let o=Math.max(a,r-n.width-a),s=Math.max(a,i-n.height-a);return{left:Math.min(Math.max(a,e),o),top:Math.min(Math.max(a,t),s)}}function Hc(e=typeof window<`u`?window.matchMedia.bind(window):()=>({matches:!0})){return e(Mc).matches}var Uc=`
308
+ }`,qt=!1;function Jt(e){if(typeof document>`u`||qt)return;if(document.querySelector(`style[data-liforma-et]`)){qt=!0;return}let t=document.createElement(`style`);t.setAttribute(`data-liforma-et`,``),t.textContent=e,document.head.appendChild(t),qt=!0}var Yt=`liforma-experience-thumbnail`;function Xt(e){if(e?.trim())try{let t=JSON.parse(e);if(t&&typeof t.avatarImage==`string`)return t}catch{}}var Zt=class extends HTMLElement{static get observedAttributes(){return[`experience-id`,`gallery-thumb`,`avatar-image`,`background-image`,`foreground-image`,`fallback-image`,`alt`,`href`,`target`,`rel`,`return-url`,`player-base-url`,`parallax`,`fit`,`lazy`]}#e=null;#t=[];#n=!1;#r=!1;#i=!1;#a=!1;#o=0;#s=0;#c=!1;#l=!1;#u=!1;#d=!1;connectedCallback(){this.#m()}disconnectedCallback(){this.#f()}attributeChangedCallback(){this.isConnected&&this.#m()}#f(){for(let e of this.#t)e();this.#t=[],this.#e=null}#p(e,t){if(!this.hasAttribute(e))return t;let n=this.getAttribute(e);return n===null||n===``||n===`true`?!0:n===`false`?!1:t}#m(){this.#f();let e=this.shadowRoot??this.attachShadow({mode:`open`}),t=document.createElement(`style`);t.textContent=Kt,e.replaceChildren(t);let n=this.getAttribute(`alt`)?.trim()||`Experience`,r=this.getAttribute(`href`),i=this.getAttribute(`experience-id`),a=xt({href:r,hasClickHandler:this.hasAttribute(`onclick`)||typeof this.onclick==`function`,experienceId:i}),o=vt({galleryThumb:Xt(this.getAttribute(`gallery-thumb`)),avatarImage:this.getAttribute(`avatar-image`)??void 0,backgroundImage:this.getAttribute(`background-image`)??void 0,foregroundImage:this.getAttribute(`foreground-image`)??void 0,fallbackImage:this.getAttribute(`fallback-image`)??void 0});if(!o)return;let s=this.#p(`parallax`,!0),c=this.getAttribute(`fit`)?.trim()===`face`?`face`:`full`,l=this.#p(`lazy`,!0);this.#n=!l;let u=a===`anchor`&&!r?.trim()&&!!i?.trim(),d=wt({href:r??void 0,experienceId:i??void 0,returnUrl:this.getAttribute(`return-url`)??void 0,playerBaseUrl:this.getAttribute(`player-base-url`)??void 0,useCurrentPageAsReturnUrl:u&&!this.getAttribute(`return-url`)?.trim()}),f;if(a===`anchor`&&d){let e=document.createElement(`a`);e.href=d;let t=this.getAttribute(`target`),n=this.getAttribute(`rel`);t&&(e.target=t),n&&(e.rel=n),f=e}else if(a===`button`){let e=document.createElement(`button`);e.type=`button`,f=e}else f=document.createElement(`div`),f.setAttribute(`role`,`img`);f.className=`liforma-et`,f.setAttribute(`aria-label`,n),this.#e=f,e.appendChild(f);let p=()=>{let e=!!o.backgroundImage,t=s&&(this.#r||this.#a),n=this.#n&&(this.#u||this.#l||this.#d);f.className=[`liforma-et`,e?`liforma-et--scene`:``,c===`face`?`liforma-et--fit-face`:``,t?`liforma-et--parallax`:``,this.#a?`liforma-et--scroll-parallax`:``,this.#n&&!n?`liforma-et--loading`:``,n?`liforma-et--revealed`:``].filter(Boolean).join(` `),f.style.setProperty(`--liforma-et-parallax-x`,String(this.#o)),f.style.setProperty(`--liforma-et-parallax-y`,String(this.#s))},m=document.createElement(`span`);m.className=`liforma-et__placeholder`,m.setAttribute(`aria-hidden`,`true`),f.appendChild(m);let h=()=>{if(!this.#n)return;let e=this.#c&&o.fallbackImage?o.fallbackImage:o.avatarImage;if(o.backgroundImage&&!f.querySelector(`.liforma-et__background`)){let e=document.createElement(`img`);e.className=`liforma-et__background liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=o.backgroundImage,this.#t.push(Ft(e,()=>{this.#l=!0,e.classList.add(`liforma-et__media--ready`),p()})),f.appendChild(e)}let t=f.querySelector(`.liforma-et__avatar`);if(t||(t=document.createElement(`img`),t.className=`liforma-et__avatar liforma-et__media`,t.alt=``,t.decoding=`async`,t.addEventListener(`error`,()=>{o.fallbackImage&&!this.#c?(this.#c=!0,t.src=o.fallbackImage):(this.#u=!0,p())}),this.#t.push(Ft(t,()=>{this.#u=!0,t.classList.add(`liforma-et__media--ready`),p()})),f.appendChild(t)),t.src!==e&&(t.src=e),o.foregroundImage&&!f.querySelector(`.liforma-et__foreground`)){let e=document.createElement(`img`);e.className=`liforma-et__foreground liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=o.foregroundImage,this.#t.push(Ft(e,()=>{this.#d=!0,e.classList.add(`liforma-et__media--ready`),p()})),f.appendChild(e)}p()};if(l?this.#t.push(Pt(f,{onVisibleChange:e=>{e&&(this.#n=!0,h(),p())}})):h(),s){this.#t.push(Wt(f,{onParallax:e=>{this.#a=!0,this.#i||(this.#o=e,this.#s=0,p())},pointerActive:()=>this.#i}));let e=e=>{if(this.#a)return;let t=f.getBoundingClientRect();t.width<=0||t.height<=0||(this.#o=((e.clientX-t.left)/t.width-.5)*2,this.#s=((e.clientY-t.top)/t.height-.5)*2,p())},t=e=>{this.#i=!0,e.pointerType===`mouse`&&(this.#r=!0),p()},n=()=>{let e=this.#i;this.#i=!1,this.#r=!1,this.#a&&e?(this.#o=Lt(f.getBoundingClientRect(),window.innerHeight),this.#s=0):this.#a||(this.#o=0,this.#s=0),p()};f.addEventListener(`pointermove`,e),f.addEventListener(`pointerdown`,t),f.addEventListener(`pointerup`,n),f.addEventListener(`pointercancel`,n),f.addEventListener(`pointerenter`,e=>{e.pointerType===`mouse`&&(this.#r=!0,p())}),f.addEventListener(`pointerleave`,()=>{this.#i||(this.#r=!1,this.#a||(this.#o=0,this.#s=0),p())}),this.#t.push(()=>{f.removeEventListener(`pointermove`,e),f.removeEventListener(`pointerdown`,t),f.removeEventListener(`pointerup`,n),f.removeEventListener(`pointercancel`,n)})}f.addEventListener(`click`,e=>{if(u&&!this.getAttribute(`return-url`)?.trim()){let t=wt({experienceId:i??void 0,playerBaseUrl:this.getAttribute(`player-base-url`)??void 0,useCurrentPageAsReturnUrl:!0});t&&e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&(e.preventDefault(),window.location.assign(t))}}),p()}};customElements.get(Yt)||customElements.define(Yt,Zt);function Qt(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.avatarImage==`string`?t.avatarImage.trim():``;return n?{avatarImage:n,...typeof t.backgroundImage==`string`&&t.backgroundImage.trim()?{backgroundImage:t.backgroundImage.trim()}:{},...typeof t.foregroundImage==`string`&&t.foregroundImage.trim()?{foregroundImage:t.foregroundImage.trim()}:{}}:null}async function $t(e,t){let n=e.trim();if(!n)throw Error(`Experience preview requires experienceId.`);let r=(t?.apiBaseUrl??a()).replace(/\/$/,``),i=await fetch(`${r}/v1/experiences/${encodeURIComponent(n)}/preview`,{method:`GET`,headers:{Accept:`application/json`},signal:t?.signal});if(!i.ok){let e=`Experience preview failed (${i.status})`;try{let t=await i.json();t.message?.trim()&&(e=t.message.trim())}catch{}throw Error(e)}let o;try{o=await i.json()}catch{throw Error(`Experience preview returned invalid JSON.`)}if(!o||typeof o!=`object`)throw Error(`Experience preview returned an invalid payload.`);let s=o,c=typeof s.experienceId==`string`?s.experienceId.trim():n,l=typeof s.title==`string`?s.title.trim():``,u=Qt(s.galleryThumb);if(!u)throw Error(`Experience preview is missing gallery thumb images.`);return{experienceId:c||n,title:l||c||n,galleryThumb:u}}var en=`(min-width: 768px)`,tn=24,nn=.5,rn=1200,an=.85,on=9/16;function sn(){if(typeof window>`u`)return 800;let e=window.screen?.availHeight;return typeof e==`number`&&e>0?e:window.innerHeight}function cn(e=typeof window<`u`?window.innerWidth:1280,t=typeof window<`u`?window.innerHeight:800,n=tn,r=typeof window<`u`?sn():800){let i=Math.max(160,Math.min(t-n*2,t*an)),a=Math.max(120,e-n*2),o=Math.min(r*nn,rn,i),s=o*on;return s>a&&(s=a,o=s/on,o>i&&(o=i,s=o*on)),{width:Math.round(s),height:Math.round(o)}}function ln(e,t=typeof window<`u`?window.innerWidth:1280,n=typeof window<`u`?window.innerHeight:800,r=tn){return{left:Math.max(r,t-e.width-r),top:Math.max(r,n-e.height-r)}}function un(e,t,n,r=typeof window<`u`?window.innerWidth:1280,i=typeof window<`u`?window.innerHeight:800,a=tn){let o=Math.max(a,r-n.width-a),s=Math.max(a,i-n.height-a);return{left:Math.min(Math.max(a,e),o),top:Math.min(Math.max(a,t),s)}}function Q(e=typeof window<`u`?window.matchMedia.bind(window):()=>({matches:!0})){return e(en).matches}var dn=`
349
309
  .liforma-ew {
350
310
  box-sizing: border-box;
351
311
  position: relative;
@@ -833,5 +793,5 @@ button.liforma-et {
833
793
  transition: none;
834
794
  }
835
795
  }
836
- `,Wc=`liforma-experience-widget-styles`;function Gc(e=Uc){if(typeof document>`u`)return;let t=document.getElementById(Wc);if(t){t.textContent=e;return}let n=document.createElement(`style`);n.id=Wc,n.textContent=e,document.head.append(n)}function Kc(e){return e===`bottom-right`||e===`bottom-left`?e:`static`}function qc(e){if(typeof e==`number`&&Number.isFinite(e))return`${e}px`;let t=typeof e==`string`?e.trim():``;return t?/^\d+(\.\d+)?$/.test(t)?`${t}px`:t:`16px`}function $(e){return e===`expanded`||e===`docked`}var Jc=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065"/><path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0-6 0"/></svg>`,Yc=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path fill="currentColor" d="M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7A1 1 0 0 0 5.7 7.11L10.59 12l-4.9 4.89a1 1 0 1 0 1.42 1.42L12 13.41l4.89 4.9a1 1 0 0 0 1.42-1.42L13.41 12l4.9-4.89a1 1 0 0 0-.01-1.4Z"/></svg>`,Xc=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 10h-4V6m6-2l-6 6m-8 4h4v4m0-4l-6 6"/></svg>`,Zc=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4h4v4m-6 2l6-6M8 20H4v-4m0 4l6-6"/></svg>`;function Qc(e,t,n){Ec(wc);let r=Js({galleryThumb:t.galleryThumb,avatarImage:t.avatarImage,backgroundImage:t.backgroundImage,foregroundImage:t.foregroundImage,fallbackImage:t.fallbackImage});if(!r)return e.replaceChildren(),null;let i=document.createElement(`div`);i.className=`liforma-et${r.backgroundImage?` liforma-et--scene`:``} liforma-et--revealed`,i.setAttribute(`aria-hidden`,`true`);let a=document.createElement(`span`);a.className=`liforma-et__placeholder`,a.setAttribute(`aria-hidden`,`true`),i.append(a);let o=e=>{e.classList.add(`liforma-et__media--ready`)};if(r.backgroundImage){let e=document.createElement(`img`);e.className=`liforma-et__background liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=r.backgroundImage,e.addEventListener(`load`,()=>o(e),{once:!0}),i.append(e)}let s=document.createElement(`img`);if(s.className=`liforma-et__avatar liforma-et__media`,s.alt=``,s.decoding=`async`,s.src=r.avatarImage,s.addEventListener(`load`,()=>o(s),{once:!0}),s.addEventListener(`error`,()=>{r.fallbackImage&&(s.src=r.fallbackImage)},{once:!0}),i.append(s),r.foregroundImage){let e=document.createElement(`img`);e.className=`liforma-et__foreground liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=r.foregroundImage,e.addEventListener(`load`,()=>o(e),{once:!0}),i.append(e)}return e.replaceChildren(i),n?.parallax===!1?()=>{}:Cc(i)}function $c(e){return e.startButton?{...e.startButton,label:e.startButton.label??e.startButtonLabel??`Tap to talk`,placement:e.startButton.placement??`bottom-center`,variant:e.startButton.variant??`primary`}:{label:e.startButtonLabel??`Tap to talk`,placement:`bottom-center`,variant:`primary`}}function el(e){let t=!1,n=()=>{t||e()},r=()=>{if(t)return;let e=window.requestIdleCallback;if(typeof e==`function`){let t=e(n,{timeout:3e3});i=()=>{window.cancelIdleCallback?.(t)};return}let r=window.setTimeout(n,1);i=()=>window.clearTimeout(r)},i=null;return document.readyState===`complete`?r():window.addEventListener(`load`,r,{once:!0}),()=>{t=!0,window.removeEventListener(`load`,r),i?.()}}function tl(e,t){Gc(Uc);let n=t.experienceId?.trim();if(!n)throw Error(`ExperienceWidget requires experienceId.`);let r=t.prefetch??`onExpand`,i=Kc(t.position),a=document.createElement(`div`);a.className=`liforma-ew`,a.dataset.state=`collapsed`,a.dataset.prefetch=r,a.dataset.position=i,a.style.setProperty(`--liforma-ew-max-w`,t.expandedMaxWidth??`100%`),a.style.setProperty(`--liforma-ew-max-h`,t.expandedMaxHeight??`100%`),i!==`static`&&a.style.setProperty(`--liforma-ew-offset`,qc(t.offset));let o=document.createElement(`button`);o.type=`button`,o.className=`liforma-ew__hit`,o.setAttribute(`aria-label`,t.alt),o.disabled=!0;let s=document.createElement(`div`);s.className=`liforma-ew__face`,o.append(s);let c=document.createElement(`div`);c.className=`liforma-ew__face-status`,c.textContent=`Loading…`,s.append(c);let l=document.createElement(`div`);l.className=`liforma-ew__warm`,l.hidden=!0,l.setAttribute(`aria-hidden`,`true`);let u=document.createElement(`div`);u.className=`liforma-ew__overlay`,u.hidden=!0,u.setAttribute(`role`,`dialog`),u.setAttribute(`aria-modal`,`true`),u.setAttribute(`aria-label`,t.alt);let d=document.createElement(`button`);d.type=`button`,d.className=`liforma-ew__backdrop`,d.setAttribute(`aria-label`,`Close experience`);let f=document.createElement(`div`);f.className=`liforma-ew__panel`;let p=document.createElement(`div`);p.className=`liforma-ew__toolbar`,p.hidden=!0;let m=document.createElement(`span`);m.className=`liforma-ew__drag-grip`,m.setAttribute(`aria-hidden`,`true`);let h=document.createElement(`button`);h.type=`button`,h.className=`liforma-ew__icon-btn liforma-ew__dock-toggle`,h.innerHTML=Xc,h.setAttribute(`aria-label`,`Reduce`);let g=document.createElement(`button`);g.type=`button`,g.className=`liforma-ew__icon-btn liforma-ew__settings`,g.innerHTML=Jc,g.setAttribute(`aria-label`,`Audio settings`),g.setAttribute(`aria-pressed`,`false`);let _=document.createElement(`button`);_.type=`button`,_.className=`liforma-ew__icon-btn liforma-ew__close`,_.innerHTML=Yc,_.setAttribute(`aria-label`,`Close`),p.append(m,h,g,_);let ee=document.createElement(`div`);ee.className=`liforma-ew__stage`;let v=document.createElement(`div`);v.className=`liforma-ew__status`,v.hidden=!0,f.append(ee,v),u.append(d,f),a.append(o,l,u,p),e.replaceChildren(a);let y=null,b=!1,x=!1,te=!1,S=!1,C=!1,w=!1,T=!1,E=0,ne=``,re=null,D=null,O=null,k=null,A=null,ie=null,j=null,ae=0,oe=0,M=null,se=!1,ce=new AbortController,le=t.parallax!==!1,N=()=>{let e=a.dataset.state;return e===`expanded`||e===`docked`||e===`collapsed`?e:`collapsed`},ue=()=>{O!==null&&(clearTimeout(O),O=null)},P=()=>{k!==null&&(clearTimeout(k),k=null),a.classList.remove(`liforma-ew--layout-settling`)},de=()=>{for(let e of[f,l,p])e.style.removeProperty(`left`),e.style.removeProperty(`top`),e.style.removeProperty(`width`),e.style.removeProperty(`height`),e.style.removeProperty(`right`),e.style.removeProperty(`bottom`);p.classList.remove(`liforma-ew__toolbar--dragging`),a.classList.remove(`liforma-ew--dock-dragging`)},F=(e,t,n,r)=>{let i=i=>{i.style.left=`${e}px`,i.style.top=`${t}px`,i.style.width=`${n}px`,i.style.height=`${r}px`,i.style.right=`auto`,i.style.bottom=`auto`};i(f),i(l);let a=p.offsetWidth||120;p.style.left=`${e+n-a-10}px`,p.style.top=`${t+10}px`,p.style.right=`auto`,p.style.bottom=`auto`,p.style.width=`auto`,p.style.height=`auto`},fe=(e,t)=>{if(N()!==`docked`)return;let n=zc(),r=Vc(e-ae,t-oe,n);A=r.left,ie=r.top,F(r.left,r.top,n.width,n.height)},pe=(e,t)=>{if(N()!==`docked`||!Number.isFinite(e)||!Number.isFinite(t)||e===0&&t===0)return;let n=zc(),r=A??f.getBoundingClientRect().left,i=ie??f.getBoundingClientRect().top,a=Vc(r+e,i+t,n);A=a.left,ie=a.top,F(a.left,a.top,n.width,n.height)},me=e=>{M===`toolbar`&&(j===null||e.pointerId!==j||(e.preventDefault(),fe(e.clientX,e.clientY)))},I=e=>{if(j===null||e&&e.pointerId!==j)return;let t=M;j=null,M=null,p.classList.remove(`liforma-ew__toolbar--dragging`),a.classList.remove(`liforma-ew--dock-dragging`),t===`toolbar`&&se&&(se=!1,window.removeEventListener(`pointermove`,me),window.removeEventListener(`pointerup`,I),window.removeEventListener(`pointercancel`,I))},he=(e,t,n)=>{if(x||N()!==`docked`||!Hc()||j!==null)return;j=n,M=`toolbar`,p.classList.add(`liforma-ew__toolbar--dragging`),a.classList.add(`liforma-ew--dock-dragging`);let r=f.getBoundingClientRect();ae=e-r.left,oe=t-r.top,se||(se=!0,window.addEventListener(`pointermove`,me),window.addEventListener(`pointerup`,I),window.addEventListener(`pointercancel`,I))},ge=e=>{if(x||N()!==`docked`||!Hc()||j!==null)return;j=e.pointerId,M=`player`,p.classList.add(`liforma-ew__toolbar--dragging`),a.classList.add(`liforma-ew--dock-dragging`);let t=f.getBoundingClientRect();A=t.left,ie=t.top},_e=e=>{M===`player`&&(j===null||e.pointerId!==j||pe(e.dx,e.dy))},ve=e=>{M===`player`&&(j===null||e.pointerId!==j||I())},L=()=>{let e=Hc(),t=N();if(!e||t!==`expanded`&&t!==`docked`){h.hidden=!0;return}h.hidden=!1,t===`docked`?(h.innerHTML=Zc,h.setAttribute(`aria-label`,`Maximize`)):(h.innerHTML=Xc,h.setAttribute(`aria-label`,`Reduce`))},ye=e=>{let t=zc(),n=e&&A!==null&&ie!==null?Vc(A,ie,t):Bc(t);n=Vc(n.left,n.top,t),A=n.left,ie=n.top,F(n.left,n.top,t.width,t.height),L()},be=()=>{a.classList.remove(`liforma-ew--session-revealed`),requestAnimationFrame(()=>{requestAnimationFrame(()=>{x||!$(a.dataset.state)||a.classList.add(`liforma-ew--session-revealed`)})})},xe=e=>{if(P(),a.classList.remove(`liforma-ew--session-revealed`),a.classList.add(`liforma-ew--layout-settling`),e(),!T){a.classList.remove(`liforma-ew--layout-settling`);return}k=setTimeout(()=>{if(k=null,x||!$(a.dataset.state)){a.classList.remove(`liforma-ew--layout-settling`);return}a.classList.remove(`liforma-ew--layout-settling`),be()},220)},Se=()=>(a.classList.add(`liforma-ew--session-concealing`),a.classList.remove(`liforma-ew--session-revealed`),new Promise(e=>{ue(),O=setTimeout(()=>{O=null,a.classList.remove(`liforma-ew--session-concealing`),e()},280)})),Ce={galleryThumb:t.galleryThumb,avatarImage:t.avatarImage,backgroundImage:t.backgroundImage,foregroundImage:t.foregroundImage,fallbackImage:t.fallbackImage},R=e=>{if(!e){v.hidden=!0,v.textContent=``;return}v.hidden=!1,v.textContent=e},we=e=>{if(!e){c.hidden=!0,c.textContent=``;return}c.hidden=!1,c.textContent=e,s.contains(c)||s.append(c)},Te=()=>{te=!0,o.disabled=!1,we(null),r===`onExpand`&&t.onPrefetchReady?.()},Ee=()=>{S=!0,a.dataset.warm=`true`,l.hidden=!1,T||(o.tabIndex=-1,o.setAttribute(`aria-hidden`,`true`)),t.onPrefetchReady?.()},De=e=>{re?.(),re=null;let t=Qc(s,e,{parallax:le});return t?(re=t,!0):!1},Oe=()=>{if(De(Ce)){Te();return}we(`Loading…`),jc(n,{signal:ce.signal}).then(e=>{if(!x){if(!De({galleryThumb:e.galleryThumb}))throw Error(`Experience preview is missing gallery thumb images.`);Te()}}).catch(e=>{if(x||ce.signal.aborted)return;let n=e instanceof Error?e:Error(String(e));we(`Preview unavailable`),o.disabled=!0,t.onError?.(n),console.error(`[ExperienceWidget]`,n)})},ke=()=>({experienceId:n,ui:`widget`,...t.sessionEndpoint?{sessionEndpoint:t.sessionEndpoint}:{},...t.language?{language:t.language}:{},...t.mode?{mode:t.mode}:{},...t.speechInputMode?{speechInputMode:t.speechInputMode}:{},...t.speechOnly===void 0?{}:{speechOnly:t.speechOnly},...t.fit?{fit:t.fit}:{},...t.embedBaseUrl?{embedBaseUrl:t.embedBaseUrl}:{},startButton:$c(t)}),Ae=(e=!0)=>{o.hidden=!0,u.hidden=!1,p.hidden=!1,u.setAttribute(`aria-modal`,`true`),de(),a.dataset.state=`expanded`,R(null),typeof document<`u`&&(ne=document.body.style.overflow,document.body.style.overflow=`hidden`),L(),e&&t.onExpanded?.()},je=()=>{o.hidden=!0,u.hidden=!1,p.hidden=!1,u.setAttribute(`aria-modal`,`false`),a.dataset.state=`docked`,R(null),typeof document<`u`&&(document.body.style.overflow=ne),ye(!0),L(),y?.setWidgetChrome(`docked`)},Me=e=>{e.on(`started`,()=>{x||(T=!0,a.dataset.live=`true`,R(null),t.onStarted?.(),$(a.dataset.state)&&be())})},Ne=()=>{P(),u.hidden=!0,p.hidden=!0,de(),a.dataset.state=`collapsed`,a.classList.remove(`liforma-ew--session-revealed`),a.classList.remove(`liforma-ew--session-concealing`),g.setAttribute(`aria-pressed`,`false`),o.hidden=!1,o.tabIndex=0,o.removeAttribute(`aria-hidden`),te&&(o.disabled=!1),R(null),typeof document<`u`&&(document.body.style.overflow=ne),L()},Pe=()=>{ue(),P(),E+=1,b=!1,S=!1,C=!1,w=!1,T=!1;let e=y;y=null,e?.destroy(),ee.replaceChildren(),l.replaceChildren(),l.hidden=!0,delete a.dataset.warm,delete a.dataset.live,a.classList.remove(`liforma-ew--session-revealed`)},Fe=()=>{if(!x&&$(a.dataset.state)){if(I(),b=!1,y&&w){let e=y;(async()=>{T&&(await Se(),x||y!==e)||(S&&e.setWidgetChrome(`collapsed`),Ne(),T?(a.dataset.live=`true`,o.tabIndex=0,o.removeAttribute(`aria-hidden`),o.disabled=!1):S&&Ee(),t.onCollapsed?.(),t.onClose?.())})();return}Pe(),Ne(),t.onCollapsed?.(),t.onClose?.()}},Ie=()=>{x||Hc()&&N()===`expanded`&&xe(()=>{je()})},Le=()=>{x||N()===`docked`&&(I(),xe(()=>{de(),Ae(!1),y?.setWidgetChrome(`expanded`)}))},Re=()=>{!y||!T||(ue(),a.classList.remove(`liforma-ew--session-revealed`),Ae(),y.setWidgetChrome(`expanded`),b=!1,be())},ze=()=>{!y||!w||T||(ue(),a.classList.remove(`liforma-ew--session-revealed`),Ae(),b=!1,S&&y.setWidgetChrome(`expanded`))},Be=e=>{x||e!==E&&!T||(ue(),a.classList.remove(`liforma-ew--session-revealed`),Ae(),b=!1,y?.setWidgetChrome(`expanded`),T&&be())},Ve=()=>{if(x||C||S||y||$(a.dataset.state))return;C=!0;let e=E;l.hidden=!1,(async()=>{try{let t=await ws.startSession(ke());if(x||e!==E){t.destroy();return}y=t,Me(t);let n=await t.attach({container:l,onWidgetReady:()=>{x||e!==E||(C=!1,w=!0,Ee())},onWidgetExpand:()=>{Be(e)},onWidgetAudioSettings:e=>{x||Ge(e)},onWidgetDragStart:e=>{x||ge(e)},onWidgetDragMove:e=>{x||_e(e)},onWidgetDragEnd:e=>{x||ve(e)},onStateUpdate:e=>{x||e===`error`&&$(a.dataset.state)&&R(`Could not load the experience.`)}});if(x||e!==E){t.destroy(),y===t&&(y=null);return}w=!0,n.on(`close`,()=>{x||Fe()})}catch(n){if(x||e!==E)return;C=!1,l.hidden=!0,l.replaceChildren(),y=null;let r=n instanceof Error?n:Error(String(n));t.onError?.(r),console.error(`[ExperienceWidget] warm prefetch failed`,r)}})()},He=()=>{if(x||b||!te||$(a.dataset.state))return;if(y&&T){Re();return}if(y&&w){ze();return}let e=++E;b=!0,S=!1,C=!1,w=!1,T=!1,delete a.dataset.warm,delete a.dataset.live,l.hidden=!0,l.replaceChildren(),y&&=(y.destroy(),null),(async()=>{try{Ae();let t=await ws.startSession(ke());if(x||e!==E){t.destroy();return}y=t,Me(t);let n=await t.attach({container:ee,onWidgetAudioSettings:e=>{x||Ge(e)},onWidgetDragStart:e=>{x||ge(e)},onWidgetDragMove:e=>{x||_e(e)},onWidgetDragEnd:e=>{x||ve(e)},onStateUpdate:e=>{x||(e===`error`?R(`Could not load the experience.`):$(a.dataset.state)&&R(null))}});if(x||e!==E){t.destroy(),y===t&&(y=null);return}w=!0,n.on(`close`,()=>{x||Fe()})}catch(n){if(x||e!==E)return;let r=n instanceof Error?n:Error(String(n));R(r.message),t.onError?.(r),console.error(`[ExperienceWidget]`,r)}finally{e===E&&(b=!1)}})()},Ue=()=>{if(!(x||$(a.dataset.state))){if(y&&T){Re();return}if(y&&w){ze();return}He()}},We=e=>{if(e.stopPropagation(),N()===`expanded`){Ie();return}N()===`docked`&&Le()},Ge=e=>{g.setAttribute(`aria-pressed`,e?`true`:`false`)},Ke=e=>{e.stopPropagation(),$(a.dataset.state)&&y?.toggleAudioSettings()},qe=e=>{N()===`docked`&&Hc()&&(e.target?.closest(`button`)||(e.preventDefault(),he(e.clientX,e.clientY,e.pointerId)))},Je=e=>{e.key===`Escape`&&$(a.dataset.state)&&(e.preventDefault(),Fe())},Ye=()=>{if(!x){if(N()===`docked`){if(!Hc()){Le();return}T?xe(()=>{ye(!0)}):ye(!0);return}L()}},Xe=typeof window<`u`?window.matchMedia(Mc):null,Ze=()=>{if(!x){if(N()===`docked`&&!Hc()){Le();return}L()}};return o.addEventListener(`click`,Ue),d.addEventListener(`click`,Fe),_.addEventListener(`click`,e=>{e.stopPropagation(),Fe()}),h.addEventListener(`click`,We),g.addEventListener(`click`,Ke),p.addEventListener(`pointerdown`,qe),window.addEventListener(`keydown`,Je),window.addEventListener(`resize`,Ye),Xe?.addEventListener(`change`,Ze),Oe(),L(),r===`eager`?queueMicrotask(()=>{x||Ve()}):r===`idle`&&(D=el(()=>{x||Ve()})),{root:a,expand:Ue,collapse:Fe,dock:Ie,maximize:Le,prefetch(){if(r===`onExpand`){Ve();return}Ve()},destroy(){x||(x=!0,I(),D?.(),D=null,ce.abort(),re?.(),re=null,window.removeEventListener(`keydown`,Je),window.removeEventListener(`resize`,Ye),Xe?.removeEventListener(`change`,Ze),Pe(),Ne(),e.replaceChildren())}}}var nl=`liforma-experience-widget`;function rl(e){if(e?.trim())try{let t=JSON.parse(e);if(t&&typeof t==`object`&&typeof t.avatarImage==`string`)return t}catch{}}function il(e){let t=e?.trim();return t===`conversation`||t===`presenter`?t:void 0}function al(e){let t=e?.trim();return t===`auto`||t===`manual`||t===`off`?t:void 0}function ol(e){let t=e?.trim();return t===`full`||t===`face`?t:void 0}function sl(e){let t=e?.trim();return t===`en`||t===`es`?t:void 0}function cl(e){let t=e?.trim();return t===`bottom-right`||t===`bottom-left`?t:`static`}var ll=class extends HTMLElement{static get observedAttributes(){return[`experience-id`,`alt`,`gallery-thumb`,`avatar-image`,`background-image`,`foreground-image`,`fallback-image`,`prefetch`,`parallax`,`position`,`offset`,`session-endpoint`,`language`,`mode`,`speech-input-mode`,`speech-only`,`fit`,`expanded-max-width`,`expanded-max-height`,`start-button-label`]}#e=null;#t=null;connectedCallback(){this.#n(),this.#r()}disconnectedCallback(){this.#e?.destroy(),this.#e=null}attributeChangedCallback(){this.isConnected&&(this.#n(),this.#r())}#n(){if(cl(this.getAttribute(`position`))!==`static`){this.style.display=`contents`,this.style.removeProperty(`width`),this.style.removeProperty(`height`),this.style.removeProperty(`min-height`);return}if(this.style.display=`block`,this.style.width||=`100%`,this.style.height||=`100%`,!this.style.minHeight){let e=getComputedStyle(this).minHeight;(e===`0px`||e===`auto`)&&(this.style.minHeight=`224px`)}}#r(){this.#e?.destroy(),this.#e=null;let e=this.getAttribute(`experience-id`)?.trim(),t=this.getAttribute(`alt`)?.trim()||`Open experience`;if(!e)return;let n=cl(this.getAttribute(`position`));this.#t||(this.#t=document.createElement(`div`),this.replaceChildren(this.#t)),this.#t.style.cssText=n===`static`?`width:100%;height:100%;min-height:inherit;`:`display:contents;`;let r=this.getAttribute(`prefetch`)?.trim(),i=r===`idle`||r===`eager`||r===`onExpand`?r:`onExpand`,a=this.getAttribute(`speech-only`),o=this.getAttribute(`offset`);try{this.#e=tl(this.#t,{experienceId:e,alt:t,galleryThumb:rl(this.getAttribute(`gallery-thumb`)),avatarImage:this.getAttribute(`avatar-image`)??void 0,backgroundImage:this.getAttribute(`background-image`)??void 0,foregroundImage:this.getAttribute(`foreground-image`)??void 0,fallbackImage:this.getAttribute(`fallback-image`)??void 0,prefetch:i,parallax:this.getAttribute(`parallax`)!==`false`,position:n,offset:o===null?void 0:o,sessionEndpoint:this.getAttribute(`session-endpoint`)??void 0,language:sl(this.getAttribute(`language`)),mode:il(this.getAttribute(`mode`)),speechInputMode:al(this.getAttribute(`speech-input-mode`)),speechOnly:a===null?void 0:a===``||a===`true`,fit:ol(this.getAttribute(`fit`)),expandedMaxWidth:this.getAttribute(`expanded-max-width`)??void 0,expandedMaxHeight:this.getAttribute(`expanded-max-height`)??void 0,startButtonLabel:this.getAttribute(`start-button-label`)??void 0,onExpanded:()=>{this.dispatchEvent(new CustomEvent(`expanded`,{bubbles:!0}))},onCollapsed:()=>{this.dispatchEvent(new CustomEvent(`collapsed`,{bubbles:!0}))},onStarted:()=>{this.dispatchEvent(new CustomEvent(`started`,{bubbles:!0}))},onClose:()=>{this.dispatchEvent(new CustomEvent(`close`,{bubbles:!0}))},onError:e=>{this.dispatchEvent(new CustomEvent(`error`,{detail:e,bubbles:!0}))}})}catch(e){console.error(`[liforma-experience-widget]`,e)}}};return typeof customElements<`u`&&!customElements.get(nl)&&customElements.define(nl,ll),window.Liforma={Experience:ws,sdkVersion:`v2`,features:{speakApi:!0,speechAudioApi:!0}},e.Experience=ws,e.SPEECH_LIMITS=Yo,e.SpeechBufferTimeoutError=Qo,e.SpeechRuntimeError=Q,e.SpeechUtteranceClosedError=Zo,e.UnsupportedSpeechOperationError=Xo,e})({});
796
+ `,fn=`liforma-experience-widget-styles`;function pn(e=dn){if(typeof document>`u`)return;let t=document.getElementById(fn);if(t){t.textContent=e;return}let n=document.createElement(`style`);n.id=fn,n.textContent=e,document.head.append(n)}function mn(e){return e===`bottom-right`||e===`bottom-left`?e:`static`}function hn(e){if(typeof e==`number`&&Number.isFinite(e))return`${e}px`;let t=typeof e==`string`?e.trim():``;return t?/^\d+(\.\d+)?$/.test(t)?`${t}px`:t:`16px`}function $(e){return e===`expanded`||e===`docked`}var gn=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065"/><path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0-6 0"/></svg>`,_n=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path fill="currentColor" d="M18.3 5.71a1 1 0 0 0-1.41 0L12 10.59 7.11 5.7A1 1 0 0 0 5.7 7.11L10.59 12l-4.9 4.89a1 1 0 1 0 1.42 1.42L12 13.41l4.89 4.9a1 1 0 0 0 1.42-1.42L13.41 12l4.9-4.89a1 1 0 0 0-.01-1.4Z"/></svg>`,vn=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 10h-4V6m6-2l-6 6m-8 4h4v4m0-4l-6 6"/></svg>`,yn=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 4h4v4m-6 2l6-6M8 20H4v-4m0 4l6-6"/></svg>`;function bn(e,t,n){Jt(Kt);let r=vt({galleryThumb:t.galleryThumb,avatarImage:t.avatarImage,backgroundImage:t.backgroundImage,foregroundImage:t.foregroundImage,fallbackImage:t.fallbackImage});if(!r)return e.replaceChildren(),null;let i=document.createElement(`div`);i.className=`liforma-et${r.backgroundImage?` liforma-et--scene`:``} liforma-et--revealed`,i.setAttribute(`aria-hidden`,`true`);let a=document.createElement(`span`);a.className=`liforma-et__placeholder`,a.setAttribute(`aria-hidden`,`true`),i.append(a);let o=e=>{e.classList.add(`liforma-et__media--ready`)};if(r.backgroundImage){let e=document.createElement(`img`);e.className=`liforma-et__background liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=r.backgroundImage,e.addEventListener(`load`,()=>o(e),{once:!0}),i.append(e)}let s=document.createElement(`img`);if(s.className=`liforma-et__avatar liforma-et__media`,s.alt=``,s.decoding=`async`,s.src=r.avatarImage,s.addEventListener(`load`,()=>o(s),{once:!0}),s.addEventListener(`error`,()=>{r.fallbackImage&&(s.src=r.fallbackImage)},{once:!0}),i.append(s),r.foregroundImage){let e=document.createElement(`img`);e.className=`liforma-et__foreground liforma-et__media`,e.alt=``,e.decoding=`async`,e.src=r.foregroundImage,e.addEventListener(`load`,()=>o(e),{once:!0}),i.append(e)}return e.replaceChildren(i),n?.parallax===!1?()=>{}:Gt(i)}function xn(e){return e.startButton?{...e.startButton,label:e.startButton.label??e.startButtonLabel??`Tap to talk`,placement:e.startButton.placement??`bottom-center`,variant:e.startButton.variant??`primary`}:{label:e.startButtonLabel??`Tap to talk`,placement:`bottom-center`,variant:`primary`}}function Sn(e){let t=!1,n=()=>{t||e()},r=()=>{if(t)return;let e=window.requestIdleCallback;if(typeof e==`function`){let t=e(n,{timeout:3e3});i=()=>{window.cancelIdleCallback?.(t)};return}let r=window.setTimeout(n,1);i=()=>window.clearTimeout(r)},i=null;return document.readyState===`complete`?r():window.addEventListener(`load`,r,{once:!0}),()=>{t=!0,window.removeEventListener(`load`,r),i?.()}}function Cn(e,t){pn(dn);let n=t.experienceId?.trim();if(!n)throw Error(`ExperienceWidget requires experienceId.`);let r=t.prefetch??`onExpand`,i=mn(t.position),a=document.createElement(`div`);a.className=`liforma-ew`,a.dataset.state=`collapsed`,a.dataset.prefetch=r,a.dataset.position=i,a.style.setProperty(`--liforma-ew-max-w`,t.expandedMaxWidth??`100%`),a.style.setProperty(`--liforma-ew-max-h`,t.expandedMaxHeight??`100%`),i!==`static`&&a.style.setProperty(`--liforma-ew-offset`,hn(t.offset));let o=document.createElement(`button`);o.type=`button`,o.className=`liforma-ew__hit`,o.setAttribute(`aria-label`,t.alt),o.disabled=!0;let s=document.createElement(`div`);s.className=`liforma-ew__face`,o.append(s);let c=document.createElement(`div`);c.className=`liforma-ew__face-status`,c.textContent=`Loading…`,s.append(c);let l=document.createElement(`div`);l.className=`liforma-ew__warm`,l.hidden=!0,l.setAttribute(`aria-hidden`,`true`);let u=document.createElement(`div`);u.className=`liforma-ew__overlay`,u.hidden=!0,u.setAttribute(`role`,`dialog`),u.setAttribute(`aria-modal`,`true`),u.setAttribute(`aria-label`,t.alt);let d=document.createElement(`button`);d.type=`button`,d.className=`liforma-ew__backdrop`,d.setAttribute(`aria-label`,`Close experience`);let f=document.createElement(`div`);f.className=`liforma-ew__panel`;let p=document.createElement(`div`);p.className=`liforma-ew__toolbar`,p.hidden=!0;let m=document.createElement(`span`);m.className=`liforma-ew__drag-grip`,m.setAttribute(`aria-hidden`,`true`);let h=document.createElement(`button`);h.type=`button`,h.className=`liforma-ew__icon-btn liforma-ew__dock-toggle`,h.innerHTML=vn,h.setAttribute(`aria-label`,`Reduce`);let g=document.createElement(`button`);g.type=`button`,g.className=`liforma-ew__icon-btn liforma-ew__settings`,g.innerHTML=gn,g.setAttribute(`aria-label`,`Audio settings`),g.setAttribute(`aria-pressed`,`false`);let _=document.createElement(`button`);_.type=`button`,_.className=`liforma-ew__icon-btn liforma-ew__close`,_.innerHTML=_n,_.setAttribute(`aria-label`,`Close`),p.append(m,h,g,_);let ee=document.createElement(`div`);ee.className=`liforma-ew__stage`;let v=document.createElement(`div`);v.className=`liforma-ew__status`,v.hidden=!0,f.append(ee,v),u.append(d,f),a.append(o,l,u,p),e.replaceChildren(a);let y=null,b=!1,x=!1,te=!1,S=!1,C=!1,w=!1,T=!1,E=0,ne=``,D=null,re=null,O=null,k=null,A=null,j=null,M=null,ie=0,ae=0,N=null,P=!1,oe=new AbortController,se=t.parallax!==!1,F=()=>{let e=a.dataset.state;return e===`expanded`||e===`docked`||e===`collapsed`?e:`collapsed`},I=()=>{O!==null&&(clearTimeout(O),O=null)},L=()=>{k!==null&&(clearTimeout(k),k=null),a.classList.remove(`liforma-ew--layout-settling`)},ce=()=>{for(let e of[f,l,p])e.style.removeProperty(`left`),e.style.removeProperty(`top`),e.style.removeProperty(`width`),e.style.removeProperty(`height`),e.style.removeProperty(`right`),e.style.removeProperty(`bottom`);p.classList.remove(`liforma-ew__toolbar--dragging`),a.classList.remove(`liforma-ew--dock-dragging`)},le=(e,t,n,r)=>{let i=i=>{i.style.left=`${e}px`,i.style.top=`${t}px`,i.style.width=`${n}px`,i.style.height=`${r}px`,i.style.right=`auto`,i.style.bottom=`auto`};i(f),i(l);let a=p.offsetWidth||120;p.style.left=`${e+n-a-10}px`,p.style.top=`${t+10}px`,p.style.right=`auto`,p.style.bottom=`auto`,p.style.width=`auto`,p.style.height=`auto`},ue=(e,t)=>{if(F()!==`docked`)return;let n=cn(),r=un(e-ie,t-ae,n);A=r.left,j=r.top,le(r.left,r.top,n.width,n.height)},de=(e,t)=>{if(F()!==`docked`||!Number.isFinite(e)||!Number.isFinite(t)||e===0&&t===0)return;let n=cn(),r=A??f.getBoundingClientRect().left,i=j??f.getBoundingClientRect().top,a=un(r+e,i+t,n);A=a.left,j=a.top,le(a.left,a.top,n.width,n.height)},fe=e=>{N===`toolbar`&&(M===null||e.pointerId!==M||(e.preventDefault(),ue(e.clientX,e.clientY)))},R=e=>{if(M===null||e&&e.pointerId!==M)return;let t=N;M=null,N=null,p.classList.remove(`liforma-ew__toolbar--dragging`),a.classList.remove(`liforma-ew--dock-dragging`),t===`toolbar`&&P&&(P=!1,window.removeEventListener(`pointermove`,fe),window.removeEventListener(`pointerup`,R),window.removeEventListener(`pointercancel`,R))},pe=(e,t,n)=>{if(x||F()!==`docked`||!Q()||M!==null)return;M=n,N=`toolbar`,p.classList.add(`liforma-ew__toolbar--dragging`),a.classList.add(`liforma-ew--dock-dragging`);let r=f.getBoundingClientRect();ie=e-r.left,ae=t-r.top,P||(P=!0,window.addEventListener(`pointermove`,fe),window.addEventListener(`pointerup`,R),window.addEventListener(`pointercancel`,R))},me=e=>{if(x||F()!==`docked`||!Q()||M!==null)return;M=e.pointerId,N=`player`,p.classList.add(`liforma-ew__toolbar--dragging`),a.classList.add(`liforma-ew--dock-dragging`);let t=f.getBoundingClientRect();A=t.left,j=t.top},he=e=>{N===`player`&&(M===null||e.pointerId!==M||de(e.dx,e.dy))},ge=e=>{N===`player`&&(M===null||e.pointerId!==M||R())},z=()=>{let e=Q(),t=F();if(!e||t!==`expanded`&&t!==`docked`){h.hidden=!0;return}h.hidden=!1,t===`docked`?(h.innerHTML=yn,h.setAttribute(`aria-label`,`Maximize`)):(h.innerHTML=vn,h.setAttribute(`aria-label`,`Reduce`))},_e=e=>{let t=cn(),n=e&&A!==null&&j!==null?un(A,j,t):ln(t);n=un(n.left,n.top,t),A=n.left,j=n.top,le(n.left,n.top,t.width,t.height),z()},ve=()=>{a.classList.remove(`liforma-ew--session-revealed`),requestAnimationFrame(()=>{requestAnimationFrame(()=>{x||!$(a.dataset.state)||a.classList.add(`liforma-ew--session-revealed`)})})},ye=e=>{if(L(),a.classList.remove(`liforma-ew--session-revealed`),a.classList.add(`liforma-ew--layout-settling`),e(),!T){a.classList.remove(`liforma-ew--layout-settling`);return}k=setTimeout(()=>{if(k=null,x||!$(a.dataset.state)){a.classList.remove(`liforma-ew--layout-settling`);return}a.classList.remove(`liforma-ew--layout-settling`),ve()},220)},be=()=>(a.classList.add(`liforma-ew--session-concealing`),a.classList.remove(`liforma-ew--session-revealed`),new Promise(e=>{I(),O=setTimeout(()=>{O=null,a.classList.remove(`liforma-ew--session-concealing`),e()},280)})),xe={galleryThumb:t.galleryThumb,avatarImage:t.avatarImage,backgroundImage:t.backgroundImage,foregroundImage:t.foregroundImage,fallbackImage:t.fallbackImage},B=e=>{if(!e){v.hidden=!0,v.textContent=``;return}v.hidden=!1,v.textContent=e},V=e=>{if(!e){c.hidden=!0,c.textContent=``;return}c.hidden=!1,c.textContent=e,s.contains(c)||s.append(c)},H=()=>{te=!0,o.disabled=!1,V(null),r===`onExpand`&&t.onPrefetchReady?.()},Se=()=>{S=!0,a.dataset.warm=`true`,l.hidden=!1,T||(o.tabIndex=-1,o.setAttribute(`aria-hidden`,`true`)),t.onPrefetchReady?.()},Ce=e=>{D?.(),D=null;let t=bn(s,e,{parallax:se});return t?(D=t,!0):!1},U=()=>{if(Ce(xe)){H();return}V(`Loading…`),$t(n,{signal:oe.signal}).then(e=>{if(!x){if(!Ce({galleryThumb:e.galleryThumb}))throw Error(`Experience preview is missing gallery thumb images.`);H()}}).catch(e=>{if(x||oe.signal.aborted)return;let n=e instanceof Error?e:Error(String(e));V(`Preview unavailable`),o.disabled=!0,t.onError?.(n),console.error(`[ExperienceWidget]`,n)})},we=()=>({experienceId:n,ui:`widget`,...t.sessionEndpoint?{sessionEndpoint:t.sessionEndpoint}:{},...t.locale?{locale:t.locale}:{},...t.language?{language:t.language}:{},...t.mode?{mode:t.mode}:{},...t.speechInputMode?{speechInputMode:t.speechInputMode}:{},...t.speechOnly===void 0?{}:{speechOnly:t.speechOnly},...t.embedBaseUrl?{embedBaseUrl:t.embedBaseUrl}:{}}),W=()=>({...t.fit?{fit:t.fit}:{},startButton:xn(t)}),G=(e=!0)=>{o.hidden=!0,u.hidden=!1,p.hidden=!1,u.setAttribute(`aria-modal`,`true`),ce(),a.dataset.state=`expanded`,B(null),typeof document<`u`&&(ne=document.body.style.overflow,document.body.style.overflow=`hidden`),z(),e&&t.onExpanded?.()},Te=()=>{o.hidden=!0,u.hidden=!1,p.hidden=!1,u.setAttribute(`aria-modal`,`false`),a.dataset.state=`docked`,B(null),typeof document<`u`&&(document.body.style.overflow=ne),_e(!0),z(),y?.setWidgetChrome(`docked`)},Ee=e=>{e.on(`started`,()=>{x||(T=!0,a.dataset.live=`true`,B(null),t.onStarted?.(),$(a.dataset.state)&&ve())})},K=()=>{L(),u.hidden=!0,p.hidden=!0,ce(),a.dataset.state=`collapsed`,a.classList.remove(`liforma-ew--session-revealed`),a.classList.remove(`liforma-ew--session-concealing`),g.setAttribute(`aria-pressed`,`false`),o.hidden=!1,o.tabIndex=0,o.removeAttribute(`aria-hidden`),te&&(o.disabled=!1),B(null),typeof document<`u`&&(document.body.style.overflow=ne),z()},De=()=>{I(),L(),E+=1,b=!1,S=!1,C=!1,w=!1,T=!1;let e=y;y=null,e?.destroy(),ee.replaceChildren(),l.replaceChildren(),l.hidden=!0,delete a.dataset.warm,delete a.dataset.live,a.classList.remove(`liforma-ew--session-revealed`)},q=()=>{if(!x&&$(a.dataset.state)){if(R(),b=!1,y&&w){let e=y;(async()=>{T&&(await be(),x||y!==e)||(S&&e.setWidgetChrome(`collapsed`),K(),T?(a.dataset.live=`true`,o.tabIndex=0,o.removeAttribute(`aria-hidden`),o.disabled=!1):S&&Se(),t.onCollapsed?.(),t.onClose?.())})();return}De(),K(),t.onCollapsed?.(),t.onClose?.()}},Oe=()=>{x||Q()&&F()===`expanded`&&ye(()=>{Te()})},J=()=>{x||F()===`docked`&&(R(),ye(()=>{ce(),G(!1),y?.setWidgetChrome(`expanded`)}))},ke=()=>{!y||!T||(I(),a.classList.remove(`liforma-ew--session-revealed`),G(),y.setWidgetChrome(`expanded`),b=!1,ve())},Ae=()=>{!y||!w||T||(I(),a.classList.remove(`liforma-ew--session-revealed`),G(),b=!1,S||y.setWidgetChrome(`expanded`))},je=e=>{x||e!==E&&!T||(I(),a.classList.remove(`liforma-ew--session-revealed`),G(),b=!1,T&&ve())},Me=()=>{if(x||C||S||y||$(a.dataset.state))return;C=!0;let e=E;l.hidden=!1,(async()=>{try{let t=await qe.startSession(we());if(x||e!==E){t.destroy();return}y=t,Ee(t);let n=await t.attach({container:l,...W(),onWidgetReady:()=>{x||e!==E||(C=!1,w=!0,$(a.dataset.state)?t.setWidgetChrome(`expanded`):Se())},onWidgetExpand:()=>{je(e)},onWidgetAudioSettings:e=>{x||Ie(e)},onWidgetDragStart:e=>{x||me(e)},onWidgetDragMove:e=>{x||he(e)},onWidgetDragEnd:e=>{x||ge(e)},onPlayerStatusChange:e=>{x||e===`error`&&$(a.dataset.state)&&B(`Could not load the experience.`)}});if(x||e!==E){t.destroy(),y===t&&(y=null);return}n.on(`close`,()=>{x||q()})}catch(n){if(x||e!==E)return;C=!1,l.hidden=!0,l.replaceChildren(),y=null;let r=n instanceof Error?n:Error(String(n));t.onError?.(r),console.error(`[ExperienceWidget] warm prefetch failed`,r)}})()},Ne=()=>{if(x||b||!te||$(a.dataset.state))return;if(y&&T){ke();return}if(y&&w){Ae();return}let e=++E;b=!0,S=!1,C=!1,w=!1,T=!1,delete a.dataset.warm,delete a.dataset.live,l.hidden=!0,l.replaceChildren(),y&&=(y.destroy(),null),(async()=>{try{G();let t=await qe.startSession(we());if(x||e!==E){t.destroy();return}y=t,Ee(t);let n=await t.attach({container:ee,...W(),onWidgetAudioSettings:e=>{x||Ie(e)},onWidgetDragStart:e=>{x||me(e)},onWidgetDragMove:e=>{x||he(e)},onWidgetDragEnd:e=>{x||ge(e)},onPlayerStatusChange:e=>{x||(e===`error`?B(`Could not load the experience.`):$(a.dataset.state)&&B(null))}});if(x||e!==E){t.destroy(),y===t&&(y=null);return}w=!0,t.setWidgetChrome(`expanded`),n.on(`close`,()=>{x||q()})}catch(n){if(x||e!==E)return;let r=n instanceof Error?n:Error(String(n));B(r.message),t.onError?.(r),console.error(`[ExperienceWidget]`,r)}finally{e===E&&(b=!1)}})()},Pe=()=>{if(!(x||$(a.dataset.state))){if(y&&T){ke();return}if(y&&w){Ae();return}if(C||y){G();return}Ne()}},Fe=e=>{if(e.stopPropagation(),F()===`expanded`){Oe();return}F()===`docked`&&J()},Ie=e=>{g.setAttribute(`aria-pressed`,e?`true`:`false`)},Le=e=>{e.stopPropagation(),$(a.dataset.state)&&y?.toggleAudioSettings()},Re=e=>{F()===`docked`&&Q()&&(e.target?.closest(`button`)||(e.preventDefault(),pe(e.clientX,e.clientY,e.pointerId)))},ze=e=>{e.key===`Escape`&&$(a.dataset.state)&&(e.preventDefault(),q())},Be=()=>{if(!x){if(F()===`docked`){if(!Q()){J();return}T?ye(()=>{_e(!0)}):_e(!0);return}z()}},Ve=typeof window<`u`?window.matchMedia(en):null,He=()=>{if(!x){if(F()===`docked`&&!Q()){J();return}z()}};return o.addEventListener(`click`,Pe),d.addEventListener(`click`,q),_.addEventListener(`click`,e=>{e.stopPropagation(),q()}),h.addEventListener(`click`,Fe),g.addEventListener(`click`,Le),p.addEventListener(`pointerdown`,Re),window.addEventListener(`keydown`,ze),window.addEventListener(`resize`,Be),Ve?.addEventListener(`change`,He),U(),z(),r===`eager`?queueMicrotask(()=>{x||Me()}):r===`idle`&&(re=Sn(()=>{x||Me()})),{root:a,expand:Pe,collapse:q,dock:Oe,maximize:J,prefetch(){if(r===`onExpand`){Me();return}Me()},destroy(){x||(x=!0,R(),re?.(),re=null,oe.abort(),D?.(),D=null,window.removeEventListener(`keydown`,ze),window.removeEventListener(`resize`,Be),Ve?.removeEventListener(`change`,He),De(),K(),e.replaceChildren())}}}var wn=`liforma-experience-widget`;function Tn(e){if(e?.trim())try{let t=JSON.parse(e);if(t&&typeof t==`object`&&typeof t.avatarImage==`string`)return t}catch{}}function En(e){let t=e?.trim();return t===`conversation`||t===`presenter`?t:void 0}function Dn(e){let t=e?.trim();return t===`auto`||t===`manual`||t===`off`?t:void 0}function On(e){let t=e?.trim();return t===`full`||t===`face`?t:void 0}function kn(e){let t=e?.trim();return t===`en`||t===`es`?t:void 0}function An(e){let t=e?.trim();return t===`bottom-right`||t===`bottom-left`?t:`static`}var jn=class extends HTMLElement{static get observedAttributes(){return[`experience-id`,`alt`,`gallery-thumb`,`avatar-image`,`background-image`,`foreground-image`,`fallback-image`,`prefetch`,`parallax`,`position`,`offset`,`session-endpoint`,`locale`,`secondary-locale`,`learning-locale`,`language`,`mode`,`speech-input-mode`,`speech-only`,`fit`,`expanded-max-width`,`expanded-max-height`,`start-button-label`]}#e=null;#t=null;connectedCallback(){this.#n(),this.#r()}disconnectedCallback(){this.#e?.destroy(),this.#e=null}attributeChangedCallback(){this.isConnected&&(this.#n(),this.#r())}#n(){if(An(this.getAttribute(`position`))!==`static`){this.style.display=`contents`,this.style.removeProperty(`width`),this.style.removeProperty(`height`),this.style.removeProperty(`min-height`);return}if(this.style.display=`block`,this.style.width||=`100%`,this.style.height||=`100%`,!this.style.minHeight){let e=getComputedStyle(this).minHeight;(e===`0px`||e===`auto`)&&(this.style.minHeight=`224px`)}}#r(){this.#e?.destroy(),this.#e=null;let e=this.getAttribute(`experience-id`)?.trim(),t=this.getAttribute(`alt`)?.trim()||`Open experience`;if(!e)return;let n=An(this.getAttribute(`position`));this.#t||(this.#t=document.createElement(`div`),this.replaceChildren(this.#t)),this.#t.style.cssText=n===`static`?`width:100%;height:100%;min-height:inherit;`:`display:contents;`;let r=this.getAttribute(`prefetch`)?.trim(),i=r===`idle`||r===`eager`||r===`onExpand`?r:`onExpand`,a=this.getAttribute(`speech-only`),o=this.getAttribute(`offset`);try{this.#e=Cn(this.#t,{experienceId:e,alt:t,galleryThumb:Tn(this.getAttribute(`gallery-thumb`)),avatarImage:this.getAttribute(`avatar-image`)??void 0,backgroundImage:this.getAttribute(`background-image`)??void 0,foregroundImage:this.getAttribute(`foreground-image`)??void 0,fallbackImage:this.getAttribute(`fallback-image`)??void 0,prefetch:i,parallax:this.getAttribute(`parallax`)!==`false`,position:n,offset:o===null?void 0:o,sessionEndpoint:this.getAttribute(`session-endpoint`)??void 0,locale:this.getAttribute(`locale`)?.trim()||void 0,secondaryLocale:this.getAttribute(`secondary-locale`)?.trim()||void 0,learningLocale:this.getAttribute(`learning-locale`)?.trim()||void 0,language:kn(this.getAttribute(`language`)),mode:En(this.getAttribute(`mode`)),speechInputMode:Dn(this.getAttribute(`speech-input-mode`)),speechOnly:a===null?void 0:a===``||a===`true`,fit:On(this.getAttribute(`fit`)),expandedMaxWidth:this.getAttribute(`expanded-max-width`)??void 0,expandedMaxHeight:this.getAttribute(`expanded-max-height`)??void 0,startButtonLabel:this.getAttribute(`start-button-label`)??void 0,onExpanded:()=>{this.dispatchEvent(new CustomEvent(`expanded`,{bubbles:!0}))},onCollapsed:()=>{this.dispatchEvent(new CustomEvent(`collapsed`,{bubbles:!0}))},onStarted:()=>{this.dispatchEvent(new CustomEvent(`started`,{bubbles:!0}))},onClose:()=>{this.dispatchEvent(new CustomEvent(`close`,{bubbles:!0}))},onError:e=>{this.dispatchEvent(new CustomEvent(`error`,{detail:e,bubbles:!0}))}})}catch(e){console.error(`[liforma-experience-widget]`,e)}}};return typeof customElements<`u`&&!customElements.get(wn)&&customElements.define(wn,jn),window.Liforma={Experience:qe,sdkVersion:`v2`,features:{speakApi:!0,speechAudioApi:!0}},e.Experience=qe,e.LiformaError=o,e.SPEECH_LIMITS=U,e.SpeechBufferTimeoutError=Te,e.SpeechRuntimeError=G,e.SpeechUtteranceClosedError=W,e.UnsupportedSpeechOperationError=we,e.liformaErrorFromResponse=c,e.warnLocaleVoiceFallbacks=v,e})({});
837
797
  //# sourceMappingURL=client.js.map