@northlight/ui 2.36.10 → 2.36.11

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.
@@ -2589,7 +2589,7 @@ declare const useOverflowGroup: () => {
2589
2589
  containerRef: (node: any) => void;
2590
2590
  };
2591
2591
 
2592
- declare const getContrastColor: (color: string) => "text.default" | "text.inverted";
2592
+ declare const getContrastColor: (color: string) => "text.default" | "text.inverted" | undefined;
2593
2593
 
2594
2594
  declare const luminosity: (hexcolor: string) => number;
2595
2595
 
@@ -364,12 +364,16 @@ const useDidUpdateEffect = (effect, dependencies) => {
364
364
  };
365
365
 
366
366
  const luminosity = (hexcolor) => {
367
- let color = hexcolor;
368
- if (color.slice(0, 1) === "#") {
369
- color = color.slice(1);
367
+ if (!hexcolor || typeof hexcolor !== "string")
368
+ return Number.NaN;
369
+ let color = hexcolor.trim();
370
+ if (!/^#?[0-9a-f]{3}([0-9a-f]{3})?$/i.test(color)) {
371
+ return Number.NaN;
370
372
  }
373
+ if (color[0] === "#")
374
+ color = color.slice(1);
371
375
  if (color.length === 3) {
372
- color = color.split("").map((hex) => hex + hex).join("");
376
+ color = color.split("").map((h) => h + h).join("");
373
377
  }
374
378
  const r = parseInt(color.substring(0, 2), 16);
375
379
  const g = parseInt(color.substring(2, 4), 16);
@@ -378,16 +382,28 @@ const luminosity = (hexcolor) => {
378
382
  return brightness;
379
383
  };
380
384
 
385
+ function safeUseToken(tokenOrValue) {
386
+ try {
387
+ return useToken("colors", tokenOrValue);
388
+ } catch (e) {
389
+ return tokenOrValue;
390
+ }
391
+ }
381
392
  const getContrastColor = (color) => {
382
- const colorTwo = useToken("colors", "text.default");
383
- const colorOne = useToken("colors", "text.inverted");
384
- const colorInHex = useToken("colors", color);
385
- const l1 = luminosity(colorOne);
386
- const l2 = luminosity(colorTwo);
387
- const threshold = (l1 + l2) / 2;
388
- const brightColor = l1 > l2 ? colorOne : colorTwo;
389
- const darkColor = l1 > l2 ? colorTwo : colorOne;
390
- return luminosity(colorInHex) >= threshold ? darkColor : brightColor;
393
+ const textDefault = useToken("colors", "text.default");
394
+ const textInverted = useToken("colors", "text.inverted");
395
+ const normalized = typeof color === "string" ? color.trim() : color;
396
+ const isHex = /^#?[0-9a-f]{3}([0-9a-f]{3})?$/i.test(normalized);
397
+ const bgResolved = isHex ? normalized[0] === "#" ? normalized : `#${normalized}` : safeUseToken(normalized);
398
+ const lInverted = luminosity(textInverted);
399
+ const lDefault = luminosity(textDefault);
400
+ const threshold = (lInverted + lDefault) / 2;
401
+ const brightColor = lInverted > lDefault ? textInverted : textDefault;
402
+ const darkColor = lInverted > lDefault ? textDefault : textInverted;
403
+ const lBg = luminosity(bgResolved);
404
+ if (Number.isNaN(lBg))
405
+ return void 0;
406
+ return lBg >= threshold ? darkColor : brightColor;
391
407
  };
392
408
 
393
409
  const ring = {
@@ -784,14 +800,14 @@ const Button$1 = {
784
800
  }
785
801
  }),
786
802
  brandSubdued: ({ theme: { colors: color } }) => ({
787
- color: color.text.button.link,
803
+ color: color.text.button.brandSubdued,
788
804
  bgColor: color.background.button.ghost,
789
805
  _hover: {
790
806
  bg: color.background.button.brand,
791
807
  color: color.text.inverted,
792
808
  _disabled: {
793
809
  bgColor: color.background.button.ghost,
794
- color: color.text.button.link
810
+ color: color.text.button.brandSubdued
795
811
  }
796
812
  },
797
813
  _active: {
@@ -1646,7 +1662,8 @@ const Tag$1 = {
1646
1662
  variants: {
1647
1663
  solid: ({ theme: { colors }, bgColor, colorScheme, currentTheme }) => {
1648
1664
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
1649
- const tagBgColor = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][500] ? colors[processedColorScheme][500] : processedColorScheme;
1665
+ const tagBgColorRaw = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][500] ? colors[processedColorScheme][500] : processedColorScheme;
1666
+ const tagBgColor = typeof tagBgColorRaw === "string" ? tagBgColorRaw.trim() : tagBgColorRaw;
1650
1667
  const tagColor = getContrastColor(useToken$1("colors", tagBgColor));
1651
1668
  return {
1652
1669
  container: {
@@ -1657,7 +1674,8 @@ const Tag$1 = {
1657
1674
  },
1658
1675
  subtle: ({ theme: { colors }, colorScheme, bgColor, currentTheme }) => {
1659
1676
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
1660
- const tagBgColor = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][100] ? colors[processedColorScheme][100] : processedColorScheme;
1677
+ const tagBgColorRaw = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][100] ? colors[processedColorScheme][100] : processedColorScheme;
1678
+ const tagBgColor = typeof tagBgColorRaw === "string" ? tagBgColorRaw.trim() : tagBgColorRaw;
1661
1679
  const tagColor = getContrastColor(useToken$1("colors", tagBgColor));
1662
1680
  return {
1663
1681
  container: {
@@ -3576,12 +3594,13 @@ const Badge$1 = {
3576
3594
  };
3577
3595
  },
3578
3596
  variants: {
3579
- solid: ({ colorScheme, theme: { colors }, currentTheme }) => {
3597
+ solid: ({ colorScheme, theme: { colors }, currentTheme, bg, bgColor }) => {
3598
+ var _a;
3580
3599
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
3581
- const bgColor = processedColorScheme === "mediatoolBlue" ? colors[processedColorScheme][500] : colors[processedColorScheme] && colors[processedColorScheme][500];
3600
+ const finalBg = (_a = bg != null ? bg : bgColor) != null ? _a : processedColorScheme === "mediatoolBlue" ? colors[processedColorScheme][500] : colors[processedColorScheme] && colors[processedColorScheme][500];
3582
3601
  return {
3583
- bgColor,
3584
- color: getContrastColor(bgColor != null ? bgColor : useToken$1("colors", processedColorScheme))
3602
+ bgColor: finalBg,
3603
+ color: getContrastColor(finalBg != null ? finalBg : useToken$1("colors", processedColorScheme))
3585
3604
  };
3586
3605
  },
3587
3606
  outline: ({ colorScheme, theme: { colors }, currentTheme }) => {
@@ -3616,7 +3635,8 @@ const Badge$1 = {
3616
3635
  }
3617
3636
  },
3618
3637
  defaultProps: {
3619
- size: "sm"
3638
+ size: "sm",
3639
+ variant: "solid"
3620
3640
  }
3621
3641
  };
3622
3642