@eka-care/medassist-widget-embed 0.2.117 → 0.2.118

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
@@ -61,6 +61,7 @@ The widget appears as a floating button; clicking it loads and opens the chat.
61
61
  - **`side-panel-mode`** – `"push"` (default) or `"overlay"`; only used with `display-mode="side_panel"`
62
62
  - **`side-panel-width`** – panel width in px, clamped to 320–560 (default 400); side panel only
63
63
  - **`side`** – `"right"` (default) or `"left"`; defaults to `"left"` on RTL documents; side panel only
64
+ - **`override-widget-width`** / **`override-widget-height`** – size of the floating window in px (positive numbers; anything else is ignored). Floating mode on desktop only: full page, side panel and the mobile layout keep their own sizing. Clamped to 320–800 wide and 480–900 high, and never larger than the viewport minus 20px on each side. They override the agent config's `theme.widget_width` / `theme.widget_height`; precedence per dimension is host override → agent config → default 384×600
64
65
  - **`context`** – JSON string of context key-value pairs
65
66
 
66
67
  ### Programmatic config with `EkaMedAssist.init()`
@@ -78,6 +79,8 @@ window.EkaMedAssist.init({
78
79
  background: "#1a1738",
79
80
  primary: "#09FBD3",
80
81
  textColor: "white",
82
+ overrideWidgetWidth: 480, // floating window size in px (same as the override-widget-* attributes)
83
+ overrideWidgetHeight: 720,
81
84
  },
82
85
  });
