@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.
- package/dist/API.md +1058 -18
- 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/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 +35 -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 +8264 -3553
- 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__/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__/mortgage.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +11 -0
- 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/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/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 +35 -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,287 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** A price level of an `MOrderBook`: `[price, size]`. */
|
|
3
|
+
export type OrderBookLevel = [price: number, size: number]
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<script setup lang="ts">
|
|
7
|
+
/**
|
|
8
|
+
* A live order book (market depth) for an exchange or trading screen: asks above, bids below (or side by side),
|
|
9
|
+
* each level with its size, the running total and a depth bar, and the last price and spread in the middle. Levels
|
|
10
|
+
* whose size changes flash; `step` groups levels into coarser price buckets. Clicking a level emits it, e.g. to
|
|
11
|
+
* fill an order form's price.
|
|
12
|
+
*
|
|
13
|
+
* @slot middle Replaces the last price / spread row. Slot props: `{ lastPrice, direction, spread, spreadPercent }`
|
|
14
|
+
* @event select A level was clicked: `{ price, size, side }`
|
|
15
|
+
*/
|
|
16
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
17
|
+
import MIcon from './MIcon.vue'
|
|
18
|
+
import { useLocale } from '../composables/useLocale'
|
|
19
|
+
|
|
20
|
+
const locale = useLocale()
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(
|
|
23
|
+
defineProps<{
|
|
24
|
+
/** Buy orders, `[price, size]`, any order */
|
|
25
|
+
bids: OrderBookLevel[]
|
|
26
|
+
/** Sell orders, `[price, size]`, any order */
|
|
27
|
+
asks: OrderBookLevel[]
|
|
28
|
+
/** Levels shown per side */
|
|
29
|
+
levels?: number
|
|
30
|
+
/** Groups prices into buckets of this size (bids round down, asks round up) */
|
|
31
|
+
step?: number
|
|
32
|
+
/** Decimals of prices. Defaults to the decimals of `step`, or 2 */
|
|
33
|
+
decimals?: number
|
|
34
|
+
/** Decimals of sizes */
|
|
35
|
+
sizeDecimals?: number
|
|
36
|
+
/** Last traded price, shown between the sides; its arrow follows the previous value */
|
|
37
|
+
lastPrice?: number
|
|
38
|
+
/** Asks above bids, or bids and asks side by side */
|
|
39
|
+
layout?: 'stacked' | 'split'
|
|
40
|
+
/** Flashes levels whose size changed */
|
|
41
|
+
flash?: boolean
|
|
42
|
+
/** Color of bids (any CSS color) */
|
|
43
|
+
bidColor?: string
|
|
44
|
+
/** Color of asks (any CSS color) */
|
|
45
|
+
askColor?: string
|
|
46
|
+
}>(),
|
|
47
|
+
{
|
|
48
|
+
levels: 10,
|
|
49
|
+
sizeDecimals: 4,
|
|
50
|
+
layout: 'stacked',
|
|
51
|
+
flash: true,
|
|
52
|
+
bidColor: 'var(--color-success)',
|
|
53
|
+
askColor: 'var(--color-error)',
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const emit = defineEmits<{ select: [{ price: number; size: number; side: 'bid' | 'ask' }] }>()
|
|
58
|
+
|
|
59
|
+
const priceDecimals = computed(() => {
|
|
60
|
+
if (props.decimals !== undefined) return props.decimals
|
|
61
|
+
if (props.step !== undefined) {
|
|
62
|
+
const s = String(props.step)
|
|
63
|
+
return s.includes('.') ? s.split('.')[1]!.length : 0
|
|
64
|
+
}
|
|
65
|
+
return 2
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function bucket(p: number, side: 'bid' | 'ask') {
|
|
69
|
+
if (!props.step) return p
|
|
70
|
+
const k = p / props.step
|
|
71
|
+
// Nudge away float noise (0.3 / 0.1 = 2.9999999999999996) before rounding
|
|
72
|
+
const r = side === 'bid' ? Math.floor(k + 1e-9) : Math.ceil(k - 1e-9)
|
|
73
|
+
return Number((r * props.step).toFixed(priceDecimals.value))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface Row { price: number; size: number; total: number }
|
|
77
|
+
|
|
78
|
+
function build(levels: OrderBookLevel[], side: 'bid' | 'ask'): Row[] {
|
|
79
|
+
const map = new Map<number, number>()
|
|
80
|
+
for (const [p, s] of levels) {
|
|
81
|
+
if (!(s > 0)) continue
|
|
82
|
+
const b = bucket(p, side)
|
|
83
|
+
map.set(b, (map.get(b) ?? 0) + s)
|
|
84
|
+
}
|
|
85
|
+
const sorted = [...map.entries()].sort((a, b) => (side === 'bid' ? b[0] - a[0] : a[0] - b[0])).slice(0, props.levels)
|
|
86
|
+
let total = 0
|
|
87
|
+
return sorted.map(([price, size]) => ({ price, size, total: (total += size) }))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const bidRows = computed(() => build(props.bids, 'bid'))
|
|
91
|
+
/** Best ask first (nearest the middle) */
|
|
92
|
+
const askRows = computed(() => build(props.asks, 'ask'))
|
|
93
|
+
const maxTotal = computed(() => Math.max(bidRows.value.at(-1)?.total ?? 0, askRows.value.at(-1)?.total ?? 0, 1e-12))
|
|
94
|
+
|
|
95
|
+
const spread = computed(() => {
|
|
96
|
+
const b = bidRows.value[0]?.price
|
|
97
|
+
const a = askRows.value[0]?.price
|
|
98
|
+
if (b === undefined || a === undefined) return null
|
|
99
|
+
const s = a - b
|
|
100
|
+
return { value: s, percent: (s / ((a + b) / 2)) * 100 }
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const direction = ref<'up' | 'down' | null>(null)
|
|
104
|
+
watch(
|
|
105
|
+
() => props.lastPrice,
|
|
106
|
+
(now, before) => {
|
|
107
|
+
if (now === undefined || before === undefined || now === before) return
|
|
108
|
+
direction.value = now > before ? 'up' : 'down'
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const priceFmt = computed(() => new Intl.NumberFormat(locale.lang, { minimumFractionDigits: priceDecimals.value, maximumFractionDigits: priceDecimals.value }))
|
|
113
|
+
// Fixed decimals keep the size column aligned
|
|
114
|
+
const sizeFmt = computed(() => new Intl.NumberFormat(locale.lang, { minimumFractionDigits: props.sizeDecimals, maximumFractionDigits: props.sizeDecimals }))
|
|
115
|
+
|
|
116
|
+
// ── flashes: a generation number per level restarts its animation by re-keying the overlay ──
|
|
117
|
+
const flashes = ref(new Map<string, number>())
|
|
118
|
+
let gen = 0
|
|
119
|
+
const timers = new Set<ReturnType<typeof setTimeout>>()
|
|
120
|
+
function diff(rows: Row[], prev: Row[] | undefined, side: string) {
|
|
121
|
+
if (!props.flash || !prev) return
|
|
122
|
+
const old = new Map(prev.map((r) => [r.price, r.size]))
|
|
123
|
+
for (const r of rows) {
|
|
124
|
+
if (old.get(r.price) === r.size) continue
|
|
125
|
+
const k = `${side}:${r.price}`
|
|
126
|
+
const g = ++gen
|
|
127
|
+
flashes.value.set(k, g)
|
|
128
|
+
const t = setTimeout(() => {
|
|
129
|
+
timers.delete(t)
|
|
130
|
+
if (flashes.value.get(k) === g) flashes.value.delete(k)
|
|
131
|
+
}, 700)
|
|
132
|
+
timers.add(t)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
watch(bidRows, (rows, prev) => diff(rows, prev, 'bid'))
|
|
136
|
+
watch(askRows, (rows, prev) => diff(rows, prev, 'ask'))
|
|
137
|
+
onBeforeUnmount(() => timers.forEach(clearTimeout))
|
|
138
|
+
|
|
139
|
+
/** Asks listed top to bottom: worst first in stacked layout so the best sits by the middle */
|
|
140
|
+
const askList = computed(() => (props.layout === 'stacked' ? [...askRows.value].reverse() : askRows.value))
|
|
141
|
+
|
|
142
|
+
function pick(r: Row, side: 'bid' | 'ask') {
|
|
143
|
+
emit('select', { price: r.price, size: r.size, side })
|
|
144
|
+
}
|
|
145
|
+
</script>
|
|
146
|
+
|
|
147
|
+
<template>
|
|
148
|
+
<div class="m3-order-book text-body-medium tabular-nums text-on-surface" :data-layout="layout">
|
|
149
|
+
<div v-if="layout === 'stacked'" class="flex flex-col">
|
|
150
|
+
<div class="grid grid-cols-3 px-3 pb-1 text-label-medium text-on-surface-variant">
|
|
151
|
+
<span>{{ locale.bookPrice }}</span>
|
|
152
|
+
<span class="text-end">{{ locale.bookSize }}</span>
|
|
153
|
+
<span class="text-end">{{ locale.bookTotal }}</span>
|
|
154
|
+
</div>
|
|
155
|
+
|
|
156
|
+
<button
|
|
157
|
+
v-for="r in askList"
|
|
158
|
+
:key="`a${r.price}`"
|
|
159
|
+
type="button"
|
|
160
|
+
class="m3-ob-row relative grid w-full grid-cols-3 px-3 py-0.5 text-start"
|
|
161
|
+
data-side="ask"
|
|
162
|
+
@click="pick(r, 'ask')"
|
|
163
|
+
>
|
|
164
|
+
<span class="m3-ob-depth absolute inset-y-0 right-0" :style="{ width: `${(r.total / maxTotal) * 100}%`, background: askColor }" />
|
|
165
|
+
<span v-if="flashes.get(`ask:${r.price}`)" :key="flashes.get(`ask:${r.price}`)" class="m3-ob-flash absolute inset-0" :style="{ background: askColor }" />
|
|
166
|
+
<span class="relative" :style="{ color: askColor }">{{ priceFmt.format(r.price) }}</span>
|
|
167
|
+
<span class="relative text-end">{{ sizeFmt.format(r.size) }}</span>
|
|
168
|
+
<span class="relative text-end text-on-surface-variant">{{ sizeFmt.format(r.total) }}</span>
|
|
169
|
+
</button>
|
|
170
|
+
|
|
171
|
+
<div class="my-1 flex items-center gap-3 border-y border-outline-variant px-3 py-2" data-middle>
|
|
172
|
+
<slot name="middle" :last-price="lastPrice" :direction="direction" :spread="spread?.value" :spread-percent="spread?.percent">
|
|
173
|
+
<span
|
|
174
|
+
v-if="lastPrice !== undefined"
|
|
175
|
+
class="flex items-center gap-0.5 text-title-large font-medium"
|
|
176
|
+
:style="{ color: direction === 'down' ? askColor : direction === 'up' ? bidColor : undefined }"
|
|
177
|
+
>
|
|
178
|
+
{{ priceFmt.format(lastPrice) }}
|
|
179
|
+
<MIcon v-if="direction" :name="direction === 'up' ? 'arrow_upward' : 'arrow_downward'" :size="18" />
|
|
180
|
+
</span>
|
|
181
|
+
<span v-if="spread" class="ms-auto text-label-medium text-on-surface-variant" data-spread>
|
|
182
|
+
{{ locale.bookSpread }} {{ priceFmt.format(spread.value) }} ({{ spread.percent.toFixed(3) }}%)
|
|
183
|
+
</span>
|
|
184
|
+
</slot>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<button
|
|
188
|
+
v-for="r in bidRows"
|
|
189
|
+
:key="`b${r.price}`"
|
|
190
|
+
type="button"
|
|
191
|
+
class="m3-ob-row relative grid w-full grid-cols-3 px-3 py-0.5 text-start"
|
|
192
|
+
data-side="bid"
|
|
193
|
+
@click="pick(r, 'bid')"
|
|
194
|
+
>
|
|
195
|
+
<span class="m3-ob-depth absolute inset-y-0 right-0" :style="{ width: `${(r.total / maxTotal) * 100}%`, background: bidColor }" />
|
|
196
|
+
<span v-if="flashes.get(`bid:${r.price}`)" :key="flashes.get(`bid:${r.price}`)" class="m3-ob-flash absolute inset-0" :style="{ background: bidColor }" />
|
|
197
|
+
<span class="relative" :style="{ color: bidColor }">{{ priceFmt.format(r.price) }}</span>
|
|
198
|
+
<span class="relative text-end">{{ sizeFmt.format(r.size) }}</span>
|
|
199
|
+
<span class="relative text-end text-on-surface-variant">{{ sizeFmt.format(r.total) }}</span>
|
|
200
|
+
</button>
|
|
201
|
+
</div>
|
|
202
|
+
|
|
203
|
+
<div v-else class="flex flex-col">
|
|
204
|
+
<div class="flex items-center gap-3 border-b border-outline-variant px-3 pb-2" data-middle>
|
|
205
|
+
<slot name="middle" :last-price="lastPrice" :direction="direction" :spread="spread?.value" :spread-percent="spread?.percent">
|
|
206
|
+
<span
|
|
207
|
+
v-if="lastPrice !== undefined"
|
|
208
|
+
class="flex items-center gap-0.5 text-title-large font-medium"
|
|
209
|
+
:style="{ color: direction === 'down' ? askColor : direction === 'up' ? bidColor : undefined }"
|
|
210
|
+
>
|
|
211
|
+
{{ priceFmt.format(lastPrice) }}
|
|
212
|
+
<MIcon v-if="direction" :name="direction === 'up' ? 'arrow_upward' : 'arrow_downward'" :size="18" />
|
|
213
|
+
</span>
|
|
214
|
+
<span v-if="spread" class="ms-auto text-label-medium text-on-surface-variant" data-spread>
|
|
215
|
+
{{ locale.bookSpread }} {{ priceFmt.format(spread.value) }} ({{ spread.percent.toFixed(3) }}%)
|
|
216
|
+
</span>
|
|
217
|
+
</slot>
|
|
218
|
+
</div>
|
|
219
|
+
<div class="grid grid-cols-2 gap-px pt-1">
|
|
220
|
+
<div>
|
|
221
|
+
<div class="grid grid-cols-2 px-3 pb-1 text-label-medium text-on-surface-variant">
|
|
222
|
+
<span>{{ locale.bookSize }}</span>
|
|
223
|
+
<span class="text-end">{{ locale.bookPrice }}</span>
|
|
224
|
+
</div>
|
|
225
|
+
<button
|
|
226
|
+
v-for="r in bidRows"
|
|
227
|
+
:key="`b${r.price}`"
|
|
228
|
+
type="button"
|
|
229
|
+
class="m3-ob-row relative grid w-full grid-cols-2 px-3 py-0.5 text-start"
|
|
230
|
+
data-side="bid"
|
|
231
|
+
@click="pick(r, 'bid')"
|
|
232
|
+
>
|
|
233
|
+
<span class="m3-ob-depth absolute inset-y-0 right-0" :style="{ width: `${(r.total / maxTotal) * 100}%`, background: bidColor }" />
|
|
234
|
+
<span v-if="flashes.get(`bid:${r.price}`)" :key="flashes.get(`bid:${r.price}`)" class="m3-ob-flash absolute inset-0" :style="{ background: bidColor }" />
|
|
235
|
+
<span class="relative">{{ sizeFmt.format(r.size) }}</span>
|
|
236
|
+
<span class="relative text-end" :style="{ color: bidColor }">{{ priceFmt.format(r.price) }}</span>
|
|
237
|
+
</button>
|
|
238
|
+
</div>
|
|
239
|
+
<div>
|
|
240
|
+
<div class="grid grid-cols-2 px-3 pb-1 text-label-medium text-on-surface-variant">
|
|
241
|
+
<span>{{ locale.bookPrice }}</span>
|
|
242
|
+
<span class="text-end">{{ locale.bookSize }}</span>
|
|
243
|
+
</div>
|
|
244
|
+
<button
|
|
245
|
+
v-for="r in askList"
|
|
246
|
+
:key="`a${r.price}`"
|
|
247
|
+
type="button"
|
|
248
|
+
class="m3-ob-row relative grid w-full grid-cols-2 px-3 py-0.5 text-start"
|
|
249
|
+
data-side="ask"
|
|
250
|
+
@click="pick(r, 'ask')"
|
|
251
|
+
>
|
|
252
|
+
<span class="m3-ob-depth absolute inset-y-0 left-0" :style="{ width: `${(r.total / maxTotal) * 100}%`, background: askColor }" />
|
|
253
|
+
<span v-if="flashes.get(`ask:${r.price}`)" :key="flashes.get(`ask:${r.price}`)" class="m3-ob-flash absolute inset-0" :style="{ background: askColor }" />
|
|
254
|
+
<span class="relative" :style="{ color: askColor }">{{ priceFmt.format(r.price) }}</span>
|
|
255
|
+
<span class="relative text-end">{{ sizeFmt.format(r.size) }}</span>
|
|
256
|
+
</button>
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
</div>
|
|
261
|
+
</template>
|
|
262
|
+
|
|
263
|
+
<style>
|
|
264
|
+
.m3-ob-depth {
|
|
265
|
+
opacity: 0.14;
|
|
266
|
+
transition: width 200ms ease;
|
|
267
|
+
}
|
|
268
|
+
.m3-ob-flash {
|
|
269
|
+
opacity: 0;
|
|
270
|
+
animation: m3-ob-flash 700ms ease-out;
|
|
271
|
+
}
|
|
272
|
+
@keyframes m3-ob-flash {
|
|
273
|
+
from { opacity: 0.35; }
|
|
274
|
+
to { opacity: 0; }
|
|
275
|
+
}
|
|
276
|
+
.m3-ob-row:hover {
|
|
277
|
+
background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
278
|
+
}
|
|
279
|
+
.m3-ob-row:focus-visible {
|
|
280
|
+
outline: 2px solid var(--color-secondary);
|
|
281
|
+
outline-offset: -2px;
|
|
282
|
+
}
|
|
283
|
+
@media (prefers-reduced-motion: reduce) {
|
|
284
|
+
.m3-ob-flash { animation: none; }
|
|
285
|
+
.m3-ob-depth { transition: none; }
|
|
286
|
+
}
|
|
287
|
+
</style>
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ref as sharedRef, type Ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
/** A modifier on an order line: a plain string, or with a kind to style additions and removals. */
|
|
5
|
+
export type OrderModifier = string | { label: string; kind?: 'add' | 'remove' | 'info' }
|
|
6
|
+
|
|
7
|
+
/** A line of an `MOrderTicket`. */
|
|
8
|
+
export interface OrderItem {
|
|
9
|
+
id: string | number
|
|
10
|
+
name: string
|
|
11
|
+
quantity?: number
|
|
12
|
+
modifiers?: OrderModifier[]
|
|
13
|
+
/** A free note for this line, e.g. "allergy: nuts" */
|
|
14
|
+
note?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// One clock for every ticket on the screen: a kitchen display can show dozens
|
|
18
|
+
const now: Ref<number> = sharedRef(Date.now())
|
|
19
|
+
let subscribers = 0
|
|
20
|
+
let timer: ReturnType<typeof setInterval> | null = null
|
|
21
|
+
|
|
22
|
+
function subscribe() {
|
|
23
|
+
if (subscribers++ === 0 && typeof window !== 'undefined') {
|
|
24
|
+
now.value = Date.now()
|
|
25
|
+
timer = setInterval(() => (now.value = Date.now()), 1000)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function unsubscribe() {
|
|
29
|
+
if (--subscribers === 0 && timer) {
|
|
30
|
+
clearInterval(timer)
|
|
31
|
+
timer = null
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
/**
|
|
38
|
+
* A kitchen ticket (comanda) for a kitchen display or an order queue: the order number, where it goes, how long it
|
|
39
|
+
* has been waiting (the header turns amber, then red, as it ages) and its lines with quantities, modifiers and
|
|
40
|
+
* notes. Tapping a line crosses it out as done; once every line is done `complete` fires. Every ticket on the page
|
|
41
|
+
* shares one clock.
|
|
42
|
+
*
|
|
43
|
+
* @slot header Extra content in the header, under the title (e.g. chips with the waiter or channel)
|
|
44
|
+
* @slot item Replaces a line's content (the tappable row stays). Slot props: `{ item, done }`
|
|
45
|
+
* @slot actions Content at the bottom (e.g. bump / recall buttons). Slot props: `{ allDone, elapsed }`
|
|
46
|
+
* @event update:done Emitted with the ids of the lines marked done — powers v-model:done
|
|
47
|
+
* @event complete Emitted when the last line is marked done
|
|
48
|
+
*/
|
|
49
|
+
import { computed, onBeforeUnmount, onMounted } from 'vue'
|
|
50
|
+
import MIcon from './MIcon.vue'
|
|
51
|
+
|
|
52
|
+
const props = withDefaults(
|
|
53
|
+
defineProps<{
|
|
54
|
+
/** Order number shown big in the header, e.g. 42 or "A-17" */
|
|
55
|
+
number: string | number
|
|
56
|
+
/** Where it goes, e.g. "Table 7", "Takeaway · Ana" */
|
|
57
|
+
title?: string
|
|
58
|
+
/** Material Symbol before the title, e.g. "restaurant", "takeout_dining", "two_wheeler" */
|
|
59
|
+
icon?: string
|
|
60
|
+
/** When the order came in (Date, ISO string or epoch ms); drives the timer */
|
|
61
|
+
createdAt: Date | string | number
|
|
62
|
+
/** When it was finished: freezes the timer at that moment */
|
|
63
|
+
finishedAt?: Date | string | number
|
|
64
|
+
/** The order lines */
|
|
65
|
+
items: OrderItem[]
|
|
66
|
+
/** Ids of the lines done (v-model:done) */
|
|
67
|
+
done?: (string | number)[]
|
|
68
|
+
/** A note for the whole order */
|
|
69
|
+
note?: string
|
|
70
|
+
/** Minutes after which the header turns to the warning color */
|
|
71
|
+
warnAfter?: number
|
|
72
|
+
/** Minutes after which the header turns to the error color */
|
|
73
|
+
lateAfter?: number
|
|
74
|
+
/** Read-only: lines can't be ticked */
|
|
75
|
+
readonly?: boolean
|
|
76
|
+
}>(),
|
|
77
|
+
{
|
|
78
|
+
done: () => [],
|
|
79
|
+
warnAfter: 10,
|
|
80
|
+
lateAfter: 20,
|
|
81
|
+
readonly: false,
|
|
82
|
+
},
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const emit = defineEmits<{
|
|
86
|
+
'update:done': [(string | number)[]]
|
|
87
|
+
complete: []
|
|
88
|
+
}>()
|
|
89
|
+
|
|
90
|
+
// The shared clock only runs while a ticket is mounted: refresh it so the first render isn't stale
|
|
91
|
+
if (subscribers === 0) now.value = Date.now()
|
|
92
|
+
onMounted(subscribe)
|
|
93
|
+
onBeforeUnmount(unsubscribe)
|
|
94
|
+
|
|
95
|
+
function toMs(v: Date | string | number) {
|
|
96
|
+
return v instanceof Date ? v.getTime() : typeof v === 'number' ? v : Date.parse(v)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Seconds since the order came in */
|
|
100
|
+
const elapsed = computed(() => {
|
|
101
|
+
const end = props.finishedAt !== undefined ? toMs(props.finishedAt) : now.value
|
|
102
|
+
return Math.max(0, Math.floor((end - toMs(props.createdAt)) / 1000))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const elapsedText = computed(() => {
|
|
106
|
+
const s = elapsed.value
|
|
107
|
+
const h = Math.floor(s / 3600)
|
|
108
|
+
const m = Math.floor((s % 3600) / 60)
|
|
109
|
+
const sec = String(s % 60).padStart(2, '0')
|
|
110
|
+
return h > 0 ? `${h}:${String(m).padStart(2, '0')}:${sec}` : `${m}:${sec}`
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const level = computed<'normal' | 'warn' | 'late'>(() => {
|
|
114
|
+
const min = elapsed.value / 60
|
|
115
|
+
if (props.finishedAt !== undefined) return 'normal'
|
|
116
|
+
if (min >= props.lateAfter) return 'late'
|
|
117
|
+
if (min >= props.warnAfter) return 'warn'
|
|
118
|
+
return 'normal'
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const doneSet = computed(() => new Set(props.done))
|
|
122
|
+
const allDone = computed(() => props.items.length > 0 && props.items.every((i) => doneSet.value.has(i.id)))
|
|
123
|
+
|
|
124
|
+
function toggle(item: OrderItem) {
|
|
125
|
+
if (props.readonly) return
|
|
126
|
+
const next = doneSet.value.has(item.id) ? props.done.filter((id) => id !== item.id) : [...props.done, item.id]
|
|
127
|
+
emit('update:done', next)
|
|
128
|
+
if (!doneSet.value.has(item.id) && props.items.every((i) => i.id === item.id || doneSet.value.has(i.id))) emit('complete')
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function mod(m: OrderModifier) {
|
|
132
|
+
return typeof m === 'string' ? { label: m, kind: 'info' as const } : { kind: 'info' as const, ...m }
|
|
133
|
+
}
|
|
134
|
+
</script>
|
|
135
|
+
|
|
136
|
+
<template>
|
|
137
|
+
<div class="m3-order-ticket flex flex-col overflow-hidden rounded-lg bg-surface-container-low text-on-surface shadow-elevation-1">
|
|
138
|
+
<div
|
|
139
|
+
class="flex items-start gap-3 px-4 py-3 transition-colors duration-300"
|
|
140
|
+
:class="{
|
|
141
|
+
'bg-surface-container-highest text-on-surface': level === 'normal',
|
|
142
|
+
'bg-tertiary-container text-on-tertiary-container': level === 'warn',
|
|
143
|
+
'bg-error-container text-on-error-container': level === 'late',
|
|
144
|
+
}"
|
|
145
|
+
:data-level="level"
|
|
146
|
+
>
|
|
147
|
+
<span class="text-headline-small font-medium tabular-nums">#{{ number }}</span>
|
|
148
|
+
<div class="min-w-0 flex-1">
|
|
149
|
+
<div v-if="title" class="flex items-center gap-1.5 truncate text-title-medium">
|
|
150
|
+
<MIcon v-if="icon" :name="icon" :size="20" />
|
|
151
|
+
<span class="truncate">{{ title }}</span>
|
|
152
|
+
</div>
|
|
153
|
+
<slot name="header" />
|
|
154
|
+
</div>
|
|
155
|
+
<span class="flex shrink-0 items-center gap-1 text-title-medium tabular-nums" role="timer" :aria-label="elapsedText">
|
|
156
|
+
<MIcon :name="finishedAt !== undefined ? 'check_circle' : 'schedule'" :size="20" />
|
|
157
|
+
{{ elapsedText }}
|
|
158
|
+
</span>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<ul class="flex flex-col py-1" role="list">
|
|
162
|
+
<li v-for="item in items" :key="item.id">
|
|
163
|
+
<button
|
|
164
|
+
type="button"
|
|
165
|
+
class="m3-order-line flex w-full items-start gap-3 px-4 py-2 text-left transition-opacity duration-150"
|
|
166
|
+
:class="[doneSet.has(item.id) ? 'is-done opacity-50' : '', readonly ? 'cursor-default' : 'cursor-pointer']"
|
|
167
|
+
:aria-pressed="doneSet.has(item.id)"
|
|
168
|
+
:disabled="readonly"
|
|
169
|
+
@click="toggle(item)"
|
|
170
|
+
>
|
|
171
|
+
<slot name="item" :item="item" :done="doneSet.has(item.id)">
|
|
172
|
+
<span class="min-w-8 text-title-medium font-medium tabular-nums">{{ item.quantity ?? 1 }}×</span>
|
|
173
|
+
<span class="min-w-0 flex-1">
|
|
174
|
+
<span class="m3-order-line__name block text-title-medium">{{ item.name }}</span>
|
|
175
|
+
<span
|
|
176
|
+
v-for="(m, i) in (item.modifiers ?? []).map(mod)"
|
|
177
|
+
:key="i"
|
|
178
|
+
class="block text-body-medium"
|
|
179
|
+
:class="{
|
|
180
|
+
'text-error': m.kind === 'remove',
|
|
181
|
+
'text-primary': m.kind === 'add',
|
|
182
|
+
'text-on-surface-variant': m.kind === 'info',
|
|
183
|
+
}"
|
|
184
|
+
>{{ m.kind === 'remove' ? '− ' : m.kind === 'add' ? '+ ' : '' }}{{ m.label }}</span>
|
|
185
|
+
<span v-if="item.note" class="mt-0.5 flex items-center gap-1 text-body-medium italic text-tertiary">
|
|
186
|
+
<MIcon name="sticky_note_2" :size="16" />{{ item.note }}
|
|
187
|
+
</span>
|
|
188
|
+
</span>
|
|
189
|
+
<MIcon v-if="doneSet.has(item.id)" name="check" :size="20" class="text-primary" />
|
|
190
|
+
</slot>
|
|
191
|
+
</button>
|
|
192
|
+
</li>
|
|
193
|
+
</ul>
|
|
194
|
+
|
|
195
|
+
<div v-if="note" class="mx-4 mb-3 flex items-start gap-2 rounded-sm bg-tertiary-container/50 px-3 py-2 text-body-medium text-on-tertiary-container">
|
|
196
|
+
<MIcon name="sticky_note_2" :size="18" class="mt-0.5" />
|
|
197
|
+
<span>{{ note }}</span>
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
<div v-if="$slots.actions" class="mt-auto flex gap-2 px-4 pb-4">
|
|
201
|
+
<slot name="actions" :allDone="allDone" :elapsed="elapsed" />
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
</template>
|
|
205
|
+
|
|
206
|
+
<style>
|
|
207
|
+
.m3-order-line:not(:disabled):hover {
|
|
208
|
+
background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
|
|
209
|
+
}
|
|
210
|
+
.m3-order-line:focus-visible {
|
|
211
|
+
outline: 3px solid var(--color-secondary);
|
|
212
|
+
outline-offset: -3px;
|
|
213
|
+
}
|
|
214
|
+
.m3-order-line.is-done .m3-order-line__name {
|
|
215
|
+
text-decoration: line-through;
|
|
216
|
+
}
|
|
217
|
+
</style>
|