@plumeria/core 0.9.7 → 0.9.9

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
@@ -1,38 +1,38 @@
1
1
  # @plumeria/core
2
2
 
3
- **Zero-runtime CSS in JS library in TypeScript.**
3
+ **Zero-runtime, expressive CSS-in-JS library for TypeScript.**
4
4
 
5
- ## Installation
5
+ ## 🌱 Installation
6
6
 
7
- To start using Plumeria, Install the following two packages:
7
+ To get started with Plumeria, install the core package:
8
8
 
9
9
  ```sh
10
10
  npm install @plumeria/core
11
11
  ```
12
12
 
13
- ### Compiler
13
+ ### 🛠 Compiler (for static extraction)
14
14
 
15
- To compile `@plumeria/core`, for example, to use `npx css`, install
16
- [`@plumeria/compiler`](https://www.npmjs.com/package/@plumeria/compiler) for static extraction through the build process.
15
+ If you want to extract styles at build time using commands like `npx css`, install:
17
16
 
18
17
  ```sh
19
18
  npm install --save-dev @plumeria/compiler
20
19
  ```
21
20
 
22
- ### StyleSheet
21
+ More at: [@plumeria/compiler on npm](https://www.npmjs.com/package/@plumeria/compiler)
23
22
 
24
- Import stylesheet in your application's entry point.
25
- Applies the static stylesheet for production environments.
23
+ ### 🎨 Stylesheet Import
24
+
25
+ In your app entry point, import the compiled CSS file:
26
26
 
27
27
  ```ts
28
28
  import '@plumeria/core/stylesheet.css';
29
29
  ```
30
30
 
31
- ## API
31
+ ## 📘 API Reference
32
32
 
33
- ### css.create()
33
+ ### `css.create()`
34
34
 
35
- Styles are defined as a map of CSS rules using css.create(). In the example below, there are 2 different CSS className. The className `styles.box` and `styles.text` are arbitrary names given to the rules.
35
+ Define a set of styles:
36
36
 
37
37
  ```ts
38
38
  import { css } from '@plumeria/core';
@@ -48,16 +48,13 @@ const styles = css.create({
48
48
  });
49
49
  ```
50
50
 
51
- Pseudo and media queries can be wrapped in property style definitions:
52
- Also, any properties that are not wrapped will conform to that className.
51
+ Supports pseudo/media queries inline:
53
52
 
54
53
  ```ts
55
54
  const styles = css.create({
56
55
  box: {
57
- // 900px
58
56
  [css.media.maxWidth(900)]: {
59
57
  width: '100%',
60
- color: 'rgb(60,60,60)',
61
58
  },
62
59
  },
63
60
  text: {
@@ -70,9 +67,45 @@ const styles = css.create({
70
67
  });
71
68
  ```
72
69
 
73
- ### css.global()
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
+ [css.pseudo.hover]: {
86
+ scale: 1.5,
87
+ },
88
+ },
89
+ active: {
90
+ [css.pseudo.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
+ ### `css.global()`
74
107
 
75
- This API lets you define global CSS.
108
+ Define global styles:
76
109
 
77
110
  ```ts
78
111
  css.global({
@@ -92,9 +125,9 @@ css.global({
92
125
  });
93
126
  ```
94
127
 
95
- ### css.keyframes()
128
+ ### `css.keyframes()`
96
129
 
97
- Define @keyframes and set the return value directly to animationName.
130
+ Create keyframes for animation:
98
131
 
99
132
  ```ts
100
133
  const fade = css.keyframes({
@@ -114,25 +147,55 @@ const styles = css.create({
114
147
  });
115
148
  ```
116
149
 
117
- ### css.defineVars()
150
+ ### `css.defineConsts()`
118
151
 
119
- Defines custom CSS variables (custom properties) at the `:root` level.
120
- This API allows you to declare design tokens such as spacing, sizes, or other constants, which can be referenced throughout your styles using the tokens.sm to `var(--sm)` syntax.
152
+ Define reusable constant values with type safety:
153
+
154
+ ```ts
155
+ const breakpoints = css.defineConsts({
156
+ xs: css.media.maxWidth(480),
157
+ sm: css.media.maxWidth(640),
158
+ md: css.media.maxWidth(768),
159
+ lg: css.media.maxWidth(1024),
160
+ xl: css.media.maxWidth(1280),
161
+ });
162
+ ```
163
+
164
+ Use them in your style definitions:
165
+
166
+ ```ts
167
+ const styles = css.create({
168
+ container: {
169
+ [breakpoints.sm]: {
170
+ padding: 16,
171
+ },
172
+ [breakpoints.lg]: {
173
+ padding: 32,
174
+ },
175
+ },
176
+ });
177
+ ```
178
+
179
+ Constants are fully type-safe and readonly.
180
+
181
+ ### `css.defineVars()`
182
+
183
+ Define design tokens with CSS variables:
121
184
 
122
185
  ```ts
123
186
  const tokens = css.defineVars({
124
- xs: 240,
125
- sm: 360,
126
- md: 480,
127
- lg: 600,
128
- xl: 720,
187
+ white: 'white',
188
+ black: 'black',
189
+ textPrimary: '#eaeaea',
190
+ textSecondary: '#333',
191
+ link: 'lightblue',
192
+ accent: 'purple',
129
193
  });
130
194
  ```
131
195
 
132
- ### css.defineTheme()
196
+ ### `css.defineTheme()`
133
197
 
134
- Define data-theme as objects.
135
- A default compile to :root, and the rest as a string compile to data-theme, You can also use media and container here.
198
+ Define theme values with responsive and conditional support:
136
199
 
137
200
  ```ts
138
201
  const themes = css.defineTheme({
@@ -149,12 +212,9 @@ const themes = css.defineTheme({
149
212
  });
150
213
  ```
151
214
 
152
- ### css.color
153
-
154
- Mixes #000 or #FFF into the color.
155
- The first argument takes the color and the second argument takes the same value as opacity (string % or number).
215
+ ### `css.color`
156
216
 
157
- You can also retrieve the complement of the color property from an color object.
217
+ Color utilities:
158
218
 
159
219
  ```ts
160
220
  color: css.color.darken('skyblue', 0.12),
@@ -162,35 +222,35 @@ color: css.color.lighten('navy', 0.6),
162
222
 
163
223
  color: css.color.skyblue,
164
224
  color: css.color.aqua,
165
- // ...many more colors
166
- color: css.color.*...,
167
-
225
+ // and many more
168
226
  ```
169
227
 
170
- ### cx
228
+ ### `cx`
171
229
 
172
- Merges strings such as class names and pseudo.
230
+ Classname merging helper:
173
231
 
174
232
  ```tsx
175
- // ":hover::after"
176
233
  cx(css.pseudo.hover, css.pseudo.after);
177
- // "text_hash box_hash"
178
- cx(styles.text, styles, box);
234
+ // => ":hover::after"
235
+ cx(styles.text, styles.box);
236
+ // => "text_hash box_hash"
179
237
  ```
180
238
 
181
- ## ESLint
239
+ ## 🧹 ESLint Support
182
240
 
183
- [@plumeria/eslint-plugin](https://www.npmjs.com/package/@plumeria/eslint-plugin)
241
+ Use [@plumeria/eslint-plugin](https://www.npmjs.com/package/@plumeria/eslint-plugin) for recommended rules:
184
242
 
185
243
  ### Rules: recommended
186
244
 
187
- \- no-inner-call:(error)
188
- \- no-unused-keys:(warn)
189
- \- sort-properties:(warn)
190
- \- validate-values:(warn)
245
+ ```
246
+ - no-inner-call: error
247
+ - no-unused-keys: warn
248
+ - sort-properties: warn
249
+ - validate-values: warn
250
+ ```
191
251
 
192
- It is recommended to use it in conjunction with TypeScript completion, which is one of the big advantages of using plumeria.
252
+ Plumeria is best used alongside TypeScript for excellent autocomplete and validation support.
193
253
 
194
- ## License
254
+ ## 📄 License
195
255
 
196
- plumeria is [MIT licensed](https://github.com/refirst11/rscute/blob/main/LICENSE).
256
+ Plumeria is [MIT licensed](https://github.com/zss-in-js/plumeria/blob/main/LICENSE).
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { CSSHTML, CSSProperties, CreateKeyframes, CreateStyle, CreateStyleType, CreateTheme, CreateVars, ReturnType } from "zss-engine";
1
+ import { CSSHTML, CSSProperties, CreateKeyframes, CreateStyle, CreateStyleType, CreateTheme, CreateValues, ReturnType } from "zss-engine";
2
2
 
3
3
  //#region src/css.d.ts
4
4
  declare class css {
5
- static create<T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): ReturnType<T>;
5
+ static create<const T extends Record<string, CSSProperties>>(object: CreateStyleType<T>): ReturnType<T>;
6
+ static createComposite<const T extends Record<string, CSSProperties>>(className: string, object: T): ReturnType<T>;
6
7
  static global(object: CSSHTML): void;
7
- static defineVars<const T extends CreateVars>(object: T): { [K in keyof T]: `var(--${string})` };
8
- static defineTheme<const T extends CreateTheme>(object: T): { [K in keyof T]: `var(--${string})` };
9
8
  static keyframes(object: CreateKeyframes): string;
9
+ static defineConsts<const T extends CreateValues>(object: T): T;
10
+ static defineVars<const T extends CreateValues>(object: T): { [K in keyof T]: `var(--${string})` };
11
+ static defineTheme<const T extends CreateTheme>(object: T): { [K in keyof T]: `var(--${string})` };
10
12
  static media: {
11
13
  dark: "@media (prefers-color-scheme: dark)";
12
14
  light: "@media (prefers-color-scheme: light)";
package/dist/index.js CHANGED
@@ -19,6 +19,12 @@ function create(object) {
19
19
  });
20
20
  return Object.freeze(object);
21
21
  }
22
+ function createComposite(className, object) {
23
+ const composed = create(object);
24
+ const result = {};
25
+ for (const key in composed) result[key] = `${className} ${composed[key]}`;
26
+ return result;
27
+ }
22
28
  function global(object) {
23
29
  const base36Hash = (0, zss_engine.genBase36Hash)(object, 8);
24
30
  const { styleSheet } = (0, zss_engine.transpiler)(object, void 0, "--global");
@@ -26,6 +32,14 @@ function global(object) {
26
32
  require_css.resolvePromise_2(styleSheet);
27
33
  if (zss_engine.isDevAndTest) zss_engine.isServer ? (0, zss_engine.injectServerCSS)(base36Hash, styleSheet) : (0, zss_engine.injectClientGlobalCSS)(styleSheet);
28
34
  }
35
+ const keyframes = (object) => {
36
+ const prefix = (0, zss_engine.genBase36Hash)(object, 8);
37
+ global({ [`@keyframes ${prefix}`]: object });
38
+ return prefix;
39
+ };
40
+ const defineConsts = (constants) => {
41
+ return constants;
42
+ };
29
43
  const defineVars = (object) => {
30
44
  const styles = { ":root": {} };
31
45
  const result = {};
@@ -58,27 +72,28 @@ const defineTheme = (object) => {
58
72
  global(styles);
59
73
  return result;
60
74
  };
61
- const keyframes = (object) => {
62
- const prefix = (0, zss_engine.genBase36Hash)(object, 8);
63
- global({ [`@keyframes ${prefix}`]: object });
64
- return prefix;
65
- };
66
75
  var css = class {
67
76
  static create(object) {
68
77
  return create(object);
69
78
  }
79
+ static createComposite(className, object) {
80
+ return createComposite(className, object);
81
+ }
70
82
  static global(object) {
71
83
  return global(object);
72
84
  }
85
+ static keyframes(object) {
86
+ return keyframes(object);
87
+ }
88
+ static defineConsts(object) {
89
+ return defineConsts(object);
90
+ }
73
91
  static defineVars(object) {
74
92
  return defineVars(object);
75
93
  }
76
94
  static defineTheme(object) {
77
95
  return defineTheme(object);
78
96
  }
79
- static keyframes(object) {
80
- return keyframes(object);
81
- }
82
97
  static media = zss_utils.media;
83
98
  static container = zss_utils.container;
84
99
  static pseudo = zss_utils.pseudo;
package/dist/index.mjs CHANGED
@@ -18,6 +18,12 @@ function create(object) {
18
18
  });
19
19
  return Object.freeze(object);
20
20
  }
21
+ function createComposite(className, object) {
22
+ const composed = create(object);
23
+ const result = {};
24
+ for (const key in composed) result[key] = `${className} ${composed[key]}`;
25
+ return result;
26
+ }
21
27
  function global(object) {
22
28
  const base36Hash = genBase36Hash(object, 8);
23
29
  const { styleSheet } = transpiler(object, void 0, "--global");
@@ -25,6 +31,14 @@ function global(object) {
25
31
  resolvePromise_2(styleSheet);
26
32
  if (isDevAndTest) isServer ? injectServerCSS(base36Hash, styleSheet) : injectClientGlobalCSS(styleSheet);
27
33
  }
34
+ const keyframes = (object) => {
35
+ const prefix = genBase36Hash(object, 8);
36
+ global({ [`@keyframes ${prefix}`]: object });
37
+ return prefix;
38
+ };
39
+ const defineConsts = (constants) => {
40
+ return constants;
41
+ };
28
42
  const defineVars = (object) => {
29
43
  const styles = { ":root": {} };
30
44
  const result = {};
@@ -57,27 +71,28 @@ const defineTheme = (object) => {
57
71
  global(styles);
58
72
  return result;
59
73
  };
60
- const keyframes = (object) => {
61
- const prefix = genBase36Hash(object, 8);
62
- global({ [`@keyframes ${prefix}`]: object });
63
- return prefix;
64
- };
65
74
  var css = class {
66
75
  static create(object) {
67
76
  return create(object);
68
77
  }
78
+ static createComposite(className, object) {
79
+ return createComposite(className, object);
80
+ }
69
81
  static global(object) {
70
82
  return global(object);
71
83
  }
84
+ static keyframes(object) {
85
+ return keyframes(object);
86
+ }
87
+ static defineConsts(object) {
88
+ return defineConsts(object);
89
+ }
72
90
  static defineVars(object) {
73
91
  return defineVars(object);
74
92
  }
75
93
  static defineTheme(object) {
76
94
  return defineTheme(object);
77
95
  }
78
- static keyframes(object) {
79
- return keyframes(object);
80
- }
81
96
  static media = media;
82
97
  static container = container;
83
98
  static pseudo = pseudo;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plumeria/core",
3
- "version": "0.9.7",
4
- "description": "Zero-runtime CSS in JS - Compile at build-time. No runtime overhead.",
3
+ "version": "0.9.9",
4
+ "description": "Zero-runtime, expressive CSS-in-JS library for TypeScript.",
5
5
  "keywords": [
6
6
  "css",
7
7
  "css-in-js",
@@ -39,7 +39,7 @@
39
39
  "stylesheet.css"
40
40
  ],
41
41
  "dependencies": {
42
- "zss-engine": "0.2.39",
42
+ "zss-engine": "0.2.40",
43
43
  "zss-utils": "0.2.3"
44
44
  },
45
45
  "publishConfig": {