@descope-ui/common 0.0.9 → 0.0.11

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.11](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.10...@descope-ui/common-0.0.11) (2025-04-29)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * CSSStyleSheet fallback for older browser ([#639](https://github.com/descope/web-components-ui/issues/639)) ([1ff86cc](https://github.com/descope/web-components-ui/commit/1ff86ccd6d5a00de025207d99f034772b92ac910))
11
+
12
+ ## [0.0.10](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.9...@descope-ui/common-0.0.10) (2025-04-16)
13
+
5
14
  ## [0.0.9](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.8...@descope-ui/common-0.0.9) (2025-03-06)
6
15
 
7
16
  ## [0.0.8](https://github.com/descope/web-components-ui/compare/@descope-ui/common-0.0.7...@descope-ui/common-0.0.8) (2025-03-05)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@descope-ui/common",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "dependencies": {
5
5
  "element-internals-polyfill": "^1.3.9",
6
6
  "color": "^4.2.3",
@@ -45,19 +45,19 @@ export const observeChildren = (ele, callback) => {
45
45
 
46
46
  const createSyncAttrsCb =
47
47
  (srcEle, targetEle, mapAttrs = {}) =>
48
- (attrNames) => {
49
- attrNames.forEach((attrName) => {
50
- const targetAttrName = mapAttrs[attrName] || attrName;
51
- const srcAttrVal = srcEle.getAttribute(attrName);
52
- if (srcAttrVal !== null) {
53
- if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
54
- targetEle.setAttribute(targetAttrName, srcAttrVal);
48
+ (attrNames) => {
49
+ attrNames.forEach((attrName) => {
50
+ const targetAttrName = mapAttrs[attrName] || attrName;
51
+ const srcAttrVal = srcEle.getAttribute(attrName);
52
+ if (srcAttrVal !== null) {
53
+ if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
54
+ targetEle.setAttribute(targetAttrName, srcAttrVal);
55
+ }
56
+ } else {
57
+ targetEle.removeAttribute(targetAttrName);
55
58
  }
56
- } else {
57
- targetEle.removeAttribute(targetAttrName);
58
- }
59
- });
60
- };
59
+ });
60
+ };
61
61
 
62
62
  export const syncAttrs = (ele1, ele2, options) => {
63
63
  observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
@@ -94,8 +94,16 @@ export const forwardProps = (src, target, props = []) => {
94
94
  Object.defineProperties(target, config);
95
95
  };
96
96
 
97
- export const injectStyle = (cssString, ref, {prepend = false} = {}) => {
98
- const style = new CSSStyleSheet();
97
+ export const injectStyle = (cssString, ref, { prepend = false } = {}) => {
98
+
99
+ let style;
100
+ try {
101
+ style = new CSSStyleSheet();
102
+ } catch (e) {
103
+ // fallback for browsers that don't support CSSStyleSheet
104
+ return generateStyleTagFallback(cssString, ref, { prepend });
105
+ }
106
+
99
107
  const _ref = ref?.shadowRoot || ref;
100
108
  if (cssString) {
101
109
  style.replaceSync(cssString);
@@ -109,3 +117,33 @@ export const injectStyle = (cssString, ref, {prepend = false} = {}) => {
109
117
 
110
118
  return style;
111
119
  }
120
+
121
+ // we should mimic the CSSStyleSheet API for the fns we are using
122
+ class CSSStyleSheetMock {
123
+ constructor(cssString, ref, { prepend = false } = {}) {
124
+ this.styleEle = document.createElement('style');
125
+ this.styleEle.textContent = cssString;
126
+ this.styleEle.setAttribute('nonce', window.DESCOPE_NONCE);
127
+ this.ref = ref?.shadowRoot || ref;
128
+
129
+ if (!this.ref) {
130
+ return
131
+ }
132
+
133
+ if (prepend) {
134
+ this.ref.prepend(this.styleEle);
135
+ } else {
136
+ this.ref.append(this.styleEle);
137
+ }
138
+ }
139
+
140
+ replaceSync(cssString) {
141
+ this.styleEle.textContent = cssString;
142
+ }
143
+
144
+ get cssRules() {
145
+ return this.styleEle.sheet?.cssRules;
146
+ }
147
+ }
148
+
149
+ const generateStyleTagFallback = (cssString, ref, { prepend = false } = {}) => new CSSStyleSheetMock(cssString, ref, { prepend });
@@ -22,6 +22,7 @@ const booleanAttributesList = [
22
22
  'has-no-options',
23
23
  'loading',
24
24
  'allow-custom-value',
25
+ 'collapsed',
25
26
  ];
26
27
 
27
28
  const isBooleanAttribute = (attr) => {