@everymatrix/lottery-ticket-controller 1.87.25 → 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.
@@ -35,6 +35,8 @@ const getTranslations$2 = (data) => {
35
35
  });
36
36
  };
37
37
 
38
+ const StyleCacheKey = '__WIDGET_GLOBAL_STYLE_CACHE__';
39
+
38
40
  /**
39
41
  * @name setClientStyling
40
42
  * @description Method used to create and append to the passed element of the widget a style element with the content received
@@ -80,18 +82,75 @@ function setClientStylingURL(stylingContainer, clientStylingUrl) {
80
82
  * @param {HTMLElement} stylingContainer The highest element of the widget
81
83
  * @param {string} domain The domain from where the content should be fetched (e.g. 'Casino.Style', 'App.Style', 'casino-footer.style', etc.)
82
84
  * @param {ref} subscription A reference to a variable where the subscription should be saved for unsubscribing when no longer needed
85
+ * @param {boolean} useAdoptedStyleSheets A flag to gradually enable testing of adoptedStyleSheets
83
86
  */
84
- function setStreamStyling(stylingContainer, domain, subscription) {
85
- if (window.emMessageBus) {
86
- const sheet = document.createElement('style');
87
+ function setStreamStyling(stylingContainer, domain, subscription, useAdoptedStyleSheets = false) {
88
+ if (!window.emMessageBus) return;
87
89
 
88
- window.emMessageBus.subscribe(domain, (data) => {
89
- sheet.innerHTML = data;
90
- if (stylingContainer) {
91
- stylingContainer.appendChild(sheet);
92
- }
93
- });
90
+ const supportAdoptStyle = 'adoptedStyleSheets' in Document.prototype;
91
+
92
+ if (!supportAdoptStyle || !useAdoptedStyleSheets) {
93
+ subscription = getStyleTagSubscription(stylingContainer, domain);
94
+
95
+ return subscription;
96
+ }
97
+
98
+ if (!window[StyleCacheKey]) {
99
+ window[StyleCacheKey] = {};
94
100
  }
101
+ subscription = getAdoptStyleSubscription(stylingContainer, domain);
102
+
103
+ const originalUnsubscribe = subscription.unsubscribe.bind(subscription);
104
+ const wrappedUnsubscribe = () => {
105
+ if (window[StyleCacheKey][domain]) {
106
+ const cachedObject = window[StyleCacheKey][domain];
107
+ cachedObject.refCount > 1
108
+ ? (cachedObject.refCount = cachedObject.refCount - 1)
109
+ : delete window[StyleCacheKey][domain];
110
+ }
111
+
112
+ originalUnsubscribe();
113
+ };
114
+ subscription.unsubscribe = wrappedUnsubscribe;
115
+
116
+ return subscription;
117
+ }
118
+
119
+ function getStyleTagSubscription(stylingContainer, domain) {
120
+ const sheet = document.createElement('style');
121
+
122
+ return window.emMessageBus.subscribe(domain, (data) => {
123
+ if (stylingContainer) {
124
+ sheet.innerHTML = data;
125
+ stylingContainer.appendChild(sheet);
126
+ }
127
+ });
128
+ }
129
+
130
+ function getAdoptStyleSubscription(stylingContainer, domain) {
131
+ return window.emMessageBus.subscribe(domain, (data) => {
132
+ if (!stylingContainer) return;
133
+
134
+ const shadowRoot = stylingContainer.getRootNode();
135
+ const cacheStyleObject = window[StyleCacheKey];
136
+ let cachedStyle = cacheStyleObject[domain]?.sheet;
137
+
138
+ if (!cachedStyle) {
139
+ cachedStyle = new CSSStyleSheet();
140
+ cachedStyle.replaceSync(data);
141
+ cacheStyleObject[domain] = {
142
+ sheet: cachedStyle,
143
+ refCount: 1
144
+ };
145
+ } else {
146
+ cacheStyleObject[domain].refCount = cacheStyleObject[domain].refCount + 1;
147
+ }
148
+
149
+ const currentSheets = shadowRoot.adoptedStyleSheets || [];
150
+ if (!currentSheets.includes(cachedStyle)) {
151
+ shadowRoot.adoptedStyleSheets = [...currentSheets, cachedStyle];
152
+ }
153
+ });
95
154
  }
96
155
 
97
156
  const helperAccordionCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.Header{border-radius:5px;background:var(--emw--color-primary, #009993);display:flex;gap:30px;border:1px solid var(--emw--color-primary, #009993);padding:8px 10px;user-select:none;margin-bottom:1px;cursor:pointer}.Header:hover{background:var(--emw--color-secondary, #00aba4)}.Header .Title,.Header .Subtitle,.Header .Description{margin:0;font-size:14px;color:var(--emw--color-typography-inverse, rgb(255, 255, 255));text-transform:capitalize}.Header .Expand{margin-left:auto;color:var(--emw--color-typography-inverse, rgb(255, 255, 255));width:17px;height:17px;cursor:pointer;text-align:center;transform:rotate(90deg);font-size:20px;user-select:none}.HeaderTicketHistory{border-radius:4px;background:var(--emw--color-background, #fff);display:flex;gap:30px;border:1px solid var(--emw--color-primary, #009993);padding:8px 10px;user-select:none;margin-bottom:5px;cursor:pointer}.HeaderTicketHistory:hover{background:var(--emw--color-secondary, #00aba4)}.HeaderTicketHistory .Title,.HeaderTicketHistory .Subtitle,.HeaderTicketHistory .Description{margin:0;font-size:14px;color:var(--emw--color-typography, #000)}.HeaderTicketHistory .Expand{margin-left:auto;color:var(--emw--color-typography-inverse, rgb(255, 255, 255));width:17px;height:17px;cursor:pointer;text-align:center;transform:rotate(90deg);font-size:20px;user-select:none}.Content{border-radius:0 0 4px 4px;background:var(--emw--color-background, #fff);border:1px solid var(--emw--color-primary, #009993);padding:10px 15px;user-select:none;color:var(--emw--color-typography, #000);margin-bottom:10px}.ActionButton{cursor:pointer;display:inline-block;border-radius:var(--emw--button-border-radius, 4px);margin:20px 0 10px;text-transform:uppercase;font-size:12px;text-align:center;padding:8px 20px;min-width:80px;background:var(--emw--color-error, #ff3d00);border:1px solid var(--emw--color-error, #ff3d00);color:var(--emw--color-background, #fff)}.ActionButton:hover{background:var(--emw--color-secondary, #ff6536);border:1px solid var(--emw--color-error, #ff3d00)}";
@@ -130,13 +189,13 @@ const HelperAccordion = class {
130
189
  }
131
190
  handleMbSourceChange(newValue, oldValue) {
132
191
  if (newValue != oldValue) {
133
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
192
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
134
193
  }
135
194
  }
136
195
  componentDidLoad() {
137
196
  if (this.stylingContainer) {
138
197
  if (this.mbSource)
139
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
198
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
140
199
  if (this.clientStyling)
141
200
  setClientStyling(this.stylingContainer, this.clientStyling);
142
201
  if (this.clientStylingUrl)
@@ -211,13 +270,13 @@ const LotteryBullet = class {
211
270
  }
212
271
  handleMbSourceChange(newValue, oldValue) {
213
272
  if (newValue != oldValue) {
214
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
273
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
215
274
  }
216
275
  }
217
276
  componentDidLoad() {
218
277
  if (this.stylingContainer) {
219
278
  if (this.mbSource)
220
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
279
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
221
280
  if (this.clientStyling)
222
281
  setClientStyling(this.stylingContainer, this.clientStyling);
223
282
  if (this.clientStylingUrl)
@@ -280,13 +339,13 @@ const LotteryGrid = class {
280
339
  }
281
340
  handleMbSourceChange(newValue, oldValue) {
282
341
  if (newValue != oldValue) {
283
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
342
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
284
343
  }
285
344
  }
286
345
  componentDidLoad() {
287
346
  if (this.stylingContainer) {
288
347
  if (this.mbSource)
289
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
348
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
290
349
  if (this.clientStyling)
291
350
  setClientStyling(this.stylingContainer, this.clientStyling);
292
351
  if (this.clientStylingUrl)
@@ -7300,7 +7359,7 @@ const LotteryTicket = class {
7300
7359
  }
7301
7360
  handleMbSourceChange(newValue, oldValue) {
7302
7361
  if (newValue != oldValue) {
7303
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7362
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7304
7363
  }
7305
7364
  }
7306
7365
  checkForClickOutside(ev) {
@@ -7387,7 +7446,7 @@ const LotteryTicket = class {
7387
7446
  componentDidLoad() {
7388
7447
  if (this.stylingContainer) {
7389
7448
  if (this.mbSource)
7390
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7449
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7391
7450
  if (this.clientStyling)
7392
7451
  setClientStyling(this.stylingContainer, this.clientStyling);
7393
7452
  if (this.clientStylingUrl)
@@ -7608,13 +7667,13 @@ const LotteryTicketController = class {
7608
7667
  }
7609
7668
  handleMbSourceChange(newValue, oldValue) {
7610
7669
  if (newValue != oldValue) {
7611
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7670
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7612
7671
  }
7613
7672
  }
7614
7673
  componentDidLoad() {
7615
7674
  if (this.stylingContainer) {
7616
7675
  if (this.mbSource)
7617
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7676
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7618
7677
  if (this.clientStyling)
7619
7678
  setClientStyling(this.stylingContainer, this.clientStyling);
7620
7679
  if (this.clientStylingUrl)
@@ -31,6 +31,8 @@ const getTranslations$2 = (data) => {
31
31
  });
32
32
  };
33
33
 
34
+ const StyleCacheKey = '__WIDGET_GLOBAL_STYLE_CACHE__';
35
+
34
36
  /**
35
37
  * @name setClientStyling
36
38
  * @description Method used to create and append to the passed element of the widget a style element with the content received
@@ -76,18 +78,75 @@ function setClientStylingURL(stylingContainer, clientStylingUrl) {
76
78
  * @param {HTMLElement} stylingContainer The highest element of the widget
77
79
  * @param {string} domain The domain from where the content should be fetched (e.g. 'Casino.Style', 'App.Style', 'casino-footer.style', etc.)
78
80
  * @param {ref} subscription A reference to a variable where the subscription should be saved for unsubscribing when no longer needed
81
+ * @param {boolean} useAdoptedStyleSheets A flag to gradually enable testing of adoptedStyleSheets
79
82
  */
80
- function setStreamStyling(stylingContainer, domain, subscription) {
81
- if (window.emMessageBus) {
82
- const sheet = document.createElement('style');
83
+ function setStreamStyling(stylingContainer, domain, subscription, useAdoptedStyleSheets = false) {
84
+ if (!window.emMessageBus) return;
83
85
 
84
- window.emMessageBus.subscribe(domain, (data) => {
85
- sheet.innerHTML = data;
86
- if (stylingContainer) {
87
- stylingContainer.appendChild(sheet);
88
- }
89
- });
86
+ const supportAdoptStyle = 'adoptedStyleSheets' in Document.prototype;
87
+
88
+ if (!supportAdoptStyle || !useAdoptedStyleSheets) {
89
+ subscription = getStyleTagSubscription(stylingContainer, domain);
90
+
91
+ return subscription;
92
+ }
93
+
94
+ if (!window[StyleCacheKey]) {
95
+ window[StyleCacheKey] = {};
90
96
  }
97
+ subscription = getAdoptStyleSubscription(stylingContainer, domain);
98
+
99
+ const originalUnsubscribe = subscription.unsubscribe.bind(subscription);
100
+ const wrappedUnsubscribe = () => {
101
+ if (window[StyleCacheKey][domain]) {
102
+ const cachedObject = window[StyleCacheKey][domain];
103
+ cachedObject.refCount > 1
104
+ ? (cachedObject.refCount = cachedObject.refCount - 1)
105
+ : delete window[StyleCacheKey][domain];
106
+ }
107
+
108
+ originalUnsubscribe();
109
+ };
110
+ subscription.unsubscribe = wrappedUnsubscribe;
111
+
112
+ return subscription;
113
+ }
114
+
115
+ function getStyleTagSubscription(stylingContainer, domain) {
116
+ const sheet = document.createElement('style');
117
+
118
+ return window.emMessageBus.subscribe(domain, (data) => {
119
+ if (stylingContainer) {
120
+ sheet.innerHTML = data;
121
+ stylingContainer.appendChild(sheet);
122
+ }
123
+ });
124
+ }
125
+
126
+ function getAdoptStyleSubscription(stylingContainer, domain) {
127
+ return window.emMessageBus.subscribe(domain, (data) => {
128
+ if (!stylingContainer) return;
129
+
130
+ const shadowRoot = stylingContainer.getRootNode();
131
+ const cacheStyleObject = window[StyleCacheKey];
132
+ let cachedStyle = cacheStyleObject[domain]?.sheet;
133
+
134
+ if (!cachedStyle) {
135
+ cachedStyle = new CSSStyleSheet();
136
+ cachedStyle.replaceSync(data);
137
+ cacheStyleObject[domain] = {
138
+ sheet: cachedStyle,
139
+ refCount: 1
140
+ };
141
+ } else {
142
+ cacheStyleObject[domain].refCount = cacheStyleObject[domain].refCount + 1;
143
+ }
144
+
145
+ const currentSheets = shadowRoot.adoptedStyleSheets || [];
146
+ if (!currentSheets.includes(cachedStyle)) {
147
+ shadowRoot.adoptedStyleSheets = [...currentSheets, cachedStyle];
148
+ }
149
+ });
91
150
  }
92
151
 
93
152
  const helperAccordionCss = "@import url(\"https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap\");:host{display:block;font-family:\"Roboto\", sans-serif}.Header{border-radius:5px;background:var(--emw--color-primary, #009993);display:flex;gap:30px;border:1px solid var(--emw--color-primary, #009993);padding:8px 10px;user-select:none;margin-bottom:1px;cursor:pointer}.Header:hover{background:var(--emw--color-secondary, #00aba4)}.Header .Title,.Header .Subtitle,.Header .Description{margin:0;font-size:14px;color:var(--emw--color-typography-inverse, rgb(255, 255, 255));text-transform:capitalize}.Header .Expand{margin-left:auto;color:var(--emw--color-typography-inverse, rgb(255, 255, 255));width:17px;height:17px;cursor:pointer;text-align:center;transform:rotate(90deg);font-size:20px;user-select:none}.HeaderTicketHistory{border-radius:4px;background:var(--emw--color-background, #fff);display:flex;gap:30px;border:1px solid var(--emw--color-primary, #009993);padding:8px 10px;user-select:none;margin-bottom:5px;cursor:pointer}.HeaderTicketHistory:hover{background:var(--emw--color-secondary, #00aba4)}.HeaderTicketHistory .Title,.HeaderTicketHistory .Subtitle,.HeaderTicketHistory .Description{margin:0;font-size:14px;color:var(--emw--color-typography, #000)}.HeaderTicketHistory .Expand{margin-left:auto;color:var(--emw--color-typography-inverse, rgb(255, 255, 255));width:17px;height:17px;cursor:pointer;text-align:center;transform:rotate(90deg);font-size:20px;user-select:none}.Content{border-radius:0 0 4px 4px;background:var(--emw--color-background, #fff);border:1px solid var(--emw--color-primary, #009993);padding:10px 15px;user-select:none;color:var(--emw--color-typography, #000);margin-bottom:10px}.ActionButton{cursor:pointer;display:inline-block;border-radius:var(--emw--button-border-radius, 4px);margin:20px 0 10px;text-transform:uppercase;font-size:12px;text-align:center;padding:8px 20px;min-width:80px;background:var(--emw--color-error, #ff3d00);border:1px solid var(--emw--color-error, #ff3d00);color:var(--emw--color-background, #fff)}.ActionButton:hover{background:var(--emw--color-secondary, #ff6536);border:1px solid var(--emw--color-error, #ff3d00)}";
@@ -126,13 +185,13 @@ const HelperAccordion = class {
126
185
  }
127
186
  handleMbSourceChange(newValue, oldValue) {
128
187
  if (newValue != oldValue) {
129
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
188
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
130
189
  }
131
190
  }
132
191
  componentDidLoad() {
133
192
  if (this.stylingContainer) {
134
193
  if (this.mbSource)
135
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
194
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
136
195
  if (this.clientStyling)
137
196
  setClientStyling(this.stylingContainer, this.clientStyling);
138
197
  if (this.clientStylingUrl)
@@ -207,13 +266,13 @@ const LotteryBullet = class {
207
266
  }
208
267
  handleMbSourceChange(newValue, oldValue) {
209
268
  if (newValue != oldValue) {
210
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
269
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
211
270
  }
212
271
  }
213
272
  componentDidLoad() {
214
273
  if (this.stylingContainer) {
215
274
  if (this.mbSource)
216
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
275
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
217
276
  if (this.clientStyling)
218
277
  setClientStyling(this.stylingContainer, this.clientStyling);
219
278
  if (this.clientStylingUrl)
@@ -276,13 +335,13 @@ const LotteryGrid = class {
276
335
  }
277
336
  handleMbSourceChange(newValue, oldValue) {
278
337
  if (newValue != oldValue) {
279
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
338
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
280
339
  }
281
340
  }
282
341
  componentDidLoad() {
283
342
  if (this.stylingContainer) {
284
343
  if (this.mbSource)
285
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
344
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
286
345
  if (this.clientStyling)
287
346
  setClientStyling(this.stylingContainer, this.clientStyling);
288
347
  if (this.clientStylingUrl)
@@ -7296,7 +7355,7 @@ const LotteryTicket = class {
7296
7355
  }
7297
7356
  handleMbSourceChange(newValue, oldValue) {
7298
7357
  if (newValue != oldValue) {
7299
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7358
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7300
7359
  }
7301
7360
  }
7302
7361
  checkForClickOutside(ev) {
@@ -7383,7 +7442,7 @@ const LotteryTicket = class {
7383
7442
  componentDidLoad() {
7384
7443
  if (this.stylingContainer) {
7385
7444
  if (this.mbSource)
7386
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7445
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7387
7446
  if (this.clientStyling)
7388
7447
  setClientStyling(this.stylingContainer, this.clientStyling);
7389
7448
  if (this.clientStylingUrl)
@@ -7604,13 +7663,13 @@ const LotteryTicketController = class {
7604
7663
  }
7605
7664
  handleMbSourceChange(newValue, oldValue) {
7606
7665
  if (newValue != oldValue) {
7607
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7666
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7608
7667
  }
7609
7668
  }
7610
7669
  componentDidLoad() {
7611
7670
  if (this.stylingContainer) {
7612
7671
  if (this.mbSource)
7613
- setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`);
7672
+ setStreamStyling(this.stylingContainer, `${this.mbSource}.Style`, this.stylingSubscription);
7614
7673
  if (this.clientStyling)
7615
7674
  setClientStyling(this.stylingContainer, this.clientStyling);
7616
7675
  if (this.clientStylingUrl)