@plumeria/core 0.10.4 → 0.11.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 +19 -42
- package/dist/index.d.ts +16 -25
- package/dist/index.js +38 -43
- package/dist/index.mjs +36 -40
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ import '@plumeria/core/stylesheet.css';
|
|
|
35
35
|
Define a set of styles:
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
|
-
import { css,
|
|
38
|
+
import { css, ps } from '@plumeria/core';
|
|
39
39
|
|
|
40
40
|
const styles = css.create({
|
|
41
41
|
box: {
|
|
@@ -46,6 +46,15 @@ const styles = css.create({
|
|
|
46
46
|
color: 'yellow',
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
|
+
|
|
50
|
+
const classNameString = css.props(styles.text, styles.box);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Use `css.props()` to convert a style object into a string with a hashed key.
|
|
54
|
+
You can use them like this:
|
|
55
|
+
|
|
56
|
+
```jsx
|
|
57
|
+
<div className={css.props(styles.text, styles.box)} />
|
|
49
58
|
```
|
|
50
59
|
|
|
51
60
|
Supports pseudo/media queries inline:
|
|
@@ -67,42 +76,6 @@ const styles = css.create({
|
|
|
67
76
|
});
|
|
68
77
|
```
|
|
69
78
|
|
|
70
|
-
### `css.createComposite()`
|
|
71
|
-
|
|
72
|
-
Creates modifier classes for a base style:
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
const styles = css.create({
|
|
76
|
-
flexBox: {
|
|
77
|
-
display: 'flex',
|
|
78
|
-
flexDirection: 'column',
|
|
79
|
-
justifyContent: 'center',
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const composed = css.createComposite(styles.flexBox, {
|
|
84
|
-
hover: {
|
|
85
|
-
[ps.hover]: {
|
|
86
|
-
scale: 1.5,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
active: {
|
|
90
|
-
[ps.active]: {
|
|
91
|
-
color: css.color.gray,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
This produces named modifier classes based on the base style.
|
|
98
|
-
You can use them like this:
|
|
99
|
-
|
|
100
|
-
```jsx
|
|
101
|
-
<div className={composed.hover} />
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Automatically generates all modifier variants while keeping the base style clean.
|
|
105
|
-
|
|
106
79
|
### `css.global()`
|
|
107
80
|
|
|
108
81
|
Define global styles:
|
|
@@ -225,15 +198,19 @@ color: css.color.aqua,
|
|
|
225
198
|
// and many more
|
|
226
199
|
```
|
|
227
200
|
|
|
228
|
-
### `
|
|
201
|
+
### `css.px`
|
|
229
202
|
|
|
230
|
-
|
|
203
|
+
Pseudo expand helper:
|
|
231
204
|
|
|
232
205
|
```tsx
|
|
233
|
-
px(ps.hover, ps.after);
|
|
206
|
+
css.px(ps.hover, ps.after);
|
|
234
207
|
// => ":hover::after"
|
|
235
|
-
|
|
236
|
-
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`px` is also available as an export function.
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
import { px } from '@plumeria/core';
|
|
237
214
|
```
|
|
238
215
|
|
|
239
216
|
## 🧹 ESLint Support
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import { CSSHTML, CSSProperties, CreateKeyframes, CreateStyle, CreateStyleType, CreateTheme, CreateValues, Join, ReturnType } from "zss-engine";
|
|
1
|
+
import { CSSHTML, CSSProperties, CreateKeyframes, CreateStyle, CreateStyleType, CreateTheme, CreateValues, Join, ReturnRx, ReturnType, ReturnVariableType, RxVariableSet } from "zss-engine";
|
|
2
2
|
import { ps } from "zss-utils";
|
|
3
3
|
|
|
4
4
|
//#region src/css.d.ts
|
|
5
|
+
declare const rx: (cssProperties: Readonly<CSSProperties>, varSet: RxVariableSet) => {
|
|
6
|
+
className: string;
|
|
7
|
+
style: {
|
|
8
|
+
[k: string]: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare const px: <T extends readonly string[]>(...pseudos: T) => Join<T>;
|
|
5
12
|
declare class css {
|
|
13
|
+
private constructor();
|
|
6
14
|
static create<const T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): ReturnType<T>;
|
|
7
|
-
static createComposite<const T extends Record<string, CSSProperties>>(className: string, object: T): ReturnType<T>;
|
|
8
15
|
static global(object: CSSHTML): void;
|
|
9
16
|
static keyframes(object: CreateKeyframes): string;
|
|
10
|
-
static defineConsts<const T extends CreateValues>(object: T):
|
|
11
|
-
static defineVars<const T extends CreateValues>(object: T):
|
|
12
|
-
static defineTheme<const T extends CreateTheme>(object: T):
|
|
17
|
+
static defineConsts<const T extends CreateValues>(object: T): CreateValues;
|
|
18
|
+
static defineVars<const T extends CreateValues>(object: T): ReturnVariableType<T>;
|
|
19
|
+
static defineTheme<const T extends CreateTheme>(object: T): ReturnVariableType<T>;
|
|
20
|
+
static props(...objects: (false | Readonly<CSSProperties> | null | undefined)[]): string;
|
|
21
|
+
static rx(cssProperties: Readonly<CSSProperties>, varSet: RxVariableSet): ReturnRx;
|
|
22
|
+
static px<T extends readonly string[]>(...pseudos: T): Join<T>;
|
|
13
23
|
static media: {
|
|
14
24
|
dark: "@media (prefers-color-scheme: dark)";
|
|
15
25
|
light: "@media (prefers-color-scheme: light)";
|
|
@@ -185,23 +195,4 @@ declare class css {
|
|
|
185
195
|
yellowgreen: "yellowgreen";
|
|
186
196
|
};
|
|
187
197
|
} //#endregion
|
|
188
|
-
|
|
189
|
-
declare const cx: (...classes: Array<string | null | undefined | false>) => string;
|
|
190
|
-
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/px.d.ts
|
|
193
|
-
declare const px: <T extends readonly string[]>(...pseudos: T) => Join<T>;
|
|
194
|
-
|
|
195
|
-
//#endregion
|
|
196
|
-
//#region src/rx.d.ts
|
|
197
|
-
declare const rx: (className: string, varSet: {
|
|
198
|
-
[key: `--${string}`]: string;
|
|
199
|
-
}) => {
|
|
200
|
-
className: string;
|
|
201
|
-
style: {
|
|
202
|
-
[k: string]: string;
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
//#endregion
|
|
207
|
-
export { CSSHTML, CSSProperties, CreateStyle, css, cx, ps, px, rx };
|
|
198
|
+
export { CSSHTML, CSSProperties, CreateStyle, css, ps, px, rx };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const zss_engine = require_css.__toESM(require("zss-engine"));
|
|
|
4
4
|
const zss_utils = require_css.__toESM(require("zss-utils"));
|
|
5
5
|
|
|
6
6
|
//#region src/css.ts
|
|
7
|
+
const objectToKeyHashMap = new WeakMap();
|
|
7
8
|
function create(object) {
|
|
8
9
|
const base36Hash = (0, zss_engine.genBase36Hash)(object, 6);
|
|
9
10
|
const { styleSheet } = (0, zss_engine.transpiler)(object, base36Hash);
|
|
@@ -11,26 +12,39 @@ function create(object) {
|
|
|
11
12
|
if (typeof require_css.globalPromise_1 === "undefined") require_css.initPromise_1();
|
|
12
13
|
require_css.resolvePromise_1(styleSheet);
|
|
13
14
|
Object.keys(object).forEach((key) => {
|
|
15
|
+
const cssProperties = object[key];
|
|
16
|
+
const hashedClassName = key + "_" + base36Hash;
|
|
17
|
+
objectToKeyHashMap.set(cssProperties, hashedClassName);
|
|
14
18
|
Object.defineProperty(object, key, { get: () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return className;
|
|
19
|
+
if (zss_engine.isTestingDevelopment) injectCSS(base36Hash, styleSheet);
|
|
20
|
+
return Object.freeze(cssProperties);
|
|
18
21
|
} });
|
|
19
22
|
});
|
|
20
23
|
return Object.freeze(object);
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
25
|
+
const props = (...objects) => {
|
|
26
|
+
const classNames = objects.filter(Boolean).map((obj) => {
|
|
27
|
+
if (obj && typeof obj === "object") {
|
|
28
|
+
const keyHash = objectToKeyHashMap.get(obj);
|
|
29
|
+
if (keyHash) return keyHash;
|
|
30
|
+
}
|
|
31
|
+
return "";
|
|
32
|
+
});
|
|
33
|
+
return [...new Set(classNames)].join(" ");
|
|
34
|
+
};
|
|
35
|
+
const rx = (cssProperties, varSet) => ({
|
|
36
|
+
className: props(cssProperties),
|
|
37
|
+
style: Object.fromEntries(Object.entries(varSet).map(([key, value]) => [key, value]))
|
|
38
|
+
});
|
|
39
|
+
const px = (...pseudos) => {
|
|
40
|
+
return pseudos.filter(Boolean).join("");
|
|
41
|
+
};
|
|
28
42
|
function global(object) {
|
|
29
43
|
const base36Hash = (0, zss_engine.genBase36Hash)(object, 8);
|
|
30
44
|
const { styleSheet } = (0, zss_engine.transpiler)(object, void 0, "--global");
|
|
31
45
|
if (typeof require_css.globalPromise_2 === "undefined") require_css.initPromise_2();
|
|
32
46
|
require_css.resolvePromise_2(styleSheet);
|
|
33
|
-
if (zss_engine.
|
|
47
|
+
if (zss_engine.isTestingDevelopment) zss_engine.isServer ? (0, zss_engine.injectServerCSS)(base36Hash, styleSheet) : (0, zss_engine.injectClientGlobalCSS)(styleSheet);
|
|
34
48
|
}
|
|
35
49
|
const keyframes = (object) => {
|
|
36
50
|
const prefix = (0, zss_engine.genBase36Hash)(object, 8);
|
|
@@ -73,12 +87,10 @@ const defineTheme = (object) => {
|
|
|
73
87
|
return result;
|
|
74
88
|
};
|
|
75
89
|
var css = class {
|
|
90
|
+
constructor() {}
|
|
76
91
|
static create(object) {
|
|
77
92
|
return create(object);
|
|
78
93
|
}
|
|
79
|
-
static createComposite(className, object) {
|
|
80
|
-
return createComposite(className, object);
|
|
81
|
-
}
|
|
82
94
|
static global(object) {
|
|
83
95
|
return global(object);
|
|
84
96
|
}
|
|
@@ -94,39 +106,22 @@ var css = class {
|
|
|
94
106
|
static defineTheme(object) {
|
|
95
107
|
return defineTheme(object);
|
|
96
108
|
}
|
|
109
|
+
static props(...objects) {
|
|
110
|
+
return props(...objects);
|
|
111
|
+
}
|
|
112
|
+
static rx(cssProperties, varSet) {
|
|
113
|
+
return rx(cssProperties, varSet);
|
|
114
|
+
}
|
|
115
|
+
static px(...pseudos) {
|
|
116
|
+
return px(...pseudos);
|
|
117
|
+
}
|
|
97
118
|
static media = zss_utils.media;
|
|
98
119
|
static container = zss_utils.container;
|
|
99
120
|
static color = zss_utils.color;
|
|
100
121
|
};
|
|
101
|
-
var css_default = css;
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
//#region src/cx.ts
|
|
105
|
-
const cx = (...classes) => [...new Set(classes.filter(Boolean))].join(" ");
|
|
106
|
-
var cx_default = cx;
|
|
107
|
-
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/ps.ts
|
|
110
|
-
var ps_default = zss_utils.ps;
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/px.ts
|
|
114
|
-
const px = (...pseudos) => {
|
|
115
|
-
return pseudos.filter(Boolean).join("");
|
|
116
|
-
};
|
|
117
|
-
var px_default = px;
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/rx.ts
|
|
121
|
-
const rx = (className, varSet) => ({
|
|
122
|
-
className,
|
|
123
|
-
style: Object.fromEntries(Object.entries(varSet).map(([key, value]) => [key, value]))
|
|
124
|
-
});
|
|
125
|
-
var rx_default = rx;
|
|
126
122
|
|
|
127
123
|
//#endregion
|
|
128
|
-
exports.css =
|
|
129
|
-
exports.
|
|
130
|
-
exports.
|
|
131
|
-
exports.
|
|
132
|
-
exports.rx = rx_default;
|
|
124
|
+
exports.css = css;
|
|
125
|
+
exports.ps = zss_utils.ps;
|
|
126
|
+
exports.px = px;
|
|
127
|
+
exports.rx = rx;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { globalPromise_1, globalPromise_2, initPromise_1, initPromise_2, resolvePromise_1, resolvePromise_2 } from "./css.mjs";
|
|
2
|
-
import { camelToKebabCase, genBase36Hash, injectClientCSS, injectClientGlobalCSS, injectServerCSS,
|
|
2
|
+
import { camelToKebabCase, genBase36Hash, injectClientCSS, injectClientGlobalCSS, injectServerCSS, isServer, isTestingDevelopment, transpiler } from "zss-engine";
|
|
3
3
|
import { color, container, media, ps } from "zss-utils";
|
|
4
4
|
|
|
5
5
|
//#region src/css.ts
|
|
6
|
+
const objectToKeyHashMap = new WeakMap();
|
|
6
7
|
function create(object) {
|
|
7
8
|
const base36Hash = genBase36Hash(object, 6);
|
|
8
9
|
const { styleSheet } = transpiler(object, base36Hash);
|
|
@@ -10,26 +11,39 @@ function create(object) {
|
|
|
10
11
|
if (typeof globalPromise_1 === "undefined") initPromise_1();
|
|
11
12
|
resolvePromise_1(styleSheet);
|
|
12
13
|
Object.keys(object).forEach((key) => {
|
|
14
|
+
const cssProperties = object[key];
|
|
15
|
+
const hashedClassName = key + "_" + base36Hash;
|
|
16
|
+
objectToKeyHashMap.set(cssProperties, hashedClassName);
|
|
13
17
|
Object.defineProperty(object, key, { get: () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return className;
|
|
18
|
+
if (isTestingDevelopment) injectCSS(base36Hash, styleSheet);
|
|
19
|
+
return Object.freeze(cssProperties);
|
|
17
20
|
} });
|
|
18
21
|
});
|
|
19
22
|
return Object.freeze(object);
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
24
|
+
const props = (...objects) => {
|
|
25
|
+
const classNames = objects.filter(Boolean).map((obj) => {
|
|
26
|
+
if (obj && typeof obj === "object") {
|
|
27
|
+
const keyHash = objectToKeyHashMap.get(obj);
|
|
28
|
+
if (keyHash) return keyHash;
|
|
29
|
+
}
|
|
30
|
+
return "";
|
|
31
|
+
});
|
|
32
|
+
return [...new Set(classNames)].join(" ");
|
|
33
|
+
};
|
|
34
|
+
const rx = (cssProperties, varSet) => ({
|
|
35
|
+
className: props(cssProperties),
|
|
36
|
+
style: Object.fromEntries(Object.entries(varSet).map(([key, value]) => [key, value]))
|
|
37
|
+
});
|
|
38
|
+
const px = (...pseudos) => {
|
|
39
|
+
return pseudos.filter(Boolean).join("");
|
|
40
|
+
};
|
|
27
41
|
function global(object) {
|
|
28
42
|
const base36Hash = genBase36Hash(object, 8);
|
|
29
43
|
const { styleSheet } = transpiler(object, void 0, "--global");
|
|
30
44
|
if (typeof globalPromise_2 === "undefined") initPromise_2();
|
|
31
45
|
resolvePromise_2(styleSheet);
|
|
32
|
-
if (
|
|
46
|
+
if (isTestingDevelopment) isServer ? injectServerCSS(base36Hash, styleSheet) : injectClientGlobalCSS(styleSheet);
|
|
33
47
|
}
|
|
34
48
|
const keyframes = (object) => {
|
|
35
49
|
const prefix = genBase36Hash(object, 8);
|
|
@@ -72,12 +86,10 @@ const defineTheme = (object) => {
|
|
|
72
86
|
return result;
|
|
73
87
|
};
|
|
74
88
|
var css = class {
|
|
89
|
+
constructor() {}
|
|
75
90
|
static create(object) {
|
|
76
91
|
return create(object);
|
|
77
92
|
}
|
|
78
|
-
static createComposite(className, object) {
|
|
79
|
-
return createComposite(className, object);
|
|
80
|
-
}
|
|
81
93
|
static global(object) {
|
|
82
94
|
return global(object);
|
|
83
95
|
}
|
|
@@ -93,35 +105,19 @@ var css = class {
|
|
|
93
105
|
static defineTheme(object) {
|
|
94
106
|
return defineTheme(object);
|
|
95
107
|
}
|
|
108
|
+
static props(...objects) {
|
|
109
|
+
return props(...objects);
|
|
110
|
+
}
|
|
111
|
+
static rx(cssProperties, varSet) {
|
|
112
|
+
return rx(cssProperties, varSet);
|
|
113
|
+
}
|
|
114
|
+
static px(...pseudos) {
|
|
115
|
+
return px(...pseudos);
|
|
116
|
+
}
|
|
96
117
|
static media = media;
|
|
97
118
|
static container = container;
|
|
98
119
|
static color = color;
|
|
99
120
|
};
|
|
100
|
-
var css_default = css;
|
|
101
|
-
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/cx.ts
|
|
104
|
-
const cx = (...classes) => [...new Set(classes.filter(Boolean))].join(" ");
|
|
105
|
-
var cx_default = cx;
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/ps.ts
|
|
109
|
-
var ps_default = ps;
|
|
110
|
-
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/px.ts
|
|
113
|
-
const px = (...pseudos) => {
|
|
114
|
-
return pseudos.filter(Boolean).join("");
|
|
115
|
-
};
|
|
116
|
-
var px_default = px;
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region src/rx.ts
|
|
120
|
-
const rx = (className, varSet) => ({
|
|
121
|
-
className,
|
|
122
|
-
style: Object.fromEntries(Object.entries(varSet).map(([key, value]) => [key, value]))
|
|
123
|
-
});
|
|
124
|
-
var rx_default = rx;
|
|
125
121
|
|
|
126
122
|
//#endregion
|
|
127
|
-
export {
|
|
123
|
+
export { css, ps, px, rx };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Zero-runtime, expressive CSS-in-JS library for TypeScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"stylesheet.css"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"zss-engine": "0.2.
|
|
42
|
+
"zss-engine": "0.2.44",
|
|
43
43
|
"zss-utils": "0.2.4"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|