@authon/js 0.3.2 → 0.3.4

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 CHANGED
@@ -153,6 +153,7 @@ var ModalRenderer = class {
153
153
  captchaSiteKey = "";
154
154
  turnstileWidgetId = null;
155
155
  turnstileToken = "";
156
+ turnstileWrapper = null;
156
157
  constructor(options) {
157
158
  this.mode = options.mode;
158
159
  this.theme = options.theme || "auto";
@@ -200,6 +201,10 @@ var ModalRenderer = class {
200
201
  this.turnstileWidgetId = null;
201
202
  this.turnstileToken = "";
202
203
  }
204
+ if (this.turnstileWrapper) {
205
+ this.turnstileWrapper.remove();
206
+ this.turnstileWrapper = null;
207
+ }
203
208
  if (this.hostElement) {
204
209
  this.hostElement.remove();
205
210
  this.hostElement = null;
@@ -481,16 +486,28 @@ var ModalRenderer = class {
481
486
  }
482
487
  renderTurnstile() {
483
488
  if (!this.captchaSiteKey || !this.shadowRoot) return;
484
- const container = this.shadowRoot.getElementById("turnstile-container");
485
- if (!container) return;
489
+ const anchor = this.shadowRoot.getElementById("turnstile-container");
490
+ if (!anchor) return;
486
491
  const w = window;
492
+ const positionWrapper = () => {
493
+ if (!this.turnstileWrapper || !anchor.isConnected) return;
494
+ const rect = anchor.getBoundingClientRect();
495
+ Object.assign(this.turnstileWrapper.style, {
496
+ position: "fixed",
497
+ top: `${rect.top}px`,
498
+ left: `${rect.left}px`,
499
+ width: `${rect.width}px`,
500
+ zIndex: "2147483647",
501
+ display: "flex",
502
+ justifyContent: "center"
503
+ });
504
+ };
487
505
  const tryRender = () => {
488
- if (!w.turnstile || !container.isConnected) return;
489
- const wrapper = document.createElement("div");
490
- wrapper.style.display = "flex";
491
- wrapper.style.justifyContent = "center";
492
- document.body.appendChild(wrapper);
493
- this.turnstileWidgetId = w.turnstile.render(wrapper, {
506
+ if (!w.turnstile || !anchor.isConnected) return;
507
+ this.turnstileWrapper = document.createElement("div");
508
+ document.body.appendChild(this.turnstileWrapper);
509
+ positionWrapper();
510
+ this.turnstileWidgetId = w.turnstile.render(this.turnstileWrapper, {
494
511
  sitekey: this.captchaSiteKey,
495
512
  callback: (token) => {
496
513
  this.turnstileToken = token;
@@ -504,7 +521,8 @@ var ModalRenderer = class {
504
521
  theme: this.isDark() ? "dark" : "light",
505
522
  size: "flexible"
506
523
  });
507
- container.appendChild(wrapper);
524
+ window.addEventListener("scroll", positionWrapper, { passive: true });
525
+ window.addEventListener("resize", positionWrapper, { passive: true });
508
526
  };
509
527
  if (w.turnstile) {
510
528
  tryRender();