@descope/web-components-ui 1.72.0 → 1.73.0

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.
@@ -270,19 +270,19 @@ const observeChildren = (ele, callback) => {
270
270
 
271
271
  const createSyncAttrsCb =
272
272
  (srcEle, targetEle, mapAttrs = {}) =>
273
- (attrNames) => {
274
- attrNames.forEach((attrName) => {
275
- const targetAttrName = mapAttrs[attrName] || attrName;
276
- const srcAttrVal = srcEle.getAttribute(attrName);
277
- if (srcAttrVal !== null) {
278
- if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
279
- targetEle.setAttribute(targetAttrName, srcAttrVal);
273
+ (attrNames) => {
274
+ attrNames.forEach((attrName) => {
275
+ const targetAttrName = mapAttrs[attrName] || attrName;
276
+ const srcAttrVal = srcEle.getAttribute(attrName);
277
+ if (srcAttrVal !== null) {
278
+ if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
279
+ targetEle.setAttribute(targetAttrName, srcAttrVal);
280
+ }
281
+ } else {
282
+ targetEle.removeAttribute(targetAttrName);
280
283
  }
281
- } else {
282
- targetEle.removeAttribute(targetAttrName);
283
- }
284
- });
285
- };
284
+ });
285
+ };
286
286
 
287
287
  const syncAttrs = (ele1, ele2, options) => {
288
288
  observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
@@ -319,8 +319,16 @@ const forwardProps$2 = (src, target, props = []) => {
319
319
  Object.defineProperties(target, config);
320
320
  };
321
321
 
322
- const injectStyle = (cssString, ref, {prepend = false} = {}) => {
323
- const style = new CSSStyleSheet();
322
+ const injectStyle = (cssString, ref, { prepend = false } = {}) => {
323
+
324
+ let style;
325
+ try {
326
+ style = new CSSStyleSheet();
327
+ } catch (e) {
328
+ // fallback for browsers that don't support CSSStyleSheet
329
+ return generateStyleTagFallback(cssString, ref, { prepend });
330
+ }
331
+
324
332
  const _ref = ref?.shadowRoot || ref;
325
333
  if (cssString) {
326
334
  style.replaceSync(cssString);
@@ -335,6 +343,36 @@ const injectStyle = (cssString, ref, {prepend = false} = {}) => {
335
343
  return style;
336
344
  };
337
345
 
346
+ // we should mimic the CSSStyleSheet API for the fns we are using
347
+ class CSSStyleSheetMock {
348
+ constructor(cssString, ref, { prepend = false } = {}) {
349
+ this.styleEle = document.createElement('style');
350
+ this.styleEle.textContent = cssString;
351
+ this.styleEle.setAttribute('nonce', window.DESCOPE_NONCE);
352
+ this.ref = ref?.shadowRoot || ref;
353
+
354
+ if (!this.ref) {
355
+ return
356
+ }
357
+
358
+ if (prepend) {
359
+ this.ref.prepend(this.styleEle);
360
+ } else {
361
+ this.ref.append(this.styleEle);
362
+ }
363
+ }
364
+
365
+ replaceSync(cssString) {
366
+ this.styleEle.textContent = cssString;
367
+ }
368
+
369
+ get cssRules() {
370
+ return this.styleEle.sheet?.cssRules;
371
+ }
372
+ }
373
+
374
+ const generateStyleTagFallback = (cssString, ref, { prepend = false } = {}) => new CSSStyleSheetMock(cssString, ref, { prepend });
375
+
338
376
  class ComponentsThemeManager {
339
377
  static mountOnPropName = 'DescopeThemeManager';
340
378