@eka-care/medassist-widget-embed 0.2.36 → 0.2.37

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/README.md CHANGED
@@ -87,6 +87,36 @@ window.EkaMedAssist.init({
87
87
  icon-url="https://example.com/custom-icon.svg"></eka-medassist-widget>
88
88
  ```
89
89
 
90
+ ### Custom launcher styling
91
+
92
+ If you need to reposition the floating launcher button (different breakpoints, custom z-index, etc.), pass CSS via `customLauncherStyles` in `init()` — or set it directly with the `custom-launcher-styles` attribute. The CSS is injected into the launcher's Shadow DOM, so you can use media queries, hover states, and anything else CSS allows.
93
+
94
+ Two selectors are supported as a stable contract:
95
+
96
+ - `:host` — the launcher wrapper. Use this to override `position`, `bottom`, `right`, `left`, `top`, `transform`, `z-index`, etc.
97
+ - `#medassist-open-btn` — the button element itself. Use this for size, background, box-shadow, border-radius, etc.
98
+
99
+ ```javascript
100
+ window.EkaMedAssist.init({
101
+ agentId: "your-agent-id",
102
+ customLauncherStyles: `
103
+ @media (max-width: 991px) {
104
+ :host {
105
+ right: auto;
106
+ left: 50%;
107
+ bottom: 47px;
108
+ transform: translateX(-50%);
109
+ }
110
+ }
111
+ @media (max-width: 767px) {
112
+ :host { bottom: 34px; }
113
+ }
114
+ `,
115
+ });
116
+ ```
117
+
118
+ This only affects the launcher button — the chat panel that opens on click is unaffected.
119
+
90
120
  ## How it works
91
121
 
92
122
  1. **Initial load** – The script registers the custom element `<eka-medassist-widget>`.
package/dist/index.d.ts CHANGED
@@ -31,6 +31,7 @@ type MedAssistInitConfig = {
31
31
  baseUrl?: string;
32
32
  resize?: boolean;
33
33
  displayMode?: "full" | "widget";
34
+ customLauncherStyles?: string;
34
35
  theme?: {
35
36
  backgroundImage?: string;
36
37
  primary?: string;
@@ -137,6 +138,7 @@ declare class MedAssistWidgetLoader extends HTMLElement {
137
138
  private initNudge;
138
139
  private showNudgePopup;
139
140
  private dismissNudgePopup;
141
+ private applyCustomLauncherStyles;
140
142
  renderButton(): void;
141
143
  initializeFullMode(): void;
142
144
  loadAndRender(): Promise<void>;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},getEnvironment=e=>{if(e==="production"||e==="development"||e==="staging")return e},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var e;return!((e=scriptEl==null?void 0:scriptEl.src)===null||e===void 0)&&e.includes("@dev")?"https://unpkg.com/@eka-care/medassist-widget@dev/dist/":"https://unpkg.com/@eka-care/medassist-widget@latest/dist/"})();function mapAgentConfigThemeToWidgetTheme(e){if(!e)return;const t=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...t&&{textColor:t},...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}}}function preloadImage(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 fetchAgentConfig(e,t){const n=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,o=await fetch(n,{headers:{"ngrok-skip-browser-warning":"69420"}});if(!o.ok)return;const i=await o.json();if(i!=null&&i.success&&(i!=null&&i.data))return i.data}const NUDGE_STORAGE_KEY="eka-medassist-nudges";function getNudgeStore(){try{const e=localStorage.getItem(NUDGE_STORAGE_KEY);return e?JSON.parse(e):{}}catch{return{}}}function setNudgeStore(e){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(e))}catch{}}function normalizePath(e){let t=e.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function findCachedNudge(e,t){const o=getNudgeStore()[e];if(!o)return null;let i;try{i=new URL(t)}catch{return null}const s=i.host,d=o[s];if(!d)return null;const r=i.pathname.split("/").filter(Boolean),c=[];for(let a=r.length;a>=0;a--)c.push(a===0?"/":"/"+r.slice(0,a).join("/"));for(const a of c){if(d[a]!==void 0)return{domain:s,path:a,data:d[a]};const u=a==="/"?"/*":a+"/*";if(d[u]!==void 0)return{domain:s,path:u,data:d[u]}}return null}function clearNudgeForPath(e,t,n){const o=getNudgeStore(),i=o[e];!i||!i[t]||(delete i[t][n],setNudgeStore(o))}function storeNudgeResponse(e,t){var n,o,i,s;const d=(n=t==null?void 0:t.url_pattern)===null||n===void 0?void 0:n.domain,r=(o=t==null?void 0:t.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((i=t.nudges)===null||i===void 0)&&i.length)||!t.expiry||!d||!r)return;const c=getNudgeStore();c[e]||(c[e]={}),c[e][d]||(c[e][d]={}),c[e][d][r]={nudges:t.nudges,expiry:t.expiry,delay:(s=t.delay)!==null&&s!==void 0?s:5},setNudgeStore(c)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(e,t){const n=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${e}=${t}; expires=${n}; path=/; SameSite=Lax`}function getNudgeCookie(e){const t=document.cookie.split(";").map(o=>o.trim()).find(o=>o.startsWith(`${NUDGE_COOKIE_PREFIX}-${e}=`));if(!t)return null;const n=t.split("=")[1];return n==="open"||n==="closed"?n:null}async function fetchNudgeData(e,t){const n=`${t}/med-assist/user-nudge`,o=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(i=>{var s,d,r;const c=(s=i.getAttribute("name"))!==null&&s!==void 0?s:void 0,a=(d=i.getAttribute("property"))!==null&&d!==void 0?d:void 0,u=(r=i.getAttribute("content"))!==null&&r!==void 0?r:void 0;(c||a)&&o.push({name:c,property:a,content:u})});try{const i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":e,referer:typeof window!="undefined"?window.location.href:""},body:JSON.stringify({meta_tags:o,url:typeof window!="undefined"?window.location.href:""})});return i.ok?await i.json():void 0}catch{return}}const globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const e=window;e.__ekaMedAssistConfig__=globalMedAssistConfig,e.EkaMedAssist={init(t){var n,o,i;Object.assign(globalMedAssistConfig,t);const s=getWidgetElement();if(s){if(t.agentId&&s.setAttribute("agent-id",t.agentId),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")&&s.setAttribute("display-mode",t.displayMode),t.context)try{s.setAttribute("context",JSON.stringify(t.context))}catch{console.warn("Failed to stringify context passed to init")}!((n=t.theme)===null||n===void 0)&&n.backgroundImage&&preloadImage(t.theme.backgroundImage),(i=(o=s).openFromBridge)===null||i===void 0||i.call(o)}}}}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 e=scriptEl.dataset.widgetAssets;if(e==="local")return`${scriptBaseUrl}src/`;if(e&&e.length>0)try{return new URL(e,scriptBaseUrl).href}catch{return e.endsWith("/")?e:`${e}/`}return DEFAULT_WIDGET_ASSET_BASE})(),WIDGET_JS_URL=`${widgetAssetBaseUrl}medassist-widget.js`,WIDGET_CSS_URL=`${widgetAssetBaseUrl}medassist-widget.css`;let widgetScriptPromise=null,widgetCssTextPromise=null;function getWidgetCssTextPromise(){return widgetCssTextPromise||(widgetCssTextPromise=fetch(WIDGET_CSS_URL).then(e=>{if(!e.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return e.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{getAgentConfig(){if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},n=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",o=t.agentId||this.getAttribute("agent-id")||"";if(!o)return Promise.resolve(void 0);this.agentConfigPromise=fetchAgentConfig(n,o).catch(()=>{})}return this.agentConfigPromise}constructor(){super(),this.reactRoot=null,this.agentConfigPromise=null,this.attachShadow({mode:"open"}),this.defaultIconUrl="https://cdn.eka.care/bot-icon.svg",this.widgetLoaded=!1,this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadWidgetCss().then(()=>this.loadWidgetScript()).then(()=>this.loadAndRender()).catch(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderButton(),this.preloadWidgetAssets(),this.initNudge())}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode==="widget"&&this.renderButton(),t==="display-mode"){const n=this.getAttribute("display-mode")==="full"?"full":"widget";n!==this.displayMode&&(this.displayMode=n,n==="full"?this.initializeFullMode():this.renderButton())}}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetScript(),this.preloadBackgroundImage()}preloadBackgroundImage(){var t;const n=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,o=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,i=(t=n==null?void 0:n.theme)===null||t===void 0?void 0:t.backgroundImage,s=o==null?void 0:o.backgroundImage;i&&preloadImage(i),s&&s!==i&&preloadImage(s),this.getAgentConfig().then(d=>{var r;const c=(r=d==null?void 0:d.theme)===null||r===void 0?void 0:r.background_img;c&&preloadImage(c)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const t=n=>{var o;((o=n.data)===null||o===void 0?void 0:o.type)==="AUTH_EXPIRED"&&window.parent!==window&&window.parent.postMessage({type:"AUTH_EXPIRED",message:"Authentication expired"},"*")};window.addEventListener("message",t)}openFromBridge(){this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.displayMode==="full"?this.initializeFullMode():this.renderButton(),this.loadWidgetCss().then(()=>this.loadWidgetScript()).then(()=>this.loadAndRender()).catch(t=>{console.error("Failed to open MedAssist widget from bridge",t)})}async initNudge(){var t,n,o,i;const s=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,d=(s==null?void 0:s.agentId)||this.getAttribute("agent-id")||"";if(!d)return;const r=await this.getAgentConfig();if(!(r!=null&&r.nudge))return;const c=(n=(t=r==null?void 0:r.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&n!==void 0?n:"#ffffff",a=typeof window!="undefined"?window.location.href:"";let u=findCachedNudge(d,a);if(u){const f=Math.floor(Date.now()/1e3);u.data.expiry<=f&&(clearNudgeForPath(d,u.domain,u.path),u=null)}if(!u){const f=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,y=(f==null?void 0:f.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",p=await fetchNudgeData(d,y).catch(()=>{});if(!(!((o=p==null?void 0:p.nudges)===null||o===void 0)&&o.length)||(storeNudgeResponse(d,p),u=findCachedNudge(d,a),!u))return}const m=u.data.nudges[Math.floor(Math.random()*u.data.nudges.length)],h=(i=u.data.delay)!==null&&i!==void 0?i:5;setTimeout(()=>{this.showNudgePopup(m,c)},h*1e3)}showNudgePopup(t,n){var o,i;const s=this.shadowRoot;if(!s||!(!((o=s.getElementById("medassist-widget-root"))===null||o===void 0)&&o.classList.contains("hidden")))return;const r=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(r&&getNudgeCookie(r)!==null||s.getElementById("medassist-nudge-popup"))return;const a=document.createElement("div");a.id="medassist-nudge-popup",a.innerHTML=`
1
+ "use strict";const getCurrentScript=()=>{if(typeof document=="undefined")return console.error("document is not defined"),null;const{currentScript:e}=document;if(e instanceof HTMLScriptElement)return e;const t=document.getElementsByTagName("script");return t.length?t[t.length-1]:null},getEnvironment=e=>{if(e==="production"||e==="development"||e==="staging")return e},scriptEl=getCurrentScript(),DEFAULT_WIDGET_ASSET_BASE=(()=>{var e;return!((e=scriptEl==null?void 0:scriptEl.src)===null||e===void 0)&&e.includes("@dev")?"https://unpkg.com/@eka-care/medassist-widget@dev/dist/":"https://unpkg.com/@eka-care/medassist-widget@latest/dist/"})();function mapAgentConfigThemeToWidgetTheme(e){if(!e)return;const t=e.mode==="dark"?"white":e.mode==="light"?"black":void 0;return{...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...t&&{textColor:t},...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}}}function preloadImage(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 fetchAgentConfig(e,t){const o=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,i=await fetch(o,{headers:{"ngrok-skip-browser-warning":"69420"}});if(!i.ok)return;const n=await i.json();if(n!=null&&n.success&&(n!=null&&n.data))return n.data}const NUDGE_STORAGE_KEY="eka-medassist-nudges";function getNudgeStore(){try{const e=localStorage.getItem(NUDGE_STORAGE_KEY);return e?JSON.parse(e):{}}catch{return{}}}function setNudgeStore(e){try{localStorage.setItem(NUDGE_STORAGE_KEY,JSON.stringify(e))}catch{}}function normalizePath(e){let t=e.replace(/\/+$/,"");return t.startsWith("/")||(t="/"+t),t||"/"}function findCachedNudge(e,t){const i=getNudgeStore()[e];if(!i)return null;let n;try{n=new URL(t)}catch{return null}const s=n.host,d=i[s];if(!d)return null;const r=n.pathname.split("/").filter(Boolean),c=[];for(let a=r.length;a>=0;a--)c.push(a===0?"/":"/"+r.slice(0,a).join("/"));for(const a of c){if(d[a]!==void 0)return{domain:s,path:a,data:d[a]};const u=a==="/"?"/*":a+"/*";if(d[u]!==void 0)return{domain:s,path:u,data:d[u]}}return null}function clearNudgeForPath(e,t,o){const i=getNudgeStore(),n=i[e];!n||!n[t]||(delete n[t][o],setNudgeStore(i))}function storeNudgeResponse(e,t){var o,i,n,s;const d=(o=t==null?void 0:t.url_pattern)===null||o===void 0?void 0:o.domain,r=(i=t==null?void 0:t.url_pattern)===null||i===void 0?void 0:i.path;if(!(!((n=t.nudges)===null||n===void 0)&&n.length)||!t.expiry||!d||!r)return;const c=getNudgeStore();c[e]||(c[e]={}),c[e][d]||(c[e][d]={}),c[e][d][r]={nudges:t.nudges,expiry:t.expiry,delay:(s=t.delay)!==null&&s!==void 0?s:5},setNudgeStore(c)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(e,t){const o=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${e}=${t}; expires=${o}; path=/; SameSite=Lax`}function getNudgeCookie(e){const t=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${e}=`));if(!t)return null;const o=t.split("=")[1];return o==="open"||o==="closed"?o:null}async function fetchNudgeData(e,t){const o=`${t}/med-assist/user-nudge`,i=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(n=>{var s,d,r;const c=(s=n.getAttribute("name"))!==null&&s!==void 0?s:void 0,a=(d=n.getAttribute("property"))!==null&&d!==void 0?d:void 0,u=(r=n.getAttribute("content"))!==null&&r!==void 0?r:void 0;(c||a)&&i.push({name:c,property:a,content:u})});try{const n=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","x-agent-id":e,referer:typeof window!="undefined"?window.location.href:""},body:JSON.stringify({meta_tags:i,url:typeof window!="undefined"?window.location.href:""})});return n.ok?await n.json():void 0}catch{return}}const globalMedAssistConfig={},getWidgetElement=()=>typeof document=="undefined"?null:document.querySelector("eka-medassist-widget");if(typeof window!="undefined"){const e=window;e.__ekaMedAssistConfig__=globalMedAssistConfig,e.EkaMedAssist={init(t){var o,i,n;Object.assign(globalMedAssistConfig,t);const s=getWidgetElement();if(s){if(t.agentId&&s.setAttribute("agent-id",t.agentId),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")&&s.setAttribute("display-mode",t.displayMode),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),!((o=t.theme)===null||o===void 0)&&o.backgroundImage&&preloadImage(t.theme.backgroundImage),(n=(i=s).openFromBridge)===null||n===void 0||n.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 e=scriptEl.dataset.widgetAssets;if(e==="local")return`${scriptBaseUrl}src/`;if(e&&e.length>0)try{return new URL(e,scriptBaseUrl).href}catch{return e.endsWith("/")?e:`${e}/`}return DEFAULT_WIDGET_ASSET_BASE})(),WIDGET_JS_URL=`${widgetAssetBaseUrl}medassist-widget.js`,WIDGET_CSS_URL=`${widgetAssetBaseUrl}medassist-widget.css`;let widgetScriptPromise=null,widgetCssTextPromise=null;function getWidgetCssTextPromise(){return widgetCssTextPromise||(widgetCssTextPromise=fetch(WIDGET_CSS_URL).then(e=>{if(!e.ok)throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);return e.text()})),widgetCssTextPromise}class MedAssistWidgetLoader extends HTMLElement{getAgentConfig(){if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},o=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",i=t.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);this.agentConfigPromise=fetchAgentConfig(o,i).catch(()=>{})}return this.agentConfigPromise}constructor(){super(),this.reactRoot=null,this.agentConfigPromise=null,this.attachShadow({mode:"open"}),this.defaultIconUrl="https://cdn.eka.care/bot-icon.svg",this.widgetLoaded=!1,this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.setupAuthExpirationListener()}static get observedAttributes(){return["icon-url","display-mode","custom-launcher-styles"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadWidgetCss().then(()=>this.loadWidgetScript()).then(()=>this.loadAndRender()).catch(t=>{console.error("Failed to load MedAssist widget in full mode",t)})):(this.renderButton(),this.preloadWidgetAssets(),this.initNudge())}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode==="widget"&&this.renderButton(),t==="display-mode"){const o=this.getAttribute("display-mode")==="full"?"full":"widget";o!==this.displayMode&&(this.displayMode=o,o==="full"?this.initializeFullMode():this.renderButton())}t==="custom-launcher-styles"&&this.applyCustomLauncherStyles()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetScript(),this.preloadBackgroundImage()}preloadBackgroundImage(){var t;const o=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,i=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,n=(t=o==null?void 0:o.theme)===null||t===void 0?void 0:t.backgroundImage,s=i==null?void 0:i.backgroundImage;n&&preloadImage(n),s&&s!==n&&preloadImage(s),this.getAgentConfig().then(d=>{var r;const c=(r=d==null?void 0:d.theme)===null||r===void 0?void 0:r.background_img;c&&preloadImage(c)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const t=o=>{var i;((i=o.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(){this.displayMode=this.getAttribute("display-mode")==="full"?"full":"widget",this.displayMode==="full"?this.initializeFullMode():this.renderButton(),this.loadWidgetCss().then(()=>this.loadWidgetScript()).then(()=>this.loadAndRender()).catch(t=>{console.error("Failed to open MedAssist widget from bridge",t)})}async initNudge(){var t,o,i,n;const s=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,d=(s==null?void 0:s.agentId)||this.getAttribute("agent-id")||"";if(!d)return;const r=await this.getAgentConfig();if(!(r!=null&&r.nudge))return;const c=(o=(t=r==null?void 0:r.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&o!==void 0?o:"#ffffff",a=typeof window!="undefined"?window.location.href:"";let u=findCachedNudge(d,a);if(u){const f=Math.floor(Date.now()/1e3);u.data.expiry<=f&&(clearNudgeForPath(d,u.domain,u.path),u=null)}if(!u){const f=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,v=(f==null?void 0:f.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",h=await fetchNudgeData(d,v).catch(()=>{});if(!(!((i=h==null?void 0:h.nudges)===null||i===void 0)&&i.length)||(storeNudgeResponse(d,h),u=findCachedNudge(d,a),!u))return}const m=u.data.nudges[Math.floor(Math.random()*u.data.nudges.length)],p=(n=u.data.delay)!==null&&n!==void 0?n:5;setTimeout(()=>{this.showNudgePopup(m,c)},p*1e3)}showNudgePopup(t,o){var i,n;const s=this.shadowRoot;if(!s||!(!((i=s.getElementById("medassist-widget-root"))===null||i===void 0)&&i.classList.contains("hidden")))return;const r=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(r&&getNudgeCookie(r)!==null||s.getElementById("medassist-nudge-popup"))return;const a=document.createElement("div");a.id="medassist-nudge-popup",a.innerHTML=`
2
2
  <style>
3
3
  @keyframes nudge-slide-up {
4
4
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
@@ -9,7 +9,7 @@
9
9
  bottom: 76px;
10
10
  right: 0;
11
11
  width: 272px;
12
- background: ${n};
12
+ background: ${o};
13
13
  border-radius: 16px;
14
14
  box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
15
15
  padding: 16px 16px 14px 16px;
@@ -29,7 +29,7 @@
29
29
  right: 20px;
30
30
  width: 16px;
31
31
  height: 10px;
32
- background: ${n};
32
+ background: ${o};
33
33
  clip-path: polygon(0 0, 100% 0, 50% 100%);
34
34
  }
35
35
  #medassist-nudge-popup {
@@ -79,7 +79,7 @@
79
79
  <p class="nudge-text">${t.replace(/</g,"&lt;").replace(/>/g,"&gt;")}</p>
80
80
  <button class="nudge-close" aria-label="Dismiss">&#x2715;</button>
81
81
  </div>
82
- `,(i=a.querySelector(".nudge-close"))===null||i===void 0||i.addEventListener("click",u=>{u.stopPropagation(),r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup()}),a.addEventListener("click",()=>{r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),s.appendChild(a)}dismissNudgePopup(){var t;const n=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-nudge-popup");n==null||n.remove()}renderButton(){var t;const n=this.getAttribute("icon-url")||this.defaultIconUrl,o=n==null?void 0:n.toLowerCase().endsWith(".svg"),i=this.shadowRoot;if(!i){console.error("Shadow root was not created");return}if(!i.querySelector("button"))i.innerHTML=`
82
+ `,(n=a.querySelector(".nudge-close"))===null||n===void 0||n.addEventListener("click",u=>{u.stopPropagation(),r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup()}),a.addEventListener("click",()=>{r&&setNudgeCookie(r,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),s.appendChild(a)}dismissNudgePopup(){var t;const o=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-nudge-popup");o==null||o.remove()}applyCustomLauncherStyles(){var t;const o=this.shadowRoot;if(!o||this.displayMode!=="widget")return;const i=o.querySelector('style[data-medassist-custom-launcher="true"]'),n=(t=this.getAttribute("custom-launcher-styles"))!==null&&t!==void 0?t:"";if(!n){i==null||i.remove();return}if(i){i.textContent=n;return}const s=document.createElement("style");s.setAttribute("data-medassist-custom-launcher","true"),s.textContent=n,o.appendChild(s)}renderButton(){var t;const o=this.getAttribute("icon-url")||this.defaultIconUrl,i=this.shadowRoot;if(!i){console.error("Shadow root was not created");return}if(!i.querySelector("button"))i.innerHTML=`
83
83
  <style>
84
84
  #medassist-open-btn {
85
85
  width: 60px;
@@ -97,22 +97,8 @@
97
97
  #medassist-open-btn img {
98
98
  width: 60px;
99
99
  height: 60px;
100
+ border-radius: 50%;
100
101
  object-fit: cover;
101
- /* Use clip-path (vector clip) instead of border-radius
102
- (which iOS implements via a raster mask and blurs SVGs). */
103
- -webkit-clip-path: circle(50%);
104
- clip-path: circle(50%);
105
- }
106
- /* iOS picks a raster buffer for SVG <img> based on box size, so we
107
- render the image at 2\xD7 and scale it down. The translate3d also
108
- promotes the element to its own compositing layer. */
109
- #medassist-open-btn img.is-svg {
110
- width: 120px;
111
- height: 120px;
112
- -webkit-transform: translate3d(0, 0, 0) scale(0.5);
113
- transform: translate3d(0, 0, 0) scale(0.5);
114
- transform-origin: center center;
115
- shape-rendering: geometricPrecision;
116
102
  }
