@m3ui-vue/m3ui-vue 0.8.5 → 0.8.6

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.
Files changed (49) hide show
  1. package/README.md +1 -1
  2. package/dist/{MMenuItem-BXIxwIdM.js → MMenuItem-BmPLAyv5.js} +2 -2
  3. package/dist/{MMenuItem-BXIxwIdM.js.map → MMenuItem-BmPLAyv5.js.map} +1 -1
  4. package/dist/code-editor.js +1 -1
  5. package/dist/components/MChatBubble.vue.d.ts +4 -2
  6. package/dist/components/MCheckbox.vue.d.ts +2 -0
  7. package/dist/components/MDragDropList.vue.d.ts +19 -6
  8. package/dist/components/MFileUpload.vue.d.ts +16 -4
  9. package/dist/components/MKanban.vue.d.ts +15 -6
  10. package/dist/components/MTransferList.vue.d.ts +9 -3
  11. package/dist/components/_MTransferPane.vue.d.ts +39 -0
  12. package/dist/composables/useLocale.d.ts +24 -0
  13. package/dist/locales/index.js +175 -7
  14. package/dist/locales/index.js.map +1 -1
  15. package/dist/m3ui-vue.css +1 -1
  16. package/dist/m3ui.js +3576 -2679
  17. package/dist/m3ui.js.map +1 -1
  18. package/dist/rich-text-editor.js +2 -2
  19. package/dist/styles.css +1 -1
  20. package/dist/{useLocale-DbREg9Zn.js → useLocale-4afAzuuP.js} +26 -2
  21. package/dist/useLocale-4afAzuuP.js.map +1 -0
  22. package/package.json +1 -1
  23. package/src/__tests__/MChatBubble.test.ts +33 -0
  24. package/src/__tests__/MDragDropList.test.ts +194 -0
  25. package/src/__tests__/MFileUpload.test.ts +78 -0
  26. package/src/__tests__/MKanban.test.ts +150 -0
  27. package/src/__tests__/MPullToRefresh.test.ts +67 -0
  28. package/src/__tests__/MRating.test.ts +72 -0
  29. package/src/__tests__/MTransferList.test.ts +76 -0
  30. package/src/components/MChatBubble.vue +107 -20
  31. package/src/components/MCheckbox.vue +3 -0
  32. package/src/components/MDragDropList.vue +485 -56
  33. package/src/components/MFileUpload.vue +56 -20
  34. package/src/components/MKanban.vue +720 -78
  35. package/src/components/MNavigationRail.vue +35 -23
  36. package/src/components/MPullToRefresh.vue +101 -35
  37. package/src/components/MRating.vue +163 -67
  38. package/src/components/MResult.vue +19 -9
  39. package/src/components/MTransferList.vue +133 -130
  40. package/src/components/_MTransferPane.vue +182 -0
  41. package/src/composables/useLocale.ts +68 -0
  42. package/src/locales/de.ts +34 -0
  43. package/src/locales/es.ts +34 -0
  44. package/src/locales/fr.ts +34 -0
  45. package/src/locales/ja.ts +34 -0
  46. package/src/locales/ko.ts +34 -0
  47. package/src/locales/pt.ts +34 -0
  48. package/src/locales/zh.ts +34 -0
  49. package/dist/useLocale-DbREg9Zn.js.map +0 -1
