@hkdigital/lib-sveltekit 0.0.97 → 0.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/svelte/image/ImageVariantsLoader.svelte.d.ts +9 -2
- package/dist/classes/svelte/image/ImageVariantsLoader.svelte.js +38 -31
- package/dist/components/image/EnhancedImage.svelte__ +162 -0
- package/dist/components/image/ImageBox.svelte +104 -145
- package/dist/components/image/ImageBox.svelte.d.ts +6 -49
- package/dist/components/image/ImageBox.svelte__ +242 -0
- package/dist/components/image/ImageBox.svelte___ +241 -0
- package/dist/components/image/ResponsiveImage.svelte +2 -14
- package/dist/components/image/ResponsiveImage.svelte__ +90 -0
- package/dist/components/image/index.d.ts +0 -1
- package/dist/components/image/index.js +0 -1
- package/dist/components/inputs/text-input/TextInput.svelte +2 -2
- package/dist/config/tailwind.extend.d.ts +7 -0
- package/dist/config/tailwind.extend.js +8 -0
- package/dist/constants/index.js +1 -1
- package/dist/constants/state-labels/submit-states.d.ts +4 -0
- package/dist/constants/state-labels/submit-states.js +4 -0
- package/dist/util/image/index.d.ts +16 -0
- package/dist/util/image/index.js +62 -0
- package/package.json +2 -2
- package/dist/constants/css-states/index.d.ts +0 -1
- package/dist/constants/css-states/index.js +0 -1
- /package/dist/constants/{css-states → state-labels}/input-states.d.ts +0 -0
- /package/dist/constants/{css-states → state-labels}/input-states.js +0 -0
package/dist/util/image/index.js
CHANGED
@@ -22,3 +22,65 @@ export function toSingleImageMeta(imageMeta) {
|
|
22
22
|
|
23
23
|
throw new Error('Invalid value for parameter [imageMeta]');
|
24
24
|
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Calculate effective width based on container dimensions and fit mode
|
28
|
+
*
|
29
|
+
* @param {object} params
|
30
|
+
* @param {number} [params.containerWidth] Container width in pixels
|
31
|
+
* @param {number} [params.containerHeight] Container height in pixels
|
32
|
+
* @param {number} params.imageAspectRatio Original image aspect ratio (width/height)
|
33
|
+
* @param {'cover'|'contain'|'fill'} [params.fit='contain'] Fit mode
|
34
|
+
* @returns {number} Effective width needed
|
35
|
+
*/
|
36
|
+
export function calculateEffectiveWidth({
|
37
|
+
containerWidth,
|
38
|
+
containerHeight,
|
39
|
+
imageAspectRatio,
|
40
|
+
fit = 'contain'
|
41
|
+
}) {
|
42
|
+
if (containerWidth && !containerHeight) {
|
43
|
+
// If only width is provided, use it
|
44
|
+
|
45
|
+
return containerWidth;
|
46
|
+
}
|
47
|
+
|
48
|
+
if (!containerWidth && containerHeight) {
|
49
|
+
// If only height is provided, calculate width based on aspect ratio
|
50
|
+
|
51
|
+
return containerHeight * imageAspectRatio;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (containerWidth && containerHeight) {
|
55
|
+
// If both dimensions are provided, calculate based on fit mode
|
56
|
+
|
57
|
+
const containerAspectRatio = containerWidth / containerHeight;
|
58
|
+
|
59
|
+
switch (fit) {
|
60
|
+
case 'fill':
|
61
|
+
return containerWidth;
|
62
|
+
|
63
|
+
case 'contain':
|
64
|
+
if (containerAspectRatio > imageAspectRatio) {
|
65
|
+
// Height constrained, scale width accordingly
|
66
|
+
|
67
|
+
return containerHeight * imageAspectRatio;
|
68
|
+
}
|
69
|
+
return containerWidth;
|
70
|
+
|
71
|
+
case 'cover':
|
72
|
+
if (containerAspectRatio < imageAspectRatio) {
|
73
|
+
// Height constrained, scale width accordingly
|
74
|
+
|
75
|
+
return containerHeight * imageAspectRatio;
|
76
|
+
}
|
77
|
+
return containerWidth;
|
78
|
+
|
79
|
+
default:
|
80
|
+
return containerWidth;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
// Fallback if neither dimension is provided
|
85
|
+
throw new Error('Either containerWidth or containerHeight must be provided');
|
86
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hkdigital/lib-sveltekit",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.99",
|
4
4
|
"author": {
|
5
5
|
"name": "HKdigital",
|
6
6
|
"url": "https://hkdigital.nl"
|
@@ -70,6 +70,7 @@
|
|
70
70
|
"@sveltejs/adapter-auto": "^3.3.1",
|
71
71
|
"@sveltejs/package": "^2.3.7",
|
72
72
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
73
|
+
"@tailwindcss/typography": "^0.5.16",
|
73
74
|
"@types/eslint": "^9.6.1",
|
74
75
|
"autoprefixer": "^10.4.20",
|
75
76
|
"cross-env": "^7.0.3",
|
@@ -94,7 +95,6 @@
|
|
94
95
|
"vitest": "^2.1.8"
|
95
96
|
},
|
96
97
|
"dependencies": {
|
97
|
-
"@tailwindcss/typography": "^0.5.16",
|
98
98
|
"zod": "^3.24.1"
|
99
99
|
}
|
100
100
|
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./input-states.js";
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './input-states.js';
|
File without changes
|
File without changes
|