@rokkit/core 1.0.0-next.121 → 1.0.0-next.123

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.
Files changed (172) hide show
  1. package/dist/colors/index.d.ts +328 -254
  2. package/dist/constants.d.ts +14 -1
  3. package/dist/theme.d.ts +820 -35
  4. package/dist/types.d.ts +55 -0
  5. package/package.json +2 -2
  6. package/src/colors/extra.json +16 -0
  7. package/src/colors/index.js +6 -3
  8. package/src/colors/syntax.json +4 -4
  9. package/src/colors/tailwind.json +0 -14
  10. package/src/constants.js +52 -11
  11. package/src/theme.js +119 -150
  12. package/src/types.js +36 -0
  13. package/src/utils.js +20 -13
  14. package/dist/packages/actions/src/delegate.svelte.d.ts +0 -13
  15. package/dist/packages/actions/src/dismissable.svelte.d.ts +0 -7
  16. package/dist/packages/actions/src/fillable.svelte.d.ts +0 -8
  17. package/dist/packages/actions/src/index.d.ts +0 -11
  18. package/dist/packages/actions/src/kbd.d.ts +0 -44
  19. package/dist/packages/actions/src/keyboard.svelte.d.ts +0 -7
  20. package/dist/packages/actions/src/lib/event-manager.d.ts +0 -8
  21. package/dist/packages/actions/src/lib/index.d.ts +0 -2
  22. package/dist/packages/actions/src/lib/internal.d.ts +0 -19
  23. package/dist/packages/actions/src/navigable.svelte.d.ts +0 -8
  24. package/dist/packages/actions/src/navigator.svelte.d.ts +0 -20
  25. package/dist/packages/actions/src/pannable.svelte.d.ts +0 -6
  26. package/dist/packages/actions/src/skinnable.svelte.d.ts +0 -8
  27. package/dist/packages/actions/src/swipeable.svelte.d.ts +0 -14
  28. package/dist/packages/actions/src/themable.svelte.d.ts +0 -7
  29. package/dist/packages/actions/src/types.d.ts +0 -72
  30. package/dist/packages/actions/src/utils.d.ts +0 -18
  31. package/dist/packages/bits-ui/src/index.d.ts +0 -2
  32. package/dist/packages/bits-ui/src/reference.d.ts +0 -22
  33. package/dist/packages/bits-ui/src/tree/constants.d.ts +0 -13
  34. package/dist/packages/bits-ui/src/tree/index.d.ts +0 -7
  35. package/dist/packages/bits-ui/src/tree/types.d.ts +0 -71
  36. package/dist/packages/core/src/calendar.d.ts +0 -10
  37. package/dist/packages/core/src/colors/index.d.ts +0 -333
  38. package/dist/packages/core/src/connector.d.ts +0 -8
  39. package/dist/packages/core/src/constants.d.ts +0 -39
  40. package/dist/packages/core/src/events.d.ts +0 -12
  41. package/dist/packages/core/src/field-mapper.d.ts +0 -63
  42. package/dist/packages/core/src/index.d.ts +0 -13
  43. package/dist/packages/core/src/key-event-map.d.ts +0 -18
  44. package/dist/packages/core/src/mapped-items.d.ts +0 -14
  45. package/dist/packages/core/src/mapping.d.ts +0 -75
  46. package/dist/packages/core/src/nested.d.ts +0 -18
  47. package/dist/packages/core/src/string.d.ts +0 -59
  48. package/dist/packages/core/src/theme.d.ts +0 -52
  49. package/dist/packages/core/src/ticks.d.ts +0 -10
  50. package/dist/packages/core/src/types.d.ts +0 -245
  51. package/dist/packages/core/src/utils.d.ts +0 -70
  52. package/dist/packages/data/src/aggregators.d.ts +0 -2
  53. package/dist/packages/data/src/constants.d.ts +0 -46
  54. package/dist/packages/data/src/convert.d.ts +0 -10
  55. package/dist/packages/data/src/dataset.d.ts +0 -43
  56. package/dist/packages/data/src/filter.d.ts +0 -26
  57. package/dist/packages/data/src/formatter.d.ts +0 -10
  58. package/dist/packages/data/src/hierarchy.d.ts +0 -36
  59. package/dist/packages/data/src/index.d.ts +0 -7
  60. package/dist/packages/data/src/infer.d.ts +0 -80
  61. package/dist/packages/data/src/join.d.ts +0 -95
  62. package/dist/packages/data/src/list.d.ts +0 -121
  63. package/dist/packages/data/src/metadata.d.ts +0 -32
  64. package/dist/packages/data/src/model.d.ts +0 -29
  65. package/dist/packages/data/src/parser.d.ts +0 -31
  66. package/dist/packages/data/src/renamer.d.ts +0 -37
  67. package/dist/packages/data/src/rollup.d.ts +0 -51
  68. package/dist/packages/data/src/types.d.ts +0 -346
  69. package/dist/packages/data/src/utils.d.ts +0 -6
  70. package/dist/packages/data/src/view.d.ts +0 -35
  71. package/dist/packages/helpers/src/components/index.d.ts +0 -2
  72. package/dist/packages/helpers/src/index.d.ts +0 -1
  73. package/dist/packages/helpers/src/matchers/action.d.ts +0 -27
  74. package/dist/packages/helpers/src/matchers/array.d.ts +0 -10
  75. package/dist/packages/helpers/src/matchers/dataset.d.ts +0 -10
  76. package/dist/packages/helpers/src/matchers/event.d.ts +0 -10
  77. package/dist/packages/helpers/src/matchers/index.d.ts +0 -4
  78. package/dist/packages/helpers/src/matchers/internal.d.ts +0 -1
  79. package/dist/packages/helpers/src/mocks/animate.d.ts +0 -1
  80. package/dist/packages/helpers/src/mocks/element.d.ts +0 -60
  81. package/dist/packages/helpers/src/mocks/index.d.ts +0 -2
  82. package/dist/packages/helpers/src/mocks/match-media.d.ts +0 -30
  83. package/dist/packages/helpers/src/mocks/resize-observer.d.ts +0 -9
  84. package/dist/packages/helpers/src/simulators/index.d.ts +0 -1
  85. package/dist/packages/helpers/src/simulators/touch.d.ts +0 -40
  86. package/dist/packages/icons/src/convert.d.ts +0 -22
  87. package/dist/packages/icons/src/index.d.ts +0 -2
  88. package/dist/packages/input/src/index.d.ts +0 -18
  89. package/dist/packages/states/src/constants.d.ts +0 -27
  90. package/dist/packages/states/src/derive.svelte.d.ts +0 -22
  91. package/dist/packages/states/src/hierarchy.d.ts +0 -34
  92. package/dist/packages/states/src/index.d.ts +0 -5
  93. package/dist/packages/states/src/list-controller.svelte.d.ts +0 -70
  94. package/dist/packages/states/src/nested-controller.svelte.d.ts +0 -32
  95. package/dist/packages/states/src/proxy.svelte.d.ts +0 -43
  96. package/dist/packages/states/src/tabular.svelte.d.ts +0 -5
  97. package/dist/packages/states/src/traversal.svelte.d.ts +0 -69
  98. package/dist/packages/states/src/vibe.svelte.d.ts +0 -622
  99. package/dist/packages/themes/src/constants.d.ts +0 -6
  100. package/dist/packages/themes/src/index.d.ts +0 -2
  101. package/dist/packages/tutorial/src/assimilate.d.ts +0 -25
  102. package/dist/packages/tutorial/src/collector.d.ts +0 -46
  103. package/dist/packages/tutorial/src/files.d.ts +0 -8
  104. package/dist/packages/tutorial/src/index.d.ts +0 -2
  105. package/dist/packages/tutorial/src/metadata/base.d.ts +0 -19
  106. package/dist/packages/tutorial/src/metadata/factory.d.ts +0 -19
  107. package/dist/packages/tutorial/src/metadata/index.d.ts +0 -2
  108. package/dist/packages/tutorial/src/metadata/javascript.d.ts +0 -7
  109. package/dist/packages/tutorial/src/metadata/json.d.ts +0 -7
  110. package/dist/packages/tutorial/src/metadata/markdown.d.ts +0 -7
  111. package/dist/packages/tutorial/src/metadata/registry.d.ts +0 -26
  112. package/dist/packages/tutorial/src/metamodel.d.ts +0 -45
  113. package/dist/packages/tutorial/src/tutorial.d.ts +0 -21
  114. package/dist/packages/tutorial/src/types.d.ts +0 -172
  115. package/dist/packages/tutorial/src/utils.d.ts +0 -13
  116. package/dist/packages/ui/src/constants.d.ts +0 -2
  117. package/dist/packages/ui/src/index.d.ts +0 -42
  118. package/dist/packages/ui/src/input/types.d.ts +0 -9
  119. package/dist/packages/ui/src/lib/fields.d.ts +0 -16
  120. package/dist/packages/ui/src/lib/form.d.ts +0 -95
  121. package/dist/packages/ui/src/lib/index.d.ts +0 -6
  122. package/dist/packages/ui/src/lib/layout.d.ts +0 -7
  123. package/dist/packages/ui/src/lib/nested.d.ts +0 -48
  124. package/dist/packages/ui/src/lib/schema.d.ts +0 -7
  125. package/dist/packages/ui/src/lib/select.d.ts +0 -8
  126. package/dist/packages/ui/src/lib/tree.d.ts +0 -9
  127. package/dist/packages/ui/src/types.d.ts +0 -5
  128. package/dist/packages/ui/src/wrappers/index.d.ts +0 -3
  129. package/dist/sites/learn/src/hooks.d.ts +0 -1
  130. package/dist/sites/learn/src/hooks.server.d.ts +0 -2
  131. package/dist/sites/learn/src/lib/index.d.ts +0 -7
  132. package/dist/sites/learn/src/lib/media.d.ts +0 -13
  133. package/dist/sites/learn/src/lib/paraglide/messages/en.d.ts +0 -3
  134. package/dist/sites/learn/src/lib/paraglide/messages/fr.d.ts +0 -3
  135. package/dist/sites/learn/src/lib/paraglide/messages/hi.d.ts +0 -3
  136. package/dist/sites/learn/src/lib/paraglide/messages.d.ts +0 -5
  137. package/dist/sites/learn/src/lib/paraglide/runtime.d.ts +0 -52
  138. package/dist/sites/learn/src/lib/stories/02-elements/01-list/03-mapping/src/data.d.ts +0 -5
  139. package/dist/sites/learn/src/lib/stories/02-elements/01-list/04-mixed/src/data.d.ts +0 -13
  140. package/dist/sites/learn/src/lib/stories/02-elements/02-tabs/04-fields/src/data.d.ts +0 -5
  141. package/dist/sites/learn/src/lib/stories/02-elements/02-tabs/05-using/src/data.d.ts +0 -6
  142. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/01-intro/src/data.d.ts +0 -4
  143. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/02-fields/src/data.d.ts +0 -9
  144. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/03-using/src/data.d.ts +0 -19
  145. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/04-mixed/src/data.d.ts +0 -30
  146. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/props.d.ts +0 -15
  147. package/dist/sites/learn/src/lib/stories/02-elements/04-tree/01-intro/src/data.d.ts +0 -12
  148. package/dist/sites/learn/src/lib/stories/02-elements/06-select/02-fields/src/data.d.ts +0 -5
  149. package/dist/sites/learn/src/lib/stories/02-elements/07-multi-select/02-fields/src/data.d.ts +0 -5
  150. package/dist/sites/learn/src/lib/stories/02-elements/08-drop-down/02-fields/src/data.d.ts +0 -5
  151. package/dist/sites/learn/src/lib/stories/05-templates/01-form/02-schema/src/schema.d.ts +0 -22
  152. package/dist/sites/learn/src/lib/stories/05-templates/01-form/03-layout/src/layout.d.ts +0 -19
  153. package/dist/sites/learn/src/lib/stories/05-templates/01-form/03-layout/src/schema.d.ts +0 -36
  154. package/dist/sites/learn/src/lib/stories/05-templates/01-form/05-validation/src/schema.d.ts +0 -34
  155. package/dist/sites/learn/src/lib/stories/05-templates/02-editor/01-introduction/src/data.d.ts +0 -39
  156. package/dist/sites/learn/src/lib/stories/05-templates/02-editor/01-introduction/src/schema.d.ts +0 -187
  157. package/dist/sites/learn/src/lib/stories/06-layout/03-stepper/01-intro/src/data.d.ts +0 -37
  158. package/dist/sites/learn/src/lib/stories/06-layout/03-stepper/02-play/src/data.d.ts +0 -37
  159. package/dist/sites/learn/src/lib/stories/index.d.ts +0 -1
  160. package/dist/sites/learn/src/lib/theme.svelte.d.ts +0 -70
  161. package/dist/sites/learn/src/routes/(learn)/+layout.d.ts +0 -12
  162. package/dist/sites/learn/src/routes/(learn)/[segment]/[...slug]/+page.d.ts +0 -8
  163. package/dist/sites/learn/src/routes/+layout.d.ts +0 -18
  164. package/dist/sites/quick-start/src/hooks.d.ts +0 -1
  165. package/dist/sites/quick-start/src/hooks.server.d.ts +0 -2
  166. package/dist/sites/quick-start/src/lib/index.d.ts +0 -1
  167. package/dist/sites/quick-start/src/lib/paraglide/messages/en.d.ts +0 -3
  168. package/dist/sites/quick-start/src/lib/paraglide/messages/fr.d.ts +0 -3
  169. package/dist/sites/quick-start/src/lib/paraglide/messages/hi.d.ts +0 -3
  170. package/dist/sites/quick-start/src/lib/paraglide/messages.d.ts +0 -5
  171. package/dist/sites/quick-start/src/lib/paraglide/runtime.d.ts +0 -52
  172. package/dist/sites/quick-start/src/routes/+layout.d.ts +0 -9
