@vettvangur/design-system 2.0.62 → 2.0.63

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 (2) hide show
  1. package/dist/index.js +47 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2154,6 +2154,34 @@ function normalizeValuesKeys(values) {
2154
2154
  function escapeCssSingleQuotedString(value) {
2155
2155
  return String(value).replace(/\\/g, '\\\\').replace(/'/g, "\\'");
2156
2156
  }
2157
+ function splitFontStack(raw) {
2158
+ return String(raw ?? '').split(',').map(p => p.trim()).filter(Boolean);
2159
+ }
2160
+ function maybeCollapseToBaseFont(raw, {
2161
+ baseTokenKey,
2162
+ baseFamily
2163
+ }) {
2164
+ // Collapse "Sharp Grotesk Medium 19" -> var(--font-body) when baseFamily is "Sharp Grotesk".
2165
+ // This keeps projects with a single font family from generating multiple (near-identical) families.
2166
+ // Does not hardcode any specific family name.
2167
+ const v = String(raw ?? '').trim();
2168
+ if (!v || !baseTokenKey || !baseFamily) {
2169
+ return raw;
2170
+ }
2171
+
2172
+ // Avoid changing var() or multi-stack definitions.
2173
+ if (/^var\(/.test(v) || v.includes(',')) {
2174
+ return raw;
2175
+ }
2176
+ const base = String(baseFamily).trim();
2177
+ if (!base) {
2178
+ return raw;
2179
+ }
2180
+ if (v === base || v.startsWith(`${base} `)) {
2181
+ return `var(--${baseTokenKey})`;
2182
+ }
2183
+ return raw;
2184
+ }
2157
2185
  function formatFontFamilyValue(raw) {
2158
2186
  if (raw == null) {
2159
2187
  return raw;
@@ -2164,7 +2192,7 @@ function formatFontFamilyValue(raw) {
2164
2192
  }
2165
2193
 
2166
2194
  // Allow comma-separated stacks and quote parts that would otherwise be parsed as separate identifiers.
2167
- const parts = s.split(',').map(p => p.trim()).filter(Boolean);
2195
+ const parts = splitFontStack(s);
2168
2196
  const formatted = parts.map(p => {
2169
2197
  // Keep CSS var() and already-quoted values.
2170
2198
  if (/^var\(/.test(p)) {
@@ -2226,9 +2254,25 @@ async function generateFontFamily(variableSet, config) {
2226
2254
  */
2227
2255
  async function generateFile(variables, config) {
2228
2256
  let css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n` + `@theme {\n`;
2257
+
2258
+ // If a project uses a single font family, designers sometimes encode style/optical size into the
2259
+ // "family" token (e.g. "Sharp Grotesk Medium 19"). For CSS, we usually want a stable family name.
2260
+ // We use the first part of the base token's mobile stack as the canonical family and collapse
2261
+ // other families that match (or start with) it.
2262
+ const baseTokenKey = Object.hasOwn(variables || {}, 'font-body') ? 'font-body' : null;
2263
+ const baseMobileRaw = baseTokenKey ? variables?.[baseTokenKey]?.values?.mobile : null;
2264
+ const baseFamily = baseMobileRaw ? splitFontStack(baseMobileRaw)[0] : null;
2229
2265
  for (const [key, token] of Object.entries(variables || {})) {
2230
- const mobile = formatFontFamilyValue(token?.values?.mobile);
2231
- const desktop = formatFontFamilyValue(token?.values?.desktop);
2266
+ const mobileRaw = key === baseTokenKey ? token?.values?.mobile : maybeCollapseToBaseFont(token?.values?.mobile, {
2267
+ baseTokenKey,
2268
+ baseFamily
2269
+ });
2270
+ const desktopRaw = key === baseTokenKey ? token?.values?.desktop : maybeCollapseToBaseFont(token?.values?.desktop, {
2271
+ baseTokenKey,
2272
+ baseFamily
2273
+ });
2274
+ const mobile = formatFontFamilyValue(mobileRaw);
2275
+ const desktop = formatFontFamilyValue(desktopRaw);
2232
2276
  if (mobile != null) {
2233
2277
  css += ` --${key}: ${mobile};\n`;
2234
2278
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vettvangur/design-system",
3
- "version": "2.0.62",
3
+ "version": "2.0.63",
4
4
  "description": "",
5
5
  "access": "public",
6
6
  "type": "module",