@hkdigital/lib-sveltekit 0.0.99 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/components/area/HkArea.svelte +1 -1
  2. package/dist/components/area/HkGridArea.svelte +1 -1
  3. package/dist/components/boxes/game-box/GameBox.svelte +112 -0
  4. package/dist/components/boxes/game-box/GameBox.svelte.d.ts +13 -0
  5. package/dist/components/boxes/game-box/gamebox.util.d.ts +32 -0
  6. package/dist/components/boxes/game-box/gamebox.util.js +83 -0
  7. package/dist/components/boxes/index.d.ts +2 -0
  8. package/dist/components/boxes/index.js +2 -0
  9. package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte +199 -0
  10. package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte.d.ts +20 -0
  11. package/dist/components/buttons/button/Button.svelte +75 -0
  12. package/dist/components/buttons/button/Button.svelte.d.ts +19 -0
  13. package/dist/components/buttons/button-text/TextButton.svelte +21 -0
  14. package/dist/components/buttons/button-text/TextButton.svelte.d.ts +5 -0
  15. package/dist/components/buttons/index.d.ts +2 -1
  16. package/dist/components/buttons/index.js +2 -1
  17. package/dist/components/hkdev/blocks/TextBlock.svelte +47 -0
  18. package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +11 -0
  19. package/dist/components/hkdev/buttons/CheckButton.svelte +63 -0
  20. package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +16 -0
  21. package/dist/components/icon/HkIcon.svelte +1 -1
  22. package/dist/components/icon/HkTabIcon.svelte +6 -2
  23. package/dist/components/image/EnhancedImage.svelte__ +1 -1
  24. package/dist/components/image/ResponsiveImage.svelte +1 -1
  25. package/dist/components/image/ResponsiveImage.svelte__ +1 -1
  26. package/dist/components/inputs/text-input/TestTextInput.svelte__ +2 -2
  27. package/dist/components/inputs/text-input/TextInput.svelte +1 -1
  28. package/dist/components/inputs/text-input/TextInput.svelte___ +1 -1
  29. package/dist/components/layout/HkGridLayers.svelte +1 -1
  30. package/dist/components/panels/plain-panel/PlainPanel.svelte +1 -1
  31. package/dist/components/rows/panel-grid-row/PanelGridRow.svelte +1 -1
  32. package/dist/components/rows/panel-row-2/PanelRow2.svelte +1 -1
  33. package/dist/components/tab-bar/HkTabBar.svelte +1 -1
  34. package/dist/components/tab-bar/HkTabBarSelector.svelte +1 -1
  35. package/dist/design-system/design-config.d.ts +156 -0
  36. package/dist/design-system/design-config.js +73 -0
  37. package/dist/design-system/tailwind-theme-extend.d.ts +23 -0
  38. package/dist/design-system/tailwind-theme-extend.js +151 -0
  39. package/dist/themes/hkdev/components/blocks/text-block.postcss +41 -0
  40. package/dist/themes/hkdev/components/buttons/button-text.postcss +34 -0
  41. package/dist/themes/hkdev/components/buttons/button.postcss +138 -0
  42. package/dist/themes/hkdev/components/buttons/button.postcss__ +40 -0
  43. package/dist/themes/hkdev/components/buttons/button.postcss___ +91 -0
  44. package/dist/themes/hkdev/components.postcss +8 -2
  45. package/dist/themes/hkdev/globals.postcss +5 -6
  46. package/dist/util/css/css-vars.d.ts +24 -0
  47. package/dist/util/css/css-vars.js +83 -0
  48. package/dist/util/css/index.d.ts +1 -0
  49. package/dist/util/css/index.js +1 -0
  50. package/dist/util/design-system/components/states.d.ts +15 -0
  51. package/dist/util/design-system/components/states.js +22 -0
  52. package/dist/util/design-system/css/clamp.d.ts +17 -0
  53. package/dist/util/design-system/css/clamp.js +66 -0
  54. package/dist/util/design-system/css/root-design-vars.d.ts +77 -0
  55. package/dist/util/design-system/css/root-design-vars.js +100 -0
  56. package/dist/util/design-system/index.d.ts +5 -0
  57. package/dist/util/design-system/index.js +5 -0
  58. package/dist/util/design-system/layout/scaling.d.ts +44 -0
  59. package/dist/util/design-system/layout/scaling.js +97 -0
  60. package/dist/util/design-system/tailwind.d.ts +176 -0
  61. package/dist/util/design-system/tailwind.js +289 -0
  62. package/package.json +10 -11
  63. package/dist/components/buttons/plain-button/PlainButton.svelte +0 -37
  64. package/dist/components/buttons/plain-button/PlainButton.svelte.d.ts +0 -10
  65. package/dist/config/tailwind.extend.d.ts +0 -56
  66. package/dist/config/tailwind.extend.js +0 -64
  67. package/dist/themes/hkdev/components/buttons/plain-button.postcss +0 -73
