@rokkit/core 1.0.0-next.16 → 1.0.0-next.160

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 (75) hide show
  1. package/README.md +121 -1
  2. package/package.json +31 -39
  3. package/src/calendar.js +44 -0
  4. package/src/colors/extra.json +16 -0
  5. package/src/colors/index.ts +24 -0
  6. package/src/colors/syntax.json +42 -0
  7. package/src/colors/tailwind.json +275 -0
  8. package/src/connector.js +34 -0
  9. package/src/constants.js +165 -107
  10. package/src/events.js +32 -0
  11. package/src/field-mapper.js +147 -0
  12. package/src/index.js +19 -27
  13. package/src/key-event-map.js +35 -0
  14. package/src/mapped-items.js +22 -0
  15. package/src/mapping.js +21 -0
  16. package/src/nested.js +28 -0
  17. package/src/string.js +97 -0
  18. package/src/theme.ts +208 -0
  19. package/src/ticks.js +26 -0
  20. package/src/types.js +160 -0
  21. package/src/utils.js +272 -0
  22. package/src/vite/icon-collections.js +73 -0
  23. package/src/vite/index.js +1 -0
  24. package/LICENSE +0 -21
  25. package/src/Accordion.svelte +0 -80
  26. package/src/Alerts.svelte +0 -39
  27. package/src/DropDown.svelte +0 -82
  28. package/src/DropSearch.svelte +0 -67
  29. package/src/EditableTabs.svelte +0 -31
  30. package/src/Icon.svelte +0 -15
  31. package/src/List-Discard.svelte +0 -48
  32. package/src/List.svelte +0 -65
  33. package/src/ListActions.svelte +0 -35
  34. package/src/NavTabs.svelte +0 -0
  35. package/src/NestedList.svelte +0 -77
  36. package/src/Overlay.svelte +0 -4
  37. package/src/PageNavigator.svelte +0 -94
  38. package/src/ResponsiveGrid.svelte +0 -73
  39. package/src/Scrollable.svelte +0 -8
  40. package/src/Searchable.svelte +0 -19
  41. package/src/Sidebar.svelte +0 -5
  42. package/src/Slider.svelte +0 -17
  43. package/src/SpinList.svelte +0 -48
  44. package/src/SplitPane.svelte +0 -109
  45. package/src/SplitView.svelte +0 -44
  46. package/src/Splitter.svelte +0 -95
  47. package/src/TabItem.svelte +0 -27
  48. package/src/TabItems.svelte +0 -34
  49. package/src/Tabs.svelte +0 -49
  50. package/src/Tree.svelte +0 -45
  51. package/src/actions/dismissable.js +0 -24
  52. package/src/actions/fillable.js +0 -114
  53. package/src/actions/hierarchy.js +0 -180
  54. package/src/actions/index.js +0 -7
  55. package/src/actions/navigable.js +0 -43
  56. package/src/actions/navigator.js +0 -179
  57. package/src/actions/pannable.js +0 -50
  58. package/src/actions/swipeable.js +0 -56
  59. package/src/actions/themeable.js +0 -23
  60. package/src/items/Collapsible.svelte +0 -51
  61. package/src/items/Connector.svelte +0 -26
  62. package/src/items/Link.svelte +0 -18
  63. package/src/items/Node.svelte +0 -52
  64. package/src/items/Pill.svelte +0 -33
  65. package/src/items/Separator.svelte +0 -1
  66. package/src/items/Summary.svelte +0 -27
  67. package/src/items/Text.svelte +0 -21
  68. package/src/items/index.js +0 -8
  69. package/src/list.js +0 -14
  70. package/src/mocks/Custom.svelte +0 -7
  71. package/src/mocks/index.js +0 -10
  72. package/src/stores/alerts.js +0 -3
  73. package/src/stores/index.js +0 -6
  74. package/src/stores/persist.js +0 -63
  75. package/src/stores/theme.js +0 -34
