@m3ui-vue/m3ui-vue 1.3.8 → 1.4.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/dist/API.md +1102 -20
- package/dist/{MButton-D5eJiDza.js → MButton-DQMTIlaV.js} +2 -2
- package/dist/{MButton-D5eJiDza.js.map → MButton-DQMTIlaV.js.map} +1 -1
- package/dist/{MDialog-WqB0jewp.js → MDialog-cdgapGfZ.js} +2 -2
- package/dist/{MDialog-WqB0jewp.js.map → MDialog-cdgapGfZ.js.map} +1 -1
- package/dist/{MListItem-Cf-C2Ru-.js → MListItem-ZkSGIIrb.js} +2 -2
- package/dist/{MListItem-Cf-C2Ru-.js.map → MListItem-ZkSGIIrb.js.map} +1 -1
- package/dist/{MLoadingIndicator-D4GzEZoH.js → MLoadingIndicator-U6_oGx8z.js} +2 -2
- package/dist/{MLoadingIndicator-D4GzEZoH.js.map → MLoadingIndicator-U6_oGx8z.js.map} +1 -1
- package/dist/{MSeekBar-B19xoWE3.js → MSeekBar-DTZVizZg.js} +2 -2
- package/dist/{MSeekBar-B19xoWE3.js.map → MSeekBar-DTZVizZg.js.map} +1 -1
- package/dist/{MSlider-9RoiuebS.js → MSlider-CqJkEYRZ.js} +2 -2
- package/dist/{MSlider-9RoiuebS.js.map → MSlider-CqJkEYRZ.js.map} +1 -1
- package/dist/{MSpinner-BNF8MN-L.js → MSpinner-Btgc-0nb.js} +2 -2
- package/dist/{MSpinner-BNF8MN-L.js.map → MSpinner-Btgc-0nb.js.map} +1 -1
- package/dist/{MTextField-CuG0T3qh.js → MTextField-B6M0gJEO.js} +2 -2
- package/dist/{MTextField-CuG0T3qh.js.map → MTextField-B6M0gJEO.js.map} +1 -1
- package/dist/{MTooltip-Bv7yxngk.js → MTooltip-Dspji4XG.js} +4 -4
- package/dist/{MTooltip-Bv7yxngk.js.map → MTooltip-Dspji4XG.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +2 -2
- package/dist/components/MAvailabilityCalendar.vue.d.ts +83 -0
- package/dist/components/MBeforeAfter.vue.d.ts +61 -0
- package/dist/components/MBodyMap.vue.d.ts +70 -0
- package/dist/components/MCandlestickChart.vue.d.ts +82 -0
- package/dist/components/MCertificate.vue.d.ts +76 -0
- package/dist/components/MCountdown.vue.d.ts +80 -0
- package/dist/components/MCreditCardInput.vue.d.ts +75 -0
- package/dist/components/MMortgageCalculator.vue.d.ts +83 -0
- package/dist/components/MOdontogram.vue.d.ts +86 -0
- package/dist/components/MOrderBook.vue.d.ts +89 -0
- package/dist/components/MOrderTicket.vue.d.ts +91 -0
- package/dist/components/MPosKeypad.vue.d.ts +84 -0
- package/dist/components/MProductConfigurator.vue.d.ts +136 -0
- package/dist/components/MQuiz.vue.d.ts +102 -0
- package/dist/components/MReceipt.vue.d.ts +93 -0
- package/dist/components/MSeatMap.vue.d.ts +131 -0
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MTicket.vue.d.ts +83 -0
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/MVitalsChart.vue.d.ts +73 -0
- package/dist/composables/_printElement.d.ts +9 -0
- package/dist/composables/cardBrand.d.ts +25 -0
- package/dist/composables/mortgage.d.ts +37 -0
- package/dist/composables/useLocale.d.ts +131 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +37 -0
- package/dist/locales/index.js +924 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +10125 -5263
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-D2ucaY-l.js → useLocale-DLKJIRFi.js} +133 -2
- package/dist/useLocale-DLKJIRFi.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAvailabilityCalendar.test.ts +85 -0
- package/src/__tests__/MBeforeAfter.test.ts +79 -0
- package/src/__tests__/MBodyMap.test.ts +60 -0
- package/src/__tests__/MCandlestickChart.test.ts +66 -0
- package/src/__tests__/MCertificate.test.ts +32 -0
- package/src/__tests__/MCountdown.test.ts +75 -0
- package/src/__tests__/MCreditCardInput.test.ts +122 -0
- package/src/__tests__/MMortgageCalculator.test.ts +49 -0
- package/src/__tests__/MOdontogram.test.ts +93 -0
- package/src/__tests__/MOrderBook.test.ts +66 -0
- package/src/__tests__/MOrderTicket.test.ts +68 -0
- package/src/__tests__/MPosKeypad.test.ts +116 -0
- package/src/__tests__/MProductConfigurator.test.ts +73 -0
- package/src/__tests__/MQuiz.test.ts +104 -0
- package/src/__tests__/MReceipt.test.ts +52 -0
- package/src/__tests__/MSeatMap.test.ts +76 -0
- package/src/__tests__/MTicket.test.ts +38 -0
- package/src/__tests__/MVitalsChart.test.ts +49 -0
- package/src/__tests__/clearToNull.test.ts +30 -0
- package/src/__tests__/mortgage.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +11 -0
- package/src/components/MAutocomplete.vue +2 -2
- package/src/components/MAvailabilityCalendar.vue +460 -0
- package/src/components/MBeforeAfter.vue +248 -0
- package/src/components/MBodyMap.vue +266 -0
- package/src/components/MCandlestickChart.vue +479 -0
- package/src/components/MCertificate.vue +351 -0
- package/src/components/MCountdown.vue +200 -0
- package/src/components/MCreditCardInput.vue +351 -0
- package/src/components/MMortgageCalculator.vue +258 -0
- package/src/components/MOdontogram.vue +462 -0
- package/src/components/MOrderBook.vue +287 -0
- package/src/components/MOrderTicket.vue +217 -0
- package/src/components/MPosKeypad.vue +406 -0
- package/src/components/MProductConfigurator.vue +412 -0
- package/src/components/MQuiz.vue +531 -0
- package/src/components/MReceipt.vue +249 -0
- package/src/components/MSeatMap.vue +431 -0
- package/src/components/MSelect.vue +2 -2
- package/src/components/MTicket.vue +209 -0
- package/src/components/MVitalsChart.vue +303 -0
- package/src/composables/_printElement.ts +36 -0
- package/src/composables/cardBrand.ts +104 -0
- package/src/composables/mortgage.ts +70 -0
- package/src/composables/useLocale.ts +277 -0
- package/src/index.ts +37 -0
- package/src/locales/de.ts +131 -0
- package/src/locales/es.ts +131 -0
- package/src/locales/fr.ts +131 -0
- package/src/locales/ja.ts +131 -0
- package/src/locales/ko.ts +131 -0
- package/src/locales/pt.ts +131 -0
- package/src/locales/zh.ts +131 -0
- package/dist/useLocale-D2ucaY-l.js.map +0 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Compares two images (or any two pieces of content) stacked on top of each other, split by a handle the user
|
|
4
|
+
* drags: a renovation, a photo edit, a redesign. Clicking anywhere moves the split there; the handle is a slider
|
|
5
|
+
* for the keyboard (arrows, Page Up/Down, Home/End).
|
|
6
|
+
*
|
|
7
|
+
* The root has no size of its own beyond the images: give it a width (and an `aspectRatio`, or a height through
|
|
8
|
+
* `class`) to make it a fixed box.
|
|
9
|
+
*
|
|
10
|
+
* @slot before Content of the "before" side, replacing the `before` image
|
|
11
|
+
* @slot after Content of the "after" side, replacing the `after` image
|
|
12
|
+
* @slot handle Replaces the round grip in the middle of the divider. Slot props: `{ position, dragging }`
|
|
13
|
+
* @event update:modelValue Emitted while dragging or stepping with the keyboard — powers v-model (0–100)
|
|
14
|
+
* @event change Emitted once when a drag or a key press ends, with the final position
|
|
15
|
+
*/
|
|
16
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
17
|
+
import MIcon from './MIcon.vue'
|
|
18
|
+
import { useLocale } from '../composables/useLocale'
|
|
19
|
+
|
|
20
|
+
const locale = useLocale()
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(
|
|
23
|
+
defineProps<{
|
|
24
|
+
/** Split position as a percentage (v-model). Without v-model the component keeps its own, starting here */
|
|
25
|
+
modelValue?: number
|
|
26
|
+
/** Image URL of the "before" side (left, or top when vertical) */
|
|
27
|
+
before?: string
|
|
28
|
+
/** Image URL of the "after" side (right, or bottom when vertical) */
|
|
29
|
+
after?: string
|
|
30
|
+
/** Alt text of the "before" image */
|
|
31
|
+
beforeAlt?: string
|
|
32
|
+
/** Alt text of the "after" image */
|
|
33
|
+
afterAlt?: string
|
|
34
|
+
/** Label chip on the "before" side. Defaults to the locale's "Before"; pass an empty string to hide it */
|
|
35
|
+
beforeLabel?: string
|
|
36
|
+
/** Label chip on the "after" side. Defaults to the locale's "After"; pass an empty string to hide it */
|
|
37
|
+
afterLabel?: string
|
|
38
|
+
/** Direction the divider moves in */
|
|
39
|
+
orientation?: 'horizontal' | 'vertical'
|
|
40
|
+
/** Moves the split with the pointer on hover, without pressing (mouse only; touch still drags) */
|
|
41
|
+
hover?: boolean
|
|
42
|
+
/** CSS aspect-ratio of the box, e.g. "16 / 9". Unset sizes to the "after" content */
|
|
43
|
+
aspectRatio?: string
|
|
44
|
+
/** Hides the round grip, leaving only the divider line */
|
|
45
|
+
hideHandle?: boolean
|
|
46
|
+
/** Percentage moved by an arrow key (Page Up/Down move 10×) */
|
|
47
|
+
step?: number
|
|
48
|
+
/** Disables dragging and the keyboard */
|
|
49
|
+
disabled?: boolean
|
|
50
|
+
}>(),
|
|
51
|
+
{
|
|
52
|
+
modelValue: undefined,
|
|
53
|
+
orientation: 'horizontal',
|
|
54
|
+
hover: false,
|
|
55
|
+
hideHandle: false,
|
|
56
|
+
step: 1,
|
|
57
|
+
disabled: false,
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const emit = defineEmits<{ 'update:modelValue': [number]; change: [number] }>()
|
|
62
|
+
|
|
63
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
64
|
+
const inner = ref(clamp(props.modelValue ?? 50))
|
|
65
|
+
watch(() => props.modelValue, (v) => { if (v !== undefined) inner.value = clamp(v) })
|
|
66
|
+
const position = computed(() => inner.value)
|
|
67
|
+
const dragging = ref(false)
|
|
68
|
+
const vertical = computed(() => props.orientation === 'vertical')
|
|
69
|
+
|
|
70
|
+
const beforeText = computed(() => props.beforeLabel ?? locale.compareBefore)
|
|
71
|
+
const afterText = computed(() => props.afterLabel ?? locale.compareAfter)
|
|
72
|
+
|
|
73
|
+
function clamp(v: number) {
|
|
74
|
+
return Math.min(100, Math.max(0, v))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function set(v: number) {
|
|
78
|
+
const next = Math.round(clamp(v) * 100) / 100
|
|
79
|
+
if (next === inner.value) return
|
|
80
|
+
inner.value = next
|
|
81
|
+
emit('update:modelValue', next)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function fromPointer(e: PointerEvent) {
|
|
85
|
+
const r = rootEl.value?.getBoundingClientRect()
|
|
86
|
+
if (!r) return
|
|
87
|
+
const p = vertical.value
|
|
88
|
+
? ((e.clientY - r.top) / (r.height || 1)) * 100
|
|
89
|
+
: ((e.clientX - r.left) / (r.width || 1)) * 100
|
|
90
|
+
set(p)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let activePointer: number | null = null
|
|
94
|
+
|
|
95
|
+
function onPointerDown(e: PointerEvent) {
|
|
96
|
+
if (props.disabled || e.button > 0) return
|
|
97
|
+
activePointer = e.pointerId
|
|
98
|
+
dragging.value = true
|
|
99
|
+
try { rootEl.value?.setPointerCapture(e.pointerId) } catch { /* not capturable (synthetic) */ }
|
|
100
|
+
fromPointer(e)
|
|
101
|
+
// Keep focus on the handle so the keyboard continues from where the pointer left it
|
|
102
|
+
handleEl.value?.focus({ preventScroll: true })
|
|
103
|
+
e.preventDefault()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function onPointerMove(e: PointerEvent) {
|
|
107
|
+
if (props.disabled) return
|
|
108
|
+
if (dragging.value && e.pointerId === activePointer) fromPointer(e)
|
|
109
|
+
else if (props.hover && !dragging.value && e.pointerType === 'mouse') fromPointer(e)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function endDrag(e: PointerEvent) {
|
|
113
|
+
if (e.pointerId !== activePointer) return
|
|
114
|
+
activePointer = null
|
|
115
|
+
dragging.value = false
|
|
116
|
+
emit('change', inner.value)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const handleEl = ref<HTMLElement | null>(null)
|
|
120
|
+
|
|
121
|
+
function onKeydown(e: KeyboardEvent) {
|
|
122
|
+
if (props.disabled) return
|
|
123
|
+
const big = props.step * 10
|
|
124
|
+
const back = vertical.value ? 'ArrowUp' : 'ArrowLeft'
|
|
125
|
+
const fwd = vertical.value ? 'ArrowDown' : 'ArrowRight'
|
|
126
|
+
let next: number | null = null
|
|
127
|
+
if (e.key === back || (!vertical.value && e.key === 'ArrowDown') || (vertical.value && e.key === 'ArrowLeft')) next = inner.value - props.step
|
|
128
|
+
else if (e.key === fwd || (!vertical.value && e.key === 'ArrowUp') || (vertical.value && e.key === 'ArrowRight')) next = inner.value + props.step
|
|
129
|
+
else if (e.key === 'PageDown') next = inner.value - big
|
|
130
|
+
else if (e.key === 'PageUp') next = inner.value + big
|
|
131
|
+
else if (e.key === 'Home') next = 0
|
|
132
|
+
else if (e.key === 'End') next = 100
|
|
133
|
+
if (next === null) return
|
|
134
|
+
e.preventDefault()
|
|
135
|
+
set(next)
|
|
136
|
+
emit('change', inner.value)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
onBeforeUnmount(() => { activePointer = null })
|
|
140
|
+
|
|
141
|
+
// The "before" layer is clipped to the part left of (above) the divider
|
|
142
|
+
const beforeClip = computed(() =>
|
|
143
|
+
vertical.value ? `inset(0 0 ${100 - position.value}% 0)` : `inset(0 ${100 - position.value}% 0 0)`,
|
|
144
|
+
)
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<template>
|
|
148
|
+
<div
|
|
149
|
+
ref="rootEl"
|
|
150
|
+
class="m3-before-after overflow-hidden select-none"
|
|
151
|
+
:class="[
|
|
152
|
+
vertical ? 'touch-pan-x' : 'touch-pan-y',
|
|
153
|
+
disabled ? 'cursor-default' : vertical ? 'cursor-row-resize' : 'cursor-col-resize',
|
|
154
|
+
]"
|
|
155
|
+
:style="aspectRatio ? { aspectRatio } : undefined"
|
|
156
|
+
@pointerdown="onPointerDown"
|
|
157
|
+
@pointermove="onPointerMove"
|
|
158
|
+
@pointerup="endDrag"
|
|
159
|
+
@pointercancel="endDrag"
|
|
160
|
+
@dragstart.prevent
|
|
161
|
+
>
|
|
162
|
+
<!-- After: the full layer underneath, which also sizes the box when no aspect ratio is given -->
|
|
163
|
+
<div class="m3-before-after__layer" :class="aspectRatio ? 'absolute inset-0' : 'relative'">
|
|
164
|
+
<slot name="after">
|
|
165
|
+
<img v-if="after" :src="after" :alt="afterAlt ?? afterText" draggable="false" class="block h-full w-full object-cover" />
|
|
166
|
+
</slot>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<!-- Before: same box on top, clipped at the divider -->
|
|
170
|
+
<div class="absolute inset-0" :style="{ clipPath: beforeClip }">
|
|
171
|
+
<slot name="before">
|
|
172
|
+
<img v-if="before" :src="before" :alt="beforeAlt ?? beforeText" draggable="false" class="block h-full w-full object-cover" />
|
|
173
|
+
</slot>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<span
|
|
177
|
+
v-if="beforeText"
|
|
178
|
+
class="pointer-events-none absolute rounded-full bg-inverse-surface/70 px-3 py-1 text-label-large text-inverse-on-surface backdrop-blur-sm transition-opacity duration-150"
|
|
179
|
+
:class="vertical ? 'left-1/2 top-3 -translate-x-1/2' : 'left-3 top-3'"
|
|
180
|
+
:style="{ opacity: position < 12 ? 0 : 1 }"
|
|
181
|
+
>{{ beforeText }}</span>
|
|
182
|
+
<span
|
|
183
|
+
v-if="afterText"
|
|
184
|
+
class="pointer-events-none absolute rounded-full bg-inverse-surface/70 px-3 py-1 text-label-large text-inverse-on-surface backdrop-blur-sm transition-opacity duration-150"
|
|
185
|
+
:class="vertical ? 'bottom-3 left-1/2 -translate-x-1/2' : 'right-3 top-3'"
|
|
186
|
+
:style="{ opacity: position > 88 ? 0 : 1 }"
|
|
187
|
+
>{{ afterText }}</span>
|
|
188
|
+
|
|
189
|
+
<!-- Divider + handle -->
|
|
190
|
+
<div
|
|
191
|
+
class="pointer-events-none absolute"
|
|
192
|
+
:class="vertical ? 'inset-x-0 h-0' : 'inset-y-0 w-0'"
|
|
193
|
+
:style="vertical ? { top: `${position}%` } : { left: `${position}%` }"
|
|
194
|
+
>
|
|
195
|
+
<div
|
|
196
|
+
class="m3-before-after__line absolute shadow-elevation-1"
|
|
197
|
+
:class="vertical ? 'inset-x-0 -top-px h-0.5' : 'inset-y-0 -left-px w-0.5'"
|
|
198
|
+
/>
|
|
199
|
+
<div
|
|
200
|
+
ref="handleEl"
|
|
201
|
+
role="slider"
|
|
202
|
+
:tabindex="disabled ? undefined : 0"
|
|
203
|
+
:aria-label="locale.compareSlider"
|
|
204
|
+
:aria-orientation="orientation"
|
|
205
|
+
aria-valuemin="0"
|
|
206
|
+
aria-valuemax="100"
|
|
207
|
+
:aria-valuenow="Math.round(position)"
|
|
208
|
+
:aria-disabled="disabled || undefined"
|
|
209
|
+
class="m3-before-after__handle pointer-events-auto absolute -translate-x-1/2 -translate-y-1/2 outline-none"
|
|
210
|
+
:class="vertical ? 'left-1/2 top-0' : 'left-0 top-1/2'"
|
|
211
|
+
@keydown="onKeydown"
|
|
212
|
+
>
|
|
213
|
+
<slot name="handle" :position="position" :dragging="dragging">
|
|
214
|
+
<div
|
|
215
|
+
v-if="!hideHandle"
|
|
216
|
+
class="m3-before-after__grip flex h-10 w-10 items-center justify-center rounded-full shadow-elevation-2 transition-transform duration-150"
|
|
217
|
+
:class="[dragging ? 'scale-110' : '', vertical ? 'rotate-90' : '']"
|
|
218
|
+
>
|
|
219
|
+
<MIcon name="code" :size="24" />
|
|
220
|
+
</div>
|
|
221
|
+
</slot>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
</template>
|
|
226
|
+
|
|
227
|
+
<style>
|
|
228
|
+
@layer base {
|
|
229
|
+
.m3-before-after {
|
|
230
|
+
position: relative;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
.m3-before-after__handle:focus-visible > * {
|
|
234
|
+
outline: 3px solid var(--color-secondary);
|
|
235
|
+
outline-offset: 2px;
|
|
236
|
+
}
|
|
237
|
+
/* White in both themes: the divider sits on photos, where a theme surface color can vanish */
|
|
238
|
+
.m3-before-after__line {
|
|
239
|
+
background: #fff;
|
|
240
|
+
}
|
|
241
|
+
.m3-before-after__grip {
|
|
242
|
+
background: #fff;
|
|
243
|
+
color: #1d1b20;
|
|
244
|
+
}
|
|
245
|
+
.m3-before-after__layer > img {
|
|
246
|
+
pointer-events: none;
|
|
247
|
+
}
|
|
248
|
+
</style>
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** Marked regions of an `MBodyMap`: region id → level (1…levels). Regions not in the record are unmarked. */
|
|
3
|
+
export type BodyMapValue = Record<string, number>
|
|
4
|
+
|
|
5
|
+
/** A region of the body map, as passed to `select` and the `region` slot. */
|
|
6
|
+
export interface BodyRegion {
|
|
7
|
+
/** e.g. "head", "shoulder-right", "back-calf-left" */
|
|
8
|
+
id: string
|
|
9
|
+
/** Translated name, e.g. "Shoulder, right" */
|
|
10
|
+
label: string
|
|
11
|
+
view: 'front' | 'back'
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
/**
|
|
17
|
+
* A body silhouette, front and back, with regions to mark: where it hurts, an injury, a rash, a tattoo, the site of
|
|
18
|
+
* an injection. Each tap moves a region one level up (with `levels` > 1, e.g. mild → moderate → severe) and back to
|
|
19
|
+
* unmarked. Sides are the patient's: on the front view their right is on the viewer's left.
|
|
20
|
+
*
|
|
21
|
+
* Region ids: `head`, `neck`, `chest-right`, `abdomen`, `pelvis`, `shoulder-left`, `upper-arm-right`,
|
|
22
|
+
* `forearm-left`, `hand-right`, `thigh-left`, `knee-right`, `leg-left`, `foot-right`; on the back view the same
|
|
23
|
+
* prefixed with `back-` (`back-head`, `back-shoulder-left`…) plus `back-upper-back-right`, `back-lower-back`,
|
|
24
|
+
* `back-glute-left`, `back-calf-right`.
|
|
25
|
+
*
|
|
26
|
+
* @slot legend Replaces the levels legend. Slot props: `{ levels, colors, labels }`
|
|
27
|
+
* @event update:modelValue The marked regions — powers v-model
|
|
28
|
+
* @event select A region changed: `{ id, label, view, level }` (level 0 = cleared)
|
|
29
|
+
*/
|
|
30
|
+
import { computed } from 'vue'
|
|
31
|
+
import { useLocale } from '../composables/useLocale'
|
|
32
|
+
|
|
33
|
+
const locale = useLocale()
|
|
34
|
+
|
|
35
|
+
const props = withDefaults(
|
|
36
|
+
defineProps<{
|
|
37
|
+
/** Marked regions: id → level (v-model) */
|
|
38
|
+
modelValue?: BodyMapValue
|
|
39
|
+
/** Levels a region cycles through. 1 = a plain on/off selection */
|
|
40
|
+
levels?: number
|
|
41
|
+
/** Color of each level (any CSS color). Defaults to a ramp from the error container to the error color */
|
|
42
|
+
levelColors?: string[]
|
|
43
|
+
/** Names of the levels, shown in the legend, e.g. ['Mild', 'Moderate', 'Severe'] */
|
|
44
|
+
levelLabels?: string[]
|
|
45
|
+
/** Which side(s) of the body to draw */
|
|
46
|
+
view?: 'front' | 'back' | 'both'
|
|
47
|
+
/** Region ids that can't be marked */
|
|
48
|
+
disabledRegions?: string[]
|
|
49
|
+
/** Shows the marks but doesn't change them */
|
|
50
|
+
readonly?: boolean
|
|
51
|
+
}>(),
|
|
52
|
+
{
|
|
53
|
+
modelValue: () => ({}),
|
|
54
|
+
levels: 1,
|
|
55
|
+
view: 'both',
|
|
56
|
+
disabledRegions: () => [],
|
|
57
|
+
readonly: false,
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const emit = defineEmits<{
|
|
62
|
+
'update:modelValue': [BodyMapValue]
|
|
63
|
+
select: [BodyRegion & { level: number }]
|
|
64
|
+
}>()
|
|
65
|
+
|
|
66
|
+
type Part =
|
|
67
|
+
| 'Head' | 'Neck' | 'Chest' | 'Abdomen' | 'Pelvis' | 'Shoulder' | 'UpperArm' | 'Forearm' | 'Hand'
|
|
68
|
+
| 'Thigh' | 'Knee' | 'Leg' | 'Foot' | 'UpperBack' | 'LowerBack' | 'Glute' | 'Calf'
|
|
69
|
+
|
|
70
|
+
type Shape = { kind: 'rect'; x: number; y: number; w: number; h: number; r: number } | { kind: 'ellipse'; cx: number; cy: number; rx: number; ry: number }
|
|
71
|
+
|
|
72
|
+
/** Shapes on the viewer's left half (x < 100), mirrored for the other side; `mid` shapes sit on the center line */
|
|
73
|
+
interface Piece { front: Part; back: Part; shape: Shape; mid?: boolean }
|
|
74
|
+
|
|
75
|
+
const R = (x: number, y: number, w: number, h: number, r: number): Shape => ({ kind: 'rect', x, y, w, h, r })
|
|
76
|
+
const E = (cx: number, cy: number, rx: number, ry: number): Shape => ({ kind: 'ellipse', cx, cy, rx, ry })
|
|
77
|
+
|
|
78
|
+
const PIECES: Piece[] = [
|
|
79
|
+
{ front: 'Head', back: 'Head', shape: E(100, 30, 19, 23), mid: true },
|
|
80
|
+
{ front: 'Neck', back: 'Neck', shape: R(91, 55, 18, 11, 4), mid: true },
|
|
81
|
+
{ front: 'Shoulder', back: 'Shoulder', shape: E(67, 78, 13, 11) },
|
|
82
|
+
{ front: 'Chest', back: 'UpperBack', shape: R(79, 68, 20.5, 47, 6) },
|
|
83
|
+
{ front: 'Abdomen', back: 'LowerBack', shape: R(79, 117, 42, 46, 6), mid: true },
|
|
84
|
+
{ front: 'UpperArm', back: 'UpperArm', shape: R(53, 91, 17, 58, 8) },
|
|
85
|
+
{ front: 'Forearm', back: 'Forearm', shape: R(49, 151, 16, 58, 7) },
|
|
86
|
+
{ front: 'Hand', back: 'Hand', shape: E(56, 223, 9, 13) },
|
|
87
|
+
{ front: 'Thigh', back: 'Thigh', shape: R(80, 197, 19, 86, 8) },
|
|
88
|
+
{ front: 'Knee', back: 'Knee', shape: E(89.5, 293, 9, 9) },
|
|
89
|
+
{ front: 'Leg', back: 'Calf', shape: R(81, 304, 17, 78, 7) },
|
|
90
|
+
{ front: 'Foot', back: 'Foot', shape: E(87, 394, 10, 7) },
|
|
91
|
+
]
|
|
92
|
+
// The pelvis is one piece on the front and two buttocks on the back
|
|
93
|
+
const PELVIS_FRONT: Shape = R(79, 165, 42, 30, 8)
|
|
94
|
+
const GLUTE: Shape = R(79, 165, 20.5, 30, 8)
|
|
95
|
+
|
|
96
|
+
/** Parts that only exist on the back, so their name needs no "(back)" */
|
|
97
|
+
const BACK_ONLY: Part[] = ['UpperBack', 'LowerBack', 'Glute', 'Calf']
|
|
98
|
+
|
|
99
|
+
function mirror(s: Shape): Shape {
|
|
100
|
+
return s.kind === 'rect' ? { ...s, x: 200 - s.x - s.w } : { ...s, cx: 200 - s.cx }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const kebab = (p: Part) => p.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
|
|
104
|
+
|
|
105
|
+
interface Region extends BodyRegion { shape: Shape }
|
|
106
|
+
|
|
107
|
+
function partLabel(part: Part, side: 'right' | 'left' | null, view: 'front' | 'back') {
|
|
108
|
+
let name = locale[`body${part}` as keyof typeof locale] as string
|
|
109
|
+
if (side) name = (side === 'right' ? locale.bodyRight : locale.bodyLeft).replace('{part}', name)
|
|
110
|
+
if (view === 'back' && !BACK_ONLY.includes(part)) name = locale.bodyRear.replace('{part}', name)
|
|
111
|
+
return name
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function region(view: 'front' | 'back', part: Part, side: 'right' | 'left' | null, shape: Shape): Region {
|
|
115
|
+
const id = `${view === 'back' ? 'back-' : ''}${kebab(part)}${side ? `-${side}` : ''}`
|
|
116
|
+
return { id, view, shape, label: partLabel(part, side, view) }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function build(view: 'front' | 'back'): Region[] {
|
|
120
|
+
const out: Region[] = []
|
|
121
|
+
// Front: the viewer's left is the patient's right. Back: the viewer's left is the patient's left
|
|
122
|
+
const leftSide = view === 'front' ? 'right' : 'left'
|
|
123
|
+
const rightSide = view === 'front' ? 'left' : 'right'
|
|
124
|
+
for (const p of PIECES) {
|
|
125
|
+
const part = view === 'front' ? p.front : p.back
|
|
126
|
+
if (p.mid) out.push(region(view, part, null, p.shape))
|
|
127
|
+
else {
|
|
128
|
+
out.push(region(view, part, leftSide, p.shape))
|
|
129
|
+
out.push(region(view, part, rightSide, mirror(p.shape)))
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (view === 'front') out.push(region(view, 'Pelvis', null, PELVIS_FRONT))
|
|
133
|
+
else {
|
|
134
|
+
out.push(region(view, 'Glute', leftSide, GLUTE))
|
|
135
|
+
out.push(region(view, 'Glute', rightSide, mirror(GLUTE)))
|
|
136
|
+
}
|
|
137
|
+
return out
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const views = computed(() => {
|
|
141
|
+
const v: { key: 'front' | 'back'; label: string; regions: Region[] }[] = []
|
|
142
|
+
if (props.view !== 'back') v.push({ key: 'front', label: locale.bodyFront, regions: build('front') })
|
|
143
|
+
if (props.view !== 'front') v.push({ key: 'back', label: locale.bodyBack, regions: build('back') })
|
|
144
|
+
return v
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
const colors = computed(() =>
|
|
148
|
+
Array.from({ length: props.levels }, (_, i) =>
|
|
149
|
+
props.levelColors?.[i] ??
|
|
150
|
+
(props.levels === 1
|
|
151
|
+
? 'var(--color-error)'
|
|
152
|
+
: // from the error container (mildest) to the error color (worst): far apart in both themes
|
|
153
|
+
`color-mix(in srgb, var(--color-error) ${Math.round((100 * i) / (props.levels - 1))}%, var(--color-error-container))`),
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
function levelOf(id: string) {
|
|
158
|
+
return Math.min(props.levels, Math.max(0, props.modelValue[id] ?? 0))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function disabled(id: string) {
|
|
162
|
+
return props.readonly || props.disabledRegions.includes(id)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function setLevel(r: Region, level: number) {
|
|
166
|
+
if (disabled(r.id)) return
|
|
167
|
+
const next = { ...props.modelValue }
|
|
168
|
+
if (level > 0) next[r.id] = level
|
|
169
|
+
else delete next[r.id]
|
|
170
|
+
emit('update:modelValue', next)
|
|
171
|
+
emit('select', { id: r.id, label: r.label, view: r.view, level })
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function cycle(r: Region) {
|
|
175
|
+
setLevel(r, (levelOf(r.id) + 1) % (props.levels + 1))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function onKeydown(e: KeyboardEvent, r: Region) {
|
|
179
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
180
|
+
e.preventDefault()
|
|
181
|
+
cycle(r)
|
|
182
|
+
} else if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
183
|
+
e.preventDefault()
|
|
184
|
+
setLevel(r, 0)
|
|
185
|
+
} else if (/^[0-9]$/.test(e.key) && Number(e.key) <= props.levels) {
|
|
186
|
+
e.preventDefault()
|
|
187
|
+
setLevel(r, Number(e.key))
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function ariaLabel(r: Region) {
|
|
192
|
+
const l = levelOf(r.id)
|
|
193
|
+
if (!l || props.levels === 1) return r.label
|
|
194
|
+
return `${r.label}: ${props.levelLabels?.[l - 1] ?? l}`
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const showLegend = computed(() => props.levels > 1 || !!props.levelLabels?.length)
|
|
198
|
+
</script>
|
|
199
|
+
|
|
200
|
+
<template>
|
|
201
|
+
<div class="m3-body-map flex flex-col items-center gap-3 text-on-surface">
|
|
202
|
+
<div class="flex w-full justify-center gap-4">
|
|
203
|
+
<figure v-for="v in views" :key="v.key" class="flex min-w-0 max-w-56 flex-1 flex-col items-center gap-1">
|
|
204
|
+
<svg viewBox="0 0 200 410" class="block w-full" role="group" :aria-label="v.label" :data-view="v.key">
|
|
205
|
+
<template v-for="r in v.regions" :key="r.id">
|
|
206
|
+
<component
|
|
207
|
+
:is="r.shape.kind"
|
|
208
|
+
v-bind="r.shape.kind === 'rect'
|
|
209
|
+
? { x: r.shape.x, y: r.shape.y, width: r.shape.w, height: r.shape.h, rx: r.shape.r }
|
|
210
|
+
: { cx: r.shape.cx, cy: r.shape.cy, rx: r.shape.rx, ry: r.shape.ry }"
|
|
211
|
+
class="m3-body-map__region"
|
|
212
|
+
:class="{ 'is-disabled': disabled(r.id) }"
|
|
213
|
+
:style="levelOf(r.id) ? { fill: colors[levelOf(r.id) - 1] } : undefined"
|
|
214
|
+
:tabindex="disabled(r.id) ? -1 : 0"
|
|
215
|
+
role="checkbox"
|
|
216
|
+
:aria-checked="levelOf(r.id) > 0"
|
|
217
|
+
:aria-label="ariaLabel(r)"
|
|
218
|
+
:aria-disabled="disabled(r.id) || undefined"
|
|
219
|
+
:data-region="r.id"
|
|
220
|
+
:data-level="levelOf(r.id) || undefined"
|
|
221
|
+
@click="cycle(r)"
|
|
222
|
+
@keydown="onKeydown($event, r)"
|
|
223
|
+
>
|
|
224
|
+
<title>{{ ariaLabel(r) }}</title>
|
|
225
|
+
</component>
|
|
226
|
+
</template>
|
|
227
|
+
</svg>
|
|
228
|
+
<figcaption v-if="view === 'both'" class="text-label-large text-on-surface-variant">{{ v.label }}</figcaption>
|
|
229
|
+
</figure>
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
<div v-if="showLegend" class="flex flex-wrap justify-center gap-x-4 gap-y-1" data-legend>
|
|
233
|
+
<slot name="legend" :levels="levels" :colors="colors" :labels="levelLabels">
|
|
234
|
+
<span v-for="(c, i) in colors" :key="i" class="flex items-center gap-1.5 text-label-large">
|
|
235
|
+
<span class="h-3 w-3 rounded-full" :style="{ background: c }" />
|
|
236
|
+
{{ levelLabels?.[i] ?? i + 1 }}
|
|
237
|
+
</span>
|
|
238
|
+
</slot>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
</template>
|
|
242
|
+
|
|
243
|
+
<style>
|
|
244
|
+
.m3-body-map__region {
|
|
245
|
+
fill: var(--color-surface-container-highest);
|
|
246
|
+
stroke: var(--color-outline-variant);
|
|
247
|
+
stroke-width: 1;
|
|
248
|
+
cursor: pointer;
|
|
249
|
+
outline: none;
|
|
250
|
+
transition: fill 150ms ease;
|
|
251
|
+
}
|
|
252
|
+
.m3-body-map__region:not(.is-disabled):not([data-level]):hover {
|
|
253
|
+
fill: color-mix(in srgb, var(--color-on-surface) 12%, var(--color-surface-container-highest));
|
|
254
|
+
}
|
|
255
|
+
.m3-body-map__region[data-level]:hover {
|
|
256
|
+
filter: brightness(1.08);
|
|
257
|
+
}
|
|
258
|
+
.m3-body-map__region:focus-visible {
|
|
259
|
+
stroke: var(--color-secondary);
|
|
260
|
+
stroke-width: 3;
|
|
261
|
+
}
|
|
262
|
+
.m3-body-map__region.is-disabled {
|
|
263
|
+
cursor: default;
|
|
264
|
+
opacity: 0.4;
|
|
265
|
+
}
|
|
266
|
+
</style>
|