@thi.ng/hiccup-css 2.3.5 → 2.4.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-28T23:24:39Z
3
+ - **Last updated**: 2024-01-23T15:58:27Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-css@2.4.0) (2024-01-23)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add appendStyleSheet(), update injectStyleSheet() ([1eccb38](https://github.com/thi-ng/umbrella/commit/1eccb38))
17
+
12
18
  ### [2.3.4](https://github.com/thi-ng/umbrella/tree/@thi.ng/hiccup-css@2.3.4) (2023-12-22)
13
19
 
14
20
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -7,8 +7,9 @@
7
7
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/hiccup-css.svg)
8
8
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
9
9
 
10
- This project is part of the
11
- [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo and anti-framework.
10
+ This is a standalone project, maintained as part of the
11
+ [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo and
12
+ anti-framework.
12
13
 
13
14
  - [About](#about)
14
15
  - [Features](#features)
@@ -678,4 +679,4 @@ If this project contributes to an academic publication, please cite it as:
678
679
 
679
680
  ## License
680
681
 
681
- © 2016 - 2023 Karsten Schmidt // Apache License 2.0
682
+ © 2016 - 2024 Karsten Schmidt // Apache License 2.0
package/inject.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Injects given CSS string as global stylesheet in DOM head. If `first`
3
- * is true, inserts it as first stylesheet, else (default) appends it.
2
+ * Syntax sugar for {@link appendStyleSheet}. Injects given CSS string as global
3
+ * stylesheet in DOM head. If `first` is true, inserts it as first stylesheet,
4
+ * else (default) appends it.
4
5
  *
5
6
  * Returns created style DOM element.
6
7
  *
@@ -8,4 +9,15 @@
8
9
  * @param first - true, if prepend to stylesheet list (else append)
9
10
  */
10
11
  export declare const injectStyleSheet: (css: string, first?: boolean) => HTMLStyleElement;
12
+ /**
13
+ * Injects given CSS string as <style> element and attaches it to `parent`. If
14
+ * `first` is true, inserts it as first child, else (default) appends it.
15
+ * Returns created style DOM element.
16
+ *
17
+ * @param css
18
+ * @param parent
19
+ * @param first
20
+ * @returns
21
+ */
22
+ export declare const appendStyleSheet: (css: string, parent: Element | ShadowRoot, first?: boolean) => HTMLStyleElement;
11
23
  //# sourceMappingURL=inject.d.ts.map
package/inject.js CHANGED
@@ -1,5 +1,5 @@
1
- const injectStyleSheet = (css, first = false) => {
2
- const head = document.getElementsByTagName("head")[0];
1
+ const injectStyleSheet = (css, first = false) => appendStyleSheet(css, document.head, first);
2
+ const appendStyleSheet = (css, parent, first = false) => {
3
3
  const sheet = document.createElement("style");
4
4
  sheet.setAttribute("type", "text/css");
5
5
  if (sheet.styleSheet !== void 0) {
@@ -8,12 +8,13 @@ const injectStyleSheet = (css, first = false) => {
8
8
  sheet.textContent = css;
9
9
  }
10
10
  if (first) {
11
- head.insertBefore(sheet, head.firstChild);
11
+ parent.insertBefore(sheet, parent.firstChild);
12
12
  } else {
13
- head.appendChild(sheet);
13
+ parent.appendChild(sheet);
14
14
  }
15
15
  return sheet;
16
16
  };
17
17
  export {
18
+ appendStyleSheet,
18
19
  injectStyleSheet
19
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/hiccup-css",
3
- "version": "2.3.5",
3
+ "version": "2.4.0",
4
4
  "description": "CSS from nested JS data structures",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,10 +35,10 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.9.15",
39
- "@thi.ng/checks": "^3.4.15",
40
- "@thi.ng/errors": "^2.4.9",
41
- "@thi.ng/transducers": "^8.8.19"
38
+ "@thi.ng/api": "^8.9.17",
39
+ "@thi.ng/checks": "^3.4.17",
40
+ "@thi.ng/errors": "^2.4.11",
41
+ "@thi.ng/transducers": "^8.8.21"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@microsoft/api-extractor": "^7.39.0",
@@ -126,5 +126,5 @@
126
126
  ],
127
127
  "year": 2016
128
128
  },
129
- "gitHead": "775c664723cd87d6ac5909cedf91195317add287\n"
129
+ "gitHead": "417b5a7ea7bd54a3b4f086fe0fc2ce8e8933c9b2\n"
130
130
  }