@m3ui-vue/m3ui-vue 1.3.8 → 1.4.0

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 (111) hide show
  1. package/dist/API.md +1058 -18
  2. package/dist/{MButton-D5eJiDza.js → MButton-DQMTIlaV.js} +2 -2
  3. package/dist/{MButton-D5eJiDza.js.map → MButton-DQMTIlaV.js.map} +1 -1
  4. package/dist/{MDialog-WqB0jewp.js → MDialog-cdgapGfZ.js} +2 -2
  5. package/dist/{MDialog-WqB0jewp.js.map → MDialog-cdgapGfZ.js.map} +1 -1
  6. package/dist/{MListItem-Cf-C2Ru-.js → MListItem-ZkSGIIrb.js} +2 -2
  7. package/dist/{MListItem-Cf-C2Ru-.js.map → MListItem-ZkSGIIrb.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-D4GzEZoH.js → MLoadingIndicator-U6_oGx8z.js} +2 -2
  9. package/dist/{MLoadingIndicator-D4GzEZoH.js.map → MLoadingIndicator-U6_oGx8z.js.map} +1 -1
  10. package/dist/{MSeekBar-B19xoWE3.js → MSeekBar-DTZVizZg.js} +2 -2
  11. package/dist/{MSeekBar-B19xoWE3.js.map → MSeekBar-DTZVizZg.js.map} +1 -1
  12. package/dist/{MSlider-9RoiuebS.js → MSlider-CqJkEYRZ.js} +2 -2
  13. package/dist/{MSlider-9RoiuebS.js.map → MSlider-CqJkEYRZ.js.map} +1 -1
  14. package/dist/{MSpinner-BNF8MN-L.js → MSpinner-Btgc-0nb.js} +2 -2
  15. package/dist/{MSpinner-BNF8MN-L.js.map → MSpinner-Btgc-0nb.js.map} +1 -1
  16. package/dist/{MTextField-CuG0T3qh.js → MTextField-B6M0gJEO.js} +2 -2
  17. package/dist/{MTextField-CuG0T3qh.js.map → MTextField-B6M0gJEO.js.map} +1 -1
  18. package/dist/{MTooltip-Bv7yxngk.js → MTooltip-Dspji4XG.js} +4 -4
  19. package/dist/{MTooltip-Bv7yxngk.js.map → MTooltip-Dspji4XG.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MAudioPlayer.vue.d.ts +2 -2
  23. package/dist/components/MAvailabilityCalendar.vue.d.ts +83 -0
  24. package/dist/components/MBeforeAfter.vue.d.ts +61 -0
  25. package/dist/components/MBodyMap.vue.d.ts +70 -0
  26. package/dist/components/MCandlestickChart.vue.d.ts +82 -0
  27. package/dist/components/MCertificate.vue.d.ts +76 -0
  28. package/dist/components/MCreditCardInput.vue.d.ts +75 -0
  29. package/dist/components/MMortgageCalculator.vue.d.ts +83 -0
  30. package/dist/components/MOdontogram.vue.d.ts +86 -0
  31. package/dist/components/MOrderBook.vue.d.ts +89 -0
  32. package/dist/components/MOrderTicket.vue.d.ts +91 -0
  33. package/dist/components/MPosKeypad.vue.d.ts +84 -0
  34. package/dist/components/MProductConfigurator.vue.d.ts +136 -0
  35. package/dist/components/MQuiz.vue.d.ts +102 -0
  36. package/dist/components/MReceipt.vue.d.ts +93 -0
  37. package/dist/components/MSeatMap.vue.d.ts +131 -0
  38. package/dist/components/MSeekBar.vue.d.ts +1 -1
  39. package/dist/components/MTicket.vue.d.ts +83 -0
  40. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  41. package/dist/components/MVitalsChart.vue.d.ts +73 -0
  42. package/dist/composables/_printElement.d.ts +9 -0
  43. package/dist/composables/cardBrand.d.ts +25 -0
  44. package/dist/composables/mortgage.d.ts +37 -0
  45. package/dist/composables/useLocale.d.ts +131 -0
  46. package/dist/draw.js +2 -2
  47. package/dist/flow.js +1 -1
  48. package/dist/gantt.js +1 -1
  49. package/dist/index.d.ts +35 -0
  50. package/dist/locales/index.js +924 -7
  51. package/dist/locales/index.js.map +1 -1
  52. package/dist/m3ui-vue.css +1 -1
  53. package/dist/m3ui.js +8264 -3553
  54. package/dist/m3ui.js.map +1 -1
  55. package/dist/map.js +5 -5
  56. package/dist/media.js +4 -4
  57. package/dist/pdf.js +4 -4
  58. package/dist/rich-text-editor.js +4 -4
  59. package/dist/styles.css +1 -1
  60. package/dist/{useLocale-D2ucaY-l.js → useLocale-DLKJIRFi.js} +133 -2
  61. package/dist/useLocale-DLKJIRFi.js.map +1 -0
  62. package/package.json +1 -1
  63. package/src/__tests__/MAvailabilityCalendar.test.ts +85 -0
  64. package/src/__tests__/MBeforeAfter.test.ts +79 -0
  65. package/src/__tests__/MBodyMap.test.ts +60 -0
  66. package/src/__tests__/MCandlestickChart.test.ts +66 -0
  67. package/src/__tests__/MCertificate.test.ts +32 -0
  68. package/src/__tests__/MCreditCardInput.test.ts +122 -0
  69. package/src/__tests__/MMortgageCalculator.test.ts +49 -0
  70. package/src/__tests__/MOdontogram.test.ts +93 -0
  71. package/src/__tests__/MOrderBook.test.ts +66 -0
  72. package/src/__tests__/MOrderTicket.test.ts +68 -0
  73. package/src/__tests__/MPosKeypad.test.ts +116 -0
  74. package/src/__tests__/MProductConfigurator.test.ts +73 -0
  75. package/src/__tests__/MQuiz.test.ts +104 -0
  76. package/src/__tests__/MReceipt.test.ts +52 -0
  77. package/src/__tests__/MSeatMap.test.ts +76 -0
  78. package/src/__tests__/MTicket.test.ts +38 -0
  79. package/src/__tests__/MVitalsChart.test.ts +49 -0
  80. package/src/__tests__/mortgage.test.ts +25 -0
  81. package/src/__tests__/ssr.test.ts +11 -0
  82. package/src/components/MAvailabilityCalendar.vue +460 -0
  83. package/src/components/MBeforeAfter.vue +248 -0
  84. package/src/components/MBodyMap.vue +266 -0
  85. package/src/components/MCandlestickChart.vue +479 -0
  86. package/src/components/MCertificate.vue +351 -0
  87. package/src/components/MCreditCardInput.vue +351 -0
  88. package/src/components/MMortgageCalculator.vue +258 -0
  89. package/src/components/MOdontogram.vue +462 -0
  90. package/src/components/MOrderBook.vue +287 -0
  91. package/src/components/MOrderTicket.vue +217 -0
  92. package/src/components/MPosKeypad.vue +406 -0
  93. package/src/components/MProductConfigurator.vue +412 -0
  94. package/src/components/MQuiz.vue +531 -0
  95. package/src/components/MReceipt.vue +249 -0
  96. package/src/components/MSeatMap.vue +431 -0
  97. package/src/components/MTicket.vue +209 -0
  98. package/src/components/MVitalsChart.vue +303 -0
  99. package/src/composables/_printElement.ts +36 -0
  100. package/src/composables/cardBrand.ts +104 -0
  101. package/src/composables/mortgage.ts +70 -0
  102. package/src/composables/useLocale.ts +277 -0
  103. package/src/index.ts +35 -0
  104. package/src/locales/de.ts +131 -0
  105. package/src/locales/es.ts +131 -0
  106. package/src/locales/fr.ts +131 -0
  107. package/src/locales/ja.ts +131 -0
  108. package/src/locales/ko.ts +131 -0
  109. package/src/locales/pt.ts +131 -0
  110. package/src/locales/zh.ts +131 -0
  111. package/dist/useLocale-D2ucaY-l.js.map +0 -1
@@ -0,0 +1,258 @@
1
+ <script lang="ts">
2
+ /** The inputs of an `MMortgageCalculator` (its v-model). */
3
+ export interface MortgageInput {
4
+ /** Price of the property */
5
+ price: number
6
+ /** Down payment, in money (not percent) */
7
+ down: number
8
+ /** Yearly interest rate, in percent */
9
+ rate: number
10
+ /** Term in years */
11
+ years: number
12
+ }
13
+ </script>
14
+
15
+ <script setup lang="ts">
16
+ /**
17
+ * A mortgage / loan calculator for a property listing or a bank: price, down payment, rate and term in, the monthly
18
+ * payment, the principal vs interest split and the yearly amortization schedule out. Supports the french system
19
+ * (the same payment every month) and the german one (the same principal every month, falling payments). The math
20
+ * is also exported on its own as `amortize()`.
21
+ *
22
+ * @slot summary Replaces the result panel. Slot props: `{ loan, monthly, schedule }`
23
+ * @event update:modelValue The inputs — powers v-model
24
+ */
25
+ import { computed, ref } from 'vue'
26
+ import MNumberField from './MNumberField.vue'
27
+ import MSlider from './MSlider.vue'
28
+ import MButton from './MButton.vue'
29
+ import { amortize } from '../composables/mortgage'
30
+ import { useLocale } from '../composables/useLocale'
31
+ import { vRipple } from '../directives/vRipple'
32
+
33
+ const locale = useLocale()
34
+
35
+ const props = withDefaults(
36
+ defineProps<{
37
+ /** The inputs (v-model) */
38
+ modelValue: MortgageInput
39
+ /** `french`: fixed payment. `german`: fixed principal, payments fall over time */
40
+ system?: 'french' | 'german'
41
+ /** Terms offered, in years */
42
+ terms?: number[]
43
+ /** Monthly costs added on top of the loan payment, e.g. property tax or insurance */
44
+ extras?: { label: string; amount: number }[]
45
+ /** ISO 4217 code to format amounts */
46
+ currency?: string
47
+ /** Fields layout: the default filled or outlined */
48
+ variant?: 'filled' | 'outlined'
49
+ /** Hides the inputs, showing only the results (for a read-only quote) */
50
+ readonly?: boolean
51
+ /** Shows the yearly schedule open */
52
+ scheduleOpen?: boolean
53
+ }>(),
54
+ {
55
+ system: 'french',
56
+ terms: () => [10, 15, 20, 25, 30],
57
+ extras: () => [],
58
+ variant: 'outlined',
59
+ readonly: false,
60
+ scheduleOpen: false,
61
+ },
62
+ )
63
+
64
+ const emit = defineEmits<{ 'update:modelValue': [MortgageInput] }>()
65
+
66
+ function update(patch: Partial<MortgageInput>) {
67
+ emit('update:modelValue', { ...props.modelValue, ...patch })
68
+ }
69
+
70
+ const loan = computed(() => Math.max(0, props.modelValue.price - props.modelValue.down))
71
+ const downPercent = computed(() => (props.modelValue.price > 0 ? (props.modelValue.down / props.modelValue.price) * 100 : 0))
72
+
73
+ const schedule = computed(() =>
74
+ amortize({ principal: loan.value, rate: props.modelValue.rate, years: props.modelValue.years, system: props.system }),
75
+ )
76
+ const extrasTotal = computed(() => props.extras.reduce((s, e) => s + e.amount, 0))
77
+ const monthly = computed(() => schedule.value.firstPayment + extrasTotal.value)
78
+
79
+ /** The schedule folded by year */
80
+ const years = computed(() => {
81
+ const out: { year: number; principal: number; interest: number; balance: number }[] = []
82
+ for (const p of schedule.value.payments) {
83
+ const y = Math.ceil(p.n / 12)
84
+ const row = out[y - 1] ?? (out[y - 1] = { year: y, principal: 0, interest: 0, balance: 0 })
85
+ row.principal += p.principal
86
+ row.interest += p.interest
87
+ row.balance = p.balance
88
+ }
89
+ return out
90
+ })
91
+
92
+ const fmt = computed(() =>
93
+ new Intl.NumberFormat(locale.lang, props.currency ? { style: 'currency', currency: props.currency, maximumFractionDigits: 0 } : { maximumFractionDigits: 0 }),
94
+ )
95
+ const fmtCents = computed(() =>
96
+ new Intl.NumberFormat(locale.lang, props.currency ? { style: 'currency', currency: props.currency } : { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
97
+ )
98
+
99
+ // Donut: principal vs interest of everything paid
100
+ const interestShare = computed(() => {
101
+ const t = schedule.value.totalPaid
102
+ return t > 0 ? schedule.value.totalInterest / t : 0
103
+ })
104
+ const R = 52
105
+ const C = 2 * Math.PI * R
106
+
107
+ const showSchedule = ref(props.scheduleOpen)
108
+
109
+ defineExpose({ loan, monthly, schedule })
110
+ </script>
111
+
112
+ <template>
113
+ <div class="m3-mortgage @container text-on-surface">
114
+ <div class="grid gap-6 @2xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
115
+ <div v-if="!readonly" class="flex flex-col gap-4">
116
+ <MNumberField
117
+ :model-value="modelValue.price"
118
+ :label="locale.mortgagePrice"
119
+ :variant="variant"
120
+ :min="0"
121
+ :step="1000"
122
+ leading-icon="home"
123
+ data-field="price"
124
+ @update:model-value="(v) => update({ price: v ?? 0, down: Math.min(modelValue.down, v ?? 0) })"
125
+ />
126
+ <div class="flex flex-col gap-1">
127
+ <MNumberField
128
+ :model-value="modelValue.down"
129
+ :label="locale.mortgageDown"
130
+ :variant="variant"
131
+ :min="0"
132
+ :max="modelValue.price"
133
+ :step="1000"
134
+ :hint="`${downPercent.toFixed(1)}%`"
135
+ leading-icon="savings"
136
+ data-field="down"
137
+ @update:model-value="(v) => update({ down: Math.min(v ?? 0, modelValue.price) })"
138
+ />
139
+ <MSlider
140
+ :model-value="Math.round(downPercent)"
141
+ :min="0"
142
+ :max="100"
143
+ :step="1"
144
+ size="xs"
145
+ :aria-label="locale.mortgageDown"
146
+ @update:model-value="(v) => update({ down: Math.round((modelValue.price * (v as number)) / 100) })"
147
+ />
148
+ </div>
149
+ <MNumberField
150
+ :model-value="modelValue.rate"
151
+ :label="locale.mortgageRate"
152
+ :variant="variant"
153
+ :min="0"
154
+ :max="100"
155
+ :step="0.05"
156
+ leading-icon="percent"
157
+ data-field="rate"
158
+ @update:model-value="(v) => update({ rate: v ?? 0 })"
159
+ />
160
+ <div>
161
+ <p class="mb-2 text-label-large text-on-surface-variant">{{ locale.mortgageTerm }}</p>
162
+ <div class="flex flex-wrap gap-2" role="radiogroup" :aria-label="locale.mortgageTerm">
163
+ <button
164
+ v-for="t in terms"
165
+ :key="t"
166
+ v-ripple
167
+ type="button"
168
+ role="radio"
169
+ :aria-checked="modelValue.years === t"
170
+ class="relative flex h-9 items-center gap-1 overflow-hidden rounded-sm border px-3 text-label-large transition-colors"
171
+ :class="modelValue.years === t
172
+ ? 'border-transparent bg-secondary-container text-on-secondary-container'
173
+ : 'border-outline-variant text-on-surface-variant'"
174
+ :data-term="t"
175
+ @click="update({ years: t })"
176
+ >
177
+ {{ locale.mortgageYears.replace('{n}', String(t)) }}
178
+ </button>
179
+ </div>
180
+ </div>
181
+ </div>
182
+
183
+ <div class="flex flex-col gap-4 rounded-lg bg-surface-container p-5">
184
+ <slot name="summary" :loan="loan" :monthly="monthly" :schedule="schedule">
185
+ <div>
186
+ <p class="text-label-large text-on-surface-variant">
187
+ {{ system === 'german' ? locale.mortgageFirstPayment : locale.mortgageMonthly }}
188
+ </p>
189
+ <p class="text-display-small font-medium tabular-nums text-primary" data-monthly>{{ fmtCents.format(monthly) }}</p>
190
+ <p v-if="extras.length" class="text-body-medium text-on-surface-variant tabular-nums" data-extras>
191
+ {{ fmtCents.format(schedule.firstPayment) }}<template v-for="e in extras" :key="e.label"> + {{ e.label }} {{ fmtCents.format(e.amount) }}</template>
192
+ </p>
193
+ <p v-if="system === 'german' && schedule.payments.length" class="text-body-medium text-on-surface-variant tabular-nums">
194
+ {{ locale.mortgageLastPayment }}: {{ fmtCents.format(schedule.lastPayment + extrasTotal) }}
195
+ </p>
196
+ </div>
197
+
198
+ <div class="flex items-center gap-5">
199
+ <svg viewBox="0 0 128 128" class="h-28 w-28 shrink-0 -rotate-90" aria-hidden="true">
200
+ <circle cx="64" cy="64" :r="R" fill="none" stroke="var(--color-primary)" stroke-width="16" />
201
+ <circle
202
+ cx="64"
203
+ cy="64"
204
+ :r="R"
205
+ fill="none"
206
+ stroke="var(--color-tertiary)"
207
+ stroke-width="16"
208
+ :stroke-dasharray="`${interestShare * C} ${C}`"
209
+ class="transition-[stroke-dasharray] duration-300"
210
+ />
211
+ </svg>
212
+ <dl class="grid flex-1 grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1 text-body-medium">
213
+ <dt class="flex items-center gap-2"><span class="h-3 w-3 rounded-full bg-primary" />{{ locale.mortgageLoan }}</dt>
214
+ <dd class="text-end tabular-nums" data-loan>{{ fmt.format(loan) }}</dd>
215
+ <dt class="flex items-center gap-2"><span class="h-3 w-3 rounded-full bg-tertiary" />{{ locale.mortgageInterest }}</dt>
216
+ <dd class="text-end tabular-nums" data-interest>{{ fmt.format(schedule.totalInterest) }}</dd>
217
+ <dt class="mt-1 border-t border-outline-variant pt-1 font-medium">{{ locale.mortgageTotal }}</dt>
218
+ <dd class="mt-1 border-t border-outline-variant pt-1 text-end font-medium tabular-nums">{{ fmt.format(schedule.totalPaid) }}</dd>
219
+ </dl>
220
+ </div>
221
+ </slot>
222
+ </div>
223
+ </div>
224
+
225
+ <div v-if="years.length" class="mt-4">
226
+ <MButton variant="text" :icon="showSchedule ? 'expand_less' : 'expand_more'" :aria-expanded="showSchedule" data-toggle-schedule @click="showSchedule = !showSchedule">
227
+ {{ locale.mortgageSchedule }}
228
+ </MButton>
229
+ <div v-if="showSchedule" class="mt-2 max-h-80 overflow-auto rounded-md border border-outline-variant">
230
+ <table class="w-full text-body-medium tabular-nums" data-schedule>
231
+ <thead class="sticky top-0 bg-surface-container-high text-label-large text-on-surface-variant">
232
+ <tr>
233
+ <th class="px-3 py-2 text-start font-medium">{{ locale.mortgageYear }}</th>
234
+ <th class="px-3 py-2 text-end font-medium">{{ locale.mortgagePrincipal }}</th>
235
+ <th class="px-3 py-2 text-end font-medium">{{ locale.mortgageInterest }}</th>
236
+ <th class="px-3 py-2 text-end font-medium">{{ locale.mortgageBalance }}</th>
237
+ </tr>
238
+ </thead>
239
+ <tbody>
240
+ <tr v-for="y in years" :key="y.year" class="border-t border-outline-variant">
241
+ <td class="px-3 py-1.5">{{ y.year }}</td>
242
+ <td class="px-3 py-1.5 text-end">{{ fmt.format(y.principal) }}</td>
243
+ <td class="px-3 py-1.5 text-end">{{ fmt.format(y.interest) }}</td>
244
+ <td class="px-3 py-1.5 text-end">
245
+ <div class="flex items-center justify-end gap-2">
246
+ <span class="hidden h-1.5 w-16 overflow-hidden rounded-full bg-surface-container-highest sm:block">
247
+ <span class="block h-full bg-primary" :style="{ width: `${loan ? (y.balance / loan) * 100 : 0}%` }" />
248
+ </span>
249
+ {{ fmt.format(y.balance) }}
250
+ </div>
251
+ </td>
252
+ </tr>
253
+ </tbody>
254
+ </table>
255
+ </div>
256
+ </div>
257
+ </div>
258
+ </template>