@vettvangur/design-system 2.0.76 → 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 +27 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4003,11 +4003,21 @@ function rgbaFromColor(color) {
|
|
|
4003
4003
|
}
|
|
4004
4004
|
|
|
4005
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.
|
|
4006
4010
|
let a = v;
|
|
4007
|
-
if (a > 1 && a <=
|
|
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) {
|
|
4008
4015
|
a /= 100;
|
|
4009
4016
|
} else if (a > 100 && a <= 255) {
|
|
4010
4017
|
a /= 255;
|
|
4018
|
+
} else if (a > 0 && a <= 0.1) {
|
|
4019
|
+
// Figma: 4% is 0.04; we want 0.4.
|
|
4020
|
+
a *= 10;
|
|
4011
4021
|
}
|
|
4012
4022
|
a = Math.max(0, Math.min(1, a));
|
|
4013
4023
|
|
|
@@ -4112,6 +4122,16 @@ function renderTheme(lines) {
|
|
|
4112
4122
|
return `@theme {\n${lines.join('\n')}\n}\n`;
|
|
4113
4123
|
}
|
|
4114
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
|
+
|
|
4115
4135
|
/**
|
|
4116
4136
|
* Generate shadows.
|
|
4117
4137
|
*
|
|
@@ -4127,19 +4147,21 @@ function renderTheme(lines) {
|
|
|
4127
4147
|
*/
|
|
4128
4148
|
async function generateShadows(variableSet, config) {
|
|
4129
4149
|
message('generating shadows...');
|
|
4130
|
-
const
|
|
4150
|
+
const themeLines = [];
|
|
4151
|
+
const utilityBlocks = [];
|
|
4131
4152
|
for (const [rawKey, token] of Object.entries(variableSet || {})) {
|
|
4132
4153
|
const key = toShadowKey(rawKey);
|
|
4133
4154
|
const value = buildShadowValue(token?.effects);
|
|
4134
4155
|
if (!value) {
|
|
4135
4156
|
continue;
|
|
4136
4157
|
}
|
|
4137
|
-
|
|
4158
|
+
themeLines.push(` --${key}: ${value};`);
|
|
4159
|
+
utilityBlocks.push(`@utility ${key} {\n box-shadow: var(--${key});\n}`);
|
|
4138
4160
|
}
|
|
4139
|
-
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)}`;
|
|
4140
4162
|
const outPath = path.join(config.paths.styles, 'config', 'shadow.css');
|
|
4141
4163
|
await fs$1.writeFile(outPath, css, 'utf8');
|
|
4142
|
-
message(`finished generating shadows (${
|
|
4164
|
+
message(`finished generating shadows (${themeLines.length})`);
|
|
4143
4165
|
}
|
|
4144
4166
|
|
|
4145
4167
|
/**
|