@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,209 @@
1
+ <script lang="ts">
2
+ /** One end of a trip in an `MTicket`: an airport, a station, a terminal. */
3
+ export interface TicketStop {
4
+ /** Short code shown big, e.g. "EZE" or "RET" */
5
+ code: string
6
+ /** City or station name under the code */
7
+ name?: string
8
+ /** Departure / arrival time, shown under the name */
9
+ time?: string
10
+ }
11
+
12
+ /** A label/value pair on an `MTicket`, e.g. `{ label: 'Gate', value: 'B12' }`. */
13
+ export interface TicketField {
14
+ label: string
15
+ value: string | number
16
+ /** Emphasizes the value (e.g. the seat or the gate) */
17
+ strong?: boolean
18
+ }
19
+ </script>
20
+
21
+ <script setup lang="ts">
22
+ /**
23
+ * A ticket with a tear-off stub: a boarding pass, a bus or train ticket, a concert or cinema entry, a coupon. The
24
+ * stub is separated by a perforated line with two notches cut out, and usually holds the code to scan (put an
25
+ * `MQRCode` or `MBarcode` in the `stub` slot). Trips get a from → to route; any ticket gets a grid of fields.
26
+ *
27
+ * @slot header Replaces the title row in the colored band (e.g. an airline logo and a status chip)
28
+ * @slot default Content of the main part, under the route and fields
29
+ * @slot stub Content of the stub: a QR, a barcode, a number
30
+ */
31
+ import { computed } from 'vue'
32
+ import MIcon from './MIcon.vue'
33
+
34
+ const ROLES = ['primary', 'secondary', 'tertiary', 'error', 'success']
35
+
36
+ const props = withDefaults(
37
+ defineProps<{
38
+ /** Title in the colored band, e.g. the airline, the event or the movie */
39
+ title?: string
40
+ /** A line under the title, e.g. the venue or the date */
41
+ subtitle?: string
42
+ /** Material Symbol before the title */
43
+ icon?: string
44
+ /** Band color: a role (primary, secondary, tertiary, error, success) or any CSS color */
45
+ color?: string
46
+ /** Where the trip starts */
47
+ from?: TicketStop
48
+ /** Where the trip ends */
49
+ to?: TicketStop
50
+ /** Material Symbol between from and to */
51
+ transport?: string
52
+ /** Label/value pairs in a grid */
53
+ fields?: TicketField[]
54
+ /** Stub beside the main part (an event ticket) or under it (a phone boarding pass) */
55
+ orientation?: 'horizontal' | 'vertical'
56
+ /** Width of the stub in horizontal orientation (any CSS length) */
57
+ stubSize?: string
58
+ /** Radius of the notches cut at the perforation, in px */
59
+ notch?: number
60
+ }>(),
61
+ {
62
+ color: 'primary',
63
+ transport: 'flight',
64
+ fields: () => [],
65
+ orientation: 'horizontal',
66
+ stubSize: '10rem',
67
+ notch: 12,
68
+ },
69
+ )
70
+
71
+ const band = computed(() =>
72
+ ROLES.includes(props.color)
73
+ ? { background: `var(--color-${props.color})`, color: `var(--color-on-${props.color})` }
74
+ : { background: props.color, color: '#fff' },
75
+ )
76
+
77
+ const vertical = computed(() => props.orientation === 'vertical')
78
+ </script>
79
+
80
+ <template>
81
+ <div
82
+ class="m3-ticket flex text-on-surface"
83
+ :class="vertical ? 'flex-col' : 'flex-row'"
84
+ :style="{ '--m3-ticket-notch': `${notch}px`, '--m3-ticket-stub': stubSize }"
85
+ :data-orientation="orientation"
86
+ >
87
+ <div class="m3-ticket__main flex min-w-0 flex-1 flex-col overflow-hidden bg-surface-container-lowest">
88
+ <div class="flex items-center gap-3 px-5 py-3" :style="band">
89
+ <slot name="header">
90
+ <MIcon v-if="icon" :name="icon" :size="24" />
91
+ <div class="min-w-0 flex-1">
92
+ <div v-if="title" class="truncate text-title-medium font-medium">{{ title }}</div>
93
+ <div v-if="subtitle" class="truncate text-body-medium opacity-80">{{ subtitle }}</div>
94
+ </div>
95
+ </slot>
96
+ </div>
97
+
98
+ <div class="flex flex-1 flex-col gap-4 px-5 py-4">
99
+ <div v-if="from || to" class="flex items-start gap-3" data-route>
100
+ <div v-if="from" class="min-w-0">
101
+ <div class="text-display-small font-medium leading-none tracking-tight">{{ from.code }}</div>
102
+ <div v-if="from.name" class="mt-1 truncate text-body-medium text-on-surface-variant">{{ from.name }}</div>
103
+ <div v-if="from.time" class="text-title-medium tabular-nums">{{ from.time }}</div>
104
+ </div>
105
+ <div class="flex flex-1 items-center gap-1 pt-3 text-on-surface-variant" aria-hidden="true">
106
+ <span class="h-0 flex-1 border-t-2 border-dotted border-outline-variant" />
107
+ <MIcon :name="transport" :size="24" :class="transport === 'flight' ? 'rotate-90' : ''" class="text-primary" />
108
+ <span class="h-0 flex-1 border-t-2 border-dotted border-outline-variant" />
109
+ </div>
110
+ <div v-if="to" class="min-w-0 text-end">
111
+ <div class="text-display-small font-medium leading-none tracking-tight">{{ to.code }}</div>
112
+ <div v-if="to.name" class="mt-1 truncate text-body-medium text-on-surface-variant">{{ to.name }}</div>
113
+ <div v-if="to.time" class="text-title-medium tabular-nums">{{ to.time }}</div>
114
+ </div>
115
+ </div>
116
+
117
+ <dl v-if="fields.length" class="grid grid-cols-[repeat(auto-fill,minmax(5.5rem,1fr))] gap-x-4 gap-y-3">
118
+ <div v-for="f in fields" :key="f.label" class="min-w-0">
119
+ <dt class="truncate text-label-medium uppercase tracking-wide text-on-surface-variant">{{ f.label }}</dt>
120
+ <dd class="truncate" :class="f.strong ? 'text-title-large font-medium text-primary' : 'text-title-medium'">{{ f.value }}</dd>
121
+ </div>
122
+ </dl>
123
+
124
+ <slot />
125
+ </div>
126
+ </div>
127
+
128
+ <div
129
+ v-if="$slots.stub"
130
+ class="m3-ticket__stub relative flex shrink-0 flex-col items-center justify-center gap-2 bg-surface-container-lowest p-4"
131
+ >
132
+ <span class="m3-ticket__perforation" aria-hidden="true" />
133
+ <slot name="stub" />
134
+ </div>
135
+ </div>
136
+ </template>
137
+
138
+ <style>
139
+ .m3-ticket {
140
+ filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.15)) drop-shadow(0 1px 3px rgb(0 0 0 / 0.1));
141
+ }
142
+ .m3-ticket__main,
143
+ .m3-ticket__stub {
144
+ --r: var(--m3-ticket-notch);
145
+ }
146
+ /* Each half cuts its own two corners at the perforation, so the notches line up whatever the content size */
147
+ .m3-ticket[data-orientation='horizontal'] .m3-ticket__main {
148
+ border-radius: var(--radius-lg, 16px) 0 0 var(--radius-lg, 16px);
149
+ }
150
+ .m3-ticket[data-orientation='horizontal'] .m3-ticket__stub {
151
+ width: var(--m3-ticket-stub);
152
+ border-radius: 0 var(--radius-lg, 16px) var(--radius-lg, 16px) 0;
153
+ -webkit-mask:
154
+ radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) top / 100% 51% no-repeat,
155
+ radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
156
+ mask:
157
+ radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) top / 100% 51% no-repeat,
158
+ radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
159
+ }
160
+ .m3-ticket[data-orientation='horizontal']:has(.m3-ticket__stub) .m3-ticket__main {
161
+ -webkit-mask:
162
+ radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) top / 100% 51% no-repeat,
163
+ radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
164
+ mask:
165
+ radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) top / 100% 51% no-repeat,
166
+ radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
167
+ }
168
+ .m3-ticket[data-orientation='vertical'] .m3-ticket__main {
169
+ border-radius: var(--radius-lg, 16px) var(--radius-lg, 16px) 0 0;
170
+ }
171
+ .m3-ticket[data-orientation='vertical'] .m3-ticket__stub {
172
+ border-radius: 0 0 var(--radius-lg, 16px) var(--radius-lg, 16px);
173
+ -webkit-mask:
174
+ radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) left / 51% 100% no-repeat,
175
+ radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) right / 51% 100% no-repeat;
176
+ mask:
177
+ radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) left / 51% 100% no-repeat,
178
+ radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) right / 51% 100% no-repeat;
179
+ }
180
+ .m3-ticket[data-orientation='vertical']:has(.m3-ticket__stub) .m3-ticket__main {
181
+ -webkit-mask:
182
+ radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) left / 51% 100% no-repeat,
183
+ radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) right / 51% 100% no-repeat;
184
+ mask:
185
+ radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) left / 51% 100% no-repeat,
186
+ radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) right / 51% 100% no-repeat;
187
+ }
188
+ .m3-ticket:not(:has(.m3-ticket__stub)) .m3-ticket__main {
189
+ border-radius: var(--radius-lg, 16px);
190
+ }
191
+ .m3-ticket__perforation {
192
+ position: absolute;
193
+ --dash: color-mix(in srgb, var(--color-on-surface) 30%, transparent);
194
+ }
195
+ .m3-ticket[data-orientation='horizontal'] .m3-ticket__perforation {
196
+ left: 0;
197
+ top: calc(var(--r) + 4px);
198
+ bottom: calc(var(--r) + 4px);
199
+ width: 2px;
200
+ background: repeating-linear-gradient(to bottom, var(--dash) 0 6px, transparent 6px 12px);
201
+ }
202
+ .m3-ticket[data-orientation='vertical'] .m3-ticket__perforation {
203
+ top: 0;
204
+ left: calc(var(--r) + 4px);
205
+ right: calc(var(--r) + 4px);
206
+ height: 2px;
207
+ background: repeating-linear-gradient(to right, var(--dash) 0 6px, transparent 6px 12px);
208
+ }
209
+ </style>
@@ -0,0 +1,303 @@
1
+ <script lang="ts">
2
+ /** One reading of a vital sign. A pair is a range reading such as blood pressure: `[systolic, diastolic]`. */
3
+ export interface VitalReading {
4
+ time: Date | string | number
5
+ value: number | [number, number]
6
+ }
7
+
8
+ /** A vital sign: its readings, unit and normal range. */
9
+ export interface VitalSeries {
10
+ key: string
11
+ label: string
12
+ unit?: string
13
+ /** Line / point color (any CSS color). Defaults to the primary color */
14
+ color?: string
15
+ decimals?: number
16
+ /**
17
+ * Normal range, drawn as a band. For pair readings give one range per value:
18
+ * `[[90, 120], [60, 80]]` for systolic and diastolic
19
+ */
20
+ normal?: [number, number] | [[number, number], [number, number]]
21
+ /** Fixed axis range; by default it fits the readings and the normal band */
22
+ domain?: [number, number]
23
+ data: VitalReading[]
24
+ }
25
+ </script>
26
+
27
+ <script setup lang="ts">
28
+ /**
29
+ * A vitals flowsheet: one row per vital sign (heart rate, blood pressure, SpO₂, temperature, respiratory rate…)
30
+ * over a shared time axis, each with its normal range as a band, readings outside it in the error color, and the
31
+ * latest value (with a High / Low tag) beside the row. Blood pressure and other pair readings are drawn as bars from
32
+ * the lower to the upper value. Hovering (or the arrow keys) moves a crosshair across every row at once.
33
+ *
34
+ * @slot label Replaces a row's label column. Slot props: `{ series, reading, status }`
35
+ * @event hover The time under the crosshair (epoch ms), or null when it leaves
36
+ */
37
+ import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
38
+ import { useLocale } from '../composables/useLocale'
39
+
40
+ const locale = useLocale()
41
+
42
+ const props = withDefaults(
43
+ defineProps<{
44
+ series: VitalSeries[]
45
+ /** Height of each row's plot, in px */
46
+ rowHeight?: number
47
+ /** Start of the time axis (defaults to the first reading) */
48
+ from?: Date | string | number
49
+ /** End of the time axis (defaults to the last reading) */
50
+ to?: Date | string | number
51
+ }>(),
52
+ { rowHeight: 64 },
53
+ )
54
+
55
+ const emit = defineEmits<{ hover: [number | null] }>()
56
+
57
+ const toMs = (t: Date | string | number) => (t instanceof Date ? t.getTime() : typeof t === 'number' ? t : Date.parse(t))
58
+
59
+ const rootEl = ref<HTMLElement | null>(null)
60
+ const width = ref(640)
61
+ let ro: ResizeObserver | null = null
62
+ onMounted(() => {
63
+ if (!rootEl.value) return
64
+ width.value = rootEl.value.clientWidth || 640
65
+ if (typeof ResizeObserver !== 'undefined') {
66
+ ro = new ResizeObserver(([e]) => (width.value = e!.contentRect.width || width.value))
67
+ ro.observe(rootEl.value)
68
+ }
69
+ })
70
+ onBeforeUnmount(() => ro?.disconnect())
71
+
72
+ const narrow = computed(() => width.value < 480)
73
+ const LABEL_W = computed(() => (narrow.value ? 0 : Math.min(150, Math.round(width.value * 0.3))))
74
+ const PAD = 8
75
+ const plotW = computed(() => Math.max(60, width.value - LABEL_W.value - PAD * 2))
76
+
77
+ const sorted = computed(() =>
78
+ props.series.map((s) => ({ ...s, data: [...s.data].sort((a, b) => toMs(a.time) - toMs(b.time)) })),
79
+ )
80
+
81
+ const times = computed(() => {
82
+ const set = new Set<number>()
83
+ for (const s of sorted.value) for (const r of s.data) set.add(toMs(r.time))
84
+ return [...set].sort((a, b) => a - b)
85
+ })
86
+ const t0 = computed(() => (props.from !== undefined ? toMs(props.from) : times.value[0] ?? 0))
87
+ const t1 = computed(() => {
88
+ const end = props.to !== undefined ? toMs(props.to) : times.value.at(-1) ?? 1
89
+ return end === t0.value ? end + 1 : end
90
+ })
91
+ const x = (t: number) => PAD + ((t - t0.value) / (t1.value - t0.value)) * plotW.value
92
+
93
+ const ranges = (s: VitalSeries): [number, number][] => {
94
+ if (!s.normal) return []
95
+ return Array.isArray(s.normal[0]) ? (s.normal as [[number, number], [number, number]]) : [s.normal as [number, number]]
96
+ }
97
+
98
+ function domainOf(s: VitalSeries): [number, number] {
99
+ if (s.domain) return s.domain
100
+ let lo = Infinity
101
+ let hi = -Infinity
102
+ for (const r of s.data) for (const v of Array.isArray(r.value) ? r.value : [r.value]) {
103
+ lo = Math.min(lo, v)
104
+ hi = Math.max(hi, v)
105
+ }
106
+ for (const [a, b] of ranges(s)) {
107
+ lo = Math.min(lo, a)
108
+ hi = Math.max(hi, b)
109
+ }
110
+ if (!isFinite(lo)) return [0, 1]
111
+ const pad = (hi - lo || Math.abs(hi) || 1) * 0.12
112
+ return [lo - pad, hi + pad]
113
+ }
114
+
115
+ function yFor(s: VitalSeries) {
116
+ const [lo, hi] = domainOf(s)
117
+ const h = props.rowHeight
118
+ return (v: number) => 4 + (1 - (v - lo) / (hi - lo)) * (h - 8)
119
+ }
120
+
121
+ /** 'high' | 'low' | 'normal' for a reading against the series' normal range(s) */
122
+ function statusOf(s: VitalSeries, r: VitalReading | undefined): 'high' | 'low' | 'normal' {
123
+ if (!r) return 'normal'
124
+ const rs = ranges(s)
125
+ const vals = Array.isArray(r.value) ? r.value : [r.value]
126
+ let st: 'high' | 'low' | 'normal' = 'normal'
127
+ vals.forEach((v, i) => {
128
+ const range = rs[Math.min(i, rs.length - 1)]
129
+ if (!range) return
130
+ if (v > range[1]) st = 'high'
131
+ else if (v < range[0] && st !== 'high') st = 'low'
132
+ })
133
+ return st
134
+ }
135
+
136
+ function fmt(s: VitalSeries, v: number | [number, number]) {
137
+ const f = new Intl.NumberFormat(locale.lang, { maximumFractionDigits: s.decimals ?? 0, minimumFractionDigits: s.decimals ?? 0 })
138
+ return Array.isArray(v) ? `${f.format(v[0])}/${f.format(v[1])}` : f.format(v)
139
+ }
140
+
141
+ const rows = computed(() =>
142
+ sorted.value.map((s) => {
143
+ const y = yFor(s)
144
+ const color = s.color ?? 'var(--color-primary)'
145
+ const pair = s.data.some((r) => Array.isArray(r.value))
146
+ const bands = ranges(s).map(([a, b]) => ({ y: y(b), h: Math.max(1, y(a) - y(b)) }))
147
+ const lines: string[] = []
148
+ if (pair) {
149
+ for (const k of [0, 1]) lines.push(s.data.map((r, i) => `${i ? 'L' : 'M'}${x(toMs(r.time)).toFixed(1)} ${y((r.value as [number, number])[k]!).toFixed(1)}`).join(''))
150
+ } else {
151
+ lines.push(s.data.map((r, i) => `${i ? 'L' : 'M'}${x(toMs(r.time)).toFixed(1)} ${y(r.value as number).toFixed(1)}`).join(''))
152
+ }
153
+ const points = s.data.map((r) => {
154
+ const t = toMs(r.time)
155
+ const out = statusOf(s, r) !== 'normal'
156
+ return Array.isArray(r.value)
157
+ ? { t, x: x(t), y1: y(r.value[0]), y2: y(r.value[1]), out }
158
+ : { t, x: x(t), y: y(r.value), out }
159
+ })
160
+ return { s, color, bands, lines, points, pair }
161
+ }),
162
+ )
163
+
164
+ // ── crosshair ──
165
+ const hoverT = ref<number | null>(null)
166
+ function readingAt(s: VitalSeries, t: number | null): VitalReading | undefined {
167
+ if (t === null) return s.data.at(-1)
168
+ // the latest reading at or before the hovered time
169
+ let best: VitalReading | undefined
170
+ for (const r of s.data) if (toMs(r.time) <= t) best = r
171
+ return best
172
+ }
173
+ function nearestTime(px: number) {
174
+ const t = t0.value + ((px - PAD) / plotW.value) * (t1.value - t0.value)
175
+ let best = times.value[0] ?? null
176
+ for (const tt of times.value) if (Math.abs(tt - t) < Math.abs((best ?? 0) - t)) best = tt
177
+ return best
178
+ }
179
+ function setHover(t: number | null) {
180
+ if (t !== hoverT.value) emit('hover', t)
181
+ hoverT.value = t
182
+ }
183
+ function onPointerMove(e: PointerEvent) {
184
+ const svg = (e.currentTarget as Element).getBoundingClientRect()
185
+ setHover(nearestTime(e.clientX - svg.left))
186
+ }
187
+ function onKeydown(e: KeyboardEvent) {
188
+ if (!times.value.length) return
189
+ const i = hoverT.value === null ? times.value.length : times.value.indexOf(hoverT.value)
190
+ if (e.key === 'ArrowLeft') setHover(times.value[Math.max(0, i - 1)]!)
191
+ else if (e.key === 'ArrowRight') setHover(times.value[Math.min(times.value.length - 1, i + 1)]!)
192
+ else if (e.key === 'Escape') setHover(null)
193
+ else return
194
+ e.preventDefault()
195
+ }
196
+
197
+ // ── time axis ──
198
+ const spanMs = computed(() => t1.value - t0.value)
199
+ const tickFmt = computed(() =>
200
+ new Intl.DateTimeFormat(locale.lang, spanMs.value <= 2 * 86_400_000 ? { hour: '2-digit', minute: '2-digit' } : { day: 'numeric', month: 'short' }),
201
+ )
202
+ const fullFmt = computed(() => new Intl.DateTimeFormat(locale.lang, { dateStyle: 'medium', timeStyle: 'short' }))
203
+ const ticks = computed(() => {
204
+ const n = Math.max(2, Math.floor(plotW.value / 90))
205
+ return Array.from({ length: n + 1 }, (_, i) => t0.value + (spanMs.value * i) / n)
206
+ })
207
+ </script>
208
+
209
+ <template>
210
+ <div
211
+ ref="rootEl"
212
+ class="m3-vitals text-on-surface outline-none"
213
+ tabindex="0"
214
+ @keydown="onKeydown"
215
+ >
216
+ <p v-if="!times.length" class="py-6 text-center text-body-medium text-on-surface-variant">{{ locale.vitalsNoData }}</p>
217
+ <template v-else>
218
+ <div
219
+ v-for="row in rows"
220
+ :key="row.s.key"
221
+ class="flex border-b border-outline-variant"
222
+ :class="narrow ? 'flex-col pt-2' : 'items-center'"
223
+ :data-vital="row.s.key"
224
+ >
225
+ <div class="shrink-0 pe-2" :style="narrow ? undefined : { width: `${LABEL_W}px` }">
226
+ <slot name="label" :series="row.s" :reading="readingAt(row.s, hoverT)" :status="statusOf(row.s, readingAt(row.s, hoverT))">
227
+ <div class="flex items-baseline gap-2" :class="narrow ? '' : 'flex-col gap-0'">
228
+ <span class="text-label-large text-on-surface-variant">{{ row.s.label }}</span>
229
+ <span v-if="readingAt(row.s, hoverT)" class="flex items-baseline gap-1">
230
+ <span
231
+ class="text-title-large font-medium tabular-nums"
232
+ :class="statusOf(row.s, readingAt(row.s, hoverT)) !== 'normal' ? 'text-error' : ''"
233
+ data-value
234
+ >{{ fmt(row.s, readingAt(row.s, hoverT)!.value) }}</span>
235
+ <span v-if="row.s.unit" class="text-body-small text-on-surface-variant">{{ row.s.unit }}</span>
236
+ <span
237
+ v-if="statusOf(row.s, readingAt(row.s, hoverT)) !== 'normal'"
238
+ class="rounded-xs bg-error-container px-1 text-label-small font-medium text-on-error-container"
239
+ data-status
240
+ >{{ statusOf(row.s, readingAt(row.s, hoverT)) === 'high' ? locale.vitalsHigh : locale.vitalsLow }}</span>
241
+ </span>
242
+ </div>
243
+ </slot>
244
+ </div>
245
+ <svg
246
+ :width="plotW + PAD * 2"
247
+ :height="rowHeight"
248
+ class="block shrink-0 touch-pan-y"
249
+ aria-hidden="true"
250
+ @pointermove="onPointerMove"
251
+ @pointerdown="onPointerMove"
252
+ @pointerleave="(e) => e.pointerType === 'mouse' && setHover(null)"
253
+ >
254
+ <rect v-for="(b, i) in row.bands" :key="i" :x="PAD" :y="b.y" :width="plotW" :height="b.h" class="fill-success" fill-opacity="0.12" data-band />
255
+ <path v-for="(d, i) in row.lines" :key="i" :d="d" fill="none" :stroke="row.color" stroke-width="1.5" :stroke-opacity="row.pair ? 0.5 : 1" />
256
+ <template v-for="p in row.points" :key="p.t">
257
+ <g v-if="'y1' in p">
258
+ <line :x1="p.x" :x2="p.x" :y1="p.y1" :y2="p.y2" :stroke="p.out ? 'var(--color-error)' : row.color" stroke-width="3" stroke-linecap="round" />
259
+ <line :x1="p.x - 4" :x2="p.x + 4" :y1="p.y1" :y2="p.y1" :stroke="p.out ? 'var(--color-error)' : row.color" stroke-width="2" />
260
+ <line :x1="p.x - 4" :x2="p.x + 4" :y1="p.y2" :y2="p.y2" :stroke="p.out ? 'var(--color-error)' : row.color" stroke-width="2" />
261
+ </g>
262
+ <circle
263
+ v-else
264
+ :cx="p.x"
265
+ :cy="p.y"
266
+ :r="p.t === hoverT ? 5 : 3.5"
267
+ :fill="p.out ? 'var(--color-error)' : row.color"
268
+ class="stroke-surface"
269
+ stroke-width="1.5"
270
+ :data-out="p.out || undefined"
271
+ />
272
+ </template>
273
+ <line v-if="hoverT !== null" :x1="x(hoverT)" :x2="x(hoverT)" y1="0" :y2="rowHeight" class="stroke-on-surface-variant" stroke-dasharray="3 3" />
274
+ </svg>
275
+ </div>
276
+
277
+ <div class="flex" :style="narrow ? undefined : { paddingInlineStart: `${LABEL_W}px` }">
278
+ <svg :width="plotW + PAD * 2" height="22" class="block" aria-hidden="true">
279
+ <text
280
+ v-for="(t, i) in ticks"
281
+ :key="t"
282
+ :x="x(t)"
283
+ y="15"
284
+ :text-anchor="i === 0 ? 'start' : i === ticks.length - 1 ? 'end' : 'middle'"
285
+ class="fill-on-surface-variant text-[11px]"
286
+ >{{ tickFmt.format(t) }}</text>
287
+ </svg>
288
+ </div>
289
+ <p class="mt-1 flex min-h-5 items-center gap-3 text-body-small text-on-surface-variant">
290
+ <span class="flex items-center gap-1"><span class="h-2.5 w-4 rounded-[2px] bg-success/20" />{{ locale.vitalsNormal }}</span>
291
+ <span v-if="hoverT !== null" class="ms-auto tabular-nums" data-hover-time>{{ fullFmt.format(hoverT) }}</span>
292
+ </p>
293
+ </template>
294
+ </div>
295
+ </template>
296
+
297
+ <style>
298
+ .m3-vitals:focus-visible {
299
+ outline: 3px solid var(--color-secondary);
300
+ outline-offset: 2px;
301
+ border-radius: 4px;
302
+ }
303
+ </style>
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Prints one element on its own: copies it with the page's stylesheets into a hidden iframe and prints that frame,
3
+ * so the rest of the page (navigation, other content) never reaches the paper. Always prints the light theme.
4
+ * Internal: used by MReceipt and MCertificate.
5
+ */
6
+ export function printElement(el: HTMLElement, { page, css = '' }: { page: string; css?: string }) {
7
+ if (typeof document === 'undefined') return
8
+ const frame = document.createElement('iframe')
9
+ frame.setAttribute('aria-hidden', 'true')
10
+ frame.style.cssText = 'position:fixed;right:0;bottom:0;width:0;height:0;border:0;visibility:hidden'
11
+ document.body.appendChild(frame)
12
+ const doc = frame.contentDocument
13
+ const win = frame.contentWindow
14
+ if (!doc || !win) return frame.remove()
15
+ const styles = Array.from(document.querySelectorAll('style, link[rel="stylesheet"]'))
16
+ .map((n) => n.outerHTML)
17
+ .join('')
18
+ const html = document.documentElement
19
+ const palette = html.getAttribute('data-palette')
20
+ doc.open()
21
+ doc.write(
22
+ `<!doctype html><html class="${html.className.replace(/\bdark\b/, '')}"${palette ? ` data-palette="${palette}"` : ''}>` +
23
+ `<head><meta charset="utf-8"><base href="${document.baseURI}">${styles}` +
24
+ `<style>@page{size:${page};margin:0}html,body{margin:0;background:#fff;-webkit-print-color-adjust:exact;print-color-adjust:exact}${css}</style>` +
25
+ `</head><body>${el.outerHTML}</body></html>`,
26
+ )
27
+ doc.close()
28
+ const go = () => {
29
+ win.focus()
30
+ win.print()
31
+ setTimeout(() => frame.remove(), 1000)
32
+ }
33
+ // Wait for the copied stylesheets before printing
34
+ if (doc.readyState === 'complete') setTimeout(go, 50)
35
+ else frame.addEventListener('load', go, { once: true })
36
+ }
@@ -0,0 +1,104 @@
1
+ /** Card networks recognized by `detectCardBrand()` and `MCreditCardInput`. */
2
+ export type CardBrand =
3
+ | 'visa'
4
+ | 'mastercard'
5
+ | 'amex'
6
+ | 'discover'
7
+ | 'diners'
8
+ | 'jcb'
9
+ | 'unionpay'
10
+ | 'maestro'
11
+ | 'naranja'
12
+ | 'cabal'
13
+ | 'unknown'
14
+
15
+ export interface CardBrandInfo {
16
+ brand: CardBrand
17
+ /** Display name, e.g. "Mastercard" */
18
+ name: string
19
+ /** Valid lengths of the number, in digits */
20
+ lengths: number[]
21
+ /** Digit counts after which a space is shown, e.g. [4, 8, 12] → `4242 4242 4242 4242` */
22
+ gaps: number[]
23
+ /** Length of the security code */
24
+ cvcLength: number
25
+ /** Whether the number has to pass the Luhn checksum */
26
+ luhn: boolean
27
+ }
28
+
29
+ const BRANDS: (CardBrandInfo & { pattern: RegExp })[] = [
30
+ // Specific local networks go before the broad ranges they sit in
31
+ { brand: 'naranja', name: 'Naranja', pattern: /^589562/, lengths: [16], gaps: [4, 8, 12], cvcLength: 3, luhn: false },
32
+ { brand: 'cabal', name: 'Cabal', pattern: /^(60420[1-9]|6042[1-9]\d|6043\d\d|604400|589657)/, lengths: [16], gaps: [4, 8, 12], cvcLength: 3, luhn: true },
33
+ { brand: 'visa', name: 'Visa', pattern: /^4/, lengths: [13, 16], gaps: [4, 8, 12], cvcLength: 3, luhn: true },
34
+ { brand: 'mastercard', name: 'Mastercard', pattern: /^(5[1-5]|222[1-9]|22[3-9]\d|2[3-6]\d\d|27[01]\d|2720)/, lengths: [16], gaps: [4, 8, 12], cvcLength: 3, luhn: true },
35
+ { brand: 'amex', name: 'American Express', pattern: /^3[47]/, lengths: [15], gaps: [4, 10], cvcLength: 4, luhn: true },
36
+ { brand: 'diners', name: 'Diners Club', pattern: /^(36|38|30[0-5])/, lengths: [14, 16, 19], gaps: [4, 10], cvcLength: 3, luhn: true },
37
+ { brand: 'jcb', name: 'JCB', pattern: /^35(2[89]|[3-8])/, lengths: [16, 17, 18, 19], gaps: [4, 8, 12], cvcLength: 3, luhn: true },
38
+ { brand: 'discover', name: 'Discover', pattern: /^(6011|65|64[4-9])/, lengths: [16, 19], gaps: [4, 8, 12], cvcLength: 3, luhn: true },
39
+ { brand: 'unionpay', name: 'UnionPay', pattern: /^62/, lengths: [16, 17, 18, 19], gaps: [4, 8, 12], cvcLength: 3, luhn: false },
40
+ { brand: 'maestro', name: 'Maestro', pattern: /^(5018|5020|5038|5893|6304|6759|676[1-3])/, lengths: [12, 13, 14, 15, 16, 17, 18, 19], gaps: [4, 8, 12], cvcLength: 3, luhn: true },
41
+ ]
42
+
43
+ const UNKNOWN: CardBrandInfo = { brand: 'unknown', name: '', lengths: [12, 13, 14, 15, 16], gaps: [4, 8, 12], cvcLength: 3, luhn: true }
44
+
45
+ /** Card network of a (partial) number, from its leading digits. Spaces and dashes are ignored. */
46
+ export function detectCardBrand(number: string): CardBrandInfo {
47
+ const digits = number.replace(/\D/g, '')
48
+ if (!digits) return UNKNOWN
49
+ const hit = BRANDS.find((b) => b.pattern.test(digits))
50
+ if (!hit) return UNKNOWN
51
+ const { pattern: _pattern, ...info } = hit
52
+ return info
53
+ }
54
+
55
+ /** Luhn (mod 10) checksum of a card number. Spaces and dashes are ignored. */
56
+ export function luhnCheck(number: string): boolean {
57
+ const digits = number.replace(/\D/g, '')
58
+ if (!digits) return false
59
+ let sum = 0
60
+ let double = false
61
+ for (let i = digits.length - 1; i >= 0; i--) {
62
+ let d = digits.charCodeAt(i) - 48
63
+ if (double) {
64
+ d *= 2
65
+ if (d > 9) d -= 9
66
+ }
67
+ sum += d
68
+ double = !double
69
+ }
70
+ return sum % 10 === 0
71
+ }
72
+
73
+ /** Formats digits with the brand's gaps: `"4242424242424242"` → `"4242 4242 4242 4242"`. */
74
+ export function formatCardNumber(number: string): string {
75
+ const digits = number.replace(/\D/g, '')
76
+ const { gaps } = detectCardBrand(digits)
77
+ let out = ''
78
+ for (let i = 0; i < digits.length; i++) {
79
+ if (i > 0 && gaps.includes(i)) out += ' '
80
+ out += digits[i]
81
+ }
82
+ return out
83
+ }
84
+
85
+ /** Whether a card number is complete and valid for its brand (length, plus Luhn where the network uses it). */
86
+ export function isValidCardNumber(number: string): boolean {
87
+ const digits = number.replace(/\D/g, '')
88
+ const info = detectCardBrand(digits)
89
+ if (!info.lengths.includes(digits.length)) return false
90
+ return !info.luhn || luhnCheck(digits)
91
+ }
92
+
93
+ /** Whether an `MM/YY` expiry is well formed and not in the past (a card is valid through its expiry month). */
94
+ export function isValidExpiry(expiry: string, now: Date = new Date()): boolean {
95
+ const m = /^(\d{2})\/(\d{2})$/.exec(expiry.trim())
96
+ if (!m) return false
97
+ const month = Number(m[1])
98
+ const year = 2000 + Number(m[2])
99
+ if (month < 1 || month > 12) return false
100
+ const thisYear = now.getFullYear()
101
+ const thisMonth = now.getMonth() + 1
102
+ if (year > thisYear + 20) return false
103
+ return year > thisYear || (year === thisYear && month >= thisMonth)
104
+ }