@webmate-studio/builder 0.2.156 → 0.2.159

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webmate-studio/builder",
3
- "version": "0.2.156",
3
+ "version": "0.2.159",
4
4
  "type": "module",
5
5
  "description": "Webmate Studio Component Builder",
6
6
  "keywords": [
@@ -15,7 +15,8 @@ import {
15
15
  calculateOnColor,
16
16
  DEFAULT_SURFACE_TOKENS,
17
17
  defaultDesignTokensV2,
18
- normalizeShadowValue
18
+ normalizeShadowValue,
19
+ isGradientValue
19
20
  } from './design-tokens-v2.js';
20
21
 
21
22
 
@@ -600,9 +601,9 @@ function resolveShadowToCSS(shadowValue, t) {
600
601
  }
601
602
 
602
603
  function addButtonVariantVars(lines, prefix, variant, t) {
603
- if (variant.bg) lines.push(` --${prefix}-bg: ${resolveColorRef(variant.bg, t)};`);
604
- if (variant.bgHover) lines.push(` --${prefix}-bg-hover: ${resolveColorRef(variant.bgHover, t)};`);
605
- if (variant.bgActive) lines.push(` --${prefix}-bg-active: ${resolveColorRef(variant.bgActive, t)};`);
604
+ if (variant.bg) lines.push(` --${prefix}-bg: ${resolveBackgroundValue(variant.bg, t)};`);
605
+ if (variant.bgHover) lines.push(` --${prefix}-bg-hover: ${resolveBackgroundValue(variant.bgHover, t)};`);
606
+ if (variant.bgActive) lines.push(` --${prefix}-bg-active: ${resolveBackgroundValue(variant.bgActive, t)};`);
606
607
  if (variant.text) lines.push(` --${prefix}-text: ${resolveColorRef(variant.text, t)};`);
607
608
  if (variant.textHover) lines.push(` --${prefix}-text-hover: ${resolveColorRef(variant.textHover, t)};`);
608
609
  if (variant.textActive) lines.push(` --${prefix}-text-active: ${resolveColorRef(variant.textActive, t)};`);
@@ -616,6 +617,8 @@ function addButtonVariantVars(lines, prefix, variant, t) {
616
617
  const shadowActiveCSS = resolveShadowToCSS(variant.shadowActive, t);
617
618
  if (shadowActiveCSS !== 'none') lines.push(` --${prefix}-shadow-active: ${shadowActiveCSS};`);
618
619
  if (variant.focusRingColor) lines.push(` --${prefix}-focus-ring: ${resolveColorRef(variant.focusRingColor, t)};`);
620
+ if (variant.paddingX != null) lines.push(` --${prefix}-padding-x: ${variant.paddingX};`);
621
+ if (variant.paddingY != null) lines.push(` --${prefix}-padding-y: ${variant.paddingY};`);
619
622
  if (variant.fontFamily) {
620
623
  const fontDef = t.typography?.fonts?.find(f => f.name === variant.fontFamily);
621
624
  const fallback = fontDef?.fallback || 'sans-serif';
@@ -650,6 +653,49 @@ function resolveColorRef(ref, t) {
650
653
  return `var(--color-${ref})`;
651
654
  }
652
655
 
656
+ /**
657
+ * Löst einen Hintergrundwert auf — entweder Farbreferenz (String) oder Gradient (Object).
658
+ * String → delegiert an resolveColorRef()
659
+ * Object → buildGradientCSS()
660
+ */
661
+ function resolveBackgroundValue(val, t) {
662
+ if (!val) return 'none';
663
+ if (isGradientValue(val)) return buildGradientCSS(val, t);
664
+ return resolveColorRef(val, t);
665
+ }
666
+
667
+ /**
668
+ * Baut einen CSS-Gradient-String aus einem Gradient-Objekt.
669
+ * Unterstützt linear-gradient, radial-gradient und conic-gradient.
670
+ */
671
+ function buildGradientCSS(gradient, t) {
672
+ const stops = (gradient.stops || []).map(stop => {
673
+ const color = resolveColorRef(stop.color, t);
674
+ const colorCSS = (stop.opacity != null && stop.opacity < 100)
675
+ ? `color-mix(in srgb, ${color} ${stop.opacity}%, transparent)`
676
+ : color;
677
+ return `${colorCSS} ${stop.position}%`;
678
+ }).join(', ');
679
+
680
+ switch (gradient.type) {
681
+ case 'radial': {
682
+ const shape = gradient.shape || 'circle';
683
+ const size = gradient.size || 'farthest-corner';
684
+ const pos = gradient.position || 'center';
685
+ return `radial-gradient(${shape} ${size} at ${pos}, ${stops})`;
686
+ }
687
+ case 'conic': {
688
+ const fromAngle = gradient.fromAngle || 0;
689
+ const pos = gradient.position || 'center';
690
+ return `conic-gradient(from ${fromAngle}deg at ${pos}, ${stops})`;
691
+ }
692
+ default: { // linear
693
+ const angle = gradient.angle ?? 135;
694
+ return `linear-gradient(${angle}deg, ${stops})`;
695
+ }
696
+ }
697
+ }
698
+
653
699
 
654
700
  // ─── Button-Klassen ─────────────────────────────────────────────────────────
655
701
 
@@ -684,7 +730,9 @@ function generateButtonClasses(t) {
684
730
  const s = t.buttons.sizes?.[size];
685
731
  if (!s) continue;
686
732
  css += `\n.btn-${size} {
687
- padding: var(--btn-${size}-padding-y) var(--btn-${size}-padding-x);
733
+ --btn-padding-x: var(--btn-${size}-padding-x);
734
+ --btn-padding-y: var(--btn-${size}-padding-y);
735
+ padding: var(--btn-padding-y) var(--btn-padding-x);
688
736
  font-size: calc(var(--btn-${size}-font-size) * var(--btn-font-scale, 1));
689
737
  font-weight: var(--btn-${size}-font-weight);
690
738
  line-height: var(--btn-${size}-line-height);
@@ -739,6 +787,13 @@ function generateVariantNormalCSS(variant, v, t) {
739
787
  if (v.normal.textDecoration) {
740
788
  css += `\n text-decoration: ${v.normal.textDecoration};`;
741
789
  }
790
+ // Padding overrides (variant overrides size)
791
+ if (v.normal.paddingX != null) {
792
+ css += `\n --btn-padding-x: var(--${p}-padding-x);`;
793
+ }
794
+ if (v.normal.paddingY != null) {
795
+ css += `\n --btn-padding-y: var(--${p}-padding-y);`;
796
+ }
742
797
  // Typography overrides
743
798
  if (v.normal.fontFamily) {
744
799
  css += `\n font-family: var(--${p}-font-family);`;
@@ -845,6 +900,13 @@ function generateVariantOnSurfaceCSS(variant, v, t) {
845
900
  if (v.onSurface.textDecoration) {
846
901
  css += `\n text-decoration: ${v.onSurface.textDecoration};`;
847
902
  }
903
+ // Padding overrides (variant overrides size)
904
+ if (v.onSurface.paddingX != null) {
905
+ css += `\n --btn-padding-x: var(--${osp}-padding-x);`;
906
+ }
907
+ if (v.onSurface.paddingY != null) {
908
+ css += `\n --btn-padding-y: var(--${osp}-padding-y);`;
909
+ }
848
910
  // Typography overrides
849
911
  if (v.onSurface.fontFamily) {
850
912
  css += `\n font-family: var(--${osp}-font-family);`;
@@ -1039,6 +1039,8 @@ export const defaultDesignTokensV2 = {
1039
1039
  hoverY: 0,
1040
1040
  activeScale: 0.97,
1041
1041
  activeY: 0,
1042
+ paddingX: null,
1043
+ paddingY: null,
1042
1044
  fontFamily: null,
1043
1045
  fontSizeScale: 1,
1044
1046
  fontWeight: null,
@@ -1064,6 +1066,8 @@ export const defaultDesignTokensV2 = {
1064
1066
  hoverY: 0,
1065
1067
  activeScale: 0.97,
1066
1068
  activeY: 0,
1069
+ paddingX: null,
1070
+ paddingY: null,
1067
1071
  fontFamily: null,
1068
1072
  fontSizeScale: 1,
1069
1073
  fontWeight: null,
@@ -1090,6 +1094,8 @@ export const defaultDesignTokensV2 = {
1090
1094
  hoverY: 0,
1091
1095
  activeScale: 0.97,
1092
1096
  activeY: 0,
1097
+ paddingX: null,
1098
+ paddingY: null,
1093
1099
  fontFamily: null,
1094
1100
  fontSizeScale: 1,
1095
1101
  fontWeight: null,
@@ -1115,6 +1121,8 @@ export const defaultDesignTokensV2 = {
1115
1121
  hoverY: 0,
1116
1122
  activeScale: 0.97,
1117
1123
  activeY: 0,
1124
+ paddingX: null,
1125
+ paddingY: null,
1118
1126
  fontFamily: null,
1119
1127
  fontSizeScale: 1,
1120
1128
  fontWeight: null,
@@ -1141,6 +1149,8 @@ export const defaultDesignTokensV2 = {
1141
1149
  hoverY: 0,
1142
1150
  activeScale: 0.97,
1143
1151
  activeY: 0,
1152
+ paddingX: null,
1153
+ paddingY: null,
1144
1154
  fontFamily: null,
1145
1155
  fontSizeScale: 1,
1146
1156
  fontWeight: null,
@@ -1166,6 +1176,8 @@ export const defaultDesignTokensV2 = {
1166
1176
  hoverY: 0,
1167
1177
  activeScale: 0.97,
1168
1178
  activeY: 0,
1179
+ paddingX: null,
1180
+ paddingY: null,
1169
1181
  fontFamily: null,
1170
1182
  fontSizeScale: 1,
1171
1183
  fontWeight: null,
@@ -1192,6 +1204,8 @@ export const defaultDesignTokensV2 = {
1192
1204
  hoverY: 0,
1193
1205
  activeScale: 0.97,
1194
1206
  activeY: 0,
1207
+ paddingX: null,
1208
+ paddingY: null,
1195
1209
  fontFamily: null,
1196
1210
  fontSizeScale: 1,
1197
1211
  fontWeight: null,
@@ -1217,6 +1231,8 @@ export const defaultDesignTokensV2 = {
1217
1231
  hoverY: 0,
1218
1232
  activeScale: 0.97,
1219
1233
  activeY: 0,
1234
+ paddingX: null,
1235
+ paddingY: null,
1220
1236
  fontFamily: null,
1221
1237
  fontSizeScale: 1,
1222
1238
  fontWeight: null,
@@ -1243,6 +1259,8 @@ export const defaultDesignTokensV2 = {
1243
1259
  hoverY: 0,
1244
1260
  activeScale: 0.97,
1245
1261
  activeY: 0,
1262
+ paddingX: '0rem',
1263
+ paddingY: null,
1246
1264
  fontFamily: null,
1247
1265
  fontSizeScale: 1,
1248
1266
  fontWeight: null,
@@ -1270,6 +1288,8 @@ export const defaultDesignTokensV2 = {
1270
1288
  hoverY: 0,
1271
1289
  activeScale: 0.97,
1272
1290
  activeY: 0,
1291
+ paddingX: '0rem',
1292
+ paddingY: null,
1273
1293
  fontFamily: null,
1274
1294
  fontSizeScale: 1,
1275
1295
  fontWeight: null,
@@ -1298,6 +1318,8 @@ export const defaultDesignTokensV2 = {
1298
1318
  hoverY: 0,
1299
1319
  activeScale: 0.97,
1300
1320
  activeY: 0,
1321
+ paddingX: null,
1322
+ paddingY: null,
1301
1323
  fontFamily: null,
1302
1324
  fontSizeScale: 1,
1303
1325
  fontWeight: null,
@@ -1323,6 +1345,8 @@ export const defaultDesignTokensV2 = {
1323
1345
  hoverY: 0,
1324
1346
  activeScale: 0.97,
1325
1347
  activeY: 0,
1348
+ paddingX: null,
1349
+ paddingY: null,
1326
1350
  fontFamily: null,
1327
1351
  fontSizeScale: 1,
1328
1352
  fontWeight: null,
@@ -1375,6 +1399,56 @@ export const defaultDesignTokensV2 = {
1375
1399
  };
1376
1400
 
1377
1401
 
1402
+ // ─── Gradient-Hilfsfunktionen ───────────────────────────────────────────────
1403
+
1404
+ /**
1405
+ * Position-Keywords für radial/conic Gradients.
1406
+ */
1407
+ export const GRADIENT_POSITIONS = [
1408
+ 'center', 'top', 'right', 'bottom', 'left',
1409
+ 'top left', 'top right', 'bottom left', 'bottom right'
1410
+ ];
1411
+
1412
+ /**
1413
+ * Size-Keywords für radial Gradients.
1414
+ */
1415
+ export const RADIAL_SIZES = [
1416
+ 'farthest-corner', 'closest-side', 'farthest-side', 'closest-corner'
1417
+ ];
1418
+
1419
+ /**
1420
+ * Prüft ob ein Wert ein Gradient-Objekt ist (statt einer Farbreferenz-String).
1421
+ */
1422
+ export function isGradientValue(val) {
1423
+ return val != null && typeof val === 'object' && val.type && Array.isArray(val.stops);
1424
+ }
1425
+
1426
+ /**
1427
+ * Erzeugt einen Standard-Gradient-Stop.
1428
+ */
1429
+ export function createDefaultGradientStop(position = 0) {
1430
+ return { color: 'primary-9', position, opacity: 100 };
1431
+ }
1432
+
1433
+ /**
1434
+ * Erzeugt ein Standard-Gradient-Objekt mit 2 Stops.
1435
+ */
1436
+ export function createDefaultGradient() {
1437
+ return {
1438
+ type: 'linear',
1439
+ angle: 135,
1440
+ shape: 'circle',
1441
+ position: 'center',
1442
+ size: 'farthest-corner',
1443
+ fromAngle: 0,
1444
+ stops: [
1445
+ { color: 'primary-9', position: 0, opacity: 100 },
1446
+ { color: 'primary-6', position: 100, opacity: 100 }
1447
+ ]
1448
+ };
1449
+ }
1450
+
1451
+
1378
1452
  // ─── Erkennung ──────────────────────────────────────────────────────────────
1379
1453
 
1380
1454
  /**