@m3ui-vue/m3ui-vue 0.6.4 → 0.7.1
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 +4 -0
- package/dist/{MMenuItem-C7jKU-Qh.js → MMenuItem-xQ1x6-DH.js} +38 -21
- package/dist/MMenuItem-xQ1x6-DH.js.map +1 -0
- package/dist/code-editor.js +1 -1
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MFab.vue.d.ts +24 -2
- package/dist/components/MFabMenu.vue.d.ts +37 -0
- package/dist/components/MLoadingIndicator.vue.d.ts +13 -0
- package/dist/components/MPullToRefresh.vue.d.ts +30 -0
- package/dist/components/MSearchBar.vue.d.ts +57 -0
- package/dist/components/MSwitch.vue.d.ts +2 -0
- package/dist/components/MTopAppBar.vue.d.ts +4 -0
- package/dist/composables/useLocale.d.ts +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/locales/index.js +7 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +2031 -1539
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles/theme.css +1 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-BKsIWNix.js → useLocale-DbREg9Zn.js} +2 -1
- package/dist/useLocale-DbREg9Zn.js.map +1 -0
- package/package.json +1 -1
- package/src/components/MAutocomplete.vue +1 -1
- package/src/components/MBottomSheet.vue +1 -1
- package/src/components/MButton.vue +18 -2
- package/src/components/MCard.vue +10 -1
- package/src/components/MCheckbox.vue +38 -23
- package/src/components/MChip.vue +10 -1
- package/src/components/MColorPickerModal.vue +1 -1
- package/src/components/MCommandPalette.vue +1 -1
- package/src/components/MDatePickerModal.vue +1 -1
- package/src/components/MDateRangePickerModal.vue +1 -1
- package/src/components/MDialog.vue +1 -1
- package/src/components/MFab.vue +66 -11
- package/src/components/MFabMenu.vue +167 -0
- package/src/components/MIconButton.vue +16 -2
- package/src/components/MLoadingIndicator.vue +184 -0
- package/src/components/MMultiAutocomplete.vue +1 -1
- package/src/components/MMultiSelect.vue +1 -1
- package/src/components/MNavigationDrawer.vue +1 -1
- package/src/components/MOverlay.vue +1 -1
- package/src/components/MPullToRefresh.vue +180 -0
- package/src/components/MRadio.vue +38 -36
- package/src/components/MSearchBar.vue +237 -0
- package/src/components/MSelect.vue +1 -1
- package/src/components/MSideSheet.vue +1 -1
- package/src/components/MSlider.vue +42 -20
- package/src/components/MSpotlightSearch.vue +1 -1
- package/src/components/MSwitch.vue +54 -27
- package/src/components/MTabs.vue +72 -33
- package/src/components/MTimePickerModal.vue +1 -1
- package/src/components/MTopAppBar.vue +16 -8
- package/src/components/MTour.vue +1 -1
- package/src/composables/useLocale.ts +2 -0
- package/src/index.ts +5 -0
- package/src/locales/de.ts +1 -0
- package/src/locales/es.ts +1 -0
- package/src/locales/fr.ts +1 -0
- package/src/locales/ja.ts +1 -0
- package/src/locales/ko.ts +1 -0
- package/src/locales/pt.ts +1 -0
- package/src/locales/zh.ts +1 -0
- package/src/styles/theme.css +1 -0
- package/dist/MMenuItem-C7jKU-Qh.js.map +0 -1
- package/dist/useLocale-BKsIWNix.js.map +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import MFab from './MFab.vue'
|
|
4
|
+
import MIcon from './MIcon.vue'
|
|
5
|
+
|
|
6
|
+
export interface FabMenuItem {
|
|
7
|
+
icon: string
|
|
8
|
+
label: string
|
|
9
|
+
to?: string | Record<string, any>
|
|
10
|
+
onClick?: () => void
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
/** Overrides the menu's own `color` for just this row. */
|
|
13
|
+
color?: 'primary' | 'secondary' | 'tertiary' | 'surface'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const props = withDefaults(
|
|
17
|
+
defineProps<{
|
|
18
|
+
icon: string
|
|
19
|
+
/** Shows the trigger as an extended FAB (icon + text) instead of icon-only. */
|
|
20
|
+
label?: string
|
|
21
|
+
items: FabMenuItem[]
|
|
22
|
+
color?: 'primary' | 'secondary' | 'tertiary' | 'surface'
|
|
23
|
+
/** Trigger FAB size — independent from `itemSize` below. */
|
|
24
|
+
size?: 'small' | 'regular' | 'large'
|
|
25
|
+
/** Menu item row size — independent from the trigger FAB's own `size`. */
|
|
26
|
+
itemSize?: 'small' | 'regular' | 'large'
|
|
27
|
+
direction?: 'up' | 'down'
|
|
28
|
+
align?: 'start' | 'end'
|
|
29
|
+
scrim?: boolean
|
|
30
|
+
persistent?: boolean
|
|
31
|
+
disabled?: boolean
|
|
32
|
+
}>(),
|
|
33
|
+
{
|
|
34
|
+
color: 'primary',
|
|
35
|
+
size: 'regular',
|
|
36
|
+
itemSize: 'large',
|
|
37
|
+
direction: 'up',
|
|
38
|
+
align: 'end',
|
|
39
|
+
scrim: true,
|
|
40
|
+
persistent: false,
|
|
41
|
+
disabled: false,
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
// Same role/container pairing MFab itself uses for its trigger, applied here
|
|
46
|
+
// to each menu item row — matches the real M3 FloatingActionButtonMenuItem,
|
|
47
|
+
// whose default container color is the color role's *Container, not a
|
|
48
|
+
// neutral surface tone.
|
|
49
|
+
const colorMap: Record<string, string> = {
|
|
50
|
+
primary: 'bg-primary-container text-on-primary-container',
|
|
51
|
+
secondary: 'bg-secondary-container text-on-secondary-container',
|
|
52
|
+
tertiary: 'bg-tertiary-container text-on-tertiary-container',
|
|
53
|
+
surface: 'bg-surface-container-high text-primary',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 'large' matches the real FabMenuBaselineTokens: 56dp row height (py-4 +
|
|
57
|
+
// 24px icon/line-height ≈ 56px), 24dp icon, 24dp horizontal padding, 8dp
|
|
58
|
+
// icon-label gap, titleMedium text — and is the default, matching M3.
|
|
59
|
+
const sizeClasses: Record<string, string> = {
|
|
60
|
+
small: 'gap-2 px-3 py-2 text-label-medium',
|
|
61
|
+
regular: 'gap-3 px-4 py-2.5 text-label-large',
|
|
62
|
+
large: 'gap-2 px-6 py-4 text-title-medium',
|
|
63
|
+
}
|
|
64
|
+
const iconSize: Record<string, number> = { small: 18, regular: 20, large: 24 }
|
|
65
|
+
|
|
66
|
+
// Ported from androidx.compose.material3.FloatingActionButtonMenuItem: each
|
|
67
|
+
// row reveals via its own width growth + fade (no group-level scale, no
|
|
68
|
+
// circular mask), staggered starting from the item closest to the FAB.
|
|
69
|
+
// Reveal direction (which side the content wipes in from) follows `align`,
|
|
70
|
+
// same as which edge the whole menu is anchored to.
|
|
71
|
+
const revealClass = computed(() => (props.align === 'start' ? 'm3-fabmenu-item--from-start' : 'm3-fabmenu-item--from-end'))
|
|
72
|
+
|
|
73
|
+
function handleItemClick(item: FabMenuItem, close: () => void) {
|
|
74
|
+
if (item.disabled) return
|
|
75
|
+
if (!props.persistent) close()
|
|
76
|
+
item.onClick?.()
|
|
77
|
+
}
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<template>
|
|
81
|
+
<MFab
|
|
82
|
+
:icon="icon"
|
|
83
|
+
:label="label"
|
|
84
|
+
:color="color"
|
|
85
|
+
:size="size"
|
|
86
|
+
:direction="direction"
|
|
87
|
+
:align="align"
|
|
88
|
+
:scrim="scrim"
|
|
89
|
+
:persistent="persistent"
|
|
90
|
+
:disabled="disabled"
|
|
91
|
+
content-transition="fade"
|
|
92
|
+
>
|
|
93
|
+
<template #content="{ close }">
|
|
94
|
+
<TransitionGroup
|
|
95
|
+
name="m3-fabmenu-item"
|
|
96
|
+
tag="div"
|
|
97
|
+
appear
|
|
98
|
+
class="relative"
|
|
99
|
+
:class="direction === 'up' ? 'flex flex-col-reverse gap-2' : 'flex flex-col gap-2'"
|
|
100
|
+
>
|
|
101
|
+
<component
|
|
102
|
+
:is="item.to ? 'RouterLink' : 'button'"
|
|
103
|
+
v-for="(item, i) in items"
|
|
104
|
+
:key="i"
|
|
105
|
+
:to="item.to || undefined"
|
|
106
|
+
:type="item.to ? undefined : 'button'"
|
|
107
|
+
class="m3-fabmenu-item shrink-0 cursor-pointer rounded-full font-medium shadow-elevation-1 transition-shadow duration-150 hover:shadow-elevation-2 disabled:cursor-not-allowed disabled:opacity-[0.38]"
|
|
108
|
+
:class="[colorMap[item.color ?? color], revealClass]"
|
|
109
|
+
:style="{ '--m3-fabmenu-delay': `${i * 35}ms` }"
|
|
110
|
+
:disabled="item.disabled"
|
|
111
|
+
@click="handleItemClick(item, close)"
|
|
112
|
+
>
|
|
113
|
+
<span class="m3-fabmenu-item-inner flex items-center whitespace-nowrap" :class="sizeClasses[itemSize]">
|
|
114
|
+
<MIcon :name="item.icon" :size="iconSize[itemSize]" class="shrink-0" />
|
|
115
|
+
{{ item.label }}
|
|
116
|
+
</span>
|
|
117
|
+
</component>
|
|
118
|
+
</TransitionGroup>
|
|
119
|
+
</template>
|
|
120
|
+
</MFab>
|
|
121
|
+
</template>
|
|
122
|
+
|
|
123
|
+
<style scoped>
|
|
124
|
+
/* Two springs run together, per item, approximating the real component:
|
|
125
|
+
- width (clip-path here, to avoid layout reflow) is roughly FastSpatial
|
|
126
|
+
(dampingRatio 0.6, stiffness 800) — fast with a gentle bouncy overshoot.
|
|
127
|
+
- opacity is roughly FastEffects (dampingRatio 1.0, stiffness 3800) —
|
|
128
|
+
no bounce, a touch faster than the width settles.
|
|
129
|
+
Staggered by --m3-fabmenu-delay on the way in, starting from the item
|
|
130
|
+
closest to the FAB. Closing is a single simultaneous fade for every item
|
|
131
|
+
instead of a reverse stagger — real M3 does stagger the close too, but
|
|
132
|
+
that needs MFab's own panel-close timing to know each item's delay, which
|
|
133
|
+
isn't worth the coupling; this keeps the two independent. */
|
|
134
|
+
.m3-fabmenu-item-inner {
|
|
135
|
+
clip-path: inset(0 0 0 0%);
|
|
136
|
+
transition: clip-path 220ms cubic-bezier(0.3, 1.2, 0.4, 1);
|
|
137
|
+
}
|
|
138
|
+
.m3-fabmenu-item-enter-active .m3-fabmenu-item-inner {
|
|
139
|
+
transition-delay: var(--m3-fabmenu-delay, 0ms);
|
|
140
|
+
}
|
|
141
|
+
.m3-fabmenu-item-enter-active,
|
|
142
|
+
.m3-fabmenu-item-leave-active {
|
|
143
|
+
transition: opacity 140ms ease-out;
|
|
144
|
+
}
|
|
145
|
+
.m3-fabmenu-item-enter-active {
|
|
146
|
+
transition-delay: var(--m3-fabmenu-delay, 0ms);
|
|
147
|
+
}
|
|
148
|
+
.m3-fabmenu-item-enter-from,
|
|
149
|
+
.m3-fabmenu-item-leave-to {
|
|
150
|
+
opacity: 0;
|
|
151
|
+
}
|
|
152
|
+
.m3-fabmenu-item--from-end.m3-fabmenu-item-enter-from .m3-fabmenu-item-inner,
|
|
153
|
+
.m3-fabmenu-item--from-end.m3-fabmenu-item-leave-to .m3-fabmenu-item-inner {
|
|
154
|
+
clip-path: inset(0 0 0 100%);
|
|
155
|
+
}
|
|
156
|
+
.m3-fabmenu-item--from-start.m3-fabmenu-item-enter-from .m3-fabmenu-item-inner,
|
|
157
|
+
.m3-fabmenu-item--from-start.m3-fabmenu-item-leave-to .m3-fabmenu-item-inner {
|
|
158
|
+
clip-path: inset(0 100% 0 0);
|
|
159
|
+
}
|
|
160
|
+
@media (prefers-reduced-motion: reduce) {
|
|
161
|
+
.m3-fabmenu-item-inner,
|
|
162
|
+
.m3-fabmenu-item-enter-active,
|
|
163
|
+
.m3-fabmenu-item-leave-active {
|
|
164
|
+
transition: none;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
</style>
|
|
@@ -37,7 +37,21 @@ const resolved = computed(() => {
|
|
|
37
37
|
|
|
38
38
|
const base =
|
|
39
39
|
'inline-flex shrink-0 items-center justify-center transition-colors duration-150 cursor-pointer ' +
|
|
40
|
-
'disabled:cursor-not-allowed disabled:
|
|
40
|
+
'disabled:cursor-not-allowed disabled:text-on-surface/38'
|
|
41
|
+
|
|
42
|
+
// M3 disabled tokens: container at 12% on-surface (filled/tonal/outlined have one,
|
|
43
|
+
// standard doesn't), icon content always at 38% on-surface (handled in `base` above).
|
|
44
|
+
const disabledContainerClasses = computed(() => {
|
|
45
|
+
switch (props.variant) {
|
|
46
|
+
case 'filled':
|
|
47
|
+
case 'tonal':
|
|
48
|
+
return 'disabled:bg-on-surface/12'
|
|
49
|
+
case 'outlined':
|
|
50
|
+
return 'disabled:border-on-surface/12'
|
|
51
|
+
default:
|
|
52
|
+
return ''
|
|
53
|
+
}
|
|
54
|
+
})
|
|
41
55
|
|
|
42
56
|
const shapeClass = computed(() => props.shape === 'squared' ? 'rounded-md' : 'rounded-full')
|
|
43
57
|
|
|
@@ -74,7 +88,7 @@ const variantClasses = computed(() => {
|
|
|
74
88
|
:type="to ? undefined : 'button'"
|
|
75
89
|
:aria-label="label || undefined"
|
|
76
90
|
:disabled="disabled"
|
|
77
|
-
:class="[base, shapeClass, variantClasses, 'relative overflow-hidden']"
|
|
91
|
+
:class="[base, shapeClass, variantClasses, disabledContainerClasses, 'relative overflow-hidden']"
|
|
78
92
|
:style="{ width: `${resolved.px}px`, height: `${resolved.px}px` }"
|
|
79
93
|
@pointerdown="createRipple"
|
|
80
94
|
>
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onMounted, onUnmounted, ref } from "vue";
|
|
3
|
+
import { useLocale } from '../composables/useLocale';
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
size?: number;
|
|
8
|
+
contained?: boolean;
|
|
9
|
+
color?: "primary" | "secondary" | "tertiary" | "error";
|
|
10
|
+
label?: string;
|
|
11
|
+
}>(),
|
|
12
|
+
{ size: 48, contained: false, color: "primary" },
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const locale = useLocale();
|
|
16
|
+
|
|
17
|
+
const colorMap: Record<"primary" | "secondary" | "tertiary" | "error", { active: string; container: string }> = {
|
|
18
|
+
primary: { active: "var(--color-primary)", container: "var(--color-primary-container)" },
|
|
19
|
+
secondary: { active: "var(--color-secondary)", container: "var(--color-secondary-container)" },
|
|
20
|
+
tertiary: { active: "var(--color-tertiary)", container: "var(--color-tertiary-container)" },
|
|
21
|
+
error: { active: "var(--color-error)", container: "var(--color-error-container)" },
|
|
22
|
+
};
|
|
23
|
+
const svgColor = computed(() => colorMap[props.color]);
|
|
24
|
+
|
|
25
|
+
const innerSize = computed(() => (props.contained ? Math.round(props.size * 0.55) : props.size));
|
|
26
|
+
|
|
27
|
+
// ── Shape morph geometry ───────────────────────────────────────────────────
|
|
28
|
+
// Every shape is sampled as a radius multiplier at the same K angles, so any
|
|
29
|
+
// two shapes can be linearly interpolated point-by-point into a smooth
|
|
30
|
+
// in-between silhouette — the same trick as MSpinner's wavy path, applied to
|
|
31
|
+
// a rotating cast of shapes instead of a single fixed waveform.
|
|
32
|
+
const K = 120;
|
|
33
|
+
const R = 36;
|
|
34
|
+
// Hard ceiling on the sampled radius: the spring's overshoot can transiently
|
|
35
|
+
// push a point's interpolated radius past both shapes' own peaks, and the
|
|
36
|
+
// most eccentric shape (pill) already sits close to the viewBox edge — this
|
|
37
|
+
// keeps every shape's silhouette fully inside the 0..100 viewBox at all times.
|
|
38
|
+
const MAX_R = 47;
|
|
39
|
+
const angles: number[] = [];
|
|
40
|
+
const cosT: number[] = [];
|
|
41
|
+
const sinT: number[] = [];
|
|
42
|
+
for (let i = 0; i < K; i++) {
|
|
43
|
+
const theta = (2 * Math.PI * i) / K - Math.PI / 2;
|
|
44
|
+
angles.push(theta);
|
|
45
|
+
cosT.push(Math.cos(theta));
|
|
46
|
+
sinT.push(Math.sin(theta));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Same seven-shape sequence (and rough proportions) as Google's own
|
|
50
|
+
// androidx.compose.material3.LoadingIndicator: SoftBurst → Cookie9Sided →
|
|
51
|
+
// Pentagon → Pill → Sunny → Cookie4Sided → Oval → (loops back to SoftBurst).
|
|
52
|
+
// Exact vertex data isn't public outside the Kotlin source, so each is
|
|
53
|
+
// approximated as a radius multiplier at the same K angles as the rest.
|
|
54
|
+
type ShapeFn = (theta: number) => number;
|
|
55
|
+
function ellipse(a: number, b: number): ShapeFn {
|
|
56
|
+
return (t) => (a * b) / Math.sqrt((b * Math.cos(t)) ** 2 + (a * Math.sin(t)) ** 2);
|
|
57
|
+
}
|
|
58
|
+
const shapeFns: ShapeFn[] = [
|
|
59
|
+
(t) => 1 + 0.07 * Math.cos(10 * t), // soft burst
|
|
60
|
+
(t) => 1 + 0.15 * Math.cos(9 * t), // cookie (9 lobes)
|
|
61
|
+
(t) => 1 + 0.1 * Math.cos(5 * t) + 0.02 * Math.cos(10 * t), // pentagon
|
|
62
|
+
ellipse(1.3, 0.7), // pill
|
|
63
|
+
(t) => 1 + 0.22 * Math.cos(8 * t), // sunny (8-point burst)
|
|
64
|
+
(t) => 1 + 0.16 * Math.cos(4 * t), // cookie (4 lobes)
|
|
65
|
+
ellipse(1.2, 0.8), // oval
|
|
66
|
+
];
|
|
67
|
+
const shapes: number[][] = shapeFns.map((fn) => angles.map(fn));
|
|
68
|
+
const SHAPE_COUNT = shapes.length;
|
|
69
|
+
|
|
70
|
+
// Timing/physics mirror the real component: ~650ms per shape, morphed by an
|
|
71
|
+
// underdamped spring (dampingRatio 0.6, stiffness 200) rather than a fixed
|
|
72
|
+
// easing curve — it overshoots slightly and settles, which is what reads as
|
|
73
|
+
// a "bounce". The exact same progress value drives a synced +90° rotation
|
|
74
|
+
// swing on top of a slow constant spin, so the turn is what visually carries
|
|
75
|
+
// the shape change instead of the two feeling like separate animations.
|
|
76
|
+
const MORPH_INTERVAL_MS = 650;
|
|
77
|
+
const GLOBAL_ROTATION_MS = 4666;
|
|
78
|
+
const DAMPING = 0.6;
|
|
79
|
+
const OMEGA_N = Math.sqrt(200);
|
|
80
|
+
const OMEGA_D = OMEGA_N * Math.sqrt(1 - DAMPING * DAMPING);
|
|
81
|
+
|
|
82
|
+
function springProgress(tSec: number): number {
|
|
83
|
+
if (tSec <= 0) return 0;
|
|
84
|
+
const decay = Math.exp(-DAMPING * OMEGA_N * tSec);
|
|
85
|
+
return 1 - decay * (Math.cos(OMEGA_D * tSec) + ((DAMPING * OMEGA_N) / OMEGA_D) * Math.sin(OMEGA_D * tSec));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function easeInOut(t: number) {
|
|
89
|
+
return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const ptX = new Float64Array(K);
|
|
93
|
+
const ptY = new Float64Array(K);
|
|
94
|
+
|
|
95
|
+
// Straight segments between the K sampled points would facet visibly on the
|
|
96
|
+
// more eccentric shapes (the pill/oval's tips are high-curvature and get
|
|
97
|
+
// under-sampled by uniform angle steps) — a closed Catmull-Rom spline
|
|
98
|
+
// (converted to cubic Béziers) keeps every edge tangent-smooth regardless.
|
|
99
|
+
function buildPath(from: number[], to: number[], f: number): string {
|
|
100
|
+
for (let i = 0; i < K; i++) {
|
|
101
|
+
const r = Math.min(R * (from[i]! + (to[i]! - from[i]!) * f), MAX_R);
|
|
102
|
+
ptX[i] = 50 + r * cosT[i]!;
|
|
103
|
+
ptY[i] = 50 + r * sinT[i]!;
|
|
104
|
+
}
|
|
105
|
+
let d = `M${ptX[0]!.toFixed(2)},${ptY[0]!.toFixed(2)}`;
|
|
106
|
+
for (let i = 0; i < K; i++) {
|
|
107
|
+
const i0 = (i - 1 + K) % K;
|
|
108
|
+
const i1 = i;
|
|
109
|
+
const i2 = (i + 1) % K;
|
|
110
|
+
const i3 = (i + 2) % K;
|
|
111
|
+
const c1x = ptX[i1]! + (ptX[i2]! - ptX[i0]!) / 6;
|
|
112
|
+
const c1y = ptY[i1]! + (ptY[i2]! - ptY[i0]!) / 6;
|
|
113
|
+
const c2x = ptX[i2]! - (ptX[i3]! - ptX[i1]!) / 6;
|
|
114
|
+
const c2y = ptY[i2]! - (ptY[i3]! - ptY[i1]!) / 6;
|
|
115
|
+
d += `C${c1x.toFixed(2)},${c1y.toFixed(2)},${c2x.toFixed(2)},${c2y.toFixed(2)},${ptX[i2]!.toFixed(2)},${ptY[i2]!.toFixed(2)}`;
|
|
116
|
+
}
|
|
117
|
+
return d + "Z";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const pathEl = ref<SVGPathElement | null>(null);
|
|
121
|
+
const svgEl = ref<SVGSVGElement | null>(null);
|
|
122
|
+
const prefersReducedMotion = ref(false);
|
|
123
|
+
|
|
124
|
+
let rafId = 0;
|
|
125
|
+
let mountTime = -1;
|
|
126
|
+
let shapeIndex = 0;
|
|
127
|
+
let segStart = -1;
|
|
128
|
+
let morphRotationTarget = 90; // starts at a quarter turn, like the source component
|
|
129
|
+
|
|
130
|
+
function tick(now: number) {
|
|
131
|
+
if (mountTime < 0) mountTime = now;
|
|
132
|
+
if (segStart < 0) segStart = now;
|
|
133
|
+
|
|
134
|
+
const reduced = prefersReducedMotion.value;
|
|
135
|
+
const interval = reduced ? MORPH_INTERVAL_MS * 1.8 : MORPH_INTERVAL_MS;
|
|
136
|
+
let elapsed = now - segStart;
|
|
137
|
+
if (elapsed >= interval) {
|
|
138
|
+
shapeIndex = (shapeIndex + 1) % SHAPE_COUNT;
|
|
139
|
+
morphRotationTarget = (morphRotationTarget + 90) % 360;
|
|
140
|
+
segStart = now;
|
|
141
|
+
elapsed = 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const p = reduced ? easeInOut(elapsed / interval) : springProgress(elapsed / 1000);
|
|
145
|
+
const from = shapes[shapeIndex]!;
|
|
146
|
+
const to = shapes[(shapeIndex + 1) % SHAPE_COUNT]!;
|
|
147
|
+
pathEl.value?.setAttribute("d", buildPath(from, to, p));
|
|
148
|
+
|
|
149
|
+
if (!reduced && svgEl.value) {
|
|
150
|
+
const globalDeg = (((now - mountTime) / GLOBAL_ROTATION_MS) * 360) % 360;
|
|
151
|
+
svgEl.value.style.transform = `rotate(${(p * 90 + morphRotationTarget + globalDeg).toFixed(2)}deg)`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
rafId = requestAnimationFrame(tick);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
onMounted(() => {
|
|
158
|
+
prefersReducedMotion.value = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
159
|
+
pathEl.value?.setAttribute("d", buildPath(shapes[0]!, shapes[0]!, 0));
|
|
160
|
+
rafId = requestAnimationFrame(tick);
|
|
161
|
+
});
|
|
162
|
+
onUnmounted(() => cancelAnimationFrame(rafId));
|
|
163
|
+
</script>
|
|
164
|
+
|
|
165
|
+
<template>
|
|
166
|
+
<span
|
|
167
|
+
class="inline-flex shrink-0 items-center justify-center"
|
|
168
|
+
:class="contained ? 'rounded-full' : undefined"
|
|
169
|
+
:style="{ width: `${size}px`, height: `${size}px`, backgroundColor: contained ? svgColor.container : undefined }"
|
|
170
|
+
role="status"
|
|
171
|
+
:aria-label="label ?? locale.loading"
|
|
172
|
+
>
|
|
173
|
+
<svg
|
|
174
|
+
ref="svgEl"
|
|
175
|
+
:width="innerSize"
|
|
176
|
+
:height="innerSize"
|
|
177
|
+
viewBox="0 0 100 100"
|
|
178
|
+
shape-rendering="geometricPrecision"
|
|
179
|
+
style="transform-origin: 50% 50%"
|
|
180
|
+
>
|
|
181
|
+
<path ref="pathEl" shape-rendering="geometricPrecision" :style="{ fill: svgColor.active }" />
|
|
182
|
+
</svg>
|
|
183
|
+
</span>
|
|
184
|
+
</template>
|
|
@@ -494,7 +494,7 @@ const labelClasses = computed(() => {
|
|
|
494
494
|
<Transition name="m3-mac-modal">
|
|
495
495
|
<div
|
|
496
496
|
v-if="modalOpen && mode === 'modal'"
|
|
497
|
-
class="fixed inset-0 z-50 flex items-center justify-center bg-
|
|
497
|
+
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/40 p-4"
|
|
498
498
|
@click.self="closeDropdown"
|
|
499
499
|
>
|
|
500
500
|
<div class="mac-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3">
|
|
@@ -389,7 +389,7 @@ const labelClasses = computed(() => {
|
|
|
389
389
|
<Transition name="m3-ms-modal">
|
|
390
390
|
<div
|
|
391
391
|
v-if="modalOpen && mode === 'modal'"
|
|
392
|
-
class="fixed inset-0 z-50 flex items-center justify-center bg-
|
|
392
|
+
class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/40 p-4"
|
|
393
393
|
@click.self="close"
|
|
394
394
|
>
|
|
395
395
|
<div class="ms-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3">
|
|
@@ -34,7 +34,7 @@ function handleScrimClick() {
|
|
|
34
34
|
<div v-if="modelValue" class="fixed inset-0" :style="style">
|
|
35
35
|
<div
|
|
36
36
|
v-if="scrim"
|
|
37
|
-
class="absolute inset-0 bg-
|
|
37
|
+
class="absolute inset-0 bg-scrim/50"
|
|
38
38
|
@click="handleScrimClick"
|
|
39
39
|
/>
|
|
40
40
|
<div class="relative h-full w-full">
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
|
|
3
|
+
import MLoadingIndicator from "./MLoadingIndicator.vue";
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
refreshing?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
threshold?: number;
|
|
10
|
+
size?: number;
|
|
11
|
+
color?: "primary" | "secondary" | "tertiary" | "error";
|
|
12
|
+
}>(),
|
|
13
|
+
{ refreshing: false, disabled: false, threshold: 64, size: 36, color: "primary" },
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const emit = defineEmits<{ refresh: [] }>();
|
|
17
|
+
|
|
18
|
+
// Beyond `threshold`, the drag keeps following the pointer but scaled down —
|
|
19
|
+
// same "rubber band" feel as MLightbox's swipe-to-navigate.
|
|
20
|
+
const MAX_PULL_MULTIPLIER = 1.8;
|
|
21
|
+
const RESISTANCE = 0.45;
|
|
22
|
+
|
|
23
|
+
const scrollEl = ref<HTMLElement | null>(null);
|
|
24
|
+
const indicatorEl = ref<HTMLElement | null>(null);
|
|
25
|
+
const isPulling = ref(false);
|
|
26
|
+
|
|
27
|
+
let pointerId: number | null = null;
|
|
28
|
+
let startY = 0;
|
|
29
|
+
let pulling = false;
|
|
30
|
+
let pullDistance = 0;
|
|
31
|
+
// True once a drag has crossed the threshold and been released (or refreshing
|
|
32
|
+
// was set programmatically) — the indicator stays pinned until it clears.
|
|
33
|
+
let committed = false;
|
|
34
|
+
|
|
35
|
+
// Fixed resting inset once settled/refreshing — deliberately small and
|
|
36
|
+
// independent of `threshold`/`size` math, so it always reads as "just inside
|
|
37
|
+
// the edge" rather than wherever the drag happened to end up.
|
|
38
|
+
const SETTLE_GAP = 12;
|
|
39
|
+
|
|
40
|
+
function setTransition(el: HTMLElement, animate: boolean) {
|
|
41
|
+
el.style.transition = animate ? "transform 0.25s cubic-bezier(0.2, 0, 0, 1), opacity 0.25s ease" : "none";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Live preview while actively dragging — slides in from above (clipped/
|
|
45
|
+
// hidden by the container's overflow) and grows with the pull.
|
|
46
|
+
function previewIndicator(distance: number) {
|
|
47
|
+
const el = indicatorEl.value;
|
|
48
|
+
if (!el) return;
|
|
49
|
+
setTransition(el, false);
|
|
50
|
+
const progress = Math.min(1, distance / props.threshold);
|
|
51
|
+
el.style.transform = `translateY(${distance - props.size}px) scale(${0.5 + progress * 0.5})`;
|
|
52
|
+
el.style.opacity = `${progress}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function settleIndicator(animate: boolean) {
|
|
56
|
+
const el = indicatorEl.value;
|
|
57
|
+
if (!el) return;
|
|
58
|
+
setTransition(el, animate);
|
|
59
|
+
el.style.transform = `translateY(${SETTLE_GAP}px) scale(1)`;
|
|
60
|
+
el.style.opacity = "1";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function hideIndicator(animate: boolean) {
|
|
64
|
+
const el = indicatorEl.value;
|
|
65
|
+
if (!el) return;
|
|
66
|
+
setTransition(el, animate);
|
|
67
|
+
el.style.transform = `translateY(-${props.size}px) scale(0.5)`;
|
|
68
|
+
el.style.opacity = "0";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function onPointerDown(e: PointerEvent) {
|
|
72
|
+
if (props.disabled || props.refreshing || committed || e.button !== 0) return;
|
|
73
|
+
if (!scrollEl.value || scrollEl.value.scrollTop > 0) return;
|
|
74
|
+
pointerId = e.pointerId;
|
|
75
|
+
startY = e.clientY;
|
|
76
|
+
pulling = true;
|
|
77
|
+
isPulling.value = true;
|
|
78
|
+
// Declare up front (before any touchmove fires) that this element handles
|
|
79
|
+
// its own touch gestures now — waiting and calling preventDefault() from
|
|
80
|
+
// inside pointermove is too late on some mobile browsers, which may have
|
|
81
|
+
// already started resolving the touch as a native scroll/pull-to-refresh
|
|
82
|
+
// and cancel our pointer sequence out from under us. Note this only fully
|
|
83
|
+
// holds up in contexts without a competing OS/browser-chrome gesture layer
|
|
84
|
+
// (Capacitor/Electron shells, desktop mouse) — a real mobile browser tab
|
|
85
|
+
// can still occasionally win that race and cancel the drag.
|
|
86
|
+
scrollEl.value.style.touchAction = "none";
|
|
87
|
+
scrollEl.value.setPointerCapture(e.pointerId);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onPointerMove(e: PointerEvent) {
|
|
91
|
+
if (!pulling || e.pointerId !== pointerId) return;
|
|
92
|
+
const raw = e.clientY - startY;
|
|
93
|
+
if (raw <= 0) {
|
|
94
|
+
// Dragging back upward — not a pull. Hand touch scrolling back so the
|
|
95
|
+
// rest of this gesture can scroll the list normally.
|
|
96
|
+
pullDistance = 0;
|
|
97
|
+
hideIndicator(false);
|
|
98
|
+
if (scrollEl.value) scrollEl.value.style.touchAction = "";
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
const maxPull = props.threshold * MAX_PULL_MULTIPLIER;
|
|
103
|
+
pullDistance = Math.min(
|
|
104
|
+
raw <= props.threshold ? raw : props.threshold + (raw - props.threshold) * RESISTANCE,
|
|
105
|
+
maxPull,
|
|
106
|
+
);
|
|
107
|
+
previewIndicator(pullDistance);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function endPull(e: PointerEvent) {
|
|
111
|
+
if (!pulling || e.pointerId !== pointerId) return;
|
|
112
|
+
pulling = false;
|
|
113
|
+
isPulling.value = false;
|
|
114
|
+
if (scrollEl.value) {
|
|
115
|
+
scrollEl.value.style.touchAction = "";
|
|
116
|
+
if (scrollEl.value.hasPointerCapture(e.pointerId)) scrollEl.value.releasePointerCapture(e.pointerId);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (pullDistance >= props.threshold) {
|
|
120
|
+
committed = true;
|
|
121
|
+
settleIndicator(true);
|
|
122
|
+
emit("refresh");
|
|
123
|
+
} else {
|
|
124
|
+
hideIndicator(true);
|
|
125
|
+
}
|
|
126
|
+
pullDistance = 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Also settles the indicator when a refresh is triggered programmatically
|
|
130
|
+
// (not from a drag) and releases it once the caller clears `refreshing`.
|
|
131
|
+
watch(
|
|
132
|
+
() => props.refreshing,
|
|
133
|
+
(refreshing) => {
|
|
134
|
+
if (refreshing) {
|
|
135
|
+
if (!committed) {
|
|
136
|
+
committed = true;
|
|
137
|
+
settleIndicator(true);
|
|
138
|
+
}
|
|
139
|
+
} else if (committed) {
|
|
140
|
+
committed = false;
|
|
141
|
+
hideIndicator(true);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// The indicator's transform/opacity are owned entirely by the functions
|
|
147
|
+
// above, written directly to the DOM — never bound reactively in the
|
|
148
|
+
// template. A reactive `:style` there would fight this: Vue re-patches any
|
|
149
|
+
// style property it tracks on every re-render of this component (and
|
|
150
|
+
// `isPulling` toggling — used below for the `select-none` class — forces
|
|
151
|
+
// exactly such a re-render right at pointerdown/endPull), stomping whatever
|
|
152
|
+
// transform we'd just applied back to its bound value.
|
|
153
|
+
onMounted(() => hideIndicator(false));
|
|
154
|
+
onBeforeUnmount(() => {
|
|
155
|
+
pulling = false;
|
|
156
|
+
});
|
|
157
|
+
</script>
|
|
158
|
+
|
|
159
|
+
<template>
|
|
160
|
+
<div class="relative overflow-hidden">
|
|
161
|
+
<div
|
|
162
|
+
ref="indicatorEl"
|
|
163
|
+
class="pointer-events-none absolute inset-x-0 top-0 z-10 flex justify-center opacity-0"
|
|
164
|
+
>
|
|
165
|
+
<MLoadingIndicator :size="size" :color="color" contained />
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
<div
|
|
169
|
+
ref="scrollEl"
|
|
170
|
+
class="h-full overflow-y-auto overscroll-y-contain"
|
|
171
|
+
:class="{ 'select-none': isPulling }"
|
|
172
|
+
@pointerdown="onPointerDown"
|
|
173
|
+
@pointermove="onPointerMove"
|
|
174
|
+
@pointerup="endPull"
|
|
175
|
+
@pointercancel="endPull"
|
|
176
|
+
>
|
|
177
|
+
<slot />
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
</template>
|