@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,351 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** A signature line of an `MCertificate`. */
|
|
3
|
+
export interface CertificateSignature {
|
|
4
|
+
name: string
|
|
5
|
+
/** e.g. "Course director" */
|
|
6
|
+
role?: string
|
|
7
|
+
/** Image of the signature (a URL or a data URL, e.g. from MSignaturePad), drawn over the line */
|
|
8
|
+
image?: string
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
/**
|
|
14
|
+
* A printable certificate or diploma: a course completion, an award, a training, a membership. It keeps an A4 shape
|
|
15
|
+
* at any width and scales its type with it, so the same component works as a thumbnail, on screen and on paper;
|
|
16
|
+
* `print()` prints just the certificate on an A4 page. Three looks: `classic` (double frame and serif type),
|
|
17
|
+
* `modern` (a colored band) and `minimal`.
|
|
18
|
+
*
|
|
19
|
+
* @slot logo The issuer's logo, at the top
|
|
20
|
+
* @slot seal Replaces the seal (a rosette with an icon)
|
|
21
|
+
* @slot default Extra content under the description (grades, hours, a QR to verify)
|
|
22
|
+
*/
|
|
23
|
+
import { computed, ref } from 'vue'
|
|
24
|
+
import MIcon from './MIcon.vue'
|
|
25
|
+
import { useLocale } from '../composables/useLocale'
|
|
26
|
+
import { printElement } from '../composables/_printElement'
|
|
27
|
+
|
|
28
|
+
const locale = useLocale()
|
|
29
|
+
|
|
30
|
+
const ROLES = ['primary', 'secondary', 'tertiary', 'error', 'success']
|
|
31
|
+
|
|
32
|
+
const props = withDefaults(
|
|
33
|
+
defineProps<{
|
|
34
|
+
/** Who receives it */
|
|
35
|
+
recipient: string
|
|
36
|
+
/** Big title. Defaults to the locale's "Certificate of completion" */
|
|
37
|
+
title?: string
|
|
38
|
+
/** Line before the name. Defaults to the locale's "This certifies that" */
|
|
39
|
+
presentedTo?: string
|
|
40
|
+
/** What it is for, e.g. "has completed the course Vue 3 Fundamentals (24 hours)" */
|
|
41
|
+
description?: string
|
|
42
|
+
/** Name of the issuing organization */
|
|
43
|
+
issuer?: string
|
|
44
|
+
/** Date it was awarded (Date, ISO string or epoch ms) */
|
|
45
|
+
date?: Date | string | number
|
|
46
|
+
/** Certificate number or verification code */
|
|
47
|
+
code?: string
|
|
48
|
+
signatures?: CertificateSignature[]
|
|
49
|
+
/** Look of the certificate */
|
|
50
|
+
variant?: 'classic' | 'modern' | 'minimal'
|
|
51
|
+
/** Accent color: a role (primary, secondary, tertiary, error, success) or any CSS color */
|
|
52
|
+
color?: string
|
|
53
|
+
/** Material Symbol in the seal; `false` hides the seal */
|
|
54
|
+
seal?: string | false
|
|
55
|
+
orientation?: 'landscape' | 'portrait'
|
|
56
|
+
}>(),
|
|
57
|
+
{
|
|
58
|
+
signatures: () => [],
|
|
59
|
+
variant: 'classic',
|
|
60
|
+
color: 'primary',
|
|
61
|
+
seal: 'workspace_premium',
|
|
62
|
+
orientation: 'landscape',
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const accent = computed(() => (ROLES.includes(props.color) ? `var(--color-${props.color})` : props.color))
|
|
67
|
+
|
|
68
|
+
const dateText = computed(() => {
|
|
69
|
+
if (props.date === undefined) return ''
|
|
70
|
+
const d = props.date instanceof Date ? props.date : new Date(props.date)
|
|
71
|
+
return new Intl.DateTimeFormat(locale.lang, { dateStyle: 'long' }).format(d)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
75
|
+
|
|
76
|
+
/** Prints just the certificate, filling an A4 page */
|
|
77
|
+
function print() {
|
|
78
|
+
if (!rootEl.value) return
|
|
79
|
+
printElement(rootEl.value, {
|
|
80
|
+
page: `A4 ${props.orientation}`,
|
|
81
|
+
css: '.m3-certificate{width:100vw!important;max-width:none!important;box-shadow:none!important}',
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
defineExpose({ print })
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<div
|
|
90
|
+
ref="rootEl"
|
|
91
|
+
class="m3-certificate"
|
|
92
|
+
:class="[`m3-certificate--${variant}`]"
|
|
93
|
+
:style="{ '--m3-cert-accent': accent, aspectRatio: orientation === 'landscape' ? '297 / 210' : '210 / 297' }"
|
|
94
|
+
:data-variant="variant"
|
|
95
|
+
>
|
|
96
|
+
<div class="m3-certificate__frame">
|
|
97
|
+
<div v-if="$slots.logo || issuer" class="m3-certificate__issuer">
|
|
98
|
+
<slot name="logo" />
|
|
99
|
+
<span v-if="issuer" data-issuer>{{ issuer }}</span>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<h2 class="m3-certificate__title" data-title>{{ title ?? locale.certTitle }}</h2>
|
|
103
|
+
<p class="m3-certificate__lead">{{ presentedTo ?? locale.certPresentedTo }}</p>
|
|
104
|
+
<p class="m3-certificate__name" data-recipient>{{ recipient }}</p>
|
|
105
|
+
<p v-if="description" class="m3-certificate__desc">{{ description }}</p>
|
|
106
|
+
<div v-if="$slots.default" class="m3-certificate__extra"><slot /></div>
|
|
107
|
+
|
|
108
|
+
<div class="m3-certificate__footer">
|
|
109
|
+
<div v-if="dateText" class="m3-certificate__sign">
|
|
110
|
+
<span class="m3-certificate__sign-value">{{ dateText }}</span>
|
|
111
|
+
<span class="m3-certificate__sign-line" />
|
|
112
|
+
<span class="m3-certificate__sign-role">{{ locale.certDate }}</span>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<div v-if="seal !== false || $slots.seal" class="m3-certificate__seal" aria-hidden="true">
|
|
116
|
+
<slot name="seal">
|
|
117
|
+
<svg viewBox="0 0 100 100" class="m3-certificate__rosette">
|
|
118
|
+
<polygon
|
|
119
|
+
:points="Array.from({ length: 24 }, (_, i) => {
|
|
120
|
+
const a = (i * Math.PI) / 12
|
|
121
|
+
const r = i % 2 ? 44 : 50
|
|
122
|
+
return `${50 + r * Math.cos(a)},${50 + r * Math.sin(a)}`
|
|
123
|
+
}).join(' ')"
|
|
124
|
+
/>
|
|
125
|
+
<circle cx="50" cy="50" r="36" fill="none" stroke="currentColor" stroke-width="1.5" stroke-dasharray="2 2.5" />
|
|
126
|
+
</svg>
|
|
127
|
+
<MIcon :name="seal || 'workspace_premium'" class="m3-certificate__seal-icon" />
|
|
128
|
+
</slot>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<div v-for="s in signatures" :key="s.name" class="m3-certificate__sign" data-signature>
|
|
132
|
+
<img v-if="s.image" :src="s.image" alt="" class="m3-certificate__sign-img" />
|
|
133
|
+
<span v-else class="m3-certificate__sign-value"> </span>
|
|
134
|
+
<span class="m3-certificate__sign-line" />
|
|
135
|
+
<span class="m3-certificate__sign-name">{{ s.name }}</span>
|
|
136
|
+
<span v-if="s.role" class="m3-certificate__sign-role">{{ s.role }}</span>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<p v-if="code" class="m3-certificate__code" data-code>{{ locale.certId }}: {{ code }}</p>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</template>
|
|
144
|
+
|
|
145
|
+
<style>
|
|
146
|
+
@layer base {
|
|
147
|
+
.m3-certificate {
|
|
148
|
+
width: 100%;
|
|
149
|
+
position: relative;
|
|
150
|
+
overflow: hidden;
|
|
151
|
+
background: #fffdf8;
|
|
152
|
+
color: #1d1b20;
|
|
153
|
+
box-shadow: var(--shadow-elevation-2);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
.m3-certificate {
|
|
157
|
+
container-type: inline-size;
|
|
158
|
+
/* The paper is always light: in the dark theme the accent role is a light tone, so it's darkened into ink */
|
|
159
|
+
--m3-cert-ink: var(--m3-cert-accent);
|
|
160
|
+
}
|
|
161
|
+
:where(.dark) .m3-certificate {
|
|
162
|
+
--m3-cert-ink: color-mix(in oklab, var(--m3-cert-accent) 55%, #000);
|
|
163
|
+
}
|
|
164
|
+
.m3-certificate__frame {
|
|
165
|
+
position: absolute;
|
|
166
|
+
inset: 3.2cqw;
|
|
167
|
+
display: flex;
|
|
168
|
+
flex-direction: column;
|
|
169
|
+
align-items: center;
|
|
170
|
+
justify-content: center;
|
|
171
|
+
text-align: center;
|
|
172
|
+
padding: 3cqw 6cqw;
|
|
173
|
+
gap: 1cqw;
|
|
174
|
+
}
|
|
175
|
+
.m3-certificate__issuer {
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: 1.2cqw;
|
|
179
|
+
font-size: 1.7cqw;
|
|
180
|
+
font-weight: 600;
|
|
181
|
+
letter-spacing: 0.25em;
|
|
182
|
+
text-transform: uppercase;
|
|
183
|
+
color: var(--m3-cert-ink);
|
|
184
|
+
}
|
|
185
|
+
.m3-certificate__issuer img,
|
|
186
|
+
.m3-certificate__issuer svg {
|
|
187
|
+
height: 4.5cqw;
|
|
188
|
+
width: auto;
|
|
189
|
+
}
|
|
190
|
+
.m3-certificate__title {
|
|
191
|
+
font-size: 4.6cqw;
|
|
192
|
+
line-height: 1.1;
|
|
193
|
+
font-weight: 700;
|
|
194
|
+
margin-top: 1cqw;
|
|
195
|
+
}
|
|
196
|
+
.m3-certificate__lead {
|
|
197
|
+
font-size: 1.8cqw;
|
|
198
|
+
color: #49454f;
|
|
199
|
+
margin-top: 1.4cqw;
|
|
200
|
+
}
|
|
201
|
+
.m3-certificate__name {
|
|
202
|
+
font-size: 5.4cqw;
|
|
203
|
+
line-height: 1.15;
|
|
204
|
+
color: var(--m3-cert-ink);
|
|
205
|
+
padding: 0 4cqw 0.6cqw;
|
|
206
|
+
border-bottom: 0.15cqw solid color-mix(in srgb, var(--m3-cert-ink) 50%, transparent);
|
|
207
|
+
}
|
|
208
|
+
.m3-certificate__desc {
|
|
209
|
+
font-size: 1.9cqw;
|
|
210
|
+
line-height: 1.45;
|
|
211
|
+
max-width: 72cqw;
|
|
212
|
+
color: #49454f;
|
|
213
|
+
margin-top: 0.6cqw;
|
|
214
|
+
}
|
|
215
|
+
.m3-certificate__extra {
|
|
216
|
+
font-size: 1.6cqw;
|
|
217
|
+
}
|
|
218
|
+
.m3-certificate__footer {
|
|
219
|
+
display: flex;
|
|
220
|
+
align-items: flex-end;
|
|
221
|
+
justify-content: center;
|
|
222
|
+
gap: 6cqw;
|
|
223
|
+
width: 100%;
|
|
224
|
+
margin-top: auto;
|
|
225
|
+
}
|
|
226
|
+
.m3-certificate__sign {
|
|
227
|
+
display: flex;
|
|
228
|
+
flex-direction: column;
|
|
229
|
+
align-items: center;
|
|
230
|
+
min-width: 18cqw;
|
|
231
|
+
}
|
|
232
|
+
.m3-certificate__sign-value {
|
|
233
|
+
font-size: 1.7cqw;
|
|
234
|
+
padding-bottom: 0.4cqw;
|
|
235
|
+
}
|
|
236
|
+
.m3-certificate__sign-img {
|
|
237
|
+
height: 5.5cqw;
|
|
238
|
+
max-width: 22cqw;
|
|
239
|
+
object-fit: contain;
|
|
240
|
+
margin-bottom: -0.8cqw;
|
|
241
|
+
}
|
|
242
|
+
.m3-certificate__sign-line {
|
|
243
|
+
align-self: stretch;
|
|
244
|
+
border-top: 0.12cqw solid #1d1b20;
|
|
245
|
+
}
|
|
246
|
+
.m3-certificate__sign-name {
|
|
247
|
+
font-size: 1.6cqw;
|
|
248
|
+
font-weight: 600;
|
|
249
|
+
margin-top: 0.5cqw;
|
|
250
|
+
}
|
|
251
|
+
.m3-certificate__sign-role {
|
|
252
|
+
font-size: 1.35cqw;
|
|
253
|
+
color: #49454f;
|
|
254
|
+
margin-top: 0.3cqw;
|
|
255
|
+
}
|
|
256
|
+
.m3-certificate__seal {
|
|
257
|
+
position: relative;
|
|
258
|
+
width: 11cqw;
|
|
259
|
+
height: 11cqw;
|
|
260
|
+
flex-shrink: 0;
|
|
261
|
+
color: #fff;
|
|
262
|
+
}
|
|
263
|
+
.m3-certificate__rosette {
|
|
264
|
+
width: 100%;
|
|
265
|
+
height: 100%;
|
|
266
|
+
fill: var(--m3-cert-ink);
|
|
267
|
+
}
|
|
268
|
+
.m3-certificate__seal-icon {
|
|
269
|
+
position: absolute;
|
|
270
|
+
inset: 0;
|
|
271
|
+
margin: auto;
|
|
272
|
+
font-size: 5cqw !important;
|
|
273
|
+
width: 5cqw !important;
|
|
274
|
+
height: 5cqw !important;
|
|
275
|
+
display: flex;
|
|
276
|
+
align-items: center;
|
|
277
|
+
justify-content: center;
|
|
278
|
+
}
|
|
279
|
+
.m3-certificate__code {
|
|
280
|
+
position: absolute;
|
|
281
|
+
bottom: 1.2cqw;
|
|
282
|
+
right: 2cqw;
|
|
283
|
+
font-size: 1.1cqw;
|
|
284
|
+
color: #79747e;
|
|
285
|
+
font-family: var(--font-mono, ui-monospace, monospace);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/* classic: double frame, corner marks, serif type */
|
|
289
|
+
.m3-certificate--classic {
|
|
290
|
+
font-family: var(--font-serif, Georgia, 'Times New Roman', serif);
|
|
291
|
+
}
|
|
292
|
+
.m3-certificate--classic .m3-certificate__frame {
|
|
293
|
+
border: 0.5cqw double var(--m3-cert-ink);
|
|
294
|
+
outline: 0.15cqw solid color-mix(in srgb, var(--m3-cert-ink) 45%, transparent);
|
|
295
|
+
outline-offset: 0.8cqw;
|
|
296
|
+
}
|
|
297
|
+
.m3-certificate--classic .m3-certificate__title {
|
|
298
|
+
font-weight: 400;
|
|
299
|
+
letter-spacing: 0.06em;
|
|
300
|
+
text-transform: uppercase;
|
|
301
|
+
}
|
|
302
|
+
.m3-certificate--classic .m3-certificate__name {
|
|
303
|
+
font-style: italic;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/* modern: a band of the accent color on the left */
|
|
307
|
+
.m3-certificate--modern {
|
|
308
|
+
font-family: var(--font-sans, system-ui, sans-serif);
|
|
309
|
+
}
|
|
310
|
+
.m3-certificate--modern::before {
|
|
311
|
+
content: '';
|
|
312
|
+
position: absolute;
|
|
313
|
+
inset: 0 auto 0 0;
|
|
314
|
+
width: 2.4cqw;
|
|
315
|
+
background: var(--m3-cert-ink);
|
|
316
|
+
}
|
|
317
|
+
.m3-certificate--modern::after {
|
|
318
|
+
content: '';
|
|
319
|
+
position: absolute;
|
|
320
|
+
top: -12cqw;
|
|
321
|
+
right: -12cqw;
|
|
322
|
+
width: 34cqw;
|
|
323
|
+
height: 34cqw;
|
|
324
|
+
border-radius: 50%;
|
|
325
|
+
background: color-mix(in srgb, var(--m3-cert-ink) 10%, transparent);
|
|
326
|
+
}
|
|
327
|
+
.m3-certificate--modern .m3-certificate__frame {
|
|
328
|
+
align-items: flex-start;
|
|
329
|
+
text-align: start;
|
|
330
|
+
inset: 3.2cqw 3.2cqw 3.2cqw 6cqw;
|
|
331
|
+
z-index: 1;
|
|
332
|
+
}
|
|
333
|
+
.m3-certificate--modern .m3-certificate__name {
|
|
334
|
+
padding-inline: 0 4cqw;
|
|
335
|
+
font-weight: 600;
|
|
336
|
+
}
|
|
337
|
+
.m3-certificate--modern .m3-certificate__footer {
|
|
338
|
+
justify-content: flex-start;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* minimal: a hairline frame */
|
|
342
|
+
.m3-certificate--minimal {
|
|
343
|
+
font-family: var(--font-sans, system-ui, sans-serif);
|
|
344
|
+
}
|
|
345
|
+
.m3-certificate--minimal .m3-certificate__frame {
|
|
346
|
+
border: 0.12cqw solid #cac4d0;
|
|
347
|
+
}
|
|
348
|
+
.m3-certificate--minimal .m3-certificate__title {
|
|
349
|
+
font-weight: 300;
|
|
350
|
+
}
|
|
351
|
+
</style>
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export type CountdownUnit = 'days' | 'hours' | 'minutes' | 'seconds'
|
|
3
|
+
|
|
4
|
+
/** What the default slot receives: the time left, split into the units shown */
|
|
5
|
+
export interface CountdownParts {
|
|
6
|
+
days: number
|
|
7
|
+
hours: number
|
|
8
|
+
minutes: number
|
|
9
|
+
seconds: number
|
|
10
|
+
/** Milliseconds left (0 once finished) */
|
|
11
|
+
total: number
|
|
12
|
+
finished: boolean
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
/**
|
|
18
|
+
* MCountdown — a countdown to a date: days, hours, minutes and seconds with rolling digits, in boxes or inline.
|
|
19
|
+
* Unit names come from `Intl` in the app's language. Units left out of `units` fold into the next larger one shown
|
|
20
|
+
* (no `days` → 50 hours). Ticks on the second boundary; every tick costs one timer, not one per digit.
|
|
21
|
+
*
|
|
22
|
+
* @slot default Replaces the whole rendering; receives `CountdownParts` (`days`, `hours`, `minutes`, `seconds`, `total`, `finished`)
|
|
23
|
+
* @slot finished Shown instead of the countdown once it reaches zero
|
|
24
|
+
* @event finished Emitted once when the countdown reaches zero (not on mount if `to` is already past)
|
|
25
|
+
* @event tick Emitted every second with the `CountdownParts`
|
|
26
|
+
*/
|
|
27
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
28
|
+
import MAnimatedNumber from './MAnimatedNumber.vue'
|
|
29
|
+
import { useLocale } from '../composables/useLocale'
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(
|
|
32
|
+
defineProps<{
|
|
33
|
+
/** The moment it counts down to: a `Date`, a timestamp in ms, or a date string */
|
|
34
|
+
to: Date | number | string
|
|
35
|
+
/** Units shown, largest first; leaving one out folds it into the next larger one */
|
|
36
|
+
units?: CountdownUnit[]
|
|
37
|
+
/** `boxes`: each unit in its own container with its name below; `inline`: one line of text (3d 04h 12m) */
|
|
38
|
+
variant?: 'boxes' | 'inline'
|
|
39
|
+
/** Digit size */
|
|
40
|
+
size?: 'sm' | 'md' | 'lg'
|
|
41
|
+
/** Show unit names */
|
|
42
|
+
labels?: boolean
|
|
43
|
+
/** Hide leading units while they're zero (no "0 days" a few hours before) */
|
|
44
|
+
hideEmpty?: boolean
|
|
45
|
+
/** Roll the digits; false (or the system's reduced motion) swaps them */
|
|
46
|
+
animate?: boolean
|
|
47
|
+
/** BCP-47 language for the unit names; defaults to the app's locale */
|
|
48
|
+
locale?: string
|
|
49
|
+
}>(),
|
|
50
|
+
{
|
|
51
|
+
units: () => ['days', 'hours', 'minutes', 'seconds'],
|
|
52
|
+
variant: 'boxes',
|
|
53
|
+
size: 'md',
|
|
54
|
+
labels: true,
|
|
55
|
+
hideEmpty: false,
|
|
56
|
+
animate: true,
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const emit = defineEmits<{ finished: []; tick: [CountdownParts] }>()
|
|
61
|
+
|
|
62
|
+
const t = useLocale()
|
|
63
|
+
const lang = computed(() => props.locale ?? t.lang)
|
|
64
|
+
|
|
65
|
+
const target = computed(() => {
|
|
66
|
+
const v = props.to
|
|
67
|
+
return v instanceof Date ? v.getTime() : typeof v === 'number' ? v : new Date(v).getTime()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const now = ref(Date.now())
|
|
71
|
+
const total = computed(() => (Number.isNaN(target.value) ? 0 : Math.max(0, target.value - now.value)))
|
|
72
|
+
|
|
73
|
+
const ORDER: CountdownUnit[] = ['days', 'hours', 'minutes', 'seconds']
|
|
74
|
+
const MS: Record<CountdownUnit, number> = { days: 86_400_000, hours: 3_600_000, minutes: 60_000, seconds: 1000 }
|
|
75
|
+
|
|
76
|
+
const shown = computed(() => ORDER.filter((u) => props.units.includes(u)))
|
|
77
|
+
|
|
78
|
+
const parts = computed<CountdownParts>(() => {
|
|
79
|
+
// Round up to the smallest unit shown: 0.4s left reads 1s (30s left reads 1 min without seconds), and 0 only
|
|
80
|
+
// appears when it's really over.
|
|
81
|
+
const step = MS[shown.value[shown.value.length - 1] ?? 'seconds']
|
|
82
|
+
let rest = Math.ceil(total.value / step) * step
|
|
83
|
+
const out: CountdownParts = { days: 0, hours: 0, minutes: 0, seconds: 0, total: total.value, finished: total.value <= 0 }
|
|
84
|
+
for (const u of shown.value) {
|
|
85
|
+
out[u] = Math.floor(rest / MS[u])
|
|
86
|
+
rest -= out[u] * MS[u]
|
|
87
|
+
}
|
|
88
|
+
return out
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const visible = computed(() => {
|
|
92
|
+
if (!props.hideEmpty) return shown.value
|
|
93
|
+
const first = shown.value.findIndex((u) => parts.value[u] > 0)
|
|
94
|
+
// Always keep the smallest unit, so the finished state still reads 00.
|
|
95
|
+
return shown.value.slice(first === -1 ? shown.value.length - 1 : Math.min(first, shown.value.length - 1))
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const INTL_UNIT: Record<CountdownUnit, string> = { days: 'day', hours: 'hour', minutes: 'minute', seconds: 'second' }
|
|
99
|
+
|
|
100
|
+
/** The language's own word for the unit, plural-aware ("1 día", "3 días"), or its narrow form for inline */
|
|
101
|
+
function unitLabel(u: CountdownUnit, n: number, display: 'long' | 'narrow') {
|
|
102
|
+
try {
|
|
103
|
+
const fmt = new Intl.NumberFormat(lang.value, { style: 'unit', unit: INTL_UNIT[u], unitDisplay: display })
|
|
104
|
+
return fmt.formatToParts(n).filter((p) => p.type === 'unit' || (display === 'narrow' && p.type === 'literal'))
|
|
105
|
+
.map((p) => p.value).join('').trim()
|
|
106
|
+
} catch {
|
|
107
|
+
return u
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const accessibleText = computed(() =>
|
|
112
|
+
shown.value
|
|
113
|
+
.map((u) => {
|
|
114
|
+
try {
|
|
115
|
+
return new Intl.NumberFormat(lang.value, { style: 'unit', unit: INTL_UNIT[u], unitDisplay: 'long' }).format(parts.value[u])
|
|
116
|
+
} catch {
|
|
117
|
+
return `${parts.value[u]} ${u}`
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
.join(', '),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
// Leading unit unpadded (3 days, 120 hours), the rest always two digits (04:09).
|
|
124
|
+
const digitFormat = (i: number) => ({ minimumIntegerDigits: i === 0 ? 1 : 2, useGrouping: false })
|
|
125
|
+
|
|
126
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
127
|
+
let done = false
|
|
128
|
+
|
|
129
|
+
function schedule() {
|
|
130
|
+
clearTimeout(timer)
|
|
131
|
+
if (total.value <= 0) return
|
|
132
|
+
// Wake when the remaining time crosses the next whole second, so displayed seconds flip on time
|
|
133
|
+
// (a late timer is harmless, it just reschedules from the new remainder).
|
|
134
|
+
const delay = total.value % 1000 || 1000
|
|
135
|
+
timer = setTimeout(step, delay)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function step() {
|
|
139
|
+
now.value = Date.now()
|
|
140
|
+
emit('tick', parts.value)
|
|
141
|
+
if (total.value <= 0 && !done) {
|
|
142
|
+
done = true
|
|
143
|
+
emit('finished')
|
|
144
|
+
}
|
|
145
|
+
schedule()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
watch(target, () => {
|
|
149
|
+
now.value = Date.now()
|
|
150
|
+
done = total.value <= 0
|
|
151
|
+
schedule()
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
onMounted(() => {
|
|
155
|
+
now.value = Date.now()
|
|
156
|
+
done = total.value <= 0
|
|
157
|
+
schedule()
|
|
158
|
+
})
|
|
159
|
+
onBeforeUnmount(() => clearTimeout(timer))
|
|
160
|
+
|
|
161
|
+
const sizeClass = computed(
|
|
162
|
+
() => ({ sm: 'text-title-large', md: 'text-display-small', lg: 'text-display-medium' })[props.size],
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
defineExpose({ parts })
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<template>
|
|
169
|
+
<div class="m3-countdown" :data-variant="variant" role="timer" :aria-label="accessibleText">
|
|
170
|
+
<slot v-if="parts.finished && $slots.finished" name="finished" />
|
|
171
|
+
<slot v-else-if="$slots.default" v-bind="parts" />
|
|
172
|
+
<div v-else-if="variant === 'boxes'" class="flex items-start gap-2" aria-hidden="true">
|
|
173
|
+
<div v-for="(u, i) in visible" :key="u" class="flex flex-col items-center gap-1">
|
|
174
|
+
<div
|
|
175
|
+
class="flex min-w-[2ch] items-center justify-center rounded-md bg-surface-container-high px-3 py-2 tabular-nums text-on-surface"
|
|
176
|
+
:class="sizeClass"
|
|
177
|
+
>
|
|
178
|
+
<MAnimatedNumber :value="parts[u]" :format="digitFormat(i)" :animate="animate" />
|
|
179
|
+
</div>
|
|
180
|
+
<span v-if="labels" class="text-label-medium text-on-surface-variant">{{ unitLabel(u, parts[u], 'long') }}</span>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
<span v-else class="inline-flex items-baseline gap-1.5 tabular-nums text-on-surface" :class="sizeClass" aria-hidden="true">
|
|
184
|
+
<span v-for="(u, i) in visible" :key="u" class="inline-flex items-baseline">
|
|
185
|
+
<MAnimatedNumber :value="parts[u]" :format="digitFormat(i)" :animate="animate" />
|
|
186
|
+
<span v-if="labels" class="text-on-surface-variant">{{ unitLabel(u, parts[u], 'narrow') }}</span>
|
|
187
|
+
<span v-else-if="i < visible.length - 1" class="text-on-surface-variant">:</span>
|
|
188
|
+
</span>
|
|
189
|
+
</span>
|
|
190
|
+
</div>
|
|
191
|
+
</template>
|
|
192
|
+
|
|
193
|
+
<style>
|
|
194
|
+
/* Defaults in the base layer so the consumer's classes on the root win (see MShape). */
|
|
195
|
+
@layer base {
|
|
196
|
+
.m3-countdown {
|
|
197
|
+
display: inline-block;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
</style>
|