@hkdigital/lib-sveltekit 0.1.0 → 0.1.2
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/classes/svelte/audio/AudioScene.svelte.js +1 -1
- package/dist/classes/svelte/image/ImageLoader.svelte.js +1 -1
- package/dist/classes/svelte/image/ImageScene.svelte.js +1 -1
- package/dist/classes/svelte/network-loader/NetworkLoader.svelte.js +1 -1
- package/dist/components/area/HkArea.svelte +1 -1
- package/dist/components/area/HkArea.svelte.d.ts +14 -0
- package/dist/components/area/HkGridArea.svelte +1 -1
- package/dist/components/area/HkGridArea.svelte.d.ts +22 -0
- package/dist/components/boxes/game-box/GameBox.svelte +112 -0
- package/dist/components/boxes/game-box/GameBox.svelte.d.ts +28 -0
- package/dist/components/boxes/game-box/gamebox.util.d.ts +32 -0
- package/dist/components/boxes/game-box/gamebox.util.js +83 -0
- package/dist/components/boxes/index.d.ts +2 -0
- package/dist/components/boxes/index.js +2 -0
- package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte +199 -0
- package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte.d.ts +42 -0
- package/dist/components/buttons/button/Button.svelte +75 -0
- package/dist/components/buttons/button/Button.svelte.d.ts +40 -0
- package/dist/components/buttons/button-text/TextButton.svelte +21 -0
- package/dist/components/buttons/button-text/TextButton.svelte.d.ts +12 -0
- package/dist/components/buttons/index.d.ts +2 -1
- package/dist/components/buttons/index.js +2 -1
- package/dist/components/hkdev/blocks/TextBlock.svelte +47 -0
- package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +24 -0
- package/dist/components/hkdev/buttons/CheckButton.svelte +63 -0
- package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +34 -0
- package/dist/components/icon/HkIcon.svelte +1 -1
- package/dist/components/icon/HkIcon.svelte.d.ts +12 -0
- package/dist/components/icon/HkTabIcon.svelte +6 -2
- package/dist/components/icon/HkTabIcon.svelte.d.ts +21 -0
- package/dist/components/image/EnhancedImage.svelte__ +1 -1
- package/dist/components/image/ImageBox.svelte.d.ts +19 -0
- package/dist/components/image/ResponsiveImage.svelte +1 -1
- package/dist/components/image/ResponsiveImage.svelte.d.ts +16 -0
- package/dist/components/image/ResponsiveImage.svelte__ +1 -1
- package/dist/components/inputs/text-input/TestTextInput.svelte__ +2 -2
- package/dist/components/inputs/text-input/TextInput.svelte +1 -1
- package/dist/components/inputs/text-input/TextInput.svelte.d.ts +28 -0
- package/dist/components/inputs/text-input/TextInput.svelte___ +1 -1
- package/dist/components/layout/HkAppLayout.svelte.d.ts +11 -0
- package/dist/components/layout/HkGridLayers.svelte +1 -1
- package/dist/components/layout/HkGridLayers.svelte.d.ts +23 -0
- package/dist/components/panels/plain-panel/PlainPanel.svelte +1 -1
- package/dist/components/panels/plain-panel/PlainPanel.svelte.d.ts +12 -0
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte +1 -1
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +14 -0
- package/dist/components/rows/panel-row-2/PanelRow2.svelte +1 -1
- package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +14 -0
- package/dist/components/tab-bar/HkTabBar.svelte +1 -1
- package/dist/components/tab-bar/HkTabBar.svelte.d.ts +18 -0
- package/dist/components/tab-bar/HkTabBarSelector.svelte +1 -1
- package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +19 -0
- package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte.d.ts +10 -0
- package/dist/design-system/design-config.d.ts +156 -0
- package/dist/design-system/design-config.js +73 -0
- package/dist/design-system/tailwind-theme-extend.d.ts +23 -0
- package/dist/design-system/tailwind-theme-extend.js +151 -0
- package/dist/themes/hkdev/components/blocks/text-block.postcss +41 -0
- package/dist/themes/hkdev/components/buttons/button-text.postcss +34 -0
- package/dist/themes/hkdev/components/buttons/button.postcss +138 -0
- package/dist/themes/hkdev/components/buttons/button.postcss__ +40 -0
- package/dist/themes/hkdev/components/buttons/button.postcss___ +91 -0
- package/dist/themes/hkdev/components.postcss +8 -2
- package/dist/themes/hkdev/globals.postcss +5 -6
- package/dist/util/css/css-vars.d.ts +24 -0
- package/dist/util/css/css-vars.js +83 -0
- package/dist/util/css/index.d.ts +1 -0
- package/dist/util/css/index.js +1 -0
- package/dist/util/design-system/components/states.d.ts +15 -0
- package/dist/util/design-system/components/states.js +22 -0
- package/dist/util/design-system/css/clamp.d.ts +17 -0
- package/dist/util/design-system/css/clamp.js +66 -0
- package/dist/util/design-system/css/root-design-vars.d.ts +77 -0
- package/dist/util/design-system/css/root-design-vars.js +100 -0
- package/dist/util/design-system/index.d.ts +5 -0
- package/dist/util/design-system/index.js +5 -0
- package/dist/util/design-system/layout/scaling.d.ts +44 -0
- package/dist/util/design-system/layout/scaling.js +97 -0
- package/dist/util/design-system/tailwind.d.ts +176 -0
- package/dist/util/design-system/tailwind.js +289 -0
- package/dist/util/http/index.js +1 -1
- package/package.json +18 -18
- package/dist/components/buttons/plain-button/PlainButton.svelte +0 -37
- package/dist/components/buttons/plain-button/PlainButton.svelte.d.ts +0 -10
- package/dist/config/tailwind.extend.d.ts +0 -56
- package/dist/config/tailwind.extend.js +0 -64
- package/dist/themes/hkdev/components/buttons/plain-button.postcss +0 -73
@@ -0,0 +1,97 @@
|
|
1
|
+
import { clamp } from '../css/clamp.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Manages responsive design scaling by calculating and applying scale factors
|
5
|
+
* based on viewport dimensions and design system requirements.
|
6
|
+
*
|
7
|
+
* @param {Object} design - The base design dimensions
|
8
|
+
* @param {number} design.width - The reference design width
|
9
|
+
* @param {number} design.height - The reference design height
|
10
|
+
* @param {Object} clamping - The min/max values for various scale factors
|
11
|
+
* @param {Object} clamping.ui - UI element scaling constraints
|
12
|
+
* @param {number} clamping.ui.min - Minimum UI scale factor
|
13
|
+
* @param {number} clamping.ui.max - Maximum UI scale factor
|
14
|
+
* @param {Object} clamping.textContent - Content text scaling constraints
|
15
|
+
* @param {number} clamping.textContent.min - Minimum content text scale factor
|
16
|
+
* @param {number} clamping.textContent.max - Maximum content text scale factor
|
17
|
+
* @param {Object} clamping.textHeading - Heading text scaling constraints
|
18
|
+
* @param {number} clamping.textHeading.min - Minimum heading text scale factor
|
19
|
+
* @param {number} clamping.textHeading.max - Maximum heading text scale factor
|
20
|
+
* @param {Object} clamping.textUi - UI text scaling constraints
|
21
|
+
* @param {number} clamping.textUi.min - Minimum UI text scale factor
|
22
|
+
* @param {number} clamping.textUi.max - Maximum UI text scale factor
|
23
|
+
*
|
24
|
+
* @returns {()=>void} A cleanup function that removes the event listener
|
25
|
+
*/
|
26
|
+
export function enableScalingUI(design, clamping) {
|
27
|
+
/**
|
28
|
+
* Updates CSS scale variables based on current viewport dimensions
|
29
|
+
* and design system constraints
|
30
|
+
*/
|
31
|
+
function updateScaleValues() {
|
32
|
+
try {
|
33
|
+
const vw = window.innerWidth;
|
34
|
+
const vh = window.innerHeight;
|
35
|
+
|
36
|
+
// Calculate scale factors based on viewport size relative to design dimensions
|
37
|
+
const scaleW = vw / design.width;
|
38
|
+
const scaleH = vh / design.height;
|
39
|
+
|
40
|
+
// Use the smaller scale factor to ensure content fits within viewport
|
41
|
+
const scaleViewport = Math.min(scaleW, scaleH);
|
42
|
+
|
43
|
+
// Apply clamping to different element types
|
44
|
+
const scaleUI = clamp(scaleViewport, clamping.ui.min, clamping.ui.max);
|
45
|
+
|
46
|
+
const scaleTextContent = clamp(
|
47
|
+
scaleViewport,
|
48
|
+
clamping.textContent.min,
|
49
|
+
clamping.textContent.max
|
50
|
+
);
|
51
|
+
|
52
|
+
const scaleTextHeading = clamp(
|
53
|
+
scaleViewport,
|
54
|
+
clamping.textHeading.min,
|
55
|
+
clamping.textHeading.max
|
56
|
+
);
|
57
|
+
|
58
|
+
const scaleTextUi = clamp(
|
59
|
+
scaleViewport,
|
60
|
+
clamping.textUi.min,
|
61
|
+
clamping.textUi.max
|
62
|
+
);
|
63
|
+
|
64
|
+
// Set CSS custom properties for use in the design system
|
65
|
+
document.documentElement.style.setProperty('--scale-w', String(scaleW));
|
66
|
+
document.documentElement.style.setProperty('--scale-h', String(scaleH));
|
67
|
+
document.documentElement.style.setProperty(
|
68
|
+
'--scale-viewport',
|
69
|
+
String(scaleViewport)
|
70
|
+
);
|
71
|
+
document.documentElement.style.setProperty('--scale-ui', String(scaleUI));
|
72
|
+
document.documentElement.style.setProperty(
|
73
|
+
'--scale-text-content',
|
74
|
+
String(scaleTextContent)
|
75
|
+
);
|
76
|
+
document.documentElement.style.setProperty(
|
77
|
+
'--scale-text-heading',
|
78
|
+
String(scaleTextHeading)
|
79
|
+
);
|
80
|
+
document.documentElement.style.setProperty(
|
81
|
+
'--scale-text-ui',
|
82
|
+
String(scaleTextUi)
|
83
|
+
);
|
84
|
+
} catch (error) {
|
85
|
+
console.error('Error updating design scale values:', error);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
// Initialize scales and attach resize listener
|
90
|
+
updateScaleValues();
|
91
|
+
window.addEventListener('resize', updateScaleValues);
|
92
|
+
|
93
|
+
// Return cleanup function
|
94
|
+
return function cleanup() {
|
95
|
+
window.removeEventListener('resize', updateScaleValues);
|
96
|
+
};
|
97
|
+
}
|
@@ -0,0 +1,176 @@
|
|
1
|
+
/**
|
2
|
+
* Generates text-based spacing units with with different scaling
|
3
|
+
* units (ut, ct, ht)
|
4
|
+
*
|
5
|
+
* @param {number[]} values
|
6
|
+
* Array of pixel values to generate text-based spacing units for
|
7
|
+
*
|
8
|
+
* @returns {{[key: string]: string}}
|
9
|
+
* Generated text-based spacing units with ut, ct, and ht suffixes
|
10
|
+
*
|
11
|
+
* @throws {Error} If values is not an array or contains non-numeric values
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* generateTextBasedSpacing([1, 2, 4, 8])
|
15
|
+
* // Returns:
|
16
|
+
* // {
|
17
|
+
* // '1ut': 'calc(1px * var(--scale-text-ui))',
|
18
|
+
* // '2ut': 'calc(2px * var(--scale-text-ui))',
|
19
|
+
* // '1ct': 'calc(1px * var(--scale-text-content))',
|
20
|
+
* // '2ct': 'calc(2px * var(--scale-text-content))',
|
21
|
+
* // '1ht': 'calc(1px * var(--scale-text-heading))',
|
22
|
+
* // '2ht': 'calc(2px * var(--scale-text-heading))'
|
23
|
+
* // }
|
24
|
+
*/
|
25
|
+
export function generateTextBasedSpacing(values: number[]): {
|
26
|
+
[key: string]: string;
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* Generates viewport-based spacing units with different scaling
|
30
|
+
* units (p, vp, wp, hp)
|
31
|
+
*
|
32
|
+
* @param {number[]} values
|
33
|
+
* Array of pixel values to generate viewport-based spacing units for
|
34
|
+
*
|
35
|
+
* @returns {Object.<string, string>}
|
36
|
+
* Generated viewport-based spacing units:
|
37
|
+
* - p: UI points (clamped scaling)
|
38
|
+
* - vp: Viewport points (min of width/height)
|
39
|
+
* - wp: Width points
|
40
|
+
* - hp: Height points
|
41
|
+
*
|
42
|
+
* @throws {Error} If values is not an array or contains non-numeric values
|
43
|
+
*
|
44
|
+
* @example
|
45
|
+
* generateViewportBasedSpacing([1, 2, 4])
|
46
|
+
* // Returns:
|
47
|
+
* // {
|
48
|
+
* // '1p': 'calc(1px * var(--scale-ui))',
|
49
|
+
* // '1vp': 'calc(1px * var(--scale-viewport))',
|
50
|
+
* // '1wp': 'calc(1px * var(--scale-w))',
|
51
|
+
* // '1hp': 'calc(1px * var(--scale-h))'
|
52
|
+
* // }
|
53
|
+
*/
|
54
|
+
export function generateViewportBasedSpacing(values: number[]): {
|
55
|
+
[x: string]: string;
|
56
|
+
};
|
57
|
+
/**
|
58
|
+
* Generates semantic text style definitions for a specific text category
|
59
|
+
* (content, UI, or heading). Each style includes a scaled font size and
|
60
|
+
* line height.
|
61
|
+
*
|
62
|
+
* @param {{[key: string]: {size: number, lineHeight?: number}}} sizes
|
63
|
+
* Set of text sizes to generate styles for
|
64
|
+
*
|
65
|
+
* @param {'content' | 'ui' | 'heading'} category
|
66
|
+
* Text category to generate styles for
|
67
|
+
*
|
68
|
+
* @returns {{[key: string]: [string, {lineHeight: number}]}}
|
69
|
+
* Generated text styles in Tailwind format
|
70
|
+
*
|
71
|
+
* @throws {Error} If a size has an invalid size or lineHeight
|
72
|
+
*
|
73
|
+
* @example
|
74
|
+
* const TEXT_CONTENT_SIZES = {
|
75
|
+
* sm: { size: 16, lineHeight: 1.5 },
|
76
|
+
* base: { size: 20, lineHeight: 1.5 },
|
77
|
+
* lg: { size: 24, lineHeight: 1.4 }
|
78
|
+
* };
|
79
|
+
*
|
80
|
+
* generateTextStyles(TEXT_CONTENT_SIZES, 'content');
|
81
|
+
* // Returns:
|
82
|
+
* // {
|
83
|
+
* // 'content-sm':
|
84
|
+
* // ['calc(16px * var(--scale-text-content))', { lineHeight: 1.5 }],
|
85
|
+
* // 'content-base':
|
86
|
+
* // ['calc(20px * var(--scale-text-content))', { lineHeight: 1.5 }],
|
87
|
+
* // 'content-lg':
|
88
|
+
* // ['calc(24px * var(--scale-text-content))', { lineHeight: 1.4 }]
|
89
|
+
* // }
|
90
|
+
*/
|
91
|
+
export function generateTextStyles(sizes: {
|
92
|
+
[key: string]: {
|
93
|
+
size: number;
|
94
|
+
lineHeight?: number;
|
95
|
+
};
|
96
|
+
}, category: "content" | "ui" | "heading"): {
|
97
|
+
[key: string]: [string, {
|
98
|
+
lineHeight: number;
|
99
|
+
}];
|
100
|
+
};
|
101
|
+
/**
|
102
|
+
* Generates border radius styles with UI scaling
|
103
|
+
*
|
104
|
+
* @param {{[key: string]: string | {size: number}}} sizes
|
105
|
+
* Set of radius sizes to generate, either as:
|
106
|
+
* - Object with size property (e.g., { size: 10 })
|
107
|
+
* - Direct string value (e.g., '0px', '9999px')
|
108
|
+
*
|
109
|
+
* @returns {Object.<string, string>}
|
110
|
+
* Generated border radius styles in Tailwind format
|
111
|
+
*
|
112
|
+
* @throws {Error} If a value has an invalid type
|
113
|
+
*
|
114
|
+
* @example
|
115
|
+
* const RADIUS_SIZES = {
|
116
|
+
* none: '0px',
|
117
|
+
* sm: { size: 10 },
|
118
|
+
* md: { size: 15 },
|
119
|
+
* full: '9999px'
|
120
|
+
* };
|
121
|
+
*
|
122
|
+
* generateBorderRadiusStyles(RADIUS_SIZES)
|
123
|
+
* // Returns:
|
124
|
+
* // {
|
125
|
+
* // 'none': '0px',
|
126
|
+
* // 'sm': 'calc(10px * var(--scale-ui))',
|
127
|
+
* // 'md': 'calc(15px * var(--scale-ui))',
|
128
|
+
* // 'full': '9999px'
|
129
|
+
* // }
|
130
|
+
*/
|
131
|
+
export function generateBorderRadiusStyles(sizes: {
|
132
|
+
[key: string]: string | {
|
133
|
+
size: number;
|
134
|
+
};
|
135
|
+
}): {
|
136
|
+
[x: string]: string;
|
137
|
+
};
|
138
|
+
/**
|
139
|
+
* Generates width styles for various CSS properties with UI scaling and explicit naming
|
140
|
+
*
|
141
|
+
* @param {{[key: string]: {size: number}}} sizes
|
142
|
+
* Set of width sizes to generate
|
143
|
+
*
|
144
|
+
* @param {string} [prefix='width']
|
145
|
+
* Prefix to add before each variant name (default: 'width')
|
146
|
+
*
|
147
|
+
* @param {string} scaleVar
|
148
|
+
* CSS variable to use for scaling (default: '--scale-ui')
|
149
|
+
*
|
150
|
+
* @returns {{[key: string]: string}}
|
151
|
+
* Generated width styles in Tailwind format
|
152
|
+
*
|
153
|
+
* @throws {Error} If a size has an invalid type
|
154
|
+
*
|
155
|
+
* @example
|
156
|
+
* const WIDTH_SIZES = {
|
157
|
+
* thin: { size: 1 },
|
158
|
+
* normal: { size: 2 },
|
159
|
+
* thick: { size: 4 }
|
160
|
+
* };
|
161
|
+
*
|
162
|
+
* generateWidthStyles(WIDTH_SIZES, 'width')
|
163
|
+
* // Returns:
|
164
|
+
* // {
|
165
|
+
* // 'width-thin': 'calc(1px * var(--scale-ui))',
|
166
|
+
* // 'width-normal': 'calc(2px * var(--scale-ui))',
|
167
|
+
* // 'width-thick': 'calc(4px * var(--scale-ui))'
|
168
|
+
* // }
|
169
|
+
*/
|
170
|
+
export function generateWidthStyles(sizes: {
|
171
|
+
[key: string]: {
|
172
|
+
size: number;
|
173
|
+
};
|
174
|
+
}, prefix?: string, scaleVar?: string): {
|
175
|
+
[key: string]: string;
|
176
|
+
};
|
@@ -0,0 +1,289 @@
|
|
1
|
+
/**
|
2
|
+
* Generates text-based spacing units with with different scaling
|
3
|
+
* units (ut, ct, ht)
|
4
|
+
*
|
5
|
+
* @param {number[]} values
|
6
|
+
* Array of pixel values to generate text-based spacing units for
|
7
|
+
*
|
8
|
+
* @returns {{[key: string]: string}}
|
9
|
+
* Generated text-based spacing units with ut, ct, and ht suffixes
|
10
|
+
*
|
11
|
+
* @throws {Error} If values is not an array or contains non-numeric values
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* generateTextBasedSpacing([1, 2, 4, 8])
|
15
|
+
* // Returns:
|
16
|
+
* // {
|
17
|
+
* // '1ut': 'calc(1px * var(--scale-text-ui))',
|
18
|
+
* // '2ut': 'calc(2px * var(--scale-text-ui))',
|
19
|
+
* // '1ct': 'calc(1px * var(--scale-text-content))',
|
20
|
+
* // '2ct': 'calc(2px * var(--scale-text-content))',
|
21
|
+
* // '1ht': 'calc(1px * var(--scale-text-heading))',
|
22
|
+
* // '2ht': 'calc(2px * var(--scale-text-heading))'
|
23
|
+
* // }
|
24
|
+
*/
|
25
|
+
export function generateTextBasedSpacing(values) {
|
26
|
+
if (!Array.isArray(values)) {
|
27
|
+
throw new Error('values must be an array');
|
28
|
+
}
|
29
|
+
|
30
|
+
return values.reduce((units, value) => {
|
31
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
32
|
+
throw new Error(`Invalid spacing value: ${value}. Must be a number.`);
|
33
|
+
}
|
34
|
+
|
35
|
+
// Generate UI text spacing units
|
36
|
+
units[`${value}ut`] = `calc(${value}px * var(--scale-text-ui))`;
|
37
|
+
|
38
|
+
// Generate content text spacing units
|
39
|
+
units[`${value}ct`] = `calc(${value}px * var(--scale-text-content))`;
|
40
|
+
|
41
|
+
// Generate heading text spacing units
|
42
|
+
units[`${value}ht`] = `calc(${value}px * var(--scale-text-heading))`;
|
43
|
+
|
44
|
+
return units;
|
45
|
+
}, {});
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Generates viewport-based spacing units with different scaling
|
50
|
+
* units (p, vp, wp, hp)
|
51
|
+
*
|
52
|
+
* @param {number[]} values
|
53
|
+
* Array of pixel values to generate viewport-based spacing units for
|
54
|
+
*
|
55
|
+
* @returns {Object.<string, string>}
|
56
|
+
* Generated viewport-based spacing units:
|
57
|
+
* - p: UI points (clamped scaling)
|
58
|
+
* - vp: Viewport points (min of width/height)
|
59
|
+
* - wp: Width points
|
60
|
+
* - hp: Height points
|
61
|
+
*
|
62
|
+
* @throws {Error} If values is not an array or contains non-numeric values
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
* generateViewportBasedSpacing([1, 2, 4])
|
66
|
+
* // Returns:
|
67
|
+
* // {
|
68
|
+
* // '1p': 'calc(1px * var(--scale-ui))',
|
69
|
+
* // '1vp': 'calc(1px * var(--scale-viewport))',
|
70
|
+
* // '1wp': 'calc(1px * var(--scale-w))',
|
71
|
+
* // '1hp': 'calc(1px * var(--scale-h))'
|
72
|
+
* // }
|
73
|
+
*/
|
74
|
+
export function generateViewportBasedSpacing(values) {
|
75
|
+
if (!Array.isArray(values)) {
|
76
|
+
throw new Error('values must be an array');
|
77
|
+
}
|
78
|
+
|
79
|
+
return values.reduce((units, value) => {
|
80
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
81
|
+
throw new Error(`Invalid spacing value: ${value}. Must be a number.`);
|
82
|
+
}
|
83
|
+
|
84
|
+
// Viewport points (min of width/height)
|
85
|
+
units[`${value}vp`] = `calc(${value}px * var(--scale-viewport))`;
|
86
|
+
// Width points
|
87
|
+
units[`${value}wp`] = `calc(${value}px * var(--scale-w))`;
|
88
|
+
// Height points
|
89
|
+
units[`${value}hp`] = `calc(${value}px * var(--scale-h))`;
|
90
|
+
// UI points
|
91
|
+
units[`${value}p`] = `calc(${value}px * var(--scale-ui))`;
|
92
|
+
return units;
|
93
|
+
}, {});
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Generates semantic text style definitions for a specific text category
|
98
|
+
* (content, UI, or heading). Each style includes a scaled font size and
|
99
|
+
* line height.
|
100
|
+
*
|
101
|
+
* @param {{[key: string]: {size: number, lineHeight?: number}}} sizes
|
102
|
+
* Set of text sizes to generate styles for
|
103
|
+
*
|
104
|
+
* @param {'content' | 'ui' | 'heading'} category
|
105
|
+
* Text category to generate styles for
|
106
|
+
*
|
107
|
+
* @returns {{[key: string]: [string, {lineHeight: number}]}}
|
108
|
+
* Generated text styles in Tailwind format
|
109
|
+
*
|
110
|
+
* @throws {Error} If a size has an invalid size or lineHeight
|
111
|
+
*
|
112
|
+
* @example
|
113
|
+
* const TEXT_CONTENT_SIZES = {
|
114
|
+
* sm: { size: 16, lineHeight: 1.5 },
|
115
|
+
* base: { size: 20, lineHeight: 1.5 },
|
116
|
+
* lg: { size: 24, lineHeight: 1.4 }
|
117
|
+
* };
|
118
|
+
*
|
119
|
+
* generateTextStyles(TEXT_CONTENT_SIZES, 'content');
|
120
|
+
* // Returns:
|
121
|
+
* // {
|
122
|
+
* // 'content-sm':
|
123
|
+
* // ['calc(16px * var(--scale-text-content))', { lineHeight: 1.5 }],
|
124
|
+
* // 'content-base':
|
125
|
+
* // ['calc(20px * var(--scale-text-content))', { lineHeight: 1.5 }],
|
126
|
+
* // 'content-lg':
|
127
|
+
* // ['calc(24px * var(--scale-text-content))', { lineHeight: 1.4 }]
|
128
|
+
* // }
|
129
|
+
*/
|
130
|
+
export function generateTextStyles(sizes, category) {
|
131
|
+
if (!sizes || typeof sizes !== 'object') {
|
132
|
+
throw new Error('sizes must be an object');
|
133
|
+
}
|
134
|
+
|
135
|
+
if (!['content', 'ui', 'heading'].includes(category)) {
|
136
|
+
throw new Error('category must be one of: content, ui, heading');
|
137
|
+
}
|
138
|
+
|
139
|
+
return Object.entries(sizes).reduce((result, [variant, config]) => {
|
140
|
+
// Validate config
|
141
|
+
if (!config || typeof config !== 'object') {
|
142
|
+
throw new Error(
|
143
|
+
`Invalid size config for "${variant}": must be an object`
|
144
|
+
);
|
145
|
+
}
|
146
|
+
|
147
|
+
if (typeof config.size !== 'number') {
|
148
|
+
throw new Error(
|
149
|
+
`Invalid size for "${category}-${variant}": must be a number`
|
150
|
+
);
|
151
|
+
}
|
152
|
+
|
153
|
+
if (
|
154
|
+
config.lineHeight !== undefined &&
|
155
|
+
typeof config.lineHeight !== 'number'
|
156
|
+
) {
|
157
|
+
throw new Error(
|
158
|
+
`Invalid lineHeight for "${category}-${variant}": must be a number`
|
159
|
+
);
|
160
|
+
}
|
161
|
+
|
162
|
+
const { size, lineHeight = 1.5 } = config;
|
163
|
+
|
164
|
+
result[`${category}-${variant}`] = [
|
165
|
+
`calc(${size}px * var(--scale-text-${category}))`,
|
166
|
+
{ lineHeight }
|
167
|
+
];
|
168
|
+
|
169
|
+
return result;
|
170
|
+
}, {});
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Generates border radius styles with UI scaling
|
175
|
+
*
|
176
|
+
* @param {{[key: string]: string | {size: number}}} sizes
|
177
|
+
* Set of radius sizes to generate, either as:
|
178
|
+
* - Object with size property (e.g., { size: 10 })
|
179
|
+
* - Direct string value (e.g., '0px', '9999px')
|
180
|
+
*
|
181
|
+
* @returns {Object.<string, string>}
|
182
|
+
* Generated border radius styles in Tailwind format
|
183
|
+
*
|
184
|
+
* @throws {Error} If a value has an invalid type
|
185
|
+
*
|
186
|
+
* @example
|
187
|
+
* const RADIUS_SIZES = {
|
188
|
+
* none: '0px',
|
189
|
+
* sm: { size: 10 },
|
190
|
+
* md: { size: 15 },
|
191
|
+
* full: '9999px'
|
192
|
+
* };
|
193
|
+
*
|
194
|
+
* generateBorderRadiusStyles(RADIUS_SIZES)
|
195
|
+
* // Returns:
|
196
|
+
* // {
|
197
|
+
* // 'none': '0px',
|
198
|
+
* // 'sm': 'calc(10px * var(--scale-ui))',
|
199
|
+
* // 'md': 'calc(15px * var(--scale-ui))',
|
200
|
+
* // 'full': '9999px'
|
201
|
+
* // }
|
202
|
+
*/
|
203
|
+
export function generateBorderRadiusStyles(sizes) {
|
204
|
+
if (!sizes || typeof sizes !== 'object') {
|
205
|
+
throw new Error('sizes must be an object');
|
206
|
+
}
|
207
|
+
|
208
|
+
return Object.entries(sizes).reduce((result, [variant, value]) => {
|
209
|
+
if (typeof value === 'object' && value !== null) {
|
210
|
+
// Handle {size: 10} format
|
211
|
+
if (typeof value.size !== 'number') {
|
212
|
+
throw new Error(
|
213
|
+
`Invalid radius size for "${variant}": size must be a number`
|
214
|
+
);
|
215
|
+
}
|
216
|
+
result[variant] = `calc(${value.size}px * var(--scale-ui))`;
|
217
|
+
} else if (typeof value === 'string') {
|
218
|
+
// Handle direct strings (like '0px' or '9999px')
|
219
|
+
result[variant] = value;
|
220
|
+
} else {
|
221
|
+
throw new Error(
|
222
|
+
`Invalid radius value for "${variant}": ` +
|
223
|
+
`must be an object with size property or a string`
|
224
|
+
);
|
225
|
+
}
|
226
|
+
return result;
|
227
|
+
}, {});
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Generates width styles for various CSS properties with UI scaling and explicit naming
|
232
|
+
*
|
233
|
+
* @param {{[key: string]: {size: number}}} sizes
|
234
|
+
* Set of width sizes to generate
|
235
|
+
*
|
236
|
+
* @param {string} [prefix='width']
|
237
|
+
* Prefix to add before each variant name (default: 'width')
|
238
|
+
*
|
239
|
+
* @param {string} scaleVar
|
240
|
+
* CSS variable to use for scaling (default: '--scale-ui')
|
241
|
+
*
|
242
|
+
* @returns {{[key: string]: string}}
|
243
|
+
* Generated width styles in Tailwind format
|
244
|
+
*
|
245
|
+
* @throws {Error} If a size has an invalid type
|
246
|
+
*
|
247
|
+
* @example
|
248
|
+
* const WIDTH_SIZES = {
|
249
|
+
* thin: { size: 1 },
|
250
|
+
* normal: { size: 2 },
|
251
|
+
* thick: { size: 4 }
|
252
|
+
* };
|
253
|
+
*
|
254
|
+
* generateWidthStyles(WIDTH_SIZES, 'width')
|
255
|
+
* // Returns:
|
256
|
+
* // {
|
257
|
+
* // 'width-thin': 'calc(1px * var(--scale-ui))',
|
258
|
+
* // 'width-normal': 'calc(2px * var(--scale-ui))',
|
259
|
+
* // 'width-thick': 'calc(4px * var(--scale-ui))'
|
260
|
+
* // }
|
261
|
+
*/
|
262
|
+
export function generateWidthStyles(
|
263
|
+
sizes,
|
264
|
+
prefix = 'width',
|
265
|
+
scaleVar = '--scale-ui'
|
266
|
+
) {
|
267
|
+
if (!sizes || typeof sizes !== 'object') {
|
268
|
+
throw new Error('sizes must be an object');
|
269
|
+
}
|
270
|
+
|
271
|
+
return Object.entries(sizes).reduce((result, [variant, value]) => {
|
272
|
+
if (typeof value === 'object' && value !== null) {
|
273
|
+
if (typeof value.size !== 'number') {
|
274
|
+
throw new Error(
|
275
|
+
`Invalid width size for "${variant}": size must be a number`
|
276
|
+
);
|
277
|
+
}
|
278
|
+
|
279
|
+
result[`${prefix}${prefix.length ? '-' : ''}${variant}`] =
|
280
|
+
`calc(${value.size}px * var(${scaleVar}))`;
|
281
|
+
} else {
|
282
|
+
throw new Error(
|
283
|
+
`Invalid width value for "${variant}": ` +
|
284
|
+
`must be an object with size property`
|
285
|
+
);
|
286
|
+
}
|
287
|
+
return result;
|
288
|
+
}, {});
|
289
|
+
}
|
package/dist/util/http/index.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
// AbortError,
|
6
6
|
// TimeoutError,
|
7
7
|
// TypeOrValueError
|
8
|
-
// } from '
|
8
|
+
// } from '$lib/constants/errors/index.js';
|
9
9
|
|
10
10
|
// import { setRequestHeaders } from './headers.js';
|
11
11
|
// import { getErrorFromResponse } from './errors.js';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hkdigital/lib-sveltekit",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.2",
|
4
4
|
"author": {
|
5
5
|
"name": "HKdigital",
|
6
6
|
"url": "https://hkdigital.nl"
|
@@ -63,37 +63,37 @@
|
|
63
63
|
"valibot": "^0.42.1"
|
64
64
|
},
|
65
65
|
"devDependencies": {
|
66
|
-
"@playwright/test": "^1.
|
66
|
+
"@playwright/test": "^1.50.1",
|
67
67
|
"@skeletonlabs/skeleton": "3.0.0-next.2",
|
68
68
|
"@skeletonlabs/skeleton-svelte": "1.0.0-next.4",
|
69
69
|
"@steeze-ui/heroicons": "^2.4.2",
|
70
|
-
"@sveltejs/adapter-auto": "^
|
71
|
-
"@sveltejs/package": "^2.3.
|
70
|
+
"@sveltejs/adapter-auto": "^4.0.0",
|
71
|
+
"@sveltejs/package": "^2.3.10",
|
72
72
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
73
73
|
"@tailwindcss/typography": "^0.5.16",
|
74
74
|
"@types/eslint": "^9.6.1",
|
75
75
|
"autoprefixer": "^10.4.20",
|
76
|
-
"eslint": "^9.
|
77
|
-
"eslint-config-prettier": "^10.0.
|
78
|
-
"eslint-plugin-svelte": "^
|
79
|
-
"globals": "^
|
76
|
+
"eslint": "^9.21.0",
|
77
|
+
"eslint-config-prettier": "^10.0.2",
|
78
|
+
"eslint-plugin-svelte": "^3.0.2",
|
79
|
+
"globals": "^16.0.0",
|
80
80
|
"jsdom": "^26.0.0",
|
81
|
-
"postcss": "^8.5.
|
81
|
+
"postcss": "^8.5.3",
|
82
82
|
"postcss-mixins": "^11.0.3",
|
83
|
-
"prettier": "^3.
|
83
|
+
"prettier": "^3.5.3",
|
84
84
|
"prettier-plugin-svelte": "^3.3.3",
|
85
|
-
"prettier-plugin-tailwindcss": "^0.6.
|
86
|
-
"publint": "^0.3.
|
87
|
-
"standardized-audio-context-mock": "^9.7.
|
88
|
-
"svelte": "^5.
|
85
|
+
"prettier-plugin-tailwindcss": "^0.6.11",
|
86
|
+
"publint": "^0.3.7",
|
87
|
+
"standardized-audio-context-mock": "^9.7.16",
|
88
|
+
"svelte": "^5.20.5",
|
89
89
|
"svelte-check": "^4.1.4",
|
90
90
|
"tailwindcss": "^3.4.17",
|
91
|
-
"typescript": "^5.
|
92
|
-
"vite": "^6.0
|
91
|
+
"typescript": "^5.8.2",
|
92
|
+
"vite": "^6.2.0",
|
93
93
|
"vite-imagetools": "^7.0.5",
|
94
|
-
"vitest": "^
|
94
|
+
"vitest": "^3.0.7"
|
95
95
|
},
|
96
96
|
"dependencies": {
|
97
|
-
"zod": "^3.24.
|
97
|
+
"zod": "^3.24.2"
|
98
98
|
}
|
99
99
|
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
<script>
|
2
|
-
/**
|
3
|
-
* @type {{
|
4
|
-
* base?: string,
|
5
|
-
* bg?: string,
|
6
|
-
* variant?: string,
|
7
|
-
* classes?: string,
|
8
|
-
* role?: 'primary' | 'secondary',
|
9
|
-
* children: import('svelte').Snippet,
|
10
|
-
* [key: string]: any
|
11
|
-
* }}
|
12
|
-
*/
|
13
|
-
const {
|
14
|
-
// Style
|
15
|
-
base,
|
16
|
-
bg,
|
17
|
-
variant,
|
18
|
-
classes,
|
19
|
-
|
20
|
-
role = 'primary',
|
21
|
-
|
22
|
-
// Snippets
|
23
|
-
children,
|
24
|
-
|
25
|
-
// Attributes
|
26
|
-
...attrs
|
27
|
-
} = $props();
|
28
|
-
</script>
|
29
|
-
|
30
|
-
<button
|
31
|
-
data-button="plain-button"
|
32
|
-
type="button"
|
33
|
-
class="{base} {bg} {variant} {classes} role-{role}"
|
34
|
-
{...attrs}
|
35
|
-
>
|
36
|
-
<p class="p">{@render children()}</p>
|
37
|
-
</button>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
export default PlainButton;
|
2
|
-
declare const PlainButton: import("svelte").Component<{
|
3
|
-
[key: string]: any;
|
4
|
-
base?: string;
|
5
|
-
bg?: string;
|
6
|
-
variant?: string;
|
7
|
-
classes?: string;
|
8
|
-
role?: "primary" | "secondary";
|
9
|
-
children: import("svelte").Snippet;
|
10
|
-
}, {}, "">;
|