mood-ui 0.10.0 → 0.11.0
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/data-display/Chart.cjs +6 -0
- package/dist/components/data-display/Chart.cjs.map +1 -0
- package/dist/components/data-display/Chart.mjs +7 -0
- package/dist/components/data-display/Chart.mjs.map +1 -0
- package/dist/components/data-display/Chart.vue_vue_type_script_setup_true_lang.cjs +48 -0
- package/dist/components/data-display/Chart.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/data-display/Chart.vue_vue_type_script_setup_true_lang.mjs +47 -0
- package/dist/components/data-display/Chart.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/data-display/Stat.cjs.map +1 -1
- package/dist/components/data-display/Stat.mjs.map +1 -1
- package/dist/components/data-display/Stat.vue_vue_type_script_setup_true_lang.cjs +88 -75
- package/dist/components/data-display/Stat.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/Stat.vue_vue_type_script_setup_true_lang.mjs +90 -77
- package/dist/components/data-display/Stat.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/chart/Cartesian.cjs +6 -0
- package/dist/components/data-display/chart/Cartesian.cjs.map +1 -0
- package/dist/components/data-display/chart/Cartesian.mjs +7 -0
- package/dist/components/data-display/chart/Cartesian.mjs.map +1 -0
- package/dist/components/data-display/chart/Cartesian.vue_vue_type_script_setup_true_lang.cjs +573 -0
- package/dist/components/data-display/chart/Cartesian.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/data-display/chart/Cartesian.vue_vue_type_script_setup_true_lang.mjs +572 -0
- package/dist/components/data-display/chart/Cartesian.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/data-display/chart/Heatmap.cjs +6 -0
- package/dist/components/data-display/chart/Heatmap.cjs.map +1 -0
- package/dist/components/data-display/chart/Heatmap.mjs +7 -0
- package/dist/components/data-display/chart/Heatmap.mjs.map +1 -0
- package/dist/components/data-display/chart/Heatmap.vue_vue_type_script_setup_true_lang.cjs +332 -0
- package/dist/components/data-display/chart/Heatmap.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/data-display/chart/Heatmap.vue_vue_type_script_setup_true_lang.mjs +331 -0
- package/dist/components/data-display/chart/Heatmap.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/data-display/chart/Polar.cjs +6 -0
- package/dist/components/data-display/chart/Polar.cjs.map +1 -0
- package/dist/components/data-display/chart/Polar.mjs +7 -0
- package/dist/components/data-display/chart/Polar.mjs.map +1 -0
- package/dist/components/data-display/chart/Polar.vue_vue_type_script_setup_true_lang.cjs +361 -0
- package/dist/components/data-display/chart/Polar.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/data-display/chart/Polar.vue_vue_type_script_setup_true_lang.mjs +360 -0
- package/dist/components/data-display/chart/Polar.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/data-display/chart/Radar.cjs +6 -0
- package/dist/components/data-display/chart/Radar.cjs.map +1 -0
- package/dist/components/data-display/chart/Radar.mjs +7 -0
- package/dist/components/data-display/chart/Radar.mjs.map +1 -0
- package/dist/components/data-display/chart/Radar.vue_vue_type_script_setup_true_lang.cjs +347 -0
- package/dist/components/data-display/chart/Radar.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/data-display/chart/Radar.vue_vue_type_script_setup_true_lang.mjs +346 -0
- package/dist/components/data-display/chart/Radar.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/data-display/chart/Sparkline.cjs +6 -0
- package/dist/components/data-display/chart/Sparkline.cjs.map +1 -0
- package/dist/components/data-display/chart/Sparkline.mjs +7 -0
- package/dist/components/data-display/chart/Sparkline.mjs.map +1 -0
- package/dist/components/data-display/chart/Sparkline.vue_vue_type_script_setup_true_lang.cjs +293 -0
- package/dist/components/data-display/chart/Sparkline.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/data-display/chart/Sparkline.vue_vue_type_script_setup_true_lang.mjs +292 -0
- package/dist/components/data-display/chart/Sparkline.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/data-display/chart/useChart.cjs +189 -0
- package/dist/components/data-display/chart/useChart.cjs.map +1 -0
- package/dist/components/data-display/chart/useChart.mjs +182 -0
- package/dist/components/data-display/chart/useChart.mjs.map +1 -0
- package/dist/components/data-display/date-picker/DateRangePicker.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateRangePicker.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.cjs +1 -7
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.mjs +1 -7
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/feedback/Tooltip.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs +20 -3
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs +20 -3
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Button.cjs +1 -1
- package/dist/components/forms/Button.cjs.map +1 -1
- package/dist/components/forms/Button.mjs +1 -1
- package/dist/components/forms/Button.mjs.map +1 -1
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.cjs +76 -63
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.mjs +77 -64
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/ButtonGroup.cjs +1 -1
- package/dist/components/forms/ButtonGroup.cjs.map +1 -1
- package/dist/components/forms/ButtonGroup.mjs +1 -1
- package/dist/components/forms/ButtonGroup.mjs.map +1 -1
- package/dist/components/forms/ButtonGroup.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/ButtonGroup.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/ButtonGroup.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/ButtonGroup.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Checkbox.cjs +1 -1
- package/dist/components/forms/Checkbox.cjs.map +1 -1
- package/dist/components/forms/Checkbox.mjs +1 -1
- package/dist/components/forms/Checkbox.mjs.map +1 -1
- package/dist/components/forms/Checkbox.vue_vue_type_script_setup_true_lang.cjs +7 -7
- package/dist/components/forms/Checkbox.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Checkbox.vue_vue_type_script_setup_true_lang.mjs +7 -7
- package/dist/components/forms/Checkbox.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/ColorPicker.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/ColorPicker.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/DateField.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/DateField.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/DateRangeField.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/DateRangeField.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/DateTimeField.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/DateTimeField.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/FormField.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/FormField.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/Input.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/Input.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/MenuButton.cjs +6 -0
- package/dist/components/forms/MenuButton.cjs.map +1 -0
- package/dist/components/forms/MenuButton.mjs +7 -0
- package/dist/components/forms/MenuButton.mjs.map +1 -0
- package/dist/components/forms/MenuButton.vue_vue_type_script_setup_true_lang.cjs +270 -0
- package/dist/components/forms/MenuButton.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/forms/MenuButton.vue_vue_type_script_setup_true_lang.mjs +269 -0
- package/dist/components/forms/MenuButton.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/NumberInput.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/NumberInput.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/OTPInput.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/OTPInput.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/PasswordInput.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/PasswordInput.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/Radio.cjs +1 -1
- package/dist/components/forms/Radio.cjs.map +1 -1
- package/dist/components/forms/Radio.mjs +1 -1
- package/dist/components/forms/Radio.mjs.map +1 -1
- package/dist/components/forms/Radio.vue_vue_type_script_setup_true_lang.cjs +6 -6
- package/dist/components/forms/Radio.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Radio.vue_vue_type_script_setup_true_lang.mjs +6 -6
- package/dist/components/forms/Radio.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/RangeSlider.cjs.map +1 -1
- package/dist/components/forms/RangeSlider.mjs.map +1 -1
- package/dist/components/forms/RangeSlider.vue_vue_type_script_setup_true_lang.cjs +6 -6
- package/dist/components/forms/RangeSlider.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/RangeSlider.vue_vue_type_script_setup_true_lang.mjs +6 -6
- package/dist/components/forms/RangeSlider.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/SearchInput.cjs.map +1 -1
- package/dist/components/forms/SearchInput.mjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs +225 -20
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs +227 -22
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Segmented.cjs +1 -1
- package/dist/components/forms/Segmented.cjs.map +1 -1
- package/dist/components/forms/Segmented.mjs +1 -1
- package/dist/components/forms/Segmented.mjs.map +1 -1
- package/dist/components/forms/Segmented.vue_vue_type_script_setup_true_lang.cjs +4 -12
- package/dist/components/forms/Segmented.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Segmented.vue_vue_type_script_setup_true_lang.mjs +4 -12
- package/dist/components/forms/Segmented.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Select.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/Select.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/Slider.cjs.map +1 -1
- package/dist/components/forms/Slider.mjs.map +1 -1
- package/dist/components/forms/Slider.vue_vue_type_script_setup_true_lang.cjs +6 -6
- package/dist/components/forms/Slider.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Slider.vue_vue_type_script_setup_true_lang.mjs +6 -6
- package/dist/components/forms/Slider.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Switch.cjs +1 -1
- package/dist/components/forms/Switch.cjs.map +1 -1
- package/dist/components/forms/Switch.mjs +1 -1
- package/dist/components/forms/Switch.mjs.map +1 -1
- package/dist/components/forms/Switch.vue_vue_type_script_setup_true_lang.cjs +7 -7
- package/dist/components/forms/Switch.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Switch.vue_vue_type_script_setup_true_lang.mjs +7 -7
- package/dist/components/forms/Switch.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/layout/AppShell.cjs.map +1 -1
- package/dist/components/layout/AppShell.mjs.map +1 -1
- package/dist/components/layout/AppShell.vue_vue_type_script_setup_true_lang.cjs +8 -8
- package/dist/components/layout/AppShell.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/AppShell.vue_vue_type_script_setup_true_lang.mjs +8 -8
- package/dist/components/layout/AppShell.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/Sidebar.cjs.map +1 -1
- package/dist/components/layout/Sidebar.mjs.map +1 -1
- package/dist/components/layout/Sidebar.vue_vue_type_script_setup_true_lang.cjs +36 -21
- package/dist/components/layout/Sidebar.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/Sidebar.vue_vue_type_script_setup_true_lang.mjs +36 -21
- package/dist/components/layout/Sidebar.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/Topbar.cjs.map +1 -1
- package/dist/components/layout/Topbar.mjs.map +1 -1
- package/dist/components/layout/Topbar.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/layout/Topbar.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/Topbar.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/layout/Topbar.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/Switcher.cjs.map +1 -1
- package/dist/components/navigation/Switcher.mjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs +4 -4
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs +4 -4
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/Tabs.cjs +1 -1
- package/dist/components/navigation/Tabs.cjs.map +1 -1
- package/dist/components/navigation/Tabs.mjs +1 -1
- package/dist/components/navigation/Tabs.mjs.map +1 -1
- package/dist/components/navigation/Tabs.vue_vue_type_script_setup_true_lang.cjs +1 -9
- package/dist/components/navigation/Tabs.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/Tabs.vue_vue_type_script_setup_true_lang.mjs +1 -9
- package/dist/components/navigation/Tabs.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/composables/useField.cjs +21 -23
- package/dist/composables/useField.cjs.map +1 -1
- package/dist/composables/useField.mjs +21 -24
- package/dist/composables/useField.mjs.map +1 -1
- package/dist/composables/usePopover.cjs +5 -1
- package/dist/composables/usePopover.cjs.map +1 -1
- package/dist/composables/usePopover.mjs +5 -1
- package/dist/composables/usePopover.mjs.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.mjs +4 -2
- package/dist/mood-ui.css +107 -473
- package/dist/types/components/data-display/Chart.vue.d.ts +8 -0
- package/dist/types/components/data-display/Stat.vue.d.ts +12 -2
- package/dist/types/components/data-display/chart/Cartesian.vue.d.ts +17 -0
- package/dist/types/components/data-display/chart/Heatmap.vue.d.ts +10 -0
- package/dist/types/components/data-display/chart/Polar.vue.d.ts +9 -0
- package/dist/types/components/data-display/chart/Radar.vue.d.ts +10 -0
- package/dist/types/components/data-display/chart/Sparkline.vue.d.ts +13 -0
- package/dist/types/components/data-display/chart/useChart.d.ts +49 -0
- package/dist/types/components/feedback/Drawer.vue.d.ts +2 -2
- package/dist/types/components/feedback/Modal.vue.d.ts +2 -2
- package/dist/types/components/feedback/Tooltip.vue.d.ts +1 -1
- package/dist/types/components/forms/Button.vue.d.ts +3 -2
- package/dist/types/components/forms/Combobox.vue.d.ts +3 -3
- package/dist/types/components/forms/DateField.vue.d.ts +3 -3
- package/dist/types/components/forms/DateRangeField.vue.d.ts +3 -3
- package/dist/types/components/forms/DateTimeField.vue.d.ts +3 -3
- package/dist/types/components/forms/MenuButton.vue.d.ts +23 -0
- package/dist/types/components/forms/MultiSelect.vue.d.ts +3 -3
- package/dist/types/components/forms/SearchInput.vue.d.ts +33 -2
- package/dist/types/components/forms/Select.vue.d.ts +2 -2
- package/dist/types/components/layout/AppShell.vue.d.ts +1 -1
- package/dist/types/components/layout/PageHeader.vue.d.ts +1 -1
- package/dist/types/components/layout/Sidebar.vue.d.ts +4 -4
- package/dist/types/components/layout/Stack.vue.d.ts +1 -1
- package/dist/types/components/layout/Topbar.vue.d.ts +1 -1
- package/dist/types/components/navigation/Breadcrumbs.vue.d.ts +1 -1
- package/dist/types/components/navigation/Switcher.vue.d.ts +3 -3
- package/dist/types/composables/useField.d.ts +10 -0
- package/dist/types/composables/usePopover.d.ts +7 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/interfaces/data-display/Chart.interface.d.ts +97 -0
- package/dist/types/interfaces/data-display/Stat.interface.d.ts +17 -6
- package/dist/types/interfaces/feedback/Tooltip.interface.d.ts +11 -0
- package/dist/types/interfaces/forms/MenuButton.interface.d.ts +38 -0
- package/dist/types/interfaces/forms/SearchInput.interface.d.ts +36 -0
- package/package.json +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
//#region src/components/data-display/chart/useChart.ts
|
|
2
|
+
var SEMANTIC = {
|
|
3
|
+
default: "var(--foreground)",
|
|
4
|
+
primary: "var(--primary)",
|
|
5
|
+
success: "var(--success)",
|
|
6
|
+
danger: "var(--destructive)",
|
|
7
|
+
warning: "var(--warning)",
|
|
8
|
+
info: "var(--info)"
|
|
9
|
+
};
|
|
10
|
+
/** Resolve a color: a semantic token name → its CSS var; a palette index →
|
|
11
|
+
* `--chart-N`; anything else is treated as a raw CSS color. */
|
|
12
|
+
function resolveColor(color, index = 0) {
|
|
13
|
+
if (!color) return `var(--chart-${index % 6 + 1})`;
|
|
14
|
+
if (SEMANTIC[color]) return SEMANTIC[color];
|
|
15
|
+
if (/^chart-[1-6]$/.test(color)) return `var(--${color})`;
|
|
16
|
+
return color;
|
|
17
|
+
}
|
|
18
|
+
/** Turn the polymorphic `data` prop into `{ categories, series }`. */
|
|
19
|
+
function normalize(data, opts = {}) {
|
|
20
|
+
const { index, series, labels, color } = opts;
|
|
21
|
+
const arr = data ?? [];
|
|
22
|
+
if (arr.length === 0 || typeof arr[0] === "number") {
|
|
23
|
+
const values = arr;
|
|
24
|
+
return {
|
|
25
|
+
categories: labels ?? values.map((_, i) => i),
|
|
26
|
+
series: [{
|
|
27
|
+
key: "value",
|
|
28
|
+
name: "value",
|
|
29
|
+
color: resolveColor(color, 0),
|
|
30
|
+
values
|
|
31
|
+
}]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const rows = arr;
|
|
35
|
+
const cats = index ? rows.map((r) => r[index]) : rows.map((_, i) => i);
|
|
36
|
+
let defs;
|
|
37
|
+
if (series && series.length) defs = series.map((s) => typeof s === "string" ? { key: s } : s);
|
|
38
|
+
else {
|
|
39
|
+
const first = rows[0] ?? {};
|
|
40
|
+
defs = Object.keys(first).filter((k) => k !== index && typeof first[k] === "number").map((k) => ({ key: k }));
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
categories: cats,
|
|
44
|
+
series: defs.map((s, i) => ({
|
|
45
|
+
key: s.key,
|
|
46
|
+
name: s.name ?? s.key,
|
|
47
|
+
color: s.color ? resolveColor(s.color, i) : `var(--chart-${i % 6 + 1})`,
|
|
48
|
+
values: rows.map((r) => {
|
|
49
|
+
const v = r[s.key];
|
|
50
|
+
return typeof v === "number" ? v : null;
|
|
51
|
+
})
|
|
52
|
+
}))
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Min/max across all series values (ignoring nulls). */
|
|
56
|
+
function extent(series, includeZero = true) {
|
|
57
|
+
let min = Infinity;
|
|
58
|
+
let max = -Infinity;
|
|
59
|
+
for (const s of series) for (const v of s.values) {
|
|
60
|
+
if (v == null) continue;
|
|
61
|
+
if (v < min) min = v;
|
|
62
|
+
if (v > max) max = v;
|
|
63
|
+
}
|
|
64
|
+
if (!isFinite(min)) {
|
|
65
|
+
min = 0;
|
|
66
|
+
max = 1;
|
|
67
|
+
}
|
|
68
|
+
if (includeZero) {
|
|
69
|
+
min = Math.min(min, 0);
|
|
70
|
+
max = Math.max(max, 0);
|
|
71
|
+
}
|
|
72
|
+
if (min === max) max = min + 1;
|
|
73
|
+
return [min, max];
|
|
74
|
+
}
|
|
75
|
+
/** Column-wise sums, for stacked charts / totals. */
|
|
76
|
+
function stackedExtent(series) {
|
|
77
|
+
const n = series[0]?.values.length ?? 0;
|
|
78
|
+
let max = 0;
|
|
79
|
+
let min = 0;
|
|
80
|
+
for (let i = 0; i < n; i++) {
|
|
81
|
+
let pos = 0;
|
|
82
|
+
let neg = 0;
|
|
83
|
+
for (const s of series) {
|
|
84
|
+
const v = s.values[i] ?? 0;
|
|
85
|
+
if (v >= 0) pos += v;
|
|
86
|
+
else neg += v;
|
|
87
|
+
}
|
|
88
|
+
if (pos > max) max = pos;
|
|
89
|
+
if (neg < min) min = neg;
|
|
90
|
+
}
|
|
91
|
+
if (min === max) max = min + 1;
|
|
92
|
+
return [min, max];
|
|
93
|
+
}
|
|
94
|
+
/** "Nice" axis ticks on a 1/2/5×10ⁿ lattice covering [min,max]. */
|
|
95
|
+
function niceTicks(min, max, count = 5) {
|
|
96
|
+
if (min === max) {
|
|
97
|
+
min -= 1;
|
|
98
|
+
max += 1;
|
|
99
|
+
}
|
|
100
|
+
const rough = (max - min) / Math.max(1, count);
|
|
101
|
+
const pow = Math.pow(10, Math.floor(Math.log10(rough)));
|
|
102
|
+
const norm = rough / pow;
|
|
103
|
+
const step = (norm >= 5 ? 10 : norm >= 2 ? 5 : norm >= 1 ? 2 : 1) * pow;
|
|
104
|
+
const niceMin = Math.floor(min / step) * step;
|
|
105
|
+
const niceMax = Math.ceil(max / step) * step;
|
|
106
|
+
const ticks = [];
|
|
107
|
+
for (let v = niceMin; v <= niceMax + step * 1e-6; v += step) ticks.push(Number(v.toFixed(10)));
|
|
108
|
+
return ticks;
|
|
109
|
+
}
|
|
110
|
+
/** Compact number formatter: 1_200 → "1.2k", 3_400_000 → "3.4M". */
|
|
111
|
+
function compact(v) {
|
|
112
|
+
const abs = Math.abs(v);
|
|
113
|
+
if (abs >= 1e9) return (v / 1e9).toFixed(1).replace(/\.0$/, "") + "B";
|
|
114
|
+
if (abs >= 1e6) return (v / 1e6).toFixed(1).replace(/\.0$/, "") + "M";
|
|
115
|
+
if (abs >= 1e3) return (v / 1e3).toFixed(1).replace(/\.0$/, "") + "k";
|
|
116
|
+
return String(Number(v.toFixed(2)));
|
|
117
|
+
}
|
|
118
|
+
/** Build a line path through points, with curve style. Handles null gaps by
|
|
119
|
+
* breaking the path (unless `connect`). */
|
|
120
|
+
function linePath(pts, curve = "smooth", connect = false) {
|
|
121
|
+
const segs = [];
|
|
122
|
+
let cur = [];
|
|
123
|
+
for (const p of pts) {
|
|
124
|
+
if (p == null) {
|
|
125
|
+
if (!connect) {
|
|
126
|
+
if (cur.length) segs.push(cur);
|
|
127
|
+
cur = [];
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
cur.push(p);
|
|
132
|
+
}
|
|
133
|
+
if (cur.length) segs.push(cur);
|
|
134
|
+
return segs.map((seg) => segToPath(seg, curve)).join(" ");
|
|
135
|
+
}
|
|
136
|
+
function segToPath(seg, curve) {
|
|
137
|
+
if (seg.length === 0) return "";
|
|
138
|
+
if (seg.length === 1) return `M ${f(seg[0].x)} ${f(seg[0].y)}`;
|
|
139
|
+
if (curve === "linear") return `M ${f(seg[0].x)} ${f(seg[0].y)} ` + seg.slice(1).map((p) => `L ${f(p.x)} ${f(p.y)}`).join(" ");
|
|
140
|
+
if (curve === "step") {
|
|
141
|
+
let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;
|
|
142
|
+
for (let i = 1; i < seg.length; i++) {
|
|
143
|
+
const midX = (seg[i - 1].x + seg[i].x) / 2;
|
|
144
|
+
d += ` L ${f(midX)} ${f(seg[i - 1].y)} L ${f(midX)} ${f(seg[i].y)} L ${f(seg[i].x)} ${f(seg[i].y)}`;
|
|
145
|
+
}
|
|
146
|
+
return d;
|
|
147
|
+
}
|
|
148
|
+
let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;
|
|
149
|
+
for (let i = 0; i < seg.length - 1; i++) {
|
|
150
|
+
const p0 = seg[i - 1] ?? seg[i];
|
|
151
|
+
const p1 = seg[i];
|
|
152
|
+
const p2 = seg[i + 1];
|
|
153
|
+
const p3 = seg[i + 2] ?? p2;
|
|
154
|
+
const c1x = p1.x + (p2.x - p0.x) / 6;
|
|
155
|
+
const c1y = p1.y + (p2.y - p0.y) / 6;
|
|
156
|
+
const c2x = p2.x - (p3.x - p1.x) / 6;
|
|
157
|
+
const c2y = p2.y - (p3.y - p1.y) / 6;
|
|
158
|
+
d += ` C ${f(c1x)} ${f(c1y)}, ${f(c2x)} ${f(c2y)}, ${f(p2.x)} ${f(p2.y)}`;
|
|
159
|
+
}
|
|
160
|
+
return d;
|
|
161
|
+
}
|
|
162
|
+
/** Arc path for donut/pie/gauge slices (SVG A command). */
|
|
163
|
+
function arcPath(cx, cy, rOuter, rInner, a0, a1) {
|
|
164
|
+
const large = a1 - a0 > Math.PI ? 1 : 0;
|
|
165
|
+
const x0 = cx + rOuter * Math.cos(a0);
|
|
166
|
+
const y0 = cy + rOuter * Math.sin(a0);
|
|
167
|
+
const x1 = cx + rOuter * Math.cos(a1);
|
|
168
|
+
const y1 = cy + rOuter * Math.sin(a1);
|
|
169
|
+
if (rInner <= 0) return `M ${cx} ${cy} L ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} Z`;
|
|
170
|
+
const xi0 = cx + rInner * Math.cos(a1);
|
|
171
|
+
const yi0 = cy + rInner * Math.sin(a1);
|
|
172
|
+
const xi1 = cx + rInner * Math.cos(a0);
|
|
173
|
+
const yi1 = cy + rInner * Math.sin(a0);
|
|
174
|
+
return `M ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} L ${f(xi0)} ${f(yi0)} A ${f(rInner)} ${f(rInner)} 0 ${large} 0 ${f(xi1)} ${f(yi1)} Z`;
|
|
175
|
+
}
|
|
176
|
+
function f(n) {
|
|
177
|
+
return Number.isFinite(n) ? n.toFixed(2) : "0";
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
exports.arcPath = arcPath;
|
|
181
|
+
exports.compact = compact;
|
|
182
|
+
exports.extent = extent;
|
|
183
|
+
exports.linePath = linePath;
|
|
184
|
+
exports.niceTicks = niceTicks;
|
|
185
|
+
exports.normalize = normalize;
|
|
186
|
+
exports.resolveColor = resolveColor;
|
|
187
|
+
exports.stackedExtent = stackedExtent;
|
|
188
|
+
|
|
189
|
+
//# sourceMappingURL=useChart.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChart.cjs","names":[],"sources":["../../../../src/components/data-display/chart/useChart.ts"],"sourcesContent":["/**\n * Shared chart math + normalization, used by the internal Cartesian / Polar\n * chart renderers behind the public `<Chart type>` component.\n */\n\nexport interface ChartPoint {\n x: number;\n y: number;\n}\n\n/** A normalized series: one line/area/bar group. */\nexport interface NormSeries {\n key: string;\n name: string;\n color: string;\n values: (number | null)[];\n}\n\nexport interface NormData {\n categories: (string | number)[];\n series: NormSeries[];\n}\n\nexport type SeriesDef = string | { key: string; name?: string; color?: string };\n\nconst SEMANTIC: Record<string, string> = {\n default: 'var(--foreground)',\n primary: 'var(--primary)',\n success: 'var(--success)',\n danger: 'var(--destructive)',\n warning: 'var(--warning)',\n info: 'var(--info)',\n};\n\n/** Resolve a color: a semantic token name → its CSS var; a palette index →\n * `--chart-N`; anything else is treated as a raw CSS color. */\nexport function resolveColor(color: string | undefined, index = 0): string {\n if (!color) return `var(--chart-${(index % 6) + 1})`;\n if (SEMANTIC[color]) return SEMANTIC[color];\n if (/^chart-[1-6]$/.test(color)) return `var(--${color})`;\n return color; // raw CSS color\n}\n\ninterface NormalizeOpts {\n index?: string;\n series?: SeriesDef[];\n labels?: (string | number)[];\n color?: string;\n}\n\n/** Turn the polymorphic `data` prop into `{ categories, series }`. */\nexport function normalize(\n data: number[] | Record<string, unknown>[],\n opts: NormalizeOpts = {},\n): NormData {\n const { index, series, labels, color } = opts;\n const arr = data ?? [];\n\n // number[] → a single series\n if (arr.length === 0 || typeof arr[0] === 'number') {\n const values = arr as number[];\n return {\n categories: labels ?? values.map((_, i) => i),\n series: [{ key: 'value', name: 'value', color: resolveColor(color, 0), values }],\n };\n }\n\n // rows[] + index (x key) + series (keys or defs)\n const rows = arr as Record<string, unknown>[];\n const cats = index ? rows.map((r) => r[index] as string | number) : rows.map((_, i) => i);\n let defs: { key: string; name?: string; color?: string }[];\n if (series && series.length) {\n defs = series.map((s) => (typeof s === 'string' ? { key: s } : s));\n } else {\n const first = rows[0] ?? {};\n defs = Object.keys(first)\n .filter((k) => k !== index && typeof first[k] === 'number')\n .map((k) => ({ key: k }));\n }\n return {\n categories: cats,\n series: defs.map((s, i) => ({\n key: s.key,\n name: s.name ?? s.key,\n color: s.color ? resolveColor(s.color, i) : `var(--chart-${(i % 6) + 1})`,\n values: rows.map((r) => {\n const v = r[s.key];\n return typeof v === 'number' ? v : null;\n }),\n })),\n };\n}\n\n/** Min/max across all series values (ignoring nulls). */\nexport function extent(series: NormSeries[], includeZero = true): [number, number] {\n let min = Infinity;\n let max = -Infinity;\n for (const s of series) {\n for (const v of s.values) {\n if (v == null) continue;\n if (v < min) min = v;\n if (v > max) max = v;\n }\n }\n if (!isFinite(min)) { min = 0; max = 1; }\n if (includeZero) { min = Math.min(min, 0); max = Math.max(max, 0); }\n if (min === max) { max = min + 1; }\n return [min, max];\n}\n\n/** Column-wise sums, for stacked charts / totals. */\nexport function stackedExtent(series: NormSeries[]): [number, number] {\n const n = series[0]?.values.length ?? 0;\n let max = 0;\n let min = 0;\n for (let i = 0; i < n; i++) {\n let pos = 0;\n let neg = 0;\n for (const s of series) {\n const v = s.values[i] ?? 0;\n if (v >= 0) pos += v; else neg += v;\n }\n if (pos > max) max = pos;\n if (neg < min) min = neg;\n }\n if (min === max) max = min + 1;\n return [min, max];\n}\n\n/** \"Nice\" axis ticks on a 1/2/5×10ⁿ lattice covering [min,max]. */\nexport function niceTicks(min: number, max: number, count = 5): number[] {\n if (min === max) { min -= 1; max += 1; }\n const range = max - min;\n const rough = range / Math.max(1, count);\n const pow = Math.pow(10, Math.floor(Math.log10(rough)));\n const norm = rough / pow;\n const step = (norm >= 5 ? 10 : norm >= 2 ? 5 : norm >= 1 ? 2 : 1) * pow;\n const niceMin = Math.floor(min / step) * step;\n const niceMax = Math.ceil(max / step) * step;\n const ticks: number[] = [];\n for (let v = niceMin; v <= niceMax + step * 1e-6; v += step) {\n ticks.push(Number(v.toFixed(10)));\n }\n return ticks;\n}\n\n/** Compact number formatter: 1_200 → \"1.2k\", 3_400_000 → \"3.4M\". */\nexport function compact(v: number): string {\n const abs = Math.abs(v);\n if (abs >= 1e9) return (v / 1e9).toFixed(1).replace(/\\.0$/, '') + 'B';\n if (abs >= 1e6) return (v / 1e6).toFixed(1).replace(/\\.0$/, '') + 'M';\n if (abs >= 1e3) return (v / 1e3).toFixed(1).replace(/\\.0$/, '') + 'k';\n return String(Number(v.toFixed(2)));\n}\n\n/* ---------- Path builders ---------- */\n\n/** Build a line path through points, with curve style. Handles null gaps by\n * breaking the path (unless `connect`). */\nexport function linePath(\n pts: (ChartPoint | null)[],\n curve: 'smooth' | 'linear' | 'step' = 'smooth',\n connect = false,\n): string {\n const segs: ChartPoint[][] = [];\n let cur: ChartPoint[] = [];\n for (const p of pts) {\n if (p == null) {\n if (!connect) { if (cur.length) segs.push(cur); cur = []; }\n continue;\n }\n cur.push(p);\n }\n if (cur.length) segs.push(cur);\n\n return segs.map((seg) => segToPath(seg, curve)).join(' ');\n}\n\nfunction segToPath(seg: ChartPoint[], curve: 'smooth' | 'linear' | 'step'): string {\n if (seg.length === 0) return '';\n if (seg.length === 1) return `M ${f(seg[0].x)} ${f(seg[0].y)}`;\n if (curve === 'linear') {\n return `M ${f(seg[0].x)} ${f(seg[0].y)} ` + seg.slice(1).map((p) => `L ${f(p.x)} ${f(p.y)}`).join(' ');\n }\n if (curve === 'step') {\n let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;\n for (let i = 1; i < seg.length; i++) {\n const midX = (seg[i - 1].x + seg[i].x) / 2;\n d += ` L ${f(midX)} ${f(seg[i - 1].y)} L ${f(midX)} ${f(seg[i].y)} L ${f(seg[i].x)} ${f(seg[i].y)}`;\n }\n return d;\n }\n // smooth: Catmull-Rom → cubic Bézier\n let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;\n for (let i = 0; i < seg.length - 1; i++) {\n const p0 = seg[i - 1] ?? seg[i];\n const p1 = seg[i];\n const p2 = seg[i + 1];\n const p3 = seg[i + 2] ?? p2;\n const c1x = p1.x + (p2.x - p0.x) / 6;\n const c1y = p1.y + (p2.y - p0.y) / 6;\n const c2x = p2.x - (p3.x - p1.x) / 6;\n const c2y = p2.y - (p3.y - p1.y) / 6;\n d += ` C ${f(c1x)} ${f(c1y)}, ${f(c2x)} ${f(c2y)}, ${f(p2.x)} ${f(p2.y)}`;\n }\n return d;\n}\n\n/** Arc path for donut/pie/gauge slices (SVG A command). */\nexport function arcPath(cx: number, cy: number, rOuter: number, rInner: number, a0: number, a1: number): string {\n const large = a1 - a0 > Math.PI ? 1 : 0;\n const x0 = cx + rOuter * Math.cos(a0);\n const y0 = cy + rOuter * Math.sin(a0);\n const x1 = cx + rOuter * Math.cos(a1);\n const y1 = cy + rOuter * Math.sin(a1);\n if (rInner <= 0) {\n return `M ${cx} ${cy} L ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} Z`;\n }\n const xi0 = cx + rInner * Math.cos(a1);\n const yi0 = cy + rInner * Math.sin(a1);\n const xi1 = cx + rInner * Math.cos(a0);\n const yi1 = cy + rInner * Math.sin(a0);\n return (\n `M ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} ` +\n `L ${f(xi0)} ${f(yi0)} A ${f(rInner)} ${f(rInner)} 0 ${large} 0 ${f(xi1)} ${f(yi1)} Z`\n );\n}\n\nfunction f(n: number): string {\n return Number.isFinite(n) ? n.toFixed(2) : '0';\n}\n"],"mappings":";AAyBA,IAAM,WAAmC;CACrC,SAAS;CACT,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,MAAM;CACT;;;AAID,S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+1,182 @@
|
|
|
1
|
+
//#region src/components/data-display/chart/useChart.ts
|
|
2
|
+
var SEMANTIC = {
|
|
3
|
+
default: "var(--foreground)",
|
|
4
|
+
primary: "var(--primary)",
|
|
5
|
+
success: "var(--success)",
|
|
6
|
+
danger: "var(--destructive)",
|
|
7
|
+
warning: "var(--warning)",
|
|
8
|
+
info: "var(--info)"
|
|
9
|
+
};
|
|
10
|
+
/** Resolve a color: a semantic token name → its CSS var; a palette index →
|
|
11
|
+
* `--chart-N`; anything else is treated as a raw CSS color. */
|
|
12
|
+
function resolveColor(color, index = 0) {
|
|
13
|
+
if (!color) return `var(--chart-${index % 6 + 1})`;
|
|
14
|
+
if (SEMANTIC[color]) return SEMANTIC[color];
|
|
15
|
+
if (/^chart-[1-6]$/.test(color)) return `var(--${color})`;
|
|
16
|
+
return color;
|
|
17
|
+
}
|
|
18
|
+
/** Turn the polymorphic `data` prop into `{ categories, series }`. */
|
|
19
|
+
function normalize(data, opts = {}) {
|
|
20
|
+
const { index, series, labels, color } = opts;
|
|
21
|
+
const arr = data ?? [];
|
|
22
|
+
if (arr.length === 0 || typeof arr[0] === "number") {
|
|
23
|
+
const values = arr;
|
|
24
|
+
return {
|
|
25
|
+
categories: labels ?? values.map((_, i) => i),
|
|
26
|
+
series: [{
|
|
27
|
+
key: "value",
|
|
28
|
+
name: "value",
|
|
29
|
+
color: resolveColor(color, 0),
|
|
30
|
+
values
|
|
31
|
+
}]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const rows = arr;
|
|
35
|
+
const cats = index ? rows.map((r) => r[index]) : rows.map((_, i) => i);
|
|
36
|
+
let defs;
|
|
37
|
+
if (series && series.length) defs = series.map((s) => typeof s === "string" ? { key: s } : s);
|
|
38
|
+
else {
|
|
39
|
+
const first = rows[0] ?? {};
|
|
40
|
+
defs = Object.keys(first).filter((k) => k !== index && typeof first[k] === "number").map((k) => ({ key: k }));
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
categories: cats,
|
|
44
|
+
series: defs.map((s, i) => ({
|
|
45
|
+
key: s.key,
|
|
46
|
+
name: s.name ?? s.key,
|
|
47
|
+
color: s.color ? resolveColor(s.color, i) : `var(--chart-${i % 6 + 1})`,
|
|
48
|
+
values: rows.map((r) => {
|
|
49
|
+
const v = r[s.key];
|
|
50
|
+
return typeof v === "number" ? v : null;
|
|
51
|
+
})
|
|
52
|
+
}))
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Min/max across all series values (ignoring nulls). */
|
|
56
|
+
function extent(series, includeZero = true) {
|
|
57
|
+
let min = Infinity;
|
|
58
|
+
let max = -Infinity;
|
|
59
|
+
for (const s of series) for (const v of s.values) {
|
|
60
|
+
if (v == null) continue;
|
|
61
|
+
if (v < min) min = v;
|
|
62
|
+
if (v > max) max = v;
|
|
63
|
+
}
|
|
64
|
+
if (!isFinite(min)) {
|
|
65
|
+
min = 0;
|
|
66
|
+
max = 1;
|
|
67
|
+
}
|
|
68
|
+
if (includeZero) {
|
|
69
|
+
min = Math.min(min, 0);
|
|
70
|
+
max = Math.max(max, 0);
|
|
71
|
+
}
|
|
72
|
+
if (min === max) max = min + 1;
|
|
73
|
+
return [min, max];
|
|
74
|
+
}
|
|
75
|
+
/** Column-wise sums, for stacked charts / totals. */
|
|
76
|
+
function stackedExtent(series) {
|
|
77
|
+
const n = series[0]?.values.length ?? 0;
|
|
78
|
+
let max = 0;
|
|
79
|
+
let min = 0;
|
|
80
|
+
for (let i = 0; i < n; i++) {
|
|
81
|
+
let pos = 0;
|
|
82
|
+
let neg = 0;
|
|
83
|
+
for (const s of series) {
|
|
84
|
+
const v = s.values[i] ?? 0;
|
|
85
|
+
if (v >= 0) pos += v;
|
|
86
|
+
else neg += v;
|
|
87
|
+
}
|
|
88
|
+
if (pos > max) max = pos;
|
|
89
|
+
if (neg < min) min = neg;
|
|
90
|
+
}
|
|
91
|
+
if (min === max) max = min + 1;
|
|
92
|
+
return [min, max];
|
|
93
|
+
}
|
|
94
|
+
/** "Nice" axis ticks on a 1/2/5×10ⁿ lattice covering [min,max]. */
|
|
95
|
+
function niceTicks(min, max, count = 5) {
|
|
96
|
+
if (min === max) {
|
|
97
|
+
min -= 1;
|
|
98
|
+
max += 1;
|
|
99
|
+
}
|
|
100
|
+
const rough = (max - min) / Math.max(1, count);
|
|
101
|
+
const pow = Math.pow(10, Math.floor(Math.log10(rough)));
|
|
102
|
+
const norm = rough / pow;
|
|
103
|
+
const step = (norm >= 5 ? 10 : norm >= 2 ? 5 : norm >= 1 ? 2 : 1) * pow;
|
|
104
|
+
const niceMin = Math.floor(min / step) * step;
|
|
105
|
+
const niceMax = Math.ceil(max / step) * step;
|
|
106
|
+
const ticks = [];
|
|
107
|
+
for (let v = niceMin; v <= niceMax + step * 1e-6; v += step) ticks.push(Number(v.toFixed(10)));
|
|
108
|
+
return ticks;
|
|
109
|
+
}
|
|
110
|
+
/** Compact number formatter: 1_200 → "1.2k", 3_400_000 → "3.4M". */
|
|
111
|
+
function compact(v) {
|
|
112
|
+
const abs = Math.abs(v);
|
|
113
|
+
if (abs >= 1e9) return (v / 1e9).toFixed(1).replace(/\.0$/, "") + "B";
|
|
114
|
+
if (abs >= 1e6) return (v / 1e6).toFixed(1).replace(/\.0$/, "") + "M";
|
|
115
|
+
if (abs >= 1e3) return (v / 1e3).toFixed(1).replace(/\.0$/, "") + "k";
|
|
116
|
+
return String(Number(v.toFixed(2)));
|
|
117
|
+
}
|
|
118
|
+
/** Build a line path through points, with curve style. Handles null gaps by
|
|
119
|
+
* breaking the path (unless `connect`). */
|
|
120
|
+
function linePath(pts, curve = "smooth", connect = false) {
|
|
121
|
+
const segs = [];
|
|
122
|
+
let cur = [];
|
|
123
|
+
for (const p of pts) {
|
|
124
|
+
if (p == null) {
|
|
125
|
+
if (!connect) {
|
|
126
|
+
if (cur.length) segs.push(cur);
|
|
127
|
+
cur = [];
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
cur.push(p);
|
|
132
|
+
}
|
|
133
|
+
if (cur.length) segs.push(cur);
|
|
134
|
+
return segs.map((seg) => segToPath(seg, curve)).join(" ");
|
|
135
|
+
}
|
|
136
|
+
function segToPath(seg, curve) {
|
|
137
|
+
if (seg.length === 0) return "";
|
|
138
|
+
if (seg.length === 1) return `M ${f(seg[0].x)} ${f(seg[0].y)}`;
|
|
139
|
+
if (curve === "linear") return `M ${f(seg[0].x)} ${f(seg[0].y)} ` + seg.slice(1).map((p) => `L ${f(p.x)} ${f(p.y)}`).join(" ");
|
|
140
|
+
if (curve === "step") {
|
|
141
|
+
let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;
|
|
142
|
+
for (let i = 1; i < seg.length; i++) {
|
|
143
|
+
const midX = (seg[i - 1].x + seg[i].x) / 2;
|
|
144
|
+
d += ` L ${f(midX)} ${f(seg[i - 1].y)} L ${f(midX)} ${f(seg[i].y)} L ${f(seg[i].x)} ${f(seg[i].y)}`;
|
|
145
|
+
}
|
|
146
|
+
return d;
|
|
147
|
+
}
|
|
148
|
+
let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;
|
|
149
|
+
for (let i = 0; i < seg.length - 1; i++) {
|
|
150
|
+
const p0 = seg[i - 1] ?? seg[i];
|
|
151
|
+
const p1 = seg[i];
|
|
152
|
+
const p2 = seg[i + 1];
|
|
153
|
+
const p3 = seg[i + 2] ?? p2;
|
|
154
|
+
const c1x = p1.x + (p2.x - p0.x) / 6;
|
|
155
|
+
const c1y = p1.y + (p2.y - p0.y) / 6;
|
|
156
|
+
const c2x = p2.x - (p3.x - p1.x) / 6;
|
|
157
|
+
const c2y = p2.y - (p3.y - p1.y) / 6;
|
|
158
|
+
d += ` C ${f(c1x)} ${f(c1y)}, ${f(c2x)} ${f(c2y)}, ${f(p2.x)} ${f(p2.y)}`;
|
|
159
|
+
}
|
|
160
|
+
return d;
|
|
161
|
+
}
|
|
162
|
+
/** Arc path for donut/pie/gauge slices (SVG A command). */
|
|
163
|
+
function arcPath(cx, cy, rOuter, rInner, a0, a1) {
|
|
164
|
+
const large = a1 - a0 > Math.PI ? 1 : 0;
|
|
165
|
+
const x0 = cx + rOuter * Math.cos(a0);
|
|
166
|
+
const y0 = cy + rOuter * Math.sin(a0);
|
|
167
|
+
const x1 = cx + rOuter * Math.cos(a1);
|
|
168
|
+
const y1 = cy + rOuter * Math.sin(a1);
|
|
169
|
+
if (rInner <= 0) return `M ${cx} ${cy} L ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} Z`;
|
|
170
|
+
const xi0 = cx + rInner * Math.cos(a1);
|
|
171
|
+
const yi0 = cy + rInner * Math.sin(a1);
|
|
172
|
+
const xi1 = cx + rInner * Math.cos(a0);
|
|
173
|
+
const yi1 = cy + rInner * Math.sin(a0);
|
|
174
|
+
return `M ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} L ${f(xi0)} ${f(yi0)} A ${f(rInner)} ${f(rInner)} 0 ${large} 0 ${f(xi1)} ${f(yi1)} Z`;
|
|
175
|
+
}
|
|
176
|
+
function f(n) {
|
|
177
|
+
return Number.isFinite(n) ? n.toFixed(2) : "0";
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
export { arcPath, compact, extent, linePath, niceTicks, normalize, resolveColor, stackedExtent };
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=useChart.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChart.mjs","names":[],"sources":["../../../../src/components/data-display/chart/useChart.ts"],"sourcesContent":["/**\n * Shared chart math + normalization, used by the internal Cartesian / Polar\n * chart renderers behind the public `<Chart type>` component.\n */\n\nexport interface ChartPoint {\n x: number;\n y: number;\n}\n\n/** A normalized series: one line/area/bar group. */\nexport interface NormSeries {\n key: string;\n name: string;\n color: string;\n values: (number | null)[];\n}\n\nexport interface NormData {\n categories: (string | number)[];\n series: NormSeries[];\n}\n\nexport type SeriesDef = string | { key: string; name?: string; color?: string };\n\nconst SEMANTIC: Record<string, string> = {\n default: 'var(--foreground)',\n primary: 'var(--primary)',\n success: 'var(--success)',\n danger: 'var(--destructive)',\n warning: 'var(--warning)',\n info: 'var(--info)',\n};\n\n/** Resolve a color: a semantic token name → its CSS var; a palette index →\n * `--chart-N`; anything else is treated as a raw CSS color. */\nexport function resolveColor(color: string | undefined, index = 0): string {\n if (!color) return `var(--chart-${(index % 6) + 1})`;\n if (SEMANTIC[color]) return SEMANTIC[color];\n if (/^chart-[1-6]$/.test(color)) return `var(--${color})`;\n return color; // raw CSS color\n}\n\ninterface NormalizeOpts {\n index?: string;\n series?: SeriesDef[];\n labels?: (string | number)[];\n color?: string;\n}\n\n/** Turn the polymorphic `data` prop into `{ categories, series }`. */\nexport function normalize(\n data: number[] | Record<string, unknown>[],\n opts: NormalizeOpts = {},\n): NormData {\n const { index, series, labels, color } = opts;\n const arr = data ?? [];\n\n // number[] → a single series\n if (arr.length === 0 || typeof arr[0] === 'number') {\n const values = arr as number[];\n return {\n categories: labels ?? values.map((_, i) => i),\n series: [{ key: 'value', name: 'value', color: resolveColor(color, 0), values }],\n };\n }\n\n // rows[] + index (x key) + series (keys or defs)\n const rows = arr as Record<string, unknown>[];\n const cats = index ? rows.map((r) => r[index] as string | number) : rows.map((_, i) => i);\n let defs: { key: string; name?: string; color?: string }[];\n if (series && series.length) {\n defs = series.map((s) => (typeof s === 'string' ? { key: s } : s));\n } else {\n const first = rows[0] ?? {};\n defs = Object.keys(first)\n .filter((k) => k !== index && typeof first[k] === 'number')\n .map((k) => ({ key: k }));\n }\n return {\n categories: cats,\n series: defs.map((s, i) => ({\n key: s.key,\n name: s.name ?? s.key,\n color: s.color ? resolveColor(s.color, i) : `var(--chart-${(i % 6) + 1})`,\n values: rows.map((r) => {\n const v = r[s.key];\n return typeof v === 'number' ? v : null;\n }),\n })),\n };\n}\n\n/** Min/max across all series values (ignoring nulls). */\nexport function extent(series: NormSeries[], includeZero = true): [number, number] {\n let min = Infinity;\n let max = -Infinity;\n for (const s of series) {\n for (const v of s.values) {\n if (v == null) continue;\n if (v < min) min = v;\n if (v > max) max = v;\n }\n }\n if (!isFinite(min)) { min = 0; max = 1; }\n if (includeZero) { min = Math.min(min, 0); max = Math.max(max, 0); }\n if (min === max) { max = min + 1; }\n return [min, max];\n}\n\n/** Column-wise sums, for stacked charts / totals. */\nexport function stackedExtent(series: NormSeries[]): [number, number] {\n const n = series[0]?.values.length ?? 0;\n let max = 0;\n let min = 0;\n for (let i = 0; i < n; i++) {\n let pos = 0;\n let neg = 0;\n for (const s of series) {\n const v = s.values[i] ?? 0;\n if (v >= 0) pos += v; else neg += v;\n }\n if (pos > max) max = pos;\n if (neg < min) min = neg;\n }\n if (min === max) max = min + 1;\n return [min, max];\n}\n\n/** \"Nice\" axis ticks on a 1/2/5×10ⁿ lattice covering [min,max]. */\nexport function niceTicks(min: number, max: number, count = 5): number[] {\n if (min === max) { min -= 1; max += 1; }\n const range = max - min;\n const rough = range / Math.max(1, count);\n const pow = Math.pow(10, Math.floor(Math.log10(rough)));\n const norm = rough / pow;\n const step = (norm >= 5 ? 10 : norm >= 2 ? 5 : norm >= 1 ? 2 : 1) * pow;\n const niceMin = Math.floor(min / step) * step;\n const niceMax = Math.ceil(max / step) * step;\n const ticks: number[] = [];\n for (let v = niceMin; v <= niceMax + step * 1e-6; v += step) {\n ticks.push(Number(v.toFixed(10)));\n }\n return ticks;\n}\n\n/** Compact number formatter: 1_200 → \"1.2k\", 3_400_000 → \"3.4M\". */\nexport function compact(v: number): string {\n const abs = Math.abs(v);\n if (abs >= 1e9) return (v / 1e9).toFixed(1).replace(/\\.0$/, '') + 'B';\n if (abs >= 1e6) return (v / 1e6).toFixed(1).replace(/\\.0$/, '') + 'M';\n if (abs >= 1e3) return (v / 1e3).toFixed(1).replace(/\\.0$/, '') + 'k';\n return String(Number(v.toFixed(2)));\n}\n\n/* ---------- Path builders ---------- */\n\n/** Build a line path through points, with curve style. Handles null gaps by\n * breaking the path (unless `connect`). */\nexport function linePath(\n pts: (ChartPoint | null)[],\n curve: 'smooth' | 'linear' | 'step' = 'smooth',\n connect = false,\n): string {\n const segs: ChartPoint[][] = [];\n let cur: ChartPoint[] = [];\n for (const p of pts) {\n if (p == null) {\n if (!connect) { if (cur.length) segs.push(cur); cur = []; }\n continue;\n }\n cur.push(p);\n }\n if (cur.length) segs.push(cur);\n\n return segs.map((seg) => segToPath(seg, curve)).join(' ');\n}\n\nfunction segToPath(seg: ChartPoint[], curve: 'smooth' | 'linear' | 'step'): string {\n if (seg.length === 0) return '';\n if (seg.length === 1) return `M ${f(seg[0].x)} ${f(seg[0].y)}`;\n if (curve === 'linear') {\n return `M ${f(seg[0].x)} ${f(seg[0].y)} ` + seg.slice(1).map((p) => `L ${f(p.x)} ${f(p.y)}`).join(' ');\n }\n if (curve === 'step') {\n let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;\n for (let i = 1; i < seg.length; i++) {\n const midX = (seg[i - 1].x + seg[i].x) / 2;\n d += ` L ${f(midX)} ${f(seg[i - 1].y)} L ${f(midX)} ${f(seg[i].y)} L ${f(seg[i].x)} ${f(seg[i].y)}`;\n }\n return d;\n }\n // smooth: Catmull-Rom → cubic Bézier\n let d = `M ${f(seg[0].x)} ${f(seg[0].y)}`;\n for (let i = 0; i < seg.length - 1; i++) {\n const p0 = seg[i - 1] ?? seg[i];\n const p1 = seg[i];\n const p2 = seg[i + 1];\n const p3 = seg[i + 2] ?? p2;\n const c1x = p1.x + (p2.x - p0.x) / 6;\n const c1y = p1.y + (p2.y - p0.y) / 6;\n const c2x = p2.x - (p3.x - p1.x) / 6;\n const c2y = p2.y - (p3.y - p1.y) / 6;\n d += ` C ${f(c1x)} ${f(c1y)}, ${f(c2x)} ${f(c2y)}, ${f(p2.x)} ${f(p2.y)}`;\n }\n return d;\n}\n\n/** Arc path for donut/pie/gauge slices (SVG A command). */\nexport function arcPath(cx: number, cy: number, rOuter: number, rInner: number, a0: number, a1: number): string {\n const large = a1 - a0 > Math.PI ? 1 : 0;\n const x0 = cx + rOuter * Math.cos(a0);\n const y0 = cy + rOuter * Math.sin(a0);\n const x1 = cx + rOuter * Math.cos(a1);\n const y1 = cy + rOuter * Math.sin(a1);\n if (rInner <= 0) {\n return `M ${cx} ${cy} L ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} Z`;\n }\n const xi0 = cx + rInner * Math.cos(a1);\n const yi0 = cy + rInner * Math.sin(a1);\n const xi1 = cx + rInner * Math.cos(a0);\n const yi1 = cy + rInner * Math.sin(a0);\n return (\n `M ${f(x0)} ${f(y0)} A ${f(rOuter)} ${f(rOuter)} 0 ${large} 1 ${f(x1)} ${f(y1)} ` +\n `L ${f(xi0)} ${f(yi0)} A ${f(rInner)} ${f(rInner)} 0 ${large} 0 ${f(xi1)} ${f(yi1)} Z`\n );\n}\n\nfunction f(n: number): string {\n return Number.isFinite(n) ? n.toFixed(2) : '0';\n}\n"],"mappings":";AAyBA,IAAM,WAAmC;CACrC,SAAS;CACT,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,MAAM;CACT;;;AAID,SAAgB,aAAa,OAA2B,QAAQ,GAAW;CACvE,IAAI,CAAC,OAAO,OAAO,eAAgB,QAAQ,IAAK,EAAE;CAClD,IAAI,SAAS,QAAQ,OAAO,SAAS;CACrC,IAAI,gBAAgB,KAAK,MAAM,EAAE,OAAO,SAAS,MAAM;CACvD,OAAO;;;AAWX,SAAgB,UACZ,MACA,OAAsB,EAAE,EAChB;CACR,MAAM,EAAE,OAAO,QAAQ,QAAQ,UAAU;CACzC,MAAM,MAAM,QAAQ,EAAE;CAGtB,IAAI,IAAI,WAAW,KAAK,OAAO,IAAI,OAAO,UAAU;EAChD,MAAM,SAAS;EACf,OAAO;GACH,YAAY,UAAU,OAAO,KAAK,GAAG,MAAM,EAAE;GAC7C,QAAQ,CAAC;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G,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,MAAM,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;CAExG,MAAM,MAAM,KAAK,SAAS,KAAK,IAAI,GAAG;CACtC,MAAM,MAAM,KAAK,SAAS,KAAK,IAAI,GAAG;CACtC,MAAM,MAAM,KAAK,SAAS,KAAK,IAAI,GAAG;CACtC,MAAM,MAAM,KAAK,SAAS,KAAK,IAAI,GAAG;CACtC,OACI,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,MAAM,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,KAC1E,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,MAAM,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC;;AAI3F,SAAS,EAAE,GAAmB;CAC1B,OAAO,OAAO,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateRangePicker.cjs","names":[],"sources":["../../../../src/components/data-display/date-picker/DateRangePicker.vue"],"sourcesContent":["<template> \n <div \n :class=\"['inline-flex flex-col sm:flex-row select-none bg-card w-fit max-w-full self-start', variant === 'outline' ? 'border border-border' : '', containerRadiusClass]\" \n role=\"application\" \n aria-label=\"Date range picker\" \n > \n <div \n v-if=\"showPresets\" \n class=\"flex flex-row sm:flex-col gap-2 sm:gap-1 p-3 border-b sm:border-b-0 sm:border-r border-border sm:min-w-35 overflow-x-auto sm:overflow-x-visible\" \n > \n <button \n v-for=\"preset in effectivePresets\" \n :key=\"preset.label\" \n type=\"button\" \n @click=\"applyPreset(preset)\" \n :class=\"[ \n 'text-left text-sm px-3 py-1.5 rounded-md transition-colors cursor-pointer focus:outline-none focus-visible:ring-2 shrink-0 whitespace-nowrap', \n focusRingColorClass, \n isActivePreset(preset) \n ? activePresetClasses \n : 'text-foreground/80 hover:bg-muted', \n ]\" \n > \n {{ preset.label }} \n </button> \n </div> \n \n <div class=\"flex flex-col sm:flex-row\"> \n <div \n v-for=\"(panel, idx) in panels\" \n :key=\"idx\" \n class=\"flex flex-col\" \n :class=\"idx > 0 ? 'border-t sm:border-t-0 sm:border-l border-border' : ''\" \n > \n <div class=\"flex items-center justify-between px-2 py-3\"> \n <div class=\"flex items-center gap-0.5\"> \n <Button \n v-if=\"idx === 0\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronDoubleLeftIcon\" \n :ariaLabel=\"loc.calendar.prevYear\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('right', () => shiftYear(-1))\" \n /> \n <Button \n v-if=\"idx === 0\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronLeftIcon\" \n :ariaLabel=\"loc.calendar.prevMonth\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('right', () => shiftMonth(-1))\" \n /> \n <div v-if=\"idx !== 0\" class=\"w-15\"></div> \n </div> \n \n <span class=\"text-sm font-semibold text-foreground\"> \n {{ formatMonthYear(panel.month, panel.year) }} \n </span> \n \n <div class=\"flex items-center gap-0.5\"> \n <Button \n v-if=\"idx === panels.length - 1\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronRightIcon\" \n :ariaLabel=\"loc.calendar.nextMonth\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('left', () => shiftMonth(1))\" \n /> \n <Button \n v-if=\"idx === panels.length - 1\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronDoubleRightIcon\" \n :ariaLabel=\"loc.calendar.nextYear\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('left', () => shiftYear(1))\" \n /> \n <div v-if=\"idx !== panels.length - 1\" class=\"w-15\"></div> \n </div> \n </div> \n \n <div class=\"grid grid-cols-7 px-2\"> \n <div \n v-for=\"dayLabel in weekDayLabels\" \n :key=\"dayLabel\" \n class=\"text-center text-xs font-medium text-muted-foreground py-2\" \n > \n {{ dayLabel }} \n </div> \n </div> \n \n <div class=\"overflow-hidden px-2 pb-3\"> \n <div :ref=\"(el: unknown) => setGridRef(el as HTMLElement | null, idx)\" class=\"grid grid-cols-7\"> \n <div \n v-for=\"day in panel.days\" \n :key=\"day.date.getTime()\" \n class=\"relative flex items-center justify-center w-9 h-9\" \n > \n <span \n v-if=\"bgSide(day) === 'full'\" \n aria-hidden=\"true\" \n :class=\"['absolute inset-y-0 -inset-x-px pointer-events-none', rangeMiddleBgClass]\" \n /> \n <span \n v-else-if=\"bgSide(day) === 'left'\" \n aria-hidden=\"true\" \n :class=\"['absolute inset-y-0 -left-px right-1/2 pointer-events-none', rangeMiddleBgClass]\" \n /> \n <span \n v-else-if=\"bgSide(day) === 'right'\" \n aria-hidden=\"true\" \n :class=\"['absolute inset-y-0 left-1/2 -right-px pointer-events-none', rangeMiddleBgClass]\" \n /> \n \n <button \n type=\"button\" \n :disabled=\"day.disabled\" \n :aria-label=\"day.date.toLocaleDateString(locale === 'default' ? undefined : locale)\" \n :aria-selected=\"day.isRangeStart || day.isRangeEnd\" \n @click=\"!day.disabled && handleDayClick(day.date)\" \n @mouseenter=\"!day.disabled && (hoverDate = day.date)\" \n @mouseleave=\"hoverDate = null\" \n :class=\"[ \n 'relative z-10 w-9 h-9 text-sm flex items-center justify-center transition-colors cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1', \n dayRadiusClass, \n focusRingColorClass, \n dayStateClasses(day), \n ]\" \n > \n {{ day.day }} \n </button> \n </div> \n </div> \n </div> \n </div> \n </div> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { ref, computed, nextTick } from 'vue'; \nimport { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleLeftIcon, ChevronDoubleRightIcon } from '@heroicons/vue/24/outline'; \nimport Button from '../../forms/Button.vue'; \nimport gsap from 'gsap'; \nimport type { DateRangePicker, RangePreset } from '../../../interfaces/data-display/date-picker/DateRangePicker.interface'; \nimport { isSameDay, startOfDay, type CalendarDay } from '../../../composables/useCalendar'; \nimport { useResolvedColor, useResolvedRadius, useModoLocale } from '../../../composables/useModoConfig'; \n \nconst loc = useModoLocale(); \n \nconst props = withDefaults(defineProps<DateRangePicker>(), { \n modelValue: () => [null, null] as [Date | null, Date | null], \n locale: 'default', \n firstDayOfWeek: 0, \n color: 'default', \n variant: 'outline', \n months: 2, \n showPresets: true, \n}); \n \nconst resolvedColor = useResolvedColor(() => props.color); \nconst resolvedRadius = useResolvedRadius(() => props.radius); \n \nconst emit = defineEmits<{ \n 'update:modelValue': [range: [Date | null, Date | null]]; \n 'rangeComplete': [range: [Date, Date]]; \n}>(); \n \nconst gridRefs = ref<(HTMLElement | null)[]>([]); \nconst setGridRef = (el: HTMLElement | null, idx: number) => { gridRefs.value[idx] = el; }; \n \nconst today = new Date(); \n \nconst baseMonth = ref(props.modelValue[0]?.getMonth() ?? today.getMonth()); \nconst baseYear = ref(props.modelValue[0]?.getFullYear() ?? today.getFullYear()); \n \nconst pendingStart = ref<Date | null>(props.modelValue[0] ?? null); \nconst pendingEnd = ref<Date | null>(props.modelValue[1] ?? null); \nconst hoverDate = ref<Date | null>(null); \nconst isAnimating = ref(false); \n \nconst defaultPresets: RangePreset[] = [ \n { label: 'Today', range: () => [new Date(), new Date()] }, \n { label: 'Yesterday', range: () => { const d = new Date(); d.setDate(d.getDate() - 1); return [d, new Date(d)]; } }, \n { label: 'Last 7 days', range: () => { const s = new Date(); s.setDate(s.getDate() - 6); return [s, new Date()]; } }, \n { label: 'Last 30 days', range: () => { const s = new Date(); s.setDate(s.getDate() - 29); return [s, new Date()]; } }, \n { label: 'This month', range: () => { const now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), 1), new Date(now.getFullYear(), now.getMonth() + 1, 0)]; } }, \n { label: 'Last month', range: () => { const now = new Date(); return [new Date(now.getFullYear(), now.getMonth() - 1, 1), new Date(now.getFullYear(), now.getMonth(), 0)]; } }, \n { label: 'This year', range: () => { const now = new Date(); return [new Date(now.getFullYear(), 0, 1), new Date(now.getFullYear(), 11, 31)]; } }, \n]; \n \nconst effectivePresets = computed(() => props.presets ?? defaultPresets); \n \nconst isActivePreset = (preset: RangePreset) => { \n if (!pendingStart.value || !pendingEnd.value) return false; \n const [s, e] = preset.range(); \n return isSameDay(s, pendingStart.value) && isSameDay(e, pendingEnd.value); \n}; \n \nconst applyPreset = (preset: RangePreset) => { \n const [s, e] = preset.range(); \n pendingStart.value = s; \n pendingEnd.value = e; \n baseMonth.value = s.getMonth(); \n baseYear.value = s.getFullYear(); \n emit('update:modelValue', [s, e]); \n emit('rangeComplete', [s, e]); \n}; \n \nconst locale = computed(() => props.locale === 'default' ? undefined : props.locale); \n \nconst formatMonthYear = (month: number, year: number) => { \n return new Date(year, month, 1).toLocaleString(locale.value, { month: 'long', year: 'numeric' }); \n}; \n \nconst weekDayLabels = computed(() => { \n const labels: string[] = []; \n const base = new Date(2024, 0, 7 + props.firstDayOfWeek); \n for (let i = 0; i < 7; i++) { \n const d = new Date(base); \n d.setDate(base.getDate() + i); \n labels.push(d.toLocaleString(locale.value, { weekday: 'short' }).slice(0, 2)); \n } \n return labels; \n}); \n \ninterface Panel { \n month: number; \n year: number; \n days: CalendarDay[]; \n} \n \nconst currentRange = computed<[Date | null, Date | null]>(() => { \n if (pendingStart.value && !pendingEnd.value && hoverDate.value) { \n const s = pendingStart.value; \n const h = hoverDate.value; \n return h < s ? [h, s] : [s, h]; \n } \n return [pendingStart.value, pendingEnd.value]; \n}); \n \nconst isDateDisabled = (date: Date) => { \n if (props.minDate && date < startOfDay(props.minDate)) return true; \n if (props.maxDate && date > startOfDay(props.maxDate)) return true; \n if (props.disabledDates?.some(d => isSameDay(d, date))) return true; \n if (props.maxRange && pendingStart.value && !pendingEnd.value) { \n if (inclusiveDaysBetween(pendingStart.value, date) > props.maxRange) return true; \n } \n return false; \n}; \n \nconst buildPanel = (month: number, year: number): Panel => { \n const days: CalendarDay[] = []; \n const firstOfMonth = new Date(year, month, 1); \n const lastOfMonth = new Date(year, month + 1, 0); \n const [rangeStart, rangeEnd] = currentRange.value; \n \n let startDow = firstOfMonth.getDay() - props.firstDayOfWeek; \n if (startDow < 0) startDow += 7; \n \n const build = (date: Date, isOutside: boolean): CalendarDay => { \n const inRange = !!(rangeStart && rangeEnd && \n startOfDay(date).getTime() >= startOfDay(rangeStart).getTime() && \n startOfDay(date).getTime() <= startOfDay(rangeEnd).getTime()); \n return { \n date, \n day: date.getDate(), \n isToday: isSameDay(date, today), \n isSelected: false, \n isOutside, \n disabled: isDateDisabled(date), \n inRange, \n isRangeStart: !!rangeStart && isSameDay(date, rangeStart), \n isRangeEnd: !!rangeEnd && isSameDay(date, rangeEnd), \n }; \n }; \n \n for (let i = startDow - 1; i >= 0; i--) { \n const date = new Date(year, month, -i); \n days.push(build(date, true)); \n } \n for (let d = 1; d <= lastOfMonth.getDate(); d++) { \n days.push(build(new Date(year, month, d), false)); \n } \n const targetLength = Math.ceil(days.length / 7) * 7 < 42 ? 42 : Math.ceil(days.length / 7) * 7; \n let nextDay = 1; \n while (days.length < targetLength) { \n days.push(build(new Date(year, month + 1, nextDay++), true)); \n } \n \n return { month, year, days }; \n}; \n \nconst panels = computed<Panel[]>(() => { \n const result: Panel[] = []; \n for (let i = 0; i < props.months; i++) { \n const m = (baseMonth.value + i) % 12; \n const y = baseYear.value + Math.floor((baseMonth.value + i) / 12); \n result.push(buildPanel(m, y)); \n } \n return result; \n}); \n \nconst shiftMonth = (delta: number) => { \n let m = baseMonth.value + delta; \n let y = baseYear.value; \n while (m < 0) { m += 12; y--; } \n while (m > 11) { m -= 12; y++; } \n baseMonth.value = m; \n baseYear.value = y; \n}; \n \nconst shiftYear = (delta: number) => { \n baseYear.value += delta; \n}; \n \nconst animateShift = (direction: 'left' | 'right', action: () => void): Promise<void> => { \n return new Promise((resolve) => { \n const grids = gridRefs.value.filter((g): g is HTMLElement => !!g); \n if (grids.length === 0 || isAnimating.value) { \n action(); \n resolve(); \n return; \n } \n isAnimating.value = true; \n const from = direction === 'left' ? -20 : 20; \n const to = direction === 'left' ? 20 : -20; \n \n gsap.to(grids, { \n x: to, \n opacity: 0, \n duration: 0.15, \n ease: 'power2.in', \n onComplete: () => { \n action(); \n nextTick(() => { \n const newGrids = gridRefs.value.filter((g): g is HTMLElement => !!g); \n gsap.fromTo( \n newGrids, \n { x: from, opacity: 0 }, \n { \n x: 0, opacity: 1, duration: 0.2, ease: 'power2.out', \n onComplete: () => { isAnimating.value = false; resolve(); }, \n } \n ); \n }); \n }, \n }); \n }); \n}; \n \nconst MS_PER_DAY = 86400000; \nconst inclusiveDaysBetween = (a: Date, b: Date) => \n Math.abs(Math.round((startOfDay(b).getTime() - startOfDay(a).getTime()) / MS_PER_DAY)) + 1; \n \nconst handleDayClick = (date: Date) => { \n if (!pendingStart.value || (pendingStart.value && pendingEnd.value)) { \n pendingStart.value = date; \n pendingEnd.value = null; \n emit('update:modelValue', [date, null]); \n return; \n } \n let start = pendingStart.value; \n let end = date; \n if (end < start) [start, end] = [end, start]; \n \n if (props.minRange && inclusiveDaysBetween(start, end) < props.minRange) { \n pendingStart.value = date; \n pendingEnd.value = null; \n emit('update:modelValue', [date, null]); \n return; \n } \n \n pendingStart.value = start; \n pendingEnd.value = end; \n emit('update:modelValue', [start, end]); \n emit('rangeComplete', [start, end]); \n}; \n \nconst colorBg = computed(() => ({ \n default: 'bg-foreground text-background', \n primary: 'bg-primary text-primary-foreground', \n danger: 'bg-destructive text-destructive-foreground', \n success: 'bg-success text-success-foreground', \n warning: 'bg-warning text-warning-foreground', \n}[resolvedColor.value] ?? 'bg-primary text-primary-foreground')); \n \nconst rangeMiddleBgClass = computed(() => ({ \n default: 'bg-muted', \n primary: 'bg-primary-subtle', \n danger: 'bg-destructive-subtle', \n success: 'bg-success-subtle', \n warning: 'bg-warning-subtle', \n}[resolvedColor.value] ?? 'bg-primary-subtle')); \n \nconst activePresetClasses = computed(() => ({ \n default: 'bg-muted text-foreground font-medium', \n primary: 'bg-primary-subtle text-primary font-medium', \n danger: 'bg-destructive-subtle text-destructive font-medium', \n success: 'bg-success-subtle text-success font-medium', \n warning: 'bg-warning-subtle text-warning font-medium', \n}[resolvedColor.value] ?? 'bg-primary-subtle text-primary font-medium')); \n \nconst focusRingColorClass = computed(() => ({ \n default: 'focus-visible:ring-ring', \n primary: 'focus-visible:ring-primary', \n danger: 'focus-visible:ring-destructive', \n success: 'focus-visible:ring-success', \n warning: 'focus-visible:ring-warning', \n}[resolvedColor.value] ?? 'focus-visible:ring-primary')); \n \nconst containerRadiusClass = computed(() => ({ \n none: 'rounded-none', \n small: 'rounded-sm', \n medium: 'rounded-md', \n large: 'rounded-lg', \n full: 'rounded-xl', \n}[resolvedRadius.value] ?? 'rounded-lg')); \n \nconst dayRadiusClass = computed(() => ({ \n none: 'rounded-none', \n small: 'rounded-sm', \n medium: 'rounded-md', \n large: 'rounded-lg', \n full: 'rounded-full', \n}[resolvedRadius.value] ?? 'rounded-full')); \n \ntype BgSide = 'none' | 'full' | 'left' | 'right'; \nconst bgSide = (day: CalendarDay): BgSide => { \n if (day.disabled) return 'none'; \n const [rs, re] = currentRange.value; \n if (!rs || !re || isSameDay(rs, re)) return 'none'; \n if (day.isRangeStart) return 'right'; \n if (day.isRangeEnd) return 'left'; \n if (day.inRange) return 'full'; \n return 'none'; \n}; \n \nconst todayTextClass = computed(() => ({ \n default: 'text-foreground', \n primary: 'text-primary', \n danger: 'text-destructive', \n success: 'text-success', \n warning: 'text-warning', \n}[resolvedColor.value] ?? 'text-primary')); \n \nconst dayStateClasses = (day: CalendarDay): string => { \n if (day.disabled) return 'text-muted-foreground/60 cursor-not-allowed'; \n if (day.isRangeStart || day.isRangeEnd) { \n return `${colorBg.value} hover:opacity-90`; \n } \n if (day.isToday) { \n return `font-semibold ${todayTextClass.value} hover:bg-muted`; \n } \n if (day.isOutside) return 'text-muted-foreground/40 hover:bg-muted'; \n return 'text-foreground/80 hover:bg-muted'; \n}; \n</script>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"DateRangePicker.cjs","names":[],"sources":["../../../../src/components/data-display/date-picker/DateRangePicker.vue"],"sourcesContent":["<template> \n <div \n :class=\"['inline-flex flex-col sm:flex-row select-none bg-card w-fit max-w-full self-start', variant === 'outline' ? 'border border-border' : '', containerRadiusClass]\" \n role=\"application\" \n aria-label=\"Date range picker\" \n > \n <div \n v-if=\"showPresets\" \n class=\"flex flex-row sm:flex-col gap-2 sm:gap-1 p-3 border-b sm:border-b-0 sm:border-r border-border sm:min-w-35 overflow-x-auto sm:overflow-x-visible\" \n > \n <button \n v-for=\"preset in effectivePresets\" \n :key=\"preset.label\" \n type=\"button\" \n @click=\"applyPreset(preset)\" \n :class=\"[ \n 'text-left text-sm px-3 py-1.5 rounded-md transition-colors cursor-pointer focus:outline-none focus-visible:ring-2 shrink-0 whitespace-nowrap', \n focusRingColorClass, \n isActivePreset(preset) \n ? activePresetClasses \n : 'text-foreground/80 hover:bg-muted', \n ]\" \n > \n {{ preset.label }} \n </button> \n </div> \n \n <div class=\"flex flex-col sm:flex-row\"> \n <div \n v-for=\"(panel, idx) in panels\" \n :key=\"idx\" \n class=\"flex flex-col\" \n :class=\"idx > 0 ? 'border-t sm:border-t-0 sm:border-l border-border' : ''\" \n > \n <div class=\"flex items-center justify-between px-2 py-3\"> \n <div class=\"flex items-center gap-0.5\"> \n <Button \n v-if=\"idx === 0\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronDoubleLeftIcon\" \n :ariaLabel=\"loc.calendar.prevYear\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('right', () => shiftYear(-1))\" \n /> \n <Button \n v-if=\"idx === 0\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronLeftIcon\" \n :ariaLabel=\"loc.calendar.prevMonth\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('right', () => shiftMonth(-1))\" \n /> \n <div v-if=\"idx !== 0\" class=\"w-15\"></div> \n </div> \n \n <span class=\"text-sm font-semibold text-foreground\"> \n {{ formatMonthYear(panel.month, panel.year) }} \n </span> \n \n <div class=\"flex items-center gap-0.5\"> \n <Button \n v-if=\"idx === panels.length - 1\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronRightIcon\" \n :ariaLabel=\"loc.calendar.nextMonth\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('left', () => shiftMonth(1))\" \n /> \n <Button \n v-if=\"idx === panels.length - 1\" \n variant=\"text\" \n size=\"small\" \n radius=\"medium\" \n :icon=\"ChevronDoubleRightIcon\" \n :ariaLabel=\"loc.calendar.nextYear\" \n class=\"text-muted-foreground\" \n @click=\"animateShift('left', () => shiftYear(1))\" \n /> \n <div v-if=\"idx !== panels.length - 1\" class=\"w-15\"></div> \n </div> \n </div> \n \n <div class=\"grid grid-cols-7 px-2\"> \n <div \n v-for=\"dayLabel in weekDayLabels\" \n :key=\"dayLabel\" \n class=\"text-center text-xs font-medium text-muted-foreground py-2\" \n > \n {{ dayLabel }} \n </div> \n </div> \n \n <div class=\"overflow-hidden px-2 pb-3\"> \n <div :ref=\"(el: unknown) => setGridRef(el as HTMLElement | null, idx)\" class=\"grid grid-cols-7\"> \n <div \n v-for=\"day in panel.days\" \n :key=\"day.date.getTime()\" \n class=\"relative flex items-center justify-center w-9 h-9\" \n > \n <span \n v-if=\"bgSide(day) === 'full'\" \n aria-hidden=\"true\" \n :class=\"['absolute inset-y-0 -inset-x-px pointer-events-none', rangeMiddleBgClass]\" \n /> \n <span \n v-else-if=\"bgSide(day) === 'left'\" \n aria-hidden=\"true\" \n :class=\"['absolute inset-y-0 -left-px right-1/2 pointer-events-none', rangeMiddleBgClass]\" \n /> \n <span \n v-else-if=\"bgSide(day) === 'right'\" \n aria-hidden=\"true\" \n :class=\"['absolute inset-y-0 left-1/2 -right-px pointer-events-none', rangeMiddleBgClass]\" \n /> \n \n <button \n type=\"button\" \n :disabled=\"day.disabled\" \n :aria-label=\"day.date.toLocaleDateString(locale === 'default' ? undefined : locale)\" \n :aria-selected=\"day.isRangeStart || day.isRangeEnd\" \n @click=\"!day.disabled && handleDayClick(day.date)\" \n @mouseenter=\"!day.disabled && (hoverDate = day.date)\" \n @mouseleave=\"hoverDate = null\" \n :class=\"[ \n 'relative z-10 w-9 h-9 text-sm flex items-center justify-center transition-colors cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1', \n dayRadiusClass, \n focusRingColorClass, \n dayStateClasses(day), \n ]\" \n > \n {{ day.day }} \n </button> \n </div> \n </div> \n </div> \n </div> \n </div> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { ref, computed, nextTick } from 'vue'; \nimport { ChevronLeftIcon, ChevronRightIcon, ChevronDoubleLeftIcon, ChevronDoubleRightIcon } from '@heroicons/vue/24/outline'; \nimport Button from '../../forms/Button.vue'; \nimport gsap from 'gsap'; \nimport type { DateRangePicker, RangePreset } from '../../../interfaces/data-display/date-picker/DateRangePicker.interface'; \nimport { isSameDay, startOfDay, type CalendarDay } from '../../../composables/useCalendar'; \nimport { useResolvedColor, useResolvedRadius, useModoLocale } from '../../../composables/useModoConfig'; \n \nconst loc = useModoLocale(); \n \nconst props = withDefaults(defineProps<DateRangePicker>(), { \n modelValue: () => [null, null] as [Date | null, Date | null], \n locale: 'default', \n firstDayOfWeek: 0, \n color: 'default', \n variant: 'outline', \n months: 2, \n showPresets: true, \n}); \n \nconst resolvedColor = useResolvedColor(() => props.color); \nconst resolvedRadius = useResolvedRadius(() => props.radius); \n \nconst emit = defineEmits<{ \n 'update:modelValue': [range: [Date | null, Date | null]]; \n 'rangeComplete': [range: [Date, Date]]; \n}>(); \n \nconst gridRefs = ref<(HTMLElement | null)[]>([]); \nconst setGridRef = (el: HTMLElement | null, idx: number) => { gridRefs.value[idx] = el; }; \n \nconst today = new Date(); \n \nconst baseMonth = ref(props.modelValue[0]?.getMonth() ?? today.getMonth()); \nconst baseYear = ref(props.modelValue[0]?.getFullYear() ?? today.getFullYear()); \n \nconst pendingStart = ref<Date | null>(props.modelValue[0] ?? null); \nconst pendingEnd = ref<Date | null>(props.modelValue[1] ?? null); \nconst hoverDate = ref<Date | null>(null); \nconst isAnimating = ref(false); \n \nconst defaultPresets: RangePreset[] = [ \n { label: 'Today', range: () => [new Date(), new Date()] }, \n { label: 'Yesterday', range: () => { const d = new Date(); d.setDate(d.getDate() - 1); return [d, new Date(d)]; } }, \n { label: 'Last 7 days', range: () => { const s = new Date(); s.setDate(s.getDate() - 6); return [s, new Date()]; } }, \n { label: 'Last 30 days', range: () => { const s = new Date(); s.setDate(s.getDate() - 29); return [s, new Date()]; } }, \n { label: 'This month', range: () => { const now = new Date(); return [new Date(now.getFullYear(), now.getMonth(), 1), new Date(now.getFullYear(), now.getMonth() + 1, 0)]; } }, \n { label: 'Last month', range: () => { const now = new Date(); return [new Date(now.getFullYear(), now.getMonth() - 1, 1), new Date(now.getFullYear(), now.getMonth(), 0)]; } }, \n { label: 'This year', range: () => { const now = new Date(); return [new Date(now.getFullYear(), 0, 1), new Date(now.getFullYear(), 11, 31)]; } }, \n]; \n \nconst effectivePresets = computed(() => props.presets ?? defaultPresets); \n \nconst isActivePreset = (preset: RangePreset) => { \n if (!pendingStart.value || !pendingEnd.value) return false; \n const [s, e] = preset.range(); \n return isSameDay(s, pendingStart.value) && isSameDay(e, pendingEnd.value); \n}; \n \nconst applyPreset = (preset: RangePreset) => { \n const [s, e] = preset.range(); \n pendingStart.value = s; \n pendingEnd.value = e; \n baseMonth.value = s.getMonth(); \n baseYear.value = s.getFullYear(); \n emit('update:modelValue', [s, e]); \n emit('rangeComplete', [s, e]); \n}; \n \nconst locale = computed(() => props.locale === 'default' ? undefined : props.locale); \n \nconst formatMonthYear = (month: number, year: number) => { \n return new Date(year, month, 1).toLocaleString(locale.value, { month: 'long', year: 'numeric' }); \n}; \n \nconst weekDayLabels = computed(() => { \n const labels: string[] = []; \n const base = new Date(2024, 0, 7 + props.firstDayOfWeek); \n for (let i = 0; i < 7; i++) { \n const d = new Date(base); \n d.setDate(base.getDate() + i); \n labels.push(d.toLocaleString(locale.value, { weekday: 'short' }).slice(0, 2)); \n } \n return labels; \n}); \n \ninterface Panel { \n month: number; \n year: number; \n days: CalendarDay[]; \n} \n \nconst currentRange = computed<[Date | null, Date | null]>(() => { \n if (pendingStart.value && !pendingEnd.value && hoverDate.value) { \n const s = pendingStart.value; \n const h = hoverDate.value; \n return h < s ? [h, s] : [s, h]; \n } \n return [pendingStart.value, pendingEnd.value]; \n}); \n \nconst isDateDisabled = (date: Date) => { \n if (props.minDate && date < startOfDay(props.minDate)) return true; \n if (props.maxDate && date > startOfDay(props.maxDate)) return true; \n if (props.disabledDates?.some(d => isSameDay(d, date))) return true; \n if (props.maxRange && pendingStart.value && !pendingEnd.value) { \n if (inclusiveDaysBetween(pendingStart.value, date) > props.maxRange) return true; \n } \n return false; \n}; \n \nconst buildPanel = (month: number, year: number): Panel => { \n const days: CalendarDay[] = []; \n const firstOfMonth = new Date(year, month, 1); \n const lastOfMonth = new Date(year, month + 1, 0); \n const [rangeStart, rangeEnd] = currentRange.value; \n \n let startDow = firstOfMonth.getDay() - props.firstDayOfWeek; \n if (startDow < 0) startDow += 7; \n \n const build = (date: Date, isOutside: boolean): CalendarDay => { \n const inRange = !!(rangeStart && rangeEnd && \n startOfDay(date).getTime() >= startOfDay(rangeStart).getTime() && \n startOfDay(date).getTime() <= startOfDay(rangeEnd).getTime()); \n return { \n date, \n day: date.getDate(), \n isToday: isSameDay(date, today), \n isSelected: false, \n isOutside, \n disabled: isDateDisabled(date), \n inRange, \n isRangeStart: !!rangeStart && isSameDay(date, rangeStart), \n isRangeEnd: !!rangeEnd && isSameDay(date, rangeEnd), \n }; \n }; \n \n for (let i = startDow - 1; i >= 0; i--) { \n const date = new Date(year, month, -i); \n days.push(build(date, true)); \n } \n for (let d = 1; d <= lastOfMonth.getDate(); d++) { \n days.push(build(new Date(year, month, d), false)); \n } \n const targetLength = Math.ceil(days.length / 7) * 7 < 42 ? 42 : Math.ceil(days.length / 7) * 7; \n let nextDay = 1; \n while (days.length < targetLength) { \n days.push(build(new Date(year, month + 1, nextDay++), true)); \n } \n \n return { month, year, days }; \n}; \n \nconst panels = computed<Panel[]>(() => { \n const result: Panel[] = []; \n for (let i = 0; i < props.months; i++) { \n const m = (baseMonth.value + i) % 12; \n const y = baseYear.value + Math.floor((baseMonth.value + i) / 12); \n result.push(buildPanel(m, y)); \n } \n return result; \n}); \n \nconst shiftMonth = (delta: number) => { \n let m = baseMonth.value + delta; \n let y = baseYear.value; \n while (m < 0) { m += 12; y--; } \n while (m > 11) { m -= 12; y++; } \n baseMonth.value = m; \n baseYear.value = y; \n}; \n \nconst shiftYear = (delta: number) => { \n baseYear.value += delta; \n}; \n \nconst animateShift = (direction: 'left' | 'right', action: () => void): Promise<void> => { \n return new Promise((resolve) => { \n const grids = gridRefs.value.filter((g): g is HTMLElement => !!g); \n if (grids.length === 0 || isAnimating.value) { \n action(); \n resolve(); \n return; \n } \n isAnimating.value = true; \n const from = direction === 'left' ? -20 : 20; \n const to = direction === 'left' ? 20 : -20; \n \n gsap.to(grids, { \n x: to, \n opacity: 0, \n duration: 0.15, \n ease: 'power2.in', \n onComplete: () => { \n action(); \n nextTick(() => { \n const newGrids = gridRefs.value.filter((g): g is HTMLElement => !!g); \n gsap.fromTo( \n newGrids, \n { x: from, opacity: 0 }, \n { \n x: 0, opacity: 1, duration: 0.2, ease: 'power2.out', \n onComplete: () => { isAnimating.value = false; resolve(); }, \n } \n ); \n }); \n }, \n }); \n }); \n}; \n \nconst MS_PER_DAY = 86400000; \nconst inclusiveDaysBetween = (a: Date, b: Date) => \n Math.abs(Math.round((startOfDay(b).getTime() - startOfDay(a).getTime()) / MS_PER_DAY)) + 1; \n \nconst handleDayClick = (date: Date) => { \n if (!pendingStart.value || (pendingStart.value && pendingEnd.value)) { \n pendingStart.value = date; \n pendingEnd.value = null; \n emit('update:modelValue', [date, null]); \n return; \n } \n let start = pendingStart.value; \n let end = date; \n if (end < start) [start, end] = [end, start]; \n \n if (props.minRange && inclusiveDaysBetween(start, end) < props.minRange) { \n pendingStart.value = date; \n pendingEnd.value = null; \n emit('update:modelValue', [date, null]); \n return; \n } \n \n pendingStart.value = start; \n pendingEnd.value = end; \n emit('update:modelValue', [start, end]); \n emit('rangeComplete', [start, end]); \n}; \n \nconst colorBg = computed(() => ({ \n default: 'bg-foreground text-background', \n primary: 'bg-primary text-primary-foreground', \n danger: 'bg-destructive text-destructive-foreground', \n success: 'bg-success text-success-foreground', \n warning: 'bg-warning text-warning-foreground', \n}[resolvedColor.value] ?? 'bg-primary text-primary-foreground')); \n \nconst rangeMiddleBgClass = computed(() => ({ \n default: 'bg-muted', \n primary: 'bg-primary-subtle', \n danger: 'bg-destructive-subtle', \n success: 'bg-success-subtle', \n warning: 'bg-warning-subtle', \n}[resolvedColor.value] ?? 'bg-primary-subtle')); \n \nconst activePresetClasses = computed(() => ({ \n default: 'bg-muted text-foreground font-medium', \n primary: 'bg-primary-subtle text-primary font-medium', \n danger: 'bg-destructive-subtle text-destructive font-medium', \n success: 'bg-success-subtle text-success font-medium', \n warning: 'bg-warning-subtle text-warning font-medium', \n}[resolvedColor.value] ?? 'bg-primary-subtle text-primary font-medium')); \n \n// Unified focus ring across the system — colour-agnostic.\nconst focusRingColorClass = computed(() => 'focus-visible:ring-ring/60');\n \nconst containerRadiusClass = computed(() => ({ \n none: 'rounded-none', \n small: 'rounded-sm', \n medium: 'rounded-md', \n large: 'rounded-lg', \n full: 'rounded-xl', \n}[resolvedRadius.value] ?? 'rounded-lg')); \n \nconst dayRadiusClass = computed(() => ({ \n none: 'rounded-none', \n small: 'rounded-sm', \n medium: 'rounded-md', \n large: 'rounded-lg', \n full: 'rounded-full', \n}[resolvedRadius.value] ?? 'rounded-full')); \n \ntype BgSide = 'none' | 'full' | 'left' | 'right'; \nconst bgSide = (day: CalendarDay): BgSide => { \n if (day.disabled) return 'none'; \n const [rs, re] = currentRange.value; \n if (!rs || !re || isSameDay(rs, re)) return 'none'; \n if (day.isRangeStart) return 'right'; \n if (day.isRangeEnd) return 'left'; \n if (day.inRange) return 'full'; \n return 'none'; \n}; \n \nconst todayTextClass = computed(() => ({ \n default: 'text-foreground', \n primary: 'text-primary', \n danger: 'text-destructive', \n success: 'text-success', \n warning: 'text-warning', \n}[resolvedColor.value] ?? 'text-primary')); \n \nconst dayStateClasses = (day: CalendarDay): string => { \n if (day.disabled) return 'text-muted-foreground/60 cursor-not-allowed'; \n if (day.isRangeStart || day.isRangeEnd) { \n return `${colorBg.value} hover:opacity-90`; \n } \n if (day.isToday) { \n return `font-semibold ${todayTextClass.value} hover:bg-muted`; \n } \n if (day.isOutside) return 'text-muted-foreground/40 hover:bg-muted'; \n return 'text-foreground/80 hover:bg-muted'; \n}; \n</script>\n"],"mappings":""}
|