package/dist/types.d.ts CHANGED
@@ -243,3 +243,58 @@ export type CalendarDay = {
243
243
  */
244
244
  weekend: boolean;
245
245
  };
246
+ export type ColorPalette = {
247
+ /**
248
+ * 50 - The color for the 50 shade.
249
+ */
250
+ "": string;
251
+ };
252
+ export type ColorCollection = {
253
+ [x: string]: ColorPalette;
254
+ };
255
+ export type ColorMapping = {
256
+ /**
257
+ * - The primary color.
258
+ */
259
+ primary?: string | undefined;
260
+ /**
261
+ * - The secondary color.
262
+ */
263
+ secondary?: string | undefined;
264
+ /**
265
+ * - The tertiary color.
266
+ */
267
+ tertiary?: string | undefined;
268
+ /**
269
+ * - The surface color.
270
+ */
271
+ surface?: string | undefined;
272
+ /**
273
+ * - The info color.
274
+ */
275
+ info?: string | undefined;
276
+ /**
277
+ * - The success color.
278
+ */
279
+ success?: string | undefined;
280
+ /**
281
+ * - The warning color.
282
+ */
283
+ warning?: string | undefined;
284
+ /**
285
+ * - The error color.
286
+ */
287
+ error?: string | undefined;
288
+ };
289
+ export type ColorTheme = {
290
+ /**
291
+ * - The color mapping.
292
+ */
293
+ mapping?: ColorMapping | undefined;
294
+ /**
295
+ * - The color collection.
296
+ */
297
+ colors?: {
298
+ [x: string]: ColorPalette;
299
+ } | undefined;
300
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/core",
3
- "version": "1.0.0-next.121",
3
+ "version": "1.0.0-next.123",
4
4
  "description": "Contains core utility functions and classes that can be used in various components.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -31,6 +31,6 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "date-fns": "^4.1.0",
34
- "ramda": "^0.30.1"
34
+ "ramda": "^0.31.3"
35
35
  }
