@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.
- package/dist/components/attachment.d.cts +1 -1
- package/dist/components/attachment.d.ts +1 -1
- package/dist/components/avatar.js +1 -1
- package/dist/components/badge.cjs +1 -1
- package/dist/components/badge.cjs.map +1 -1
- package/dist/components/badge.js +2 -2
- package/dist/components/badge.js.map +1 -1
- package/dist/components/box.js +1 -1
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button-group.js +1 -1
- package/dist/components/button.cjs.map +1 -1
- package/dist/components/button.d.cts +3 -3
- package/dist/components/button.d.ts +3 -3
- package/dist/components/button.js +1 -1
- package/dist/components/button.js.map +1 -1
- package/dist/components/calendar.cjs +4 -3
- package/dist/components/calendar.cjs.map +1 -1
- package/dist/components/calendar.js +4 -3
- package/dist/components/calendar.js.map +1 -1
- package/dist/components/callout.d.cts +1 -1
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/card.js +1 -1
- package/dist/components/checkbox.cjs.map +1 -1
- package/dist/components/checkbox.js +1 -1
- package/dist/components/checkbox.js.map +1 -1
- package/dist/components/circular-gauge.cjs +1 -1
- package/dist/components/circular-gauge.cjs.map +1 -1
- package/dist/components/circular-gauge.js +1 -1
- package/dist/components/circular-gauge.js.map +1 -1
- package/dist/components/dialog.cjs +1 -1
- package/dist/components/dialog.cjs.map +1 -1
- package/dist/components/dialog.js +1 -1
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/drawer.cjs +2 -2
- package/dist/components/drawer.cjs.map +1 -1
- package/dist/components/drawer.js +2 -2
- package/dist/components/drawer.js.map +1 -1
- package/dist/components/energy-breakdown.cjs +1 -1
- package/dist/components/energy-breakdown.cjs.map +1 -1
- package/dist/components/energy-breakdown.js +1 -1
- package/dist/components/energy-breakdown.js.map +1 -1
- package/dist/components/icon.js +1 -1
- package/dist/components/input-date.cjs +4 -0
- package/dist/components/input-date.cjs.map +1 -1
- package/dist/components/input-date.js +4 -0
- package/dist/components/input-date.js.map +1 -1
- package/dist/components/input-group.d.cts +1 -1
- package/dist/components/input-group.d.ts +1 -1
- package/dist/components/input-otp.cjs +1 -1
- package/dist/components/input-otp.js +1 -1
- package/dist/components/input.cjs +1 -1
- package/dist/components/input.js +1 -1
- package/dist/components/line-chart.cjs +2 -2
- package/dist/components/line-chart.cjs.map +1 -1
- package/dist/components/line-chart.js +3 -3
- package/dist/components/line-chart.js.map +1 -1
- package/dist/components/message-scroller.cjs +1 -1
- package/dist/components/message-scroller.js +1 -1
- package/dist/components/page-header.d.cts +1 -1
- package/dist/components/page-header.d.ts +1 -1
- package/dist/components/pill.cjs +2 -2
- package/dist/components/pill.cjs.map +1 -1
- package/dist/components/pill.js +3 -3
- package/dist/components/pill.js.map +1 -1
- package/dist/components/popover.cjs +2 -1
- package/dist/components/popover.cjs.map +1 -1
- package/dist/components/popover.d.cts +2 -1
- package/dist/components/popover.d.ts +2 -1
- package/dist/components/popover.js +2 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/power-history-chart.cjs +1 -1
- package/dist/components/power-history-chart.js +1 -1
- package/dist/components/progress.cjs +1 -1
- package/dist/components/progress.cjs.map +1 -1
- package/dist/components/progress.js +1 -1
- package/dist/components/progress.js.map +1 -1
- package/dist/components/radio.js +1 -1
- package/dist/components/segmented-control.cjs +4 -4
- package/dist/components/segmented-control.cjs.map +1 -1
- package/dist/components/segmented-control.d.cts +2 -16
- package/dist/components/segmented-control.d.ts +2 -16
- package/dist/components/segmented-control.js +5 -5
- package/dist/components/segmented-control.js.map +1 -1
- package/dist/components/select.cjs +1 -1
- package/dist/components/select.js +1 -1
- package/dist/components/switch.cjs +1 -1
- package/dist/components/switch.cjs.map +1 -1
- package/dist/components/switch.js +2 -2
- package/dist/components/switch.js.map +1 -1
- package/dist/components/tabs.cjs +2 -2
- package/dist/components/tabs.cjs.map +1 -1
- package/dist/components/tabs.d.cts +1 -8
- package/dist/components/tabs.d.ts +1 -8
- package/dist/components/tabs.js +2 -2
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/textarea.cjs +1 -1
- package/dist/components/textarea.js +1 -1
- package/dist/components/theme.js +1 -1
- package/dist/components/toggle-group.cjs +40 -0
- package/dist/components/toggle-group.cjs.map +1 -0
- package/dist/components/toggle-group.d.cts +28 -0
- package/dist/components/toggle-group.d.ts +28 -0
- package/dist/components/toggle-group.js +37 -0
- package/dist/components/toggle-group.js.map +1 -0
- package/dist/components/toggle.cjs +69 -0
- package/dist/components/toggle.cjs.map +1 -0
- package/dist/components/toggle.d.cts +23 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +66 -0
- package/dist/components/toggle.js.map +1 -0
- package/dist/components/tooltip.cjs +1 -1
- package/dist/components/tooltip.cjs.map +1 -1
- package/dist/components/tooltip.js +1 -1
- package/dist/components/tooltip.js.map +1 -1
- package/dist/lib/generate-radix-colors.cjs +1 -1
- package/dist/lib/generate-radix-colors.cjs.map +1 -1
- package/dist/lib/generate-radix-colors.js +1 -1
- package/dist/lib/generate-radix-colors.js.map +1 -1
- package/dist/lib/toggle-group-context.cjs +12 -0
- package/dist/lib/toggle-group-context.cjs.map +1 -0
- package/dist/lib/toggle-group-context.d.cts +17 -0
- package/dist/lib/toggle-group-context.d.ts +17 -0
- package/dist/lib/toggle-group-context.js +9 -0
- package/dist/lib/toggle-group-context.js.map +1 -0
- package/dist/styles/theme.css +15 -4
- package/dist/utils/format.cjs +1 -0
- package/dist/utils/format.cjs.map +1 -1
- package/dist/utils/format.d.cts +2 -1
- package/dist/utils/format.d.ts +2 -1
- package/dist/utils/format.js +1 -1
- package/dist/utils/format.js.map +1 -1
- 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"}
|
package/dist/styles/theme.css
CHANGED
|
@@ -600,7 +600,7 @@
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
/*
|
|
603
|
-
* Overlay / focus / selection
|
|
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
|
|
package/dist/utils/format.cjs
CHANGED
|
@@ -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"}
|
package/dist/utils/format.d.cts
CHANGED
|
@@ -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
|
package/dist/utils/format.d.ts
CHANGED
|
@@ -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
|
package/dist/utils/format.js
CHANGED
|
@@ -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
|
package/dist/utils/format.js.map
CHANGED
|
@@ -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,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.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 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"}
|