@rokkit/core 1.0.0-next.120 → 1.0.0-next.122

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 (169) hide show
  1. package/dist/colors/index.d.ts +326 -252
  2. package/dist/constants.d.ts +12 -0
  3. package/dist/theme.d.ts +1141 -35
  4. package/package.json +1 -1
  5. package/src/colors/extra.json +16 -0
  6. package/src/colors/index.js +5 -2
  7. package/src/colors/tailwind.json +0 -14
  8. package/src/constants.js +50 -10
  9. package/src/theme.js +105 -151
  10. package/src/utils.js +19 -12
  11. package/dist/packages/actions/src/delegate.svelte.d.ts +0 -13
  12. package/dist/packages/actions/src/dismissable.svelte.d.ts +0 -7
  13. package/dist/packages/actions/src/fillable.svelte.d.ts +0 -8
  14. package/dist/packages/actions/src/index.d.ts +0 -11
  15. package/dist/packages/actions/src/kbd.d.ts +0 -44
  16. package/dist/packages/actions/src/keyboard.svelte.d.ts +0 -7
  17. package/dist/packages/actions/src/lib/event-manager.d.ts +0 -8
  18. package/dist/packages/actions/src/lib/index.d.ts +0 -2
  19. package/dist/packages/actions/src/lib/internal.d.ts +0 -19
  20. package/dist/packages/actions/src/navigable.svelte.d.ts +0 -8
  21. package/dist/packages/actions/src/navigator.svelte.d.ts +0 -20
  22. package/dist/packages/actions/src/pannable.svelte.d.ts +0 -6
  23. package/dist/packages/actions/src/skinnable.svelte.d.ts +0 -8
  24. package/dist/packages/actions/src/swipeable.svelte.d.ts +0 -14
  25. package/dist/packages/actions/src/themable.svelte.d.ts +0 -7
  26. package/dist/packages/actions/src/types.d.ts +0 -72
  27. package/dist/packages/actions/src/utils.d.ts +0 -18
  28. package/dist/packages/bits-ui/src/index.d.ts +0 -2
  29. package/dist/packages/bits-ui/src/reference.d.ts +0 -22
  30. package/dist/packages/bits-ui/src/tree/constants.d.ts +0 -13
  31. package/dist/packages/bits-ui/src/tree/index.d.ts +0 -7
  32. package/dist/packages/bits-ui/src/tree/types.d.ts +0 -71
  33. package/dist/packages/core/src/calendar.d.ts +0 -10
  34. package/dist/packages/core/src/colors/index.d.ts +0 -333
  35. package/dist/packages/core/src/connector.d.ts +0 -8
  36. package/dist/packages/core/src/constants.d.ts +0 -39
  37. package/dist/packages/core/src/events.d.ts +0 -12
  38. package/dist/packages/core/src/field-mapper.d.ts +0 -63
  39. package/dist/packages/core/src/index.d.ts +0 -13
  40. package/dist/packages/core/src/key-event-map.d.ts +0 -18
  41. package/dist/packages/core/src/mapped-items.d.ts +0 -14
  42. package/dist/packages/core/src/mapping.d.ts +0 -75
  43. package/dist/packages/core/src/nested.d.ts +0 -18
  44. package/dist/packages/core/src/string.d.ts +0 -59
  45. package/dist/packages/core/src/theme.d.ts +0 -52
  46. package/dist/packages/core/src/ticks.d.ts +0 -10
  47. package/dist/packages/core/src/types.d.ts +0 -245
  48. package/dist/packages/core/src/utils.d.ts +0 -70
  49. package/dist/packages/data/src/aggregators.d.ts +0 -2
  50. package/dist/packages/data/src/constants.d.ts +0 -46
  51. package/dist/packages/data/src/convert.d.ts +0 -10
  52. package/dist/packages/data/src/dataset.d.ts +0 -43
  53. package/dist/packages/data/src/filter.d.ts +0 -26
  54. package/dist/packages/data/src/formatter.d.ts +0 -10
  55. package/dist/packages/data/src/hierarchy.d.ts +0 -36
  56. package/dist/packages/data/src/index.d.ts +0 -7
  57. package/dist/packages/data/src/infer.d.ts +0 -80
  58. package/dist/packages/data/src/join.d.ts +0 -95
  59. package/dist/packages/data/src/list.d.ts +0 -121
  60. package/dist/packages/data/src/metadata.d.ts +0 -32
  61. package/dist/packages/data/src/model.d.ts +0 -29
  62. package/dist/packages/data/src/parser.d.ts +0 -31
  63. package/dist/packages/data/src/renamer.d.ts +0 -37
  64. package/dist/packages/data/src/rollup.d.ts +0 -51
  65. package/dist/packages/data/src/types.d.ts +0 -346
  66. package/dist/packages/data/src/utils.d.ts +0 -6
  67. package/dist/packages/data/src/view.d.ts +0 -35
  68. package/dist/packages/helpers/src/components/index.d.ts +0 -2
  69. package/dist/packages/helpers/src/index.d.ts +0 -1
  70. package/dist/packages/helpers/src/matchers/action.d.ts +0 -27
  71. package/dist/packages/helpers/src/matchers/array.d.ts +0 -10
  72. package/dist/packages/helpers/src/matchers/dataset.d.ts +0 -10
  73. package/dist/packages/helpers/src/matchers/event.d.ts +0 -10
  74. package/dist/packages/helpers/src/matchers/index.d.ts +0 -4
  75. package/dist/packages/helpers/src/matchers/internal.d.ts +0 -1
  76. package/dist/packages/helpers/src/mocks/animate.d.ts +0 -1
  77. package/dist/packages/helpers/src/mocks/element.d.ts +0 -60
  78. package/dist/packages/helpers/src/mocks/index.d.ts +0 -2
  79. package/dist/packages/helpers/src/mocks/match-media.d.ts +0 -30
  80. package/dist/packages/helpers/src/mocks/resize-observer.d.ts +0 -9
  81. package/dist/packages/helpers/src/simulators/index.d.ts +0 -1
  82. package/dist/packages/helpers/src/simulators/touch.d.ts +0 -40
  83. package/dist/packages/icons/src/convert.d.ts +0 -22
  84. package/dist/packages/icons/src/index.d.ts +0 -2
  85. package/dist/packages/input/src/index.d.ts +0 -18
  86. package/dist/packages/states/src/constants.d.ts +0 -27
  87. package/dist/packages/states/src/derive.svelte.d.ts +0 -22
  88. package/dist/packages/states/src/hierarchy.d.ts +0 -34
  89. package/dist/packages/states/src/index.d.ts +0 -5
  90. package/dist/packages/states/src/list-controller.svelte.d.ts +0 -70
  91. package/dist/packages/states/src/nested-controller.svelte.d.ts +0 -32
  92. package/dist/packages/states/src/proxy.svelte.d.ts +0 -43
  93. package/dist/packages/states/src/tabular.svelte.d.ts +0 -5
  94. package/dist/packages/states/src/traversal.svelte.d.ts +0 -69
  95. package/dist/packages/states/src/vibe.svelte.d.ts +0 -622
  96. package/dist/packages/themes/src/constants.d.ts +0 -6
  97. package/dist/packages/themes/src/index.d.ts +0 -2
  98. package/dist/packages/tutorial/src/assimilate.d.ts +0 -25
  99. package/dist/packages/tutorial/src/collector.d.ts +0 -46
  100. package/dist/packages/tutorial/src/files.d.ts +0 -8
  101. package/dist/packages/tutorial/src/index.d.ts +0 -2
  102. package/dist/packages/tutorial/src/metadata/base.d.ts +0 -19
  103. package/dist/packages/tutorial/src/metadata/factory.d.ts +0 -19
  104. package/dist/packages/tutorial/src/metadata/index.d.ts +0 -2
  105. package/dist/packages/tutorial/src/metadata/javascript.d.ts +0 -7
  106. package/dist/packages/tutorial/src/metadata/json.d.ts +0 -7
  107. package/dist/packages/tutorial/src/metadata/markdown.d.ts +0 -7
  108. package/dist/packages/tutorial/src/metadata/registry.d.ts +0 -26
  109. package/dist/packages/tutorial/src/metamodel.d.ts +0 -45
  110. package/dist/packages/tutorial/src/tutorial.d.ts +0 -21
  111. package/dist/packages/tutorial/src/types.d.ts +0 -172
  112. package/dist/packages/tutorial/src/utils.d.ts +0 -13
  113. package/dist/packages/ui/src/constants.d.ts +0 -2
  114. package/dist/packages/ui/src/index.d.ts +0 -42
  115. package/dist/packages/ui/src/input/types.d.ts +0 -9
  116. package/dist/packages/ui/src/lib/fields.d.ts +0 -16
  117. package/dist/packages/ui/src/lib/form.d.ts +0 -95
  118. package/dist/packages/ui/src/lib/index.d.ts +0 -6
  119. package/dist/packages/ui/src/lib/layout.d.ts +0 -7
  120. package/dist/packages/ui/src/lib/nested.d.ts +0 -48
  121. package/dist/packages/ui/src/lib/schema.d.ts +0 -7
  122. package/dist/packages/ui/src/lib/select.d.ts +0 -8
  123. package/dist/packages/ui/src/lib/tree.d.ts +0 -9
  124. package/dist/packages/ui/src/types.d.ts +0 -5
  125. package/dist/packages/ui/src/wrappers/index.d.ts +0 -3
  126. package/dist/sites/learn/src/hooks.d.ts +0 -1
  127. package/dist/sites/learn/src/hooks.server.d.ts +0 -2
  128. package/dist/sites/learn/src/lib/index.d.ts +0 -7
  129. package/dist/sites/learn/src/lib/media.d.ts +0 -13
  130. package/dist/sites/learn/src/lib/paraglide/messages/en.d.ts +0 -3
  131. package/dist/sites/learn/src/lib/paraglide/messages/fr.d.ts +0 -3
  132. package/dist/sites/learn/src/lib/paraglide/messages/hi.d.ts +0 -3
  133. package/dist/sites/learn/src/lib/paraglide/messages.d.ts +0 -5
  134. package/dist/sites/learn/src/lib/paraglide/runtime.d.ts +0 -52
  135. package/dist/sites/learn/src/lib/stories/02-elements/01-list/03-mapping/src/data.d.ts +0 -5
  136. package/dist/sites/learn/src/lib/stories/02-elements/01-list/04-mixed/src/data.d.ts +0 -13
  137. package/dist/sites/learn/src/lib/stories/02-elements/02-tabs/04-fields/src/data.d.ts +0 -5
  138. package/dist/sites/learn/src/lib/stories/02-elements/02-tabs/05-using/src/data.d.ts +0 -6
  139. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/01-intro/src/data.d.ts +0 -4
  140. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/02-fields/src/data.d.ts +0 -9
  141. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/03-using/src/data.d.ts +0 -19
  142. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/04-mixed/src/data.d.ts +0 -30
  143. package/dist/sites/learn/src/lib/stories/02-elements/03-accordion/props.d.ts +0 -15
  144. package/dist/sites/learn/src/lib/stories/02-elements/04-tree/01-intro/src/data.d.ts +0 -12
  145. package/dist/sites/learn/src/lib/stories/02-elements/06-select/02-fields/src/data.d.ts +0 -5
  146. package/dist/sites/learn/src/lib/stories/02-elements/07-multi-select/02-fields/src/data.d.ts +0 -5
  147. package/dist/sites/learn/src/lib/stories/02-elements/08-drop-down/02-fields/src/data.d.ts +0 -5
  148. package/dist/sites/learn/src/lib/stories/05-templates/01-form/02-schema/src/schema.d.ts +0 -22
  149. package/dist/sites/learn/src/lib/stories/05-templates/01-form/03-layout/src/layout.d.ts +0 -19
  150. package/dist/sites/learn/src/lib/stories/05-templates/01-form/03-layout/src/schema.d.ts +0 -36
  151. package/dist/sites/learn/src/lib/stories/05-templates/01-form/05-validation/src/schema.d.ts +0 -34
  152. package/dist/sites/learn/src/lib/stories/05-templates/02-editor/01-introduction/src/data.d.ts +0 -39
  153. package/dist/sites/learn/src/lib/stories/05-templates/02-editor/01-introduction/src/schema.d.ts +0 -187
  154. package/dist/sites/learn/src/lib/stories/06-layout/03-stepper/01-intro/src/data.d.ts +0 -37
  155. package/dist/sites/learn/src/lib/stories/06-layout/03-stepper/02-play/src/data.d.ts +0 -37
  156. package/dist/sites/learn/src/lib/stories/index.d.ts +0 -1
  157. package/dist/sites/learn/src/lib/theme.svelte.d.ts +0 -70
  158. package/dist/sites/learn/src/routes/(learn)/+layout.d.ts +0 -12
  159. package/dist/sites/learn/src/routes/(learn)/[segment]/[...slug]/+page.d.ts +0 -8
  160. package/dist/sites/learn/src/routes/+layout.d.ts +0 -18
  161. package/dist/sites/quick-start/src/hooks.d.ts +0 -1
  162. package/dist/sites/quick-start/src/hooks.server.d.ts +0 -2
  163. package/dist/sites/quick-start/src/lib/index.d.ts +0 -1
  164. package/dist/sites/quick-start/src/lib/paraglide/messages/en.d.ts +0 -3
  165. package/dist/sites/quick-start/src/lib/paraglide/messages/fr.d.ts +0 -3
  166. package/dist/sites/quick-start/src/lib/paraglide/messages/hi.d.ts +0 -3
  167. package/dist/sites/quick-start/src/lib/paraglide/messages.d.ts +0 -5
  168. package/dist/sites/quick-start/src/lib/paraglide/runtime.d.ts +0 -52
  169. package/dist/sites/quick-start/src/routes/+layout.d.ts +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/core",
