@latte-macchiat-io/latte-vanilla-components 0.0.324 → 0.0.326
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/package.json
CHANGED
@@ -5,6 +5,7 @@ import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
|
|
5
5
|
import { queries } from '../../styles/mediaqueries';
|
6
6
|
import { themeContract } from '../../theme/contract.css';
|
7
7
|
|
8
|
+
import { generateResponsive } from '../../utils/generateResponsive';
|
8
9
|
import { generateResponsiveMedia } from '../../utils/generateResponsiveMedia';
|
9
10
|
import { generateResponsiveMediaCalc } from '../../utils/generateResponsiveMediaCalc';
|
10
11
|
import { mergeResponsiveMedias } from '../../utils/mergeResponsiveMedias';
|
@@ -185,11 +186,18 @@ export const carouselBullets = style({
|
|
185
186
|
position: 'absolute',
|
186
187
|
justifyContent: 'center',
|
187
188
|
|
188
|
-
'@media':
|
189
|
-
|
189
|
+
'@media': generateResponsive(
|
190
|
+
{
|
190
191
|
gap: themeContract.carousel.bullet.gap,
|
191
|
-
}
|
192
|
-
|
192
|
+
},
|
193
|
+
[
|
194
|
+
{
|
195
|
+
property: 'top',
|
196
|
+
base: '100%',
|
197
|
+
offset: themeContract.carousel.bullet.positionVerticalOffset,
|
198
|
+
operator: '+',
|
199
|
+
},
|
200
|
+
]
|
193
201
|
),
|
194
202
|
});
|
195
203
|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
// utils/generateResponsive.ts
|
2
|
+
import { queries } from '../styles/mediaqueries';
|
3
|
+
|
4
|
+
type BreakpointKey = 'mobile' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
5
|
+
type ResponsiveValue = string | number | { toString(): string };
|
6
|
+
type BreakpointMap = Partial<Record<BreakpointKey, ResponsiveValue>>;
|
7
|
+
|
8
|
+
const BPS: BreakpointKey[] = ['mobile', 'sm', 'md', 'lg', 'xl', '2xl'];
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Generate fully responsive CSS object for Vanilla Extract
|
12
|
+
*
|
13
|
+
* @param props - normal CSS properties (string/number or responsive map)
|
14
|
+
* @param calcProps - optional array of calc() rules
|
15
|
+
* @returns object ready for `@media` in Vanilla Extract
|
16
|
+
*/
|
17
|
+
export function generateResponsive(
|
18
|
+
props: Record<string, ResponsiveValue | BreakpointMap>,
|
19
|
+
calcProps?: Array<{
|
20
|
+
property: string;
|
21
|
+
base: ResponsiveValue | BreakpointMap;
|
22
|
+
offset: ResponsiveValue | BreakpointMap;
|
23
|
+
operator?: string; // + - * / ...
|
24
|
+
}>
|
25
|
+
): Record<string, Record<string, string>> {
|
26
|
+
const result: Record<string, Record<string, string>> = {};
|
27
|
+
|
28
|
+
const toCssValue = (v: ResponsiveValue) => {
|
29
|
+
const s = String(v);
|
30
|
+
return s.startsWith('--') ? `var(${s})` : s;
|
31
|
+
};
|
32
|
+
|
33
|
+
// 1️⃣ Normal props
|
34
|
+
for (const [cssProp, valOrMap] of Object.entries(props)) {
|
35
|
+
const isMapLike =
|
36
|
+
valOrMap && typeof valOrMap === 'object' && !Array.isArray(valOrMap) && Object.keys(valOrMap).some((k) => BPS.includes(k as BreakpointKey));
|
37
|
+
|
38
|
+
if (isMapLike) {
|
39
|
+
const map = valOrMap as BreakpointMap;
|
40
|
+
for (const bp of BPS) {
|
41
|
+
const token = map[bp];
|
42
|
+
if (token === undefined) continue;
|
43
|
+
const media = queries[bp as keyof typeof queries];
|
44
|
+
if (!result[media]) result[media] = {};
|
45
|
+
result[media][cssProp] = toCssValue(token);
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
// single value => apply to all breakpoints
|
49
|
+
const token = valOrMap as ResponsiveValue;
|
50
|
+
for (const bp of BPS) {
|
51
|
+
const media = queries[bp as keyof typeof queries];
|
52
|
+
if (!result[media]) result[media] = {};
|
53
|
+
result[media][cssProp] = toCssValue(token);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
// 2️⃣ Calc props
|
59
|
+
if (calcProps) {
|
60
|
+
for (const { property, base, offset, operator = '+' } of calcProps) {
|
61
|
+
for (const bp of BPS) {
|
62
|
+
const media = queries[bp as keyof typeof queries];
|
63
|
+
|
64
|
+
// ✅ TypeScript safe access
|
65
|
+
const baseValue =
|
66
|
+
typeof base === 'object' && !Array.isArray(base) ? ((base as BreakpointMap)[bp] ?? Object.values(base as BreakpointMap)[0]) : base;
|
67
|
+
|
68
|
+
const offsetValue =
|
69
|
+
typeof offset === 'object' && !Array.isArray(offset)
|
70
|
+
? ((offset as BreakpointMap)[bp] ?? Object.values(offset as BreakpointMap)[0])
|
71
|
+
: offset;
|
72
|
+
|
73
|
+
if (!result[media]) result[media] = {};
|
74
|
+
result[media][property] = `calc(${baseValue} ${operator} ${offsetValue})`;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
return result;
|
80
|
+
}
|