@wvdsh/sdk-js 0.0.35 → 0.0.37

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7433,6 +7433,23 @@ var WavedashSDK = (() => {
7433
7433
  }
7434
7434
  };
7435
7435
 
7436
+ // src/utils/focusManager.ts
7437
+ function takeFocus() {
7438
+ if (typeof document !== "undefined") {
7439
+ const gameFocusTargets = document.getElementsByClassName("game-focus-target");
7440
+ if (gameFocusTargets.length > 0) {
7441
+ gameFocusTargets[0].focus();
7442
+ } else {
7443
+ const focusableElement = document.querySelector(
7444
+ "canvas, input, button, [tabindex]:not([tabindex='-1'])"
7445
+ );
7446
+ if (focusableElement) {
7447
+ focusableElement.focus();
7448
+ }
7449
+ }
7450
+ }
7451
+ }
7452
+
7436
7453
  // src/utils/iframeMessenger.ts
7437
7454
  var RESPONSE_TIMEOUT_MS = 5e3;
7438
7455
  var IFrameMessenger = class {
@@ -7451,22 +7468,7 @@ var WavedashSDK = (() => {
7451
7468
  pending.resolve(event.data.data);
7452
7469
  }
7453
7470
  } else if (event.data?.type === IFRAME_MESSAGE_TYPE.TAKE_FOCUS) {
7454
- console.log("[IFRAME MESSENGER] Taking focus");
7455
- if (typeof document !== "undefined") {
7456
- const gameFocusTargets = document.getElementsByClassName("game-focus-target");
7457
- if (gameFocusTargets.length > 0) {
7458
- console.log("[IFRAME MESSENGER] Focusing on game focus target");
7459
- gameFocusTargets[0].focus();
7460
- } else {
7461
- const focusableElement = document.querySelector(
7462
- "canvas, input, button, [tabindex]:not([tabindex='-1'])"
7463
- );
7464
- if (focusableElement) {
7465
- console.log("[IFRAME MESSENGER] Focusing on fallback target");
7466
- focusableElement.focus();
7467
- }
7468
- }
7469
- }
7471
+ takeFocus();
7470
7472
  }
7471
7473
  };
7472
7474
  this.pendingRequests = /* @__PURE__ */ new Map();
@@ -7478,15 +7480,15 @@ var WavedashSDK = (() => {
7478
7480
  }
7479
7481
  /**
7480
7482
  * Derive parent origin from iframe URL pattern
7481
- * iframe: [gameSlug].builds.[parentDomain]
7483
+ * iframe: [gameSlug].builds.[parentDomain] or [gameSlug].sandbox.[parentDomain]
7482
7484
  * parent: [parentDomain]
7483
7485
  */
7484
7486
  deriveParentOrigin() {
7485
7487
  if (typeof window === "undefined") return "";
7486
7488
  const iframeHost = window.location.hostname;
7487
- const match = iframeHost.match(/^[\w-]+\.builds\.(.+)$/);
7489
+ const match = iframeHost.match(/^[\w-]+\.(builds|sandbox)\.(.+)$/);
7488
7490
  if (match) {
7489
- const parentDomain = match[1];
7491
+ const parentDomain = match[2];
7490
7492
  return `${window.location.protocol}//${parentDomain}`;
7491
7493
  }
7492
7494
  console.error(`Invalid iframe hostname pattern: ${iframeHost}`);
@@ -8036,6 +8038,7 @@ var WavedashSDK = (() => {
8036
8038
  IFRAME_MESSAGE_TYPE.LOADING_COMPLETE,
8037
8039
  {}
8038
8040
  );
8041
+ takeFocus();
8039
8042
  }
8040
8043
  };
8041
8044
  var getAuthToken = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wvdsh/sdk-js",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "Wavedash JavaScript SDK",
5
5
  "main": "./dist/index.js",
6
6
  "files": [