@hkdigital/lib-sveltekit 0.1.5 → 0.1.6

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 (204) hide show
  1. package/README.md +127 -127
  2. package/dist/classes/data/IterableTree.js +243 -243
  3. package/dist/classes/data/Selector.js +190 -190
  4. package/dist/classes/data/index.js +2 -2
  5. package/dist/classes/index.js +3 -3
  6. package/dist/classes/promise/HkPromise.js +377 -377
  7. package/dist/classes/promise/index.js +1 -1
  8. package/dist/classes/stores/SubscribersCount.js +107 -107
  9. package/dist/classes/stores/index.js +1 -1
  10. package/dist/classes/streams/LogTransformStream.js +19 -19
  11. package/dist/classes/streams/ServerEventsStore.js +110 -110
  12. package/dist/classes/streams/TimeStampSource.js +26 -26
  13. package/dist/classes/streams/index.js +3 -3
  14. package/dist/classes/svelte/audio/AudioLoader.svelte.js +58 -58
  15. package/dist/classes/svelte/audio/AudioScene.svelte.js +282 -282
  16. package/dist/classes/svelte/audio/mocks.js +35 -35
  17. package/dist/classes/svelte/final-state-machine/FiniteStateMachine.svelte.js +133 -133
  18. package/dist/classes/svelte/final-state-machine/index.js +1 -1
  19. package/dist/classes/svelte/image/ImageLoader.svelte.js +47 -47
  20. package/dist/classes/svelte/image/ImageScene.svelte.js +253 -253
  21. package/dist/classes/svelte/image/ImageVariantsLoader.svelte.js +152 -152
  22. package/dist/classes/svelte/image/index.js +4 -4
  23. package/dist/classes/svelte/image/mocks.js +35 -35
  24. package/dist/classes/svelte/image/typedef.js +8 -8
  25. package/dist/classes/svelte/loading-state-machine/LoadingStateMachine.svelte.js +109 -109
  26. package/dist/classes/svelte/loading-state-machine/constants.js +16 -16
  27. package/dist/classes/svelte/loading-state-machine/index.js +3 -3
  28. package/dist/classes/svelte/network-loader/NetworkLoader.svelte.js +331 -331
  29. package/dist/classes/svelte/network-loader/constants.js +3 -3
  30. package/dist/classes/svelte/network-loader/index.js +3 -3
  31. package/dist/classes/svelte/network-loader/mocks.js +30 -30
  32. package/dist/classes/svelte/network-loader/typedef.js +8 -8
  33. package/dist/components/area/HkArea.svelte +49 -49
  34. package/dist/components/area/HkArea.svelte.d.ts +0 -14
  35. package/dist/components/area/HkGridArea.svelte +77 -77
  36. package/dist/components/area/HkGridArea.svelte.d.ts +0 -22
  37. package/dist/components/area/index.js +2 -2
  38. package/dist/components/boxes/game-box/GameBox.svelte +112 -112
  39. package/dist/components/boxes/game-box/GameBox.svelte.d.ts +0 -15
  40. package/dist/components/boxes/game-box/gamebox.util.js +83 -83
  41. package/dist/components/boxes/index.js +2 -2
  42. package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte +199 -199
  43. package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte.d.ts +0 -22
  44. package/dist/components/buttons/button/Button.svelte +75 -75
  45. package/dist/components/buttons/button/Button.svelte.d.ts +0 -21
  46. package/dist/components/buttons/button-text/TextButton.svelte +21 -21
  47. package/dist/components/buttons/button-text/TextButton.svelte.d.ts +0 -7
  48. package/dist/components/buttons/index.js +2 -2
  49. package/dist/components/hkdev/blocks/TextBlock.svelte +46 -46
  50. package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +0 -13
  51. package/dist/components/hkdev/buttons/CheckButton.svelte +62 -62
  52. package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +0 -18
  53. package/dist/components/icon/HkIcon.svelte +86 -86
  54. package/dist/components/icon/HkIcon.svelte.d.ts +0 -12
  55. package/dist/components/icon/HkTabIcon.svelte +116 -116
  56. package/dist/components/icon/HkTabIcon.svelte.d.ts +0 -21
  57. package/dist/components/icon/index.js +4 -4
  58. package/dist/components/icon/typedef.js +16 -16
  59. package/dist/components/image/ImageBox.svelte +208 -208
  60. package/dist/components/image/ImageBox.svelte.d.ts +0 -19
  61. package/dist/components/image/index.js +5 -5
  62. package/dist/components/image/typedef.js +32 -32
  63. package/dist/components/index.js +2 -2
  64. package/dist/components/inputs/index.js +1 -1
  65. package/dist/components/inputs/text-input/TestTextInput.svelte__ +102 -102
  66. package/dist/components/inputs/text-input/TextInput.svelte +226 -226
  67. package/dist/components/inputs/text-input/TextInput.svelte.d.ts +0 -28
  68. package/dist/components/inputs/text-input/TextInput.svelte___ +83 -83
  69. package/dist/components/inputs/text-input/assets/IconInvalid.svelte +14 -14
  70. package/dist/components/inputs/text-input/assets/IconValid.svelte +12 -12
  71. package/dist/components/layout/HkAppLayout.state.svelte.js +25 -25
  72. package/dist/components/layout/HkAppLayout.svelte +251 -251
  73. package/dist/components/layout/HkAppLayout.svelte.d.ts +0 -11
  74. package/dist/components/layout/HkGridLayers.svelte +82 -82
  75. package/dist/components/layout/HkGridLayers.svelte.d.ts +0 -23
  76. package/dist/components/layout/index.js +9 -9
  77. package/dist/components/panels/index.js +1 -1
  78. package/dist/components/panels/plain-panel/PlainPanel.svelte +33 -33
  79. package/dist/components/panels/plain-panel/PlainPanel.svelte.d.ts +0 -12
  80. package/dist/components/rows/index.js +3 -3
  81. package/dist/components/rows/panel-grid-row/PanelGridRow.svelte +104 -104
  82. package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +0 -14
  83. package/dist/components/rows/panel-row-2/PanelRow2.svelte +40 -40
  84. package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +0 -14
  85. package/dist/components/tab-bar/HkTabBar.state.svelte.js +149 -149
  86. package/dist/components/tab-bar/HkTabBar.svelte +74 -74
  87. package/dist/components/tab-bar/HkTabBar.svelte.d.ts +0 -18
  88. package/dist/components/tab-bar/HkTabBarSelector.state.svelte.js +93 -93
  89. package/dist/components/tab-bar/HkTabBarSelector.svelte +49 -49
  90. package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +0 -19
  91. package/dist/components/tab-bar/index.js +17 -17
  92. package/dist/components/tab-bar/typedef.js +8 -8
  93. package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte +179 -179
  94. package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte.d.ts +0 -10
  95. package/dist/components/widgets/compare-left-right/index.js +1 -1
  96. package/dist/components/widgets/scale-control/index.js +1 -1
  97. package/dist/config/imagetools-config.js +189 -189
  98. package/dist/config/imagetools.d.ts +71 -71
  99. package/dist/config/typedef.js +8 -8
  100. package/dist/constants/errors/api.js +9 -9
  101. package/dist/constants/errors/generic.js +5 -5
  102. package/dist/constants/errors/index.js +3 -3
  103. package/dist/constants/errors/jwt.js +5 -5
  104. package/dist/constants/http/headers.js +6 -6
  105. package/dist/constants/http/index.js +2 -2
  106. package/dist/constants/http/methods.js +2 -2
  107. package/dist/constants/index.js +3 -3
  108. package/dist/constants/mime/application.js +5 -5
  109. package/dist/constants/mime/audio.js +13 -13
  110. package/dist/constants/mime/image.js +3 -3
  111. package/dist/constants/mime/index.js +4 -4
  112. package/dist/constants/mime/text.js +2 -2
  113. package/dist/constants/regexp/index.js +31 -31
  114. package/dist/constants/regexp/inspiratie.js__ +95 -95
  115. package/dist/constants/regexp/text.js +49 -49
  116. package/dist/constants/regexp/user.js +32 -32
  117. package/dist/constants/regexp/web.js +3 -3
  118. package/dist/constants/state-labels/input-states.js +11 -11
  119. package/dist/constants/state-labels/submit-states.js +4 -4
  120. package/dist/constants/time.js +28 -28
  121. package/dist/css/tw-prose.postcss__ +259 -259
  122. package/dist/css/utilities.postcss +43 -43
  123. package/dist/design/design-config.js +73 -73
  124. package/dist/design/tailwind-theme-extend.d.ts +4 -4
  125. package/dist/design/tailwind-theme-extend.js +151 -151
  126. package/dist/schemas/index.js +1 -1
  127. package/dist/schemas/validate-url.js +180 -180
  128. package/dist/server/index.js +1 -1
  129. package/dist/server/logger.js +94 -94
  130. package/dist/states/index.js +1 -1
  131. package/dist/states/navigation.svelte.js +55 -55
  132. package/dist/stores/index.js +1 -1
  133. package/dist/stores/theme.js +80 -80
  134. package/dist/themes/hkdev/components/blocks/text-block.postcss +40 -40
  135. package/dist/themes/hkdev/components/boxes/game-box.postcss +13 -13
  136. package/dist/themes/hkdev/components/buttons/button-text.postcss +34 -34
  137. package/dist/themes/hkdev/components/buttons/button.postcss +138 -138
  138. package/dist/themes/hkdev/components/buttons/skip-button.postcss +8 -8
  139. package/dist/themes/hkdev/components/inputs/text-input.postcss +108 -108
  140. package/dist/themes/hkdev/components/panels/plain-panel.postcss +46 -46
  141. package/dist/themes/hkdev/components/panels/speech-bubble.postcss +52 -52
  142. package/dist/themes/hkdev/components/rows/panel-grid-row.postcss +7 -7
  143. package/dist/themes/hkdev/components/rows/panel-row-2.postcss +9 -9
  144. package/dist/themes/hkdev/components.postcss +55 -55
  145. package/dist/themes/hkdev/debug.postcss +1 -1
  146. package/dist/themes/hkdev/global/layout.postcss +39 -39
  147. package/dist/themes/hkdev/global/on-colors.postcss +53 -53
  148. package/dist/themes/hkdev/global/text.postcss__ +34 -34
  149. package/dist/themes/hkdev/global/vars.postcss__ +7 -7
  150. package/dist/themes/hkdev/globals.postcss +11 -11
  151. package/dist/themes/hkdev/responsive.postcss +12 -12
  152. package/dist/themes/hkdev/theme-ext.js +15 -15
  153. package/dist/themes/hkdev/theme.js +227 -227
  154. package/dist/themes/index.js +1 -1
  155. package/dist/util/array/index.js +455 -455
  156. package/dist/util/compare/index.js +247 -247
  157. package/dist/util/css/css-vars.js +83 -83
  158. package/dist/util/css/index.js +1 -1
  159. package/dist/util/design-system/components/states.js +22 -22
  160. package/dist/util/design-system/css/clamp.d.ts +2 -2
  161. package/dist/util/design-system/css/clamp.js +66 -66
  162. package/dist/util/design-system/css/root-design-vars.js +100 -100
  163. package/dist/util/design-system/index.js +5 -5
  164. package/dist/util/design-system/layout/scaling.js +97 -97
  165. package/dist/util/design-system/tailwind.js +289 -289
  166. package/dist/util/expect/arrays.js +47 -47
  167. package/dist/util/expect/index.js +259 -259
  168. package/dist/util/expect/primitives.js +55 -55
  169. package/dist/util/expect/url.js +60 -60
  170. package/dist/util/function/index.js +218 -218
  171. package/dist/util/http/errors.js +97 -97
  172. package/dist/util/http/headers.js +45 -45
  173. package/dist/util/http/http-request.js +273 -273
  174. package/dist/util/http/index.js +22 -22
  175. package/dist/util/http/json-request.js +143 -143
  176. package/dist/util/http/mocks.js +65 -65
  177. package/dist/util/http/response.js +228 -228
  178. package/dist/util/http/url.js +52 -52
  179. package/dist/util/image/index.js +86 -86
  180. package/dist/util/index.js +2 -2
  181. package/dist/util/is/index.js +140 -140
  182. package/dist/util/iterate/index.js +234 -234
  183. package/dist/util/object/index.js +1361 -1361
  184. package/dist/util/singleton/index.js +97 -97
  185. package/dist/util/string/index.js +184 -184
  186. package/dist/util/svelte/index.js +2 -2
  187. package/dist/util/svelte/observe/index.js +49 -49
  188. package/dist/util/svelte/state-context/index.js +83 -83
  189. package/dist/util/svelte/wait/index.js +38 -38
  190. package/dist/util/sveltekit/index.js +1 -1
  191. package/dist/util/sveltekit/route-folders/index.js +82 -82
  192. package/dist/util/time/index.js +339 -339
  193. package/dist/valibot/date.js__ +10 -10
  194. package/dist/valibot/index.js +9 -9
  195. package/dist/valibot/url.js +95 -95
  196. package/dist/valibot/user.js +23 -23
  197. package/dist/zod/all.js +33 -33
  198. package/dist/zod/generic.js +11 -11
  199. package/dist/zod/javascript.js +32 -32
  200. package/dist/zod/user.js +16 -16
  201. package/dist/zod/web.js +52 -52
  202. package/package.json +99 -99
  203. package/dist/themes/hkdev/components/buttons/button.postcss__ +0 -40
  204. package/dist/themes/hkdev/components/buttons/button.postcss___ +0 -91