package/src/string.js ADDED
@@ -0,0 +1,97 @@
1
+ import { filter } from 'ramda'
2
+ /**
3
+ * Capitalizes the first letter of input string
4
+ *
5
+ * @param {String} str
6
+ * @returns {String}
7
+ */
8
+ export function toInitCapCase(text) {
9
+ return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase()
10
+ }
11
+
12
+ /**
13
+ * Convert a hyphen separated string to PascalCase
14
+ *
15
+ * @param {String} text
16
+ * @returns
17
+ */
18
+ export function toPascalCase(text) {
19
+ return text
20
+ .split('-')
21
+ .map((part) => toInitCapCase(part))
22
+ .join('')
23
+ }
24
+
25
+ /**
26
+ * Convert a PascalCase string to snake case with separator as hyphen
27
+ *
28
+ * @param {string} text
29
+ * @returns {string}
30
+ */
31
+ export function toHyphenCase(text) {
32
+ return text
33
+ .replace(/\s+/, '-')
34
+ .replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
35
+ .replace(/^-/, '')
36
+ }
37
+
38
+ /**
39
+ * Simple comparison for two strings
40
+ *
41
+ * @param {String} a
42
+ * @param {String} b
43
+ * @returns
44
+ */
45
+ export function compareStrings(a, b) {
46
+ return a > b ? 1 : a < b ? -1 : 0
47
+ }
48
+
49
+ /**
50
+ * Sort by splitting hyphen separated strings while keeping strings with same number of parts together
51
+ *
52
+ * @param {String} a hyphen separates string
53
+ * @param {String} b hyphen separates string
54
+ * @param {string} separator - separator to split the string
55
+ * @returns {Number} -1, 0, 1 based on comparison
56
+ */
57
+ export function sortByParts(a, b, separator = '-') {
58
+ const partsOfA = a.split(separator)
59
+ const partsOfB = b.split(separator)
60
+
61
+ let result = compareStrings(partsOfA[0], partsOfB[0])
62
+ if (result === 0) result = partsOfA.length - partsOfB.length
63
+ if (result === 0) result = compareStrings(a, b)
64
+ return result
65
+ }
66
+
67
+ /**
68
+ * Generates a unique id from current timestamp
69
+ *
70
+ * @returns {String} timestamp based unique id
71
+ */
72
+ export function uniqueId(prefix = '', separator = '-') {
73
+ const pair = prefix && prefix.length > 0 ? [prefix] : []
74
+ pair.push(Date.now().toString(36))
75
+ return pair.join(separator)
76
+ }
77
+
78
+ /**
79
+ * Removes undefined and null values from the input object.
80
+ *
81
+ * @param {Object} obj
82
+ * @returns {Object}
83
+ */
84
+ export function compact(obj) {
85
+ return filter((x) => x !== undefined && x !== null, obj)
86
+ }
87
+
88
+ /**
89
+ * Converts an input number into it's hexadecimal representation, with optional left padded zeroes based on the `size`
90
+ *
91
+ * @param {number} value
92
+ * @param {number} size
93
+ * @returns
94
+ */
95
+ export function toHexString(value, size = 2) {
96
+ return value.toString(16).padStart(size, '0')
97
+ }
package/src/theme.ts ADDED
@@ -0,0 +1,208 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ import { DEFAULT_THEME_MAPPING, defaultColors, TONE_MAP } from './constants'
4
+ import { shades } from './colors/index'
5
+ import { colorToRgb } from './utils'
6
+
7
+ const modifiers = {
8
+ hsl: (value) => `hsl(${value} / <alpha-value>)`,
9
+ rgb: (value) => `rgb(${value} / <alpha-value>)`,
10
+ none: (value) => value
11
+ }
12
+
13
+ /**
14
+ * Generate shades for a color using css varuable
15
+ *
16
+ * @param {string} name
17
+ * @param {string} modifier
18
+ * @returns
19
+ */
20
+ export function shadesOf(name, modifier = 'none') {
21
+ const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
22
+
23
+ return shades.reduce(
24
+ (result, shade) => ({
25
+ ...result,
26
+ [shade]: fn(`var(--color-${name}-${shade})`)
27
+ }),
28
+ {
29
+ DEFAULT: fn(`var(--color-${name}-500)`)
30
+ }
31
+ )
32
+ }
33
+
34
+ /**
35
+ * Generates color rules for a specific theme variant, for both light and dark modes.
36
+ *
37
+ * @param {string} variant - The name of the variant to generate rules for.
38
+ * @param {Object} colors - The object containing color definitions.
39
+ * @param {Object} mapping - An object that maps variant names to color property names.
40
+ * @returns {import('./types').ShadeMappings} An array containing the color rules for both light and dark modes.
41
+ */
42
+ function generateColorRules(variant, colors, mapping) {
43
+ return ['DEFAULT', ...shades].flatMap((shade) => [
44
+ {
45
+ key: shade === 'DEFAULT' ? `--color-${variant}` : `--color-${variant}-${shade}`,
46
+ value: colorToRgb(colors[mapping[variant]][`${shade}`])
47
+ }
48
+ ])
49
+ }
50
+
51
+ /**
52
+ * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
53
+ *
54
+ * @param {Object} [mapping=DEFAULT_THEME_MAPPING] - An object mapping variant names to color property names.
55
+ * @param {Object} [colors=defaultColors] - The object containing default color definitions.
56
+ * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
57
+ */
58
+ export function themeRules(mapping = DEFAULT_THEME_MAPPING, colors = defaultColors) {
59
+ mapping = { ...DEFAULT_THEME_MAPPING, ...mapping }
60
+ colors = { ...defaultColors, ...colors }
61
+ const variants = Object.keys(mapping)
62
+ const rules = variants
63
+ .flatMap((variant) => generateColorRules(variant, colors, mapping))
64
+ .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
65
+
66
+ return rules
67
+ }
68
+
69
+ const SEMANTIC_PREFIXES = [
70
+ 'bg',
71
+ 'border',
72
+ 'border-l',
73
+ 'border-r',
74
+ 'border-t',
75
+ 'border-b',
76
+ 'text',
77
+ 'ring',
78
+ 'outline',
79
+ 'from',
80
+ 'to',
81
+ 'divide',
82
+ 'stroke',
83
+ 'fill'
84
+ ]
85
+
86
+ /**
87
+ * @param {{ prefix: string, name: string, toneName: string, lightValue: number, darkValue: number }} opts
88
+ * @returns {Array}
89
+ */
90
+ function toneShortcuts({ prefix, name, toneName, lightValue, darkValue }) {
91
+ const variantPattern = new RegExp(`^(.+):${prefix}-${name}-${toneName}(\\/\\d+)?$`)
92
+ const opacityPattern = new RegExp(`^${prefix}-${name}-${toneName}(\\/\\d+)?$`)
93
+ const exactPattern = `${prefix}-${name}-${toneName}`
94
+ return [
95
+ [
96
+ variantPattern,
97
+ ([, variant, end]) =>
98
+ `${variant}:${prefix}-${name}-${lightValue}${end || ''} ${variant}:dark:${prefix}-${name}-${darkValue}${end || ''}`
99
+ ],
100
+ [
101
+ opacityPattern,
102
+ ([, end]) =>
103
+ `${prefix}-${name}-${lightValue}${end || ''} dark:${prefix}-${name}-${darkValue}${end || ''}`
104
+ ],
105
+ [exactPattern, `${prefix}-${name}-${lightValue} dark:${prefix}-${name}-${darkValue}`]
106
+ ]
107
+ }
108
+
109
+ /**
110
+ * Generates UnoCSS shortcut definitions for semantic tones with bg, border, text.
111
+ * @param {string} name - Color name (e.g., 'primary')
112
+ * @returns {Array} Array of shortcut definitions
113
+ */
114
+ export function semanticShortcuts(name) {
115
+ const shortcuts = []
116
+ for (const [toneName, lightValue] of Object.entries(TONE_MAP)) {
117
+ const darkValue = 1000 - lightValue
118
+ for (const prefix of SEMANTIC_PREFIXES) {
119
+ shortcuts.push(...toneShortcuts({ prefix, name, toneName, lightValue, darkValue }))
120
+ }
121
+ }
122
+ return shortcuts
123
+ }
124
+
125
+ /**
126
+ * Generates "on-color" text shortcuts for readable text on colored backgrounds.
127
+ *
128
+ * - `text-on-{name}` → high contrast text for use on z5+ backgrounds (always light text)
129
+ * - `text-on-{name}-muted` → slightly muted but still readable on z5+ backgrounds
130
+ *
131
+ * @param {string} name - Color name (e.g., 'primary', 'surface')
132
+ * @returns {Array} Array of shortcut definitions
133
+ */
134
+ export function contrastShortcuts(name) {
135
+ return [
136
+ [`text-on-${name}`, `text-${name}-50 dark:text-${name}-50`],
137
+ [`text-on-${name}-muted`, `text-${name}-100 dark:text-${name}-200`]
138
+ ]
139
+ }
140
+
141
+ /**
142
+ * Theme class for managing color palettes, mappings, and semantic shortcuts.
143
+ */
144
+ export class Theme {
145
+ #colors
146
+ #mapping
147
+
148
+ /**
149
+ *
150
+ * @param {import('./types.js').ColorTheme} param0
151
+ */
152
+ constructor({ colors = defaultColors, mapping = DEFAULT_THEME_MAPPING } = {}) {
153
+ this.#colors = { ...defaultColors, ...colors }
154
+ this.#mapping = { ...DEFAULT_THEME_MAPPING, ...mapping }
155
+ }
156
+
157
+ get colors() {
158
+ return this.#colors
159
+ }
160
+ set colors(colors) {
161
+ this.#colors = { ...colors }
162
+ }
163
+
164
+ get mapping() {
165
+ return this.#mapping
166
+ }
167
+ set mapping(mapping) {
168
+ this.#mapping = { ...mapping }
169
+ }
170
+
171
+ mapVariant(color, variant) {
172
+ return Object.keys(color).reduce(
173
+ (acc, key) => ({
174
+ ...acc,
175
+ [key]:
176
+ key === 'DEFAULT'
177
+ ? `rgba(var(--color-${variant}),<alpha-value>)`
178
+ : `rgba(var(--color-${variant}-${key}),<alpha-value>)`
179
+ }),
180
+ {}
181
+ )
182
+ }
183
+
184
+ getColorRules(mapping = null) {
185
+ const variants = Object.entries({ ...this.#mapping, ...mapping })
186
+ return variants.reduce(
187
+ (acc, [variant, key]) => ({
188
+ ...acc,
189
+ [variant]: this.mapVariant(this.#colors[key], variant)
190
+ }),
191
+ {}
192
+ )
193
+ }
194
+
195
+ getPalette(mapping = null) {
196
+ const useMapping = { ...this.#mapping, ...mapping }
197
+ const useColors = { ...defaultColors, ...this.#colors }
198
+ const variants = Object.keys(useMapping)
199
+ const rules = variants
200
+ .flatMap((variant) => generateColorRules(variant, useColors, useMapping))
201
+ .reduce((acc, { key, value }) => ({ ...acc, [key]: value }), {})
202
+ return rules
203
+ }
204
+
205
+ getShortcuts(name) {
206
+ return [...semanticShortcuts(name), ...contrastShortcuts(name)]
207
+ }
208
+ }
package/src/ticks.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Generates an array of tick marks for a range of values.
3
+ *
4
+ * @param {number} lowerBound - The lower bound of the range.
5
+ * @param {number} upperBound - The upper bound of the range.
6
+ * @param {number} [minorTickStep=upperBound-lowerBound] - The step size for minor ticks.
7
+ * @param {number} [majorTickStep=1] - The step size for major ticks.
8
+ * @returns {import('./types').TickMark[]>} An array of tick mark objects.
9
+ */
10
+ export function generateTicks(
11
+ lowerBound,
12
+ upperBound,
13
+ minorTickStep = upperBound - lowerBound,
14
+ majorTickStep = 1
15
+ ) {
16
+ const length = 1 + Math.ceil((upperBound - lowerBound) / minorTickStep)
17
+ return Array.from({ length }, (_, i) => {
18
+ const value = i === length - 1 ? upperBound : lowerBound + minorTickStep * i
19
+ const major = i === 0 || i === length - 1 || i % majorTickStep === 0
20
+ return {
21
+ value,
22
+ label: major ? value : '',
23
+ major
24
+ }
25
+ })
26
+ }
package/src/types.js ADDED
@@ -0,0 +1,160 @@
1
+ /**
2
+ * @typedef {'child' | 'last' | 'sibling' | 'empty' | 'icon'} LineType
3
+ */
4
+
5
+ /**
6
+ * @typedef {Object.<string, Function>} EventHandlers
7
+ * An object where keys are event names and values are event handler functions.
8
+ */
9
+
10
+ /**
11
+ * Component map to be used to render the item.
12
+ * @typedef {Object<string, import('svelte').SvelteComponent>} ComponentMap
13
+ */
14
+
15
+ /**
16
+ * Options for the sort order of the column.
17
+ *
18
+ * @typedef {'ascending'|'descending'|'none'} SortOptions
19
+ */
20
+
21
+ /**
22
+ * @typedef {'checked'|'unchecked'|'indeterminate'} SelectionState
23
+ */
24
+
25
+ /**
26
+ * Options for the horizontal alignment of the column content.
27
+ *
28
+ * @typedef {'left'|'middle'|'right'} HorizontalAlignOptions
29
+ */
30
+
31
+ /**
32
+ * Options for the action type of the column.
33
+ *
34
+ * @typedef {'select'|'edit'|'delete'} ActionTypes
35
+ */
36
+
37
+ /**
38
+ * Structure to map custom fields for rendering. This is used to identofy the attributes for various purposes.
39
+ *
40
+ * @typedef FieldMapping
41
+ * @property {string} [id='id'] Unique id for the item
42
+ * @property {string} [text='text'] the text to render
43
+ * @property {string} [value='value'] the value associated with the item
44
+ * @property {string} [url='url'] a URL
45
+ * @property {string} [icon='icon'] icon to render
46
+ * @property {string} [image='image'] the image to render
47
+ * @property {string} [children='children'] children of the item
48
+ * @property {string} [summary='summary'] summary of the item
49
+ * @property {string} [notes='notes'] notes for the item
50
+ * @property {string} [props='props'] additional properties
51
+ * @property {string} [isOpen='_open'] item is open or closed
52
+ * @property {string} [level='level'] level of item
53
+ * @property {string} [parent='parent'] item is a parent
54
+ * @property {string} [currency='currency] column specifying currency to be used for the current value
55
+ * @property {string} [isDeleted='_deleted'] item is deleted
56
+ * @property {FieldMapping} [fields] Field mapping to be used on children in the next level
57
+ */
58
+
59
+ /**
60
+ * Column metadata for the table.
61
+ *
62
+ * @typedef {Object} ColumnMetadata
63
+ *
64
+ * @property {string} name - The name of the column.
65
+ * @property {string} dataType - The data type of the column (e.g., "string", "number", "date").
66
+ * @property {FieldMapping} [fields] - Additional attributes for the column.
67
+ * @property {number} [digits=0] - The number of digits for numeric values (defaults to 0).
68
+ * @property {Function} formatter - A function to format the column value.
69
+ * @property {boolean} [virtual] - Indicates if the column is virtual (true/false).
70
+ * @property {boolean} [sortable] - Indicates if the column is sortable (true/false).
71
+ * @property {SortOptions} [sortOrder] - The sort order of the column.
72
+ * @property {HorizontalAlignOptions} [align] - The alignment of the column content.
73
+ * @property {ActionTypes} [action] - Action attribute for action columns.
74
+ */
75
+
76
+ /**
77
+ * Track the state of a row in the table.
78
+ *
79
+ * @typedef {Object} RowState
80
+ * @property {number} index - The index of the node in the flat list.
81
+ * @property {number} depth - The depth of the node in the hierarchy.
82
+ * @property {string} [value] - The value of the hierarchy node.
83
+ * @property {boolean} [isHidden] - Indicates whether the node is visible (true/false).
84
+ * @property {boolean} [isParent] - Indicates if this node is a parent (true/false).
85
+ * @property {boolean} [isExpanded] - Indicates whether the node is expanded (true/false).
86
+ * @property {number} [parentIndex] - The index of the parent node in the flat list.
87
+ * @property {SelectionState} [selected] - Indicates whether the node is selected (true/false/indeterminate).
88
+ * @property {Array<number>} childred - The indices of the children in the flat list.
89
+ */
90
+
91
+ /**
92
+ * Track the state of all rows in the table.
93
+ *
94
+ * @typedef {Object} RowStateMap
95
+ * @property {RowState[]} rows - Flat list of hierarchy nodes.
96
+ */
97
+
98
+ /**
99
+ * Shade mapping for color variables
100
+ *
101
+ * @typedef {Object} ShadeMapping
102
+ * @property {string} key - the variable name to be used
103
+ * @property {string} value - the value to be used
104
+ * @property {string} mode - light or dark mode
105
+ */
106
+
107
+ /**
108
+ * @typedef {Object} TickMark
109
+ * @property {number} value - The value of the tick mark.
110
+ * @property {string} label - The label for the tick mark.
111
+ * @property {boolean} major - Indicates if the tick mark is a major tick.
112
+ */
113
+
114
+ /**
115
+ * @typedef {Object} CalendarDay
116
+ * @property {number} day - The day of the month.
117
+ * @property {number} offset - indicates the offset for positioning
118
+ * @property {date} date - Datevalue for the day.
119
+ * @property {string} text - formatted text for the day.
120
+ * @property {boolean} holiday - Indicates if the day is a holiday.
121
+ * @property {boolean} weekend - Indicates if the day is on the weekend.
122
+ */
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
+ */
160
+ export default {}