@@ -223,11 +223,19 @@ onUnmounted(() => {
223
223
  the pill (inline-flex, no explicit width) resizes right along with it via ordinary
224
224
  flex layout — no separate width bookkeeping needed. The pill is always left-anchored
225
225
  with a constant `pl-4`, so the icon's horizontal position never moves at all.
226
+
227
+ The pill NEVER gets an explicit width, collapsed included: collapsed it's
228
+ pl-4 + 24px icon + pr-4 + a 0-wide label = exactly 56dp, the same as the old `w-14`.
229
+ Switching `auto` <-> `w-14` can't be transitioned (auto isn't interpolable), so on
230
+ collapse the pill snapped to 56px on the first frame and flex-shrink squeezed the
231
+ still-visible label to 0, which then regrew a few px before clipping away — the
232
+ label visibly vanished and popped back. Keeping width content-driven in both
233
+ states means it only ever follows the label's own animated width.
226
234
  -->
227
235
  <span
228
- class="absolute left-0 inline-flex items-center pl-4 rounded-full transition-all duration-200"
236
+ class="absolute left-0 inline-flex items-center pl-4 pr-4 rounded-full transition-all duration-200"
229
237
  :class="[
230
- railExpanded ? 'top-1 h-14 pr-4' : 'top-1.5 h-8 w-14',
238
+ railExpanded ? 'top-1 h-14' : 'top-1.5 h-8',
231
239
  item.value === modelValue
232
240
  ? 'bg-secondary-container text-on-secondary-container'
233
241
  : 'bg-transparent text-on-surface-variant group-hover:bg-on-surface/8',
@@ -246,26 +254,28 @@ onUnmounted(() => {
246
254
  margin, so it doesn't leave a gap when collapsed) grows left-to-right out of the
247
255
  icon's edge, so the text reads as emerging out of the icon rather than fading in
248
256
  in place. Text itself never moves — only the clipping box's width animates.
249
- Animating `max-width` rather than `width` (up to a generous 200px cap, well past
250
- any realistic label) is what lets the box settle at the label's own intrinsic
251
- width once expanded — a plain `width` transition would need a fixed end value,
252
- which is exactly the old bug: every label reveal stopped at the same hardcoded
253
- 130px regardless of text length, leaving dead space in the pill after a short
254
- label like "Home" instead of hugging it. `whitespace-nowrap` plus `inline-block`
255
- keep it shrink-to-fit and from reflowing as max-width changes. Opacity animates
257
+ The width animates via a one-column grid, `grid-template-columns: 0fr <-> 1fr`
258
+ (the inner span is `min-w-0 overflow-hidden`), which interpolates straight to the
259
+ label's own intrinsic width. Earlier versions used `width` (fixed end value, every
260
+ pill stopped at the same 130px regardless of text) and then `max-width: 0 <-> 200px`
261
+ (hugged the text, but since 200px is far past a label like "Home" (~38px), most of
262
+ the transition changed nothing visible and the real shrink was crammed into its
263
+ last few frames). `whitespace-nowrap` keeps the text from reflowing. Opacity animates
256
264
  alongside it so collapsing reads as fading out while it shrinks, rather than
257
265
  staying solid until the box clips it. Its own text color intentionally differs from
258
266
  the pill's (`text-secondary` vs the pill's `text-on-secondary-container`) — M3's
259
267
  `ItemActiveLabelTextColor` is a different token from `ItemActiveIconColor`.
260
268
  -->
261
269
  <span
262
- class="inline-block overflow-hidden whitespace-nowrap text-left text-label-large font-medium transition-[max-width,opacity,margin-left] duration-200"
263
- :class="[
264
- railExpanded ? 'ml-2 max-w-[200px] opacity-100' : 'ml-0 max-w-0 opacity-0',
265
- item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant',
266
- ]"
270
+ class="grid transition-[grid-template-columns,opacity,margin-left] duration-200"
271
+ :class="railExpanded ? 'ml-2 grid-cols-[1fr] opacity-100' : 'ml-0 grid-cols-[0fr] opacity-0'"
267
272
  >
268
- {{ item.label }}
273
+ <span
274
+ class="min-w-0 overflow-hidden whitespace-nowrap text-left text-label-large font-medium"
275
+ :class="item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant'"
276
+ >
277
+ {{ item.label }}
278
+ </span>
269
279
  </span>
270
280
  </span>
271
281
 
