@css-hooks/preact 2.0.3 → 3.0.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/README.md CHANGED
@@ -27,18 +27,18 @@ experience without runtime style injection or build steps.
27
27
 
28
28
  ```jsx
29
29
  <button
30
- style={css({
31
- background: "#004982",
32
- color: "#eeeff0",
33
- on: $ => [
34
- $("&:hover", {
35
- background: "#1b659c",
36
- }),
37
- $("&:active", {
38
- background: "#9f3131",
39
- }),
40
- ],
41
- })}
30
+ style={pipe(
31
+ {
32
+ background: "#004982",
33
+ color: "#eeeff0",
34
+ },
35
+ on("&:hover", {
36
+ background: "#1b659c",
37
+ }),
38
+ on("&:active", {
39
+ background: "#9f3131",
40
+ }),
41
+ )}
42
42
  >
43
43
  Save changes
44
44
  </button>
@@ -50,13 +50,12 @@ experience without runtime style injection or build steps.
50
50
  <label>
51
51
  <input type="checkbox" checked />
52
52
  <span
53
- style={css({
54
- on: $ => [
55
- $(":checked + &", {
56
- textDecoration: "line-through",
57
- }),
58
- ],
59
- })}
53
+ style={pipe(
54
+ {},
55
+ on(":checked + &", {
56
+ textDecoration: "line-through",
57
+ }),
58
+ )}
60
59
  >
61
60
  Simplify CSS architecture
62
61
  </span>
@@ -68,30 +67,42 @@ experience without runtime style injection or build steps.
68
67
  ```jsx
69
68
  <>
70
69
  <span
71
- style={css({
72
- on: ($, { not }) => [
73
- $(not("@container sm"), {
74
- display: "none",
75
- }),
76
- ],
77
- })}
70
+ style={pipe(
71
+ {},
72
+ on(not("@container (width < 400px)"), {
73
+ display: "none",
74
+ }),
75
+ )}
78
76
  >
79
77
  sm
80
78
  </span>
81
79
  <span
82
- style={css({
83
- on: ($, { not }) => [
84
- $(not("@container lg"), {
85
- display: "none",
86
- }),
87
- ],
88
- })}
80
+ style={pipe(
81
+ {},
82
+ on("@container (width < 400px)", {
83
+ display: "none",
84
+ }),
85
+ )}
89
86
  >
90
87
  lg
91
88
  </span>
92
89
  </>
