@vettvangur/design-system 2.0.30 → 2.0.32
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/index.js +131 -51
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1494,8 +1494,12 @@ function normalizeModeKey$1(k) {
|
|
|
1494
1494
|
}
|
|
1495
1495
|
function toTextKey(rawKey) {
|
|
1496
1496
|
// "font-size-headline-1" -> "text-headline-1"
|
|
1497
|
-
if (rawKey.startsWith('font-size-'))
|
|
1498
|
-
|
|
1497
|
+
if (rawKey.startsWith('font-size-')) {
|
|
1498
|
+
return `text-${rawKey.slice('font-size-'.length)}`;
|
|
1499
|
+
}
|
|
1500
|
+
if (rawKey.startsWith('text-')) {
|
|
1501
|
+
return rawKey;
|
|
1502
|
+
}
|
|
1499
1503
|
return `text-${rawKey}`;
|
|
1500
1504
|
}
|
|
1501
1505
|
async function normalizeFontSizes(variableSet) {
|
|
@@ -1523,7 +1527,9 @@ function toLeadingKey(rawKey) {
|
|
|
1523
1527
|
if (rawKey.startsWith('font-line-height-')) {
|
|
1524
1528
|
return `leading-${rawKey.slice('font-line-height-'.length)}`;
|
|
1525
1529
|
}
|
|
1526
|
-
if (rawKey.startsWith('leading-'))
|
|
1530
|
+
if (rawKey.startsWith('leading-')) {
|
|
1531
|
+
return rawKey;
|
|
1532
|
+
}
|
|
1527
1533
|
return `leading-${rawKey}`;
|
|
1528
1534
|
}
|
|
1529
1535
|
async function normalizeLineHeights(variableSet) {
|
|
@@ -1551,7 +1557,9 @@ function bodyIndexFromTextKey(k) {
|
|
|
1551
1557
|
return m ? m[1] : null;
|
|
1552
1558
|
}
|
|
1553
1559
|
function needsDesktopLine$1(values) {
|
|
1554
|
-
if (!values)
|
|
1560
|
+
if (!values) {
|
|
1561
|
+
return false;
|
|
1562
|
+
}
|
|
1555
1563
|
return values.desktop !== values.mobile;
|
|
1556
1564
|
}
|
|
1557
1565
|
function blockForBody(b) {
|
|
@@ -1581,13 +1589,25 @@ async function generateBodies(sizes, lineHeights, config) {
|
|
|
1581
1589
|
const nlh = await normalizeLineHeights(lineHeights);
|
|
1582
1590
|
const bodies = [];
|
|
1583
1591
|
for (const [textKey, fs] of Object.entries(nfs ?? {})) {
|
|
1584
|
-
if (!fs)
|
|
1585
|
-
|
|
1592
|
+
if (!fs) {
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
if (isHeadlineKey$1(textKey)) {
|
|
1596
|
+
continue;
|
|
1597
|
+
}
|
|
1586
1598
|
let lhKey = null;
|
|
1587
1599
|
const n = bodyIndexFromTextKey(textKey);
|
|
1588
|
-
if (n)
|
|
1600
|
+
if (n) {
|
|
1601
|
+
lhKey = `leading-body-${n}`;
|
|
1602
|
+
} else if (textKey === 'text-blockquote') {
|
|
1603
|
+
lhKey = 'leading-blockquote';
|
|
1604
|
+
} else {
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1589
1607
|
const lh = nlh?.[lhKey];
|
|
1590
|
-
if (!lh)
|
|
1608
|
+
if (!lh) {
|
|
1609
|
+
continue;
|
|
1610
|
+
}
|
|
1591
1611
|
bodies.push({
|
|
1592
1612
|
key: textKey.replace(/^text-/, ''),
|
|
1593
1613
|
// body-1 | body-2 | ... | blockquote
|
|
@@ -1617,7 +1637,9 @@ function headlineIndexFromTextKey(k) {
|
|
|
1617
1637
|
return m ? m[1] : null;
|
|
1618
1638
|
}
|
|
1619
1639
|
function needsDesktopLine(values) {
|
|
1620
|
-
if (!values)
|
|
1640
|
+
if (!values) {
|
|
1641
|
+
return false;
|
|
1642
|
+
}
|
|
1621
1643
|
return values.desktop !== values.mobile;
|
|
1622
1644
|
}
|
|
1623
1645
|
function blockForHeadline(h) {
|
|
@@ -1650,13 +1672,21 @@ async function generateHeadlines(sizes, lineHeights, config) {
|
|
|
1650
1672
|
const nlh = await normalizeLineHeights(lineHeights);
|
|
1651
1673
|
const headlines = [];
|
|
1652
1674
|
for (const [textKey, fs] of Object.entries(nfs ?? {})) {
|
|
1653
|
-
if (!fs)
|
|
1654
|
-
|
|
1675
|
+
if (!fs) {
|
|
1676
|
+
continue;
|
|
1677
|
+
}
|
|
1678
|
+
if (!isHeadlineKey(textKey)) {
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1655
1681
|
const n = headlineIndexFromTextKey(textKey);
|
|
1656
|
-
if (!n)
|
|
1682
|
+
if (!n) {
|
|
1683
|
+
continue;
|
|
1684
|
+
}
|
|
1657
1685
|
const lhKey = `leading-headline-${n}`;
|
|
1658
1686
|
const lh = nlh?.[lhKey];
|
|
1659
|
-
if (!lh)
|
|
1687
|
+
if (!lh) {
|
|
1688
|
+
continue;
|
|
1689
|
+
}
|
|
1660
1690
|
headlines.push({
|
|
1661
1691
|
key: textKey.replace(/^text-/, ''),
|
|
1662
1692
|
// headline-1 | headline-2 | ...
|
|
@@ -1678,11 +1708,30 @@ async function generateHeadlines(sizes, lineHeights, config) {
|
|
|
1678
1708
|
message(`finished generating (${headlines.length}) headline utilities`);
|
|
1679
1709
|
}
|
|
1680
1710
|
|
|
1711
|
+
function rem(px) {
|
|
1712
|
+
const n = Number(px);
|
|
1713
|
+
if (!Number.isFinite(n)) {
|
|
1714
|
+
return String(px);
|
|
1715
|
+
}
|
|
1716
|
+
if (n === 0) {
|
|
1717
|
+
return '0';
|
|
1718
|
+
}
|
|
1719
|
+
const v = n / 16;
|
|
1720
|
+
// Keep output stable and readable (no long floats)
|
|
1721
|
+
const rounded = Math.round(v * 1000000) / 1000000;
|
|
1722
|
+
return `${rounded}rem`;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1681
1725
|
async function renderTypography(tokens, config) {
|
|
1682
|
-
let css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n` + `@theme {\n` + ` --text-0:
|
|
1726
|
+
let css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n` + `@theme {\n` + ` --text-0: 0;\n` + ` --text-full: 100%;\n` + ` --leading-0: 0;\n` + ` --leading-full: 100%;\n`;
|
|
1683
1727
|
const emit = (key, value) => {
|
|
1684
|
-
if (value == null)
|
|
1685
|
-
|
|
1728
|
+
if (value == null) {
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
if (typeof value === 'number') {
|
|
1732
|
+
const v = value === 0 ? '0' : rem(value);
|
|
1733
|
+
return ` --${key}: ${v};\n`;
|
|
1734
|
+
}
|
|
1686
1735
|
return ` --${key}: ${String(value)};\n`; // already has units
|
|
1687
1736
|
};
|
|
1688
1737
|
for (const [key, token] of Object.entries(tokens || {})) {
|
|
@@ -1716,9 +1765,13 @@ function modeKey(raw) {
|
|
|
1716
1765
|
return kebab$1(raw);
|
|
1717
1766
|
}
|
|
1718
1767
|
function pickNumber(values, preferredMode) {
|
|
1719
|
-
if (!values || typeof values !== 'object')
|
|
1768
|
+
if (!values || typeof values !== 'object') {
|
|
1769
|
+
return null;
|
|
1770
|
+
}
|
|
1720
1771
|
const direct = values[preferredMode];
|
|
1721
|
-
if (typeof direct === 'number')
|
|
1772
|
+
if (typeof direct === 'number') {
|
|
1773
|
+
return direct;
|
|
1774
|
+
}
|
|
1722
1775
|
const normalizedPreferred = modeKey(preferredMode) ;
|
|
1723
1776
|
if (normalizedPreferred && typeof values[normalizedPreferred] === 'number') {
|
|
1724
1777
|
return values[normalizedPreferred];
|
|
@@ -1731,22 +1784,30 @@ function renderTheme$1(lines) {
|
|
|
1731
1784
|
}
|
|
1732
1785
|
function ensureVar(lines, varName, value) {
|
|
1733
1786
|
const exists = lines.some(l => l.startsWith(` ${varName}:`));
|
|
1734
|
-
if (!exists)
|
|
1787
|
+
if (!exists) {
|
|
1788
|
+
lines.unshift(` ${varName}: ${value};`);
|
|
1789
|
+
}
|
|
1735
1790
|
}
|
|
1736
1791
|
|
|
1737
1792
|
// Hoisted: unit policy lives here
|
|
1738
|
-
function
|
|
1739
|
-
if (n == null)
|
|
1740
|
-
|
|
1741
|
-
|
|
1793
|
+
function addRem(map, name, n) {
|
|
1794
|
+
if (n == null) {
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
if (map.has(name)) {
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
map.set(name, n === 0 ? '0' : rem(n));
|
|
1742
1801
|
}
|
|
1743
1802
|
function generateSpacingCss(scales) {
|
|
1744
1803
|
const map = new Map();
|
|
1745
1804
|
const takeNumericGroup = group => {
|
|
1746
1805
|
for (const [tokenKey, token] of Object.entries(group || {})) {
|
|
1747
1806
|
const v = pickNumber(token?.values, 'Mode 1');
|
|
1748
|
-
if (v == null)
|
|
1749
|
-
|
|
1807
|
+
if (v == null) {
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
addRem(map, `--spacing-${kebab$1(tokenKey)}`, v);
|
|
1750
1811
|
}
|
|
1751
1812
|
};
|
|
1752
1813
|
|
|
@@ -1758,9 +1819,11 @@ function generateSpacingCss(scales) {
|
|
|
1758
1819
|
// vertical: scale-60 -> vertical-60
|
|
1759
1820
|
for (const [tokenKey, token] of Object.entries(scales?.vertical || {})) {
|
|
1760
1821
|
const v = pickNumber(token?.values, 'Mode 1');
|
|
1761
|
-
if (v == null)
|
|
1822
|
+
if (v == null) {
|
|
1823
|
+
continue;
|
|
1824
|
+
}
|
|
1762
1825
|
const k = kebab$1(tokenKey).replace(/^scale-/, '');
|
|
1763
|
-
|
|
1826
|
+
addRem(map, `--spacing-vertical-${k}`, v);
|
|
1764
1827
|
}
|
|
1765
1828
|
const lines = Array.from(map.entries()).map(([k, v]) => ` ${k}: ${v};`);
|
|
1766
1829
|
|
|
@@ -1776,8 +1839,10 @@ function generateBorderCss(scales) {
|
|
|
1776
1839
|
const map = new Map();
|
|
1777
1840
|
for (const [tokenKey, token] of Object.entries(scales?.border || {})) {
|
|
1778
1841
|
const v = pickNumber(token?.values, 'Mode 1');
|
|
1779
|
-
if (v == null)
|
|
1780
|
-
|
|
1842
|
+
if (v == null) {
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
addRem(map, `--border-${kebab$1(tokenKey)}`, v);
|
|
1781
1846
|
}
|
|
1782
1847
|
const lines = Array.from(map.entries()).map(([k, v]) => ` ${k}: ${v};`);
|
|
1783
1848
|
|
|
@@ -1791,17 +1856,21 @@ function generateRadiusCss(scales) {
|
|
|
1791
1856
|
const k = kebab$1(tokenKey);
|
|
1792
1857
|
|
|
1793
1858
|
// skip these entirely (manual vars below)
|
|
1794
|
-
if (k === 'round' || k === 'circle')
|
|
1859
|
+
if (k === 'round' || k === 'circle') {
|
|
1860
|
+
continue;
|
|
1861
|
+
}
|
|
1795
1862
|
const v = pickNumber(token?.values, 'Mode 1');
|
|
1796
|
-
if (v == null)
|
|
1797
|
-
|
|
1863
|
+
if (v == null) {
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
addRem(map, `--radius-${k}`, v);
|
|
1798
1867
|
}
|
|
1799
1868
|
const lines = Array.from(map.entries()).map(([k, v]) => ` ${k}: ${v};`);
|
|
1800
1869
|
|
|
1801
1870
|
// manual required defaults
|
|
1802
1871
|
ensureVar(lines, '--radius-0', '0');
|
|
1803
1872
|
ensureVar(lines, '--radius-circle', '50%');
|
|
1804
|
-
ensureVar(lines, '--radius-rounded',
|
|
1873
|
+
ensureVar(lines, '--radius-rounded', rem(100));
|
|
1805
1874
|
return `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n` + renderTheme$1(lines);
|
|
1806
1875
|
}
|
|
1807
1876
|
async function generateScales(variableSet, config) {
|
|
@@ -1825,7 +1894,9 @@ function kebab(s) {
|
|
|
1825
1894
|
function toShadowKey(rawKey) {
|
|
1826
1895
|
// enforce "shadow-x"
|
|
1827
1896
|
const k = kebab(rawKey);
|
|
1828
|
-
if (k.startsWith('shadow-'))
|
|
1897
|
+
if (k.startsWith('shadow-')) {
|
|
1898
|
+
return k;
|
|
1899
|
+
}
|
|
1829
1900
|
return `shadow-${k}`;
|
|
1830
1901
|
}
|
|
1831
1902
|
function rgbaFromColor(color) {
|
|
@@ -1844,7 +1915,9 @@ function rgbaFromColor(color) {
|
|
|
1844
1915
|
const hex = String(color?.hex ?? '').trim();
|
|
1845
1916
|
// supports #RRGGBB or #RRGGBBAA
|
|
1846
1917
|
const m = hex.match(/^#?([0-9a-f]{6})([0-9a-f]{2})?$/i);
|
|
1847
|
-
if (!m)
|
|
1918
|
+
if (!m) {
|
|
1919
|
+
return null;
|
|
1920
|
+
}
|
|
1848
1921
|
const rgb = m[1];
|
|
1849
1922
|
const aa = m[2];
|
|
1850
1923
|
const rr = parseInt(rgb.slice(0, 2), 16);
|
|
@@ -1854,7 +1927,9 @@ function rgbaFromColor(color) {
|
|
|
1854
1927
|
return `rgba(${rr} ${gg} ${bb} / ${alpha})`;
|
|
1855
1928
|
}
|
|
1856
1929
|
function effectToBoxShadow(effect) {
|
|
1857
|
-
if (!effect || effect.kind !== 'DROP_SHADOW')
|
|
1930
|
+
if (!effect || effect.kind !== 'DROP_SHADOW') {
|
|
1931
|
+
return null;
|
|
1932
|
+
}
|
|
1858
1933
|
const x = Number(effect.offset?.x ?? 0);
|
|
1859
1934
|
const y = Number(effect.offset?.y ?? 0);
|
|
1860
1935
|
const blur = Number(effect.radius ?? 0);
|
|
@@ -1862,13 +1937,16 @@ function effectToBoxShadow(effect) {
|
|
|
1862
1937
|
const color = rgbaFromColor(effect.color) ?? 'rgba(0 0 0 / 0.25)';
|
|
1863
1938
|
|
|
1864
1939
|
// "x y blur spread color"
|
|
1865
|
-
|
|
1940
|
+
const len = n => n === 0 ? '0' : rem(n);
|
|
1941
|
+
return `${len(x)} ${len(y)} ${len(blur)} ${len(spread)} ${color}`;
|
|
1866
1942
|
}
|
|
1867
1943
|
function buildShadowValue(effects) {
|
|
1868
1944
|
const parts = [];
|
|
1869
1945
|
for (const e of effects || []) {
|
|
1870
1946
|
const s = effectToBoxShadow(e);
|
|
1871
|
-
if (s)
|
|
1947
|
+
if (s) {
|
|
1948
|
+
parts.push(s);
|
|
1949
|
+
}
|
|
1872
1950
|
}
|
|
1873
1951
|
return parts.length ? parts.join(', ') : null;
|
|
1874
1952
|
}
|
|
@@ -1881,7 +1959,9 @@ async function generateShadows(variableSet, config) {
|
|
|
1881
1959
|
for (const [rawKey, token] of Object.entries(variableSet || {})) {
|
|
1882
1960
|
const key = toShadowKey(rawKey);
|
|
1883
1961
|
const value = buildShadowValue(token?.effects);
|
|
1884
|
-
if (!value)
|
|
1962
|
+
if (!value) {
|
|
1963
|
+
continue;
|
|
1964
|
+
}
|
|
1885
1965
|
lines.push(` --${key}: ${value};`);
|
|
1886
1966
|
}
|
|
1887
1967
|
const css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n` + renderTheme(lines);
|
|
@@ -1893,17 +1973,17 @@ async function generateShadows(variableSet, config) {
|
|
|
1893
1973
|
const BREAKPOINTS_CSS = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */
|
|
1894
1974
|
|
|
1895
1975
|
@theme {
|
|
1896
|
-
--breakpoint-phone-xs:
|
|
1897
|
-
--breakpoint-phone-s:
|
|
1898
|
-
--breakpoint-phone-m:
|
|
1899
|
-
--breakpoint-tablet:
|
|
1900
|
-
--breakpoint-desktop-xs:
|
|
1901
|
-
--breakpoint-desktop-s:
|
|
1902
|
-
--breakpoint-desktop-m:
|
|
1903
|
-
--breakpoint-desktop-l:
|
|
1904
|
-
--breakpoint-desktop-xl:
|
|
1905
|
-
--breakpoint-desktop-xxl:
|
|
1906
|
-
--breakpoint-ultrawide:
|
|
1976
|
+
--breakpoint-phone-xs: ${rem(0)};
|
|
1977
|
+
--breakpoint-phone-s: ${rem(321)};
|
|
1978
|
+
--breakpoint-phone-m: ${rem(426)};
|
|
1979
|
+
--breakpoint-tablet: ${rem(576)};
|
|
1980
|
+
--breakpoint-desktop-xs: ${rem(775)};
|
|
1981
|
+
--breakpoint-desktop-s: ${rem(992)};
|
|
1982
|
+
--breakpoint-desktop-m: ${rem(1200)};
|
|
1983
|
+
--breakpoint-desktop-l: ${rem(1280)};
|
|
1984
|
+
--breakpoint-desktop-xl: ${rem(1367)};
|
|
1985
|
+
--breakpoint-desktop-xxl: ${rem(1740)};
|
|
1986
|
+
--breakpoint-ultrawide: ${rem(2000)};
|
|
1907
1987
|
}
|
|
1908
1988
|
`;
|
|
1909
1989
|
async function generateScreens(config) {
|
|
@@ -2880,7 +2960,7 @@ async function generateNavigation(config, outpath) {
|
|
|
2880
2960
|
function renderDesignSystemViewCshtml(projectName) {
|
|
2881
2961
|
return `@* AUTO-GENERATED - DO NOT EDIT BY HAND *@
|
|
2882
2962
|
@{
|
|
2883
|
-
Layout = "Master.cshtml";
|
|
2963
|
+
Layout = "${ProjectName}Master.cshtml";
|
|
2884
2964
|
// This template will used later, right now users are redirected to /design-system/colors
|
|
2885
2965
|
}
|
|
2886
2966
|
<section class="ds">
|