@@ -1,22 +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
- }
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
+ }
@@ -9,9 +9,9 @@ export function getClampParams(varName: string): any;
9
9
  /**
10
10
  * CSS clamp function implementation
11
11
  *
12
+ * @param {number} value - Value to clamp
12
13
  * @param {number} min - Minimum value
13
- * @param {number} val - Value to clamp
14
14
  * @param {number} max - Maximum value
15
15
  * @returns {number} Clamped value
16
16
  */
17
- export function clamp(min: number, val: number, max: number): number;
17
+ export function clamp(value: number, min: number, max: number): number;
@@ -1,66 +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
- }
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} value - Value to clamp
60
+ * @param {number} min - Minimum value
61
+ * @param {number} max - Maximum value
62
+ * @returns {number} Clamped value
63
+ */
64
+ export function clamp(value, min, max) {
65
+ return Math.max(min, Math.min(value, max));
66
+ }
@@ -1,100 +1,100 @@
1
- import { getRootCssVar } from '../../css/css-vars.js';
2
-
3
- /**
4
- * Generates a complete HTML style tag with CSS custom properties for
5
- * the design system based on provided configuration.
6
- *
7
- * @param {Object} design - Design dimensions configuration
8
- * @param {number} design.width - The design width in pixels
9
- * @param {number} design.height - The design height in pixels
10
- * @param {Object} clamping - Scaling configuration parameters
11
- * @param {Object} clamping.ui - UI clamping configuration
12
- * @param {number} clamping.ui.min - Minimum UI scaling factor
13
- * @param {number} clamping.ui.max - Maximum UI scaling factor
14
- * @param {Object} clamping.textContent - Content text scaling configuration
15
- * @param {number} clamping.textContent.min - Minimum content text scaling
16
- * @param {number} clamping.textContent.max - Maximum content text scaling
17
- * @param {Object} clamping.textHeading - Heading text clamping configuration
18
- * @param {number} clamping.textHeading.min - Minimum heading text scaling
19
- * @param {number} clamping.textHeading.max - Maximum heading text scaling
20
- * @param {Object} clamping.textUi - UI text clamping configuration
21
- * @param {number} clamping.textUi.min - Minimum UI text scaling
22
- * @param {number} clamping.textUi.max - Maximum UI text scaling
23
- *
24
- * @returns {string} Complete HTML style tag with design system CSS variables
25
- *
26
- * @example
27
- * // +layout.svelte
28
- * <script>
29
- * import { DESIGN, CLAMPING } from '../../../tailwind/extend/clamping/config.js';
30
- *
31
- * import { rootDesignVarsHTML } from '../index.js';
32
- * </script>
33
- *
34
- * <svelte:head>
35
- * {@html rootDesignVarsHTML(DESIGN, CLAMPING)}
36
- * </svelte:head>
37
- *
38
- * // Generates style tag for use in svelte:head
39
- * // <style>:root { --design-width: 1920; ... }</style>
40
- */
41
- export function rootDesignVarsHTML(design, clamping) {
42
- return `<style>:root {
43
- /* Design dimensions */
44
- --design-width: ${design.width};
45
- --design-height: ${design.height};
46
-
47
- /* Base clamping units */
48
- --scale-w: 1;
49
- --scale-h: 1;
50
- --scale-viewport: min(var(--scale-w), var(--scale-h));
51
-
52
- /* Scaling factors with configurable clamping */
53
- --scale-ui: clamp(${clamping.ui.min}, var(--scale-viewport), ${clamping.ui.max});
54
- --scale-text-content: clamp(${clamping.textContent.min}, var(--scale-viewport), ${clamping.textContent.max});
55
- --scale-text-heading: clamp(${clamping.textHeading.min}, var(--scale-viewport), ${clamping.textHeading.max});
56
- --scale-text-ui: clamp(${clamping.textUi.min}, var(--scale-viewport), ${clamping.textUi.max});
57
- }</style>`;
58
- }
59
-
60
- /**
61
- * Get design width from CSS variables
62
- *
63
- * @returns {number} Design width
64
- */
65
- export function getRootCssDesignWidth() {
66
- return getRootCssVar('design-width');
67
- }
68
-
69
- /**
70
- * Get design height from CSS variables
71
- *
72
- * @returns {number} Design height
73
- */
74
- export function getRootCssDesignHeight() {
75
- return getRootCssVar('design-height');
76
- }
77
-
78
- /**
79
- * Retrieves all current scaling factors from CSS variables
80
- *
81
- * @returns {Object} An object containing all scaling factors
82
- */
83
- export function getAllRootScalingVars() {
84
- const styles = getComputedStyle(document.documentElement);
85
-
86
- return {
87
- scaleW: parseFloat(styles.getPropertyValue('--scale-w').trim()) || 0,
88
- scaleH: parseFloat(styles.getPropertyValue('--scale-h').trim()) || 0,
89
- scaleViewport:
90
- parseFloat(styles.getPropertyValue('--scale-viewport').trim()) || 0,
91
-
92
- scaleUI: parseFloat(styles.getPropertyValue('--scale-ui').trim()) || 0,
93
- scaleTextContent:
94
- parseFloat(styles.getPropertyValue('--scale-text-content').trim()) || 0,
95
- scaleTextHeading:
96
- parseFloat(styles.getPropertyValue('--scale-text-heading').trim()) || 0,
97
- scaleTextUI:
98
- parseFloat(styles.getPropertyValue('--scale-text-ui').trim()) || 0
99
- };
100
- }
1
+ import { getRootCssVar } from '../../css/css-vars.js';
2
+
3
+ /**
4
+ * Generates a complete HTML style tag with CSS custom properties for
5
+ * the design system based on provided configuration.
6
+ *
7
+ * @param {Object} design - Design dimensions configuration
8
+ * @param {number} design.width - The design width in pixels
9
+ * @param {number} design.height - The design height in pixels
10
+ * @param {Object} clamping - Scaling configuration parameters
11
+ * @param {Object} clamping.ui - UI clamping configuration
12
+ * @param {number} clamping.ui.min - Minimum UI scaling factor
13
+ * @param {number} clamping.ui.max - Maximum UI scaling factor
14
+ * @param {Object} clamping.textContent - Content text scaling configuration
15
+ * @param {number} clamping.textContent.min - Minimum content text scaling
16
+ * @param {number} clamping.textContent.max - Maximum content text scaling
17
+ * @param {Object} clamping.textHeading - Heading text clamping configuration
18
+ * @param {number} clamping.textHeading.min - Minimum heading text scaling
19
+ * @param {number} clamping.textHeading.max - Maximum heading text scaling
20
+ * @param {Object} clamping.textUi - UI text clamping configuration
21
+ * @param {number} clamping.textUi.min - Minimum UI text scaling
22
+ * @param {number} clamping.textUi.max - Maximum UI text scaling
23
+ *
24
+ * @returns {string} Complete HTML style tag with design system CSS variables
25
+ *
26
+ * @example
27
+ * // +layout.svelte
28
+ * <script>
29
+ * import { DESIGN, CLAMPING } from '../../../tailwind/extend/clamping/config.js';
30
+ *
31
+ * import { rootDesignVarsHTML } from '../index.js';
32
+ * </script>
33
+ *
34
+ * <svelte:head>
35
+ * {@html rootDesignVarsHTML(DESIGN, CLAMPING)}
36
+ * </svelte:head>
37
+ *
38
+ * // Generates style tag for use in svelte:head
39
+ * // <style>:root { --design-width: 1920; ... }</style>
40
+ */
41
+ export function rootDesignVarsHTML(design, clamping) {
42
+ return `<style>:root {
43
+ /* Design dimensions */
44
+ --design-width: ${design.width};
45
+ --design-height: ${design.height};
46
+
47
+ /* Base clamping units */
48
+ --scale-w: 1;
49
+ --scale-h: 1;
50
+ --scale-viewport: min(var(--scale-w), var(--scale-h));
51
+
52
+ /* Scaling factors with configurable clamping */
53
+ --scale-ui: clamp(${clamping.ui.min}, var(--scale-viewport), ${clamping.ui.max});
54
+ --scale-text-content: clamp(${clamping.textContent.min}, var(--scale-viewport), ${clamping.textContent.max});
55
+ --scale-text-heading: clamp(${clamping.textHeading.min}, var(--scale-viewport), ${clamping.textHeading.max});
56
+ --scale-text-ui: clamp(${clamping.textUi.min}, var(--scale-viewport), ${clamping.textUi.max});
57
+ }</style>`;
58
+ }
59
+
60
+ /**
61
+ * Get design width from CSS variables
62
+ *
63
+ * @returns {number} Design width
64
+ */
65
+ export function getRootCssDesignWidth() {
66
+ return getRootCssVar('design-width');
67
+ }
68
+
69
+ /**
70
+ * Get design height from CSS variables
71
+ *
72
+ * @returns {number} Design height
73
+ */
74
+ export function getRootCssDesignHeight() {
75
+ return getRootCssVar('design-height');
76
+ }
77
+
78
+ /**
79
+ * Retrieves all current scaling factors from CSS variables
80
+ *
81
+ * @returns {Object} An object containing all scaling factors
82
+ */
83
+ export function getAllRootScalingVars() {
84
+ const styles = getComputedStyle(document.documentElement);
85
+
86
+ return {
87
+ scaleW: parseFloat(styles.getPropertyValue('--scale-w').trim()) || 0,
88
+ scaleH: parseFloat(styles.getPropertyValue('--scale-h').trim()) || 0,
89
+ scaleViewport:
90
+ parseFloat(styles.getPropertyValue('--scale-viewport').trim()) || 0,
91
+
92
+ scaleUI: parseFloat(styles.getPropertyValue('--scale-ui').trim()) || 0,
93
+ scaleTextContent:
94
+ parseFloat(styles.getPropertyValue('--scale-text-content').trim()) || 0,
95
+ scaleTextHeading:
96
+ parseFloat(styles.getPropertyValue('--scale-text-heading').trim()) || 0,
97
+ scaleTextUI:
98
+ parseFloat(styles.getPropertyValue('--scale-text-ui').trim()) || 0
99
+ };
100
+ }
@@ -1,5 +1,5 @@
1
- export * from './css/clamp.js';
2
- export * from './css/root-design-vars.js';
3
- export * from './components/states.js';
4
- export * from './layout/scaling.js';
5
- export * from './tailwind.js';
1
+ export * from './css/clamp.js';
2
+ export * from './css/root-design-vars.js';
3
+ export * from './components/states.js';
4
+ export * from './layout/scaling.js';
5
+ export * from './tailwind.js';
@@ -1,97 +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
- }
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
+ }