93
90
  ```
94
91
 
92
+ ## Compatibility
93
+
94
+ ### Framework integrations
95
+
96
+ | <img src="https://github.com/reactjs.png" alt="React" style="width: 24px; height: 24px" /><br/>React | <img src="https://github.com/preactjs.png" alt="Preact" style="width: 24px; height: 24px" /><br/>Preact | <img src="https://github.com/solidjs.png" alt="Solid" style="width: 24px; height: 24px" /><br/>Solid | <img src="https://github.com/qwikdev.png" alt="Qwik" style="width: 24px; height: 24px" /><br/>Qwik |
97
+ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
98
+ | <div align="center"><a href="https://www.npmjs.com/package/@css-hooks/react">✅</a></div> | <div align="center"><a href="https://www.npmjs.com/package/@css-hooks/preact">✅</a></div> | <div align="center"><a href="https://www.npmjs.com/package/@css-hooks/solid">✅</a></div> | <div align="center"><a href="https://www.npmjs.com/package/@css-hooks/qwik">✅</a></div> |
99
+
100
+ ### Browser support
101
+
102
+ | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/chrome/chrome_24x24.png" alt="Chrome" /><br/>Chrome | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/edge/edge_24x24.png" alt="Edge" /><br/>Edge | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/safari/safari_24x24.png" alt="Safari" /><br/>Safari | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/firefox/firefox_24x24.png" alt="Firefox" /><br/>Firefox | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/opera/opera_24x24.png" alt="Opera" /><br/>Opera |
103
+ | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
104
+ | <div align="center">49+</div> | <div align="center">16+</div> | <div align="center">10+</div> | <div align="center">31+</div> | <div align="center">36+</div> |
105
+
95
106
  ## Documentation
96
107
 
97
108
  Please visit [css-hooks.com](https://css-hooks.com) to get started.
package/cjs/index.js CHANGED
@@ -1,27 +1,32 @@
1
- 'use strict';
2
- // @ts-nocheck
3
-
4
- const { buildHooksSystem } = require("@css-hooks/core");
5
-
6
- const IS_NON_DIMENSIONAL =
7
- /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
8
-
9
- function _stringifyValue(propertyName, value) {
10
- switch (typeof value) {
11
- case "string":
12
- return value;
13
- case "number":
14
- return `${value}${
15
- typeof propertyName === "string" &&
16
- IS_NON_DIMENSIONAL.test(propertyName)
17
- ? ""
18
- : "px"
19
- }`;
20
- default:
21
- return null;
22
- }
1
+ "use strict";
2
+ /**
3
+ * CSS Hooks for {@link https://preactjs.com | Preact}
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports._stringifyValue = exports.createHooks = void 0;
9
+ const core_1 = require("@css-hooks/core");
10
+ const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
11
+ /**
12
+ * A {@link @css-hooks/core#CreateHooksFn} configured to use Preact's
13
+ * `JSX.CSSProperties` type and logic for converting CSS values into strings.
14
+ *
15
+ * @public
16
+ */
17
+ exports.createHooks = (0, core_1.buildHooksSystem)(_stringifyValue);
18
+ /** @internal */
19
+ function _stringifyValue(value, propertyName) {
20
+ switch (typeof value) {
21
+ case "string":
22
+ return value;
23
+ case "number":
24
+ return `${value}${typeof propertyName === "string" &&
25
+ IS_NON_DIMENSIONAL.test(propertyName)
26
+ ? ""
27
+ : "px"}`;
28
+ default:
29
+ return null;
30
+ }
23
31
  }
24
- exports._stringifyValue = _stringifyValue
25
-
26
- const createHooks = buildHooksSystem(_stringifyValue);
27
- exports.createHooks = createHooks;
32
+ exports._stringifyValue = _stringifyValue;
package/esm/index.js CHANGED
@@ -1,24 +1,28 @@
1
- // @ts-nocheck
2
-
1
+ /**
2
+ * CSS Hooks for {@link https://preactjs.com | Preact}
3
+ *
4
+ * @packageDocumentation
5
+ */
3
6
  import { buildHooksSystem } from "@css-hooks/core";
4
-
5
- const IS_NON_DIMENSIONAL =
6
- /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
7
-
8
- export function _stringifyValue(propertyName, value) {
9
- switch (typeof value) {
10
- case "string":
11
- return value;
12
- case "number":
13
- return `${value}${
14
- typeof propertyName === "string" &&
15
- IS_NON_DIMENSIONAL.test(propertyName)
16
- ? ""
17
- : "px"
18
- }`;
19
- default:
20
- return null;
21
- }
22
- }
23
-
7
+ const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
8
+ /**
9
+ * A {@link @css-hooks/core#CreateHooksFn} configured to use Preact's
10
+ * `JSX.CSSProperties` type and logic for converting CSS values into strings.
11
+ *
12
+ * @public
13
+ */
24
14
  export const createHooks = buildHooksSystem(_stringifyValue);
15
+ /** @internal */
16
+ export function _stringifyValue(value, propertyName) {
17
+ switch (typeof value) {
18
+ case "string":
19
+ return value;
20
+ case "number":
21
+ return `${value}${typeof propertyName === "string" &&
22
+ IS_NON_DIMENSIONAL.test(propertyName)
23
+ ? ""
24
+ : "px"}`;
25
+ default:
26
+ return null;
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,29 +1,25 @@
1
1
  {
2
2
  "name": "@css-hooks/preact",
3
3
  "description": "CSS Hooks for Preact",
4
- "version": "2.0.3",
4
+ "version": "3.0.0",
5
5
  "author": "Nick Saunders",
6
6
  "dependencies": {
7
- "@css-hooks/core": "^2.0.3"
7
+ "@css-hooks/core": "3.0.0"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@microsoft/api-extractor": "^7.39.4",
11
- "@tsconfig/strictest": "^2.0.1",
12
- "@typescript-eslint/eslint-plugin": "^7.0.0",
13
- "@typescript-eslint/parser": "^7.0.0",
14
- "ascjs": "^6.0.3",
15
- "eslint": "^8.50.0",
16
- "eslint-plugin-compat": "^4.2.0",
11
+ "@types/node": "^20.12.7",
17
12
  "preact": ">=10.0.0 <11.0.0",
18
13
  "rimraf": "^5.0.1",
19
- "ts-watch": "^1.0.8",
20
- "typescript": "^5.1.6"
14
+ "tsx": "^4.19.1",
15
+ "typescript": "=5.4.2"
21
16
  },
22
17
  "files": [
23
18
  "cjs",
24
19
  "esm",
25
20
  "types",
26
- "tsdoc-metadata.json"
21
+ "tsdoc-metadata.json",
22
+ "!**/*.test.*"
27
23
  ],
28
24
  "license": "MIT",
29
25
  "main": "cjs",
@@ -32,30 +28,28 @@
32
28
  "peerDependencies": {
33
29
  "preact": ">=10.0.0 <11.0.0"
34
30
  },
31
+ "peerDependenciesMeta": {
32
+ "preact": {
33
+ "optional": true
34
+ }
35
+ },
35
36
  "private": false,
36
37
  "repository": {
37
38
  "type": "git",
38
39
  "url": "https://github.com/css-hooks/css-hooks.git",
39
40
  "directory": "packages/preact"
40
41
  },
41
- "scripts": {
42
- "api": "node -e \"var path=require('path').resolve,fs=require('fs'),cp=fs.cpSync;cp(path('src', 'index.d.ts'),path('types','index.d.ts'))\" && api-extractor run",
43
- "clean": "rimraf cjs esm out types",
44
- "lint": "eslint src .*.*js *.*js",
45
- "postversion": "npm install @css-hooks/core@^$npm_package_version --force",
46
- "prepublishOnly": "node -e \"var path=require('path').resolve,fs=require('fs'),cp=fs.cpSync,mkdir=fs.mkdirSync;cp(path('src', 'index.d.ts'),path('types','index.d.ts'));cp(path('src','index.js'),path('esm','index.js'));mkdir(path('cjs'),{recursive:true})\" && ascjs src/index.js cjs/index.js",
47
- "test": "tsc && node --test",
48
- "test.watch": "tsc-watch --onSuccess 'node --test'"
49
- },
50
42
  "types": "types",
51
43
  "exports": {
52
44
  ".": {
45
+ "@css-hooks/source": "./src/index.ts",
53
46
  "import": "./esm/index.js",
54
47
  "require": "./cjs/index.js",
55
48
  "types": "./types/index.d.ts"
56
49
  }
57
50
  },
58
- "browserslist": [
59
- "supports css-variables"
60
- ]
61
- }
51
+ "scripts": {
52
+ "clean": "rimraf cjs esm types",
53
+ "test": "node --import tsx --conditions @css-hooks/source --test src/index.test.ts"
54
+ }
55
+ }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.43.1"
9
+ }
10
+ ]
11
+ }
package/types/index.d.ts CHANGED
@@ -3,27 +3,13 @@
3
3
  *
4
4
  * @packageDocumentation
5
5
  */
6
-
7
6
  import type { JSX } from "preact";
8
- import type { CreateHooksFn } from "@css-hooks/core";
9
-
10
- /**
11
- * A version of Preact's `JSX.CSSProperties` type that admits an `on` field
12
- *
13
- * @public
14
- */
15
- export type CSSProperties = JSX.DOMCSSProperties & { cssText?: string | null };
16
-
17
7
  /**
18
8
  * A {@link @css-hooks/core#CreateHooksFn} configured to use Preact's
19
9
  * `JSX.CSSProperties` type and logic for converting CSS values into strings.
20
10
  *
21
11
  * @public
22
12
  */
23
- export const createHooks: CreateHooksFn<CSSProperties>;
24
-
13
+ export declare const createHooks: import("@css-hooks/core").CreateHooksFn<JSX.CSSProperties>;
25
14
  /** @internal */
26
- declare function _stringifyValue(
27
- propertyName: string,
28
- value: unknown,
29
- ): string | null;
15
+ export declare function _stringifyValue(value: unknown, propertyName: string): string | null;