@plumeria/core 0.2.4 → 0.3.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 +21 -0
- package/package.json +13 -7
- package/readme.md +26 -26
- package/bin/css.mjs +0 -44
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 zss-in-js contributer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CSS-in-JS
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Near Zero-runtime CSS-in-JS for efficient design systems.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"css",
|
|
@@ -14,12 +14,18 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"main": "dist/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@plumeria/collection": "^0.1.2",
|
|
22
|
-
"@plumeria/compiler": "^0.1.1",
|
|
23
22
|
"zss-engine": "^0.2.3"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rm -rf dist && tsc && cp -r src/styles dist",
|
|
29
|
+
"test": "jest --config ../../jest.config.js"
|
|
24
30
|
}
|
|
25
|
-
}
|
|
31
|
+
}
|
package/readme.md
CHANGED
|
@@ -12,18 +12,18 @@ npm install --save @plumeria/core
|
|
|
12
12
|
|
|
13
13
|
### css.create()
|
|
14
14
|
|
|
15
|
-
Styles are defined as a map of CSS
|
|
15
|
+
Styles are defined as a map of CSS rules using css.create(). In the example below, there are 2 different CSS rules. The names "box" and "text" are arbitrary names given to the rules.
|
|
16
16
|
|
|
17
17
|
```tsx
|
|
18
|
-
import { css } from
|
|
18
|
+
import { css } from '@plumeria/core';
|
|
19
19
|
|
|
20
20
|
const styles = css.create({
|
|
21
21
|
box: {
|
|
22
|
-
width:
|
|
23
|
-
color:
|
|
22
|
+
width: '100%',
|
|
23
|
+
color: 'rgb(60,60,60)',
|
|
24
24
|
},
|
|
25
25
|
text: {
|
|
26
|
-
color:
|
|
26
|
+
color: 'yellow',
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
```
|
|
@@ -33,22 +33,20 @@ Pseudo and media queries can be wrapped in property style definitions:
|
|
|
33
33
|
```ts
|
|
34
34
|
const styles = css.create({
|
|
35
35
|
box: {
|
|
36
|
-
[css.media.max(
|
|
37
|
-
width:
|
|
38
|
-
color:
|
|
36
|
+
[css.media.max('width: 900px')]: {
|
|
37
|
+
width: '100%',
|
|
38
|
+
color: 'rgb(60,60,60)',
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
41
|
text: {
|
|
42
42
|
[css.pseudo.hover]: {
|
|
43
|
-
color:
|
|
43
|
+
color: 'yellow',
|
|
44
44
|
opacity: 0.9,
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
The compiler extracts the CSS rules, replacing the rules in the source code with the compiled CSS.
|
|
51
|
-
|
|
52
50
|
### css.global()
|
|
53
51
|
|
|
54
52
|
This API lets you define global CSS.
|
|
@@ -65,6 +63,8 @@ css.global({
|
|
|
65
63
|
});
|
|
66
64
|
```
|
|
67
65
|
|
|
66
|
+
The compiler extracts the CSS rules, replacing the rules in the source code with the compiled CSS.
|
|
67
|
+
|
|
68
68
|
### cx
|
|
69
69
|
|
|
70
70
|
Merges strings such as class names and pseudos.
|
|
@@ -73,7 +73,7 @@ Merges strings such as class names and pseudos.
|
|
|
73
73
|
const styles = css.create({
|
|
74
74
|
text: {
|
|
75
75
|
[cx(css.pseudo.hover, css.pseudo.after)]: {
|
|
76
|
-
color:
|
|
76
|
+
color: 'yellow',
|
|
77
77
|
opacity: 0.9,
|
|
78
78
|
},
|
|
79
79
|
},
|
|
@@ -97,7 +97,7 @@ const fade = css.keyframes({
|
|
|
97
97
|
const styles = css.create({
|
|
98
98
|
box: {
|
|
99
99
|
animationName: fade,
|
|
100
|
-
animationDuration:
|
|
100
|
+
animationDuration: '1s',
|
|
101
101
|
},
|
|
102
102
|
});
|
|
103
103
|
```
|
|
@@ -109,16 +109,16 @@ A default compile to :root, and the rest as a string compile to data-theme, You
|
|
|
109
109
|
|
|
110
110
|
```ts
|
|
111
111
|
const colors = css.defineThemeVars({
|
|
112
|
-
normal:
|
|
112
|
+
normal: 'white',
|
|
113
113
|
text_primary: {
|
|
114
|
-
default:
|
|
115
|
-
light:
|
|
116
|
-
dark:
|
|
117
|
-
[css.media.max(
|
|
114
|
+
default: 'rgb(60,60,60)',
|
|
115
|
+
light: 'black',
|
|
116
|
+
dark: 'white',
|
|
117
|
+
[css.media.max('width: 700px')]: 'gray',
|
|
118
118
|
},
|
|
119
119
|
bg_primary: {
|
|
120
|
-
light:
|
|
121
|
-
dark:
|
|
120
|
+
light: 'white',
|
|
121
|
+
dark: 'black',
|
|
122
122
|
},
|
|
123
123
|
});
|
|
124
124
|
```
|
|
@@ -129,8 +129,8 @@ Mixes #000 or #FFF into the color.
|
|
|
129
129
|
The first argument takes the color and the second argument takes the same value as opacity (string % or number).
|
|
130
130
|
|
|
131
131
|
```ts
|
|
132
|
-
css.colors.darken(
|
|
133
|
-
css.colors.darken(
|
|
132
|
+
css.colors.darken('skyblue', 0.12);
|
|
133
|
+
css.colors.darken('skyblue', '12%');
|
|
134
134
|
```
|
|
135
135
|
|
|
136
136
|
## Linter
|
|
@@ -143,15 +143,15 @@ Type safety relies on this eslint-plugin. It includes 397 properties, excluding
|
|
|
143
143
|
Plumeria complies with Semantic HTML, which means that it uses one style for each class name.
|
|
144
144
|
|
|
145
145
|
```tsx
|
|
146
|
-
import { css } from
|
|
146
|
+
import { css } from '@plumeria/core';
|
|
147
147
|
|
|
148
148
|
const styles = css.create({
|
|
149
149
|
box: {
|
|
150
|
-
width:
|
|
151
|
-
color:
|
|
150
|
+
width: '100%',
|
|
151
|
+
color: 'rgb(60,60,60)',
|
|
152
152
|
},
|
|
153
153
|
text: {
|
|
154
|
-
color:
|
|
154
|
+
color: 'yellow',
|
|
155
155
|
},
|
|
156
156
|
});
|
|
157
157
|
```
|
package/bin/css.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { execSync } from 'child_process';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { styleText } from 'util';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
|
|
8
|
-
const checkMark = styleText('greenBright', '✓');
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const isPnpm = fs.existsSync(path.join(process.cwd(), 'node_modules/.pnpm'));
|
|
12
|
-
|
|
13
|
-
const typecheck = process.argv.includes('--type-check');
|
|
14
|
-
if (typecheck)
|
|
15
|
-
execSync('npx tsc --noEmit --incremental false', {
|
|
16
|
-
stdio: 'inherit',
|
|
17
|
-
cwd: process.cwd(),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const plumeriaPath = isPnpm ? findPnpmPlumeriaPath() : path.join(process.cwd(), 'node_modules/@plumeria');
|
|
21
|
-
|
|
22
|
-
const argv = process.argv.includes('--log') ? ' --log' : '';
|
|
23
|
-
execSync('npx tsx compiler/src/index.ts' + argv, {
|
|
24
|
-
stdio: 'inherit',
|
|
25
|
-
cwd: plumeriaPath,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const completed = typecheck ? 'Type-check completed' : '';
|
|
29
|
-
console.log(` ${checkMark} Compiled... ${completed}`);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error('Compilation failed:', error.message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function findPnpmPlumeriaPath() {
|
|
36
|
-
const pnpmPath = path.join(process.cwd(), 'node_modules/.pnpm');
|
|
37
|
-
const plumeriaDir = fs.readdirSync(pnpmPath).find(dir => dir.startsWith('@plumeria+core@'));
|
|
38
|
-
|
|
39
|
-
if (!plumeriaDir) {
|
|
40
|
-
throw new Error('Could not find @plumeria package in pnpm directory');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return path.join(pnpmPath, plumeriaDir, 'node_modules/@plumeria');
|
|
44
|
-
}
|