@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.
@@ -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.97",
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';