@epam/ai-dial-visualizer-connector 1.3.0-dev.124 → 1.3.0-dev.126
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/index.js +25 -29
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,20 +3,20 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
3
3
|
return e.SendVisualizeData = "SEND_VISUALIZE_DATA", e.SendGroupedVisualizeData = "SEND_GROUPED_VISUALIZE_DATA", e.SetVisualizerOptions = "SET_VISUALIZER_OPTIONS", e;
|
|
4
4
|
}({}), t = /* @__PURE__ */ function(e) {
|
|
5
5
|
return e.InitReady = "INIT_READY", e.Ready = "READY", e.ReadyToInteract = "READY_TO_INTERACT", e.SendMessage = "SEND_MESSAGE", e.CreatedConversationSuccess = "CREATED_CONVERSATION_SUCCESS", e.UpdatedConversationSuccess = "UPDATED_CONVERSATION_SUCCESS", e.UpdatedApplicationSuccess = "UPDATED_APPLICATION_SUCCESS", e;
|
|
6
|
-
}({}), n =
|
|
6
|
+
}({}), n = 1e4, r = () => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
7
7
|
let t = Math.random() * 16 | 0;
|
|
8
8
|
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
9
|
-
}),
|
|
9
|
+
}), i = class {
|
|
10
10
|
type;
|
|
11
11
|
payload;
|
|
12
12
|
promise;
|
|
13
|
-
requestId =
|
|
13
|
+
requestId = r();
|
|
14
14
|
resolveFn;
|
|
15
15
|
timeoutHandle;
|
|
16
16
|
replied = !1;
|
|
17
|
-
constructor(e, t,
|
|
17
|
+
constructor(e, t, r, i) {
|
|
18
18
|
this.type = e, this.payload = t;
|
|
19
|
-
let a =
|
|
19
|
+
let a = r || n;
|
|
20
20
|
this.promise = new Promise((t, n) => {
|
|
21
21
|
this.resolveFn = t, this.timeoutHandle = setTimeout(() => {
|
|
22
22
|
n(`[${i}] Request ${e} failed. Timeout ${a}`);
|
|
@@ -39,12 +39,12 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
39
39
|
requestId: this.requestId
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
},
|
|
42
|
+
}, a = (e, t) => {
|
|
43
43
|
for (let n of Object.keys(t)) {
|
|
44
44
|
let r = t[n];
|
|
45
45
|
r && (e.style[n] = r);
|
|
46
46
|
}
|
|
47
|
-
},
|
|
47
|
+
}, o = class {
|
|
48
48
|
promise;
|
|
49
49
|
resolveFn;
|
|
50
50
|
rejectFn;
|
|
@@ -63,7 +63,7 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
63
63
|
ready() {
|
|
64
64
|
return this.promise;
|
|
65
65
|
}
|
|
66
|
-
},
|
|
66
|
+
}, s = "VisualizerConnector", c = "Chat Visualizer destroyed", l = [
|
|
67
67
|
"allow-same-origin",
|
|
68
68
|
"allow-scripts",
|
|
69
69
|
"allow-modals",
|
|
@@ -71,18 +71,18 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
71
71
|
"allow-downloads",
|
|
72
72
|
"allow-popups",
|
|
73
73
|
"allow-presentation"
|
|
74
|
-
],
|
|
74
|
+
], u = "clipboard-write *; fullscreen *; accelerometer *; gyroscope *; autoplay *; web-share *; encrypted-media *", d = class {
|
|
75
75
|
root;
|
|
76
76
|
subscriptions = [];
|
|
77
77
|
iframe;
|
|
78
78
|
loader;
|
|
79
79
|
loaderDisplayCss = "flex";
|
|
80
|
-
iframeInteraction = new
|
|
80
|
+
iframeInteraction = new o();
|
|
81
81
|
requests = [];
|
|
82
82
|
options;
|
|
83
83
|
isDestroyed = !1;
|
|
84
84
|
constructor(e, t) {
|
|
85
|
-
this.options = t, this.root = this.getRoot(e), this.iframe = this.initIframe(), this.loader = this.initLoader(t.loaderStyles ?? {}, t.loaderClass, t.loaderInnerHTML), this.root.appendChild(this.loader), this.root.appendChild(this.iframe),
|
|
85
|
+
this.options = t, this.root = this.getRoot(e), this.iframe = this.initIframe(), this.loader = this.initLoader(t.loaderStyles ?? {}, t.loaderClass, t.loaderInnerHTML), this.root.appendChild(this.loader), this.root.appendChild(this.iframe), a(this.root, { position: "relative" }), this.showLoader(), window.addEventListener("message", this.process);
|
|
86
86
|
}
|
|
87
87
|
async ready() {
|
|
88
88
|
return this.iframeInteraction.ready();
|
|
@@ -91,13 +91,13 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
91
91
|
if (n) try {
|
|
92
92
|
await this.iframeInteraction.ready();
|
|
93
93
|
} catch (e) {
|
|
94
|
-
if (e ===
|
|
94
|
+
if (e === c) return;
|
|
95
95
|
throw e;
|
|
96
96
|
}
|
|
97
97
|
let r = this.iframe.contentWindow;
|
|
98
98
|
if (!this.iframe.isConnected || !r) return;
|
|
99
|
-
let
|
|
100
|
-
return this.requests.push(
|
|
99
|
+
let a = new i(`${this.options.visualizerName}/${e}`, t, this.options.requestTimeout, s);
|
|
100
|
+
return this.requests.push(a), r.postMessage(a.toPostMessage(), this.options.domain), a.promise;
|
|
101
101
|
}
|
|
102
102
|
subscribe(e, t) {
|
|
103
103
|
return this.subscriptions.push({
|
|
@@ -111,15 +111,15 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
111
111
|
this.options = e;
|
|
112
112
|
}
|
|
113
113
|
destroy() {
|
|
114
|
-
this.isDestroyed || (this.isDestroyed = !0, window.removeEventListener("message", this.process), this.iframeInteraction.ready().catch(() => void 0), this.iframeInteraction.fail(
|
|
114
|
+
this.isDestroyed || (this.isDestroyed = !0, window.removeEventListener("message", this.process), this.iframeInteraction.ready().catch(() => void 0), this.iframeInteraction.fail(c), this.iframe.remove(), this.loader.remove());
|
|
115
115
|
}
|
|
116
116
|
initIframe() {
|
|
117
117
|
let e = document.createElement("iframe");
|
|
118
|
-
return e.src = this.options.domain, e.setAttribute("sandbox",
|
|
118
|
+
return e.src = this.options.domain, e.setAttribute("sandbox", l.join(" ")), e.setAttribute("allow", u), e.style.height = "100%", e.style.width = "100%", e.style.border = "none", e.loading = "lazy", e;
|
|
119
119
|
}
|
|
120
|
-
initLoader(e, t,
|
|
121
|
-
let
|
|
122
|
-
return
|
|
120
|
+
initLoader(e, t, n) {
|
|
121
|
+
let r = document.createElement("div");
|
|
122
|
+
return r.innerHTML = n ?? "<svg width=\"48\" height=\"48\" viewBox=\"0 0 48 48\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<path d=\"M24 39V46.5\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.4\" d=\"M9 24H1.5\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.5\" d=\"M8.0918 8.0918L13.3994 13.3994\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.6\" d=\"M24 1.5V9\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.7\" d=\"M39.9121 8.08594L37.2607 10.7373L34.6094 13.3887\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.8\" d=\"M46.5 24H39\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.9\" d=\"M34.6055 34.6055L39.9082 39.9082\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path opacity=\"0.3\" d=\"M13.3936 34.6055L8.08594 39.9131\" stroke=\"#7F8792\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<animateTransform attributeName=\"transform\" attributeType=\"XML\" type=\"rotate\" from=\"0 0 0\" to=\"360 0 0\" dur=\"1s\" repeatCount=\"indefinite\" />\n</svg>\n", t && (r.className = t), e.display && (this.loaderDisplayCss = e.display), a(r, {
|
|
123
123
|
position: "absolute",
|
|
124
124
|
background: "white",
|
|
125
125
|
display: this.loaderDisplayCss,
|
|
@@ -131,12 +131,12 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
131
131
|
bottom: "0",
|
|
132
132
|
zIndex: "2",
|
|
133
133
|
...e
|
|
134
|
-
}),
|
|
134
|
+
}), r;
|
|
135
135
|
}
|
|
136
136
|
getRoot(e) {
|
|
137
137
|
if (typeof e != "string") return e;
|
|
138
138
|
let t = document.querySelector(e);
|
|
139
|
-
if (!t) throw Error(`[${
|
|
139
|
+
if (!t) throw Error(`[${s}] There is no element with selector ${e} to append iframe`);
|
|
140
140
|
return t;
|
|
141
141
|
}
|
|
142
142
|
process = (e) => {
|
|
@@ -152,21 +152,17 @@ var e = /* @__PURE__ */ function(e) {
|
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
154
|
let { requestId: i, payload: a } = e.data;
|
|
155
|
-
|
|
156
|
-
this.processEvent(n, a);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
this.requests.find((e) => e.match(n, i))?.reply(a), this.requests = this.requests.filter((e) => !e.isReplied);
|
|
155
|
+
i ? (this.requests.find((e) => e.match(n, i))?.reply(a), this.requests = this.requests.filter((e) => !e.isReplied)) : this.processEvent(n, a);
|
|
160
156
|
};
|
|
161
157
|
processEvent(e, t) {
|
|
162
158
|
for (let n of this.subscriptions) n.eventType === e && n.callback(t);
|
|
163
159
|
}
|
|
164
160
|
showLoader() {
|
|
165
|
-
|
|
161
|
+
a(this.loader, { display: this.loaderDisplayCss });
|
|
166
162
|
}
|
|
167
163
|
hideLoader() {
|
|
168
|
-
|
|
164
|
+
a(this.loader, { display: "none" });
|
|
169
165
|
}
|
|
170
166
|
};
|
|
171
167
|
//#endregion
|
|
172
|
-
export {
|
|
168
|
+
export { d as VisualizerConnector, t as VisualizerConnectorEvents, e as VisualizerConnectorRequests };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epam/ai-dial-visualizer-connector",
|
|
3
3
|
"description": "Host-side postMessage connector that mounts a custom visualizer iframe and delivers its data",
|
|
4
|
-
"version": "1.3.0-dev.
|
|
4
|
+
"version": "1.3.0-dev.126",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.js",
|