83
86
  ```
@@ -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.139/dist/medassist-widget.js"
21
+ href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.140/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.139/dist/medassist-widget.css"
30
+ href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.140/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.139/dist/medassist-widget.css"
37
+ href="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.140/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.139/dist/medassist-widget.js"
152
+ src="https://cdn.jsdelivr.net/npm/@eka-care/medassist-widget@0.1.140/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.139/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)}})();
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.140/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
@@ -38,6 +38,14 @@ type AgentConfig = {
38
38
  tips?: string[];
39
39
  /** Feature flag — currently gates the chat-history UI (session drawer + fullscreen sidebar). */
40
40
  feature?: boolean;
41
+ /** Floating-widget width in px (desktop "widget" mode only). Clamped by the widget. */
42
+ widget_width?: number;
43
+ /** Floating-widget height in px (desktop "widget" mode only). Clamped by the widget. */
44
+ widget_height?: number;
45
+ /** How the closed widget is shown ("widget" mode only). Host `launcher-type` wins. Default "button". */
46
+ launcher_type?: "button" | "chatbox";
47
+ /** Launcher CSS, applied over the defaults. Host `custom-launcher-styles` wins over it. */
48
+ launcher_styles?: string;
41
49
  };
42
50
  initial_message?: {
43
51
  text?: string;
@@ -78,6 +86,8 @@ type MedAssistInitConfig = {
78
86
  /** Only relevant when displayMode is "side_panel". Which viewport edge the panel docks to. Defaults to "right", or "left" when the document is RTL. */
79
87
  side?: "left" | "right";
80
88
  customLauncherStyles?: string;
89
+ /** "widget" mode only. "chatbox" shows a message box instead of the round button; the widget opens on send. Default "button". */
90
+ launcherType?: "button" | "chatbox";
81
91
  redirectUrl?: string;
82
92
  showCloseButton?: boolean;
83
93
  theme?: {
@@ -93,6 +103,12 @@ type MedAssistInitConfig = {
93
103
  upfrontConsent?: boolean;
94
104
  tips?: string[];
95
105
  feature?: boolean;
106
+ /** Floating-widget size (px) from the agent config. Overridden by the `override…` keys below. */
107
+ widgetWidth?: number;
108
+ widgetHeight?: number;
109
+ /** Host-set floating-widget size (px). Wins over the agent config. */
110
+ overrideWidgetWidth?: number;
111
+ overrideWidgetHeight?: number;
96
112
  };
97
113
  [key: string]: unknown;
98
114
  };
@@ -108,6 +124,14 @@ declare function preloadImage(url: string): void;
108
124
  */
109
125
  type SynapseChannel = "widget" | "web" | "side_panel";
110
126
  declare function channelFromDisplayMode(displayMode: string | null | undefined): SynapseChannel;
127
+ declare function prefersReducedMotion(): boolean;
128
+ declare function nextFrame(): Promise<void>;
129
+ /**
130
+ * Icon colour on the accent: near-black on light accents, near-white on dark
131
+ * ones — the HSL-lightness > 50% rule of the widget's calculateForegroundColor.
132
+ * Non-hex colours can't be measured here and get near-white.
133
+ */
134
+ declare function colorOnAccent(color: string): string;
111
135
  /** Normalizes the `display-mode` attribute value to one of the three supported modes. */
112
136
  declare function normalizeDisplayMode(value: string | null | undefined): "full" | "widget" | "side_panel";
113
137
  type NudgeApiResponse = {
@@ -261,6 +285,21 @@ declare class MedAssistWidgetLoader extends HTMLElement {
261
285
  * - "open" → hidden (widget is mounted)
262
286
  */
263
287
  private setLauncherState;
288
+ private launcherState;
289
+ /**
290
+ * Launcher kind: host `launcher-type` attribute / init({ launcherType }),
291
+ * then agent-config `theme.launcher_type` (cached copy), then "button".
292
+ * The chatbox exists only in floating "widget" mode.
293
+ */
294
+ private getLauncherType;
295
+ private isChatboxShown;
296
+ /**
297
+ * Show the button or the chatbox for the current launcher state:
298
+ * - "idle" → chatbox (or button when the launcher is a button)
299
+ * - "loading" → button: spinner in its place; chatbox: "sending" look, input locked
300
+ * - "open" → both hidden (widget is mounted)
301
+ */
302
+ private updateLauncherView;
264
303
  /**
265
304
  * `x-channel` for every request this loader makes, from how the widget is set
266
305
  * to open. The attribute wins; `init({ displayMode })` covers calls made
@@ -341,6 +380,8 @@ declare class MedAssistWidgetLoader extends HTMLElement {
341
380
  private showNudgePopup;
342
381
  private dismissNudgePopup;
343
382
  private applyCustomLauncherStyles;
383
+ /** Agent-config launcher CSS tag, kept before the host's tag so the host's rules win. */
384
+ private setLauncherStyleTag;
344
385
  /** Agent id from init() or the attribute — the same precedence as everywhere else in this loader. */
345
386
  private getAgentId;
346
387
  /** Bumped on every renderLauncher() call so an older, still-awaiting resolution never overwrites a newer one. */
@@ -359,6 +400,13 @@ declare class MedAssistWidgetLoader extends HTMLElement {
359
400
  private renderLauncher;
360
401
  /** Set (or clear) the launcher image and reveal the launcher. */
361
402
  private setLauncherIcon;
403
+ /**
404
+ * Chatbox colours, with the same precedence the widget's theme uses:
405
+ * init({ theme }), then the `theme` attribute, then agent-config (cached)
406
+ * `accent` / `mode`. Nothing usable (no config yet, fetch failed) → the CSS
407
+ * fallbacks, which are the widget's own defaults.
408
+ */
409
+ private applyChatboxTheme;
362
410
  /**
363
411
  * Render the launcher skeleton (idempotent). The launcher starts `pending`
364
412
  * (not displayed) and is revealed by setLauncherIcon() once renderLauncher()
@@ -366,7 +414,17 @@ declare class MedAssistWidgetLoader extends HTMLElement {
366
414
  */
367
415
  renderButton(): void;
368
416
  initializeFullMode(): void;
369
- loadAndRender(): Promise<void>;
417
+ /** `firstUserMessage`: text sent from the chatbox launcher; the widget sends it once connected. */
418
+ loadAndRender(firstUserMessage?: string): Promise<void>;
419
+ /**
420
+ * Chatbox → widget opening animation. The freshly mounted window starts as
421
+ * the chatbox — same spot, same size, its bottom (the composer) where the
422
+ * chatbox was — then unfolds upward and slides to its own position. A
423
+ * clip-path reveal, not a scale, so the content never looks stretched.
424
+ * Resolves once the animation has started (the chatbox can then be hidden
425
+ * underneath it); never throws — worst case the widget just appears.
426
+ */
427
+ private growWidgetFromChatbox;
370
428
  loadWidgetCss(): Promise<void>;
371
429
  loadWidgetModule(): Promise<WidgetModule>;
372
430
  }
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 e=Array.from(document.getElementsByTagName("script")),t=e.find(o=>o.hasAttribute("data-widget-assets"));if(t)return t;const i=e.filter(o=>/(^|\/)index\.js(\?.*)?$/.test(o.src));return i.length?i[i.length-1]:e.length?e[e.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.139/dist/"})();var FeedbackTypeEnum;(function(n){n.DEFAULT="default",n.NPS="nps"})(FeedbackTypeEnum||(FeedbackTypeEnum={}));function mapAgentConfigThemeToWidgetTheme(n){var e;if(!n)return;const t=n.mode==="dark"?"white":n.mode==="light"?"black":void 0;return{...n.background_img&&{backgroundImage:n.background_img},...n.accent&&{primary:n.accent},...t&&{textColor:t},...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},...((e=n.tips)===null||e===void 0?void 0:e.length)&&{tips:n.tips},...n.feature!==void 0&&{feature:n.feature}}}function preloadImage(n){if(!(!n||typeof document=="undefined"))try{const e=document.createElement("link");e.rel="preload",e.as="image",e.href=n,document.head.appendChild(e)}catch{const e=new Image;e.src=n}}function channelFromDisplayMode(n){return n==="full"?"web":n==="side_panel"?"side_panel":"widget"}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 e=localStorage.getItem(AGENT_CONFIG_CACHE_KEY);return(e?JSON.parse(e):{})[n]}catch{return}}function writeAgentConfigCache(n,e){try{const t=localStorage.getItem(AGENT_CONFIG_CACHE_KEY),i=t?JSON.parse(t):{};i[n]={...i[n]||{},...e},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 e=n.replace(/\/+$/,"");return e.startsWith("/")||(e="/"+e),e||"/"}function getNudgePathCandidates(n){const e=n.split("/").filter(Boolean),t=[];for(let i=e.length;i>=0;i--)t.push(i===0?"/":"/"+e.slice(0,i).join("/"));return t}function findCachedNudgeForCandidates(n,e,t){const o=getNudgeStore()[n];if(!o)return null;const s=e.host,r=o[s];if(!r)return null;for(const d of t){if(r[d]!==void 0)return{domain:s,path:d,data:r[d]};const a=d==="/"?"/*":d+"/*";if(r[a]!==void 0)return{domain:s,path:a,data:r[a]}}return null}function findFreshCachedNudge(n,e,t){const i=findCachedNudgeForCandidates(n,e,t);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,e,t){const i=getNudgeStore(),o=i[n];!o||!o[e]||(delete o[e][t],setNudgeStore(i))}function storeNudgeResponse(n,e,t){var i,o,s,r;const d=(i=e==null?void 0:e.url_pattern)===null||i===void 0?void 0:i.domain,a=(o=e==null?void 0:e.url_pattern)===null||o===void 0?void 0:o.path;if(!(!((s=e.nudges)===null||s===void 0)&&s.length)||!e.expiry||!d||!a)return;const l=getNudgeStore();l[n]||(l[n]={}),l[n][d]||(l[n][d]={});const h={nudges:e.nudges,expiry:e.expiry,delay:(r=e.delay)!==null&&r!==void 0?r:5};l[n][d][a]=h,t&&t!==a&&(l[n][d][t]=h),setNudgeStore(l)}const NUDGE_COOKIE_PREFIX="eka-nudge";function setNudgeCookie(n,e){const t=new Date(Date.now()+864e5).toUTCString();document.cookie=`${NUDGE_COOKIE_PREFIX}-${n}=${e}; expires=${t}; path=/; SameSite=Lax`}function getNudgeCookie(n){const e=document.cookie.split(";").map(i=>i.trim()).find(i=>i.startsWith(`${NUDGE_COOKIE_PREFIX}-${n}=`));if(!e)return null;const t=e.split("=")[1];return t==="open"||t==="closed"?t:null}const WIDGET_STORE_KEY_PREFIX="med-assist-store-";function readPersistedSessToken(n){var e,t;try{const i=sessionStorage.getItem(`${WIDGET_STORE_KEY_PREFIX}${n}`),o=i?(t=(e=JSON.parse(i))===null||e===void 0?void 0:e.state)===null||t===void 0?void 0:t.sessToken:void 0;return typeof o=="string"&&o?o:void 0}catch{return}}async function fetchNudgeData(n,e,t,i="widget"){const o=`${t}/med-assist/user-nudge`,s=[];typeof document!="undefined"&&document.querySelectorAll("meta").forEach(r=>{var d,a,l;const h=(d=r.getAttribute("name"))!==null&&d!==void 0?d:void 0,f=(a=r.getAttribute("property"))!==null&&a!==void 0?a:void 0,p=(l=r.getAttribute("content"))!==null&&l!==void 0?l:void 0;(h||f)&&s.push({name:h,property:f,content:p})});try{const r=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 ${e}`},body:JSON.stringify({meta_tags:s,url:typeof window!="undefined"?window.location.href:""})});return r.ok?await r.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(e){var t,i,o;Object.assign(globalMedAssistConfig,e);const s=getWidgetElement();if(s){if(e.agentId&&s.setAttribute("agent-id",e.agentId),e.authToken&&s.setAttribute("auth-token",e.authToken),e.title&&s.setAttribute("title",e.title),e.iconUrl&&s.setAttribute("icon-url",e.iconUrl),e.baseUrl&&s.setAttribute("base-url",e.baseUrl),e.resize!==void 0&&s.setAttribute("resize",String(e.resize)),(e.displayMode==="full"||e.displayMode==="widget"||e.displayMode==="side_panel")&&s.setAttribute("display-mode",e.displayMode),e.sidePanelMode&&s.setAttribute("side-panel-mode",e.sidePanelMode),e.sidePanelWidth!==void 0&&s.setAttribute("side-panel-width",String(e.sidePanelWidth)),e.side&&s.setAttribute("side",e.side),e.context)try{s.setAttribute("context",JSON.stringify(e.context))}catch{console.warn("Failed to stringify context passed to init")}typeof e.customLauncherStyles=="string"&&s.setAttribute("custom-launcher-styles",e.customLauncherStyles),e.redirectUrl&&s.setAttribute("redirect-url",e.redirectUrl),!((t=e.theme)===null||t===void 0)&&t.backgroundImage&&preloadImage(e.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(e){var t;const i=(t=this.shadowRoot)===null||t===void 0?void 0:t.getElementById("medassist-open-btn");i&&(i.classList.toggle("loading",e==="loading"),i.classList.toggle("hidden",e==="open"),e==="loading"?i.setAttribute("aria-busy","true"):i.removeAttribute("aria-busy"))}getChannel(){const e=this.getAttribute("display-mode");if(e)return channelFromDisplayMode(e);const t=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0;return channelFromDisplayMode(t==null?void 0:t.displayMode)}getAgentConfig(){var e;if(!this.agentConfigPromise){const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=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);const s=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production";this.agentConfigPromise=this.loadWidgetModule().then(r=>{var d;return(d=r.fetchAgentConfig)===null||d===void 0?void 0:d.call(r,{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.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"]}connectedCallback(){this.displayMode==="full"?(this.initializeFullMode(),this.loadAndRender().catch(e=>{console.error("Failed to load MedAssist widget in full mode",e)})):(this.renderLauncher(),this.scheduleIdle(()=>{this.preloadWidgetAssets(),this.prefetchAuthTokens(),this.initNudge()}))}disconnectedCallback(){var e,t,i,o,s;(e=this.reactRoot)===null||e===void 0||e.unmount(),this.reactRoot=null,(t=document.body)===null||t===void 0||t.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(e,t,i){var o;if(typeof document=="undefined")return;const s=e?{width:t,side:i}:null,r=this.hostPushState;if(r===s||r&&s&&r.width===s.width&&r.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 d=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: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/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=`
2
2
  body.eka-medassist-pushed {
3
- ${d}: ${t}px;
3
+ ${a}: ${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 a=document.documentElement.style;e?(a.setProperty("--eka-medassist-panel-width",`${t}px`),a.setProperty("--eka-medassist-panel-side",i),document.body.classList.add("eka-medassist-pushed")):(document.body.classList.remove("eka-medassist-pushed"),a.removeProperty("--eka-medassist-panel-width"),a.removeProperty("--eka-medassist-panel-side"),this.hostPushStyleEl.remove(),this.hostPushStyleEl=null);const l={pushed:e,width:t,side:i};if(typeof window!="undefined"){try{window.dispatchEvent(new CustomEvent(SIDE_PANEL_PUSH_EVENT,{detail:l}))}catch{}const h=(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onSidePanelPushChange;if(typeof h=="function")try{h(e,t,i)}catch(f){console.error("EkaMedAssist.onSidePanelPushChange threw",f)}}}scheduleIdle(e){if(typeof window=="undefined"){e();return}const t=window.requestIdleCallback;typeof t=="function"?t(e,{timeout:3e3}):setTimeout(e,200)}attributeChangedCallback(e){if(e==="icon-url"&&this.displayMode!=="full"&&this.renderLauncher(),e==="display-mode"){const t=normalizeDisplayMode(this.getAttribute("display-mode"));t!==this.displayMode&&(this.displayMode=t,t==="full"?this.initializeFullMode():this.renderLauncher())}e==="custom-launcher-styles"&&this.applyCustomLauncherStyles()}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetModule(),this.preloadBackgroundImage()}prefetchAuthTokens(){var e;if(this.authPrefetchPromise)return this.authPrefetchPromise;const t=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},i=t.agentId||this.getAttribute("agent-id")||"";if(!i)return Promise.resolve(void 0);const o=t.authToken||this.getAttribute("auth-token")||void 0,s=t.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",r=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production";return this.authPrefetchPromise=this.loadWidgetModule().then(d=>{var a;return(a=d.prefetchAuth)===null||a===void 0?void 0:a.call(d,{agentId:i,authToken:o,serverUrl:s,environment:r,channel:this.getChannel()})}).catch(()=>{this.authPrefetchPromise=null}),this.authPrefetchPromise}async resolveSessToken(e){const t=readPersistedSessToken(e);if(t)return t;const i=await this.prefetchAuthTokens();return(i==null?void 0:i.sess_token)||readPersistedSessToken(e)}preloadBackgroundImage(){var e;const t=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,i=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(e=t==null?void 0:t.theme)===null||e===void 0?void 0:e.backgroundImage,s=i==null?void 0:i.backgroundImage;o&&preloadImage(o),s&&s!==o&&preloadImage(s),this.getAgentConfig().then(r=>{var d;const a=(d=r==null?void 0:r.theme)===null||d===void 0?void 0:d.background_img;a&&preloadImage(a)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const e=t=>{var i;((i=t.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",e)}openFromBridge(){this.displayMode=normalizeDisplayMode(this.getAttribute("display-mode")),this.displayMode==="full"?this.initializeFullMode():this.renderLauncher(),this.loadAndRender().catch(e=>{console.error("Failed to open MedAssist widget from bridge",e)})}async initNudge(){var e,t,i,o;const s=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,r=(s==null?void 0:s.agentId)||this.getAttribute("agent-id")||"";if(!r)return;const d=await this.getAgentConfig();if(!(d!=null&&d.nudge))return;const a=(t=(e=d==null?void 0:d.theme)===null||e===void 0?void 0:e.nudge_color)!==null&&t!==void 0?t:"#ffffff",l=typeof window!="undefined"?window.location.href:"";let h;try{h=new URL(l)}catch{return}const f=getNudgePathCandidates(h.pathname),p=f.slice(0,1),y=f.slice(1);let g=findFreshCachedNudge(r,h,p);if(!g){const w=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",m=await this.resolveSessToken(r).catch(()=>{});if(m){const u=await fetchNudgeData(r,m,w,this.getChannel()).catch(()=>{});!((i=u==null?void 0:u.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(r,u,normalizePath(h.pathname)),g=findFreshCachedNudge(r,h,f))}}if(g||(g=findFreshCachedNudge(r,h,y)),!g)return;const v=g.data.nudges[Math.floor(Math.random()*g.data.nudges.length)],b=(o=g.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(v,a)},b*1e3)}showNudgePopup(e,t){var i,o;const s=this.shadowRoot;if(!s||!(!((i=s.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||s.getElementById("medassist-nudge-popup"))return;const l=s.getElementById("medassist-open-btn"),h=l==null?void 0:l.getBoundingClientRect(),f=272,p=12,y=8,g=16,v=16;let b=window.innerWidth-f-p,w=76,m=f-g-y*2;if(h&&h.width>0){const A=h.left+h.width/2,S=A-f/2,C=window.innerWidth-f-p;b=Math.max(p,Math.min(S,C)),w=window.innerHeight-h.top+v,m=Math.max(g,Math.min(A-b-y,f-g-y*2))}const u=document.createElement("div");u.id="medassist-nudge-popup",u.innerHTML=`
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 u=(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onSidePanelPushChange;if(typeof u=="function")try{u(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,s=e.baseUrl||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",d=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";return this.authPrefetchPromise=this.loadWidgetModule().then(a=>{var r;return(r=a.prefetchAuth)===null||r===void 0?void 0:r.call(a,{agentId:i,authToken:o,serverUrl:s,environment:d,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,s=i==null?void 0:i.backgroundImage;o&&preloadImage(o),s&&s!==o&&preloadImage(s),this.getAgentConfig().then(d=>{var a;const r=(a=d==null?void 0:d.theme)===null||a===void 0?void 0:a.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 s=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,d=(s==null?void 0:s.agentId)||this.getAttribute("agent-id")||"";if(!d)return;const a=await this.getAgentConfig();if(!(a!=null&&a.nudge))return;const r=(e=(t=a==null?void 0:a.theme)===null||t===void 0?void 0:t.nudge_color)!==null&&e!==void 0?e:"#ffffff",l=typeof window!="undefined"?window.location.href:"";let u;try{u=new URL(l)}catch{return}const h=getNudgePathCandidates(u.pathname),b=h.slice(0,1),w=h.slice(1);let g=findFreshCachedNudge(d,u,b);if(!g){const x=(s==null?void 0:s.baseUrl)||this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",A=await this.resolveSessToken(d).catch(()=>{});if(A){const f=await fetchNudgeData(d,A,x,this.getChannel()).catch(()=>{});!((i=f==null?void 0:f.nudges)===null||i===void 0)&&i.length&&(storeNudgeResponse(d,f,normalizePath(u.pathname)),g=findFreshCachedNudge(d,u,h))}}if(g||(g=findFreshCachedNudge(d,u,w)),!g)return;const C=g.data.nudges[Math.floor(Math.random()*g.data.nudges.length)],y=(o=g.data.delay)!==null&&o!==void 0?o:5;setTimeout(()=>{this.showNudgePopup(C,r)},y*1e3)}showNudgePopup(t,e){var i,o;const s=this.shadowRoot;if(!s||!(!((i=s.getElementById("medassist-widget-root"))===null||i===void 0)&&i.classList.contains("hidden")))return;const a=((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||"";if(a&&getNudgeCookie(a)!==null||s.getElementById("medassist-nudge-popup"))return;const l=this.isChatboxShown()?s.getElementById("medassist-chatbox"):s.getElementById("medassist-open-btn"),u=l==null?void 0:l.getBoundingClientRect(),h=272,b=12,w=8,g=16,C=16;let y=window.innerWidth-h-b,x=76,A=h-g-w*2;if(u&&u.width>0){const m=u.left+u.width/2,p=m-h/2,E=window.innerWidth-h-b;y=Math.max(b,Math.min(p,E)),x=window.innerHeight-u.top+C,A=Math.max(g,Math.min(m-y-w,h-g-w*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,10 +17,10 @@
17
17
  }
18
18
  #medassist-nudge-popup {
19
19
  position: fixed;
20
- bottom: ${w}px;
21
- left: ${b}px;
22
- width: ${f}px;
23
- background: ${t};
20
+ bottom: ${x}px;
21
+ left: ${y}px;
22
+ width: ${h}px;
23
+ background: ${e};
24
24
  border-radius: 16px;
25
25
  box-shadow: 0 8px 32px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
26
26
  padding: 16px 16px 14px 16px;
@@ -37,10 +37,10 @@
37
37
  content: '';
38
38
  position: absolute;
39
39
  bottom: -8px;
40
- left: ${m}px;
40
+ left: ${A}px;
41
41
  width: 16px;
42
42
  height: 10px;
43
- background: ${t};
43
+ background: ${e};
44
44
  clip-path: polygon(0 0, 100% 0, 50% 100%);
45
45
  }
46
46
  #medassist-nudge-popup {
@@ -87,10 +87,10 @@
87
87
  }
88
88
  </style>
89
89
  <div class="nudge-header">
90
- <p class="nudge-text">${e.replace(/</g,"&lt;").replace(/>/g,"&gt;")}</p>
90
+ <p class="nudge-text">${t.replace(/</g,"&lt;").replace(/>/g,"&gt;")}</p>
91
91
  <button class="nudge-close" aria-label="Dismiss">&#x2715;</button>
92
92
  </div>
93
- `,(o=u.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",A=>{A.stopPropagation(),d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup()}),u.addEventListener("click",()=>{d&&setNudgeCookie(d,"closed"),this.dismissNudgePopup(),this.loadAndRender()}),s.appendChild(u)}dismissNudgePopup(){var e;const t=(e=this.shadowRoot)===null||e===void 0?void 0:e.getElementById("medassist-nudge-popup");t==null||t.remove()}applyCustomLauncherStyles(){var e;const t=this.shadowRoot;if(!t||this.displayMode==="full")return;const i=t.querySelector('style[data-medassist-custom-launcher="true"]'),o=(e=this.getAttribute("custom-launcher-styles"))!==null&&e!==void 0?e:"";if(!o){i==null||i.remove();return}if(i){i.textContent=o;return}const s=document.createElement("style");s.setAttribute("data-medassist-custom-launcher","true"),s.textContent=o,t.appendChild(s)}getAgentId(){return((typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{}).agentId||this.getAttribute("agent-id")||""}async renderLauncher(){var e,t;if(this.displayMode==="full")return;const i=++this.launcherRenderSeq;this.renderButton();const o=this.getAttribute("icon-url");if(o){this.setLauncherIcon(o);return}const s=this.getAgentId();if(!s)return;const r=(t=(e=readAgentConfigCache(s))===null||e===void 0?void 0:e.theme)===null||t===void 0?void 0:t.icon_img;r&&this.setLauncherIcon(r);const d=async()=>{var a;const l=await this.getAgentConfig().catch(()=>{});i===this.launcherRenderSeq&&(l&&writeAgentConfigCache(s,l),this.setLauncherIcon(((a=l==null?void 0:l.theme)===null||a===void 0?void 0:a.icon_img)||r))};r?this.scheduleIdle(()=>{d()}):await d()}setLauncherIcon(e){var t;const i=this.shadowRoot;if(!i)return;const o=i.querySelector("#medassist-open-btn img");o&&(e?o.src=e:o.removeAttribute("src")),(t=i.getElementById("medassist-open-btn"))===null||t===void 0||t.classList.remove("pending")}renderButton(){var e;const t=this.shadowRoot;if(!t){console.error("Shadow root was not created");return}t.querySelector("button")||(t.innerHTML=`
93
+ `,(o=f.querySelector(".nudge-close"))===null||o===void 0||o.addEventListener("click",m=>{m.stopPropagation(),a&&setNudgeCookie(a,"closed"),this.dismissNudgePopup()}),f.addEventListener("click",()=>{var m;if(a&&setNudgeCookie(a,"closed"),this.dismissNudgePopup(),this.isChatboxShown()){(m=s.getElementById("medassist-chatbox-input"))===null||m===void 0||m.focus();return}this.loadAndRender()}),s.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 s=this.shadowRoot;if(!s||this.displayMode==="full")return;const d=this.getAgentId(),a=(i=d?(e=(t=readAgentConfigCache(d))===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",a);const r=s.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 u=document.createElement("style");u.setAttribute("data-medassist-custom-launcher","true"),u.textContent=l,s.appendChild(u)}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 s=document.createElement("style");s.setAttribute(t,"true"),s.textContent=e;const d=i.querySelector('style[data-medassist-custom-launcher="true"]');i.insertBefore(s,d)}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 s=this.getAgentId();if(!s)return;const d=(e=(t=readAgentConfigCache(s))===null||t===void 0?void 0:t.theme)===null||e===void 0?void 0:e.icon_img;d&&this.setLauncherIcon(d);const a=async()=>{var r;const l=await this.getAgentConfig().catch(()=>{});i===this.launcherRenderSeq&&(l&&writeAgentConfigCache(s,l),this.setLauncherIcon(((r=l==null?void 0:l.theme)===null||r===void 0?void 0:r.icon_img)||d))};d?this.scheduleIdle(()=>{a()}):await a()}setLauncherIcon(t){var e,i;const o=this.shadowRoot;if(!o)return;const s=o.querySelector("#medassist-open-btn img");s&&(t?s.src=t:s.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 s=this.getAgentId(),d=s?(e=readAgentConfigCache(s))===null||e===void 0?void 0:e.theme:void 0,a=(i==null?void 0:i.primary)||(o==null?void 0:o.primary)||(d==null?void 0:d.accent);a&&(t.style.setProperty("--medassist-chatbox-accent",a),t.style.setProperty("--medassist-chatbox-on-accent",colorOnAccent(a))),((i==null?void 0:i.mode)||(o==null?void 0:o.mode)||(d==null?void 0:d.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;
@@ -167,14 +167,177 @@
167
167
  animation-duration: 1.8s;
168
168
  }
169
169
  }
170
+ /* Chatbox launcher (launcher-type="chatbox"). Defaults only \u2014 agent
171
+ config launcher_styles and the host's custom-launcher-styles are
172
+ applied after this and win. */
173
+ /* Looks like the widget's floating composer (ChatComposer): card on
174
+ --elicitation-bg, 1px accent border at 30%, 20px radius, round accent
175
+ send button. Colours come from the agent-config theme (accent, mode)
176
+ via the variables set in updateLauncherView(); the fallbacks here
177
+ are the widget's own defaults (#6B5CE0, light mode). */
178
+ #medassist-chatbox {
179
+ --medassist-chatbox-accent: #6B5CE0;
180
+ --medassist-chatbox-on-accent: #fafafa;
181
+ --medassist-chatbox-bg: #ffffff;
182
+ --medassist-chatbox-text: #000000;
183
+ --medassist-chatbox-placeholder: #4d4d4d;
184
+ /* Bottom centre. A host moving it to a corner must also reset
185
+ left and transform, e.g. left: auto; right: 20px; transform: none. */
186
+ position: fixed;
187
+ bottom: 20px;
188
+ left: 50%;
189
+ right: auto;
190
+ transform: translateX(-50%);
191
+ /* 40% of the page, but never narrower than 420px. */
192
+ width: max(420px, 40vw);
193
+ max-width: calc(100vw - 32px);
194
+ box-sizing: border-box;
195
+ display: flex;
196
+ align-items: center;
197
+ gap: 8px;
198
+ margin: 0;
199
+ min-height: 60px;
200
+ padding: 8px 8px 8px 20px;
201
+ background: var(--medassist-chatbox-bg);
202
+ border: 1px solid rgba(107, 92, 224, 0.3);
203
+ border: 1px solid color-mix(in srgb, var(--medassist-chatbox-accent) 30%, transparent);
204
+ border-radius: 20px;
205
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
206
+ font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
207
+ }
208
+ #medassist-chatbox[data-mode="dark"] {
209
+ --medassist-chatbox-bg: #000000;
210
+ --medassist-chatbox-text: #ffffff;
211
+ --medassist-chatbox-placeholder: #b3b3b3;
212
+ }
213
+ #medassist-chatbox.pending {
214
+ display: none !important;
215
+ }
216
+ /* Soft accent glow for the first ~4s after load, to draw the eye.
217
+ The class is dropped when it ends, so it never replays after the
218
+ widget is closed. Box-shadow only \u2014 transform is used for centring. */
219
+ #medassist-chatbox.pulse {
220
+ animation: medassist-chatbox-pulse 1.4s ease-out 3;
221
+ }
222
+ #medassist-chatbox.pulse:focus-within {
223
+ animation: none;
224
+ }
225
+ /* Two accent rings ripple out and fade, the outer one wider. */
226
+ @keyframes medassist-chatbox-pulse {
227
+ 0% {
228
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16),
229
+ 0 0 0 0 color-mix(in srgb, var(--medassist-chatbox-accent) 35%, transparent),
230
+ 0 0 0 0 color-mix(in srgb, var(--medassist-chatbox-accent) 20%, transparent);
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
+ }
237
+ }
238
+ @media (prefers-reduced-motion: reduce) {
239
+ #medassist-chatbox.pulse {
240
+ animation: none;
241
+ }
242
+ }
243
+ #medassist-chatbox-input {
244
+ flex: 1;
245
+ min-width: 0;
246
+ height: 44px;
247
+ padding: 0;
248
+ border: none;
249
+ outline: none;
250
+ background: transparent;
251
+ color: var(--medassist-chatbox-text);
252
+ /* 16px stops iOS Safari zooming in on focus. */
253
+ font-size: 16px;
254
+ line-height: 1.4;
255
+ font-family: inherit;
256
+ }
257
+ #medassist-chatbox-input::placeholder {
258
+ color: var(--medassist-chatbox-placeholder);
259
+ }
260
+ #medassist-chatbox.sending #medassist-chatbox-input {
261
+ opacity: 0.6;
262
+ }
263
+ .medassist-chatbox-send {
264
+ flex-shrink: 0;
265
+ width: 44px;
266
+ height: 44px;
267
+ border: none;
268
+ border-radius: 50%;
269
+ padding: 0;
270
+ cursor: pointer;
271
+ display: flex;
272
+ align-items: center;
273
+ justify-content: center;
274
+ background: var(--medassist-chatbox-accent);
275
+ color: var(--medassist-chatbox-on-accent);
276
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
277
+ transition: transform 200ms, box-shadow 200ms;
278
+ }
279
+ .medassist-chatbox-send:hover {
280
+ transform: scale(1.05);
281
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
282
+ }
283
+ .medassist-chatbox-send:active {
284
+ transform: scale(0.95);
285
+ }
286
+ .medassist-chatbox-send:disabled {
287
+ opacity: 0.4;
288
+ cursor: not-allowed;
289
+ transform: none;
290
+ box-shadow: none;
291
+ }
292
+ .medassist-chatbox-send svg {
293
+ width: 16px;
294
+ height: 16px;
295
+ }
296
+ .medassist-chatbox-spinner {
297
+ display: none;
298
+ width: 18px;
299
+ height: 18px;
300
+ box-sizing: border-box;
301
+ border-radius: 50%;
302
+ border: 2px solid currentColor;
303
+ border-top-color: transparent;
304
+ animation: medassist-spin 0.7s linear infinite;
305
+ }
306
+ #medassist-chatbox.sending .medassist-chatbox-send {
307
+ cursor: default;
308
+ pointer-events: none;
309
+ }
310
+ #medassist-chatbox.sending .medassist-chatbox-send svg {
311
+ display: none;
312
+ }
313
+ #medassist-chatbox.sending .medassist-chatbox-spinner {
314
+ display: block;
315
+ }
316
+ @media (max-width: 768px) {
317
+ #medassist-chatbox {
318
+ left: 16px;
319
+ right: 16px;
320
+ bottom: 16px;
321
+ transform: none;
322
+ width: auto;
323
+ max-width: none;
324
+ }
325
+ }
170
326
  </style>
171
327
 
172
328
  <button id="medassist-open-btn" class="pending" aria-label="Open MedAssist">
173
329
  <img alt="MedAssist Icon">
174
330
  <span id="medassist-loader" aria-hidden="true"></span>
175
331
  </button>
332
+ <form id="medassist-chatbox" class="pending hidden pulse" autocomplete="off" novalidate>
333
+ <input id="medassist-chatbox-input" type="text" enterkeyhint="send" maxlength="2000" placeholder="Ask me anything\u2026" aria-label="Message MedAssist">
334
+ <button type="submit" class="medassist-chatbox-send" aria-label="Send message" disabled>
335
+ <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
+ <span class="medassist-chatbox-spinner" aria-hidden="true"></span>
337
+ </button>
338
+ </form>
176
339
  <div id="medassist-widget-root" class="hidden"></div>
177
- `,(e=t.getElementById("medassist-open-btn"))===null||e===void 0||e.addEventListener("click",()=>{const i=this.getAgentId();i&&setNudgeCookie(i,"closed"),this.dismissNudgePopup(),this.loadAndRender()})),this.applyCustomLauncherStyles()}initializeFullMode(){const e=this.shadowRoot;if(!e){console.error("Shadow root is not available");return}e.getElementById("medassist-widget-root")||(e.innerHTML=`
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 s=e.querySelector(".medassist-chatbox-send");i==null||i.addEventListener("input",()=>{s&&(s.disabled=!i.value.trim()),!o&&(o=!0,this.preloadWidgetAssets(),this.prefetchAuthTokens())});const d=e.getElementById("medassist-chatbox"),a=()=>d==null?void 0:d.classList.remove("pulse");d==null||d.addEventListener("animationend",r=>{r.animationName==="medassist-chatbox-pulse"&&a()}),i==null||i.addEventListener("focus",a),d==null||d.addEventListener("submit",r=>{r.preventDefault();const l=i==null?void 0:i.value.trim();if(!l||this.loading)return;const u=this.getAgentId();u&&setNudgeCookie(u,"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=`
178
341
  <style>
179
342
  :host {
180
343
  display: block;
@@ -191,4 +354,4 @@
191
354
  }
192
355
  </style>
193
356
  <div id="medassist-widget-root"></div>
194
- `)}async loadAndRender(){var e,t,i;const o=this.shadowRoot;if(!o){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const s=o.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let d=this.getAttribute("icon-url")||void 0;const a=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production",l=this.getAttribute("connectivity"),h=l==="http_stream"||l==="socket"?l:void 0,f=this.getAttribute("force-start")==="true";let p=this.getAttribute("title")||"Medi Clinic";const y=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",g=this.getAttribute("display-mode"),v=normalizeDisplayMode(g),b=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,w=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,m=this.getAttribute("feedback")?(()=>{try{return JSON.parse(this.getAttribute("feedback")||"{}")}catch{return}})():void 0,u=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},A=this.getAttribute("side-panel-mode"),S=u.sidePanelMode||(A==="overlay"?"overlay":"push"),C=this.getAttribute("side-panel-width"),F=(t=u.sidePanelWidth)!==null&&t!==void 0?t:C?Number(C):void 0,O=u.side||this.getAttribute("side")||(typeof document!="undefined"&&document.dir==="rtl"?"left":"right"),D={...b||{},...u.context||{}},H=u.authToken||this.getAttribute("auth-token")||void 0,_=u.agentId||r,q=u.baseUrl||y,E=typeof window!="undefined"?(i=window.EkaMedAssist)===null||i===void 0?void 0:i.onClose:void 0,J=this.getAttribute("redirect-url")||void 0,P=u.redirectUrl||J,j=!!P||u.showCloseButton===!0;if(!_){console.error("Agent ID is required");return}if(!s){console.error("Widget root element is missing");return}this.loading=!0,this.setLauncherState("loading"),s.classList.remove("hidden");let L,R,N,U=!1,W,T=!1,M;const B=c=>{var x,k,I;p=c.name||p,d=((x=c.theme)===null||x===void 0?void 0:x.icon_img)||d,L=mapAgentConfigThemeToWidgetTheme(c.theme||void 0),R=c.allowed,N=c.connectivity,U=c.resize||(u==null?void 0:u.resize)||!1,W=c.initial_message,T=(I=(k=c.theme)===null||k===void 0?void 0:k.hide_watermark)!==null&&I!==void 0?I:!1,M=c.feedback},$=readAgentConfigCache(_);if($)B($),this.getAgentConfig().then(c=>{c&&writeAgentConfigCache(_,c)}).catch(()=>{});else try{const c=await this.getAgentConfig();c&&(writeAgentConfigCache(_,c),B(c))}catch{}const G=h||N||"socket",z={title:u.title||p,iconUrl:d||u.iconUrl,showCloseButton:j,allowed:R,environment:a,connectionType:G,onClose:()=>{var c;if((c=this.reactRoot)===null||c===void 0||c.unmount(),this.reactRoot=null,E&&typeof E=="function"&&E(),P){window.location.href=P;return}v==="full"?this.style.display="none":(this.setLauncherState("idle"),s.classList.add("hidden"))},baseUrl:q,context:D,displayMode:v,sidePanelMode:S,sidePanelWidth:F,side:O,onSidePanelPushChange:(c,x,k)=>this.applyHostPush(c,x,k),resize:U||this.getAttribute("resize")==="true",authToken:H,force:f,initialMessage:W,hideWatermark:T,...(m||M)&&{feedback:m||M},theme:{...L||{},...w||{},...u.theme||{}}},X=window;if(this.widgetLoaded){this.reactRoot=X.renderMedAssist(s,_,z),this.setLauncherState("open"),this.loading=!1;return}try{const[,c]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=c.renderMedAssist(s,_,z),this.widgetLoaded=!0,this.setLauncherState("open")}catch(c){console.error("Failed to load MedAssist widget",c),this.setLauncherState("idle"),s.classList.add("hidden")}finally{this.loading=!1}}async loadWidgetCss(){const e=this.shadowRoot;if(!e)throw new Error("Shadow root is not available");if(e.querySelector("[data-medassist-style='true']"))return;const t=await getWidgetCssTextPromise(),i=document.createElement("style");i.setAttribute("data-medassist-style","true"),i.textContent=t,e.appendChild(i)}loadWidgetModule(){return widgetModulePromise||(widgetModulePromise=import(WIDGET_JS_URL)),widgetModulePromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
357
+ `)}async loadAndRender(t){var e,i,o,s;const d=this.shadowRoot;if(!d){console.error("Shadow root is not available");return}if(this.loading)return;this.prefetchAuthTokens(),this.style.display="";const a=d.getElementById("medassist-widget-root"),r=this.getAttribute("agent-id");let l=this.getAttribute("icon-url")||void 0;const u=(e=getEnvironment(this.getAttribute("environment")))!==null&&e!==void 0?e:"production",h=this.getAttribute("connectivity"),b=h==="http_stream"||h==="socket"?h:void 0,w=this.getAttribute("force-start")==="true";let g=this.getAttribute("title")||"Medi Clinic";const C=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",y=this.getAttribute("display-mode"),x=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,m=this.getAttribute("feedback")?(()=>{try{return JSON.parse(this.getAttribute("feedback")||"{}")}catch{return}})():void 0,p=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},E=this.getAttribute("side-panel-mode"),j=p.sidePanelMode||(E==="overlay"?"overlay":"push"),R=this.getAttribute("side-panel-width"),J=(i=p.sidePanelWidth)!==null&&i!==void 0?i:R?Number(R):void 0,G=p.side||this.getAttribute("side")||(typeof document!="undefined"&&document.dir==="rtl"?"left":"right"),N=c=>{const v=Number(this.getAttribute(c));return Number.isFinite(v)&&v>0?v:void 0},B=N("override-widget-width"),T=N("override-widget-height"),V={...B!==void 0&&{overrideWidgetWidth:B},...T!==void 0&&{overrideWidgetHeight:T}},X={...A||{},...p.context||{}},Y=p.authToken||this.getAttribute("auth-token")||void 0,_=p.agentId||r,K=p.baseUrl||C,L=typeof window!="undefined"?(o=window.EkaMedAssist)===null||o===void 0?void 0:o.onClose:void 0,Z=this.getAttribute("redirect-url")||void 0,M=p.redirectUrl||Z,Q=!!M||p.showCloseButton===!0;if(!_){console.error("Agent ID is required");return}if(!a){console.error("Widget root element is missing");return}this.loading=!0,this.setLauncherState("loading"),a.classList.remove("hidden");let W,U,$,F=!1,z,O=!1,I;const D=c=>{var v,k,P;g=c.name||g,l=((v=c.theme)===null||v===void 0?void 0:v.icon_img)||l,W=mapAgentConfigThemeToWidgetTheme(c.theme||void 0),U=c.allowed,$=c.connectivity,F=c.resize||(p==null?void 0:p.resize)||!1,z=c.initial_message,O=(P=(k=c.theme)===null||k===void 0?void 0:k.hide_watermark)!==null&&P!==void 0?P:!1,I=c.feedback},q=readAgentConfigCache(_);if(q)D(q),this.getAgentConfig().then(c=>{c&&writeAgentConfigCache(_,c)}).catch(()=>{});else try{const c=await this.getAgentConfig();c&&(writeAgentConfigCache(_,c),D(c))}catch{}const tt=b||$||"socket",H={title:p.title||g,iconUrl:l||p.iconUrl,showCloseButton:Q,allowed:U,environment:u,connectionType:tt,onClose:()=>{var c;if((c=this.reactRoot)===null||c===void 0||c.unmount(),this.reactRoot=null,L&&typeof L=="function"&&L(),M){window.location.href=M;return}x==="full"?this.style.display="none":(this.setLauncherState("idle"),a.classList.add("hidden"))},baseUrl:K,context:X,displayMode:x,sidePanelMode:j,sidePanelWidth:J,side:G,onSidePanelPushChange:(c,v,k)=>this.applyHostPush(c,v,k),resize:F||this.getAttribute("resize")==="true",authToken:Y,force:w,initialMessage:z,hideWatermark:O,...(m||I)&&{feedback:m||I},...t&&{firstUserMessage:t},theme:{...W||{},...f||{},...V,...p.theme||{}}},et=window,S=t&&this.isChatboxShown()?(s=d.getElementById("medassist-chatbox"))===null||s===void 0?void 0:s.getBoundingClientRect():void 0;if(this.widgetLoaded){this.reactRoot=et.renderMedAssist(a,_,H),S&&await this.growWidgetFromChatbox(S),this.setLauncherState("open"),this.loading=!1;return}try{const[,c]=await Promise.all([this.loadWidgetCss(),this.loadWidgetModule()]);this.reactRoot=c.renderMedAssist(a,_,H),this.widgetLoaded=!0,S&&await this.growWidgetFromChatbox(S),this.setLauncherState("open")}catch(c){console.error("Failed to load MedAssist widget",c),this.setLauncherState("idle"),a.classList.add("hidden")}finally{this.loading=!1}}async growWidgetFromChatbox(t){var e;try{if(prefersReducedMotion())return;const i=this.shadowRoot;let o=null;for(let h=0;h<30&&!o;h++)await nextFrame(),o=(e=i==null?void 0:i.querySelector(".synapse-chat-widget-container"))!==null&&e!==void 0?e:null;if(!o||typeof o.animate!="function")return;const s=o.getBoundingClientRect();if(!s.width||!s.height||!t.width)return;const d=t.left+t.width/2-(s.left+s.width/2),a=t.bottom-s.bottom,r=Math.max(0,s.height-t.height),l=Math.max(0,(s.width-t.width)/2),u=s.width>=window.innerWidth-1?0:24;o.animate([{transform:`translate(${d}px, ${a}px)`,clipPath:`inset(${r}px ${l}px 0px ${l}px round 20px)`,opacity:1},{transform:"translate(0px, 0px)",clipPath:`inset(0px 0px 0px 0px round ${u}px)`,opacity:1}],{duration:480,easing:"cubic-bezier(0.32, 0.72, 0, 1)"})}catch{}}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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/medassist-widget-embed",
3
- "version": "0.2.117",
3
+ "version": "0.2.118",
4
4
  "description": "Embeddable MedAssist widget loader built with Web Components.",
5
5
  "author": "Geethanjali S",
6
6
  "license": "MIT",