neba 1.13.0 → 1.16.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/README.md +22 -30
- package/dist/a2ui/catalog.json +1466 -0
- package/dist/a2ui/components.d.ts +21 -0
- package/dist/a2ui/components.js +1 -0
- package/dist/a2ui/index.d.ts +62 -0
- package/dist/a2ui/index.js +1 -0
- package/dist/a2ui/schema.d.ts +47 -0
- package/dist/a2ui/schema.js +1 -0
- package/dist/components/accordion/Accordion.d.ts +5 -1
- package/dist/components/accordion/Accordion.js +1 -1
- package/dist/components/agent-steps/AgentSteps.d.ts +80 -0
- package/dist/components/agent-steps/AgentSteps.js +1 -0
- package/dist/components/agent-steps/index.d.ts +2 -0
- package/dist/components/agent-steps/index.js +1 -0
- package/dist/components/alert/Alert.js +1 -1
- package/dist/components/anchor/Anchor.d.ts +3 -2
- package/dist/components/anchor/Anchor.js +1 -1
- package/dist/components/animate-appear/AnimateAppear.js +1 -1
- package/dist/components/animate-blink/AnimateBlink.d.ts +3 -0
- package/dist/components/animate-blink/AnimateBlink.js +1 -1
- package/dist/components/animate-counter/AnimateCounter.d.ts +3 -1
- package/dist/components/animate-counter/AnimateCounter.js +1 -1
- package/dist/components/animate-fade/AnimateFade.js +1 -1
- package/dist/components/animate-float/AnimateFloat.js +1 -1
- package/dist/components/animate-grow/AnimateGrow.js +1 -1
- package/dist/components/animate-headline/AnimateHeadline.d.ts +9 -2
- package/dist/components/animate-headline/AnimateHeadline.js +1 -1
- package/dist/components/animate-lighting/AnimateLighting.d.ts +1 -1
- package/dist/components/animate-lighting/AnimateLighting.js +1 -1
- package/dist/components/animate-marquee/AnimateMarquee.d.ts +15 -6
- package/dist/components/animate-marquee/AnimateMarquee.js +1 -1
- package/dist/components/animate-reveal/AnimateReveal.js +1 -1
- package/dist/components/animate-rotate/AnimateRotate.js +1 -1
- package/dist/components/animate-scramble/AnimateScramble.d.ts +5 -3
- package/dist/components/animate-scramble/AnimateScramble.js +1 -1
- package/dist/components/animate-shake/AnimateShake.js +1 -1
- package/dist/components/animate-slide/AnimateSlide.js +1 -1
- package/dist/components/animate-split/AnimateSplit.d.ts +3 -1
- package/dist/components/animate-split/AnimateSplit.js +1 -1
- package/dist/components/animate-typing/AnimateTyping.d.ts +12 -4
- package/dist/components/animate-typing/AnimateTyping.js +1 -1
- package/dist/components/animate-zoom/AnimateZoom.js +1 -1
- package/dist/components/app-logo/AppLogo.js +1 -1
- package/dist/components/approval/Approval.d.ts +115 -0
- package/dist/components/approval/Approval.js +1 -0
- package/dist/components/approval/index.d.ts +2 -0
- package/dist/components/approval/index.js +1 -0
- package/dist/components/area-chart/AreaChart.d.ts +16 -5
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/aspect-ratio/AspectRatio.d.ts +6 -4
- package/dist/components/aspect-ratio/AspectRatio.js +1 -1
- package/dist/components/avatar/Avatar.js +1 -1
- package/dist/components/badge/Badge.js +1 -1
- package/dist/components/bar-chart/BarChart.d.ts +1 -1
- package/dist/components/bar-chart/BarChart.js +1 -1
- package/dist/components/blockquote/Blockquote.js +1 -1
- package/dist/components/bottom-navigation/BottomNavigation.d.ts +2 -1
- package/dist/components/bottom-navigation/BottomNavigation.js +1 -1
- package/dist/components/box/Box.d.ts +5 -0
- package/dist/components/box/Box.js +1 -1
- package/dist/components/breadcrumb/Breadcrumb.d.ts +10 -0
- package/dist/components/breadcrumb/Breadcrumb.js +1 -1
- package/dist/components/button/Button.d.ts +11 -0
- package/dist/components/button/Button.js +1 -1
- package/dist/components/button-group/ButtonGroup.js +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/card/Card.js +1 -1
- package/dist/components/carousel/Carousel.d.ts +4 -0
- package/dist/components/carousel/Carousel.js +1 -1
- package/dist/components/chat-bubble/ChatBubble.js +1 -1
- package/dist/components/checkbox/Checkbox.js +1 -1
- package/dist/components/chip/Chip.d.ts +3 -1
- package/dist/components/chip/Chip.js +1 -1
- package/dist/components/code-block/CodeBlock.d.ts +6 -3
- package/dist/components/code-block/CodeBlock.js +1 -1
- package/dist/components/collapsible/Collapsible.d.ts +11 -1
- package/dist/components/collapsible/Collapsible.js +1 -1
- package/dist/components/color-picker/ColorPicker.js +1 -1
- package/dist/components/combobox/Combobox.d.ts +11 -1
- package/dist/components/combobox/Combobox.js +1 -1
- package/dist/components/command-palette/CommandPalette.js +1 -1
- package/dist/components/confirm/Confirm.js +1 -1
- package/dist/components/container/Container.js +1 -1
- package/dist/components/context-window/ContextWindow.d.ts +103 -0
- package/dist/components/context-window/ContextWindow.js +1 -0
- package/dist/components/context-window/index.d.ts +2 -0
- package/dist/components/context-window/index.js +1 -0
- package/dist/components/data-list/DataList.js +1 -1
- package/dist/components/data-table/DataTable.d.ts +12 -1
- package/dist/components/data-table/DataTable.js +1 -1
- package/dist/components/date-picker/DatePicker.js +1 -1
- package/dist/components/date-range-picker/DateRangePicker.js +1 -1
- package/dist/components/date-time-picker/DateTimePicker.js +1 -1
- package/dist/components/dialog/Dialog.d.ts +12 -0
- package/dist/components/dialog/Dialog.js +1 -1
- package/dist/components/divider/Divider.js +1 -1
- package/dist/components/drawer/Drawer.d.ts +7 -0
- package/dist/components/drawer/Drawer.js +1 -1
- package/dist/components/empty/Empty.js +1 -1
- package/dist/components/fieldset/Fieldset.js +1 -1
- package/dist/components/file-picker/FilePicker.d.ts +12 -4
- package/dist/components/file-picker/FilePicker.js +1 -1
- package/dist/components/flex/Flex.d.ts +8 -2
- package/dist/components/flex/Flex.js +1 -1
- package/dist/components/floating-action-button/FloatingActionButton.d.ts +16 -1
- package/dist/components/floating-action-button/FloatingActionButton.js +1 -1
- package/dist/components/floating-bottom-navigation/FloatingBottomNavigation.js +1 -1
- package/dist/components/footer/Footer.d.ts +8 -0
- package/dist/components/footer/Footer.js +1 -1
- package/dist/components/form/Form.d.ts +4 -2
- package/dist/components/form/Form.js +1 -1
- package/dist/components/gallery/Gallery.d.ts +56 -3
- package/dist/components/gallery/Gallery.js +1 -1
- package/dist/components/gallery/GalleryViewer.js +1 -1
- package/dist/components/gauge-chart/GaugeChart.d.ts +1 -1
- package/dist/components/gauge-chart/GaugeChart.js +1 -1
- package/dist/components/grid/Grid.js +1 -1
- package/dist/components/grid-container/GridContainer.js +1 -1
- package/dist/components/header/Header.js +1 -1
- package/dist/components/heatmap-chart/HeatmapChart.d.ts +20 -1
- package/dist/components/heatmap-chart/HeatmapChart.js +1 -1
- package/dist/components/highlight/Highlight.js +1 -1
- package/dist/components/how-to-steps/HowToSteps.d.ts +26 -1
- package/dist/components/how-to-steps/HowToSteps.js +1 -1
- package/dist/components/icon/Icon.js +1 -1
- package/dist/components/icon-button/IconButton.d.ts +0 -20
- package/dist/components/icon-button/IconButton.js +1 -1
- package/dist/components/image/Image.d.ts +137 -11
- package/dist/components/image/Image.js +1 -1
- package/dist/components/image/index.d.ts +1 -1
- package/dist/components/inline-citation/InlineCitation.d.ts +53 -0
- package/dist/components/inline-citation/InlineCitation.js +1 -0
- package/dist/components/inline-citation/index.d.ts +2 -0
- package/dist/components/inline-citation/index.js +1 -0
- package/dist/components/line-chart/LineChart.d.ts +16 -5
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/list/List.js +1 -1
- package/dist/components/menu/Menu.d.ts +25 -11
- package/dist/components/menu/Menu.js +1 -1
- package/dist/components/menubar/Menubar.js +1 -1
- package/dist/components/meter/Meter.d.ts +6 -0
- package/dist/components/meter/Meter.js +1 -1
- package/dist/components/mockup/Mockup.js +1 -1
- package/dist/components/navigation-menu/NavigationMenu.d.ts +10 -1
- package/dist/components/navigation-menu/NavigationMenu.js +1 -1
- package/dist/components/number-field/NumberField.d.ts +20 -6
- package/dist/components/number-field/NumberField.js +1 -1
- package/dist/components/otp-field/OtpField.d.ts +7 -0
- package/dist/components/otp-field/OtpField.js +1 -1
- package/dist/components/overlay/Overlay.d.ts +1 -1
- package/dist/components/overlay/Overlay.js +1 -1
- package/dist/components/page-layout/PageLayout.d.ts +11 -0
- package/dist/components/page-layout/PageLayout.js +1 -1
- package/dist/components/pagination/Pagination.js +1 -1
- package/dist/components/panes/Panes.d.ts +11 -0
- package/dist/components/panes/Panes.js +1 -1
- package/dist/components/pie-chart/PieChart.d.ts +34 -3
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/pill/Pill.d.ts +8 -0
- package/dist/components/pill/Pill.js +1 -1
- package/dist/components/popconfirm/Popconfirm.d.ts +10 -3
- package/dist/components/popconfirm/Popconfirm.js +1 -1
- package/dist/components/popover/Popover.d.ts +8 -1
- package/dist/components/popover/Popover.js +1 -1
- package/dist/components/portal/Portal.js +1 -1
- package/dist/components/progress-box/ProgressBox.js +1 -1
- package/dist/components/progress-circular/ProgressCircular.js +1 -1
- package/dist/components/progress-linear/ProgressLinear.js +1 -1
- package/dist/components/prompt-input/PromptInput.d.ts +104 -0
- package/dist/components/prompt-input/PromptInput.js +1 -0
- package/dist/components/prompt-input/index.d.ts +2 -0
- package/dist/components/prompt-input/index.js +1 -0
- package/dist/components/provider/NebaProvider.d.ts +3 -3
- package/dist/components/provider/NebaProvider.js +1 -1
- package/dist/components/radio-group/RadioGroup.js +1 -1
- package/dist/components/rating/Rating.d.ts +4 -1
- package/dist/components/rating/Rating.js +1 -1
- package/dist/components/reasoning/Reasoning.d.ts +78 -0
- package/dist/components/reasoning/Reasoning.js +1 -0
- package/dist/components/reasoning/index.d.ts +2 -0
- package/dist/components/reasoning/index.js +1 -0
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/scroll-area/ScrollArea.js +1 -1
- package/dist/components/scroll-zone/ScrollZone.d.ts +10 -0
- package/dist/components/scroll-zone/ScrollZone.js +1 -1
- package/dist/components/segmented-button/SegmentedButton.js +1 -1
- package/dist/components/select/Select.js +1 -1
- package/dist/components/shortcut/Shortcut.js +1 -1
- package/dist/components/show/Show.d.ts +6 -5
- package/dist/components/show/Show.js +1 -1
- package/dist/components/sidebar/Sidebar.d.ts +7 -5
- package/dist/components/sidebar/Sidebar.js +1 -1
- package/dist/components/sidebar/SidebarTrigger.js +1 -1
- package/dist/components/skeleton/Skeleton.d.ts +1 -1
- package/dist/components/skeleton/Skeleton.js +1 -1
- package/dist/components/slider/Slider.d.ts +13 -1
- package/dist/components/slider/Slider.js +1 -1
- package/dist/components/sources/Sources.d.ts +78 -0
- package/dist/components/sources/Sources.js +1 -0
- package/dist/components/sources/index.d.ts +2 -0
- package/dist/components/sources/index.js +1 -0
- package/dist/components/sparkline/Sparkline.d.ts +14 -1
- package/dist/components/sparkline/Sparkline.js +1 -1
- package/dist/components/spoiler/Spoiler.js +1 -1
- package/dist/components/stack/Stack.d.ts +2 -2
- package/dist/components/stack/Stack.js +1 -1
- package/dist/components/statistic/Statistic.js +1 -1
- package/dist/components/streaming-text/StreamingText.d.ts +75 -0
- package/dist/components/streaming-text/StreamingText.js +1 -0
- package/dist/components/streaming-text/index.d.ts +2 -0
- package/dist/components/streaming-text/index.js +1 -0
- package/dist/components/switch/Switch.js +1 -1
- package/dist/components/table/Table.d.ts +8 -2
- package/dist/components/table/Table.js +1 -1
- package/dist/components/tabs/Tabs.d.ts +17 -1
- package/dist/components/tabs/Tabs.js +1 -1
- package/dist/components/text-field/TextField.js +1 -1
- package/dist/components/text-link/TextLink.js +1 -1
- package/dist/components/time-picker/TimePicker.js +1 -1
- package/dist/components/timeline/Timeline.d.ts +8 -0
- package/dist/components/timeline/Timeline.js +1 -1
- package/dist/components/timeline-chart/TimelineChart.js +1 -1
- package/dist/components/toast/Toast.d.ts +9 -3
- package/dist/components/toast/Toast.js +1 -1
- package/dist/components/toggle/Toggle.js +1 -1
- package/dist/components/toggle-group/ToggleGroup.js +1 -1
- package/dist/components/tool-call/ToolCall.d.ts +104 -0
- package/dist/components/tool-call/ToolCall.js +1 -0
- package/dist/components/tool-call/index.d.ts +2 -0
- package/dist/components/tool-call/index.js +1 -0
- package/dist/components/toolbar/Toolbar.d.ts +8 -0
- package/dist/components/toolbar/Toolbar.js +1 -1
- package/dist/components/tooltip/Tooltip.js +1 -1
- package/dist/components/tour/Tour.d.ts +2 -0
- package/dist/components/tour/Tour.js +1 -1
- package/dist/components/transfer/Transfer.js +1 -1
- package/dist/components/tree-select/TreeSelect.js +1 -1
- package/dist/components/tree-view/TreeView.d.ts +6 -0
- package/dist/components/tree-view/TreeView.js +1 -1
- package/dist/components/typography/Typography.js +1 -1
- package/dist/components/visually-hidden/VisuallyHidden.d.ts +9 -7
- package/dist/components/visually-hidden/VisuallyHidden.js +1 -1
- package/dist/components/window-pane/WindowPane.d.ts +2 -2
- package/dist/components/window-pane/WindowPane.js +1 -1
- package/dist/hooks/useElementSize.d.ts +3 -1
- package/dist/hooks/useElementSize.js +1 -1
- package/dist/hooks/useOnScreen.d.ts +3 -0
- package/dist/hooks/useOnScreen.js +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -1
- package/dist/internal/animate.d.ts +63 -16
- package/dist/internal/animate.js +1 -1
- package/dist/internal/calendar.d.ts +6 -1
- package/dist/internal/calendar.js +1 -1
- package/dist/internal/chart-brush.d.ts +53 -0
- package/dist/internal/chart-brush.js +1 -0
- package/dist/internal/chart-frame.d.ts +186 -30
- package/dist/internal/chart-frame.js +1 -1
- package/dist/internal/chart-line.js +1 -1
- package/dist/internal/chart.d.ts +133 -6
- package/dist/internal/chart.js +1 -1
- package/dist/internal/children.d.ts +15 -0
- package/dist/internal/children.js +1 -0
- package/dist/internal/color.d.ts +4 -0
- package/dist/internal/color.js +1 -1
- package/dist/internal/csv.d.ts +12 -1
- package/dist/internal/csv.js +1 -1
- package/dist/internal/data-table.d.ts +28 -10
- package/dist/internal/data-table.js +1 -1
- package/dist/internal/date.d.ts +12 -5
- package/dist/internal/date.js +1 -1
- package/dist/internal/defaults.d.ts +6 -1
- package/dist/internal/defaults.js +1 -1
- package/dist/internal/drag.d.ts +13 -1
- package/dist/internal/drag.js +1 -1
- package/dist/internal/drop.d.ts +61 -0
- package/dist/internal/drop.js +1 -0
- package/dist/internal/fieldset.d.ts +13 -0
- package/dist/internal/fieldset.js +1 -0
- package/dist/internal/glow.d.ts +102 -0
- package/dist/internal/glow.js +1 -0
- package/dist/internal/highlight.js +1 -1
- package/dist/internal/i18n.d.ts +232 -11
- package/dist/internal/i18n.js +1 -1
- package/dist/internal/icons.d.ts +13 -2
- package/dist/internal/icons.js +1 -1
- package/dist/internal/inert.d.ts +13 -0
- package/dist/internal/inert.js +1 -0
- package/dist/internal/initials.d.ts +8 -3
- package/dist/internal/initials.js +1 -1
- package/dist/internal/keys.d.ts +13 -0
- package/dist/internal/keys.js +1 -1
- package/dist/internal/link.d.ts +13 -15
- package/dist/internal/link.js +1 -1
- package/dist/internal/media.d.ts +9 -17
- package/dist/internal/media.js +1 -1
- package/dist/internal/menu.d.ts +6 -1
- package/dist/internal/mockup.d.ts +5 -4
- package/dist/internal/mockup.js +1 -1
- package/dist/internal/observe.d.ts +12 -0
- package/dist/internal/observe.js +1 -1
- package/dist/internal/page-layout.d.ts +10 -8
- package/dist/internal/page-layout.js +1 -1
- package/dist/internal/picker.d.ts +1 -1
- package/dist/internal/picker.js +1 -1
- package/dist/internal/progress.d.ts +11 -5
- package/dist/internal/progress.js +1 -1
- package/dist/internal/responsive.d.ts +0 -8
- package/dist/internal/responsive.js +1 -1
- package/dist/internal/run.d.ts +71 -0
- package/dist/internal/run.js +1 -0
- package/dist/internal/screen.d.ts +12 -0
- package/dist/internal/screen.js +1 -0
- package/dist/internal/styles.d.ts +185 -14
- package/dist/internal/styles.js +1 -1
- package/dist/internal/text.d.ts +3 -3
- package/dist/internal/text.js +1 -1
- package/dist/internal/window.js +1 -1
- package/dist/locales/ar.js +1 -1
- package/dist/locales/de.js +1 -1
- package/dist/locales/es.js +1 -1
- package/dist/locales/fr.js +1 -1
- package/dist/locales/hi.js +1 -1
- package/dist/locales/id.js +1 -1
- package/dist/locales/it.js +1 -1
- package/dist/locales/ja.js +1 -1
- package/dist/locales/ko.js +1 -1
- package/dist/locales/nl.js +1 -1
- package/dist/locales/pl.js +1 -1
- package/dist/locales/pt.js +1 -1
- package/dist/locales/ru.js +1 -1
- package/dist/locales/th.js +1 -1
- package/dist/locales/tr.js +1 -1
- package/dist/locales/vi.js +1 -1
- package/dist/locales/zh-hans.js +1 -1
- package/dist/locales/zh-hant.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/tailwind.css +516 -53
- package/dist/types.d.ts +167 -7
- package/dist/types.js +0 -8
- package/package.json +43 -9
package/dist/internal/chart.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* makes.
|
|
17
17
|
*/
|
|
18
18
|
import type * as React from 'react';
|
|
19
|
-
import type { NebaChartCategory, NebaChartDatum, NebaChartSeries, NebaDensity, NebaSize } from '../types.js';
|
|
19
|
+
import type { NebaChartCategory, NebaChartDatum, NebaChartSeries, NebaChartValueLabels, NebaDensity, NebaSize } from '../types.js';
|
|
20
20
|
/**
|
|
21
21
|
* How tall a plot is when nobody said, in pixels.
|
|
22
22
|
*
|
|
@@ -76,6 +76,38 @@ export declare const markGap = 2;
|
|
|
76
76
|
export declare const barRadius = 4;
|
|
77
77
|
/** The eight slots, as the `var()`s that resolve them per theme. */
|
|
78
78
|
export declare const chartPalette: readonly string[];
|
|
79
|
+
/**
|
|
80
|
+
* The ink a label wears inside a mark of this colour.
|
|
81
|
+
*
|
|
82
|
+
* A palette slot has its answer in `styles.css`, per theme, where the slot's own
|
|
83
|
+
* lightness is known. A literal colour is decided here, black or white by
|
|
84
|
+
* contrast, because a caller's yellow slice is exactly where a fixed white
|
|
85
|
+
* label disappears. A `var()` or a family this cannot read keeps the surface
|
|
86
|
+
* ink, which is what the slots were solved against.
|
|
87
|
+
*/
|
|
88
|
+
export declare function inkOn(explicit: string | undefined, index: number): string;
|
|
89
|
+
/**
|
|
90
|
+
* The ink a value label wears when it is written *beside* its own mark.
|
|
91
|
+
*
|
|
92
|
+
* Not the mark's colour as it stands. A slot in the ramp is solved to be a
|
|
93
|
+
* **line** — at least 3:1 against the surface, which a 2px stroke needs and a
|
|
94
|
+
* twelve-pixel number does not; every slot lands near 4:1 on white, and normal
|
|
95
|
+
* text has to clear 4.5. So the colour is taken one step toward the page's own
|
|
96
|
+
* ink, which is the same recipe `--neba-*-on-tint` uses for text in a family's
|
|
97
|
+
* colour: 85% is as far as the hue survives and as little as the contrast
|
|
98
|
+
* needs. Measured per slot, both themes, worst case 4.97:1 on white and 6.38:1
|
|
99
|
+
* on the dark sheet.
|
|
100
|
+
*
|
|
101
|
+
* The point of colouring it at all is the one thing an axis and a tooltip
|
|
102
|
+
* cannot do: on a plot with four lines on it, a number floating above a point
|
|
103
|
+
* belongs to whichever line it is nearest, and "nearest" is exactly what a
|
|
104
|
+
* reader cannot judge where two series cross. The hue says which.
|
|
105
|
+
*
|
|
106
|
+
* A caller's own `series.color` goes through the same mix, so a pale brand
|
|
107
|
+
* yellow is legible as a label without the caller having to pick a second
|
|
108
|
+
* colour for the text.
|
|
109
|
+
*/
|
|
110
|
+
export declare function labelInk(color: string): string;
|
|
79
111
|
/** A `NebaColor` resolves to its readable-on-surface accent; anything else is CSS. */
|
|
80
112
|
export declare function resolveColor(value: string): string;
|
|
81
113
|
/**
|
|
@@ -92,6 +124,17 @@ export declare function resolveColor(value: string): string;
|
|
|
92
124
|
* "Other" series, or draw a second chart.
|
|
93
125
|
*/
|
|
94
126
|
export declare function seriesColor(series: Pick<NebaChartSeries, 'color'> | undefined, index: number, palette?: readonly string[]): string;
|
|
127
|
+
/**
|
|
128
|
+
* Says so, once per count, when a chart is given more series than the palette
|
|
129
|
+
* has slots.
|
|
130
|
+
*
|
|
131
|
+
* The slots are handed out by index and repeat past the eighth, and the docs
|
|
132
|
+
* used to say they never did. Nothing in the picture tells a reader that the
|
|
133
|
+
* ninth line is not the first one again, so the one who can act on it — the
|
|
134
|
+
* developer — is told in the console instead, and a production build says
|
|
135
|
+
* nothing.
|
|
136
|
+
*/
|
|
137
|
+
export declare function warnPaletteOverflow(count: number): void;
|
|
95
138
|
/** A datum unpacked into the shape the drawing code reads. */
|
|
96
139
|
export interface ChartValue {
|
|
97
140
|
value: number | null;
|
|
@@ -100,6 +143,18 @@ export interface ChartValue {
|
|
|
100
143
|
color?: string;
|
|
101
144
|
label?: React.ReactNode;
|
|
102
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Every category renormalised to a hundred, for `stacked="full"`.
|
|
148
|
+
*
|
|
149
|
+
* A change to the data rather than to the drawing, so the axis, the marks and
|
|
150
|
+
* the table all read shares. Two things make it the frame's job rather than
|
|
151
|
+
* each chart's. The total counts only the series still shown, because hiding
|
|
152
|
+
* one in the legend has to leave the rest filling the band rather than a gap
|
|
153
|
+
* where it was. And the number the caller passed survives as the point's label,
|
|
154
|
+
* written through the chart's own `format` and locale, because a chart stacked
|
|
155
|
+
* to full that can only say percentages has thrown the data away.
|
|
156
|
+
*/
|
|
157
|
+
export declare function toFullShares(values: readonly (readonly ChartValue[])[], visible: readonly boolean[], format: (value: number) => string): ChartValue[][];
|
|
103
158
|
/**
|
|
104
159
|
* One datum, whichever of the three ways it was written.
|
|
105
160
|
*
|
|
@@ -111,6 +166,22 @@ export interface ChartValue {
|
|
|
111
166
|
export declare function toValue(datum: NebaChartDatum): ChartValue;
|
|
112
167
|
/** Every series unpacked, in the order it was given. */
|
|
113
168
|
export declare function toValues(series: readonly NebaChartSeries[]): ChartValue[][];
|
|
169
|
+
/**
|
|
170
|
+
* The same series with every gap read as a nought.
|
|
171
|
+
*
|
|
172
|
+
* Done to the **data** and not to the drawing, which is the whole reason it is
|
|
173
|
+
* a function over `NebaChartSeries` rather than three lines inside the mark
|
|
174
|
+
* builder. A line pulled down to the baseline while the tooltip at that
|
|
175
|
+
* category still says nothing, and the axis still ranges as though the month
|
|
176
|
+
* were not there, is a chart that disagrees with itself — and the table under
|
|
177
|
+
* it is the version a screen reader gets. Rewriting the series once, before the
|
|
178
|
+
* frame has unpacked it, is what keeps the picture, the scale, the tooltip, the
|
|
179
|
+
* summary and the table saying one thing.
|
|
180
|
+
*
|
|
181
|
+
* A non-finite number is a gap too, for the reason `toValue` says so: a `NaN`
|
|
182
|
+
* that reached a chart is a division nobody checked, not a reading.
|
|
183
|
+
*/
|
|
184
|
+
export declare function zeroGaps(series: readonly NebaChartSeries[]): NebaChartSeries[];
|
|
114
185
|
/**
|
|
115
186
|
* A category as a number, for a category axis that is really a value axis.
|
|
116
187
|
*
|
|
@@ -232,8 +303,13 @@ export declare function timeScale(extent: {
|
|
|
232
303
|
max?: number;
|
|
233
304
|
tickCount?: number;
|
|
234
305
|
}): TimeScale;
|
|
235
|
-
/**
|
|
236
|
-
|
|
306
|
+
/**
|
|
307
|
+
* One instant on a time axis, written unambiguously — for a tooltip or a table.
|
|
308
|
+
*
|
|
309
|
+
* `clock` adds the hour and the minute to a unit that has none, for a date
|
|
310
|
+
* whose time of day is part of what it says.
|
|
311
|
+
*/
|
|
312
|
+
export declare function formatTimeValue(value: number, unit: TimeUnit, locale?: string, clock?: boolean): string;
|
|
237
313
|
/**
|
|
238
314
|
* A whole axis of ticks, written the way an axis is read.
|
|
239
315
|
*
|
|
@@ -254,8 +330,11 @@ export declare function formatTimeTicks(ticks: readonly number[], unit: TimeUnit
|
|
|
254
330
|
* How many ticks a category axis can show before the labels collide, and which
|
|
255
331
|
* ones they are.
|
|
256
332
|
*
|
|
257
|
-
* Every nth label rather than
|
|
258
|
-
* glance and it steals a band of the plot to be unreadable in.
|
|
333
|
+
* Every nth label by default rather than turning them: a turned axis is
|
|
334
|
+
* unreadable at a glance and it steals a band of the plot to be unreadable in.
|
|
335
|
+
* `xAxis.tickAngle` is how a caller says the names matter more than the shape
|
|
336
|
+
* does, and then the width passed in here is the one a *turned* label needs,
|
|
337
|
+
* which no longer depends on how long the name is. Either way `n` is chosen so
|
|
259
338
|
* the labels clear each other at the measured width, and it always keeps the
|
|
260
339
|
* first — a reader who cannot see where the axis starts cannot read any of it.
|
|
261
340
|
*/
|
|
@@ -294,6 +373,41 @@ export declare function fitsLast(count: number, stride: number, step: number, la
|
|
|
294
373
|
* anything CJK is close to a full em, so the widest character decides.
|
|
295
374
|
*/
|
|
296
375
|
export declare function textWidth(text: string, fontSize: number): number;
|
|
376
|
+
/**
|
|
377
|
+
* What an axis' labels measure, once they have been turned by `tickAngle`.
|
|
378
|
+
*
|
|
379
|
+
* Six numbers off one angle, and they are here rather than in the component
|
|
380
|
+
* that needed them first for `internal/`'s usual reason: a Cartesian chart's
|
|
381
|
+
* category axis and a HeatmapChart's column axis both turn their labels, and
|
|
382
|
+
* two copies of this trigonometry is two charts on one dashboard disagreeing
|
|
383
|
+
* about how deep a band of turned names runs.
|
|
384
|
+
*
|
|
385
|
+
* The one that carries the idea is **`room`**. Flat, a label needs its own
|
|
386
|
+
* width along the axis, so a long name means fewer labels. Turned, two
|
|
387
|
+
* neighbours only have to clear each other *across* the text — `fontSize /
|
|
388
|
+
* sin` — which no longer depends on how long the name is, and that is the
|
|
389
|
+
* whole reason turning them fits more of them in.
|
|
390
|
+
*
|
|
391
|
+
* `angle` is clamped to a quarter turn either way, past which a label is
|
|
392
|
+
* upside down.
|
|
393
|
+
*/
|
|
394
|
+
export interface TurnedAxis {
|
|
395
|
+
/** The clamped angle. `0` is flat, and every number below answers to it. */
|
|
396
|
+
angle: number;
|
|
397
|
+
/** How deep the band of labels runs, for a widest label of `widest` pixels. */
|
|
398
|
+
depth: (widest: number) => number;
|
|
399
|
+
/** How much of the axis one label takes, so two of them clear. */
|
|
400
|
+
room: (widest: number) => number;
|
|
401
|
+
/** The widest a label may render before the band runs past `depth` pixels. */
|
|
402
|
+
cut: (depth: number) => number;
|
|
403
|
+
/** How far below the axis a label is pinned. */
|
|
404
|
+
offset: number;
|
|
405
|
+
/** How far a label hangs past its own tick, along the axis. */
|
|
406
|
+
overhang: (widest: number) => number;
|
|
407
|
+
/** Which end of the label sits on the tick, which follows the turn. */
|
|
408
|
+
anchor: 'start' | 'middle' | 'end';
|
|
409
|
+
}
|
|
410
|
+
export declare function turnedAxis(angle: number | undefined, fontSize: number): TurnedAxis;
|
|
297
411
|
/**
|
|
298
412
|
* A label cut to the room it has, with an ellipsis.
|
|
299
413
|
*
|
|
@@ -373,7 +487,7 @@ export declare function barPath(x: number, y: number, width: number, height: num
|
|
|
373
487
|
* dot can be anything. Five is enough for every palette a chart is allowed.
|
|
374
488
|
*/
|
|
375
489
|
export type MarkShape = 'circle' | 'square' | 'triangle' | 'diamond' | 'cross';
|
|
376
|
-
/** The order shapes are handed out in, matching the palette: fixed,
|
|
490
|
+
/** The order shapes are handed out in, matching the palette: fixed, and repeated past the end as the colours are. */
|
|
377
491
|
export declare const markShapes: readonly MarkShape[];
|
|
378
492
|
/**
|
|
379
493
|
* One point mark, as a path, centred on `cx`/`cy` and covering the same area a
|
|
@@ -454,6 +568,19 @@ export interface TreemapTile {
|
|
|
454
568
|
* tile's colour and its name are still its own.
|
|
455
569
|
*/
|
|
456
570
|
export declare function squarify(values: readonly number[], width: number, height: number): TreemapTile[];
|
|
571
|
+
/**
|
|
572
|
+
* Which points of a series get a label, decided once for the whole series.
|
|
573
|
+
*
|
|
574
|
+
* Once and not per point, which is the only thing worth saying about it: asking
|
|
575
|
+
* "is this the series' high" inside the loop over the points means walking the
|
|
576
|
+
* series again for each of them, and a five-hundred-point line then does a
|
|
577
|
+
* quarter of a million comparisons to place two labels — on every render, which
|
|
578
|
+
* on a chart being hovered is every frame. A line and a bar ask the same
|
|
579
|
+
* question, which is why it lives here rather than with either of them.
|
|
580
|
+
*/
|
|
581
|
+
export declare function labelledPoints(one: readonly {
|
|
582
|
+
value: number | null;
|
|
583
|
+
}[], valueLabels: NebaChartValueLabels): (index: number) => boolean;
|
|
457
584
|
/**
|
|
458
585
|
* How a category is written when nobody said.
|
|
459
586
|
*
|
package/dist/internal/chart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dateFormatter as t,numberFormatter as e}from"./format.js";export const plotHeights={xs:120,sm:160,md:220,lg:280,xl:360};export const sparklineHeights={xs:16,sm:20,md:28,lg:40,xl:56};export const lineWidths={xs:1.5,sm:1.75,md:2,lg:2.25,xl:2.5};export const markerRadii={xs:3,sm:3.5,md:4,lg:4.5,xl:5};export const chartFontSizes={xs:10,sm:11,md:12,lg:13,xl:14};export const barMaxThickness={xs:14,sm:18,md:24,lg:30,xl:36};export const barBandRatio={default:.62,compact:.82};export const markGap=2;export const barRadius=4;export const chartPalette=["var(--neba-chart-1)","var(--neba-chart-2)","var(--neba-chart-3)","var(--neba-chart-4)","var(--neba-chart-5)","var(--neba-chart-6)","var(--neba-chart-7)","var(--neba-chart-8)"];const n=new Set(["primary","secondary","success","warning","danger","info"]);export function resolveColor(t){return n.has(t)?`var(--neba-${t}-accent)`:t}export function seriesColor(t,e,n=chartPalette){return resolveColor(t?.color?t.color:n[e%n.length]??chartPalette[0])}export function toValue(t){return null==t?{value:null}:"number"==typeof t?{value:Number.isFinite(t)?t:null}:(t=>"object"==typeof t&&null!==t)(t)?{value:null!==t.y&&Number.isFinite(t.y)?t.y:null,x:t.x,z:t.z,color:t.color?resolveColor(t.color):void 0,label:t.label}:{value:null}}export function toValues(t){return t.map(t=>t.data.map(toValue))}export function toNumber(t){return t instanceof Date?Number.isFinite(t.getTime())?t.getTime():null:"number"==typeof t&&Number.isFinite(t)?t:null}export function pointX(t,e,n){return toNumber(t.x??n?.[e]??e)}export function categoryExtent(t,e){let n=1/0,r=-1/0,o=!1;return t.forEach(t=>{t.forEach((t,a)=>{if(null===t.value)return;const i=pointX(t,a,e);null!==i&&(o=!0,n=Math.min(n,i),r=Math.max(r,i))})}),o?{min:n,max:r}:null}export function bubbleRadius(t,e,n,r){return e>0&&Number.isFinite(t)&&!(t<=0)?Math.max(r,Math.sqrt(Math.min(t,e)/e)*n):0===t?0:r}export function categoryCount(t){return t.reduce((t,e)=>Math.max(t,e.data.length),0)}export function categoryAt(t,e,n){if(e&&t<e.length)return e[t];for(const e of n){const n=e[t]?.x;if(void 0!==n)return n}return t}export function extentOf(t,e){let n=1/0,r=-1/0,o=!1;if(e){const e=t.reduce((t,e)=>Math.max(t,e.length),0);for(let a=0;a<e;a++){let e=0,i=0;for(const n of t){const t=n[a]?.value;null!=t&&(o=!0,t>=0?e+=t:i+=t)}n=Math.min(n,i),r=Math.max(r,e)}}else for(const e of t)for(const{value:t}of e)null!==t&&(o=!0,n=Math.min(n,t),r=Math.max(r,t));return o?{min:n,max:r}:null}function r(t){const e=10**Math.floor(Math.log10(t)),n=t/e;return n<=1?e:n<=2?2*e:n<=5?5*e:10*e}export function valueScale(t,e={}){const{tickCount:n=5,includeZero:o=!0}=e;let a=e.min??(t?t.min:0),i=e.max??(t?t.max:1);if(o&&void 0===e.min&&(a=Math.min(a,0)),o&&void 0===e.max&&(i=Math.max(i,0)),i===a){const t=Math.abs(i)>0?.5*Math.abs(i):1;a-=t,i+=t}const u=void 0!==e.min&&void 0!==e.max?function(t,e){const n=10**Math.floor(Math.log10(t/Math.max(1,e)));let o=r(t/Math.max(1,e)),a=1/0;for(const r of[.1,1,10])for(const i of[1,2,2.5,5]){const u=i*r*n,s=t/u,c=Math.round(s);if(c<1||Math.abs(s-c)>1e-9)continue;const h=Math.abs(c-e);h<a&&(a=h,o=u)}return o}(i-a,n):r((i-a)/Math.max(1,n)),s=void 0!==e.min?a:Math.floor(a/u)*u,c=void 0!==e.max?i:Math.ceil(i/u)*u,h=c-s||1,l=[];for(let t=s;t<=c+1e-9*u;t+=u)l.push(Number(t.toFixed(12)));return{min:s,max:c,ticks:l,fraction:t=>(t-s)/h}}const o=1e3,a=6e4,i=36e5,u=24*i,s=[{unit:"second",count:1,size:o},{unit:"second",count:5,size:5e3},{unit:"second",count:15,size:15e3},{unit:"second",count:30,size:3e4},{unit:"minute",count:1,size:a},{unit:"minute",count:5,size:3e5},{unit:"minute",count:15,size:9e5},{unit:"minute",count:30,size:18e5},{unit:"hour",count:1,size:i},{unit:"hour",count:3,size:3*i},{unit:"hour",count:6,size:6*i},{unit:"hour",count:12,size:12*i},{unit:"day",count:1,size:u},{unit:"day",count:2,size:2*u},{unit:"week",count:1,size:7*u},{unit:"week",count:2,size:14*u},{unit:"month",count:1,size:30*u},{unit:"quarter",count:1,size:91*u},{unit:"month",count:6,size:182*u},{unit:"year",count:1,size:365*u}];function c(t,e,n){const r=new Date(t);if("year"===e)r.setFullYear(r.getFullYear()+n);else if("quarter"===e)r.setMonth(r.getMonth()+3*n);else if("month"===e)r.setMonth(r.getMonth()+n);else if("week"===e)r.setDate(r.getDate()+7*n);else if("day"===e)r.setDate(r.getDate()+n);else{if("hour"!==e)return t+n*("minute"===e?a:o);r.setHours(r.getHours()+n)}return r.getTime()}const h={second:"minute",minute:"hour",hour:"day",day:"month",week:"week",month:"year",quarter:"year",year:"year"};function l(t,e,n){let r=function(t,e){const n=new Date(t);if("year"===e)return new Date(n.getFullYear(),0,1).getTime();if("quarter"===e)return new Date(n.getFullYear(),3*Math.floor(n.getMonth()/3),1).getTime();if("month"===e)return new Date(n.getFullYear(),n.getMonth(),1).getTime();if("week"===e){const t=new Date(n.getFullYear(),n.getMonth(),n.getDate());return t.setDate(t.getDate()-t.getDay()),t.getTime()}return"day"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime():"hour"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()).getTime():"minute"===e?Math.floor(t/a)*a:Math.floor(t/o)*o}(t,h[e]);if("year"===e&&n>1){const t=new Date(r).getFullYear();r=new Date(t-(t%n+n)%n,0,1).getTime()}for(let o=0;o<500;o++){const o=c(r,e,n);if(o>t)return r;r=o}return r}export function timeScale(t,e={}){const{tickCount:n=6}=e;let o=e.min??t?.min??Date.parse("2000-01-01T00:00:00"),a=e.max??t?.max??o+u;a<=o&&(o-=u/2,a+=u/2);const i=a-o;let h=s[0],m=1/0;for(const t of s){const e=Math.abs(i/t.size-n);e<m&&(m=e,h=t)}const $=h.unit,f="year"===$?Math.max(1,Math.round(r(i/n/(365*u)))):h.count,x=e.min??l(o,$,f),M=[];let p=x;for(let t=0;t<500&&(M.push(p),!(p>a));t++)p=c(p,$,f);const g=e.max??M[M.length-1],d=g-x||1;return{min:x,max:g,ticks:M.filter(t=>t>=x&&t<=g),unit:$,step:f,fraction:t=>(t-x)/d}}function m(t,e){if("second"===t)return{hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"};if("minute"===t||"hour"===t)return{hour:"2-digit",minute:"2-digit",hourCycle:"h23"};if("year"===t)return{year:"numeric"};const n="month"===t||"quarter"===t?{month:"short"}:{month:"short",day:"numeric"};return e?{...n,year:"numeric"}:n}export function formatTimeValue(e,n,r){return t(r,m(n,!0)).format(new Date(e))}export function formatTimeTicks(e,n,r){const o=new Set(e.map(t=>new Date(t).getFullYear())).size>1;return e.map((e,a)=>t(r,m(n,o||0===a)).format(new Date(e)))}export function tickStride(t,e,n){if(t<=1||e<=0)return 1;const r=Math.max(1,Math.floor(e/Math.max(1,n)));return Math.max(1,Math.ceil(t/r))}export function showsTick(t,e,n,r){return t%n===0||r&&t===e-1}export function fitsLast(t,e,n,r){const o=(t-1)%e;return o>0&&o*n>=r+8}export function textWidth(t,e){let n=0;for(const e of t)n+=/[ᄀ-ᇿ⺀-가-豈-︰-﹏]/.test(e)?1:.6;return n*e}export function truncate(t,e,n){if(e<=0||textWidth(t,n)<=e)return t;const r=e-textWidth("…",n);let o="",a=0;for(const e of t){const t=a+textWidth(e,n);if(t>r)break;a=t,o+=e}return o.length>0?`${o.trimEnd()}…`:"…"}export function bandScale(t,e,n){const r=t>0?e/t:e;return{step:r,band:r*n,centre:t=>r*(t+.5)}}export function linePath(t,e){const n=[];let r=[];const o=()=>{if(0!==r.length){if(1===r.length)n.push(`M${r[0].x} ${r[0].y}h0`);else if("step"===e){n.push(`M${r[0].x} ${r[0].y}`);for(let t=1;t<r.length;t++){const e=(r[t-1].x+r[t].x)/2;n.push(`H${e}V${r[t].y}H${r[t].x}`)}}else if("smooth"===e)n.push(`M${r[0].x} ${r[0].y}`),n.push(function(t){const e=t.length,n=[];for(let r=0;r<e-1;r++){const e=t[r+1].x-t[r].x;n.push(0===e?0:(t[r+1].y-t[r].y)/e)}const r=[n[0]??0];for(let t=1;t<e-1;t++){const e=n[t-1],o=n[t];r.push(e*o<=0?0:2*e*o/(e+o))}r.push(n[e-2]??0);const o=[];for(let n=0;n<e-1;n++){const e=(t[n+1].x-t[n].x)/3;o.push(`C${t[n].x+e} ${t[n].y+r[n]*e} ${t[n+1].x-e} ${t[n+1].y-r[n+1]*e} ${t[n+1].x} ${t[n+1].y}`)}return o.join("")}(r));else{n.push(`M${r[0].x} ${r[0].y}`);for(let t=1;t<r.length;t++)n.push(`L${r[t].x} ${r[t].y}`)}r=[]}};for(const e of t)null===e?o():r.push(e);return o(),n.join("")}export function areaPath(t,e,n){const r=[];let o=0;const a=a=>{const i=t.slice(o,a).filter(Boolean);if(0===i.length)return;const u="number"==typeof e?i.map(t=>({x:t.x,y:e})).reverse():e.slice(o,a).filter(Boolean).reverse();if(0===u.length)return;const s=linePath(i,n),c=linePath(u,n).replace(/^M/,"L");r.push(`${s}${c}Z`)};for(let e=0;e<t.length;e++)null===t[e]&&(a(e),o=e+1);return a(t.length),r.join("")}export function barPath(t,e,n,r,o,a){const i=Math.max(0,Math.min(o,n/2,r/2));if(0===i||n<=0||r<=0)return`M${t} ${e}h${n}v${r}h${-n}Z`;const u=(t,e)=>`a${i} ${i} 0 0 1 ${t} ${e}`;return"up"===a?`M${t} ${e+r}V${e+i}${u(i,-i)}H${t+n-i}${u(i,i)}V${e+r}Z`:"down"===a?`M${t} ${e}H${t+n}V${e+r-i}${u(-i,i)}H${t+i}${u(-i,-i)}Z`:"right"===a?`M${t} ${e}H${t+n-i}${u(i,i)}V${e+r-i}${u(-i,i)}H${t}Z`:`M${t+n} ${e+r}H${t+i}${u(-i,-i)}V${e+i}${u(i,-i)}H${t+n}Z`}export const markShapes=["circle","square","triangle","diamond","cross"];const $={circle:1,square:.8862,triangle:1.5551,diamond:1.2533,cross:1.189};export function markPath(t,e,n,r){const o=Math.max(0,r)*$[t];if(0===o)return"";if("circle"===t)return`M${e-o} ${n}a${o} ${o} 0 1 0 ${2*o} 0a${o} ${o} 0 1 0 ${2*-o} 0Z`;if("square"===t)return`M${e-o} ${n-o}h${2*o}v${2*o}h${2*-o}Z`;if("diamond"===t)return`M${e} ${n-o}L${e+o} ${n}L${e} ${n+o}L${e-o} ${n}Z`;if("triangle"===t){return`M${[0,120,240].map(t=>{const r=(t-90)*Math.PI/180;return`${e+o*Math.cos(r)} ${n+o*Math.sin(r)}`}).join("L")}Z`}const a=o/3;return`M${e-a} ${n-o}h${2*a}v${o-a}h${o-a}v${2*a}h${-(o-a)}v${o-a}h${2*-a}v${-(o-a)}h${-(o-a)}v${2*-a}h${o-a}Z`}export function ringPath(t,e,n,r,o){const a=r=>{const o=(r-90)*Math.PI/180;return`${t+n*Math.cos(o)} ${e+n*Math.sin(o)}`};if(Math.abs(o-r)>=360){const t=r+180;return`M${a(r)}A${n} ${n} 0 1 1 ${a(t)}A${n} ${n} 0 1 1 ${a(r)}`}const i=Math.abs(o-r)>180?1:0;return`M${a(r)}A${n} ${n} 0 ${i} 1 ${a(o)}`}export function arcPath(t,e,n,r,o,a){const i=(n,r)=>{const o=(r-90)*Math.PI/180;return`${t+n*Math.cos(o)} ${e+n*Math.sin(o)}`};if(Math.abs(a-o)>=360){const t=o+180;return r>0?`M${i(n,o)}A${n} ${n} 0 1 1 ${i(n,t)}A${n} ${n} 0 1 1 ${i(n,o)}ZM${i(r,o)}A${r} ${r} 0 1 0 ${i(r,t)}A${r} ${r} 0 1 0 ${i(r,o)}Z`:`M${i(n,o)}A${n} ${n} 0 1 1 ${i(n,t)}A${n} ${n} 0 1 1 ${i(n,o)}Z`}const u=Math.abs(a-o)>180?1:0;return r<=0?`M${t} ${e}L${i(n,o)}A${n} ${n} 0 ${u} 1 ${i(n,a)}Z`:`M${i(n,o)}A${n} ${n} 0 ${u} 1 ${i(n,a)}L${i(r,a)}A${r} ${r} 0 ${u} 0 ${i(r,o)}Z`}export const rampSteps=5;export function rampStep(t,e,n,r,o=0){if("diverging"===r){const r=Math.max(Math.abs(n-o),Math.abs(o-e));if(!(r>0))return 2;const a=(t-o)/r;return Math.min(4,Math.max(0,2+Math.round(2*a)))}const a=n-e;return a>0?Math.min(4,Math.max(0,Math.floor((t-e)/a*5))):4}export function rampFill(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-${t+1})`}export function rampInk(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-on-${t+1})`}export function squarify(t,e,n){const r=t.reduce((t,e)=>t+Math.max(0,e),0);if(!(r>0)||e<=0||n<=0)return[];const o=e*n/r,a=t.map((t,e)=>({index:e,area:Math.max(0,t)*o})).filter(t=>t.area>0).sort((t,e)=>e.area-t.area),i=[];let u=0,s=0,c=e,h=n,l=[];const m=t=>{const e=Math.min(c,h),n=t.reduce((t,e)=>t+e.area,0);if(!(n>0&&e>0))return 1/0;const r=t[0].area,o=t[t.length-1].area;return Math.max(e*e*r/(n*n),n*n/(e*e*o))},$=()=>{const t=l.reduce((t,e)=>t+e.area,0),e=Math.min(c,h),n=e>0?t/e:0,r=c>=h;let o=0;for(const t of l){const e=n>0?t.area/n:0;i.push(r?{index:t.index,x:u,y:s+o,width:n,height:e}:{index:t.index,x:u+o,y:s,width:e,height:n}),o+=e}r?(u+=n,c-=n):(s+=n,h-=n),l=[]};for(const t of a)0===l.length||m([...l,t])<=m(l)||$(),l.push(t);return l.length>0&&$(),i}const f={month:"short",day:"numeric"},x={notation:"compact",maximumFractionDigits:1},M={maximumFractionDigits:2};export function formatCategory(e,n){return e instanceof Date?t(n,f).format(e):String(e)}export function compactNumber(t,n){return Math.abs(t)>=1e4?e(n,x).format(t):e(n,M).format(t)}
|
|
1
|
+
import{parseColor as t,readableInk as e}from"./color.js";import{dateFormatter as n,numberFormatter as r}from"./format.js";export const plotHeights={xs:120,sm:160,md:220,lg:280,xl:360};export const sparklineHeights={xs:16,sm:20,md:28,lg:40,xl:56};export const lineWidths={xs:1.5,sm:1.75,md:2,lg:2.25,xl:2.5};export const markerRadii={xs:3,sm:3.5,md:4,lg:4.5,xl:5};export const chartFontSizes={xs:10,sm:11,md:12,lg:13,xl:14};export const barMaxThickness={xs:14,sm:18,md:24,lg:30,xl:36};export const barBandRatio={default:.62,compact:.82};export const markGap=2;export const barRadius=4;export const chartPalette=["var(--neba-chart-1)","var(--neba-chart-2)","var(--neba-chart-3)","var(--neba-chart-4)","var(--neba-chart-5)","var(--neba-chart-6)","var(--neba-chart-7)","var(--neba-chart-8)"];export function inkOn(n,r){if(!n)return`var(--neba-chart-on-${r%chartPalette.length+1})`;const a=o.has(n)?null:t(n);return a?e(a.hsv):"var(--neba-surface)"}export function labelInk(t){return`color-mix(in oklab, ${t} 85%, var(--neba-fg))`}const o=new Set(["primary","secondary","success","warning","danger","info"]);export function resolveColor(t){return o.has(t)?`var(--neba-${t}-accent)`:t}export function seriesColor(t,e,n=chartPalette){return resolveColor(t?.color?t.color:n[e%n.length]??chartPalette[0])}const a=new Set;export function warnPaletteOverflow(t){"production"===process.env.NODE_ENV||t<=chartPalette.length||a.has(t)||(a.add(t),console.warn(`Neba: a chart was given ${t} series and its palette has ${chartPalette.length} colours, so the colours repeat from the ninth series. Fold the smallest into an "Other" series, or draw a second chart.`))}export function toFullShares(t,e,n){const r=[];return t.forEach((t,n)=>{!1!==e[n]&&t.forEach((t,e)=>{r[e]=(r[e]??0)+Math.abs(t.value??0)})}),t.map(t=>t.map((t,e)=>{if(null===t.value)return t;const o=r[e]??0;return{...t,value:0===o?0:t.value/o*100,label:t.label??n(t.value)}}))}export function toValue(t){return null==t?{value:null}:"number"==typeof t?{value:Number.isFinite(t)?t:null}:(t=>"object"==typeof t&&null!==t)(t)?{value:null!==t.y&&Number.isFinite(t.y)?t.y:null,x:t.x,z:t.z,color:t.color?resolveColor(t.color):void 0,label:t.label}:{value:null}}export function toValues(t){return t.map(t=>t.data.map(toValue))}export function zeroGaps(t){return t.map(t=>({...t,data:t.data.map(t=>null==t?0:"number"==typeof t?Number.isFinite(t)?t:0:null!==t.y&&Number.isFinite(t.y)?t:{...t,y:0})}))}export function toNumber(t){return t instanceof Date?Number.isFinite(t.getTime())?t.getTime():null:"number"==typeof t&&Number.isFinite(t)?t:null}export function pointX(t,e,n){return toNumber(t.x??n?.[e]??e)}export function categoryExtent(t,e){let n=1/0,r=-1/0,o=!1;return t.forEach(t=>{t.forEach((t,a)=>{if(null===t.value)return;const i=pointX(t,a,e);null!==i&&(o=!0,n=Math.min(n,i),r=Math.max(r,i))})}),o?{min:n,max:r}:null}export function bubbleRadius(t,e,n,r){return e>0&&Number.isFinite(t)&&!(t<=0)?Math.max(r,Math.sqrt(Math.min(t,e)/e)*n):0===t?0:r}export function categoryCount(t){return t.reduce((t,e)=>Math.max(t,e.data.length),0)}export function categoryAt(t,e,n){if(e&&t<e.length)return e[t];for(const e of n){const n=e[t]?.x;if(void 0!==n)return n}return t}export function extentOf(t,e){let n=1/0,r=-1/0,o=!1;if(e){const e=t.reduce((t,e)=>Math.max(t,e.length),0);for(let a=0;a<e;a++){let e=0,i=0;for(const n of t){const t=n[a]?.value;null!=t&&(o=!0,t>=0?e+=t:i+=t)}n=Math.min(n,i),r=Math.max(r,e)}}else for(const e of t)for(const{value:t}of e)null!==t&&(o=!0,n=Math.min(n,t),r=Math.max(r,t));return o?{min:n,max:r}:null}function i(t){const e=10**Math.floor(Math.log10(t)),n=t/e;return n<=1?e:n<=2?2*e:n<=5?5*e:10*e}export function valueScale(t,e={}){const{tickCount:n=5,includeZero:r=!0}=e;let o=e.min??(t?t.min:0),a=e.max??(t?t.max:1);r&&void 0===e.min&&(o=Math.min(o,0)),r&&void 0===e.max&&(a=Math.max(a,0));const u=void 0!==e.min&&void 0===e.max,s=void 0!==e.max&&void 0===e.min;if(a<=o&&(u||s)){const t=u?o:a,e=Math.abs(t)>0?Math.abs(t):2;u?a=o+e:o=a-e}else if(a===o){const t=Math.abs(a)>0?.5*Math.abs(a):1;o-=t,a+=t}const c=void 0!==e.min&&void 0!==e.max?function(t,e){const n=10**Math.floor(Math.log10(t/Math.max(1,e)));let r=i(t/Math.max(1,e)),o=1/0;for(const a of[.1,1,10])for(const i of[1,2,2.5,5]){const u=i*a*n,s=t/u,c=Math.round(s);if(c<1||Math.abs(s-c)>1e-9)continue;const l=Math.abs(c-e);l<o&&(o=l,r=u)}return r}(a-o,n):i((a-o)/Math.max(1,n)),l=void 0!==e.min?o:Math.floor(o/c)*c,h=void 0!==e.max?a:Math.ceil(a/c)*c,m=h-l||1,f=[];for(let t=l;t<=h+1e-9*c;t+=c)f.push(Number(t.toFixed(12)));return{min:l,max:h,ticks:f,fraction:t=>(t-l)/m}}const u=1e3,s=6e4,c=36e5,l=24*c,h=[{unit:"second",count:1,size:u},{unit:"second",count:5,size:5e3},{unit:"second",count:15,size:15e3},{unit:"second",count:30,size:3e4},{unit:"minute",count:1,size:s},{unit:"minute",count:5,size:3e5},{unit:"minute",count:15,size:9e5},{unit:"minute",count:30,size:18e5},{unit:"hour",count:1,size:c},{unit:"hour",count:3,size:3*c},{unit:"hour",count:6,size:6*c},{unit:"hour",count:12,size:12*c},{unit:"day",count:1,size:l},{unit:"day",count:2,size:2*l},{unit:"week",count:1,size:7*l},{unit:"week",count:2,size:14*l},{unit:"month",count:1,size:30*l},{unit:"quarter",count:1,size:91*l},{unit:"month",count:6,size:182*l},{unit:"year",count:1,size:365*l}];function m(t,e,n){const r=new Date(t);if("year"===e)r.setFullYear(r.getFullYear()+n);else if("quarter"===e)r.setMonth(r.getMonth()+3*n);else if("month"===e)r.setMonth(r.getMonth()+n);else if("week"===e)r.setDate(r.getDate()+7*n);else if("day"===e)r.setDate(r.getDate()+n);else{if("hour"!==e)return t+n*("minute"===e?s:u);r.setHours(r.getHours()+n)}return r.getTime()}const f={second:"minute",minute:"hour",hour:"day",day:"month",week:"week",month:"year",quarter:"year",year:"year"};function $(t,e,n){let r=function(t,e){const n=new Date(t);if("year"===e)return new Date(n.getFullYear(),0,1).getTime();if("quarter"===e)return new Date(n.getFullYear(),3*Math.floor(n.getMonth()/3),1).getTime();if("month"===e)return new Date(n.getFullYear(),n.getMonth(),1).getTime();if("week"===e){const t=new Date(n.getFullYear(),n.getMonth(),n.getDate());return t.setDate(t.getDate()-t.getDay()),t.getTime()}return"day"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime():"hour"===e?new Date(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours()).getTime():"minute"===e?Math.floor(t/s)*s:Math.floor(t/u)*u}(t,f[e]);if("year"===e&&n>1){const t=new Date(r).getFullYear();r=new Date(t-(t%n+n)%n,0,1).getTime()}for(let o=0;o<500;o++){const o=m(r,e,n);if(o>t)return r;r=o}return r}export function timeScale(t,e={}){const{tickCount:n=6}=e;let r=e.min??t?.min??Date.parse("2000-01-01T00:00:00"),o=e.max??t?.max??r+l;o<=r&&(r-=l/2,o+=l/2);const a=o-r;let u=h[0],s=1/0;for(const t of h){const e=Math.abs(a/t.size-n);e<s&&(s=e,u=t)}const c=u.unit,f="year"===c?Math.max(1,Math.round(i(a/n/(365*l)))):u.count,x=e.min??$(r,c,f),p=[];let M=$(r,c,f);for(let t=0;t<500&&(p.push(M),!(M>o));t++)M=m(M,c,f);const d=e.max??p[p.length-1],g=d-x||1;return{min:x,max:d,ticks:p.filter(t=>t>=x&&t<=d),unit:c,step:f,fraction:t=>(t-x)/g}}function x(t,e){if("second"===t)return{hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"};if("minute"===t||"hour"===t)return{hour:"2-digit",minute:"2-digit",hourCycle:"h23"};if("year"===t)return{year:"numeric"};const n="month"===t||"quarter"===t?{month:"short"}:{month:"short",day:"numeric"};return e?{...n,year:"numeric"}:n}export function formatTimeValue(t,e,r,o=!1){const a=x(e,!0);return n(r,o&&void 0===a.hour?{...a,hour:"2-digit",minute:"2-digit",hourCycle:"h23"}:a).format(new Date(t))}export function formatTimeTicks(t,e,r){const o=new Set(t.map(t=>new Date(t).getFullYear())).size>1;return t.map((t,a)=>n(r,x(e,o||0===a)).format(new Date(t)))}export function tickStride(t,e,n){if(t<=1||e<=0)return 1;const r=Math.max(1,Math.floor(e/Math.max(1,n)));return Math.max(1,Math.ceil(t/r))}export function showsTick(t,e,n,r){return t%n===0||r&&t===e-1}export function fitsLast(t,e,n,r){const o=(t-1)%e;return o>0&&o*n>=r+8}export function textWidth(t,e){let n=0;for(const e of t)n+=/[ᄀ-ᇿ⺀-가-豈-︰-﹏]/.test(e)?1:.6;return n*e}export function turnedAxis(t,e){const n=Math.max(-90,Math.min(90,t??0)),r=Math.abs(n)*(Math.PI/180),o=Math.sin(r),a=Math.cos(r);return 0===n?{angle:0,depth:()=>e,room:t=>Math.max(t,1)+12,cut:t=>t,offset:e+6,overhang:t=>t/2,anchor:"middle"}:{angle:n,depth:t=>t*o+e*a,room:()=>e/Math.max(.2,o)+4,cut:t=>Math.max(0,(t-e*a)/Math.max(.05,o)),offset:8+e/2*a,overhang:t=>t*a,anchor:n<0?"end":"start"}}export function truncate(t,e,n){if(e<=0||textWidth(t,n)<=e)return t;const r=e-textWidth("…",n);let o="",a=0;for(const e of t){const t=a+textWidth(e,n);if(t>r)break;a=t,o+=e}return o.length>0?`${o.trimEnd()}…`:"…"}export function bandScale(t,e,n){const r=t>0?e/t:e;return{step:r,band:r*n,centre:t=>r*(t+.5)}}export function linePath(t,e){const n=[];let r=[];const o=()=>{if(0!==r.length){if(1===r.length)n.push(`M${r[0].x} ${r[0].y}h0`);else if("step"===e){n.push(`M${r[0].x} ${r[0].y}`);for(let t=1;t<r.length;t++){const e=(r[t-1].x+r[t].x)/2;n.push(`H${e}V${r[t].y}H${r[t].x}`)}}else if("smooth"===e)n.push(`M${r[0].x} ${r[0].y}`),n.push(function(t){const e=t.length,n=[];for(let r=0;r<e-1;r++){const e=t[r+1].x-t[r].x;n.push(0===e?0:(t[r+1].y-t[r].y)/e)}const r=[n[0]??0];for(let t=1;t<e-1;t++){const e=n[t-1],o=n[t];r.push(e*o<=0?0:2*e*o/(e+o))}r.push(n[e-2]??0);const o=[];for(let n=0;n<e-1;n++){const e=(t[n+1].x-t[n].x)/3;o.push(`C${t[n].x+e} ${t[n].y+r[n]*e} ${t[n+1].x-e} ${t[n+1].y-r[n+1]*e} ${t[n+1].x} ${t[n+1].y}`)}return o.join("")}(r));else{n.push(`M${r[0].x} ${r[0].y}`);for(let t=1;t<r.length;t++)n.push(`L${r[t].x} ${r[t].y}`)}r=[]}};for(const e of t)null===e?o():r.push(e);return o(),n.join("")}export function areaPath(t,e,n){const r=[];let o=0;const a=a=>{const i=t.slice(o,a).filter(Boolean);if(0===i.length)return;const u="number"==typeof e?i.map(t=>({x:t.x,y:e})).reverse():e.slice(o,a).filter(Boolean).reverse();if(0===u.length)return;const s=linePath(i,n),c=linePath(u,n).replace(/^M/,"L");r.push(`${s}${c}Z`)};for(let e=0;e<t.length;e++)null===t[e]&&(a(e),o=e+1);return a(t.length),r.join("")}export function barPath(t,e,n,r,o,a){const i=Math.max(0,Math.min(o,n/2,r/2));if(0===i||n<=0||r<=0)return`M${t} ${e}h${n}v${r}h${-n}Z`;const u=(t,e)=>`a${i} ${i} 0 0 1 ${t} ${e}`;return"up"===a?`M${t} ${e+r}V${e+i}${u(i,-i)}H${t+n-i}${u(i,i)}V${e+r}Z`:"down"===a?`M${t} ${e}H${t+n}V${e+r-i}${u(-i,i)}H${t+i}${u(-i,-i)}Z`:"right"===a?`M${t} ${e}H${t+n-i}${u(i,i)}V${e+r-i}${u(-i,i)}H${t}Z`:`M${t+n} ${e+r}H${t+i}${u(-i,-i)}V${e+i}${u(i,-i)}H${t+n}Z`}export const markShapes=["circle","square","triangle","diamond","cross"];const p={circle:1,square:.8862,triangle:1.5551,diamond:1.2533,cross:1.189};export function markPath(t,e,n,r){const o=Math.max(0,r)*p[t];if(0===o)return"";if("circle"===t)return`M${e-o} ${n}a${o} ${o} 0 1 0 ${2*o} 0a${o} ${o} 0 1 0 ${2*-o} 0Z`;if("square"===t)return`M${e-o} ${n-o}h${2*o}v${2*o}h${2*-o}Z`;if("diamond"===t)return`M${e} ${n-o}L${e+o} ${n}L${e} ${n+o}L${e-o} ${n}Z`;if("triangle"===t){return`M${[0,120,240].map(t=>{const r=(t-90)*Math.PI/180;return`${e+o*Math.cos(r)} ${n+o*Math.sin(r)}`}).join("L")}Z`}const a=o/3;return`M${e-a} ${n-o}h${2*a}v${o-a}h${o-a}v${2*a}h${-(o-a)}v${o-a}h${2*-a}v${-(o-a)}h${-(o-a)}v${2*-a}h${o-a}Z`}export function ringPath(t,e,n,r,o){const a=r=>{const o=(r-90)*Math.PI/180;return`${t+n*Math.cos(o)} ${e+n*Math.sin(o)}`};if(Math.abs(o-r)>=360){const t=r+180;return`M${a(r)}A${n} ${n} 0 1 1 ${a(t)}A${n} ${n} 0 1 1 ${a(r)}`}const i=Math.abs(o-r)>180?1:0;return`M${a(r)}A${n} ${n} 0 ${i} 1 ${a(o)}`}export function arcPath(t,e,n,r,o,a){const i=(n,r)=>{const o=(r-90)*Math.PI/180;return`${t+n*Math.cos(o)} ${e+n*Math.sin(o)}`};if(Math.abs(a-o)>=360){const t=o+180;return r>0?`M${i(n,o)}A${n} ${n} 0 1 1 ${i(n,t)}A${n} ${n} 0 1 1 ${i(n,o)}ZM${i(r,o)}A${r} ${r} 0 1 0 ${i(r,t)}A${r} ${r} 0 1 0 ${i(r,o)}Z`:`M${i(n,o)}A${n} ${n} 0 1 1 ${i(n,t)}A${n} ${n} 0 1 1 ${i(n,o)}Z`}const u=Math.abs(a-o)>180?1:0;return r<=0?`M${t} ${e}L${i(n,o)}A${n} ${n} 0 ${u} 1 ${i(n,a)}Z`:`M${i(n,o)}A${n} ${n} 0 ${u} 1 ${i(n,a)}L${i(r,a)}A${r} ${r} 0 ${u} 0 ${i(r,o)}Z`}export const rampSteps=5;export function rampStep(t,e,n,r,o=0){if("diverging"===r){const r=Math.max(Math.abs(n-o),Math.abs(o-e));if(!(r>0))return 2;const a=(t-o)/r;return Math.min(4,Math.max(0,2+Math.round(2*a)))}const a=n-e;return a>0?Math.min(4,Math.max(0,Math.floor((t-e)/a*5))):t>0?4:0}export function rampFill(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-${t+1})`}export function rampInk(t,e){return`var(--neba-chart-${"diverging"===e?"div":"seq"}-on-${t+1})`}export function squarify(t,e,n){const r=t.reduce((t,e)=>t+Math.max(0,e),0);if(!(r>0)||e<=0||n<=0)return[];const o=e*n/r,a=t.map((t,e)=>({index:e,area:Math.max(0,t)*o})).filter(t=>t.area>0).sort((t,e)=>e.area-t.area),i=[];let u=0,s=0,c=e,l=n,h=[];const m=t=>{const e=Math.min(c,l),n=t.reduce((t,e)=>t+e.area,0);if(!(n>0&&e>0))return 1/0;const r=t[0].area,o=t[t.length-1].area;return Math.max(e*e*r/(n*n),n*n/(e*e*o))},f=()=>{const t=h.reduce((t,e)=>t+e.area,0),e=Math.min(c,l),n=e>0?t/e:0,r=c>=l;let o=0;for(const t of h){const e=n>0?t.area/n:0;i.push(r?{index:t.index,x:u,y:s+o,width:n,height:e}:{index:t.index,x:u+o,y:s,width:e,height:n}),o+=e}r?(u+=n,c-=n):(s+=n,l-=n),h=[]};for(const t of a)0===h.length||m([...h,t])<=m(h)||f(),h.push(t);return h.length>0&&f(),i}const M={month:"short",day:"numeric"},d={notation:"compact",maximumFractionDigits:1},g={maximumFractionDigits:2};export function labelledPoints(t,e){if("all"===e)return()=>!0;if("last"===e){let e=-1;for(let n=t.length-1;n>=0;n--)if(null!==t[n].value){e=n;break}return t=>t===e}let n=1/0,r=-1/0;for(const e of t)null!==e.value&&(n=Math.min(n,e.value),r=Math.max(r,e.value));return e=>{const o=t[e].value;return null!==o&&(o===n||o===r)}}export function formatCategory(t,e){return t instanceof Date?n(e,M).format(t):String(t)}export function compactNumber(t,e){return Math.abs(t)>=1e4?r(e,d).format(t):r(e,g).format(t)}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The key a wrapper drawn around one of a component's children should take.
|
|
4
|
+
*
|
|
5
|
+
* `Children.toArray` has already given every element a key — the caller's own
|
|
6
|
+
* where there was one, its position where there was not — so that is the key
|
|
7
|
+
* the wrapper takes too. Keying the wrapper by position instead throws the
|
|
8
|
+
* caller's key away: put a new child at the front and every wrapper after it is
|
|
9
|
+
* handed a different child, which React answers by mounting all of them again,
|
|
10
|
+
* with their state, their loaded images and their entrance animation.
|
|
11
|
+
*
|
|
12
|
+
* A string or a number has no key and keeps its position, which is all there
|
|
13
|
+
* is to go on.
|
|
14
|
+
*/
|
|
15
|
+
export declare function childKey(child: React.ReactNode, index: number): React.Key;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as e from"react";export function childKey(r,t){return e.isValidElement(r)&&null!==r.key?r.key:t}
|
package/dist/internal/color.d.ts
CHANGED
|
@@ -82,6 +82,10 @@ export declare function cssColor(hsv: Hsv, alpha?: number): string;
|
|
|
82
82
|
* is relative luminance rather than plain lightness, because the eye weighs
|
|
83
83
|
* green about six times as heavily as blue and a colour model that pretends
|
|
84
84
|
* otherwise puts the tick the wrong way round on both.
|
|
85
|
+
*
|
|
86
|
+
* Whichever ink contrasts more wins, which puts the crossover at a luminance of
|
|
87
|
+
* about 0.18 rather than halfway: a mid grey, an orange or a green reads 4:1 or
|
|
88
|
+
* better in black and under 3:1 in white.
|
|
85
89
|
*/
|
|
86
90
|
export declare function readableInk(hsv: Hsv): string;
|
|
87
91
|
/**
|
package/dist/internal/color.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function clamp(r,n,t){return r<n?n:r>t?t:r}function r(r){const n=r%360;return n<0?n+360:n}function n(r){return Math.round(r)}export function hsvToRgb({h:t,s:e,v:o}){const a=r(t)/60,s=clamp(e,0,100)/100,c=clamp(o,0,100)/100,
|
|
1
|
+
export function clamp(r,n,t){return r<n?n:r>t?t:r}function r(r){const n=r%360;return n<0?n+360:n}function n(r){return Math.round(r)}export function hsvToRgb({h:t,s:e,v:o}){const a=r(t)/60,s=clamp(e,0,100)/100,c=clamp(o,0,100)/100,u=c*s,g=u*(1-Math.abs(a%2-1)),l=c-u,b=Math.floor(a)%6,[i,f,h]=[[u,g,0],[g,u,0],[0,u,g],[0,g,u],[g,0,u],[u,0,g]][b];return{r:n(255*(i+l)),g:n(255*(f+l)),b:n(255*(h+l))}}export function rgbToHsv({r:n,g:t,b:e}){const o=clamp(n,0,255)/255,a=clamp(t,0,255)/255,s=clamp(e,0,255)/255,c=Math.max(o,a,s),u=c-Math.min(o,a,s);let g=0;return 0!==u&&(g=c===o?(a-s)/u%6:c===a?(s-o)/u+2:(o-a)/u+4),{h:r(60*g),s:0===c?0:u/c*100,v:100*c}}export function rgbToHsl({r:r,g:n,b:t}){const{h:e,s:o,v:a}=rgbToHsv({r:r,g:n,b:t}),s=a/100,c=s*(1-o/100/2),u=Math.min(c,1-c);return{h:e,s:0===u?0:(s-c)/u*100,l:100*c}}export function hslToRgb({h:r,s:n,l:t}){const e=clamp(t,0,100)/100,o=e+clamp(n,0,100)/100*Math.min(e,1-e);return hsvToRgb({h:r,s:0===o?0:2*(1-e/o)*100,v:100*o})}const t=/^#?([0-9a-f]{3,8})$/i;function e(r,n){return!0===(r.match(/-?[\d.]+%?/g)??[])[n]?.endsWith("%")}export function parseColor(r){const n=r.trim().toLowerCase();if(!n)return null;if(n.startsWith("#")||t.test(n))return function(r){const n=t.exec(r.trim());if(!n)return null;const e=n[1],o=3===e.length||4===e.length?[...e].map(r=>r+r).join(""):e;if(6!==o.length&&8!==o.length)return null;const a=r=>parseInt(o.slice(2*r,2*r+2),16);return{hsv:rgbToHsv({r:a(0),g:a(1),b:a(2)}),alpha:8===o.length?a(3)/255:1}}(n);const o=/^(rgba?|hsla?)\((.*)\)$/.exec(n);if(!o)return null;const[,a,s]=o,c=function(r){return(r.match(/-?[\d.]+%?/g)??[]).map(r=>parseFloat(r))}(s);if(c.length<3||c.some(Number.isNaN))return null;const u=function(r,n,t){return n.length<=t?1:clamp(e(r,t)?n[t]/100:n[t],0,1)}(s,c,3);if(a.startsWith("rgb")){const r=r=>e(s,r)?2.55*c[r]:c[r];return{hsv:rgbToHsv({r:r(0),g:r(1),b:r(2)}),alpha:u}}return{hsv:rgbToHsv(hslToRgb({h:c[0],s:c[1],l:c[2]})),alpha:u}}function o(r){return clamp(n(r),0,255).toString(16).padStart(2,"0")}export function rgbToHex({r:r,g:n,b:t},e=1){const a=`#${o(r)}${o(n)}${o(t)}`;return e>=1?a:`${a}${o(255*e)}`}function a(r){return String(Math.round(100*clamp(r,0,1))/100)}export function formatColor(r,t,e){const o=hsvToRgb(r);if("hex"===e)return rgbToHex(o,t);if("rgb"===e){const r=`${n(o.r)}, ${n(o.g)}, ${n(o.b)}`;return t>=1?`rgb(${r})`:`rgba(${r}, ${a(t)})`}const{h:s,s:c,l:u}=rgbToHsl(o),g=`${n(s)}, ${n(c)}%, ${n(u)}%`;return t>=1?`hsl(${g})`:`hsla(${g}, ${a(t)})`}export function cssColor(r,n=1){const{r:t,g:e,b:o}=hsvToRgb(r);return n>=1?`rgb(${t}, ${e}, ${o})`:`rgba(${t}, ${e}, ${o}, ${a(n)})`}export function readableInk(r){const{r:n,g:t,b:e}=hsvToRgb(r),o=r=>{const n=r/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4},a=.2126*o(n)+.7152*o(t)+.0722*o(e);return(a+.05)/.05>1.05/(a+.05)?"#000000":"#ffffff"}export const defaultSwatches=["#000000","#4b5563","#9ca3af","#ffffff","#ef4444","#f97316","#f59e0b","#84cc16","#22c55e","#14b8a6","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#d946ef","#ec4899"];export const checkerBackground={backgroundImage:"linear-gradient(45deg, var(--neba-border) 25%, transparent 25%), linear-gradient(-45deg, var(--neba-border) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--neba-border) 75%), linear-gradient(-45deg, transparent 75%, var(--neba-border) 75%)",backgroundSize:"8px 8px",backgroundPosition:"0 0, 0 4px, 4px -4px, -4px 0"};
|
package/dist/internal/csv.d.ts
CHANGED
|
@@ -13,8 +13,14 @@
|
|
|
13
13
|
* quote inside a quoted field is written twice. `null` and `undefined` are
|
|
14
14
|
* empty rather than the words "null" and "undefined", which is what `String()`
|
|
15
15
|
* would put in a spreadsheet cell.
|
|
16
|
+
*
|
|
17
|
+
* A string that starts with `=`, `+`, `-`, `@`, a tab or a carriage return gets a
|
|
18
|
+
* `'` in front unless `escapeFormulas` is off. Excel, Numbers and Sheets read
|
|
19
|
+
* such a cell as a formula, so a name a user typed as `=HYPERLINK(...)` would
|
|
20
|
+
* otherwise run on the machine of whoever opened the export. Only strings are
|
|
21
|
+
* touched: a negative number is a number and stays one.
|
|
16
22
|
*/
|
|
17
|
-
export declare function csvField(value: unknown, separator?: string): string;
|
|
23
|
+
export declare function csvField(value: unknown, separator?: string, escapeFormulas?: boolean): string;
|
|
18
24
|
export interface CsvOptions {
|
|
19
25
|
/** What goes between fields. `;` for the locales whose spreadsheets expect it. */
|
|
20
26
|
separator?: string;
|
|
@@ -26,6 +32,11 @@ export interface CsvOptions {
|
|
|
26
32
|
* mojibake. Every other reader ignores the mark.
|
|
27
33
|
*/
|
|
28
34
|
bom?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Puts a `'` in front of a text cell a spreadsheet would read as a formula.
|
|
37
|
+
* On by default; turn it off only for a file that is not opened in one.
|
|
38
|
+
*/
|
|
39
|
+
escapeFormulas?: boolean;
|
|
29
40
|
}
|
|
30
41
|
/** Rows of already-stringable values, as one CSV document. */
|
|
31
42
|
export declare function toCsv(rows: readonly (readonly unknown[])[], options?: CsvOptions): string;
|
package/dist/internal/csv.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function csvField(e,
|
|
1
|
+
export function csvField(e,t=",",n=!0){if(null==e)return"";const o=e instanceof Date?e.toISOString():"object"==typeof e?JSON.stringify(e):String(e),r=n&&"string"==typeof e&&/^[=+\-@\t\r]/.test(o)?`'${o}`:o;return/["\r\n]/.test(r)||r.includes(t)?`"${r.replaceAll('"','""')}"`:r}export function toCsv(e,t={}){const{separator:n=",",bom:o=!0,escapeFormulas:r=!0}=t,c=e.map(e=>e.map(e=>csvField(e,n,r)).join(n)).join("\r\n");return o?`\ufeff${c}`:c}export function downloadText(e,t,n){const o=URL.createObjectURL(new Blob([e],{type:n})),r=document.createElement("a");r.href=o,r.download=t,r.rel="noopener",r.style.display="none",document.body.append(r),r.click(),r.remove(),requestAnimationFrame(()=>URL.revokeObjectURL(o))}
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Here rather than in the component for the reason `progress.ts` and `color.ts`
|
|
5
5
|
* are here: none of it is layout and none of it is a class name. Sorting rows,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* cutting a page out of the result and working out which twenty of forty
|
|
7
|
+
* thousand rows are actually on screen are three questions with numeric
|
|
8
|
+
* answers, and a component file that also has to draw a resize handle is not
|
|
9
|
+
* where they can be read. Matching a query against the rows is `search.ts`,
|
|
10
|
+
* which three other components share.
|
|
10
11
|
*
|
|
11
12
|
* `color.ts` is the precedent for a single-consumer file: the test is whether
|
|
12
13
|
* the thing is separable, not whether two components happen to want it. Every
|
|
@@ -22,11 +23,11 @@ import type { NebaDensity, NebaSize } from '../types.js';
|
|
|
22
23
|
* offset lands, how tall the spacer above the first rendered row is, how many
|
|
23
24
|
* rows fit in the viewport for PageDown. A Tailwind class cannot be added up.
|
|
24
25
|
*
|
|
25
|
-
* The ladder
|
|
26
|
-
*
|
|
27
|
-
* screen and a Table is eight. A row here is the height of the text
|
|
28
|
-
* air to click, and nothing more; `density` is what takes the last
|
|
29
|
-
* out. A caller who puts a Chip or an Avatar in a cell raises `rowHeight`.
|
|
26
|
+
* The ladder stays at or below `controlHeightClasses` — a `md` row is a
|
|
27
|
+
* Button's 32px, and `compact` takes it to 28 — because a DataTable is a hundred
|
|
28
|
+
* rows on one screen and a Table is eight. A row here is the height of the text
|
|
29
|
+
* plus enough air to click, and nothing more; `density` is what takes the last
|
|
30
|
+
* of the air out. A caller who puts a Chip or an Avatar in a cell raises `rowHeight`.
|
|
30
31
|
*/
|
|
31
32
|
export declare const dataRowHeights: Record<NebaDensity, Record<NebaSize, number>>;
|
|
32
33
|
/**
|
|
@@ -67,6 +68,23 @@ export interface SortEntry {
|
|
|
67
68
|
* comes before `item10` rather than after it.
|
|
68
69
|
*/
|
|
69
70
|
export declare function compareValues(a: unknown, b: unknown, collator: Intl.Collator): number;
|
|
71
|
+
/**
|
|
72
|
+
* Whether a cell holds nothing to sort by.
|
|
73
|
+
*
|
|
74
|
+
* `NaN` is empty by another name: it compares false against everything, so left
|
|
75
|
+
* to a subtraction it would make the sort order depend on which rows happened to
|
|
76
|
+
* be next to each other.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isEmptyValue(value: unknown): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* How one key orders two rows: a comparison written ascending, and optionally
|
|
81
|
+
* which rows hold nothing for it. Rows that hold nothing go last whichever way
|
|
82
|
+
* the key runs, so they are kept out of the reversal a descending key applies.
|
|
83
|
+
*/
|
|
84
|
+
export type RowComparator<T> = ((a: T, b: T) => number) | {
|
|
85
|
+
compare: (a: T, b: T) => number;
|
|
86
|
+
isEmpty: (row: T) => boolean;
|
|
87
|
+
};
|
|
70
88
|
/**
|
|
71
89
|
* Sorts by every key at once, first key outermost.
|
|
72
90
|
*
|
|
@@ -79,7 +97,7 @@ export declare function compareValues(a: unknown, b: unknown, collator: Intl.Col
|
|
|
79
97
|
* over from a column that has since been removed is skipped rather than
|
|
80
98
|
* throwing.
|
|
81
99
|
*/
|
|
82
|
-
export declare function sortRows<T>(rows: readonly T[], sort: readonly SortEntry[], comparatorFor: (key: string) =>
|
|
100
|
+
export declare function sortRows<T>(rows: readonly T[], sort: readonly SortEntry[], comparatorFor: (key: string) => RowComparator<T> | null): T[];
|
|
83
101
|
/**
|
|
84
102
|
* What pressing a heading does, given what the sort already says.
|
|
85
103
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const dataRowHeights={default:{xs:24,sm:28,md:32,lg:38,xl:44},compact:{xs:20,sm:24,md:28,lg:32,xl:38}};export const dataHeaderHeights={default:{xs:28,sm:32,md:36,lg:42,xl:48},compact:{xs:24,sm:28,md:32,lg:36,xl:42}};export const dataTickWidths={xs:30,sm:34,md:38,lg:42,xl:50};export const defaultColumnWidth=160;export const minColumnWidth=48;export function compareValues(t,e,n){const o=
|
|
1
|
+
export const dataRowHeights={default:{xs:24,sm:28,md:32,lg:38,xl:44},compact:{xs:20,sm:24,md:28,lg:32,xl:38}};export const dataHeaderHeights={default:{xs:28,sm:32,md:36,lg:42,xl:48},compact:{xs:24,sm:28,md:32,lg:36,xl:42}};export const dataTickWidths={xs:30,sm:34,md:38,lg:42,xl:50};export const defaultColumnWidth=160;export const minColumnWidth=48;export function compareValues(t,e,n){const o=isEmptyValue(t),r=isEmptyValue(e);return o||r?o&&r?0:o?1:-1:"number"==typeof t&&"number"==typeof e?t-e:"boolean"==typeof t&&"boolean"==typeof e?Number(t)-Number(e):t instanceof Date&&e instanceof Date?t.getTime()-e.getTime():n.compare(String(t),String(e))}export function isEmptyValue(t){return null==t||""===t||"number"==typeof t&&Number.isNaN(t)}export function sortRows(t,e,n){if(0===e.length)return t;const o=e.map(t=>{const e=n(t.key);if(!e)return null;const o="desc"===t.direction?-1:1;return"function"==typeof e?{compare:e,isEmpty:null,sign:o}:{compare:e.compare,isEmpty:e.isEmpty,sign:o}}).filter(t=>null!==t);return 0===o.length?t:[...t].sort((t,e)=>{for(const n of o){if(n.isEmpty){const o=n.isEmpty(t);if(o!==n.isEmpty(e))return o?1:-1;if(o)continue}const o=n.compare(t,e);if(0!==o)return o*n.sign}return 0})}export function nextSort(t,e,n){const o=t.find(t=>t.key===e),r=void 0===o?"asc":"asc"===o.direction?"desc":null;return n?null===r?t.filter(t=>t.key!==e):void 0===o?[...t,{key:e,direction:r}]:t.map(t=>t.key===e?{key:e,direction:r}:t):null===r?[]:[{key:e,direction:r}]}export function pageBounds(t,e,n){const o=Math.max(1,Math.floor(n)),r=Math.max(1,Math.ceil(t/o)),i=Math.min(Math.max(Math.floor(e),1),r),a=(i-1)*o;return{pages:r,page:i,start:a,end:Math.min(a+o,t)}}export function virtualWindow(t,e,n,o,r){const i=e>0?Math.ceil(e/n):3*r,a=Math.min(Math.floor(t/n),Math.max(0,o-i)),s=Math.max(0,a-r),m=Math.min(o,s+i+2*r);return{start:s,end:m,before:s*n,after:Math.max(0,(o-m)*n)}}export function keysBetween(t,e,n){const o=t.indexOf(e),r=t.indexOf(n);return-1===o||-1===r?[]:t.slice(Math.min(o,r),Math.max(o,r)+1)}
|
package/dist/internal/date.d.ts
CHANGED
|
@@ -72,8 +72,6 @@ export declare function addYears(date: Date, amount: number): Date;
|
|
|
72
72
|
export declare function compareDay(a: Date, b: Date): number;
|
|
73
73
|
export declare function isSameDay(a: Date | null | undefined, b: Date | null | undefined): boolean;
|
|
74
74
|
export declare function isSameMonth(a: Date | null | undefined, b: Date | null | undefined): boolean;
|
|
75
|
-
/** Strictly between the two ends, both of which are optional. */
|
|
76
|
-
export declare function isDayInRange(date: Date, start: Date | null, end: Date | null): boolean;
|
|
77
75
|
/** Holds a date inside `[min, max]`, at whatever precision the bounds carry. */
|
|
78
76
|
export declare function clampDate(date: Date, min?: Date | null, max?: Date | null): Date;
|
|
79
77
|
/**
|
|
@@ -98,8 +96,6 @@ export declare function isDayOutside(date: Date, min?: Date | null, max?: Date |
|
|
|
98
96
|
* At `day` granularity this is `isDayOutside` exactly.
|
|
99
97
|
*/
|
|
100
98
|
export declare function isUnitOutside(date: Date, granularity: NebaDateGranularity, min?: Date | null, max?: Date | null): boolean;
|
|
101
|
-
/** Minutes since local midnight — what `minTime`/`maxTime` are compared on. */
|
|
102
|
-
export declare function minutesOfDay(date: Date): number;
|
|
103
99
|
/** Seconds since local midnight, for the pickers that show a seconds column. */
|
|
104
100
|
export declare function secondsOfDay(date: Date): number;
|
|
105
101
|
/** Which column of a clock a candidate time is being offered for. */
|
|
@@ -115,6 +111,16 @@ export type TimeUnit = 'hour' | 'minute' | 'second' | 'meridiem';
|
|
|
115
111
|
* candidate instead hides the 9 and makes half past nine unreachable.
|
|
116
112
|
*/
|
|
117
113
|
export declare function timeUnitSpan(unit: TimeUnit, at: Date): [number, number];
|
|
114
|
+
/**
|
|
115
|
+
* The same span as `timeUnitSpan`, as the two instants on `at`'s day.
|
|
116
|
+
*
|
|
117
|
+
* A picker comparing a row with a bound that carries a date has to leave seconds
|
|
118
|
+
* of the day behind, and the step that looks equivalent — midnight plus that
|
|
119
|
+
* many seconds — is an hour out on a day the clocks change, because that day is
|
|
120
|
+
* 23 or 25 hours long. Setting the clock fields lands on the wall-clock time the
|
|
121
|
+
* row is labelled with.
|
|
122
|
+
*/
|
|
123
|
+
export declare function timeUnitRange(unit: TimeUnit, at: Date): [Date, Date];
|
|
118
124
|
/** The same instant with one or more clock fields replaced. */
|
|
119
125
|
export declare function withTime(date: Date, parts: {
|
|
120
126
|
hours?: number;
|
|
@@ -140,7 +146,8 @@ export declare function yearPageStart(year: number): number;
|
|
|
140
146
|
export declare function formatDate(date: Date | null | undefined, locale: string | undefined, options: Intl.DateTimeFormatOptions): string;
|
|
141
147
|
/**
|
|
142
148
|
* Every distinct string those instants format to. Deduplicated, because a
|
|
143
|
-
* date-only format collapses
|
|
149
|
+
* date-only format collapses the samples into a handful. Built once per
|
|
150
|
+
* formatter, since a picker asks on every render.
|
|
144
151
|
*/
|
|
145
152
|
export declare function displaySamples(locale: string | undefined, options: Intl.DateTimeFormatOptions): string[];
|
|
146
153
|
/**
|
package/dist/internal/date.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memoise as t}from"./cache.js";import{dateFormatter as e}from"./format.js";export const YEAR_PAGE_SIZE=12;export function makeDate(t,e,r){const n=new Date(0);return n.setFullYear(t,e,r),n.setHours(0,0,0,0),n}export function isValidDate(t){return t instanceof Date&&!Number.isNaN(t.getTime())}export function startOfDay(t){const e=new Date(t.getTime());return e.setHours(0,0,0,0),e}export function startOfMonth(t){return makeDate(t.getFullYear(),t.getMonth(),1)}export function startOfYear(t){return makeDate(t.getFullYear(),0,1)}export function startOfUnit(t,e){return"year"===e?startOfYear(t):"month"===e?startOfMonth(t):startOfDay(t)}export function endOfUnit(t,e){const r=t.getFullYear();return"year"===e?makeDate(r,11,31):"month"===e?makeDate(r,t.getMonth(),daysInMonth(r,t.getMonth())):startOfDay(t)}export function daysInMonth(t,e){return makeDate(t,e+1,0).getDate()}export function today(){return startOfDay(new Date)}export function addDays(t,e){const r=new Date(t.getTime());return r.setDate(r.getDate()+e),r}export function addMonths(t,e){const r=t.getFullYear(),n=t.getMonth()+e,o=new Date(t.getTime()),a=makeDate(r,n,1);return o.setFullYear(a.getFullYear(),a.getMonth(),Math.min(t.getDate(),daysInMonth(a.getFullYear(),a.getMonth()))),o}export function addYears(t,e){return addMonths(t,12*e)}export function compareDay(t,e){return startOfDay(t).getTime()-startOfDay(e).getTime()}export function isSameDay(t,e){return isValidDate(t)&&isValidDate(e)&&0===compareDay(t,e)}export function isSameMonth(t,e){return isValidDate(t)&&isValidDate(e)&&t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()}export function
|
|
1
|
+
import{memoise as t}from"./cache.js";import{dateFormatter as e}from"./format.js";export const YEAR_PAGE_SIZE=12;export function makeDate(t,e,r){const n=new Date(0);return n.setFullYear(t,e,r),n.setHours(0,0,0,0),n}export function isValidDate(t){return t instanceof Date&&!Number.isNaN(t.getTime())}export function startOfDay(t){const e=new Date(t.getTime());return e.setHours(0,0,0,0),e}export function startOfMonth(t){return makeDate(t.getFullYear(),t.getMonth(),1)}export function startOfYear(t){return makeDate(t.getFullYear(),0,1)}export function startOfUnit(t,e){return"year"===e?startOfYear(t):"month"===e?startOfMonth(t):startOfDay(t)}export function endOfUnit(t,e){const r=t.getFullYear();return"year"===e?makeDate(r,11,31):"month"===e?makeDate(r,t.getMonth(),daysInMonth(r,t.getMonth())):startOfDay(t)}export function daysInMonth(t,e){return makeDate(t,e+1,0).getDate()}export function today(){return startOfDay(new Date)}export function addDays(t,e){const r=new Date(t.getTime());return r.setDate(r.getDate()+e),r}export function addMonths(t,e){const r=t.getFullYear(),n=t.getMonth()+e,o=new Date(t.getTime()),a=makeDate(r,n,1);return o.setFullYear(a.getFullYear(),a.getMonth(),Math.min(t.getDate(),daysInMonth(a.getFullYear(),a.getMonth()))),o}export function addYears(t,e){return addMonths(t,12*e)}export function compareDay(t,e){return startOfDay(t).getTime()-startOfDay(e).getTime()}export function isSameDay(t,e){return isValidDate(t)&&isValidDate(e)&&0===compareDay(t,e)}export function isSameMonth(t,e){return isValidDate(t)&&isValidDate(e)&&t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()}export function clampDate(t,e,r){return isValidDate(e)&&t.getTime()<e.getTime()?new Date(e.getTime()):isValidDate(r)&&t.getTime()>r.getTime()?new Date(r.getTime()):t}export function isDayOutside(t,e,r){return!!(isValidDate(e)&&compareDay(t,e)<0)||isValidDate(r)&&compareDay(t,r)>0}export function isUnitOutside(t,e,r,n){return!!(isValidDate(r)&&compareDay(endOfUnit(t,e),r)<0)||isValidDate(n)&&compareDay(startOfUnit(t,e),n)>0}export function secondsOfDay(t){return 3600*t.getHours()+60*t.getMinutes()+t.getSeconds()}export function timeUnitSpan(t,e){const r=secondsOfDay(e);if("hour"===t){const t=3600*Math.floor(r/3600);return[t,t+3599]}if("minute"===t){const t=60*Math.floor(r/60);return[t,t+59]}if("second"===t)return[r,r];const n=e.getHours()<12?0:43200;return[n,n+43200-1]}export function timeUnitRange(t,e){const[r,n]=timeUnitSpan(t,e),o=t=>withTime(e,{hours:Math.floor(t/3600),minutes:Math.floor(t%3600/60),seconds:t%60});return[o(r),o(n)]}export function withTime(t,e){const r=new Date(t.getTime());return r.setHours(e.hours??r.getHours(),e.minutes??r.getMinutes(),e.seconds??r.getSeconds(),0),r}export function mergeDateAndTime(t,e){return withTime(startOfDay(t),{hours:e.getHours(),minutes:e.getMinutes(),seconds:e.getSeconds()})}export function calendarWeeks(t,e){const r=startOfMonth(t),n=(r.getDay()-e+7)%7,o=addDays(r,-n);return Array.from({length:6},(t,e)=>Array.from({length:7},(t,r)=>addDays(o,7*e+r)))}export function yearPageStart(t){return t-(t%12+12)%12}export function formatDate(t,r,n){return isValidDate(t)?e(r,n).format(t):""}const r=Array.from({length:24},(t,e)=>new Date(2027,e%12,21+e%7,e,58,58)),n=Array.from({length:84},(t,e)=>{const r=Math.floor(e/7),n=new Date(2027,r,21).getDay();return new Date(2027,r,21+(e-n+7)%7,e%24,58,58)}),o=new WeakMap;export function displaySamples(t,a){const i=e(t,a),u=o.get(i);if(u)return u;const s=i.formatToParts(r[0]).some(t=>"weekday"===t.type),c=[...new Set((s?n:r).map(t=>i.format(t)))];return o.set(i,c),c}export function withPlaceholder(t,e){return"string"==typeof e&&""!==e?[...t,e]:t}export function toISODate(t){const e=t=>String(t).padStart(2,"0");return`${String(t.getFullYear()).padStart(4,"0")}-${e(t.getMonth()+1)}-${e(t.getDate())}`}export function toISOMonth(t){return`${String(t.getFullYear()).padStart(4,"0")}-${String(t.getMonth()+1).padStart(2,"0")}`}export function toISOYear(t){return String(t.getFullYear()).padStart(4,"0")}export function toISOTime(t,e=!1){const r=t=>String(t).padStart(2,"0"),n=`${r(t.getHours())}:${r(t.getMinutes())}`;return e?`${n}:${r(t.getSeconds())}`:n}export function toISODateTime(t,e=!1){return`${toISODate(t)}T${toISOTime(t,e)}`}const a=makeDate(2021,7,1);export function weekdayLabels(t,r,n="short"){const o=e(t,{weekday:n});return Array.from({length:7},(t,e)=>o.format(addDays(a,(r+e)%7)))}export function monthLabels(t,r="short"){const n=e(t,{month:r});return Array.from({length:12},(t,e)=>n.format(makeDate(2021,e,1)))}export function isMonthBeforeYear(t){const r=e(t,{year:"numeric",month:"long"}).formatToParts(a);return r.findIndex(t=>"month"===t.type)<r.findIndex(t=>"year"===t.type)}export function isHour12(t){const r=e(t,{hour:"numeric"}).resolvedOptions();return r.hourCycle?"h11"===r.hourCycle||"h12"===r.hourCycle:!0===r.hour12}export function meridiemLabels(t){const r=e(t,{hour:"numeric",hour12:!0}),n=t=>{const e=r.formatToParts(withTime(a,{hours:t})).find(t=>"dayPeriod"===t.type);return e?.value??(t<12?"AM":"PM")};return[n(9),n(21)]}const i=new Map;export function localeWeekStart(e){return t(i,e??"",()=>function(t){try{const e=t??(new Intl.DateTimeFormat).resolvedOptions().locale,r=new Intl.Locale(e),n="function"==typeof r.getWeekInfo?r.getWeekInfo():r.weekInfo;if("number"==typeof n?.firstDay)return n.firstDay%7}catch{}return 0}(e))}
|
|
@@ -37,10 +37,15 @@ export declare const DefaultsContext: React.Context<NebaDefaults | null>;
|
|
|
37
37
|
* the one a reader expects: the call site, then the provider, then the
|
|
38
38
|
* component's own literal default.
|
|
39
39
|
*
|
|
40
|
+
* `nearer` is a layer between the call site and the provider — a ButtonGroup
|
|
41
|
+
* around a Button — and a key it sets is left for the component to read from
|
|
42
|
+
* it. Filled first, the provider's `size` beat the group's, so a Button in a
|
|
43
|
+
* `size="lg"` group under a `size: 'sm'` provider came out small.
|
|
44
|
+
*
|
|
40
45
|
* The keys are passed in rather than worked out, and that is load-bearing. A
|
|
41
46
|
* key a component does not destructure stays in the props it spreads onto its
|
|
42
47
|
* root, so filling `density` into a component that has none would put
|
|
43
48
|
* `density="compact"` on a `<div>` — and `size` on an `<input>` is a real
|
|
44
49
|
* attribute that would quietly resize the field.
|
|
45
50
|
*/
|
|
46
|
-
export declare function useStyleDefaults<P extends object>(props: P, keys: DefaultableKey[]): P;
|
|
51
|
+
export declare function useStyleDefaults<P extends object>(props: P, keys: DefaultableKey[], nearer?: NebaDefaults | null): P;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import*as t from"react";export const DefaultsContext=/*@__PURE__*/t.createContext(null);export function useStyleDefaults(e,o){const
|
|
1
|
+
"use client";import*as t from"react";export const DefaultsContext=/*@__PURE__*/t.createContext(null);export function useStyleDefaults(e,o,n){const s=t.useContext(DefaultsContext);if(!s)return e;const r=e;let u=null;for(const t of o){const e=s[t];void 0!==e&&void 0===r[t]&&void 0===n?.[t]&&(u=u??{...r},u[t]=e)}return u??r}
|
package/dist/internal/drag.d.ts
CHANGED
|
@@ -30,6 +30,18 @@ export interface PointerDragOptions {
|
|
|
30
30
|
* the pointer leaving the element it started on.
|
|
31
31
|
*/
|
|
32
32
|
target: HTMLElement;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the pointer is captured to `target`. Without it the listeners go on
|
|
35
|
+
* the target's document, which hears the gesture wherever the pointer goes.
|
|
36
|
+
*
|
|
37
|
+
* It is for a drag that starts on something the reader may only have meant
|
|
38
|
+
* to press. A captured pointer's `click` and `dblclick` go to the capturing
|
|
39
|
+
* element rather than to what is under the pointer, so capturing on the press
|
|
40
|
+
* takes the click away from a row's `onClick` or a sort button inside a
|
|
41
|
+
* header in every browser, whether or not the pointer moved.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
capture?: boolean;
|
|
33
45
|
/** The pointer that started it. */
|
|
34
46
|
pointerId: number;
|
|
35
47
|
/** Every move until the gesture ends. */
|
|
@@ -61,4 +73,4 @@ export interface PointerDragOptions {
|
|
|
61
73
|
* Call `release` from an unmount effect. It is idempotent, so the pointer's own
|
|
62
74
|
* `pointerup` calling it first costs nothing.
|
|
63
75
|
*/
|
|
64
|
-
export declare function beginPointerDrag({ target, pointerId, onMove, onEnd, selectable, mark }: PointerDragOptions): () => void;
|
|
76
|
+
export declare function beginPointerDrag({ target, pointerId, onMove, onEnd, capture, selectable, mark }: PointerDragOptions): () => void;
|
package/dist/internal/drag.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function beginPointerDrag({target:e,pointerId:t,onMove:r,onEnd:n,
|
|
1
|
+
export function beginPointerDrag({target:e,pointerId:t,onMove:r,onEnd:n,capture:o=!0,selectable:s=!0,mark:i=!0}){const a=s?function(){const e=document.body,t=e.style.getPropertyValue("-webkit-user-select");return e.style.setProperty("-webkit-user-select","none"),()=>{t?e.style.setProperty("-webkit-user-select",t):e.style.removeProperty("-webkit-user-select")}}():null,c=o?e:e.ownerDocument;if(i&&(e.dataset.dragging="true"),o)try{e.setPointerCapture?.(t)}catch{}let l=!0;const u=()=>{l&&(l=!1,c.removeEventListener("pointermove",r),c.removeEventListener("pointerup",p),c.removeEventListener("pointercancel",p),i&&delete e.dataset.dragging,a?.())},p=()=>{u(),n?.()};return c.addEventListener("pointermove",r),c.addEventListener("pointerup",p),c.addEventListener("pointercancel",p),u}
|