@blockquote-web-components/blockquote-base-style-helpers 1.1.9 → 1.1.10

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/README.md CHANGED
@@ -204,10 +204,10 @@ export default css`
204
204
 
205
205
  #### Functions
206
206
 
207
- | Name | Description | Parameters | Return |
208
- | --------------------- | ----------- | -------------------- | ------ |
209
- | `adoptDocumentStyles` | | `renderRoot, styles` | |
210
- | `setDocumentStyles` | | `styles` | |
207
+ | Name | Description | Parameters | Return |
208
+ | --------------------- | --------------------------------------------- | ---------------------------------------------------- | ------ |
209
+ | `adoptDocumentStyles` | Adopts the given styles into the render root. | `renderRoot: Document \| HTMLElement, styles: Array` | |
210
+ | `setDocumentStyles` | Sets the document styles. | `styles: !*` | |
211
211
 
212
212
  <hr/>
213
213
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockquote-web-components/blockquote-base-style-helpers",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "Webcomponent blockquote-base-style-helpers following open-wc recommendations",
5
5
  "keywords": [
6
6
  "lit",
@@ -135,6 +135,9 @@
135
135
  "import/prefer-default-export": "off",
136
136
  "lit/no-classfield-shadowing": "off",
137
137
  "lit/no-native-attributes": "off"
138
+ },
139
+ "globals": {
140
+ "globalThis": "readonly"
138
141
  }
139
142
  },
140
143
  "stylelint": {
@@ -158,5 +161,5 @@
158
161
  "access": "public"
159
162
  },
160
163
  "customElements": "custom-elements.json",
161
- "gitHead": "0c10727d27b0d5f05acb9aeef97807513aef9874"
164
+ "gitHead": "ef40e9fad141e3a19ab89496d3cabcfa5f02447d"
162
165
  }
@@ -1,19 +1,43 @@
1
+ const globalThisOrWindow = globalThis /* c8 ignore next */ || window;
2
+
3
+ /**
4
+ * Checks if the current environment supports adopting style sheets.
5
+ * @type {boolean}
6
+ */
1
7
  const supportsAdoptingStyleSheets =
2
- window.ShadowRoot &&
3
- (window.ShadyCSS === undefined || /* c8 ignore next */ window.ShadyCSS.nativeShadow) &&
8
+ globalThisOrWindow.ShadowRoot &&
9
+ // @ts-ignore
10
+ (globalThisOrWindow.ShadyCSS === undefined /* c8 ignore next */ ||
11
+ globalThisOrWindow.ShadyCSS.nativeShadow) &&
4
12
  'adoptedStyleSheets' in Document.prototype &&
5
13
  'replace' in CSSStyleSheet.prototype;
6
14
 
15
+ /**
16
+ * The root element where styles will be rendered.
17
+ * @type {Document | HTMLElement}
18
+ */
7
19
  const renderDocumentRoot = supportsAdoptingStyleSheets
8
20
  ? document
9
21
  : /* c8 ignore next */ document.head;
10
22
 
23
+ /**
24
+ * Flattens the styles array.
25
+ * @param {Array} styles - The styles to flatten.
26
+ * @returns {Array} The flattened styles.
27
+ */
28
+ const flattenStyles = styles => (Array.isArray(styles) ? styles.flat(Infinity) : [styles]);
29
+
30
+ /**
31
+ * Adopts the given styles into the render root.
32
+ * @param {Document | HTMLElement} renderRoot - The root element where styles will be rendered.
33
+ * @param {Array} styles - The styles to adopt.
34
+ */
11
35
  export const adoptDocumentStyles = (renderRoot, styles) => {
12
36
  if (supportsAdoptingStyleSheets) {
13
37
  // https://github.com/lit/lit/issues/2984#issuecomment-1150224373
14
- // eslint-disable-next-line no-param-reassign
15
- renderRoot.adoptedStyleSheets = [
16
- ...renderRoot.adoptedStyleSheets,
38
+ const documentRoot = /** @type {Document} */ (renderRoot);
39
+ documentRoot.adoptedStyleSheets = [
40
+ ...documentRoot.adoptedStyleSheets,
17
41
  ...styles.map(s => (s instanceof CSSStyleSheet ? s : s.styleSheet)),
18
42
  ];
19
43
  } else {
@@ -25,6 +49,11 @@ export const adoptDocumentStyles = (renderRoot, styles) => {
25
49
  }
26
50
  };
27
51
 
52
+ /**
53
+ * Sets the document styles.
54
+ * @param {!*} styles - The styles to set.
55
+ */
28
56
  export const setDocumentStyles = styles => {
29
- adoptDocumentStyles(renderDocumentRoot, [styles]);
57
+ const flattenedArray = flattenStyles(styles);
58
+ adoptDocumentStyles(renderDocumentRoot, flattenedArray);
30
59
  };