@fullstackunicorn/style 1.0.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 +218 -0
- package/abstracts/init.js +12 -0
- package/commands.js +15 -0
- package/dependencies.js +2 -0
- package/index.js +108 -0
- package/package.json +52 -0
- package/sources/color.js +291 -0
- package/sources/files.js +216 -0
- package/sources/font.js +111 -0
- package/sources/parse.js +54 -0
- package/sources/style.js +215 -0
- package/sources/styles/base.js +78 -0
- package/sources/styles/border.js +70 -0
- package/sources/styles/flex.js +316 -0
- package/sources/styles/font.js +8 -0
- package/sources/styles/index.js +21 -0
- package/sources/styles/opacity.js +8 -0
- package/sources/styles/radius.js +35 -0
- package/sources/styles/size.js +164 -0
- package/sources/styles/space.js +140 -0
- package/sources/styles/text.js +162 -0
package/README.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# @fullstackunicorn/style
|
|
2
|
+
|
|
3
|
+
A cross‑platform styling engine for Web and React Native.
|
|
4
|
+
It generates unified utility classes, directional rules, responsive ratios, color‑mode styles, and typography maps — all from a single configuration file.
|
|
5
|
+
|
|
6
|
+
Designed for use inside FullstackUnicorn projects, but fully usable as a standalone styling system.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- **Unified Web + Native styling**
|
|
13
|
+
- **Utility‑first class system** (space, flex, size, radius, opacity, border…)
|
|
14
|
+
- **Automatic LTR/RTL handling**
|
|
15
|
+
- **Dark/Light color mode mapping**
|
|
16
|
+
- **Typography + font families abstraction**
|
|
17
|
+
- **Aspect‑ratio utilities (`ratio1`, `ratio_X16Y9`, …)**
|
|
18
|
+
- **Fully configurable via `style.config.js`**
|
|
19
|
+
- **Generates SCSS, JS modules, and React Native StyleSheet maps**
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @fullstackunicorn/style
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
or
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @fullstackunicorn/style
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 🧩 Usage
|
|
38
|
+
|
|
39
|
+
Create a `style.config.js` file in your project:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
export default {
|
|
43
|
+
web: true,
|
|
44
|
+
native: true,
|
|
45
|
+
|
|
46
|
+
numbers: { min: 0, max: 80, step: 1 },
|
|
47
|
+
colors: {
|
|
48
|
+
primary: '#4A46FF',
|
|
49
|
+
danger: '#FF3B30'
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
fonts: {
|
|
53
|
+
heading: 'Inter-Bold',
|
|
54
|
+
text: 'Inter-Regular'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Generate styles:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
yarn style
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This will output a `/style/` folder containing:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
/style
|
|
69
|
+
├── @use.js
|
|
70
|
+
├── @use.scss
|
|
71
|
+
├── web_styles.scss
|
|
72
|
+
├── native_styles.js
|
|
73
|
+
├── fonts.js
|
|
74
|
+
└── ...
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🖥 Web Integration
|
|
80
|
+
|
|
81
|
+
Import the generated SCSS:
|
|
82
|
+
|
|
83
|
+
```scss
|
|
84
|
+
@use './style/@use.scss';
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Use utilities:
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<div class="p16 flex row gap8 radius4 bg-primary text-white">
|
|
91
|
+
Hello Web UI
|
|
92
|
+
</div>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 📱 React Native Integration
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
import { useStyle } from './style/@use'
|
|
101
|
+
|
|
102
|
+
export const MyComponent = () => {
|
|
103
|
+
const { s, c, t } }= useStyle()
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<View style={[s.flex, s.row, s.gap8]}>
|
|
107
|
+
<Text style={t.heading}>Hello Native</Text>
|
|
108
|
+
</View>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 🧪 Generated Classes
|
|
116
|
+
|
|
117
|
+
### Example utilities
|
|
118
|
+
|
|
119
|
+
| Utility | Meaning |
|
|
120
|
+
|--------|----------|
|
|
121
|
+
| `m16` | margin 16 |
|
|
122
|
+
| `p8` | padding 8 |
|
|
123
|
+
| `flex` | display flex |
|
|
124
|
+
| `row` | flex-direction row |
|
|
125
|
+
| `gap12` | gap 12 |
|
|
126
|
+
| `radius4` | border-radius 4 |
|
|
127
|
+
| `ratio1` | 1/1 square ratio |
|
|
128
|
+
| `ratio_X16Y9` | 16/9 layout ratio |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## ⚙️ CLI
|
|
133
|
+
|
|
134
|
+
The package exposes the `style` CLI (handled by `commands.js` internally):
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
yarn style
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Outputs all generated styles into the `/style` folder.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## 📁 Project Structure
|
|
145
|
+
|
|
146
|
+
Example generated output:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
style/
|
|
150
|
+
├── @use.js
|
|
151
|
+
├── @use.scss
|
|
152
|
+
├── web_styles.scss
|
|
153
|
+
├── web_styles_colors.scss
|
|
154
|
+
├── native_styles.js
|
|
155
|
+
├── native_styles_colors.js
|
|
156
|
+
├── web_numbers.scss
|
|
157
|
+
└── fonts.js
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 🧱 Configuration Reference
|
|
163
|
+
|
|
164
|
+
### `numbers`
|
|
165
|
+
Controls spacing/size utilities.
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
numbers: { min: 0, max: 80, step: 1 }
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### `colors`
|
|
172
|
+
Creates color classes and React Native color styles.
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
colors: {
|
|
176
|
+
primary: '#4A46FF',
|
|
177
|
+
surface: '#FFFFFF',
|
|
178
|
+
text: '#000000'
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `fonts`
|
|
183
|
+
Maps font families to identifiers.
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
fonts: {
|
|
187
|
+
h1: 'Inter-Bold',
|
|
188
|
+
body: 'Inter-Regular'
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 🔧 Development
|
|
195
|
+
|
|
196
|
+
To update dependencies:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
yarn add @fullstackunicorn/filesystem
|
|
200
|
+
yarn add @fullstackunicorn/initialize
|
|
201
|
+
yarn add sass
|
|
202
|
+
yarn add -D @fullstackunicorn/reduce
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 🪪 License
|
|
208
|
+
|
|
209
|
+
MIT © fullstackunicorn.dev
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 🌈 FullstackUnicorn Ecosystem
|
|
214
|
+
|
|
215
|
+
- `@fullstackunicorn/filesystem`
|
|
216
|
+
- `@fullstackunicorn/initialize`
|
|
217
|
+
- `@fullstackunicorn/reduce`
|
|
218
|
+
- `@fullstackunicorn/style` ← (this package)
|
package/commands.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
|
|
5
|
+
const configPath = path.resolve(process.cwd(), 'style.config.js')
|
|
6
|
+
|
|
7
|
+
if (!fs.existsSync(configPath)) {
|
|
8
|
+
console.error('❌ Missing style.config.js in project root')
|
|
9
|
+
process.exit(1)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const setup = (await import(configPath)).default
|
|
13
|
+
import { run } from './sources/index.js'
|
|
14
|
+
|
|
15
|
+
run(setup)
|
package/dependencies.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import '@fullstackunicorn/initialize'
|
|
2
|
+
import { init } from '#@/abstracts/init.js'
|
|
3
|
+
import { parse } from '#@/sources/parse.js'
|
|
4
|
+
import { style } from '#@/sources/style.js'
|
|
5
|
+
import { color } from '#@/sources/color.js'
|
|
6
|
+
import { font } from '#@/sources/font.js'
|
|
7
|
+
import { files } from '#@/sources/files.js'
|
|
8
|
+
|
|
9
|
+
export const run = async (setup) => {
|
|
10
|
+
|
|
11
|
+
init.basePath(setup.BASE_PATH)
|
|
12
|
+
init.logs()
|
|
13
|
+
|
|
14
|
+
const isWeb = setup.isWeb
|
|
15
|
+
const isNative = setup.isNative
|
|
16
|
+
|
|
17
|
+
const isMono = setup.isMono
|
|
18
|
+
const defaultHtmlSass = setup.fontFamily.html ? `\n\n${setup.fontFamily.html}` : ``
|
|
19
|
+
const defaultSass = setup.defaultSass+defaultHtmlSass
|
|
20
|
+
|
|
21
|
+
const whole = 256
|
|
22
|
+
const grey = setup.saturation
|
|
23
|
+
|
|
24
|
+
const staticHues = {
|
|
25
|
+
|
|
26
|
+
WW: {R:256, G:256, B:256, name:'white'},
|
|
27
|
+
BB: {R:0, G:0, B:0, name:'black'},
|
|
28
|
+
NN: {R:128, G:128, B:128, name:'grey'},
|
|
29
|
+
...setup.staticHues
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const types = [
|
|
33
|
+
'base', // background-color
|
|
34
|
+
'item', // color
|
|
35
|
+
'line' // border-color
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
const parsed = await parse.project()
|
|
39
|
+
|
|
40
|
+
// const styleList = style.getList(test.allStyles)
|
|
41
|
+
// const colorList = color.getList(test.allColors)
|
|
42
|
+
// const fontList = font.getList(test.allFonts)
|
|
43
|
+
|
|
44
|
+
const fontList = parsed.f
|
|
45
|
+
const styleList = style.getList(parsed.s)
|
|
46
|
+
const colorList = color.getList(parsed.c)
|
|
47
|
+
const colors = color.getColors(staticHues, setup.hues, grey, whole)
|
|
48
|
+
|
|
49
|
+
const fontContents = font.getContents(fontList, setup.fontFamily, isWeb, isNative)
|
|
50
|
+
console.log(`Fonts: ${parsed.f.length}\n\n${parsed.f.join('\t')}\n\n`)
|
|
51
|
+
console.log(`Fonts present: ${fontContents.fonts.presentFont.length}\n\n${fontContents.fonts.presentFont.join('\t')}\n`)
|
|
52
|
+
console.log(`Fonts variants present: ${fontContents.fonts.present.length}\n\n${fontContents.fonts.present.join('\t')}\n`)
|
|
53
|
+
|
|
54
|
+
const colorContents = color.getContents(colorList, colors, whole, types, isWeb, isNative, isMono)
|
|
55
|
+
console.log(`Colors: ${parsed.c.length}\n\n${parsed.c.join('\t')}\n\n`)
|
|
56
|
+
console.log(`Colors present: ${colorContents.present.length}\n\n${colorContents.present.join('\t')}\n`)
|
|
57
|
+
|
|
58
|
+
const styleContents = style.getContents(styleList, setup, isWeb, isNative)
|
|
59
|
+
console.log(`Styles: ${parsed.s.length}\n\n${parsed.s.join('\t')}\n\n`)
|
|
60
|
+
console.log(`Styles present: ${styleContents.present.length}\n\n${styleContents.present.join('\t')}\n`)
|
|
61
|
+
|
|
62
|
+
if (isWeb) {
|
|
63
|
+
|
|
64
|
+
files.write('web_classes_fixed','js', styleContents.web.classes.fixed.sort())
|
|
65
|
+
files.write('web_classes_directional','js', styleContents.web.classes.directional.sort())
|
|
66
|
+
files.write('web_numbers','scss', styleContents.web.numbers.sort())
|
|
67
|
+
files.write('web_styles','scss', styleContents.web.style.sort())
|
|
68
|
+
|
|
69
|
+
files.write('web_classes_color','js', colorContents.web.classes.sort())
|
|
70
|
+
files.write('web_colors','scss', colorContents.web.colors.sort())
|
|
71
|
+
files.write('web_styles_colors','scss', colorContents.web.style.sort())
|
|
72
|
+
|
|
73
|
+
files.write('web_classes_font','js', fontContents.web.classes.sort())
|
|
74
|
+
files.write('web_fonts','scss', fontContents.web.style.sort())
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (isNative) {
|
|
78
|
+
|
|
79
|
+
files.write('native_classes_fixed','js', styleContents.native.classes.fixed.sort())
|
|
80
|
+
files.write('native_classes_directional','js', styleContents.native.classes.directional.sort())
|
|
81
|
+
files.write('native_styles','js', styleContents.native.style.sort())
|
|
82
|
+
|
|
83
|
+
files.write('native_classes_color','js', colorContents.native.classes.sort())
|
|
84
|
+
files.write('native_styles_colors','js', colorContents.native.style.sort())
|
|
85
|
+
|
|
86
|
+
files.write('native_classes_font','js', fontContents.native.classes.sort())
|
|
87
|
+
files.write('native_styles_fonts','js', fontContents.native.style.sort())
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
files.writeUse(isWeb, isNative, defaultSass, defaultHtmlSass)
|
|
91
|
+
files.writeFonts(fontContents.alphabets, fontContents.names)
|
|
92
|
+
|
|
93
|
+
console.log(`\nFONT MISSING: ${fontContents.fonts.missingFont.length}\nFONT PLATFORM MISSING: ${fontContents.fonts.missingPlatform.length}\nFONT variants: ${fontContents.fonts.present.length}\nFONT present: ${fontContents.fonts.presentFont.length}\nFONT total: ${parsed.f.length}`)
|
|
94
|
+
console.log(`\nCOLORS MISSING: ${colorContents.missing.length}\nCOLORS present: ${colorContents.present.length}\nCOLORS total: ${parsed.c.length}`)
|
|
95
|
+
console.log(`\nSTYLES MISSING: ${styleContents.missing.length}\nSTYLES present: ${styleContents.present.length}\nSTYLES total: ${parsed.s.length}\n`)
|
|
96
|
+
|
|
97
|
+
if (fontContents.fonts.missingFont.length) console.log(`Font missing: ${fontContents.fonts.missingFont.length}\n${fontContents.fonts.missingFont.join('\t')}\n`)
|
|
98
|
+
if (fontContents.fonts.missingPlatform.length) console.log(`Font Platform missing: ${fontContents.fonts.missingPlatform.length}\n${fontContents.fonts.missingPlatform.join('\t')}\n`)
|
|
99
|
+
if (colorContents.missing.length) console.log(`Colors missing: ${colorContents.missing.length}\n${colorContents.missing.join('\t')}\n`)
|
|
100
|
+
if (styleContents.missing.length) console.log(`Styles missing: ${styleContents.missing.length}\n${styleContents.missing.join('\t')}\n`)
|
|
101
|
+
|
|
102
|
+
console.log(`Missing font: ${fontContents.fonts.missingFont.length}`)
|
|
103
|
+
console.log(`Missing font platform: ${fontContents.fonts.missingPlatform.length}`)
|
|
104
|
+
console.log(`Colors missing: ${colorContents.missing.length}`)
|
|
105
|
+
console.log(`Styles missing: ${styleContents.missing.length}`)
|
|
106
|
+
console.log(``)
|
|
107
|
+
|
|
108
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"name": "@fullstackunicorn/style",
|
|
4
|
+
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
|
+
"description": "A development utility for generating responsive web and native styles (CSS, SCSS, JS, RN) from a declarative style.config.js file.",
|
|
6
|
+
"readme": "README.md",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"private": false,
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://gitlab.com/fullstackunicorn/style.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"index.js",
|
|
17
|
+
"dependencies.js",
|
|
18
|
+
"abstracts/",
|
|
19
|
+
"sources/"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"commands.js"
|
|
23
|
+
],
|
|
24
|
+
"keywords": [
|
|
25
|
+
"style-generator",
|
|
26
|
+
"scss",
|
|
27
|
+
"react-native",
|
|
28
|
+
"css",
|
|
29
|
+
"design-system",
|
|
30
|
+
"utilities",
|
|
31
|
+
"responsive-design",
|
|
32
|
+
"fullstackunicorn"
|
|
33
|
+
],
|
|
34
|
+
"imports": {
|
|
35
|
+
"#@": "./",
|
|
36
|
+
"#@/*": "./*"
|
|
37
|
+
},
|
|
38
|
+
"bin": {
|
|
39
|
+
"style": "./commands.js"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@fullstackunicorn/filesystem": "^1.0.1",
|
|
46
|
+
"@fullstackunicorn/initialize": "^1.0.2",
|
|
47
|
+
"sass": "^1.94.2"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@fullstackunicorn/reduce": "^1.0.13"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/sources/color.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
class Color {
|
|
2
|
+
|
|
3
|
+
exists = (mainArray, subArray) => {
|
|
4
|
+
|
|
5
|
+
const result = []
|
|
6
|
+
for (const item of subArray) {
|
|
7
|
+
if (mainArray.includes(item)) result.push(item)
|
|
8
|
+
}
|
|
9
|
+
if (result.length) return true
|
|
10
|
+
else return false
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getType = (platform, type) => {
|
|
15
|
+
|
|
16
|
+
const types = {
|
|
17
|
+
web: {
|
|
18
|
+
base: 'background-color',
|
|
19
|
+
item: 'color',
|
|
20
|
+
line: 'border-color'
|
|
21
|
+
},
|
|
22
|
+
native: {
|
|
23
|
+
base: 'backgroundColor',
|
|
24
|
+
item: 'color',
|
|
25
|
+
line: 'borderColor'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return types[platform][type]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getContents = (list = [], colors = {}, whole, types, isWeb, isNative, isMono) => {
|
|
32
|
+
|
|
33
|
+
const present = []
|
|
34
|
+
const missing = []
|
|
35
|
+
const done = []
|
|
36
|
+
const web = {
|
|
37
|
+
classes: [],
|
|
38
|
+
style: [],
|
|
39
|
+
colors: []
|
|
40
|
+
}
|
|
41
|
+
const native = {
|
|
42
|
+
classes: [],
|
|
43
|
+
style: [],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const item of list) {
|
|
47
|
+
|
|
48
|
+
const { type, name, color, opacityName } = item
|
|
49
|
+
|
|
50
|
+
if (!types.includes(type)) {
|
|
51
|
+
missing.push(name)
|
|
52
|
+
continue
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const opacity = item.opacity / 100
|
|
56
|
+
|
|
57
|
+
let RGB
|
|
58
|
+
let RGB_o
|
|
59
|
+
let className
|
|
60
|
+
let className_opposite
|
|
61
|
+
let CC_opposite
|
|
62
|
+
let name_opposite
|
|
63
|
+
|
|
64
|
+
const CC = colors[color]
|
|
65
|
+
|
|
66
|
+
if (!CC) {
|
|
67
|
+
missing.push(name)
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const isWhite = color === 'WW'
|
|
72
|
+
const isBlack = color === 'BB'
|
|
73
|
+
|
|
74
|
+
if (isBlack || isWhite) {
|
|
75
|
+
|
|
76
|
+
if (isBlack) {
|
|
77
|
+
CC_opposite = colors.WW
|
|
78
|
+
name_opposite = `${type}_WW${opacityName}`
|
|
79
|
+
} else {
|
|
80
|
+
CC_opposite = colors.BB
|
|
81
|
+
name_opposite = `${type}_BB${opacityName}`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
RGB = {
|
|
85
|
+
R: CC.R,
|
|
86
|
+
G: CC.G,
|
|
87
|
+
B: CC.B,
|
|
88
|
+
name: `${CC.name}${opacityName}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
RGB_o = {
|
|
92
|
+
R: CC_opposite.R,
|
|
93
|
+
G: CC_opposite.G,
|
|
94
|
+
B: CC_opposite.B,
|
|
95
|
+
name: `${CC_opposite.name}${opacityName}`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
else if (!item.grade) {
|
|
101
|
+
|
|
102
|
+
RGB = {
|
|
103
|
+
R: CC.R,
|
|
104
|
+
G: CC.G,
|
|
105
|
+
B: CC.B,
|
|
106
|
+
name: `${CC.name}${opacityName}`,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
RGB_o = { isFixed: true }
|
|
110
|
+
|
|
111
|
+
} else {
|
|
112
|
+
|
|
113
|
+
const { variant, gradeName, blend, blendName } = item
|
|
114
|
+
|
|
115
|
+
const blendCC = whole - blend
|
|
116
|
+
|
|
117
|
+
const isB = variant === 'B'
|
|
118
|
+
const NN = isB ? colors.BB : colors.WW
|
|
119
|
+
className = `${CC.name}${blendName}${variant}${opacityName}`
|
|
120
|
+
RGB = this.getColor(NN, blend, CC, blendCC, whole, className)
|
|
121
|
+
|
|
122
|
+
const variant_opposite = isB ? 'W' : 'B'
|
|
123
|
+
const NN_opposite = isB ? colors.WW : colors.BB
|
|
124
|
+
name_opposite = `${type}_${color}_${variant_opposite}${gradeName}${opacityName}`
|
|
125
|
+
className_opposite = `${CC.name}${blendName}${variant_opposite}${opacityName}`
|
|
126
|
+
RGB_o = this.getColor(NN_opposite, blend, CC, blendCC, whole, className_opposite)
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (item.isLowercaseVariant) isMono=true
|
|
131
|
+
|
|
132
|
+
let isDone
|
|
133
|
+
if (isMono) isDone = this.exists(done, [name])
|
|
134
|
+
else isDone = this.exists(done, RGB_o.isFixed ? [name] : [name, name_opposite])
|
|
135
|
+
if (isDone) continue
|
|
136
|
+
|
|
137
|
+
if (!RGB_o.isFixed && !isMono) {
|
|
138
|
+
|
|
139
|
+
if (isWeb) {
|
|
140
|
+
|
|
141
|
+
web.classes.push(
|
|
142
|
+
`${name}: isLight ? '${type}_${RGB.name}' : '${type}_${RGB_o.name}'`,
|
|
143
|
+
`${name_opposite}: isLight ? '${type}_${RGB_o.name}' : '${type}_${RGB.name}'`,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
web.style.push(
|
|
147
|
+
`.${type}_${RGB.name} { ${this.getType('web', type)}: c.$${RGB.name} }`,
|
|
148
|
+
`.${type}_${RGB_o.name} { ${this.getType('web', type)}: c.$${RGB_o.name} }`,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
web.colors.push(
|
|
152
|
+
`$${RGB.name}: rgba(${RGB.R}, ${RGB.G}, ${RGB.B}, ${opacity});`,
|
|
153
|
+
`$${RGB_o.name}: rgba(${RGB_o.R}, ${RGB_o.G}, ${RGB_o.B}, ${opacity});`
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (isNative) {
|
|
158
|
+
|
|
159
|
+
native.classes.push(
|
|
160
|
+
`${name}: color[ isLight ? '${type}_${RGB.name}' : '${type}_${RGB_o.name}']`,
|
|
161
|
+
`${name_opposite}: color[ isLight ? '${type}_${RGB_o.name}' : '${type}_${RGB.name}']`,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
native.style.push(
|
|
165
|
+
`${type}_${RGB.name}: { ${this.getType('native', type)}: 'rgba(${RGB.R}, ${RGB.G}, ${RGB.B}, ${opacity})' }`,
|
|
166
|
+
`${type}_${RGB_o.name}: { ${this.getType('native', type)}: 'rgba(${RGB_o.R}, ${RGB_o.G}, ${RGB_o.B}, ${opacity})' }`,
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
done.push(name)
|
|
171
|
+
present.push(name)
|
|
172
|
+
|
|
173
|
+
done.push(name_opposite)
|
|
174
|
+
if (list.find(element=>element.name===name_opposite)) present.push(name_opposite)
|
|
175
|
+
|
|
176
|
+
} else {
|
|
177
|
+
|
|
178
|
+
if (isWeb) {
|
|
179
|
+
|
|
180
|
+
web.classes.push(
|
|
181
|
+
`${name}: '${type}_${RGB.name}'`,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
web.style.push(
|
|
185
|
+
`.${type}_${RGB.name} { ${this.getType('web', type)}: c.$${RGB.name} }`,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
web.colors.push(
|
|
189
|
+
`$${RGB.name}: rgba(${RGB.R}, ${RGB.G}, ${RGB.B}, ${opacity});`,
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isNative) {
|
|
194
|
+
|
|
195
|
+
native.classes.push(
|
|
196
|
+
`${name}: color['${type}_${RGB.name}']`,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
native.style.push(
|
|
200
|
+
`${type}_${RGB.name}: { ${this.getType('native', type)}: 'rgba(${RGB.R}, ${RGB.G}, ${RGB.B}, ${opacity})' }`,
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
done.push(name)
|
|
205
|
+
present.push(name)
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const response = { missing, present, done }
|
|
212
|
+
if (isWeb) response.web = web
|
|
213
|
+
if (isNative) response.native = native
|
|
214
|
+
return response
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getColor = (NN, blendNN, CC, blendCC, whole, name) => ({
|
|
218
|
+
R: Math.round((NN.R * blendNN + CC.R * blendCC) / whole),
|
|
219
|
+
G: Math.round((NN.G * blendNN + CC.G * blendCC) / whole),
|
|
220
|
+
B: Math.round((NN.B * blendNN + CC.B * blendCC) / whole),
|
|
221
|
+
name,
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
getColors = (staticHues={}, hues={}, grey, whole) => {
|
|
225
|
+
|
|
226
|
+
const response = {}
|
|
227
|
+
const color = whole - grey
|
|
228
|
+
|
|
229
|
+
for (const key of Object.keys(hues)) {
|
|
230
|
+
response[key] = this.getColor(staticHues.NN, grey, hues[key], color, whole, hues[key].name)
|
|
231
|
+
}
|
|
232
|
+
return {...staticHues, ...response}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
getList = (list) => {
|
|
236
|
+
|
|
237
|
+
const response = []
|
|
238
|
+
const WB = /[WBwb]/;
|
|
239
|
+
|
|
240
|
+
for (const name of list) {
|
|
241
|
+
|
|
242
|
+
const splitted = name.split('_')
|
|
243
|
+
|
|
244
|
+
const result = {}
|
|
245
|
+
result.name = name
|
|
246
|
+
result.type = splitted[0]
|
|
247
|
+
result.color = splitted[1]
|
|
248
|
+
result.opacity = 100
|
|
249
|
+
result.opacityName = ''
|
|
250
|
+
|
|
251
|
+
let variant
|
|
252
|
+
let grade
|
|
253
|
+
let gradeName
|
|
254
|
+
let blend
|
|
255
|
+
let blendName
|
|
256
|
+
|
|
257
|
+
if (splitted[2]) {
|
|
258
|
+
|
|
259
|
+
if (WB.test(splitted[2])) {
|
|
260
|
+
|
|
261
|
+
variant = splitted[2].charAt(0)
|
|
262
|
+
|
|
263
|
+
grade = Number(splitted[2].slice(1))
|
|
264
|
+
gradeName = grade < 100 ? `0${grade}` : `${grade}`
|
|
265
|
+
blend = grade / 50 * 16
|
|
266
|
+
blendName = blend < 100 ? `_0${blend}` : `_${blend}`
|
|
267
|
+
|
|
268
|
+
if (splitted[3]) {
|
|
269
|
+
result.opacity = Number(splitted[3])
|
|
270
|
+
result.opacityName = `_${splitted[3]}`
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
result.opacity = Number(splitted[2])
|
|
274
|
+
result.opacityName = `_${splitted[2]}`
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (variant) {
|
|
278
|
+
result.variant = variant
|
|
279
|
+
result.isLowercaseVariant = variant === variant.toLowerCase()
|
|
280
|
+
result.grade = grade
|
|
281
|
+
result.gradeName = gradeName
|
|
282
|
+
result.blend = blend
|
|
283
|
+
result.blendName = blendName
|
|
284
|
+
}
|
|
285
|
+
response.push(result)
|
|
286
|
+
}
|
|
287
|
+
return response
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export const color = new Color()
|