From b5a6c4585986273a61f0f0880eb9d69f35717892 Mon Sep 17 00:00:00 2001
From: lpw <812862340@qq.com>
Date: Tue, 03 Feb 2026 16:32:15 +0800
Subject: [PATCH] 提交版本 4.10.0

---
 frameworks/Didomi.xcframework/ios-arm64/Didomi.framework/web_sdk_utilities.js |   75 ++++++++++++++++++++++++++++++-------
 1 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/frameworks/Didomi.xcframework/ios-arm64/Didomi.framework/web_sdk_utilities.js b/frameworks/Didomi.xcframework/ios-arm64/Didomi.framework/web_sdk_utilities.js
index cfe1c68..e8cdb56 100644
--- a/frameworks/Didomi.xcframework/ios-arm64/Didomi.framework/web_sdk_utilities.js
+++ b/frameworks/Didomi.xcframework/ios-arm64/Didomi.framework/web_sdk_utilities.js
@@ -1,7 +1,9 @@
 /** Script allowing to use the Web SDK from a WebView */
 
+// Check if SDK is still initializing and should not display the notice yet
+var initializationInProgress = true;
 // Check if notice was initially displayed
-var noticeReady = false;
+var noticeDisplayed = false;
 
 /**
  * Initialize the SDK with the specified configuration
@@ -11,6 +13,10 @@
     // Set the global window configuration to the config object
     window.didomiConfig = prepareConfigFromMobile(config, languageCode, isUnderage);
 
+    // Set the location properties
+    window.didomiCountry = extractCountryFromMobileConfig(config);
+    window.didomiRegion = extractRegionFromMobileConfig(config);
+    
     // If app, vendors, and iab exist, set the vendorList property
     if (
       window.didomiConfig.app &&
@@ -63,18 +69,23 @@
  * Open the notice screen
  */
 function openNotice(userStatus, options) {
+  var hasDeepLink = options != null && options.deepLinkView != null
+  if (!hasDeepLink) {
+      initializationInProgress = false
+  }
   handleWebSDKEvents();
   window.didomiOnReady = window.didomiOnReady || [];
   window.didomiOnReady.push(function (Didomi) {
     Didomi.setUserStatus(userStatus);
-    if (options != null && options.deepLinkView != null) {
+    if (hasDeepLink) {
+      initializationInProgress = false;
       Didomi.preferences.show(
         options.deepLinkView == 0 ? "purposes" : "vendors"
       );
     } else {
       Didomi.notice.show();
     }
-    noticeReady = true;
+    noticeDisplayed = true;
   });
 }
 
@@ -153,7 +164,7 @@
       {
         event: 'notice.hidden',
         listener: function () {
-          if (noticeReady && !Didomi.preferences.isVisible()) {
+          if (noticeDisplayed && !Didomi.preferences.isVisible()) {
             if (isIOS()) {
               window.webkit.messageHandlers.noticeHidden.postMessage("");
             } else {
@@ -165,7 +176,10 @@
       {
         event: 'notice.shown',
         listener: function () {
-          if (isIOS()) {
+          if (initializationInProgress) {
+            // Make sure the notice is not displayed if initialization is still in progress
+            Didomi.notice.hide();
+          } else if (isIOS()) {
             window.webkit.messageHandlers.noticeShown.postMessage("");
           } else {
             androidInterface.onNoticeShown();
@@ -336,17 +350,33 @@
 function toggleFirstSlider() {
   new Promise(function(resolve) {
     setTimeout(() => {  // Add delay to let time for the element to be attached
-      var element = document.getElementsByClassName('didomi-switch')[0];
-      if (element) {
-        element.click();
-        resolve(true);
-      } else {
-        resolve(false);
+      var elements = document.getElementsByClassName('didomi-switch');
+      var clicked = false;
+
+      // Click on 1st active slider
+      for (var index = 0; index < elements.length; index++) {
+        if (isClickable(elements[index])) {
+          elements[index].click();
+          clicked = true;
+          break;
+        }
       }
+
+      resolve(clicked);
     }, 100);
   }).then((result) => {
       enabledToggleIsCachedOrNotRequired(result);
   });
+}
+
+/**
+ * Check if a DOM element is clickable (visible and not disabled)
+ */
+function isClickable(element) {
+  if (element.disabled) return false;
+  if (element.style.display === 'none' || element.style.visibility === 'hidden') return false;
+  if (element.offsetParent === null) return false;
+  return true;
 }
 
 /**
@@ -412,13 +442,12 @@
 
 /**
  * Fix unescaped quotes.
+ * Note: lookbehinds (`(?<=...)` or `(?<!...)`) are only supported from safari 17+ 
  * @param {string} text
  * @returns the sanitized text
  */
 function sanitizeText(text) {
-  return text
-    // Escape unescaped quotes
-    .replace(/(?<!\\)(['"])/g, '\$1');
+  return text.replace(/(^|[^\\])(['"])/g, '$1\$2');
 }
 
 /**
@@ -491,6 +520,24 @@
 }
 
 /**
+ * Extract the country from the mobile config.
+ * @param {*} configFromMobile 
+ * @returns the country or null if not defined.
+ */
+function extractCountryFromMobileConfig(configFromMobile) {
+  return configFromMobile.user ? configFromMobile.user.country : null;
+}
+
+/**
+ * Extract the region from the mobile config.
+ * @param {*} configFromMobile 
+ * @returns the region or null if not defined.
+ */
+function extractRegionFromMobileConfig(configFromMobile) {
+  return configFromMobile.user ? configFromMobile.user.region : null;
+}
+
+/**
  * Prepare config file to be consumed by the Web SDK, by disabling the features already handled by Mobile SDKs.
  * @param {*} configFromMobile Config provided by mobile.
  * @param {string} languageCode language code to be set in the Config.

--
Gitblit v1.8.0