@apollosproject/web-embeds 0.1.167 → 0.1.168

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 (2) hide show
  1. package/package.json +2 -2
  2. package/widget/embed.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apollosproject/web-embeds",
3
- "version": "0.1.167",
3
+ "version": "0.1.168",
4
4
  "description": "Next-generation embeddable widget system for Apollos",
5
5
  "type": "module",
6
6
  "main": "./widget/embed.js",
@@ -17,7 +17,7 @@
17
17
  "build": "tsc && vite build && node scripts/build.cjs",
18
18
  "preview": "vite preview",
19
19
  "type-check": "tsc --noEmit",
20
- "lint": "eslint src --ext .ts,.tsx",
20
+ "lint": "yarn --cwd ../.. eslint apps/web-embeds-v2/src --ext .ts,.tsx",
21
21
  "bump": "sh scripts/bump.sh",
22
22
  "bump:prerelease": "sh scripts/bump.sh prerelease",
23
23
  "flush": "sh scripts/flush-cdn-cache.sh",
package/widget/embed.js CHANGED
@@ -38,7 +38,7 @@ Error generating stack: `+i.message+`
38
38
  *
39
39
  * This source code is licensed under the MIT license found in the
40
40
  * LICENSE file in the root directory of this source tree.
41
- */var Md=ce,Fd=Symbol.for("react.element"),Dd=Symbol.for("react.fragment"),Ad=Object.prototype.hasOwnProperty,Ud=Md.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,jd={key:!0,ref:!0,__self:!0,__source:!0};function cc(e,t,n){var r,l={},i=null,o=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(o=t.ref);for(r in t)Ad.call(t,r)&&!jd.hasOwnProperty(r)&&(l[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)l[r]===void 0&&(l[r]=t[r]);return{$$typeof:Fd,type:e,key:i,ref:o,props:l,_owner:Ud.current}}Cl.Fragment=Dd,Cl.jsx=cc,Cl.jsxs=cc,ac.exports=Cl;var mn=ac.exports;const ir={EMBED_INIT:"APOLLOS_EMBED_INIT",FULLSCREEN_CHANGED:"APOLLOS_FULLSCREEN_CHANGED",THEME_CHANGED:"APOLLOS_THEME_CHANGED"},Ft={EMBED_READY:"APOLLOS_EMBED_READY",EMBED_UPDATE:"APOLLOS_EMBED_UPDATE",NAVIGATION:"APOLLOS_NAVIGATION",REQUEST_CLOSE:"APOLLOS_REQUEST_CLOSE",REQUEST_FULLSCREEN:"APOLLOS_REQUEST_FULLSCREEN",OPEN_EXTERNAL:"APOLLOS_OPEN_EXTERNAL",REQUEST_NAVIGATION:"APOLLOS_REQUEST_NAVIGATION",HEIGHT_CHANGE:"APOLLOS_HEIGHT_CHANGE"};function or(e,t,n){e.contentWindow&&e.contentWindow.postMessage(t,n)}function Hd(e,t){if(e.origin!==t)return!1;const n=e.data;return!n||typeof n!="object"||typeof n.type!="string"?!1:Object.values(Ft).includes(n.type)}const fc=768,Bd=({config:e,state:t,onClose:n,onToggleFullscreen:r})=>{const[l,i]=zl.useState(!0),[o,u]=zl.useState(()=>typeof window<"u"&&window.innerWidth>=fc),s=ce.useRef(null),c=e.baseUrl||"https://apollos.com",h=t.currentPath==="/"?"":t.currentPath,m=new URL(`${c}/${e.slug}${h}`);m.searchParams.set("embedMode","modal");const p=m.toString(),g=new URL(c).origin,w=ce.useCallback(k=>{k.key==="Escape"&&t.isOpen&&n()},[t.isOpen,n]);ce.useEffect(()=>(document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)),[w]),ce.useEffect(()=>(t.isOpen?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[t.isOpen]),ce.useEffect(()=>{function k(){u(window.innerWidth>=fc)}return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const S=k=>{k.target===k.currentTarget&&n()},O=ce.useRef(!1);ce.useEffect(()=>{function k(L){Hd(L,g)&&(L.data.type===Ft.EMBED_READY&&(i(!1),s.current&&(or(s.current,{type:ir.EMBED_INIT,payload:{theme:t.resolvedTheme,showExpandButton:o,isFullscreen:t.isFullscreen,mode:"modal"}},g),O.current=!0)),L.data.type===Ft.REQUEST_CLOSE&&n(),L.data.type===Ft.REQUEST_FULLSCREEN&&r())}return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[g,t.resolvedTheme,t.isFullscreen,o,n,r]),ce.useEffect(()=>{O.current&&s.current&&or(s.current,{type:ir.THEME_CHANGED,payload:{theme:t.resolvedTheme}},g)},[t.resolvedTheme,g]),ce.useEffect(()=>{O.current&&s.current&&or(s.current,{type:ir.FULLSCREEN_CHANGED,payload:{isFullscreen:t.isFullscreen,showExpandButton:o}},g)},[t.isFullscreen,o,g]),ce.useEffect(()=>{i(!0),O.current=!1},[t.currentPath]),ce.useEffect(()=>{i(!0),t.isOpen||(O.current=!1)},[t.isOpen]);const f=["apls-fixed","apls-inset-0","apls-w-screen","apls-h-screen","apls-w-[100dvw]","apls-h-[100dvh]","apls-flex","apls-items-center","apls-justify-center","apls-bg-black/50",t.isOpen?"apls-opacity-100":"apls-opacity-0 apls-pointer-events-none","apls-transition-opacity","apls-duration-300","apls-ease-out"].join(" "),a=["apls-relative","apls-flex","apls-flex-col","apls-overflow-hidden","apls-shadow-2xl","apls-backdrop-blur-md","apls-bg-system-screen dark:apls-bg-system-screen-dark","apls-transition-all","apls-duration-300","apls-ease-out",t.isOpen?"apls-scale-100 apls-opacity-100":"apls-scale-95 apls-opacity-0","apls-w-screen","apls-h-screen","apls-max-h-screen","apls-w-[100dvw]","apls-h-[100dvh]","apls-max-h-[100dvh]","apls-rounded-none",...t.isFullscreen?["md:apls-w-screen","md:apls-h-screen","md:apls-max-h-screen","md:apls-w-[100dvw]","md:apls-h-[100dvh]","md:apls-max-h-[100dvh]"]:["md:apls-w-[600px]","md:apls-h-[900px]","md:apls-max-h-[95vh]","md:apls-rounded-3xl"]].join(" "),d=["apls-flex-1","apls-flex","apls-flex-col","apls-relative","apls-overflow-hidden"].join(" "),v=["apls-w-full","apls-h-full","apls-flex-grow","apls-border-none","apls-bg-transparent",...l?["apls-hidden"]:[]].join(" "),C=["apls-absolute","apls-inset-0","apls-flex","apls-items-center","apls-justify-center"].join(" "),x=["apls-w-8","apls-h-8","apls-border-[3px]","apls-border-solid","apls-border-system-regular dark:apls-border-system-regular-dark","apls-border-t-fg-tertiary dark:apls-border-t-fg-tertiary-dark","apls-rounded-full","apls-animate-spin"].join(" ");return mn.jsx("div",{className:f,onClick:S,style:{zIndex:e.zIndex},role:"dialog","aria-modal":"true","aria-label":"Apollos Embed",children:mn.jsx("div",{className:a,children:mn.jsxs("div",{className:d,children:[l?mn.jsx("div",{className:C,children:mn.jsx("div",{className:x})}):null,t.isOpen?mn.jsx("iframe",{ref:s,className:v,src:p,title:"Apollos",allow:"payment *",allowTransparency:!0}):null]})})})};function $d(e){return e.includes("ContentItem")?"/c":e==="Event"?"/e":e==="FeatureFeed"?"/f":e==="Livestream"?"/live":"/c"}function Vd(e){if(/^[A-Z]\w+-/.test(e)){const[n,...r]=e.split(/-(.*)/s);if(n&&r[0])return{type:n,randomId:r[0]}}else{const n=e.split("-").at(-1);if(!n)return null;try{const r=atob(n),[l,...i]=r.split(/-(.*)/s);if(l&&i[0])return{type:l,randomId:i[0]}}catch{return null}}return null}const Qd={showAskBar:!1,interceptLinks:!0,position:"bottom-center",offsetX:0,offsetY:48,autoOpen:!1,defaultPath:"/",baseUrl:"https://apollos.com",zIndex:999999,themeMode:"auto"},ve=class ve{constructor(t){q(this,"config");q(this,"state");q(this,"container",null);q(this,"root",null);q(this,"mediaQueryListener",null);q(this,"mediaQuery",null);q(this,"messageListener",null);q(this,"inlineIframes",new Map);q(this,"inlineSkeletons",new Map);q(this,"inlineSkeletonParentRestore",new Map);q(this,"inlineSkeletonFallbackTimeouts",new Map);q(this,"heightChangeTimeouts",new Map);if(this.config={...Qd,...t},this.state={isOpen:!1,isFullscreen:!1,currentPath:this.config.defaultPath||"/",canGoBack:!1,resolvedTheme:this.resolveTheme()},!this.config.slug)throw new Error("ApollosEmbed: slug is required in config");this.init()}resolveTheme(){const{themeMode:t}=this.config;return t==="light"?"light":t==="dark"||typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}setupThemeListener(){this.cleanupThemeListener(),!(this.config.themeMode!=="auto"||typeof window>"u"||!window.matchMedia)&&(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),this.mediaQueryListener=t=>{this.state.resolvedTheme=t.matches?"dark":"light",this.applyThemeClass(),this.render(),this.sendThemeToInlineIframes()},this.mediaQuery.addEventListener("change",this.mediaQueryListener))}cleanupThemeListener(){this.mediaQuery&&this.mediaQueryListener&&this.mediaQuery.removeEventListener("change",this.mediaQueryListener),this.mediaQuery=null,this.mediaQueryListener=null}applyThemeClass(){this.container&&(this.state.resolvedTheme==="dark"?this.container.classList.add("apls-dark"):this.container.classList.remove("apls-dark"))}init(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.setup()):this.setup()}setup(){this.config.interceptLinks&&this.setupLinkInterception(),this.setupThemeListener(),this.setupMessageListener(),this.initializeInlineIframes(),this.createContainer(),this.config.autoOpen&&this.open(),this.checkDeepLinkParams()}createContainer(){this.container=document.createElement("div"),this.container.id="apollos-embed-root",this.container.classList.add("apollos-embed"),document.body.appendChild(this.container),this.applyThemeClass(),this.root=uc(this.container),this.render()}render(){this.root&&this.root.render(zl.createElement(Bd,{config:this.config,state:{...this.state},onClose:()=>this.close(),onToggleFullscreen:()=>this.toggleFullscreen()}))}toggleFullscreen(){this.state.isFullscreen=!this.state.isFullscreen,this.render()}setupLinkInterception(){document.addEventListener("click",t=>{const r=t.target.closest("a");if(r&&this.shouldInterceptLink(r)){t.preventDefault();const i=new URL(r.href).pathname.replace(`/${this.config.slug}`,"")||"/",o=this.getLinkFullscreenOption(r);this.open(i,o!==void 0?{fullscreen:o}:void 0)}})}shouldInterceptLink(t){if(t.hasAttribute("data-apollos-external"))return!1;const n=t.href,r=this.config.baseUrl||"https://apollos.com";return new RegExp(`(apollos\\.com|${r.replace(/https?:\/\//,"")})/${this.config.slug}`).test(n)}getLinkFullscreenOption(t){if(!t.hasAttribute("data-apollos-fullscreen"))return;const n=t.getAttribute("data-apollos-fullscreen");return!(n==="false"||n==="0")}setupMessageListener(){const t=this.config.baseUrl||"https://apollos.com",n=new URL(t).origin;this.messageListener=r=>{if(r.origin!==n||!r.data||typeof r.data!="object")return;const{type:l,payload:i}=r.data;if(l===Ft.EMBED_READY){const o=r.source;this.inlineIframes.forEach((u,s)=>{s.contentWindow===o&&(this.sendInlineIframeInit(s),this.inlineIframes.set(s,!0),this.scheduleInlineSkeletonFallback(s,ve.INLINE_READY_FALLBACK_MS))})}if(l===Ft.REQUEST_NAVIGATION){const o=i;if(o!=null&&o.path){const u=this.config.navigationModalFullscreen===!0;this.open(o.path,{fullscreen:u})}}if(l===Ft.HEIGHT_CHANGE){const o=i;if(o&&typeof o.height=="number"&&o.height>0){const u=r.source;let s=null;if(this.inlineIframes.forEach((c,h)=>{h.contentWindow===u&&(s=h)}),!s){const c=document.querySelectorAll("iframe");for(const h of c)if(h.contentWindow===u){s=h;break}}s&&(this.scheduleHeightChange(s,o.height),this.inlineSkeletons.has(s)&&this.removeInlineSkeleton(s))}}},window.addEventListener("message",this.messageListener)}scheduleHeightChange(t,n){const r=this.heightChangeTimeouts.get(t);r&&clearTimeout(r.timeoutId);const l=setTimeout(()=>{this.heightChangeTimeouts.delete(t),this.applyHeightWithTransition(t,n)},ve.HEIGHT_DEBOUNCE_MS);this.heightChangeTimeouts.set(t,{timeoutId:l,height:n})}applyHeightWithTransition(t,n){(t.style.height?parseFloat(t.style.height):NaN)!==n&&(t.style.transition=`height ${ve.HEIGHT_TRANSITION_MS}ms ease-out`,t.style.height=`${n}px`)}scheduleInlineSkeletonFallback(t,n){if(!this.inlineSkeletons.has(t))return;const r=this.inlineSkeletonFallbackTimeouts.get(t);r&&clearTimeout(r);const l=setTimeout(()=>{this.inlineSkeletonFallbackTimeouts.delete(t),this.inlineSkeletons.has(t)&&this.removeInlineSkeleton(t)},n);this.inlineSkeletonFallbackTimeouts.set(t,l)}cleanupMessageListener(){this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null)}initializeInlineIframes(){const t=this.config.baseUrl||"https://apollos.com",n=new URL(t).origin;document.querySelectorAll("iframe").forEach(l=>{if(this.isInlineEmbed(l,n)){const i=this.applyInlineIframeUrlParams(l);this.inlineIframes.set(l,!1),this.createInlineSkeleton(l),i||this.sendInlineIframeInit(l)}})}isInlineEmbed(t,n){const r=t.src;if(!r)return!1;try{const l=new URL(r);return!(l.origin!==n||!l.pathname.startsWith(`/${this.config.slug}`))}catch{return!1}}applyInlineIframeUrlParams(t){const n=t.src;if(!n)return!1;try{const r=new URL(n);let l=!1;r.searchParams.get("embedMode")!=="inline"&&(r.searchParams.set("embedMode","inline"),l=!0);const i=this.state.resolvedTheme;return r.searchParams.get("theme")!==i&&(r.searchParams.set("theme",i),l=!0),l&&(t.src=r.toString()),l}catch{return!1}}sendInlineIframeInit(t){const n=this.config.baseUrl||"https://apollos.com",r=new URL(n).origin;or(t,{type:ir.EMBED_INIT,payload:{theme:this.state.resolvedTheme,showExpandButton:!1,isFullscreen:!1,mode:"inline"}},r)}sendThemeToInlineIframes(){const t=this.config.baseUrl||"https://apollos.com",n=new URL(t).origin;this.inlineIframes.forEach((r,l)=>{r&&or(l,{type:ir.THEME_CHANGED,payload:{theme:this.state.resolvedTheme}},n)})}checkDeepLinkParams(){const t=new URLSearchParams(window.location.search),n=t.get("a");if(n){this.open(n,{fullscreen:!0});return}const r=t.get("apollosId")||t.get("id");if(r){const l=Vd(r);if(l){const i=$d(l.type);this.open(`${i}/${r}`,{fullscreen:!0})}else this.open(`/c/${r}`,{fullscreen:!0});return}}open(t,n){var r,l;t&&(this.state.currentPath=t),this.state.isOpen=!0,(n==null?void 0:n.fullscreen)===!0?this.state.isFullscreen=!0:(n==null?void 0:n.fullscreen)===!1?this.state.isFullscreen=!1:this.config.defaultFullscreen===!0&&(this.state.isFullscreen=!0),this.render(),(l=(r=this.config).onOpen)==null||l.call(r)}close(){var t,n;this.state.isOpen=!1,this.state.isFullscreen=!1,this.render(),(n=(t=this.config).onClose)==null||n.call(t)}toggle(){this.state.isOpen?this.close():this.open()}navigate(t){var n,r;this.state.currentPath=t,this.render(),(r=(n=this.config).onNavigate)==null||r.call(n,t)}isOpen(){return this.state.isOpen}destroy(){this.cleanupThemeListener(),this.cleanupMessageListener(),this.heightChangeTimeouts.forEach(({timeoutId:t})=>clearTimeout(t)),this.heightChangeTimeouts.clear(),this.inlineSkeletonFallbackTimeouts.forEach(t=>clearTimeout(t)),this.inlineSkeletonFallbackTimeouts.clear(),this.inlineIframes.clear(),Array.from(this.inlineSkeletons.keys()).forEach(t=>{this.removeInlineSkeleton(t)}),this.root&&(this.root.unmount(),this.root=null),this.container&&(this.container.remove(),this.container=null)}getState(){return{...this.state}}getConfig(){return{...this.config}}createInlineSkeleton(t){if(this.inlineSkeletons.has(t))return;ve.ensureSkeletonStyles();const n=document.createElement("div");n.setAttribute("aria-busy","true"),n.style.position="absolute",n.style.inset="0",n.style.display="flex",n.style.alignItems="stretch",n.style.justifyContent="flex-start",n.style.pointerEvents="none";const r=document.createElement("div");r.style.borderRadius="12px",r.style.padding="74px 24px 20px 24px",r.style.boxShadow="0 10px 40px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.12)",r.style.minHeight="360px",r.style.display="flex",r.style.flexDirection="column",r.style.justifyContent="flex-start",r.style.gap="0",r.style.width="100%",r.style.maxWidth="100%";const l=this.state.resolvedTheme==="dark";r.style.backgroundColor=l?"#111827":"#f3f4f6";const i=(h,m,p)=>{const g=document.createElement("div");return g.style.height=`${h}px`,g.style.borderRadius=`${m}px`,g.style.backgroundColor=l?"#374151":"#ffffff",g.style.width="100%",g.style.marginBottom=`${p}px`,g.style.animation="apls-inline-skeleton-pulse 1.4s ease-in-out infinite",g},o=i(68,8,12),u=i(56,8,24),s=document.createElement("div");s.style.height="50px",s.style.width="100%",s.style.borderRadius="12px",s.style.backgroundColor=l?"#374151":"#ffffff",s.style.animation="apls-inline-skeleton-pulse 1.4s ease-in-out infinite",r.appendChild(o),r.appendChild(u),r.appendChild(s),n.appendChild(r);const c=t.parentElement;if(c){const h=window.getComputedStyle(c);h.position==="static"&&(this.inlineSkeletonParentRestore.set(t,{parent:c,originalPosition:h.position}),c.style.position="relative"),c.appendChild(n),this.inlineSkeletons.set(t,n),t.style.visibility="hidden",this.scheduleInlineSkeletonFallback(t,ve.INLINE_SKELETON_FALLBACK_MS)}}removeInlineSkeleton(t){const n=this.inlineSkeletons.get(t);n&&n.parentElement&&n.parentElement.removeChild(n),this.inlineSkeletons.delete(t);const r=this.inlineSkeletonFallbackTimeouts.get(t);r&&(clearTimeout(r),this.inlineSkeletonFallbackTimeouts.delete(t)),t.style.visibility="";const l=this.inlineSkeletonParentRestore.get(t);l&&(l.parent.style.position=l.originalPosition,this.inlineSkeletonParentRestore.delete(t))}static ensureSkeletonStyles(){if(ve.hasInjectedSkeletonStyles||typeof document>"u")return;const t=document.createElement("style");t.textContent=`
41
+ */var Md=ce,Fd=Symbol.for("react.element"),Dd=Symbol.for("react.fragment"),Ad=Object.prototype.hasOwnProperty,Ud=Md.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,jd={key:!0,ref:!0,__self:!0,__source:!0};function cc(e,t,n){var r,l={},i=null,o=null;n!==void 0&&(i=""+n),t.key!==void 0&&(i=""+t.key),t.ref!==void 0&&(o=t.ref);for(r in t)Ad.call(t,r)&&!jd.hasOwnProperty(r)&&(l[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)l[r]===void 0&&(l[r]=t[r]);return{$$typeof:Fd,type:e,key:i,ref:o,props:l,_owner:Ud.current}}Cl.Fragment=Dd,Cl.jsx=cc,Cl.jsxs=cc,ac.exports=Cl;var mn=ac.exports;const ir={EMBED_INIT:"APOLLOS_EMBED_INIT",FULLSCREEN_CHANGED:"APOLLOS_FULLSCREEN_CHANGED",THEME_CHANGED:"APOLLOS_THEME_CHANGED"},Ft={EMBED_READY:"APOLLOS_EMBED_READY",EMBED_UPDATE:"APOLLOS_EMBED_UPDATE",NAVIGATION:"APOLLOS_NAVIGATION",REQUEST_CLOSE:"APOLLOS_REQUEST_CLOSE",REQUEST_FULLSCREEN:"APOLLOS_REQUEST_FULLSCREEN",OPEN_EXTERNAL:"APOLLOS_OPEN_EXTERNAL",REQUEST_NAVIGATION:"APOLLOS_REQUEST_NAVIGATION",HEIGHT_CHANGE:"APOLLOS_HEIGHT_CHANGE"};function or(e,t,n){e.contentWindow&&e.contentWindow.postMessage(t,n)}function Hd(e,t){if(e.origin!==t)return!1;const n=e.data;return!n||typeof n!="object"||typeof n.type!="string"?!1:Object.values(Ft).includes(n.type)}const fc=768,Bd=({config:e,state:t,onClose:n,onToggleFullscreen:r})=>{const[l,i]=zl.useState(!0),[o,u]=zl.useState(()=>typeof window<"u"&&window.innerWidth>=fc),s=ce.useRef(null),c=e.baseUrl||"https://apollos.com",h=t.currentPath==="/"?"":t.currentPath,m=new URL(`${c}/${e.slug}${h}`);m.searchParams.set("embedMode","modal");const p=m.toString(),g=new URL(c).origin,w=ce.useCallback(k=>{k.key==="Escape"&&t.isOpen&&n()},[t.isOpen,n]);ce.useEffect(()=>(document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)),[w]),ce.useEffect(()=>(t.isOpen?document.body.style.overflow="hidden":document.body.style.overflow="",()=>{document.body.style.overflow=""}),[t.isOpen]),ce.useEffect(()=>{function k(){u(window.innerWidth>=fc)}return window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const S=k=>{k.target===k.currentTarget&&n()},O=ce.useRef(!1);ce.useEffect(()=>{function k(L){Hd(L,g)&&(L.data.type===Ft.EMBED_READY&&(i(!1),s.current&&(or(s.current,{type:ir.EMBED_INIT,payload:{theme:t.resolvedTheme,showExpandButton:o,isFullscreen:t.isFullscreen,mode:"modal"}},g),O.current=!0)),L.data.type===Ft.REQUEST_CLOSE&&n(),L.data.type===Ft.REQUEST_FULLSCREEN&&r())}return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[g,t.resolvedTheme,t.isFullscreen,o,n,r]),ce.useEffect(()=>{O.current&&s.current&&or(s.current,{type:ir.THEME_CHANGED,payload:{theme:t.resolvedTheme}},g)},[t.resolvedTheme,g]),ce.useEffect(()=>{O.current&&s.current&&or(s.current,{type:ir.FULLSCREEN_CHANGED,payload:{isFullscreen:t.isFullscreen,showExpandButton:o}},g)},[t.isFullscreen,o,g]),ce.useEffect(()=>{i(!0),O.current=!1},[t.currentPath]),ce.useEffect(()=>{i(!0),t.isOpen||(O.current=!1)},[t.isOpen]);const f=["apls-fixed","apls-inset-0","apls-w-screen","apls-h-screen","apls-w-[100dvw]","apls-h-[100dvh]","apls-flex","apls-items-center","apls-justify-center","apls-bg-black/50",t.isOpen?"apls-opacity-100":"apls-opacity-0 apls-pointer-events-none","apls-transition-opacity","apls-duration-300","apls-ease-out"].join(" "),a=["apls-relative","apls-flex","apls-flex-col","apls-overflow-hidden","apls-shadow-2xl","apls-backdrop-blur-md","apls-bg-system-screen dark:apls-bg-system-screen-dark","apls-transition-all","apls-duration-300","apls-ease-out",t.isOpen?"apls-scale-100 apls-opacity-100":"apls-scale-95 apls-opacity-0","apls-w-screen","apls-h-screen","apls-max-h-screen","apls-w-[100dvw]","apls-h-[100dvh]","apls-max-h-[100dvh]","apls-rounded-none",...t.isFullscreen?["md:apls-w-screen","md:apls-h-screen","md:apls-max-h-screen","md:apls-w-[100dvw]","md:apls-h-[100dvh]","md:apls-max-h-[100dvh]"]:["md:apls-w-[600px]","md:apls-h-[900px]","md:apls-max-h-[95vh]","md:apls-rounded-3xl"]].join(" "),d=["apls-flex-1","apls-flex","apls-flex-col","apls-relative","apls-overflow-hidden"].join(" "),v=["apls-w-full","apls-h-full","apls-flex-grow","apls-border-none","apls-bg-transparent",...l?["apls-hidden"]:[]].join(" "),C=["apls-absolute","apls-inset-0","apls-flex","apls-items-center","apls-justify-center"].join(" "),x=["apls-w-8","apls-h-8","apls-border-[3px]","apls-border-solid","apls-border-system-regular dark:apls-border-system-regular-dark","apls-border-t-fg-tertiary dark:apls-border-t-fg-tertiary-dark","apls-rounded-full","apls-animate-spin"].join(" ");return mn.jsx("div",{className:f,onClick:S,style:{zIndex:e.zIndex},role:"dialog","aria-modal":"true","aria-label":"Apollos Embed",children:mn.jsx("div",{className:a,children:mn.jsxs("div",{className:d,children:[l?mn.jsx("div",{className:C,children:mn.jsx("div",{className:x})}):null,t.isOpen?mn.jsx("iframe",{ref:s,className:v,src:p,title:"Apollos",allow:"payment *",allowTransparency:!0}):null]})})})};function $d(e){return e.includes("ContentItem")?"/c":e==="Event"?"/e":e==="FeatureFeed"?"/f":e==="Livestream"?"/live":"/c"}function Vd(e){if(/^[A-Z]\w+-/.test(e)){const[n,...r]=e.split(/-(.*)/s);if(n&&r[0])return{type:n,randomId:r[0]}}else{const n=e.split("-").at(-1);if(!n)return null;try{const r=atob(n),[l,...i]=r.split(/-(.*)/s);if(l&&i[0])return{type:l,randomId:i[0]}}catch{return null}}return null}const Qd={showAskBar:!1,interceptLinks:!0,position:"bottom-center",offsetX:0,offsetY:48,autoOpen:!1,defaultPath:"/",baseUrl:"https://apollos.com",zIndex:999999,themeMode:"auto"},ve=class ve{constructor(t){q(this,"config");q(this,"state");q(this,"container",null);q(this,"root",null);q(this,"mediaQueryListener",null);q(this,"mediaQuery",null);q(this,"messageListener",null);q(this,"inlineIframes",new Map);q(this,"inlineSkeletons",new Map);q(this,"inlineSkeletonParentRestore",new Map);q(this,"inlineSkeletonFallbackTimeouts",new Map);q(this,"heightChangeTimeouts",new Map);if(this.config={...Qd,...t},this.state={isOpen:!1,isFullscreen:!1,currentPath:this.config.defaultPath||"/",canGoBack:!1,resolvedTheme:this.resolveTheme()},!this.config.slug)throw new Error("ApollosEmbed: slug is required in config");this.init()}resolveTheme(){const{themeMode:t}=this.config;return t==="light"?"light":t==="dark"||typeof window<"u"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}setupThemeListener(){this.cleanupThemeListener(),!(this.config.themeMode!=="auto"||typeof window>"u"||!window.matchMedia)&&(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)"),this.mediaQueryListener=t=>{this.state.resolvedTheme=t.matches?"dark":"light",this.applyThemeClass(),this.render(),this.sendThemeToInlineIframes()},this.mediaQuery.addEventListener("change",this.mediaQueryListener))}cleanupThemeListener(){this.mediaQuery&&this.mediaQueryListener&&this.mediaQuery.removeEventListener("change",this.mediaQueryListener),this.mediaQuery=null,this.mediaQueryListener=null}applyThemeClass(){this.container&&(this.state.resolvedTheme==="dark"?this.container.classList.add("apls-dark"):this.container.classList.remove("apls-dark"))}init(){document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>this.setup()):this.setup()}setup(){this.config.interceptLinks&&this.setupLinkInterception(),this.setupThemeListener(),this.setupMessageListener(),this.initializeInlineIframes(),this.createContainer(),this.config.autoOpen&&this.open(),this.checkDeepLinkParams()}createContainer(){this.container=document.createElement("div"),this.container.id="apollos-embed-root",this.container.classList.add("apollos-embed"),document.body.appendChild(this.container),this.applyThemeClass(),this.root=uc(this.container),this.render()}render(){this.root&&this.root.render(zl.createElement(Bd,{config:this.config,state:{...this.state},onClose:()=>this.close(),onToggleFullscreen:()=>this.toggleFullscreen()}))}toggleFullscreen(){this.state.isFullscreen=!this.state.isFullscreen,this.render()}setupLinkInterception(){document.addEventListener("click",t=>{const r=t.target.closest("a");if(r&&this.shouldInterceptLink(r)){t.preventDefault();const i=new URL(r.href).pathname.replace(`/${this.config.slug}`,"")||"/",o=this.getLinkFullscreenOption(r);this.open(i,o!==void 0?{fullscreen:o}:void 0)}})}shouldInterceptLink(t){if(t.hasAttribute("data-apollos-external"))return!1;const n=t.href,r=this.config.baseUrl||"https://apollos.com";return new RegExp(`(apollos\\.com|${r.replace(/https?:\/\//,"")})/${this.config.slug}`).test(n)}getLinkFullscreenOption(t){if(!t.hasAttribute("data-apollos-fullscreen"))return;const n=t.getAttribute("data-apollos-fullscreen");return!(n==="false"||n==="0")}setupMessageListener(){const t=this.config.baseUrl||"https://apollos.com",n=new URL(t).origin;this.messageListener=r=>{if(r.origin!==n||!r.data||typeof r.data!="object")return;const{type:l,payload:i}=r.data;if(l===Ft.EMBED_READY){const o=r.source;this.inlineIframes.forEach((u,s)=>{s.contentWindow===o&&(this.sendInlineIframeInit(s),this.inlineIframes.set(s,!0),this.scheduleInlineSkeletonFallback(s,ve.INLINE_READY_FALLBACK_MS))})}if(l===Ft.REQUEST_NAVIGATION){const o=i;if(o!=null&&o.path){if(/^https?:\/\//i.test(o.path)){window.location.assign(o.path);return}const u=this.config.navigationModalFullscreen===!0;this.open(o.path,{fullscreen:u})}}if(l===Ft.HEIGHT_CHANGE){const o=i;if(o&&typeof o.height=="number"&&o.height>0){const u=r.source;let s=null;if(this.inlineIframes.forEach((c,h)=>{h.contentWindow===u&&(s=h)}),!s){const c=document.querySelectorAll("iframe");for(const h of c)if(h.contentWindow===u){s=h;break}}s&&(this.scheduleHeightChange(s,o.height),this.inlineSkeletons.has(s)&&this.removeInlineSkeleton(s))}}},window.addEventListener("message",this.messageListener)}scheduleHeightChange(t,n){const r=this.heightChangeTimeouts.get(t);r&&clearTimeout(r.timeoutId);const l=setTimeout(()=>{this.heightChangeTimeouts.delete(t),this.applyHeightWithTransition(t,n)},ve.HEIGHT_DEBOUNCE_MS);this.heightChangeTimeouts.set(t,{timeoutId:l,height:n})}applyHeightWithTransition(t,n){(t.style.height?parseFloat(t.style.height):NaN)!==n&&(t.style.transition=`height ${ve.HEIGHT_TRANSITION_MS}ms ease-out`,t.style.height=`${n}px`)}scheduleInlineSkeletonFallback(t,n){if(!this.inlineSkeletons.has(t))return;const r=this.inlineSkeletonFallbackTimeouts.get(t);r&&clearTimeout(r);const l=setTimeout(()=>{this.inlineSkeletonFallbackTimeouts.delete(t),this.inlineSkeletons.has(t)&&this.removeInlineSkeleton(t)},n);this.inlineSkeletonFallbackTimeouts.set(t,l)}cleanupMessageListener(){this.messageListener&&(window.removeEventListener("message",this.messageListener),this.messageListener=null)}initializeInlineIframes(){const t=this.config.baseUrl||"https://apollos.com",n=new URL(t).origin;document.querySelectorAll("iframe").forEach(l=>{if(this.isInlineEmbed(l,n)){const i=this.applyInlineIframeUrlParams(l);this.inlineIframes.set(l,!1),this.createInlineSkeleton(l),i||this.sendInlineIframeInit(l)}})}isInlineEmbed(t,n){const r=t.src;if(!r)return!1;try{const l=new URL(r);return!(l.origin!==n||!l.pathname.startsWith(`/${this.config.slug}`))}catch{return!1}}applyInlineIframeUrlParams(t){const n=t.src;if(!n)return!1;try{const r=new URL(n);let l=!1;r.searchParams.get("embedMode")!=="inline"&&(r.searchParams.set("embedMode","inline"),l=!0);const i=this.state.resolvedTheme;return r.searchParams.get("theme")!==i&&(r.searchParams.set("theme",i),l=!0),l&&(t.src=r.toString()),l}catch{return!1}}sendInlineIframeInit(t){const n=this.config.baseUrl||"https://apollos.com",r=new URL(n).origin;or(t,{type:ir.EMBED_INIT,payload:{theme:this.state.resolvedTheme,showExpandButton:!1,isFullscreen:!1,mode:"inline"}},r)}sendThemeToInlineIframes(){const t=this.config.baseUrl||"https://apollos.com",n=new URL(t).origin;this.inlineIframes.forEach((r,l)=>{r&&or(l,{type:ir.THEME_CHANGED,payload:{theme:this.state.resolvedTheme}},n)})}checkDeepLinkParams(){const t=new URLSearchParams(window.location.search),n=t.get("a");if(n){this.open(n,{fullscreen:!0});return}const r=t.get("apollosId")||t.get("id");if(r){const l=Vd(r);if(l){const i=$d(l.type);this.open(`${i}/${r}`,{fullscreen:!0})}else this.open(`/c/${r}`,{fullscreen:!0});return}}open(t,n){var r,l;t&&(this.state.currentPath=t),this.state.isOpen=!0,(n==null?void 0:n.fullscreen)===!0?this.state.isFullscreen=!0:(n==null?void 0:n.fullscreen)===!1?this.state.isFullscreen=!1:this.config.defaultFullscreen===!0&&(this.state.isFullscreen=!0),this.render(),(l=(r=this.config).onOpen)==null||l.call(r)}close(){var t,n;this.state.isOpen=!1,this.state.isFullscreen=!1,this.render(),(n=(t=this.config).onClose)==null||n.call(t)}toggle(){this.state.isOpen?this.close():this.open()}navigate(t){var n,r;this.state.currentPath=t,this.render(),(r=(n=this.config).onNavigate)==null||r.call(n,t)}isOpen(){return this.state.isOpen}destroy(){this.cleanupThemeListener(),this.cleanupMessageListener(),this.heightChangeTimeouts.forEach(({timeoutId:t})=>clearTimeout(t)),this.heightChangeTimeouts.clear(),this.inlineSkeletonFallbackTimeouts.forEach(t=>clearTimeout(t)),this.inlineSkeletonFallbackTimeouts.clear(),this.inlineIframes.clear(),Array.from(this.inlineSkeletons.keys()).forEach(t=>{this.removeInlineSkeleton(t)}),this.root&&(this.root.unmount(),this.root=null),this.container&&(this.container.remove(),this.container=null)}getState(){return{...this.state}}getConfig(){return{...this.config}}createInlineSkeleton(t){if(this.inlineSkeletons.has(t))return;ve.ensureSkeletonStyles();const n=document.createElement("div");n.setAttribute("aria-busy","true"),n.style.position="absolute",n.style.inset="0",n.style.display="flex",n.style.alignItems="stretch",n.style.justifyContent="flex-start",n.style.pointerEvents="none";const r=document.createElement("div");r.style.borderRadius="12px",r.style.padding="74px 24px 20px 24px",r.style.boxShadow="0 10px 40px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.12)",r.style.minHeight="360px",r.style.display="flex",r.style.flexDirection="column",r.style.justifyContent="flex-start",r.style.gap="0",r.style.width="100%",r.style.maxWidth="100%";const l=this.state.resolvedTheme==="dark";r.style.backgroundColor=l?"#111827":"#f3f4f6";const i=(h,m,p)=>{const g=document.createElement("div");return g.style.height=`${h}px`,g.style.borderRadius=`${m}px`,g.style.backgroundColor=l?"#374151":"#ffffff",g.style.width="100%",g.style.marginBottom=`${p}px`,g.style.animation="apls-inline-skeleton-pulse 1.4s ease-in-out infinite",g},o=i(68,8,12),u=i(56,8,24),s=document.createElement("div");s.style.height="50px",s.style.width="100%",s.style.borderRadius="12px",s.style.backgroundColor=l?"#374151":"#ffffff",s.style.animation="apls-inline-skeleton-pulse 1.4s ease-in-out infinite",r.appendChild(o),r.appendChild(u),r.appendChild(s),n.appendChild(r);const c=t.parentElement;if(c){const h=window.getComputedStyle(c);h.position==="static"&&(this.inlineSkeletonParentRestore.set(t,{parent:c,originalPosition:h.position}),c.style.position="relative"),c.appendChild(n),this.inlineSkeletons.set(t,n),t.style.visibility="hidden",this.scheduleInlineSkeletonFallback(t,ve.INLINE_SKELETON_FALLBACK_MS)}}removeInlineSkeleton(t){const n=this.inlineSkeletons.get(t);n&&n.parentElement&&n.parentElement.removeChild(n),this.inlineSkeletons.delete(t);const r=this.inlineSkeletonFallbackTimeouts.get(t);r&&(clearTimeout(r),this.inlineSkeletonFallbackTimeouts.delete(t)),t.style.visibility="";const l=this.inlineSkeletonParentRestore.get(t);l&&(l.parent.style.position=l.originalPosition,this.inlineSkeletonParentRestore.delete(t))}static ensureSkeletonStyles(){if(ve.hasInjectedSkeletonStyles||typeof document>"u")return;const t=document.createElement("style");t.textContent=`
42
42
  @keyframes apls-inline-skeleton-pulse {
43
43
  0%, 100% { opacity: 0.55; }
44
44
  50% { opacity: 1; }