3
- "version": "1.0.0-next.120",
3
+ "version": "1.0.0-next.122",
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",
@@ -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,5 +1,7 @@
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 = [
@@ -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
  }
@@ -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 = {
@@ -102,6 +112,38 @@ export const defaultThemeMapping = {
102
112
  info: 'cyan'
103
113
  }
104
114
 
115
+ export const TONE_MAP = {
116
+ z1: 50,
117
+ z2: 100,
118
+ z3: 200,
119
+ z4: 300,
120
+ z5: 500,
121
+ z6: 600,
122
+ z7: 700,
123
+ z8: 800,
124
+ z9: 900,
125
+ z10: 950
126
+ // base: 50,
127
+ // inset: 100,
128
+ // subtle: 200,
129
+ // muted: 300,
130
+ // raised: 400,
131
+ // elevated: 600,
132
+ // floating: 700,
133
+ // contrast: 800,
134
+ // overlay: 900
135
+ }
136
+ /**
137
+ * Splits an icon name into its group and key components.
138
+ * @param {string} name - The icon name to split.
139
+ * @returns {{ group: string, key: string, value: string }} An object containing the group, key, and value of the icon name.
140
+ */
141
+ function splitIconName(name) {
142
+ const parts = name.split('-')
143
+ const group = parts.slice(0, parts.length - 1).join('-')
144
+ return { group, key: parts[parts.length - 1], value: name }
145
+ }
146
+
105
147
  /**
106
148
  * Generate a state icon mapping from a list of icon names
107
149
  *
@@ -109,15 +151,13 @@ export const defaultThemeMapping = {
109
151
  * @returns {import('./types').StateIcons}
110
152
  */
111
153
  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
- )
154
+ return icons.map(splitIconName).reduce(
155
+ (acc, { group, key, value }) => ({
156
+ ...acc,
157
+ [group]: { ...acc[group], [key]: value }
158
+ }),
159
+ {}
160
+ )
121
161
  }
