@authon/js 0.3.2 → 0.3.3
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/index.cjs +27 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124,6 +124,7 @@ var ModalRenderer = class {
|
|
|
124
124
|
captchaSiteKey = "";
|
|
125
125
|
turnstileWidgetId = null;
|
|
126
126
|
turnstileToken = "";
|
|
127
|
+
turnstileWrapper = null;
|
|
127
128
|
constructor(options) {
|
|
128
129
|
this.mode = options.mode;
|
|
129
130
|
this.theme = options.theme || "auto";
|
|
@@ -171,6 +172,10 @@ var ModalRenderer = class {
|
|
|
171
172
|
this.turnstileWidgetId = null;
|
|
172
173
|
this.turnstileToken = "";
|
|
173
174
|
}
|
|
175
|
+
if (this.turnstileWrapper) {
|
|
176
|
+
this.turnstileWrapper.remove();
|
|
177
|
+
this.turnstileWrapper = null;
|
|
178
|
+
}
|
|
174
179
|
if (this.hostElement) {
|
|
175
180
|
this.hostElement.remove();
|
|
176
181
|
this.hostElement = null;
|
|
@@ -452,16 +457,28 @@ var ModalRenderer = class {
|
|
|
452
457
|
}
|
|
453
458
|
renderTurnstile() {
|
|
454
459
|
if (!this.captchaSiteKey || !this.shadowRoot) return;
|
|
455
|
-
const
|
|
456
|
-
if (!
|
|
460
|
+
const anchor = this.shadowRoot.getElementById("turnstile-container");
|
|
461
|
+
if (!anchor) return;
|
|
457
462
|
const w = window;
|
|
463
|
+
const positionWrapper = () => {
|
|
464
|
+
if (!this.turnstileWrapper || !anchor.isConnected) return;
|
|
465
|
+
const rect = anchor.getBoundingClientRect();
|
|
466
|
+
Object.assign(this.turnstileWrapper.style, {
|
|
467
|
+
position: "fixed",
|
|
468
|
+
top: `${rect.top}px`,
|
|
469
|
+
left: `${rect.left}px`,
|
|
470
|
+
width: `${rect.width}px`,
|
|
471
|
+
zIndex: "2147483647",
|
|
472
|
+
display: "flex",
|
|
473
|
+
justifyContent: "center"
|
|
474
|
+
});
|
|
475
|
+
};
|
|
458
476
|
const tryRender = () => {
|
|
459
|
-
if (!w.turnstile || !
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
this.turnstileWidgetId = w.turnstile.render(wrapper, {
|
|
477
|
+
if (!w.turnstile || !anchor.isConnected) return;
|
|
478
|
+
this.turnstileWrapper = document.createElement("div");
|
|
479
|
+
document.body.appendChild(this.turnstileWrapper);
|
|
480
|
+
positionWrapper();
|
|
481
|
+
this.turnstileWidgetId = w.turnstile.render(this.turnstileWrapper, {
|
|
465
482
|
sitekey: this.captchaSiteKey,
|
|
466
483
|
callback: (token) => {
|
|
467
484
|
this.turnstileToken = token;
|
|
@@ -475,7 +492,8 @@ var ModalRenderer = class {
|
|
|
475
492
|
theme: this.isDark() ? "dark" : "light",
|
|
476
493
|
size: "flexible"
|
|
477
494
|
});
|
|
478
|
-
|
|
495
|
+
window.addEventListener("scroll", positionWrapper, { passive: true });
|
|
496
|
+
window.addEventListener("resize", positionWrapper, { passive: true });
|
|
479
497
|
};
|
|
480
498
|
if (w.turnstile) {
|
|
481
499
|
tryRender();
|