@fullstackunicorn/style 1.0.13 → 1.0.14

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.
@@ -2,10 +2,15 @@ import { fsa, glob } from '#@/index.dep.js'
2
2
 
3
3
  class Parse {
4
4
 
5
- project = async () => {
5
+ project = async (sourcePaths = [process.env.BASE_PATH]) => {
6
6
 
7
- const files = await glob(`${process.env.BASE_PATH}/**/*.js`, {
8
- ignore: [`${process.env.BASE_PATH}/node_modules/**`, `${process.env.BASE_PATH}/@*/**` ]})
7
+ if (!Array.isArray(sourcePaths) || !sourcePaths.length || sourcePaths.some(value => typeof value !== 'string' || !value.trim())) {
8
+ throw new Error('SOURCE_PATHS must be a non-empty array of paths')
9
+ }
10
+
11
+ const files = [...new Set((await Promise.all(sourcePaths.map(sourcePath => glob(`${sourcePath}/**/*.js`, {
12
+ ignore: [`${sourcePath}/node_modules/**`, `${sourcePath}/@*/**`]
13
+ })))).flat())]
9
14
 
10
15
  const s_raw = []
11
16
  const c_raw = []
@@ -50,4 +55,4 @@ class Parse {
50
55
  }
51
56
  }
52
57
 
53
- export const parse = new Parse()
58
+ export const parse = new Parse()
package/modules/run.js CHANGED
@@ -35,7 +35,7 @@ export const run = async (setup) => {
35
35
  'line' // border-color
36
36
  ]
37
37
 
38
- const parsed = await parse.project()
38
+ const parsed = await parse.project(setup.SOURCE_PATHS || [setup.BASE_PATH])
39
39
 
40
40
  const fontList = parsed.f
41
41
  const styleList = style.getList(parsed.s)
@@ -80,4 +80,4 @@ export const run = async (setup) => {
80
80
  logs.prepare( fontContents.fonts, colorContents, styleContents, parsed)
81
81
  logs.toConsole()
82
82
  logs.toMarkdown(setup.LOGS_PATH)
83
- }
83
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.13",
2
+ "version": "1.0.14",
3
3
  "name": "@fullstackunicorn/style",
4
4
  "author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
5
5
  "description": "A development utility for generating responsive web and native styles (CSS, SCSS, JS, RN) from a declarative style.config.js file.",
@@ -11,7 +11,8 @@
11
11
  "files": [
12
12
  "index.js",
13
13
  "index.dep.js",
14
- "modules/"
14
+ "modules/",
15
+ "package.md"
15
16
  ],
16
17
  "bin": {
17
18
  "style": "./index.cmd.js"
@@ -38,8 +39,7 @@
38
39
  "#@/*": "./*"
39
40
  },
40
41
  "scripts": {
41
- "cmd": "chmod +x ./config.cmd.sh && ./config.cmd.sh",
42
- "test": "exit 1"
42
+ "test": "node --test tests/*.test.js"
43
43
  },
44
44
  "dependencies": {
45
45
  "@fullstackunicorn/filesystem": "^1.0.4",
package/package.md ADDED
@@ -0,0 +1,253 @@
1
+ # @fullstackunicorn/style
2
+
3
+ `SOURCE_PATHS` optionally adds explicit source roots to the normal project scan. This is used when shared components live in an installed package; nested dependencies remain excluded.
4
+
5
+ A cross‑platform styling engine for Web and React Native.
6
+ It generates unified utility classes, directional rules, responsive ratios, color‑mode styles, and typography maps — all from a single configuration file.
7
+
8
+ Designed for use inside FullstackUnicorn projects, but fully usable as a standalone styling system.
9
+
10
+ ## 📦 Installation
11
+
12
+ ```bash
13
+ yarn add @fullstackunicorn/style
14
+ ```
15
+
16
+ or
17
+
18
+ ```bash
19
+ npm install @fullstackunicorn/style
20
+ ```
21
+
22
+ ## 🧩 Usage
23
+
24
+ Create a `style.config.js` file in the root folder of the project:
25
+
26
+ ```js
27
+ export default {
28
+
29
+ // BASE PATH:
30
+ BASE_PATH: './',
31
+
32
+ // PLATFORM:
33
+ isWeb: true,
34
+ isNative: false,
35
+
36
+ // SATURATION: 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 255
37
+ saturation: 128,
38
+
39
+ // HUES: ONE channel must be ZERO
40
+ hues: {
41
+ C1: { R: 0, G: 128, B: 256, name: 'blue' },
42
+ C2: { R: 256, G: 128, B: 0, name: 'orange' },
43
+ C3: { R: 256, G: 0, B: 128, name: 'pink' },
44
+ },
45
+
46
+ // STATIC HUES NOT AFFECTED BY SATURATION
47
+ staticHues: {
48
+ RR: { R: 256, G: 0, B: 0, name: 'error' },
49
+ OR: { R: 256, G: 128, B: 0, name: 'warning' },
50
+ },
51
+
52
+ // SET THE DEFAULTS FONTS FOR EACH PLATFORM
53
+ // SET THE FONTS FOR EACH ALPHABET
54
+ // ANY FONT MENTIONED IN THE ALPHABETH (es. f1, m1) MUST HAVE A DEFAULT (fallback)
55
+ fontFamily: {
56
+ html: `html { font-family: 'sans-serif'; font-weight: 400; };`,
57
+ defaults: {
58
+ f1: {
59
+ ios: 'System',
60
+ android: 'sans-serif',
61
+ web: 'sans-serif'
62
+ },
63
+ m1: {
64
+ ios: 'Courier New',
65
+ android: 'monospace',
66
+ web: 'monospace'
67
+ }
68
+ },
69
+ fonts: {
70
+ latin: {
71
+ f1: 'OpenSans',
72
+ m1: 'Inconsolata'
73
+ },
74
+ cyrillic: {
75
+ f1: 'OpenSans',
76
+ },
77
+ greek: {
78
+ f1: 'OpenSans',
79
+ },
80
+ arabic: {
81
+ f1: 'OpenSans',
82
+ },
83
+ chinese: {
84
+ f1: 'OpenSans',
85
+ },
86
+ japanese: {
87
+ f1: 'OpenSans',
88
+ },
89
+ }
90
+ },
91
+
92
+ // DEFAULT SASS
93
+ defaultSass:
94
+ `* {
95
+ padding:0;
96
+ margin:0;
97
+ border:0;
98
+ outline:none;
99
+ background-color:unset;
100
+ text-decoration:none;
101
+ box-sizing:border-box;
102
+ cursor:default;
103
+ // user-select: none;
104
+ };
105
+
106
+ html, body { max-width:100vw; overflow-x:hidden }
107
+
108
+ body { margin:0; padding:0 }
109
+
110
+ img { overflow-clip-margin:border-box; overflow:clip }
111
+
112
+ a {
113
+ &:link {color:unset; text-decoration: none}
114
+ &:visited {color:unset; text-decoration: none}
115
+ &:link:active {color:unset; text-decoration: none}
116
+ &:visited:active {color:unset; text-decoration: none}
117
+ };
118
+
119
+ h1, h2, h3, h4, h5, h6, p, a, span, input, textarea, option, button {
120
+ margin-block-start: 0;
121
+ margin-block-end: 0;
122
+ margin-inline-start: 0;
123
+ margin-inline-end: 0;
124
+ };`
125
+
126
+ }
127
+ ```
128
+
129
+ Generate styles:
130
+
131
+ ```bash
132
+ yarn style
133
+ ```
134
+
135
+ This will output a `/style/` folder containing:
136
+
137
+ ```
138
+ /style
139
+ ├── @use.js
140
+ ├── @use.scss
141
+ ├── web_styles.scss
142
+ ├── native_styles.js
143
+ ├── fonts.js
144
+ └── ...
145
+ ```
146
+
147
+ ## 🖥 Web and React Native Integration
148
+
149
+ Ensure you create in the root folder of the project the templates folder and index.js
150
+
151
+ ```
152
+ /templates
153
+ ├── index.js
154
+ └── ...
155
+ ```
156
+
157
+ You can add as many blocks of styles you wish and later reuse it
158
+
159
+ ```js
160
+
161
+ export const templates = (s, c, t) => {
162
+
163
+ t.server = getServer(s,c,t)
164
+
165
+ t.page = {} // create a template for the pages
166
+ t.page.home = [s.col, s.XYc]
167
+ t.page.fluid = [s.col, s.XYc]
168
+ t.page.fixed = [s.col_cXsY, s.Yc, s.Xx, s.Xmax540, s.paddingX16]
169
+ t.page.docs = [s.col_cXsY, s.Yc, s.Xx, s.Xmax540, s.paddingX16, s.marginT16]
170
+ t.page.card = [s.col_cX, s.Yc, s.paddingX16]
171
+
172
+ return t
173
+ }
174
+ ```
175
+
176
+ In each component import useStyle
177
+
178
+ ```js
179
+ import { useStyle } from '#@/style/@use.js'
180
+ import { View } from '#@/imports/core/View.js'
181
+
182
+ export const BoxPod = ({ children }) => {
183
+
184
+ const { s, c, f, t, F, B, S, I, H } = useStyle()
185
+
186
+ S.box = [t.page.home, s.marginB16, c.base_C1_W600]
187
+
188
+ return (
189
+ <View classes={S.box}>
190
+ {children}
191
+ </View>
192
+ )
193
+ }
194
+ ```
195
+
196
+ The View component should have the same interface for Web and Native, but in Native environment the Native component will be rendered and in Web environments the Web component will be rendered
197
+
198
+ Web Component
199
+ ```js
200
+ export const View = ({
201
+ classes = [], inline = {}, children,
202
+ viewRef = null, setIsHover = () => { } }) => {
203
+ return (
204
+ <div className={classes.join(' ')} style={inline}
205
+ ref={viewRef}
206
+ onMouseEnter={() => setIsHover(true)}
207
+ onMouseLeave={() => setIsHover(false)}
208
+ >
209
+ {children}
210
+ </div>
211
+ )
212
+ }
213
+ ```
214
+
215
+ Native Component
216
+ ```js
217
+ import { View as NativeView, Pressable as NativePressable, Platform } from 'react-native'
218
+
219
+ export const View = ({ classes = [], inline = {}, children, viewRef, setIsHover }) => {
220
+
221
+ const props = {}
222
+ props.style = [...classes, inline]
223
+ props.ref = viewRef
224
+
225
+ if (F3.isFnc(setIsHover)) {
226
+
227
+ props.onPressIn = () => setIsHover(true);
228
+ props.onPressOut = () => setIsHover(false);
229
+ return <NativePressable {...props}>{children}</NativePressable>
230
+ }
231
+
232
+ return <NativeView {...props}>{children}</NativeView>
233
+
234
+ }
235
+ ```
236
+
237
+ ## 🧪 Generated Classes
238
+
239
+ ### Example utilities
240
+
241
+ | Utility | Meaning |
242
+ |--------|----------|
243
+ | `s.margin16` | margin 16 |
244
+ | `s.padding8` | padding 8 |
245
+ | `s.row` | display flex, flex-direction row |
246
+ | `s.gap12` | gap 12 |
247
+ | `s.radius4` | border-radius 4 |
248
+ | `s.ratio1` | 1/1 square ratio |
249
+ | `s.ratio_X16Y9` | 16/9 layout ratio |
250
+
251
+ ## 🪪 License
252
+
253
+ MIT © fullstackunicorn.dev