material 3.16.0 → 3.16.2
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 +5 -5
- package/dist/components/bottom-sheet/features/drag.js +186 -71
- package/dist/components/button/button.js +2 -15
- package/dist/components/button/compose.js +17 -0
- package/dist/components/button/config.js +20 -2
- package/dist/components/carousel/features/scroll.js +77 -5
- package/dist/components/carousel/features/slides.js +8 -4
- package/dist/components/drawer/drawer.js +1 -0
- package/dist/components/drawer/index.d.ts +63 -10
- package/dist/components/drawer/index.js +1 -1
- package/dist/components/fab-menu/fab-menu.js +55 -10
- package/dist/components/index.js +2 -2
- package/dist/components/menu/features/position.js +18 -27
- package/dist/components/menu/types.d.ts +1 -1
- package/dist/components/search/features/input.js +12 -11
- package/dist/components/select/index.d.ts +4 -1
- package/dist/components/split-button/constants.js +1 -1
- package/dist/components/top-app-bar/index.d.ts +22 -4
- package/dist/components/top-app-bar/index.js +1 -1
- package/dist/components/top-app-bar/top-app-bar.js +1 -0
- package/dist/core/dom/placement.js +11 -0
- package/dist/elements/app-bar.js +106 -0
- package/dist/elements/button.js +3 -2
- package/dist/elements/css/bottom-sheet.css +1 -1
- package/dist/elements/css/carousel.css +1 -1
- package/dist/elements/css/dialog.css +1 -1
- package/dist/elements/css/drawer.css +1 -1
- package/dist/elements/css/fab-menu.css +1 -1
- package/dist/elements/css/fab-menu.js +1 -0
- package/dist/elements/css/hosts/app-bar.css +1 -0
- package/dist/elements/css/hosts/navigation-drawer.css +1 -0
- package/dist/elements/css/menu.css +1 -1
- package/dist/elements/css/split-button.css +1 -1
- package/dist/elements/drawer.js +4 -175
- package/dist/elements/extended-fab.js +3 -2
- package/dist/elements/fab-menu.js +1 -1
- package/dist/elements/fab.js +3 -2
- package/dist/elements/form-button.d.ts +40 -0
- package/dist/elements/form-button.js +45 -1
- package/dist/elements/icon-button.d.ts +21 -6
- package/dist/elements/icon-button.js +3 -2
- package/dist/elements/index.d.ts +492 -44
- package/dist/elements/index.js +10 -1
- package/dist/elements/navigation-drawer.js +197 -0
- package/dist/elements/preupgrade/app-bar.css +2 -0
- package/dist/elements/preupgrade/badge.css +1 -1
- package/dist/elements/preupgrade/bottom-app-bar.css +1 -1
- package/dist/elements/preupgrade/bottom-sheet.css +1 -1
- package/dist/elements/preupgrade/button-group.css +1 -1
- package/dist/elements/preupgrade/button.css +1 -1
- package/dist/elements/preupgrade/card.css +1 -1
- package/dist/elements/preupgrade/carousel.css +1 -1
- package/dist/elements/preupgrade/checkbox.css +1 -1
- package/dist/elements/preupgrade/chips.css +1 -1
- package/dist/elements/preupgrade/datepicker.css +1 -1
- package/dist/elements/preupgrade/dialog.css +1 -1
- package/dist/elements/preupgrade/divider.css +1 -1
- package/dist/elements/preupgrade/drawer.css +1 -1
- package/dist/elements/preupgrade/extended-fab.css +1 -1
- package/dist/elements/preupgrade/fab-menu.css +1 -1
- package/dist/elements/preupgrade/fab.css +1 -1
- package/dist/elements/preupgrade/icon-button.css +1 -1
- package/dist/elements/preupgrade/list.css +1 -1
- package/dist/elements/preupgrade/loading-indicator.css +1 -1
- package/dist/elements/preupgrade/menu.css +1 -1
- package/dist/elements/preupgrade/navigation-bar.css +1 -1
- package/dist/elements/preupgrade/navigation-drawer.css +2 -0
- package/dist/elements/preupgrade/navigation-rail.css +1 -1
- package/dist/elements/preupgrade/progress.css +1 -1
- package/dist/elements/preupgrade/radios.css +1 -1
- package/dist/elements/preupgrade/search.css +1 -1
- package/dist/elements/preupgrade/select.css +1 -1
- package/dist/elements/preupgrade/side-sheet.css +1 -1
- package/dist/elements/preupgrade/slider.css +1 -1
- package/dist/elements/preupgrade/snackbar.css +1 -1
- package/dist/elements/preupgrade/split-button.css +1 -1
- package/dist/elements/preupgrade/switch.css +1 -1
- package/dist/elements/preupgrade/tabs.css +1 -1
- package/dist/elements/preupgrade/text-field.css +1 -1
- package/dist/elements/preupgrade/timepicker.css +1 -1
- package/dist/elements/preupgrade/toolbar.css +1 -1
- package/dist/elements/preupgrade/tooltip.css +1 -1
- package/dist/elements/preupgrade/top-app-bar.css +1 -1
- package/dist/elements/preupgrade.css +2 -2
- package/dist/elements/split-button.js +4 -1
- package/dist/elements/styles.js +8 -8
- package/dist/elements/top-app-bar.js +2 -102
- package/dist/index.d.ts +4 -4
- package/dist/react/app-bar.js +5 -0
- package/dist/react/fab-menu.js +1 -0
- package/dist/react/index.d.ts +11 -2
- package/dist/react/index.js +3 -0
- package/dist/react/jsx.d.ts +6 -0
- package/dist/react/navigation-drawer-item.js +4 -0
- package/dist/react/navigation-drawer.js +5 -0
- package/dist/solid/app-bar.js +4 -0
- package/dist/solid/fab-menu.js +1 -0
- package/dist/solid/index.d.ts +11 -2
- package/dist/solid/index.js +3 -0
- package/dist/solid/jsx.d.ts +12 -3
- package/dist/solid/navigation-drawer-item.js +3 -0
- package/dist/solid/navigation-drawer.js +4 -0
- package/dist/styles/badge.css +1 -1
- package/dist/styles/base-elements.css +1 -1
- package/dist/styles/base-lite.css +1 -1
- package/dist/styles/base.css +1 -1
- package/dist/styles/bottom-app-bar-toolbar.css +1 -1
- package/dist/styles/bottom-app-bar.css +1 -1
- package/dist/styles/bottom-sheet.css +2 -2
- package/dist/styles/button-filled-small-round.css +1 -1
- package/dist/styles/button-group.css +1 -1
- package/dist/styles/button.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/carousel.css +2 -2
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/chips.css +1 -1
- package/dist/styles/contrast.css +1 -1
- package/dist/styles/datepicker.css +1 -1
- package/dist/styles/dialog.css +2 -2
- package/dist/styles/divider.css +1 -1
- package/dist/styles/drawer.css +2 -2
- package/dist/styles/extended-fab.css +1 -1
- package/dist/styles/fab-menu.css +2 -2
- package/dist/styles/fab-menu.js +1 -0
- package/dist/styles/fab.css +1 -1
- package/dist/styles/icon-button.css +1 -1
- package/dist/styles/list.css +1 -1
- package/dist/styles/listbox.css +1 -1
- package/dist/styles/loading-indicator.css +1 -1
- package/dist/styles/menu.css +2 -2
- package/dist/styles/navigation-bar.css +1 -1
- package/dist/styles/navigation-rail.css +1 -1
- package/dist/styles/progress.css +1 -1
- package/dist/styles/radios.css +1 -1
- package/dist/styles/search.css +1 -1
- package/dist/styles/select.css +1 -1
- package/dist/styles/side-sheet.css +1 -1
- package/dist/styles/slider.css +1 -1
- package/dist/styles/snackbar.css +1 -1
- package/dist/styles/split-button.css +2 -2
- package/dist/styles/switch.css +1 -1
- package/dist/styles/tabs.css +1 -1
- package/dist/styles/text-field.css +1 -1
- package/dist/styles/timepicker.css +1 -1
- package/dist/styles/toolbar.css +1 -1
- package/dist/styles/tooltip.css +1 -1
- package/dist/styles/top-app-bar.css +1 -1
- package/dist/styles/typography.css +1 -1
- package/dist/styles/utilities.css +1 -1
- package/dist/styles.css +2 -2
- package/dist/svelte/AppBar.svelte +25 -0
- package/dist/svelte/AppBar.svelte.d.ts +5 -0
- package/dist/svelte/Drawer.svelte.d.ts +1 -0
- package/dist/svelte/DrawerItem.svelte.d.ts +1 -0
- package/dist/svelte/FabMenu.svelte +1 -0
- package/dist/svelte/NavigationDrawer.svelte +26 -0
- package/dist/svelte/NavigationDrawer.svelte.d.ts +5 -0
- package/dist/svelte/NavigationDrawerItem.svelte +11 -0
- package/dist/svelte/NavigationDrawerItem.svelte.d.ts +5 -0
- package/dist/svelte/TopAppBar.svelte.d.ts +1 -0
- package/dist/svelte/index.d.ts +3 -0
- package/dist/svelte/index.js +3 -0
- package/dist/themes/autumn-contrast.css +1 -1
- package/dist/themes/autumn.css +2 -2
- package/dist/themes/baseline-contrast.css +1 -1
- package/dist/themes/baseline.css +1 -1
- package/dist/themes/brownbeige-contrast.css +1 -1
- package/dist/themes/brownbeige.css +1 -1
- package/dist/themes/content-contrast.css +1 -1
- package/dist/themes/content.css +1 -1
- package/dist/themes/desert-contrast.css +1 -1
- package/dist/themes/desert.css +1 -1
- package/dist/themes/expressive-contrast.css +1 -1
- package/dist/themes/expressive.css +1 -1
- package/dist/themes/fidelity-contrast.css +1 -1
- package/dist/themes/fidelity.css +1 -1
- package/dist/themes/forest-contrast.css +1 -1
- package/dist/themes/forest.css +2 -2
- package/dist/themes/fruit-salad-contrast.css +1 -1
- package/dist/themes/fruit-salad.css +1 -1
- package/dist/themes/highcontrast-contrast.css +1 -1
- package/dist/themes/highcontrast.css +1 -1
- package/dist/themes/monochrome-contrast.css +1 -1
- package/dist/themes/monochrome.css +1 -1
- package/dist/themes/neutral-contrast.css +1 -1
- package/dist/themes/neutral.css +1 -1
- package/dist/themes/ocean-contrast.css +1 -1
- package/dist/themes/ocean.css +2 -2
- package/dist/themes/rainbow-contrast.css +1 -1
- package/dist/themes/rainbow.css +1 -1
- package/dist/themes/sageivory-contrast.css +1 -1
- package/dist/themes/sageivory.css +1 -1
- package/dist/themes/spring-contrast.css +1 -1
- package/dist/themes/spring.css +2 -2
- package/dist/themes/summer-contrast.css +1 -1
- package/dist/themes/summer.css +1 -1
- package/dist/themes/sunset-contrast.css +1 -1
- package/dist/themes/sunset.css +2 -2
- package/dist/themes/tealcaramel-contrast.css +1 -1
- package/dist/themes/tealcaramel.css +1 -1
- package/dist/themes/vibrant-contrast.css +1 -1
- package/dist/themes/vibrant.css +1 -1
- package/dist/tokens/catalogue.json +12 -3
- package/dist/vue/app-bar.js +4 -0
- package/dist/vue/fab-menu.js +1 -0
- package/dist/vue/index.d.ts +11 -2
- package/dist/vue/index.js +3 -0
- package/dist/vue/navigation-drawer-item.js +3 -0
- package/dist/vue/navigation-drawer.js +4 -0
- package/package.json +1 -1
- package/src/styles/components/_bottom-sheet.scss +3 -3
- package/src/styles/components/_carousel.scss +8 -2
- package/src/styles/components/_dialog.scss +2 -1
- package/src/styles/components/_drawer.scss +10 -11
- package/src/styles/components/_fab-menu.scss +50 -9
- package/src/styles/components/_menu.scss +3 -0
- package/src/styles/components/_split-button.scss +6 -16
- package/src/styles/elements/_app-bar.scss +6 -0
- package/src/styles/elements/_drawer.scss +3 -12
- package/src/styles/elements/_index.scss +2 -0
- package/src/styles/elements/_navigation-drawer.scss +10 -0
- package/src/styles/elements/_shared-app-bar.scss +49 -0
- package/src/styles/elements/_shared-drawer.scss +18 -0
- package/src/styles/elements/_top-app-bar.scss +2 -46
- package/src/styles/themes/_autumn.scss +4 -0
- package/src/styles/themes/_forest.scss +4 -0
- package/src/styles/themes/_ocean.scss +4 -0
- package/src/styles/themes/_spring.scss +4 -0
- package/src/styles/themes/_sunset.scss +4 -0
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ Import `material/styles/button` for any other variant, size or shape. This inclu
|
|
|
60
60
|
|-------|------------|
|
|
61
61
|
| Actions | Button, Icon button, Button group, Split button, FAB, Extended FAB, FAB menu, Toolbar |
|
|
62
62
|
| Selection and input | Checkbox, Switch, Radio buttons, Chips, Slider, Text field, Select, Search, Date picker, Time picker |
|
|
63
|
-
| Navigation | Navigation bar, Navigation rail, Drawer, Tabs, Menu, Top app bar
|
|
63
|
+
| Navigation | Navigation bar, Navigation rail, Drawer, Tabs, Menu, Top app bar |
|
|
64
64
|
| Containment | Card, Carousel, List, Divider, Dialog, Bottom sheet, Side sheet |
|
|
65
65
|
| Communication | Badge, Progress, Loading indicator, Snackbar, Tooltip |
|
|
66
66
|
|
|
@@ -135,10 +135,10 @@ What a bundler keeps, minified and gzipped (kB is 1,000 bytes), measured from th
|
|
|
135
135
|
<!-- sizes -->
|
|
136
136
|
| Import | gzip |
|
|
137
137
|
|--------|-----:|
|
|
138
|
-
| `createButton` from `material`, with code splitting: the initial chunks (the progress indicator loads on demand) | 7.
|
|
139
|
-
| `createButton`, without code splitting (the progress indicator included) |
|
|
140
|
-
| `createButton`, `createTextField` and `createCheckbox`, without code splitting | 20.
|
|
141
|
-
| Everything the root exports (`export * from 'material'`), without code splitting |
|
|
138
|
+
| `createButton` from `material`, with code splitting: the initial chunks (the progress indicator loads on demand) | 7.6 kB |
|
|
139
|
+
| `createButton`, without code splitting (the progress indicator included) | 14.0 kB |
|
|
140
|
+
| `createButton`, `createTextField` and `createCheckbox`, without code splitting | 20.5 kB |
|
|
141
|
+
| Everything the root exports (`export * from 'material'`), without code splitting | 135.2 kB |
|
|
142
142
|
| `material/styles/base` | 3.1 kB |
|
|
143
143
|
| `material/styles/base-lite` | 1.7 kB |
|
|
144
144
|
| `material/styles/base` and `material/styles/button` | 5.4 kB |
|
|
@@ -1,94 +1,209 @@
|
|
|
1
|
-
import { BOTTOM_SHEET_DEFAULTS, BOTTOM_SHEET_EVENTS, BOTTOM_SHEET_STATES
|
|
1
|
+
import { BOTTOM_SHEET_DEFAULTS, BOTTOM_SHEET_EVENTS, BOTTOM_SHEET_STATES } from "../constants.js";
|
|
2
|
+
import { PREFIX } from "../../../core/config.js";
|
|
3
|
+
const { EXPANDED, PARTIAL, HIDDEN } = BOTTOM_SHEET_STATES;
|
|
4
|
+
const { POSITIONAL_THRESHOLD: POS, VELOCITY_THRESHOLD: FAST } = BOTTOM_SHEET_DEFAULTS;
|
|
5
|
+
const speedOf = (samples, now) => {
|
|
6
|
+
let i = samples.length - 1;
|
|
7
|
+
const last = samples[i];
|
|
8
|
+
if (!last || i < 1)
|
|
9
|
+
return 0;
|
|
10
|
+
while (i > 0 && samples[i - 1].y === last.y)
|
|
11
|
+
i -= 1;
|
|
12
|
+
const end = samples[i];
|
|
13
|
+
if (i === 0 || now - end.t >= 100)
|
|
14
|
+
return 0;
|
|
15
|
+
let j = i - 1;
|
|
16
|
+
while (j > 0 && end.t - samples[j - 1].t <= 100)
|
|
17
|
+
j -= 1;
|
|
18
|
+
return (end.y - samples[j].y) / Math.max(end.t - samples[j].t, 1) * 1000;
|
|
19
|
+
};
|
|
20
|
+
const aim = (at, offset, velocity) => {
|
|
21
|
+
let nearest = 0;
|
|
22
|
+
for (const point of at)
|
|
23
|
+
if (Math.abs(point - offset) < Math.abs(nearest - offset))
|
|
24
|
+
nearest = point;
|
|
25
|
+
const step = (up) => {
|
|
26
|
+
if (up)
|
|
27
|
+
return at.find((point) => point >= offset - 0.5) ?? at[at.length - 1];
|
|
28
|
+
for (let index = at.length - 1; index >= 0; index -= 1)
|
|
29
|
+
if (at[index] <= offset + 0.5)
|
|
30
|
+
return at[index];
|
|
31
|
+
return at[0];
|
|
32
|
+
};
|
|
33
|
+
if (velocity === 0)
|
|
34
|
+
return nearest;
|
|
35
|
+
const forward = velocity > 0;
|
|
36
|
+
if (Math.abs(velocity) >= FAST)
|
|
37
|
+
return step(forward);
|
|
38
|
+
const behind = step(!forward);
|
|
39
|
+
return Math.abs(behind - offset) >= POS ? step(forward) : behind;
|
|
40
|
+
};
|
|
2
41
|
export const withDrag = () => (component) => {
|
|
3
42
|
const { structure, state } = component;
|
|
4
43
|
const handle = structure.handle;
|
|
44
|
+
const node = structure.container;
|
|
5
45
|
if (!handle)
|
|
6
46
|
return { ...component, drag: { release: () => { } } };
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let offset = 0;
|
|
10
|
-
let dragging = false;
|
|
11
|
-
let
|
|
12
|
-
const
|
|
13
|
-
|
|
47
|
+
const style = node.style;
|
|
48
|
+
const view = handle.ownerDocument.defaultView;
|
|
49
|
+
let id = -1, y0 = 0, from = 0, offset = 0, full = 0, peek = 0;
|
|
50
|
+
let dragging = false, travel = 0, dragged = false, gesture = 0;
|
|
51
|
+
let samples = [];
|
|
52
|
+
const states = () => {
|
|
53
|
+
const span = Math.max(full - peek, 0);
|
|
54
|
+
const at = [0];
|
|
55
|
+
const name = [EXPANDED];
|
|
56
|
+
if (span > 1) {
|
|
57
|
+
at.push(span);
|
|
58
|
+
name.push(PARTIAL);
|
|
59
|
+
}
|
|
60
|
+
if (full > span + 1) {
|
|
61
|
+
at.push(full);
|
|
62
|
+
name.push(HIDDEN);
|
|
63
|
+
}
|
|
64
|
+
return { at, name };
|
|
14
65
|
};
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
dragged = false;
|
|
66
|
+
const place = (next) => {
|
|
67
|
+
if (full <= 0)
|
|
18
68
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
state.close();
|
|
23
|
-
else if (current === BOTTOM_SHEET_STATES.PARTIAL)
|
|
24
|
-
state.setState(BOTTOM_SHEET_STATES.EXPANDED);
|
|
25
|
-
else
|
|
26
|
-
state.open();
|
|
69
|
+
const span = Math.max(full - peek, 0);
|
|
70
|
+
style.maxHeight = `${next <= span ? full - next : peek}px`;
|
|
71
|
+
style.transform = `translateY(${next <= span ? 0 : next - span}px)`;
|
|
27
72
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
73
|
+
const clear = () => { style.transition = style.maxHeight = style.transform = ""; };
|
|
74
|
+
const settle = (next, token) => {
|
|
75
|
+
void node.offsetHeight;
|
|
76
|
+
requestAnimationFrame(() => {
|
|
77
|
+
if (token !== gesture)
|
|
78
|
+
return;
|
|
79
|
+
const reduced = view?.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches ?? false;
|
|
80
|
+
style.transition = style.transform = "";
|
|
81
|
+
if (reduced || next !== HIDDEN) {
|
|
82
|
+
style.maxHeight = "";
|
|
83
|
+
return;
|
|
39
84
|
}
|
|
40
|
-
|
|
85
|
+
requestAnimationFrame(() => {
|
|
86
|
+
if (token !== gesture)
|
|
87
|
+
return;
|
|
88
|
+
const pending = (node.getAnimations?.() ?? []).filter((animation) => animation.playState === "running");
|
|
89
|
+
const drop = () => {
|
|
90
|
+
if (token === gesture)
|
|
91
|
+
style.maxHeight = "";
|
|
41
92
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
structure.container.style.transition = "none";
|
|
49
|
-
component.emit(BOTTOM_SHEET_EVENTS.DRAG_START);
|
|
93
|
+
if (!pending.length)
|
|
94
|
+
drop();
|
|
95
|
+
else
|
|
96
|
+
void Promise.all(pending.map((animation) => animation.finished.then(drop, drop)));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
50
99
|
};
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
100
|
+
const note = (clientY) => {
|
|
101
|
+
const now = performance.now();
|
|
102
|
+
samples.push({ t: now, y: clientY });
|
|
103
|
+
if (samples.length > 12)
|
|
104
|
+
samples.shift();
|
|
105
|
+
travel = Math.max(travel, Math.abs(clientY - y0));
|
|
106
|
+
offset = Math.min(Math.max(from + clientY - y0, 0), Math.max(full, 0));
|
|
107
|
+
place(offset);
|
|
57
108
|
};
|
|
58
|
-
const
|
|
109
|
+
const finish = (clientY, flick = true) => {
|
|
59
110
|
if (!dragging)
|
|
60
111
|
return;
|
|
61
112
|
dragging = false;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
113
|
+
try {
|
|
114
|
+
handle.releasePointerCapture(id);
|
|
115
|
+
}
|
|
116
|
+
catch { }
|
|
117
|
+
if (clientY != null)
|
|
118
|
+
note(clientY);
|
|
119
|
+
const { at, name } = states();
|
|
120
|
+
const next = name[at.indexOf(aim(at, offset, flick ? speedOf(samples, performance.now()) : 0))] ?? EXPANDED;
|
|
121
|
+
samples = [];
|
|
122
|
+
if (travel > 4) {
|
|
123
|
+
dragged = true;
|
|
124
|
+
setTimeout(() => { dragged = false; }, 0);
|
|
125
|
+
}
|
|
68
126
|
const previous = state.getState();
|
|
69
|
-
|
|
70
|
-
if (next === BOTTOM_SHEET_STATES.HIDDEN)
|
|
127
|
+
if (next === HIDDEN)
|
|
71
128
|
state.close();
|
|
72
129
|
else
|
|
73
130
|
state.setState(next);
|
|
74
131
|
component.emit(BOTTOM_SHEET_EVENTS.DRAG_END, { state: next, previous });
|
|
132
|
+
settle(next, gesture);
|
|
75
133
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
134
|
+
const down = (event) => {
|
|
135
|
+
const root = node.parentElement;
|
|
136
|
+
if (dragging || event.button !== 0 || !root)
|
|
137
|
+
return;
|
|
138
|
+
gesture += 1;
|
|
139
|
+
dragging = true;
|
|
140
|
+
id = event.pointerId;
|
|
141
|
+
y0 = event.clientY;
|
|
142
|
+
travel = 0;
|
|
143
|
+
samples = [];
|
|
144
|
+
const seen = node.getBoundingClientRect();
|
|
145
|
+
const rootBox = root.getBoundingClientRect();
|
|
146
|
+
for (const animation of node.getAnimations?.() ?? [])
|
|
147
|
+
animation.cancel();
|
|
148
|
+
style.transition = "none";
|
|
149
|
+
const heightOf = (value) => { style.maxHeight = value; return node.getBoundingClientRect().height; };
|
|
150
|
+
full = heightOf("100%");
|
|
151
|
+
peek = heightOf(`var(--${PREFIX}-bottom-sheet-peek-height, 50%)`);
|
|
152
|
+
from = Math.min(Math.max(seen.top - (rootBox.bottom - full), 0), Math.max(full, 0));
|
|
153
|
+
offset = from;
|
|
154
|
+
place(offset);
|
|
155
|
+
note(event.clientY);
|
|
156
|
+
try {
|
|
157
|
+
handle.setPointerCapture(event.pointerId);
|
|
158
|
+
}
|
|
159
|
+
catch { }
|
|
160
|
+
component.emit(BOTTOM_SHEET_EVENTS.DRAG_START);
|
|
161
|
+
};
|
|
162
|
+
const move = (event) => {
|
|
163
|
+
if (!dragging || event.pointerId !== id)
|
|
164
|
+
return;
|
|
165
|
+
if (event.pointerType === "mouse" && event.buttons === 0)
|
|
166
|
+
finish(event.clientY, false);
|
|
167
|
+
else
|
|
168
|
+
note(event.clientY);
|
|
169
|
+
};
|
|
170
|
+
const up = (event) => {
|
|
171
|
+
if (event.pointerId === id)
|
|
172
|
+
finish(event.clientY);
|
|
173
|
+
};
|
|
174
|
+
const end = () => finish(undefined, false);
|
|
175
|
+
const label = () => handle.setAttribute("aria-label", state.getState() === EXPANDED ? "Close sheet" : "Expand sheet");
|
|
176
|
+
const onClick = () => {
|
|
177
|
+
if (dragged) {
|
|
178
|
+
dragged = false;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const current = state.getState();
|
|
182
|
+
if (current === EXPANDED)
|
|
183
|
+
state.close();
|
|
184
|
+
else if (current === PARTIAL)
|
|
185
|
+
state.setState(EXPANDED);
|
|
186
|
+
else
|
|
187
|
+
state.open();
|
|
93
188
|
};
|
|
189
|
+
label();
|
|
190
|
+
component.on?.(BOTTOM_SHEET_EVENTS.STATE_CHANGE, label);
|
|
191
|
+
const pairs = [
|
|
192
|
+
["pointerdown", down], ["pointermove", move],
|
|
193
|
+
["pointerup", up], ["pointercancel", end],
|
|
194
|
+
["lostpointercapture", end], ["contextmenu", end], ["click", onClick],
|
|
195
|
+
];
|
|
196
|
+
for (const [type, fn] of pairs)
|
|
197
|
+
handle.addEventListener(type, fn);
|
|
198
|
+
view?.addEventListener("blur", end);
|
|
199
|
+
return { ...component, drag: { release: () => {
|
|
200
|
+
const pending = dragging;
|
|
201
|
+
finish(undefined, false);
|
|
202
|
+
if (!pending)
|
|
203
|
+
clear();
|
|
204
|
+
for (const [type, fn] of pairs)
|
|
205
|
+
handle.removeEventListener(type, fn);
|
|
206
|
+
view?.removeEventListener("blur", end);
|
|
207
|
+
component.off?.(BOTTOM_SHEET_EVENTS.STATE_CHANGE, label);
|
|
208
|
+
} } };
|
|
94
209
|
};
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import { pipe } from "../../core/compose/index.js";
|
|
2
|
-
import { createBase, withElement } from "../../core/compose/component.js";
|
|
3
|
-
import { withEvents, withText, withIcon, withVariant, withSize, withRipple, withDisabled, withLifecycle, } from "../../core/compose/features/index.js";
|
|
4
1
|
import { withProgress } from "./features/progress.js";
|
|
5
|
-
import {
|
|
6
|
-
import { withAPI } from "./api.js";
|
|
7
|
-
import { createBaseConfig, getElementConfig, getApiConfig } from "./config.js";
|
|
2
|
+
import { composeButton } from "./compose.js";
|
|
8
3
|
const createButton = (config = {}) => {
|
|
9
|
-
const baseConfig = createBaseConfig(config);
|
|
10
4
|
try {
|
|
11
|
-
|
|
12
|
-
if (baseConfig.shape && component.element) {
|
|
13
|
-
const className = `${baseConfig.prefix}-${baseConfig.componentName}--${baseConfig.shape}`;
|
|
14
|
-
component.element.classList.add(className);
|
|
15
|
-
}
|
|
16
|
-
return component;
|
|
17
|
-
}, (comp) => withAPI(getApiConfig(comp))(comp))(baseConfig);
|
|
18
|
-
return button;
|
|
5
|
+
return composeButton(config, withProgress);
|
|
19
6
|
}
|
|
20
7
|
catch (error) {
|
|
21
8
|
console.error("Button creation error:", error);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pipe } from "../../core/compose/index.js";
|
|
2
|
+
import { createBase, withElement } from "../../core/compose/component.js";
|
|
3
|
+
import { withEvents, withText, withIcon, withVariant, withSize, withRipple, withDisabled, withLifecycle, } from "../../core/compose/features/index.js";
|
|
4
|
+
import { withToggle } from "./features/toggle.js";
|
|
5
|
+
import { withAPI } from "./api.js";
|
|
6
|
+
import { createBaseConfig, getElementConfig, getApiConfig } from "./config.js";
|
|
7
|
+
const identity = () => (component) => component;
|
|
8
|
+
export const composeButton = (config = {}, progress = identity, isolated = false) => {
|
|
9
|
+
const baseConfig = createBaseConfig(config, isolated);
|
|
10
|
+
return pipe(createBase, withEvents(), withElement(getElementConfig(baseConfig)), withVariant(baseConfig), withSize(baseConfig), withText(baseConfig), withIcon(baseConfig), withDisabled(baseConfig), withToggle(baseConfig), withRipple(baseConfig), withLifecycle(), progress(baseConfig), (component) => {
|
|
11
|
+
if (baseConfig.shape && component.element) {
|
|
12
|
+
const className = `${baseConfig.prefix}-${baseConfig.componentName}--${baseConfig.shape}`;
|
|
13
|
+
component.element.classList.add(className);
|
|
14
|
+
}
|
|
15
|
+
return component;
|
|
16
|
+
}, (comp) => withAPI(getApiConfig(comp))(comp))(baseConfig);
|
|
17
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PREFIX } from "../../core/config.js";
|
|
2
|
+
import { createComponentConfig, createElementConfig } from "../../core/config/component.js";
|
|
2
3
|
import { BUTTON_VARIANTS, BUTTON_TYPES, DEFAULT_RIPPLE_CONFIG, BUTTON_SIZES, BUTTON_SHAPES, } from "./constants.js";
|
|
3
4
|
export const defaultConfig = {
|
|
4
5
|
variant: BUTTON_VARIANTS.FILLED,
|
|
@@ -11,7 +12,24 @@ rippleConfig: {
|
|
|
11
12
|
duration: DEFAULT_RIPPLE_CONFIG.DURATION,
|
|
12
13
|
},
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
const isolatedButtonConfig = (config) => {
|
|
16
|
+
const userClassName = config.className !== undefined ? config.className : config.class;
|
|
17
|
+
const defaultClassName = defaultConfig.className !== undefined ? defaultConfig.className : defaultConfig.class;
|
|
18
|
+
const merged = {
|
|
19
|
+
...defaultConfig,
|
|
20
|
+
...config,
|
|
21
|
+
componentName: "button",
|
|
22
|
+
prefix: PREFIX,
|
|
23
|
+
className: userClassName !== undefined ? userClassName : defaultClassName,
|
|
24
|
+
};
|
|
25
|
+
if ("class" in merged && merged.className !== undefined) {
|
|
26
|
+
delete merged.class;
|
|
27
|
+
}
|
|
28
|
+
return merged;
|
|
29
|
+
};
|
|
30
|
+
export const createBaseConfig = (config = {}, isolated = false) => (isolated
|
|
31
|
+
? isolatedButtonConfig(config)
|
|
32
|
+
: createComponentConfig(defaultConfig, config, "button"));
|
|
15
33
|
export const getElementConfig = (config) => {
|
|
16
34
|
const attributes = {
|
|
17
35
|
type: config.type || "button",
|
|
@@ -23,7 +23,7 @@ const corner = cornerRadius === CAROUSEL_DEFAULTS.CORNER_RADIUS
|
|
|
23
23
|
const reduceMotion = typeof window !== "undefined" && typeof window.matchMedia === "function"
|
|
24
24
|
? window.matchMedia("(prefers-reduced-motion: reduce)")
|
|
25
25
|
: null;
|
|
26
|
-
const { element, scroller, track, slideElements } = component;
|
|
26
|
+
const { element, scroller, track, layer, slideElements } = component;
|
|
27
27
|
const prefix = component.getClass("carousel");
|
|
28
28
|
const snapClass = `${prefix}__snap`;
|
|
29
29
|
element.classList.toggle(`${prefix}--snap`, snap);
|
|
@@ -97,6 +97,30 @@ sign = rtl ? -1 : 1;
|
|
|
97
97
|
lastStyles = new WeakMap();
|
|
98
98
|
count = slideElements.length;
|
|
99
99
|
containerSize = vertical ? scroller.clientHeight : scroller.clientWidth;
|
|
100
|
+
if (variant === CAROUSEL_VARIANTS.UNCONTAINED) {
|
|
101
|
+
layer.style.position = "static";
|
|
102
|
+
layer.style.width = "";
|
|
103
|
+
layer.style.height = "";
|
|
104
|
+
layer.style.top = "";
|
|
105
|
+
layer.style.left = "";
|
|
106
|
+
layer.style.right = "";
|
|
107
|
+
}
|
|
108
|
+
else if (vertical) {
|
|
109
|
+
layer.style.position = "";
|
|
110
|
+
layer.style.width = "100%";
|
|
111
|
+
layer.style.height = `${containerSize}px`;
|
|
112
|
+
layer.style.top = "0";
|
|
113
|
+
layer.style.left = "0";
|
|
114
|
+
layer.style.right = "";
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
layer.style.position = "";
|
|
118
|
+
layer.style.width = `${containerSize}px`;
|
|
119
|
+
layer.style.height = "100%";
|
|
120
|
+
layer.style.top = "0";
|
|
121
|
+
layer.style.left = rtl ? "auto" : "0";
|
|
122
|
+
layer.style.right = rtl ? "0" : "auto";
|
|
123
|
+
}
|
|
100
124
|
currentIndex = count ? Math.min(currentIndex, count - 1) : 0;
|
|
101
125
|
if (containerSize <= 0 || count === 0) {
|
|
102
126
|
strategy = null;
|
|
@@ -154,7 +178,7 @@ let offscreen = false;
|
|
|
154
178
|
if (!isUncontained) {
|
|
155
179
|
const placement = placeItem(strategy, keylines, i, scrollOffset);
|
|
156
180
|
const visible = Math.max(0, Math.min(itemSize, placement.size));
|
|
157
|
-
start = placement.center - itemSize / 2
|
|
181
|
+
start = placement.center - itemSize / 2;
|
|
158
182
|
offscreen = placement.center + visible / 2 < -itemSize || placement.center - visible / 2 > containerSize + itemSize;
|
|
159
183
|
inset = Math.max(0, (itemSize - visible) / 2);
|
|
160
184
|
if (fadeRange > 0)
|
|
@@ -240,11 +264,14 @@ slideElements[target].focus({ preventScroll: true });
|
|
|
240
264
|
goTo(target);
|
|
241
265
|
};
|
|
242
266
|
const handleFocusIn = (e) => {
|
|
267
|
+
if (dragging)
|
|
268
|
+
return;
|
|
243
269
|
const index = indexOf(e.target);
|
|
244
270
|
if (index >= 0 && index !== currentIndex)
|
|
245
271
|
goTo(index);
|
|
246
272
|
};
|
|
247
273
|
let dragging = false;
|
|
274
|
+
let dragPointer = null;
|
|
248
275
|
let dragged = false;
|
|
249
276
|
let dragStart = 0;
|
|
250
277
|
let dragScrollStart = 0;
|
|
@@ -263,6 +290,7 @@ clearPending();
|
|
|
263
290
|
if (e.pointerType !== "mouse" || e.button !== 0 || !strategy)
|
|
264
291
|
return;
|
|
265
292
|
dragging = true;
|
|
293
|
+
dragPointer = e.pointerId;
|
|
266
294
|
lastWheel = -Infinity;
|
|
267
295
|
dragged = false;
|
|
268
296
|
dragStart = vertical ? e.clientY : e.clientX;
|
|
@@ -272,16 +300,37 @@ dragVelocity = 0;
|
|
|
272
300
|
dragScrollStart = scroller[vertical ? "scrollTop" : "scrollLeft"];
|
|
273
301
|
restoreSnap();
|
|
274
302
|
element.dataset.settling = "true";
|
|
275
|
-
|
|
303
|
+
};
|
|
304
|
+
const endDrag = (e) => {
|
|
305
|
+
if (!dragging)
|
|
306
|
+
return;
|
|
307
|
+
if (e && dragPointer !== null && "pointerId" in e && e.pointerId !== dragPointer)
|
|
308
|
+
return;
|
|
309
|
+
dragging = false;
|
|
310
|
+
dragPointer = null;
|
|
311
|
+
dragged = false;
|
|
312
|
+
delete element.dataset.dragging;
|
|
313
|
+
restoreSnap();
|
|
276
314
|
};
|
|
277
315
|
const handlePointerMove = (e) => {
|
|
278
316
|
if (!dragging)
|
|
279
317
|
return;
|
|
318
|
+
if (dragPointer !== null && e.pointerId !== dragPointer)
|
|
319
|
+
return;
|
|
320
|
+
if (e.buttons === 0) {
|
|
321
|
+
if (scroller.hasPointerCapture(e.pointerId))
|
|
322
|
+
scroller.releasePointerCapture(e.pointerId);
|
|
323
|
+
endDrag(e);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
280
326
|
const position = vertical ? e.clientY : e.clientX;
|
|
281
327
|
const delta = position - dragStart;
|
|
282
328
|
if (!dragged && Math.abs(delta) < DRAG_THRESHOLD)
|
|
283
329
|
return;
|
|
330
|
+
if (!dragged) {
|
|
284
331
|
dragged = true;
|
|
332
|
+
scroller.setPointerCapture(e.pointerId);
|
|
333
|
+
}
|
|
285
334
|
element.dataset.dragging = "true";
|
|
286
335
|
const dt = e.timeStamp - dragLastTime;
|
|
287
336
|
if (dt > 0)
|
|
@@ -294,7 +343,10 @@ e.preventDefault();
|
|
|
294
343
|
const handlePointerUp = (e) => {
|
|
295
344
|
if (!dragging)
|
|
296
345
|
return;
|
|
346
|
+
if (dragPointer !== null && e.pointerId !== dragPointer)
|
|
347
|
+
return;
|
|
297
348
|
dragging = false;
|
|
349
|
+
dragPointer = null;
|
|
298
350
|
if (scroller.hasPointerCapture(e.pointerId))
|
|
299
351
|
scroller.releasePointerCapture(e.pointerId);
|
|
300
352
|
delete element.dataset.dragging;
|
|
@@ -321,7 +373,17 @@ if (dragged) {
|
|
|
321
373
|
dragged = false;
|
|
322
374
|
e.preventDefault();
|
|
323
375
|
e.stopPropagation();
|
|
376
|
+
return;
|
|
324
377
|
}
|
|
378
|
+
const slide = e.composedPath().find((node) => slideElements.includes(node));
|
|
379
|
+
if (slide) {
|
|
380
|
+
const index = slideElements.indexOf(slide);
|
|
381
|
+
if (index !== currentIndex)
|
|
382
|
+
goTo(index);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const handleDragStart = (e) => {
|
|
386
|
+
e.preventDefault();
|
|
325
387
|
};
|
|
326
388
|
let wheelDirection = 0;
|
|
327
389
|
let wheelStart = 0;
|
|
@@ -439,8 +501,13 @@ scroller.addEventListener("focusin", handleFocusIn);
|
|
|
439
501
|
scroller.addEventListener("pointerdown", handlePointerDown);
|
|
440
502
|
scroller.addEventListener("pointermove", handlePointerMove);
|
|
441
503
|
scroller.addEventListener("pointerup", handlePointerUp);
|
|
442
|
-
|
|
504
|
+
window.addEventListener("pointerup", handlePointerUp, { capture: true });
|
|
505
|
+
window.addEventListener("pointercancel", endDrag, { capture: true });
|
|
506
|
+
scroller.addEventListener("pointercancel", endDrag);
|
|
507
|
+
scroller.addEventListener("lostpointercapture", endDrag);
|
|
508
|
+
scroller.addEventListener("dragstart", handleDragStart);
|
|
443
509
|
scroller.addEventListener("click", handleClick, true);
|
|
510
|
+
window.addEventListener("blur", endDrag);
|
|
444
511
|
reduceMotion?.addEventListener?.("change", rebuild);
|
|
445
512
|
const resizeObserver = typeof ResizeObserver === "function" ? new ResizeObserver(rebuild) : null;
|
|
446
513
|
resizeObserver?.observe(scroller);
|
|
@@ -472,8 +539,13 @@ scroller.removeEventListener("focusin", handleFocusIn);
|
|
|
472
539
|
scroller.removeEventListener("pointerdown", handlePointerDown);
|
|
473
540
|
scroller.removeEventListener("pointermove", handlePointerMove);
|
|
474
541
|
scroller.removeEventListener("pointerup", handlePointerUp);
|
|
475
|
-
|
|
542
|
+
window.removeEventListener("pointerup", handlePointerUp, { capture: true });
|
|
543
|
+
window.removeEventListener("pointercancel", endDrag, { capture: true });
|
|
544
|
+
scroller.removeEventListener("pointercancel", endDrag);
|
|
545
|
+
scroller.removeEventListener("lostpointercapture", endDrag);
|
|
546
|
+
scroller.removeEventListener("dragstart", handleDragStart);
|
|
476
547
|
scroller.removeEventListener("click", handleClick, true);
|
|
548
|
+
window.removeEventListener("blur", endDrag);
|
|
477
549
|
destroy?.();
|
|
478
550
|
},
|
|
479
551
|
};
|
|
@@ -6,6 +6,9 @@ const scroller = document.createElement("div");
|
|
|
6
6
|
scroller.className = `${prefix}__scroller`;
|
|
7
7
|
const track = document.createElement("div");
|
|
8
8
|
track.className = `${prefix}__track`;
|
|
9
|
+
const layer = document.createElement("div");
|
|
10
|
+
layer.className = `${prefix}__layer`;
|
|
11
|
+
track.appendChild(layer);
|
|
9
12
|
scroller.appendChild(track);
|
|
10
13
|
component.element.appendChild(scroller);
|
|
11
14
|
const slideData = [];
|
|
@@ -92,11 +95,11 @@ const at = index !== undefined && index >= 0 && index <= slideData.length ? inde
|
|
|
92
95
|
const el = createSlideElement(slide, at);
|
|
93
96
|
slideData.splice(at, 0, slide);
|
|
94
97
|
if (at < slideElements.length) {
|
|
95
|
-
|
|
98
|
+
layer.insertBefore(el, slideElements[at]);
|
|
96
99
|
slideElements.splice(at, 0, el);
|
|
97
100
|
}
|
|
98
101
|
else {
|
|
99
|
-
|
|
102
|
+
layer.appendChild(el);
|
|
100
103
|
slideElements.push(el);
|
|
101
104
|
}
|
|
102
105
|
changed();
|
|
@@ -105,7 +108,7 @@ return slides;
|
|
|
105
108
|
removeSlide(index) {
|
|
106
109
|
if (index < 0 || index >= slideElements.length)
|
|
107
110
|
return slides;
|
|
108
|
-
|
|
111
|
+
layer.removeChild(slideElements[index]);
|
|
109
112
|
slideElements.splice(index, 1);
|
|
110
113
|
slideData.splice(index, 1);
|
|
111
114
|
changed();
|
|
@@ -125,6 +128,7 @@ getElements: () => slideElements.slice(),
|
|
|
125
128
|
};
|
|
126
129
|
enhanced.scroller = scroller;
|
|
127
130
|
enhanced.track = track;
|
|
131
|
+
enhanced.layer = layer;
|
|
128
132
|
enhanced.slides = slides;
|
|
129
133
|
enhanced.slideElements = slideElements;
|
|
130
134
|
enhanced.onSlidesChanged = (handler) => {
|
|
@@ -134,7 +138,7 @@ slidesChanged = handler;
|
|
|
134
138
|
const el = createSlideElement(slide, i);
|
|
135
139
|
slideData.push(slide);
|
|
136
140
|
slideElements.push(el);
|
|
137
|
-
|
|
141
|
+
layer.appendChild(el);
|
|
138
142
|
});
|
|
139
143
|
relabel();
|
|
140
144
|
return enhanced;
|