@m3ui-vue/m3ui-vue 0.5.10 → 0.6.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.
Files changed (87) hide show
  1. package/README.md +36 -2
  2. package/dist/{MMenuItem-DyY4zhRA.js → MMenuItem-DbbrJhFE.js} +2 -2
  3. package/dist/{MMenuItem-DyY4zhRA.js.map → MMenuItem-DbbrJhFE.js.map} +1 -1
  4. package/dist/barcode.d.ts +1 -0
  5. package/dist/barcode.js +51 -0
  6. package/dist/barcode.js.map +1 -0
  7. package/dist/code-editor.js +1 -1
  8. package/dist/components/MAutocomplete.vue.d.ts +1 -1
  9. package/dist/components/MBarcode.vue.d.ts +35 -0
  10. package/dist/components/MButton.vue.d.ts +1 -1
  11. package/dist/components/MButtonGroup.vue.d.ts +1 -1
  12. package/dist/components/MChatBubble.vue.d.ts +1 -1
  13. package/dist/components/MCircleProgressBar.vue.d.ts +1 -1
  14. package/dist/components/MCopyButton.vue.d.ts +31 -0
  15. package/dist/components/MExportButton.vue.d.ts +43 -0
  16. package/dist/components/MFab.vue.d.ts +1 -1
  17. package/dist/components/MKbd.vue.d.ts +12 -0
  18. package/dist/components/MLightbox.vue.d.ts +53 -0
  19. package/dist/components/MMultiAutocomplete.vue.d.ts +1 -1
  20. package/dist/components/MMultiSelect.vue.d.ts +1 -1
  21. package/dist/components/MPasswordMeter.vue.d.ts +17 -0
  22. package/dist/components/MPinInput.vue.d.ts +35 -0
  23. package/dist/components/MQRCode.vue.d.ts +35 -0
  24. package/dist/components/MRating.vue.d.ts +1 -1
  25. package/dist/components/MRelativeTime.vue.d.ts +8 -0
  26. package/dist/components/MSelect.vue.d.ts +1 -1
  27. package/dist/components/MShader.vue.d.ts +2 -2
  28. package/dist/components/MSignaturePad.vue.d.ts +37 -0
  29. package/dist/components/MSlider.vue.d.ts +1 -1
  30. package/dist/components/MSplitButton.vue.d.ts +1 -1
  31. package/dist/components/MSubtitle.vue.d.ts +1 -1
  32. package/dist/components/MTerminal.vue.d.ts +2 -2
  33. package/dist/components/MTitle.vue.d.ts +1 -1
  34. package/dist/components/MWindow.vue.d.ts +1 -1
  35. package/dist/composables/useColorPalette.d.ts +9 -0
  36. package/dist/composables/useLocale.d.ts +2 -0
  37. package/dist/index.d.ts +9 -0
  38. package/dist/locales/index.js +7 -0
  39. package/dist/locales/index.js.map +1 -1
  40. package/dist/m3ui-vue.css +1 -1
  41. package/dist/m3ui.js +1737 -1021
  42. package/dist/m3ui.js.map +1 -1
  43. package/dist/plugin.d.ts +9 -0
  44. package/dist/qrcode.d.ts +1 -0
  45. package/dist/qrcode.js +117 -0
  46. package/dist/qrcode.js.map +1 -0
  47. package/dist/rich-text-editor.js +2 -2
  48. package/dist/styles.css +1 -1
  49. package/dist/{useLocale-QCIVDYWx.js → useLocale-BKsIWNix.js} +2 -1
  50. package/dist/useLocale-BKsIWNix.js.map +1 -0
  51. package/package.json +21 -1
  52. package/src/__tests__/MBarcode.test.ts +40 -0
  53. package/src/__tests__/MCopyButton.test.ts +49 -0
  54. package/src/__tests__/MExportButton.test.ts +64 -0
  55. package/src/__tests__/MKbd.test.ts +33 -0
  56. package/src/__tests__/MLightbox.test.ts +195 -0
  57. package/src/__tests__/MPasswordMeter.test.ts +43 -0
  58. package/src/__tests__/MPinInput.test.ts +138 -0
  59. package/src/__tests__/MQRCode.test.ts +58 -0
  60. package/src/__tests__/MRelativeTime.test.ts +43 -0
  61. package/src/__tests__/MSignaturePad.test.ts +62 -0
  62. package/src/__tests__/plugin.test.ts +20 -1
  63. package/src/__tests__/useColorPalette.test.ts +22 -0
  64. package/src/barcode.ts +1 -0
  65. package/src/components/MBarcode.vue +61 -0
  66. package/src/components/MCopyButton.vue +62 -0
  67. package/src/components/MExportButton.vue +73 -0
  68. package/src/components/MKbd.vue +36 -0
  69. package/src/components/MLightbox.vue +405 -0
  70. package/src/components/MPasswordMeter.vue +56 -0
  71. package/src/components/MPinInput.vue +202 -0
  72. package/src/components/MQRCode.vue +131 -0
  73. package/src/components/MRelativeTime.vue +68 -0
  74. package/src/components/MSignaturePad.vue +138 -0
  75. package/src/composables/useColorPalette.ts +29 -2
  76. package/src/composables/useLocale.ts +5 -0
  77. package/src/index.ts +9 -0
  78. package/src/locales/de.ts +2 -0
  79. package/src/locales/es.ts +2 -0
  80. package/src/locales/fr.ts +2 -0
  81. package/src/locales/ja.ts +2 -0
  82. package/src/locales/ko.ts +2 -0
  83. package/src/locales/pt.ts +2 -0
  84. package/src/locales/zh.ts +2 -0
  85. package/src/plugin.ts +16 -4
  86. package/src/qrcode.ts +1 -0
  87. package/dist/useLocale-QCIVDYWx.js.map +0 -1