@@ -0,0 +1,34 @@
1
+ @define-mixin component-button-text {
2
+
3
+ /* @note using CSS vars defined in the parent button postcss */
4
+
5
+ /* Type-based styling for text buttons */
6
+ [data-component="button"][data-type="text"] {
7
+ /* Typography settings */
8
+ @apply text-ui-base uppercase;
9
+ @apply whitespace-nowrap;
10
+
11
+ /* Adjust padding to better fit text */
12
+ /*&[data-size="sm"] {
13
+ @apply px-8ut py-8ut;
14
+ }
15
+
16
+ &[data-size="md"] {
17
+ @apply px-16ut py-12ut;
18
+ }
19
+
20
+ &[data-size="lg"] {
21
+ @apply px-32ut py-16ut;
22
+ }*/
23
+
24
+ /* Role-specific text adjustments */
25
+ &[data-role="primary"] {
26
+ @apply font-extrabold;
27
+ }
28
+
29
+ &[data-role="secondary"] {
30
+ @apply font-bold;
31
+ }
32
+ }
33
+
34
+ }
@@ -0,0 +1,138 @@
1
+ @define-mixin component-button {
2
+ [data-component="button"] {
3
+ /* ---- Core Button Variables ---- */
4
+ /* These are the most reusable across button types */
5
+ --btn-border-width: 2px;
6
+ --btn-transition-duration: 150ms;
7
+ --btn-disabled-opacity: 0.6;
8
+ --btn-focus-ring-width: 3px;
9
+ --btn-focus-ring-opacity: 0.4;
10
+
11
+ /* ---- Primary Button Variables ---- */
12
+ --btn-primary-bg: var(--color-primary-500);
13
+ --btn-primary-text: var(--color-primary-50);
14
+ --btn-primary-border: var(--color-primary-500);
15
+ --btn-primary-selected-bg: var(--color-primary-700);
16
+ --btn-primary-selected-border: var(--color-primary-800);
17
+ --btn-primary-selected-text: var(--color-primary-50);
18
+ --btn-primary-hover-bg: var(--color-primary-600);
19
+ --btn-primary-hover-border: var(--color-primary-600);
20
+ --btn-primary-focus-outline: var(--color-primary-800);
21
+
22
+ /* ---- Secondary Button Variables ---- */
23
+ --btn-secondary-bg: transparent;
24
+ --btn-secondary-text: var(--color-secondary-500);
25
+ --btn-secondary-border: var(--color-secondary-500);
26
+ --btn-secondary-selected-bg: var(--color-secondary-100);
27
+ --btn-secondary-selected-border: var(--color-secondary-600);
28
+ --btn-secondary-selected-text: var(--color-secondary-800);
29
+ --btn-secondary-hover-bg: var(--color-secondary-50);
30
+ --btn-secondary-hover-border: var(--color-secondary-500);
31
+ --btn-secondary-focus-outline: var(--color-secondary-800);
32
+
33
+ /* ---- State Variables ---- */
34
+ --btn-active-transform: scale(0.98);
35
+ --btn-active-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.1);
36
+
37
+ --btn-error-border: var(--color-error-500);
38
+ --btn-loading-opacity: 0.8;
39
+
40
+ /* Base styles */
41
+ display: inline-flex;
42
+ justify-content: center;
43
+ align-items: center;
44
+ cursor: pointer;
45
+ position: relative;
46
+ transition-property: background-color, color, border-color, transform, box-shadow;
47
+ transition-duration: var(--btn-transition-duration);
48
+ }
49
+
50
+ /* Size variants */
51
+ [data-component="button"][data-size="sm"] {
52
+ @apply rounded-xs;
53
+ @apply py-8ut px-8ut;
54
+ @apply min-w-24ut min-h-24ut;
55
+ }
56
+
57
+ [data-component="button"][data-size="md"] {
58
+ @apply rounded-sm;
59
+ @apply py-8ut px-16ut;
60
+ @apply min-w-32ut min-h-32ut;
61
+ }
62
+
63
+ [data-component="button"][data-size="lg"] {
64
+ @apply rounded-sm;
65
+ @apply py-16ut px-36ut;
66
+ @apply min-w-36ut min-h-36ut;
67
+ }
68
+
69
+ /* Role-based styling for primary buttons */
70
+ [data-component="button"][data-role="primary"] {
71
+ @apply border-width-normal;
72
+ border-color: rgb(var(--btn-primary-border));
73
+ background-color: rgb(var(--btn-primary-bg));
74
+ color: rgb(var(--btn-primary-text));
75
+
76
+ &:hover:not(:disabled):not(.state-selected) {
77
+ border-color: rgb(var(--btn-primary-hover-border));
78
+ background-color: rgb(var(--btn-primary-hover-bg));
79
+ }
80
+
81
+ &:focus-visible {
82
+ @apply outline outline-normal outline-offset-normal;
83
+ outline-color: rgb(var(--btn-primary-focus-outline));
84
+ }
85
+
86
+ &.state-selected {
87
+ background-color: rgb(var(--btn-primary-selected-bg));
88
+ border-color: rgb(var(--btn-primary-selected-border));
89
+ color: rgb(var(--btn-primary-selected-text));
90
+ }
91
+ }
92
+
93
+ /* Role-based styling for secondary buttons */
94
+ [data-component="button"][data-role="secondary"] {
95
+ @apply border-width-normal;
96
+ border-color: rgb(var(--btn-secondary-border));
97
+ color: rgb(var(--btn-secondary-text));
98
+ background-color: var(--btn-secondary-bg);
99
+
100
+ &:hover:not(:disabled):not(.state-selected) {
101
+ background-color: rgb(var(--btn-secondary-hover-bg));
102
+ border-color: rgb(var(--btn-secondary-hover-border));
103
+ }
104
+
105
+ &:focus-visible {
106
+ @apply outline outline-normal outline-offset-normal;
107
+ outline-color: rgb(var(--btn-secondary-focus-outline));
108
+ }
109
+
110
+ &.state-selected {
111
+ background-color: rgb(var(--btn-secondary-selected-bg));
112
+ border-color: rgb(var(--btn-secondary-selected-border));
113
+ color: rgb(var(--btn-secondary-selected-text));
114
+ }
115
+ }
116
+
117
+ /* State-based styling */
118
+ [data-component="button"].state-active {
119
+ transform: var(--btn-active-transform);
120
+ box-shadow: var(--btn-active-shadow);
121
+ }
122
+
123
+ [data-component="button"].state-error {
124
+ border-color: rgb(var(--btn-error-border));
125
+ }
126
+
127
+ [data-component="button"].state-loading {
128
+ opacity: var(--btn-loading-opacity);
129
+ cursor: wait;
130
+ }
131
+
132
+ /* Disabled state */
133
+ [data-component="button"]:disabled {
134
+ cursor: not-allowed;
135
+ opacity: var(--btn-disabled-opacity);
136
+ pointer-events: none;
137
+ }
138
+ }
@@ -0,0 +1,40 @@
1
+ @define-mixin component-button {
2
+
3
+ [data-component="button"][data-type="plain"] {
4
+
5
+ &:not([disabled]) {
6
+ &[data-role="primary"] {
7
+ @apply ...
8
+ }
9
+
10
+ &[data-role="secondary"] {
11
+ @apply ...
12
+ }
13
+ }
14
+
15
+ &[disabled] {
16
+ &[data-role="primary"] {
17
+ @apply ...
18
+ }
19
+
20
+ &[data-role="secondary"] {
21
+ @apply ...
22
+ }
23
+ }
24
+ }
25
+
26
+ [data-component="button"][data-type="plain"] {
27
+
28
+ &[data-size="sm"] {
29
+ @apply ...
30
+ }
31
+
32
+ &[data-size="md"] {
33
+ @apply ...
34
+ }
35
+
36
+ &[data-size="lg"] {
37
+ @apply ...
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,91 @@
1
+ @define-mixin component-button {
2
+
3
+ /* Base button styles */
4
+ [data-component="button"][data-type="plain"] {
5
+ @apply rounded-md;
6
+ @apply border-width-normal;
7
+ @apply text-ui-base base-font-family font-medium;
8
+ }
9
+
10
+ /* Role-based styling for enabled buttons */
11
+ [data-component="button"][data-type="plain"] {
12
+ &:not([disabled]) {
13
+ &[data-role="primary"] {
14
+ @apply border-primary-500 bg-primary-500;
15
+ @apply text-primary-contrast-500;
16
+ }
17
+
18
+ &[data-role="secondary"] {
19
+ @apply border-secondary-500 text-secondary-500 bg-transparent;
20
+ }
21
+ }
22
+
23
+ /* Role-based styling for disabled buttons */
24
+ &[disabled] {
25
+ @apply cursor-not-allowed;
26
+
27
+ &[data-role="primary"] {
28
+ @apply bg-surface-300 text-surface-100;
29
+ }
30
+
31
+ &[data-role="secondary"] {
32
+ @apply border-surface-300 text-surface-300 bg-transparent;
33
+ }
34
+ }
35
+ }
36
+
37
+ /* Size variants */
38
+ [data-component="button"][data-type="plain"] {
39
+ &[data-size="sm"] {
40
+ @apply px-8ut py-4ut;
41
+ @apply text-ui-sm;
42
+ @apply gap-4ut;
43
+ /* height: 32ut;*/
44
+ }
45
+
46
+ &[data-size="md"] {
47
+ @apply px-16ut py-8ut;
48
+ @apply text-ui-base;
49
+ @apply gap-8ut;
50
+ /* height: 40ut;*/
51
+ }
52
+
53
+ &[data-size="lg"] {
54
+ @apply px-20ut py-10ut;
55
+ @apply text-ui-lg;
56
+ @apply gap-10ut;
57
+ /* height: 50ut;*/
58
+ }
59
+ }
60
+
61
+ /* Hover, focus and active states for enabled buttons */
62
+ [data-component="button"][data-type="plain"]:not([disabled]) {
63
+ &[data-role="primary"] {
64
+ &:hover {
65
+ @apply bg-primary-600;
66
+ }
67
+ &:focus-visible {
68
+ @apply bg-primary-600;
69
+ outline: 2ut solid rgb(var(--color-primary-300));
70
+ outline-offset: 2ut;
71
+ }
72
+ &:active {
73
+ @apply bg-primary-700;
74
+ }
75
+ }
76
+
77
+ &[data-role="secondary"] {
78
+ &:hover {
79
+ @apply bg-secondary-50;
80
+ }
81
+ &:focus-visible {
82
+ @apply bg-secondary-50;
83
+ outline: 2ut solid rgb(var(--color-secondary-300));
84
+ outline-offset: 2ut;
85
+ }
86
+ &:active {
87
+ @apply bg-secondary-100;
88
+ }
89
+ }
90
+ }
91
+ }
@@ -9,7 +9,9 @@
9
9
  /*@import "./components/rows/panel-row-2.postcss";*/
10
10
 
11
11
  /* Buttons */
12
- @import "./components/buttons/plain-button.postcss";
12
+ @import "./components/buttons/button.postcss";
13
+ @import "./components/buttons/button-text.postcss";
14
+
13
15
  /*@import "./components/buttons/skip-button.postcss";*/
14
16
 
15
17
  /* Inputs */
@@ -17,6 +19,7 @@
17
19
 
18
20
  /* ... */
19
21
  /*@import "./components/select-level.postcss";*/
22
+ @import "./components/blocks/text-block.postcss";
20
23
 
21
24
  /* Not used */
22
25
  /*@import "./components/hk-tab-icon.postcss";*/
@@ -36,8 +39,11 @@
36
39
  /* @mixin rows-panel-row-2;*/
37
40
 
38
41
  /* Buttons */
39
- @mixin buttons-plain-button;
42
+ @mixin component-button;
43
+ @mixin component-button-text;
44
+
40
45
  /* @mixin buttons-skip-button;*/
46
+ @mixin text_block;
41
47
 
42
48
  /* Inputs */
43
49
  @mixin inputs-text-input;
@@ -3,10 +3,9 @@
3
3
  @import "./global/layout.postcss";
4
4
  /*@import "./global/text.postcss";*/
5
5
 
6
- [data-theme] {
7
- /* @mixin all_vars;*/
8
- /* @mixin all_on_colors;*/
9
- @mixin all_layout;
10
- /* @mixin all_text;*/
11
-
6
+ [data-theme="hkdev"] {
7
+ /* @mixin all_vars;*/
8
+ /* @mixin all_on_colors;*/
9
+ @mixin all_layout;
10
+ /* @mixin all_text;*/
12
11
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Normalizes a CSS variable name to ensure it has the -- prefix
3
+ *
4
+ * @param {string} varName - The CSS variable name
5
+ * @returns {string} Normalized variable name with -- prefix
6
+ */
7
+ export function normalizeCssVarName(varName: string): string;
8
+ /**
9
+ * Extract a CSS variable value from document root
10
+ *
11
+ * @param {string} varName - CSS variable name without '--'
12
+ * @param {boolean} [useCache=false]
13
+ *
14
+ * @returns {any} Parsed value or default
15
+ */
16
+ export function getRootCssVar(varName: string, useCache?: boolean): any;
17
+ /**
18
+ * Sets a CSS variable in :root to a new value
19
+ *
20
+ * @param {string} varName - The CSS variable name (with or without --)
21
+ * @param {string|number} value - The new value to set
22
+ * @returns {boolean} True if successful, false otherwise
23
+ */
24
+ export function setRootCssVar(varName: string, value: string | number): boolean;
@@ -0,0 +1,83 @@
1
+ let cssVarCache = {};
2
+
3
+ /**
4
+ * Normalizes a CSS variable name to ensure it has the -- prefix
5
+ *
6
+ * @param {string} varName - The CSS variable name
7
+ * @returns {string} Normalized variable name with -- prefix
8
+ */
9
+ export function normalizeCssVarName(varName) {
10
+ if (typeof varName !== 'string') {
11
+ throw new Error('Variable name must be a string');
12
+ }
13
+ return varName.startsWith('--') ? varName : `--${varName}`;
14
+ }
15
+
16
+ /**
17
+ * Extract a CSS variable value from document root
18
+ *
19
+ * @param {string} varName - CSS variable name without '--'
20
+ * @param {boolean} [useCache=false]
21
+ *
22
+ * @returns {any} Parsed value or default
23
+ */
24
+ export function getRootCssVar(varName, useCache = false) {
25
+ if (cssVarCache[varName] !== undefined && useCache) {
26
+ return cssVarCache[varName];
27
+ }
28
+
29
+ // Get computed style from document root
30
+ const rootStyle = getComputedStyle(document.documentElement);
31
+ const declaration = rootStyle.getPropertyValue(`--${varName}`).trim();
32
+
33
+ if (!declaration) {
34
+ return null;
35
+ }
36
+
37
+ let result;
38
+
39
+ // Try to parse as number
40
+ if (!isNaN(parseFloat(declaration))) {
41
+ result = parseFloat(declaration);
42
+ } else {
43
+ // Return string value
44
+ result = declaration;
45
+ }
46
+
47
+ // Cache the result
48
+ cssVarCache[varName] = result;
49
+ return result;
50
+ }
51
+
52
+ /**
53
+ * Sets a CSS variable in :root to a new value
54
+ *
55
+ * @param {string} varName - The CSS variable name (with or without --)
56
+ * @param {string|number} value - The new value to set
57
+ * @returns {boolean} True if successful, false otherwise
58
+ */
59
+ export function setRootCssVar(varName, value) {
60
+ try {
61
+ if (varName === undefined || varName === null) {
62
+ throw new Error('Variable name cannot be null or undefined');
63
+ }
64
+
65
+ if (value === undefined || value === null) {
66
+ throw new Error('Value cannot be null or undefined');
67
+ }
68
+
69
+ const normalizedName = normalizeCssVarName(varName);
70
+
71
+ // Convert to string if numeric
72
+ const formattedValue = typeof value === 'number' ? `${value}` : value;
73
+
74
+ document.documentElement.style.setProperty(normalizedName, formattedValue);
75
+
76
+ delete cssVarCache[varName];
77
+
78
+ return true;
79
+ } catch (error) {
80
+ console.error(`Error setting CSS variable ${varName}:`, error);
81
+ return false;
82
+ }
83
+ }
@@ -0,0 +1 @@
1
+ export * from "./css-vars.js";
@@ -0,0 +1 @@
1
+ export * from './css-vars.js';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Generates state classes from an object of state variables
3
+ *
4
+ * @param {Object.<string, boolean>} stateObject
5
+ * Object with state names as keys and boolean values
6
+ *
7
+ * @returns {string} Space-separated string of state classes
8
+ *
9
+ * @example
10
+ * // Returns "state-selected state-error"
11
+ * toStateClasses({ selected: true, loading: false, error: true });
12
+ */
13
+ export function toStateClasses(stateObject: {
14
+ [x: string]: boolean;
15
+ }): string;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Generates state classes from an object of state variables
3
+ *
4
+ * @param {Object.<string, boolean>} stateObject
5
+ * Object with state names as keys and boolean values
6
+ *
7
+ * @returns {string} Space-separated string of state classes
8
+ *
9
+ * @example
10
+ * // Returns "state-selected state-error"
11
+ * toStateClasses({ selected: true, loading: false, error: true });
12
+ */
13
+ export function toStateClasses(stateObject) {
14
+ if (!stateObject || typeof stateObject !== 'object') {
15
+ return '';
16
+ }
17
+
18
+ return Object.entries(stateObject)
19
+ .filter((entry) => entry[1] === true)
20
+ .map(([state]) => `state-${state}`)
21
+ .join(' ');
22
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Extract clamp parameters from a CSS variable
3
+ *
4
+ * @param {string} varName - CSS variable name without '--'
5
+ * @returns {Object} Object with min and max values
6
+ * @throws {Error} If the CSS variable doesn't exist or doesn't contain a valid clamp function
7
+ */
8
+ export function getClampParams(varName: string): any;
9
+ /**
10
+ * CSS clamp function implementation
11
+ *
12
+ * @param {number} min - Minimum value
13
+ * @param {number} val - Value to clamp
14
+ * @param {number} max - Maximum value
15
+ * @returns {number} Clamped value
16
+ */
17
+ export function clamp(min: number, val: number, max: number): number;
@@ -0,0 +1,66 @@
1
+ import { getRootCssVar } from '../../css/index.js';
2
+
3
+ /**
4
+ * Cache to that ensures we parse CSS clamp parameters only once
5
+ * @type {Object.<string, {min: number, max: number}>}
6
+ */
7
+ let clampParamCache = {};
8
+
9
+ /**
10
+ * Extract clamp parameters from a CSS variable
11
+ *
12
+ * @param {string} varName - CSS variable name without '--'
13
+ * @returns {Object} Object with min and max values
14
+ * @throws {Error} If the CSS variable doesn't exist or doesn't contain a valid clamp function
15
+ */
16
+ export function getClampParams(varName) {
17
+ // Check cache first
18
+ if (clampParamCache[varName]) {
19
+ return clampParamCache[varName];
20
+ }
21
+
22
+ // Get the CSS variable value using the existing utility
23
+ const declaration = getRootCssVar(varName);
24
+
25
+ if (declaration === null) {
26
+ throw new Error(`CSS variable --${varName} not found`);
27
+ }
28
+
29
+ // Parse clamp() function values
30
+ const clampMatch =
31
+ typeof declaration === 'string'
32
+ ? declaration.match(
33
+ /clamp\s*\(\s*([\d.]+)\s*,\s*[^,]+\s*,\s*([\d.]+)\s*\)/
34
+ )
35
+ : null;
36
+
37
+ if (!clampMatch || clampMatch.length < 3) {
38
+ // console.log(declaration);
39
+ throw new Error(
40
+ `CSS variable --${varName} does not contain a valid clamp function`
41
+ );
42
+ }
43
+
44
+ const min = parseFloat(clampMatch[1]);
45
+ const max = parseFloat(clampMatch[2]);
46
+
47
+ if (isNaN(min) || isNaN(max)) {
48
+ throw new Error(`Invalid min/max values in CSS variable --${varName}`);
49
+ }
50
+
51
+ // Cache the result
52
+ clampParamCache[varName] = { min, max };
53
+ return { min, max };
54
+ }
55
+
56
+ /**
57
+ * CSS clamp function implementation
58
+ *
59
+ * @param {number} min - Minimum value
60
+ * @param {number} val - Value to clamp
61
+ * @param {number} max - Maximum value
62
+ * @returns {number} Clamped value
63
+ */
64
+ export function clamp(min, val, max) {
65
+ return Math.max(min, Math.min(val, max));
66
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Generates a complete HTML style tag with CSS custom properties for
3
+ * the design system based on provided configuration.
4
+ *
5
+ * @param {Object} design - Design dimensions configuration
6
+ * @param {number} design.width - The design width in pixels
7
+ * @param {number} design.height - The design height in pixels
8
+ * @param {Object} clamping - Scaling configuration parameters
9
+ * @param {Object} clamping.ui - UI clamping configuration
10
+ * @param {number} clamping.ui.min - Minimum UI scaling factor
11
+ * @param {number} clamping.ui.max - Maximum UI scaling factor
12
+ * @param {Object} clamping.textContent - Content text scaling configuration
13
+ * @param {number} clamping.textContent.min - Minimum content text scaling
14
+ * @param {number} clamping.textContent.max - Maximum content text scaling
15
+ * @param {Object} clamping.textHeading - Heading text clamping configuration
16
+ * @param {number} clamping.textHeading.min - Minimum heading text scaling
17
+ * @param {number} clamping.textHeading.max - Maximum heading text scaling
18
+ * @param {Object} clamping.textUi - UI text clamping configuration
19
+ * @param {number} clamping.textUi.min - Minimum UI text scaling
20
+ * @param {number} clamping.textUi.max - Maximum UI text scaling
21
+ *
22
+ * @returns {string} Complete HTML style tag with design system CSS variables
23
+ *
24
+ * @example
25
+ * // +layout.svelte
26
+ * <script>
27
+ * import { DESIGN, CLAMPING } from '../../../tailwind/extend/clamping/config.js';
28
+ *
29
+ * import { rootDesignVarsHTML } from '../index.js';
30
+ * </script>
31
+ *
32
+ * <svelte:head>
33
+ * {@html rootDesignVarsHTML(DESIGN, CLAMPING)}
34
+ * </svelte:head>
35
+ *
36
+ * // Generates style tag for use in svelte:head
37
+ * // <style>:root { --design-width: 1920; ... }</style>
38
+ */
39
+ export function rootDesignVarsHTML(design: {
40
+ width: number;
41
+ height: number;
42
+ }, clamping: {
43
+ ui: {
44
+ min: number;
45
+ max: number;
46
+ };
47
+ textContent: {
48
+ min: number;
49
+ max: number;
50
+ };
51
+ textHeading: {
52
+ min: number;
53
+ max: number;
54
+ };
55
+ textUi: {
56
+ min: number;
57
+ max: number;
58
+ };
59
+ }): string;
60
+ /**
61
+ * Get design width from CSS variables
62
+ *
63
+ * @returns {number} Design width
64
+ */
65
+ export function getRootCssDesignWidth(): number;
66
+ /**
67
+ * Get design height from CSS variables
68
+ *
69
+ * @returns {number} Design height
70
+ */
71
+ export function getRootCssDesignHeight(): number;
72
+ /**
73
+ * Retrieves all current scaling factors from CSS variables
74
+ *
75
+ * @returns {Object} An object containing all scaling factors
76
+ */
77
+ export function getAllRootScalingVars(): any;