@northlight/ui 2.36.10 → 2.36.12

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.
@@ -342,12 +342,16 @@
342
342
  };
343
343
 
344
344
  const luminosity = (hexcolor) => {
345
- let color = hexcolor;
346
- if (color.slice(0, 1) === "#") {
347
- color = color.slice(1);
345
+ if (!hexcolor || typeof hexcolor !== "string")
346
+ return Number.NaN;
347
+ let color = hexcolor.trim();
348
+ if (!/^#?[0-9a-f]{3}([0-9a-f]{3})?$/i.test(color)) {
349
+ return Number.NaN;
348
350
  }
351
+ if (color[0] === "#")
352
+ color = color.slice(1);
349
353
  if (color.length === 3) {
350
- color = color.split("").map((hex) => hex + hex).join("");
354
+ color = color.split("").map((h) => h + h).join("");
351
355
  }
352
356
  const r = parseInt(color.substring(0, 2), 16);
353
357
  const g = parseInt(color.substring(2, 4), 16);
@@ -356,16 +360,28 @@
356
360
  return brightness;
357
361
  };
358
362
 
363
+ function safeUseToken(tokenOrValue) {
364
+ try {
365
+ return system.useToken("colors", tokenOrValue);
366
+ } catch (e) {
367
+ return tokenOrValue;
368
+ }
369
+ }
359
370
  const getContrastColor = (color) => {
360
- const colorTwo = system.useToken("colors", "text.default");
361
- const colorOne = system.useToken("colors", "text.inverted");
362
- const colorInHex = system.useToken("colors", color);
363
- const l1 = luminosity(colorOne);
364
- const l2 = luminosity(colorTwo);
365
- const threshold = (l1 + l2) / 2;
366
- const brightColor = l1 > l2 ? colorOne : colorTwo;
367
- const darkColor = l1 > l2 ? colorTwo : colorOne;
368
- return luminosity(colorInHex) >= threshold ? darkColor : brightColor;
371
+ const textDefault = system.useToken("colors", "text.default");
372
+ const textInverted = system.useToken("colors", "text.inverted");
373
+ const normalized = typeof color === "string" ? color.trim() : color;
374
+ const isHex = /^#?[0-9a-f]{3}([0-9a-f]{3})?$/i.test(normalized);
375
+ const bgResolved = isHex ? normalized[0] === "#" ? normalized : `#${normalized}` : safeUseToken(normalized);
376
+ const lInverted = luminosity(textInverted);
377
+ const lDefault = luminosity(textDefault);
378
+ const threshold = (lInverted + lDefault) / 2;
379
+ const brightColor = lInverted > lDefault ? textInverted : textDefault;
380
+ const darkColor = lInverted > lDefault ? textDefault : textInverted;
381
+ const lBg = luminosity(bgResolved);
382
+ if (Number.isNaN(lBg))
383
+ return void 0;
384
+ return lBg >= threshold ? darkColor : brightColor;
369
385
  };
370
386
 
371
387
  const ring = {
@@ -762,14 +778,14 @@
762
778
  }
763
779
  }),
764
780
  brandSubdued: ({ theme: { colors: color } }) => ({
765
- color: color.text.button.link,
781
+ color: color.text.button.brandSubdued,
766
782
  bgColor: color.background.button.ghost,
767
783
  _hover: {
768
784
  bg: color.background.button.brand,
769
785
  color: color.text.inverted,
770
786
  _disabled: {
771
787
  bgColor: color.background.button.ghost,
772
- color: color.text.button.link
788
+ color: color.text.button.brandSubdued
773
789
  }
774
790
  },
775
791
  _active: {
@@ -840,6 +856,38 @@
840
856
  bg: color.bg.ai.hover,
841
857
  color: color.text.inverted
842
858
  }
859
+ }),
860
+ accent: ({ theme: { colors: color } }) => ({
861
+ color: color.text.button.accent,
862
+ bgColor: color.background.button.ghost,
863
+ _hover: {
864
+ bg: color.background.button["ghost-active"],
865
+ color: color.text.button.accent,
866
+ _disabled: {
867
+ bgColor: color.background.button.ghost,
868
+ color: color.text.button.accent
869
+ }
870
+ },
871
+ _active: {
872
+ bg: color.background.button["ghost-active"],
873
+ color: color.text.button.accent
874
+ }
875
+ }),
876
+ sidebar: ({ theme: { colors: color } }) => ({
877
+ color: color.text.button.sidebar,
878
+ bgColor: color.background.button.sidebar,
879
+ _hover: {
880
+ bg: color.background.button["sidebar-hover"],
881
+ color: color.text.button.sidebar,
882
+ _disabled: {
883
+ bgColor: color.background.button.ghost,
884
+ color: color.text.button.sidebar
885
+ }
886
+ },
887
+ _active: {
888
+ bg: color.background.button["sidebar-active"],
889
+ color: color.text.button["sidebar-active"]
890
+ }
843
891
  })
