@m3ui-vue/m3ui-vue 1.6.1 → 1.7.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/dist/API.md +649 -28
- package/dist/{MButton-OQ4wIERQ.js → MButton-CN3wYwIG.js} +2 -2
- package/dist/{MButton-OQ4wIERQ.js.map → MButton-CN3wYwIG.js.map} +1 -1
- package/dist/MColorPickerModal-BKM1CHxr.js +577 -0
- package/dist/MColorPickerModal-BKM1CHxr.js.map +1 -0
- package/dist/{MDialog-DYMnaBlt.js → MDialog-1LAk9WAO.js} +2 -2
- package/dist/{MDialog-DYMnaBlt.js.map → MDialog-1LAk9WAO.js.map} +1 -1
- package/dist/{MListItem-D2cNUyzP.js → MListItem-BU5KDRCB.js} +376 -270
- package/dist/MListItem-BU5KDRCB.js.map +1 -0
- package/dist/{MLoadingIndicator-DWUj0BAB.js → MLoadingIndicator-RykOo5tf.js} +2 -2
- package/dist/{MLoadingIndicator-DWUj0BAB.js.map → MLoadingIndicator-RykOo5tf.js.map} +1 -1
- package/dist/{MSeekBar-C4cn9RIF.js → MSeekBar-B_Y3MpVz.js} +2 -2
- package/dist/{MSeekBar-C4cn9RIF.js.map → MSeekBar-B_Y3MpVz.js.map} +1 -1
- package/dist/MSegmentedButton-CiOOY1-N.js +105 -0
- package/dist/MSegmentedButton-CiOOY1-N.js.map +1 -0
- package/dist/MSlider-BCeVIxcq.js +739 -0
- package/dist/MSlider-BCeVIxcq.js.map +1 -0
- package/dist/{MSpinner-DZkXZJpc.js → MSpinner-Cs03qoqE.js} +2 -2
- package/dist/{MSpinner-DZkXZJpc.js.map → MSpinner-Cs03qoqE.js.map} +1 -1
- package/dist/{MTextField-CNH-byir.js → MTextField-NaFbMkjv.js} +162 -115
- package/dist/MTextField-NaFbMkjv.js.map +1 -0
- package/dist/MTooltip-CK39Zon4.js +183 -0
- package/dist/MTooltip-CK39Zon4.js.map +1 -0
- package/dist/_useFieldValidation-Bz34IAQY.js +191 -0
- package/dist/_useFieldValidation-Bz34IAQY.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +184 -103
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MAddressField.vue.d.ts +18 -3
- package/dist/components/MAppBarWithSearch.vue.d.ts +1 -1
- package/dist/components/MAudioRecorder.vue.d.ts +2 -2
- package/dist/components/MAutocomplete.vue.d.ts +22 -3
- package/dist/components/MCheckbox.vue.d.ts +23 -1
- package/dist/components/MCodeEditor.vue.d.ts +23 -1
- package/dist/components/MColorPicker.vue.d.ts +24 -3
- package/dist/components/MConfirmDialog.vue.d.ts +2 -2
- package/dist/components/MCountrySelect.vue.d.ts +13 -2
- package/dist/components/MCreditCardInput.vue.d.ts +33 -0
- package/dist/components/MCronField.vue.d.ts +23 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDatePicker.vue.d.ts +24 -3
- package/dist/components/MDateRangePicker.vue.d.ts +24 -3
- package/dist/components/MFileUpload.vue.d.ts +23 -2
- package/dist/components/MForm.vue.d.ts +61 -0
- package/dist/components/MJsonEditor.vue.d.ts +23 -1
- package/dist/components/MMapRoute.vue.d.ts +168 -0
- package/dist/components/MMaskField.vue.d.ts +20 -2
- package/dist/components/MMentionField.vue.d.ts +13 -2
- package/dist/components/MMultiAutocomplete.vue.d.ts +22 -3
- package/dist/components/MMultiSelect.vue.d.ts +22 -3
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MNotificationCenter.vue.d.ts +2 -2
- package/dist/components/MNumberField.vue.d.ts +20 -2
- package/dist/components/MPhoneInput.vue.d.ts +19 -4
- package/dist/components/MPinInput.vue.d.ts +24 -3
- package/dist/components/MPosKeypad.vue.d.ts +2 -2
- package/dist/components/MRadioGroup.vue.d.ts +23 -1
- package/dist/components/MRating.vue.d.ts +23 -1
- package/dist/components/MRichTextEditor.vue.d.ts +23 -1
- package/dist/components/MSearchBar.vue.d.ts +1 -1
- package/dist/components/MSegmentedButton.vue.d.ts +23 -2
- package/dist/components/MSelect.vue.d.ts +22 -3
- package/dist/components/MSignaturePad.vue.d.ts +19 -0
- package/dist/components/MSlider.vue.d.ts +23 -1
- package/dist/components/MSwitch.vue.d.ts +23 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +20 -2
- package/dist/components/MText.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +26 -3
- package/dist/components/MTimePicker.vue.d.ts +24 -3
- package/dist/components/MTimezoneSelect.vue.d.ts +13 -2
- package/dist/components/MTour.vue.d.ts +2 -2
- package/dist/components/MTrackingTimeline.vue.d.ts +75 -0
- package/dist/components/MWindow.vue.d.ts +2 -2
- package/dist/composables/_routeGeometry.d.ts +26 -0
- package/dist/composables/_useFieldValidation.d.ts +91 -0
- package/dist/composables/mapRouting.d.ts +35 -0
- package/dist/composables/useLocale.d.ts +23 -0
- package/dist/composables/validation.d.ts +82 -0
- package/dist/draw.js +27 -26
- package/dist/draw.js.map +1 -1
- package/dist/flow.js +1 -1
- package/dist/gantt.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/locales/index.js +154 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7350 -6183
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +4 -0
- package/dist/map.js +1319 -867
- package/dist/map.js.map +1 -1
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +189 -146
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DaVSTdm0.js → useLocale-Dh1xZZ8i.js} +22 -1
- package/dist/useLocale-Dh1xZZ8i.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MForm.test.ts +325 -0
- package/src/__tests__/MMapRoute.test.ts +384 -0
- package/src/__tests__/MPhoneInput.test.ts +5 -2
- package/src/__tests__/MRichTextEditor.test.ts +2 -1
- package/src/__tests__/MTrackingTimeline.test.ts +66 -0
- package/src/__tests__/_fakeMaplibre.ts +4 -1
- package/src/__tests__/_osrmRoutes.ts +10 -0
- package/src/__tests__/attrsFallthrough.test.ts +11 -0
- package/src/__tests__/fieldsValidation.test.ts +229 -0
- package/src/__tests__/ssr.test.ts +1 -0
- package/src/__tests__/validation.test.ts +77 -0
- package/src/components/MAddressField.vue +45 -8
- package/src/components/MAudioRecorder.vue +9 -9
- package/src/components/MAutocomplete.vue +69 -23
- package/src/components/MCheckbox.vue +80 -17
- package/src/components/MCodeEditor.vue +59 -2
- package/src/components/MColorPicker.vue +65 -16
- package/src/components/MCountrySelect.vue +17 -3
- package/src/components/MCreditCardInput.vue +76 -7
- package/src/components/MCronField.vue +60 -10
- package/src/components/MDatePicker.vue +65 -16
- package/src/components/MDateRangePicker.vue +66 -16
- package/src/components/MFileUpload.vue +71 -8
- package/src/components/MForm.vue +208 -0
- package/src/components/MJsonEditor.vue +57 -3
- package/src/components/MMapBaseLayers.vue +29 -28
- package/src/components/MMapMeasure.vue +1 -1
- package/src/components/MMapRoute.vue +470 -0
- package/src/components/MMaskField.vue +55 -13
- package/src/components/MMentionField.vue +17 -2
- package/src/components/MMultiAutocomplete.vue +70 -23
- package/src/components/MMultiSelect.vue +70 -23
- package/src/components/MNumberField.vue +58 -16
- package/src/components/MPhoneInput.vue +60 -18
- package/src/components/MPinInput.vue +58 -10
- package/src/components/MRadioGroup.vue +65 -4
- package/src/components/MRating.vue +62 -6
- package/src/components/MRichTextEditor.vue +64 -4
- package/src/components/MSegmentedButton.vue +59 -2
- package/src/components/MSelect.vue +72 -26
- package/src/components/MSignaturePad.vue +71 -6
- package/src/components/MSlider.vue +61 -10
- package/src/components/MSwitch.vue +63 -8
- package/src/components/MTagInput.vue +67 -25
- package/src/components/MTextField.vue +68 -14
- package/src/components/MTimePicker.vue +65 -16
- package/src/components/MTimezoneSelect.vue +17 -3
- package/src/components/MTrackingTimeline.vue +257 -0
- package/src/composables/_routeGeometry.ts +140 -0
- package/src/composables/_useFieldValidation.ts +287 -0
- package/src/composables/mapRouting.ts +55 -0
- package/src/composables/useLocale.ts +46 -0
- package/src/composables/validation.ts +178 -0
- package/src/index.ts +5 -0
- package/src/locales/de.ts +21 -0
- package/src/locales/es.ts +28 -7
- package/src/locales/fr.ts +21 -0
- package/src/locales/ja.ts +21 -0
- package/src/locales/ko.ts +21 -0
- package/src/locales/pt.ts +21 -0
- package/src/locales/zh.ts +21 -0
- package/src/map.ts +4 -0
- package/dist/MListItem-D2cNUyzP.js.map +0 -1
- package/dist/MSegmentedButton-BEB4gXLA.js +0 -64
- package/dist/MSegmentedButton-BEB4gXLA.js.map +0 -1
- package/dist/MSlider-BIkA6DiE.js +0 -690
- package/dist/MSlider-BIkA6DiE.js.map +0 -1
- package/dist/MTextField-CNH-byir.js.map +0 -1
- package/dist/MTooltip-Dd5g2zhh.js +0 -754
- package/dist/MTooltip-Dd5g2zhh.js.map +0 -1
- package/dist/useLocale-DaVSTdm0.js.map +0 -1
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @event update:modelValue A time zone was picked (its IANA name), or cleared (null)
|
|
9
9
|
*/
|
|
10
10
|
import { computed, onMounted } from 'vue'
|
|
11
|
+
import type { ValidateOn, ValidationRule } from '../composables/validation'
|
|
11
12
|
import MAutocomplete from './MAutocomplete.vue'
|
|
12
13
|
import { useLocale } from '../composables/useLocale'
|
|
13
14
|
|
|
@@ -29,10 +30,18 @@ const props = withDefaults(
|
|
|
29
30
|
clearable?: boolean
|
|
30
31
|
/** Helper text below the field */
|
|
31
32
|
hint?: string
|
|
32
|
-
/** Error state */
|
|
33
|
-
error?: boolean
|
|
33
|
+
/** Error state. A string is also the message */
|
|
34
|
+
error?: boolean | string
|
|
34
35
|
/** Error message shown when `error` is true */
|
|
35
36
|
errorLabel?: string
|
|
37
|
+
/** Validation rules (functions or a Standard Schema); see `MForm` */
|
|
38
|
+
rules?: ValidationRule | ValidationRule[]
|
|
39
|
+
/** When the rules are checked and shown: on leaving the field (default), while typing, or only on submit */
|
|
40
|
+
validateOn?: ValidateOn
|
|
41
|
+
/** Wait this long (ms) after the value stops changing before re-checking (one request for an async rule, not one per key). Defaults to its `MForm`'s */
|
|
42
|
+
validateDebounce?: number
|
|
43
|
+
/** The key of this field in its `MForm` */
|
|
44
|
+
name?: string
|
|
36
45
|
/** Marks it as required */
|
|
37
46
|
required?: boolean
|
|
38
47
|
/** Disables the field */
|
|
@@ -41,7 +50,7 @@ const props = withDefaults(
|
|
|
41
50
|
{ modelValue: null, detect: false, variant: 'filled', mode: 'docked', clearable: false },
|
|
42
51
|
)
|
|
43
52
|
|
|
44
|
-
const emit = defineEmits<{ 'update:modelValue': [zone: string | null] }>()
|
|
53
|
+
const emit = defineEmits<{ blur: []; 'update:modelValue': [zone: string | null] }>()
|
|
45
54
|
|
|
46
55
|
const t = useLocale()
|
|
47
56
|
|
|
@@ -108,6 +117,11 @@ onMounted(() => {
|
|
|
108
117
|
:hint="hint"
|
|
109
118
|
:error="error"
|
|
110
119
|
:error-label="errorLabel"
|
|
120
|
+
:rules="rules"
|
|
121
|
+
:validate-on="validateOn"
|
|
122
|
+
:validate-debounce="validateDebounce"
|
|
123
|
+
:name="name"
|
|
124
|
+
@blur="emit('blur')"
|
|
111
125
|
:required="required"
|
|
112
126
|
:disabled="disabled"
|
|
113
127
|
leading-icon="schedule"
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** A stage of an `MTrackingTimeline`: Order placed, Preparing, On the way, Delivered… */
|
|
3
|
+
export interface TrackingStep {
|
|
4
|
+
/** Its name */
|
|
5
|
+
label: string
|
|
6
|
+
/** A line under it in the details (who, where) */
|
|
7
|
+
description?: string
|
|
8
|
+
/** A Material Symbol for its dot */
|
|
9
|
+
icon?: string
|
|
10
|
+
/** When it happened (or is expected): shown as a time in the details */
|
|
11
|
+
time?: string | number | Date
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Where the order stands besides its step: on time, running late, or called off */
|
|
15
|
+
export type TrackingStatus = 'active' | 'delayed' | 'canceled'
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
/**
|
|
20
|
+
* An order's progress for deliveries, rides and shipments: the current stage and the arrival time on top ("12 min ·
|
|
21
|
+
* Arrives 3:45 PM", kept up to date), a bar of stage icons whose current leg fills as it goes (`stepProgress`, e.g.
|
|
22
|
+
* from `MMapRoute`'s progress), delayed and canceled states, and the stages with their times in a details list that
|
|
23
|
+
* opens below. Not an M3 spec component: built from M3 pieces (`MTimeline`, `MCollapse`, the progress indicator's
|
|
24
|
+
* track and color roles).
|
|
25
|
+
*
|
|
26
|
+
* @slot title Replaces the title (the current stage's name). Scope: `{ step, index }`
|
|
27
|
+
* @slot extra Content between the bar and the details: the courier, a call button, a map
|
|
28
|
+
* @event update:expanded The details opened or closed — powers v-model:expanded
|
|
29
|
+
*/
|
|
30
|
+
import { computed, onBeforeUnmount, onMounted, ref, useId, watch } from 'vue'
|
|
31
|
+
import MIcon from './MIcon.vue'
|
|
32
|
+
import MButton from './MButton.vue'
|
|
33
|
+
import MCollapse from './MCollapse.vue'
|
|
34
|
+
import MTimeline from './MTimeline.vue'
|
|
35
|
+
import { useLocale } from '../composables/useLocale'
|
|
36
|
+
|
|
37
|
+
const props = withDefaults(
|
|
38
|
+
defineProps<{
|
|
39
|
+
/** The stages, in order */
|
|
40
|
+
steps: TrackingStep[]
|
|
41
|
+
/** The stage it's at (0-based): earlier ones are done. `steps.length` (or more) means all done */
|
|
42
|
+
current: number
|
|
43
|
+
/** How far along the current stage's leg it is, 0–1 (the bar fills toward the next stage) */
|
|
44
|
+
stepProgress?: number
|
|
45
|
+
/** The expected arrival: shows the minutes left and the time, and updates by itself */
|
|
46
|
+
eta?: string | number | Date
|
|
47
|
+
/** On time (`active`), running late (`delayed`) or called off (`canceled`) */
|
|
48
|
+
status?: TrackingStatus
|
|
49
|
+
/** The title, instead of the current stage's name */
|
|
50
|
+
title?: string
|
|
51
|
+
/** A line under the title ("Your courier is 2 blocks away") */
|
|
52
|
+
message?: string
|
|
53
|
+
/** Offer the stages with their times in a list that opens below */
|
|
54
|
+
details?: boolean
|
|
55
|
+
/** Whether the details are open (v-model:expanded) */
|
|
56
|
+
expanded?: boolean
|
|
57
|
+
}>(),
|
|
58
|
+
{ stepProgress: 0, status: 'active', details: true, expanded: undefined },
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const emit = defineEmits<{ 'update:expanded': [open: boolean] }>()
|
|
62
|
+
|
|
63
|
+
const locale = useLocale()
|
|
64
|
+
const detailsId = useId()
|
|
65
|
+
|
|
66
|
+
const last = computed(() => props.steps.length - 1)
|
|
67
|
+
const done = computed(() => props.status !== 'canceled' && props.current >= last.value)
|
|
68
|
+
const at = computed(() => Math.min(Math.max(props.current, 0), last.value))
|
|
69
|
+
|
|
70
|
+
type State = 'done' | 'current' | 'upcoming'
|
|
71
|
+
const stateOf = (i: number): State => (done.value || i < at.value ? 'done' : i === at.value ? 'current' : 'upcoming')
|
|
72
|
+
|
|
73
|
+
/** How full the leg after stage i is, 0–1 */
|
|
74
|
+
const legFill = (i: number) => {
|
|
75
|
+
if (done.value || i < at.value) return 1
|
|
76
|
+
if (i === at.value && props.status !== 'canceled') return Math.min(Math.max(props.stepProgress, 0), 1)
|
|
77
|
+
return 0
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ── Time ───────────────────────────────────────────────────────────
|
|
81
|
+
const now = ref(Date.now())
|
|
82
|
+
let timer: ReturnType<typeof setInterval> | undefined
|
|
83
|
+
onMounted(() => { timer = setInterval(() => (now.value = Date.now()), 15_000) })
|
|
84
|
+
onBeforeUnmount(() => clearInterval(timer))
|
|
85
|
+
|
|
86
|
+
const toDate = (v: string | number | Date) => (v instanceof Date ? v : new Date(v))
|
|
87
|
+
const timeFormat = computed(() => new Intl.DateTimeFormat(locale.lang || undefined, { hour: 'numeric', minute: '2-digit' }))
|
|
88
|
+
const formatTime = (v: string | number | Date | undefined) => {
|
|
89
|
+
if (v == null) return undefined
|
|
90
|
+
const d = toDate(v)
|
|
91
|
+
return Number.isNaN(d.getTime()) ? String(v) : timeFormat.value.format(d)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The minutes (or hours) left, as the big number */
|
|
95
|
+
const remaining = computed(() => {
|
|
96
|
+
if (props.eta == null || done.value || props.status === 'canceled') return null
|
|
97
|
+
const ms = toDate(props.eta).getTime() - now.value
|
|
98
|
+
if (Number.isNaN(ms)) return null
|
|
99
|
+
const min = Math.ceil(ms / 60_000)
|
|
100
|
+
if (min <= 1) return { text: locale.trackingArrivingNow, short: true }
|
|
101
|
+
const unit = min >= 90 ? 'hour' : 'minute'
|
|
102
|
+
const value = unit === 'hour' ? Math.round(min / 60) : min
|
|
103
|
+
return { text: new Intl.NumberFormat(locale.lang || undefined, { style: 'unit', unit, unitDisplay: 'short' }).format(value), short: false }
|
|
104
|
+
})
|
|
105
|
+
const etaLine = computed(() => {
|
|
106
|
+
if (done.value) {
|
|
107
|
+
const t = formatTime(props.steps[last.value]?.time)
|
|
108
|
+
return t ? `${locale.trackingDelivered} · ${t}` : locale.trackingDelivered
|
|
109
|
+
}
|
|
110
|
+
if (props.eta == null || props.status === 'canceled') return null
|
|
111
|
+
return locale.trackingArrives.replace('{time}', formatTime(props.eta) ?? '')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const heading = computed(() => props.title ?? props.steps[at.value]?.label ?? '')
|
|
115
|
+
|
|
116
|
+
// ── Details ────────────────────────────────────────────────────────
|
|
117
|
+
const openInner = ref(false)
|
|
118
|
+
const open = computed(() => props.expanded ?? openInner.value)
|
|
119
|
+
function toggle() {
|
|
120
|
+
const next = !open.value
|
|
121
|
+
openInner.value = next
|
|
122
|
+
emit('update:expanded', next)
|
|
123
|
+
}
|
|
124
|
+
watch(() => props.expanded, (v) => { if (v != null) openInner.value = v })
|
|
125
|
+
|
|
126
|
+
const timelineItems = computed(() =>
|
|
127
|
+
props.steps.map((s, i) => ({
|
|
128
|
+
title: s.label,
|
|
129
|
+
description: s.description,
|
|
130
|
+
icon: s.icon,
|
|
131
|
+
date: formatTime(s.time),
|
|
132
|
+
color: props.status === 'canceled' && i === at.value ? ('error' as const) : undefined,
|
|
133
|
+
})),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
// Colors for the current stage by status: tertiary while late (M3's accent for "needs attention but not an error")
|
|
137
|
+
const accent = computed(() =>
|
|
138
|
+
props.status === 'canceled' ? { solid: 'bg-error text-on-error', soft: 'bg-error-container text-on-error-container', fill: 'bg-error', text: 'text-error' }
|
|
139
|
+
: props.status === 'delayed' ? { solid: 'bg-tertiary text-on-tertiary', soft: 'bg-tertiary-container text-on-tertiary-container', fill: 'bg-tertiary', text: 'text-tertiary' }
|
|
140
|
+
: { solid: 'bg-primary text-on-primary', soft: 'bg-primary-container text-on-primary-container', fill: 'bg-primary', text: 'text-primary' },
|
|
141
|
+
)
|
|
142
|
+
const dotClass = (i: number) => {
|
|
143
|
+
const s = stateOf(i)
|
|
144
|
+
if (s === 'done') return 'bg-primary text-on-primary'
|
|
145
|
+
if (s === 'current') return accent.value.soft
|
|
146
|
+
return props.status === 'canceled' ? 'bg-surface-container-highest text-on-surface/38' : 'bg-surface-container-highest text-on-surface-variant'
|
|
147
|
+
}
|
|
148
|
+
const dotIcon = (i: number) => {
|
|
149
|
+
if (props.status === 'canceled' && stateOf(i) === 'current') return 'close'
|
|
150
|
+
return props.steps[i]?.icon ?? (stateOf(i) === 'done' ? 'check' : 'circle')
|
|
151
|
+
}
|
|
152
|
+
const statusChip = computed(() =>
|
|
153
|
+
props.status === 'delayed' ? { label: locale.trackingDelayed, icon: 'schedule' } : props.status === 'canceled' ? { label: locale.trackingCanceled, icon: 'cancel' } : null,
|
|
154
|
+
)
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
<template>
|
|
158
|
+
<section class="m3-tracking flex flex-col gap-4 rounded-xl bg-surface-container-low p-4" :aria-label="heading">
|
|
159
|
+
<!-- Title, status and arrival -->
|
|
160
|
+
<div class="flex items-start gap-4">
|
|
161
|
+
<div class="min-w-0 flex-1">
|
|
162
|
+
<div class="flex flex-wrap items-center gap-2">
|
|
163
|
+
<h3 class="text-title-large text-on-surface">
|
|
164
|
+
<slot name="title" :step="steps[at]" :index="at">{{ heading }}</slot>
|
|
165
|
+
</h3>
|
|
166
|
+
<span
|
|
167
|
+
v-if="statusChip"
|
|
168
|
+
class="inline-flex h-6 items-center gap-1 rounded-sm px-2 text-label-medium"
|
|
169
|
+
:class="accent.soft"
|
|
170
|
+
>
|
|
171
|
+
<MIcon :name="statusChip.icon" :size="16" />{{ statusChip.label }}
|
|
172
|
+
</span>
|
|
173
|
+
</div>
|
|
174
|
+
<p v-if="message" class="mt-1 text-body-medium text-on-surface-variant">{{ message }}</p>
|
|
175
|
+
</div>
|
|
176
|
+
<div v-if="remaining || etaLine" class="shrink-0 text-right" aria-live="polite">
|
|
177
|
+
<p v-if="remaining" class="tabular-nums" :class="[remaining.short ? 'text-title-medium' : 'text-headline-small', accent.text]">{{ remaining.text }}</p>
|
|
178
|
+
<p v-if="etaLine" class="text-body-small text-on-surface-variant">{{ etaLine }}</p>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<!-- The stages: dots joined by legs that fill -->
|
|
183
|
+
<ol class="flex items-center" :aria-label="heading">
|
|
184
|
+
<template v-for="(step, i) in steps" :key="i">
|
|
185
|
+
<li
|
|
186
|
+
class="relative flex shrink-0"
|
|
187
|
+
:aria-current="stateOf(i) === 'current' && !done ? 'step' : undefined"
|
|
188
|
+
:title="step.label"
|
|
189
|
+
>
|
|
190
|
+
<span class="sr-only">{{ step.label }}</span>
|
|
191
|
+
<span
|
|
192
|
+
v-if="stateOf(i) === 'current' && !done && status !== 'canceled'"
|
|
193
|
+
class="m3-tracking-pulse absolute inset-0 rounded-full"
|
|
194
|
+
:class="accent.fill"
|
|
195
|
+
aria-hidden="true"
|
|
196
|
+
/>
|
|
197
|
+
<span
|
|
198
|
+
class="relative flex h-9 w-9 items-center justify-center rounded-full transition-colors duration-300"
|
|
199
|
+
:class="dotClass(i)"
|
|
200
|
+
aria-hidden="true"
|
|
201
|
+
>
|
|
202
|
+
<MIcon :name="dotIcon(i)" :size="20" :filled="stateOf(i) !== 'upcoming'" />
|
|
203
|
+
</span>
|
|
204
|
+
</li>
|
|
205
|
+
<li v-if="i < steps.length - 1" class="mx-1 h-1 min-w-4 flex-1 overflow-hidden rounded-full bg-surface-container-highest" aria-hidden="true">
|
|
206
|
+
<span
|
|
207
|
+
class="block h-full rounded-full transition-[width] duration-500 ease-out"
|
|
208
|
+
:class="i < at || done ? 'bg-primary' : accent.fill"
|
|
209
|
+
:style="{ width: `${legFill(i) * 100}%` }"
|
|
210
|
+
/>
|
|
211
|
+
</li>
|
|
212
|
+
</template>
|
|
213
|
+
</ol>
|
|
214
|
+
|
|
215
|
+
<slot name="extra" />
|
|
216
|
+
|
|
217
|
+
<template v-if="details">
|
|
218
|
+
<MCollapse :id="detailsId" :open="open">
|
|
219
|
+
<MTimeline :items="timelineItems" :current="done ? steps.length : at" dense />
|
|
220
|
+
</MCollapse>
|
|
221
|
+
<MButton
|
|
222
|
+
variant="text"
|
|
223
|
+
size="sm"
|
|
224
|
+
class="self-start"
|
|
225
|
+
:icon="open ? 'expand_less' : 'expand_more'"
|
|
226
|
+
:aria-expanded="open"
|
|
227
|
+
:aria-controls="detailsId"
|
|
228
|
+
@click="toggle"
|
|
229
|
+
>
|
|
230
|
+
{{ open ? locale.trackingHideDetails : locale.trackingShowDetails }}
|
|
231
|
+
</MButton>
|
|
232
|
+
</template>
|
|
233
|
+
</section>
|
|
234
|
+
</template>
|
|
235
|
+
|
|
236
|
+
<style scoped>
|
|
237
|
+
/* The current stage breathes: a ring that grows and fades, like a live location dot */
|
|
238
|
+
.m3-tracking-pulse {
|
|
239
|
+
animation: m3-tracking-pulse 1.8s cubic-bezier(0.2, 0, 0, 1) infinite;
|
|
240
|
+
}
|
|
241
|
+
@keyframes m3-tracking-pulse {
|
|
242
|
+
from {
|
|
243
|
+
transform: scale(1);
|
|
244
|
+
opacity: 0.32;
|
|
245
|
+
}
|
|
246
|
+
to {
|
|
247
|
+
transform: scale(1.7);
|
|
248
|
+
opacity: 0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
@media (prefers-reduced-motion: reduce) {
|
|
252
|
+
.m3-tracking-pulse {
|
|
253
|
+
animation: none;
|
|
254
|
+
display: none;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
</style>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Internal: walking along a route (a path of [lng, lat] points) for MMapRoute — distances in meters, on the same sphere
|
|
2
|
+
// as _mapGeometry.ts
|
|
3
|
+
|
|
4
|
+
import { distance, type LngLat } from './_mapGeometry'
|
|
5
|
+
|
|
6
|
+
const RAD = Math.PI / 180
|
|
7
|
+
|
|
8
|
+
/** Distance from the start to each point of the path, in meters (`[0, …, total]`). */
|
|
9
|
+
export function cumulative(path: LngLat[]): number[] {
|
|
10
|
+
const out = [0]
|
|
11
|
+
for (let i = 1; i < path.length; i++) out.push(out[i - 1]! + distance(path[i - 1]!, path[i]!))
|
|
12
|
+
return out
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Initial bearing from a to b, degrees clockwise from north (0–360). */
|
|
16
|
+
export function bearing(a: LngLat, b: LngLat): number {
|
|
17
|
+
const φ1 = a[1] * RAD
|
|
18
|
+
const φ2 = b[1] * RAD
|
|
19
|
+
const Δλ = (b[0] - a[0]) * RAD
|
|
20
|
+
const y = Math.sin(Δλ) * Math.cos(φ2)
|
|
21
|
+
const x = Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ)
|
|
22
|
+
return ((Math.atan2(y, x) / RAD) + 360) % 360
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The segment holding distance `d` (index of its first point). */
|
|
26
|
+
function segmentAt(cum: number[], d: number): number {
|
|
27
|
+
let lo = 0
|
|
28
|
+
let hi = cum.length - 1
|
|
29
|
+
while (hi - lo > 1) {
|
|
30
|
+
const mid = (lo + hi) >> 1
|
|
31
|
+
if (cum[mid]! <= d) lo = mid
|
|
32
|
+
else hi = mid
|
|
33
|
+
}
|
|
34
|
+
return lo
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The point `d` meters along the path, and the heading there. Clamped to the path's ends. */
|
|
38
|
+
export function pointAlong(path: LngLat[], cum: number[], d: number): { lngLat: LngLat; bearing: number } {
|
|
39
|
+
if (path.length === 0) return { lngLat: [0, 0], bearing: 0 }
|
|
40
|
+
if (path.length === 1) return { lngLat: path[0]!, bearing: 0 }
|
|
41
|
+
const total = cum[cum.length - 1]!
|
|
42
|
+
const at = Math.min(Math.max(d, 0), total)
|
|
43
|
+
const i = Math.min(segmentAt(cum, at), path.length - 2)
|
|
44
|
+
const a = path[i]!
|
|
45
|
+
const b = path[i + 1]!
|
|
46
|
+
const len = cum[i + 1]! - cum[i]!
|
|
47
|
+
const t = len > 0 ? (at - cum[i]!) / len : 0
|
|
48
|
+
return { lngLat: [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t], bearing: headingFrom(path, cum, i) }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The heading of segment i, or of the nearest one with some length (routing output repeats points) */
|
|
52
|
+
function headingFrom(path: LngLat[], cum: number[], i: number): number {
|
|
53
|
+
for (let j = i; j < path.length - 1; j++) if (cum[j + 1]! > cum[j]!) return bearing(path[j]!, path[j + 1]!)
|
|
54
|
+
for (let j = i - 1; j >= 0; j--) if (cum[j + 1]! > cum[j]!) return bearing(path[j]!, path[j + 1]!)
|
|
55
|
+
return 0
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The part of the path between two distances along it. */
|
|
59
|
+
export function slicePath(path: LngLat[], cum: number[], from: number, to: number): LngLat[] {
|
|
60
|
+
if (path.length < 2) return [...path]
|
|
61
|
+
const total = cum[cum.length - 1]!
|
|
62
|
+
const start = Math.min(Math.max(from, 0), total)
|
|
63
|
+
const end = Math.min(Math.max(to, start), total)
|
|
64
|
+
const out: LngLat[] = [pointAlong(path, cum, start).lngLat]
|
|
65
|
+
for (let i = 0; i < path.length; i++) if (cum[i]! > start && cum[i]! < end) out.push(path[i]!)
|
|
66
|
+
out.push(pointAlong(path, cum, end).lngLat)
|
|
67
|
+
return out
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* How far along the path (meters) the point nearest to `p` is: where a GPS position, slightly off the road, falls on
|
|
72
|
+
* the route. Projects onto each segment in a local flat approximation (fine at street scale).
|
|
73
|
+
*/
|
|
74
|
+
export function project(path: LngLat[], cum: number[], p: LngLat): number {
|
|
75
|
+
if (path.length < 2) return 0
|
|
76
|
+
const k = Math.cos(p[1] * RAD)
|
|
77
|
+
let best = Infinity
|
|
78
|
+
let along = 0
|
|
79
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
80
|
+
const a = path[i]!
|
|
81
|
+
const b = path[i + 1]!
|
|
82
|
+
const ax = a[0] * k, ay = a[1], bx = b[0] * k, by = b[1], px = p[0] * k, py = p[1]
|
|
83
|
+
const dx = bx - ax
|
|
84
|
+
const dy = by - ay
|
|
85
|
+
const len2 = dx * dx + dy * dy
|
|
86
|
+
const t = len2 > 0 ? Math.min(1, Math.max(0, ((px - ax) * dx + (py - ay) * dy) / len2)) : 0
|
|
87
|
+
const qx = ax + dx * t - px
|
|
88
|
+
const qy = ay + dy * t - py
|
|
89
|
+
const d2 = qx * qx + qy * qy
|
|
90
|
+
if (d2 < best) {
|
|
91
|
+
best = d2
|
|
92
|
+
along = cum[i]! + (cum[i + 1]! - cum[i]!) * t
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return along
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Like `project`, but for something that moves forward along the route (a vehicle's GPS fixes, the stops in order):
|
|
100
|
+
* only the part from `from` on is considered (minus `back` meters of slack for jitter), and points further ahead
|
|
101
|
+
* cost a little more, so a route that passes the same place twice (out and back on one avenue, a loop, two close
|
|
102
|
+
* parallel streets) doesn't snap a fix to the wrong pass. Never returns less than `from`.
|
|
103
|
+
*/
|
|
104
|
+
export function projectForward(path: LngLat[], cum: number[], p: LngLat, from: number, back = 25): number {
|
|
105
|
+
if (path.length < 2) return 0
|
|
106
|
+
const M = 111_320 // meters per degree of latitude
|
|
107
|
+
const k = Math.cos(p[1] * RAD)
|
|
108
|
+
const total = cum[cum.length - 1]!
|
|
109
|
+
if (from >= total) return total
|
|
110
|
+
let best = Infinity
|
|
111
|
+
let along = from
|
|
112
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
113
|
+
if (cum[i + 1]! < from - back) continue
|
|
114
|
+
const a = path[i]!
|
|
115
|
+
const b = path[i + 1]!
|
|
116
|
+
const ax = a[0] * k, ay = a[1], bx = b[0] * k, by = b[1], px = p[0] * k, py = p[1]
|
|
117
|
+
const dx = bx - ax
|
|
118
|
+
const dy = by - ay
|
|
119
|
+
const len2 = dx * dx + dy * dy
|
|
120
|
+
const t = len2 > 0 ? Math.min(1, Math.max(0, ((px - ax) * dx + (py - ay) * dy) / len2)) : 0
|
|
121
|
+
const off = Math.hypot(ax + dx * t - px, ay + dy * t - py) * M
|
|
122
|
+
const d = cum[i]! + (cum[i + 1]! - cum[i]!) * t
|
|
123
|
+
// A kilometer ahead costs as much as being 50 m off the road
|
|
124
|
+
const cost = off + 0.05 * Math.max(0, d - from)
|
|
125
|
+
if (cost < best) {
|
|
126
|
+
best = cost
|
|
127
|
+
along = d
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return Math.max(along, from)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The bounding box of points, `[[west, south], [east, north]]`. */
|
|
134
|
+
export function bounds(points: LngLat[]): [LngLat, LngLat] {
|
|
135
|
+
let w = Infinity, s = Infinity, e = -Infinity, n = -Infinity
|
|
136
|
+
for (const [lng, lat] of points) {
|
|
137
|
+
w = Math.min(w, lng); e = Math.max(e, lng); s = Math.min(s, lat); n = Math.max(n, lat)
|
|
138
|
+
}
|
|
139
|
+
return [[w, s], [e, n]]
|
|
140
|
+
}
|