@ripperts/poco-agent-embed 0.1.0 → 0.1.2
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 +23 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -106,6 +106,10 @@
|
|
|
106
106
|
var language = ["en", "zh"].includes(requestedLanguage)
|
|
107
107
|
? requestedLanguage
|
|
108
108
|
: "en";
|
|
109
|
+
var toggleButtonLabels =
|
|
110
|
+
language === "zh"
|
|
111
|
+
? { open: "打开 AI 助手", close: "关闭 AI 助手" }
|
|
112
|
+
: { open: "Open AI Agent", close: "Close AI Agent" };
|
|
109
113
|
var theme = ["light", "dark", "system"].includes(options.theme)
|
|
110
114
|
? options.theme
|
|
111
115
|
: "system";
|
|
@@ -136,6 +140,22 @@
|
|
|
136
140
|
var openIcon = createIcon(options.openIcon, false);
|
|
137
141
|
var closeIcon = createIcon(options.closeIcon, true);
|
|
138
142
|
|
|
143
|
+
function renderFloatingState() {
|
|
144
|
+
container.style.opacity = opened ? "1" : "0";
|
|
145
|
+
container.style.visibility = opened ? "visible" : "hidden";
|
|
146
|
+
container.style.pointerEvents = opened ? "auto" : "none";
|
|
147
|
+
container.style.transform = opened ? "scale(1)" : "scale(.96)";
|
|
148
|
+
if (!button) return;
|
|
149
|
+
button.replaceChildren(opened ? closeIcon : openIcon);
|
|
150
|
+
button.setAttribute("aria-expanded", opened ? "true" : "false");
|
|
151
|
+
button.setAttribute(
|
|
152
|
+
"aria-label",
|
|
153
|
+
opened
|
|
154
|
+
? toggleButtonLabels.close
|
|
155
|
+
: options.ariaLabel || toggleButtonLabels.open,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
139
159
|
if (target) {
|
|
140
160
|
container.style.cssText =
|
|
141
161
|
"position:relative;width:100%;height:100%;overflow:hidden";
|
|
@@ -160,7 +180,6 @@
|
|
|
160
180
|
|
|
161
181
|
button = document.createElement("button");
|
|
162
182
|
button.type = "button";
|
|
163
|
-
button.setAttribute("aria-label", options.ariaLabel || "Open AI Agent");
|
|
164
183
|
button.style.cssText = [
|
|
165
184
|
"position:fixed",
|
|
166
185
|
"display:flex",
|
|
@@ -188,19 +207,6 @@
|
|
|
188
207
|
container.style[horizontal] = "20px";
|
|
189
208
|
container.style.transformOrigin = vertical + " " + horizontal;
|
|
190
209
|
|
|
191
|
-
function renderButtonIcon() {
|
|
192
|
-
button.replaceChildren(opened ? closeIcon : openIcon);
|
|
193
|
-
button.setAttribute("aria-expanded", opened ? "true" : "false");
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function renderOpenState() {
|
|
197
|
-
container.style.opacity = opened ? "1" : "0";
|
|
198
|
-
container.style.visibility = opened ? "visible" : "hidden";
|
|
199
|
-
container.style.pointerEvents = opened ? "auto" : "none";
|
|
200
|
-
container.style.transform = opened ? "scale(1)" : "scale(.96)";
|
|
201
|
-
renderButtonIcon();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
210
|
function anchorContainerToButton() {
|
|
205
211
|
var rect = button.getBoundingClientRect();
|
|
206
212
|
var useLeft = rect.left + rect.width / 2 < window.innerWidth / 2;
|
|
@@ -299,9 +305,10 @@
|
|
|
299
305
|
button.addEventListener("click", function () {
|
|
300
306
|
if (Date.now() < suppressClickUntil) return;
|
|
301
307
|
opened = !opened;
|
|
302
|
-
|
|
308
|
+
renderFloatingState();
|
|
303
309
|
});
|
|
304
310
|
|
|
311
|
+
renderFloatingState();
|
|
305
312
|
document.body.appendChild(container);
|
|
306
313
|
document.body.appendChild(button);
|
|
307
314
|
window.addEventListener("resize", updateViewportPosition);
|
|
@@ -313,7 +320,6 @@
|
|
|
313
320
|
);
|
|
314
321
|
}
|
|
315
322
|
updateViewportPosition();
|
|
316
|
-
renderOpenState();
|
|
317
323
|
}
|
|
318
324
|
|
|
319
325
|
async function authenticate() {
|
|
@@ -367,14 +373,7 @@
|
|
|
367
373
|
function setOpened(next) {
|
|
368
374
|
if (destroyed || target) return;
|
|
369
375
|
opened = next;
|
|
370
|
-
|
|
371
|
-
container.style.visibility = opened ? "visible" : "hidden";
|
|
372
|
-
container.style.pointerEvents = opened ? "auto" : "none";
|
|
373
|
-
container.style.transform = opened ? "scale(1)" : "scale(.96)";
|
|
374
|
-
if (button) {
|
|
375
|
-
button.replaceChildren(opened ? closeIcon : openIcon);
|
|
376
|
-
button.setAttribute("aria-expanded", opened ? "true" : "false");
|
|
377
|
-
}
|
|
376
|
+
renderFloatingState();
|
|
378
377
|
}
|
|
379
378
|
|
|
380
379
|
return {
|