@rokkit/core 1.0.0-next.95 → 1.0.0-next.97

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.95",
3
+ "version": "1.0.0-next.97",
4
4
  "description": "Core components, actions and stores for svelte apps.",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -12,21 +12,22 @@
12
12
  "access": "public"
13
13
  },
14
14
  "devDependencies": {
15
- "@sveltejs/vite-plugin-svelte": "^3.0.2",
16
- "@testing-library/svelte": "^4.1.0",
17
- "@types/ramda": "^0.29.12",
18
- "@vitest/coverage-v8": "^1.4.0",
19
- "@vitest/ui": "~1.4.0",
20
- "jsdom": "^24.0.0",
21
- "svelte": "^4.2.12",
22
- "typescript": "^5.4.4",
23
- "vite": "^5.2.8",
24
- "vitest": "~1.4.0",
25
- "shared-config": "1.0.0-next.95",
26
- "validators": "1.0.0-next.95"
15
+ "@sveltejs/vite-plugin-svelte": "^3.1.1",
16
+ "@testing-library/svelte": "^5.1.0",
17
+ "@types/ramda": "^0.30.0",
18
+ "@vitest/coverage-v8": "^1.6.0",
19
+ "@vitest/ui": "~1.6.0",
20
+ "jsdom": "^24.1.0",
21
+ "svelte": "^4.2.17",
22
+ "typescript": "^5.4.5",
23
+ "vite": "^5.2.12",
24
+ "vitest": "~1.6.0",
25
+ "shared-config": "1.0.0-next.97",
26
+ "validators": "1.0.0-next.97"
27
27
  },
28
28
  "files": [
29
29
  "src/**/*.js",
30
+ "src/**/*.json",
30
31
  "src/**/*.svelte",
31
32
  "!spec"
32
33
  ],
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "dependencies": {
44
45
  "date-fns": "^3.6.0",
45
- "ramda": "^0.29.1"
46
+ "ramda": "^0.30.1"
46
47
  },