844
892
  },
845
893
  defaultProps: {
@@ -1624,7 +1672,8 @@
1624
1672
  variants: {
1625
1673
  solid: ({ theme: { colors }, bgColor, colorScheme, currentTheme }) => {
1626
1674
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
1627
- const tagBgColor = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][500] ? colors[processedColorScheme][500] : processedColorScheme;
1675
+ const tagBgColorRaw = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][500] ? colors[processedColorScheme][500] : processedColorScheme;
1676
+ const tagBgColor = typeof tagBgColorRaw === "string" ? tagBgColorRaw.trim() : tagBgColorRaw;
1628
1677
  const tagColor = getContrastColor(react.useToken("colors", tagBgColor));
1629
1678
  return {
1630
1679
  container: {
@@ -1635,7 +1684,8 @@
1635
1684
  },
1636
1685
  subtle: ({ theme: { colors }, colorScheme, bgColor, currentTheme }) => {
1637
1686
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
1638
- const tagBgColor = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][100] ? colors[processedColorScheme][100] : processedColorScheme;
1687
+ const tagBgColorRaw = bgColor != null ? bgColor : colors[processedColorScheme] && colors[processedColorScheme][100] ? colors[processedColorScheme][100] : processedColorScheme;
1688
+ const tagBgColor = typeof tagBgColorRaw === "string" ? tagBgColorRaw.trim() : tagBgColorRaw;
1639
1689
  const tagColor = getContrastColor(react.useToken("colors", tagBgColor));
1640
1690
  return {
1641
1691
  container: {
@@ -3554,12 +3604,13 @@
3554
3604
  };
3555
3605
  },
3556
3606
  variants: {
3557
- solid: ({ colorScheme, theme: { colors }, currentTheme }) => {
3607
+ solid: ({ colorScheme, theme: { colors }, currentTheme, bg, bgColor }) => {
3608
+ var _a;
3558
3609
  const processedColorScheme = processColorSchemeBasedOnTheme({ currentTheme, colorScheme });
3559
- const bgColor = processedColorScheme === "mediatoolBlue" ? colors[processedColorScheme][500] : colors[processedColorScheme] && colors[processedColorScheme][500];
3610
+ const finalBg = (_a = bg != null ? bg : bgColor) != null ? _a : processedColorScheme === "mediatoolBlue" ? colors[processedColorScheme][500] : colors[processedColorScheme] && colors[processedColorScheme][500];
3560
3611
  return {
3561
- bgColor,
3562
- color: getContrastColor(bgColor != null ? bgColor : react.useToken("colors", processedColorScheme))
3612
+ bgColor: finalBg,
3613
+ color: getContrastColor(finalBg != null ? finalBg : react.useToken("colors", processedColorScheme))
3563
3614
  };
3564
3615
  },
3565
3616
  outline: ({ colorScheme, theme: { colors }, currentTheme }) => {
@@ -3594,7 +3645,8 @@
3594
3645
  }
3595
3646
  },
3596
3647
  defaultProps: {
3597
- size: "sm"
3648
+ size: "sm",
3649
+ variant: "solid"
3598
3650
  }
3599
3651
  };
3600
3652