@css-hooks/core 3.2.0-next.8 → 4.0.0-next.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 +5 -5
- package/cjs/index.js +45 -32
- package/esm/index.js +45 -32
- package/package.json +1 -1
- package/types/index.d.ts +71 -61
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<a id="logomark" href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/
|
|
2
|
+
<a id="logomark" href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/v4.0.0-next.0/.github/logomark.svg" height="128" /></a><br/><br/>
|
|
3
3
|
<div id="wordmark">
|
|
4
|
-
<a href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/
|
|
4
|
+
<a href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/v4.0.0-next.0/.github/wordmark-dark.svg" width="256"></a>
|
|
5
5
|
</div>
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
8
|
<br/>
|
|
9
9
|
|
|
10
10
|
<div align="center" id="badges">
|
|
11
|
-
<a href="https://github.com/css-hooks/css-hooks/tree/
|
|
12
|
-
<a href="https://www.npmjs.com/package/@css-hooks/core/v/
|
|
13
|
-
<a href="https://github.com/css-hooks/css-hooks/blob/
|
|
11
|
+
<a href="https://github.com/css-hooks/css-hooks/tree/v4.0.0-next.0"><img src="https://img.shields.io/badge/tag-v4.0.0--next.0-ffd700" alt="tag v4.0.0-next.0"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@css-hooks/core/v/4.0.0-next.0"><img src="https://img.shields.io/badge/npm-v4.0.0--next.0-ffd700" alt="npm version"></a>
|
|
13
|
+
<a href="https://github.com/css-hooks/css-hooks/blob/v4.0.0-next.0/LICENSE"><img src="https://img.shields.io/badge/license-MIT-ffd700" alt="license"></a>
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
16
|
---
|
package/cjs/index.js
CHANGED
|
@@ -9,18 +9,22 @@ exports.buildHooksSystem = buildHooksSystem;
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a flavor of CSS Hooks tailored to a specific app framework.
|
|
11
11
|
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Primarily for internal use, advanced use cases, or when an appropriate
|
|
14
|
+
* framework integration is not provided
|
|
15
|
+
*
|
|
16
|
+
* @typeParam CSSProperties - The type of a style object, typically defined by
|
|
17
|
+
* an app framework (e.g., React's `CSSProperties` type)
|
|
18
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
19
|
+
* with which they conflict
|
|
20
|
+
*
|
|
12
21
|
* @param stringify - The function used to stringify values when merging
|
|
13
|
-
*
|
|
22
|
+
* override styles
|
|
14
23
|
*
|
|
15
24
|
* @returns The `createHooks` function used to bootstrap CSS Hooks within an app
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @remarks
|
|
19
|
-
* Primarily for internal use, advanced use cases, or when an appropriate
|
|
20
|
-
* framework integration is not provided.
|
|
25
|
+
* or component library
|
|
21
26
|
*
|
|
22
27
|
* @public
|
|
23
|
-
*
|
|
24
28
|
*/
|
|
25
29
|
function buildHooksSystem(stringify = String) {
|
|
26
30
|
return (...selectors) => {
|
|
@@ -32,8 +36,8 @@ function buildHooksSystem(stringify = String) {
|
|
|
32
36
|
const indent = Array(2).fill(space).join("");
|
|
33
37
|
return `*${space}{${newline}${selectors
|
|
34
38
|
.flatMap(selector => [
|
|
35
|
-
`${indent}--${createHash(selector)}
|
|
36
|
-
`${indent}--${createHash(selector)}
|
|
39
|
+
`${indent}--${createHash(selector)}0:${space}initial;`,
|
|
40
|
+
`${indent}--${createHash(selector)}1:${space};`,
|
|
37
41
|
])
|
|
38
42
|
.join(newline)}${newline}}${newline}${selectors
|
|
39
43
|
.flatMap(def => {
|
|
@@ -41,16 +45,16 @@ function buildHooksSystem(stringify = String) {
|
|
|
41
45
|
return [
|
|
42
46
|
`${def} {`,
|
|
43
47
|
`${indent}* {`,
|
|
44
|
-
`${indent}${indent}--${createHash(def)}
|
|
45
|
-
`${indent}${indent}--${createHash(def)}
|
|
48
|
+
`${indent}${indent}--${createHash(def)}0:${space};`,
|
|
49
|
+
`${indent}${indent}--${createHash(def)}1:${space}initial;`,
|
|
46
50
|
`${indent}}`,
|
|
47
51
|
"}",
|
|
48
52
|
];
|
|
49
53
|
}
|
|
50
54
|
return [
|
|
51
55
|
`${def.replace(/&/g, "*")}${space}{`,
|
|
52
|
-
`${indent}--${createHash(def)}
|
|
53
|
-
`${indent}--${createHash(def)}
|
|
56
|
+
`${indent}--${createHash(def)}0:${space};`,
|
|
57
|
+
`${indent}--${createHash(def)}1:${space}initial;`,
|
|
54
58
|
"}",
|
|
55
59
|
];
|
|
56
60
|
})
|
|
@@ -59,15 +63,12 @@ function buildHooksSystem(stringify = String) {
|
|
|
59
63
|
and: (...and) => ({ and }),
|
|
60
64
|
or: (...or) => ({ or }),
|
|
61
65
|
not: not => ({ not }),
|
|
62
|
-
on(condition,
|
|
63
|
-
return fallbackStyle => {
|
|
64
|
-
const conditionalStyle = conditionalStyleOrFn instanceof Function
|
|
65
|
-
? conditionalStyleOrFn(fallbackStyle)
|
|
66
|
-
: conditionalStyleOrFn;
|
|
66
|
+
on(condition, overrideStyle) {
|
|
67
|
+
return (fallbackStyle) => {
|
|
67
68
|
const style = { ...fallbackStyle };
|
|
68
|
-
for (const property in
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
69
|
+
for (const property in overrideStyle) {
|
|
70
|
+
const overrideValue = stringify(overrideStyle[property], property);
|
|
71
|
+
if (overrideValue === null) {
|
|
71
72
|
continue;
|
|
72
73
|
}
|
|
73
74
|
let fallbackValue = "revert-layer";
|
|
@@ -77,7 +78,7 @@ function buildHooksSystem(stringify = String) {
|
|
|
77
78
|
fallbackValue = fv;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
const [value, extraDecls] = buildExpression(condition,
|
|
81
|
+
const [value, extraDecls] = buildExpression(condition, overrideValue, fallbackValue);
|
|
81
82
|
Object.assign(style, { [property]: value }, extraDecls);
|
|
82
83
|
}
|
|
83
84
|
return style;
|
|
@@ -96,7 +97,7 @@ function buildHooksSystem(stringify = String) {
|
|
|
96
97
|
valFalse = `var(--${hash})`;
|
|
97
98
|
}
|
|
98
99
|
return [
|
|
99
|
-
`var(--${createHash(condition)}
|
|
100
|
+
`var(--${createHash(condition)}1,${space}${valTrue})${space}var(--${createHash(condition)}0,${space}${valFalse})`,
|
|
100
101
|
extraDecls,
|
|
101
102
|
];
|
|
102
103
|
}
|
|
@@ -125,14 +126,26 @@ function buildHooksSystem(stringify = String) {
|
|
|
125
126
|
};
|
|
126
127
|
};
|
|
127
128
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
let
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
const hashAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
130
|
+
function createHash(value) {
|
|
131
|
+
let h1 = 0xdeadbeef;
|
|
132
|
+
let h2 = 0x41c6ce57;
|
|
133
|
+
for (let i = 0; i < value.length; i++) {
|
|
134
|
+
const code = value.charCodeAt(i);
|
|
135
|
+
h1 = Math.imul(h1 ^ code, 0x9e3779b1);
|
|
136
|
+
h2 = Math.imul(h2 ^ code, 0x5f356495);
|
|
137
|
+
}
|
|
138
|
+
h1 =
|
|
139
|
+
Math.imul(h1 ^ (h1 >>> 16), 0x85ebca6b) ^
|
|
140
|
+
Math.imul(h2 ^ (h2 >>> 13), 0xc2b2ae35);
|
|
141
|
+
h2 =
|
|
142
|
+
Math.imul(h2 ^ (h2 >>> 16), 0x85ebca6b) ^
|
|
143
|
+
Math.imul(h1 ^ (h1 >>> 13), 0xc2b2ae35);
|
|
144
|
+
let hash = (h1 >>> 0) + 0x100000000 * (h2 & 0xf);
|
|
145
|
+
let encoded = "";
|
|
146
|
+
for (let i = 0; i < 6; i++) {
|
|
147
|
+
encoded = hashAlphabet.charAt(hash % 64) + encoded;
|
|
148
|
+
hash = Math.floor(hash / 64);
|
|
135
149
|
}
|
|
136
|
-
|
|
137
|
-
return /^[0-9]/.test(str) ? `a${str}` : str;
|
|
150
|
+
return encoded;
|
|
138
151
|
}
|
package/esm/index.js
CHANGED
|
@@ -6,18 +6,22 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates a flavor of CSS Hooks tailored to a specific app framework.
|
|
8
8
|
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Primarily for internal use, advanced use cases, or when an appropriate
|
|
11
|
+
* framework integration is not provided
|
|
12
|
+
*
|
|
13
|
+
* @typeParam CSSProperties - The type of a style object, typically defined by
|
|
14
|
+
* an app framework (e.g., React's `CSSProperties` type)
|
|
15
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
16
|
+
* with which they conflict
|
|
17
|
+
*
|
|
9
18
|
* @param stringify - The function used to stringify values when merging
|
|
10
|
-
*
|
|
19
|
+
* override styles
|
|
11
20
|
*
|
|
12
21
|
* @returns The `createHooks` function used to bootstrap CSS Hooks within an app
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* Primarily for internal use, advanced use cases, or when an appropriate
|
|
17
|
-
* framework integration is not provided.
|
|
22
|
+
* or component library
|
|
18
23
|
*
|
|
19
24
|
* @public
|
|
20
|
-
*
|
|
21
25
|
*/
|
|
22
26
|
export function buildHooksSystem(stringify = String) {
|
|
23
27
|
return (...selectors) => {
|
|
@@ -29,8 +33,8 @@ export function buildHooksSystem(stringify = String) {
|
|
|
29
33
|
const indent = Array(2).fill(space).join("");
|
|
30
34
|
return `*${space}{${newline}${selectors
|
|
31
35
|
.flatMap(selector => [
|
|
32
|
-
`${indent}--${createHash(selector)}
|
|
33
|
-
`${indent}--${createHash(selector)}
|
|
36
|
+
`${indent}--${createHash(selector)}0:${space}initial;`,
|
|
37
|
+
`${indent}--${createHash(selector)}1:${space};`,
|
|
34
38
|
])
|
|
35
39
|
.join(newline)}${newline}}${newline}${selectors
|
|
36
40
|
.flatMap(def => {
|
|
@@ -38,16 +42,16 @@ export function buildHooksSystem(stringify = String) {
|
|
|
38
42
|
return [
|
|
39
43
|
`${def} {`,
|
|
40
44
|
`${indent}* {`,
|
|
41
|
-
`${indent}${indent}--${createHash(def)}
|
|
42
|
-
`${indent}${indent}--${createHash(def)}
|
|
45
|
+
`${indent}${indent}--${createHash(def)}0:${space};`,
|
|
46
|
+
`${indent}${indent}--${createHash(def)}1:${space}initial;`,
|
|
43
47
|
`${indent}}`,
|
|
44
48
|
"}",
|
|
45
49
|
];
|
|
46
50
|
}
|
|
47
51
|
return [
|
|
48
52
|
`${def.replace(/&/g, "*")}${space}{`,
|
|
49
|
-
`${indent}--${createHash(def)}
|
|
50
|
-
`${indent}--${createHash(def)}
|
|
53
|
+
`${indent}--${createHash(def)}0:${space};`,
|
|
54
|
+
`${indent}--${createHash(def)}1:${space}initial;`,
|
|
51
55
|
"}",
|
|
52
56
|
];
|
|
53
57
|
})
|
|
@@ -56,15 +60,12 @@ export function buildHooksSystem(stringify = String) {
|
|
|
56
60
|
and: (...and) => ({ and }),
|
|
57
61
|
or: (...or) => ({ or }),
|
|
58
62
|
not: not => ({ not }),
|
|
59
|
-
on(condition,
|
|
60
|
-
return fallbackStyle => {
|
|
61
|
-
const conditionalStyle = conditionalStyleOrFn instanceof Function
|
|
62
|
-
? conditionalStyleOrFn(fallbackStyle)
|
|
63
|
-
: conditionalStyleOrFn;
|
|
63
|
+
on(condition, overrideStyle) {
|
|
64
|
+
return (fallbackStyle) => {
|
|
64
65
|
const style = { ...fallbackStyle };
|
|
65
|
-
for (const property in
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
66
|
+
for (const property in overrideStyle) {
|
|
67
|
+
const overrideValue = stringify(overrideStyle[property], property);
|
|
68
|
+
if (overrideValue === null) {
|
|
68
69
|
continue;
|
|
69
70
|
}
|
|
70
71
|
let fallbackValue = "revert-layer";
|
|
@@ -74,7 +75,7 @@ export function buildHooksSystem(stringify = String) {
|
|
|
74
75
|
fallbackValue = fv;
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
const [value, extraDecls] = buildExpression(condition,
|
|
78
|
+
const [value, extraDecls] = buildExpression(condition, overrideValue, fallbackValue);
|
|
78
79
|
Object.assign(style, { [property]: value }, extraDecls);
|
|
79
80
|
}
|
|
80
81
|
return style;
|
|
@@ -93,7 +94,7 @@ export function buildHooksSystem(stringify = String) {
|
|
|
93
94
|
valFalse = `var(--${hash})`;
|
|
94
95
|
}
|
|
95
96
|
return [
|
|
96
|
-
`var(--${createHash(condition)}
|
|
97
|
+
`var(--${createHash(condition)}1,${space}${valTrue})${space}var(--${createHash(condition)}0,${space}${valFalse})`,
|
|
97
98
|
extraDecls,
|
|
98
99
|
];
|
|
99
100
|
}
|
|
@@ -122,14 +123,26 @@ export function buildHooksSystem(stringify = String) {
|
|
|
122
123
|
};
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
let
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
126
|
+
const hashAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
127
|
+
function createHash(value) {
|
|
128
|
+
let h1 = 0xdeadbeef;
|
|
129
|
+
let h2 = 0x41c6ce57;
|
|
130
|
+
for (let i = 0; i < value.length; i++) {
|
|
131
|
+
const code = value.charCodeAt(i);
|
|
132
|
+
h1 = Math.imul(h1 ^ code, 0x9e3779b1);
|
|
133
|
+
h2 = Math.imul(h2 ^ code, 0x5f356495);
|
|
134
|
+
}
|
|
135
|
+
h1 =
|
|
136
|
+
Math.imul(h1 ^ (h1 >>> 16), 0x85ebca6b) ^
|
|
137
|
+
Math.imul(h2 ^ (h2 >>> 13), 0xc2b2ae35);
|
|
138
|
+
h2 =
|
|
139
|
+
Math.imul(h2 ^ (h2 >>> 16), 0x85ebca6b) ^
|
|
140
|
+
Math.imul(h1 ^ (h1 >>> 13), 0xc2b2ae35);
|
|
141
|
+
let hash = (h1 >>> 0) + 0x100000000 * (h2 & 0xf);
|
|
142
|
+
let encoded = "";
|
|
143
|
+
for (let i = 0; i < 6; i++) {
|
|
144
|
+
encoded = hashAlphabet.charAt(hash % 64) + encoded;
|
|
145
|
+
hash = Math.floor(hash / 64);
|
|
132
146
|
}
|
|
133
|
-
|
|
134
|
-
return /^[0-9]/.test(str) ? `a${str}` : str;
|
|
147
|
+
return encoded;
|
|
135
148
|
}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents the conditions under which a given hook or declaration applies.
|
|
8
8
|
*
|
|
9
|
-
* @typeParam S - The basic type of condition to enhance with boolean
|
|
10
|
-
* operations.
|
|
9
|
+
* @typeParam S - The basic type of condition to enhance with boolean operations
|
|
11
10
|
*
|
|
12
11
|
* @public
|
|
13
12
|
*/
|
|
@@ -19,18 +18,16 @@ export type Condition<S> = S | {
|
|
|
19
18
|
not: Condition<S>;
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
|
-
* Function to convert a value into a string
|
|
21
|
+
* Function to convert a value into a string
|
|
23
22
|
*
|
|
24
|
-
* @
|
|
23
|
+
* @remarks
|
|
24
|
+
* Used for merging a conditional property value with the fallback value
|
|
25
25
|
*
|
|
26
|
+
* @param value - The value to stringify
|
|
26
27
|
* @param propertyName - The property name corresponding to the value being
|
|
27
|
-
*
|
|
28
|
+
* stringified
|
|
28
29
|
*
|
|
29
|
-
* @
|
|
30
|
-
* Used for merging a conditional property value with the fallback value.
|
|
31
|
-
*
|
|
32
|
-
* @returns The stringified value, or `undefined` if the value cannot be
|
|
33
|
-
* stringified
|
|
30
|
+
* @returns The stringified value, or `null` if the value cannot be stringified
|
|
34
31
|
*
|
|
35
32
|
* @public
|
|
36
33
|
*/
|
|
@@ -39,57 +36,66 @@ export type StringifyFn = (value: unknown, propertyName: string) => string | nul
|
|
|
39
36
|
* Represents the selector logic used to create a hook.
|
|
40
37
|
*
|
|
41
38
|
* @remarks
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
39
|
+
* Three forms are supported:
|
|
40
|
+
*
|
|
41
|
+
* 1. A basic selector, where `&` is used as a placeholder for the element to which
|
|
42
|
+
* the condition applies. The `&` character must appear somewhere.
|
|
43
|
+
* 2. `@media`, `@container`, and `@supports` at-rules. Each value must begin with
|
|
44
|
+
* its keyword, followed by a space.
|
|
45
|
+
* 3. `@starting-style` with no additional parameters
|
|
48
46
|
*
|
|
49
47
|
* @public
|
|
50
48
|
*/
|
|
51
49
|
export type Selector = `${string}&${string}` | `@${"media" | "container" | "supports"} ${string}` | "@starting-style";
|
|
52
50
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @typeParam CSSProperties - The type of a standard (flat) style object,
|
|
56
|
-
* typically defined by an app framework (e.g., React's `CSSProperties` type).
|
|
51
|
+
* Resolves the CSS property names that conflict with an override style.
|
|
57
52
|
*
|
|
58
|
-
* @
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
53
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
54
|
+
* they conflict with
|
|
55
|
+
* @typeParam OverrideCSSProperties - The conditional declarations for which
|
|
56
|
+
* conflicting properties are resolved
|
|
57
|
+
*/
|
|
58
|
+
type CSSPropertyConflictKeys<CSSPropertyConflicts extends object, OverrideCSSProperties> = CSSPropertyConflicts[keyof OverrideCSSProperties & keyof CSSPropertyConflicts] & PropertyKey;
|
|
59
|
+
/**
|
|
60
|
+
* Prevents conflicting CSS properties from being assigned values in a base
|
|
61
|
+
* style.
|
|
61
62
|
*
|
|
62
|
-
* @
|
|
63
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
64
|
+
* with which they conflict
|
|
65
|
+
* @typeParam OverrideCSSProperties - The conditional declarations for which
|
|
66
|
+
* conflicting properties are forbidden
|
|
63
67
|
*/
|
|
64
|
-
|
|
68
|
+
type ForbidCSSPropertyConflicts<CSSPropertyConflicts extends object, OverrideCSSProperties> = {
|
|
69
|
+
[P in CSSPropertyConflictKeys<CSSPropertyConflicts, OverrideCSSProperties>]?: never;
|
|
70
|
+
};
|
|
65
71
|
/**
|
|
66
72
|
* An object containing the functions needed to support and use the configured
|
|
67
|
-
* hooks
|
|
73
|
+
* hooks
|
|
68
74
|
*
|
|
69
75
|
* @typeParam S - The type of the selector logic for which to generate hooks
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @public
|
|
76
|
+
* @typeParam CSSProperties - The type of a style object, typically defined by
|
|
77
|
+
* an app framework (e.g., React's `CSSProperties` type)
|
|
78
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
79
|
+
* with which they conflict
|
|
75
80
|
*/
|
|
76
|
-
|
|
81
|
+
interface CreateHooksResult<S, CSSProperties, CSSPropertyConflicts extends object> {
|
|
77
82
|
/**
|
|
78
|
-
*
|
|
83
|
+
* Creates a function that enhances a style object with conditional override
|
|
84
|
+
* styles.
|
|
79
85
|
*/
|
|
80
|
-
on: (condition: Condition<S>,
|
|
86
|
+
on: <OverrideCSSProperties extends CSSProperties, BaseCSSProperties extends Omit<CSSProperties, CSSPropertyConflictKeys<CSSPropertyConflicts, OverrideCSSProperties>>>(condition: Condition<S>, overrideStyle: OverrideCSSProperties) => (style: CSSProperties & BaseCSSProperties & ForbidCSSPropertyConflicts<CSSPropertyConflicts, OverrideCSSProperties>) => BaseCSSProperties & OverrideCSSProperties;
|
|
81
87
|
/**
|
|
82
88
|
* Combines a list of conditions into a single condition which is true when
|
|
83
89
|
* all of the specified conditions are true.
|
|
84
90
|
*
|
|
85
91
|
* @typeParam C - The type of the conditions which must all be true in order
|
|
86
|
-
*
|
|
92
|
+
* for the condition to be true
|
|
87
93
|
*
|
|
88
94
|
* @param conditions - The conditions which must all be true in order for the
|
|
89
|
-
*
|
|
95
|
+
* condition to be true
|
|
90
96
|
*
|
|
91
97
|
* @returns A condition that is true when all of the specified conditions are
|
|
92
|
-
*
|
|
98
|
+
* true
|
|
93
99
|
*/
|
|
94
100
|
and: <C extends Condition<S>[]>(...conditions: C) => {
|
|
95
101
|
and: C;
|
|
@@ -99,13 +105,13 @@ export interface CreateHooksResult<S, CSSProperties> {
|
|
|
99
105
|
* any of the specified conditions are true.
|
|
100
106
|
*
|
|
101
107
|
* @typeParam C - The type of the conditions any one of which must be true in
|
|
102
|
-
*
|
|
108
|
+
* order for the condition to be true
|
|
103
109
|
*
|
|
104
110
|
* @param conditions - The conditions any one of which must be true in order
|
|
105
|
-
*
|
|
111
|
+
* for the condition to be true
|
|
106
112
|
*
|
|
107
113
|
* @returns A condition that is true when any of the specified conditions are
|
|
108
|
-
*
|
|
114
|
+
* true
|
|
109
115
|
*/
|
|
110
116
|
or: <C extends Condition<S>[]>(...conditions: C) => {
|
|
111
117
|
or: C;
|
|
@@ -113,54 +119,58 @@ export interface CreateHooksResult<S, CSSProperties> {
|
|
|
113
119
|
/**
|
|
114
120
|
* Negates a condition.
|
|
115
121
|
*
|
|
116
|
-
* @typeParam
|
|
117
|
-
*
|
|
122
|
+
* @typeParam C - The type of the condition which must be false in order for
|
|
123
|
+
* the resulting condition to be true
|
|
118
124
|
*
|
|
119
125
|
* @param condition - The condition which must be false in order for the
|
|
120
|
-
*
|
|
126
|
+
* resulting condition to be true
|
|
121
127
|
*
|
|
122
128
|
* @returns A condition that is true when the specified condition is false.
|
|
123
129
|
*/
|
|
124
130
|
not: <C extends Condition<S>>(condition: C) => {
|
|
125
131
|
not: C;
|
|
126
132
|
};
|
|
127
|
-
/**
|
|
128
|
-
* The style sheet required to support the configured hooks.
|
|
129
|
-
*/
|
|
133
|
+
/** Returns the style sheet required to support the configured hooks. */
|
|
130
134
|
styleSheet: () => string;
|
|
131
135
|
}
|
|
132
136
|
/**
|
|
133
137
|
* Represents the function used to define hooks and related configuration.
|
|
134
138
|
*
|
|
135
|
-
* @typeParam CSSProperties - The type of a
|
|
136
|
-
*
|
|
139
|
+
* @typeParam CSSProperties - The type of a style object, typically defined by
|
|
140
|
+
* an app framework (e.g., React's `CSSProperties` type)
|
|
141
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
142
|
+
* with which they conflict
|
|
143
|
+
* @typeParam S - The type of selectors for which to create hooks
|
|
137
144
|
*
|
|
138
|
-
* @
|
|
139
|
-
*
|
|
140
|
-
* @param selectors - The selectors for which to create hooks.
|
|
145
|
+
* @param selectors - The selectors for which to create hooks
|
|
141
146
|
*
|
|
142
147
|
* @returns An object containing the functions needed to support and use the
|
|
143
|
-
*
|
|
148
|
+
* configured hooks
|
|
144
149
|
*
|
|
145
150
|
* @public
|
|
146
151
|
*/
|
|
147
|
-
export type CreateHooksFn<CSSProperties> = <S extends Selector>(...selectors: S[]) => CreateHooksResult<S, CSSProperties>;
|
|
152
|
+
export type CreateHooksFn<CSSProperties, CSSPropertyConflicts extends object = object> = <S extends Selector>(...selectors: S[]) => CreateHooksResult<S, CSSProperties, CSSPropertyConflicts>;
|
|
148
153
|
/**
|
|
149
154
|
* Creates a flavor of CSS Hooks tailored to a specific app framework.
|
|
150
155
|
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* Primarily for internal use, advanced use cases, or when an appropriate
|
|
158
|
+
* framework integration is not provided
|
|
159
|
+
*
|
|
160
|
+
* @typeParam CSSProperties - The type of a style object, typically defined by
|
|
161
|
+
* an app framework (e.g., React's `CSSProperties` type)
|
|
162
|
+
* @typeParam CSSPropertyConflicts - A map from CSS properties to the properties
|
|
163
|
+
* with which they conflict
|
|
164
|
+
*
|
|
151
165
|
* @param stringify - The function used to stringify values when merging
|
|
152
|
-
*
|
|
166
|
+
* override styles
|
|
153
167
|
*
|
|
154
168
|
* @returns The `createHooks` function used to bootstrap CSS Hooks within an app
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @remarks
|
|
158
|
-
* Primarily for internal use, advanced use cases, or when an appropriate
|
|
159
|
-
* framework integration is not provided.
|
|
169
|
+
* or component library
|
|
160
170
|
*
|
|
161
171
|
* @public
|
|
162
|
-
*
|
|
163
172
|
*/
|
|
164
173
|
export declare function buildHooksSystem<CSSProperties extends {
|
|
165
174
|
[P: string]: any;
|
|
166
|
-
} = Record<string, unknown
|
|
175
|
+
} = Record<string, unknown>, CSSPropertyConflicts extends object = object>(stringify?: StringifyFn): CreateHooksFn<CSSProperties, CSSPropertyConflicts>;
|
|
176
|
+
export {};
|