@epilot/spark-ui 0.22.1 → 0.23.1

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.
Files changed (133) hide show
  1. package/dist/components/attachment.d.cts +1 -1
  2. package/dist/components/attachment.d.ts +1 -1
  3. package/dist/components/avatar.js +1 -1
  4. package/dist/components/badge.cjs +1 -1
  5. package/dist/components/badge.cjs.map +1 -1
  6. package/dist/components/badge.js +2 -2
  7. package/dist/components/badge.js.map +1 -1
  8. package/dist/components/box.js +1 -1
  9. package/dist/components/bubble.d.cts +1 -1
  10. package/dist/components/bubble.d.ts +1 -1
  11. package/dist/components/button-group.js +1 -1
  12. package/dist/components/button.cjs.map +1 -1
  13. package/dist/components/button.d.cts +3 -3
  14. package/dist/components/button.d.ts +3 -3
  15. package/dist/components/button.js +1 -1
  16. package/dist/components/button.js.map +1 -1
  17. package/dist/components/calendar.cjs +4 -3
  18. package/dist/components/calendar.cjs.map +1 -1
  19. package/dist/components/calendar.js +4 -3
  20. package/dist/components/calendar.js.map +1 -1
  21. package/dist/components/callout.d.cts +1 -1
  22. package/dist/components/callout.d.ts +1 -1
  23. package/dist/components/card.js +1 -1
  24. package/dist/components/checkbox.cjs.map +1 -1
  25. package/dist/components/checkbox.js +1 -1
  26. package/dist/components/checkbox.js.map +1 -1
  27. package/dist/components/circular-gauge.cjs +1 -1
  28. package/dist/components/circular-gauge.cjs.map +1 -1
  29. package/dist/components/circular-gauge.js +1 -1
  30. package/dist/components/circular-gauge.js.map +1 -1
  31. package/dist/components/dialog.cjs +1 -1
  32. package/dist/components/dialog.cjs.map +1 -1
  33. package/dist/components/dialog.js +1 -1
  34. package/dist/components/dialog.js.map +1 -1
  35. package/dist/components/drawer.cjs +2 -2
  36. package/dist/components/drawer.cjs.map +1 -1
  37. package/dist/components/drawer.js +2 -2
  38. package/dist/components/drawer.js.map +1 -1
  39. package/dist/components/energy-breakdown.cjs +1 -1
  40. package/dist/components/energy-breakdown.cjs.map +1 -1
  41. package/dist/components/energy-breakdown.js +1 -1
  42. package/dist/components/energy-breakdown.js.map +1 -1
  43. package/dist/components/icon.js +1 -1
  44. package/dist/components/input-date.cjs +4 -0
  45. package/dist/components/input-date.cjs.map +1 -1
  46. package/dist/components/input-date.js +4 -0
  47. package/dist/components/input-date.js.map +1 -1
  48. package/dist/components/input-group.d.cts +1 -1
  49. package/dist/components/input-group.d.ts +1 -1
  50. package/dist/components/input-otp.cjs +1 -1
  51. package/dist/components/input-otp.js +1 -1
  52. package/dist/components/input.cjs +1 -1
  53. package/dist/components/input.js +1 -1
  54. package/dist/components/line-chart.cjs +2 -2
  55. package/dist/components/line-chart.cjs.map +1 -1
  56. package/dist/components/line-chart.js +3 -3
  57. package/dist/components/line-chart.js.map +1 -1
  58. package/dist/components/message-scroller.cjs +1 -1
  59. package/dist/components/message-scroller.js +1 -1
  60. package/dist/components/page-header.d.cts +1 -1
  61. package/dist/components/page-header.d.ts +1 -1
  62. package/dist/components/pill.cjs +2 -2
  63. package/dist/components/pill.cjs.map +1 -1
  64. package/dist/components/pill.js +3 -3
  65. package/dist/components/pill.js.map +1 -1
  66. package/dist/components/popover.cjs +2 -1
  67. package/dist/components/popover.cjs.map +1 -1
  68. package/dist/components/popover.d.cts +2 -1
  69. package/dist/components/popover.d.ts +2 -1
  70. package/dist/components/popover.js +2 -1
  71. package/dist/components/popover.js.map +1 -1
  72. package/dist/components/power-history-chart.cjs +1 -1
  73. package/dist/components/power-history-chart.js +1 -1
  74. package/dist/components/progress.cjs +1 -1
  75. package/dist/components/progress.cjs.map +1 -1
  76. package/dist/components/progress.js +1 -1
  77. package/dist/components/progress.js.map +1 -1
  78. package/dist/components/radio.js +1 -1
  79. package/dist/components/segmented-control.cjs +4 -4
  80. package/dist/components/segmented-control.cjs.map +1 -1
  81. package/dist/components/segmented-control.d.cts +2 -16
  82. package/dist/components/segmented-control.d.ts +2 -16
  83. package/dist/components/segmented-control.js +5 -5
  84. package/dist/components/segmented-control.js.map +1 -1
  85. package/dist/components/select.cjs +1 -1
  86. package/dist/components/select.js +1 -1
  87. package/dist/components/switch.cjs +1 -1
  88. package/dist/components/switch.cjs.map +1 -1
  89. package/dist/components/switch.js +2 -2
  90. package/dist/components/switch.js.map +1 -1
  91. package/dist/components/tabs.cjs +2 -2
  92. package/dist/components/tabs.cjs.map +1 -1
  93. package/dist/components/tabs.d.cts +1 -8
  94. package/dist/components/tabs.d.ts +1 -8
  95. package/dist/components/tabs.js +2 -2
  96. package/dist/components/tabs.js.map +1 -1
  97. package/dist/components/textarea.cjs +1 -1
  98. package/dist/components/textarea.js +1 -1
  99. package/dist/components/theme.js +1 -1
  100. package/dist/components/toggle-group.cjs +40 -0
  101. package/dist/components/toggle-group.cjs.map +1 -0
  102. package/dist/components/toggle-group.d.cts +28 -0
  103. package/dist/components/toggle-group.d.ts +28 -0
  104. package/dist/components/toggle-group.js +37 -0
  105. package/dist/components/toggle-group.js.map +1 -0
  106. package/dist/components/toggle.cjs +69 -0
  107. package/dist/components/toggle.cjs.map +1 -0
  108. package/dist/components/toggle.d.cts +23 -0
  109. package/dist/components/toggle.d.ts +23 -0
  110. package/dist/components/toggle.js +66 -0
  111. package/dist/components/toggle.js.map +1 -0
  112. package/dist/components/tooltip.cjs +1 -1
  113. package/dist/components/tooltip.cjs.map +1 -1
  114. package/dist/components/tooltip.js +1 -1
  115. package/dist/components/tooltip.js.map +1 -1
  116. package/dist/lib/generate-radix-colors.cjs +1 -1
  117. package/dist/lib/generate-radix-colors.cjs.map +1 -1
  118. package/dist/lib/generate-radix-colors.js +1 -1
  119. package/dist/lib/generate-radix-colors.js.map +1 -1
  120. package/dist/lib/toggle-group-context.cjs +12 -0
  121. package/dist/lib/toggle-group-context.cjs.map +1 -0
  122. package/dist/lib/toggle-group-context.d.cts +17 -0
  123. package/dist/lib/toggle-group-context.d.ts +17 -0
  124. package/dist/lib/toggle-group-context.js +9 -0
  125. package/dist/lib/toggle-group-context.js.map +1 -0
  126. package/dist/styles/theme.css +15 -4
  127. package/dist/utils/format.cjs +1 -0
  128. package/dist/utils/format.cjs.map +1 -1
  129. package/dist/utils/format.d.cts +2 -1
  130. package/dist/utils/format.d.ts +2 -1
  131. package/dist/utils/format.js +1 -1
  132. package/dist/utils/format.js.map +1 -1
  133. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toggle-group-context.js","names":["React"],"sources":["../../src/lib/toggle-group-context.ts"],"sourcesContent":["import * as React from 'react'\nimport type { SparkButtonColor } from '../components/button'\nimport type { ButtonProps } from '../components/button'\nimport type { ToggleStyle } from '../components/toggle'\n\n/** `ToggleGroup`'s defaults for its `Toggle`s; kept out of the public exports. */\nexport const ToggleGroupContext = React.createContext<{\n styleVariant?: ToggleStyle\n color?: SparkButtonColor\n size?: ButtonProps['size']\n showCheck?: boolean\n}>({})\n"],"mappings":";;;;AAMA,MAAa,qBAAqBA,QAAM,cAKrC,CAAC,CAAC"}
