@css-hooks/preact 0.6.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/cjs/index.js +38 -0
- package/esm/index.js +34 -0
- package/package.json +44 -0
- package/types/index.d.ts +29 -0
package/cjs/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recommended = exports.createHooks = exports.stringifyValue = void 0;
|
|
4
|
+
const core_1 = require("@css-hooks/core");
|
|
5
|
+
Object.defineProperty(exports, "recommended", { enumerable: true, get: function () { return core_1.recommended; } });
|
|
6
|
+
/**
|
|
7
|
+
* @remarks
|
|
8
|
+
* Sourced from
|
|
9
|
+
* {@link https://github.com/preactjs/preact/blob/4fea40d1124ba631f8a11c27f6e71e018136318e/src/constants.js#L3-L4 | Preact}.
|
|
10
|
+
*/
|
|
11
|
+
const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This should align with
|
|
17
|
+
* {@link https://github.com/preactjs/preact/blob/4fea40d1124ba631f8a11c27f6e71e018136318e/src/diff/props.js#L36-L46 | Preact's algorithm}.
|
|
18
|
+
*/
|
|
19
|
+
function stringifyValue(propertyName, value) {
|
|
20
|
+
if (typeof value === "string") {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === "number") {
|
|
24
|
+
return `${value}${typeof propertyName === "string" && IS_NON_DIMENSIONAL.test(propertyName)
|
|
25
|
+
? ""
|
|
26
|
+
: "px"}`;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
exports.stringifyValue = stringifyValue;
|
|
31
|
+
/**
|
|
32
|
+
* Creates the hooks specified in the configuration.
|
|
33
|
+
*
|
|
34
|
+
* @param config - The hooks to build
|
|
35
|
+
*
|
|
36
|
+
* @returns The CSS required to enable the configured hooks, along with the corresponding `hooks` function for use in components.
|
|
37
|
+
*/
|
|
38
|
+
exports.createHooks = (0, core_1.buildHooksSystem)(stringifyValue);
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { buildHooksSystem, recommended } from "@css-hooks/core";
|
|
2
|
+
/**
|
|
3
|
+
* @remarks
|
|
4
|
+
* Sourced from
|
|
5
|
+
* {@link https://github.com/preactjs/preact/blob/4fea40d1124ba631f8a11c27f6e71e018136318e/src/constants.js#L3-L4 | Preact}.
|
|
6
|
+
*/
|
|
7
|
+
const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This should align with
|
|
13
|
+
* {@link https://github.com/preactjs/preact/blob/4fea40d1124ba631f8a11c27f6e71e018136318e/src/diff/props.js#L36-L46 | Preact's algorithm}.
|
|
14
|
+
*/
|
|
15
|
+
export function stringifyValue(propertyName, value) {
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value === "number") {
|
|
20
|
+
return `${value}${typeof propertyName === "string" && IS_NON_DIMENSIONAL.test(propertyName)
|
|
21
|
+
? ""
|
|
22
|
+
: "px"}`;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates the hooks specified in the configuration.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The hooks to build
|
|
30
|
+
*
|
|
31
|
+
* @returns The CSS required to enable the configured hooks, along with the corresponding `hooks` function for use in components.
|
|
32
|
+
*/
|
|
33
|
+
export const createHooks = buildHooksSystem(stringifyValue);
|
|
34
|
+
export { recommended };
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@css-hooks/preact",
|
|
3
|
+
"description": "CSS Hooks for Preact",
|
|
4
|
+
"version": "0.6.0",
|
|
5
|
+
"author": "Nick Saunders",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@css-hooks/core": "^0.6.0"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@tsconfig/node-lts": "^18.12.3",
|
|
11
|
+
"@tsconfig/strictest": "^2.0.1",
|
|
12
|
+
"@types/jest": "^29.5.3",
|
|
13
|
+
"jest": "^29.6.2",
|
|
14
|
+
"preact": ">=10.0.0 <11.0.0",
|
|
15
|
+
"rimraf": "^5.0.1",
|
|
16
|
+
"ts-jest": "^29.1.1",
|
|
17
|
+
"typescript": "^5.1.6"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"cjs",
|
|
21
|
+
"esm",
|
|
22
|
+
"types"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"main": "cjs",
|
|
26
|
+
"module": "esm",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"preact": ">=10.0.0 <11.0.0"
|
|
29
|
+
},
|
|
30
|
+
"private": false,
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/css-hooks/css-hooks.git",
|
|
34
|
+
"directory": "packages/preact"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"clean": "rimraf cjs esm types",
|
|
38
|
+
"lint": "eslint __tests__ src .*.*js *.*js",
|
|
39
|
+
"postversion": "npm install @css-hooks/core@^$npm_package_version --force",
|
|
40
|
+
"prepublishOnly": "tsc -p tsconfig.dist.json --outDir cjs --module commonjs && tsc -p tsconfig.dist.json --outDir esm --module es6 && tsc -p tsconfig.dist.json --declaration --emitDeclarationOnly --outDir types",
|
|
41
|
+
"test": "jest"
|
|
42
|
+
},
|
|
43
|
+
"types": "types"
|
|
44
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JSX } from "preact";
|
|
2
|
+
import { recommended } from "@css-hooks/core";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The type we really want is {@link JSX.CSSProperties}. However, that type
|
|
8
|
+
* enforces a flat structure that is incompatible with hooks.
|
|
9
|
+
*/
|
|
10
|
+
export type CSSProperties = JSX.DOMCSSProperties & {
|
|
11
|
+
cssText?: string | null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* This should align with
|
|
18
|
+
* {@link https://github.com/preactjs/preact/blob/4fea40d1124ba631f8a11c27f6e71e018136318e/src/diff/props.js#L36-L46 | Preact's algorithm}.
|
|
19
|
+
*/
|
|
20
|
+
export declare function stringifyValue(propertyName: string | number | symbol, value: unknown): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Creates the hooks specified in the configuration.
|
|
23
|
+
*
|
|
24
|
+
* @param config - The hooks to build
|
|
25
|
+
*
|
|
26
|
+
* @returns The CSS required to enable the configured hooks, along with the corresponding `hooks` function for use in components.
|
|
27
|
+
*/
|
|
28
|
+
export declare const createHooks: <HookProperties extends string | number | symbol>(config: Record<HookProperties, `@container ${string}` | `@media ${string}` | `:${string}` | `${string}&${string}`>) => readonly [string, (properties: import("@css-hooks/core").WithHooks<HookProperties, CSSProperties>) => CSSProperties];
|
|
29
|
+
export { recommended };
|