@rokkit/core 1.0.0-next.83 → 1.0.0-next.85
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/package.json +3 -3
- package/src/index.js +1 -0
- package/src/nested.js +1 -0
- package/src/theme.js +140 -0
- package/src/utils.js +0 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/core",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.85",
|
|
4
4
|
"description": "Core components, actions and stores for svelte apps.",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"typescript": "^5.3.3",
|
|
23
23
|
"vite": "^5.1.4",
|
|
24
24
|
"vitest": "~1.3.1",
|
|
25
|
-
"shared-config": "1.0.0-next.
|
|
26
|
-
"validators": "1.0.0-next.
|
|
25
|
+
"shared-config": "1.0.0-next.85",
|
|
26
|
+
"validators": "1.0.0-next.85"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"src/**/*.js",
|
package/src/index.js
CHANGED
package/src/nested.js
CHANGED
package/src/theme.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { defaultThemeMapping, defaultColors, syntaxColors } from './constants'
|
|
2
|
+
|
|
3
|
+
const modifiers = {
|
|
4
|
+
hsl: (value) => `hsl(${value})`,
|
|
5
|
+
rgb: (value) => `rgb(${value})`,
|
|
6
|
+
none: (value) => value
|
|
7
|
+
}
|
|
8
|
+
const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
|
|
9
|
+
const defaultPalette = [
|
|
10
|
+
'neutral',
|
|
11
|
+
'primary',
|
|
12
|
+
'secondary',
|
|
13
|
+
'accent',
|
|
14
|
+
'info',
|
|
15
|
+
'error',
|
|
16
|
+
'warn',
|
|
17
|
+
'pass'
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generate shades for a color using css varuable
|
|
22
|
+
*
|
|
23
|
+
* @param {string} name
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export function shadesOf(name, modifier = 'none') {
|
|
27
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
28
|
+
|
|
29
|
+
return shades.reduce(
|
|
30
|
+
(result, shade) => ({
|
|
31
|
+
...result,
|
|
32
|
+
[shade]: fn(`var(--${name}-${shade})`)
|
|
33
|
+
}),
|
|
34
|
+
{
|
|
35
|
+
DEFAULT: fn(`var(--${name}-500)`),
|
|
36
|
+
sunken: fn(`var(--${name}-50)`),
|
|
37
|
+
inset: fn(`var(--${name}-100)`),
|
|
38
|
+
base: fn(`var(--${name}-200)`),
|
|
39
|
+
subtle: fn(`var(--${name}-300)`),
|
|
40
|
+
muted: fn(`var(--${name}-400)`),
|
|
41
|
+
raised: fn(`var(--${name}-500)`),
|
|
42
|
+
elevated: fn(`var(--${name}-600)`),
|
|
43
|
+
floating: fn(`var(--${name}-700)`),
|
|
44
|
+
contrast: fn(`var(--${name}-800)`)
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function stateColors(name, modifier = 'none') {
|
|
50
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
51
|
+
return {
|
|
52
|
+
DEFAULT: fn(`var(--${name}-500)`),
|
|
53
|
+
light: fn(`var(--${name}-200)`),
|
|
54
|
+
dark: fn(`var(--${name}-700)`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function themeColors(modifier = 'none') {
|
|
59
|
+
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
60
|
+
|
|
61
|
+
let states = ['info', 'error', 'warn', 'pass']
|
|
62
|
+
let variants = ['neutral', 'primary', 'secondary', 'accent']
|
|
63
|
+
let colors = states.reduce(
|
|
64
|
+
(acc, state) => ({ ...acc, [state]: stateColors(state, modifier) }),
|
|
65
|
+
{}
|
|
66
|
+
)
|
|
67
|
+
colors = variants.reduce(
|
|
68
|
+
(acc, variant) => ({ ...acc, [variant]: shadesOf(variant, modifier) }),
|
|
69
|
+
colors
|
|
70
|
+
)
|
|
71
|
+
colors.neutral = {
|
|
72
|
+
...colors.neutral,
|
|
73
|
+
contrast: fn(`var(--neutral-800)`),
|
|
74
|
+
zebra: fn(`var(--neutral-zebra)`)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return colors
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function contrastColors(light = '#ffffff', dark = '#000000', palette = defaultPalette) {
|
|
81
|
+
const colors = palette
|
|
82
|
+
.flatMap((variant) => [
|
|
83
|
+
shades.map((shade) => ({
|
|
84
|
+
key: `--on-${variant}-${shade}`,
|
|
85
|
+
value: shade < 500 ? dark : light,
|
|
86
|
+
mode: 'light'
|
|
87
|
+
})),
|
|
88
|
+
shades.map((shade) => ({
|
|
89
|
+
key: `--on-${variant}-${shade}`,
|
|
90
|
+
value: shade > 500 ? dark : light,
|
|
91
|
+
mode: 'dark'
|
|
92
|
+
}))
|
|
93
|
+
])
|
|
94
|
+
.reduce((acc, item) => [...acc, ...item], [])
|
|
95
|
+
return colors
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
|
|
99
|
+
// const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
|
|
100
|
+
mapping = { ...defaultThemeMapping, ...mapping }
|
|
101
|
+
const variants = Object.keys(mapping)
|
|
102
|
+
const rules = variants
|
|
103
|
+
.flatMap((variant) => [
|
|
104
|
+
shades.map((shade) => ({
|
|
105
|
+
key: `--${variant}-${shade}`,
|
|
106
|
+
value: colors[mapping[variant]][shade],
|
|
107
|
+
mode: 'light'
|
|
108
|
+
})),
|
|
109
|
+
shades.map((shade, i) => ({
|
|
110
|
+
key: `--${variant}-${shade}`,
|
|
111
|
+
value: colors[mapping[variant]][shades[shades.length - i - 1]],
|
|
112
|
+
mode: 'dark'
|
|
113
|
+
}))
|
|
114
|
+
])
|
|
115
|
+
.reduce((acc, item) => [...acc, ...item], [])
|
|
116
|
+
|
|
117
|
+
const light = rules
|
|
118
|
+
.filter((rule) => rule.mode === 'light')
|
|
119
|
+
.reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
|
|
120
|
+
const dark = rules
|
|
121
|
+
.filter((rule) => rule.mode === 'dark')
|
|
122
|
+
.reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
|
|
123
|
+
|
|
124
|
+
return [
|
|
125
|
+
[
|
|
126
|
+
`${name}-mode-light`,
|
|
127
|
+
{
|
|
128
|
+
...light,
|
|
129
|
+
...syntaxColors['one-dark'].light
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
`${name}-mode-dark`,
|
|
134
|
+
{
|
|
135
|
+
...dark,
|
|
136
|
+
...syntaxColors['one-dark'].dark
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
]
|
|
140
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import { defaultThemeMapping, defaultColors, syntaxColors } from './constants'
|
|
2
|
-
|
|
3
|
-
const modifiers = {
|
|
4
|
-
hsl: (value) => `hsl(${value})`,
|
|
5
|
-
rgb: (value) => `rgb(${value})`,
|
|
6
|
-
none: (value) => value
|
|
7
|
-
}
|
|
8
|
-
|
|
9
1
|
/**
|
|
10
2
|
* Generates a random id
|
|
11
3
|
*
|
|
@@ -25,67 +17,6 @@ export function isObject(val) {
|
|
|
25
17
|
return typeof val === 'object' && val !== null && !(val instanceof Date)
|
|
26
18
|
}
|
|
27
19
|
|
|
28
|
-
/**
|
|
29
|
-
* Generate shades for a color using css varuable
|
|
30
|
-
*
|
|
31
|
-
* @param {string} name
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
|
-
export function shadesOf(name, modifier = 'none') {
|
|
35
|
-
const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
|
|
36
|
-
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
37
|
-
|
|
38
|
-
return shades.reduce(
|
|
39
|
-
(result, shade) => ({
|
|
40
|
-
...result,
|
|
41
|
-
[shade]: fn(`var(--${name}-${shade})`)
|
|
42
|
-
}),
|
|
43
|
-
{
|
|
44
|
-
DEFAULT: fn(`var(--${name}-500)`),
|
|
45
|
-
sunken: fn(`var(--${name}-50)`),
|
|
46
|
-
inset: fn(`var(--${name}-100)`),
|
|
47
|
-
base: fn(`var(--${name}-200)`),
|
|
48
|
-
subtle: fn(`var(--${name}-300)`),
|
|
49
|
-
muted: fn(`var(--${name}-400)`),
|
|
50
|
-
raised: fn(`var(--${name}-500)`),
|
|
51
|
-
elevated: fn(`var(--${name}-600)`),
|
|
52
|
-
floating: fn(`var(--${name}-700)`),
|
|
53
|
-
contrast: fn(`var(--${name}-800)`)
|
|
54
|
-
}
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function stateColors(name, modifier = 'none') {
|
|
59
|
-
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
60
|
-
return {
|
|
61
|
-
DEFAULT: fn(`var(--${name}-500)`),
|
|
62
|
-
light: fn(`var(--${name}-200)`),
|
|
63
|
-
dark: fn(`var(--${name}-700)`)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function themeColors(modifier = 'none') {
|
|
68
|
-
const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
|
|
69
|
-
|
|
70
|
-
let states = ['info', 'error', 'warn', 'pass']
|
|
71
|
-
let variants = ['neutral', 'primary', 'secondary', 'accent']
|
|
72
|
-
let colors = states.reduce(
|
|
73
|
-
(acc, state) => ({ ...acc, [state]: stateColors(state, modifier) }),
|
|
74
|
-
{}
|
|
75
|
-
)
|
|
76
|
-
colors = variants.reduce(
|
|
77
|
-
(acc, variant) => ({ ...acc, [variant]: shadesOf(variant, modifier) }),
|
|
78
|
-
colors
|
|
79
|
-
)
|
|
80
|
-
colors.neutral = {
|
|
81
|
-
...colors.neutral,
|
|
82
|
-
contrast: fn(`var(--neutral-800)`),
|
|
83
|
-
zebra: fn(`var(--neutral-zebra)`)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return colors
|
|
87
|
-
}
|
|
88
|
-
|
|
89
20
|
export function iconShortcuts(icons, collection, variants) {
|
|
90
21
|
const suffix = variants ? `-${variants}` : ''
|
|
91
22
|
const shortcuts = !collection
|
|
@@ -105,60 +36,3 @@ export function scaledPath(size, x) {
|
|
|
105
36
|
if (Array.isArray(x)) return x.map((x) => scaledPath(size, x)).join(' ')
|
|
106
37
|
return typeof x === 'number' ? x * size : x
|
|
107
38
|
}
|
|
108
|
-
export function contrastColors(light, dark, shades, mapping) {
|
|
109
|
-
Object.keys(mapping).flatMap((variant) => [
|
|
110
|
-
shades.map((shade) => ({
|
|
111
|
-
key: `--on-${variant}-${shade}`,
|
|
112
|
-
value: shade < 500 ? dark : light,
|
|
113
|
-
mode: 'light'
|
|
114
|
-
})),
|
|
115
|
-
shades.map((shade) => ({
|
|
116
|
-
key: `--on-${variant}-${shade}`,
|
|
117
|
-
value: shade > 500 ? dark : light,
|
|
118
|
-
mode: 'dark'
|
|
119
|
-
}))
|
|
120
|
-
])
|
|
121
|
-
}
|
|
122
|
-
export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
|
|
123
|
-
const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
|
|
124
|
-
mapping = { ...defaultThemeMapping, ...mapping }
|
|
125
|
-
const variants = Object.keys(mapping)
|
|
126
|
-
const rules = variants
|
|
127
|
-
.flatMap((variant) => [
|
|
128
|
-
shades.map((shade) => ({
|
|
129
|
-
key: `--${variant}-${shade}`,
|
|
130
|
-
value: colors[mapping[variant]][shade],
|
|
131
|
-
mode: 'light'
|
|
132
|
-
})),
|
|
133
|
-
shades.map((shade, i) => ({
|
|
134
|
-
key: `--${variant}-${shade}`,
|
|
135
|
-
value: colors[mapping[variant]][shades[shades.length - i - 1]],
|
|
136
|
-
mode: 'dark'
|
|
137
|
-
}))
|
|
138
|
-
])
|
|
139
|
-
.reduce((acc, item) => [...acc, ...item], [])
|
|
140
|
-
|
|
141
|
-
const light = rules
|
|
142
|
-
.filter((rule) => rule.mode === 'light')
|
|
143
|
-
.reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
|
|
144
|
-
const dark = rules
|
|
145
|
-
.filter((rule) => rule.mode === 'dark')
|
|
146
|
-
.reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
|
|
147
|
-
|
|
148
|
-
return [
|
|
149
|
-
[
|
|
150
|
-
`${name}-mode-light`,
|
|
151
|
-
{
|
|
152
|
-
...light,
|
|
153
|
-
...syntaxColors['one-dark'].light
|
|
154
|
-
}
|
|
155
|
-
],
|
|
156
|
-
[
|
|
157
|
-
`${name}-mode-dark`,
|
|
158
|
-
{
|
|
159
|
-
...dark,
|
|
160
|
-
...syntaxColors['one-dark'].dark
|
|
161
|
-
}
|
|
162
|
-
]
|
|
163
|
-
]
|
|
164
|
-
}
|