@css-hooks/core 1.5.4 → 1.7.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/LICENSE +2 -0
- package/README.md +10 -4
- package/cjs/index.js +55 -30
- package/esm/index.js +55 -30
- package/package.json +1 -1
- package/types/index.d.ts +3 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -53,10 +53,16 @@ Please visit [css-hooks.com](https://css-hooks.com) to get started.
|
|
|
53
53
|
|
|
54
54
|
- [@css-hooks/recommended](packages/recommended): Recommended hook configuration
|
|
55
55
|
with sensible defaults
|
|
56
|
-
- [@css-hooks/react](packages/react):
|
|
57
|
-
|
|
58
|
-
- [@css-hooks/preact](packages/preact):
|
|
59
|
-
|
|
56
|
+
- [@css-hooks/react](https://github.com/css-hooks/css-hooks/tree/master/packages/react):
|
|
57
|
+
React framework integration
|
|
58
|
+
- [@css-hooks/preact](https://github.com/css-hooks/css-hooks/tree/master/packages/preact):
|
|
59
|
+
Preact framework integration
|
|
60
|
+
- [@css-hooks/solid](https://github.com/css-hooks/css-hooks/tree/master/packages/solid):
|
|
61
|
+
Solid framework integration
|
|
62
|
+
- [@css-hooks/qwik](https://github.com/css-hooks/css-hooks/tree/master/packages/qwik):
|
|
63
|
+
Qwik framework integration
|
|
64
|
+
- [@css-hooks/core](https://github.com/css-hooks/css-hooks/tree/master/packages/core):
|
|
65
|
+
Core package (internal / advanced use cases)
|
|
60
66
|
|
|
61
67
|
## Contributing
|
|
62
68
|
|
package/cjs/index.js
CHANGED
|
@@ -57,13 +57,6 @@ function buildHooksSystem(stringify = genericStringify) {
|
|
|
57
57
|
? `${hookName.replace(/[^A-Za-z0-9-]/g, "_")}-${specHash}`
|
|
58
58
|
: specHash;
|
|
59
59
|
});
|
|
60
|
-
function forEachHook(properties, callback) {
|
|
61
|
-
return Object.entries(properties)
|
|
62
|
-
.filter(([key]) => key in config)
|
|
63
|
-
.forEach(([hookName, value]) => {
|
|
64
|
-
callback(hookName, value);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
60
|
const hooks = Object.entries(config)
|
|
68
61
|
.map(([name, definition]) => {
|
|
69
62
|
function nest(input) {
|
|
@@ -175,34 +168,66 @@ function buildHooksSystem(stringify = genericStringify) {
|
|
|
175
168
|
rule: "",
|
|
176
169
|
});
|
|
177
170
|
function cssImpl(properties, fallback = propertyName => stringifyImpl(propertyName, properties[propertyName])) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
171
|
+
const sort = options === null || options === void 0 ? void 0 : options.sort;
|
|
172
|
+
const keys = sort ? Object.keys(properties) : [];
|
|
173
|
+
for (const k in properties) {
|
|
174
|
+
const key = k;
|
|
175
|
+
const value = properties[key];
|
|
176
|
+
if (key in config) {
|
|
177
|
+
const hookName = key;
|
|
178
|
+
const innerProperties = value;
|
|
179
|
+
cssImpl(innerProperties, propertyName => {
|
|
180
|
+
let v = stringifyImpl(propertyName, innerProperties[propertyName]);
|
|
181
|
+
if (v === null) {
|
|
182
|
+
v = fallback(propertyName);
|
|
183
|
+
}
|
|
184
|
+
if (v === null) {
|
|
185
|
+
v = fallbackKeyword;
|
|
186
|
+
}
|
|
187
|
+
return v;
|
|
188
|
+
});
|
|
189
|
+
for (const propertyNameStr in innerProperties) {
|
|
190
|
+
if (keys.indexOf(propertyNameStr) > keys.indexOf(hookName)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const propertyName = propertyNameStr;
|
|
194
|
+
const v1 = stringifyImpl(propertyName, innerProperties[propertyName]);
|
|
195
|
+
if (v1 !== null) {
|
|
196
|
+
let v0 = fallback(propertyName);
|
|
197
|
+
if (v0 === null) {
|
|
198
|
+
v0 = fallbackKeyword;
|
|
199
|
+
}
|
|
200
|
+
if (sort) {
|
|
201
|
+
delete properties[propertyName];
|
|
202
|
+
}
|
|
203
|
+
properties[propertyName] = `var(--${hookId(hookName)}-1, ${v1}) var(--${hookId(hookName)}-0, ${v0})`;
|
|
196
204
|
}
|
|
197
|
-
properties[propertyName] = `var(--${hookId(hookName)}-1, ${v1}) var(--${hookId(hookName)}-0, ${v0})`;
|
|
198
205
|
}
|
|
206
|
+
delete properties[hookName];
|
|
199
207
|
}
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
else if (sort) {
|
|
209
|
+
delete properties[key];
|
|
210
|
+
Object.assign(properties, { [key]: value });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
202
213
|
return properties;
|
|
203
214
|
}
|
|
204
|
-
function css(properties) {
|
|
205
|
-
|
|
215
|
+
function css(...properties) {
|
|
216
|
+
const styles = [{}].concat(JSON.parse(JSON.stringify(properties)));
|
|
217
|
+
do {
|
|
218
|
+
const current = styles[0];
|
|
219
|
+
const next = styles[1] || {};
|
|
220
|
+
if (options === null || options === void 0 ? void 0 : options.sort) {
|
|
221
|
+
for (const k in next) {
|
|
222
|
+
if (k in current) {
|
|
223
|
+
delete current[k];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
styles[0] = cssImpl(Object.assign(current, next));
|
|
228
|
+
styles.splice(1, 1);
|
|
229
|
+
} while (styles[1]);
|
|
230
|
+
return styles[0];
|
|
206
231
|
}
|
|
207
232
|
return [`*{${hooks.init}}${hooks.rule}`, css];
|
|
208
233
|
};
|
package/esm/index.js
CHANGED
|
@@ -53,13 +53,6 @@ export function buildHooksSystem(stringify = genericStringify) {
|
|
|
53
53
|
? `${hookName.replace(/[^A-Za-z0-9-]/g, "_")}-${specHash}`
|
|
54
54
|
: specHash;
|
|
55
55
|
});
|
|
56
|
-
function forEachHook(properties, callback) {
|
|
57
|
-
return Object.entries(properties)
|
|
58
|
-
.filter(([key]) => key in config)
|
|
59
|
-
.forEach(([hookName, value]) => {
|
|
60
|
-
callback(hookName, value);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
56
|
const hooks = Object.entries(config)
|
|
64
57
|
.map(([name, definition]) => {
|
|
65
58
|
function nest(input) {
|
|
@@ -171,34 +164,66 @@ export function buildHooksSystem(stringify = genericStringify) {
|
|
|
171
164
|
rule: "",
|
|
172
165
|
});
|
|
173
166
|
function cssImpl(properties, fallback = propertyName => stringifyImpl(propertyName, properties[propertyName])) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
167
|
+
const sort = options === null || options === void 0 ? void 0 : options.sort;
|
|
168
|
+
const keys = sort ? Object.keys(properties) : [];
|
|
169
|
+
for (const k in properties) {
|
|
170
|
+
const key = k;
|
|
171
|
+
const value = properties[key];
|
|
172
|
+
if (key in config) {
|
|
173
|
+
const hookName = key;
|
|
174
|
+
const innerProperties = value;
|
|
175
|
+
cssImpl(innerProperties, propertyName => {
|
|
176
|
+
let v = stringifyImpl(propertyName, innerProperties[propertyName]);
|
|
177
|
+
if (v === null) {
|
|
178
|
+
v = fallback(propertyName);
|
|
179
|
+
}
|
|
180
|
+
if (v === null) {
|
|
181
|
+
v = fallbackKeyword;
|
|
182
|
+
}
|
|
183
|
+
return v;
|
|
184
|
+
});
|
|
185
|
+
for (const propertyNameStr in innerProperties) {
|
|
186
|
+
if (keys.indexOf(propertyNameStr) > keys.indexOf(hookName)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const propertyName = propertyNameStr;
|
|
190
|
+
const v1 = stringifyImpl(propertyName, innerProperties[propertyName]);
|
|
191
|
+
if (v1 !== null) {
|
|
192
|
+
let v0 = fallback(propertyName);
|
|
193
|
+
if (v0 === null) {
|
|
194
|
+
v0 = fallbackKeyword;
|
|
195
|
+
}
|
|
196
|
+
if (sort) {
|
|
197
|
+
delete properties[propertyName];
|
|
198
|
+
}
|
|
199
|
+
properties[propertyName] = `var(--${hookId(hookName)}-1, ${v1}) var(--${hookId(hookName)}-0, ${v0})`;
|
|
192
200
|
}
|
|
193
|
-
properties[propertyName] = `var(--${hookId(hookName)}-1, ${v1}) var(--${hookId(hookName)}-0, ${v0})`;
|
|
194
201
|
}
|
|
202
|
+
delete properties[hookName];
|
|
195
203
|
}
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
else if (sort) {
|
|
205
|
+
delete properties[key];
|
|
206
|
+
Object.assign(properties, { [key]: value });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
198
209
|
return properties;
|
|
199
210
|
}
|
|
200
|
-
function css(properties) {
|
|
201
|
-
|
|
211
|
+
function css(...properties) {
|
|
212
|
+
const styles = [{}].concat(JSON.parse(JSON.stringify(properties)));
|
|
213
|
+
do {
|
|
214
|
+
const current = styles[0];
|
|
215
|
+
const next = styles[1] || {};
|
|
216
|
+
if (options === null || options === void 0 ? void 0 : options.sort) {
|
|
217
|
+
for (const k in next) {
|
|
218
|
+
if (k in current) {
|
|
219
|
+
delete current[k];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
styles[0] = cssImpl(Object.assign(current, next));
|
|
224
|
+
styles.splice(1, 1);
|
|
225
|
+
} while (styles[1]);
|
|
226
|
+
return styles[0];
|
|
202
227
|
}
|
|
203
228
|
return [`*{${hooks.init}}${hooks.rule}`, css];
|
|
204
229
|
};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export declare function buildHooksSystem<Properties = Record<string, unknown>>(s
|
|
|
18
18
|
/** @internal */ hookNameToId?: (hookName: string) => string;
|
|
19
19
|
}) & {
|
|
20
20
|
fallback?: "unset" | "revert-layer";
|
|
21
|
-
|
|
21
|
+
/** @experimental */
|
|
22
|
+
sort?: boolean;
|
|
23
|
+
}) | undefined) => [string, (properties_0: WithHooks<HookProperties, Properties>, ...properties_1: (WithHooks<HookProperties, Properties> | undefined)[]) => Properties];
|
|
22
24
|
/**
|
|
23
25
|
* A list of hooks offered as a "sensible default" to solve the most common use cases.
|
|
24
26
|
*
|