@hkdigital/lib-sveltekit 0.1.4 → 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.
- package/README.md +127 -127
- package/dist/classes/data/IterableTree.js +243 -243
- package/dist/classes/data/Selector.js +190 -190
- package/dist/classes/data/index.js +2 -2
- package/dist/classes/index.js +3 -3
- package/dist/classes/promise/HkPromise.js +377 -377
- package/dist/classes/promise/index.js +1 -1
- package/dist/classes/stores/SubscribersCount.js +107 -107
- package/dist/classes/stores/index.js +1 -1
- package/dist/classes/streams/LogTransformStream.js +19 -19
- package/dist/classes/streams/ServerEventsStore.js +110 -110
- package/dist/classes/streams/TimeStampSource.js +26 -26
- package/dist/classes/streams/index.js +3 -3
- package/dist/classes/{svkit → svelte}/audio/AudioLoader.svelte.js +58 -58
- package/dist/classes/{svkit → svelte}/audio/AudioScene.svelte.js +282 -282
- package/dist/classes/{svkit → svelte}/audio/mocks.js +35 -35
- package/dist/classes/{svkit → svelte}/final-state-machine/FiniteStateMachine.svelte.js +133 -133
- package/dist/classes/{svkit → svelte}/final-state-machine/index.js +1 -1
- package/dist/classes/{svkit → svelte}/image/ImageLoader.svelte.js +47 -47
- package/dist/classes/{svkit → svelte}/image/ImageScene.svelte.js +253 -253
- package/dist/classes/{svkit → svelte}/image/ImageVariantsLoader.svelte.js +152 -152
- package/dist/classes/{svkit → svelte}/image/index.js +4 -4
- package/dist/classes/{svkit → svelte}/image/mocks.js +35 -35
- package/dist/classes/{svkit → svelte}/image/typedef.js +8 -8
- package/dist/classes/{svkit → svelte}/loading-state-machine/LoadingStateMachine.svelte.js +109 -109
- package/dist/classes/{svkit → svelte}/loading-state-machine/constants.js +16 -16
- package/dist/classes/{svkit → svelte}/loading-state-machine/index.js +3 -3
- package/dist/classes/{svkit → svelte}/network-loader/NetworkLoader.svelte.js +331 -331
- package/dist/classes/{svkit → svelte}/network-loader/constants.js +3 -3
- package/dist/classes/{svkit → svelte}/network-loader/index.js +3 -3
- package/dist/classes/{svkit → svelte}/network-loader/mocks.js +30 -30
- package/dist/classes/{svkit → svelte}/network-loader/typedef.js +8 -8
- package/dist/components/area/HkArea.svelte +49 -49
- package/dist/components/area/HkArea.svelte.d.ts +0 -14
- package/dist/components/area/HkGridArea.svelte +77 -77
- package/dist/components/area/HkGridArea.svelte.d.ts +0 -22
- package/dist/components/area/index.js +2 -2
- package/dist/components/boxes/game-box/GameBox.svelte +112 -112
- package/dist/components/boxes/game-box/GameBox.svelte.d.ts +0 -15
- package/dist/components/boxes/game-box/gamebox.util.js +83 -83
- package/dist/components/boxes/index.js +2 -2
- package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte +199 -199
- package/dist/components/boxes/virtual-viewport/VirtualViewport.svelte.d.ts +0 -22
- package/dist/components/buttons/button/Button.svelte +75 -75
- package/dist/components/buttons/button/Button.svelte.d.ts +0 -21
- package/dist/components/buttons/button-text/TextButton.svelte +21 -21
- package/dist/components/buttons/button-text/TextButton.svelte.d.ts +0 -7
- package/dist/components/buttons/index.js +2 -2
- package/dist/components/hkdev/blocks/TextBlock.svelte +46 -46
- package/dist/components/hkdev/blocks/TextBlock.svelte.d.ts +0 -13
- package/dist/components/hkdev/buttons/CheckButton.svelte +62 -62
- package/dist/components/hkdev/buttons/CheckButton.svelte.d.ts +0 -18
- package/dist/components/icon/HkIcon.svelte +86 -86
- package/dist/components/icon/HkIcon.svelte.d.ts +0 -12
- package/dist/components/icon/HkTabIcon.svelte +116 -116
- package/dist/components/icon/HkTabIcon.svelte.d.ts +0 -21
- package/dist/components/icon/index.js +4 -4
- package/dist/components/icon/typedef.js +16 -16
- package/dist/components/image/ImageBox.svelte +208 -208
- package/dist/components/image/ImageBox.svelte.d.ts +2 -21
- package/dist/components/image/index.js +5 -5
- package/dist/components/image/typedef.js +32 -32
- package/dist/components/index.js +2 -2
- package/dist/components/inputs/index.js +1 -1
- package/dist/components/inputs/text-input/TestTextInput.svelte__ +102 -102
- package/dist/components/inputs/text-input/TextInput.svelte +226 -226
- package/dist/components/inputs/text-input/TextInput.svelte.d.ts +0 -28
- package/dist/components/inputs/text-input/TextInput.svelte___ +83 -83
- package/dist/components/inputs/text-input/assets/IconInvalid.svelte +14 -14
- package/dist/components/inputs/text-input/assets/IconValid.svelte +12 -12
- package/dist/components/layout/HkAppLayout.state.svelte.js +25 -25
- package/dist/components/layout/HkAppLayout.svelte +251 -251
- package/dist/components/layout/HkAppLayout.svelte.d.ts +0 -11
- package/dist/components/layout/HkGridLayers.svelte +82 -82
- package/dist/components/layout/HkGridLayers.svelte.d.ts +0 -23
- package/dist/components/layout/index.js +9 -9
- package/dist/components/panels/index.js +1 -1
- package/dist/components/panels/plain-panel/PlainPanel.svelte +33 -33
- package/dist/components/panels/plain-panel/PlainPanel.svelte.d.ts +0 -12
- package/dist/components/rows/index.js +3 -3
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte +104 -104
- package/dist/components/rows/panel-grid-row/PanelGridRow.svelte.d.ts +0 -14
- package/dist/components/rows/panel-row-2/PanelRow2.svelte +40 -40
- package/dist/components/rows/panel-row-2/PanelRow2.svelte.d.ts +0 -14
- package/dist/components/tab-bar/HkTabBar.state.svelte.js +149 -149
- package/dist/components/tab-bar/HkTabBar.svelte +74 -74
- package/dist/components/tab-bar/HkTabBar.svelte.d.ts +0 -18
- package/dist/components/tab-bar/HkTabBarSelector.state.svelte.js +93 -93
- package/dist/components/tab-bar/HkTabBarSelector.svelte +49 -49
- package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +0 -19
- package/dist/components/tab-bar/index.js +17 -17
- package/dist/components/tab-bar/typedef.js +8 -8
- package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte +179 -179
- package/dist/components/widgets/compare-left-right/CompareLeftRight.svelte.d.ts +0 -10
- package/dist/components/widgets/compare-left-right/index.js +1 -1
- package/dist/components/widgets/scale-control/index.js +1 -1
- package/dist/config/imagetools-config.js +189 -189
- package/dist/config/imagetools.d.ts +71 -71
- package/dist/config/typedef.js +8 -8
- package/dist/constants/errors/api.js +9 -9
- package/dist/constants/errors/generic.js +5 -5
- package/dist/constants/errors/index.js +3 -3
- package/dist/constants/errors/jwt.js +5 -5
- package/dist/constants/http/headers.js +6 -6
- package/dist/constants/http/index.js +2 -2
- package/dist/constants/http/methods.js +2 -2
- package/dist/constants/index.js +3 -3
- package/dist/constants/mime/application.js +5 -5
- package/dist/constants/mime/audio.js +13 -13
- package/dist/constants/mime/image.js +3 -3
- package/dist/constants/mime/index.js +4 -4
- package/dist/constants/mime/text.js +2 -2
- package/dist/constants/regexp/index.js +31 -31
- package/dist/constants/regexp/inspiratie.js__ +95 -95
- package/dist/constants/regexp/text.js +49 -49
- package/dist/constants/regexp/user.js +32 -32
- package/dist/constants/regexp/web.js +3 -3
- package/dist/constants/state-labels/input-states.js +11 -11
- package/dist/constants/state-labels/submit-states.js +4 -4
- package/dist/constants/time.js +28 -28
- package/dist/css/tw-prose.postcss__ +259 -259
- package/dist/css/utilities.postcss +43 -43
- package/dist/{design-system → design}/design-config.js +73 -73
- package/dist/{design-system → design}/tailwind-theme-extend.d.ts +4 -4
- package/dist/{design-system → design}/tailwind-theme-extend.js +151 -151
- package/dist/schemas/index.js +1 -1
- package/dist/schemas/validate-url.js +180 -180
- package/dist/server/index.js +1 -1
- package/dist/server/logger.js +94 -94
- package/dist/states/index.js +1 -1
- package/dist/states/navigation.svelte.js +55 -55
- package/dist/stores/index.js +1 -1
- package/dist/stores/theme.js +80 -80
- package/dist/themes/hkdev/components/blocks/text-block.postcss +40 -40
- package/dist/themes/hkdev/components/boxes/game-box.postcss +13 -13
- package/dist/themes/hkdev/components/buttons/button-text.postcss +34 -34
- package/dist/themes/hkdev/components/buttons/button.postcss +138 -138
- package/dist/themes/hkdev/components/buttons/skip-button.postcss +8 -8
- package/dist/themes/hkdev/components/inputs/text-input.postcss +108 -108
- package/dist/themes/hkdev/components/panels/plain-panel.postcss +46 -46
- package/dist/themes/hkdev/components/panels/speech-bubble.postcss +52 -52
- package/dist/themes/hkdev/components/rows/panel-grid-row.postcss +7 -7
- package/dist/themes/hkdev/components/rows/panel-row-2.postcss +9 -9
- package/dist/themes/hkdev/components.postcss +55 -55
- package/dist/themes/hkdev/debug.postcss +1 -1
- package/dist/themes/hkdev/global/layout.postcss +39 -39
- package/dist/themes/hkdev/global/on-colors.postcss +53 -53
- package/dist/themes/hkdev/global/text.postcss__ +34 -34
- package/dist/themes/hkdev/global/vars.postcss__ +7 -7
- package/dist/themes/hkdev/globals.postcss +11 -11
- package/dist/themes/hkdev/responsive.postcss +12 -12
- package/dist/themes/hkdev/theme-ext.js +15 -15
- package/dist/themes/hkdev/theme.js +227 -227
- package/dist/themes/index.js +1 -1
- package/dist/util/array/index.js +455 -455
- package/dist/util/compare/index.js +247 -247
- package/dist/util/css/css-vars.js +83 -83
- package/dist/util/css/index.js +1 -1
- package/dist/util/design-system/components/states.js +22 -22
- package/dist/util/design-system/css/clamp.d.ts +2 -2
- package/dist/util/design-system/css/clamp.js +66 -66
- package/dist/util/design-system/css/root-design-vars.js +100 -100
- package/dist/util/design-system/index.js +5 -5
- package/dist/util/design-system/layout/scaling.js +97 -97
- package/dist/util/design-system/tailwind.js +289 -289
- package/dist/util/expect/arrays.js +47 -47
- package/dist/util/expect/index.js +259 -259
- package/dist/util/expect/primitives.js +55 -55
- package/dist/util/expect/url.js +60 -60
- package/dist/util/function/index.js +218 -218
- package/dist/util/http/errors.js +97 -97
- package/dist/util/http/headers.js +45 -45
- package/dist/util/http/http-request.js +273 -273
- package/dist/util/http/index.js +22 -22
- package/dist/util/http/json-request.js +143 -143
- package/dist/util/http/mocks.js +65 -65
- package/dist/util/http/response.js +228 -228
- package/dist/util/http/url.js +52 -52
- package/dist/util/image/index.js +86 -86
- package/dist/util/index.js +2 -2
- package/dist/util/is/index.js +140 -140
- package/dist/util/iterate/index.js +234 -234
- package/dist/util/object/index.js +1361 -1361
- package/dist/util/singleton/index.js +97 -97
- package/dist/util/string/index.js +184 -184
- package/dist/util/svelte/index.js +2 -2
- package/dist/util/svelte/observe/index.js +49 -49
- package/dist/util/svelte/state-context/index.js +83 -83
- package/dist/util/svelte/wait/index.js +38 -38
- package/dist/util/sveltekit/index.js +1 -1
- package/dist/util/sveltekit/route-folders/index.js +82 -82
- package/dist/util/time/index.js +339 -339
- package/dist/valibot/date.js__ +10 -10
- package/dist/valibot/index.js +9 -9
- package/dist/valibot/url.js +95 -95
- package/dist/valibot/user.js +23 -23
- package/dist/zod/all.js +33 -33
- package/dist/zod/generic.js +11 -11
- package/dist/zod/javascript.js +32 -32
- package/dist/zod/user.js +16 -16
- package/dist/zod/web.js +52 -52
- package/package.json +99 -99
- package/dist/themes/hkdev/components/buttons/button.postcss__ +0 -40
- package/dist/themes/hkdev/components/buttons/button.postcss___ +0 -91
- /package/dist/classes/{svkit → svelte}/audio/AudioLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/audio/AudioScene.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/audio/mocks.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/final-state-machine/FiniteStateMachine.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/final-state-machine/index.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/image/ImageLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/image/ImageScene.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/image/ImageVariantsLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/image/index.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/image/mocks.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/image/typedef.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/loading-state-machine/LoadingStateMachine.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/loading-state-machine/constants.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/loading-state-machine/index.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/network-loader/NetworkLoader.svelte.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/network-loader/constants.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/network-loader/index.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/network-loader/mocks.d.ts +0 -0
- /package/dist/classes/{svkit → svelte}/network-loader/typedef.d.ts +0 -0
- /package/dist/{design-system → design}/design-config.d.ts +0 -0
@@ -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(
|
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}
|
60
|
-
* @param {number}
|
61
|
-
* @param {number} max - Maximum value
|
62
|
-
* @returns {number} Clamped value
|
63
|
-
*/
|
64
|
-
export function clamp(
|
65
|
-
return Math.max(min, Math.min(
|
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
|
+
}
|