@luxalgo/vela-ui 0.0.0-stage → 0.2.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/CHANGELOG.md +91 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +86 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +55 -0
- package/dist/button.js +11 -0
- package/dist/calendar.d.ts +24 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +103 -0
- package/dist/callout-bubble.js +177 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-7VMN7NKJ.js +133 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-B5ZSRUDQ.js +227 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-C3ICYMI3.js +25 -0
- package/dist/chunk-CC3DDNFC.js +117 -0
- package/dist/chunk-E2FE6V2N.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-GVRX3UAV.js +82 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MJ4RUGX7.js +403 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-U3EH42YY.js +72 -0
- package/dist/chunk-V2Q4MRMS.js +573 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-WBGSYCV2.js +101 -0
- package/dist/chunk-WGULXRWD.js +351 -0
- package/dist/chunk-WXH3EFV5.js +219 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XBEL4K33.js +142 -0
- package/dist/chunk-Z5PINFQO.js +280 -0
- package/dist/collapsible.d.ts +49 -0
- package/dist/collapsible.js +106 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +17 -0
- package/dist/css.js +4 -0
- package/dist/data-table.d.ts +40 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/h-Bl37qUis.d.ts +24 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +87 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/item.d.ts +72 -0
- package/dist/item.js +131 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +4508 -0
- package/dist/month-grid.d.ts +45 -0
- package/dist/month-grid.js +157 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/slider.d.ts +46 -0
- package/dist/slider.js +111 -0
- package/dist/sort-button.d.ts +41 -0
- package/dist/sort-button.js +88 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +65 -0
- package/dist/tabs.js +155 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +199 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1994 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +217 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +250 -0
- package/llms.txt +71 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +379 -0
- package/registry/callout-bubble.ts +347 -0
- package/registry/checkbox.ts +234 -0
- package/registry/collapsible.ts +271 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/item.ts +376 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/month-grid.ts +328 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/slider.ts +259 -0
- package/registry/sort-button.ts +189 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +426 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +137 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +379 -0
- package/src/components/callout-bubble.ts +347 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/collapsible.ts +271 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/item.ts +376 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/month-grid.ts +328 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/slider.ts +259 -0
- package/src/components/sort-button.ts +189 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +426 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +117 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +151 -0
- package/src/lib/css.ts +48 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/scope.ts +135 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +664 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
// Item: one row of a list (a watchlist, a list of alerts, search results): media (an icon, a
|
|
2
|
+
// logo, an avatar, a star), a title over a description, then at its end the meta (figures,
|
|
3
|
+
// badges) and the actions (buttons). With `onSelect` the whole row is clickable, while a press
|
|
4
|
+
// on a control inside it stays that control's. To the keyboard (Enter, Space) and to screen
|
|
5
|
+
// readers the row is a button; a row with actions makes its text the button instead, as a
|
|
6
|
+
// button cannot hold other buttons. `selected` marks the current row; `revealActions` keeps the actions
|
|
7
|
+
// out of sight until the row is hovered or holds focus, while the meta stays. `default` is
|
|
8
|
+
// bare until hovered, `outline` bordered, `muted` on a sunken fill; `sm` is the compact row of
|
|
9
|
+
// dense panels. ItemGroup stacks rows, with a line between them when `separated`.
|
|
10
|
+
import { css, defineStyles } from '../lib/css';
|
|
11
|
+
import { defineComponent } from '../lib/define';
|
|
12
|
+
import { append, h, type Child } from '../lib/h';
|
|
13
|
+
import { iconEl } from '../lib/icons';
|
|
14
|
+
import { t } from '../lib/t';
|
|
15
|
+
import { variants, type VariantProps } from '../lib/variants';
|
|
16
|
+
|
|
17
|
+
export const itemDef = defineComponent({
|
|
18
|
+
name: 'item',
|
|
19
|
+
parts: ['root', 'media', 'content', 'title', 'description', 'meta', 'actions', 'group'],
|
|
20
|
+
settings: { radius: t.radius.md, gap: '10px' },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const itemVariants = variants({ variant: ['default', 'outline', 'muted'], size: ['default', 'sm'] });
|
|
24
|
+
|
|
25
|
+
export type ItemVariant = (typeof itemVariants.spec.variant)[number];
|
|
26
|
+
export type ItemSize = (typeof itemVariants.spec.size)[number];
|
|
27
|
+
|
|
28
|
+
export interface ItemProps extends VariantProps<typeof itemVariants> {
|
|
29
|
+
/** The first line: text, or an element (a ticker with a chip after it). */
|
|
30
|
+
title: string | Node;
|
|
31
|
+
/** The muted line under the title. */
|
|
32
|
+
description?: string | Node;
|
|
33
|
+
/** Before the text: an icon id from the kit's registry, or an element (a logo, an
|
|
34
|
+
* avatar, a favorite star). */
|
|
35
|
+
media?: string | Node;
|
|
36
|
+
/** After the text, always shown: figures and badges (a price and its change). */
|
|
37
|
+
meta?: Child;
|
|
38
|
+
/** At the row's end: its buttons. */
|
|
39
|
+
actions?: Child;
|
|
40
|
+
/** Show the actions only while the row is hovered or holds focus (on touch screens they
|
|
41
|
+
* always show). The meta stays. */
|
|
42
|
+
revealActions?: boolean;
|
|
43
|
+
/** The current row (the open symbol, the highlighted result). */
|
|
44
|
+
selected?: boolean;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
/** Makes the row clickable: a click, Enter or Space runs it. */
|
|
47
|
+
onSelect?: (e: MouseEvent | KeyboardEvent) => void;
|
|
48
|
+
/** The row's role (default `button` when it has `onSelect` and no actions, its text being
|
|
49
|
+
* the button when it has actions); `option` in a listbox, where `selected` is
|
|
50
|
+
* `aria-selected`. */
|
|
51
|
+
role?: string;
|
|
52
|
+
/** Extra class names (layout hooks). */
|
|
53
|
+
className?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ItemHandle {
|
|
57
|
+
readonly el: HTMLElement;
|
|
58
|
+
setSelected(selected: boolean): void;
|
|
59
|
+
setDisabled(disabled: boolean): void;
|
|
60
|
+
setTitle(title: string | Node): void;
|
|
61
|
+
/** A new description; null removes it. */
|
|
62
|
+
setDescription(description: string | Node | null): void;
|
|
63
|
+
destroy(): void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface ItemGroupProps {
|
|
67
|
+
/** The rows, as elements or as the handles `createItem` returns. */
|
|
68
|
+
items?: ReadonlyArray<HTMLElement | ItemHandle>;
|
|
69
|
+
/** A line between the rows, edge to edge (default: separate rounded rows). */
|
|
70
|
+
separated?: boolean;
|
|
71
|
+
/** The list's accessible name. */
|
|
72
|
+
label?: string;
|
|
73
|
+
/** The group's role: default `group` when it has a `label` (the name needs a role to be
|
|
74
|
+
* read), none otherwise; `listbox` for rows whose role is `option`. */
|
|
75
|
+
role?: string;
|
|
76
|
+
/** Extra class names (layout hooks). */
|
|
77
|
+
className?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ItemGroupHandle {
|
|
81
|
+
readonly el: HTMLElement;
|
|
82
|
+
/** Replace the rows. */
|
|
83
|
+
setItems(items: ReadonlyArray<HTMLElement | ItemHandle>): void;
|
|
84
|
+
destroy(): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A press on one of these inside a row belongs to it, not to the row. */
|
|
88
|
+
const CONTROL = 'button, a[href], input, select, textarea, label, summary, [role="button"], [role="checkbox"], [role="switch"], [role="menuitem"], [role="option"], [role="link"], [contenteditable]:not([contenteditable="false"])';
|
|
89
|
+
|
|
90
|
+
const injectStyles = defineStyles(
|
|
91
|
+
'vela-ui-item',
|
|
92
|
+
css`
|
|
93
|
+
@layer vela.ui {
|
|
94
|
+
[data-slot='item'] {
|
|
95
|
+
position: relative;
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
min-width: 0;
|
|
98
|
+
padding: 8px 10px;
|
|
99
|
+
border: 1px solid transparent;
|
|
100
|
+
border-radius: ${itemDef.vars.radius};
|
|
101
|
+
color: ${t.fg};
|
|
102
|
+
font-size: 13px;
|
|
103
|
+
text-align: start;
|
|
104
|
+
transition:
|
|
105
|
+
background ${t.dur.fast} ease,
|
|
106
|
+
border-color ${t.dur.fast} ease;
|
|
107
|
+
|
|
108
|
+
&:where(:not([hidden])) {
|
|
109
|
+
display: flex;
|
|
110
|
+
align-items: center;
|
|
111
|
+
gap: ${itemDef.vars.gap};
|
|
112
|
+
}
|
|
113
|
+
&[data-size='sm'] {
|
|
114
|
+
gap: 8px;
|
|
115
|
+
padding: 4px 8px;
|
|
116
|
+
font-size: 12px;
|
|
117
|
+
}
|
|
118
|
+
&[data-variant='outline'] {
|
|
119
|
+
border-color: ${t.border};
|
|
120
|
+
}
|
|
121
|
+
&[data-variant='muted'] {
|
|
122
|
+
background: ${t.surface.sunken};
|
|
123
|
+
}
|
|
124
|
+
&[data-clickable] {
|
|
125
|
+
cursor: pointer;
|
|
126
|
+
user-select: none;
|
|
127
|
+
-webkit-tap-highlight-color: transparent;
|
|
128
|
+
}
|
|
129
|
+
&[data-clickable]:not([data-disabled]):hover {
|
|
130
|
+
background: ${t.hover};
|
|
131
|
+
}
|
|
132
|
+
&[data-selected],
|
|
133
|
+
&[data-selected][data-clickable]:hover {
|
|
134
|
+
background: ${t.active};
|
|
135
|
+
}
|
|
136
|
+
&:focus-visible {
|
|
137
|
+
outline: 2px solid ${t.focus};
|
|
138
|
+
outline-offset: -2px;
|
|
139
|
+
}
|
|
140
|
+
&[data-disabled] {
|
|
141
|
+
cursor: default;
|
|
142
|
+
opacity: 0.5;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
[data-slot='item-media'] {
|
|
146
|
+
flex: none;
|
|
147
|
+
color: ${t.fg.muted};
|
|
148
|
+
|
|
149
|
+
&:where(:not([hidden])) {
|
|
150
|
+
display: inline-flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
justify-content: center;
|
|
153
|
+
}
|
|
154
|
+
& > [data-icon] {
|
|
155
|
+
width: 1em;
|
|
156
|
+
height: 1em;
|
|
157
|
+
font-size: 16px;
|
|
158
|
+
line-height: 0;
|
|
159
|
+
}
|
|
160
|
+
& > [data-icon] > svg {
|
|
161
|
+
width: 100%;
|
|
162
|
+
height: 100%;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
[data-slot='item-content'] {
|
|
166
|
+
flex: 1 1 auto;
|
|
167
|
+
min-width: 0;
|
|
168
|
+
|
|
169
|
+
&:where(:not([hidden])) {
|
|
170
|
+
display: flex;
|
|
171
|
+
flex-direction: column;
|
|
172
|
+
gap: 2px;
|
|
173
|
+
}
|
|
174
|
+
&[role='button']:focus-visible {
|
|
175
|
+
outline: 2px solid ${t.focus};
|
|
176
|
+
outline-offset: 2px;
|
|
177
|
+
border-radius: ${t.radius.sm};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
[data-slot='item-title'],
|
|
181
|
+
[data-slot='item-description'] {
|
|
182
|
+
min-width: 0;
|
|
183
|
+
overflow: hidden;
|
|
184
|
+
text-overflow: ellipsis;
|
|
185
|
+
white-space: nowrap;
|
|
186
|
+
}
|
|
187
|
+
[data-slot='item-title'] {
|
|
188
|
+
color: ${t.fg.bright};
|
|
189
|
+
font-weight: 500;
|
|
190
|
+
line-height: 18px;
|
|
191
|
+
}
|
|
192
|
+
[data-slot='item-description'] {
|
|
193
|
+
color: ${t.fg.muted};
|
|
194
|
+
font-size: 12px;
|
|
195
|
+
line-height: 16px;
|
|
196
|
+
|
|
197
|
+
&:is([data-size='sm'] *) {
|
|
198
|
+
font-size: 11px;
|
|
199
|
+
line-height: 14px;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
[data-slot='item-meta'] {
|
|
203
|
+
flex: none;
|
|
204
|
+
gap: 8px;
|
|
205
|
+
color: ${t.fg};
|
|
206
|
+
font-variant-numeric: tabular-nums;
|
|
207
|
+
text-align: end;
|
|
208
|
+
white-space: nowrap;
|
|
209
|
+
|
|
210
|
+
&:where(:not([hidden])) {
|
|
211
|
+
display: inline-flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
[data-slot='item-actions'] {
|
|
216
|
+
flex: none;
|
|
217
|
+
gap: 4px;
|
|
218
|
+
|
|
219
|
+
&:where(:not([hidden])) {
|
|
220
|
+
display: inline-flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
}
|
|
223
|
+
&:is([data-reveal-actions] > *) {
|
|
224
|
+
opacity: 0;
|
|
225
|
+
transition: opacity ${t.dur.fast} ease;
|
|
226
|
+
}
|
|
227
|
+
&:is([data-reveal-actions]:hover > *, [data-reveal-actions]:focus-within > *) {
|
|
228
|
+
opacity: 1;
|
|
229
|
+
}
|
|
230
|
+
@media (hover: none) {
|
|
231
|
+
&:is([data-reveal-actions] > *) {
|
|
232
|
+
opacity: 1;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
[data-slot='item-group'] {
|
|
237
|
+
min-width: 0;
|
|
238
|
+
|
|
239
|
+
&:where(:not([hidden])) {
|
|
240
|
+
display: flex;
|
|
241
|
+
flex-direction: column;
|
|
242
|
+
gap: 2px;
|
|
243
|
+
}
|
|
244
|
+
&[data-separated] {
|
|
245
|
+
gap: 0;
|
|
246
|
+
}
|
|
247
|
+
&[data-separated] > [data-slot='item'] {
|
|
248
|
+
border-radius: 0;
|
|
249
|
+
border-bottom-color: ${t.border.faint};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
`,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
class ItemImpl implements ItemHandle {
|
|
257
|
+
readonly el: HTMLElement;
|
|
258
|
+
private readonly content: HTMLElement;
|
|
259
|
+
private readonly titleEl: HTMLElement;
|
|
260
|
+
private descriptionEl: HTMLElement | null = null;
|
|
261
|
+
/** What takes the focus, the role and the states: the row, or its text in a row with actions. */
|
|
262
|
+
private readonly control: HTMLElement;
|
|
263
|
+
private readonly option: boolean;
|
|
264
|
+
private disabled = false;
|
|
265
|
+
private readonly onClick = (e: MouseEvent): void => {
|
|
266
|
+
if (this.disabled) return;
|
|
267
|
+
const control = e.target instanceof Element ? e.target.closest(CONTROL) : null;
|
|
268
|
+
if (control && control !== this.control && control !== this.el && this.el.contains(control)) return;
|
|
269
|
+
this.props.onSelect?.(e);
|
|
270
|
+
};
|
|
271
|
+
private readonly onKey = (e: KeyboardEvent): void => {
|
|
272
|
+
if (this.disabled || e.target !== this.control || (e.key !== 'Enter' && e.key !== ' ')) return;
|
|
273
|
+
e.preventDefault();
|
|
274
|
+
this.props.onSelect?.(e);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
constructor(private readonly props: ItemProps) {
|
|
278
|
+
injectStyles(document);
|
|
279
|
+
const clickable = !!props.onSelect;
|
|
280
|
+
const textControl = clickable && props.role === undefined && props.actions !== undefined && props.actions !== null;
|
|
281
|
+
const role = props.role ?? (clickable ? 'button' : null);
|
|
282
|
+
this.option = role === 'option';
|
|
283
|
+
let media: HTMLElement | null = null;
|
|
284
|
+
if (props.media !== undefined) {
|
|
285
|
+
media = h('div', { slot: itemDef.slot('media') });
|
|
286
|
+
if (typeof props.media === 'string') {
|
|
287
|
+
const icon = iconEl(props.media, document);
|
|
288
|
+
icon.dataset.icon = '';
|
|
289
|
+
media.appendChild(icon);
|
|
290
|
+
} else media.appendChild(props.media);
|
|
291
|
+
}
|
|
292
|
+
this.titleEl = h('div', { slot: itemDef.slot('title') }, props.title);
|
|
293
|
+
this.content = h('div', { slot: itemDef.slot('content'), attrs: textControl ? { role, tabindex: '0' } : undefined }, this.titleEl);
|
|
294
|
+
const trailing = (part: 'meta' | 'actions', children: Child): HTMLElement | null => {
|
|
295
|
+
if (children === undefined || children === null) return null;
|
|
296
|
+
const el = h('div', { slot: itemDef.slot(part) });
|
|
297
|
+
append(el, [children]);
|
|
298
|
+
return el;
|
|
299
|
+
};
|
|
300
|
+
this.el = h(
|
|
301
|
+
'div',
|
|
302
|
+
{
|
|
303
|
+
className: props.className,
|
|
304
|
+
slot: itemDef.slot('root'),
|
|
305
|
+
attrs: { ...itemVariants(props), role: textControl ? null : role, tabindex: clickable && !textControl ? '0' : null },
|
|
306
|
+
data: { clickable: clickable || null, 'reveal-actions': props.revealActions || null },
|
|
307
|
+
},
|
|
308
|
+
media,
|
|
309
|
+
this.content,
|
|
310
|
+
trailing('meta', props.meta),
|
|
311
|
+
trailing('actions', props.actions),
|
|
312
|
+
);
|
|
313
|
+
this.control = textControl ? this.content : this.el;
|
|
314
|
+
if (props.description !== undefined) this.setDescription(props.description);
|
|
315
|
+
if (clickable) {
|
|
316
|
+
this.el.addEventListener('click', this.onClick);
|
|
317
|
+
this.control.addEventListener('keydown', this.onKey);
|
|
318
|
+
}
|
|
319
|
+
this.setSelected(props.selected ?? false);
|
|
320
|
+
this.setDisabled(props.disabled ?? false);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
setSelected(selected: boolean): void {
|
|
324
|
+
this.el.toggleAttribute('data-selected', selected);
|
|
325
|
+
if (this.option) this.control.setAttribute('aria-selected', String(selected));
|
|
326
|
+
else if (selected) this.control.setAttribute('aria-current', 'true');
|
|
327
|
+
else this.control.removeAttribute('aria-current');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
setDisabled(disabled: boolean): void {
|
|
331
|
+
this.disabled = disabled;
|
|
332
|
+
this.el.toggleAttribute('data-disabled', disabled);
|
|
333
|
+
if (disabled) this.control.setAttribute('aria-disabled', 'true');
|
|
334
|
+
else this.control.removeAttribute('aria-disabled');
|
|
335
|
+
if (this.props.onSelect) this.control.tabIndex = disabled ? -1 : 0;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
setTitle(title: string | Node): void {
|
|
339
|
+
this.titleEl.replaceChildren(title);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
setDescription(description: string | Node | null): void {
|
|
343
|
+
if (description === null) {
|
|
344
|
+
this.descriptionEl?.remove();
|
|
345
|
+
this.descriptionEl = null;
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
this.descriptionEl ??= this.content.appendChild(h('div', { slot: itemDef.slot('description') }));
|
|
349
|
+
this.descriptionEl.replaceChildren(description);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
destroy(): void {
|
|
353
|
+
this.el.removeEventListener('click', this.onClick);
|
|
354
|
+
this.control.removeEventListener('keydown', this.onKey);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function createItem(props: ItemProps): ItemHandle {
|
|
359
|
+
return new ItemImpl(props);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** Rows stacked as one list. */
|
|
363
|
+
export function createItemGroup(props: ItemGroupProps = {}): ItemGroupHandle {
|
|
364
|
+
injectStyles(document);
|
|
365
|
+
const el = h('div', {
|
|
366
|
+
className: props.className,
|
|
367
|
+
slot: itemDef.slot('group'),
|
|
368
|
+
attrs: { role: props.role ?? (props.label ? 'group' : null), 'aria-label': props.label ?? null },
|
|
369
|
+
data: { separated: props.separated || null },
|
|
370
|
+
});
|
|
371
|
+
const setItems = (items: ReadonlyArray<HTMLElement | ItemHandle>): void => {
|
|
372
|
+
el.replaceChildren(...items.map((item) => (item instanceof HTMLElement ? item : item.el)));
|
|
373
|
+
};
|
|
374
|
+
setItems(props.items ?? []);
|
|
375
|
+
return { el, setItems, destroy: () => el.remove() };
|
|
376
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Kbd: one key of a shortcut, drawn as a keycap (`Alt`, `A`). A shortcut is a row of them;
|
|
2
|
+
// hover cards and menus show them beside the command they trigger.
|
|
3
|
+
import { css, defineStyles } from '../lib/css';
|
|
4
|
+
import { defineComponent } from '../lib/define';
|
|
5
|
+
import { h } from '../lib/h';
|
|
6
|
+
import { t } from '../lib/t';
|
|
7
|
+
|
|
8
|
+
export const kbdDef = defineComponent({
|
|
9
|
+
name: 'kbd',
|
|
10
|
+
parts: ['root'],
|
|
11
|
+
settings: { radius: '5px', shadow: `inset 0 -1px 0 ${t.border}` },
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export interface KbdProps {
|
|
15
|
+
/** The key's label (`Alt`, `⌘`, `K`). */
|
|
16
|
+
text: string;
|
|
17
|
+
/** Extra class names (layout hooks). */
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface KbdHandle {
|
|
22
|
+
readonly el: HTMLElement;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const injectStyles = defineStyles(
|
|
27
|
+
'vela-ui-kbd',
|
|
28
|
+
css`
|
|
29
|
+
@layer vela.ui {
|
|
30
|
+
[data-slot='kbd'] {
|
|
31
|
+
min-width: 18px;
|
|
32
|
+
height: 18px;
|
|
33
|
+
padding: 0 4px;
|
|
34
|
+
border-radius: ${kbdDef.vars.radius};
|
|
35
|
+
border: 1px solid ${t.border};
|
|
36
|
+
border-bottom-color: color-mix(in srgb, ${t.fg.muted} 35%, transparent);
|
|
37
|
+
background: ${t.hover};
|
|
38
|
+
color: ${t.fg.bright};
|
|
39
|
+
font: inherit;
|
|
40
|
+
font-size: 10px;
|
|
41
|
+
font-weight: 500;
|
|
42
|
+
line-height: 1;
|
|
43
|
+
box-shadow: ${kbdDef.vars.shadow};
|
|
44
|
+
|
|
45
|
+
&:where(:not([hidden])) {
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export function createKbd(props: KbdProps): KbdHandle {
|
|
56
|
+
injectStyles(document);
|
|
57
|
+
const el = h('kbd', { className: props.className, slot: kbdDef.slot('root'), text: props.text });
|
|
58
|
+
return { el, destroy: () => el.remove() };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A shortcut (`Alt+A`) as a row of keycaps, one per key. */
|
|
62
|
+
export function shortcutKeys(shortcut: string): HTMLElement[] {
|
|
63
|
+
return shortcut.split('+').map((key) => createKbd({ text: key }).el);
|
|
64
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// LineChart: a compact area chart with a hover readout (equity curves, P&L over time): one line
|
|
2
|
+
// over a fading area, in the profit tone when its last point ends at or above the baseline and
|
|
3
|
+
// the loss tone below it, with optional axis labels under and beside the plot.
|
|
4
|
+
import { css, defineStyles } from '../lib/css';
|
|
5
|
+
import { chartFrame, escapeXml, niceStep, showTip } from '../lib/chart';
|
|
6
|
+
import { defineComponent } from '../lib/define';
|
|
7
|
+
import { pageUid } from '../lib/page';
|
|
8
|
+
import { t } from '../lib/t';
|
|
9
|
+
|
|
10
|
+
export const lineChartDef = defineComponent({
|
|
11
|
+
name: 'line-chart',
|
|
12
|
+
parts: ['root', 'label', 'area', 'line', 'dot', 'tip'],
|
|
13
|
+
settings: { 'tip-radius': '3px', 'tip-shadow': t.shadow, 'tip-z': '2', 'tip-bg': t.surface.elev, 'stroke-width': '2' },
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export interface LinePoint {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LineChartProps {
|
|
22
|
+
/** Axis label size in px (default 10). */
|
|
23
|
+
axisFont?: number;
|
|
24
|
+
/** The hover readout of a point. */
|
|
25
|
+
format?: (p: LinePoint, index: number) => string | Node;
|
|
26
|
+
/** The area fills down (or up) to this value (default 0). */
|
|
27
|
+
baseline?: number;
|
|
28
|
+
/** Label the x axis under the plot and the y axis beside it. */
|
|
29
|
+
axes?: boolean;
|
|
30
|
+
xFormat?: (x: number) => string;
|
|
31
|
+
yFormat?: (y: number) => string;
|
|
32
|
+
/** Extra class names (layout hooks). */
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface LineChartHandle {
|
|
37
|
+
readonly el: HTMLElement;
|
|
38
|
+
setData(points: readonly LinePoint[]): void;
|
|
39
|
+
/** Show or drop the axis labels; dropped, the plot takes their room. */
|
|
40
|
+
setAxes(on: boolean): void;
|
|
41
|
+
destroy(): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const injectStyles = defineStyles(
|
|
45
|
+
'vela-ui-line-chart',
|
|
46
|
+
css`
|
|
47
|
+
@layer vela.ui {
|
|
48
|
+
[data-slot='line-chart'] {
|
|
49
|
+
--_ink: ${t.profit};
|
|
50
|
+
position: relative;
|
|
51
|
+
width: 100%;
|
|
52
|
+
height: 100%;
|
|
53
|
+
|
|
54
|
+
&[data-tone='loss'] {
|
|
55
|
+
--_ink: ${t.loss};
|
|
56
|
+
}
|
|
57
|
+
& > svg {
|
|
58
|
+
display: block;
|
|
59
|
+
width: 100%;
|
|
60
|
+
height: 100%;
|
|
61
|
+
overflow: visible;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
[data-slot='line-chart-label'] {
|
|
65
|
+
fill: ${t.fg.muted};
|
|
66
|
+
}
|
|
67
|
+
[data-slot='line-chart-line'] {
|
|
68
|
+
fill: none;
|
|
69
|
+
stroke: var(--_ink);
|
|
70
|
+
stroke-width: ${lineChartDef.vars['stroke-width']};
|
|
71
|
+
stroke-linejoin: round;
|
|
72
|
+
vector-effect: non-scaling-stroke;
|
|
73
|
+
}
|
|
74
|
+
[data-slot='line-chart-dot'] {
|
|
75
|
+
fill: var(--_ink);
|
|
76
|
+
opacity: 0;
|
|
77
|
+
|
|
78
|
+
&[data-on] {
|
|
79
|
+
opacity: 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
[data-slot='line-chart-tip'] {
|
|
83
|
+
position: absolute;
|
|
84
|
+
z-index: ${lineChartDef.vars['tip-z']};
|
|
85
|
+
top: 0;
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
padding: 8px;
|
|
88
|
+
border-radius: ${lineChartDef.vars['tip-radius']};
|
|
89
|
+
border: 1px solid ${t.border};
|
|
90
|
+
background: ${lineChartDef.vars['tip-bg']};
|
|
91
|
+
color: ${t.fg.bright};
|
|
92
|
+
box-shadow: ${lineChartDef.vars['tip-shadow']};
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
line-height: 1.35;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
font-variant-numeric: tabular-nums;
|
|
97
|
+
transition:
|
|
98
|
+
left ${t.dur.fast} ease-out,
|
|
99
|
+
top ${t.dur.fast} ease-out;
|
|
100
|
+
|
|
101
|
+
&[data-instant] {
|
|
102
|
+
transition: none;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
`,
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
export function createLineChart(props: LineChartProps = {}): LineChartHandle {
|
|
110
|
+
injectStyles(document);
|
|
111
|
+
let points: readonly LinePoint[] = [];
|
|
112
|
+
let axes = !!props.axes;
|
|
113
|
+
const id = pageUid('vela-line-chart');
|
|
114
|
+
const font = props.axisFont ?? 10;
|
|
115
|
+
const slot = (part: (typeof lineChartDef.parts)[number]) => `data-slot="${lineChartDef.slot(part)}"`;
|
|
116
|
+
const axisRight = (): number => (axes ? Math.round(56 + (font - 10) * 3) : 0);
|
|
117
|
+
const axisBottom = (): number => (axes ? Math.round(font * 1.4 + 4) : 0);
|
|
118
|
+
|
|
119
|
+
const dims = () => {
|
|
120
|
+
const w = frame.el.clientWidth - axisRight();
|
|
121
|
+
const ht = frame.el.clientHeight - axisBottom();
|
|
122
|
+
if (w < 4 || ht < 4 || points.length < 2) return null;
|
|
123
|
+
const base = props.baseline ?? 0;
|
|
124
|
+
let minY = base;
|
|
125
|
+
let maxY = base;
|
|
126
|
+
for (const p of points) {
|
|
127
|
+
if (p.y < minY) minY = p.y;
|
|
128
|
+
if (p.y > maxY) maxY = p.y;
|
|
129
|
+
}
|
|
130
|
+
if (minY === maxY) maxY = minY + 1;
|
|
131
|
+
const pad = (maxY - minY) * 0.08;
|
|
132
|
+
return { w, h: ht, minY: minY - pad, maxY: maxY + pad, minX: points[0]!.x, maxX: points[points.length - 1]!.x };
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const draw = (): void => {
|
|
136
|
+
const d = dims();
|
|
137
|
+
if (!d) {
|
|
138
|
+
frame.svg.replaceChildren();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const sx = (x: number): number => (d.maxX === d.minX ? 0 : ((x - d.minX) / (d.maxX - d.minX)) * d.w);
|
|
142
|
+
const sy = (y: number): number => d.h - ((y - d.minY) / (d.maxY - d.minY)) * d.h;
|
|
143
|
+
const base = sy(props.baseline ?? 0);
|
|
144
|
+
const line = points.map((p, i) => `${i === 0 ? 'M' : 'L'}${sx(p.x).toFixed(1)},${sy(p.y).toFixed(1)}`).join('');
|
|
145
|
+
const area = `${line}L${sx(d.maxX).toFixed(1)},${base.toFixed(1)}L0,${base.toFixed(1)}Z`;
|
|
146
|
+
const gain = points[points.length - 1]!.y >= (props.baseline ?? 0);
|
|
147
|
+
frame.el.dataset.tone = gain ? 'profit' : 'loss';
|
|
148
|
+
// Denser toward the line: the top for a gain, the bottom for a loss.
|
|
149
|
+
const fade = [0.85, 0.65, 0.45, 0.3, 0.15, 0.05];
|
|
150
|
+
const stops = (gain ? fade : [...fade].reverse()).map((o, i) => `<stop offset="${i / 5}" style="stop-color: var(--_ink); stop-opacity: ${o}"/>`).join('');
|
|
151
|
+
let labels = '';
|
|
152
|
+
if (axes) {
|
|
153
|
+
const label = (x: number, y: number, text: string, anchor: string): string => `<text ${slot('label')} x="${x.toFixed(1)}" y="${y.toFixed(1)}" font-size="${font}" text-anchor="${anchor}">${escapeXml(text)}</text>`;
|
|
154
|
+
const step = niceStep(d.maxY - d.minY, Math.max(2, Math.floor(d.h / 42)));
|
|
155
|
+
for (let v = Math.ceil(d.minY / step) * step; v <= d.maxY; v += step) {
|
|
156
|
+
const y = sy(v);
|
|
157
|
+
if (y < font / 2 || y > d.h - 2) continue;
|
|
158
|
+
labels += label(d.w + 8, y + font / 3, props.yFormat ? props.yFormat(Math.abs(v) < step / 2 ? 0 : v) : v.toFixed(0), 'start');
|
|
159
|
+
}
|
|
160
|
+
const ticks = Math.max(2, Math.floor(d.w / 107));
|
|
161
|
+
let last = '';
|
|
162
|
+
for (let i = 0; i <= ticks; i += 1) {
|
|
163
|
+
const x = d.minX + ((d.maxX - d.minX) * i) / ticks;
|
|
164
|
+
const text = props.xFormat ? props.xFormat(x) : String(Math.round(x));
|
|
165
|
+
if (text === last) continue;
|
|
166
|
+
last = text;
|
|
167
|
+
labels += label(Math.min(d.w - 20, Math.max(20, sx(x))), d.h + font + 4, text, 'middle');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
frame.svg.setAttribute('viewBox', `0 0 ${d.w + axisRight()} ${d.h + axisBottom()}`);
|
|
171
|
+
frame.svg.innerHTML =
|
|
172
|
+
`<defs><linearGradient id="${id}-g" x1="0" y1="0" x2="0" y2="1">${stops}</linearGradient></defs>` +
|
|
173
|
+
labels +
|
|
174
|
+
`<path ${slot('area')} d="${area}" fill="url(#${id}-g)"/>` +
|
|
175
|
+
`<path ${slot('line')} d="${line}"/>` +
|
|
176
|
+
`<circle ${slot('dot')} r="4"/>`;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const frame = chartFrame(lineChartDef.slot('root'), lineChartDef.slot('tip'), props.className, draw);
|
|
180
|
+
const hover = (e: PointerEvent | null): void => {
|
|
181
|
+
const d = dims();
|
|
182
|
+
const dot = frame.svg.querySelector<SVGCircleElement>(`[data-slot="${lineChartDef.slot('dot')}"]`);
|
|
183
|
+
if (!d || !e || !dot) {
|
|
184
|
+
frame.tip.hidden = true;
|
|
185
|
+
dot?.removeAttribute('data-on');
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const target = d.minX + ((e.clientX - frame.el.getBoundingClientRect().left) / d.w) * (d.maxX - d.minX);
|
|
189
|
+
let index = 0;
|
|
190
|
+
for (let i = 1; i < points.length; i += 1) if (Math.abs(points[i]!.x - target) < Math.abs(points[index]!.x - target)) index = i;
|
|
191
|
+
const best = points[index]!;
|
|
192
|
+
const px = d.maxX === d.minX ? 0 : ((best.x - d.minX) / (d.maxX - d.minX)) * d.w;
|
|
193
|
+
const py = d.h - ((best.y - d.minY) / (d.maxY - d.minY)) * d.h;
|
|
194
|
+
dot.setAttribute('cx', String(px));
|
|
195
|
+
dot.setAttribute('cy', String(py));
|
|
196
|
+
dot.setAttribute('data-on', '');
|
|
197
|
+
showTip(frame.tip, props.format ? props.format(best, index) : String(best.y), { w: d.w + axisRight(), h: d.h + axisBottom() }, px, py);
|
|
198
|
+
};
|
|
199
|
+
frame.el.addEventListener('pointermove', hover);
|
|
200
|
+
frame.el.addEventListener('pointerleave', () => hover(null));
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
el: frame.el,
|
|
204
|
+
setData(next) {
|
|
205
|
+
points = next;
|
|
206
|
+
draw();
|
|
207
|
+
},
|
|
208
|
+
setAxes(on) {
|
|
209
|
+
if (on === axes) return;
|
|
210
|
+
axes = on;
|
|
211
|
+
draw();
|
|
212
|
+
},
|
|
213
|
+
destroy() {
|
|
214
|
+
frame.disconnect();
|
|
215
|
+
frame.el.remove();
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|