@eka-care/medassist-widget-embed 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/iframe-helper.js +2 -75
- package/dist/iframe.js +1 -318
- package/dist/index.js +4 -456
- package/dist/src/medassist-widget.css +6 -2
- package/dist/src/medassist-widget.js +89 -29
- package/package.json +10 -15
- package/assets/bot-icon.svg +0 -7
- package/dist/src/medassist-widget.js.map +0 -1
- package/iframe-helper.ts +0 -126
- package/iframe.html +0 -61
- package/iframe.ts +0 -381
- package/index.ts +0 -603
- package/src/.gitkeep +0 -2
- package/src/medassist-widget.css +0 -2793
- package/src/medassist-widget.js +0 -43678
- package/src/medassist-widget.js.map +0 -1
- package/src/vite.svg +0 -1
- package/test.html +0 -70
package/dist/index.js
CHANGED
|
@@ -1,286 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const getCurrentScript = () => {
|
|
3
|
-
if (typeof document === "undefined") {
|
|
4
|
-
console.error("document is not defined");
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const { currentScript } = document;
|
|
8
|
-
if (currentScript instanceof HTMLScriptElement) {
|
|
9
|
-
return currentScript;
|
|
10
|
-
}
|
|
11
|
-
const scripts = document.getElementsByTagName("script");
|
|
12
|
-
return scripts.length ? scripts[scripts.length - 1] : null;
|
|
13
|
-
};
|
|
14
|
-
const getEnvironment = (value) => {
|
|
15
|
-
if (value === "production" ||
|
|
16
|
-
value === "development" ||
|
|
17
|
-
value === "staging") {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
};
|
|
22
|
-
const scriptEl = getCurrentScript();
|
|
23
|
-
// Detect version tag from script src (e.g., @dev, @latest)
|
|
24
|
-
const DEFAULT_WIDGET_ASSET_BASE = (() => {
|
|
25
|
-
var _a;
|
|
26
|
-
if ((_a = scriptEl === null || scriptEl === void 0 ? void 0 : scriptEl.src) === null || _a === void 0 ? void 0 : _a.includes("@dev")) {
|
|
27
|
-
return "https://unpkg.com/@eka-care/medassist-widget@dev/dist/";
|
|
28
|
-
}
|
|
29
|
-
return "https://unpkg.com/@eka-care/medassist-widget@latest/dist/";
|
|
30
|
-
})();
|
|
31
|
-
/** Map agent-config API theme to widget theme (mode → textColor: dark→black, light→white) */
|
|
32
|
-
function mapAgentConfigThemeToWidgetTheme(apiTheme) {
|
|
33
|
-
if (!apiTheme)
|
|
34
|
-
return undefined;
|
|
35
|
-
const textColor = apiTheme.mode === "dark" ? "white" : apiTheme.mode === "light" ? "black" : undefined;
|
|
36
|
-
return {
|
|
37
|
-
...(apiTheme.background && { background: apiTheme.background }),
|
|
38
|
-
...(apiTheme.background_img && { backgroundImage: apiTheme.background_img }),
|
|
39
|
-
...(apiTheme.accent && { primary: apiTheme.accent }),
|
|
40
|
-
...(textColor && { textColor }),
|
|
41
|
-
...(apiTheme.title_img && { titleImg: apiTheme.title_img }),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/** Preload an image by URL so it is cached and loads faster when the widget uses it. */
|
|
45
|
-
function preloadImage(url) {
|
|
46
|
-
if (!url || typeof document === "undefined")
|
|
47
|
-
return;
|
|
48
|
-
try {
|
|
49
|
-
const link = document.createElement("link");
|
|
50
|
-
link.rel = "preload";
|
|
51
|
-
link.as = "image";
|
|
52
|
-
link.href = url;
|
|
53
|
-
document.head.appendChild(link);
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
// fallback: use Image to prime cache
|
|
57
|
-
const img = new Image();
|
|
58
|
-
img.src = url;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/** Fetch agent-config from API and return theme from response data */
|
|
62
|
-
async function fetchAgentConfig(baseUrl, agentId) {
|
|
63
|
-
const url = `${baseUrl.replace(/\/$/, "")}/med-assist/agent-config/${agentId}`;
|
|
64
|
-
const res = await fetch(url, {
|
|
65
|
-
headers: {
|
|
66
|
-
"ngrok-skip-browser-warning": "69420",
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
if (!res.ok)
|
|
70
|
-
return undefined;
|
|
71
|
-
const json = await res.json();
|
|
72
|
-
if ((json === null || json === void 0 ? void 0 : json.success) && (json === null || json === void 0 ? void 0 : json.data))
|
|
73
|
-
return json.data;
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
const globalMedAssistConfig = {};
|
|
77
|
-
const getWidgetElement = () => {
|
|
78
|
-
if (typeof document === "undefined") {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
return document.querySelector("eka-medassist-widget");
|
|
82
|
-
};
|
|
83
|
-
if (typeof window !== "undefined") {
|
|
84
|
-
const w = window;
|
|
85
|
-
w.__ekaMedAssistConfig__ = globalMedAssistConfig;
|
|
86
|
-
w.EkaMedAssist = {
|
|
87
|
-
init(config) {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
Object.assign(globalMedAssistConfig, config);
|
|
90
|
-
const el = getWidgetElement();
|
|
91
|
-
if (!el)
|
|
92
|
-
return;
|
|
93
|
-
if (config.agentId)
|
|
94
|
-
el.setAttribute("agent-id", config.agentId);
|
|
95
|
-
if (config.title)
|
|
96
|
-
el.setAttribute("title", config.title);
|
|
97
|
-
if (config.iconUrl)
|
|
98
|
-
el.setAttribute("icon-url", config.iconUrl);
|
|
99
|
-
if (config.baseUrl)
|
|
100
|
-
el.setAttribute("base-url", config.baseUrl);
|
|
101
|
-
if (config.context) {
|
|
102
|
-
try {
|
|
103
|
-
el.setAttribute("context", JSON.stringify(config.context));
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
console.warn("Failed to stringify context passed to init");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if ((_a = config.theme) === null || _a === void 0 ? void 0 : _a.backgroundImage) {
|
|
110
|
-
preloadImage(config.theme.backgroundImage);
|
|
111
|
-
}
|
|
112
|
-
(_c = (_b = el).openFromBridge) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
const scriptBaseUrl = (() => {
|
|
117
|
-
if (!scriptEl) {
|
|
118
|
-
return "";
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
return new URL(".", scriptEl.src || window.location.href).href;
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
return "";
|
|
125
|
-
}
|
|
126
|
-
})();
|
|
127
|
-
const widgetAssetBaseUrl = (() => {
|
|
128
|
-
if (!scriptEl) {
|
|
129
|
-
return DEFAULT_WIDGET_ASSET_BASE;
|
|
130
|
-
}
|
|
131
|
-
const dataValue = scriptEl.dataset.widgetAssets;
|
|
132
|
-
if (dataValue === "local") {
|
|
133
|
-
return `${scriptBaseUrl}src/`;
|
|
134
|
-
}
|
|
135
|
-
if (dataValue && dataValue.length > 0) {
|
|
136
|
-
try {
|
|
137
|
-
return new URL(dataValue, scriptBaseUrl).href;
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
return dataValue.endsWith("/") ? dataValue : `${dataValue}/`;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return DEFAULT_WIDGET_ASSET_BASE;
|
|
144
|
-
})();
|
|
145
|
-
const WIDGET_JS_URL = `${widgetAssetBaseUrl}medassist-widget.js`;
|
|
146
|
-
const WIDGET_CSS_URL = `${widgetAssetBaseUrl}medassist-widget.css`;
|
|
147
|
-
let widgetScriptPromise = null;
|
|
148
|
-
let widgetCssTextPromise = null;
|
|
149
|
-
/** Start fetching widget CSS (shared promise). Used for preload and by loadWidgetCss. */
|
|
150
|
-
function getWidgetCssTextPromise() {
|
|
151
|
-
if (!widgetCssTextPromise) {
|
|
152
|
-
widgetCssTextPromise = fetch(WIDGET_CSS_URL).then((response) => {
|
|
153
|
-
if (!response.ok) {
|
|
154
|
-
throw new Error(`Unable to fetch widget styles from ${WIDGET_CSS_URL}`);
|
|
155
|
-
}
|
|
156
|
-
return response.text();
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
return widgetCssTextPromise;
|
|
160
|
-
}
|
|
161
|
-
class MedAssistWidgetLoader extends HTMLElement {
|
|
162
|
-
constructor() {
|
|
163
|
-
super();
|
|
164
|
-
this.attachShadow({ mode: "open" });
|
|
165
|
-
this.defaultIconUrl = "https://cdn.eka.care/bot-icon.svg";
|
|
166
|
-
this.widgetLoaded = false;
|
|
167
|
-
this.displayMode = this.getAttribute("display-mode") === "full" ? "full" : "widget";
|
|
168
|
-
// Listen for AUTH_EXPIRED events from the widget and forward to parent
|
|
169
|
-
this.setupAuthExpirationListener();
|
|
170
|
-
}
|
|
171
|
-
static get observedAttributes() {
|
|
172
|
-
return ["icon-url", "display-mode"];
|
|
173
|
-
}
|
|
174
|
-
connectedCallback() {
|
|
175
|
-
if (this.displayMode === "full") {
|
|
176
|
-
this.initializeFullMode();
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
this.renderButton();
|
|
180
|
-
this.preloadWidgetAssets();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
attributeChangedCallback(name) {
|
|
184
|
-
if (name === "icon-url") {
|
|
185
|
-
if (this.displayMode === "widget") {
|
|
186
|
-
this.renderButton();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (name === "display-mode") {
|
|
190
|
-
const newMode = this.getAttribute("display-mode") === "full" ? "full" : "widget";
|
|
191
|
-
if (newMode !== this.displayMode) {
|
|
192
|
-
this.displayMode = newMode;
|
|
193
|
-
if (newMode === "full") {
|
|
194
|
-
this.initializeFullMode();
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
this.renderButton();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
/** When in widget mode, start loading JS and CSS on page load so first open is faster. */
|
|
203
|
-
preloadWidgetAssets() {
|
|
204
|
-
getWidgetCssTextPromise(); // start CSS fetch (no inject until open)
|
|
205
|
-
void this.loadWidgetScript(); // start JS load
|
|
206
|
-
void this.preloadBackgroundImage();
|
|
207
|
-
}
|
|
208
|
-
/** Preload theme background image from init config, theme attribute, or agent-config API. */
|
|
209
|
-
preloadBackgroundImage() {
|
|
210
|
-
var _a;
|
|
211
|
-
const initConfig = typeof window !== "undefined"
|
|
212
|
-
? window.__ekaMedAssistConfig__
|
|
213
|
-
: undefined;
|
|
214
|
-
const attributeTheme = this.getAttribute("theme")
|
|
215
|
-
? (() => {
|
|
216
|
-
try {
|
|
217
|
-
return JSON.parse(this.getAttribute("theme") || "{}");
|
|
218
|
-
}
|
|
219
|
-
catch {
|
|
220
|
-
return undefined;
|
|
221
|
-
}
|
|
222
|
-
})()
|
|
223
|
-
: undefined;
|
|
224
|
-
const fromInit = (_a = initConfig === null || initConfig === void 0 ? void 0 : initConfig.theme) === null || _a === void 0 ? void 0 : _a.backgroundImage;
|
|
225
|
-
const fromAttr = attributeTheme === null || attributeTheme === void 0 ? void 0 : attributeTheme.backgroundImage;
|
|
226
|
-
if (fromInit)
|
|
227
|
-
preloadImage(fromInit);
|
|
228
|
-
if (fromAttr && fromAttr !== fromInit)
|
|
229
|
-
preloadImage(fromAttr);
|
|
230
|
-
const baseUrl = (initConfig === null || initConfig === void 0 ? void 0 : initConfig.baseUrl) || this.getAttribute("base-url") || "";
|
|
231
|
-
const agentId = (initConfig === null || initConfig === void 0 ? void 0 : initConfig.agentId) || this.getAttribute("agent-id") || "";
|
|
232
|
-
if (baseUrl && agentId) {
|
|
233
|
-
fetchAgentConfig(baseUrl, agentId)
|
|
234
|
-
.then((agentConfig) => {
|
|
235
|
-
var _a;
|
|
236
|
-
const url = (_a = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) === null || _a === void 0 ? void 0 : _a.background_img;
|
|
237
|
-
if (url)
|
|
238
|
-
preloadImage(url);
|
|
239
|
-
})
|
|
240
|
-
.catch(() => {
|
|
241
|
-
// ignore; widget will load config when it opens
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
setupAuthExpirationListener() {
|
|
246
|
-
if (typeof window === "undefined")
|
|
247
|
-
return;
|
|
248
|
-
const messageHandler = (event) => {
|
|
249
|
-
var _a;
|
|
250
|
-
if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === "AUTH_EXPIRED") {
|
|
251
|
-
if (window.parent !== window) {
|
|
252
|
-
window.parent.postMessage({ type: "AUTH_EXPIRED", message: "Authentication expired" }, "*");
|
|
253
|
-
}
|
|
254
|
-
// window.webkit.messageHandlers.authTokenExpired.postMessage({});
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
window.addEventListener("message", messageHandler);
|
|
258
|
-
}
|
|
259
|
-
openFromBridge() {
|
|
260
|
-
this.displayMode = this.getAttribute("display-mode") === "full" ? "full" : "widget";
|
|
261
|
-
if (this.displayMode === "full") {
|
|
262
|
-
this.initializeFullMode();
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
this.renderButton();
|
|
266
|
-
}
|
|
267
|
-
this.loadWidgetCss()
|
|
268
|
-
.then(() => this.loadWidgetScript())
|
|
269
|
-
.then(() => this.loadAndRender())
|
|
270
|
-
.catch((error) => {
|
|
271
|
-
console.error("Failed to open MedAssist widget from bridge", error);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
renderButton() {
|
|
275
|
-
var _a;
|
|
276
|
-
const iconUrl = this.getAttribute("icon-url") || this.defaultIconUrl;
|
|
277
|
-
const shadowRoot = this.shadowRoot;
|
|
278
|
-
if (!shadowRoot) {
|
|
279
|
-
console.error("Shadow root was not created");
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (!shadowRoot.querySelector("button")) {
|
|
283
|
-
shadowRoot.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&&{background:e.background},...e.background_img&&{backgroundImage:e.background_img},...e.accent&&{primary:e.accent},...t&&{textColor:t},...e.title_img&&{titleImg:e.title_img}}}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 i=`${e.replace(/\/$/,"")}/med-assist/agent-config/${t}`,n=await fetch(i,{headers:{"ngrok-skip-browser-warning":"69420"}});if(!n.ok)return;const o=await n.json();if(o!=null&&o.success&&(o!=null&&o.data))return o.data}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 i,n,o;Object.assign(globalMedAssistConfig,t);const d=getWidgetElement();if(d){if(t.agentId&&d.setAttribute("agent-id",t.agentId),t.title&&d.setAttribute("title",t.title),t.iconUrl&&d.setAttribute("icon-url",t.iconUrl),t.baseUrl&&d.setAttribute("base-url",t.baseUrl),t.context)try{d.setAttribute("context",JSON.stringify(t.context))}catch{console.warn("Failed to stringify context passed to init")}!((i=t.theme)===null||i===void 0)&&i.backgroundImage&&preloadImage(t.theme.backgroundImage),(o=(n=d).openFromBridge)===null||o===void 0||o.call(n)}}}}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{constructor(){super(),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.renderButton(),this.preloadWidgetAssets())}attributeChangedCallback(t){if(t==="icon-url"&&this.displayMode==="widget"&&this.renderButton(),t==="display-mode"){const i=this.getAttribute("display-mode")==="full"?"full":"widget";i!==this.displayMode&&(this.displayMode=i,i==="full"?this.initializeFullMode():this.renderButton())}}preloadWidgetAssets(){getWidgetCssTextPromise(),this.loadWidgetScript(),this.preloadBackgroundImage()}preloadBackgroundImage(){var t;const i=typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0,n=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,o=(t=i==null?void 0:i.theme)===null||t===void 0?void 0:t.backgroundImage,d=n==null?void 0:n.backgroundImage;o&&preloadImage(o),d&&d!==o&&preloadImage(d);const r=(i==null?void 0:i.baseUrl)||this.getAttribute("base-url")||"",a=(i==null?void 0:i.agentId)||this.getAttribute("agent-id")||"";r&&a&&fetchAgentConfig(r,a).then(u=>{var l;const g=(l=u==null?void 0:u.theme)===null||l===void 0?void 0:l.background_img;g&&preloadImage(g)}).catch(()=>{})}setupAuthExpirationListener(){if(typeof window=="undefined")return;const t=i=>{var n;((n=i.data)===null||n===void 0?void 0:n.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)})}renderButton(){var t;const i=this.getAttribute("icon-url")||this.defaultIconUrl,n=this.shadowRoot;if(!n){console.error("Shadow root was not created");return}if(!n.querySelector("button"))n.innerHTML=`
|
|
284
2
|
<style>
|
|
285
3
|
#medassist-open-btn {
|
|
286
4
|
width: 60px;
|
|
@@ -317,28 +35,10 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
317
35
|
</style>
|
|
318
36
|
|
|
319
37
|
<button id="medassist-open-btn">
|
|
320
|
-
<img src="${
|
|
38
|
+
<img src="${i}" alt="MedAssist Icon">
|
|
321
39
|
</button>
|
|
322
40
|
<div id="medassist-widget-root" class="hidden"></div>
|
|
323
|
-
|
|
324
|
-
(_a = shadowRoot
|
|
325
|
-
.getElementById("medassist-open-btn")) === null || _a === void 0 ? void 0 : _a.addEventListener("click", () => this.loadAndRender());
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
const img = shadowRoot.querySelector("#medassist-open-btn img");
|
|
329
|
-
if (img) {
|
|
330
|
-
img.src = iconUrl;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
initializeFullMode() {
|
|
335
|
-
const shadowRoot = this.shadowRoot;
|
|
336
|
-
if (!shadowRoot) {
|
|
337
|
-
console.error("Shadow root is not available");
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
if (!shadowRoot.getElementById("medassist-widget-root")) {
|
|
341
|
-
shadowRoot.innerHTML = `
|
|
41
|
+
`,(t=n.getElementById("medassist-open-btn"))===null||t===void 0||t.addEventListener("click",()=>this.loadAndRender());else{const o=n.querySelector("#medassist-open-btn img");o&&(o.src=i)}}initializeFullMode(){const t=this.shadowRoot;if(!t){console.error("Shadow root is not available");return}t.getElementById("medassist-widget-root")||(t.innerHTML=`
|
|
342
42
|
<style>
|
|
343
43
|
:host {
|
|
344
44
|
display: block;
|
|
@@ -355,156 +55,4 @@ class MedAssistWidgetLoader extends HTMLElement {
|
|
|
355
55
|
}
|
|
356
56
|
</style>
|
|
357
57
|
<div id="medassist-widget-root"></div>
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
async loadAndRender() {
|
|
362
|
-
var _a, _b, _c, _d;
|
|
363
|
-
const shadowRoot = this.shadowRoot;
|
|
364
|
-
if (!shadowRoot) {
|
|
365
|
-
console.error("Shadow root is not available");
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const button = shadowRoot.getElementById("medassist-open-btn");
|
|
369
|
-
const rootElement = shadowRoot.getElementById("medassist-widget-root");
|
|
370
|
-
const agentId = this.getAttribute("agent-id");
|
|
371
|
-
let iconUrl = this.getAttribute("icon-url") || this.defaultIconUrl;
|
|
372
|
-
const environment = (_a = getEnvironment(this.getAttribute("environment"))) !== null && _a !== void 0 ? _a : "production";
|
|
373
|
-
let title = this.getAttribute("title") || "Medi Clinic";
|
|
374
|
-
const baseUrl = this.getAttribute("base-url") || "https://matrix.eka.care/reloaded";
|
|
375
|
-
const displayModeAttribute = this.getAttribute("display-mode");
|
|
376
|
-
const displayMode = displayModeAttribute === "full" ? "full" : "widget";
|
|
377
|
-
const attributeContext = this.getAttribute("context") ? JSON.parse(this.getAttribute("context") || "{}") : undefined;
|
|
378
|
-
const attributeTheme = this.getAttribute("theme") ? (() => { try {
|
|
379
|
-
return JSON.parse(this.getAttribute("theme") || "{}");
|
|
380
|
-
}
|
|
381
|
-
catch {
|
|
382
|
-
return undefined;
|
|
383
|
-
} })() : undefined;
|
|
384
|
-
const initConfig = (typeof window !== "undefined"
|
|
385
|
-
? window.__ekaMedAssistConfig__
|
|
386
|
-
: undefined) || {};
|
|
387
|
-
const mergedContext = {
|
|
388
|
-
...(attributeContext || {}),
|
|
389
|
-
...(initConfig.context || {}),
|
|
390
|
-
};
|
|
391
|
-
const auth = initConfig.auth || undefined;
|
|
392
|
-
const resolvedAgentId = initConfig.agentId || agentId;
|
|
393
|
-
const apiBaseUrl = initConfig.baseUrl || baseUrl;
|
|
394
|
-
const customOnClose = typeof window !== "undefined" ? (_b = window.EkaMedAssist) === null || _b === void 0 ? void 0 : _b.onClose : undefined;
|
|
395
|
-
if (!resolvedAgentId) {
|
|
396
|
-
console.error("Agent ID is required");
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
if (!rootElement) {
|
|
400
|
-
console.error("Widget root element is missing");
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
if (button) {
|
|
404
|
-
button.classList.add("hidden");
|
|
405
|
-
}
|
|
406
|
-
rootElement.classList.remove("hidden");
|
|
407
|
-
// Fetch agent-config when baseUrl is available; derive theme (mode → textColor: dark→black, light→white)
|
|
408
|
-
let apiTheme = undefined;
|
|
409
|
-
let allowed;
|
|
410
|
-
if (apiBaseUrl) {
|
|
411
|
-
try {
|
|
412
|
-
const agentConfig = await fetchAgentConfig(apiBaseUrl, resolvedAgentId);
|
|
413
|
-
title = (agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.name) || title;
|
|
414
|
-
iconUrl = ((_c = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) === null || _c === void 0 ? void 0 : _c.icon_img) || iconUrl;
|
|
415
|
-
apiTheme = mapAgentConfigThemeToWidgetTheme((agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.theme) || undefined);
|
|
416
|
-
allowed = agentConfig === null || agentConfig === void 0 ? void 0 : agentConfig.allowed;
|
|
417
|
-
}
|
|
418
|
-
catch {
|
|
419
|
-
// ignore; use attribute + init theme only
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
const widgetConfig = {
|
|
423
|
-
title: initConfig.title || title,
|
|
424
|
-
iconUrl: initConfig.iconUrl || iconUrl,
|
|
425
|
-
allowed,
|
|
426
|
-
environment,
|
|
427
|
-
onClose: () => {
|
|
428
|
-
if (customOnClose && typeof customOnClose === "function") {
|
|
429
|
-
customOnClose();
|
|
430
|
-
}
|
|
431
|
-
if (button) {
|
|
432
|
-
button.classList.remove("hidden");
|
|
433
|
-
}
|
|
434
|
-
rootElement.classList.add("hidden");
|
|
435
|
-
},
|
|
436
|
-
baseUrl: apiBaseUrl,
|
|
437
|
-
context: mergedContext,
|
|
438
|
-
displayMode,
|
|
439
|
-
auth,
|
|
440
|
-
theme: { ...(apiTheme || {}), ...(attributeTheme || {}), ...(initConfig.theme || {}) }
|
|
441
|
-
};
|
|
442
|
-
if (this.widgetLoaded) {
|
|
443
|
-
(_d = window.renderMedAssist) === null || _d === void 0 ? void 0 : _d.call(window, rootElement, resolvedAgentId, widgetConfig);
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
try {
|
|
447
|
-
await Promise.all([this.loadWidgetCss(), this.loadWidgetScript()]);
|
|
448
|
-
if (typeof window.renderMedAssist !== "function") {
|
|
449
|
-
throw new Error("renderMedAssist is not available on window");
|
|
450
|
-
}
|
|
451
|
-
window.renderMedAssist(rootElement, resolvedAgentId, widgetConfig);
|
|
452
|
-
this.widgetLoaded = true;
|
|
453
|
-
}
|
|
454
|
-
catch (error) {
|
|
455
|
-
console.error("Failed to load MedAssist widget", error);
|
|
456
|
-
if (button) {
|
|
457
|
-
button.classList.remove("hidden");
|
|
458
|
-
}
|
|
459
|
-
rootElement.classList.add("hidden");
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
async loadWidgetCss() {
|
|
463
|
-
const shadowRoot = this.shadowRoot;
|
|
464
|
-
if (!shadowRoot) {
|
|
465
|
-
throw new Error("Shadow root is not available");
|
|
466
|
-
}
|
|
467
|
-
if (shadowRoot.querySelector("[data-medassist-style='true']")) {
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
const cssText = await getWidgetCssTextPromise();
|
|
471
|
-
const styleTag = document.createElement("style");
|
|
472
|
-
styleTag.setAttribute("data-medassist-style", "true");
|
|
473
|
-
styleTag.textContent = cssText;
|
|
474
|
-
shadowRoot.appendChild(styleTag);
|
|
475
|
-
}
|
|
476
|
-
loadWidgetScript() {
|
|
477
|
-
if (!widgetScriptPromise) {
|
|
478
|
-
widgetScriptPromise = new Promise((resolve, reject) => {
|
|
479
|
-
const existingScript = document.querySelector(`script[src="${WIDGET_JS_URL}"]`);
|
|
480
|
-
if (existingScript) {
|
|
481
|
-
if (existingScript.dataset.loaded === "true") {
|
|
482
|
-
resolve();
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
existingScript.addEventListener("load", () => resolve());
|
|
486
|
-
existingScript.addEventListener("error", (event) => reject(event.error || new Error("Unknown script loading error")));
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
const script = document.createElement("script");
|
|
490
|
-
script.src = WIDGET_JS_URL;
|
|
491
|
-
script.async = true;
|
|
492
|
-
script.dataset.widget = "medassist";
|
|
493
|
-
script.onload = () => {
|
|
494
|
-
script.dataset.loaded = "true";
|
|
495
|
-
resolve();
|
|
496
|
-
};
|
|
497
|
-
script.onerror = (event) => {
|
|
498
|
-
if (event instanceof ErrorEvent && event.error) {
|
|
499
|
-
reject(event.error);
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
reject(new Error(`Failed to load ${WIDGET_JS_URL}`));
|
|
503
|
-
};
|
|
504
|
-
document.head.appendChild(script);
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
return widgetScriptPromise;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
customElements.define("eka-medassist-widget", MedAssistWidgetLoader);
|
|
58
|
+
`)}async loadAndRender(){var t,i,n,o;const d=this.shadowRoot;if(!d){console.error("Shadow root is not available");return}const r=d.getElementById("medassist-open-btn"),a=d.getElementById("medassist-widget-root"),u=this.getAttribute("agent-id");let l=this.getAttribute("icon-url")||this.defaultIconUrl;const g=(t=getEnvironment(this.getAttribute("environment")))!==null&&t!==void 0?t:"production";let f=this.getAttribute("title")||"Medi Clinic";const y=this.getAttribute("base-url")||"https://matrix.eka.care/reloaded",A=this.getAttribute("display-mode")==="full"?"full":"widget",k=this.getAttribute("context")?JSON.parse(this.getAttribute("context")||"{}"):void 0,E=this.getAttribute("theme")?(()=>{try{return JSON.parse(this.getAttribute("theme")||"{}")}catch{return}})():void 0,c=(typeof window!="undefined"?window.__ekaMedAssistConfig__:void 0)||{},_={...k||{},...c.context||{}},x=c.auth||void 0,h=c.agentId||u,m=c.baseUrl||y,w=typeof window!="undefined"?(i=window.EkaMedAssist)===null||i===void 0?void 0:i.onClose:void 0;if(!h){console.error("Agent ID is required");return}if(!a){console.error("Widget root element is missing");return}r&&r.classList.add("hidden"),a.classList.remove("hidden");let p,b;if(m)try{const s=await fetchAgentConfig(m,h);f=(s==null?void 0:s.name)||f,l=((n=s==null?void 0:s.theme)===null||n===void 0?void 0:n.icon_img)||l,p=mapAgentConfigThemeToWidgetTheme((s==null?void 0:s.theme)||void 0),b=s==null?void 0:s.allowed}catch{}const v={title:c.title||f,iconUrl:c.iconUrl||l,allowed:b,environment:g,onClose:()=>{w&&typeof w=="function"&&w(),r&&r.classList.remove("hidden"),a.classList.add("hidden")},baseUrl:m,context:_,displayMode:A,auth:x,theme:{...p||{},...E||{},...c.theme||{}}};if(this.widgetLoaded){(o=window.renderMedAssist)===null||o===void 0||o.call(window,a,h,v);return}try{if(await Promise.all([this.loadWidgetCss(),this.loadWidgetScript()]),typeof window.renderMedAssist!="function")throw new Error("renderMedAssist is not available on window");window.renderMedAssist(a,h,v),this.widgetLoaded=!0}catch(s){console.error("Failed to load MedAssist widget",s),r&&r.classList.remove("hidden"),a.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 i=await getWidgetCssTextPromise(),n=document.createElement("style");n.setAttribute("data-medassist-style","true"),n.textContent=i,t.appendChild(n)}loadWidgetScript(){return widgetScriptPromise||(widgetScriptPromise=new Promise((t,i)=>{const n=document.querySelector(`script[src="${WIDGET_JS_URL}"]`);if(n){if(n.dataset.loaded==="true"){t();return}n.addEventListener("load",()=>t()),n.addEventListener("error",d=>i(d.error||new Error("Unknown script loading error")));return}const o=document.createElement("script");o.src=WIDGET_JS_URL,o.async=!0,o.dataset.widget="medassist",o.onload=()=>{o.dataset.loaded="true",t()},o.onerror=d=>{if(d instanceof ErrorEvent&&d.error){i(d.error);return}i(new Error(`Failed to load ${WIDGET_JS_URL}`))},document.head.appendChild(o)})),widgetScriptPromise}}customElements.define("eka-medassist-widget",MedAssistWidgetLoader);
|
|
@@ -1657,6 +1657,10 @@ body {
|
|
|
1657
1657
|
background-image: linear-gradient(to right, var(--tw-gradient-stops));
|
|
1658
1658
|
}
|
|
1659
1659
|
|
|
1660
|
+
.bg-none {
|
|
1661
|
+
background-image: none;
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1660
1664
|
.from-primary {
|
|
1661
1665
|
--tw-gradient-from: hsl(var(--primary)) var(--tw-gradient-from-position);
|
|
1662
1666
|
--tw-gradient-to: hsl(var(--primary) / 0) var(--tw-gradient-to-position);
|
|
@@ -2701,8 +2705,8 @@ body {
|
|
|
2701
2705
|
cursor: not-allowed;
|
|
2702
2706
|
}
|
|
2703
2707
|
|
|
2704
|
-
.disabled\:bg-
|
|
2705
|
-
background-color: hsl(var(--
|
|
2708
|
+
.disabled\:bg-primary\/50:disabled {
|
|
2709
|
+
background-color: hsl(var(--primary) / 0.5);
|
|
2706
2710
|
}
|
|
2707
2711
|
|
|
2708
2712
|
.disabled\:text-text-tertiary:disabled {
|