@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/sources/files.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { fss } from '#@/dependencies.js'
|
|
2
|
+
|
|
3
|
+
class Files {
|
|
4
|
+
|
|
5
|
+
tryWrite = (path, file) => {
|
|
6
|
+
try {
|
|
7
|
+
fss.writeFile(path, file)
|
|
8
|
+
console.log(`SUCCESS: file written: ${path}`)
|
|
9
|
+
} catch (error) { console.log(`ERROR: file NOT written: ${path} \n${error}`)}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
write = (filename, extension, content) => {
|
|
13
|
+
|
|
14
|
+
const basePath = process.env.BASE_PATH
|
|
15
|
+
const stylePath = `${basePath}style`
|
|
16
|
+
|
|
17
|
+
const file = this[filename](content).join('\n')
|
|
18
|
+
|
|
19
|
+
if (!fss.exists(stylePath)) fss.writeDir(stylePath)
|
|
20
|
+
this.tryWrite(`${stylePath}/${filename}.${extension}`, file)
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
writeUse = (isWeb, isNative, defaultSass) => {
|
|
25
|
+
|
|
26
|
+
const basePath = process.env.BASE_PATH
|
|
27
|
+
const stylePath = `${basePath}style`
|
|
28
|
+
|
|
29
|
+
if (!fss.exists(stylePath)) fss.writeDir(stylePath)
|
|
30
|
+
|
|
31
|
+
if (isNative) {
|
|
32
|
+
this.tryWrite(`${stylePath}/@use.js`, this.use('native'))
|
|
33
|
+
if (isWeb) {
|
|
34
|
+
this.tryWrite(`${stylePath}/@use.web.js`, this.use('web'))
|
|
35
|
+
this.tryWrite(`${stylePath}/@use.scss`, this.useSass(defaultSass))
|
|
36
|
+
}
|
|
37
|
+
} else if (isWeb) {
|
|
38
|
+
this.tryWrite(`${stylePath}/@use.js`, this.use('web'))
|
|
39
|
+
this.tryWrite(`${stylePath}/defaults.scss`, defaultSass)
|
|
40
|
+
this.tryWrite(`${stylePath}/@use.scss`, this.useSass())
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
writeFonts = (alphabets, fonts) => {
|
|
45
|
+
|
|
46
|
+
const basePath = process.env.BASE_PATH
|
|
47
|
+
const stylePath = `${basePath}style`
|
|
48
|
+
|
|
49
|
+
const file = [
|
|
50
|
+
`export const fonts = ${JSON.stringify(fonts, null, 2)}\n\n`,
|
|
51
|
+
`export const alphabets = ${JSON.stringify(alphabets, null, 2)}`,
|
|
52
|
+
].join('')
|
|
53
|
+
|
|
54
|
+
if (!fss.exists(stylePath)) fss.writeDir(stylePath)
|
|
55
|
+
this.tryWrite(`${stylePath}/fonts.js`, file)
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
web_numbers = content => content
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
web_classes_fixed = (content) => ([
|
|
63
|
+
`export const web_classes_fixed = {`,
|
|
64
|
+
`\t${content.join(',\n\t')}`,
|
|
65
|
+
`}`
|
|
66
|
+
])
|
|
67
|
+
web_classes_directional = (content) => ([
|
|
68
|
+
`export const web_classes_directional = isRTL => ({`,
|
|
69
|
+
`\t${content.join(',\n\t')}`,
|
|
70
|
+
`})`
|
|
71
|
+
])
|
|
72
|
+
web_classes_font = (content) => ([
|
|
73
|
+
`export const web_classes_font = {`,
|
|
74
|
+
`\t${content.join(',\n\t')}`,
|
|
75
|
+
`}`
|
|
76
|
+
])
|
|
77
|
+
|
|
78
|
+
web_styles = (content) => ([
|
|
79
|
+
`@use './web_numbers.scss' as n;`,
|
|
80
|
+
`${content.join(';\n')}`,
|
|
81
|
+
])
|
|
82
|
+
web_fonts = (content) => ([
|
|
83
|
+
`${content.join(';\n')}`,
|
|
84
|
+
])
|
|
85
|
+
|
|
86
|
+
native_classes_fixed = (content) => [
|
|
87
|
+
`import { native_styles as style } from './native_styles.js'`,
|
|
88
|
+
`export const native_classes_fixed = {`,
|
|
89
|
+
`\t${content.join(',\n\t')}`,
|
|
90
|
+
`}`
|
|
91
|
+
]
|
|
92
|
+
native_classes_directional = (content) => [
|
|
93
|
+
`import { native_styles as style } from './native_styles.js'`,
|
|
94
|
+
`export const native_classes_directional = isRTL => ({`,
|
|
95
|
+
`\t${content.join(',\n\t')}`,
|
|
96
|
+
`})`
|
|
97
|
+
]
|
|
98
|
+
native_classes_font = (content) => [
|
|
99
|
+
`import { native_styles as style } from './native_styles.js'`,
|
|
100
|
+
`export const native_classes_font = {`,
|
|
101
|
+
`\t${content.join(',\n\t')}`,
|
|
102
|
+
`}`
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
native_styles = (content) => [
|
|
106
|
+
`import { StyleSheet } from 'react-native'`,
|
|
107
|
+
`const mapStyle = obj => StyleSheet.create(obj)`,
|
|
108
|
+
`export const native_styles = mapStyle({`,
|
|
109
|
+
`\t${content.join(',\n\t')}`,
|
|
110
|
+
`})`
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
native_styles_fonts = (content) => [
|
|
114
|
+
`import { StyleSheet } from 'react-native'`,
|
|
115
|
+
`const mapStyle = obj => StyleSheet.create(obj)`,
|
|
116
|
+
`export const native_styles_fonts = mapStyle({`,
|
|
117
|
+
`\t${content.join(',\n\t')}`,
|
|
118
|
+
`})`
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
web_colors = content => content
|
|
122
|
+
|
|
123
|
+
web_classes_color = (content) => ([
|
|
124
|
+
`export const web_classes_color = isLight => ({`,
|
|
125
|
+
`\t${content.join(',\n\t')}`,
|
|
126
|
+
`})`
|
|
127
|
+
])
|
|
128
|
+
|
|
129
|
+
web_styles_colors = (content) => ([
|
|
130
|
+
`@use './web_colors.scss' as c;`,
|
|
131
|
+
`${content.join(';\n')}`,
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
native_classes_color = (content) => [
|
|
135
|
+
`import { native_styles_colors as color } from './native_styles_colors.js'`,
|
|
136
|
+
`export const native_classes_color = isLight => ({`,
|
|
137
|
+
`\t${content.join(',\n\t')}`,
|
|
138
|
+
`})`
|
|
139
|
+
]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
native_styles_colors = (content) => [
|
|
143
|
+
`import { StyleSheet } from 'react-native'`,
|
|
144
|
+
`const mapStyle = obj => StyleSheet.create(obj)`,
|
|
145
|
+
`export const native_styles_colors = mapStyle({`,
|
|
146
|
+
`\t${content.join(',\n\t')}`,
|
|
147
|
+
`})`
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
useSass = () => (
|
|
151
|
+
`@forward './defaults.scss';
|
|
152
|
+
@forward './web_styles_colors.scss';
|
|
153
|
+
@forward './web_styles.scss';
|
|
154
|
+
@forward './web_fonts.scss';`
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
use = type => (
|
|
158
|
+
`import { useGetIsDark } from '#@/base/theme/@use'
|
|
159
|
+
import { useGetLanguage } from '#@/base/language/@use'
|
|
160
|
+
import { templates } from '#@/templates/index'
|
|
161
|
+
|
|
162
|
+
import { ${type}_classes_color as color } from './${type}_classes_color'
|
|
163
|
+
import { ${type}_classes_directional as directional } from './${type}_classes_directional'
|
|
164
|
+
import { ${type}_classes_fixed as fixed } from './${type}_classes_fixed'
|
|
165
|
+
import { ${type}_classes_font as fonts } from './${type}_classes_font'
|
|
166
|
+
import { fonts as f, alphabets } from './fonts.js'
|
|
167
|
+
|
|
168
|
+
class Empty {
|
|
169
|
+
F = {} // font
|
|
170
|
+
B = {} // boolean
|
|
171
|
+
S = {} // style
|
|
172
|
+
I = {} // inline
|
|
173
|
+
H = {} // hover
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const useTemplate = () => {
|
|
177
|
+
|
|
178
|
+
const isDark = useGetIsDark()
|
|
179
|
+
const language = useGetLanguage()
|
|
180
|
+
|
|
181
|
+
const s = {
|
|
182
|
+
...fixed,
|
|
183
|
+
...directional(language.isRTL)
|
|
184
|
+
}
|
|
185
|
+
const c = color(!isDark)
|
|
186
|
+
|
|
187
|
+
const template = {}
|
|
188
|
+
|
|
189
|
+
const t = templates(s, c, template)
|
|
190
|
+
|
|
191
|
+
return { s, c, t }
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export const useStyle = () => {
|
|
196
|
+
|
|
197
|
+
const empty = new Empty
|
|
198
|
+
|
|
199
|
+
const { s, c, t } = useTemplate()
|
|
200
|
+
|
|
201
|
+
return { s, c, t, f, ...empty }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export const useStyleFonts = () => ({ fonts, alphabets })
|
|
205
|
+
|
|
206
|
+
export const useImage = dataUri => ({
|
|
207
|
+
backgroundImage:'url('+dataUri+')',
|
|
208
|
+
backgroundSize:'cover',
|
|
209
|
+
backgroundRepeat:'no-repeat',
|
|
210
|
+
width:'100%', height:'100%'
|
|
211
|
+
})`
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export const files = new Files()
|
package/sources/font.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
class Font {
|
|
2
|
+
|
|
3
|
+
required = {
|
|
4
|
+
web: ['web'],
|
|
5
|
+
native: ['ios', 'android', 'web']
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getFont = {
|
|
9
|
+
target: `fixed`,
|
|
10
|
+
write: (name, value) => (name),
|
|
11
|
+
webClasses: (name, value) => (`'${name}': '${name}'`),
|
|
12
|
+
webStyle: (name, value) => (`.${name} { font-family: ${value} }`),
|
|
13
|
+
nativeClasses: (name, value) => (`'${name}': style['${name}']`),
|
|
14
|
+
nativeStyle: (name, value) => (`'${name}': { fontFamily: '${value}' }`)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getName = (value) => value.includes(" ") ? `'${value}'` : value
|
|
18
|
+
|
|
19
|
+
getContents = (list = [], fontFamily = {}, isWeb, isNative) => {
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(list) && !list.length) list=['f1']
|
|
22
|
+
|
|
23
|
+
let required = isNative ? this.required.native : this.required.web
|
|
24
|
+
|
|
25
|
+
const fonts = {
|
|
26
|
+
parsed: [],
|
|
27
|
+
presentFont: [],
|
|
28
|
+
missingFont: [],
|
|
29
|
+
missingPlatform: [],
|
|
30
|
+
present: [],
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const names = {}
|
|
34
|
+
|
|
35
|
+
const web = {
|
|
36
|
+
classes: [],
|
|
37
|
+
style: [],
|
|
38
|
+
}
|
|
39
|
+
const native = {
|
|
40
|
+
classes: [],
|
|
41
|
+
style: [],
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const alphabets = { }
|
|
45
|
+
|
|
46
|
+
for (const font of list) {
|
|
47
|
+
|
|
48
|
+
const fontList = Object.keys(fontFamily.defaults)
|
|
49
|
+
const platforms = Object.keys(fontFamily.defaults[font])
|
|
50
|
+
|
|
51
|
+
fonts.parsed.push(font)
|
|
52
|
+
|
|
53
|
+
if (!fontList.includes(font)) {
|
|
54
|
+
fonts.missingFont.push(font)
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!required.every(val => platforms.includes(val))) {
|
|
59
|
+
fonts.missingPlatform.push(font)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (const platform of platforms) {
|
|
64
|
+
|
|
65
|
+
const name = `${font}-default-${platform}`
|
|
66
|
+
const value = fontFamily.defaults[font][platform]
|
|
67
|
+
|
|
68
|
+
web.classes.push(this.getFont.webClasses(name, value))
|
|
69
|
+
web.style.push(this.getFont.webStyle(name, this.getName(value)))
|
|
70
|
+
native.classes.push(this.getFont.nativeClasses(name, value))
|
|
71
|
+
native.style.push(this.getFont.nativeStyle(name, value))
|
|
72
|
+
|
|
73
|
+
fonts.present.push(name)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
names[font]=font
|
|
77
|
+
|
|
78
|
+
fonts.presentFont.push(font)
|
|
79
|
+
|
|
80
|
+
for (const alphabeth of Object.keys(fontFamily.fonts)) {
|
|
81
|
+
|
|
82
|
+
const value = fontFamily.fonts[alphabeth][font]
|
|
83
|
+
|
|
84
|
+
if (!value) continue
|
|
85
|
+
|
|
86
|
+
if (!alphabets[alphabeth]) alphabets[alphabeth]={}
|
|
87
|
+
alphabets[alphabeth][font] = value
|
|
88
|
+
|
|
89
|
+
const name = `${font}-${alphabeth}`
|
|
90
|
+
|
|
91
|
+
const webDefault = fontFamily.defaults[font].web
|
|
92
|
+
const isDefault = value === webDefault
|
|
93
|
+
|
|
94
|
+
const webValue = isDefault ? this.getName(value) : `${this.getName(value)}, ${this.getName(webDefault)}`
|
|
95
|
+
|
|
96
|
+
web.classes.push(this.getFont.webClasses(name, value))
|
|
97
|
+
web.style.push(this.getFont.webStyle(name, webValue))
|
|
98
|
+
native.classes.push(this.getFont.nativeClasses(name, value))
|
|
99
|
+
native.style.push(this.getFont.nativeStyle(name, value))
|
|
100
|
+
|
|
101
|
+
fonts.present.push(name)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { alphabets, fonts, web, native, names }
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const font = new Font()
|
package/sources/parse.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import { glob } from 'glob'
|
|
3
|
+
|
|
4
|
+
class Parse {
|
|
5
|
+
|
|
6
|
+
project = async () => {
|
|
7
|
+
|
|
8
|
+
const files = await glob(`${process.env.BASE_PATH}/**/*.js`, {
|
|
9
|
+
ignore: [`${process.env.BASE_PATH}/node_modules/**`, `${process.env.BASE_PATH}/@*/**` ]})
|
|
10
|
+
|
|
11
|
+
const s_raw = []
|
|
12
|
+
const c_raw = []
|
|
13
|
+
const f_raw = []
|
|
14
|
+
|
|
15
|
+
for (let file of files ) {
|
|
16
|
+
|
|
17
|
+
const data = fs.readFileSync(file)
|
|
18
|
+
|
|
19
|
+
const isStyle = data.includes('useStyle()')
|
|
20
|
+
|
|
21
|
+
const s_regex = /\bs\.(\w+)/g
|
|
22
|
+
const c_regex = /\bc\.(\w+)/g
|
|
23
|
+
const f_regex = /\bf\.(\w+)/g
|
|
24
|
+
|
|
25
|
+
const s_matches = []
|
|
26
|
+
const c_matches = []
|
|
27
|
+
const f_matches = []
|
|
28
|
+
|
|
29
|
+
let s_match
|
|
30
|
+
let c_match
|
|
31
|
+
let f_match
|
|
32
|
+
|
|
33
|
+
while ((s_match = s_regex.exec(data)) !== null) if(isStyle) s_matches.push(s_match[1])
|
|
34
|
+
while ((c_match = c_regex.exec(data)) !== null) if(isStyle) c_matches.push(c_match[1])
|
|
35
|
+
while ((f_match = f_regex.exec(data)) !== null) if(isStyle) f_matches.push(f_match[1])
|
|
36
|
+
|
|
37
|
+
const s_unique = [...new Set(s_matches)]
|
|
38
|
+
const c_unique = [...new Set(c_matches)]
|
|
39
|
+
const f_unique = [...new Set(f_matches)]
|
|
40
|
+
|
|
41
|
+
s_raw.push(...s_unique)
|
|
42
|
+
c_raw.push(...c_unique)
|
|
43
|
+
f_raw.push(...f_unique)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const s = [...new Set(s_raw)].sort()
|
|
47
|
+
const c = [...new Set(c_raw)].sort()
|
|
48
|
+
const f = [...new Set(f_raw)].sort()
|
|
49
|
+
|
|
50
|
+
return { s, c, f }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const parse = new Parse()
|
package/sources/style.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { styles } from '#@/sources/styles/index.js'
|
|
2
|
+
|
|
3
|
+
class Style {
|
|
4
|
+
|
|
5
|
+
getList = (list) => {
|
|
6
|
+
|
|
7
|
+
const result = []
|
|
8
|
+
|
|
9
|
+
const numericSuffix = /\d+$/
|
|
10
|
+
const twoLetterTwoNumber = /^([A-Za-z])(\d+)([A-Za-z])(\d+)$/
|
|
11
|
+
|
|
12
|
+
for (const item of list) {
|
|
13
|
+
|
|
14
|
+
// 1. If underscores exist, handle carefully
|
|
15
|
+
if (item.includes('_')) {
|
|
16
|
+
const [prefix, tail] = item.split('_')
|
|
17
|
+
|
|
18
|
+
// 1A. MULTI-NUMBER PATTERN (e.g. X16Y9)
|
|
19
|
+
const m = tail.match(twoLetterTwoNumber)
|
|
20
|
+
if (m) {
|
|
21
|
+
const A = m[1], nA = Number(m[2])
|
|
22
|
+
const B = m[3], nB = Number(m[4])
|
|
23
|
+
const finalKey = `${prefix}${A}${B}`
|
|
24
|
+
result.push({ name: item, key: finalKey, params: { [A]: nA, [B]: nB } })
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!/\d/.test(item)) {
|
|
29
|
+
result.push({ name: item, key: item })
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 2. NUMERIC-SUFFIX PATTERN (margin64 etc)
|
|
35
|
+
const nmatch = item.match(numericSuffix)
|
|
36
|
+
if (nmatch) {
|
|
37
|
+
const num = Number(nmatch[0])
|
|
38
|
+
const key = item.slice(0, -nmatch[0].length)
|
|
39
|
+
result.push({ name: item, key, number: num })
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 3. DEFAULT: no underscore, no numeric suffix
|
|
44
|
+
result.push({ name: item, key: item })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exists = (mainArray, subArray) => {
|
|
51
|
+
const result = []
|
|
52
|
+
for (const item of subArray) {
|
|
53
|
+
if (mainArray.includes(item)) result.push(item)
|
|
54
|
+
}
|
|
55
|
+
if (result.length) return true
|
|
56
|
+
else return false
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getPresent = (mainArray, subArray) => {
|
|
61
|
+
const result = []
|
|
62
|
+
for (const item of subArray) {
|
|
63
|
+
const found = mainArray.find(element => element.name === item)
|
|
64
|
+
if (found?.name) result.push(item)
|
|
65
|
+
}
|
|
66
|
+
return result
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// getContents = (list, { fonts }, isWeb, isNative) => {
|
|
70
|
+
|
|
71
|
+
// const present = []
|
|
72
|
+
// const missing = []
|
|
73
|
+
// const done = []
|
|
74
|
+
// const web = {
|
|
75
|
+
// classes: {
|
|
76
|
+
// fixed: [],
|
|
77
|
+
// directional: []
|
|
78
|
+
// },
|
|
79
|
+
// style: [],
|
|
80
|
+
// numbers: []
|
|
81
|
+
// }
|
|
82
|
+
// const native = {
|
|
83
|
+
// classes: {
|
|
84
|
+
// fixed: [],
|
|
85
|
+
// directional: []
|
|
86
|
+
// },
|
|
87
|
+
// style: [],
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
// for (const { name, key, number } of list) {
|
|
91
|
+
|
|
92
|
+
// const is0 = number === 0
|
|
93
|
+
|
|
94
|
+
// const noStyle = !styles?.[key]?.write(number)
|
|
95
|
+
// // const noFont = key==='font' && (number>(fonts.length-1))
|
|
96
|
+
|
|
97
|
+
// // if (noStyle || noFont) {
|
|
98
|
+
// if (noStyle) {
|
|
99
|
+
// missing.push(name)
|
|
100
|
+
// continue
|
|
101
|
+
// }
|
|
102
|
+
|
|
103
|
+
// const { target, write, webClasses, webStyle, nativeClasses, nativeStyle } = styles[key]
|
|
104
|
+
|
|
105
|
+
// const isDone = this.exists(done, write(number))
|
|
106
|
+
// if (isDone) continue
|
|
107
|
+
|
|
108
|
+
// if (isWeb) {
|
|
109
|
+
// web.classes[target].push(...webClasses(number))
|
|
110
|
+
// web.style.push(...webStyle(number, fonts))
|
|
111
|
+
// const numString = `$px${number} : ${is0 ? 0 : number / 16}rem;`
|
|
112
|
+
// if (is0 || (number && !web.numbers.includes(numString))) web.numbers.push(numString)
|
|
113
|
+
// if (key === 'fpSup' || key === 'fpSub') {
|
|
114
|
+
// const num1 = Math.floor(number * 0.25)
|
|
115
|
+
// const num1String = `$px${num1} : ${is0 ? 0 : num1 / 16}rem;`
|
|
116
|
+
// if (num1 && !web.numbers.includes(num1String)) web.numbers.push(num1String)
|
|
117
|
+
// const num2 = Math.floor(number * 0.75)
|
|
118
|
+
// const num2String = `$px${num2} : ${is0 ? 0 : num2 / 16}rem;`
|
|
119
|
+
// if (num2 && !web.numbers.includes(num2String)) web.numbers.push(num2String)
|
|
120
|
+
// }
|
|
121
|
+
// }
|
|
122
|
+
|
|
123
|
+
// if (isNative) {
|
|
124
|
+
// native.classes[target].push(...nativeClasses(number))
|
|
125
|
+
// native.style.push(...nativeStyle(number, fonts))
|
|
126
|
+
// }
|
|
127
|
+
|
|
128
|
+
// present.push(...this.getPresent(list, write(number)))
|
|
129
|
+
// done.push(...write(number))
|
|
130
|
+
// }
|
|
131
|
+
|
|
132
|
+
// const response = { missing, present, done }
|
|
133
|
+
// if (isWeb) response.web = web
|
|
134
|
+
// if (isNative) response.native = native
|
|
135
|
+
// return response
|
|
136
|
+
// }
|
|
137
|
+
|
|
138
|
+
getContents = (list, { fonts }, isWeb, isNative) => {
|
|
139
|
+
|
|
140
|
+
const present = []
|
|
141
|
+
const missing = []
|
|
142
|
+
const done = []
|
|
143
|
+
const web = {
|
|
144
|
+
classes: {
|
|
145
|
+
fixed: [],
|
|
146
|
+
directional: []
|
|
147
|
+
},
|
|
148
|
+
style: [],
|
|
149
|
+
numbers: []
|
|
150
|
+
}
|
|
151
|
+
const native = {
|
|
152
|
+
classes: {
|
|
153
|
+
fixed: [],
|
|
154
|
+
directional: []
|
|
155
|
+
},
|
|
156
|
+
style: [],
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for (const item of list) {
|
|
160
|
+
|
|
161
|
+
const { name, key, number, params } = item
|
|
162
|
+
const arg = params ?? number
|
|
163
|
+
const is0 = number === 0
|
|
164
|
+
|
|
165
|
+
const noStyle = !styles?.[key]?.write(arg)
|
|
166
|
+
if (noStyle) {
|
|
167
|
+
missing.push(name)
|
|
168
|
+
continue
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const { target, write, webClasses, webStyle, nativeClasses, nativeStyle } = styles[key]
|
|
172
|
+
|
|
173
|
+
const isDone = this.exists(done, write(arg))
|
|
174
|
+
if (isDone) continue
|
|
175
|
+
|
|
176
|
+
if (isWeb) {
|
|
177
|
+
web.classes[target].push(...webClasses(arg))
|
|
178
|
+
web.style.push(...webStyle(arg, fonts))
|
|
179
|
+
|
|
180
|
+
// only build $px... variables when we actually have a number
|
|
181
|
+
if (typeof number === 'number') {
|
|
182
|
+
const numString = `$px${number} : ${is0 ? 0 : number / 16}rem;`
|
|
183
|
+
if (is0 || (number && !web.numbers.includes(numString))) {
|
|
184
|
+
web.numbers.push(numString)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (key === 'fpSup' || key === 'fpSub') {
|
|
188
|
+
const num1 = Math.floor(number * 0.25)
|
|
189
|
+
const num1String = `$px${num1} : ${num1 ? num1 / 16 : 0}rem;`
|
|
190
|
+
if (num1 && !web.numbers.includes(num1String)) web.numbers.push(num1String)
|
|
191
|
+
|
|
192
|
+
const num2 = Math.floor(number * 0.75)
|
|
193
|
+
const num2String = `$px${num2} : ${num2 ? num2 / 16 : 0}rem;`
|
|
194
|
+
if (num2 && !web.numbers.includes(num2String)) web.numbers.push(num2String)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (isNative) {
|
|
200
|
+
native.classes[target].push(...nativeClasses(arg))
|
|
201
|
+
native.style.push(...nativeStyle(arg, fonts))
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
present.push(...this.getPresent(list, write(arg)))
|
|
205
|
+
done.push(...write(arg))
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const response = { missing, present, done }
|
|
209
|
+
if (isWeb) response.web = web
|
|
210
|
+
if (isNative) response.native = native
|
|
211
|
+
return response
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const style = new Style()
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const f_position = (position) => ({
|
|
2
|
+
target: `fixed`,
|
|
3
|
+
write: () => ([position]),
|
|
4
|
+
webClasses: () => ([`${position}: '${position}'`]),
|
|
5
|
+
webStyle: () => ([`.${position} { position:${position} }`]),
|
|
6
|
+
nativeClasses: () => ([`${position}: style['${position}']`]),
|
|
7
|
+
nativeStyle: () => ([`${position}: { position:'${position}' }`])
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const fixed = f_position('fixed')
|
|
11
|
+
export const absolute = f_position('absolute')
|
|
12
|
+
export const relative = f_position('relative')
|
|
13
|
+
|
|
14
|
+
const f_overflow = (name, type, axis) => ({
|
|
15
|
+
target: `fixed`,
|
|
16
|
+
write: () => ([name]),
|
|
17
|
+
webClasses: () => ([`${name}: '${name}'`]),
|
|
18
|
+
webStyle: () => ([`.${name} { overflow${axis?`-${axis}`:''}:${type} }`]),
|
|
19
|
+
nativeClasses: () => ([`${name}: style['${name}']`]),
|
|
20
|
+
nativeStyle: () => ([`${name}: { overflow${axis?axis.toUpperCase():''}:'${type}' }`])
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const overflowXh = f_overflow('overflowXh','hidden','x')
|
|
24
|
+
export const overflowYh = f_overflow('overflowYh','hidden','y')
|
|
25
|
+
|
|
26
|
+
export const overflowXs = f_overflow('overflowXs','scroll','x')
|
|
27
|
+
export const overflowYs = f_overflow('overflowYs','scroll','y')
|
|
28
|
+
|
|
29
|
+
export const overflowXYh = f_overflow('overflowXYh','hidden')
|
|
30
|
+
export const overflowXYs = f_overflow('overflowXYs','scroll')
|
|
31
|
+
|
|
32
|
+
export const flip = {
|
|
33
|
+
target: `fixed`,
|
|
34
|
+
write: (n='') => ([`flip`]),
|
|
35
|
+
webClasses: (n) => ([`flip: 'flip'`]),
|
|
36
|
+
webStyle: (n) => ([`.flip { transform: scaleX(-1) }`]),
|
|
37
|
+
nativeClasses: (n) => ([`flip: style['flip']`]),
|
|
38
|
+
nativeStyle: (n) => ([`flip: { transform: [{ scaleX: -1 }] }`])
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// new to be tested
|
|
43
|
+
|
|
44
|
+
export const pressOn = {
|
|
45
|
+
target: 'fixed',
|
|
46
|
+
write: () => ([`pressOn`]),
|
|
47
|
+
webClasses: () => ([`pressOn: 'pressOn'`]),
|
|
48
|
+
webStyle: () => ([`.pressOn { pointer-events: auto }`]),
|
|
49
|
+
nativeClasses: () => ([`pressOn: style['pressOn']`]),
|
|
50
|
+
nativeStyle: () => ([`pressOn: { pointerEvents: 'auto' }`]),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const pressOff = {
|
|
54
|
+
target: 'fixed',
|
|
55
|
+
write: () => ([`pressOff`]),
|
|
56
|
+
webClasses: () => ([`pressOff: 'pressOff'`]),
|
|
57
|
+
webStyle: () => ([`.pressOff { pointer-events: none }`]),
|
|
58
|
+
nativeClasses: () => ([`pressOff: style['pressOff']`]),
|
|
59
|
+
nativeStyle: () => ([`pressOff: { pointerEvents: 'none' }`]),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const ratio = {
|
|
63
|
+
target: 'fixed',
|
|
64
|
+
write: () => [ 'ratio' ],
|
|
65
|
+
webClasses: () => ([ `ratio: 'ratio'` ]),
|
|
66
|
+
webStyle: () => ([ `.ratio { aspect-ratio: 1 / 1 }` ]),
|
|
67
|
+
nativeClasses: () => ([ `ratio: style['ratio']` ]),
|
|
68
|
+
nativeStyle: () => ([ `ratio: { aspectRatio: 1 }` ]),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const ratioXY = {
|
|
72
|
+
target: 'fixed',
|
|
73
|
+
write: ({ X, Y }) => ([ `ratioXY_${X}_${Y}` ]),
|
|
74
|
+
webClasses: ({ X, Y }) => ([`ratioXY_${X}_${Y}: 'ratioXY_${X}_${Y}'`]),
|
|
75
|
+
webStyle: ({ X, Y }) => ([`.ratioXY_${X}_${Y} { aspect-ratio: ${X} / ${Y} }`]),
|
|
76
|
+
nativeClasses: ({ X, Y }) => ([`ratioXY_${X}_${Y}: style['ratioXY_${X}_${Y}']`]),
|
|
77
|
+
nativeStyle: ({ X, Y }) => ([`ratioXY_${X}_${Y}: { aspectRatio: ${X / Y} }`]),
|
|
78
|
+
}
|