@shumoku/core 0.2.0 → 0.2.3
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/dist/icons/build-icons.js +3 -3
- package/dist/icons/build-icons.js.map +1 -1
- package/dist/icons/generated-icons.js +10 -10
- package/dist/icons/generated-icons.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/layout/hierarchical.d.ts +1 -1
- package/dist/layout/hierarchical.d.ts.map +1 -1
- package/dist/layout/hierarchical.js +82 -66
- package/dist/layout/hierarchical.js.map +1 -1
- package/dist/layout/index.d.ts +1 -1
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js.map +1 -1
- package/dist/models/types.d.ts.map +1 -1
- package/dist/models/types.js +13 -13
- package/dist/models/types.js.map +1 -1
- package/dist/renderer/index.d.ts +4 -3
- package/dist/renderer/index.d.ts.map +1 -1
- package/dist/renderer/index.js +3 -2
- package/dist/renderer/index.js.map +1 -1
- package/dist/renderer/svg.d.ts +26 -4
- package/dist/renderer/svg.d.ts.map +1 -1
- package/dist/renderer/svg.js +286 -147
- package/dist/renderer/svg.js.map +1 -1
- package/dist/renderer/types.d.ts +70 -0
- package/dist/renderer/types.d.ts.map +1 -0
- package/dist/renderer/types.js +6 -0
- package/dist/renderer/types.js.map +1 -0
- package/dist/themes/dark.d.ts.map +1 -1
- package/dist/themes/dark.js +1 -1
- package/dist/themes/dark.js.map +1 -1
- package/dist/themes/index.d.ts +3 -3
- package/dist/themes/index.d.ts.map +1 -1
- package/dist/themes/index.js +4 -4
- package/dist/themes/index.js.map +1 -1
- package/dist/themes/modern.d.ts.map +1 -1
- package/dist/themes/modern.js.map +1 -1
- package/dist/themes/types.d.ts.map +1 -1
- package/dist/themes/utils.d.ts +1 -1
- package/dist/themes/utils.d.ts.map +1 -1
- package/dist/themes/utils.js +5 -4
- package/dist/themes/utils.js.map +1 -1
- package/package.json +88 -92
- package/src/constants.ts +35 -35
- package/src/icons/build-icons.ts +12 -6
- package/src/icons/generated-icons.ts +12 -12
- package/src/index.test.ts +66 -0
- package/src/index.ts +6 -13
- package/src/layout/hierarchical.ts +1251 -1221
- package/src/layout/index.ts +1 -1
- package/src/models/types.ts +47 -37
- package/src/themes/dark.ts +15 -15
- package/src/themes/index.ts +7 -7
- package/src/themes/modern.ts +22 -22
- package/src/themes/types.ts +26 -26
- package/src/themes/utils.ts +25 -24
- package/src/renderer/index.ts +0 -6
- package/src/renderer/svg.ts +0 -1277
package/src/themes/utils.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Theme utilities
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { Theme, ThemeOptions
|
|
5
|
+
import type { DeepPartial, Theme, ThemeOptions } from './types.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Merge theme with overrides
|
|
9
9
|
*/
|
|
10
10
|
export function mergeTheme(base: Theme, overrides?: DeepPartial<Theme>): Theme {
|
|
11
11
|
if (!overrides) return base
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
return deepMerge(base, overrides) as Theme
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -26,7 +26,7 @@ export function createTheme(options: ThemeOptions): Theme {
|
|
|
26
26
|
*/
|
|
27
27
|
export function applyThemeToCSS(theme: Theme, root: HTMLElement = document.documentElement): void {
|
|
28
28
|
const prefix = '--shumoku'
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
// Colors
|
|
31
31
|
root.style.setProperty(`${prefix}-bg`, theme.colors.background)
|
|
32
32
|
root.style.setProperty(`${prefix}-surface`, theme.colors.surface)
|
|
@@ -38,34 +38,34 @@ export function applyThemeToCSS(theme: Theme, root: HTMLElement = document.docum
|
|
|
38
38
|
root.style.setProperty(`${prefix}-warning`, theme.colors.warning)
|
|
39
39
|
root.style.setProperty(`${prefix}-error`, theme.colors.error)
|
|
40
40
|
root.style.setProperty(`${prefix}-info`, theme.colors.info)
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
// Dimensions
|
|
43
43
|
root.style.setProperty(`${prefix}-radius-sm`, `${theme.dimensions.radius.small}px`)
|
|
44
44
|
root.style.setProperty(`${prefix}-radius-md`, `${theme.dimensions.radius.medium}px`)
|
|
45
45
|
root.style.setProperty(`${prefix}-radius-lg`, `${theme.dimensions.radius.large}px`)
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
// Spacing
|
|
48
48
|
root.style.setProperty(`${prefix}-space-xs`, `${theme.dimensions.spacing.xs}px`)
|
|
49
49
|
root.style.setProperty(`${prefix}-space-sm`, `${theme.dimensions.spacing.sm}px`)
|
|
50
50
|
root.style.setProperty(`${prefix}-space-md`, `${theme.dimensions.spacing.md}px`)
|
|
51
51
|
root.style.setProperty(`${prefix}-space-lg`, `${theme.dimensions.spacing.lg}px`)
|
|
52
52
|
root.style.setProperty(`${prefix}-space-xl`, `${theme.dimensions.spacing.xl}px`)
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
// Typography
|
|
55
55
|
root.style.setProperty(`${prefix}-font-sans`, theme.typography.fontFamily.sans)
|
|
56
56
|
root.style.setProperty(`${prefix}-font-mono`, theme.typography.fontFamily.mono)
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
// Shadows
|
|
59
59
|
const shadowToCSS = (shadow: Theme['shadows'][keyof Theme['shadows']]) => {
|
|
60
60
|
const alpha = shadow.alpha || 1
|
|
61
61
|
const color = hexToRgba(shadow.color, alpha)
|
|
62
62
|
return `${shadow.offsetX}px ${shadow.offsetY}px ${shadow.blur}px ${color}`
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
root.style.setProperty(`${prefix}-shadow-sm`, shadowToCSS(theme.shadows.small))
|
|
66
66
|
root.style.setProperty(`${prefix}-shadow-md`, shadowToCSS(theme.shadows.medium))
|
|
67
67
|
root.style.setProperty(`${prefix}-shadow-lg`, shadowToCSS(theme.shadows.large))
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
// Set theme variant
|
|
70
70
|
root.setAttribute('data-theme', theme.variant)
|
|
71
71
|
}
|
|
@@ -76,11 +76,11 @@ export function applyThemeToCSS(theme: Theme, root: HTMLElement = document.docum
|
|
|
76
76
|
export function getThemeFromCSS(root: HTMLElement = document.documentElement): Partial<Theme> {
|
|
77
77
|
const prefix = '--shumoku'
|
|
78
78
|
const style = getComputedStyle(root)
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
const getVar = (name: string) => style.getPropertyValue(`${prefix}-${name}`).trim()
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
return {
|
|
83
|
-
variant: root.getAttribute('data-theme') as 'light' | 'dark' || 'light',
|
|
83
|
+
variant: (root.getAttribute('data-theme') as 'light' | 'dark') || 'light',
|
|
84
84
|
colors: {
|
|
85
85
|
background: getVar('bg'),
|
|
86
86
|
surface: getVar('surface'),
|
|
@@ -99,29 +99,30 @@ export function getThemeFromCSS(root: HTMLElement = document.documentElement): P
|
|
|
99
99
|
/**
|
|
100
100
|
* Convert hex color to rgba
|
|
101
101
|
*/
|
|
102
|
-
function hexToRgba(hex: string, alpha
|
|
102
|
+
function hexToRgba(hex: string, alpha = 1): string {
|
|
103
103
|
if (hex === 'transparent') return 'transparent'
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
|
|
106
106
|
if (!result) return hex
|
|
107
|
-
|
|
108
|
-
const r = parseInt(result[1], 16)
|
|
109
|
-
const g = parseInt(result[2], 16)
|
|
110
|
-
const b = parseInt(result[3], 16)
|
|
111
|
-
|
|
107
|
+
|
|
108
|
+
const r = Number.parseInt(result[1], 16)
|
|
109
|
+
const g = Number.parseInt(result[2], 16)
|
|
110
|
+
const b = Number.parseInt(result[3], 16)
|
|
111
|
+
|
|
112
112
|
return `rgba(${r}, ${g}, ${b}, ${alpha})`
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Deep merge utility
|
|
117
117
|
*/
|
|
118
|
+
// biome-ignore lint/suspicious/noExplicitAny: generic deep merge requires any types
|
|
118
119
|
function deepMerge(target: any, source: any): any {
|
|
119
120
|
if (!source) return target
|
|
120
|
-
|
|
121
|
+
|
|
121
122
|
const result = { ...target }
|
|
122
|
-
|
|
123
|
+
|
|
123
124
|
for (const key in source) {
|
|
124
|
-
if (
|
|
125
|
+
if (Object.hasOwn(source, key)) {
|
|
125
126
|
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
126
127
|
result[key] = deepMerge(target[key] || {}, source[key])
|
|
127
128
|
} else {
|
|
@@ -129,7 +130,7 @@ function deepMerge(target: any, source: any): any {
|
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
|
-
|
|
133
|
+
|
|
133
134
|
return result
|
|
134
135
|
}
|
|
135
136
|
|
|
@@ -140,4 +141,4 @@ function getDefaultTheme(): Theme {
|
|
|
140
141
|
// Lazy import to avoid circular dependency
|
|
141
142
|
const { modernTheme } = require('./modern')
|
|
142
143
|
return modernTheme
|
|
143
|
-
}
|
|
144
|
+
}
|