36
36
  }
@@ -0,0 +1,16 @@
1
+ {
2
+ "shark": {
3
+ "DEFAULT": "#828C9F",
4
+ "50": "#ffffff",
5
+ "100": "#efefef",
6
+ "200": "#E0E0E0",
7
+ "300": "#C1C6D0",
8
+ "400": "#828C9F",
9
+ "500": "#677287",
10
+ "600": "#51596A",
11
+ "700": "#3B414D",
12
+ "800": "#2E323C",
13
+ "900": "#20242A",
14
+ "950": "#1A1C22"
15
+ }
16
+ }
@@ -1,9 +1,11 @@
1
- import defaultTailwindColors from './tailwind.json' with { type: 'json' }
1
+ import { colors } from '@unocss/preset-mini/colors'
2
+ // import defaultTailwindColors from './tailwind.json' with { type: 'json' }
2
3
  import syntaxColorPalette from './syntax.json' with { type: 'json' }
4
+ import extraColors from './extra.json' with { type: 'json' }
3
5
 
4
6
  export const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
5
7
  export const defaultPalette = [
6
- 'neutral',
8
+ 'surface',
7
9
  'primary',
8
10
  'secondary',
9
11
  'accent',
@@ -15,5 +17,6 @@ export const defaultPalette = [
15
17
 
16
18
  export const syntaxColors = syntaxColorPalette
17
19
  export const defaultColors = {
18
- ...defaultTailwindColors
20
+ ...colors,
21
+ ...extraColors
19
22
  }
@@ -2,7 +2,7 @@
2
2
  "one-dark": {
3
3
  "dark": {
4
4
  "--tab-size": "2",
5
- "--code-fill": "var(--neutral-100)",
5
+ "--code-fill": "var(--surface-100)",
6
6
  "--code-normal": "#e06c75",
7
7
  "--code-string": "#98c379",
8
8
  "--code-number": "#d19a66",
@@ -14,14 +14,14 @@
14
14
  "--code-operator": "#56b6c2",
15
15
  "--code-function": "#61afef",
16
16
  "--code-gutter-marker": "black",
17
- "--code-gutter-subtle": "#999",
17
+ "--code-gutter-z2": "#999",
18
18
  "--code-cursor": "#24292e",
19
19
  "--code-cursor-block": "rgba(20, 255, 20, 0.5)",
20
20
  "--code-linenumbers": "rgba(27, 31, 35, 0.3)"
21
21
  },
22
22
  "light": {
23
23
  "--tab-size": "2",
24
- "--code-fill": "var(--neutral-100)",
24
+ "--code-fill": "var(--surface-100)",
25
25
  "--code-normal": "#333333",
26
26
  "--code-string": "#9D8248",
27
27
  "--code-number": "#71A15D",
@@ -33,7 +33,7 @@
33
33
  "--code-operator": "#bf5625",
34
34
  "--code-function": "#a71d5d",
35
35
  "--code-gutter-marker": "black",
36
- "--code-gutter-subtle": "#999",
36
+ "--code-gutter-z2": "#999",
37
37
  "--code-cursor": "#24292e",
38
38
  "--code-cursor-block": "rgba(20, 255, 20, 0.5)",
39
39
  "--code-linenumbers": "rgba(27, 31, 35, 0.3)"
@@ -271,19 +271,5 @@
271
271
  "800": "#27272a",
272
272
  "900": "#18181b",
273
273
  "950": "#000000"
274
- },
275
- "shark": {
276
- "DEFAULT": "#677287",
277
- "50": "#ffffff",
278
- "100": "#efefef",
279
- "200": "#E0E0E0",
280
- "300": "#C1C6D0",
281
- "400": "#828C9F",
282
- "500": "#677287",
283
- "600": "#51596A",
284
- "700": "#3B414D",
285
- "800": "#2E323C",
286
- "900": "#20242A",
287
- "950": "#1A1C22"
288
274
  }
289
275
  }
package/src/constants.js CHANGED
@@ -38,6 +38,8 @@ export const defaultIcons = [
38
38
  'action-clear',
39
39
  'action-search',
40
40
  'action-close',
41
+ 'action-copy',
42
+ 'action-copysuccess',
41
43
  'node-opened',
42
44
  'node-closed',
43
45
  'selector-opened',
@@ -71,7 +73,15 @@ export const defaultIcons = [
71
73
  'validity-failed',
72
74
  'validity-passed',
73
75
  'validity-unknown',
74
- 'validity-warning'
76
+ 'validity-warning',
77
+ 'alert-clear',
78
+ 'alert-unread',
79
+ 'align-horizontal-left',
80
+ 'align-horizontal-right',
81
+ 'align-horizontal-center',
82
+ 'align-vertical-top',
83
+ 'align-vertical-bottom',
84
+ 'align-vertical-middle'
75
85
  ]
76
86
 
77
87
  export const defaultOptions = {
@@ -91,7 +101,7 @@ export const defaultKeyMap = {
91
101
  }
92
102
 
93
103
  export const defaultThemeMapping = {
94
- neutral: 'slate',
104
+ surface: 'slate',
95
105
  primary: 'orange',
96
106
  secondary: 'pink',
97
107
  accent: 'sky',
@@ -102,6 +112,39 @@ export const defaultThemeMapping = {
102
112
  info: 'cyan'
103
113
  }
104
114
 
115
+ export const TONE_MAP = {
116
+ z0: 50,
117
+ z1: 100,
118
+ z2: 200,
119
+ z3: 300,
120
+ z4: 400,
121
+ z5: 500,
122
+ z6: 600,
123
+ z7: 700,
124
+ z8: 800,
125
+ z9: 900,
126
+ z10: 950
127
+ // base: 50,
128
+ // inset: 100,
129
+ // subtle: 200,
130
+ // muted: 300,
131
+ // raised: 400,
132
+ // elevated: 600,
133
+ // floating: 700,
134
+ // contrast: 800,
135
+ // overlay: 900
136
+ }
137
+ /**
138
+ * Splits an icon name into its group and key components.
139
+ * @param {string} name - The icon name to split.
140
+ * @returns {{ group: string, key: string, value: string }} An object containing the group, key, and value of the icon name.
141
+ */
142
+ function splitIconName(name) {
143
+ const parts = name.split('-')
144
+ const group = parts.slice(0, parts.length - 1).join('-')
145
+ return { group, key: parts[parts.length - 1], value: name }
146
+ }
147
+
105
148
  /**
106
149
  * Generate a state icon mapping from a list of icon names
107
150
  *
@@ -109,15 +152,13 @@ export const defaultThemeMapping = {
109
152
  * @returns {import('./types').StateIcons}
110
153
  */
111
154
  export function stateIconsFromNames(icons) {
112
- return icons
113
- .map((k) => [...k.split('-')])
114
- .reduce(
115
- (acc, parts) => ({
116
- ...acc,
117
- [parts[0]]: { ...acc[parts[0]], [parts[1]]: parts.join('-') }
118
- }),
119
- {}
120
- )
155
+ return icons.map(splitIconName).reduce(
156
+ (acc, { group, key, value }) => ({
157
+ ...acc,
158
+ [group]: { ...acc[group], [key]: value }
159
+ }),
160
+ {}
161
+ )
121
162
  }
122
163
 
123
164
  export const defaultStateIcons = stateIconsFromNames(defaultIcons)
package/src/theme.js CHANGED
@@ -1,11 +1,11 @@
1
- import { defaultThemeMapping, defaultColors, syntaxColors } from './constants.js'
2
- import { shades, defaultPalette } from './colors/index.js'
1
+ import { defaultThemeMapping, defaultColors, TONE_MAP } from './constants.js'
2
+ import { shades } from './colors/index.js'
3
3
  import { hex2rgb } from './utils'
4
4
 
5
5
  const modifiers = {
6
6
  hsl: (value) => `hsl(${value} / <alpha-value>)`,
7
- rgb: (value) => `rgb(${value} / <alpha-value>)`
8
- // rgb: (value) => value
7
+ rgb: (value) => `rgb(${value} / <alpha-value>)`,
8
+ none: (value) => value
9
9
  }
10
10
 
11
11
  /**
@@ -15,109 +15,20 @@ const modifiers = {
15
15
  * @param {string} modifier
16
16
  * @returns
17
17
  */
18
- export function shadesOf(name, modifier = 'rgb') {
19
- const fn = modifier in modifiers ? modifiers[modifier] : modifiers.rgb
18
+ export function shadesOf(name, modifier = 'none') {
19
+ const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
20
20
 
21
21
  return shades.reduce(
22
22
  (result, shade) => ({
23
23
  ...result,
24
- [shade]: fn(`var(--${name}-${shade})`)
24
+ [shade]: fn(`var(--color-${name}-${shade})`)
25
25
  }),
26
26
  {
27
- DEFAULT: fn(`var(--${name}-500)`),
28
- base: fn(`var(--${name}-50)`),
29
- inset: fn(`var(--${name}-100)`),
30
- subtle: fn(`var(--${name}-200)`),
31
- muted: fn(`var(--${name}-300)`),
32
- raised: fn(`var(--${name}-400)`),
33
- elevated: fn(`var(--${name}-600)`),
34
- floating: fn(`var(--${name}-700)`),
35
- contrast: fn(`var(--${name}-800)`),
36
- overlay: fn(`var(--${name}-900)`)
27
+ DEFAULT: fn(`var(--color-${name}-500)`)
37
28
  }
38
29
  )
39
30
  }
40
31
 
41
- /**
42
- * Generate shades for a color using css varuable
43
- *
44
- * @param {string} name
45
- * @param {string} modifier
46
- * @returns {object}
47
- */
48
- export function stateColors(name, modifier = 'rgb') {
49
- const fn = modifier in modifiers ? modifiers[modifier] : modifiers.rgb
50
- return {
51
- DEFAULT: fn(`var(--${name}-500)`),
52
- light: fn(`var(--${name}-200)`),
53
- dark: fn(`var(--${name}-700)`)
54
- }
55
- }
56
-
57
- /**
58
- *
59
- * @param {string} modifier
60
- * @returns
61
- */
62
- export function themeColors(modifier = 'rgb') {
63
- const fn = modifier in modifiers ? modifiers[modifier] : modifiers.rgb
64
-
65
- const states = ['info', 'danger', 'warning', 'success', 'error']
66
- const variants = ['neutral', 'primary', 'secondary', 'accent']
67
- let colors = states.reduce(
68
- (acc, state) => ({ ...acc, [state]: stateColors(state, modifier) }),
69
- {}
70
- )
71
- colors = variants.reduce(
72
- (acc, variant) => ({ ...acc, [variant]: shadesOf(variant, modifier) }),
73
- colors
74
- )
75
- colors.neutral = {
76
- ...colors.neutral,
77
- // contrast: fn(`var(--neutral-800)`),
78
- zebra: fn('var(--neutral-zebra)')
79
- }
80
-
81
- return colors
82
- }
83
-
84
- /**
85
- * Creates an array of shade mapping objects for a given theme variant and mode.
86
- * Each object represents a CSS custom property (variable) with its value set based on a provided condition.
87
- *
88
- * @param {string} variant - The name of the theme variant (e.g., 'primary', 'secondary').
89
- * @param {'light' | 'dark'} mode - The theme mode for which the mappings are being created.
90
- * @param {function(number): string} valueCondition - A function that takes a shade value and returns the color value
91
- * based on the condition appropriate for light or dark mode.
92
- * @returns {{import('./types'}.ShadeMapping[]>} An array of objects, where each object contains key, value, and mode
93
- * properties corresponding to a CSS custom property definition.
94
- */
95
- function createShadeMappings(variant, mode, valueCondition) {
96
- return shades.map((shade) => ({
97
- key: `--on-${variant}-${shade}`,
98
- value: valueCondition(shade),
99
- mode
100
- }))
101
- }
102
-
103
- /**
104
- * Generates contrast colors for light and dark modes based on a given palette. Each color variant in the
105
- * palette is mapped to either a light or dark contrast color depending on the shade's value.
106
- *
107
- * @param {string} [light='#ffffff'] - The default light color used when the shade is >= 500 in light mode or <= 500 in dark mode.
108
- * @param {string} [dark='#000000'] - The default dark color used when the shade is < 500 in light mode or > 500 in dark mode.
109
- * @param {Array<string>} [palette=defaultPalette] - An array of color variant names to generate contrast colors for.
110
- * @returns {Array<Object>} An array containing contrast color rules organized by light and dark modes for each variant in the palette.
111
- */
112
- export function contrastColors(light = '#ffffff', dark = '#000000', palette = defaultPalette) {
113
- const colors = palette
114
- .flatMap((variant) => [
115
- createShadeMappings(variant, 'light', (shade) => (shade < 500 ? dark : light)),
116
- createShadeMappings(variant, 'dark', (shade) => (shade > 500 ? dark : light))
117
- ])
118
- .reduce((acc, item) => [...acc, ...item], [])
119
- return colors
120
- }
121
32
  /**
122
33
  * Generates color rules for a specific theme variant, for both light and dark modes.
123
34
  *
@@ -127,79 +38,137 @@ export function contrastColors(light = '#ffffff', dark = '#000000', palette = de
127
38
  * @returns {import('./types').ShadeMappings} An array containing the color rules for both light and dark modes.
128
39
  */
129
40
  function generateColorRules(variant, colors, mapping) {
130
- return shades.flatMap((shade, index) => [
131
- {
132
- key: `--${variant}-${shade}`,
133
- value: hex2rgb(colors[mapping[variant]][shade]),
134
- mode: 'light'
135
- },
41
+ return ['DEFAULT', ...shades].flatMap((shade) => [
136
42
  {
137
- key: `--${variant}-${shade}`,
138
- value: hex2rgb(colors[mapping[variant]][shades[shades.length - index - 1]]),
139
- mode: 'dark'
43
+ key: shade === 'DEFAULT' ? `--color-${variant}` : `--color-${variant}-${shade}`,
44
+ value: hex2rgb(colors[mapping[variant]][`${shade}`])
140
45
  }
141
46
  ])
142
47
  }
143
48
 
144
49
  /**
145
- * Filters the rules for a specific mode and transforms them into an object mapping
146
- * CSS variable names to their values.
50
+ * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
147
51
  *
148
- * @param {Array<Object>} rules - The array of rules to filter and transform.
149
- * @param {'light' | 'dark'} mode - The mode to filter by.
150
- * @returns {Object} An object containing the rules specific to the provided mode.
52
+ * @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
53
+ * @param {Object} [colors=defaultColors] - The object containing default color definitions.
54
+ * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
151
55
  */
152
- function filterRulesByMode(rules, mode) {
153
- return rules
154
- .filter((rule) => rule.mode === mode)
56
+ export function themeRules(mapping = defaultThemeMapping, colors = defaultColors) {
57
+ mapping = { ...defaultThemeMapping, ...mapping }
58
+ colors = { ...defaultColors, ...colors }
59
+ const variants = Object.keys(mapping)
60
+ const rules = variants
61
+ .flatMap((variant) => generateColorRules(variant, colors, mapping))
155
62
  .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
63
+
64
+ return rules
156
65
  }
157
66
 
158
67
  /**
159
- * Creates a theme variant object with a given mode, a collection of color rules, and additional colors.
160
- *
161
- * @param {string} name - The base name for the theme variant.
162
- * @param {'light' | 'dark'} mode - The mode of the theme variant.
163
- * @param {Object} colors - The object containing color rules for the theme.
164
- * @param {Object} extraColors - Any additional color properties for the theme.
165
- * @returns {Array} An array where the first element is the theme's name and the second element
166
- * is an object containing all color rules and extra properties for the theme variant.
68
+ * Generates UnoCSS shortcut definitions for semantic tones with bg, border, text.
69
+ * @param {string} name - Color name (e.g., 'primary')
70
+ * @returns {Array} Array of shortcut definitions
167
71
  */
168
- function createThemeVariant(name, mode, colors, extraColors) {
169
- return [
170
- `${name}-mode-${mode}`,
171
- {
172
- ...colors,
173
- ...extraColors
72
+ export function semanticShortcuts(name) {
73
+ const prefixes = ['bg', 'border', 'text', 'ring', 'outline', 'from', 'to', 'divide']
74
+ const shortcuts = []
75
+
76
+ for (const [toneName, lightValue] of Object.entries(TONE_MAP)) {
77
+ const darkValue = 1000 - lightValue
78
+
79
+ for (const prefix of prefixes) {
80
+ // Variant-prefixed regex (e.g., hover:bg-primary-base)
81
+ const variantPattern = new RegExp(`^(.+):${prefix}-${name}-${toneName}(\/\\d+)?$`)
82
+ shortcuts.push([
83
+ variantPattern,
84
+ ([, variant, end]) =>
85
+ `${variant}:${prefix}-${name}-${lightValue}${end || ''} ${variant}:dark:${prefix}-${name}-${darkValue}${end || ''}`
86
+ ])
87
+
88
+ const opacityPattern = new RegExp(`${prefix}-${name}-${toneName}(\/\\d+)?$`)
89
+ shortcuts.push([
90
+ opacityPattern,
91
+ ([, end]) =>
92
+ `${prefix}-${name}-${lightValue}${end || ''} dark:${prefix}-${name}-${darkValue}${end || ''}`
93
+ ])
94
+
95
+ // Exact static shortcut (e.g., bg-primary-base)
96
+ const exactPattern = `${prefix}-${name}-${toneName}`
97
+ shortcuts.push([
98
+ exactPattern,
99
+ `${prefix}-${name}-${lightValue} dark:${prefix}-${name}-${darkValue}`
100
+ ])
174
101
  }
175
- ]
102
+ }
103
+
104
+ return shortcuts
176
105
  }
177
106
 
178
107
  /**
179
- * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
180
- *
181
- * @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
182
- * @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
183
- * @param {Object} [colors=defaultColors] - The object containing default color definitions.
184
- * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
108
+ * Theme class for managing color palettes, mappings, and semantic shortcuts.
185
109
  */
186
- export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
187
- mapping = { ...defaultThemeMapping, ...mapping }
188
- const variants = Object.keys(mapping)
110
+ export class Theme {
111
+ #colors
112
+ #mapping
113
+
114
+ /**
115
+ *
116
+ * @param {import('./types.js').ColorTheme} param0
117
+ */
118
+ constructor({ colors = defaultColors, mapping = defaultThemeMapping } = {}) {
119
+ this.#colors = { ...defaultColors, ...colors }
120
+ this.#mapping = { ...defaultThemeMapping, ...mapping }
121
+ }
189
122
 
190
- const rules = variants.reduce(
191
- (acc, variant) => [
192
- ...acc,
193
- ...generateColorRules(variant, { ...defaultColors, ...colors }, mapping)
194
- ],
195
- []
196
- )
123
+ get colors() {
124
+ return this.#colors
125
+ }
126
+ set colors(colors) {
127
+ this.#colors = { ...colors }
128
+ }
197
129
 
198
- const lightRules = filterRulesByMode(rules, 'light')
199
- const darkRules = filterRulesByMode(rules, 'dark')
130
+ get mapping() {
131
+ return this.#mapping
132
+ }
133
+ set mapping(mapping) {
134
+ this.#mapping = { ...mapping }
135
+ }
136
+
137
+ mapVariant(color, variant) {
138
+ return Object.keys(color).reduce(
139
+ (acc, key) => ({
140
+ ...acc,
141
+ [key]:
142
+ key === 'DEFAULT'
143
+ ? `rgba(var(--color-${variant}),<alpha-value>)`
144
+ : `rgba(var(--color-${variant}-${key}),<alpha-value>)`
145
+ }),
146
+ {}
147
+ )
148
+ }
200
149
 
201
- const lightTheme = createThemeVariant(name, 'light', lightRules, syntaxColors['one-dark'].light)
202
- const darkTheme = createThemeVariant(name, 'dark', darkRules, syntaxColors['one-dark'].dark)
150
+ getColorRules(mapping = null) {
151
+ const variants = Object.entries({ ...this.#mapping, ...mapping })
152
+ return variants.reduce(
153
+ (acc, [variant, key]) => ({
154
+ ...acc,
155
+ [variant]: this.mapVariant(this.#colors[key], variant)
156
+ }),
157
+ {}
158
+ )
159
+ }
203
160
 
204
- return [lightTheme, darkTheme]
161
+ getPalette(mapping = null) {
162
+ const useMapping = { ...this.#mapping, ...mapping }
163
+ const useColors = { ...defaultColors, ...this.#colors }
164
+ const variants = Object.keys(useMapping)
165
+ const rules = variants
166
+ .flatMap((variant) => generateColorRules(variant, useColors, useMapping))
167
+ .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
168
+ return rules
169
+ }
170
+
171
+ getShortcuts(name) {
172
+ return semanticShortcuts(name)
173
+ }
205
174
  }
package/src/types.js CHANGED
@@ -121,4 +121,40 @@
121
121
  * @property {boolean} weekend - Indicates if the day is on the weekend.
122
122
  */
123
123
 
124
+ /**
125
+ * @typedef {Object} ColorPalette
126
+ * @property {string} 50 - The color for the 50 shade.
127
+ * @property {string} 100 - The color for the 100 shade.
128
+ * @property {string} 200 - The color for the 200 shade.
129
+ * @property {string} 300 - The color for the 300 shade.
130
+ * @property {string} 400 - The color for the 400 shade.
131
+ * @property {string} 500 - The color for the 500 shade.
132
+ * @property {string} 600 - The color for the 600 shade.
133
+ * @property {string} 700 - The color for the 700 shade.
134
+ * @property {string} 800 - The color for the 800 shade.
135
+ * @property {string} 900 - The color for the 900 shade.
136
+ * @property {string} 950 - The color for the 950 shade.
137
+ */
138
+
139
+ /**
140
+ * @typedef {Object<string,ColorPalette>} ColorCollection
141
+ */
142
+
143
+ /**
144
+ * @typedef {Object} ColorMapping
145
+ * @property {string} [primary] - The primary color.
146
+ * @property {string} [secondary] - The secondary color.
147
+ * @property {string} [tertiary] - The tertiary color.
148
+ * @property {string} [surface] - The surface color.
149
+ * @property {string} [info] - The info color.
150
+ * @property {string} [success] - The success color.
151
+ * @property {string} [warning] - The warning color.
152
+ * @property {string} [error] - The error color.
153
+ */
154
+
155
+ /**
156
+ * @typedef {Object} ColorTheme
157
+ * @property {ColorMapping} [mapping] - The color mapping.
158
+ * @property {ColorCollection} [colors] - The color collection.
159
+ */
124
160
  export default {}