@antadesign/anta 0.2.2 → 0.3.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 +14 -0
- package/dist/anta_helpers.d.ts +39 -1
- package/dist/anta_helpers.js +30 -2
- package/dist/components/Button.d.ts +7 -4
- package/dist/components/Button.js +6 -11
- package/dist/components/Checkbox.d.ts +97 -0
- package/dist/components/Checkbox.js +77 -0
- package/dist/components/Expander.d.ts +74 -0
- package/dist/components/Expander.js +53 -0
- package/dist/components/Input.d.ts +159 -0
- package/dist/components/Input.js +150 -0
- package/dist/components/Menu.d.ts +70 -0
- package/dist/components/Menu.js +42 -0
- package/dist/components/MenuGroup.d.ts +24 -0
- package/dist/components/MenuGroup.js +19 -0
- package/dist/components/MenuItem.d.ts +50 -0
- package/dist/components/MenuItem.js +41 -0
- package/dist/components/MenuSeparator.d.ts +14 -0
- package/dist/components/MenuSeparator.js +7 -0
- package/dist/components/Progress.d.ts +12 -6
- package/dist/components/Progress.js +7 -4
- package/dist/components/Radio.d.ts +37 -0
- package/dist/components/Radio.js +33 -0
- package/dist/components/RadioGroup.d.ts +119 -0
- package/dist/components/RadioGroup.js +108 -0
- package/dist/components/Tag.d.ts +38 -5
- package/dist/components/Tag.js +9 -5
- package/dist/components/Text.d.ts +27 -12
- package/dist/components/Text.js +6 -3
- package/dist/components/Title.d.ts +10 -1
- package/dist/elements/a-button.css +1 -1
- package/dist/elements/a-button.d.ts +56 -0
- package/dist/elements/a-button.js +13 -11
- package/dist/elements/a-checkbox.css +1 -0
- package/dist/elements/a-checkbox.d.ts +52 -0
- package/dist/elements/a-checkbox.js +130 -0
- package/dist/elements/a-expander.css +1 -0
- package/dist/elements/a-expander.d.ts +28 -0
- package/dist/elements/a-expander.js +237 -0
- package/dist/elements/a-icon.d.ts +14 -0
- package/dist/elements/a-icon.shapes.css +1 -1
- package/dist/elements/a-icon.shapes.d.ts +9 -1
- package/dist/elements/a-icon.shapes.js +10 -1
- package/dist/elements/a-input.css +1 -0
- package/dist/elements/a-input.d.ts +68 -0
- package/dist/elements/a-input.js +511 -0
- package/dist/elements/a-menu-group.css +1 -0
- package/dist/elements/a-menu-group.d.ts +13 -0
- package/dist/elements/a-menu-group.js +15 -0
- package/dist/elements/a-menu-item.css +1 -0
- package/dist/elements/a-menu-item.d.ts +47 -0
- package/dist/elements/a-menu-item.js +30 -0
- package/dist/elements/a-menu-separator.css +1 -0
- package/dist/elements/a-menu-separator.d.ts +13 -0
- package/dist/elements/a-menu-separator.js +15 -0
- package/dist/elements/a-menu.css +1 -0
- package/dist/elements/a-menu.d.ts +171 -0
- package/dist/elements/a-menu.js +714 -0
- package/dist/elements/a-progress.css +1 -1
- package/dist/elements/a-progress.d.ts +12 -0
- package/dist/elements/a-progress.js +1 -0
- package/dist/elements/a-radio-group.css +1 -0
- package/dist/elements/a-radio-group.d.ts +33 -0
- package/dist/elements/a-radio-group.js +160 -0
- package/dist/elements/a-radio.css +1 -0
- package/dist/elements/a-radio.d.ts +14 -0
- package/dist/elements/a-radio.js +46 -0
- package/dist/elements/a-tag.css +1 -1
- package/dist/elements/a-text.css +1 -1
- package/dist/elements/a-text.d.ts +42 -3
- package/dist/elements/a-text.js +73 -33
- package/dist/elements/a-tooltip.d.ts +43 -11
- package/dist/elements/a-tooltip.js +46 -51
- package/dist/elements/index.d.ts +9 -0
- package/dist/elements/index.js +27 -0
- package/dist/general_types.d.ts +467 -15
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/jsx-runtime.d.ts +42 -7
- package/dist/jsx-runtime.js +14 -2
- package/dist/tokens.css +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
import { HTMLElementBase } from '../anta_helpers';
|
|
2
2
|
import './a-tooltip.css';
|
|
3
|
+
/**
|
|
4
|
+
* `<a-tooltip>` — floating bubble placed as a child of the element it
|
|
5
|
+
* describes.
|
|
6
|
+
*
|
|
7
|
+
* Styling notes (`a-tooltip.css` ships comment-free):
|
|
8
|
+
* - `a-tooltip:not(:defined)` is hidden — before upgrade the host is an
|
|
9
|
+
* unknown inline element and its content would flash *inside the anchor*.
|
|
10
|
+
* Once defined, the shadow `:host { display: contents }` governs and
|
|
11
|
+
* content renders only in the popover via the slot.
|
|
12
|
+
* - Only the bubble "chrome" is tokenized (`--tooltip-*`): it lives inside
|
|
13
|
+
* the shadow popover, unreachable from plain consumer CSS; the custom
|
|
14
|
+
* properties inherit across the shadow boundary. The content is slotted
|
|
15
|
+
* light DOM — its font/color/size are already styleable from the page and
|
|
16
|
+
* are intentionally NOT tokens.
|
|
17
|
+
* - The frost: `--tooltip-bg` is a mostly-opaque mix of `--bg-1` that, with
|
|
18
|
+
* the container's backdrop blur, reads as a frosted bubble. `--bg-1` is
|
|
19
|
+
* white in light / black in dark, so dark mode flips automatically (the
|
|
20
|
+
* `.dark` override just lowers the alpha and adds an inset white ring so
|
|
21
|
+
* the edge stays crisp on dark content). There's no real border by
|
|
22
|
+
* default — the hairline edge comes from `--tooltip-shadow`; set
|
|
23
|
+
* `--tooltip-border` for an actual one.
|
|
24
|
+
* - On coarse/no-hover pointers, an anchor that owns a tooltip
|
|
25
|
+
* (`:where(:has(> a-tooltip))`, specificity 0 for easy override)
|
|
26
|
+
* suppresses long-press text selection and the iOS callout so
|
|
27
|
+
* press-and-hold cleanly reveals the bubble (see the long-press handling
|
|
28
|
+
* below) instead of selecting text or popping the system menu.
|
|
29
|
+
*/
|
|
3
30
|
export declare class ATooltipElement extends HTMLElementBase {
|
|
4
31
|
static observedAttributes: string[];
|
|
5
32
|
/** Shadow-internal popover surface — the only thing we ever mutate. */
|
|
6
33
|
private container;
|
|
7
|
-
/** Inner bubble inside `.container`.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
34
|
+
/** Inner bubble inside `.container`. This IS the `<slot>` (styled
|
|
35
|
+
* `display:block`), so it both projects the content and paints all visual
|
|
36
|
+
* chrome — one element instead of a div-wrapping-a-slot. It carries the
|
|
37
|
+
* proximity (distance-from-anchor) opacity, kept separate from the
|
|
38
|
+
* container's enter/exit/cross-fade opacity. */
|
|
10
39
|
private bubble;
|
|
11
40
|
private anchor;
|
|
12
41
|
listening: boolean;
|
|
@@ -31,14 +60,6 @@ export declare class ATooltipElement extends HTMLElementBase {
|
|
|
31
60
|
* fed the latest cursor event, so it shows at the cursor and so moving back
|
|
32
61
|
* onto an anchor after the tooltip was dismissed re-arms it. */
|
|
33
62
|
private makeDebouncedShow;
|
|
34
|
-
/** The element's OWN window / document. The class may be defined in a
|
|
35
|
-
* different realm than the element lives in (e.g. the docs playground
|
|
36
|
-
* renders into an iframe but reuses the parent page's element class), so
|
|
37
|
-
* the module-global `window`/`document` can point at the wrong frame.
|
|
38
|
-
* Everything viewport- or document-scoped (clamping, scroll/key/move
|
|
39
|
-
* listeners) must go through these so it's correct in any frame. */
|
|
40
|
-
private get view();
|
|
41
|
-
private get doc();
|
|
42
63
|
private get isInteractive();
|
|
43
64
|
/** Pinned under the anchor (no cursor-following) — the DEFAULT. Following the
|
|
44
65
|
* cursor is opt-in via the `follow` attribute. `interactive` (you can't move
|
|
@@ -47,6 +68,17 @@ export declare class ATooltipElement extends HTMLElementBase {
|
|
|
47
68
|
private get isPinned();
|
|
48
69
|
private get prefersTop();
|
|
49
70
|
private get delay();
|
|
71
|
+
private positionFrame?;
|
|
72
|
+
private pendingPosition?;
|
|
73
|
+
private schedulePosition;
|
|
74
|
+
/** Pick the vertical origin: prefer the `above` candidate when `preferAbove`
|
|
75
|
+
* (auto-flipping to `below` if it'd clip the top), else `below` (flipping to
|
|
76
|
+
* `above` if it'd clip the bottom). Shared by anchor- and cursor-anchored
|
|
77
|
+
* placement — only the candidate origins differ. */
|
|
78
|
+
private flipVertical;
|
|
79
|
+
/** Clamp a candidate (left, top) into the viewport and write it as the
|
|
80
|
+
* container's transform — the single place the transform is set. */
|
|
81
|
+
private place;
|
|
50
82
|
private positionToTarget;
|
|
51
83
|
private positionToMouse;
|
|
52
84
|
private position;
|
|
@@ -64,9 +64,11 @@ class ATooltipElement extends HTMLElementBase {
|
|
|
64
64
|
static observedAttributes = ["delay"];
|
|
65
65
|
/** Shadow-internal popover surface — the only thing we ever mutate. */
|
|
66
66
|
container;
|
|
67
|
-
/** Inner bubble inside `.container`.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
67
|
+
/** Inner bubble inside `.container`. This IS the `<slot>` (styled
|
|
68
|
+
* `display:block`), so it both projects the content and paints all visual
|
|
69
|
+
* chrome — one element instead of a div-wrapping-a-slot. It carries the
|
|
70
|
+
* proximity (distance-from-anchor) opacity, kept separate from the
|
|
71
|
+
* container's enter/exit/cross-fade opacity. */
|
|
70
72
|
bubble;
|
|
71
73
|
anchor = null;
|
|
72
74
|
listening = false;
|
|
@@ -117,6 +119,7 @@ class ATooltipElement extends HTMLElementBase {
|
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
.bubble {
|
|
122
|
+
display: block;
|
|
120
123
|
box-sizing: border-box;
|
|
121
124
|
width: fit-content;
|
|
122
125
|
max-width: var(--tooltip-max-width, min(calc(100vw - 20px), 80ch));
|
|
@@ -155,10 +158,9 @@ class ATooltipElement extends HTMLElementBase {
|
|
|
155
158
|
this.container.className = "container";
|
|
156
159
|
this.container.setAttribute("popover", "manual");
|
|
157
160
|
this.container.setAttribute("role", "tooltip");
|
|
158
|
-
this.bubble = document.createElement("
|
|
161
|
+
this.bubble = document.createElement("slot");
|
|
159
162
|
this.bubble.className = "bubble";
|
|
160
163
|
this.bubble.setAttribute("part", "bubble");
|
|
161
|
-
this.bubble.append(document.createElement("slot"));
|
|
162
164
|
this.container.append(this.bubble);
|
|
163
165
|
this.container.addEventListener("mouseenter", () => {
|
|
164
166
|
if (this.isInteractive) this.cancelHide();
|
|
@@ -196,18 +198,6 @@ class ATooltipElement extends HTMLElementBase {
|
|
|
196
198
|
this.debouncedShow?.cancel();
|
|
197
199
|
this.debouncedShow = debounce((e) => this.show(e), this.delay);
|
|
198
200
|
}
|
|
199
|
-
/** The element's OWN window / document. The class may be defined in a
|
|
200
|
-
* different realm than the element lives in (e.g. the docs playground
|
|
201
|
-
* renders into an iframe but reuses the parent page's element class), so
|
|
202
|
-
* the module-global `window`/`document` can point at the wrong frame.
|
|
203
|
-
* Everything viewport- or document-scoped (clamping, scroll/key/move
|
|
204
|
-
* listeners) must go through these so it's correct in any frame. */
|
|
205
|
-
get view() {
|
|
206
|
-
return this.ownerDocument?.defaultView ?? window;
|
|
207
|
-
}
|
|
208
|
-
get doc() {
|
|
209
|
-
return this.ownerDocument ?? document;
|
|
210
|
-
}
|
|
211
201
|
get isInteractive() {
|
|
212
202
|
return this.hasAttribute("interactive");
|
|
213
203
|
}
|
|
@@ -229,49 +219,54 @@ class ATooltipElement extends HTMLElementBase {
|
|
|
229
219
|
return Number.isFinite(n) ? n : DEFAULT_DELAY;
|
|
230
220
|
}
|
|
231
221
|
// --- positioning (sets only the shadow container's own transform) ---
|
|
222
|
+
// Single pending position frame: a burst of mousemoves within one frame
|
|
223
|
+
// coalesces to ONE layout read + transform write, using the LATEST geometry
|
|
224
|
+
// (earlier samples never matter — only where the cursor ends the frame).
|
|
225
|
+
positionFrame;
|
|
226
|
+
pendingPosition;
|
|
227
|
+
schedulePosition(compute) {
|
|
228
|
+
this.pendingPosition = compute;
|
|
229
|
+
if (this.positionFrame != null) return;
|
|
230
|
+
this.positionFrame = this.view.requestAnimationFrame(() => {
|
|
231
|
+
this.positionFrame = void 0;
|
|
232
|
+
const run = this.pendingPosition;
|
|
233
|
+
this.pendingPosition = void 0;
|
|
234
|
+
run?.();
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/** Pick the vertical origin: prefer the `above` candidate when `preferAbove`
|
|
238
|
+
* (auto-flipping to `below` if it'd clip the top), else `below` (flipping to
|
|
239
|
+
* `above` if it'd clip the bottom). Shared by anchor- and cursor-anchored
|
|
240
|
+
* placement — only the candidate origins differ. */
|
|
241
|
+
flipVertical(above, below, boxHeight, vh, preferAbove) {
|
|
242
|
+
if (preferAbove) return above < MARGIN ? below : above;
|
|
243
|
+
return below + boxHeight > vh ? above : below;
|
|
244
|
+
}
|
|
245
|
+
/** Clamp a candidate (left, top) into the viewport and write it as the
|
|
246
|
+
* container's transform — the single place the transform is set. */
|
|
247
|
+
place(left, top, boxWidth, vw) {
|
|
248
|
+
if (left + boxWidth > vw) left = vw - boxWidth - MARGIN;
|
|
249
|
+
left = Math.max(MARGIN, left);
|
|
250
|
+
top = Math.max(MARGIN, top);
|
|
251
|
+
this.container.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
|
|
252
|
+
}
|
|
232
253
|
positionToTarget = () => {
|
|
233
|
-
|
|
254
|
+
this.schedulePosition(() => {
|
|
234
255
|
if (!this.anchor || !this.shown) return;
|
|
235
256
|
const a = this.anchor.getBoundingClientRect();
|
|
236
257
|
const box = this.container.getBoundingClientRect();
|
|
237
|
-
const
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
let left = a.left;
|
|
241
|
-
if (left + box.width > vw) left = vw - box.width - MARGIN;
|
|
242
|
-
left = Math.max(MARGIN, left);
|
|
243
|
-
let top;
|
|
244
|
-
if (this.prefersTop || this.touchOpen) {
|
|
245
|
-
top = a.top - box.height - MARGIN;
|
|
246
|
-
if (top < MARGIN) top = a.bottom + MARGIN;
|
|
247
|
-
} else {
|
|
248
|
-
top = a.bottom + MARGIN;
|
|
249
|
-
if (top + box.height > vh) top = a.top - box.height - MARGIN;
|
|
250
|
-
}
|
|
251
|
-
top = Math.max(MARGIN, top);
|
|
252
|
-
this.container.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
|
|
258
|
+
const { innerWidth: vw, innerHeight: vh } = this.view;
|
|
259
|
+
const top = this.flipVertical(a.top - box.height - MARGIN, a.bottom + MARGIN, box.height, vh, this.prefersTop || this.touchOpen);
|
|
260
|
+
this.place(a.left, top, box.width, vw);
|
|
253
261
|
});
|
|
254
262
|
};
|
|
255
263
|
positionToMouse = (e) => {
|
|
256
|
-
|
|
264
|
+
this.schedulePosition(() => {
|
|
257
265
|
if (!this.shown && !this.fading) return;
|
|
258
266
|
const box = this.container.getBoundingClientRect();
|
|
259
|
-
const
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
let left = e.clientX - PADDING_X;
|
|
263
|
-
if (left + box.width > vw) left = vw - box.width - MARGIN;
|
|
264
|
-
left = Math.max(MARGIN, left);
|
|
265
|
-
let top;
|
|
266
|
-
if (this.prefersTop) {
|
|
267
|
-
top = e.clientY - box.height - MARGIN * 2;
|
|
268
|
-
if (top < MARGIN) top = e.clientY + CURSOR_SIZE;
|
|
269
|
-
} else {
|
|
270
|
-
top = e.clientY + CURSOR_SIZE;
|
|
271
|
-
if (top + box.height > vh) top = e.clientY - box.height - MARGIN * 2;
|
|
272
|
-
}
|
|
273
|
-
top = Math.max(MARGIN, top);
|
|
274
|
-
this.container.style.transform = `translate(${Math.round(left)}px, ${Math.round(top)}px)`;
|
|
267
|
+
const { innerWidth: vw, innerHeight: vh } = this.view;
|
|
268
|
+
const top = this.flipVertical(e.clientY - box.height - MARGIN * 2, e.clientY + CURSOR_SIZE, box.height, vh, this.prefersTop);
|
|
269
|
+
this.place(e.clientX - PADDING_X, top, box.width, vw);
|
|
275
270
|
});
|
|
276
271
|
};
|
|
277
272
|
position(e) {
|
package/dist/elements/index.d.ts
CHANGED
|
@@ -17,6 +17,15 @@ export { AProgressElement, register_a_progress } from './a-progress';
|
|
|
17
17
|
export { ATextElement, register_a_text } from './a-text';
|
|
18
18
|
export { AIconElement, register_a_icon } from './a-icon';
|
|
19
19
|
export { AButtonElement, register_a_button } from './a-button';
|
|
20
|
+
export { ACheckboxElement, register_a_checkbox } from './a-checkbox';
|
|
21
|
+
export { AExpanderElement, register_a_expander } from './a-expander';
|
|
20
22
|
export { ATooltipElement, register_a_tooltip } from './a-tooltip';
|
|
23
|
+
export { AInputElement, register_a_input } from './a-input';
|
|
24
|
+
export { ARadioElement, register_a_radio } from './a-radio';
|
|
25
|
+
export { ARadioGroupElement, register_a_radio_group } from './a-radio-group';
|
|
26
|
+
export { AMenuElement, register_a_menu } from './a-menu';
|
|
27
|
+
export { AMenuItemElement, register_a_menu_item } from './a-menu-item';
|
|
28
|
+
export { AMenuSeparatorElement, register_a_menu_separator } from './a-menu-separator';
|
|
29
|
+
export { AMenuGroupElement, register_a_menu_group } from './a-menu-group';
|
|
21
30
|
import './a-title.css';
|
|
22
31
|
import './a-tag.css';
|
package/dist/elements/index.js
CHANGED
|
@@ -2,18 +2,45 @@ import { AProgressElement, register_a_progress } from "./a-progress";
|
|
|
2
2
|
import { ATextElement, register_a_text } from "./a-text";
|
|
3
3
|
import { AIconElement, register_a_icon } from "./a-icon";
|
|
4
4
|
import { AButtonElement, register_a_button } from "./a-button";
|
|
5
|
+
import { ACheckboxElement, register_a_checkbox } from "./a-checkbox";
|
|
6
|
+
import { AExpanderElement, register_a_expander } from "./a-expander";
|
|
5
7
|
import { ATooltipElement, register_a_tooltip } from "./a-tooltip";
|
|
8
|
+
import { AInputElement, register_a_input } from "./a-input";
|
|
9
|
+
import { ARadioElement, register_a_radio } from "./a-radio";
|
|
10
|
+
import { ARadioGroupElement, register_a_radio_group } from "./a-radio-group";
|
|
11
|
+
import { AMenuElement, register_a_menu } from "./a-menu";
|
|
12
|
+
import { AMenuItemElement, register_a_menu_item } from "./a-menu-item";
|
|
13
|
+
import { AMenuSeparatorElement, register_a_menu_separator } from "./a-menu-separator";
|
|
14
|
+
import { AMenuGroupElement, register_a_menu_group } from "./a-menu-group";
|
|
6
15
|
import "./a-title.css";
|
|
7
16
|
import "./a-tag.css";
|
|
8
17
|
export {
|
|
9
18
|
AButtonElement,
|
|
19
|
+
ACheckboxElement,
|
|
20
|
+
AExpanderElement,
|
|
10
21
|
AIconElement,
|
|
22
|
+
AInputElement,
|
|
23
|
+
AMenuElement,
|
|
24
|
+
AMenuGroupElement,
|
|
25
|
+
AMenuItemElement,
|
|
26
|
+
AMenuSeparatorElement,
|
|
11
27
|
AProgressElement,
|
|
28
|
+
ARadioElement,
|
|
29
|
+
ARadioGroupElement,
|
|
12
30
|
ATextElement,
|
|
13
31
|
ATooltipElement,
|
|
14
32
|
register_a_button,
|
|
33
|
+
register_a_checkbox,
|
|
34
|
+
register_a_expander,
|
|
15
35
|
register_a_icon,
|
|
36
|
+
register_a_input,
|
|
37
|
+
register_a_menu,
|
|
38
|
+
register_a_menu_group,
|
|
39
|
+
register_a_menu_item,
|
|
40
|
+
register_a_menu_separator,
|
|
16
41
|
register_a_progress,
|
|
42
|
+
register_a_radio,
|
|
43
|
+
register_a_radio_group,
|
|
17
44
|
register_a_text,
|
|
18
45
|
register_a_tooltip
|
|
19
46
|
};
|