@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.
- package/README.md +36 -2
- package/dist/{MMenuItem-DyY4zhRA.js → MMenuItem-DbbrJhFE.js} +2 -2
- package/dist/{MMenuItem-DyY4zhRA.js.map → MMenuItem-DbbrJhFE.js.map} +1 -1
- package/dist/barcode.d.ts +1 -0
- package/dist/barcode.js +51 -0
- package/dist/barcode.js.map +1 -0
- package/dist/code-editor.js +1 -1
- package/dist/components/MAutocomplete.vue.d.ts +1 -1
- package/dist/components/MBarcode.vue.d.ts +35 -0
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MButtonGroup.vue.d.ts +1 -1
- package/dist/components/MChatBubble.vue.d.ts +1 -1
- package/dist/components/MCircleProgressBar.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +31 -0
- package/dist/components/MExportButton.vue.d.ts +43 -0
- package/dist/components/MFab.vue.d.ts +1 -1
- package/dist/components/MKbd.vue.d.ts +12 -0
- package/dist/components/MLightbox.vue.d.ts +53 -0
- package/dist/components/MMultiAutocomplete.vue.d.ts +1 -1
- package/dist/components/MMultiSelect.vue.d.ts +1 -1
- package/dist/components/MPasswordMeter.vue.d.ts +17 -0
- package/dist/components/MPinInput.vue.d.ts +35 -0
- package/dist/components/MQRCode.vue.d.ts +35 -0
- package/dist/components/MRating.vue.d.ts +1 -1
- package/dist/components/MRelativeTime.vue.d.ts +8 -0
- package/dist/components/MSelect.vue.d.ts +1 -1
- package/dist/components/MShader.vue.d.ts +2 -2
- package/dist/components/MSignaturePad.vue.d.ts +37 -0
- package/dist/components/MSlider.vue.d.ts +1 -1
- package/dist/components/MSplitButton.vue.d.ts +1 -1
- package/dist/components/MSubtitle.vue.d.ts +1 -1
- package/dist/components/MTerminal.vue.d.ts +2 -2
- package/dist/components/MTitle.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/composables/useColorPalette.d.ts +9 -0
- package/dist/composables/useLocale.d.ts +2 -0
- package/dist/index.d.ts +9 -0
- package/dist/locales/index.js +7 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +1737 -1021
- package/dist/m3ui.js.map +1 -1
- package/dist/plugin.d.ts +9 -0
- package/dist/qrcode.d.ts +1 -0
- package/dist/qrcode.js +117 -0
- package/dist/qrcode.js.map +1 -0
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-QCIVDYWx.js → useLocale-BKsIWNix.js} +2 -1
- package/dist/useLocale-BKsIWNix.js.map +1 -0
- package/package.json +21 -1
- package/src/__tests__/MBarcode.test.ts +40 -0
- package/src/__tests__/MCopyButton.test.ts +49 -0
- package/src/__tests__/MExportButton.test.ts +64 -0
- package/src/__tests__/MKbd.test.ts +33 -0
- package/src/__tests__/MLightbox.test.ts +195 -0
- package/src/__tests__/MPasswordMeter.test.ts +43 -0
- package/src/__tests__/MPinInput.test.ts +138 -0
- package/src/__tests__/MQRCode.test.ts +58 -0
- package/src/__tests__/MRelativeTime.test.ts +43 -0
- package/src/__tests__/MSignaturePad.test.ts +62 -0
- package/src/__tests__/plugin.test.ts +20 -1
- package/src/__tests__/useColorPalette.test.ts +22 -0
- package/src/barcode.ts +1 -0
- package/src/components/MBarcode.vue +61 -0
- package/src/components/MCopyButton.vue +62 -0
- package/src/components/MExportButton.vue +73 -0
- package/src/components/MKbd.vue +36 -0
- package/src/components/MLightbox.vue +405 -0
- package/src/components/MPasswordMeter.vue +56 -0
- package/src/components/MPinInput.vue +202 -0
- package/src/components/MQRCode.vue +131 -0
- package/src/components/MRelativeTime.vue +68 -0
- package/src/components/MSignaturePad.vue +138 -0
- package/src/composables/useColorPalette.ts +29 -2
- package/src/composables/useLocale.ts +5 -0
- package/src/index.ts +9 -0
- package/src/locales/de.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/plugin.ts +16 -4
- package/src/qrcode.ts +1 -0
- package/dist/useLocale-QCIVDYWx.js.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onUnmounted, ref } from 'vue'
|
|
3
|
+
import MIconButton from './MIconButton.vue'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
value: string
|
|
8
|
+
icon?: string
|
|
9
|
+
copiedIcon?: string
|
|
10
|
+
label?: string
|
|
11
|
+
copiedLabel?: string
|
|
12
|
+
variant?: 'standard' | 'filled' | 'tonal' | 'outlined'
|
|
13
|
+
shape?: 'rounded' | 'squared'
|
|
14
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | number
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
resetDelay?: number
|
|
17
|
+
}>(),
|
|
18
|
+
{
|
|
19
|
+
icon: 'content_copy',
|
|
20
|
+
copiedIcon: 'check',
|
|
21
|
+
label: 'Copy',
|
|
22
|
+
copiedLabel: 'Copied',
|
|
23
|
+
variant: 'standard',
|
|
24
|
+
shape: 'rounded',
|
|
25
|
+
size: 'sm',
|
|
26
|
+
disabled: false,
|
|
27
|
+
resetDelay: 2000,
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const emit = defineEmits<{ copied: [string]; error: [unknown] }>()
|
|
32
|
+
|
|
33
|
+
const copied = ref(false)
|
|
34
|
+
let resetTimer: ReturnType<typeof setTimeout> | undefined
|
|
35
|
+
|
|
36
|
+
async function onClick() {
|
|
37
|
+
if (props.disabled) return
|
|
38
|
+
try {
|
|
39
|
+
await navigator.clipboard.writeText(props.value)
|
|
40
|
+
copied.value = true
|
|
41
|
+
emit('copied', props.value)
|
|
42
|
+
clearTimeout(resetTimer)
|
|
43
|
+
resetTimer = setTimeout(() => { copied.value = false }, props.resetDelay)
|
|
44
|
+
} catch (err) {
|
|
45
|
+
emit('error', err)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onUnmounted(() => clearTimeout(resetTimer))
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<MIconButton
|
|
54
|
+
:icon="copied ? copiedIcon : icon"
|
|
55
|
+
:label="copied ? copiedLabel : label"
|
|
56
|
+
:variant="variant"
|
|
57
|
+
:shape="shape"
|
|
58
|
+
:size="size"
|
|
59
|
+
:disabled="disabled"
|
|
60
|
+
@click="onClick"
|
|
61
|
+
/>
|
|
62
|
+
</template>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import MButton from './MButton.vue'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(
|
|
5
|
+
defineProps<{
|
|
6
|
+
data: Record<string, unknown>[]
|
|
7
|
+
format?: 'csv' | 'json'
|
|
8
|
+
filename?: string
|
|
9
|
+
label?: string
|
|
10
|
+
icon?: string
|
|
11
|
+
variant?: 'filled' | 'tonal' | 'outlined' | 'text' | 'elevated'
|
|
12
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
}>(),
|
|
15
|
+
{
|
|
16
|
+
format: 'csv',
|
|
17
|
+
filename: 'export',
|
|
18
|
+
label: 'Export',
|
|
19
|
+
icon: 'download',
|
|
20
|
+
variant: 'outlined',
|
|
21
|
+
size: 'sm',
|
|
22
|
+
disabled: false,
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{ exported: [{ format: string; filename: string }]; error: [unknown] }>()
|
|
27
|
+
|
|
28
|
+
function escapeCsvField(value: unknown): string {
|
|
29
|
+
const s = value == null ? '' : String(value)
|
|
30
|
+
return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function toCsv(rows: Record<string, unknown>[]): string {
|
|
34
|
+
if (rows.length === 0) return ''
|
|
35
|
+
const headers = Object.keys(rows[0]!)
|
|
36
|
+
const lines = [
|
|
37
|
+
headers.map(escapeCsvField).join(','),
|
|
38
|
+
...rows.map((row) => headers.map((h) => escapeCsvField(row[h])).join(',')),
|
|
39
|
+
]
|
|
40
|
+
return lines.join('\n')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function download(content: string, filename: string, mime: string) {
|
|
44
|
+
const blob = new Blob([content], { type: mime })
|
|
45
|
+
const url = URL.createObjectURL(blob)
|
|
46
|
+
const a = document.createElement('a')
|
|
47
|
+
a.href = url
|
|
48
|
+
a.download = filename
|
|
49
|
+
a.click()
|
|
50
|
+
URL.revokeObjectURL(url)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function onClick() {
|
|
54
|
+
if (props.disabled) return
|
|
55
|
+
try {
|
|
56
|
+
const filename = `${props.filename}.${props.format}`
|
|
57
|
+
if (props.format === 'json') {
|
|
58
|
+
download(JSON.stringify(props.data, null, 2), filename, 'application/json')
|
|
59
|
+
} else {
|
|
60
|
+
download(toCsv(props.data), filename, 'text/csv')
|
|
61
|
+
}
|
|
62
|
+
emit('exported', { format: props.format, filename })
|
|
63
|
+
} catch (err) {
|
|
64
|
+
emit('error', err)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<MButton :variant="variant" :size="size" :icon="icon" :disabled="disabled" @click="onClick">
|
|
71
|
+
<slot>{{ label }}</slot>
|
|
72
|
+
</MButton>
|
|
73
|
+
</template>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(
|
|
5
|
+
defineProps<{
|
|
6
|
+
/** A '+'-delimited string ("Ctrl+Shift+K") or an array of keys (['Ctrl', 'Shift', 'K']). */
|
|
7
|
+
keys: string | string[]
|
|
8
|
+
size?: 'sm' | 'md' | 'lg'
|
|
9
|
+
separator?: string
|
|
10
|
+
}>(),
|
|
11
|
+
{
|
|
12
|
+
size: 'md',
|
|
13
|
+
separator: '+',
|
|
14
|
+
},
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const keyList = computed(() => (Array.isArray(props.keys) ? props.keys : props.keys.split('+')))
|
|
18
|
+
|
|
19
|
+
const sizeClasses = {
|
|
20
|
+
sm: 'h-5 min-w-5 px-1 text-[10px]',
|
|
21
|
+
md: 'h-6 min-w-6 px-1.5 text-label-small',
|
|
22
|
+
lg: 'h-7 min-w-7 px-2 text-label-medium',
|
|
23
|
+
}
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<span class="inline-flex items-center gap-1">
|
|
28
|
+
<template v-for="(key, i) in keyList" :key="i">
|
|
29
|
+
<kbd
|
|
30
|
+
class="inline-flex items-center justify-center rounded-sm border border-b-2 border-outline-variant bg-surface-container-high font-sans font-medium text-on-surface-variant"
|
|
31
|
+
:class="sizeClasses[size]"
|
|
32
|
+
>{{ key }}</kbd>
|
|
33
|
+
<span v-if="i < keyList.length - 1" class="text-on-surface-variant" aria-hidden="true">{{ separator }}</span>
|
|
34
|
+
</template>
|
|
35
|
+
</span>
|
|
36
|
+
</template>
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, watch, onMounted, onBeforeUnmount } from 'vue'
|
|
3
|
+
import MIcon from './MIcon.vue'
|
|
4
|
+
import { useLocale } from '../composables/useLocale'
|
|
5
|
+
|
|
6
|
+
export interface LightboxItem {
|
|
7
|
+
src: string
|
|
8
|
+
alt?: string
|
|
9
|
+
caption?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface OriginRect {
|
|
13
|
+
x: number
|
|
14
|
+
y: number
|
|
15
|
+
width: number
|
|
16
|
+
height: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const props = withDefaults(
|
|
20
|
+
defineProps<{
|
|
21
|
+
modelValue?: boolean
|
|
22
|
+
/** Explicit gallery. Omit it to auto-detect `<img>` elements rendered in the default slot instead. */
|
|
23
|
+
items?: LightboxItem[]
|
|
24
|
+
index?: number
|
|
25
|
+
loop?: boolean
|
|
26
|
+
closeLabel?: string
|
|
27
|
+
/** Show a row of clickable thumbnails at the bottom for jumping directly to an image. */
|
|
28
|
+
showThumbnails?: boolean
|
|
29
|
+
/** Round the corners of the main opened image (the thumbnail strip keeps its own fixed rounding). */
|
|
30
|
+
rounded?: boolean
|
|
31
|
+
}>(),
|
|
32
|
+
{
|
|
33
|
+
modelValue: false,
|
|
34
|
+
index: 0,
|
|
35
|
+
loop: true,
|
|
36
|
+
showThumbnails: false,
|
|
37
|
+
rounded: true,
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const emit = defineEmits<{
|
|
42
|
+
'update:modelValue': [boolean]
|
|
43
|
+
'update:index': [number]
|
|
44
|
+
change: [index: number]
|
|
45
|
+
}>()
|
|
46
|
+
|
|
47
|
+
const locale = useLocale()
|
|
48
|
+
|
|
49
|
+
const containerEl = ref<HTMLElement>()
|
|
50
|
+
const stageImageEl = ref<HTMLElement>()
|
|
51
|
+
const scannedItems = ref<LightboxItem[]>([])
|
|
52
|
+
const isOpen = ref(props.modelValue)
|
|
53
|
+
const currentIndex = ref(props.index)
|
|
54
|
+
const direction = ref(1)
|
|
55
|
+
// Set on open() when we have a clicked thumbnail to expand from (Discord-style); cleared once
|
|
56
|
+
// the opening transition has played so later next()/prev() use the plain slide instead.
|
|
57
|
+
const isFirstShow = ref(true)
|
|
58
|
+
let originRect: OriginRect | null = null
|
|
59
|
+
|
|
60
|
+
const galleryItems = computed(() => props.items ?? scannedItems.value)
|
|
61
|
+
const current = computed(() => galleryItems.value[currentIndex.value])
|
|
62
|
+
const hasMultiple = computed(() => galleryItems.value.length > 1)
|
|
63
|
+
|
|
64
|
+
watch(() => props.modelValue, (v) => { isOpen.value = v })
|
|
65
|
+
watch(() => props.index, (v) => { currentIndex.value = v })
|
|
66
|
+
|
|
67
|
+
function setIndex(i: number) {
|
|
68
|
+
currentIndex.value = i
|
|
69
|
+
emit('update:index', i)
|
|
70
|
+
emit('change', i)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function open(i = 0, sourceEl?: HTMLElement) {
|
|
74
|
+
originRect = sourceEl ? sourceEl.getBoundingClientRect() : null
|
|
75
|
+
isFirstShow.value = true
|
|
76
|
+
setIndex(i)
|
|
77
|
+
isOpen.value = true
|
|
78
|
+
emit('update:modelValue', true)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function close() {
|
|
82
|
+
isOpen.value = false
|
|
83
|
+
emit('update:modelValue', false)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function next() {
|
|
87
|
+
const len = galleryItems.value.length
|
|
88
|
+
if (!len) return
|
|
89
|
+
isFirstShow.value = false
|
|
90
|
+
direction.value = 1
|
|
91
|
+
if (currentIndex.value < len - 1) setIndex(currentIndex.value + 1)
|
|
92
|
+
else if (props.loop) setIndex(0)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function prev() {
|
|
96
|
+
const len = galleryItems.value.length
|
|
97
|
+
if (!len) return
|
|
98
|
+
isFirstShow.value = false
|
|
99
|
+
direction.value = -1
|
|
100
|
+
if (currentIndex.value > 0) setIndex(currentIndex.value - 1)
|
|
101
|
+
else if (props.loop) setIndex(len - 1)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function goTo(i: number) {
|
|
105
|
+
if (i === currentIndex.value) return
|
|
106
|
+
isFirstShow.value = false
|
|
107
|
+
direction.value = i > currentIndex.value ? 1 : -1
|
|
108
|
+
setIndex(i)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function onKeydown(e: KeyboardEvent) {
|
|
112
|
+
if (e.key === 'Escape') close()
|
|
113
|
+
else if (e.key === 'ArrowRight') next()
|
|
114
|
+
else if (e.key === 'ArrowLeft') prev()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
watch(isOpen, (open) => {
|
|
118
|
+
if (open) {
|
|
119
|
+
document.addEventListener('keydown', onKeydown)
|
|
120
|
+
document.body.style.overflow = 'hidden'
|
|
121
|
+
} else {
|
|
122
|
+
document.removeEventListener('keydown', onKeydown)
|
|
123
|
+
document.body.style.overflow = ''
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
// ── Image transition: Discord-style expand from the clicked thumbnail on open, then a
|
|
128
|
+
// slide between images on next()/prev()/goTo(). Driven entirely from JS (css: false) since
|
|
129
|
+
// the "expand" transform depends on the clicked element's on-screen position/size, which
|
|
130
|
+
// plain CSS classes can't know about.
|
|
131
|
+
function transitionEndPromise(el: HTMLElement) {
|
|
132
|
+
return new Promise<void>((resolve) => {
|
|
133
|
+
const handler = (ev: TransitionEvent) => {
|
|
134
|
+
if (ev.target !== el) return
|
|
135
|
+
el.removeEventListener('transitionend', handler)
|
|
136
|
+
resolve()
|
|
137
|
+
}
|
|
138
|
+
el.addEventListener('transitionend', handler)
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function onImageBeforeEnter(el: Element) {
|
|
143
|
+
const target = el as HTMLElement
|
|
144
|
+
if (isFirstShow.value) {
|
|
145
|
+
if (originRect) {
|
|
146
|
+
// Translate by the two boxes' centers (target fills the stage and centers the image via
|
|
147
|
+
// flex, so its center already coincides with the image's), but scale by the ratio against
|
|
148
|
+
// the actual rendered <img> size, not the full-stage wrapper's size.
|
|
149
|
+
const containerRect = target.getBoundingClientRect()
|
|
150
|
+
const imgRect = target.querySelector('img')?.getBoundingClientRect() ?? containerRect
|
|
151
|
+
const dx = originRect.x + originRect.width / 2 - (containerRect.left + containerRect.width / 2)
|
|
152
|
+
const dy = originRect.y + originRect.height / 2 - (containerRect.top + containerRect.height / 2)
|
|
153
|
+
const area = Math.max(imgRect.width * imgRect.height, 1)
|
|
154
|
+
const scale = Math.min(1, Math.max(0.05, Math.sqrt((originRect.width * originRect.height) / area)))
|
|
155
|
+
target.style.transform = `translate(${dx}px, ${dy}px) scale(${scale})`
|
|
156
|
+
} else {
|
|
157
|
+
target.style.transform = 'scale(0.92)'
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
target.style.transform = `translateX(${direction.value >= 0 ? 100 : -100}%)`
|
|
161
|
+
}
|
|
162
|
+
target.style.opacity = '0'
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function onImageEnter(el: Element, done: () => void) {
|
|
166
|
+
const target = el as HTMLElement
|
|
167
|
+
void target.offsetWidth // force reflow so the "from" styles above are committed first
|
|
168
|
+
if (isFirstShow.value) {
|
|
169
|
+
// Let the scrim fade in on its own first, Discord-style, before the image starts growing.
|
|
170
|
+
await new Promise((resolve) => setTimeout(resolve, 120))
|
|
171
|
+
}
|
|
172
|
+
target.style.transition = 'transform 0.32s cubic-bezier(0.2, 0, 0, 1), opacity 0.28s ease'
|
|
173
|
+
target.style.transform = ''
|
|
174
|
+
target.style.opacity = ''
|
|
175
|
+
await transitionEndPromise(target)
|
|
176
|
+
target.style.transition = ''
|
|
177
|
+
isFirstShow.value = false
|
|
178
|
+
done()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function onImageLeave(el: Element, done: () => void) {
|
|
182
|
+
const target = el as HTMLElement
|
|
183
|
+
target.style.transition = 'transform 0.32s cubic-bezier(0.2, 0, 0, 1), opacity 0.28s ease'
|
|
184
|
+
target.style.transform = `translateX(${direction.value >= 0 ? -100 : 100}%)`
|
|
185
|
+
target.style.opacity = '0'
|
|
186
|
+
await transitionEndPromise(target)
|
|
187
|
+
done()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ── Swipe/drag to navigate: follows the pointer 1:1 while held, then either commits to
|
|
191
|
+
// next()/prev() (which take over via the enter/leave hooks above, continuing smoothly from
|
|
192
|
+
// wherever the drag left off) or springs back to center if released short of the threshold.
|
|
193
|
+
let dragPointerId: number | null = null
|
|
194
|
+
let dragStartX = 0
|
|
195
|
+
let dragOffsetPx = 0
|
|
196
|
+
let dragStageWidth = 0
|
|
197
|
+
let isDragging = false
|
|
198
|
+
|
|
199
|
+
function onStagePointerDown(e: PointerEvent) {
|
|
200
|
+
if (!hasMultiple.value || e.button !== 0) return
|
|
201
|
+
const stage = e.currentTarget as HTMLElement
|
|
202
|
+
dragStageWidth = stage.clientWidth
|
|
203
|
+
dragStartX = e.clientX
|
|
204
|
+
dragOffsetPx = 0
|
|
205
|
+
dragPointerId = e.pointerId
|
|
206
|
+
isDragging = true
|
|
207
|
+
stage.setPointerCapture(e.pointerId)
|
|
208
|
+
if (stageImageEl.value) stageImageEl.value.style.transition = 'none'
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function onStagePointerMove(e: PointerEvent) {
|
|
212
|
+
if (!isDragging || e.pointerId !== dragPointerId) return
|
|
213
|
+
dragOffsetPx = e.clientX - dragStartX
|
|
214
|
+
if (stageImageEl.value) stageImageEl.value.style.transform = `translateX(${dragOffsetPx}px)`
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function endDrag(e: PointerEvent) {
|
|
218
|
+
if (!isDragging || e.pointerId !== dragPointerId) return
|
|
219
|
+
isDragging = false
|
|
220
|
+
const stage = e.currentTarget as HTMLElement
|
|
221
|
+
if (stage.hasPointerCapture(e.pointerId)) stage.releasePointerCapture(e.pointerId)
|
|
222
|
+
|
|
223
|
+
const threshold = Math.min(120, dragStageWidth * 0.25)
|
|
224
|
+
const offset = dragOffsetPx
|
|
225
|
+
dragOffsetPx = 0
|
|
226
|
+
|
|
227
|
+
if (offset <= -threshold) next()
|
|
228
|
+
else if (offset >= threshold) prev()
|
|
229
|
+
else if (stageImageEl.value) {
|
|
230
|
+
const el = stageImageEl.value
|
|
231
|
+
el.style.transition = 'transform 0.25s cubic-bezier(0.2, 0, 0, 1)'
|
|
232
|
+
el.style.transform = ''
|
|
233
|
+
const cleanup = (ev: TransitionEvent) => {
|
|
234
|
+
if (ev.target !== el) return
|
|
235
|
+
el.style.transition = ''
|
|
236
|
+
el.removeEventListener('transitionend', cleanup)
|
|
237
|
+
}
|
|
238
|
+
el.addEventListener('transitionend', cleanup)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Auto-scan mode: pull <img> elements out of whatever is rendered in the default slot
|
|
243
|
+
// (e.g. MMarkdown output, a hand-rolled gallery grid) so this works without building an
|
|
244
|
+
// `items` array by hand. Opt an image out with `data-lightbox="false"`.
|
|
245
|
+
let observer: MutationObserver | null = null
|
|
246
|
+
|
|
247
|
+
function scan() {
|
|
248
|
+
if (props.items || !containerEl.value) return
|
|
249
|
+
const imgs = Array.from(containerEl.value.querySelectorAll('img')).filter(
|
|
250
|
+
(img) => img.dataset.lightbox !== 'false',
|
|
251
|
+
)
|
|
252
|
+
scannedItems.value = imgs.map((img) => ({
|
|
253
|
+
src: img.currentSrc || img.src,
|
|
254
|
+
alt: img.alt || undefined,
|
|
255
|
+
caption: img.dataset.caption || img.title || undefined,
|
|
256
|
+
}))
|
|
257
|
+
imgs.forEach((img, i) => {
|
|
258
|
+
img.style.cursor = 'zoom-in'
|
|
259
|
+
img.onclick = (e) => {
|
|
260
|
+
e.preventDefault()
|
|
261
|
+
open(i, img)
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
onMounted(() => {
|
|
267
|
+
if (props.items || !containerEl.value) return
|
|
268
|
+
scan()
|
|
269
|
+
observer = new MutationObserver(scan)
|
|
270
|
+
observer.observe(containerEl.value, {
|
|
271
|
+
childList: true,
|
|
272
|
+
subtree: true,
|
|
273
|
+
attributes: true,
|
|
274
|
+
attributeFilter: ['src'],
|
|
275
|
+
})
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
onBeforeUnmount(() => {
|
|
279
|
+
observer?.disconnect()
|
|
280
|
+
document.removeEventListener('keydown', onKeydown)
|
|
281
|
+
document.body.style.overflow = ''
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
defineExpose({ open, close, next, prev })
|
|
285
|
+
</script>
|
|
286
|
+
|
|
287
|
+
<template>
|
|
288
|
+
<div ref="containerEl" class="contents">
|
|
289
|
+
<slot />
|
|
290
|
+
</div>
|
|
291
|
+
|
|
292
|
+
<Teleport to="body">
|
|
293
|
+
<Transition name="m3-lightbox">
|
|
294
|
+
<div
|
|
295
|
+
v-if="isOpen"
|
|
296
|
+
class="fixed inset-0 z-[100] flex flex-col bg-black/90"
|
|
297
|
+
@click.self="close"
|
|
298
|
+
>
|
|
299
|
+
<span
|
|
300
|
+
v-if="hasMultiple"
|
|
301
|
+
class="absolute left-2 top-2 z-10 rounded-full bg-black/30 px-3 py-1 text-label-large text-white sm:left-4 sm:top-4"
|
|
302
|
+
>
|
|
303
|
+
{{ currentIndex + 1 }} / {{ galleryItems.length }}
|
|
304
|
+
</span>
|
|
305
|
+
|
|
306
|
+
<button
|
|
307
|
+
type="button"
|
|
308
|
+
class="absolute right-2 top-2 z-10 flex h-11 w-11 items-center justify-center rounded-full bg-black/30 text-white transition-colors hover:bg-black/50 sm:right-4 sm:top-4"
|
|
309
|
+
:aria-label="closeLabel ?? locale.close"
|
|
310
|
+
@click="close"
|
|
311
|
+
>
|
|
312
|
+
<MIcon name="close" :size="24" />
|
|
313
|
+
</button>
|
|
314
|
+
|
|
315
|
+
<div class="relative flex flex-1 items-center justify-center overflow-hidden" @click.self="close">
|
|
316
|
+
<button
|
|
317
|
+
v-if="hasMultiple"
|
|
318
|
+
type="button"
|
|
319
|
+
class="absolute left-2 top-1/2 z-10 flex h-11 w-11 -translate-y-1/2 items-center justify-center rounded-full bg-black/30 text-white transition-colors hover:bg-black/50 sm:left-4"
|
|
320
|
+
:aria-label="locale.previous"
|
|
321
|
+
@click.stop="prev"
|
|
322
|
+
>
|
|
323
|
+
<MIcon name="chevron_left" :size="28" />
|
|
324
|
+
</button>
|
|
325
|
+
|
|
326
|
+
<div
|
|
327
|
+
class="relative h-full w-full touch-pan-y overflow-hidden"
|
|
328
|
+
@pointerdown="onStagePointerDown"
|
|
329
|
+
@pointermove="onStagePointerMove"
|
|
330
|
+
@pointerup="endDrag"
|
|
331
|
+
@pointercancel="endDrag"
|
|
332
|
+
>
|
|
333
|
+
<Transition
|
|
334
|
+
:css="false"
|
|
335
|
+
@before-enter="onImageBeforeEnter"
|
|
336
|
+
@enter="onImageEnter"
|
|
337
|
+
@leave="onImageLeave"
|
|
338
|
+
>
|
|
339
|
+
<div
|
|
340
|
+
v-if="current"
|
|
341
|
+
:key="currentIndex"
|
|
342
|
+
ref="stageImageEl"
|
|
343
|
+
class="absolute inset-0 flex items-center justify-center p-4"
|
|
344
|
+
@click="close"
|
|
345
|
+
>
|
|
346
|
+
<img
|
|
347
|
+
:src="current.src"
|
|
348
|
+
:alt="current.alt ?? ''"
|
|
349
|
+
class="max-h-full max-w-full select-none object-contain"
|
|
350
|
+
:class="rounded ? 'rounded-2xl' : ''"
|
|
351
|
+
draggable="false"
|
|
352
|
+
@click.stop
|
|
353
|
+
/>
|
|
354
|
+
</div>
|
|
355
|
+
</Transition>
|
|
356
|
+
</div>
|
|
357
|
+
|
|
358
|
+
<button
|
|
359
|
+
v-if="hasMultiple"
|
|
360
|
+
type="button"
|
|
361
|
+
class="absolute right-2 top-1/2 z-10 flex h-11 w-11 -translate-y-1/2 items-center justify-center rounded-full bg-black/30 text-white transition-colors hover:bg-black/50 sm:right-4"
|
|
362
|
+
:aria-label="locale.next"
|
|
363
|
+
@click.stop="next"
|
|
364
|
+
>
|
|
365
|
+
<MIcon name="chevron_right" :size="28" />
|
|
366
|
+
</button>
|
|
367
|
+
</div>
|
|
368
|
+
|
|
369
|
+
<p
|
|
370
|
+
v-if="current?.caption"
|
|
371
|
+
class="z-10 px-4 text-center text-body-medium text-white/90"
|
|
372
|
+
>
|
|
373
|
+
{{ current.caption }}
|
|
374
|
+
</p>
|
|
375
|
+
|
|
376
|
+
<div
|
|
377
|
+
v-if="showThumbnails && hasMultiple"
|
|
378
|
+
class="z-10 flex justify-center gap-2 overflow-x-auto p-4"
|
|
379
|
+
>
|
|
380
|
+
<button
|
|
381
|
+
v-for="(item, i) in galleryItems"
|
|
382
|
+
:key="i"
|
|
383
|
+
type="button"
|
|
384
|
+
class="h-14 w-14 shrink-0 overflow-hidden rounded-md ring-2 transition-opacity"
|
|
385
|
+
:class="i === currentIndex ? 'opacity-100 ring-white' : 'opacity-50 ring-transparent hover:opacity-80'"
|
|
386
|
+
@click="goTo(i)"
|
|
387
|
+
>
|
|
388
|
+
<img :src="item.src" :alt="item.alt ?? ''" class="h-full w-full object-cover" draggable="false" />
|
|
389
|
+
</button>
|
|
390
|
+
</div>
|
|
391
|
+
</div>
|
|
392
|
+
</Transition>
|
|
393
|
+
</Teleport>
|
|
394
|
+
</template>
|
|
395
|
+
|
|
396
|
+
<style scoped>
|
|
397
|
+
.m3-lightbox-enter-active,
|
|
398
|
+
.m3-lightbox-leave-active {
|
|
399
|
+
transition: opacity 0.2s ease;
|
|
400
|
+
}
|
|
401
|
+
.m3-lightbox-enter-from,
|
|
402
|
+
.m3-lightbox-leave-to {
|
|
403
|
+
opacity: 0;
|
|
404
|
+
}
|
|
405
|
+
</style>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, watch } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(
|
|
5
|
+
defineProps<{
|
|
6
|
+
value: string
|
|
7
|
+
/** 5 labels, weakest to strongest. */
|
|
8
|
+
labels?: string[]
|
|
9
|
+
/** Length considered "long enough" — also used (+4) as the "very long" bonus threshold. */
|
|
10
|
+
minLength?: number
|
|
11
|
+
}>(),
|
|
12
|
+
{
|
|
13
|
+
labels: () => ['Very weak', 'Weak', 'Fair', 'Good', 'Strong'],
|
|
14
|
+
minLength: 8,
|
|
15
|
+
},
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const emit = defineEmits<{ score: [number] }>()
|
|
19
|
+
|
|
20
|
+
function scorePassword(pw: string, minLength: number): number {
|
|
21
|
+
let score = 0
|
|
22
|
+
if (pw.length >= minLength) score++
|
|
23
|
+
if (pw.length >= minLength + 4) score++
|
|
24
|
+
if (/[a-z]/.test(pw) && /[A-Z]/.test(pw)) score++
|
|
25
|
+
if (/\d/.test(pw)) score++
|
|
26
|
+
if (/[^a-zA-Z0-9]/.test(pw)) score++
|
|
27
|
+
return Math.min(score, 4)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const hasValue = computed(() => props.value.length > 0)
|
|
31
|
+
const score = computed(() => scorePassword(props.value, props.minLength))
|
|
32
|
+
const filledCount = computed(() => (hasValue.value ? score.value + 1 : 0))
|
|
33
|
+
|
|
34
|
+
const COLORS = ['bg-error', 'bg-error', 'bg-tertiary', 'bg-primary', 'bg-success']
|
|
35
|
+
const TEXT_COLORS = ['text-error', 'text-error', 'text-tertiary', 'text-primary', 'text-success']
|
|
36
|
+
|
|
37
|
+
const barColor = computed(() => COLORS[score.value])
|
|
38
|
+
const textColor = computed(() => TEXT_COLORS[score.value])
|
|
39
|
+
const label = computed(() => props.labels[score.value] ?? '')
|
|
40
|
+
|
|
41
|
+
watch([() => props.value, score], () => emit('score', hasValue.value ? score.value : -1), { immediate: true })
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<template>
|
|
45
|
+
<div class="flex flex-col gap-1">
|
|
46
|
+
<div class="flex gap-1">
|
|
47
|
+
<div
|
|
48
|
+
v-for="i in 5"
|
|
49
|
+
:key="i"
|
|
50
|
+
class="h-1 flex-1 rounded-full transition-colors duration-200"
|
|
51
|
+
:class="i <= filledCount ? barColor : 'bg-surface-container-highest'"
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
<p v-if="hasValue" class="text-body-small" :class="textColor">{{ label }}</p>
|
|
55
|
+
</div>
|
|
56
|
+
</template>
|