@rokkit/core 1.0.0-next.84 → 1.0.0-next.86

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/core",
3
- "version": "1.0.0-next.84",
3
+ "version": "1.0.0-next.86",
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.84",
26
- "validators": "1.0.0-next.84"
25
+ "shared-config": "1.0.0-next.86",
26
+ "validators": "1.0.0-next.86"
27
27
  },
28
28
  "files": [
29
29
  "src/**/*.js",
@@ -1,5 +1,15 @@
1
1
  import { defaultTailwindColors } from './tailwind'
2
-
2
+ export const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
3
+ export const defaultPalette = [
4
+ 'neutral',
5
+ 'primary',
6
+ 'secondary',
7
+ 'accent',
8
+ 'success',
9
+ 'warning',
10
+ 'danger',
11
+ 'info'
12
+ ]
3
13
  export * from './syntax'
4
14
 
5
15
  export const defaultColors = {
package/src/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export { defaultColors, syntaxColors } from './colors'
1
+ export { defaultColors, syntaxColors, shades, defaultPalette } from './colors'
2
2
 
3
3
  /**
4
4
  * @type {import('./types).FieldMapping} Fields
@@ -83,9 +83,9 @@ export const defaultThemeMapping = {
83
83
  accent: 'sky',
84
84
  success: 'green',
85
85
  warning: 'yellow',
86
+ danger: 'red',
86
87
  error: 'red',
87
- info: 'cyan',
88
- pass: 'green'
88
+ info: 'cyan'
89
89
  }
90
90
 
91
91
  export function stateIconsFromNames(icons) {
package/src/index.js CHANGED
@@ -7,5 +7,6 @@ export * from './connector'
7
7
  export * from './ticks'
8
8
  export * from './calendar'
9
9
  export * from './utils'
10
+ export * from './theme'
10
11
  export * from './parser'
11
12
  export * from './string'
package/src/theme.js ADDED
@@ -0,0 +1,129 @@
1
+ import { defaultThemeMapping, defaultColors, syntaxColors } from './constants'
2
+ import { shades, defaultPalette } from './colors'
3
+
4
+ const modifiers = {
5
+ hsl: (value) => `hsl(${value})`,
6
+ rgb: (value) => `rgb(${value})`,
7
+ none: (value) => value
8
+ }
9
+
10
+ /**
11
+ * Generate shades for a color using css varuable
12
+ *
13
+ * @param {string} name
14
+ * @returns
15
+ */
16
+ export function shadesOf(name, modifier = 'none') {
17
+ const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
18
+
19
+ return shades.reduce(
20
+ (result, shade) => ({
21
+ ...result,
22
+ [shade]: fn(`var(--${name}-${shade})`)
23
+ }),
24
+ {
25
+ DEFAULT: fn(`var(--${name}-500)`),
26
+ sunken: fn(`var(--${name}-50)`),
27
+ inset: fn(`var(--${name}-100)`),
28
+ base: fn(`var(--${name}-200)`),
29
+ subtle: fn(`var(--${name}-300)`),
30
+ muted: fn(`var(--${name}-400)`),
31
+ raised: fn(`var(--${name}-500)`),
32
+ elevated: fn(`var(--${name}-600)`),
33
+ floating: fn(`var(--${name}-700)`),
34
+ contrast: fn(`var(--${name}-800)`)
35
+ }
36
+ )
37
+ }
38
+
39
+ export function stateColors(name, modifier = 'none') {
40
+ const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
41
+ return {
42
+ DEFAULT: fn(`var(--${name}-500)`),
43
+ light: fn(`var(--${name}-200)`),
44
+ dark: fn(`var(--${name}-700)`)
45
+ }
46
+ }
47
+
48
+ export function themeColors(modifier = 'none') {
49
+ const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
50
+
51
+ let states = ['info', 'danger', 'warning', 'success', 'error']
52
+ let variants = ['neutral', 'primary', 'secondary', 'accent']
53
+ let colors = states.reduce(
54
+ (acc, state) => ({ ...acc, [state]: stateColors(state, modifier) }),
55
+ {}
56
+ )
57
+ colors = variants.reduce(
58
+ (acc, variant) => ({ ...acc, [variant]: shadesOf(variant, modifier) }),
59
+ colors
60
+ )
61
+ colors.neutral = {
62
+ ...colors.neutral,
63
+ contrast: fn(`var(--neutral-800)`),
64
+ zebra: fn(`var(--neutral-zebra)`)
65
+ }
66
+
67
+ return colors
68
+ }
69
+
70
+ export function contrastColors(light = '#ffffff', dark = '#000000', palette = defaultPalette) {
71
+ const colors = palette
72
+ .flatMap((variant) => [
73
+ shades.map((shade) => ({
74
+ key: `--on-${variant}-${shade}`,
75
+ value: shade < 500 ? dark : light,
76
+ mode: 'light'
77
+ })),
78
+ shades.map((shade) => ({
79
+ key: `--on-${variant}-${shade}`,
80
+ value: shade > 500 ? dark : light,
81
+ mode: 'dark'
82
+ }))
83
+ ])
84
+ .reduce((acc, item) => [...acc, ...item], [])
85
+ return colors
86
+ }
87
+
88
+ export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
89
+ mapping = { ...defaultThemeMapping, ...mapping }
90
+ const variants = Object.keys(mapping)
91
+ const rules = variants
92
+ .flatMap((variant) => [
93
+ shades.map((shade) => ({
94
+ key: `--${variant}-${shade}`,
95
+ value: colors[mapping[variant]][shade],
96
+ mode: 'light'
97
+ })),
98
+ shades.map((shade, i) => ({
99
+ key: `--${variant}-${shade}`,
100
+ value: colors[mapping[variant]][shades[shades.length - i - 1]],
101
+ mode: 'dark'
102
+ }))
103
+ ])
104
+ .reduce((acc, item) => [...acc, ...item], [])
105
+
106
+ const light = rules
107
+ .filter((rule) => rule.mode === 'light')
108
+ .reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
109
+ const dark = rules
110
+ .filter((rule) => rule.mode === 'dark')
111
+ .reduce((acc, item) => ({ ...acc, [item.key]: item.value }), {})
112
+
113
+ return [
114
+ [
115
+ `${name}-mode-light`,
116
+ {
117
+ ...light,
118
+ ...syntaxColors['one-dark'].light
119
+ }
120
+ ],
121
+ [
122
+ `${name}-mode-dark`,
123
+ {
124
+ ...dark,
125
+ ...syntaxColors['one-dark'].dark
126
+ }
127
+ ]
128
+ ]
129
+ }
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
- }