@@ -0,0 +1,202 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, ref, watch } from 'vue'
3
+
4
+ const props = withDefaults(
5
+ defineProps<{
6
+ modelValue: string
7
+ length?: number
8
+ /** Segment sizes for a grouped layout, e.g. [2, 4, 2, 3, 1, 3] renders `__ ____ __ ___ _ ___`. Overrides `length` (derived as the sum). */
9
+ groups?: number[]
10
+ /** Visual separator rendered between groups (only used when `groups` is set). */
11
+ separator?: string
12
+ type?: 'numeric' | 'alphanumeric'
13
+ masked?: boolean
14
+ variant?: 'filled' | 'outlined'
15
+ error?: boolean
16
+ errorLabel?: string
17
+ hint?: string
18
+ disabled?: boolean
19
+ autoFocus?: boolean
20
+ label?: string
21
+ }>(),
22
+ {
23
+ modelValue: '',
24
+ length: 6,
25
+ separator: '-',
26
+ type: 'numeric',
27
+ masked: false,
28
+ variant: 'filled',
29
+ disabled: false,
30
+ autoFocus: false,
31
+ },
32
+ )
33
+
34
+ const totalLength = computed(() => (props.groups?.length ? props.groups.reduce((a, b) => a + b, 0) : props.length))
35
+
36
+ // Index (0-based) of the last box in each group except the last — a
37
+ // separator is rendered right after each of these boxes.
38
+ const groupBoundaries = computed(() => {
39
+ const boundaries = new Set<number>()
40
+ if (!props.groups?.length) return boundaries
41
+ let sum = 0
42
+ for (const size of props.groups.slice(0, -1)) {
43
+ sum += size
44
+ boundaries.add(sum - 1)
45
+ }
46
+ return boundaries
47
+ })
48
+
49
+ const emit = defineEmits<{ 'update:modelValue': [string]; complete: [string] }>()
50
+
51
+ const inputEls = ref<(HTMLInputElement | null)[]>([])
52
+
53
+ function setInputEl(el: any, i: number) {
54
+ inputEls.value[i] = el as HTMLInputElement | null
55
+ }
56
+
57
+ const allowedPattern = computed(() => (props.type === 'numeric' ? /[0-9]/ : /[a-zA-Z0-9]/))
58
+
59
+ // A gap can appear in the middle of the value if the user clicks past an
60
+ // empty box (e.g. fills 0 and 1, then clicks box 3 directly). '\0' preserves
61
+ // that empty slot's position; trailing empties are just dropped.
62
+ const EMPTY = '\0'
63
+
64
+ const digits = computed(() => Array.from({ length: totalLength.value }, (_, i) => {
65
+ const c = props.modelValue[i]
66
+ return c === undefined || c === EMPTY ? '' : c
67
+ }))
68
+
69
+ function charsToValue(chars: string[]): string {
70
+ let end = chars.length
71
+ while (end > 0 && !chars[end - 1]) end--
72
+ return chars.slice(0, end).map((c) => c || EMPTY).join('')
73
+ }
74
+
75
+ function setValue(chars: string[]) {
76
+ const next = charsToValue(chars)
77
+ emit('update:modelValue', next)
78
+ if (next.length === totalLength.value && !next.includes(EMPTY)) {
79
+ emit('complete', next)
80
+ }
81
+ }
82
+
83
+ function focusInput(i: number) {
84
+ nextTick(() => inputEls.value[i]?.focus())
85
+ }
86
+
87
+ function onFocus(i: number) {
88
+ inputEls.value[i]?.select()
89
+ }
90
+
91
+ function onInput(i: number, e: Event) {
92
+ const input = e.target as HTMLInputElement
93
+ const char = input.value.slice(-1)
94
+
95
+ if (char && !allowedPattern.value.test(char)) {
96
+ input.value = digits.value[i] ?? ''
97
+ return
98
+ }
99
+
100
+ const chars = [...digits.value]
101
+ chars[i] = char
102
+ setValue(chars)
103
+
104
+ if (char && i < totalLength.value - 1) {
105
+ focusInput(i + 1)
106
+ }
107
+ }
108
+
109
+ function onKeydown(i: number, e: KeyboardEvent) {
110
+ if (e.key === 'Backspace' && !digits.value[i] && i > 0) {
111
+ e.preventDefault()
112
+ const chars = [...digits.value]
113
+ chars[i - 1] = ''
114
+ setValue(chars)
115
+ focusInput(i - 1)
116
+ } else if (e.key === 'ArrowLeft' && i > 0) {
117
+ e.preventDefault()
118
+ focusInput(i - 1)
119
+ } else if (e.key === 'ArrowRight' && i < totalLength.value - 1) {
120
+ e.preventDefault()
121
+ focusInput(i + 1)
122
+ }
123
+ }
124
+
125
+ function onPaste(i: number, e: ClipboardEvent) {
126
+ e.preventDefault()
127
+ const pasted = (e.clipboardData?.getData('text') ?? '').split('').filter((c) => allowedPattern.value.test(c))
128
+ if (pasted.length === 0) return
129
+
130
+ const chars = [...digits.value]
131
+ let last = i
132
+ for (const c of pasted) {
133
+ if (last >= totalLength.value) break
134
+ chars[last] = c
135
+ last++
136
+ }
137
+ setValue(chars)
138
+ focusInput(Math.min(last, totalLength.value - 1))
139
+ }
140
+
141
+ watch(
142
+ () => props.autoFocus,
143
+ (v) => {
144
+ if (v) focusInput(0)
145
+ },
146
+ { immediate: true },
147
+ )
148
+
149
+ const boxClasses = computed(() => {
150
+ const base = [
151
+ 'h-14 w-12 text-center text-title-large text-on-surface outline-none',
152
+ 'transition-[border-color,border-width] duration-150',
153
+ 'disabled:cursor-not-allowed disabled:opacity-[0.38]',
154
+ ]
155
+ if (props.variant === 'outlined') {
156
+ return [...base,
157
+ 'rounded-sm border bg-transparent',
158
+ props.error
159
+ ? 'border-error focus:border-2 focus:border-error'
160
+ : 'border-outline hover:border-on-surface focus:border-2 focus:border-primary',
161
+ ].join(' ')
162
+ }
163
+ return [...base,
164
+ 'rounded-t-sm bg-surface-container-highest border-b',
165
+ props.error
166
+ ? 'border-error focus:border-b-2 focus:border-error'
167
+ : 'border-on-surface-variant hover:border-on-surface focus:border-b-2 focus:border-primary',
168
+ ].join(' ')
169
+ })
170
+ </script>
171
+
172
+ <template>
173
+ <div class="flex flex-col gap-1">
174
+ <div role="group" :aria-label="label" class="flex items-center gap-2">
175
+ <template v-for="(digit, i) in digits" :key="i">
176
+ <input
177
+ :ref="(el) => setInputEl(el, i)"
178
+ :value="digit"
179
+ :type="masked ? 'password' : 'text'"
180
+ :inputmode="type === 'numeric' ? 'numeric' : 'text'"
181
+ autocomplete="one-time-code"
182
+ maxlength="1"
183
+ :disabled="disabled"
184
+ :aria-label="`Digit ${i + 1} of ${totalLength}`"
185
+ :class="boxClasses"
186
+ @input="onInput(i, $event)"
187
+ @keydown="onKeydown(i, $event)"
188
+ @paste="onPaste(i, $event)"
189
+ @focus="onFocus(i)"
190
+ />
191
+ <span
192
+ v-if="groupBoundaries.has(i)"
193
+ aria-hidden="true"
194
+ class="select-none text-title-large text-on-surface-variant"
195
+ >{{ separator }}</span>
196
+ </template>
197
+ </div>
198
+
199
+ <p v-if="error && errorLabel" class="px-1 text-body-small text-error">{{ errorLabel }}</p>
200
+ <p v-else-if="hint" class="px-1 text-body-small text-on-surface-variant">{{ hint }}</p>
201
+ </div>
202
+ </template>
@@ -0,0 +1,131 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import QRCode from 'qrcode-generator'
4
+
5
+ const props = withDefaults(
6
+ defineProps<{
7
+ value: string
8
+ size?: number
9
+ /** Quiet zone around the code, in modules. */
10
+ margin?: number
11
+ errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'
12
+ color?: string
13
+ background?: string
14
+ label?: string
15
+ /** Rounds the outer container corners. */
16
+ rounded?: boolean
17
+ /** 'square' is the classic scannable pixel grid. 'dots' rounds each module — still fully scannable, just a softer look. */
18
+ moduleStyle?: 'square' | 'dots'
19
+ }>(),
20
+ {
21
+ size: 200,
22
+ margin: 4,
23
+ errorCorrectionLevel: 'M',
24
+ color: '#000000',
25
+ background: '#ffffff',
26
+ rounded: true,
27
+ moduleStyle: 'square',
28
+ },
29
+ )
30
+
31
+ // qr and error are derived together in one computed so they can never be
32
+ // read out of sync with each other (e.g. a template `v-if="error"` seeing a
33
+ // stale value from before `qr` — which sets it — was actually evaluated).
34
+ const result = computed(() => {
35
+ try {
36
+ const instance = QRCode(0, props.errorCorrectionLevel)
37
+ instance.addData(props.value)
38
+ instance.make()
39
+ return { qr: instance, error: null as string | null }
40
+ } catch (err) {
41
+ // qrcode-generator throws plain strings (e.g. "code length overflow...")
42
+ const message = typeof err === 'string' ? err : err instanceof Error ? err.message : 'Failed to generate QR code'
43
+ return { qr: null, error: message }
44
+ }
45
+ })
46
+
47
+ const qr = computed(() => result.value.qr)
48
+ const error = computed(() => result.value.error)
49
+
50
+ const moduleCount = computed(() => qr.value?.getModuleCount() ?? 0)
51
+ const totalModules = computed(() => moduleCount.value + props.margin * 2)
52
+ const moduleSize = computed(() => (totalModules.value > 0 ? props.size / totalModules.value : 0))
53
+ const containerRadius = computed(() => (props.rounded ? props.size * 0.06 : 0))
54
+
55
+ // A corner rounds only when neither of its two perpendicular neighbors is
56
+ // also dark — otherwise adjacent modules (e.g. the finder-pattern squares,
57
+ // or any run of touching pixels) would each round independently and leave
58
+ // visible notches instead of merging into one smooth shape.
59
+ function roundedRectPath(x: number, y: number, s: number, rTL: number, rTR: number, rBR: number, rBL: number): string {
60
+ return `M${x + rTL},${y} H${x + s - rTR} A${rTR},${rTR} 0 0 1 ${x + s},${y + rTR} V${y + s - rBR} A${rBR},${rBR} 0 0 1 ${x + s - rBR},${y + s} H${x + rBL} A${rBL},${rBL} 0 0 1 ${x},${y + s - rBL} V${y + rTL} A${rTL},${rTL} 0 0 1 ${x + rTL},${y} Z`
61
+ }
62
+
63
+ const cells = computed(() => {
64
+ const result: { x: number; y: number; d?: string }[] = []
65
+ const inst = qr.value
66
+ if (!inst) return result
67
+ const count = moduleCount.value
68
+ const s = moduleSize.value
69
+ const isDark = (row: number, col: number) => row >= 0 && row < count && col >= 0 && col < count && inst.isDark(row, col)
70
+
71
+ for (let row = 0; row < count; row++) {
72
+ for (let col = 0; col < count; col++) {
73
+ if (!isDark(row, col)) continue
74
+ const x = (col + props.margin) * s
75
+ const y = (row + props.margin) * s
76
+
77
+ if (props.moduleStyle !== 'dots') {
78
+ result.push({ x, y })
79
+ continue
80
+ }
81
+
82
+ const radius = s / 2
83
+ const up = isDark(row - 1, col)
84
+ const down = isDark(row + 1, col)
85
+ const left = isDark(row, col - 1)
86
+ const right = isDark(row, col + 1)
87
+ result.push({
88
+ x, y,
89
+ d: roundedRectPath(
90
+ x, y, s,
91
+ up || left ? 0 : radius,
92
+ up || right ? 0 : radius,
93
+ down || right ? 0 : radius,
94
+ down || left ? 0 : radius,
95
+ ),
96
+ })
97
+ }
98
+ }
99
+ return result
100
+ })
101
+ </script>
102
+
103
+ <template>
104
+ <div v-if="error" class="flex items-center justify-center text-body-small text-error" :style="{ width: `${size}px`, height: `${size}px` }">
105
+ <slot name="error">{{ error }}</slot>
106
+ </div>
107
+ <svg
108
+ v-else
109
+ :width="size"
110
+ :height="size"
111
+ :viewBox="`0 0 ${size} ${size}`"
112
+ role="img"
113
+ :aria-label="label ?? value"
114
+ >
115
+ <rect x="0" y="0" :width="size" :height="size" :rx="containerRadius" :ry="containerRadius" :fill="background" />
116
+ <template v-if="moduleStyle === 'dots'">
117
+ <path v-for="(cell, i) in cells" :key="i" :d="cell.d" :fill="color" />
118
+ </template>
119
+ <template v-else>
120
+ <rect
121
+ v-for="(cell, i) in cells"
122
+ :key="i"
123
+ :x="cell.x"
124
+ :y="cell.y"
125
+ :width="moduleSize"
126
+ :height="moduleSize"
127
+ :fill="color"
128
+ />
129
+ </template>
130
+ </svg>
131
+ </template>
@@ -0,0 +1,68 @@
1
+ <script setup lang="ts">
2
+ import { computed, onUnmounted, ref, watch } from 'vue'
3
+ import { useLocale } from '../composables/useLocale'
4
+
5
+ const props = withDefaults(
6
+ defineProps<{
7
+ value: string | number | Date
8
+ /** BCP-47 locale tag (e.g. 'es-ES'). Defaults to the app's locale (via createM3UI/useLocale), then the browser's locale. */
9
+ locale?: string
10
+ }>(),
11
+ {},
12
+ )
13
+
14
+ const appLocale = useLocale()
15
+ const resolvedLocale = computed(() => props.locale ?? appLocale.lang)
16
+
17
+ const date = computed(() => new Date(props.value))
18
+ const now = ref(Date.now())
19
+
20
+ // Re-render at a cadence that matches the current magnitude — no point
21
+ // re-checking every second once we're already saying "3 hours ago".
22
+ const DIVISIONS: { amount: number; unit: Intl.RelativeTimeFormatUnit; tick: number }[] = [
23
+ { amount: 60, unit: 'seconds', tick: 1_000 },
24
+ { amount: 60, unit: 'minutes', tick: 30_000 },
25
+ { amount: 24, unit: 'hours', tick: 60_000 },
26
+ { amount: 7, unit: 'days', tick: 3_600_000 },
27
+ { amount: 4.34524, unit: 'weeks', tick: 3_600_000 },
28
+ { amount: 12, unit: 'months', tick: 3_600_000 },
29
+ { amount: Infinity, unit: 'years', tick: 0 },
30
+ ]
31
+
32
+ let timer: ReturnType<typeof setTimeout> | undefined
33
+
34
+ function scheduleNext() {
35
+ clearTimeout(timer)
36
+ let duration = (date.value.getTime() - now.value) / 1000
37
+ for (const division of DIVISIONS) {
38
+ if (Math.abs(duration) < division.amount) {
39
+ if (division.tick > 0) {
40
+ timer = setTimeout(() => { now.value = Date.now(); scheduleNext() }, division.tick)
41
+ }
42
+ return
43
+ }
44
+ duration /= division.amount
45
+ }
46
+ }
47
+
48
+ watch(date, () => { now.value = Date.now(); scheduleNext() }, { immediate: true })
49
+ onUnmounted(() => clearTimeout(timer))
50
+
51
+ const formatted = computed(() => {
52
+ const formatter = new Intl.RelativeTimeFormat(resolvedLocale.value, { numeric: 'auto' })
53
+ let duration = (date.value.getTime() - now.value) / 1000
54
+ for (const division of DIVISIONS) {
55
+ if (Math.abs(duration) < division.amount) {
56
+ return formatter.format(Math.round(duration), division.unit)
57
+ }
58
+ duration /= division.amount
59
+ }
60
+ return formatter.format(0, 'seconds')
61
+ })
62
+
63
+ const absolute = computed(() => date.value.toLocaleString(resolvedLocale.value))
64
+ </script>
65
+
66
+ <template>
67
+ <time :datetime="date.toISOString()" :title="absolute">{{ formatted }}</time>
68
+ </template>
@@ -0,0 +1,138 @@
1
+ <script setup lang="ts">
2
+ import { computed, onMounted, ref, watch } from 'vue'
3
+
4
+ const props = withDefaults(
5
+ defineProps<{
6
+ width?: number
7
+ height?: number
8
+ lineWidth?: number
9
+ color?: string
10
+ background?: string
11
+ variant?: 'filled' | 'outlined'
12
+ disabled?: boolean
13
+ }>(),
14
+ {
15
+ width: 400,
16
+ height: 200,
17
+ lineWidth: 2.5,
18
+ color: '#000000',
19
+ background: '#ffffff',
20
+ variant: 'outlined',
21
+ disabled: false,
22
+ },
23
+ )
24
+
25
+ const emit = defineEmits<{ begin: []; end: [string]; change: [string] }>()
26
+
27
+ type Point = { x: number; y: number }
28
+
29
+ const canvasEl = ref<HTMLCanvasElement | null>(null)
30
+ const strokes = ref<Point[][]>([])
31
+ const drawing = ref(false)
32
+ const empty = computed(() => strokes.value.length === 0)
33
+
34
+ function getContext() {
35
+ return canvasEl.value?.getContext('2d') ?? null
36
+ }
37
+
38
+ function redraw() {
39
+ const ctx = getContext()
40
+ const canvas = canvasEl.value
41
+ if (!ctx || !canvas) return
42
+
43
+ ctx.clearRect(0, 0, canvas.width, canvas.height)
44
+ ctx.fillStyle = props.background
45
+ ctx.fillRect(0, 0, canvas.width, canvas.height)
46
+
47
+ ctx.strokeStyle = props.color
48
+ ctx.lineWidth = props.lineWidth
49
+ ctx.lineCap = 'round'
50
+ ctx.lineJoin = 'round'
51
+
52
+ for (const stroke of strokes.value) {
53
+ if (stroke.length < 2) continue
54
+ ctx.beginPath()
55
+ ctx.moveTo(stroke[0]!.x, stroke[0]!.y)
56
+ for (const point of stroke.slice(1)) ctx.lineTo(point.x, point.y)
57
+ ctx.stroke()
58
+ }
59
+ }
60
+
61
+ function pointFromEvent(e: PointerEvent): Point {
62
+ const rect = canvasEl.value!.getBoundingClientRect()
63
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top }
64
+ }
65
+
66
+ function onPointerDown(e: PointerEvent) {
67
+ if (props.disabled) return
68
+ drawing.value = true
69
+ strokes.value.push([pointFromEvent(e)])
70
+ emit('begin')
71
+ canvasEl.value?.setPointerCapture(e.pointerId)
72
+ }
73
+
74
+ function onPointerMove(e: PointerEvent) {
75
+ if (!drawing.value) return
76
+ strokes.value[strokes.value.length - 1]!.push(pointFromEvent(e))
77
+ redraw()
78
+ }
79
+
80
+ function onPointerUp() {
81
+ if (!drawing.value) return
82
+ drawing.value = false
83
+ const dataUrl = toDataURL()
84
+ emit('end', dataUrl)
85
+ emit('change', dataUrl)
86
+ }
87
+
88
+ function clear() {
89
+ strokes.value = []
90
+ redraw()
91
+ }
92
+
93
+ function undo() {
94
+ strokes.value = strokes.value.slice(0, -1)
95
+ redraw()
96
+ emit('change', toDataURL())
97
+ }
98
+
99
+ function isEmpty(): boolean {
100
+ return empty.value
101
+ }
102
+
103
+ function toDataURL(type?: string, quality?: number): string {
104
+ return canvasEl.value?.toDataURL(type, quality) ?? ''
105
+ }
106
+
107
+ watch([() => props.color, () => props.background, () => props.lineWidth], redraw)
108
+
109
+ onMounted(redraw)
110
+
111
+ defineExpose({ clear, undo, isEmpty, toDataURL })
112
+
113
+ const containerClasses = computed(() => {
114
+ if (props.variant === 'outlined') {
115
+ return 'rounded-sm border border-outline'
116
+ }
117
+ return 'rounded-t-sm bg-surface-container-highest border-b border-on-surface-variant'
118
+ })
119
+ </script>
120
+
121
+ <template>
122
+ <div
123
+ class="inline-block touch-none"
124
+ :class="[containerClasses, disabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-crosshair']"
125
+ >
126
+ <canvas
127
+ ref="canvasEl"
128
+ :width="width"
129
+ :height="height"
130
+ role="img"
131
+ aria-label="Signature pad"
132
+ @pointerdown="onPointerDown"
133
+ @pointermove="onPointerMove"
134
+ @pointerup="onPointerUp"
135
+ @pointerleave="onPointerUp"
136
+ />
137
+ </div>
138
+ </template>
@@ -41,10 +41,15 @@ export const palettes: Palette[] = [
41
41
 
42
42
  const current = ref(localStorage.getItem('m3-palette') ?? 'purple')
43
43
 
44
+ // Whether palette changes are written to localStorage. Defaults to true (existing behavior).
45
+ // An app can disable it via `createM3UI({ persistPalette: false })` or `useColorPalette().setPersistPalette(false)`
46
+ // so its chosen palette can't be overridden by a stored value on the next boot.
47
+ const persistEnabled = ref(true)
48
+
44
49
  export function useColorPalette() {
45
50
  watchEffect(() => {
46
51
  const id = current.value
47
- localStorage.setItem('m3-palette', id)
52
+ if (persistEnabled.value) localStorage.setItem('m3-palette', id)
48
53
 
49
54
  if (id === 'purple') {
50
55
  document.documentElement.removeAttribute('data-palette')
@@ -60,7 +65,12 @@ export function useColorPalette() {
60
65
  setTimeout(() => document.documentElement.classList.remove('theme-transitioning'), 300)
61
66
  }
62
67
 
63
- return { palette: current, palettes, set }
68
+ function setPersistPalette(enabled: boolean) {
69
+ persistEnabled.value = enabled
70
+ if (enabled) localStorage.setItem('m3-palette', current.value)
71
+ }
72
+
73
+ return { palette: current, palettes, set, persistPalette: persistEnabled, setPersistPalette }
64
74
  }
65
75
 
66
76
  // Apply on module load so palette is visible before any component mounts
@@ -68,3 +78,20 @@ const saved = localStorage.getItem('m3-palette')
68
78
  if (saved && saved !== 'purple') {
69
79
  document.documentElement.setAttribute('data-palette', saved)
70
80
  }
81
+
82
+ /**
83
+ * Internal: used by `createM3UI({ palette, persistPalette: false })` to force a palette on boot,
84
+ * bypassing whatever is already in localStorage, without waiting for a component to call
85
+ * `useColorPalette()` (which is what actually reacts to `current` via the watchEffect above).
86
+ * Not exported from the package's public entry points.
87
+ */
88
+ export function __forcePalette(id: string, persist: boolean) {
89
+ persistEnabled.value = persist
90
+ current.value = id
91
+ if (id === 'purple') {
92
+ document.documentElement.removeAttribute('data-palette')
93
+ } else {
94
+ document.documentElement.setAttribute('data-palette', id)
95
+ }
96
+ if (persist) localStorage.setItem('m3-palette', id)
97
+ }
@@ -1,6 +1,9 @@
1
1
  import { inject, reactive, watchEffect, toValue, type InjectionKey, type MaybeRef } from 'vue'
2
2
 
3
3
  export interface M3Locale {
4
+ /** BCP-47 language tag (e.g. 'en', 'es', 'pt') — read by locale-aware components (MRelativeTime) that use Intl formatting. */
5
+ lang: string
6
+
4
7
  // Common
5
8
  search: string
6
9
  noResults: string
@@ -103,6 +106,8 @@ export interface M3Locale {
103
106
  }
104
107
 
105
108
  export const defaultLocale: M3Locale = {
109
+ lang: 'en',
110
+
106
111
  search: 'Search...',
107
112
  noResults: 'No results',
108
113
  close: 'Close',
package/src/index.ts CHANGED
@@ -47,6 +47,7 @@ export { default as MCommandPalette } from './components/MCommandPalette.vue'
47
47
  export { default as MConfirmDialog } from './components/MConfirmDialog.vue'
48
48
  export { default as MContainer } from './components/MContainer.vue'
49
49
  export { default as MContextMenu } from './components/MContextMenu.vue'
50
+ export { default as MCopyButton } from './components/MCopyButton.vue'
50
51
  export { default as MDataTable } from './components/MDataTable.vue'
51
52
  export { default as MDatePicker } from './components/MDatePicker.vue'
52
53
  export { default as MDatePickerModal } from './components/MDatePickerModal.vue'
@@ -60,6 +61,7 @@ export { default as MEmojiButton } from './components/MEmojiButton.vue'
60
61
  export { default as MEmojiSelector } from './components/MEmojiSelector.vue'
61
62
  export { default as MEmptyState } from './components/MEmptyState.vue'
62
63
  export { default as MExpansionPanel } from './components/MExpansionPanel.vue'
64
+ export { default as MExportButton } from './components/MExportButton.vue'
63
65
  export { default as MFab } from './components/MFab.vue'
64
66
  export { default as MFileUpload } from './components/MFileUpload.vue'
65
67
  export { default as MFixed } from './components/MFixed.vue'
@@ -74,6 +76,9 @@ export { default as MInfiniteScroll } from './components/MInfiniteScroll.vue'
74
76
  // MJsonEditor — import from '@m3ui-vue/m3ui-vue/code-editor'
75
77
  export { default as MJsonViewer } from './components/MJsonViewer.vue'
76
78
  export { default as MKanban } from './components/MKanban.vue'
79
+ export { default as MKbd } from './components/MKbd.vue'
80
+ export { default as MLightbox } from './components/MLightbox.vue'
81
+ export type { LightboxItem } from './components/MLightbox.vue'
77
82
  export { default as MList } from './components/MList.vue'
78
83
  export { default as MListItem } from './components/MListItem.vue'
79
84
  export { default as MListSubheader } from './components/MListSubheader.vue'
@@ -94,12 +99,15 @@ export { default as MNavigationDrawer } from './components/MNavigationDrawer.vue
94
99
  export { default as MNavigationRail } from './components/MNavigationRail.vue'
95
100
  export { default as MOverlay } from './components/MOverlay.vue'
96
101
  export { default as MPagination } from './components/MPagination.vue'
102
+ export { default as MPasswordMeter } from './components/MPasswordMeter.vue'
103
+ export { default as MPinInput } from './components/MPinInput.vue'
97
104
  export { default as MProgressBar } from './components/MProgressBar.vue'
98
105
  export { default as MCircleProgressBar } from './components/MCircleProgressBar.vue'
99
106
  export { default as MRadio } from './components/MRadio.vue'
100
107
  export { default as MRadioGroup } from './components/MRadioGroup.vue'
101
108
  export { default as MRating } from './components/MRating.vue'
102
109
  export { default as MRelative } from './components/MRelative.vue'
110
+ export { default as MRelativeTime } from './components/MRelativeTime.vue'
103
111
  export { default as MResponsive } from './components/MResponsive.vue'
104
112
  export { default as MResult } from './components/MResult.vue'
105
113
  // MRichTextEditor — import from '@m3ui-vue/m3ui-vue/rich-text-editor'
@@ -112,6 +120,7 @@ export type { SelectOption } from './components/MSelect.vue'
112
120
  export { default as MShader } from './components/MShader.vue'
113
121
  export type { ShaderRenderer, ShaderStatus } from './components/MShader.vue'
114
122
  export { default as MSideSheet } from './components/MSideSheet.vue'
123
+ export { default as MSignaturePad } from './components/MSignaturePad.vue'
115
124
  export { default as MSkeleton } from './components/MSkeleton.vue'
116
125
  export { default as MSlider } from './components/MSlider.vue'
117
126
  export { default as MSnackbar } from './components/MSnackbar.vue'
package/src/locales/de.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { M3Locale } from '../composables/useLocale'
2
2
 
3
3
  export const deLocale: M3Locale = {
4
+ lang: 'de',
5
+
4
6
  // Common
5
7
  search: 'Suchen...',
6
8
  noResults: 'Keine Ergebnisse',
package/src/locales/es.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { M3Locale } from '../composables/useLocale'
2
2
 
3
3
  export const esLocale: M3Locale = {
4
+ lang: 'es',
5
+
4
6
  // Common
5
7
  search: 'Buscar...',
6
8
  noResults: 'Sin resultados',
package/src/locales/fr.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { M3Locale } from '../composables/useLocale'
2
2
 
3
3
  export const frLocale: M3Locale = {
4
+ lang: 'fr',
5
+
4
6
  // Common
5
7
  search: 'Rechercher...',
6
8
  noResults: 'Aucun résultat',