@eka-care/medassist-widget-embed 0.2.118-dev.0 → 0.2.119-dev.0
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/eka-agents.html +4 -4
- package/dist/iframe.js +1 -1
- package/dist/index.d.ts +28 -6
- package/dist/index.js +158 -52
- package/package.json +1 -1
package/dist/eka-agents.html
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
CORS mode — the browser would download it twice. -->
|
|
19
19
|
<link
|
|
20
20
|
rel="modulepreload"
|
|
21
|
-
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.
|
|
21
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.141-dev.0/dist/medassist-widget.js"
|
|
22
22
|
fetchpriority="high"
|
|
23
23
|
crossorigin
|
|
24
24
|
/>
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
<link
|
|
28
28
|
rel="preload"
|
|
29
29
|
as="style"
|
|
30
|
-
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.
|
|
30
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.141-dev.0/dist/medassist-widget.css"
|
|
31
31
|
onload="this.rel='stylesheet'"
|
|
32
32
|
crossorigin
|
|
33
33
|
/>
|
|
34
34
|
<noscript>
|
|
35
35
|
<link
|
|
36
36
|
rel="stylesheet"
|
|
37
|
-
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.
|
|
37
|
+
href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.141-dev.0/dist/medassist-widget.css"
|
|
38
38
|
/>
|
|
39
39
|
</noscript>
|
|
40
40
|
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
window.renderMedAssist would never be set. -->
|
|
150
150
|
<script
|
|
151
151
|
type="module"
|
|
152
|
-
src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.
|
|
152
|
+
src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.141-dev.0/dist/medassist-widget.js"
|
|
153
153
|
onload="init()"
|
|
154
154
|
fetchpriority="high"
|
|
155
155
|
crossorigin
|
package/dist/iframe.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(function(){const $=()=>{if(typeof document=="undefined")return null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},C=e=>{if(e==="production"||e==="development"||e==="staging")return e};function z(e){var t;if(!e)return;const r=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background&&{background:e.background},...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...r&&{textColor:r},...e.mode&&{mode:e.mode},...e.header_tinted!==void 0&&{headerTinted:e.header_tinted},...e.title_img&&{titleImg:e.title_img},...e.tagline&&{tagline:e.tagline},...e.consent_content&&{consentContent:e.consent_content},...((t=e.tips)===null||t===void 0?void 0:t.length)&&{tips:e.tips},...e.feature!==void 0&&{feature:e.feature}}}function S(e){if(!(!e||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=e,document.head.appendChild(t)}catch{const t=new Image;t.src=e}}async function F(e,t,r){var n;try{return await h(),await((n=window.fetchAgentConfig)===null||n===void 0?void 0:n.call(window,{agentId:t,serverUrl:e,environment:r,channel:"web"}))}catch{return}}const U="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.
|
|
1
|
+
"use strict";(function(){const $=()=>{if(typeof document=="undefined")return null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},C=e=>{if(e==="production"||e==="development"||e==="staging")return e};function z(e){var t;if(!e)return;const r=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background&&{background:e.background},...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...r&&{textColor:r},...e.mode&&{mode:e.mode},...e.header_tinted!==void 0&&{headerTinted:e.header_tinted},...e.title_img&&{titleImg:e.title_img},...e.tagline&&{tagline:e.tagline},...e.consent_content&&{consentContent:e.consent_content},...((t=e.tips)===null||t===void 0?void 0:t.length)&&{tips:e.tips},...e.feature!==void 0&&{feature:e.feature}}}function S(e){if(!(!e||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=e,document.head.appendChild(t)}catch{const t=new Image;t.src=e}}async function F(e,t,r){var n;try{return await h(),await((n=window.fetchAgentConfig)===null||n===void 0?void 0:n.call(window,{agentId:t,serverUrl:e,environment:r,channel:"web"}))}catch{return}}const U="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.141-dev.0/dist/",s=$(),b=(()=>{if(!s)return"";try{return new URL(".",s.src||window.location.href).href}catch{return""}})(),u=(()=>{if(!s)return U;const e=s.dataset.widgetAssets;if(e==="local")return`${b}src/`;if(e&&e.length>0)try{return new URL(e,b).href}catch{return e.endsWith("/")?e:`${e}/`}return U})(),a=`${u}medassist-widget.js`,g=`${u}medassist-widget.css`;let f=null,m=null;const i=new URLSearchParams(typeof window!="undefined"?window.location.search:""),A=i.get("agentId"),w=i.get("baseUrl")||"https://matrix.eka.care/reloaded";if(typeof document!="undefined"&&document.head){try{const e=new URL(u).origin,t=new URL(w).origin,r=document.createElement("link");if(r.rel="preconnect",r.href=e,r.crossOrigin="anonymous",document.head.appendChild(r),e!==t){const c=document.createElement("link");c.rel="preconnect",c.href=t,c.crossOrigin="anonymous",document.head.appendChild(c)}const n=document.createElement("link");n.rel="modulepreload",n.href=a,document.head.appendChild(n);const d=document.createElement("link");d.rel="preload",d.as="style",d.href=g,document.head.appendChild(d)}catch{}M(),h()}const L=A&&w?F(w,A,C(i.get("environment"))):Promise.resolve(void 0);if(typeof document!="undefined"&&document.head){const e=i.get("theme");if(e)try{const t=JSON.parse(e);t.backgroundImage&&S(t.backgroundImage)}catch{}L.then(t=>{var r;const n=(r=t==null?void 0:t.theme)===null||r===void 0?void 0:r.background_img;n&&S(n)})}const I=async()=>{var e,t,r,n,d,c,p;const P=i.get("agentId");if(!P){console.error("Agent ID is required in URL parameters");return}let v=i.get("title")||"Medi Clinic",y=i.get("iconUrl")||void 0;const x=i.get("context"),G=i.get("baseUrl")||"https://matrix.eka.care/reloaded",O=i.get("auth-token")||void 0;let k=i.get("resize")==="true"?!0:void 0;const J=(e=C(i.get("environment")))!==null&&e!==void 0?e:"production",_=i.get("connectivity"),N=_==="http_stream"||_==="socket"?_:void 0,E=i.get("theme")?(()=>{try{return JSON.parse(i.get("theme")||"{}")}catch{return}})():void 0,q=document.getElementById("root")||document.body;try{const[,,o]=await Promise.all([M(),h(),L]);if(!(window!=null&&window.renderMedAssist)||typeof(window==null?void 0:window.renderMedAssist)!="function")throw new Error("renderMedAssist is not available on window");let l,W,R,B,D=!1;o&&(v=(t=o==null?void 0:o.name)!==null&&t!==void 0?t:v,y=(n=(r=o==null?void 0:o.theme)===null||r===void 0?void 0:r.icon_img)!==null&&n!==void 0?n:y,l=z((d=o==null?void 0:o.theme)!==null&&d!==void 0?d:void 0),W=o==null?void 0:o.allowed,R=o==null?void 0:o.connectivity,B=o==null?void 0:o.initial_message,D=(p=(c=o==null?void 0:o.theme)===null||c===void 0?void 0:c.hide_watermark)!==null&&p!==void 0?p:!1,k=k||(o==null?void 0:o.resize)||void 0);const H={title:v,iconUrl:y,environment:J,connectionType:R||N||"socket",onClose:()=>{window.parent!==window&&window.parent.postMessage({type:"WIDGET_CLOSE"},"*")},context:x?JSON.parse(x):void 0,baseUrl:G,displayMode:"full",allowed:W,showCloseButton:!1,resize:k,initialMessage:B,hideWatermark:D,...O&&{authToken:O},theme:{...l!=null?l:{},...E!=null?E:{}}};window.renderMedAssist(q,P,H)}catch(o){throw console.error("Failed to initialize MedAssist widget",o),o}};async function M(){document.querySelector("link[data-medassist-style='true']")||(m||(m=new Promise((t,r)=>{const n=document.createElement("link");n.rel="stylesheet",n.href=g,n.setAttribute("data-medassist-style","true"),n.onload=()=>{t("")},n.onerror=()=>{r(new Error(`Failed to load ${g}`))},document.head.appendChild(n)})),await m)}function h(){return f||(f=new Promise((e,t)=>{const r=document.querySelector(`script[src="${a}"]`);if(r){if(r.dataset.loaded==="true"){e();return}r.addEventListener("load",()=>e()),r.addEventListener("error",d=>t(d.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=a,n.type="module",n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",e()},n.onerror=d=>{if(d instanceof ErrorEvent&&d.error){t(d.error);return}t(new Error(`Failed to load ${a}`))},document.head.appendChild(n)})),f}if(typeof document!="undefined")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",I);else try{I()}catch(e){console.error("Failed to initialize MedAssist widget",e)}})();
|
package/dist/index.d.ts
CHANGED
|
@@ -278,6 +278,10 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
278
278
|
private reactRoot;
|
|
279
279
|
private agentConfigPromise;
|
|
280
280
|
private loading;
|
|
281
|
+
/** True once the widget has been opened from this launcher: closing it then leaves a chat in progress. */
|
|
282
|
+
private chatStarted;
|
|
283
|
+
private placeholderTimer;
|
|
284
|
+
private placeholderIndex;
|
|
281
285
|
/**
|
|
282
286
|
* Launcher visual state:
|
|
283
287
|
* - "idle" → icon, clickable
|
|
@@ -416,15 +420,33 @@ declare class MedAssistWidgetLoader extends HTMLElement {
|
|
|
416
420
|
initializeFullMode(): void;
|
|
417
421
|
/** `firstUserMessage`: text sent from the chatbox launcher; the widget sends it once connected. */
|
|
418
422
|
loadAndRender(firstUserMessage?: string): Promise<void>;
|
|
423
|
+
/** Opening animation: `open-animation` attribute / init({ openAnimation }): rise (default) | unfold | pop | curtain | fade | none. */
|
|
424
|
+
private getOpenAnimation;
|
|
419
425
|
/**
|
|
420
|
-
* Chatbox → widget opening animation. The
|
|
421
|
-
* the chatbox
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
+
* Chatbox → widget opening animation. The window sits bottom-centre, exactly
|
|
427
|
+
* where the chatbox is. Style is chosen with `open-animation`:
|
|
428
|
+
* - rise (default): lifts up from just below with a soft fade
|
|
429
|
+
* - unfold: starts as the chatbox pill and unfolds upward/outward
|
|
430
|
+
* - pop: springs out of the bar with a small overshoot
|
|
431
|
+
* - curtain: a full-width wipe from the bottom edge upward
|
|
432
|
+
* - fade: a plain, quick crossfade
|
|
433
|
+
* - none: no animation
|
|
434
|
+
* Content settles in a beat after the shape (except fade). Resolves once the
|
|
435
|
+
* animation has started; never throws — worst case the widget just appears.
|
|
426
436
|
*/
|
|
427
437
|
private growWidgetFromChatbox;
|
|
438
|
+
/** Placeholders the chatbox cycles through while idle: host `chatbox-placeholders` / init({ chatboxPlaceholders }) first, else this page's nudges, else the agent's suggestion labels, else generic defaults. */
|
|
439
|
+
private getChatboxPlaceholders;
|
|
440
|
+
/** Grow the chatbox textarea with its content (up to its max-height, then scroll). */
|
|
441
|
+
private autosizeChatbox;
|
|
442
|
+
/** Fade the top / bottom edge of the textarea only where there is more text beyond it. */
|
|
443
|
+
private updateChatboxFades;
|
|
444
|
+
/** The invitation pulse runs while the bar is idle, no chat is in progress, and nothing has been typed. */
|
|
445
|
+
private syncChatboxPulse;
|
|
446
|
+
/** Paint the right placeholder: "Continue your chat…" while a chat is in progress, hidden once the user types. */
|
|
447
|
+
private syncChatboxPlaceholder;
|
|
448
|
+
/** Every 3.5s the idle placeholder slides out and the next one slides in. Paused while typing, focused, loading, or with reduced motion. */
|
|
449
|
+
private startPlaceholderRotation;
|
|
428
450
|
loadWidgetCss(): Promise<void>;
|
|
429
451
|
loadWidgetModule(): Promise<WidgetModule>;
|
|
430
452
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:n}=document;if(n instanceof HTMLScriptElement)return n;const t=Array.from(document.getElementsByTagName("script")),e=t.find(o=>o.hasAttribute("data-widget-assets"));if(e)return e;const i=t.filter(o=>/(^|\/)index\.js(\?.*)?$/.test(o.src));return i.length?i[i.length-1]:t.length?t[t.length-1]:null},getEnvironment=n=>{if(n==="production"||n==="development"||n==="staging")return n},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var n;return!((n=scriptEl==null?void 0:scriptEl.src)===null||n===void 0)&&n.includes("@dev"),"https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.140-dev.0/dist/"})();var FeedbackTypeEnum;(function(n){n.DEFAULT="default",n.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(n){var t;if(!n)return;const e=n.mode==="dark"?"white":n.mode==="light"?"black":void 0;return{...n.background_img&&{backgroundImage:n.background_img},...n.accent&&{primary:n.accent},...e&&{textColor:e},...n.mode&&{mode:n.mode},...n.header_tinted!==void 0&&{headerTinted:n.header_tinted},...n.title_img&&{titleImg:n.title_img},...n.tagline&&{tagline:n.tagline},...n.hide_watermark&&{hideWatermark:n.hide_watermark},...n.explicit_disclaimer&&{explicitDisclaimer:n.explicit_disclaimer},...n.consent_content&&{consentContent:n.consent_content},...n.upfront_consent&&{upfrontConsent:n.upfront_consent},...((t=n.tips)===null||t===void 0?void 0:t.length)&&{tips:n.tips},...n.feature!==void 0&&{feature:n.feature},...typeof n.widget_width=="number"&&{widgetWidth:n.widget_width},...typeof n.widget_height=="number"&&{widgetHeight:n.widget_height}}}function preloadImage(n){if(!(!n||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=n,document.head.appendChild(t)}catch{const t=new Image;t.src=n}}function channelFromDisplayMode(n){return n==="full"?"web":n==="side_panel"?"side_panel":"widget"}function prefersReducedMotion(){var n;return typeof window!="undefined"&&!!(!((n=window.matchMedia)===null||n===void 0)&&n.call(window,"(prefers-reduced-motion: reduce)").matches)}function nextFrame(){return new Promise(n=>requestAnimationFrame(()=>n()))}function colorOnAccent(n){const t=n.trim().replace("#",""),e=t.length===3?t.split("").map(s=>s+s).join(""):t;if(!/^[0-9a-f]{6}$/i.test(e))return"#fafafa";const i=[0,2,4].map(s=>parseInt(e.slice(s,s+2),16)/255);return(Math.max(...i)+Math.min(...i))/2>.5?"#171717":"#fafafa"}function normalizeDisplayMode(n){return n==="full"?"full":n==="side_panel"?"side_panel":"widget"}const NUDGE_STORAGE_KEY="eka-medassist-nudges",AGENT_CONFIG_CACHE_KEY="eka-medassist-agent-config";function readAgentConfigCache(n){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(t?JSON.parse(t):{})[n]}catch{return}}function writeAgentConfigCache(n,t){try{const e=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),i=e?JSON.parse(e):{};i[n]={...i[n]||{},...t},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(i))}catch{}}function getNudgeStore(){try{const n=localStorage.getItem(NUDGE_STORAGE_KEY);return n?JSON.parse(n):{}}catch{return{}}}function setNudgeStore(n){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(n))}catch{}}function normalizePath(n){let t=n.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function getNudgePathCandidates(n){const t=n.split("/").filter(Boolean),e=[];for(let i=t.length;i>=0;i--)e.push(i===0?"/":"/"+t.slice(0,i).join("/"));return e}function findCachedNudgeForCandidates(n,t,e){const o=getNudgeStore()[n];if(!o)return null;const s=t.host,d=o[s];if(!d)return null;for(const a of e){if(d[a]!==void 0)return{domain:s,path:a,data:d[a]};const r=a==="/"?"/*":a+"/*";if(d[r]!==void 0)return{domain:s,path:r,data:d[r]}}return null}function findFreshCachedNudge(n,t,e){const i=findCachedNudgeForCandidates(n,t,e);if(!i)return null;const o=Math.floor(Date.now()/1e3);return i.data.expiry<=o?(clearNudgeForPath(n,i.domain,i.path),null):i}function clearNudgeForPath(n,t,e){const i=getNudgeStore(),o=i[n];!o||!o[t]||(delete o[t][e],setNudgeStore(i))}function storeNudgeResponse(n,t,e){var i,o,s,d;const a=(i=t==null?void 0:t.url_pattern)===null||i===void 0?void 0:i.domain,r=(o=t==null?void 0:t.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((s=t.nudges)===null||s===void 0)&&s.length)||!t.expiry||!a||!r)return;const l=getNudgeStore();l[n]||(l[n]={}),l[n][a]||(l[n][a]={});const u={nudges:t.nudges,expiry:t.expiry,delay:(d=t.delay)!==null&&d!==void 0?d:5};l[n][a][r]=u,e&&e!==r&&(l[n][a][e]=u),setNudgeStore(l)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(n,t){const e=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${n}=${t}; expires=${e}; path=/; SameSite=Lax`}function getNudgeCookie(n){const t=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${n}=`));if(!t)return null;const e=t.split("=")[1];return e==="open"||e==="closed"?e:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(n){var t,e;try{const i=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${n}`),o=i?(e=(t=JSON.parse(i))===null||t===void 0?void 0:t.state)===null||e===void 0?void 0:e.sessToken:void 0;return typeof o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(n,t,e,i="widget"){const o=`${e}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(d=>{var a,r,l;const u=(a=d.getAttribute("name"))!==null&&a!==void 0?a:void 0,h=(r=d.getAttribute("property"))!==null&&r!==void 0?r:void 0,b=(l=d.getAttribute("content"))!==null&&l!==void 0?l:void 0;(u||h)&&s.push({name:u,property:h,content:b})});try{const d=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":n,"x-channel":i,referer:typeof window!="undefined"?window.location.href:"",Authorization:`Bearer ${t}`},body:JSON.stringify({meta_tags:s,url:typeof window!="undefined"?window.location.href:""})});return d.ok?await d.json():void 0}catch{return}}const SIDE_PANEL_PUSH_EVENT="eka-medassist:side-panel-push",globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const n=window;n.__ekaMedAssistConfig__=globalMedAssistConfig,n.EkaMedAssist={init(t){var e,i,o;Object.assign(globalMedAssistConfig,t);const s=getWidgetElement();if(s){if(t.agentId&&s.setAttribute("agent-id",t.agentId),t.authToken&&s.setAttribute("auth-token",t.authToken),t.title&&s.setAttribute("title",t.title),t.iconUrl&&s.setAttribute("icon-url",t.iconUrl),t.baseUrl&&s.setAttribute("base-url",t.baseUrl),t.resize!==void 0&&s.setAttribute("resize",String(t.resize)),(t.displayMode==="full"||t.displayMode==="widget"||t.displayMode==="side_panel")&&s.setAttribute("display-mode",t.displayMode),t.sidePanelMode&&s.setAttribute("side-panel-mode",t.sidePanelMode),t.sidePanelWidth!==void 0&&s.setAttribute("side-panel-width",String(t.sidePanelWidth)),t.side&&s.setAttribute("side",t.side),t.context)try{s.setAttribute("context",JSON.stringify(t.context))}catch{console.warn("Failed to stringify context passed to init")}typeof t.customLauncherStyles=="string"&&s.setAttribute("custom-launcher-styles",t.customLauncherStyles),t.launcherType&&s.setAttribute("launcher-type",t.launcherType),t.redirectUrl&&s.setAttribute("redirect-url",t.redirectUrl),!((e=t.theme)===null||e===void 0)&&e.backgroundImage&&preloadImage(t.theme.backgroundImage),(o=(i=s).openFromBridge)===null||o===void 0||o.call(i)}}}}const scriptBaseUrl=(()=>{if(!scriptEl)return"";try{return new URL(".",scriptEl.src||window.location.href).href}catch{return""}})(),widgetAssetBaseUrl=(()=>{if(!scriptEl)return DEFAULT_WIDGET_ASSET_BASE;const n=scriptEl.dataset.widgetAssets;if(n==="local")return`${scriptBaseUrl}src/`;if(n&&n.length>0)try{return new URL(n,scriptBaseUrl).href}catch{return n.endsWith("/")?n:`${n}/`}return DEFAULT_WIDGET_ASSET_BASE})(),WIDGET_JS_URL=`${widgetAssetBaseUrl}medassist-widget.js`,WIDGET_CSS_URL=`${widgetAssetBaseUrl}medassist-widget.css`;let widgetModulePromise=null,widgetCssTextPromise=null;function getWidgetCssTextPromise(){return widgetCssTextPromise||(widgetCssTextPromise=fetch(WIDGET_CSS_URL).then(n=>{if(!n.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return n.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{setLauncherState(t){this.launcherState=t,this.updateLauncherView()}getLauncherType(){var t,e;if(this.displayMode!=="widget")return"button";const i=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},o=this.getAgentId();return(this.getAttribute("launcher-type")||i.launcherType||(o?(e=(t=readAgentConfigCache(o))===null||t===void 0?void 0:t.theme)===null||e===void 0?void 0:e.launcher_type:void 0))==="chatbox"?"chatbox":"button"}isChatboxShown(){return this.getLauncherType()==="chatbox"}updateLauncherView(){const t=this.shadowRoot;if(!t)return;this.applyCustomLauncherStyles();const e=this.launcherState,i=this.isChatboxShown(),o=t.getElementById("medassist-open-btn");if(o){const d=e==="loading"&&!i;o.classList.toggle("loading",d),o.classList.toggle("hidden",e==="open"||i),d?o.setAttribute("aria-busy","true"):o.removeAttribute("aria-busy")}const s=t.getElementById("medassist-chatbox");if(s){this.applyChatboxTheme(s);const d=e==="loading"&&i;s.classList.toggle("hidden",e==="open"||!i),s.classList.toggle("sending",d);const a=t.getElementById("medassist-chatbox-input");if(a){a.readOnly=d,e==="open"&&(a.value="");const r=s.querySelector(".medassist-chatbox-send");r&&(r.disabled=!a.value.trim())}}}getChannel(){const t=this.getAttribute("display-mode");if(t)return channelFromDisplayMode(t);const e=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(e==null?void 0:e.displayMode)}getAgentConfig(){var t;if(!this.agentConfigPromise){const e=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=e.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",o=e.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);const s=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";this.agentConfigPromise=this.loadWidgetModule().then(d=>{var a;return(a=d.fetchAgentConfig)===null||a===void 0?void 0:a.call(d,{agentId:o,serverUrl:i,environment:s,channel:this.getChannel()})}).catch(()=>{this.agentConfigPromise=null})}return this.agentConfigPromise}constructor(){super(),this.hostPushStyleEl=null,this.hostPushState=null,this.reactRoot=null,this.agentConfigPromise=null,this.loading=!1,this.launcherState="idle",this.authPrefetchPromise=null,this.launcherRenderSeq=0,this.attachShadow({mode:"open"}),this.widgetLoaded=!1,this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles","redirect-url","side-panel-mode","side-panel-width","side","override-widget-width","override-widget-height","launcher-type"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderLauncher(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}disconnectedCallback(){var t,e,i,o,s;(t=this.reactRoot)===null||t===void 0||t.unmount(),this.reactRoot=null,(e=document.body)===null||e===void 0||e.classList.remove("eka-medassist-pushed"),(i=document.documentElement)===null||i===void 0||i.style.removeProperty("--eka-medassist-panel-width"),(o=document.documentElement)===null||o===void 0||o.style.removeProperty("--eka-medassist-panel-side"),(s=this.hostPushStyleEl)===null||s===void 0||s.remove(),this.hostPushStyleEl=null,this.hostPushState=null}applyHostPush(t,e,i){var o;if(typeof document=="undefined")return;const s=t?{width:e,side:i}:null,d=this.hostPushState;if(d===s||d&&s&&d.width===s.width&&d.side===s.side)return;this.hostPushState=s,this.hostPushStyleEl||(this.hostPushStyleEl=document.createElement("style"),this.hostPushStyleEl.setAttribute("data-medassist-side-panel-push","true"),document.head.appendChild(this.hostPushStyleEl));const a=i==="left"?"margin-left":"margin-right";this.hostPushStyleEl.textContent=`
|
|
1
|
+
"use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:s}=document;if(s instanceof HTMLScriptElement)return s;const t=Array.from(document.getElementsByTagName("script")),e=t.find(o=>o.hasAttribute("data-widget-assets"));if(e)return e;const i=t.filter(o=>/(^|\/)index\.js(\?.*)?$/.test(o.src));return i.length?i[i.length-1]:t.length?t[t.length-1]:null},getEnvironment=s=>{if(s==="production"||s==="development"||s==="staging")return s},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var s;return!((s=scriptEl==null?void 0:scriptEl.src)===null||s===void 0)&&s.includes("@dev"),"https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.141-dev.0/dist/"})();var FeedbackTypeEnum;(function(s){s.DEFAULT="default",s.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(s){var t;if(!s)return;const e=s.mode==="dark"?"white":s.mode==="light"?"black":void 0;return{...s.background_img&&{backgroundImage:s.background_img},...s.accent&&{primary:s.accent},...e&&{textColor:e},...s.mode&&{mode:s.mode},...s.header_tinted!==void 0&&{headerTinted:s.header_tinted},...s.title_img&&{titleImg:s.title_img},...s.tagline&&{tagline:s.tagline},...s.hide_watermark&&{hideWatermark:s.hide_watermark},...s.explicit_disclaimer&&{explicitDisclaimer:s.explicit_disclaimer},...s.consent_content&&{consentContent:s.consent_content},...s.upfront_consent&&{upfrontConsent:s.upfront_consent},...((t=s.tips)===null||t===void 0?void 0:t.length)&&{tips:s.tips},...s.feature!==void 0&&{feature:s.feature},...typeof s.widget_width=="number"&&{widgetWidth:s.widget_width},...typeof s.widget_height=="number"&&{widgetHeight:s.widget_height}}}function preloadImage(s){if(!(!s||typeof document=="undefined"))try{const t=document.createElement("link");t.rel="preload",t.as="image",t.href=s,document.head.appendChild(t)}catch{const t=new Image;t.src=s}}function channelFromDisplayMode(s){return s==="full"?"web":s==="side_panel"?"side_panel":"widget"}function prefersReducedMotion(){var s;return typeof window!="undefined"&&!!(!((s=window.matchMedia)===null||s===void 0)&&s.call(window,"(prefers-reduced-motion: reduce)").matches)}function nextFrame(){return new Promise(s=>requestAnimationFrame(()=>s()))}function colorOnAccent(s){const t=s.trim().replace("#",""),e=t.length===3?t.split("").map(n=>n+n).join(""):t;if(!/^[0-9a-f]{6}$/i.test(e))return"#fafafa";const i=[0,2,4].map(n=>parseInt(e.slice(n,n+2),16)/255);return(Math.max(...i)+Math.min(...i))/2>.5?"#171717":"#fafafa"}function normalizeDisplayMode(s){return s==="full"?"full":s==="side_panel"?"side_panel":"widget"}const NUDGE_STORAGE_KEY="eka-medassist-nudges",AGENT_CONFIG_CACHE_KEY="eka-medassist-agent-config";function readAgentConfigCache(s){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(t?JSON.parse(t):{})[s]}catch{return}}function writeAgentConfigCache(s,t){try{const e=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),i=e?JSON.parse(e):{};i[s]={...i[s]||{},...t},localStorage.setItem(AGENT_CONFIG_CACHE_KEY,JSON.stringify(i))}catch{}}function getNudgeStore(){try{const s=localStorage.getItem(NUDGE_STORAGE_KEY);return s?JSON.parse(s):{}}catch{return{}}}function setNudgeStore(s){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(s))}catch{}}function normalizePath(s){let t=s.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function getNudgePathCandidates(s){const t=s.split("/").filter(Boolean),e=[];for(let i=t.length;i>=0;i--)e.push(i===0?"/":"/"+t.slice(0,i).join("/"));return e}function findCachedNudgeForCandidates(s,t,e){const o=getNudgeStore()[s];if(!o)return null;const n=t.host,a=o[n];if(!a)return null;for(const d of e){if(a[d]!==void 0)return{domain:n,path:d,data:a[d]};const r=d==="/"?"/*":d+"/*";if(a[r]!==void 0)return{domain:n,path:r,data:a[r]}}return null}function findFreshCachedNudge(s,t,e){const i=findCachedNudgeForCandidates(s,t,e);if(!i)return null;const o=Math.floor(Date.now()/1e3);return i.data.expiry<=o?(clearNudgeForPath(s,i.domain,i.path),null):i}function clearNudgeForPath(s,t,e){const i=getNudgeStore(),o=i[s];!o||!o[t]||(delete o[t][e],setNudgeStore(i))}function storeNudgeResponse(s,t,e){var i,o,n,a;const d=(i=t==null?void 0:t.url_pattern)===null||i===void 0?void 0:i.domain,r=(o=t==null?void 0:t.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((n=t.nudges)===null||n===void 0)&&n.length)||!t.expiry||!d||!r)return;const l=getNudgeStore();l[s]||(l[s]={}),l[s][d]||(l[s][d]={});const c={nudges:t.nudges,expiry:t.expiry,delay:(a=t.delay)!==null&&a!==void 0?a:5};l[s][d][r]=c,e&&e!==r&&(l[s][d][e]=c),setNudgeStore(l)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(s,t){const e=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${s}=${t}; expires=${e}; path=/; SameSite=Lax`}function getNudgeCookie(s){const t=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${s}=`));if(!t)return null;const e=t.split("=")[1];return e==="open"||e==="closed"?e:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(s){var t,e;try{const i=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${s}`),o=i?(e=(t=JSON.parse(i))===null||t===void 0?void 0:t.state)===null||e===void 0?void 0:e.sessToken:void 0;return typeof o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(s,t,e,i="widget"){const o=`${e}/med-assist/user-nudge`,n=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(a=>{var d,r,l;const c=(d=a.getAttribute("name"))!==null&&d!==void 0?d:void 0,h=(r=a.getAttribute("property"))!==null&&r!==void 0?r:void 0,m=(l=a.getAttribute("content"))!==null&&l!==void 0?l:void 0;(c||h)&&n.push({name:c,property:h,content:m})});try{const a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":s,"x-channel":i,referer:typeof window!="undefined"?window.location.href:"",Authorization:`Bearer ${t}`},body:JSON.stringify({meta_tags:n,url:typeof window!="undefined"?window.location.href:""})});return a.ok?await a.json():void 0}catch{return}}const SIDE_PANEL_PUSH_EVENT="eka-medassist:side-panel-push",globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const s=window;s.__ekaMedAssistConfig__=globalMedAssistConfig,s.EkaMedAssist={init(t){var e,i,o;Object.assign(globalMedAssistConfig,t);const n=getWidgetElement();if(n){if(t.agentId&&n.setAttribute("agent-id",t.agentId),t.authToken&&n.setAttribute("auth-token",t.authToken),t.title&&n.setAttribute("title",t.title),t.iconUrl&&n.setAttribute("icon-url",t.iconUrl),t.baseUrl&&n.setAttribute("base-url",t.baseUrl),t.resize!==void 0&&n.setAttribute("resize",String(t.resize)),(t.displayMode==="full"||t.displayMode==="widget"||t.displayMode==="side_panel")&&n.setAttribute("display-mode",t.displayMode),t.sidePanelMode&&n.setAttribute("side-panel-mode",t.sidePanelMode),t.sidePanelWidth!==void 0&&n.setAttribute("side-panel-width",String(t.sidePanelWidth)),t.side&&n.setAttribute("side",t.side),t.context)try{n.setAttribute("context",JSON.stringify(t.context))}catch{console.warn("Failed to stringify context passed to init")}typeof t.customLauncherStyles=="string"&&n.setAttribute("custom-launcher-styles",t.customLauncherStyles),t.launcherType&&n.setAttribute("launcher-type",t.launcherType),t.redirectUrl&&n.setAttribute("redirect-url",t.redirectUrl),!((e=t.theme)===null||e===void 0)&&e.backgroundImage&&preloadImage(t.theme.backgroundImage),(o=(i=n).openFromBridge)===null||o===void 0||o.call(i)}}}}const scriptBaseUrl=(()=>{if(!scriptEl)return"";try{return new URL(".",scriptEl.src||window.location.href).href}catch{return""}})(),widgetAssetBaseUrl=(()=>{if(!scriptEl)return DEFAULT_WIDGET_ASSET_BASE;const s=scriptEl.dataset.widgetAssets;if(s==="local")return`${scriptBaseUrl}src/`;if(s&&s.length>0)try{return new URL(s,scriptBaseUrl).href}catch{return s.endsWith("/")?s:`${s}/`}return DEFAULT_WIDGET_ASSET_BASE})(),WIDGET_JS_URL=`${widgetAssetBaseUrl}medassist-widget.js`,WIDGET_CSS_URL=`${widgetAssetBaseUrl}medassist-widget.css`;let widgetModulePromise=null,widgetCssTextPromise=null;function getWidgetCssTextPromise(){return widgetCssTextPromise||(widgetCssTextPromise=fetch(WIDGET_CSS_URL).then(s=>{if(!s.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return s.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{setLauncherState(t){this.launcherState=t,this.updateLauncherView()}getLauncherType(){var t,e;if(this.displayMode!=="widget")return"button";const i=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},o=this.getAgentId();return(this.getAttribute("launcher-type")||i.launcherType||(o?(e=(t=readAgentConfigCache(o))===null||t===void 0?void 0:t.theme)===null||e===void 0?void 0:e.launcher_type:void 0))==="chatbox"?"chatbox":"button"}isChatboxShown(){return this.getLauncherType()==="chatbox"}updateLauncherView(){const t=this.shadowRoot;if(!t)return;this.applyCustomLauncherStyles();const e=this.launcherState,i=this.isChatboxShown(),o=t.getElementById("medassist-open-btn");if(o){const a=e==="loading"&&!i;o.classList.toggle("loading",a),o.classList.toggle("hidden",e==="open"||i),a?o.setAttribute("aria-busy","true"):o.removeAttribute("aria-busy")}const n=t.getElementById("medassist-chatbox");if(n){this.applyChatboxTheme(n);const a=e==="loading"&&i;n.classList.toggle("hidden",e==="open"||!i),n.classList.toggle("sending",a);const d=this.chatStarted&&e==="idle";n.classList.toggle("continuing",d),this.syncChatboxPlaceholder(),this.syncChatboxPulse();const r=t.getElementById("medassist-chatbox-input");if(r){r.readOnly=a||d,e==="open"&&(r.value="",this.autosizeChatbox());const l=n.querySelector(".medassist-chatbox-send");l&&(l.disabled=!r.value.trim())}}}getChannel(){const t=this.getAttribute("display-mode");if(t)return channelFromDisplayMode(t);const e=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(e==null?void 0:e.displayMode)}getAgentConfig(){var t;if(!this.agentConfigPromise){const e=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=e.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",o=e.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);const n=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";this.agentConfigPromise=this.loadWidgetModule().then(a=>{var d;return(d=a.fetchAgentConfig)===null||d===void 0?void 0:d.call(a,{agentId:o,serverUrl:i,environment:n,channel:this.getChannel()})}).catch(()=>{this.agentConfigPromise=null})}return this.agentConfigPromise}constructor(){super(),this.hostPushStyleEl=null,this.hostPushState=null,this.reactRoot=null,this.agentConfigPromise=null,this.loading=!1,this.chatStarted=!1,this.placeholderTimer=null,this.placeholderIndex=0,this.launcherState="idle",this.authPrefetchPromise=null,this.launcherRenderSeq=0,this.attachShadow({mode:"open"}),this.widgetLoaded=!1,this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles","redirect-url","side-panel-mode","side-panel-width","side","override-widget-width","override-widget-height","launcher-type"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderLauncher(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}disconnectedCallback(){var t,e,i,o,n;this.placeholderTimer&&clearInterval(this.placeholderTimer),this.placeholderTimer=null,(t=this.reactRoot)===null||t===void 0||t.unmount(),this.reactRoot=null,(e=document.body)===null||e===void 0||e.classList.remove("eka-medassist-pushed"),(i=document.documentElement)===null||i===void 0||i.style.removeProperty("--eka-medassist-panel-width"),(o=document.documentElement)===null||o===void 0||o.style.removeProperty("--eka-medassist-panel-side"),(n=this.hostPushStyleEl)===null||n===void 0||n.remove(),this.hostPushStyleEl=null,this.hostPushState=null}applyHostPush(t,e,i){var o;if(typeof document=="undefined")return;const n=t?{width:e,side:i}:null,a=this.hostPushState;if(a===n||a&&n&&a.width===n.width&&a.side===n.side)return;this.hostPushState=n,this.hostPushStyleEl||(this.hostPushStyleEl=document.createElement("style"),this.hostPushStyleEl.setAttribute("data-medassist-side-panel-push","true"),document.head.appendChild(this.hostPushStyleEl));const d=i==="left"?"margin-left":"margin-right";this.hostPushStyleEl.textContent=`
|
|
2
2
|
body.eka-medassist-pushed {
|
|
3
|
-
${
|
|
3
|
+
${d}: ${e}px;
|
|
4
4
|
transition: margin 300ms ease;
|
|
5
5
|
}
|
|
6
6
|
body.eka-medassist-pushed > * {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
@media (prefers-reduced-motion: reduce) {
|
|
10
10
|
body.eka-medassist-pushed { transition: none !important; }
|
|
11
11
|
}
|
|
12
|
-
`;const r=document.documentElement.style;t?(r.setProperty("--eka-medassist-panel-width",`${e}px`),r.setProperty("--eka-medassist-panel-side",i),document.body.classList.add("eka-medassist-pushed")):(document.body.classList.remove("eka-medassist-pushed"),r.removeProperty("--eka-medassist-panel-width"),r.removeProperty("--eka-medassist-panel-side"),this.hostPushStyleEl.remove(),this.hostPushStyleEl=null);const l={pushed:t,width:e,side:i};if(typeof window!="undefined"){try{window.dispatchEvent(new CustomEvent(SIDE_PANEL_PUSH_EVENT,{detail:l}))}catch{}const
|
|
12
|
+
`;const r=document.documentElement.style;t?(r.setProperty("--eka-medassist-panel-width",`${e}px`),r.setProperty("--eka-medassist-panel-side",i),document.body.classList.add("eka-medassist-pushed")):(document.body.classList.remove("eka-medassist-pushed"),r.removeProperty("--eka-medassist-panel-width"),r.removeProperty("--eka-medassist-panel-side"),this.hostPushStyleEl.remove(),this.hostPushStyleEl=null);const l={pushed:t,width:e,side:i};if(typeof window!="undefined"){try{window.dispatchEvent(new CustomEvent(SIDE_PANEL_PUSH_EVENT,{detail:l}))}catch{}const c=(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onSidePanelPushChange;if(typeof c=="function")try{c(t,e,i)}catch(h){console.error("EkaMedAssist.onSidePanelPushChange threw",h)}}}scheduleIdle(t){if(typeof window=="undefined"){t();return}const e=window.requestIdleCallback;typeof e=="function"?e(t,{timeout:3e3}):setTimeout(t,200)}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode!=="full"&&this.renderLauncher(),t==="display-mode"){const e=normalizeDisplayMode(this.getAttribute("display-mode"));e!==this.displayMode&&(this.displayMode=e,e==="full"?this.initializeFullMode():this.renderLauncher())}t==="custom-launcher-styles"&&this.applyCustomLauncherStyles(),t==="launcher-type"&&this.updateLauncherView()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetModule(),this.preloadBackgroundImage()}prefetchAuthTokens(){var t;if(this.authPrefetchPromise)return this.authPrefetchPromise;const e=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=e.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);const o=e.authToken||this.getAttribute("auth-token")||void 0,n=e.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",a=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";return this.authPrefetchPromise=this.loadWidgetModule().then(d=>{var r;return(r=d.prefetchAuth)===null||r===void 0?void 0:r.call(d,{agentId:i,authToken:o,serverUrl:n,environment:a,channel:this.getChannel()})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(t){const e=readPersistedSessToken(t);if(e)return e;const i=await this.prefetchAuthTokens();return(i==null?void 0:i.sess_token)||readPersistedSessToken(t)}preloadBackgroundImage(){var t;const e=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,i=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(t=e==null?void 0:e.theme)===null||t===void 0?void 0:t.backgroundImage,n=i==null?void 0:i.backgroundImage;o&&preloadImage(o),n&&n!==o&&preloadImage(n),this.getAgentConfig().then(a=>{var d;const r=(d=a==null?void 0:a.theme)===null||d===void 0?void 0:d.background_img;r&&preloadImage(r)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const t=e=>{var i;((i=e.data)===null||i===void 0?void 0:i.type)==="AUTH_EXPIRED"&&window.parent!==window&&window.parent.postMessage({type:"AUTH_EXPIRED",message:"Authentication expired"},"*")};window.addEventListener("message",t)}openFromBridge(){if(this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.displayMode==="full")this.initializeFullMode();else if(this.renderLauncher(),this.getLauncherType()==="chatbox")return;this.loadAndRender().catch(t=>{console.error("Failed to open MedAssist widget from bridge",t)})}async initNudge(){var t,e,i,o;const n=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,a=(n==null?void 0:n.agentId)||this.getAttribute("agent-id")||"";if(!a)return;const d=await this.getAgentConfig();if(!(d!=null&&d.nudge))return;const r=(e=(t=d==null?void 0:d.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&e!==void 0?e:"#ffffff",l=typeof window!="undefined"?window.location.href:"";let c;try{c=new URL(l)}catch{return}const h=getNudgePathCandidates(c.pathname),m=h.slice(0,1),x=h.slice(1);let p=findFreshCachedNudge(a,c,m);if(!p){const w=(n==null?void 0:n.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",A=await this.resolveSessToken(a).catch(()=>{});if(A){const f=await fetchNudgeData(a,A,w,this.getChannel()).catch(()=>{});!((i=f==null?void 0:f.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(a,f,normalizePath(c.pathname)),p=findFreshCachedNudge(a,c,h))}}if(p||(p=findFreshCachedNudge(a,c,x)),!p)return;const C=p.data.nudges[Math.floor(Math.random()*p.data.nudges.length)],y=(o=p.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(C,r)},y*1e3)}showNudgePopup(t,e){var i,o;const n=this.shadowRoot;if(!n||!(!((i=n.getElementById("medassist-widget-root"))===null||i===void 0)&&i.classList.contains("hidden")))return;const d=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(d&&getNudgeCookie(d)!==null||n.getElementById("medassist-nudge-popup"))return;const l=this.isChatboxShown()?n.getElementById("medassist-chatbox"):n.getElementById("medassist-open-btn"),c=l==null?void 0:l.getBoundingClientRect(),h=272,m=12,x=8,p=16,C=16;let y=window.innerWidth-h-m,w=76,A=h-p-x*2;if(c&&c.width>0){const b=c.left+c.width/2,g=b-h/2,E=window.innerWidth-h-m;y=Math.max(m,Math.min(g,E)),w=window.innerHeight-c.top+C,A=Math.max(p,Math.min(b-y-x,h-p-x*2))}const f=document.createElement("div");f.id="medassist-nudge-popup",f.innerHTML=`
|
|
13
13
|
<style>
|
|
14
14
|
@keyframes nudge-slide-up {
|
|
15
15
|
from { opacity: 0; transform: translateY(12px) scale(0.97); }
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
#medassist-nudge-popup {
|
|
19
19
|
position: fixed;
|
|
20
|
-
bottom: ${
|
|
20
|
+
bottom: ${w}px;
|
|
21
21
|
left: ${y}px;
|
|
22
22
|
width: ${h}px;
|
|
23
23
|
background: ${e};
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
<p class="nudge-text">${t.replace(/</g,"<").replace(/>/g,">")}</p>
|
|
91
91
|
<button class="nudge-close" aria-label="Dismiss">✕</button>
|
|
92
92
|
</div>
|
|
93
|
-
`,(o=f.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",
|
|
93
|
+
`,(o=f.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",b=>{b.stopPropagation(),d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup()}),f.addEventListener("click",()=>{var b;if(d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.isChatboxShown()){(b=n.getElementById("medassist-chatbox-input"))===null||b===void 0||b.focus();return}this.loadAndRender()}),n.appendChild(f)}dismissNudgePopup(){var t;const e=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-nudge-popup");e==null||e.remove()}applyCustomLauncherStyles(){var t,e,i,o;const n=this.shadowRoot;if(!n||this.displayMode==="full")return;const a=this.getAgentId(),d=(i=a?(e=(t=readAgentConfigCache(a))===null||t===void 0?void 0:t.theme)===null||e===void 0?void 0:e.launcher_styles:void 0)!==null&&i!==void 0?i:"";this.setLauncherStyleTag("data-medassist-config-launcher",d);const r=n.querySelector('style[data-medassist-custom-launcher="true"]'),l=(o=this.getAttribute("custom-launcher-styles"))!==null&&o!==void 0?o:"";if(!l){r==null||r.remove();return}if(r){r.textContent=l;return}const c=document.createElement("style");c.setAttribute("data-medassist-custom-launcher","true"),c.textContent=l,n.appendChild(c)}setLauncherStyleTag(t,e){const i=this.shadowRoot;if(!i)return;const o=i.querySelector(`style[${t}="true"]`);if(!e){o==null||o.remove();return}if(o){o.textContent=e;return}const n=document.createElement("style");n.setAttribute(t,"true"),n.textContent=e;const a=i.querySelector('style[data-medassist-custom-launcher="true"]');i.insertBefore(n,a)}getAgentId(){return((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||""}async renderLauncher(){var t,e;if(this.displayMode==="full")return;const i=++this.launcherRenderSeq;this.renderButton();const o=this.getAttribute("icon-url");if(o){this.setLauncherIcon(o);const r=this.getAgentId();r&&this.scheduleIdle(()=>{this.getAgentConfig().then(l=>{!l||i!==this.launcherRenderSeq||(writeAgentConfigCache(r,l),this.updateLauncherView())})});return}const n=this.getAgentId();if(!n)return;const a=(e=(t=readAgentConfigCache(n))===null||t===void 0?void 0:t.theme)===null||e===void 0?void 0:e.icon_img;a&&this.setLauncherIcon(a);const d=async()=>{var r;const l=await this.getAgentConfig().catch(()=>{});i===this.launcherRenderSeq&&(l&&writeAgentConfigCache(n,l),this.setLauncherIcon(((r=l==null?void 0:l.theme)===null||r===void 0?void 0:r.icon_img)||a))};a?this.scheduleIdle(()=>{d()}):await d()}setLauncherIcon(t){var e,i;const o=this.shadowRoot;if(!o)return;const n=o.querySelector("#medassist-open-btn img");n&&(t?n.src=t:n.removeAttribute("src")),(e=o.getElementById("medassist-open-btn"))===null||e===void 0||e.classList.remove("pending"),(i=o.getElementById("medassist-chatbox"))===null||i===void 0||i.classList.remove("pending"),this.updateLauncherView()}applyChatboxTheme(t){var e;const i=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).theme;let o;try{o=JSON.parse(this.getAttribute("theme")||"{}")}catch{o=void 0}const n=this.getAgentId(),a=n?(e=readAgentConfigCache(n))===null||e===void 0?void 0:e.theme:void 0,d=(i==null?void 0:i.primary)||(o==null?void 0:o.primary)||(a==null?void 0:a.accent);d&&(t.style.setProperty("--medassist-chatbox-accent",d),t.style.setProperty("--medassist-chatbox-on-accent",colorOnAccent(d))),((i==null?void 0:i.mode)||(o==null?void 0:o.mode)||(a==null?void 0:a.mode))==="dark"?t.setAttribute("data-mode","dark"):t.removeAttribute("data-mode")}renderButton(){var t;const e=this.shadowRoot;if(!e){console.error("Shadow root was not created");return}if(!e.querySelector("button")){e.innerHTML=`
|
|
94
94
|
<style>
|
|
95
95
|
#medassist-open-btn {
|
|
96
96
|
width: 60px;
|
|
@@ -182,27 +182,28 @@
|
|
|
182
182
|
--medassist-chatbox-text: #000000;
|
|
183
183
|
--medassist-chatbox-placeholder: #4d4d4d;
|
|
184
184
|
/* Bottom centre. A host moving it to a corner must also reset
|
|
185
|
-
left and
|
|
185
|
+
left and translate, e.g. left: auto; right: 20px; translate: none. */
|
|
186
186
|
position: fixed;
|
|
187
187
|
bottom: 20px;
|
|
188
188
|
left: 50%;
|
|
189
189
|
right: auto;
|
|
190
|
-
|
|
190
|
+
translate: -50% 0;
|
|
191
191
|
/* 40% of the page, but never narrower than 420px. */
|
|
192
|
-
width:
|
|
192
|
+
width: 360px;
|
|
193
193
|
max-width: calc(100vw - 32px);
|
|
194
194
|
box-sizing: border-box;
|
|
195
195
|
display: flex;
|
|
196
|
-
align-items:
|
|
196
|
+
align-items: flex-end;
|
|
197
197
|
gap: 8px;
|
|
198
198
|
margin: 0;
|
|
199
|
-
min-height:
|
|
200
|
-
padding:
|
|
199
|
+
min-height: 48px;
|
|
200
|
+
padding: 7px 7px 7px 20px;
|
|
201
201
|
background: var(--medassist-chatbox-bg);
|
|
202
202
|
border: 1px solid rgba(107, 92, 224, 0.3);
|
|
203
203
|
border: 1px solid color-mix(in srgb, var(--medassist-chatbox-accent) 30%, transparent);
|
|
204
|
-
border-radius:
|
|
205
|
-
box-shadow: 0
|
|
204
|
+
border-radius: 24px;
|
|
205
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08), 0 12px 32px rgba(0, 0, 0, 0.22), 0 28px 64px -8px rgba(0, 0, 0, 0.28);
|
|
206
|
+
transition: scale 200ms cubic-bezier(0.32, 0.72, 0, 1), box-shadow 200ms ease, border-color 200ms ease;
|
|
206
207
|
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
207
208
|
}
|
|
208
209
|
#medassist-chatbox[data-mode="dark"] {
|
|
@@ -213,47 +214,83 @@
|
|
|
213
214
|
#medassist-chatbox.pending {
|
|
214
215
|
display: none !important;
|
|
215
216
|
}
|
|
216
|
-
/*
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
#medassist-chatbox.pulse
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
100% {
|
|
233
|
-
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16),
|
|
234
|
-
0 0 0 8px transparent,
|
|
235
|
-
0 0 0 16px transparent;
|
|
236
|
-
}
|
|
217
|
+
/* Invitation pulse: while the bar is idle and untouched (nothing typed),
|
|
218
|
+
one accent wave ripples out from its edge, then
|
|
219
|
+
rests ~4s before the next. Pseudo-elements, so the bar's own shadow,
|
|
220
|
+
hover scale and centring are untouched. Managed from JS
|
|
221
|
+
(syncChatboxPulse): off once the user types, a chat is in progress,
|
|
222
|
+
or reduced motion is on. */
|
|
223
|
+
#medassist-chatbox.pulse::before {
|
|
224
|
+
content: "";
|
|
225
|
+
position: absolute;
|
|
226
|
+
left: -1px;
|
|
227
|
+
top: -1px;
|
|
228
|
+
right: -1px;
|
|
229
|
+
bottom: -1px;
|
|
230
|
+
border-radius: inherit;
|
|
231
|
+
pointer-events: none;
|
|
232
|
+
animation: medassist-chatbox-ripple 5.5s ease-out infinite;
|
|
237
233
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
234
|
+
#medassist-chatbox.pulse::before {
|
|
235
|
+
--medassist-ripple: color-mix(in srgb, var(--medassist-chatbox-accent) 38%, transparent);
|
|
236
|
+
}
|
|
237
|
+
@keyframes medassist-chatbox-ripple {
|
|
238
|
+
0% { box-shadow: 0 0 0 0 var(--medassist-ripple); }
|
|
239
|
+
22% { box-shadow: 0 0 0 16px transparent; }
|
|
240
|
+
100% { box-shadow: 0 0 0 16px transparent; }
|
|
242
241
|
}
|
|
242
|
+
/* A textarea so a long message wraps and the bar grows upward (it is
|
|
243
|
+
anchored at the bottom). Single line = 32px: 6px padding around one
|
|
244
|
+
20px line. Capped at 4 lines (92px); beyond that it scrolls. */
|
|
243
245
|
#medassist-chatbox-input {
|
|
244
246
|
flex: 1;
|
|
245
247
|
min-width: 0;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
+
display: block;
|
|
249
|
+
box-sizing: border-box;
|
|
250
|
+
height: 32px;
|
|
251
|
+
min-height: 32px;
|
|
252
|
+
max-height: 92px;
|
|
253
|
+
margin: 0;
|
|
254
|
+
padding: 6px 0;
|
|
248
255
|
border: none;
|
|
249
256
|
outline: none;
|
|
257
|
+
resize: none;
|
|
258
|
+
overflow-y: hidden;
|
|
250
259
|
background: transparent;
|
|
251
260
|
color: var(--medassist-chatbox-text);
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
line-height: 1.4;
|
|
261
|
+
font-size: 15px;
|
|
262
|
+
line-height: 20px;
|
|
255
263
|
font-family: inherit;
|
|
256
264
|
}
|
|
265
|
+
/* Minimal scrollbar, only visible once the text is taller than 4 lines. */
|
|
266
|
+
#medassist-chatbox-input::-webkit-scrollbar { width: 4px; }
|
|
267
|
+
#medassist-chatbox-input::-webkit-scrollbar-track { background: transparent; margin: 8px 0; }
|
|
268
|
+
#medassist-chatbox-input::-webkit-scrollbar-thumb {
|
|
269
|
+
background: color-mix(in srgb, var(--medassist-chatbox-text) 22%, transparent);
|
|
270
|
+
border-radius: 2px;
|
|
271
|
+
}
|
|
272
|
+
#medassist-chatbox-input::-webkit-scrollbar-thumb:hover {
|
|
273
|
+
background: color-mix(in srgb, var(--medassist-chatbox-accent) 55%, transparent);
|
|
274
|
+
}
|
|
275
|
+
@supports not selector(::-webkit-scrollbar) {
|
|
276
|
+
#medassist-chatbox-input {
|
|
277
|
+
scrollbar-width: thin;
|
|
278
|
+
scrollbar-color: color-mix(in srgb, var(--medassist-chatbox-text) 22%, transparent) transparent;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/* Soft fade at the edge(s) the text is scrolled past, so it never cuts off sharply. */
|
|
282
|
+
#medassist-chatbox-input.fade-t {
|
|
283
|
+
-webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px);
|
|
284
|
+
mask-image: linear-gradient(to bottom, transparent 0, #000 16px);
|
|
285
|
+
}
|
|
286
|
+
#medassist-chatbox-input.fade-b {
|
|
287
|
+
-webkit-mask-image: linear-gradient(to top, transparent 0, #000 16px);
|
|
288
|
+
mask-image: linear-gradient(to top, transparent 0, #000 16px);
|
|
289
|
+
}
|
|
290
|
+
#medassist-chatbox-input.fade-t.fade-b {
|
|
291
|
+
-webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
|
|
292
|
+
mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
|
|
293
|
+
}
|
|
257
294
|
#medassist-chatbox-input::placeholder {
|
|
258
295
|
color: var(--medassist-chatbox-placeholder);
|
|
259
296
|
}
|
|
@@ -262,8 +299,8 @@
|
|
|
262
299
|
}
|
|
263
300
|
.medassist-chatbox-send {
|
|
264
301
|
flex-shrink: 0;
|
|
265
|
-
width:
|
|
266
|
-
height:
|
|
302
|
+
width: 32px;
|
|
303
|
+
height: 32px;
|
|
267
304
|
border: none;
|
|
268
305
|
border-radius: 50%;
|
|
269
306
|
padding: 0;
|
|
@@ -290,8 +327,8 @@
|
|
|
290
327
|
box-shadow: none;
|
|
291
328
|
}
|
|
292
329
|
.medassist-chatbox-send svg {
|
|
293
|
-
width:
|
|
294
|
-
height:
|
|
330
|
+
width: 14px;
|
|
331
|
+
height: 14px;
|
|
295
332
|
}
|
|
296
333
|
.medassist-chatbox-spinner {
|
|
297
334
|
display: none;
|
|
@@ -313,15 +350,81 @@
|
|
|
313
350
|
#medassist-chatbox.sending .medassist-chatbox-spinner {
|
|
314
351
|
display: block;
|
|
315
352
|
}
|
|
353
|
+
/* Hover (mouse only): the whole bar grows 2% \u2014 the individual \`scale\`
|
|
354
|
+
property, so it composes with a host's own transform override. */
|
|
355
|
+
@media (hover: hover) and (pointer: fine) {
|
|
356
|
+
#medassist-chatbox:hover:not(.sending):not(.pending) {
|
|
357
|
+
scale: 1.02;
|
|
358
|
+
border-color: color-mix(in srgb, var(--medassist-chatbox-accent) 55%, transparent);
|
|
359
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1), 0 16px 40px rgba(0, 0, 0, 0.26), 0 32px 72px -8px rgba(0, 0, 0, 0.3);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/* Rotating placeholder: a text layer over the input, so it can slide. */
|
|
363
|
+
.medassist-chatbox-field {
|
|
364
|
+
position: relative;
|
|
365
|
+
flex: 1;
|
|
366
|
+
min-width: 0;
|
|
367
|
+
min-height: 32px;
|
|
368
|
+
display: flex;
|
|
369
|
+
align-items: flex-start;
|
|
370
|
+
}
|
|
371
|
+
.medassist-chatbox-field #medassist-chatbox-input {
|
|
372
|
+
width: 100%;
|
|
373
|
+
}
|
|
374
|
+
#medassist-chatbox-ph {
|
|
375
|
+
position: absolute;
|
|
376
|
+
left: 0;
|
|
377
|
+
top: 0;
|
|
378
|
+
max-width: 100%;
|
|
379
|
+
height: 32px;
|
|
380
|
+
line-height: 32px;
|
|
381
|
+
font-size: 15px;
|
|
382
|
+
color: var(--medassist-chatbox-placeholder);
|
|
383
|
+
white-space: nowrap;
|
|
384
|
+
overflow: hidden;
|
|
385
|
+
text-overflow: ellipsis;
|
|
386
|
+
pointer-events: none;
|
|
387
|
+
transition: opacity 220ms ease, transform 220ms ease;
|
|
388
|
+
}
|
|
389
|
+
#medassist-chatbox-ph.out { opacity: 0; transform: translateY(-8px); }
|
|
390
|
+
#medassist-chatbox-ph.in { opacity: 0; transform: translateY(8px); transition: none; }
|
|
391
|
+
#medassist-chatbox-ph.gone { display: none; }
|
|
392
|
+
/* Widget closed with a chat in progress: any click reopens it. */
|
|
393
|
+
#medassist-chatbox.continuing { cursor: pointer; }
|
|
394
|
+
#medassist-chatbox.continuing #medassist-chatbox-input { cursor: pointer; }
|
|
395
|
+
@media (prefers-reduced-motion: reduce) {
|
|
396
|
+
#medassist-chatbox, #medassist-chatbox-ph { transition: none; }
|
|
397
|
+
}
|
|
316
398
|
@media (max-width: 768px) {
|
|
317
399
|
#medassist-chatbox {
|
|
318
400
|
left: 16px;
|
|
319
401
|
right: 16px;
|
|
320
|
-
bottom: 16px;
|
|
402
|
+
bottom: calc(16px + env(safe-area-inset-bottom, 0px));
|
|
403
|
+
min-height: 52px;
|
|
404
|
+
padding: 7px 7px 7px 18px;
|
|
405
|
+
border-radius: 26px;
|
|
321
406
|
transform: none;
|
|
407
|
+
translate: none;
|
|
322
408
|
width: auto;
|
|
323
409
|
max-width: none;
|
|
324
410
|
}
|
|
411
|
+
.medassist-chatbox-field { min-height: 36px; }
|
|
412
|
+
#medassist-chatbox-input {
|
|
413
|
+
height: 36px;
|
|
414
|
+
min-height: 36px;
|
|
415
|
+
max-height: 96px;
|
|
416
|
+
padding: 8px 0;
|
|
417
|
+
font-size: 16px;
|
|
418
|
+
}
|
|
419
|
+
#medassist-chatbox-ph {
|
|
420
|
+
height: 36px;
|
|
421
|
+
line-height: 36px;
|
|
422
|
+
font-size: 16px;
|
|
423
|
+
}
|
|
424
|
+
.medassist-chatbox-send {
|
|
425
|
+
width: 36px;
|
|
426
|
+
height: 36px;
|
|
427
|
+
}
|
|
325
428
|
}
|
|
326
429
|
</style>
|
|
327
430
|
|
|
@@ -329,15 +432,18 @@
|
|
|
329
432
|
<img alt="MedAssist Icon">
|
|
330
433
|
<span id="medassist-loader" aria-hidden="true"></span>
|
|
331
434
|
</button>
|
|
332
|
-
<form id="medassist-chatbox" class="pending hidden
|
|
333
|
-
<
|
|
435
|
+
<form id="medassist-chatbox" class="pending hidden" autocomplete="off" novalidate>
|
|
436
|
+
<div class="medassist-chatbox-field">
|
|
437
|
+
<textarea id="medassist-chatbox-input" rows="1" enterkeyhint="send" maxlength="2000" aria-label="Message MedAssist"></textarea>
|
|
438
|
+
<span id="medassist-chatbox-ph" aria-hidden="true"></span>
|
|
439
|
+
</div>
|
|
334
440
|
<button type="submit" class="medassist-chatbox-send" aria-label="Send message" disabled>
|
|
335
441
|
<svg viewBox="0 0 17 16" fill="none" aria-hidden="true"><path d="M1.46875 0.09375L16.3125 6.9375C16.75 7.125 17 7.53125 17 8C17 8.46875 16.75 8.875 16.3125 9.0625L1.46875 15.9062C1.3125 15.9688 1.1875 16 1.03125 16C0.46875 16 0 15.5312 0 14.9688C0 14.8125 0.03125 14.6875 0.09375 14.5625L2.34375 9.5C2.5 9.15625 2.8125 8.9375 3.15625 8.90625L8.0625 8.46875C8.3125 8.46875 8.5 8.25 8.5 8C8.5 7.75 8.3125 7.5625 8.0625 7.53125L3.15625 7.09375C2.8125 7.0625 2.5 6.84375 2.34375 6.5L0.09375 1.4375C0.03125 1.3125 0 1.1875 0 1.03125C0 0.46875 0.46875 0 1.03125 0C1.1875 0 1.3125 0.03125 1.46875 0.09375Z" fill="currentColor"/></svg>
|
|
336
442
|
<span class="medassist-chatbox-spinner" aria-hidden="true"></span>
|
|
337
443
|
</button>
|
|
338
444
|
</form>
|
|
339
445
|
<div id="medassist-widget-root" class="hidden"></div>
|
|
340
|
-
`,(t=e.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const r=this.getAgentId();r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup(),this.loadAndRender()});const i=e.getElementById("medassist-chatbox-input");let o=!1;const
|
|
446
|
+
`,(t=e.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const r=this.getAgentId();r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup(),this.loadAndRender()});const i=e.getElementById("medassist-chatbox-input");let o=!1;const n=e.querySelector(".medassist-chatbox-send");i==null||i.addEventListener("input",()=>{n&&(n.disabled=!i.value.trim()),this.syncChatboxPlaceholder(),this.syncChatboxPulse(),this.autosizeChatbox(),!o&&(o=!0,this.preloadWidgetAssets(),this.prefetchAuthTokens())});const a=e.getElementById("medassist-chatbox"),d=()=>{if(!this.chatStarted||this.loading||this.launcherState!=="idle")return!1;const r=this.getAgentId();return r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup(),this.loadAndRender(),!0};a==null||a.addEventListener("click",r=>{d()&&r.preventDefault()}),i==null||i.addEventListener("scroll",()=>this.updateChatboxFades()),i==null||i.addEventListener("keydown",r=>{r.key!=="Enter"||r.shiftKey||r.isComposing||(r.preventDefault(),!d()&&i.value.trim()&&(a==null||a.requestSubmit()))}),this.startPlaceholderRotation(),a==null||a.addEventListener("submit",r=>{r.preventDefault();const l=i==null?void 0:i.value.trim();if(!l&&d()||!l||this.loading)return;const c=this.getAgentId();c&&setNudgeCookie(c,"closed"),this.dismissNudgePopup(),this.loadAndRender(l)})}this.applyCustomLauncherStyles()}initializeFullMode(){const t=this.shadowRoot;if(!t){console.error("Shadow root is not available");return}t.getElementById("medassist-widget-root")||(t.innerHTML=`
|
|
341
447
|
<style>
|
|
342
448
|
:host {
|
|
343
449
|
display: block;
|
|
@@ -354,4 +460,4 @@
|
|
|
354
460
|
}
|
|
355
461
|
</style>
|
|
356
462
|
<div id="medassist-widget-root"></div>
|
|
357
|
-
`)}async loadAndRender(t){var e,i,o,
|
|
463
|
+
`)}async loadAndRender(t){var e,i,o,n;const a=this.shadowRoot;if(!a){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const d=a.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let l=this.getAttribute("icon-url")||void 0;const c=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production",h=this.getAttribute("connectivity"),m=h==="http_stream"||h==="socket"?h:void 0,x=this.getAttribute("force-start")==="true";let p=this.getAttribute("title")||"Medi Clinic";const C=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",y=this.getAttribute("display-mode"),w=normalizeDisplayMode(y),A=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,f=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,b=this.getAttribute("feedback")?(()=>{try{return JSON.parse(this.getAttribute("feedback")||"{}")}catch{return}})():void 0,g=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},E=this.getAttribute("side-panel-mode"),J=g.sidePanelMode||(E==="overlay"?"overlay":"push"),R=this.getAttribute("side-panel-width"),Y=(i=g.sidePanelWidth)!==null&&i!==void 0?i:R?Number(R):void 0,j=g.side||this.getAttribute("side")||(typeof document!="undefined"&&document.dir==="rtl"?"left":"right"),N=u=>{const v=Number(this.getAttribute(u));return Number.isFinite(v)&&v>0?v:void 0},B=N("override-widget-width"),T=N("override-widget-height"),G={...B!==void 0&&{overrideWidgetWidth:B},...T!==void 0&&{overrideWidgetHeight:T}},V={...A||{},...g.context||{}},K=g.authToken||this.getAttribute("auth-token")||void 0,_=g.agentId||r,X=g.baseUrl||C,I=typeof window!="undefined"?(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onClose:void 0,Z=this.getAttribute("redirect-url")||void 0,P=g.redirectUrl||Z,Q=!!P||g.showCloseButton===!0;if(!_){console.error("Agent ID is required");return}if(!d){console.error("Widget root element is missing");return}this.loading=!0,this.setLauncherState("loading"),d.classList.remove("hidden");let W,z,U,$=!1,F,O=!1,L;const D=u=>{var v,k,M;p=u.name||p,l=((v=u.theme)===null||v===void 0?void 0:v.icon_img)||l,W=mapAgentConfigThemeToWidgetTheme(u.theme||void 0),z=u.allowed,U=u.connectivity,$=u.resize||(g==null?void 0:g.resize)||!1,F=u.initial_message,O=(M=(k=u.theme)===null||k===void 0?void 0:k.hide_watermark)!==null&&M!==void 0?M:!1,L=u.feedback},H=readAgentConfigCache(_);if(H)D(H),this.getAgentConfig().then(u=>{u&&writeAgentConfigCache(_,u)}).catch(()=>{});else try{const u=await this.getAgentConfig();u&&(writeAgentConfigCache(_,u),D(u))}catch{}const tt=m||U||"socket",q={title:g.title||p,iconUrl:l||g.iconUrl,showCloseButton:Q,allowed:z,environment:c,connectionType:tt,onClose:()=>{var u;if((u=this.reactRoot)===null||u===void 0||u.unmount(),this.reactRoot=null,I&&typeof I=="function"&&I(),P){window.location.href=P;return}w==="full"?this.style.display="none":(this.setLauncherState("idle"),d.classList.add("hidden"))},baseUrl:X,context:V,displayMode:w,sidePanelMode:J,sidePanelWidth:Y,side:j,onSidePanelPushChange:(u,v,k)=>this.applyHostPush(u,v,k),resize:$||this.getAttribute("resize")==="true",authToken:K,force:x,initialMessage:F,hideWatermark:O,...(b||L)&&{feedback:b||L},...t&&{firstUserMessage:t},theme:{...this.isChatboxShown()&&{widgetWidth:520},...W||{},...f||{},...G,...g.theme||{},...this.isChatboxShown()&&{openFrom:"bottom-center"}}},et=window,S=this.isChatboxShown()?(n=a.getElementById("medassist-chatbox"))===null||n===void 0?void 0:n.getBoundingClientRect():void 0;if(this.widgetLoaded){this.reactRoot=et.renderMedAssist(d,_,q),this.chatStarted=!0,S&&await this.growWidgetFromChatbox(S),this.setLauncherState("open"),this.loading=!1;return}try{const[,u]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=u.renderMedAssist(d,_,q),this.widgetLoaded=!0,this.chatStarted=!0,S&&await this.growWidgetFromChatbox(S),this.setLauncherState("open")}catch(u){console.error("Failed to load MedAssist widget",u),this.setLauncherState("idle"),d.classList.add("hidden")}finally{this.loading=!1}}getOpenAnimation(){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},e=this.getAttribute("open-animation")||t.openAnimation;return e==="unfold"||e==="pop"||e==="curtain"||e==="fade"||e==="none"?e:"rise"}async growWidgetFromChatbox(t){var e;try{const i=this.getOpenAnimation();if(i==="none"||prefersReducedMotion())return;const o=this.shadowRoot;let n=null;for(let c=0;c<30&&!n;c++)await nextFrame(),n=(e=o==null?void 0:o.querySelector(".synapse-chat-widget-container"))!==null&&e!==void 0?e:null;if(!n||typeof n.animate!="function")return;const a=n.getBoundingClientRect();if(!a.width||!a.height||!t.width)return;const d=a.width>=window.innerWidth-1?0:24,r="50% 100%";if(i==="rise")n.animate([{transform:"translateY(56px) scale(0.96)",opacity:0,transformOrigin:r},{transform:"translateY(0px) scale(1)",opacity:1,transformOrigin:r}],{duration:520,easing:"cubic-bezier(0.22, 1, 0.36, 1)"});else if(i==="pop")n.animate([{transform:"scale(0.4)",opacity:0,transformOrigin:r},{transform:"scale(1.04)",opacity:1,transformOrigin:r,offset:.6},{transform:"scale(1)",opacity:1,transformOrigin:r}],{duration:560,easing:"cubic-bezier(0.34, 1.2, 0.64, 1)"});else if(i==="curtain")n.animate([{transform:"translateY(20px)",clipPath:`inset(100% 0px 0px 0px round ${d}px)`},{transform:"translateY(0px)",clipPath:`inset(0px 0px 0px 0px round ${d}px)`}],{duration:560,easing:"cubic-bezier(0.65, 0, 0.35, 1)"});else if(i==="fade"){n.animate([{transform:"scale(0.97)",opacity:0,transformOrigin:r},{transform:"scale(1)",opacity:1,transformOrigin:r}],{duration:280,easing:"ease-out"});return}else{const c=t.left+t.width/2-(a.left+a.width/2),h=t.bottom-a.bottom,m=Math.max(0,a.height-t.height),x=Math.max(0,(a.width-t.width)/2),p=Math.min(t.height/2,28);n.animate([{transform:`translate(${c}px, ${h}px)`,clipPath:`inset(${m}px ${x}px 0px ${x}px round ${p}px)`},{transform:"translate(0px, 0px)",clipPath:`inset(0px 0px 0px 0px round ${d}px)`}],{duration:620,easing:"cubic-bezier(0.22, 1, 0.36, 1)"})}const l=Array.from(n.children).find(c=>c.tagName!=="STYLE");l==null||l.animate([{opacity:0,transform:"translateY(14px)"},{opacity:1,transform:"translateY(0px)"}],{duration:420,delay:140,easing:"cubic-bezier(0.22, 1, 0.36, 1)",fill:"backwards"})}catch{}}getChatboxPlaceholders(){var t,e,i;const o=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{};let n=o.chatboxPlaceholders;if(!Array.isArray(n))try{n=JSON.parse(this.getAttribute("chatbox-placeholders")||"null")}catch{n=null}const a=Array.isArray(n)?n.filter(l=>typeof l=="string"&&!!l.trim()):[];if(a.length)return a;const d=o.agentId||this.getAttribute("agent-id")||"",r=l=>Array.isArray(l)?l.filter(c=>typeof c=="string"&&!!c.trim()):[];if(d){try{const c=new URL(window.location.href),h=findFreshCachedNudge(d,c,getNudgePathCandidates(c.pathname)),m=r(h==null?void 0:h.data.nudges);if(m.length)return m}catch{}const l=r((i=(e=(t=readAgentConfigCache(d))===null||t===void 0?void 0:t.initial_message)===null||e===void 0?void 0:e.suggestions)===null||i===void 0?void 0:i.map(c=>c.label||c.value));if(l.length)return l}return["Ask me anything\u2026","Not sure what to ask? Just say hi\u2026","You can type in any language\u2026"]}autosizeChatbox(){var t;const e=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-chatbox-input");if(!e)return;e.style.height="auto";const i=parseFloat(getComputedStyle(e).maxHeight)||92;e.style.height=`${Math.min(e.scrollHeight,i)}px`,e.style.overflowY=e.scrollHeight>i?"auto":"hidden",this.updateChatboxFades()}updateChatboxFades(){var t;const e=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-chatbox-input");e&&(e.classList.toggle("fade-t",e.scrollTop>1),e.classList.toggle("fade-b",e.scrollHeight-e.clientHeight-e.scrollTop>1))}syncChatboxPulse(){const t=this.shadowRoot,e=t==null?void 0:t.getElementById("medassist-chatbox"),i=t==null?void 0:t.getElementById("medassist-chatbox-input");if(!e)return;const o=this.launcherState==="idle"&&!this.chatStarted&&!(i!=null&&i.value)&&!prefersReducedMotion();e.classList.toggle("pulse",o)}syncChatboxPlaceholder(){const t=this.shadowRoot,e=t==null?void 0:t.getElementById("medassist-chatbox-ph");if(!t||!e)return;const i=t.getElementById("medassist-chatbox-input"),o=this.chatStarted&&this.launcherState==="idle";e.classList.toggle("gone",!!(i!=null&&i.value));const n=o?"Continue your chat\u2026":this.getChatboxPlaceholders()[this.placeholderIndex%this.getChatboxPlaceholders().length];e.textContent!==n&&(e.textContent=n)}startPlaceholderRotation(){this.placeholderTimer||(this.syncChatboxPlaceholder(),!prefersReducedMotion()&&(this.placeholderTimer=setInterval(()=>{const t=this.shadowRoot,e=t==null?void 0:t.getElementById("medassist-chatbox-ph"),i=t==null?void 0:t.getElementById("medassist-chatbox-input");if(!t||!e||!i)return;const o=this.getChatboxPlaceholders();o.length<2||document.hidden||this.chatStarted||this.launcherState!=="idle"||i.value||t.activeElement===i||(e.classList.add("out"),setTimeout(()=>{this.placeholderIndex=(this.placeholderIndex+1)%o.length,e.classList.remove("out"),e.classList.add("in"),this.syncChatboxPlaceholder(),e.offsetWidth,e.classList.remove("in")},220))},3500)))}async loadWidgetCss(){const t=this.shadowRoot;if(!t)throw new Error("Shadow root is not available");if(t.querySelector("[data-medassist-style='true']"))return;const e=await getWidgetCssTextPromise(),i=document.createElement("style");i.setAttribute("data-medassist-style","true"),i.textContent=e,t.appendChild(i)}loadWidgetModule(){return widgetModulePromise||(widgetModulePromise=import(WIDGET_JS_URL)),widgetModulePromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
|