@@ -334,9 +344,9 @@ onUnmounted(() => {
334
344
  @click="selectModal(item)"
335
345
  >
336
346
  <span
337
- class="absolute left-0 inline-flex items-center pl-4 rounded-full transition-all duration-200"
347
+ class="absolute left-0 inline-flex items-center pl-4 pr-4 rounded-full transition-all duration-200"
338
348
  :class="[
339
- panelExpanded ? 'top-1 h-14 pr-4' : 'top-1.5 h-8 w-14',
349
+ panelExpanded ? 'top-1 h-14' : 'top-1.5 h-8',
340
350
  item.value === modelValue
341
351
  ? 'bg-secondary-container text-on-secondary-container'
342
352
  : 'bg-transparent text-on-surface-variant group-hover:bg-on-surface/8',
@@ -351,13 +361,15 @@ onUnmounted(() => {
351
361
  <MIcon v-else :name="item.icon" :size="24" />
352
362
 
353
363
  <span
354
- class="inline-block overflow-hidden whitespace-nowrap text-left text-label-large font-medium transition-[max-width,opacity,margin-left] duration-200"
355
- :class="[
356
- panelExpanded ? 'ml-2 max-w-[200px] opacity-100' : 'ml-0 max-w-0 opacity-0',
357
- item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant',
358
- ]"
364
+ class="grid transition-[grid-template-columns,opacity,margin-left] duration-200"
365
+ :class="panelExpanded ? 'ml-2 grid-cols-[1fr] opacity-100' : 'ml-0 grid-cols-[0fr] opacity-0'"
359
366
  >
360
- {{ item.label }}
367
+ <span
368
+ class="min-w-0 overflow-hidden whitespace-nowrap text-left text-label-large font-medium"
369
+ :class="item.value === modelValue ? 'text-secondary' : 'text-on-surface-variant'"
370
+ >
371
+ {{ item.label }}
372
+ </span>
361
373
  </span>
362
374
  </span>
363
375
 
@@ -68,54 +68,38 @@ function hideIndicator(animate: boolean) {
68
68
  el.style.opacity = "0";
69
69
  }
70
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;
71
+ function canStart() {
72
+ return !props.disabled && !props.refreshing && !committed && !!scrollEl.value && scrollEl.value.scrollTop <= 0;
73
+ }
74
+
75
+ function beginPull(y: number) {
76
+ startY = y;
76
77
  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);
78
+ pullDistance = 0;
88
79
  }
89
80
 
90
- function onPointerMove(e: PointerEvent) {
91
- if (!pulling || e.pointerId !== pointerId) return;
92
- const raw = e.clientY - startY;
81
+ // Returns true when the move is part of a pull (caller should block native scrolling).
82
+ function movePull(y: number): boolean {
83
+ const raw = y - startY;
93
84
  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
85
  pullDistance = 0;
97
86
  hideIndicator(false);
98
- if (scrollEl.value) scrollEl.value.style.touchAction = "";
99
- return;
87
+ return false;
100
88
  }
101
- e.preventDefault();
89
+ if (!isPulling.value) isPulling.value = true;
102
90
  const maxPull = props.threshold * MAX_PULL_MULTIPLIER;
103
91
  pullDistance = Math.min(
104
92
  raw <= props.threshold ? raw : props.threshold + (raw - props.threshold) * RESISTANCE,
105
93
  maxPull,
106
94
  );
107
95
  previewIndicator(pullDistance);
96
+ return true;
108
97
  }
109
98
 
110
- function endPull(e: PointerEvent) {
111
- if (!pulling || e.pointerId !== pointerId) return;
99
+ function finishPull() {
100
+ if (!pulling) return;
112
101
  pulling = false;
113
102
  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
103
  if (pullDistance >= props.threshold) {
120
104
  committed = true;
121
105
  settleIndicator(true);
@@ -126,6 +110,73 @@ function endPull(e: PointerEvent) {
126
110
  pullDistance = 0;
127
111
  }
128
112
 
113
+ // Mouse/pen: pointer events. Touch is handled separately below — a touch's
114
+ // `touch-action` is resolved by the browser when the finger lands, before any
115
+ // pointerdown handler runs, so it can't be switched to `none` mid-gesture: the
116
+ // browser starts a native pan and fires pointercancel, snapping the indicator
117
+ // back. The only reliable way to own a touch drag is a non-passive touchmove
118
+ // that calls preventDefault().
119
+ function onPointerDown(e: PointerEvent) {
120
+ if (e.pointerType === "touch" || e.button !== 0 || !canStart()) return;
121
+ pointerId = e.pointerId;
122
+ beginPull(e.clientY);
123
+ scrollEl.value!.setPointerCapture(e.pointerId);
124
+ }
125
+
126
+ function onPointerMove(e: PointerEvent) {
127
+ if (!pulling || e.pointerId !== pointerId) return;
128
+ movePull(e.clientY);
129
+ }
130
+
131
+ function onPointerEnd(e: PointerEvent) {
132
+ if (!pulling || e.pointerId !== pointerId) return;
133
+ pointerId = null;
134
+ if (scrollEl.value?.hasPointerCapture(e.pointerId)) scrollEl.value.releasePointerCapture(e.pointerId);
135
+ finishPull();
136
+ }
137
+
138
+ let touchId: number | null = null;
139
+ // Whether this touch gesture has been claimed as a pull (vs. a normal scroll).
140
+ let touchClaimed = false;
141
+
142
+ function onTouchStart(e: TouchEvent) {
143
+ if (e.touches.length !== 1 || !canStart()) return;
144
+ const t = e.touches[0]!;
145
+ touchId = t.identifier;
146
+ touchClaimed = false;
147
+ beginPull(t.clientY);
148
+ }
149
+
150
+ function onTouchMove(e: TouchEvent) {
151
+ if (!pulling || touchId === null) return;
152
+ const t = Array.from(e.changedTouches).find((x) => x.identifier === touchId);
153
+ if (!t) return;
154
+ if (!touchClaimed) {
155
+ // First move decides: dragging up (or the list has scrolled since touchstart)
156
+ // is a normal scroll — let the browser have the rest of the gesture.
157
+ if (t.clientY <= startY || (scrollEl.value?.scrollTop ?? 0) > 0) {
158
+ if (t.clientY < startY) {
159
+ pulling = false;
160
+ touchId = null;
161
+ }
162
+ return;
163
+ }
164
+ touchClaimed = true;
165
+ }
166
+ // Once claimed, keep blocking native scroll for the whole gesture (even if the
167
+ // finger moves back up) — browsers don't reliably hand a prevented gesture back.
168
+ if (e.cancelable) e.preventDefault();
169
+ movePull(t.clientY);
170
+ }
171
+
172
+ function onTouchEnd(e: TouchEvent) {
173
+ if (touchId === null) return;
174
+ if (!Array.from(e.changedTouches).some((x) => x.identifier === touchId)) return;
175
+ touchId = null;
176
+ touchClaimed = false;
177
+ finishPull();
178
+ }
179
+
129
180
  // Also settles the indicator when a refresh is triggered programmatically
130
181
  // (not from a drag) and releases it once the caller clears `refreshing`.
131
182
  watch(
@@ -148,11 +199,26 @@ watch(
148
199
  // template. A reactive `:style` there would fight this: Vue re-patches any
149
200
  // style property it tracks on every re-render of this component (and
150
201
  // `isPulling` toggling — used below for the `select-none` class — forces
151
- // exactly such a re-render right at pointerdown/endPull), stomping whatever
202
+ // exactly such a re-render right as a pull starts and finishes), stomping whatever
152
203
  // transform we'd just applied back to its bound value.
153
- onMounted(() => hideIndicator(false));
204
+ onMounted(() => {
205
+ hideIndicator(false);
206
+ const el = scrollEl.value;
207
+ if (!el) return;
208
+ el.addEventListener("touchstart", onTouchStart, { passive: true });
209
+ // Must be non-passive: preventDefault() here is what stops the native scroll.
210
+ el.addEventListener("touchmove", onTouchMove, { passive: false });
211
+ el.addEventListener("touchend", onTouchEnd);
212
+ el.addEventListener("touchcancel", onTouchEnd);
213
+ });
154
214
  onBeforeUnmount(() => {
155
215
  pulling = false;
216
+ const el = scrollEl.value;
217
+ if (!el) return;
218
+ el.removeEventListener("touchstart", onTouchStart);
219
+ el.removeEventListener("touchmove", onTouchMove);
220
+ el.removeEventListener("touchend", onTouchEnd);
221
+ el.removeEventListener("touchcancel", onTouchEnd);
156
222
  });
157
223
  </script>
158
224
 
@@ -171,8 +237,8 @@ onBeforeUnmount(() => {
171
237
  :class="{ 'select-none': isPulling }"
172
238
  @pointerdown="onPointerDown"
173
239
  @pointermove="onPointerMove"
174
- @pointerup="endPull"
175
- @pointercancel="endPull"
240
+ @pointerup="onPointerEnd"
241
+ @pointercancel="onPointerEnd"
176
242
  >
177
243
  <slot />
178
244
  </div>
@@ -2,6 +2,9 @@
2
2
  import { computed, ref } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
4
 
5
+ // Not part of the official M3 spec — built from M3 primitives instead: filled/outlined
6
+ // Material Symbol pairs, on-surface-variant for the unselected icon, a 40px circular
7
+ // hover/press state layer (8%/10%) tinted with the active color, and a secondary focus ring.
5
8
  const props = withDefaults(defineProps<{
6
9
  modelValue: number
7
10
  max?: number
@@ -15,94 +18,187 @@ const props = withDefaults(defineProps<{
15
18
 
16
19
  const emit = defineEmits<{ 'update:modelValue': [number] }>()
17
20
 
18
- const hovered = ref(-1)
21
+ const ROLE_COLORS: Record<string, string> = {
22
+ primary: 'text-primary',
23
+ secondary: 'text-secondary',
24
+ tertiary: 'text-tertiary',
25
+ error: 'text-error',
26
+ }
27
+
28
+ const colorClass = computed(() => ROLE_COLORS[props.color] ?? '')
29
+ const customStyle = computed(() => (props.color in ROLE_COLORS ? undefined : { color: props.color }))
30
+
31
+ const interactive = computed(() => !props.readonly && !props.disabled)
32
+ const step = computed(() => (props.halfIncrements ? 0.5 : 1))
33
+
34
+ const rootEl = ref<HTMLElement | null>(null)
35
+ const itemEls: HTMLElement[] = []
36
+
37
+ // Pointer preview: `value` is what the rating would become, `index` is the item under the
38
+ // pointer (drives the state layer). Null when the pointer isn't over the component.
39
+ const hover = ref<{ index: number; value: number } | null>(null)
40
+ const pressed = ref(false)
41
+
42
+ const clamp = (v: number) => Math.min(props.max, Math.max(0, v))
43
+
44
+ const displayValue = computed(() =>
45
+ !pressed.value && hover.value ? hover.value.value : clamp(props.modelValue || 0),
46
+ )
47
+
48
+ // Per-item fill fraction (0..1). Arbitrary fractions render exactly (e.g. a readonly 4.3
49
+ // average shows 30% of the 5th icon), not just whole/half steps.
50
+ const fills = computed(() =>
51
+ Array.from({ length: props.max }, (_, i) => Math.min(1, Math.max(0, displayValue.value - i))),
52
+ )
19
53
 
20
- const colorClass = computed(() => {
21
- const map: Record<string, string> = {
22
- primary: 'text-primary',
23
- secondary: 'text-secondary',
24
- tertiary: 'text-tertiary',
25
- error: 'text-error',
54
+ function pointerTarget(e: PointerEvent): { index: number; value: number } | null {
55
+ if (!itemEls.length) return null
56
+ const rtl = rootEl.value ? getComputedStyle(rootEl.value).direction === 'rtl' : false
57
+ const first = itemEls[0]!.getBoundingClientRect()
58
+ // Dragging past the start edge clears to 0 — the only pointer path to an empty rating.
59
+ if (pressed.value && (rtl ? e.clientX > first.right : e.clientX < first.left)) {
60
+ return { index: 0, value: 0 }
26
61
  }
27
- return map[props.color] || ''
28
- })
29
-
30
- const customStyle = computed(() => {
31
- if (['primary', 'secondary', 'tertiary', 'error'].includes(props.color)) return undefined
32
- return { color: props.color }
33
- })
34
-
35
- function valueAt(index: number, e?: MouseEvent) {
36
- if (!props.halfIncrements) return index + 1
37
- if (!e) return index + 1
38
- const rect = (e.currentTarget as HTMLElement).getBoundingClientRect()
39
- const half = (e.clientX - rect.left) < rect.width / 2
40
- return half ? index + 0.5 : index + 1
62
+ for (let i = 0; i < itemEls.length; i++) {
63
+ const r = itemEls[i]!.getBoundingClientRect()
64
+ const isLast = i === itemEls.length - 1
65
+ if (!isLast && (rtl ? e.clientX < r.left : e.clientX > r.right)) continue
66
+ const frac = rtl ? (r.right - e.clientX) / r.width : (e.clientX - r.left) / r.width
67
+ const value = props.halfIncrements && frac < 0.5 ? i + 0.5 : i + 1
68
+ return { index: i, value }
69
+ }
70
+ return null
71
+ }
72
+
73
+ function commit(v: number) {
74
+ const next = clamp(v)
75
+ if (next !== props.modelValue) emit('update:modelValue', next)
76
+ }
77
+
78
+ function onPointerDown(e: PointerEvent) {
79
+ if (!interactive.value || e.button !== 0) return
80
+ pressed.value = true
81
+ rootEl.value?.setPointerCapture(e.pointerId)
82
+ const t = pointerTarget(e)
83
+ hover.value = t
84
+ if (t) commit(t.value)
41
85
  }
42
86
 
43
- function onClick(index: number, e: MouseEvent) {
44
- if (props.readonly || props.disabled) return
45
- const v = valueAt(index, e)
46
- emit('update:modelValue', v === props.modelValue ? 0 : v)
87
+ function onPointerMove(e: PointerEvent) {
88
+ if (!interactive.value) return
89
+ if (!pressed.value && e.pointerType !== 'mouse') return
90
+ const t = pointerTarget(e)
91
+ hover.value = t
92
+ if (pressed.value && t) commit(t.value)
47
93
  }
48
94
 
49
- function onMove(index: number, e: MouseEvent) {
50
- if (props.readonly || props.disabled) return
51
- hovered.value = valueAt(index, e)
95
+ function onPointerUp(e: PointerEvent) {
96
+ if (!pressed.value) return
97
+ pressed.value = false
98
+ rootEl.value?.releasePointerCapture(e.pointerId)
99
+ if (e.pointerType !== 'mouse') hover.value = null
52
100
  }
53
101
 
54
- function onLeave() {
55
- hovered.value = -1
102
+ function onPointerLeave() {
103
+ if (!pressed.value) hover.value = null
56
104
  }
57
105
 
58
- function iconName(index: number) {
59
- const active = hovered.value >= 0 ? hovered.value : props.modelValue
60
- if (index + 1 <= active) return props.icon
61
- if (props.halfIncrements && index + 0.5 <= active) return props.icon + '_half'
62
- return props.icon + '_border' // outlined variant not available for all icons
106
+ function onKeydown(e: KeyboardEvent) {
107
+ if (!interactive.value) return
108
+ const rtl = rootEl.value ? getComputedStyle(rootEl.value).direction === 'rtl' : false
109
+ const current = clamp(props.modelValue || 0)
110
+ let next: number
111
+ switch (e.key) {
112
+ case 'ArrowUp':
113
+ next = current + step.value
114
+ break
115
+ case 'ArrowDown':
116
+ next = current - step.value
117
+ break
118
+ case 'ArrowRight':
119
+ next = current + (rtl ? -step.value : step.value)
120
+ break
121
+ case 'ArrowLeft':
122
+ next = current + (rtl ? step.value : -step.value)
123
+ break
124
+ case 'Home':
125
+ next = 0
126
+ break
127
+ case 'End':
128
+ next = props.max
129
+ break
130
+ default:
131
+ return
132
+ }
133
+ e.preventDefault()
134
+ // Snap to the step grid so an off-grid modelValue (e.g. 3.7) moves to a valid value.
135
+ commit(Math.round(next / step.value) * step.value)
63
136
  }
64
137
 
65
- function isFilled(index: number) {
66
- const active = hovered.value >= 0 ? hovered.value : props.modelValue
67
- return index + 1 <= active || (props.halfIncrements && index + 0.5 <= active)
138
+ function stateLayerClass(i: number) {
139
+ if (!interactive.value || hover.value?.index !== i) return 'opacity-0'
140
+ return pressed.value ? 'opacity-[0.10]' : 'opacity-[0.08]'
68
141
  }
142
+
143
+ const valueText = computed(() => `${clamp(props.modelValue || 0)} / ${props.max}`)
69
144
  </script>
70
145
 
71
146
  <template>
72
147
  <div
73
- class="inline-flex items-center gap-0.5"
74
- :class="disabled ? 'opacity-[0.38]' : ''"
75
- @mouseleave="onLeave"
148
+ ref="rootEl"
149
+ class="inline-flex select-none items-center gap-0.5 rounded-full outline-none ring-secondary focus-visible:ring-2"
150
+ :class="interactive ? 'cursor-pointer touch-pan-y' : 'cursor-default'"
151
+ :role="readonly ? 'img' : 'slider'"
152
+ :tabindex="interactive ? 0 : undefined"
153
+ :aria-label="readonly ? valueText : undefined"
154
+ :aria-valuemin="readonly ? undefined : 0"
155
+ :aria-valuemax="readonly ? undefined : max"
156
+ :aria-valuenow="readonly ? undefined : clamp(modelValue || 0)"
157
+ :aria-valuetext="readonly ? undefined : valueText"
158
+ :aria-disabled="disabled || undefined"
159
+ @pointerdown="onPointerDown"
160
+ @pointermove="onPointerMove"
161
+ @pointerup="onPointerUp"
162
+ @pointercancel="onPointerUp"
163
+ @pointerleave="onPointerLeave"
164
+ @keydown="onKeydown"
76
165
  >
77
- <button
78
- v-for="i in max"
166
+ <span
167
+ v-for="(fill, i) in fills"
79
168
  :key="i"
80
- type="button"
81
- class="relative inline-flex items-center justify-center rounded-full p-0.5 transition-transform duration-100"
82
- :class="[
83
- readonly || disabled ? 'cursor-default' : 'cursor-pointer hover:scale-110',
84
- ]"
85
- :style="customStyle"
86
- :disabled="disabled"
87
- @click="onClick(i - 1, $event)"
88
- @mousemove="onMove(i - 1, $event)"
169
+ :ref="(el) => { if (el) itemEls[i] = el as HTMLElement }"
170
+ class="relative inline-flex shrink-0"
171
+ :style="{ width: `${size + 4}px`, height: `${size + 4}px` }"
89
172
  >
90
- <!-- Filled star -->
91
- <MIcon
92
- v-if="isFilled(i - 1)"
93
- :name="icon"
94
- :size="size"
95
- :class="colorClass"
173
+ <!-- State layer: overhangs the item by 4px per side (size 28 → 40px circle) without
174
+ changing the component's footprint; only one is visible at a time. -->
175
+ <span
176
+ class="pointer-events-none absolute -inset-1 rounded-full bg-current transition-opacity duration-150"
177
+ :class="[colorClass, stateLayerClass(i)]"
96
178
  :style="customStyle"
97
- style="font-variation-settings: 'FILL' 1"
98
- />
99
- <!-- Empty star -->
100
- <MIcon
101
- v-else
102
- :name="icon"
103
- :size="size"
104
- class="text-on-surface-variant/40"
105
179
  />
106
- </button>
180
+ <span class="absolute inset-0.5">
181
+ <!-- Unfilled part (outlined glyph), clipped from the end side -->
182
+ <span class="absolute inset-y-0 end-0 overflow-hidden" :style="{ width: `${(1 - fill) * 100}%` }">
183
+ <MIcon
184
+ :name="icon"
185
+ :size="size"
186
+ class="absolute end-0 top-0"
187
+ :class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'"
188
+ />
189
+ </span>
190
+ <!-- Filled part (FILL 1 glyph), clipped from the start side — this is what renders
191
+ half (or any fractional) values with any icon, not just `star`. -->
192
+ <span class="absolute inset-y-0 start-0 overflow-hidden" :style="{ width: `${fill * 100}%` }">
193
+ <MIcon
194
+ :name="icon"
195
+ :size="size"
196
+ class="absolute start-0 top-0"
197
+ :class="disabled ? 'text-on-surface/38' : colorClass"
198
+ :style="[disabled ? undefined : customStyle, { fontVariationSettings: `'FILL' 1` }]"
199
+ />
200
+ </span>
201
+ </span>
202
+ </span>
107
203
  </div>
108
204
  </template>
@@ -1,6 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
+ import { useLocale, type M3Locale } from '../composables/useLocale'
4
5
 
5
6
  const props = withDefaults(defineProps<{
6
7
  status: 'success' | 'error' | 'warning' | 'info' | '404' | '403' | '500'
@@ -8,16 +9,25 @@ const props = withDefaults(defineProps<{
8
9
  description?: string
9
10
  }>(), {})
10
11
 
12
+ const t = useLocale()
13
+
14
+ const STATUS_STYLE = {
15
+ success: { icon: 'check_circle', bg: 'bg-success-container', text: 'text-on-success-container' },
16
+ error: { icon: 'error', bg: 'bg-error-container', text: 'text-on-error-container' },
17
+ warning: { icon: 'warning', bg: 'bg-tertiary-container', text: 'text-on-tertiary-container' },
18
+ info: { icon: 'info', bg: 'bg-primary-container', text: 'text-on-primary-container' },
19
+ '404': { icon: 'search_off', bg: 'bg-surface-container-high', text: 'text-on-surface-variant' },
20
+ '403': { icon: 'lock', bg: 'bg-error-container', text: 'text-on-error-container' },
21
+ '500': { icon: 'cloud_off', bg: 'bg-error-container', text: 'text-on-error-container' },
22
+ } as const
23
+
24
+ // Locale keys follow the status: success → resultSuccessTitle, 404 → result404Title, …
11
25
  const config = computed(() => {
12
- switch (props.status) {
13
- case 'success': return { icon: 'check_circle', bg: 'bg-success-container', text: 'text-on-success-container', defaultTitle: 'Operación exitosa', defaultDesc: 'La acción se completó correctamente.' }
14
- case 'error': return { icon: 'error', bg: 'bg-error-container', text: 'text-on-error-container', defaultTitle: 'Algo salió mal', defaultDesc: 'Ocurrió un error inesperado. Inténtalo de nuevo.' }
15
- case 'warning': return { icon: 'warning', bg: 'bg-tertiary-container', text: 'text-on-tertiary-container', defaultTitle: 'Atención', defaultDesc: 'Hay algo que requiere tu atención.' }
16
- case 'info': return { icon: 'info', bg: 'bg-primary-container', text: 'text-on-primary-container', defaultTitle: 'Información', defaultDesc: '' }
17
- case '404': return { icon: 'search_off', bg: 'bg-surface-container-high', text: 'text-on-surface-variant', defaultTitle: 'Página no encontrada', defaultDesc: 'La página que buscas no existe o fue movida.' }
18
- case '403': return { icon: 'lock', bg: 'bg-error-container', text: 'text-on-error-container', defaultTitle: 'Acceso denegado', defaultDesc: 'No tienes permisos para ver este recurso.' }
19
- case '500': return { icon: 'cloud_off', bg: 'bg-error-container', text: 'text-on-error-container', defaultTitle: 'Error del servidor', defaultDesc: 'El servidor no pudo procesar la solicitud.' }
20
- default: return { icon: 'info', bg: 'bg-surface-container-high', text: 'text-on-surface-variant', defaultTitle: '', defaultDesc: '' }
26
+ const key = props.status.charAt(0).toUpperCase() + props.status.slice(1)
27
+ return {
28
+ ...STATUS_STYLE[props.status],
29
+ defaultTitle: t[`result${key}Title` as keyof M3Locale],
30
+ defaultDesc: t[`result${key}Desc` as keyof M3Locale],
21
31
  }
22
32
  })
23
33