122
162
 
123
163
  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,80 +38,123 @@ 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: 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,
174
- '--plot-background': 'var(--neutral-200)'
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}$`)
82
+ shortcuts.push([
83
+ variantPattern,
84
+ ([, variant]) =>
85
+ `${variant}:${prefix}-${name}-${lightValue} ${variant}:dark:${prefix}-${name}-${darkValue}`
86
+ ])
87
+
88
+ // Exact static shortcut (e.g., bg-primary-base)
89
+ const exactPattern = `${prefix}-${name}-${toneName}`
90
+ shortcuts.push([
91
+ exactPattern,
92
+ `${prefix}-${name}-${lightValue} dark:${prefix}-${name}-${darkValue}`
93
+ ])
175
94
  }
176
- ]
95
+ }
96
+
97
+ return shortcuts
177
98
  }
178
99
 
179
100
  /**
180
- * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
181
- *
182
- * @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
183
- * @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
184
- * @param {Object} [colors=defaultColors] - The object containing default color definitions.
185
- * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
101
+ * Theme class for managing color palettes, mappings, and semantic shortcuts.
186
102
  */
187
- export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
188
- mapping = { ...defaultThemeMapping, ...mapping }
189
- const variants = Object.keys(mapping)
103
+ export class Theme {
104
+ #colors
105
+ #mapping
190
106
 
191
- const rules = variants.reduce(
192
- (acc, variant) => [
193
- ...acc,
194
- ...generateColorRules(variant, { ...defaultColors, ...colors }, mapping)
195
- ],
196
- []
197
- )
107
+ constructor({ colors = defaultColors, mapping = defaultThemeMapping } = {}) {
108
+ this.#colors = { ...defaultColors, ...colors }
109
+ this.#mapping = { ...defaultThemeMapping, ...mapping }
110
+ }
198
111
 
199
- const lightRules = filterRulesByMode(rules, 'light')
200
- const darkRules = filterRulesByMode(rules, 'dark')
112
+ get colors() {
113
+ return this.#colors
114
+ }
115
+ set colors(colors) {
116
+ this.#colors = { ...colors }
117
+ }
201
118
 
202
- const lightTheme = createThemeVariant(name, 'light', lightRules, syntaxColors['one-dark'].light)
203
- const darkTheme = createThemeVariant(name, 'dark', darkRules, syntaxColors['one-dark'].dark)
119
+ get mapping() {
120
+ return this.#mapping
121
+ }
122
+ set mapping(mapping) {
123
+ this.#mapping = { ...mapping }
124
+ }
204
125
 
205
- return [lightTheme, darkTheme]
126
+ mapVariant(color, variant) {
127
+ return Object.keys(color).reduce(
128
+ (acc, key) => ({
129
+ ...acc,
130
+ [key]: key === 'DEFAULT' ? `var(--color-${variant})` : `var(--color-${variant}-${key})`
131
+ }),
132
+ {}
133
+ )
134
+ }
135
+
136
+ getColorRules(mapping = null) {
137
+ const variants = Object.entries({ ...this.#mapping, ...mapping })
138
+ return variants.reduce(
139
+ (acc, [variant, key]) => ({
140
+ ...acc,
141
+ [variant]: this.mapVariant(this.#colors[key], variant)
142
+ }),
143
+ {}
144
+ )
145
+ }
146
+
147
+ getPalette(mapping = null) {
148
+ const useMapping = { ...this.#mapping, ...mapping }
149
+ const useColors = { ...defaultColors, ...this.#colors }
150
+ const variants = Object.keys(useMapping)
151
+ const rules = variants
152
+ .flatMap((variant) => generateColorRules(variant, useColors, useMapping))
153
+ .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
154
+ return rules
155
+ }
156
+
157
+ getShortcuts(name) {
158
+ return semanticShortcuts(name)
159
+ }
206
160
  }
package/src/utils.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { has, isNil } from 'ramda'
2
- import { URL } from 'url'
3
2
  import { DATA_IMAGE_REGEX } from './constants'
4
3
 
5
4
  let idCounter = 0
@@ -156,23 +155,31 @@ export function hex2rgb(hex) {
156
155
  * @returns {boolean} - Returns true if the string is an image URL
157
156
  */
158
157
  function isImageUrl(str) {
159
- // Check if the string is a URL
158
+ // Check if the string looks like a URL
160
159
  try {
161
- const url = new URL(str)
162
-
163
- // Check common image extensions
164
- const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.tiff']
165
- const path = url.pathname.toLowerCase()
166
-
167
- if (imageExtensions.some((ext) => path.endsWith(ext))) {
168
- return true
160
+ // Use browser-native URL constructor or fallback to regex
161
+ const url = typeof URL !== 'undefined' ? new URL(str) : null
162
+
163
+ if (url) {
164
+ // Check common image extensions
165
+ const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.tiff']
166
+ const path = url.pathname.toLowerCase()
167
+
168
+ if (imageExtensions.some((ext) => path.endsWith(ext))) {
169
+ return true
170
+ }
171
+ } else {
172
+ // Fallback regex-based URL validation for image extensions
173
+ const urlRegex = /^https?:\/\/.+\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff)(\?.*)?$/i
174
+ return urlRegex.test(str)
169
175
  }
170
176
 
171
177
  return false
172
178
  // eslint-disable-next-line no-unused-vars
173
179
  } catch (e) {
174
- // Not a valid URL
175
- return false
180
+ // Fallback regex-based validation
181
+ const urlRegex = /^https?:\/\/.+\.(jpg|jpeg|png|gif|bmp|webp|svg|tiff)(\?.*)?$/i
182
+ return urlRegex.test(str)
176
183
  }
177
184
  }
178
185
  /**
@@ -1,13 +0,0 @@
1
- /**
2
- * Svelte action function for forwarding keyboard events from a parent element to a child.
3
- * The child is selected using a CSS selector passed in the options object.
4
- * Optionally, you can specify which keyboard events you want to forward: "keydown", "keyup", and/or "keypress".
5
- * By default, all three events are forwarded.
6
- *
7
- * @param {HTMLElement} element - The parent element from which keyboard events will be forwarded.
8
- * @param {import('./types').PushDownOptions} options - The options object.
9
- * @returns {{destroy: Function}}
10
- */
11
- export function delegateKeyboardEvents(element: HTMLElement, { selector, events }: import("./types").PushDownOptions): {
12
- destroy: Function;
13
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * A svelte action function that captures clicks outside the element or escape keypress
3
- * emits a `dismiss` event. This is useful for closing a modal or dropdown.
4
- *
5
- * @param {HTMLElement} node
6
- */
7
- export function dismissable(node: HTMLElement): void;
@@ -1,8 +0,0 @@
1
- /**
2
- * Action for filling a <del>?</del> element in html block.
3
- *
4
- * @param {HTMLElement} node
5
- * @param {import('./types').FillOptions} options
6
- * @returns
7
- */
8
- export function fillable(node: HTMLElement, data: any): void;
@@ -1,11 +0,0 @@
1
- export * from "./types.js";
2
- export { keyboard } from "./keyboard.svelte.js";
3
- export { pannable } from "./pannable.svelte.js";
4
- export { swipeable } from "./swipeable.svelte.js";
5
- export { navigator } from "./navigator.svelte.js";
6
- export { themable } from "./themable.svelte.js";
7
- export { skinnable } from "./skinnable.svelte.js";
8
- export { dismissable } from "./dismissable.svelte.js";
9
- export { navigable } from "./navigable.svelte.js";
10
- export { fillable } from "./fillable.svelte.js";
11
- export { delegateKeyboardEvents } from "./delegate.svelte.js";
@@ -1,44 +0,0 @@
1
- /**
2
- * Gets keyboard action handlers based on orientation and direction
3
- * @param {Object} options - Configuration options
4
- * @param {Object} handlers - Event handler functions
5
- * @returns {Object} Object mapping key presses to handler functions
6
- */
7
- export function getKeyboardActions(options: Object, handlers: Object): Object;
8
- /**
9
- * Creates a keyboard action mapping based on navigation options
10
- *
11
- * @param {Object} options - Navigation options
12
- * @param {string} options.orientation - Whether navigation is horizontal or vertical
13
- * @param {string} options.dir - Text direction ('ltr' or 'rtl')
14
- * @param {boolean} options.nested - Whether navigation is nested
15
- * @returns {Object} Mapping of keys to actions
16
- */
17
- export function createKeyboardActionMap(options: {
18
- orientation: string;
19
- dir: string;
20
- nested: boolean;
21
- }): Object;
22
- /**
23
- * Creates a keyboard action mapping for modifier keys based on navigation options
24
- *
25
- * @param {Object} options - Navigation options
26
- * @param {string} options.orientation - Whether navigation is horizontal or vertical
27
- * @returns {Object} Mapping of keys to actions
28
- */
29
- export function createModifierKeyboardActionMap(options: {
30
- orientation: string;
31
- }): Object;
32
- /**
33
- * Gets the keyboard action for a key event
34
- * @param {KeyboardEvent} event - The keyboard event
35
- * @param {Object} options - Configuration options
36
- * @returns {string|null} The action to perform, or null if no action is defined
37
- */
38
- export function getKeyboardAction(event: KeyboardEvent, options?: Object): string | null;
39
- export namespace defaultNavigationOptions {
40
- let orientation: string;
41
- let dir: string;
42
- let nested: boolean;
43
- let enabled: boolean;
44
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Handle keyboard events
3
- *
4
- * @param {HTMLElement} root
5
- * @param {import('./types.js').KeyboardConfig} options - Custom key mappings
6
- */
7
- export function keyboard(root: HTMLElement, options?: import("./types.js").KeyboardConfig): void;
@@ -1,8 +0,0 @@
1
- /**
2
- * EventManager class to manage event listeners on an element.
3
- *
4
- * @param {HTMLElement} element - The element to listen for events on.
5
- * @param {Object} handlers - An object with event names as keys and event handlers as values.
6
- * @returns {Object} - An object with methods to activate, reset, and update the event listeners.
7
- */
8
- export function EventManager(element: HTMLElement, handlers?: Object, enabled?: boolean): Object;
@@ -1,2 +0,0 @@
1
- export * from "./internal";
2
- export { EventManager } from "./event-manager";
@@ -1,19 +0,0 @@
1
- /**
2
- * Sets up event handlers based on the given options.
3
- * Returns whether or not the event handlers are listening.
4
- *
5
- * @param {HTMLElement} element
6
- * @param {import('../types').EventHandlers} listeners
7
- * @param {import('../types').TraversableOptions} options
8
- * @returns {void}
9
- */
10
- export function setupListeners(element: HTMLElement, listeners: import("../types").EventHandlers, options: import("../types").TraversableOptions): void;
11
- /**
12
- * Removes event handlers based on the given options.
13
- * Returns whether or not the event handlers are listening.
14
- *
15
- * @param {HTMLElement} element
16
- * @param {import('../types').EventHandlers} listeners
17
- * @returns {void}
18
- */
19
- export function removeListeners(element: HTMLElement, listeners: import("../types").EventHandlers): void;
@@ -1,8 +0,0 @@
1
- /**
2
- * A svelte action function that captures keyboard evvents and emits event for corresponding movements.
3
- *
4
- * @param {HTMLElement} node
5
- * @param {import('./types').NavigableOptions} options
6
- * @returns {import('./types').SvelteActionReturn}
7
- */
8
- export function navigable(node: HTMLElement, options: import("./types").NavigableOptions): import("./types").SvelteActionReturn;