@perspective-ai/sdk 1.6.1 → 1.6.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.
- package/dist/browser.cjs +1 -4
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +1 -4
- package/dist/browser.js.map +1 -1
- package/dist/cdn/perspective.global.js +4 -4
- package/dist/cdn/perspective.global.js.map +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/loading.test.ts +2 -2
- package/src/loading.ts +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Perspective=(()=>{var Ue=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames;var Ft=Object.prototype.hasOwnProperty;var Kt=(e,r)=>{for(var t in r)Ue(e,t,{get:r[t],enumerable:!0})},Vt=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Ut(r))!Ft.call(e,o)&&o!==t&&Ue(e,o,{get:()=>r[o],enumerable:!(n=$t(r,o))||n.enumerable});return e};var zt=e=>Vt(Ue({},"__esModule",{value:!0}),e);var Rr={};Kt(Rr,{autoInit:()=>Be,configure:()=>Ke,createChatBubble:()=>Ze,createFloatBubble:()=>xe,createFullpage:()=>Pe,createWidget:()=>Re,default:()=>Hr,destroy:()=>Pt,destroyAll:()=>Dt,getConfig:()=>Ve,init:()=>te,mount:()=>Je,openPopup:()=>Oe,openSlider:()=>_e});var mt="1.6.1",he={RESIZE:1,THEME_SYNC:2,ANON_ID:4,SCROLLBAR_STYLES:8,EMBED_AUTH:16},ut=he.RESIZE|he.THEME_SYNC|he.ANON_ID|he.SCROLLBAR_STYLES|he.EMBED_AUTH,Z={embed:"embed",embedType:"embed_type",theme:"theme"},D={primary:"brand.primary",secondary:"brand.secondary",bg:"brand.bg",text:"brand.text",darkPrimary:"brand.dark.primary",darkSecondary:"brand.dark.secondary",darkBg:"brand.dark.bg",darkText:"brand.dark.text"},Fe=new Set([...Object.values(Z),...Object.values(D)]),x={widget:"data-perspective-widget",popup:"data-perspective-popup",slider:"data-perspective-slider",float:"data-perspective-float",chat:"data-perspective-chat",fullpage:"data-perspective-fullpage",params:"data-perspective-params",brand:"data-perspective-brand",brandDark:"data-perspective-brand-dark",theme:"data-perspective-theme",noStyle:"data-perspective-no-style",autoOpen:"data-perspective-auto-open",showOnce:"data-perspective-show-once",disableClose:"data-perspective-disable-close",launcherIcon:"data-perspective-launcher-icon",launcherStyle:"data-perspective-launcher-style",launcherClass:"data-perspective-launcher-class"},k={init:"perspective:init",ready:"perspective:ready",resize:"perspective:resize",submit:"perspective:submit",close:"perspective:close",error:"perspective:error",redirect:"perspective:redirect",anonId:"perspective:anon-id",injectStyles:"perspective:inject-styles",themeChange:"perspective:theme-change",authRequest:"perspective:auth-request",authSignout:"perspective:auth-signout",authComplete:"perspective:auth-complete",authCancelled:"perspective:auth-cancelled",popupAuthComplete:"perspective:popup-auth-complete",requestScrollbarStyles:"perspective:request-scrollbar-styles"},ft={SDK_OUTDATED:"SDK_OUTDATED",INVALID_RESEARCH:"INVALID_RESEARCH",UNKNOWN:"UNKNOWN"},ht={true:"true",false:"false"},L={dark:"dark",light:"light",system:"system"};var Y={anonId:"perspective-anon-id",triggerShown:"perspective-trigger-shown",embedAuthToken:"perspective-embed-auth-token",embedState:"perspective-embed-state"};var jt="https://getperspective.ai",be={};function Ke(e){be={...be,...e}}function Ve(){return{...be}}function g(){return typeof window<"u"&&typeof document<"u"}function gt(e){try{return new URL(e).origin}catch{return e}}function M(e){if(e)return gt(e);if(be.host)return gt(be.host);if(g()){let r=bt();if(r)return r}return jt}var ge=null;function bt(){if(ge!==null)return ge;if(!g())return null;let e=document.currentScript;if(e!=null&&e.src)try{return ge=new URL(e.src).origin,ge}catch{}return ge="",null}g()&&bt();var ne={primaryColor:"#7c3aed",textColor:"#ffffff",darkPrimaryColor:"#a78bfa",darkTextColor:"#ffffff"},Gt=3e3,ze=new Map,Ie=new Map;function Yt(e,r){return`${M(r)}::${e}`}async function vt(e,r){let t=Yt(e,r);if(ze.has(t))return ze.get(t);if(Ie.has(t))return Ie.get(t);let n=(async()=>{try{let o=M(r),i=new AbortController,s=setTimeout(()=>i.abort(),Gt),a=await fetch(`${o}/api/v1/embed/config/${e}`,{signal:i.signal});if(clearTimeout(s),!a.ok)return ne;let l=await a.json();return ze.set(t,l),l}catch{return ne}finally{Ie.delete(t)}})();return Ie.set(t,n),n}function yt(e){let r=e.trim();if(r.startsWith("timeout:")){let t=parseInt(r.slice(8),10);if(isNaN(t)||t<0)throw new Error(`Invalid timeout delay: "${e}"`);return{type:"timeout",delay:t}}if(r==="timeout")return{type:"timeout",delay:5e3};if(r==="exit-intent")return{type:"exit-intent"};throw new Error(`Unknown trigger type: "${e}". Expected "timeout:<ms>" or "exit-intent".`)}function je(e,r){if(e.type==="timeout"){let n=setTimeout(r,e.delay);return()=>clearTimeout(n)}if(e.type==="exit-intent"){let n=o=>{o.clientY<=0&&(r(),document.removeEventListener("mouseleave",n))};return document.addEventListener("mouseleave",n),()=>document.removeEventListener("mouseleave",n)}let t=e;throw new Error(`Unknown trigger type: ${t.type}`)}function Et(e){return`${Y.triggerShown}:${e}`}function wt(e){if(!e)return"session";let r=e.trim();return r==="visitor"?"visitor":r==="false"?!1:"session"}function Ge(e,r){if(r===!1)return!0;try{return(r==="visitor"?localStorage:sessionStorage).getItem(Et(e))===null}catch{return!0}}function Ye(e,r){if(r!==!1)try{(r==="visitor"?localStorage:sessionStorage).setItem(Et(e),"1")}catch{}}function O(...e){return e.map(r=>(r||"").split(" ")).flat().filter(Boolean).join(" ")}function _(e){return e&&e!==L.system?`perspective-${e}-theme`:void 0}function X(e){return e===L.dark?!0:e===L.light||!g()?!1:window.matchMedia("(prefers-color-scheme: dark)").matches}function xt(e){return X(e)?"dark":"light"}function Ct(e){let r=e.trim();if(!r)return;let t=r.startsWith("#")?r:`#${r}`;if(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(t))return t;let n=t.slice(1).replace(/[^0-9a-fA-F]/g,"");if(n.length>=6)return`#${n.slice(0,6)}`;if(n.length>=3)return`#${n.slice(0,3)}`}function Wt(e){if(!e||typeof e!="string")return!1;if(e.startsWith("/")&&!e.startsWith("//")||e.startsWith("?")||e.startsWith("#"))return!0;try{let r=new URL(e,window.location.origin),t=r.protocol.toLowerCase(),n=r.hostname.toLowerCase();return t==="https:"||t==="http:"&&(n==="localhost"||n==="127.0.0.1")}catch{return!1}}function qt(e){var r;try{let t=e.split(".");if(t.length!==3)return null;let n=t[1].replace(/-/g,"+").replace(/_/g,"/");return((r=JSON.parse(atob(n)).data)==null?void 0:r.expiresAt)??null}catch{return null}}function qe(e){return`${Y.embedAuthToken}:${e}`}function Qt(e){if(!g())return null;try{let r=qe(e),t=localStorage.getItem(r);if(!t)return null;let n=qt(t);return n&&n>Date.now()?t:(localStorage.removeItem(r),null)}catch{return null}}function Zt(e,r){if(g())try{localStorage.setItem(qe(e),r)}catch{}}function Xt(e){if(g())try{localStorage.removeItem(qe(e))}catch{}}function Jt(){if(!g())return"";try{let e=localStorage.getItem(Y.anonId);return e||(e=crypto.randomUUID(),localStorage.setItem(Y.anonId,e)),e}catch{return crypto.randomUUID()}}function er(){if(!g())return{};let e={},r=new URLSearchParams(window.location.search);for(let[t,n]of r.entries())Fe.has(t)||(e[t]=n);return e}function tr(e,r,t,n,o,i){let s=new URL(`${t}/interview/${e}`);if(s.searchParams.set(Z.embed,ht.true),s.searchParams.set(Z.embedType,r==="float"?"chat":r),g()){let c=window.matchMedia("(prefers-color-scheme: dark)").matches;i&&i!==L.system?s.searchParams.set(Z.theme,i):s.searchParams.set(Z.theme,c?L.dark:L.light)}else s.searchParams.set(Z.theme,i||L.light);let a=er();for(let[c,m]of Object.entries(a))s.searchParams.set(c,m);let l=(c,m)=>{if(!m)return;let f=Ct(m);f&&s.searchParams.set(c,f)};if(o!=null&&o.light&&(l(D.primary,o.light.primary),l(D.secondary,o.light.secondary),l(D.bg,o.light.bg),l(D.text,o.light.text)),o!=null&&o.dark&&(l(D.darkPrimary,o.dark.primary),l(D.darkSecondary,o.dark.secondary),l(D.darkBg,o.dark.bg),l(D.darkText,o.dark.text)),n)for(let[c,m]of Object.entries(n))Fe.has(c)||s.searchParams.set(c,m);return s.toString()}var rr=new Set(["hideProgress","hideGreeting","hideBranding","enableFullScreen"]);function N(e){let r=e==null?void 0:e.appearance;if(!r)return;let t={};return r.hideProgress!==void 0&&(t.hideProgress=r.hideProgress?"true":"false"),r.hideGreeting!==void 0&&(t.hideGreeting=r.hideGreeting?"true":"false"),r.hideBranding!==void 0&&(t.hideBranding=r.hideBranding?"true":"false"),r.enableFullScreen!==void 0&&(t.enableFullScreen=r.enableFullScreen?"true":"false"),Object.keys(t).length>0?t:void 0}function B(e,r,t,n,o,i,s){if(!g())return{};let a=document.createElement("iframe");if(a.src=tr(e,r,t,n,o,i),s&&Object.keys(s).length>0){let l=new URL(a.src);for(let[c,m]of Object.entries(s))rr.has(c)&&l.searchParams.set(c,m);a.src=l.toString()}return a.setAttribute("allow","microphone; camera"),a.setAttribute("allowfullscreen","true"),a.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-top-navigation"),a.setAttribute("data-perspective","true"),a.style.cssText="border:none;",a}function $(e,r,t,n,o){if(!g())return()=>{};let i=null,s=a=>{var l,c,m,f,d,b;if(a.origin===n&&a.source===t.contentWindow&&typeof((l=a.data)==null?void 0:l.type)=="string"&&a.data.type.startsWith("perspective:")&&a.data.researchId===e)switch(a.data.type){case k.ready:{Qe(t,n),J(t,n,{type:k.anonId,anonId:Jt()}),J(t,n,{type:k.init,version:mt,features:ut,researchId:e,hasCloseButton:(o==null?void 0:o.hasCloseButton)??!1});let p=Qt(e);p&&(J(t,n,{type:k.authComplete,token:p,researchId:e}),(c=r.onAuth)==null||c.call(r,{researchId:e,token:p})),(m=r.onReady)==null||m.call(r);break}case k.resize:o!=null&&o.skipResize||(t.style.height=`${a.data.height}px`);break;case k.submit:(f=r.onSubmit)==null||f.call(r,{researchId:e});break;case k.close:(d=r.onClose)==null||d.call(r);break;case k.error:{let p=new Error(a.data.error);p.code=a.data.code||"UNKNOWN",p.code===ft.SDK_OUTDATED?console.error("[Perspective] SDK version outdated. Please update @perspective-ai/sdk to the latest version.",p.message):console.error("[Perspective] Embed error:",p.message),(b=r.onError)==null||b.call(r,p);break}case k.redirect:{let p=a.data.url;if(!Wt(p)){console.warn("[Perspective] Blocked unsafe redirect URL:",p);return}r.onNavigate?r.onNavigate(p):window.location.href=p;break}case k.authRequest:{let{authUrl:p}=a.data;if(!p||typeof p!="string")return;let u=new URL(n).origin;try{if(new URL(p).origin!==u){console.warn("[Perspective] Blocked auth URL with unexpected origin:",p);return}}catch{console.warn("[Perspective] Blocked malformed auth URL:",p);return}i==null||i();let v=`${p}&return_url=${encodeURIComponent(window.location.href)}`,C=500,I=700,A=(window.screen.width-C)/2+(window.screenLeft??window.screenX??0),H=(window.screen.height-I)/2+(window.screenTop??window.screenY??0),E=`width=${C},height=${I},top=${H},left=${A},menubar=no,toolbar=no,location=no,status=no,scrollbars=yes`,h=window.open(v,"perspective-auth",E)??window.open(v,"_blank"),Ae=R=>{var Q;Zt(e,R),J(t,n,{type:k.authComplete,token:R,researchId:e}),(Q=r.onAuth)==null||Q.call(r,{researchId:e,token:R})},ce=()=>{clearInterval($e),window.removeEventListener("message",pe),i=null},pe=R=>{var Le,Me;if(R.source!==h||((Le=R.data)==null?void 0:Le.type)!==k.popupAuthComplete||R.origin!==u)return;let Q=(Me=R.data)==null?void 0:Me.token;Q&&Ae(Q),ce()};window.addEventListener("message",pe);let $e=h?setInterval(()=>{h.closed&&(ce(),J(t,n,{type:k.authCancelled,researchId:e}))},500):void 0;i=ce;break}case k.authSignout:{Xt(e);try{let p=new URL(n).origin,u=window.open(`${p}/embed-auth/signout`,"perspective-signout","width=1,height=1,top=0,left=0");u&&setTimeout(()=>{try{u.close()}catch{}},3e3)}catch{}break}}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s),i==null||i()}}function J(e,r,t){var n;g()&&((n=e.contentWindow)==null||n.postMessage(t,r))}var ve=new Map;function U(e,r){return ve.set(e,r),()=>{ve.delete(e),ve.size===0&&lr()}}function nr(){if(!g())return"";let r=window.matchMedia("(prefers-color-scheme: dark)").matches?"hsl(217 33% 17%)":"hsl(240 6% 90%)";return`
|
|
1
|
+
"use strict";var Perspective=(()=>{var Ue=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames;var Ft=Object.prototype.hasOwnProperty;var Kt=(e,r)=>{for(var t in r)Ue(e,t,{get:r[t],enumerable:!0})},Vt=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Ut(r))!Ft.call(e,o)&&o!==t&&Ue(e,o,{get:()=>r[o],enumerable:!(n=$t(r,o))||n.enumerable});return e};var zt=e=>Vt(Ue({},"__esModule",{value:!0}),e);var Rr={};Kt(Rr,{autoInit:()=>Be,configure:()=>Ke,createChatBubble:()=>Ze,createFloatBubble:()=>xe,createFullpage:()=>Pe,createWidget:()=>Re,default:()=>Hr,destroy:()=>Pt,destroyAll:()=>Dt,getConfig:()=>Ve,init:()=>te,mount:()=>Je,openPopup:()=>Oe,openSlider:()=>_e});var mt="1.6.2",he={RESIZE:1,THEME_SYNC:2,ANON_ID:4,SCROLLBAR_STYLES:8,EMBED_AUTH:16},ut=he.RESIZE|he.THEME_SYNC|he.ANON_ID|he.SCROLLBAR_STYLES|he.EMBED_AUTH,Z={embed:"embed",embedType:"embed_type",theme:"theme"},D={primary:"brand.primary",secondary:"brand.secondary",bg:"brand.bg",text:"brand.text",darkPrimary:"brand.dark.primary",darkSecondary:"brand.dark.secondary",darkBg:"brand.dark.bg",darkText:"brand.dark.text"},Fe=new Set([...Object.values(Z),...Object.values(D)]),x={widget:"data-perspective-widget",popup:"data-perspective-popup",slider:"data-perspective-slider",float:"data-perspective-float",chat:"data-perspective-chat",fullpage:"data-perspective-fullpage",params:"data-perspective-params",brand:"data-perspective-brand",brandDark:"data-perspective-brand-dark",theme:"data-perspective-theme",noStyle:"data-perspective-no-style",autoOpen:"data-perspective-auto-open",showOnce:"data-perspective-show-once",disableClose:"data-perspective-disable-close",launcherIcon:"data-perspective-launcher-icon",launcherStyle:"data-perspective-launcher-style",launcherClass:"data-perspective-launcher-class"},k={init:"perspective:init",ready:"perspective:ready",resize:"perspective:resize",submit:"perspective:submit",close:"perspective:close",error:"perspective:error",redirect:"perspective:redirect",anonId:"perspective:anon-id",injectStyles:"perspective:inject-styles",themeChange:"perspective:theme-change",authRequest:"perspective:auth-request",authSignout:"perspective:auth-signout",authComplete:"perspective:auth-complete",authCancelled:"perspective:auth-cancelled",popupAuthComplete:"perspective:popup-auth-complete",requestScrollbarStyles:"perspective:request-scrollbar-styles"},ft={SDK_OUTDATED:"SDK_OUTDATED",INVALID_RESEARCH:"INVALID_RESEARCH",UNKNOWN:"UNKNOWN"},ht={true:"true",false:"false"},L={dark:"dark",light:"light",system:"system"};var Y={anonId:"perspective-anon-id",triggerShown:"perspective-trigger-shown",embedAuthToken:"perspective-embed-auth-token",embedState:"perspective-embed-state"};var jt="https://getperspective.ai",be={};function Ke(e){be={...be,...e}}function Ve(){return{...be}}function g(){return typeof window<"u"&&typeof document<"u"}function gt(e){try{return new URL(e).origin}catch{return e}}function M(e){if(e)return gt(e);if(be.host)return gt(be.host);if(g()){let r=bt();if(r)return r}return jt}var ge=null;function bt(){if(ge!==null)return ge;if(!g())return null;let e=document.currentScript;if(e!=null&&e.src)try{return ge=new URL(e.src).origin,ge}catch{}return ge="",null}g()&&bt();var ne={primaryColor:"#7c3aed",textColor:"#ffffff",darkPrimaryColor:"#a78bfa",darkTextColor:"#ffffff"},Gt=3e3,ze=new Map,Ie=new Map;function Yt(e,r){return`${M(r)}::${e}`}async function vt(e,r){let t=Yt(e,r);if(ze.has(t))return ze.get(t);if(Ie.has(t))return Ie.get(t);let n=(async()=>{try{let o=M(r),i=new AbortController,s=setTimeout(()=>i.abort(),Gt),a=await fetch(`${o}/api/v1/embed/config/${e}`,{signal:i.signal});if(clearTimeout(s),!a.ok)return ne;let l=await a.json();return ze.set(t,l),l}catch{return ne}finally{Ie.delete(t)}})();return Ie.set(t,n),n}function yt(e){let r=e.trim();if(r.startsWith("timeout:")){let t=parseInt(r.slice(8),10);if(isNaN(t)||t<0)throw new Error(`Invalid timeout delay: "${e}"`);return{type:"timeout",delay:t}}if(r==="timeout")return{type:"timeout",delay:5e3};if(r==="exit-intent")return{type:"exit-intent"};throw new Error(`Unknown trigger type: "${e}". Expected "timeout:<ms>" or "exit-intent".`)}function je(e,r){if(e.type==="timeout"){let n=setTimeout(r,e.delay);return()=>clearTimeout(n)}if(e.type==="exit-intent"){let n=o=>{o.clientY<=0&&(r(),document.removeEventListener("mouseleave",n))};return document.addEventListener("mouseleave",n),()=>document.removeEventListener("mouseleave",n)}let t=e;throw new Error(`Unknown trigger type: ${t.type}`)}function Et(e){return`${Y.triggerShown}:${e}`}function wt(e){if(!e)return"session";let r=e.trim();return r==="visitor"?"visitor":r==="false"?!1:"session"}function Ge(e,r){if(r===!1)return!0;try{return(r==="visitor"?localStorage:sessionStorage).getItem(Et(e))===null}catch{return!0}}function Ye(e,r){if(r!==!1)try{(r==="visitor"?localStorage:sessionStorage).setItem(Et(e),"1")}catch{}}function O(...e){return e.map(r=>(r||"").split(" ")).flat().filter(Boolean).join(" ")}function _(e){return e&&e!==L.system?`perspective-${e}-theme`:void 0}function X(e){return e===L.dark?!0:e===L.light||!g()?!1:window.matchMedia("(prefers-color-scheme: dark)").matches}function xt(e){return X(e)?"dark":"light"}function Ct(e){let r=e.trim();if(!r)return;let t=r.startsWith("#")?r:`#${r}`;if(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(t))return t;let n=t.slice(1).replace(/[^0-9a-fA-F]/g,"");if(n.length>=6)return`#${n.slice(0,6)}`;if(n.length>=3)return`#${n.slice(0,3)}`}function Wt(e){if(!e||typeof e!="string")return!1;if(e.startsWith("/")&&!e.startsWith("//")||e.startsWith("?")||e.startsWith("#"))return!0;try{let r=new URL(e,window.location.origin),t=r.protocol.toLowerCase(),n=r.hostname.toLowerCase();return t==="https:"||t==="http:"&&(n==="localhost"||n==="127.0.0.1")}catch{return!1}}function qt(e){var r;try{let t=e.split(".");if(t.length!==3)return null;let n=t[1].replace(/-/g,"+").replace(/_/g,"/");return((r=JSON.parse(atob(n)).data)==null?void 0:r.expiresAt)??null}catch{return null}}function qe(e){return`${Y.embedAuthToken}:${e}`}function Qt(e){if(!g())return null;try{let r=qe(e),t=localStorage.getItem(r);if(!t)return null;let n=qt(t);return n&&n>Date.now()?t:(localStorage.removeItem(r),null)}catch{return null}}function Zt(e,r){if(g())try{localStorage.setItem(qe(e),r)}catch{}}function Xt(e){if(g())try{localStorage.removeItem(qe(e))}catch{}}function Jt(){if(!g())return"";try{let e=localStorage.getItem(Y.anonId);return e||(e=crypto.randomUUID(),localStorage.setItem(Y.anonId,e)),e}catch{return crypto.randomUUID()}}function er(){if(!g())return{};let e={},r=new URLSearchParams(window.location.search);for(let[t,n]of r.entries())Fe.has(t)||(e[t]=n);return e}function tr(e,r,t,n,o,i){let s=new URL(`${t}/interview/${e}`);if(s.searchParams.set(Z.embed,ht.true),s.searchParams.set(Z.embedType,r==="float"?"chat":r),g()){let c=window.matchMedia("(prefers-color-scheme: dark)").matches;i&&i!==L.system?s.searchParams.set(Z.theme,i):s.searchParams.set(Z.theme,c?L.dark:L.light)}else s.searchParams.set(Z.theme,i||L.light);let a=er();for(let[c,m]of Object.entries(a))s.searchParams.set(c,m);let l=(c,m)=>{if(!m)return;let d=Ct(m);d&&s.searchParams.set(c,d)};if(o!=null&&o.light&&(l(D.primary,o.light.primary),l(D.secondary,o.light.secondary),l(D.bg,o.light.bg),l(D.text,o.light.text)),o!=null&&o.dark&&(l(D.darkPrimary,o.dark.primary),l(D.darkSecondary,o.dark.secondary),l(D.darkBg,o.dark.bg),l(D.darkText,o.dark.text)),n)for(let[c,m]of Object.entries(n))Fe.has(c)||s.searchParams.set(c,m);return s.toString()}var rr=new Set(["hideProgress","hideGreeting","hideBranding","enableFullScreen"]);function N(e){let r=e==null?void 0:e.appearance;if(!r)return;let t={};return r.hideProgress!==void 0&&(t.hideProgress=r.hideProgress?"true":"false"),r.hideGreeting!==void 0&&(t.hideGreeting=r.hideGreeting?"true":"false"),r.hideBranding!==void 0&&(t.hideBranding=r.hideBranding?"true":"false"),r.enableFullScreen!==void 0&&(t.enableFullScreen=r.enableFullScreen?"true":"false"),Object.keys(t).length>0?t:void 0}function B(e,r,t,n,o,i,s){if(!g())return{};let a=document.createElement("iframe");if(a.src=tr(e,r,t,n,o,i),s&&Object.keys(s).length>0){let l=new URL(a.src);for(let[c,m]of Object.entries(s))rr.has(c)&&l.searchParams.set(c,m);a.src=l.toString()}return a.setAttribute("allow","microphone; camera"),a.setAttribute("allowfullscreen","true"),a.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-top-navigation"),a.setAttribute("data-perspective","true"),a.style.cssText="border:none;",a}function $(e,r,t,n,o){if(!g())return()=>{};let i=null,s=a=>{var l,c,m,d,u,y;if(a.origin===n&&a.source===t.contentWindow&&typeof((l=a.data)==null?void 0:l.type)=="string"&&a.data.type.startsWith("perspective:")&&a.data.researchId===e)switch(a.data.type){case k.ready:{Qe(t,n),J(t,n,{type:k.anonId,anonId:Jt()}),J(t,n,{type:k.init,version:mt,features:ut,researchId:e,hasCloseButton:(o==null?void 0:o.hasCloseButton)??!1});let p=Qt(e);p&&(J(t,n,{type:k.authComplete,token:p,researchId:e}),(c=r.onAuth)==null||c.call(r,{researchId:e,token:p})),(m=r.onReady)==null||m.call(r);break}case k.resize:o!=null&&o.skipResize||(t.style.height=`${a.data.height}px`);break;case k.submit:(d=r.onSubmit)==null||d.call(r,{researchId:e});break;case k.close:(u=r.onClose)==null||u.call(r);break;case k.error:{let p=new Error(a.data.error);p.code=a.data.code||"UNKNOWN",p.code===ft.SDK_OUTDATED?console.error("[Perspective] SDK version outdated. Please update @perspective-ai/sdk to the latest version.",p.message):console.error("[Perspective] Embed error:",p.message),(y=r.onError)==null||y.call(r,p);break}case k.redirect:{let p=a.data.url;if(!Wt(p)){console.warn("[Perspective] Blocked unsafe redirect URL:",p);return}r.onNavigate?r.onNavigate(p):window.location.href=p;break}case k.authRequest:{let{authUrl:p}=a.data;if(!p||typeof p!="string")return;let f=new URL(n).origin;try{if(new URL(p).origin!==f){console.warn("[Perspective] Blocked auth URL with unexpected origin:",p);return}}catch{console.warn("[Perspective] Blocked malformed auth URL:",p);return}i==null||i();let b=`${p}&return_url=${encodeURIComponent(window.location.href)}`,S=500,I=700,A=(window.screen.width-S)/2+(window.screenLeft??window.screenX??0),H=(window.screen.height-I)/2+(window.screenTop??window.screenY??0),E=`width=${S},height=${I},top=${H},left=${A},menubar=no,toolbar=no,location=no,status=no,scrollbars=yes`,h=window.open(b,"perspective-auth",E)??window.open(b,"_blank"),Ae=R=>{var Q;Zt(e,R),J(t,n,{type:k.authComplete,token:R,researchId:e}),(Q=r.onAuth)==null||Q.call(r,{researchId:e,token:R})},ce=()=>{clearInterval($e),window.removeEventListener("message",pe),i=null},pe=R=>{var Le,Me;if(R.source!==h||((Le=R.data)==null?void 0:Le.type)!==k.popupAuthComplete||R.origin!==f)return;let Q=(Me=R.data)==null?void 0:Me.token;Q&&Ae(Q),ce()};window.addEventListener("message",pe);let $e=h?setInterval(()=>{h.closed&&(ce(),J(t,n,{type:k.authCancelled,researchId:e}))},500):void 0;i=ce;break}case k.authSignout:{Xt(e);try{let p=new URL(n).origin,f=window.open(`${p}/embed-auth/signout`,"perspective-signout","width=1,height=1,top=0,left=0");f&&setTimeout(()=>{try{f.close()}catch{}},3e3)}catch{}break}}};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s),i==null||i()}}function J(e,r,t){var n;g()&&((n=e.contentWindow)==null||n.postMessage(t,r))}var ve=new Map;function U(e,r){return ve.set(e,r),()=>{ve.delete(e),ve.size===0&&lr()}}function nr(){if(!g())return"";let r=window.matchMedia("(prefers-color-scheme: dark)").matches?"hsl(217 33% 17%)":"hsl(240 6% 90%)";return`
|
|
2
2
|
* {
|
|
3
3
|
scrollbar-width: thin;
|
|
4
4
|
scrollbar-color: ${r} transparent;
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
overflow: hidden;
|
|
39
39
|
padding: 1.5rem;
|
|
40
40
|
box-sizing: border-box;
|
|
41
|
-
`;let o=`linear-gradient(90deg, ${r.shimmer} 25%, ${r.shimmerHighlight} 50%, ${r.shimmer} 75%)`,i=(d,
|
|
41
|
+
`;let o=`linear-gradient(90deg, ${r.shimmer} 25%, ${r.shimmerHighlight} 50%, ${r.shimmer} 75%)`,i=(d,u)=>{let y=document.createElement("div");return y.style.cssText=`background:${o};background-size:800px 100%;animation:perspective-shimmer 1.5s infinite linear;border-radius:8px;height:${u};width:${d};margin-bottom:0.5rem;`,y};if(!(t!=null&&t.hideBranding)||!(t!=null&&t.hideProgress)){let d=document.createElement("div");if(d.style.cssText="display:flex;flex-direction:column;align-items:center;gap:0.5rem;margin-bottom:1rem;",!(t!=null&&t.hideBranding)){let u=i("7rem","1.25rem");u.style.margin="0 auto",d.appendChild(u)}if(!(t!=null&&t.hideProgress)){let u=i("100%","0.25rem");u.style.borderRadius="9999px",d.appendChild(u)}n.appendChild(d)}if(!(t!=null&&t.hideGreeting)){let d=document.createElement("div");d.style.cssText=`border:1px solid ${r.border};border-radius:16px;padding:1.25rem;margin-bottom:1.25rem;`;let u=document.createElement("div");u.style.cssText="display:flex;align-items:center;gap:0.625rem;margin-bottom:0.875rem;";let y=i("2.25rem","2.25rem");y.style.borderRadius="50%",y.style.flexShrink="0",y.style.marginBottom="0";let p=i("6rem","0.875rem");p.style.marginBottom="0",u.appendChild(y),u.appendChild(p),d.appendChild(u);let f=i("60%","1.125rem");f.style.marginBottom="0.875rem",d.appendChild(f),d.appendChild(i("95%","0.75rem")),d.appendChild(i("90%","0.75rem"));let b=i("75%","0.75rem");b.style.marginBottom="0",d.appendChild(b),n.appendChild(d)}let s=document.createElement("div");s.style.cssText="padding:0 0.25rem;margin-bottom:auto;",s.appendChild(i("92%","0.75rem"));let a=i("50%","0.75rem");a.style.marginBottom="0.75rem",s.appendChild(a);let l=i("1.5rem","1.5rem");l.style.marginBottom="0",s.appendChild(l),n.appendChild(s);let c=document.createElement("div");c.style.cssText=`
|
|
42
42
|
margin-top: 1rem;
|
|
43
43
|
border: 1px solid ${r.border};
|
|
44
44
|
border-radius: 28px;
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
align-items: center;
|
|
49
49
|
justify-content: flex-end;
|
|
50
50
|
box-sizing: border-box;
|
|
51
|
-
`;let m=i("4.5rem","2.25rem");m.style.borderRadius="9999px",m.style.marginBottom="0",c.appendChild(m),n.appendChild(c)
|
|
51
|
+
`;let m=i("4.5rem","2.25rem");return m.style.borderRadius="9999px",m.style.marginBottom="0",c.appendChild(m),n.appendChild(c),n}var Tt=!1,dr=`
|
|
52
52
|
--perspective-overlay-bg: rgba(0, 0, 0, 0.5);
|
|
53
53
|
--perspective-modal-bg: #ffffff;
|
|
54
54
|
--perspective-modal-text: #151B23;
|
|
@@ -461,5 +461,5 @@
|
|
|
461
461
|
<path d="M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1"/>
|
|
462
462
|
</svg>`;var ee=`<svg xmlns="http://www.w3.org/2000/svg" class="lucide-x" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
463
463
|
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
464
|
-
</svg>`;var He=new WeakMap;function mr(e,r){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:r,iframe:null,container:null}}function ur(e,r){let t=e.querySelector(".perspective-embed-root"),n=e.querySelector("iframe[data-perspective]"),o=!1,i=()=>{if(!o){if(o=!0,n){let s=He.get(n);s&&(s.cleanup(),s.unregister(),He.delete(n))}t==null||t.remove()}};return{unmount:i,update:()=>{},destroy:i,researchId:r,type:"widget",iframe:n,container:e}}function Re(e,r){var b,p,u;let{researchId:t}=r;if(!g()||!e)return mr(t,"widget");if(e.querySelector("iframe[data-perspective]"))return ur(e,t);let n=M(r.host);K(),F();let o=document.createElement("div");o.className=O("perspective-embed-root",_(r.theme)),o.style.cssText="position:relative;width:100%;height:100%;min-height:500px;";let i=P({theme:r.theme,brand:r.brand,appearance:(p=(b=r._apiConfig)==null?void 0:b.embedSettings)==null?void 0:p.appearance});o.appendChild(i);let s=N((u=r._apiConfig)==null?void 0:u.embedSettings),a=B(t,"widget",n,r.params,r.brand,r.theme,s);a.style.width="100%",a.style.height="100%",a.style.minHeight="500px",a.style.opacity="0",a.style.transition="opacity 0.3s ease",o.appendChild(a),e.appendChild(o);let l={...r},c=$(t,{get onReady(){return()=>{var v;i.style.opacity="0",a.style.opacity="1",setTimeout(()=>i.remove(),300),(v=l.onReady)==null||v.call(l)}},get onSubmit(){return l.onSubmit},get onNavigate(){return l.onNavigate},get onClose(){return l.onClose},get onError(){return l.onError}},a,n,{skipResize:!0}),m=U(a,n);He.set(a,{cleanup:c,unregister:m,wrapper:o});let f=!1,d=()=>{f||(f=!0,c(),m(),He.delete(a),o.remove())};return{unmount:d,update:v=>{l={...l,...v}},destroy:d,researchId:t,type:"widget",iframe:a,container:e}}function It({researchId:e,type:r,host:t}){return`${Y.embedState}:${M(t)}:${r}:${e}`}function Ee(e){if(!g())return null;try{let r=sessionStorage.getItem(It(e));if(!r)return null;let t=JSON.parse(r);return typeof t.open=="boolean"?t.open:null}catch{return null}}function ie(e){if(g())try{let r={v:1,open:e.open};sessionStorage.setItem(It(e),JSON.stringify(r))}catch{}}function fr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:"popup",iframe:null,container:null}}function Oe(e){var I,A,H;let{researchId:r}=e;if(!g())return fr(r);let t=M(e.host);K(),F();let n=document.createElement("div");n.className=O("perspective-overlay perspective-embed-root",_(e.theme));let o=document.createElement("div");o.className="perspective-modal";let i=document.createElement("button");i.className="perspective-close",i.innerHTML=ee,i.setAttribute("aria-label","Close"),e.disableClose&&(i.style.display="none");let s=P({theme:e.theme,brand:e.brand,appearance:(A=(I=e._apiConfig)==null?void 0:I.embedSettings)==null?void 0:A.appearance});s.style.borderRadius="16px";let a=N((H=e._apiConfig)==null?void 0:H.embedSettings),l=B(r,"popup",t,e.params,e.brand,e.theme,a);l.style.opacity="0",l.style.transition="opacity 0.3s ease",o.appendChild(i),o.appendChild(s),o.appendChild(l),n.appendChild(o),document.body.appendChild(n);let c={...e},m=!0,f=null,d=E=>{ie({researchId:r,type:"popup",host:e.host,open:E})},b=U(l,t);d(!0);let p=()=>{var E;m&&(m=!1,f==null||f(),b(),n.remove(),document.removeEventListener("keydown",C),(E=c.onClose)==null||E.call(c))},u=()=>{d(!1),p()},v=()=>{p()};f=$(r,{get onReady(){return()=>{var E;s.style.opacity="0",l.style.opacity="1",setTimeout(()=>s.remove(),300),(E=c.onReady)==null||E.call(c)}},get onSubmit(){return c.onSubmit},get onNavigate(){return c.onNavigate},get onClose(){return u},get onError(){return c.onError}},l,t,{skipResize:!0,hasCloseButton:!e.disableClose});let C=E=>{E.key==="Escape"&&u()};return e.disableClose||(i.addEventListener("click",u),n.addEventListener("click",E=>{E.target===n&&u()}),document.addEventListener("keydown",C)),{unmount:v,update:E=>{c={...c,...E}},destroy:u,researchId:r,type:"popup",iframe:l,container:n}}function hr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:"slider",iframe:null,container:null}}function _e(e){var I,A,H;let{researchId:r}=e;if(!g())return hr(r);let t=M(e.host);K(),F();let n=document.createElement("div");n.className=O("perspective-slider-backdrop perspective-embed-root",_(e.theme));let o=document.createElement("div");o.className=O("perspective-slider perspective-embed-root",_(e.theme));let i=document.createElement("button");i.className="perspective-close",i.innerHTML=ee,i.setAttribute("aria-label","Close"),e.disableClose&&(i.style.display="none");let s=P({theme:e.theme,brand:e.brand,appearance:(A=(I=e._apiConfig)==null?void 0:I.embedSettings)==null?void 0:A.appearance}),a=N((H=e._apiConfig)==null?void 0:H.embedSettings),l=B(r,"slider",t,e.params,e.brand,e.theme,a);l.style.opacity="0",l.style.transition="opacity 0.3s ease",o.appendChild(i),o.appendChild(s),o.appendChild(l),document.body.appendChild(n),document.body.appendChild(o);let c={...e},m=!0,f=null,d=E=>{ie({researchId:r,type:"slider",host:e.host,open:E})},b=U(l,t);d(!0);let p=()=>{var E;m&&(m=!1,f==null||f(),b(),o.remove(),n.remove(),document.removeEventListener("keydown",C),(E=c.onClose)==null||E.call(c))},u=()=>{d(!1),p()},v=()=>{p()};f=$(r,{get onReady(){return()=>{var E;s.style.opacity="0",l.style.opacity="1",setTimeout(()=>s.remove(),300),(E=c.onReady)==null||E.call(c)}},get onSubmit(){return c.onSubmit},get onNavigate(){return c.onNavigate},get onClose(){return u},get onError(){return c.onError}},l,t,{skipResize:!0,hasCloseButton:!e.disableClose});let C=E=>{E.key==="Escape"&&u()};return e.disableClose||(i.addEventListener("click",u),n.addEventListener("click",u),document.addEventListener("keydown",C)),{unmount:v,update:E=>{c={...c,...E}},destroy:u,researchId:r,type:"slider",iframe:l,container:o}}function Ht(e,r){if(!r)return e;let t=e.launcher??{};return{...e,launcher:{...t,...r,style:{...t.style,...r.style}}}}var gr=2e3,br=3e3,vr=40,yr="Have a question? I'm here to help.";function Er(e){let r=Array.isArray(e)?e:e?[e]:[],t=r.includes("VOICE"),n=r.includes("TEXT");return t&&n?"both":n?"text":"voice"}function wr(e){var r,t;return e.channel??((r=e._apiConfig)==null?void 0:r.allowedChannels)??((t=e._apiConfig)==null?void 0:t.channel)??void 0}function xr(e){var n;let r=e.welcomeMessage??((n=e._apiConfig)==null?void 0:n.welcomeMessage),t=typeof r=="string"?r.trim():"";return t.length>0?t:yr}function Cr(e){return Er(wr(e))==="text"?Mt:Lt}function Rt(e,r){let t=document.createElement("img");return t.src=e,t.alt="",t.style.width="100%",t.style.height="100%",t.style.objectFit="cover",t.style.borderRadius="inherit",t.onerror=()=>{let n=t.parentElement;n&&(t.remove(),n.innerHTML=r)},t}function we(e,r){var o,i;let t=((o=r.launcher)==null?void 0:o.icon)??"default",n=Cr(r);if(t==="default"){e.innerHTML=n;return}if(t==="avatar"){let s=(i=r._apiConfig)==null?void 0:i.avatarUrl;s?(e.innerHTML="",e.appendChild(Rt(s,n))):e.innerHTML=n;return}if(typeof t=="object"&&t!==null){if("url"in t){e.innerHTML="",e.appendChild(Rt(t.url,n));return}if("svg"in t){e.innerHTML=t.svg;return}}e.innerHTML=n}function Sr(e){let r=e.currentTime,t=e.createOscillator(),n=e.createGain();t.type="sine",t.frequency.setValueAtTime(880,r),t.frequency.setValueAtTime(1175,r+.1),n.gain.setValueAtTime(.15,r),n.gain.linearRampToValueAtTime(.18,r+.1),n.gain.exponentialRampToValueAtTime(.001,r+.6),t.connect(n).connect(e.destination),t.start(r),t.stop(r+.65);let o=e.createOscillator(),i=e.createGain();o.type="sine",o.frequency.setValueAtTime(1175,r+.15),o.frequency.setValueAtTime(1400,r+.25),i.gain.setValueAtTime(0,r),i.gain.setValueAtTime(.12,r+.15),i.gain.exponentialRampToValueAtTime(.001,r+.55),o.connect(i).connect(e.destination),o.start(r+.15),o.stop(r+.6)}function kr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},open:()=>{},close:()=>{},toggle:()=>{},isOpen:!1,researchId:e,type:"float",iframe:null,container:null}}function xe(e){var rt,nt,ot,st,it,at;let{researchId:r,_apiConfig:t,theme:n,brand:o}=e;if(!g())return kr(r);let i=M(e.host);K(),F();let s=document.createElement("button");if(s.className=O("perspective-float-bubble perspective-embed-root",_(e.theme)),we(s,e),s.setAttribute("aria-label","Open chat"),s.setAttribute("data-perspective","float-bubble"),t||o){let w=X(n)?((rt=o==null?void 0:o.dark)==null?void 0:rt.primary)??(t==null?void 0:t.darkPrimaryColor)??"#a78bfa":((nt=o==null?void 0:o.light)==null?void 0:nt.primary)??(t==null?void 0:t.primaryColor)??"#7c3aed";s.style.setProperty("--perspective-float-bg",w),s.style.setProperty("--perspective-float-shadow",`0 4px 12px ${w}66`),s.style.setProperty("--perspective-float-shadow-hover",`0 6px 16px ${w}80`),s.style.backgroundColor=w,s.style.boxShadow=`0 4px 12px ${w}66`}let a=Ht(e,(ot=t==null?void 0:t.embedSettings)==null?void 0:ot.launcher);if(a!==e&&we(s,a),(st=a.launcher)!=null&&st.style&&Object.assign(s.style,a.launcher.style),(it=a.launcher)!=null&&it.className)for(let y of a.launcher.className.split(/\s+/).filter(Boolean))s.classList.add(y);document.body.appendChild(s),((at=e.launcher)==null?void 0:at.icon)==="avatar"&&!(t!=null&&t.avatarUrl)&&fetch(`${i}/api/v1/embed/config/${r}`).then(y=>y.ok?y.json():null).then(y=>{y!=null&&y.avatarUrl&&(h={...h,_apiConfig:{...h._apiConfig,...y}},d||we(s,h))}).catch(()=>{});let l=null,c=null,m=null,f=null,d=!1,b=null,p=null,u=null,v=null,C=!1,I=!1,A=[],H=y=>{ie({researchId:r,type:"float",host:e.host,open:y})},E=Ee({researchId:r,type:"float",host:e.host})===!0,h={...a},Ae=()=>{we(s,h),s.setAttribute("aria-label","Open chat"),s.classList.remove("perspective-float-bubble-open")},ce=()=>{s.innerHTML=ee,s.setAttribute("aria-label","Close chat"),s.classList.add("perspective-float-bubble-open")},pe=()=>{for(let y of A)window.clearTimeout(y);A=[],p!==null&&(window.clearInterval(p),p=null)},$e=()=>{u==null||u.remove(),u=null},R=()=>{p!==null&&(window.clearInterval(p),p=null),b==null||b.remove(),b=null,$e()},Q=()=>{u||d||(u=document.createElement("span"),u.className="perspective-float-notification-dot",s.appendChild(u))},Le=()=>{try{let y=window.AudioContext||window.webkitAudioContext;if(!y)return;v||(v=new y),v.state==="suspended"&&v.resume(),Sr(v)}catch{}},Me=y=>{if(R(),d)return;let w=document.createElement("div");w.className=O("perspective-float-teaser perspective-embed-root",_(h.theme));let j=document.createElement("div");j.className="perspective-float-teaser-message";let G=document.createElement("span");j.appendChild(G),w.appendChild(j),w.addEventListener("click",()=>de()),document.body.appendChild(w),b=w,Q();let V=0;p=window.setInterval(()=>{V+=1,G.textContent=y.slice(0,V),V>=y.length&&p!==null&&(window.clearInterval(p),p=null)},vr)},et=()=>{if(C||I||d)return;C=!0;let y=window.setTimeout(()=>{d||I||Le()},gr),w=window.setTimeout(()=>{d||I||Me(xr(h))},br);A.push(y,w)},de=()=>{var G,V,me;if(d)return;d=!0,H(!0),pe(),R(),l=document.createElement("div"),l.className=O("perspective-float-window perspective-embed-root",_(h.theme));let y=document.createElement("button");y.className="perspective-close",y.innerHTML=ee,y.setAttribute("aria-label","Close chat"),y.addEventListener("click",()=>re());let w=P({theme:h.theme,brand:h.brand,appearance:(V=(G=h._apiConfig)==null?void 0:G.embedSettings)==null?void 0:V.appearance});w.style.borderRadius="16px";let j=N((me=h._apiConfig)==null?void 0:me.embedSettings);c=B(r,"float",i,h.params,h.brand,h.theme,j),c.style.opacity="0",c.style.transition="opacity 0.3s ease",l.appendChild(y),l.appendChild(w),l.appendChild(c),document.body.appendChild(l),m=$(r,{get onReady(){return()=>{var ue;w.style.opacity="0",c.style.opacity="1",setTimeout(()=>w.remove(),300),(ue=h.onReady)==null||ue.call(h)}},get onSubmit(){return h.onSubmit},get onNavigate(){return h.onNavigate},get onClose(){return re},get onError(){return h.onError}},c,i,{skipResize:!0,hasCloseButton:!0}),c&&(f=U(c,i)),ce()},re=y=>{var w;d&&((y==null?void 0:y.persistState)!==!1&&H(!1),d=!1,m==null||m(),f==null||f(),l==null||l.remove(),l=null,c=null,m=null,f=null,Ae(),(w=h.onClose)==null||w.call(h))};s.addEventListener("click",()=>{d?re():de()});let tt=()=>{pe(),R(),re({persistState:!1}),s.remove(),v==null||v.close(),v=null},Bt=()=>{H(!1),tt()};return E?(C=!0,de()):et(),{unmount:tt,update:y=>{var j,G,V,me,ue,lt,ct,pt,dt;h={...h,...y};let w=h._apiConfig;if(w||h.brand){let fe=X(h.theme)?((G=(j=h.brand)==null?void 0:j.dark)==null?void 0:G.primary)??(w==null?void 0:w.darkPrimaryColor)??"#a78bfa":((me=(V=h.brand)==null?void 0:V.light)==null?void 0:me.primary)??(w==null?void 0:w.primaryColor)??"#7c3aed";(lt=(ue=h.launcher)==null?void 0:ue.style)!=null&<.backgroundColor||(s.style.setProperty("--perspective-float-bg",fe),s.style.setProperty("--perspective-float-shadow",`0 4px 12px ${fe}66`),s.style.setProperty("--perspective-float-shadow-hover",`0 6px 16px ${fe}80`),s.style.backgroundColor=fe,s.style.boxShadow=`0 4px 12px ${fe}66`)}h=Ht(h,(pt=(ct=h._apiConfig)==null?void 0:ct.embedSettings)==null?void 0:pt.launcher),we(s,h),(dt=h.launcher)!=null&&dt.style&&Object.assign(s.style,h.launcher.style),d||Ae(),et()},destroy:Bt,open:de,close:re,toggle:()=>{d?re():de()},get isOpen(){return d},researchId:r,type:"float",get iframe(){return c},container:s}}var Ze=xe;function Tr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:"fullpage",iframe:null,container:null}}function Pe(e){var f,d,b;let{researchId:r}=e;if(!g())return Tr(r);let t=M(e.host);K(),F();let n=document.createElement("div");n.className=O("perspective-embed-root perspective-fullpage",_(e.theme));let o=P({theme:e.theme,brand:e.brand,appearance:(d=(f=e._apiConfig)==null?void 0:f.embedSettings)==null?void 0:d.appearance});n.appendChild(o);let i=N((b=e._apiConfig)==null?void 0:b.embedSettings),s=B(r,"fullpage",t,e.params,e.brand,e.theme,i);s.style.opacity="0",s.style.transition="opacity 0.3s ease",n.appendChild(s),document.body.appendChild(n);let a={...e},l=null,c=U(s,t),m=()=>{var p;l==null||l(),c(),n.remove(),(p=a.onClose)==null||p.call(a)};return l=$(r,{get onReady(){return()=>{var p;o.style.opacity="0",s.style.opacity="1",setTimeout(()=>o.remove(),300),(p=a.onReady)==null||p.call(a)}},get onSubmit(){return a.onSubmit},get onNavigate(){return a.onNavigate},get onClose(){return m},get onError(){return a.onError}},s,t,{skipResize:!0}),{unmount:m,update:p=>{a={...a,...p}},destroy:m,researchId:r,type:"fullpage",iframe:s,container:n}}var S=new Map,q=new Map,T=new Map,Te=0,le=new Map;function W(e,r,t){return Te!==r||(le.get(e)??0)!==t}function Xe(e,r,t){var c,m;let n=(c=r.embedSettings)==null?void 0:c.autoTrigger;if(!(n!=null&&n.trigger))return;let o=n.trigger==="timeout"?{type:"timeout",delay:n.delay??5e3}:{type:"exit-intent"},i=n.showOnce==="false"?!1:n.showOnce??"session";if(!Ge(e,i))return;(m=T.get(e))==null||m();let s=Te,a=le.get(e)??0,l=je(o,()=>{T.delete(e),!W(e,s,a)&&(Ye(e,i),t())});T.set(e,l)}var Ne=new Map,ke=null,z=vt;function De(e,r,t){e.hasAttribute(x.noStyle)||(Ne.set(e,{themeConfig:r,theme:t==null?void 0:t.theme,brand:t==null?void 0:t.brand}),_t(e,{themeConfig:r,theme:t==null?void 0:t.theme,brand:t==null?void 0:t.brand}))}function _t(e,r){var l,c,m,f;let{themeConfig:t,theme:n,brand:o}=r,i=X(n),s=i?((l=o==null?void 0:o.dark)==null?void 0:l.primary)??t.darkPrimaryColor:((c=o==null?void 0:o.light)==null?void 0:c.primary)??t.primaryColor,a=i?((m=o==null?void 0:o.dark)==null?void 0:m.text)??t.darkTextColor:((f=o==null?void 0:o.light)==null?void 0:f.text)??t.textColor;e.style.backgroundColor=s,e.style.color=a,e.style.padding="10px 20px",e.style.border="none",e.style.borderRadius="8px",e.style.fontWeight="500",e.style.cursor="pointer"}function Ar(){Ne.forEach((e,r)=>{document.contains(r)?_t(r,e):Ne.delete(r)})}var ae=null;function Lr(){ae||!g()||(ke=window.matchMedia("(prefers-color-scheme: dark)"),ae=()=>Ar(),ke.addEventListener("change",ae))}function Mr(){ae&&ke&&(ke.removeEventListener("change",ae),ae=null,ke=null)}function Ce(e){let r=e.getAttribute(x.params);if(!r)return;let t={};for(let n of r.split(",")){let[o,...i]=n.trim().split("=");o&&(t[o.trim()]=i.join("=").trim())}return Object.keys(t).length>0?t:void 0}function Ot(e){if(!e)return;let r={};for(let t of e.split(",")){let[n,...o]=t.trim().split("=");if(n&&o.length>0){let i=o.join("=").trim();if(i){let s=n.trim();(s==="primary"||s==="secondary"||s==="bg"||s==="text")&&(r[s]=i)}}}return Object.keys(r).length>0?r:void 0}function Se(e){let r=Ot(e.getAttribute(x.brand)),t=Ot(e.getAttribute(x.brandDark)),n=e.getAttribute(x.theme),o={};return(r||t)&&(o.brand={},r&&(o.brand.light=r),t&&(o.brand.dark=t)),(n===L.dark||n===L.light||n===L.system)&&(o.theme=n),o}function Ir(e){let r=e.getAttribute(x.launcherIcon),t=e.getAttribute(x.launcherStyle),n=e.getAttribute(x.launcherClass);if(!r&&!t&&!n)return;let o={};if(r&&(r.startsWith("http")||r.startsWith("/")?o.icon={url:r}:(r==="avatar"||r==="default")&&(o.icon=r)),t){let i={};for(let s of t.split(";")){let a=s.indexOf(":");if(a===-1)continue;let l=s.slice(0,a).trim(),c=s.slice(a+1).trim();if(l&&c){let m=l.replace(/-([a-z])/g,(f,d)=>d.toUpperCase());i[m]=c}}Object.keys(i).length>0&&(o.style=i)}return n&&(o.className=n),o}function te(e){let{researchId:r}=e,t=e.type==="chat"?"float":e.type??"widget";S.has(r)&&(S.get(r).unmount(),S.delete(r));let n;switch(t){case"popup":n=Oe(e);break;case"slider":n=_e(e);break;case"float":n=xe(e);break;case"fullpage":n=Pe(e);break;default:throw new Error(`Unknown embed type "${t}". Valid types: popup, slider, float, fullpage (use init()), or widget (use mount()).`)}return S.set(r,n),n}function Je(e,r){let{researchId:t}=r,n=r.type==="chat"?"float":r.type??"widget",o=typeof e=="string"?document.querySelector(e):e;if(!o)throw new Error(`Container not found: ${e}`);S.has(t)&&(S.get(t).unmount(),S.delete(t));let i;if(n==="widget")i=Re(o,r);else return i=te({...r,type:n}),i;return S.set(t,i),i}function Pt(e){var n;let r=S.get(e);r&&(r.destroy(),S.delete(e));let t=q.get(e);t&&(t.cancelled=!0,t.skeleton.remove(),q.delete(e)),(n=T.get(e))==null||n(),T.delete(e),le.set(e,(le.get(e)??0)+1)}function Dt(){Te++,S.forEach(e=>e.unmount()),S.clear(),q.forEach(e=>{e.cancelled=!0,e.skeleton.remove()}),q.clear(),T.forEach(e=>e()),T.clear(),Ne.clear(),Mr(),g()&&document.querySelectorAll("[data-perspective-initialized]").forEach(e=>e.removeAttribute("data-perspective-initialized"))}function Be(){if(!g())return;Lr(),document.querySelectorAll(`[${x.widget}]`).forEach(t=>{let n=t.getAttribute(x.widget);if(n&&!S.has(n)){let o=Ce(t),i=Se(t),s=P({theme:i.theme,brand:i.brand});s.style.position="relative",s.style.minHeight="500px",t.appendChild(s);let a={cancelled:!1,skeleton:s};q.set(n,a),z(n).then(l=>{q.delete(n),s.remove(),!(a.cancelled||!t.isConnected||S.has(n))&&Je(t,{researchId:n,type:"widget",params:o,...i,_apiConfig:l})})}}),document.querySelectorAll(`[${x.fullpage}]`).forEach(t=>{let n=t.getAttribute(x.fullpage);if(n&&!S.has(n)){let o=Ce(t),i=Se(t),s=P({theme:i.theme,brand:i.brand});s.style.position="fixed",s.style.inset="0",s.style.zIndex="2147483647",document.body.appendChild(s);let a={cancelled:!1,skeleton:s};q.set(n,a),z(n).then(l=>{q.delete(n),s.remove(),!(a.cancelled||!t.isConnected||S.has(n))&&te({researchId:n,type:"fullpage",params:o,...i,_apiConfig:l})})}}),document.querySelectorAll(`[${x.popup}]`).forEach(t=>{var b,p;if(t.hasAttribute("data-perspective-initialized"))return;t.setAttribute("data-perspective-initialized","true");let n=t.getAttribute(x.popup);if(!n)return;let o=Ce(t),i=Se(t),s=t.getAttribute(x.autoOpen),a=t.hasAttribute(x.disableClose),l=Ee({researchId:n,type:"popup"}),c,m=()=>te({researchId:n,type:"popup",params:o,disableClose:a,...i,...c&&{_apiConfig:c}}),f=Te,d=le.get(n)??0;if(s){if(l===!0)z(n).then(u=>{W(n,f,d)||(c=u,m())});else if(l!==!1)try{let u=yt(s),v=wt(t.getAttribute(x.showOnce));if(Ge(n,v)){(b=T.get(n))==null||b();let C=z(n);C.then(A=>{W(n,f,d)||(c=A,Xe(n,A,m))});let I=je(u,()=>{T.delete(n),C.then(A=>{var H,E;W(n,f,d)||(c=A,(E=(H=A.embedSettings)==null?void 0:H.autoTrigger)!=null&&E.trigger||(Ye(n,v),m()))})});T.set(n,I)}}catch(u){console.warn("[Perspective]",u.message)}}else z(n).then(v=>{c=v,De(t,v,i),!W(n,f,d)&&(S.has(n)||Xe(n,v,m))}),De(t,ne,i),t.addEventListener("click",v=>{var C;v.preventDefault(),(C=T.get(n))==null||C(),T.delete(n),m()}),l===!0&&((p=T.get(n))==null||p(),T.delete(n),z(n).then(v=>{W(n,f,d)||(c=v,m())}))}),document.querySelectorAll(`[${x.slider}]`).forEach(t=>{var o;if(t.hasAttribute("data-perspective-initialized"))return;t.setAttribute("data-perspective-initialized","true");let n=t.getAttribute(x.slider);if(n){let i=Ce(t),s=Se(t),a=t.hasAttribute(x.disableClose),l=Ee({researchId:n,type:"slider"}),c,m=()=>te({researchId:n,type:"slider",params:i,disableClose:a,...s,...c&&{_apiConfig:c}}),f=Te,d=le.get(n)??0;z(n).then(p=>{c=p,De(t,p,s),!W(n,f,d)&&(S.has(n)||Xe(n,p,m))}),De(t,ne,s),t.addEventListener("click",p=>{var u;p.preventDefault(),(u=T.get(n))==null||u(),T.delete(n),m()}),l===!0&&((o=T.get(n))==null||o(),T.delete(n),z(n).then(p=>{W(n,f,d)||(c=p,m())}))}});let e=`[${x.float}], [${x.chat}]`,r=document.querySelector(e);if(r){let t=r.getAttribute(x.float)||r.getAttribute(x.chat);if(t&&!S.has(t)){let n=Ce(r),o=Se(r),i=Ir(r),s=te({researchId:t,type:"float",params:n,...o,...i&&{launcher:i},_apiConfig:ne});z(t).then(a=>{var c,m,f,d,b;let l=document.querySelector('[data-perspective="float-bubble"]');if(l&&!r.hasAttribute(x.noStyle)&&!((c=i==null?void 0:i.style)!=null&&c.backgroundColor)){let u=X(o.theme)?((f=(m=o.brand)==null?void 0:m.dark)==null?void 0:f.primary)??a.darkPrimaryColor:((b=(d=o.brand)==null?void 0:d.light)==null?void 0:b.primary)??a.primaryColor;l.style.setProperty("--perspective-float-bg",u),l.style.setProperty("--perspective-float-shadow",`0 4px 12px ${u}66`),l.style.setProperty("--perspective-float-shadow-hover",`0 6px 16px ${u}80`),l.style.backgroundColor=u,l.style.boxShadow=`0 4px 12px ${u}66`}if(s.type==="float"&&S.get(t)===s){let p=a.channel??a.allowedChannels??void 0;s.update({channel:p,welcomeMessage:a.welcomeMessage,_apiConfig:a})}})}}}var Nt={configure:Ke,getConfig:Ve,init:te,mount:Je,destroy:Pt,destroyAll:Dt,autoInit:Be,createWidget:Re,openPopup:Oe,openSlider:_e,createFloatBubble:xe,createFullpage:Pe,createChatBubble:Ze};if(g()&&!window.__PERSPECTIVE_SDK_INITIALIZED__){window.__PERSPECTIVE_SDK_INITIALIZED__=!0;let e=document.currentScript;e!=null&&e.parentNode&&e.parentNode.insertBefore(document.createComment(" Powered by Perspective AI \u2014 https://getperspective.ai "),e),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Be,{once:!0}):Be(),window.Perspective=Nt}var Hr=Nt;return zt(Rr);})();
|
|
464
|
+
</svg>`;var He=new WeakMap;function mr(e,r){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:r,iframe:null,container:null}}function ur(e,r){let t=e.querySelector(".perspective-embed-root"),n=e.querySelector("iframe[data-perspective]"),o=!1,i=()=>{if(!o){if(o=!0,n){let s=He.get(n);s&&(s.cleanup(),s.unregister(),He.delete(n))}t==null||t.remove()}};return{unmount:i,update:()=>{},destroy:i,researchId:r,type:"widget",iframe:n,container:e}}function Re(e,r){var y,p,f;let{researchId:t}=r;if(!g()||!e)return mr(t,"widget");if(e.querySelector("iframe[data-perspective]"))return ur(e,t);let n=M(r.host);K(),F();let o=document.createElement("div");o.className=O("perspective-embed-root",_(r.theme)),o.style.cssText="position:relative;width:100%;height:100%;min-height:500px;";let i=P({theme:r.theme,brand:r.brand,appearance:(p=(y=r._apiConfig)==null?void 0:y.embedSettings)==null?void 0:p.appearance});o.appendChild(i);let s=N((f=r._apiConfig)==null?void 0:f.embedSettings),a=B(t,"widget",n,r.params,r.brand,r.theme,s);a.style.width="100%",a.style.height="100%",a.style.minHeight="500px",a.style.opacity="0",a.style.transition="opacity 0.3s ease",o.appendChild(a),e.appendChild(o);let l={...r},c=$(t,{get onReady(){return()=>{var b;i.style.opacity="0",a.style.opacity="1",setTimeout(()=>i.remove(),300),(b=l.onReady)==null||b.call(l)}},get onSubmit(){return l.onSubmit},get onNavigate(){return l.onNavigate},get onClose(){return l.onClose},get onError(){return l.onError}},a,n,{skipResize:!0}),m=U(a,n);He.set(a,{cleanup:c,unregister:m,wrapper:o});let d=!1,u=()=>{d||(d=!0,c(),m(),He.delete(a),o.remove())};return{unmount:u,update:b=>{l={...l,...b}},destroy:u,researchId:t,type:"widget",iframe:a,container:e}}function It({researchId:e,type:r,host:t}){return`${Y.embedState}:${M(t)}:${r}:${e}`}function Ee(e){if(!g())return null;try{let r=sessionStorage.getItem(It(e));if(!r)return null;let t=JSON.parse(r);return typeof t.open=="boolean"?t.open:null}catch{return null}}function ie(e){if(g())try{let r={v:1,open:e.open};sessionStorage.setItem(It(e),JSON.stringify(r))}catch{}}function fr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:"popup",iframe:null,container:null}}function Oe(e){var I,A,H;let{researchId:r}=e;if(!g())return fr(r);let t=M(e.host);K(),F();let n=document.createElement("div");n.className=O("perspective-overlay perspective-embed-root",_(e.theme));let o=document.createElement("div");o.className="perspective-modal";let i=document.createElement("button");i.className="perspective-close",i.innerHTML=ee,i.setAttribute("aria-label","Close"),e.disableClose&&(i.style.display="none");let s=P({theme:e.theme,brand:e.brand,appearance:(A=(I=e._apiConfig)==null?void 0:I.embedSettings)==null?void 0:A.appearance});s.style.borderRadius="16px";let a=N((H=e._apiConfig)==null?void 0:H.embedSettings),l=B(r,"popup",t,e.params,e.brand,e.theme,a);l.style.opacity="0",l.style.transition="opacity 0.3s ease",o.appendChild(i),o.appendChild(s),o.appendChild(l),n.appendChild(o),document.body.appendChild(n);let c={...e},m=!0,d=null,u=E=>{ie({researchId:r,type:"popup",host:e.host,open:E})},y=U(l,t);u(!0);let p=()=>{var E;m&&(m=!1,d==null||d(),y(),n.remove(),document.removeEventListener("keydown",S),(E=c.onClose)==null||E.call(c))},f=()=>{u(!1),p()},b=()=>{p()};d=$(r,{get onReady(){return()=>{var E;s.style.opacity="0",l.style.opacity="1",setTimeout(()=>s.remove(),300),(E=c.onReady)==null||E.call(c)}},get onSubmit(){return c.onSubmit},get onNavigate(){return c.onNavigate},get onClose(){return f},get onError(){return c.onError}},l,t,{skipResize:!0,hasCloseButton:!e.disableClose});let S=E=>{E.key==="Escape"&&f()};return e.disableClose||(i.addEventListener("click",f),n.addEventListener("click",E=>{E.target===n&&f()}),document.addEventListener("keydown",S)),{unmount:b,update:E=>{c={...c,...E}},destroy:f,researchId:r,type:"popup",iframe:l,container:n}}function hr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:"slider",iframe:null,container:null}}function _e(e){var I,A,H;let{researchId:r}=e;if(!g())return hr(r);let t=M(e.host);K(),F();let n=document.createElement("div");n.className=O("perspective-slider-backdrop perspective-embed-root",_(e.theme));let o=document.createElement("div");o.className=O("perspective-slider perspective-embed-root",_(e.theme));let i=document.createElement("button");i.className="perspective-close",i.innerHTML=ee,i.setAttribute("aria-label","Close"),e.disableClose&&(i.style.display="none");let s=P({theme:e.theme,brand:e.brand,appearance:(A=(I=e._apiConfig)==null?void 0:I.embedSettings)==null?void 0:A.appearance}),a=N((H=e._apiConfig)==null?void 0:H.embedSettings),l=B(r,"slider",t,e.params,e.brand,e.theme,a);l.style.opacity="0",l.style.transition="opacity 0.3s ease",o.appendChild(i),o.appendChild(s),o.appendChild(l),document.body.appendChild(n),document.body.appendChild(o);let c={...e},m=!0,d=null,u=E=>{ie({researchId:r,type:"slider",host:e.host,open:E})},y=U(l,t);u(!0);let p=()=>{var E;m&&(m=!1,d==null||d(),y(),o.remove(),n.remove(),document.removeEventListener("keydown",S),(E=c.onClose)==null||E.call(c))},f=()=>{u(!1),p()},b=()=>{p()};d=$(r,{get onReady(){return()=>{var E;s.style.opacity="0",l.style.opacity="1",setTimeout(()=>s.remove(),300),(E=c.onReady)==null||E.call(c)}},get onSubmit(){return c.onSubmit},get onNavigate(){return c.onNavigate},get onClose(){return f},get onError(){return c.onError}},l,t,{skipResize:!0,hasCloseButton:!e.disableClose});let S=E=>{E.key==="Escape"&&f()};return e.disableClose||(i.addEventListener("click",f),n.addEventListener("click",f),document.addEventListener("keydown",S)),{unmount:b,update:E=>{c={...c,...E}},destroy:f,researchId:r,type:"slider",iframe:l,container:o}}function Ht(e,r){if(!r)return e;let t=e.launcher??{};return{...e,launcher:{...t,...r,style:{...t.style,...r.style}}}}var gr=2e3,br=3e3,vr=40,yr="Have a question? I'm here to help.";function Er(e){let r=Array.isArray(e)?e:e?[e]:[],t=r.includes("VOICE"),n=r.includes("TEXT");return t&&n?"both":n?"text":"voice"}function wr(e){var r,t;return e.channel??((r=e._apiConfig)==null?void 0:r.allowedChannels)??((t=e._apiConfig)==null?void 0:t.channel)??void 0}function xr(e){var n;let r=e.welcomeMessage??((n=e._apiConfig)==null?void 0:n.welcomeMessage),t=typeof r=="string"?r.trim():"";return t.length>0?t:yr}function Cr(e){return Er(wr(e))==="text"?Mt:Lt}function Rt(e,r){let t=document.createElement("img");return t.src=e,t.alt="",t.style.width="100%",t.style.height="100%",t.style.objectFit="cover",t.style.borderRadius="inherit",t.onerror=()=>{let n=t.parentElement;n&&(t.remove(),n.innerHTML=r)},t}function we(e,r){var o,i;let t=((o=r.launcher)==null?void 0:o.icon)??"default",n=Cr(r);if(t==="default"){e.innerHTML=n;return}if(t==="avatar"){let s=(i=r._apiConfig)==null?void 0:i.avatarUrl;s?(e.innerHTML="",e.appendChild(Rt(s,n))):e.innerHTML=n;return}if(typeof t=="object"&&t!==null){if("url"in t){e.innerHTML="",e.appendChild(Rt(t.url,n));return}if("svg"in t){e.innerHTML=t.svg;return}}e.innerHTML=n}function Sr(e){let r=e.currentTime,t=e.createOscillator(),n=e.createGain();t.type="sine",t.frequency.setValueAtTime(880,r),t.frequency.setValueAtTime(1175,r+.1),n.gain.setValueAtTime(.15,r),n.gain.linearRampToValueAtTime(.18,r+.1),n.gain.exponentialRampToValueAtTime(.001,r+.6),t.connect(n).connect(e.destination),t.start(r),t.stop(r+.65);let o=e.createOscillator(),i=e.createGain();o.type="sine",o.frequency.setValueAtTime(1175,r+.15),o.frequency.setValueAtTime(1400,r+.25),i.gain.setValueAtTime(0,r),i.gain.setValueAtTime(.12,r+.15),i.gain.exponentialRampToValueAtTime(.001,r+.55),o.connect(i).connect(e.destination),o.start(r+.15),o.stop(r+.6)}function kr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},open:()=>{},close:()=>{},toggle:()=>{},isOpen:!1,researchId:e,type:"float",iframe:null,container:null}}function xe(e){var rt,nt,ot,st,it,at;let{researchId:r,_apiConfig:t,theme:n,brand:o}=e;if(!g())return kr(r);let i=M(e.host);K(),F();let s=document.createElement("button");if(s.className=O("perspective-float-bubble perspective-embed-root",_(e.theme)),we(s,e),s.setAttribute("aria-label","Open chat"),s.setAttribute("data-perspective","float-bubble"),t||o){let w=X(n)?((rt=o==null?void 0:o.dark)==null?void 0:rt.primary)??(t==null?void 0:t.darkPrimaryColor)??"#a78bfa":((nt=o==null?void 0:o.light)==null?void 0:nt.primary)??(t==null?void 0:t.primaryColor)??"#7c3aed";s.style.setProperty("--perspective-float-bg",w),s.style.setProperty("--perspective-float-shadow",`0 4px 12px ${w}66`),s.style.setProperty("--perspective-float-shadow-hover",`0 6px 16px ${w}80`),s.style.backgroundColor=w,s.style.boxShadow=`0 4px 12px ${w}66`}let a=Ht(e,(ot=t==null?void 0:t.embedSettings)==null?void 0:ot.launcher);if(a!==e&&we(s,a),(st=a.launcher)!=null&&st.style&&Object.assign(s.style,a.launcher.style),(it=a.launcher)!=null&&it.className)for(let v of a.launcher.className.split(/\s+/).filter(Boolean))s.classList.add(v);document.body.appendChild(s),((at=e.launcher)==null?void 0:at.icon)==="avatar"&&!(t!=null&&t.avatarUrl)&&fetch(`${i}/api/v1/embed/config/${r}`).then(v=>v.ok?v.json():null).then(v=>{v!=null&&v.avatarUrl&&(h={...h,_apiConfig:{...h._apiConfig,...v}},u||we(s,h))}).catch(()=>{});let l=null,c=null,m=null,d=null,u=!1,y=null,p=null,f=null,b=null,S=!1,I=!1,A=[],H=v=>{ie({researchId:r,type:"float",host:e.host,open:v})},E=Ee({researchId:r,type:"float",host:e.host})===!0,h={...a},Ae=()=>{we(s,h),s.setAttribute("aria-label","Open chat"),s.classList.remove("perspective-float-bubble-open")},ce=()=>{s.innerHTML=ee,s.setAttribute("aria-label","Close chat"),s.classList.add("perspective-float-bubble-open")},pe=()=>{for(let v of A)window.clearTimeout(v);A=[],p!==null&&(window.clearInterval(p),p=null)},$e=()=>{f==null||f.remove(),f=null},R=()=>{p!==null&&(window.clearInterval(p),p=null),y==null||y.remove(),y=null,$e()},Q=()=>{f||u||(f=document.createElement("span"),f.className="perspective-float-notification-dot",s.appendChild(f))},Le=()=>{try{let v=window.AudioContext||window.webkitAudioContext;if(!v)return;b||(b=new v),b.state==="suspended"&&b.resume(),Sr(b)}catch{}},Me=v=>{if(R(),u)return;let w=document.createElement("div");w.className=O("perspective-float-teaser perspective-embed-root",_(h.theme));let j=document.createElement("div");j.className="perspective-float-teaser-message";let G=document.createElement("span");j.appendChild(G),w.appendChild(j),w.addEventListener("click",()=>de()),document.body.appendChild(w),y=w,Q();let V=0;p=window.setInterval(()=>{V+=1,G.textContent=v.slice(0,V),V>=v.length&&p!==null&&(window.clearInterval(p),p=null)},vr)},et=()=>{if(S||I||u)return;S=!0;let v=window.setTimeout(()=>{u||I||Le()},gr),w=window.setTimeout(()=>{u||I||Me(xr(h))},br);A.push(v,w)},de=()=>{var G,V,me;if(u)return;u=!0,H(!0),pe(),R(),l=document.createElement("div"),l.className=O("perspective-float-window perspective-embed-root",_(h.theme));let v=document.createElement("button");v.className="perspective-close",v.innerHTML=ee,v.setAttribute("aria-label","Close chat"),v.addEventListener("click",()=>re());let w=P({theme:h.theme,brand:h.brand,appearance:(V=(G=h._apiConfig)==null?void 0:G.embedSettings)==null?void 0:V.appearance});w.style.borderRadius="16px";let j=N((me=h._apiConfig)==null?void 0:me.embedSettings);c=B(r,"float",i,h.params,h.brand,h.theme,j),c.style.opacity="0",c.style.transition="opacity 0.3s ease",l.appendChild(v),l.appendChild(w),l.appendChild(c),document.body.appendChild(l),m=$(r,{get onReady(){return()=>{var ue;w.style.opacity="0",c.style.opacity="1",setTimeout(()=>w.remove(),300),(ue=h.onReady)==null||ue.call(h)}},get onSubmit(){return h.onSubmit},get onNavigate(){return h.onNavigate},get onClose(){return re},get onError(){return h.onError}},c,i,{skipResize:!0,hasCloseButton:!0}),c&&(d=U(c,i)),ce()},re=v=>{var w;u&&((v==null?void 0:v.persistState)!==!1&&H(!1),u=!1,m==null||m(),d==null||d(),l==null||l.remove(),l=null,c=null,m=null,d=null,Ae(),(w=h.onClose)==null||w.call(h))};s.addEventListener("click",()=>{u?re():de()});let tt=()=>{pe(),R(),re({persistState:!1}),s.remove(),b==null||b.close(),b=null},Bt=()=>{H(!1),tt()};return E?(S=!0,de()):et(),{unmount:tt,update:v=>{var j,G,V,me,ue,lt,ct,pt,dt;h={...h,...v};let w=h._apiConfig;if(w||h.brand){let fe=X(h.theme)?((G=(j=h.brand)==null?void 0:j.dark)==null?void 0:G.primary)??(w==null?void 0:w.darkPrimaryColor)??"#a78bfa":((me=(V=h.brand)==null?void 0:V.light)==null?void 0:me.primary)??(w==null?void 0:w.primaryColor)??"#7c3aed";(lt=(ue=h.launcher)==null?void 0:ue.style)!=null&<.backgroundColor||(s.style.setProperty("--perspective-float-bg",fe),s.style.setProperty("--perspective-float-shadow",`0 4px 12px ${fe}66`),s.style.setProperty("--perspective-float-shadow-hover",`0 6px 16px ${fe}80`),s.style.backgroundColor=fe,s.style.boxShadow=`0 4px 12px ${fe}66`)}h=Ht(h,(pt=(ct=h._apiConfig)==null?void 0:ct.embedSettings)==null?void 0:pt.launcher),we(s,h),(dt=h.launcher)!=null&&dt.style&&Object.assign(s.style,h.launcher.style),u||Ae(),et()},destroy:Bt,open:de,close:re,toggle:()=>{u?re():de()},get isOpen(){return u},researchId:r,type:"float",get iframe(){return c},container:s}}var Ze=xe;function Tr(e){return{unmount:()=>{},update:()=>{},destroy:()=>{},researchId:e,type:"fullpage",iframe:null,container:null}}function Pe(e){var d,u,y;let{researchId:r}=e;if(!g())return Tr(r);let t=M(e.host);K(),F();let n=document.createElement("div");n.className=O("perspective-embed-root perspective-fullpage",_(e.theme));let o=P({theme:e.theme,brand:e.brand,appearance:(u=(d=e._apiConfig)==null?void 0:d.embedSettings)==null?void 0:u.appearance});n.appendChild(o);let i=N((y=e._apiConfig)==null?void 0:y.embedSettings),s=B(r,"fullpage",t,e.params,e.brand,e.theme,i);s.style.opacity="0",s.style.transition="opacity 0.3s ease",n.appendChild(s),document.body.appendChild(n);let a={...e},l=null,c=U(s,t),m=()=>{var p;l==null||l(),c(),n.remove(),(p=a.onClose)==null||p.call(a)};return l=$(r,{get onReady(){return()=>{var p;o.style.opacity="0",s.style.opacity="1",setTimeout(()=>o.remove(),300),(p=a.onReady)==null||p.call(a)}},get onSubmit(){return a.onSubmit},get onNavigate(){return a.onNavigate},get onClose(){return m},get onError(){return a.onError}},s,t,{skipResize:!0}),{unmount:m,update:p=>{a={...a,...p}},destroy:m,researchId:r,type:"fullpage",iframe:s,container:n}}var C=new Map,q=new Map,T=new Map,Te=0,le=new Map;function W(e,r,t){return Te!==r||(le.get(e)??0)!==t}function Xe(e,r,t){var c,m;let n=(c=r.embedSettings)==null?void 0:c.autoTrigger;if(!(n!=null&&n.trigger))return;let o=n.trigger==="timeout"?{type:"timeout",delay:n.delay??5e3}:{type:"exit-intent"},i=n.showOnce==="false"?!1:n.showOnce??"session";if(!Ge(e,i))return;(m=T.get(e))==null||m();let s=Te,a=le.get(e)??0,l=je(o,()=>{T.delete(e),!W(e,s,a)&&(Ye(e,i),t())});T.set(e,l)}var Ne=new Map,ke=null,z=vt;function De(e,r,t){e.hasAttribute(x.noStyle)||(Ne.set(e,{themeConfig:r,theme:t==null?void 0:t.theme,brand:t==null?void 0:t.brand}),_t(e,{themeConfig:r,theme:t==null?void 0:t.theme,brand:t==null?void 0:t.brand}))}function _t(e,r){var l,c,m,d;let{themeConfig:t,theme:n,brand:o}=r,i=X(n),s=i?((l=o==null?void 0:o.dark)==null?void 0:l.primary)??t.darkPrimaryColor:((c=o==null?void 0:o.light)==null?void 0:c.primary)??t.primaryColor,a=i?((m=o==null?void 0:o.dark)==null?void 0:m.text)??t.darkTextColor:((d=o==null?void 0:o.light)==null?void 0:d.text)??t.textColor;e.style.backgroundColor=s,e.style.color=a,e.style.padding="10px 20px",e.style.border="none",e.style.borderRadius="8px",e.style.fontWeight="500",e.style.cursor="pointer"}function Ar(){Ne.forEach((e,r)=>{document.contains(r)?_t(r,e):Ne.delete(r)})}var ae=null;function Lr(){ae||!g()||(ke=window.matchMedia("(prefers-color-scheme: dark)"),ae=()=>Ar(),ke.addEventListener("change",ae))}function Mr(){ae&&ke&&(ke.removeEventListener("change",ae),ae=null,ke=null)}function Ce(e){let r=e.getAttribute(x.params);if(!r)return;let t={};for(let n of r.split(",")){let[o,...i]=n.trim().split("=");o&&(t[o.trim()]=i.join("=").trim())}return Object.keys(t).length>0?t:void 0}function Ot(e){if(!e)return;let r={};for(let t of e.split(",")){let[n,...o]=t.trim().split("=");if(n&&o.length>0){let i=o.join("=").trim();if(i){let s=n.trim();(s==="primary"||s==="secondary"||s==="bg"||s==="text")&&(r[s]=i)}}}return Object.keys(r).length>0?r:void 0}function Se(e){let r=Ot(e.getAttribute(x.brand)),t=Ot(e.getAttribute(x.brandDark)),n=e.getAttribute(x.theme),o={};return(r||t)&&(o.brand={},r&&(o.brand.light=r),t&&(o.brand.dark=t)),(n===L.dark||n===L.light||n===L.system)&&(o.theme=n),o}function Ir(e){let r=e.getAttribute(x.launcherIcon),t=e.getAttribute(x.launcherStyle),n=e.getAttribute(x.launcherClass);if(!r&&!t&&!n)return;let o={};if(r&&(r.startsWith("http")||r.startsWith("/")?o.icon={url:r}:(r==="avatar"||r==="default")&&(o.icon=r)),t){let i={};for(let s of t.split(";")){let a=s.indexOf(":");if(a===-1)continue;let l=s.slice(0,a).trim(),c=s.slice(a+1).trim();if(l&&c){let m=l.replace(/-([a-z])/g,(d,u)=>u.toUpperCase());i[m]=c}}Object.keys(i).length>0&&(o.style=i)}return n&&(o.className=n),o}function te(e){let{researchId:r}=e,t=e.type==="chat"?"float":e.type??"widget";C.has(r)&&(C.get(r).unmount(),C.delete(r));let n;switch(t){case"popup":n=Oe(e);break;case"slider":n=_e(e);break;case"float":n=xe(e);break;case"fullpage":n=Pe(e);break;default:throw new Error(`Unknown embed type "${t}". Valid types: popup, slider, float, fullpage (use init()), or widget (use mount()).`)}return C.set(r,n),n}function Je(e,r){let{researchId:t}=r,n=r.type==="chat"?"float":r.type??"widget",o=typeof e=="string"?document.querySelector(e):e;if(!o)throw new Error(`Container not found: ${e}`);C.has(t)&&(C.get(t).unmount(),C.delete(t));let i;if(n==="widget")i=Re(o,r);else return i=te({...r,type:n}),i;return C.set(t,i),i}function Pt(e){var n;let r=C.get(e);r&&(r.destroy(),C.delete(e));let t=q.get(e);t&&(t.cancelled=!0,t.skeleton.remove(),q.delete(e)),(n=T.get(e))==null||n(),T.delete(e),le.set(e,(le.get(e)??0)+1)}function Dt(){Te++,C.forEach(e=>e.unmount()),C.clear(),q.forEach(e=>{e.cancelled=!0,e.skeleton.remove()}),q.clear(),T.forEach(e=>e()),T.clear(),Ne.clear(),Mr(),g()&&document.querySelectorAll("[data-perspective-initialized]").forEach(e=>e.removeAttribute("data-perspective-initialized"))}function Be(){if(!g())return;Lr(),document.querySelectorAll(`[${x.widget}]`).forEach(t=>{let n=t.getAttribute(x.widget);if(n&&!C.has(n)){let o=Ce(t),i=Se(t),s=P({theme:i.theme,brand:i.brand});s.style.position="relative",s.style.minHeight="500px",t.appendChild(s);let a={cancelled:!1,skeleton:s};q.set(n,a),z(n).then(l=>{q.delete(n),s.remove(),!(a.cancelled||!t.isConnected||C.has(n))&&Je(t,{researchId:n,type:"widget",params:o,...i,_apiConfig:l})})}}),document.querySelectorAll(`[${x.fullpage}]`).forEach(t=>{let n=t.getAttribute(x.fullpage);if(n&&!C.has(n)){let o=Ce(t),i=Se(t),s=P({theme:i.theme,brand:i.brand});s.style.position="fixed",s.style.inset="0",s.style.zIndex="2147483647",document.body.appendChild(s);let a={cancelled:!1,skeleton:s};q.set(n,a),z(n).then(l=>{q.delete(n),s.remove(),!(a.cancelled||!t.isConnected||C.has(n))&&te({researchId:n,type:"fullpage",params:o,...i,_apiConfig:l})})}}),document.querySelectorAll(`[${x.popup}]`).forEach(t=>{var y,p;if(t.hasAttribute("data-perspective-initialized"))return;t.setAttribute("data-perspective-initialized","true");let n=t.getAttribute(x.popup);if(!n)return;let o=Ce(t),i=Se(t),s=t.getAttribute(x.autoOpen),a=t.hasAttribute(x.disableClose),l=Ee({researchId:n,type:"popup"}),c,m=()=>te({researchId:n,type:"popup",params:o,disableClose:a,...i,...c&&{_apiConfig:c}}),d=Te,u=le.get(n)??0;if(s){if(l===!0)z(n).then(f=>{W(n,d,u)||(c=f,m())});else if(l!==!1)try{let f=yt(s),b=wt(t.getAttribute(x.showOnce));if(Ge(n,b)){(y=T.get(n))==null||y();let S=z(n);S.then(A=>{W(n,d,u)||(c=A,Xe(n,A,m))});let I=je(f,()=>{T.delete(n),S.then(A=>{var H,E;W(n,d,u)||(c=A,(E=(H=A.embedSettings)==null?void 0:H.autoTrigger)!=null&&E.trigger||(Ye(n,b),m()))})});T.set(n,I)}}catch(f){console.warn("[Perspective]",f.message)}}else z(n).then(b=>{c=b,De(t,b,i),!W(n,d,u)&&(C.has(n)||Xe(n,b,m))}),De(t,ne,i),t.addEventListener("click",b=>{var S;b.preventDefault(),(S=T.get(n))==null||S(),T.delete(n),m()}),l===!0&&((p=T.get(n))==null||p(),T.delete(n),z(n).then(b=>{W(n,d,u)||(c=b,m())}))}),document.querySelectorAll(`[${x.slider}]`).forEach(t=>{var o;if(t.hasAttribute("data-perspective-initialized"))return;t.setAttribute("data-perspective-initialized","true");let n=t.getAttribute(x.slider);if(n){let i=Ce(t),s=Se(t),a=t.hasAttribute(x.disableClose),l=Ee({researchId:n,type:"slider"}),c,m=()=>te({researchId:n,type:"slider",params:i,disableClose:a,...s,...c&&{_apiConfig:c}}),d=Te,u=le.get(n)??0;z(n).then(p=>{c=p,De(t,p,s),!W(n,d,u)&&(C.has(n)||Xe(n,p,m))}),De(t,ne,s),t.addEventListener("click",p=>{var f;p.preventDefault(),(f=T.get(n))==null||f(),T.delete(n),m()}),l===!0&&((o=T.get(n))==null||o(),T.delete(n),z(n).then(p=>{W(n,d,u)||(c=p,m())}))}});let e=`[${x.float}], [${x.chat}]`,r=document.querySelector(e);if(r){let t=r.getAttribute(x.float)||r.getAttribute(x.chat);if(t&&!C.has(t)){let n=Ce(r),o=Se(r),i=Ir(r),s=te({researchId:t,type:"float",params:n,...o,...i&&{launcher:i},_apiConfig:ne});z(t).then(a=>{var c,m,d,u,y;let l=document.querySelector('[data-perspective="float-bubble"]');if(l&&!r.hasAttribute(x.noStyle)&&!((c=i==null?void 0:i.style)!=null&&c.backgroundColor)){let f=X(o.theme)?((d=(m=o.brand)==null?void 0:m.dark)==null?void 0:d.primary)??a.darkPrimaryColor:((y=(u=o.brand)==null?void 0:u.light)==null?void 0:y.primary)??a.primaryColor;l.style.setProperty("--perspective-float-bg",f),l.style.setProperty("--perspective-float-shadow",`0 4px 12px ${f}66`),l.style.setProperty("--perspective-float-shadow-hover",`0 6px 16px ${f}80`),l.style.backgroundColor=f,l.style.boxShadow=`0 4px 12px ${f}66`}if(s.type==="float"&&C.get(t)===s){let p=a.channel??a.allowedChannels??void 0;s.update({channel:p,welcomeMessage:a.welcomeMessage,_apiConfig:a})}})}}}var Nt={configure:Ke,getConfig:Ve,init:te,mount:Je,destroy:Pt,destroyAll:Dt,autoInit:Be,createWidget:Re,openPopup:Oe,openSlider:_e,createFloatBubble:xe,createFullpage:Pe,createChatBubble:Ze};if(g()&&!window.__PERSPECTIVE_SDK_INITIALIZED__){window.__PERSPECTIVE_SDK_INITIALIZED__=!0;let e=document.currentScript;e!=null&&e.parentNode&&e.parentNode.insertBefore(document.createComment(" Powered by Perspective AI \u2014 https://getperspective.ai "),e),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Be,{once:!0}):Be(),window.Perspective=Nt}var Hr=Nt;return zt(Rr);})();
|
|
465
465
|
//# sourceMappingURL=perspective.global.js.map
|