@everymatrix/user-login 1.87.26 → 1.87.27

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.
@@ -372,6 +372,8 @@ const translate = (key, customLang, values) => {
372
372
  return translation;
373
373
  };
374
374
 
375
+ const StyleCacheKey = '__WIDGET_GLOBAL_STYLE_CACHE__';
376
+
375
377
  /**
376
378
  * @name setClientStyling
377
379
  * @description Method used to create and append to the passed element of the widget a style element with the content received
@@ -417,18 +419,75 @@ function setClientStylingURL(stylingContainer, clientStylingUrl) {
417
419
  * @param {HTMLElement} stylingContainer The highest element of the widget
418
420
  * @param {string} domain The domain from where the content should be fetched (e.g. 'Casino.Style', 'App.Style', 'casino-footer.style', etc.)
419
421
  * @param {ref} subscription A reference to a variable where the subscription should be saved for unsubscribing when no longer needed
422
+ * @param {boolean} useAdoptedStyleSheets A flag to gradually enable testing of adoptedStyleSheets
420
423
  */
421
- function setStreamStyling(stylingContainer, domain, subscription) {
422
- if (window.emMessageBus) {
423
- const sheet = document.createElement('style');
424
+ function setStreamStyling(stylingContainer, domain, subscription, useAdoptedStyleSheets = false) {
425
+ if (!window.emMessageBus) return;
424
426
 
425
- window.emMessageBus.subscribe(domain, (data) => {
426
- sheet.innerHTML = data;
427
- if (stylingContainer) {
428
- stylingContainer.appendChild(sheet);
429
- }
430
- });
427
+ const supportAdoptStyle = 'adoptedStyleSheets' in Document.prototype;
428
+
429
+ if (!supportAdoptStyle || !useAdoptedStyleSheets) {
430
+ subscription = getStyleTagSubscription(stylingContainer, domain);
431
+
432
+ return subscription;
433
+ }
434
+
435
+ if (!window[StyleCacheKey]) {
436
+ window[StyleCacheKey] = {};
431
437
  }
438
+ subscription = getAdoptStyleSubscription(stylingContainer, domain);
439
+
440
+ const originalUnsubscribe = subscription.unsubscribe.bind(subscription);
441
+ const wrappedUnsubscribe = () => {
442
+ if (window[StyleCacheKey][domain]) {
443
+ const cachedObject = window[StyleCacheKey][domain];
444
+ cachedObject.refCount > 1
445
+ ? (cachedObject.refCount = cachedObject.refCount - 1)
446
+ : delete window[StyleCacheKey][domain];
447
+ }
448
+
449
+ originalUnsubscribe();
450
+ };
451
+ subscription.unsubscribe = wrappedUnsubscribe;
452
+
453
+ return subscription;
454
+ }
455
+
456
+ function getStyleTagSubscription(stylingContainer, domain) {
457
+ const sheet = document.createElement('style');
458
+
459
+ return window.emMessageBus.subscribe(domain, (data) => {
460
+ if (stylingContainer) {
461
+ sheet.innerHTML = data;
462
+ stylingContainer.appendChild(sheet);
463
+ }
464
+ });
465
+ }
466
+
467
+ function getAdoptStyleSubscription(stylingContainer, domain) {
468
+ return window.emMessageBus.subscribe(domain, (data) => {
469
+ if (!stylingContainer) return;
470
+
471
+ const shadowRoot = stylingContainer.getRootNode();
472
+ const cacheStyleObject = window[StyleCacheKey];
473
+ let cachedStyle = cacheStyleObject[domain]?.sheet;
474
+
475
+ if (!cachedStyle) {
476
+ cachedStyle = new CSSStyleSheet();
477
+ cachedStyle.replaceSync(data);
478
+ cacheStyleObject[domain] = {
479
+ sheet: cachedStyle,
480
+ refCount: 1
481
+ };
482
+ } else {
483
+ cacheStyleObject[domain].refCount = cacheStyleObject[domain].refCount + 1;
484
+ }
485
+
486
+ const currentSheets = shadowRoot.adoptedStyleSheets || [];
487
+ if (!currentSheets.includes(cachedStyle)) {
488
+ shadowRoot.adoptedStyleSheets = [...currentSheets, cachedStyle];
489
+ }
490
+ });
432
491
  }
433
492
 
434
493
  /**
@@ -7517,7 +7576,7 @@ const UserLogin = class {
7517
7576
  componentDidLoad() {
7518
7577
  if (this.stylingContainer) {
7519
7578
  if (window.emMessageBus != undefined) {
7520
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7579
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7521
7580
  }
7522
7581
  else {
7523
7582
  if (this.clientStyling)
@@ -368,6 +368,8 @@ const translate = (key, customLang, values) => {
368
368
  return translation;
369
369
  };
370
370
 
371
+ const StyleCacheKey = '__WIDGET_GLOBAL_STYLE_CACHE__';
372
+
371
373
  /**
372
374
  * @name setClientStyling
373
375
  * @description Method used to create and append to the passed element of the widget a style element with the content received
@@ -413,18 +415,75 @@ function setClientStylingURL(stylingContainer, clientStylingUrl) {
413
415
  * @param {HTMLElement} stylingContainer The highest element of the widget
414
416
  * @param {string} domain The domain from where the content should be fetched (e.g. 'Casino.Style', 'App.Style', 'casino-footer.style', etc.)
415
417
  * @param {ref} subscription A reference to a variable where the subscription should be saved for unsubscribing when no longer needed
418
+ * @param {boolean} useAdoptedStyleSheets A flag to gradually enable testing of adoptedStyleSheets
416
419
  */
417
- function setStreamStyling(stylingContainer, domain, subscription) {
418
- if (window.emMessageBus) {
419
- const sheet = document.createElement('style');
420
+ function setStreamStyling(stylingContainer, domain, subscription, useAdoptedStyleSheets = false) {
421
+ if (!window.emMessageBus) return;
420
422
 
421
- window.emMessageBus.subscribe(domain, (data) => {
422
- sheet.innerHTML = data;
423
- if (stylingContainer) {
424
- stylingContainer.appendChild(sheet);
425
- }
426
- });
423
+ const supportAdoptStyle = 'adoptedStyleSheets' in Document.prototype;
424
+
425
+ if (!supportAdoptStyle || !useAdoptedStyleSheets) {
426
+ subscription = getStyleTagSubscription(stylingContainer, domain);
427
+
428
+ return subscription;
429
+ }
430
+
431
+ if (!window[StyleCacheKey]) {
432
+ window[StyleCacheKey] = {};
427
433
  }
434
+ subscription = getAdoptStyleSubscription(stylingContainer, domain);
435
+
436
+ const originalUnsubscribe = subscription.unsubscribe.bind(subscription);
437
+ const wrappedUnsubscribe = () => {
438
+ if (window[StyleCacheKey][domain]) {
439
+ const cachedObject = window[StyleCacheKey][domain];
440
+ cachedObject.refCount > 1
441
+ ? (cachedObject.refCount = cachedObject.refCount - 1)
442
+ : delete window[StyleCacheKey][domain];
443
+ }
444
+
445
+ originalUnsubscribe();
446
+ };
447
+ subscription.unsubscribe = wrappedUnsubscribe;
448
+
449
+ return subscription;
450
+ }
451
+
452
+ function getStyleTagSubscription(stylingContainer, domain) {
453
+ const sheet = document.createElement('style');
454
+
455
+ return window.emMessageBus.subscribe(domain, (data) => {
456
+ if (stylingContainer) {
457
+ sheet.innerHTML = data;
458
+ stylingContainer.appendChild(sheet);
459
+ }
460
+ });
461
+ }
462
+
463
+ function getAdoptStyleSubscription(stylingContainer, domain) {
464
+ return window.emMessageBus.subscribe(domain, (data) => {
465
+ if (!stylingContainer) return;
466
+
467
+ const shadowRoot = stylingContainer.getRootNode();
468
+ const cacheStyleObject = window[StyleCacheKey];
469
+ let cachedStyle = cacheStyleObject[domain]?.sheet;
470
+
471
+ if (!cachedStyle) {
472
+ cachedStyle = new CSSStyleSheet();
473
+ cachedStyle.replaceSync(data);
474
+ cacheStyleObject[domain] = {
475
+ sheet: cachedStyle,
476
+ refCount: 1
477
+ };
478
+ } else {
479
+ cacheStyleObject[domain].refCount = cacheStyleObject[domain].refCount + 1;
480
+ }
481
+
482
+ const currentSheets = shadowRoot.adoptedStyleSheets || [];
483
+ if (!currentSheets.includes(cachedStyle)) {
484
+ shadowRoot.adoptedStyleSheets = [...currentSheets, cachedStyle];
485
+ }
486
+ });
428
487
  }
429
488
 
430
489
  /**
@@ -7513,7 +7572,7 @@ const UserLogin = class {
7513
7572
  componentDidLoad() {
7514
7573
  if (this.stylingContainer) {
7515
7574
  if (window.emMessageBus != undefined) {
7516
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7575
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7517
7576
  }
7518
7577
  else {
7519
7578
  if (this.clientStyling)