117
103
  :host {
118
104
  position: fixed;
@@ -132,10 +118,10 @@
132
118
  </style>
133
119
 
134
120
  <button id="medassist-open-btn">
135
- <img src="${n}" alt="MedAssist Icon"${o?' class="is-svg"':""}>
121
+ <img src="${o}" alt="MedAssist Icon">
136
122
  </button>
137
123
  <div id="medassist-widget-root" class="hidden"></div>
138
- `,(t=i.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const d=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.loadAndRender()});else{const s=i.querySelector("#medassist-open-btn img");s&&(s.src=n,s.classList.toggle("is-svg",!!o))}}initializeFullMode(){const t=this.shadowRoot;if(!t){console.error("Shadow root is not available");return}t.getElementById("medassist-widget-root")||(t.innerHTML=`
124
+ `,(t=i.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>{const s=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";s&&setNudgeCookie(s,"closed"),this.dismissNudgePopup(),this.loadAndRender()});else{const n=i.querySelector("#medassist-open-btn img");n&&(n.src=o)}this.applyCustomLauncherStyles()}initializeFullMode(){const t=this.shadowRoot;if(!t){console.error("Shadow root is not available");return}t.getElementById("medassist-widget-root")||(t.innerHTML=`
139
125
  <style>
140
126
  :host {
141
127
  display: block;
@@ -152,4 +138,4 @@
152
138
  }
153
139
  </style>
154
140
  <div id="medassist-widget-root"></div>
155
- `)}async loadAndRender(){var t,n,o;const i=this.shadowRoot;if(!i){console.error("Shadow root is not available");return}this.style.display="";const s=i.getElementById("medassist-open-btn"),d=i.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let c=this.getAttribute("icon-url")||this.defaultIconUrl;const a=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production",u=this.getAttribute("connectivity"),m=u==="sse"||u==="socket"?u:void 0;let h=this.getAttribute("title")||"Medi Clinic";const f=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",p=this.getAttribute("display-mode")==="full"?"full":"widget",E=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,S=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,g=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},M={...E||{},...g.context||{}},I=g.auth||void 0,w=g.agentId||r,U=g.baseUrl||f,b=typeof window!="undefined"?(n=window.EkaMedAssist)===null||n===void 0?void 0:n.onClose:void 0;if(!w){console.error("Agent ID is required");return}if(!d){console.error("Widget root element is missing");return}s&&s.classList.add("hidden"),d.classList.remove("hidden");let x,A,_,k=!1;try{const l=await this.getAgentConfig();h=(l==null?void 0:l.name)||h,c=((o=l==null?void 0:l.theme)===null||o===void 0?void 0:o.icon_img)||c,x=mapAgentConfigThemeToWidgetTheme((l==null?void 0:l.theme)||void 0),A=l==null?void 0:l.allowed,_=l==null?void 0:l.connectivity,k=(l==null?void 0:l.resize)||(g==null?void 0:g.resize)||!1}catch{}const L=_||m||"socket",C={title:g.title||h,iconUrl:c||g.iconUrl,allowed:A,environment:a,connectionType:L,onClose:()=>{var l;(l=this.reactRoot)===null||l===void 0||l.unmount(),this.reactRoot=null,b&&typeof b=="function"&&b(),p==="full"?this.style.display="none":(s&&s.classList.remove("hidden"),d.classList.add("hidden"))},baseUrl:U,context:M,displayMode:p,resize:k||this.getAttribute("resize")==="true",auth:I,theme:{...x||{},...S||{},...g.theme||{}}},v=window;if(this.widgetLoaded){this.reactRoot=v.renderMedAssist(d,w,C);return}try{if(await Promise.all([this.loadWidgetCss(),this.loadWidgetScript()]),typeof v.renderMedAssist!="function")throw new Error("renderMedAssist is not available on window");this.reactRoot=v.renderMedAssist(d,w,C),this.widgetLoaded=!0}catch(l){console.error("Failed to load MedAssist widget",l),s&&s.classList.remove("hidden"),d.classList.add("hidden")}}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 n=await getWidgetCssTextPromise(),o=document.createElement("style");o.setAttribute("data-medassist-style","true"),o.textContent=n,t.appendChild(o)}loadWidgetScript(){return widgetScriptPromise||(widgetScriptPromise=new Promise((t,n)=>{const o=document.querySelector(`script[src="${WIDGET_JS_URL}"]`);if(o){if(o.dataset.loaded==="true"){t();return}o.addEventListener("load",()=>t()),o.addEventListener("error",s=>n(s.error||new Error("Unknown script loading error")));return}const i=document.createElement("script");i.src=WIDGET_JS_URL,i.async=!0,i.dataset.widget="medassist",i.onload=()=>{i.dataset.loaded="true",t()},i.onerror=s=>{if(s instanceof ErrorEvent&&s.error){n(s.error);return}n(new Error(`Failed to load ${WIDGET_JS_URL}`))},document.head.appendChild(i)})),widgetScriptPromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
141
+ `)}async loadAndRender(){var t,o,i;const n=this.shadowRoot;if(!n){console.error("Shadow root is not available");return}this.style.display="";const s=n.getElementById("medassist-open-btn"),d=n.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let c=this.getAttribute("icon-url")||this.defaultIconUrl;const a=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production",u=this.getAttribute("connectivity"),m=u==="sse"||u==="socket"?u:void 0;let p=this.getAttribute("title")||"Medi Clinic";const f=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",h=this.getAttribute("display-mode")==="full"?"full":"widget",E=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,S=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,g=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},M={...E||{},...g.context||{}},I=g.auth||void 0,w=g.agentId||r,L=g.baseUrl||f,y=typeof window!="undefined"?(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onClose:void 0;if(!w){console.error("Agent ID is required");return}if(!d){console.error("Widget root element is missing");return}s&&s.classList.add("hidden"),d.classList.remove("hidden");let x,A,_,C=!1;try{const l=await this.getAgentConfig();p=(l==null?void 0:l.name)||p,c=((i=l==null?void 0:l.theme)===null||i===void 0?void 0:i.icon_img)||c,x=mapAgentConfigThemeToWidgetTheme((l==null?void 0:l.theme)||void 0),A=l==null?void 0:l.allowed,_=l==null?void 0:l.connectivity,C=(l==null?void 0:l.resize)||(g==null?void 0:g.resize)||!1}catch{}const U=_||m||"socket",k={title:g.title||p,iconUrl:c||g.iconUrl,allowed:A,environment:a,connectionType:U,onClose:()=>{var l;(l=this.reactRoot)===null||l===void 0||l.unmount(),this.reactRoot=null,y&&typeof y=="function"&&y(),h==="full"?this.style.display="none":(s&&s.classList.remove("hidden"),d.classList.add("hidden"))},baseUrl:L,context:M,displayMode:h,resize:C||this.getAttribute("resize")==="true",auth:I,theme:{...x||{},...S||{},...g.theme||{}}},b=window;if(this.widgetLoaded){this.reactRoot=b.renderMedAssist(d,w,k);return}try{if(await Promise.all([this.loadWidgetCss(),this.loadWidgetScript()]),typeof b.renderMedAssist!="function")throw new Error("renderMedAssist is not available on window");this.reactRoot=b.renderMedAssist(d,w,k),this.widgetLoaded=!0}catch(l){console.error("Failed to load MedAssist widget",l),s&&s.classList.remove("hidden"),d.classList.add("hidden")}}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 o=await getWidgetCssTextPromise(),i=document.createElement("style");i.setAttribute("data-medassist-style","true"),i.textContent=o,t.appendChild(i)}loadWidgetScript(){return widgetScriptPromise||(widgetScriptPromise=new Promise((t,o)=>{const i=document.querySelector(`script[src="${WIDGET_JS_URL}"]`);if(i){if(i.dataset.loaded==="true"){t();return}i.addEventListener("load",()=>t()),i.addEventListener("error",s=>o(s.error||new Error("Unknown script loading error")));return}const n=document.createElement("script");n.src=WIDGET_JS_URL,n.async=!0,n.dataset.widget="medassist",n.onload=()=>{n.dataset.loaded="true",t()},n.onerror=s=>{if(s instanceof ErrorEvent&&s.error){o(s.error);return}o(new Error(`Failed to load ${WIDGET_JS_URL}`))},document.head.appendChild(n)})),widgetScriptPromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/medassist-widget-embed",
3
- "version": "0.2.36",
3
+ "version": "0.2.37",
4
4
  "description": "Embeddable MedAssist widget loader built with Web Components.",
5
5
  "author": "Geethanjali S",
6
6
  "license": "MIT",