@vettvangur/design-system 2.0.74 → 2.0.77
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 +80 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3776,7 +3776,7 @@ function generateSpacingCss(scales) {
|
|
|
3776
3776
|
const lines = Array.from(map.entries()).map(([k, v]) => ` ${k}: ${v};`);
|
|
3777
3777
|
|
|
3778
3778
|
// manual required defaults
|
|
3779
|
-
ensureVar(lines, '--spacing',
|
|
3779
|
+
ensureVar(lines, '--spacing', rem(1));
|
|
3780
3780
|
ensureVar(lines, '--spacing-0', '0');
|
|
3781
3781
|
ensureVar(lines, '--spacing-auto', 'auto');
|
|
3782
3782
|
ensureVar(lines, '--spacing-full', '100%');
|
|
@@ -3981,12 +3981,59 @@ function rgbaFromColor(color) {
|
|
|
3981
3981
|
const r = color?.rgba?.r;
|
|
3982
3982
|
const g = color?.rgba?.g;
|
|
3983
3983
|
const b = color?.rgba?.b;
|
|
3984
|
+
const normalizeRgbChannel = v => {
|
|
3985
|
+
if (typeof v !== 'number' || Number.isNaN(v)) {
|
|
3986
|
+
return null;
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
// Figma typically gives channels in 0..1, but some token sources provide 0..255.
|
|
3990
|
+
if (v >= 0 && v <= 1) {
|
|
3991
|
+
return Math.round(v * 255);
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
// Handle 16-bit channels (0..65535) defensively.
|
|
3995
|
+
if (v > 255 && v <= 65535) {
|
|
3996
|
+
return Math.round(Math.max(0, Math.min(255, v / 257)));
|
|
3997
|
+
}
|
|
3998
|
+
return Math.round(Math.max(0, Math.min(255, v)));
|
|
3999
|
+
};
|
|
4000
|
+
const normalizeAlpha = v => {
|
|
4001
|
+
if (typeof v !== 'number' || Number.isNaN(v)) {
|
|
4002
|
+
return null;
|
|
4003
|
+
}
|
|
4004
|
+
|
|
4005
|
+
// Common cases: 0..1, percent (0..100), or 0..255.
|
|
4006
|
+
//
|
|
4007
|
+
// Figma color alpha comes through as 0..1 (e.g. 4% => 0.04). For shadows we want
|
|
4008
|
+
// that 4% to land as 0.4 in generated CSS (historical parity with our tokens),
|
|
4009
|
+
// so we scale very small fractional alphas up by 10.
|
|
4010
|
+
let a = v;
|
|
4011
|
+
if (a > 1 && a <= 10) {
|
|
4012
|
+
// Some sources provide alpha in a 0..10 scale (e.g. 4 => 0.4)
|
|
4013
|
+
a /= 10;
|
|
4014
|
+
} else if (a > 10 && a <= 100) {
|
|
4015
|
+
a /= 100;
|
|
4016
|
+
} else if (a > 100 && a <= 255) {
|
|
4017
|
+
a /= 255;
|
|
4018
|
+
} else if (a > 0 && a <= 0.1) {
|
|
4019
|
+
// Figma: 4% is 0.04; we want 0.4.
|
|
4020
|
+
a *= 10;
|
|
4021
|
+
}
|
|
4022
|
+
a = Math.max(0, Math.min(1, a));
|
|
4023
|
+
|
|
4024
|
+
// Avoid long float tails from upstream values.
|
|
4025
|
+
const rounded = Number(a.toFixed(4));
|
|
4026
|
+
return String(rounded);
|
|
4027
|
+
};
|
|
3984
4028
|
if ([r, g, b, a].every(v => typeof v === 'number')) {
|
|
3985
|
-
const rr =
|
|
3986
|
-
const gg =
|
|
3987
|
-
const bb =
|
|
3988
|
-
const aa =
|
|
3989
|
-
|
|
4029
|
+
const rr = normalizeRgbChannel(r);
|
|
4030
|
+
const gg = normalizeRgbChannel(g);
|
|
4031
|
+
const bb = normalizeRgbChannel(b);
|
|
4032
|
+
const aa = normalizeAlpha(a);
|
|
4033
|
+
if ([rr, gg, bb, aa].every(v => v != null)) {
|
|
4034
|
+
// Use legacy comma-separated rgba() for maximum tool compatibility.
|
|
4035
|
+
return `rgba(${rr}, ${gg}, ${bb}, ${aa})`;
|
|
4036
|
+
}
|
|
3990
4037
|
}
|
|
3991
4038
|
const hex = String(color?.hex ?? '').trim();
|
|
3992
4039
|
// supports #RRGGBB or #RRGGBBAA
|
|
@@ -4000,7 +4047,10 @@ function rgbaFromColor(color) {
|
|
|
4000
4047
|
const gg = parseInt(rgb.slice(2, 4), 16);
|
|
4001
4048
|
const bb = parseInt(rgb.slice(4, 6), 16);
|
|
4002
4049
|
const alpha = aa ? parseInt(aa, 16) / 255 : 1;
|
|
4003
|
-
|
|
4050
|
+
const alphaStr = String(Number(Math.max(0, Math.min(1, alpha)).toFixed(4)));
|
|
4051
|
+
|
|
4052
|
+
// Use legacy comma-separated rgba() for maximum tool compatibility.
|
|
4053
|
+
return `rgba(${rr}, ${gg}, ${bb}, ${alphaStr})`;
|
|
4004
4054
|
}
|
|
4005
4055
|
|
|
4006
4056
|
/**
|
|
@@ -4072,6 +4122,16 @@ function renderTheme(lines) {
|
|
|
4072
4122
|
return `@theme {\n${lines.join('\n')}\n}\n`;
|
|
4073
4123
|
}
|
|
4074
4124
|
|
|
4125
|
+
/**
|
|
4126
|
+
* Render utilities.
|
|
4127
|
+
*
|
|
4128
|
+
* @param blocks - Value.
|
|
4129
|
+
* @returns String result.
|
|
4130
|
+
*/
|
|
4131
|
+
function renderUtilities(blocks) {
|
|
4132
|
+
return blocks.length ? `${blocks.join('\n\n')}\n` : '';
|
|
4133
|
+
}
|
|
4134
|
+
|
|
4075
4135
|
/**
|
|
4076
4136
|
* Generate shadows.
|
|
4077
4137
|
*
|
|
@@ -4087,19 +4147,21 @@ function renderTheme(lines) {
|
|
|
4087
4147
|
*/
|
|
4088
4148
|
async function generateShadows(variableSet, config) {
|
|
4089
4149
|
message('generating shadows...');
|
|
4090
|
-
const
|
|
4150
|
+
const themeLines = [];
|
|
4151
|
+
const utilityBlocks = [];
|
|
4091
4152
|
for (const [rawKey, token] of Object.entries(variableSet || {})) {
|
|
4092
4153
|
const key = toShadowKey(rawKey);
|
|
4093
4154
|
const value = buildShadowValue(token?.effects);
|
|
4094
4155
|
if (!value) {
|
|
4095
4156
|
continue;
|
|
4096
4157
|
}
|
|
4097
|
-
|
|
4158
|
+
themeLines.push(` --${key}: ${value};`);
|
|
4159
|
+
utilityBlocks.push(`@utility ${key} {\n box-shadow: var(--${key});\n}`);
|
|
4098
4160
|
}
|
|
4099
|
-
const css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n${renderTheme(
|
|
4161
|
+
const css = `/* AUTO-GENERATED - DO NOT EDIT BY HAND */\n\n${renderTheme(themeLines)}\n${renderUtilities(utilityBlocks)}`;
|
|
4100
4162
|
const outPath = path.join(config.paths.styles, 'config', 'shadow.css');
|
|
4101
4163
|
await fs$1.writeFile(outPath, css, 'utf8');
|
|
4102
|
-
message(`finished generating shadows (${
|
|
4164
|
+
message(`finished generating shadows (${themeLines.length})`);
|
|
4103
4165
|
}
|
|
4104
4166
|
|
|
4105
4167
|
/**
|
|
@@ -4340,7 +4402,13 @@ async function generateTailwind(config, projectType, typography, buttons, colors
|
|
|
4340
4402
|
message(pc.yellow('-=[ tailwind ]=-'));
|
|
4341
4403
|
await generateFontFamily(typography.families, config);
|
|
4342
4404
|
await generateFontWeight(typography.weights, config);
|
|
4343
|
-
|
|
4405
|
+
const skipButtonVariants = process.env.DS_SKIP_BUTTON_VARIANTS === '1' || process.env.DS_SKIP_BUTTON_VARIANTS === 'true' || config?.raw?.generators?.tailwind?.buttonVariants === false || config?.raw?.generators?.tailwind?.buttons === false;
|
|
4406
|
+
const enableButtonVariants = process.env.DS_ENABLE_BUTTON_VARIANTS === '1' || process.env.DS_ENABLE_BUTTON_VARIANTS === 'true' || config?.raw?.generators?.tailwind?.buttonVariants === true || config?.raw?.generators?.tailwind?.buttons === true;
|
|
4407
|
+
if (skipButtonVariants || !enableButtonVariants) {
|
|
4408
|
+
message('skipping tailwind button variants generator');
|
|
4409
|
+
} else {
|
|
4410
|
+
await generateButtons$1(buttons, config);
|
|
4411
|
+
}
|
|
4344
4412
|
await generateBodies(typography.sizes, typography.lineHeights, config);
|
|
4345
4413
|
await generateHeadlines(typography.sizes, typography.lineHeights, config);
|
|
4346
4414
|
await generateTypography$1(typography.sizes, typography.lineHeights, config);
|