@hkdigital/lib-core 0.3.13 → 0.3.15
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/README.md +12 -3
- package/dist/config/README.md +4 -4
- package/dist/constants/regexp/url.js +0 -2
- package/dist/design/README.md +136 -66
- package/dist/design/config/{design-config.d.ts → design-tokens.d.ts} +23 -10
- package/dist/design/config/design-tokens.js +107 -0
- package/dist/design/generators/index.d.ts +51 -0
- package/dist/design/generators/index.js +89 -0
- package/dist/design/index.d.ts +3 -4
- package/dist/design/index.js +24 -41
- package/dist/design/plugins/skeleton.d.ts +4 -2
- package/dist/design/plugins/skeleton.js +3 -2
- package/dist/design/themes/hkdev/components/buttons/button-text.css +19 -25
- package/dist/design/utils/clamp.js +1 -1
- package/dist/design/utils/root-vars.d.ts +50 -39
- package/dist/design/utils/root-vars.js +127 -29
- package/dist/logging/index.d.ts +2 -3
- package/dist/logging/index.js +3 -4
- package/dist/logging/internal/adapters/console.js +3 -7
- package/dist/logging/internal/adapters/pino.js +21 -11
- package/dist/logging/internal/factories/client.js +1 -1
- package/dist/logging/internal/factories/server.js +1 -1
- package/dist/logging/internal/logger/Logger.d.ts +2 -2
- package/dist/logging/internal/logger/Logger.js +3 -3
- package/dist/services/index.d.ts +0 -2
- package/dist/services/index.js +0 -3
- package/dist/services/typedef.d.ts +2 -0
- package/dist/services/typedef.js +2 -0
- package/dist/typedef/index.d.ts +0 -1
- package/dist/typedef/index.js +0 -1
- package/dist/ui/components/game-box/GameBox.svelte +1 -1
- package/dist/ui/primitives/buttons/button-text/TextButton.svelte +1 -1
- package/dist/ui/primitives/debug/debug-panel-design-scaling/DebugPanelDesignScaling.svelte +7 -7
- package/dist/ui/primitives/index.d.ts +1 -0
- package/dist/ui/primitives/index.js +1 -2
- package/package.json +2 -2
- package/dist/design/config/design-config.js +0 -73
- package/dist/design/tailwind-theme-extend.d.ts +0 -23
- package/dist/design/tailwind-theme-extend.js +0 -158
- package/dist/logging/internal/factories/universal.d.ts +0 -9
- package/dist/logging/internal/factories/universal.js +0 -22
- /package/dist/logging/{internal/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/logging/{internal/constants.js → constants.js} +0 -0
- /package/dist/logging/{internal/typedef.d.ts → typedef.d.ts} +0 -0
- /package/dist/logging/{internal/typedef.js → typedef.js} +0 -0
|
@@ -1,3 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate complete Tailwind CSS theme extensions from design configuration
|
|
3
|
+
*
|
|
4
|
+
* Takes design configuration objects and generates complete Tailwind theme extensions.
|
|
5
|
+
* Users can define their own design-config.js with custom values and pass them here.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} designConfig - Design configuration object
|
|
8
|
+
* @param {Object} designConfig.TEXT_POINT_SIZES - Array of text point sizes for spacing
|
|
9
|
+
* @param {Object} designConfig.VIEWPORT_POINT_SIZES - Array of viewport point sizes
|
|
10
|
+
* @param {Object} designConfig.TEXT_BASE_SIZES - Base text size configurations
|
|
11
|
+
* @param {Object} designConfig.TEXT_HEADING_SIZES - Heading text size configurations
|
|
12
|
+
* @param {Object} designConfig.TEXT_UI_SIZES - UI text size configurations
|
|
13
|
+
* @param {Object} designConfig.RADIUS_SIZES - Border radius configurations
|
|
14
|
+
* @param {Object} designConfig.BORDER_WIDTH_SIZES - Border width configurations
|
|
15
|
+
* @param {Object} designConfig.STROKE_WIDTH_SIZES - Stroke width configurations
|
|
16
|
+
*
|
|
17
|
+
* @returns {Object} Complete Tailwind theme extension object
|
|
18
|
+
*
|
|
19
|
+
* @example Basic usage
|
|
20
|
+
* ```javascript
|
|
21
|
+
* // your-project/src/lib/design/design-config.js
|
|
22
|
+
* export const DESIGN = { width: 1440, height: 900 };
|
|
23
|
+
* export const TEXT_BASE_SIZES = {
|
|
24
|
+
* sm: { size: 12, lineHeight: 1.3 },
|
|
25
|
+
* md: { size: 16, lineHeight: 1.4 }
|
|
26
|
+
* };
|
|
27
|
+
* // ... other exports
|
|
28
|
+
*
|
|
29
|
+
* // your-project/tailwind.config.js
|
|
30
|
+
* import { generateTailwindThemeExtensions } from '@hkdigital/lib-core/design/index.js';
|
|
31
|
+
* import { customUtilitiesPlugin } from '@hkdigital/lib-core/design/index.js';
|
|
32
|
+
* import * as designConfig from './src/lib/design/design-config.js';
|
|
33
|
+
*
|
|
34
|
+
* export default {
|
|
35
|
+
* theme: {
|
|
36
|
+
* extend: generateTailwindThemeExtensions(designConfig)
|
|
37
|
+
* },
|
|
38
|
+
* plugins: [customUtilitiesPlugin]
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export function generateTailwindThemeExtensions({
|
|
43
|
+
TEXT_POINT_SIZES,
|
|
44
|
+
VIEWPORT_POINT_SIZES,
|
|
45
|
+
TEXT_BASE_SIZES,
|
|
46
|
+
TEXT_HEADING_SIZES,
|
|
47
|
+
TEXT_UI_SIZES,
|
|
48
|
+
RADIUS_SIZES,
|
|
49
|
+
BORDER_WIDTH_SIZES,
|
|
50
|
+
STROKE_WIDTH_SIZES
|
|
51
|
+
}) {
|
|
52
|
+
const textBasedSpacing = generateTextBasedSpacing(TEXT_POINT_SIZES);
|
|
53
|
+
const viewportBasedSpacing = generateViewportBasedSpacing(VIEWPORT_POINT_SIZES);
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
spacing: {
|
|
57
|
+
...viewportBasedSpacing,
|
|
58
|
+
...textBasedSpacing
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
fontSize: {
|
|
62
|
+
...textBasedSpacing,
|
|
63
|
+
...generateTextStyles(TEXT_BASE_SIZES, 'base'),
|
|
64
|
+
...generateTextStyles(TEXT_HEADING_SIZES, 'heading'),
|
|
65
|
+
...generateTextStyles(TEXT_UI_SIZES, 'ui')
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
borderRadius: {
|
|
69
|
+
...generateBorderRadiusStyles(RADIUS_SIZES)
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
borderWidth: {
|
|
73
|
+
...generateWidthStyles(BORDER_WIDTH_SIZES, 'width')
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
strokeWidth: {
|
|
77
|
+
...generateWidthStyles(STROKE_WIDTH_SIZES, 'width')
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
outlineWidth: {
|
|
81
|
+
...generateWidthStyles(STROKE_WIDTH_SIZES, '')
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
outlineOffset: {
|
|
85
|
+
...generateWidthStyles(STROKE_WIDTH_SIZES, '')
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
1
90
|
/**
|
|
2
91
|
* Generates text-based spacing units with with different scaling
|
|
3
92
|
* units (ut, bt, ht)
|
package/dist/design/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
export { designTokens } from "./config/design-tokens.js";
|
|
1
2
|
export { customUtilitiesPlugin } from "./plugins/skeleton.js";
|
|
2
3
|
export { toStateClasses } from "./utils/states.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { spacing, fontSize, borderRadius, borderWidth, strokeWidth, outlineWidth, outlineOffset } from "./tailwind-theme-extend.js";
|
|
6
|
-
export { rootDesignVarsHTML, getRootCssDesignWidth, getRootCssDesignHeight, getAllRootScalingVars } from "./utils/root-vars.js";
|
|
4
|
+
export { generateTailwindThemeExtensions, generateTextBasedSpacing, generateViewportBasedSpacing, generateTextStyles, generateBorderRadiusStyles, generateWidthStyles } from "./generators/index.js";
|
|
5
|
+
export { designTokensToRootCssVars, getRootCssDesignWidth, getRootCssDesignHeight, getAllRootScalingVars } from "./utils/root-vars.js";
|
|
7
6
|
export { getClampParams, clamp } from "./utils/clamp.js";
|
|
8
7
|
export { enableContainerScaling, enableScalingUI } from "./utils/scaling.js";
|
package/dist/design/index.js
CHANGED
|
@@ -2,53 +2,49 @@
|
|
|
2
2
|
* @fileoverview HKdigital Core Design System
|
|
3
3
|
*
|
|
4
4
|
* This module provides a comprehensive design system for building consistent,
|
|
5
|
-
* responsive interfaces. It includes
|
|
6
|
-
* and
|
|
5
|
+
* responsive interfaces. It includes design tokens, generator functions,
|
|
6
|
+
* and utility functions for creating custom Tailwind theme extensions.
|
|
7
7
|
*
|
|
8
|
-
* @example Basic usage
|
|
8
|
+
* @example Basic usage with default tokens
|
|
9
9
|
* ```javascript
|
|
10
|
-
* import {
|
|
10
|
+
* import { generateTailwindThemeExtensions, designTokens, customUtilitiesPlugin } from '@hkdigital/lib-core/design/index.js';
|
|
11
|
+
*
|
|
12
|
+
* const themeExtensions = generateTailwindThemeExtensions(designTokens);
|
|
11
13
|
*
|
|
12
14
|
* export default {
|
|
13
15
|
* theme: {
|
|
14
|
-
* extend:
|
|
16
|
+
* extend: themeExtensions
|
|
15
17
|
* },
|
|
16
18
|
* plugins: [customUtilitiesPlugin]
|
|
17
19
|
* };
|
|
18
20
|
* ```
|
|
19
21
|
*
|
|
20
|
-
* @example
|
|
22
|
+
* @example Custom design tokens
|
|
21
23
|
* ```javascript
|
|
22
|
-
* import {
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* TEXT_POINT_SIZES
|
|
26
|
-
*
|
|
24
|
+
* import { generateTailwindThemeExtensions } from '@hkdigital/lib-core/design/index.js';
|
|
25
|
+
*
|
|
26
|
+
* const myTokens = {
|
|
27
|
+
* TEXT_POINT_SIZES: [4, 8, 12, 16, 24],
|
|
28
|
+
* TEXT_BASE_SIZES: {
|
|
29
|
+
* sm: { size: 12, lineHeight: 1.3 }
|
|
30
|
+
* }
|
|
31
|
+
* // ... other tokens
|
|
32
|
+
* };
|
|
27
33
|
*
|
|
28
|
-
* const
|
|
34
|
+
* const themeExtensions = generateTailwindThemeExtensions(myTokens);
|
|
29
35
|
* ```
|
|
30
36
|
*/
|
|
31
37
|
|
|
32
|
-
// ===
|
|
33
|
-
//
|
|
38
|
+
// === Design Tokens ===
|
|
39
|
+
// Default design tokens - projects can import and customize for their own design systems
|
|
34
40
|
|
|
35
|
-
export {
|
|
36
|
-
DESIGN,
|
|
37
|
-
CLAMPING,
|
|
38
|
-
TEXT_POINT_SIZES,
|
|
39
|
-
VIEWPORT_POINT_SIZES,
|
|
40
|
-
TEXT_BASE_SIZES,
|
|
41
|
-
TEXT_HEADING_SIZES,
|
|
42
|
-
TEXT_UI_SIZES,
|
|
43
|
-
RADIUS_SIZES,
|
|
44
|
-
BORDER_WIDTH_SIZES,
|
|
45
|
-
STROKE_WIDTH_SIZES
|
|
46
|
-
} from './config/design-config.js';
|
|
41
|
+
export { designTokens } from './config/design-tokens.js';
|
|
47
42
|
|
|
48
43
|
// === Generator Functions ===
|
|
49
44
|
// Essential tools for projects to build custom Tailwind extensions
|
|
50
45
|
|
|
51
46
|
export {
|
|
47
|
+
generateTailwindThemeExtensions,
|
|
52
48
|
generateTextBasedSpacing,
|
|
53
49
|
generateViewportBasedSpacing,
|
|
54
50
|
generateTextStyles,
|
|
@@ -56,19 +52,6 @@ export {
|
|
|
56
52
|
generateWidthStyles
|
|
57
53
|
} from './generators/index.js';
|
|
58
54
|
|
|
59
|
-
// === Ready-to-use Tailwind Extensions ===
|
|
60
|
-
// Built using default configuration - projects can use directly or as reference
|
|
61
|
-
|
|
62
|
-
export {
|
|
63
|
-
spacing,
|
|
64
|
-
fontSize,
|
|
65
|
-
borderRadius,
|
|
66
|
-
borderWidth,
|
|
67
|
-
strokeWidth,
|
|
68
|
-
outlineWidth,
|
|
69
|
-
outlineOffset
|
|
70
|
-
} from './tailwind-theme-extend.js';
|
|
71
|
-
|
|
72
55
|
// === Plugins & Utilities ===
|
|
73
56
|
// Framework integration tools
|
|
74
57
|
|
|
@@ -78,7 +61,7 @@ export { customUtilitiesPlugin } from './plugins/skeleton.js';
|
|
|
78
61
|
// Essential utility functions for design system implementation
|
|
79
62
|
|
|
80
63
|
export {
|
|
81
|
-
|
|
64
|
+
designTokensToRootCssVars,
|
|
82
65
|
getRootCssDesignWidth,
|
|
83
66
|
getRootCssDesignHeight,
|
|
84
67
|
getAllRootScalingVars
|
|
@@ -94,4 +77,4 @@ export { toStateClasses } from './utils/states.js';
|
|
|
94
77
|
export {
|
|
95
78
|
enableContainerScaling,
|
|
96
79
|
enableScalingUI
|
|
97
|
-
} from './utils/scaling.js';
|
|
80
|
+
} from './utils/scaling.js';
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
* ]
|
|
34
34
|
* };
|
|
35
35
|
*
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
36
|
+
* @param {object} _ - Tailwind plugin API
|
|
37
|
+
* @param {function} _.addUtilities - Function to add utilities
|
|
38
|
+
* @param {*} _.theme
|
|
38
39
|
*/
|
|
39
40
|
export function customUtilitiesPlugin({ addUtilities, theme }: {
|
|
40
41
|
addUtilities: Function;
|
|
42
|
+
theme: any;
|
|
41
43
|
}): void;
|
|
@@ -33,8 +33,9 @@
|
|
|
33
33
|
* ]
|
|
34
34
|
* };
|
|
35
35
|
*
|
|
36
|
-
* @param {
|
|
37
|
-
* @param {
|
|
36
|
+
* @param {object} _ - Tailwind plugin API
|
|
37
|
+
* @param {function} _.addUtilities - Function to add utilities
|
|
38
|
+
* @param {*} _.theme
|
|
38
39
|
*/
|
|
39
40
|
export function customUtilitiesPlugin({ addUtilities, theme }) {
|
|
40
41
|
const fontFamilyUtilities = {
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
@define-mixin component-button-text {
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
/* Type-based styling for text buttons */
|
|
3
|
+
[data-component='button'][data-type='text'] {
|
|
4
|
+
/* Typography settings */
|
|
5
|
+
@apply font-ui text-ui-md;
|
|
6
|
+
@apply uppercase;
|
|
7
|
+
@apply whitespace-nowrap;
|
|
4
8
|
|
|
5
|
-
/*
|
|
6
|
-
[data-component="button"][data-type="text"] {
|
|
9
|
+
/* Size settings */
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
@apply
|
|
10
|
-
@apply
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
&[data-size="md"] {
|
|
16
|
-
@apply rounded-sm;
|
|
17
|
-
@apply py-8ut px-16ut;
|
|
18
|
-
min-width: var(--btn-min-width);
|
|
19
|
-
min-height: var(--btn-min-height);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/* Role-specific text adjustments */
|
|
23
|
-
&[data-role="primary"] {
|
|
24
|
-
@apply font-extrabold;
|
|
25
|
-
}
|
|
11
|
+
&[data-size='md'] {
|
|
12
|
+
@apply rounded-sm;
|
|
13
|
+
@apply py-8ut px-16ut;
|
|
14
|
+
min-width: var(--btn-min-width);
|
|
15
|
+
min-height: var(--btn-min-height);
|
|
16
|
+
}
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
/* Role-specific text adjustments */
|
|
19
|
+
&[data-role='primary'] {
|
|
20
|
+
@apply font-extrabold;
|
|
30
21
|
}
|
|
31
22
|
|
|
23
|
+
&[data-role='secondary'] {
|
|
24
|
+
@apply font-bold;
|
|
25
|
+
}
|
|
32
26
|
}
|
|
@@ -1,60 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a complete HTML style tag with CSS custom properties for
|
|
3
|
-
* the design system based on provided configuration.
|
|
3
|
+
* the design system based on provided design tokens configuration.
|
|
4
4
|
*
|
|
5
|
-
* @param {Object}
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {number}
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {Object}
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {number}
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {number}
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {number}
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {number}
|
|
5
|
+
* @param {Object} designTokens - Complete design tokens object
|
|
6
|
+
* @param {Object} designTokens.DESIGN - Design dimensions configuration
|
|
7
|
+
* @param {number} designTokens.DESIGN.width - The design width in pixels
|
|
8
|
+
* @param {number} designTokens.DESIGN.height - The design height in pixels
|
|
9
|
+
* @param {Object} designTokens.CLAMPING - Scaling configuration parameters
|
|
10
|
+
* @param {Object} designTokens.CLAMPING.ui - UI clamping configuration
|
|
11
|
+
* @param {number} designTokens.CLAMPING.ui.min - Minimum UI scaling factor
|
|
12
|
+
* @param {number} designTokens.CLAMPING.ui.max - Maximum UI scaling factor
|
|
13
|
+
* @param {Object} designTokens.CLAMPING.textBase - Base text scaling configuration
|
|
14
|
+
* @param {number} designTokens.CLAMPING.textBase.min - Minimum base text scaling
|
|
15
|
+
* @param {number} designTokens.CLAMPING.textBase.max - Maximum base text scaling
|
|
16
|
+
* @param {Object} designTokens.CLAMPING.textHeading - Heading text clamping configuration
|
|
17
|
+
* @param {number} designTokens.CLAMPING.textHeading.min - Minimum heading text scaling
|
|
18
|
+
* @param {number} designTokens.CLAMPING.textHeading.max - Maximum heading text scaling
|
|
19
|
+
* @param {Object} designTokens.CLAMPING.textUi - UI text clamping configuration
|
|
20
|
+
* @param {number} designTokens.CLAMPING.textUi.min - Minimum UI text scaling
|
|
21
|
+
* @param {number} designTokens.CLAMPING.textUi.max - Maximum UI text scaling
|
|
21
22
|
*
|
|
22
23
|
* @returns {string} Complete HTML style tag with design system CSS variables
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* // +layout.svelte
|
|
26
27
|
* <script>
|
|
27
|
-
* import {
|
|
28
|
-
*
|
|
29
|
-
* import { rootDesignVarsHTML } from './root-vars.js';
|
|
28
|
+
* import { designTokens, designTokensToRootCssVars } from '@hkdigital/lib-core/design/index.js';
|
|
30
29
|
* </script>
|
|
31
30
|
*
|
|
32
31
|
* <svelte:head>
|
|
33
|
-
* {@html
|
|
32
|
+
* {@html designTokensToRootCssVars(designTokens)}
|
|
34
33
|
* </svelte:head>
|
|
35
34
|
*
|
|
36
35
|
* // Generates style tag for use in svelte:head
|
|
37
36
|
* // <style>:root { --design-width: 1920; ... }</style>
|
|
38
37
|
*/
|
|
39
|
-
export function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ui: {
|
|
44
|
-
min: number;
|
|
45
|
-
max: number;
|
|
46
|
-
};
|
|
47
|
-
textBase: {
|
|
48
|
-
min: number;
|
|
49
|
-
max: number;
|
|
38
|
+
export function designTokensToRootCssVars(designTokens: {
|
|
39
|
+
DESIGN: {
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
50
42
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
CLAMPING: {
|
|
44
|
+
ui: {
|
|
45
|
+
min: number;
|
|
46
|
+
max: number;
|
|
47
|
+
};
|
|
48
|
+
textBase: {
|
|
49
|
+
min: number;
|
|
50
|
+
max: number;
|
|
51
|
+
};
|
|
52
|
+
textHeading: {
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
};
|
|
56
|
+
textUi: {
|
|
57
|
+
min: number;
|
|
58
|
+
max: number;
|
|
59
|
+
};
|
|
58
60
|
};
|
|
59
61
|
}): string;
|
|
60
62
|
/**
|
|
@@ -75,3 +77,12 @@ export function getRootCssDesignHeight(): number;
|
|
|
75
77
|
* @returns {Object} An object containing all scaling factors
|
|
76
78
|
*/
|
|
77
79
|
export function getAllRootScalingVars(): any;
|
|
80
|
+
/**
|
|
81
|
+
* Extract a CSS variable value from document root
|
|
82
|
+
*
|
|
83
|
+
* @param {string} varName - CSS variable name without '--'
|
|
84
|
+
* @param {boolean} [useCache=false]
|
|
85
|
+
*
|
|
86
|
+
* @returns {any} Parsed value or default
|
|
87
|
+
*/
|
|
88
|
+
export function getRootCssVar(varName: string, useCache?: boolean): any;
|
|
@@ -1,48 +1,136 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* CSS Variables Utilities
|
|
3
|
+
* Copied from $lib/util/css/css-vars.js to make design system self-contained
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let cssVarCache = {};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Normalizes a CSS variable name to ensure it has the -- prefix
|
|
10
|
+
*
|
|
11
|
+
* @param {string} varName - The CSS variable name
|
|
12
|
+
* @returns {string} Normalized variable name with -- prefix
|
|
13
|
+
*/
|
|
14
|
+
function normalizeCssVarName(varName) {
|
|
15
|
+
if (typeof varName !== 'string') {
|
|
16
|
+
throw new Error('Variable name must be a string');
|
|
17
|
+
}
|
|
18
|
+
return varName.startsWith('--') ? varName : `--${varName}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Extract a CSS variable value from document root
|
|
23
|
+
*
|
|
24
|
+
* @param {string} varName - CSS variable name without '--'
|
|
25
|
+
* @param {boolean} [useCache=false]
|
|
26
|
+
*
|
|
27
|
+
* @returns {any} Parsed value or default
|
|
28
|
+
*/
|
|
29
|
+
function getRootCssVar(varName, useCache = false) {
|
|
30
|
+
if (cssVarCache[varName] !== undefined && useCache) {
|
|
31
|
+
return cssVarCache[varName];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Get computed style from document root
|
|
35
|
+
const rootStyle = getComputedStyle(document.documentElement);
|
|
36
|
+
const declaration = rootStyle.getPropertyValue(`--${varName}`).trim();
|
|
37
|
+
|
|
38
|
+
if (!declaration) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let result;
|
|
43
|
+
|
|
44
|
+
// Try to parse as number
|
|
45
|
+
if (!isNaN(parseFloat(declaration))) {
|
|
46
|
+
result = parseFloat(declaration);
|
|
47
|
+
} else {
|
|
48
|
+
// Return string value
|
|
49
|
+
result = declaration;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Cache the result
|
|
53
|
+
cssVarCache[varName] = result;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Sets a CSS variable in :root to a new value
|
|
59
|
+
*
|
|
60
|
+
* @param {string} varName - The CSS variable name (with or without --)
|
|
61
|
+
* @param {string|number} value - The new value to set
|
|
62
|
+
* @returns {boolean} True if successful, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
function setRootCssVar(varName, value) {
|
|
65
|
+
try {
|
|
66
|
+
if (varName === undefined || varName === null) {
|
|
67
|
+
throw new Error('Variable name cannot be null or undefined');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (value === undefined || value === null) {
|
|
71
|
+
throw new Error('Value cannot be null or undefined');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const normalizedName = normalizeCssVarName(varName);
|
|
75
|
+
|
|
76
|
+
// Convert to string if numeric
|
|
77
|
+
const formattedValue = typeof value === 'number' ? `${value}` : value;
|
|
78
|
+
|
|
79
|
+
document.documentElement.style.setProperty(normalizedName, formattedValue);
|
|
80
|
+
|
|
81
|
+
delete cssVarCache[varName];
|
|
82
|
+
|
|
83
|
+
return true;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error(`Error setting CSS variable ${varName}:`, error);
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
2
89
|
|
|
3
90
|
/**
|
|
4
91
|
* Generates a complete HTML style tag with CSS custom properties for
|
|
5
|
-
* the design system based on provided configuration.
|
|
92
|
+
* the design system based on provided design tokens configuration.
|
|
6
93
|
*
|
|
7
|
-
* @param {Object}
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {number}
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {Object}
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {number}
|
|
14
|
-
* @param {
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {number}
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {number}
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {number}
|
|
94
|
+
* @param {Object} designTokens - Complete design tokens object
|
|
95
|
+
* @param {Object} designTokens.DESIGN - Design dimensions configuration
|
|
96
|
+
* @param {number} designTokens.DESIGN.width - The design width in pixels
|
|
97
|
+
* @param {number} designTokens.DESIGN.height - The design height in pixels
|
|
98
|
+
* @param {Object} designTokens.CLAMPING - Scaling configuration parameters
|
|
99
|
+
* @param {Object} designTokens.CLAMPING.ui - UI clamping configuration
|
|
100
|
+
* @param {number} designTokens.CLAMPING.ui.min - Minimum UI scaling factor
|
|
101
|
+
* @param {number} designTokens.CLAMPING.ui.max - Maximum UI scaling factor
|
|
102
|
+
* @param {Object} designTokens.CLAMPING.textBase - Base text scaling configuration
|
|
103
|
+
* @param {number} designTokens.CLAMPING.textBase.min - Minimum base text scaling
|
|
104
|
+
* @param {number} designTokens.CLAMPING.textBase.max - Maximum base text scaling
|
|
105
|
+
* @param {Object} designTokens.CLAMPING.textHeading - Heading text clamping configuration
|
|
106
|
+
* @param {number} designTokens.CLAMPING.textHeading.min - Minimum heading text scaling
|
|
107
|
+
* @param {number} designTokens.CLAMPING.textHeading.max - Maximum heading text scaling
|
|
108
|
+
* @param {Object} designTokens.CLAMPING.textUi - UI text clamping configuration
|
|
109
|
+
* @param {number} designTokens.CLAMPING.textUi.min - Minimum UI text scaling
|
|
110
|
+
* @param {number} designTokens.CLAMPING.textUi.max - Maximum UI text scaling
|
|
23
111
|
*
|
|
24
112
|
* @returns {string} Complete HTML style tag with design system CSS variables
|
|
25
113
|
*
|
|
26
114
|
* @example
|
|
27
115
|
* // +layout.svelte
|
|
28
116
|
* <script>
|
|
29
|
-
* import {
|
|
30
|
-
*
|
|
31
|
-
* import { rootDesignVarsHTML } from './root-vars.js';
|
|
117
|
+
* import { designTokens, designTokensToRootCssVars } from '@hkdigital/lib-core/design/index.js';
|
|
32
118
|
* </script>
|
|
33
119
|
*
|
|
34
120
|
* <svelte:head>
|
|
35
|
-
* {@html
|
|
121
|
+
* {@html designTokensToRootCssVars(designTokens)}
|
|
36
122
|
* </svelte:head>
|
|
37
123
|
*
|
|
38
124
|
* // Generates style tag for use in svelte:head
|
|
39
125
|
* // <style>:root { --design-width: 1920; ... }</style>
|
|
40
126
|
*/
|
|
41
|
-
export function
|
|
127
|
+
export function designTokensToRootCssVars(designTokens) {
|
|
128
|
+
const { DESIGN, CLAMPING } = designTokens;
|
|
129
|
+
|
|
42
130
|
return `<style>:root {
|
|
43
131
|
/* Design dimensions */
|
|
44
|
-
--design-width: ${
|
|
45
|
-
--design-height: ${
|
|
132
|
+
--design-width: ${DESIGN.width};
|
|
133
|
+
--design-height: ${DESIGN.height};
|
|
46
134
|
|
|
47
135
|
/* Scaling factors */
|
|
48
136
|
--scale-w: 1;
|
|
@@ -52,10 +140,10 @@ export function rootDesignVarsHTML(design, clamping) {
|
|
|
52
140
|
--scale-viewport: 1;
|
|
53
141
|
|
|
54
142
|
/* Base clamping units */
|
|
55
|
-
--scale-ui: clamp(${
|
|
56
|
-
--scale-text-base: clamp(${
|
|
57
|
-
--scale-text-heading: clamp(${
|
|
58
|
-
--scale-text-ui: clamp(${
|
|
143
|
+
--scale-ui: clamp(${CLAMPING.ui.min}, var(--scale-viewport), ${CLAMPING.ui.max});
|
|
144
|
+
--scale-text-base: clamp(${CLAMPING.textBase.min}, var(--scale-viewport), ${CLAMPING.textBase.max});
|
|
145
|
+
--scale-text-heading: clamp(${CLAMPING.textHeading.min}, var(--scale-viewport), ${CLAMPING.textHeading.max});
|
|
146
|
+
--scale-text-ui: clamp(${CLAMPING.textUi.min}, var(--scale-viewport), ${CLAMPING.textUi.max});
|
|
59
147
|
}</style>`;
|
|
60
148
|
}
|
|
61
149
|
|
|
@@ -68,6 +156,16 @@ export function getRootCssDesignWidth() {
|
|
|
68
156
|
return getRootCssVar('design-width');
|
|
69
157
|
}
|
|
70
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Extract a CSS variable value from document root (exported for use by other design system utilities)
|
|
161
|
+
*
|
|
162
|
+
* @param {string} varName - CSS variable name without '--'
|
|
163
|
+
* @param {boolean} [useCache=false]
|
|
164
|
+
*
|
|
165
|
+
* @returns {any} Parsed value or default
|
|
166
|
+
*/
|
|
167
|
+
export { getRootCssVar };
|
|
168
|
+
|
|
71
169
|
/**
|
|
72
170
|
* Get design height from CSS variables
|
|
73
171
|
*
|
package/dist/logging/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { createServerLogger } from "./internal/factories/server.js";
|
|
2
2
|
export { createClientLogger } from "./internal/factories/client.js";
|
|
3
|
-
export { createLogger } from "./internal/factories/universal.js";
|
|
4
3
|
export { Logger } from "./internal/logger/index.js";
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
4
|
+
export * from "./constants.js";
|
|
5
|
+
export * from "./typedef.js";
|
package/dist/logging/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Factories
|
|
2
2
|
export { createServerLogger } from './internal/factories/server.js';
|
|
3
3
|
export { createClientLogger } from './internal/factories/client.js';
|
|
4
|
-
export { createLogger } from './internal/factories/universal.js';
|
|
5
4
|
|
|
6
|
-
// Logger (advanced usage)
|
|
5
|
+
// Logger (for advanced usage)
|
|
7
6
|
export { Logger } from './internal/logger/index.js';
|
|
8
7
|
|
|
9
8
|
// Constants and typedefs
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
9
|
+
export * from './constants.js';
|
|
10
|
+
export * from './typedef.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LEVELS } from '
|
|
1
|
+
import { LEVELS } from '../../constants.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* (Browser) console adapter that uses native DevTools styling
|
|
@@ -35,12 +35,8 @@ export class ConsoleAdapter {
|
|
|
35
35
|
const styles = this._getStyles(level);
|
|
36
36
|
const prefix = `%c[${source}]`;
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
const logData = details
|
|
40
|
-
? { ...this.context, ...details }
|
|
41
|
-
: Object.keys(this.context).length > 0
|
|
42
|
-
? this.context
|
|
43
|
-
: undefined;
|
|
38
|
+
// Process details for better error formatting
|
|
39
|
+
const logData = this._processLogData(details);
|
|
44
40
|
|
|
45
41
|
if (logData) {
|
|
46
42
|
console[this._getConsoleMethod(level)](prefix, styles, message, logData);
|