47
48
  "scripts": {
48
49
  "format": "prettier --write .",
package/src/calendar.js CHANGED
@@ -10,6 +10,14 @@ export const weekdays = [
10
10
  'Saturday'
11
11
  ]
12
12
 
13
+ /**
14
+ * Get the days in the month.
15
+ *
16
+ * @param {Date} value
17
+ * @param {Array} holidays
18
+ * @param {boolean} fixed
19
+ * @returns {import('./types').CalendarDay[]}
20
+ */
13
21
  export function getCalendarDays(value, holidays = [], fixed = false) {
14
22
  const month = getMonth(value)
15
23
  const year = getYear(value)
@@ -0,0 +1,42 @@
1
+ {
2
+ "one-dark": {
3
+ "dark": {
4
+ "--tab-size": "2",
5
+ "--code-fill": "var(--neutral-100)",
6
+ "--code-normal": "#e06c75",
7
+ "--code-string": "#98c379",
8
+ "--code-number": "#d19a66",
9
+ "--code-atrule": "var(--code-string)",
10
+ "--code-keyword": "#c678dd",
11
+ "--code-comment": "#5c6370",
12
+ "--code-property": "#d19a66",
13
+ "--code-selector": "var(--code-keyword)",
14
+ "--code-operator": "#56b6c2",
15
+ "--code-function": "#61afef",
16
+ "--code-gutter-marker": "black",
17
+ "--code-gutter-subtle": "#999",
18
+ "--code-cursor": "#24292e",
19
+ "--code-cursor-block": "rgba(20, 255, 20, 0.5)",
20
+ "--code-linenumbers": "rgba(27, 31, 35, 0.3)"
21
+ },
22
+ "light": {
23
+ "--tab-size": "2",
24
+ "--code-fill": "var(--neutral-100)",
25
+ "--code-normal": "#333333",
26
+ "--code-string": "#9D8248",
27
+ "--code-number": "#71A15D",
28
+ "--code-atrule": "var(--code-string)",
29
+ "--code-keyword": "#3080B5",
30
+ "--code-comment": "#969896",
31
+ "--code-property": "#63a35c",
32
+ "--code-selector": "var(--code-keyword)",
33
+ "--code-operator": "#bf5625",
34
+ "--code-function": "#a71d5d",
35
+ "--code-gutter-marker": "black",
36
+ "--code-gutter-subtle": "#999",
37
+ "--code-cursor": "#24292e",
38
+ "--code-cursor-block": "rgba(20, 255, 20, 0.5)",
39
+ "--code-linenumbers": "rgba(27, 31, 35, 0.3)"
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,289 @@
1
+ {
2
+ "amber": {
3
+ "50": "#fffbeb",
4
+ "100": "#fef3c7",
5
+ "200": "#fde68a",
6
+ "300": "#fcd34d",
7
+ "400": "#fbbf24",
8
+ "500": "#f59e0b",
9
+ "600": "#d97706",
10
+ "700": "#b45309",
11
+ "800": "#92400e",
12
+ "900": "#78350f",
13
+ "950": "#451a03"
14
+ },
15
+ "blue": {
16
+ "50": "#eff6ff",
17
+ "100": "#dbeafe",
18
+ "200": "#bfdbfe",
19
+ "300": "#93c5fd",
20
+ "400": "#60a5fa",
21
+ "500": "#3b82f6",
22
+ "600": "#2563eb",
23
+ "700": "#1d4ed8",
24
+ "800": "#1e40af",
25
+ "900": "#1e3a8a",
26
+ "950": "#172554"
27
+ },
28
+ "cyan": {
29
+ "50": "#ecfeff",
30
+ "100": "#cffafe",
31
+ "200": "#a5f3fc",
32
+ "300": "#67e8f9",
33
+ "400": "#22d3ee",
34
+ "500": "#06b6d4",
35
+ "600": "#0891b2",
36
+ "700": "#0e7490",
37
+ "800": "#155e75",
38
+ "900": "#164e63",
39
+ "950": "#083344"
40
+ },
41
+ "emerald": {
42
+ "50": "#ecfdf5",
43
+ "100": "#d1fae5",
44
+ "200": "#a7f3d0",
45
+ "300": "#6ee7b7",
46
+ "400": "#34d399",
47
+ "500": "#10b981",
48
+ "600": "#059669",
49
+ "700": "#047857",
50
+ "800": "#065f46",
51
+ "900": "#064e3b",
52
+ "950": "#022c22"
53
+ },
54
+ "fuscia": {
55
+ "50": "#fdf4ff",
56
+ "100": "#fae8ff",
57
+ "200": "#f5d0fe",
58
+ "300": "#f0abfc",
59
+ "400": "#e879f9",
60
+ "500": "#d946ef",
61
+ "600": "#c026d3",
62
+ "700": "#a21caf",
63
+ "800": "#86198f",
64
+ "900": "#701a75",
65
+ "950": "#4a044e"
66
+ },
67
+ "gray": {
68
+ "50": "#f9fafb",
69
+ "100": "#f3f4f6",
70
+ "200": "#e5e7eb",
71
+ "300": "#d1d5db",
72
+ "400": "#9ca3af",
73
+ "500": "#6b7280",
74
+ "600": "#4b5563",
75
+ "700": "#374151",
76
+ "800": "#1f2937",
77
+ "900": "#111827",
78
+ "950": "#00060c"
79
+ },
80
+ "green": {
81
+ "50": "#f0fdf4",
82
+ "100": "#dcfce7",
83
+ "200": "#bbf7d0",
84
+ "300": "#86efac",
85
+ "400": "#4ade80",
86
+ "500": "#22c55e",
87
+ "600": "#16a34a",
88
+ "700": "#15803d",
89
+ "800": "#166534",
90
+ "900": "#14532d",
91
+ "950": "#052e16"
92
+ },
93
+ "indigo": {
94
+ "50": "#eef2ff",
95
+ "100": "#e0e7ff",
96
+ "200": "#c7d2fe",
97
+ "300": "#a5b4fc",
98
+ "400": "#818cf8",
99
+ "500": "#6366f1",
100
+ "600": "#4f46e5",
101
+ "700": "#4338ca",
102
+ "800": "#3730a3",
103
+ "900": "#312e81",
104
+ "950": "#1e1b4b"
105
+ },
106
+ "lime": {
107
+ "50": "#f7fee7",
108
+ "100": "#ecfccb",
109
+ "200": "#d9f99d",
110
+ "300": "#bef264",
111
+ "400": "#a3e635",
112
+ "500": "#84cc16",
113
+ "600": "#65a30d",
114
+ "700": "#4d7c0f",
115
+ "800": "#3f6212",
116
+ "900": "#365314",
117
+ "950": "#1a2e05"
118
+ },
119
+ "orange": {
120
+ "50": "#fff7ed",
121
+ "100": "#ffedd5",
122
+ "200": "#fed7aa",
123
+ "300": "#fdba74",
124
+ "400": "#fb923c",
125
+ "500": "#f97316",
126
+ "600": "#ea580c",
127
+ "700": "#c2410c",
128
+ "800": "#9a3412",
129
+ "900": "#7c2d12",
130
+ "950": "#431407"
131
+ },
132
+ "pink": {
133
+ "50": "#fdf2f8",
134
+ "100": "#fce7f3",
135
+ "200": "#fbcfe8",
136
+ "300": "#f9a8d4",
137
+ "400": "#f472b6",
138
+ "500": "#ec4899",
139
+ "600": "#db2777",
140
+ "700": "#be185d",
141
+ "800": "#9d174d",
142
+ "900": "#831843",
143
+ "950": "#500724"
144
+ },
145
+ "purple": {
146
+ "50": "#faf5ff",
147
+ "100": "#f3e8ff",
148
+ "200": "#e9d5ff",
149
+ "300": "#d8b4fe",
150
+ "400": "#c084fc",
151
+ "500": "#a855f7",
152
+ "600": "#9333ea",
153
+ "700": "#7e22ce",
154
+ "800": "#6b21a8",
155
+ "900": "#581c87",
156
+ "950": "#3b0764"
157
+ },
158
+ "red": {
159
+ "50": "#fef2f2",
160
+ "100": "#fee2e2",
161
+ "200": "#fecaca",
162
+ "300": "#fca5a5",
163
+ "400": "#f87171",
164
+ "500": "#ef4444",
165
+ "600": "#dc2626",
166
+ "700": "#b91c1c",
167
+ "800": "#991b1b",
168
+ "900": "#7f1d1d",
169
+ "950": "#450a0a"
170
+ },
171
+ "rose": {
172
+ "50": "#fff1f2",
173
+ "100": "#ffe4e6",
174
+ "200": "#fecdd3",
175
+ "300": "#fda4af",
176
+ "400": "#fb7185",
177
+ "500": "#f43f5e",
178
+ "600": "#e11d48",
179
+ "700": "#be123c",
180
+ "800": "#9f1239",
181
+ "900": "#881337",
182
+ "950": "#4c0519"
183
+ },
184
+ "sky": {
185
+ "50": "#f0f9ff",
186
+ "100": "#e0f2fe",
187
+ "200": "#bae6fd",
188
+ "300": "#7dd3fc",
189
+ "400": "#38bdf8",
190
+ "500": "#0ea5e9",
191
+ "600": "#0284c7",
192
+ "700": "#0369a1",
193
+ "800": "#075985",
194
+ "900": "#0c4a6e",
195
+ "950": "#082f49"
196
+ },
197
+ "slate": {
198
+ "50": "#f8fafc",
199
+ "100": "#f1f5f9",
200
+ "200": "#e2e8f0",
201
+ "300": "#cbd5e0",
202
+ "400": "#94a3b8",
203
+ "500": "#64748b",
204
+ "600": "#475569",
205
+ "700": "#334155",
206
+ "800": "#1e293b",
207
+ "900": "#0f172a",
208
+ "950": "#020617"
209
+ },
210
+ "stone": {
211
+ "50": "#fafaf9",
212
+ "100": "#f5f5f4",
213
+ "200": "#e7e5e4",
214
+ "300": "#d6d3d1",
215
+ "400": "#a8a29e",
216
+ "500": "#78716c",
217
+ "600": "#57534e",
218
+ "700": "#44403c",
219
+ "800": "#292524",
220
+ "900": "#1c1917",
221
+ "950": "#0c0a09"
222
+ },
223
+ "teal": {
224
+ "50": "#f0fdfa",
225
+ "100": "#ccfbf1",
226
+ "200": "#99f6e4",
227
+ "300": "#5eead4",
228
+ "400": "#2dd4bf",
229
+ "500": "#14b8a6",
230
+ "600": "#0d9488",
231
+ "700": "#0f766e",
232
+ "800": "#115e59",
233
+ "900": "#134e4a",
234
+ "950": "#042f2e"
235
+ },
236
+ "violet": {
237
+ "50": "#f5f3ff",
238
+ "100": "#ede9fe",
239
+ "200": "#ddd6fe",
240
+ "300": "#c4b5fd",
241
+ "400": "#a78bfa",
242
+ "500": "#8b5cf6",
243
+ "600": "#7c3aed",
244
+ "700": "#6d28d9",
245
+ "800": "#5b21b6",
246
+ "900": "#4c1d95",
247
+ "950": "#2e1065"
248
+ },
249
+ "yellow": {
250
+ "50": "#fefce8",
251
+ "100": "#fef9c3",
252
+ "200": "#fef08a",
253
+ "300": "#fde047",
254
+ "400": "#facc15",
255
+ "500": "#eab308",
256
+ "600": "#ca8a04",
257
+ "700": "#a16207",
258
+ "800": "#854d0e",
259
+ "900": "#713f12",
260
+ "950": "#422006"
261
+ },
262
+ "zinc": {
263
+ "50": "#fafafa",
264
+ "100": "#f4f4f5",
265
+ "200": "#e4e4e7",
266
+ "300": "#d4d4d8",
267
+ "400": "#a1a1aa",
268
+ "500": "#71717a",
269
+ "600": "#52525b",
270
+ "700": "#3f3f46",
271
+ "800": "#27272a",
272
+ "900": "#18181b",
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
+ }
289
+ }
package/src/constants.js CHANGED
@@ -97,6 +97,12 @@ export const defaultThemeMapping = {
97
97
  info: 'cyan'
98
98
  }
99
99
 
100
+ /**
101
+ * Generate a state icon mapping from a list of icon names
102
+ *
103
+ * @param {string[]} icons
104
+ * @returns {import('./types').StateIcons}
105
+ */
100
106
  export function stateIconsFromNames(icons) {
101
107
  return icons
102
108
  .map((k) => [...k.split('-')])
package/src/index.js CHANGED
@@ -1,12 +1,17 @@
1
+ // skipcq: JS-E1004 - Needed for exposing JS Doc types
1
2
  export * from './types'
3
+ // skipcq: JS-E1004 - Needed for exposing all constants
2
4
  export * from './constants'
3
- export * from './nested'
5
+ export { flattenNestedList, findValueFromPath } from './nested'
6
+ // skipcq: JS-E1004 - Needed for exposing all functions
4
7
  export * from './mapping'
5
- export * from './mapped-list'
6
- export * from './connector'
7
- export * from './ticks'
8
- export * from './calendar'
8
+ export { mappedList } from './mapped-list'
9
+ export { getLineTypes } from './connector'
10
+ export { generateTicks } from './ticks'
11
+ export { weekdays, getCalendarDays } from './calendar'
12
+ // skipcq: JS-E1004 - Needed for exposing all functions
9
13
  export * from './utils'
14
+ // skipcq: JS-E1004 - Needed for exposing all functions
10
15
  export * from './theme'
11
- export * from './parser'
16
+ // skipcq: JS-E1004 - Needed for exposing all functions
12
17
  export * from './string'
@@ -28,6 +28,7 @@ function findInChildren(item, index, fields, value, attr, position) {
28
28
  index
29
29
  ])
30
30
  }
31
+ return null
31
32
  }
32
33
  /**
33
34
  * Traverses the tree to find an item by value.
@@ -186,7 +187,6 @@ function getNextSiblingOrAncestor(position, items, fields) {
186
187
  let children = parent.item[parent.fields.children]
187
188
  if (index < children.length - 1) {
188
189
  index += 1
189
-
190
190
  const sibling = findItemByIndexArray([...position.slice(0, -1), index], items, fields)
191
191
  return { item: sibling.item, position: sibling.position, fields }
192
192
  } else {
@@ -197,12 +197,10 @@ function getNextSiblingOrAncestor(position, items, fields) {
197
197
  parent = findItemByIndexArray(position, items, fields)
198
198
  children = parent.item[parent.fields.children]
199
199
  }
200
- if (index < children.length - 1) {
201
- return {
202
- item: children[index + 1],
203
- position: [...position, index + 1],
204
- fields
205
- }
200
+ return {
201
+ item: children[index + 1],
202
+ position: [...position, index + 1],
203
+ fields
206
204
  }
207
205
  }
208
206
  }
package/src/mapping.js CHANGED
@@ -5,7 +5,7 @@ import { toString, isObject } from './utils'
5
5
  * Get the component to be used to render the item.
6
6
  * If the component is null or undefined, it will return the default component.
7
7
  *
8
- * @param {object|string} value
8
+ * @param {object|string} value
9
9
  * @param {import('./types.js').FieldMapping} fields
10
10
  * @param {import('./types.js').ComponentMap} using
11
11
  */
@@ -18,24 +18,34 @@ export function getComponent(value, fields, using) {
18
18
  /**
19
19
  * Get the icon for the item. If the icon is an object, it will use the state to determine which icon to use.
20
20
  *
21
- * @param {object|string} value
21
+ * @param {object|string} value
22
22
  * @param {import('./types.js').FieldMapping} fields
23
+ * @returns {string}
23
24
  */
24
25
  export function getIcon(value, fields = defaultFields) {
25
26
  if (fields.icon === undefined || typeof (value ?? '') !== 'object') return null
26
- // console.log(fields.icon, fields.state, value[fields.icon][value[fields.state]])
27
- const name =
28
- typeof value[fields.icon] === 'object'
29
- ? value[fields.icon][value[fields.state]]
30
- : value[fields.icon]
27
+
28
+ const name = getIconFromObject(value, fields)
31
29
  return fields.iconPrefix ? [fields.iconPrefix, name].join('-') : name
32
30
  }
33
31
 
32
+ /**
33
+ * Get the icon for the item. If the icon is an object, it will use the state to determine which icon to use.
34
+ *
35
+ * @param {object} value
36
+ * @param {import('./types.js').FieldMapping} fields
37
+ * @returns {string}
38
+ */
39
+ function getIconFromObject(value, fields) {
40
+ if (typeof value[fields.icon] === 'object') return value[fields.icon][value[fields.state]]
41
+ return value[fields.icon]
42
+ }
43
+
34
44
  /**
35
45
  * Get the value for the item. If the value is an object,
36
46
  * it will use the field mapping to determine which attribute to get.
37
47
  *
38
- * @param {*} node
48
+ * @param {*} node
39
49
  * @param {import('./types').FieldMapping} fields
40
50
  * @returns {*}
41
51
  */
@@ -54,11 +64,6 @@ export function getValue(node, fields = defaultFields) {
54
64
  export function getText(node, fields = defaultFields) {
55
65
  const value = isObject(node) ? node[fields.text] : node
56
66
  return value
57
- // return value != null
58
- // ? isObject(value)
59
- // ? JSON.stringify(value, null, 2)
60
- // : value.toString()
61
- // : value
62
67
  }
63
68
 
64
69
  /**
@@ -67,8 +72,8 @@ export function getText(node, fields = defaultFields) {
67
72
  *
68
73
  * @param {*} node
69
74
  * @param {import('./types').FieldMapping} fields
70
- * @param {function} formatter
71
- * @returns {*}
75
+ * @param {Function} formatter
76
+ * @returns {Function}
72
77
  */
73
78
  export function getFormattedText(node, fields = defaultFields, formatter = toString) {
74
79
  const value = isObject(node) ? node[fields.text] : node
@@ -79,7 +84,7 @@ export function getFormattedText(node, fields = defaultFields, formatter = toStr
79
84
  }
80
85
  /**
81
86
  * Gets the attribute from the node
82
- * @param {*} node
87
+ * @param {*} node
83
88
  * @param {string} attr
84
89
  * @returns {*}
85
90
  */
@@ -89,7 +94,7 @@ export function getAttribute(node, attr) {
89
94
  /**
90
95
  * Check if the current item is a parent
91
96
  *
92
- * @param {*} item
97
+ * @param {*} item
93
98
  * @param {import('./types').FieldMapping} fields
94
99
  * @returns {boolean}
95
100
  */
@@ -105,7 +110,7 @@ export function hasChildren(item, fields) {
105
110
  /**
106
111
  * Check if the current item is a parent and is expanded
107
112
  *
108
- * @param {*} item
113
+ * @param {*} item
109
114
  * @param {import('./types').FieldMapping} fields
110
115
  * @returns {boolean}
111
116
  */
@@ -121,7 +126,7 @@ export function isExpanded(item, fields) {
121
126
  /**
122
127
  * Verify if at least one item has children
123
128
  *
124
- * @param {Array<*>} items
129
+ * @param {Array<*>} items
125
130
  * @param {import('./types').FieldMapping} fields
126
131
  * @returns {boolean}
127
132
  */
package/src/nested.js CHANGED
@@ -1,6 +1,14 @@
1
1
  import { omit } from 'ramda'
2
2
  import { defaultFields } from './constants'
3
3
 
4
+ /**
5
+ * Flattens a nested list of items
6
+ *
7
+ * @param {Array} items
8
+ * @param {import('./types).FieldMapping} fields
9
+ * @param {number} level
10
+ * @returns {Array}
11
+ */
4
12
  export function flattenNestedList(items, fields = defaultFields, level = 0) {
5
13
  fields = { ...defaultFields, ...fields }
6
14
  let data = []
@@ -20,9 +28,11 @@ export function flattenNestedList(items, fields = defaultFields, level = 0) {
20
28
  }
21
29
 
22
30
  /**
23
- * Converts a path slug to a value in the menu
31
+ * Matches a path slug to a value in the menu
24
32
  *
25
- * @param {string} slug
33
+ * @param {string} slug
34
+ * @param {Array} data
35
+ * @param {import('./types').FieldMapping} fields
26
36
  * @returns {any}
27
37
  */
28
38
  export function findValueFromPath(slug, data, fields) {
package/src/theme.js CHANGED
@@ -11,6 +11,7 @@ const modifiers = {
11
11
  * Generate shades for a color using css varuable
12
12
  *
13
13
  * @param {string} name
14
+ * @param {string} modifier
14
15
  * @returns
15
16
  */
16
17
  export function shadesOf(name, modifier = 'none') {
@@ -30,11 +31,19 @@ export function shadesOf(name, modifier = 'none') {
30
31
  raised: fn(`var(--${name}-400)`),
31
32
  elevated: fn(`var(--${name}-600)`),
32
33
  floating: fn(`var(--${name}-700)`),
33
- contrast: fn(`var(--${name}-800)`)
34
+ contrast: fn(`var(--${name}-800)`),
35
+ overlay: fn(`var(--${name}-900)`)
34
36
  }
35
37
  )
36
38
  }
37
39
 
40
+ /**
41
+ * Generate shades for a color using css varuable
42
+ *
43
+ * @param {string} name
44
+ * @param {string} modifier
45
+ * @returns {object}
46
+ */
38
47
  export function stateColors(name, modifier = 'none') {
39
48
  const fn = modifier in modifiers ? modifiers[modifier] : modifiers.none
40
49
  return {
@@ -70,13 +79,12 @@ export function themeColors(modifier = 'none') {
70
79
  * Creates an array of shade mapping objects for a given theme variant and mode.
71
80
  * Each object represents a CSS custom property (variable) with its value set based on a provided condition.
72
81
  *
73
- * @param {string} variant - The name of the theme variant (e.g., 'primary', 'secondary').
74
- * @param {'light' | 'dark'} mode - The theme mode for which the mappings are being created.
82
+ * @param {string} variant - The name of the theme variant (e.g., 'primary', 'secondary').
83
+ * @param {'light' | 'dark'} mode - The theme mode for which the mappings are being created.
75
84
  * @param {function(number): string} valueCondition - A function that takes a shade value and returns the color value
76
85
  * based on the condition appropriate for light or dark mode.
77
- * @returns {Array<{key: string, value: string, mode: string}>} An array of objects, where each object contains
78
- * key, value, and mode properties corresponding to
79
- * a CSS custom property definition.
86
+ * @returns {{import('./types'}.ShadeMapping[]>} An array of objects, where each object contains key, value, and mode
87
+ * properties corresponding to a CSS custom property definition.
80
88
  */
81
89
  function createShadeMappings(variant, mode, valueCondition) {
82
90
  return shades.map((shade) => ({
@@ -110,7 +118,7 @@ export function contrastColors(light = '#ffffff', dark = '#000000', palette = de
110
118
  * @param {string} variant - The name of the variant to generate rules for.
111
119
  * @param {Object} colors - The object containing color definitions.
112
120
  * @param {Object} mapping - An object that maps variant names to color property names.
113
- * @returns {Array<Object>} An array containing the color rules for both light and dark modes.
121
+ * @returns {import('./types').ShadeMappings} An array containing the color rules for both light and dark modes.
114
122
  */
115
123
  function generateColorRules(variant, colors, mapping) {
116
124
  return shades.flatMap((shade, index) => [
@@ -165,9 +173,9 @@ function createThemeVariant(name, mode, colors, extraColors) {
165
173
  /**
166
174
  * Constructs and returns the light and dark theme variants based on provided color mapping and color definitions.
167
175
  *
168
- * @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
176
+ * @param {string} name - The base name for the theme, defaults to 'rokkit' if not provided.
169
177
  * @param {Object} [mapping=defaultThemeMapping] - An object mapping variant names to color property names.
170
- * @param {Object} [colors=defaultColors] - The object containing default color definitions.
178
+ * @param {Object} [colors=defaultColors] - The object containing default color definitions.
171
179
  * @returns {Array<Array>} An array containing two arrays, one for the light theme variant and another for the dark theme.
172
180
  */
173
181
  export function themeRules(name = 'rokkit', mapping = defaultThemeMapping, colors = defaultColors) {
package/src/ticks.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Generates an array of tick marks for a range of values.
3
3
  *
4
- * @param {number} lowerBound - The lower bound of the range.
5
- * @param {number} upperBound - The upper bound of the range.
4
+ * @param {number} lowerBound - The lower bound of the range.
5
+ * @param {number} upperBound - The upper bound of the range.
6
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 {Array<{value: number, label: string, major: boolean}>} An array of tick mark objects.
7
+ * @param {number} [majorTickStep=1] - The step size for major ticks.
8
+ * @returns {import('./types').TickMark[]>} An array of tick mark objects.
9
9
  */
10
10
  export function generateTicks(
11
11
  lowerBound,
@@ -13,10 +13,6 @@ export function generateTicks(
13
13
  minorTickStep = upperBound - lowerBound,
14
14
  majorTickStep = 1
15
15
  ) {
16
- // lowerBound = +lowerBound
17
- // upperBound = +upperBound
18
- // minorTickStep = +minorTickStep
19
- // majorTickStep = +majorTickStep
20
16
  const length = 1 + Math.ceil((upperBound - lowerBound) / minorTickStep)
21
17
  return Array.from({ length }, (_, i) => {
22
18
  const value = i === length - 1 ? upperBound : lowerBound + minorTickStep * i
package/src/types.js CHANGED
@@ -86,4 +86,30 @@
86
86
  * @property {RowState[]} rows - Flat list of hierarchy nodes.
87
87
  */
88
88
 
89
+ /**
90
+ * Shade mapping for color variables
91
+ *
92
+ * @typedef {Object} ShadeMapping
93
+ * @property {string} key - the variable name to be used
94
+ * @property {string} value - the value to be used
95
+ * @property {string} mode - light or dark mode
96
+ */
97
+
98
+ /**
99
+ * @typedef {Object} TickMark
100
+ * @property {number} value - The value of the tick mark.
101
+ * @property {string} label - The label for the tick mark.
102
+ * @property {boolean} major - Indicates if the tick mark is a major tick.
103
+ */
104
+
105
+ /**
106
+ * @typedef {Object} CalendarDay
107
+ * @property {number} day - The day of the month.
108
+ * @property {number} offset - indicates the offset for positioning
109
+ * @property {date} date - Datevalue for the day.
110
+ * @property {string} text - formatted text for the day.
111
+ * @property {boolean} holiday - Indicates if the day is a holiday.
112
+ * @property {boolean} weekend - Indicates if the day is on the weekend.
113
+ */
114
+
89
115
  export default {}
package/src/parser.js DELETED
@@ -1,110 +0,0 @@
1
- /**
2
- * Constructs a regular expression pattern for matching search filter strings.
3
- * The pattern captures "column", "operator", and "value" groups for filter expressions.
4
- * Supported operators include common comparison and wildcard operators.
5
- *
6
- * Examples of valid expressions this regex can match:
7
- * - "username:john_doe"
8
- * - "age>30"
9
- * - "status!=active"
10
- * - "title~\"Product Manager\""
11
- * - "completed!~*yes"
12
- *
13
- * The "column" group matches one or more word characters.
14
- * The "operator" group matches one among the specified comparison or wildcard operators:
15
- * :, >, <, >=, <=, =<, =>, =, !=, ~, ~*, !~, !~*.
16
- * The "value" group matches either a double-quoted string or a single unquoted word
17
- * that doesn't include whitespace or any of the operator characters.
18
- *
19
- * @returns {RegExp} - The regular expression pattern to identify search filter elements.
20
- */
21
- export function getRegex() {
22
- const column = '[\\w]+'
23
- const operator = ':|>|<|>=|<=|=<|=>|=|!=|~|~\\*|!~|!~\\*'
24
- const value = '("[^"]+"|[^\\s=:<>!~*]+)'
25
-
26
- const pattern = `(?<group>((?<column>${column})\\s?(?<operator>${operator})\\s?)(?<value>${value}))`
27
-
28
- return new RegExp(pattern, 'gm')
29
- }
30
-
31
- /**
32
- * Parses a search string and extracts filters based on a predefined regular expression pattern.
33
- * Each filter captures column, operator, and value components. Any remaining text that
34
- * does not fit the pattern is considered a general search term.
35
- *
36
- * @param {string} string - The search string to parse for filters.
37
- * @returns {Object[]} - An array of filter objects each containing the column, operator, and value,
38
- * plus an additional object for general search if there is remaining text.
39
- */
40
- export function parseFilters(string) {
41
- const results = []
42
- const regex = getRegex()
43
-
44
- // Split the string into an array of tokens
45
- const tokens = string.matchAll(regex)
46
- let search = string
47
-
48
- // Iterate over the tokens
49
- for (const token of tokens) {
50
- // Extract the named groups from the token
51
- let { group, column, operator, value } = token.groups
52
- search = search.replace(group, '').trim()
53
-
54
- operator = replaceOperators(operator)
55
- value = processValue(value, operator)
56
-
57
- if (column && value) results.push({ column, operator, value })
58
- }
59
-
60
- if (search.length > 0) {
61
- results.push({
62
- operator: '~*',
63
- value: new RegExp(removeQuotes(search), 'i')
64
- })
65
- }
66
-
67
- return results
68
- }
69
-
70
- /**
71
- * Replaces various shorthand operators with their standardized equivalent for filtering.
72
- *
73
- * @param {string} operator - The operator to be replaced.
74
- * @returns {string} - The replaced operator string.
75
- */
76
- function replaceOperators(operator) {
77
- return operator.replace(':', '~*').replace('=>', '>=').replace('=<', '<=')
78
- }
79
-
80
- /**
81
- * Processes the filter value provided, converting it into a format suitable for filtering.
82
- * If the operator includes a tilde (~), the value is converted to a RegExp.
83
- *
84
- * @param {string|number} value - The value to be processed. It could be a string needing quote removal or a number that needs parsing.
85
- * @param {string} operator - The operator that determines the type of processing to be applied to the value.
86
- * @returns {string|number|RegExp} - The processed value, which may be a RegExp if the operator involves pattern matching.
87
- */
88
- function processValue(value, operator) {
89
- // If the value can be parsed as an integer, do so. Otherwise, strip quotes if present.
90
-
91
- value = !isNaN(parseInt(value)) ? parseInt(value) : removeQuotes(value)
92
- // If the operator includes a tilde (~), treat the value as a regular expression,
93
- // case-insensitive if '*' is present, sensitive otherwise.
94
- if (operator.includes('~')) {
95
- value = operator.includes('*') ? new RegExp(value, 'i') : new RegExp(value)
96
- }
97
-
98
- return value
99
- }
100
-
101
- /**
102
- * Removes double quotes from the start and end of a string.
103
- *
104
- * @param {string} str - The input string from which the surrounding quotes should be removed.
105
- * @returns {string} - The unquoted string.
106
- */
107
- function removeQuotes(str) {
108
- const quoteMatch = str.match(/^"([^"]+)"$/)
109
- return quoteMatch ? quoteMatch[1] : str
110
- }