@@ -600,7 +600,7 @@
600
600
  }
601
601
 
602
602
  /*
603
- * Overlay / focus / selection / autofill — Radix-parity semantic tokens, derived
603
+ * Overlay / focus / selection — Radix-parity semantic tokens, derived
604
604
  * from existing scales (additive; the --spark-* contract is untouched). Overlay is
605
605
  * page-level (backdrops portal to <body>); the rest follow the accent per scope.
606
606
  */
@@ -616,6 +616,16 @@
616
616
  --color-overlay: var(--black-a8);
617
617
  }
618
618
 
619
+ .light,
620
+ .light-theme {
621
+ color-scheme: light;
622
+ }
623
+
624
+ .dark,
625
+ .dark-theme {
626
+ color-scheme: dark;
627
+ }
628
+
619
629
  :root,
620
630
  .spark-theme {
621
631
  /*
@@ -629,7 +639,6 @@
629
639
  --color-focus-root: var(--spark-11);
630
640
  --color-primary-focus: var(--spark-11);
631
641
  --color-selection-root: var(--spark-a5);
632
- --color-autofill-root: var(--spark-a3);
633
642
  }
634
643
 
635
644
  .spark-theme ::selection {
@@ -638,10 +647,12 @@
638
647
 
639
648
  .spark-theme :-webkit-autofill,
640
649
  .spark-theme :-webkit-autofill:hover,
641
- .spark-theme :-webkit-autofill:focus {
650
+ .spark-theme :-webkit-autofill:focus,
651
+ .spark-theme :-webkit-autofill:active {
642
652
  -webkit-text-fill-color: var(--neutral-12);
643
- -webkit-box-shadow: 0 0 0 1000px var(--color-autofill-root) inset;
644
653
  caret-color: var(--neutral-12);
654
+ -webkit-background-clip: text;
655
+ background-clip: text;
645
656
  }
646
657
  }
647
658
 
@@ -49,6 +49,7 @@ exports.formatPercent = formatPercent;
49
49
  exports.formatPower = formatPower;
50
50
  exports.formatRatio = formatRatio;
51
51
  exports.formatThousands = formatThousands;
52
+ exports.getDocumentLang = getDocumentLang;
52
53
  exports.integerFormat = integerFormat;
53
54
  exports.localeNumberFormat = localeNumberFormat;
54
55
  exports.oneDecimalFormat = oneDecimalFormat;
@@ -1 +1 @@
1
- {"version":3,"file":"format.cjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoDecimalFormat,\n}\n"],"mappings":";;;;AAMA,SAAS,kBAAsC;CAC7C,OAAO,OAAO,aAAa,cACvB,KAAA,IACA,SAAS,gBAAgB,QAAQ,KAAA;AACvC;AAEA,MAAM,sBACJ,YACuB;CACvB,MAAM,wBAAQ,IAAI,IAA+B;CACjD,OAAO,EACL,SAAS,UAAU;EACjB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,MAAM,UAAU;EACtB,IAAI,YAAY,MAAM,IAAI,GAAG;EAC7B,IAAI,CAAC,WAAW;GACd,YAAY,IAAI,KAAK,aAAa,QAAQ,OAAO;GACjD,MAAM,IAAI,KAAK,SAAS;EAC1B;EACA,OAAO,UAAU,OAAO,KAAK;CAC/B,EACF;AACF;AAEA,MAAM,kBAAkB,aACtB,mBAAmB,EAAE,uBAAuB,SAAS,CAAC;AAExD,MAAM,gBAAgB,eAAe,CAAC;AACtC,MAAM,mBAAmB,eAAe,CAAC;AACzC,MAAM,mBAAmB,eAAe,CAAC;AAEzC,MAAM,mBAAmB,MAAc,cAAc,OAAO,CAAC;AAE7D,MAAM,gBAAgB,MAAc;CAClC,IAAI,KAAK,KACP,OAAO,GAAG,iBAAiB,OAAO,IAAI,GAAI;CAE5C,IAAI,KAAK,KAAO,OAAO,GAAG,cAAc,OAAO,CAAC;CAChD,IAAI,KAAK,IAAI,OAAO,GAAG,iBAAiB,OAAO,CAAC;CAChD,OAAO,GAAG,iBAAiB,OAAO,CAAC;AACrC;AAEA,MAAM,eACJ,OACA,EAAE,SAAS,UAAgC,CAAC,MACjC;CACX,IAAI,SAAS,MAAM,OAAA;CACnB,MAAM,UAAU,KAAK,MAAM,KAAK;CAEhC,OAAO,GADM,UAAU,UAAU,IAAI,MAAM,KAC1B,cAAc,OAAO,OAAO;AAC/C;AAEA,MAAM,iBAAiB,UAAiC;CACtD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,KAAK;AACtC;AAEA,MAAM,eAAe,UAAiC;CACpD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,QAAQ,GAAG;AAC5C"}
1
+ {"version":3,"file":"format.cjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n getDocumentLang,\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoDecimalFormat,\n}\n"],"mappings":";;;;AAMA,SAAS,kBAAsC;CAC7C,OAAO,OAAO,aAAa,cACvB,KAAA,IACA,SAAS,gBAAgB,QAAQ,KAAA;AACvC;AAEA,MAAM,sBACJ,YACuB;CACvB,MAAM,wBAAQ,IAAI,IAA+B;CACjD,OAAO,EACL,SAAS,UAAU;EACjB,MAAM,SAAS,gBAAgB;EAC/B,MAAM,MAAM,UAAU;EACtB,IAAI,YAAY,MAAM,IAAI,GAAG;EAC7B,IAAI,CAAC,WAAW;GACd,YAAY,IAAI,KAAK,aAAa,QAAQ,OAAO;GACjD,MAAM,IAAI,KAAK,SAAS;EAC1B;EACA,OAAO,UAAU,OAAO,KAAK;CAC/B,EACF;AACF;AAEA,MAAM,kBAAkB,aACtB,mBAAmB,EAAE,uBAAuB,SAAS,CAAC;AAExD,MAAM,gBAAgB,eAAe,CAAC;AACtC,MAAM,mBAAmB,eAAe,CAAC;AACzC,MAAM,mBAAmB,eAAe,CAAC;AAEzC,MAAM,mBAAmB,MAAc,cAAc,OAAO,CAAC;AAE7D,MAAM,gBAAgB,MAAc;CAClC,IAAI,KAAK,KACP,OAAO,GAAG,iBAAiB,OAAO,IAAI,GAAI;CAE5C,IAAI,KAAK,KAAO,OAAO,GAAG,cAAc,OAAO,CAAC;CAChD,IAAI,KAAK,IAAI,OAAO,GAAG,iBAAiB,OAAO,CAAC;CAChD,OAAO,GAAG,iBAAiB,OAAO,CAAC;AACrC;AAEA,MAAM,eACJ,OACA,EAAE,SAAS,UAAgC,CAAC,MACjC;CACX,IAAI,SAAS,MAAM,OAAA;CACnB,MAAM,UAAU,KAAK,MAAM,KAAK;CAEhC,OAAO,GADM,UAAU,UAAU,IAAI,MAAM,KAC1B,cAAc,OAAO,OAAO;AAC/C;AAEA,MAAM,iBAAiB,UAAiC;CACtD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,KAAK;AACtC;AAEA,MAAM,eAAe,UAAiC;CACpD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,QAAQ,GAAG;AAC5C"}
@@ -4,6 +4,7 @@
4
4
  interface LocaleNumberFormat {
5
5
  format: (value: number) => string;
6
6
  }
7
+ declare function getDocumentLang(): string | undefined;
7
8
  declare const localeNumberFormat: (options?: Intl.NumberFormatOptions) => LocaleNumberFormat;
8
9
  declare const decimalsFormat: (decimals: number) => LocaleNumberFormat;
9
10
  declare const integerFormat: LocaleNumberFormat;
@@ -19,5 +20,5 @@ declare const formatPower: (value: number | null, {
19
20
  declare const formatPercent: (value: number | null) => string;
20
21
  declare const formatRatio: (value: number | null) => string;
21
22
  //#endregion
22
- export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
23
+ export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, getDocumentLang, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
23
24
  //# sourceMappingURL=format.d.cts.map
@@ -4,6 +4,7 @@
4
4
  interface LocaleNumberFormat {
5
5
  format: (value: number) => string;
6
6
  }
7
+ declare function getDocumentLang(): string | undefined;
7
8
  declare const localeNumberFormat: (options?: Intl.NumberFormatOptions) => LocaleNumberFormat;
8
9
  declare const decimalsFormat: (decimals: number) => LocaleNumberFormat;
9
10
  declare const integerFormat: LocaleNumberFormat;
@@ -19,5 +20,5 @@ declare const formatPower: (value: number | null, {
19
20
  declare const formatPercent: (value: number | null) => string;
20
21
  declare const formatRatio: (value: number | null) => string;
21
22
  //#endregion
22
- export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
23
+ export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, getDocumentLang, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
23
24
  //# sourceMappingURL=format.d.ts.map
@@ -42,6 +42,6 @@ const formatRatio = (value) => {
42
42
  return `${integerFormat.format(value * 100)} %`;
43
43
  };
44
44
  //#endregion
45
- export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
45
+ export { decimalsFormat, formatEnergy, formatPercent, formatPower, formatRatio, formatThousands, getDocumentLang, integerFormat, localeNumberFormat, oneDecimalFormat, twoDecimalFormat };
46
46
 
47
47
  //# sourceMappingURL=format.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimalsFormat,\n integerFormat,\n oneDecimalFormat,\n twoDecimalFormat,\n}\n"],"mappings":";;;AAMA,SAAS,kBAAsC;CAC7C,OAAO,OAAO,aAAa,cACvB,KAAA,IACA,SAAS,gBAAgB,QAAQ,KAA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"],"sourcesContent":["import { EM_DASH, NARROW_NBSP } from './chars'\n\ninterface LocaleNumberFormat {\n format: (value: number) => string\n}\n\nfunction getDocumentLang(): string | undefined {\n return typeof document === 'undefined'\n ? undefined\n : document.documentElement.lang || undefined\n}\n\nconst localeNumberFormat = (\n options?: Intl.NumberFormatOptions,\n): LocaleNumberFormat => {\n const cache = new Map<string, Intl.NumberFormat>()\n return {\n format: (value) => {\n const locale = getDocumentLang()\n const key = locale ?? ''\n let formatter = cache.get(key)\n if (!formatter) {\n formatter = new Intl.NumberFormat(locale, options)\n cache.set(key, formatter)\n }\n return formatter.format(value)\n },\n }\n}\n\nconst decimalsFormat = (decimals: number) =>\n localeNumberFormat({ maximumFractionDigits: decimals })\n\nconst integerFormat = decimalsFormat(0)\nconst oneDecimalFormat = decimalsFormat(1)\nconst twoDecimalFormat = decimalsFormat(2)\n\nconst formatThousands = (n: number) => integerFormat.format(n)\n\nconst formatEnergy = (v: number) => {\n if (v >= 1_000_000) {\n return `${twoDecimalFormat.format(v / 1000)}${NARROW_NBSP}MWh`\n }\n if (v >= 1_000) return `${integerFormat.format(v)}${NARROW_NBSP}kWh`\n if (v >= 10) return `${oneDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n return `${twoDecimalFormat.format(v)}${NARROW_NBSP}kWh`\n}\n\nconst formatPower = (\n value: number | null,\n { signed = false }: { signed?: boolean } = {},\n): string => {\n if (value == null) return EM_DASH\n const rounded = Math.round(value)\n const sign = signed && rounded > 0 ? '+' : ''\n return `${sign}${integerFormat.format(rounded)}${NARROW_NBSP}W`\n}\n\nconst formatPercent = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value)}${NARROW_NBSP}%`\n}\n\nconst formatRatio = (value: number | null): string => {\n if (value == null) return EM_DASH\n return `${integerFormat.format(value * 100)}${NARROW_NBSP}%`\n}\n\nexport {\n getDocumentLang,\n formatThousands,\n formatEnergy,\n formatPower,\n formatPercent,\n formatRatio,\n localeNumberFormat,\n decimals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,MAAM,eAAe,UAAiC;CACpD,IAAI,SAAS,MAAM,OAAA;CACnB,OAAO,GAAG,cAAc,OAAO,QAAQ,GAAG;AAC5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epilot/spark-ui",
3
- "version": "0.22.1",
3
+ "version": "0.23.1",
4
4
  "description": "React UI component library from Spark SDK",
5
5
  "homepage": "https://spark-ui.epilot.io/docs/ui",
6
6
  "license": "Apache-2.0",