@m3ui-vue/m3ui-vue 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/dist/API.md +940 -33
  2. package/dist/{MButton-CPghlKb0.js → MButton-OQ4wIERQ.js} +2 -2
  3. package/dist/{MButton-CPghlKb0.js.map → MButton-OQ4wIERQ.js.map} +1 -1
  4. package/dist/{MDialog-X50At1Gk.js → MDialog-DYMnaBlt.js} +3 -3
  5. package/dist/{MDialog-X50At1Gk.js.map → MDialog-DYMnaBlt.js.map} +1 -1
  6. package/dist/{MListItem-DVi1j1QI.js → MListItem-D2cNUyzP.js} +211 -168
  7. package/dist/MListItem-D2cNUyzP.js.map +1 -0
  8. package/dist/{MLoadingIndicator-vooA3110.js → MLoadingIndicator-DWUj0BAB.js} +2 -2
  9. package/dist/{MLoadingIndicator-vooA3110.js.map → MLoadingIndicator-DWUj0BAB.js.map} +1 -1
  10. package/dist/{MMenuItem-CRNZkVVr.js → MMenuItem-BuxYoASE.js} +133 -151
  11. package/dist/MMenuItem-BuxYoASE.js.map +1 -0
  12. package/dist/{MSeekBar-BL2W5_rD.js → MSeekBar-C4cn9RIF.js} +2 -2
  13. package/dist/{MSeekBar-BL2W5_rD.js.map → MSeekBar-C4cn9RIF.js.map} +1 -1
  14. package/dist/{MSlider-B9NcKTmZ.js → MSlider-BIkA6DiE.js} +2 -2
  15. package/dist/{MSlider-B9NcKTmZ.js.map → MSlider-BIkA6DiE.js.map} +1 -1
  16. package/dist/{MSpinner-_XpTRkAg.js → MSpinner-DZkXZJpc.js} +2 -2
  17. package/dist/{MSpinner-_XpTRkAg.js.map → MSpinner-DZkXZJpc.js.map} +1 -1
  18. package/dist/{MTextField-DpcPmR5B.js → MTextField-CNH-byir.js} +2 -2
  19. package/dist/{MTextField-DpcPmR5B.js.map → MTextField-CNH-byir.js.map} +1 -1
  20. package/dist/{MTooltip-BL3jPYPT.js → MTooltip-Dd5g2zhh.js} +4 -4
  21. package/dist/{MTooltip-BL3jPYPT.js.map → MTooltip-Dd5g2zhh.js.map} +1 -1
  22. package/dist/{_useEscapeStack-C5-BYr8y.js → _popupPosition-nL8SVKPK.js} +20 -2
  23. package/dist/_popupPosition-nL8SVKPK.js.map +1 -0
  24. package/dist/api.json +1 -1
  25. package/dist/code-editor.js +1 -1
  26. package/dist/components/MAddressField.vue.d.ts +54 -0
  27. package/dist/components/MAudioPlayer.vue.d.ts +1 -1
  28. package/dist/components/MAudioRecorder.vue.d.ts +51 -0
  29. package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
  30. package/dist/components/MCameraCapture.vue.d.ts +51 -0
  31. package/dist/components/MCollapse.vue.d.ts +32 -0
  32. package/dist/components/MCountrySelect.vue.d.ts +41 -0
  33. package/dist/components/MCronField.vue.d.ts +26 -0
  34. package/dist/components/MDashboardGrid.vue.d.ts +65 -0
  35. package/dist/components/MDiffViewer.vue.d.ts +56 -0
  36. package/dist/components/MExpansionPanel.vue.d.ts +26 -3
  37. package/dist/components/MFilterBuilder.vue.d.ts +22 -0
  38. package/dist/components/MFlex.vue.d.ts +1 -1
  39. package/dist/components/MMapCluster.vue.d.ts +80 -0
  40. package/dist/components/MMapDraw.vue.d.ts +79 -0
  41. package/dist/components/MMentionField.vue.d.ts +102 -0
  42. package/dist/components/MNotificationCenter.vue.d.ts +57 -0
  43. package/dist/components/MQRScanner.vue.d.ts +52 -0
  44. package/dist/components/MQuiz.vue.d.ts +1 -1
  45. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  46. package/dist/components/MStack.vue.d.ts +1 -1
  47. package/dist/components/MTimezoneSelect.vue.d.ts +39 -0
  48. package/dist/components/MToolbar.vue.d.ts +1 -1
  49. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  50. package/dist/components/_MFilterGroup.vue.d.ts +17 -0
  51. package/dist/composables/_caretPosition.d.ts +6 -0
  52. package/dist/composables/_useCamera.d.ts +16 -0
  53. package/dist/composables/_useFollowAnchor.d.ts +15 -0
  54. package/dist/composables/cron.d.ts +29 -0
  55. package/dist/composables/dashboardLayout.d.ts +28 -0
  56. package/dist/composables/filterBuilder.d.ts +55 -0
  57. package/dist/composables/mapAdapters.d.ts +6 -1
  58. package/dist/composables/mapSearch.d.ts +1 -0
  59. package/dist/composables/textDiff.d.ts +24 -0
  60. package/dist/composables/useLocale.d.ts +108 -0
  61. package/dist/draw.js +3 -3
  62. package/dist/flow.js +1 -1
  63. package/dist/gantt.js +1 -1
  64. package/dist/index.d.ts +25 -0
  65. package/dist/locales/index.js +749 -0
  66. package/dist/locales/index.js.map +1 -1
  67. package/dist/m3ui-vue.css +1 -1
  68. package/dist/m3ui.js +9888 -6940
  69. package/dist/m3ui.js.map +1 -1
  70. package/dist/map.d.ts +5 -0
  71. package/dist/map.js +1462 -576
  72. package/dist/map.js.map +1 -1
  73. package/dist/media.js +5 -5
  74. package/dist/pdf.js +5 -5
  75. package/dist/rich-text-editor.js +5 -5
  76. package/dist/styles.css +1 -1
  77. package/dist/{useLocale-COav9m8C.js → useLocale-DaVSTdm0.js} +108 -1
  78. package/dist/useLocale-DaVSTdm0.js.map +1 -0
  79. package/package.json +1 -1
  80. package/src/__tests__/MAddressField.test.ts +149 -0
  81. package/src/__tests__/MAudioRecorder.test.ts +125 -0
  82. package/src/__tests__/MCameraCapture.test.ts +154 -0
  83. package/src/__tests__/MCountrySelect.test.ts +67 -0
  84. package/src/__tests__/MCronField.test.ts +100 -0
  85. package/src/__tests__/MDashboardGrid.test.ts +122 -0
  86. package/src/__tests__/MDiffViewer.test.ts +68 -0
  87. package/src/__tests__/MExpansionPanel.test.ts +107 -0
  88. package/src/__tests__/MFilterBuilder.test.ts +130 -0
  89. package/src/__tests__/MMapCluster.test.ts +127 -0
  90. package/src/__tests__/MMapDraw.test.ts +188 -0
  91. package/src/__tests__/MMapLayers.test.ts +56 -0
  92. package/src/__tests__/MMentionField.test.ts +163 -0
  93. package/src/__tests__/MNotificationCenter.test.ts +94 -0
  94. package/src/__tests__/_fakeMaplibre.ts +14 -3
  95. package/src/__tests__/attrsFallthrough.test.ts +4 -0
  96. package/src/__tests__/cron.test.ts +68 -0
  97. package/src/__tests__/dashboardLayout.test.ts +45 -0
  98. package/src/__tests__/filterBuilder.test.ts +91 -0
  99. package/src/__tests__/followAnchor.test.ts +162 -0
  100. package/src/__tests__/ssr.test.ts +3 -0
  101. package/src/__tests__/textDiff.test.ts +37 -0
  102. package/src/components/MAddressField.vue +301 -0
  103. package/src/components/MAudioRecorder.vue +334 -0
  104. package/src/components/MAutocomplete.vue +3 -7
  105. package/src/components/MCameraCapture.vue +156 -0
  106. package/src/components/MCollapse.vue +91 -0
  107. package/src/components/MColorPicker.vue +4 -8
  108. package/src/components/MCountrySelect.vue +89 -0
  109. package/src/components/MCronField.vue +251 -0
  110. package/src/components/MDashboardGrid.vue +382 -0
  111. package/src/components/MDatePicker.vue +10 -7
  112. package/src/components/MDateRangePicker.vue +10 -7
  113. package/src/components/MDiffViewer.vue +234 -0
  114. package/src/components/MExpansionPanel.vue +56 -48
  115. package/src/components/MFilterBuilder.vue +47 -0
  116. package/src/components/MMapCluster.vue +295 -0
  117. package/src/components/MMapDraw.vue +601 -0
  118. package/src/components/MMapSearch.vue +1 -9
  119. package/src/components/MMentionField.vue +373 -0
  120. package/src/components/MMultiAutocomplete.vue +3 -7
  121. package/src/components/MMultiSelect.vue +3 -7
  122. package/src/components/MNotificationCenter.vue +252 -0
  123. package/src/components/MPhoneInput.vue +3 -10
  124. package/src/components/MQRScanner.vue +177 -0
  125. package/src/components/MSelect.vue +3 -7
  126. package/src/components/MTimePicker.vue +10 -7
  127. package/src/components/MTimezoneSelect.vue +116 -0
  128. package/src/components/_MFilterGroup.vue +210 -0
  129. package/src/composables/_caretPosition.ts +44 -0
  130. package/src/composables/_useCamera.ts +66 -0
  131. package/src/composables/_useFollowAnchor.ts +109 -0
  132. package/src/composables/cron.ts +179 -0
  133. package/src/composables/dashboardLayout.ts +94 -0
  134. package/src/composables/filterBuilder.ts +195 -0
  135. package/src/composables/mapAdapters.ts +29 -15
  136. package/src/composables/mapSearch.ts +10 -0
  137. package/src/composables/textDiff.ts +106 -0
  138. package/src/composables/useLocale.ts +215 -0
  139. package/src/index.ts +25 -0
  140. package/src/locales/de.ts +107 -0
  141. package/src/locales/es.ts +107 -0
  142. package/src/locales/fr.ts +107 -0
  143. package/src/locales/ja.ts +107 -0
  144. package/src/locales/ko.ts +107 -0
  145. package/src/locales/pt.ts +107 -0
  146. package/src/locales/zh.ts +107 -0
  147. package/src/map.ts +5 -0
  148. package/dist/MListItem-DVi1j1QI.js.map +0 -1
  149. package/dist/MMenuItem-CRNZkVVr.js.map +0 -1
  150. package/dist/_useEscapeStack-C5-BYr8y.js.map +0 -1
  151. package/dist/useLocale-COav9m8C.js.map +0 -1
@@ -0,0 +1,210 @@
1
+ <script setup lang="ts">
2
+ // Internal: one group of MFilterBuilder (its rules, nested groups and buttons), recursive. Changes go up as a new
3
+ // group object; it never mutates the one it got.
4
+ import { computed } from 'vue'
5
+ import MButton from './MButton.vue'
6
+ import MDatePicker from './MDatePicker.vue'
7
+ import MIconButton from './MIconButton.vue'
8
+ import MMultiSelect from './MMultiSelect.vue'
9
+ import MNumberField from './MNumberField.vue'
10
+ import MSegmentedButton from './MSegmentedButton.vue'
11
+ import MSelect from './MSelect.vue'
12
+ import MTextField from './MTextField.vue'
13
+ import MFilterGroup from './_MFilterGroup.vue'
14
+ import { useLocale } from '../composables/useLocale'
15
+ import {
16
+ VALUELESS, createGroup, createRule, isGroup, operatorsFor,
17
+ type FilterField, type FilterGroup, type FilterOperator, type FilterRule,
18
+ } from '../composables/filterBuilder'
19
+
20
+ const props = defineProps<{
21
+ group: FilterGroup
22
+ fields: FilterField[]
23
+ depth: number
24
+ maxDepth: number
25
+ disabled?: boolean
26
+ }>()
27
+
28
+ const emit = defineEmits<{ update: [group: FilterGroup]; remove: [] }>()
29
+
30
+ const t = useLocale()
31
+
32
+ const fieldOptions = computed(() => props.fields.map((f) => ({ label: f.label, value: f.key })))
33
+ const fieldOf = (key: string) => props.fields.find((f) => f.key === key)
34
+
35
+ const OP_LABELS = computed<Record<FilterOperator, string>>(() => ({
36
+ contains: t.filterOpContains, notContains: t.filterOpNotContains, equals: t.filterOpEquals, notEquals: t.filterOpNotEquals,
37
+ startsWith: t.filterOpStartsWith, endsWith: t.filterOpEndsWith, gt: t.filterOpGt, gte: t.filterOpGte, lt: t.filterOpLt,
38
+ lte: t.filterOpLte, between: t.filterOpBetween, in: t.filterOpIn, notIn: t.filterOpNotIn, isTrue: t.filterOpIsTrue,
39
+ isFalse: t.filterOpIsFalse, isEmpty: t.filterOpIsEmpty, isNotEmpty: t.filterOpIsNotEmpty,
40
+ }))
41
+ function opLabel(op: FilterOperator, field?: FilterField) {
42
+ // On dates, greater / less read as after / before
43
+ if (field?.type === 'date' && op === 'gt') return t.filterOpAfter
44
+ if (field?.type === 'date' && op === 'lt') return t.filterOpBefore
45
+ return OP_LABELS.value[op]
46
+ }
47
+ const operatorOptions = (rule: FilterRule) => {
48
+ const field = fieldOf(rule.field)
49
+ return field ? operatorsFor(field).map((op) => ({ label: opLabel(op, field), value: op })) : []
50
+ }
51
+
52
+ const combinators = computed(() => [
53
+ { value: 'and' as const, label: t.filterMatchAll },
54
+ { value: 'or' as const, label: t.filterMatchAny },
55
+ ])
56
+
57
+ function set(rules: (FilterRule | FilterGroup)[], combinator = props.group.combinator) {
58
+ emit('update', { ...props.group, combinator, rules })
59
+ }
60
+ function replace(i: number, next: FilterRule | FilterGroup) {
61
+ set(props.group.rules.map((r, j) => (j === i ? next : r)))
62
+ }
63
+ function removeAt(i: number) {
64
+ set(props.group.rules.filter((_, j) => j !== i))
65
+ }
66
+
67
+ function setField(i: number, rule: FilterRule, key: unknown) {
68
+ const field = fieldOf(String(key))
69
+ if (!field || field.key === rule.field) return
70
+ replace(i, { ...createRule(field), id: rule.id })
71
+ }
72
+ function setOperator(i: number, rule: FilterRule, op: unknown) {
73
+ const next = op as FilterOperator
74
+ if (next === rule.operator) return
75
+ // A value survives when it still fits: none for valueless operators, a pair only for `between`, a list for in / notIn
76
+ const shape = (o: FilterOperator) => (VALUELESS.includes(o) ? 'none' : o === 'between' ? 'pair' : o === 'in' || o === 'notIn' ? 'list' : 'one')
77
+ const value = shape(next) === shape(rule.operator) ? rule.value : undefined
78
+ replace(i, { ...rule, operator: next, value })
79
+ }
80
+ const setValue = (i: number, rule: FilterRule, value: unknown) => replace(i, { ...rule, value })
81
+ function setBound(i: number, rule: FilterRule, which: 0 | 1, value: unknown) {
82
+ const pair = Array.isArray(rule.value) ? [...rule.value] : [null, null]
83
+ pair[which] = value === '' ? null : value
84
+ replace(i, { ...rule, value: pair })
85
+ }
86
+ const bound = (rule: FilterRule, which: 0 | 1) => (Array.isArray(rule.value) ? rule.value[which] ?? null : null)
87
+
88
+ function addRule() {
89
+ const first = props.fields[0]
90
+ if (first) set([...props.group.rules, createRule(first)])
91
+ }
92
+ function addGroup() {
93
+ const first = props.fields[0]
94
+ const group = createGroup(props.group.combinator === 'and' ? 'or' : 'and')
95
+ if (first) group.rules.push(createRule(first))
96
+ set([...props.group.rules, group])
97
+ }
98
+ </script>
99
+
100
+ <template>
101
+ <div class="flex flex-col gap-3">
102
+ <div v-if="group.rules.length > 1 || depth > 0" class="flex items-center gap-2">
103
+ <MSegmentedButton
104
+ :model-value="group.combinator"
105
+ :options="combinators"
106
+ density="compact"
107
+ class="w-auto"
108
+ :aria-disabled="disabled || undefined"
109
+ @update:model-value="(v: 'and' | 'or') => !disabled && set(group.rules, v)"
110
+ />
111
+ <span class="flex-1" />
112
+ <MIconButton v-if="depth > 0" icon="delete" :label="t.filterRemoveGroup" size="sm" :disabled="disabled" @click="emit('remove')" />
113
+ </div>
114
+
115
+ <p v-if="!group.rules.length && depth === 0" class="text-body-medium text-on-surface-variant">{{ t.filterNoConditions }}</p>
116
+
117
+ <template v-for="(rule, i) in group.rules" :key="rule.id">
118
+ <!-- A nested group -->
119
+ <div v-if="isGroup(rule)" class="rounded-md border border-outline-variant bg-surface-container-low p-3" data-filter-group>
120
+ <MFilterGroup
121
+ :group="rule"
122
+ :fields="fields"
123
+ :depth="depth + 1"
124
+ :max-depth="maxDepth"
125
+ :disabled="disabled"
126
+ @update="(g: FilterGroup) => replace(i, g)"
127
+ @remove="removeAt(i)"
128
+ />
129
+ </div>
130
+
131
+ <!-- A rule: field · operator · value · remove; wraps on narrow widths -->
132
+ <div v-else class="flex flex-wrap items-start gap-2" data-filter-rule>
133
+ <MSelect
134
+ :model-value="rule.field"
135
+ :options="fieldOptions"
136
+ :label="t.filterField"
137
+ variant="outlined"
138
+ :disabled="disabled"
139
+ class="min-w-40 flex-[1_1_10rem]"
140
+ @update:model-value="(v: unknown) => setField(i, rule, v)"
141
+ />
142
+ <MSelect
143
+ :model-value="rule.operator"
144
+ :options="operatorOptions(rule)"
145
+ :label="t.filterOperator"
146
+ variant="outlined"
147
+ :disabled="disabled"
148
+ class="min-w-40 flex-[1_1_10rem]"
149
+ @update:model-value="(v: unknown) => setOperator(i, rule, v)"
150
+ />
151
+
152
+ <div class="flex min-w-48 flex-[2_1_14rem] gap-2">
153
+ <template v-if="VALUELESS.includes(rule.operator)" />
154
+ <template v-else-if="rule.operator === 'between' && fieldOf(rule.field)?.type === 'date'">
155
+ <MDatePicker :model-value="(bound(rule, 0) as string | null)" :label="t.filterFrom" variant="outlined" :disabled="disabled" class="min-w-0 flex-1" @update:model-value="(v: string | null) => setBound(i, rule, 0, v)" />
156
+ <MDatePicker :model-value="(bound(rule, 1) as string | null)" :label="t.filterTo" variant="outlined" :disabled="disabled" class="min-w-0 flex-1" @update:model-value="(v: string | null) => setBound(i, rule, 1, v)" />
157
+ </template>
158
+ <template v-else-if="rule.operator === 'between'">
159
+ <MNumberField :model-value="(bound(rule, 0) as number | null)" :label="t.filterFrom" variant="outlined" :disabled="disabled" class="min-w-0 flex-1" @update:model-value="(v: number | null) => setBound(i, rule, 0, v)" />
160
+ <MNumberField :model-value="(bound(rule, 1) as number | null)" :label="t.filterTo" variant="outlined" :disabled="disabled" class="min-w-0 flex-1" @update:model-value="(v: number | null) => setBound(i, rule, 1, v)" />
161
+ </template>
162
+ <MMultiSelect
163
+ v-else-if="rule.operator === 'in' || rule.operator === 'notIn'"
164
+ :model-value="(Array.isArray(rule.value) ? rule.value : [])"
165
+ :options="fieldOf(rule.field)?.options ?? []"
166
+ :label="t.filterValue"
167
+ variant="outlined"
168
+ :disabled="disabled"
169
+ class="min-w-0 flex-1"
170
+ @update:model-value="(v: unknown[]) => setValue(i, rule, v)"
171
+ />
172
+ <MDatePicker
173
+ v-else-if="fieldOf(rule.field)?.type === 'date'"
174
+ :model-value="(rule.value as string | null) ?? null"
175
+ :label="t.filterValue"
176
+ variant="outlined"
177
+ :disabled="disabled"
178
+ class="min-w-0 flex-1"
179
+ @update:model-value="(v: string | null) => setValue(i, rule, v)"
180
+ />
181
+ <MNumberField
182
+ v-else-if="fieldOf(rule.field)?.type === 'number'"
183
+ :model-value="(rule.value as number | null) ?? null"
184
+ :label="t.filterValue"
185
+ variant="outlined"
186
+ :disabled="disabled"
187
+ class="min-w-0 flex-1"
188
+ @update:model-value="(v: number | null) => setValue(i, rule, v)"
189
+ />
190
+ <MTextField
191
+ v-else
192
+ :model-value="String(rule.value ?? '')"
193
+ :label="t.filterValue"
194
+ variant="outlined"
195
+ :disabled="disabled"
196
+ class="min-w-0 flex-1"
197
+ @update:model-value="(v: string | number) => setValue(i, rule, v)"
198
+ />
199
+ </div>
200
+
201
+ <MIconButton icon="close" :label="t.filterRemoveCondition" size="sm" :disabled="disabled" class="mt-3 shrink-0" @click="removeAt(i)" />
202
+ </div>
203
+ </template>
204
+
205
+ <div class="flex flex-wrap gap-1">
206
+ <MButton variant="text" icon="add" size="sm" :disabled="disabled || !fields.length" @click="addRule">{{ t.filterAddCondition }}</MButton>
207
+ <MButton v-if="depth < maxDepth" variant="text" icon="library_add" size="sm" :disabled="disabled || !fields.length" @click="addGroup">{{ t.filterAddGroup }}</MButton>
208
+ </div>
209
+ </div>
210
+ </template>
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Internal (not exported from index.ts): where the caret of a textarea or input is on screen, to hang a popup from
3
+ * it (MMentionField). A hidden mirror element copies the field's box and text styles and the text up to the caret;
4
+ * a marker span at the end lands where the caret is. Measured afresh on each call, so it follows the field's scroll.
5
+ */
6
+
7
+ // What decides where text wraps and how big it is
8
+ const PROPS = [
9
+ 'direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY',
10
+ 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'borderStyle',
11
+ 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
12
+ 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily',
13
+ 'textAlign', 'textTransform', 'textIndent', 'textDecoration', 'letterSpacing', 'wordSpacing', 'tabSize',
14
+ ] as const
15
+
16
+ /** The caret's box in viewport coordinates: `{ left, top, height }`. */
17
+ export function caretRect(el: HTMLTextAreaElement | HTMLInputElement, position = el.selectionStart ?? el.value.length) {
18
+ const mirror = document.createElement('div')
19
+ const style = getComputedStyle(el)
20
+ const s = mirror.style
21
+ for (const p of PROPS) s[p] = style[p]
22
+ s.position = 'absolute'
23
+ s.visibility = 'hidden'
24
+ s.top = '0'
25
+ s.left = '-9999px'
26
+ s.whiteSpace = el instanceof HTMLTextAreaElement ? 'pre-wrap' : 'pre'
27
+ s.overflowWrap = el instanceof HTMLTextAreaElement ? 'break-word' : 'normal'
28
+ mirror.textContent = el.value.slice(0, position)
29
+ const marker = document.createElement('span')
30
+ // Something with a height even at the end of a line
31
+ marker.textContent = el.value.slice(position) || '.'
32
+ mirror.appendChild(marker)
33
+ document.body.appendChild(mirror)
34
+ const box = el.getBoundingClientRect()
35
+ const lineHeight = parseFloat(style.lineHeight) || parseFloat(style.fontSize) * 1.2
36
+ // offsetLeft/Top count from inside the mirror's border, and fields may keep room in theirs (MTextField's label)
37
+ const rect = {
38
+ left: box.left + (parseFloat(style.borderLeftWidth) || 0) + marker.offsetLeft - el.scrollLeft,
39
+ top: box.top + (parseFloat(style.borderTopWidth) || 0) + marker.offsetTop - el.scrollTop,
40
+ height: lineHeight,
41
+ }
42
+ mirror.remove()
43
+ return rect
44
+ }
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Internal (not exported from index.ts): the camera behind MCameraCapture and MQRScanner. Starts a getUserMedia
3
+ * stream on a <video>, switches between the front and back cameras, stops every track when stopped or unmounted
4
+ * (so the browser's camera light goes off), and turns failures into a kind the components word through the locale.
5
+ */
6
+ import { onBeforeUnmount, ref, shallowRef, type Ref } from 'vue'
7
+
8
+ export type CameraFacing = 'user' | 'environment'
9
+ export type CameraError = 'denied' | 'unavailable' | 'unsupported' | 'failed'
10
+
11
+ export function useCamera(video: Ref<HTMLVideoElement | null | undefined>, options: { facing: () => CameraFacing; resolution?: () => number }) {
12
+ const stream = shallowRef<MediaStream | null>(null)
13
+ const status = ref<'idle' | 'starting' | 'live' | 'error'>('idle')
14
+ const error = ref<CameraError | null>(null)
15
+ const facing = ref<CameraFacing>(options.facing())
16
+ /** More than one camera: worth offering to switch */
17
+ const canSwitch = ref(false)
18
+
19
+ function stop() {
20
+ stream.value?.getTracks().forEach((t) => t.stop())
21
+ stream.value = null
22
+ if (video.value) video.value.srcObject = null
23
+ if (status.value !== 'error') status.value = 'idle'
24
+ }
25
+
26
+ async function start(next: CameraFacing = facing.value) {
27
+ const media = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined
28
+ if (!media?.getUserMedia) {
29
+ status.value = 'error'
30
+ error.value = 'unsupported'
31
+ return
32
+ }
33
+ stop()
34
+ facing.value = next
35
+ status.value = 'starting'
36
+ error.value = null
37
+ const ideal = options.resolution?.() ?? 1280
38
+ try {
39
+ const s = await media.getUserMedia({ audio: false, video: { facingMode: { ideal: next }, width: { ideal }, height: { ideal } } })
40
+ stream.value = s
41
+ if (video.value) {
42
+ video.value.srcObject = s
43
+ await video.value.play().catch(() => {})
44
+ }
45
+ status.value = 'live'
46
+ try {
47
+ const devices = await media.enumerateDevices?.()
48
+ canSwitch.value = (devices ?? []).filter((d) => d.kind === 'videoinput').length > 1
49
+ } catch {
50
+ canSwitch.value = false
51
+ }
52
+ } catch (e) {
53
+ const name = (e as { name?: string })?.name
54
+ status.value = 'error'
55
+ error.value = name === 'NotAllowedError' || name === 'SecurityError' ? 'denied'
56
+ : name === 'NotFoundError' || name === 'OverconstrainedError' || name === 'NotReadableError' ? 'unavailable'
57
+ : 'failed'
58
+ }
59
+ }
60
+
61
+ const switchCamera = () => start(facing.value === 'user' ? 'environment' : 'user')
62
+
63
+ onBeforeUnmount(stop)
64
+
65
+ return { stream, status, error, facing, canSwitch, start, stop, switchCamera }
66
+ }
@@ -0,0 +1,109 @@
1
+ import { onBeforeUnmount, watch, type Ref } from 'vue'
2
+
3
+ /*
4
+ * Internal (not exported from index.ts): keeps a teleported, `position: fixed` popup attached to the field that
5
+ * opened it while it's open. The page or any scroll container around the field scrolling, the window resizing
6
+ * (browser zoom resizes it too), the visual viewport changing (pinch zoom, the on-screen keyboard) and the field
7
+ * itself resizing (chips wrapping onto a new line) all re-run the component's own `place()`, once per frame. Once
8
+ * the field is scrolled out of sight (outside the window or clipped away by a scroll container around it) the popup
9
+ * closes, rather than floating over unrelated content, and the field loses focus so it doesn't keep looking open.
10
+ * Scrolls inside the popup itself are ignored.
11
+ */
12
+
13
+ const CLIPS = /(auto|scroll|hidden|clip)/
14
+
15
+ /** True when nothing of `el` is visible: outside the window, or cut away by an overflow-clipping ancestor. */
16
+ export function isAnchorHidden(el: Element): boolean {
17
+ if (!el.isConnected) return true
18
+ const r = el.getBoundingClientRect()
19
+ let top = r.top
20
+ let left = r.left
21
+ let bottom = r.bottom
22
+ let right = r.right
23
+ for (let p = el.parentElement; p && p !== document.body && p !== document.documentElement; p = p.parentElement) {
24
+ const s = getComputedStyle(p)
25
+ if (s.position === 'fixed') break
26
+ if (!CLIPS.test(s.overflow + s.overflowX + s.overflowY)) continue
27
+ const c = p.getBoundingClientRect()
28
+ top = Math.max(top, c.top)
29
+ left = Math.max(left, c.left)
30
+ bottom = Math.min(bottom, c.bottom)
31
+ right = Math.min(right, c.right)
32
+ }
33
+ top = Math.max(top, 0)
34
+ left = Math.max(left, 0)
35
+ bottom = Math.min(bottom, window.innerHeight)
36
+ right = Math.min(right, window.innerWidth)
37
+ return bottom <= top || right <= left
38
+ }
39
+
40
+ export function useFollowAnchor(options: {
41
+ /** Whether the popup is open: the listeners only exist while it is. */
42
+ open: () => boolean
43
+ /** The field the popup hangs from. */
44
+ anchor: Ref<HTMLElement | null | undefined>
45
+ /** The popup (scrolls inside it don't move it). */
46
+ popup: Ref<HTMLElement | null | undefined>
47
+ /** Re-measures the field and moves the popup. */
48
+ place: () => void
49
+ /** Closes the popup once the field can't be seen. */
50
+ close: () => void
51
+ }) {
52
+ let frame = 0
53
+ let observer: ResizeObserver | null = null
54
+ let attached = false
55
+
56
+ function run() {
57
+ frame = 0
58
+ if (!options.open()) return
59
+ const anchor = options.anchor.value
60
+ if (!anchor || isAnchorHidden(anchor)) {
61
+ options.close()
62
+ // A focused field looks open (floated label, primary indicator): once it's gone from view, the user left it
63
+ const active = document.activeElement
64
+ if (anchor && active instanceof HTMLElement && anchor.contains(active)) active.blur()
65
+ return
66
+ }
67
+ options.place()
68
+ }
69
+
70
+ function schedule() {
71
+ if (!frame) frame = requestAnimationFrame(run)
72
+ }
73
+
74
+ function onScroll(e: Event) {
75
+ const t = e.target
76
+ if (t instanceof Node && options.popup.value?.contains(t)) return
77
+ schedule()
78
+ }
79
+
80
+ function attach() {
81
+ if (attached || typeof window === 'undefined') return
82
+ attached = true
83
+ window.addEventListener('scroll', onScroll, { capture: true, passive: true })
84
+ window.addEventListener('resize', schedule)
85
+ window.visualViewport?.addEventListener('resize', schedule)
86
+ window.visualViewport?.addEventListener('scroll', schedule)
87
+ if (typeof ResizeObserver !== 'undefined' && options.anchor.value) {
88
+ // Its first callback fires right away, with the size the popup was just placed for: harmless
89
+ observer = new ResizeObserver(schedule)
90
+ observer.observe(options.anchor.value)
91
+ }
92
+ }
93
+
94
+ function detach() {
95
+ if (!attached) return
96
+ attached = false
97
+ window.removeEventListener('scroll', onScroll, { capture: true })
98
+ window.removeEventListener('resize', schedule)
99
+ window.visualViewport?.removeEventListener('resize', schedule)
100
+ window.visualViewport?.removeEventListener('scroll', schedule)
101
+ observer?.disconnect()
102
+ observer = null
103
+ if (frame) cancelAnimationFrame(frame)
104
+ frame = 0
105
+ }
106
+
107
+ watch(options.open, (v) => (v ? attach() : detach()), { immediate: true })
108
+ onBeforeUnmount(detach)
109
+ }
@@ -0,0 +1,179 @@
1
+ /*
2
+ * Five-field cron expressions (minute hour day-of-month month day-of-week), as crontab reads them: `*`, numbers,
3
+ * ranges `a-b`, steps `*\/n` and `a-b/n`, lists `a,b`, month and weekday names (`JAN`, `MON`), 7 as Sunday, and the
4
+ * macros `@yearly`, `@monthly`, `@weekly`, `@daily`, `@hourly`. When both day fields are restricted, a day matching
5
+ * either runs (crontab's rule). Used by MCronField; usable on their own.
6
+ */
7
+ import type { M3Locale } from './useLocale'
8
+
9
+ /** An expression read into the values each field allows. */
10
+ export interface CronSchedule {
11
+ minutes: number[]
12
+ hours: number[]
13
+ days: number[]
14
+ months: number[]
15
+ weekdays: number[]
16
+ /** Which fields were `*` (unrestricted) */
17
+ any: { days: boolean; weekdays: boolean; minutes: boolean; hours: boolean; months: boolean }
18
+ /** The fields as written (after macros), for describing steps */
19
+ fields: string[]
20
+ }
21
+
22
+ const MACROS: Record<string, string> = {
23
+ '@yearly': '0 0 1 1 *', '@annually': '0 0 1 1 *', '@monthly': '0 0 1 * *', '@weekly': '0 0 * * 0',
24
+ '@daily': '0 0 * * *', '@midnight': '0 0 * * *', '@hourly': '0 * * * *',
25
+ }
26
+ const MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
27
+ const DAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
28
+ const RANGES: [number, number][] = [[0, 59], [0, 23], [1, 31], [1, 12], [0, 7]]
29
+
30
+ function value(token: string, field: number): number {
31
+ const up = token.toUpperCase()
32
+ if (field === 3 && MONTHS.includes(up)) return MONTHS.indexOf(up) + 1
33
+ if (field === 4 && DAYS.includes(up)) return DAYS.indexOf(up)
34
+ if (!/^\d+$/.test(token)) throw new Error(token)
35
+ return Number(token)
36
+ }
37
+
38
+ function expand(part: string, field: number): number[] {
39
+ const [lo, hi] = RANGES[field]!
40
+ const out = new Set<number>()
41
+ for (const item of part.split(',')) {
42
+ const [range, stepText] = item.split('/') as [string, string | undefined]
43
+ const step = stepText === undefined ? 1 : Number(stepText)
44
+ if (!Number.isInteger(step) || step < 1) throw new Error(item)
45
+ let a: number, b: number
46
+ if (range === '*') [a, b] = [lo, hi]
47
+ else if (range.includes('-')) {
48
+ const [x, y] = range.split('-')
49
+ a = value(x!, field)
50
+ b = value(y!, field)
51
+ } else {
52
+ a = value(range, field)
53
+ // `5/15` means from 5 to the end, every 15
54
+ b = stepText === undefined ? a : hi
55
+ }
56
+ if (a < lo || b > hi || a > b) throw new Error(item)
57
+ for (let v = a; v <= b; v += step) out.add(field === 4 && v === 7 ? 0 : v)
58
+ }
59
+ return [...out].sort((x, y) => x - y)
60
+ }
61
+
62
+ /** Reads an expression; null when it isn't valid. */
63
+ export function parseCron(expression: string): CronSchedule | null {
64
+ const text = expression.trim()
65
+ const fields = (MACROS[text.toLowerCase()] ?? text).split(/\s+/)
66
+ if (fields.length !== 5) return null
67
+ try {
68
+ const [minutes, hours, days, months, weekdays] = fields.map((f, i) => expand(f, i)) as number[][]
69
+ return {
70
+ minutes: minutes!, hours: hours!, days: days!, months: months!, weekdays: weekdays!,
71
+ any: { minutes: fields[0] === '*', hours: fields[1] === '*', days: fields[2] === '*', months: fields[3] === '*', weekdays: fields[4] === '*' },
72
+ fields,
73
+ }
74
+ } catch {
75
+ return null
76
+ }
77
+ }
78
+
79
+ /** Whether an expression is valid. */
80
+ export const isValidCron = (expression: string) => parseCron(expression) !== null
81
+
82
+ function dayMatches(s: CronSchedule, d: Date) {
83
+ const dom = s.days.includes(d.getDate())
84
+ const dow = s.weekdays.includes(d.getDay())
85
+ if (s.any.days && s.any.weekdays) return true
86
+ if (s.any.days) return dow
87
+ if (s.any.weekdays) return dom
88
+ return dom || dow
89
+ }
90
+
91
+ /** The next times it runs after `from` (local time), up to `count`, within four years. */
92
+ export function nextCronRuns(expression: string, count = 5, from: Date = new Date()): Date[] {
93
+ const s = parseCron(expression)
94
+ if (!s) return []
95
+ const out: Date[] = []
96
+ const d = new Date(from)
97
+ d.setSeconds(0, 0)
98
+ d.setMinutes(d.getMinutes() + 1)
99
+ const limit = from.getTime() + 4 * 366 * 864e5
100
+ while (out.length < count && d.getTime() <= limit) {
101
+ if (!s.months.includes(d.getMonth() + 1)) {
102
+ d.setMonth(d.getMonth() + 1, 1)
103
+ d.setHours(0, 0)
104
+ continue
105
+ }
106
+ if (!dayMatches(s, d)) {
107
+ d.setDate(d.getDate() + 1)
108
+ d.setHours(0, 0)
109
+ continue
110
+ }
111
+ if (!s.hours.includes(d.getHours())) {
112
+ d.setHours(d.getHours() + 1, 0)
113
+ continue
114
+ }
115
+ if (!s.minutes.includes(d.getMinutes())) {
116
+ d.setMinutes(d.getMinutes() + 1)
117
+ continue
118
+ }
119
+ out.push(new Date(d))
120
+ d.setMinutes(d.getMinutes() + 1)
121
+ }
122
+ return out
123
+ }
124
+
125
+ /** The locale strings the description uses. */
126
+ export type CronStrings = Pick<M3Locale,
127
+ 'lang' | 'cronEveryMinute' | 'cronEveryNMinutes' | 'cronHourlyAt' | 'cronAt' | 'cronEveryNHoursAt' |
128
+ 'cronMinutesOfHours' | 'cronOnDaysOfMonth' | 'cronInMonths' | 'cronRange'>
129
+
130
+ /** Consecutive runs of 3 or more as `from–to`, the rest one by one. */
131
+ function compact(values: number[], name: (v: number) => string, range: string): string[] {
132
+ const out: string[] = []
133
+ for (let i = 0; i < values.length; i++) {
134
+ let j = i
135
+ while (j + 1 < values.length && values[j + 1] === values[j]! + 1) j++
136
+ if (j - i >= 2) {
137
+ out.push(range.replace('{from}', name(values[i]!)).replace('{to}', name(values[j]!)))
138
+ i = j
139
+ } else out.push(name(values[i]!))
140
+ }
141
+ return out
142
+ }
143
+
144
+ /** A sentence for the expression in the locale's language ("At 09:00, Monday to Friday"), or null when invalid. */
145
+ export function describeCron(expression: string, t: CronStrings): string | null {
146
+ const s = parseCron(expression)
147
+ if (!s) return null
148
+ const lang = t.lang || undefined
149
+ const list = (items: string[], type: 'conjunction' | 'disjunction' = 'conjunction') =>
150
+ typeof Intl.ListFormat === 'function' ? new Intl.ListFormat(lang, { type }).format(items) : items.join(', ')
151
+ const time = (h: number, m: number) => new Intl.DateTimeFormat(lang, { hour: 'numeric', minute: '2-digit' }).format(new Date(2024, 0, 1, h, m))
152
+ const weekday = (d: number) => new Intl.DateTimeFormat(lang, { weekday: 'long' }).format(new Date(2024, 0, 7 + d))
153
+ const month = (m: number) => new Intl.DateTimeFormat(lang, { month: 'long' }).format(new Date(2024, m - 1, 1))
154
+ const step = (field: string) => /^\*\/(\d+)$/.exec(field)?.[1]
155
+
156
+ // When
157
+ let when: string
158
+ const [mf, hf] = s.fields
159
+ const oneMinute = s.minutes.length === 1 ? s.minutes[0]! : null
160
+ if (s.any.minutes && s.any.hours) when = t.cronEveryMinute
161
+ else if (step(mf!) && s.any.hours) when = t.cronEveryNMinutes.replace('{n}', step(mf!)!)
162
+ else if (oneMinute !== null && s.any.hours) when = t.cronHourlyAt.replace('{m}', String(oneMinute))
163
+ else if (oneMinute !== null && step(hf!)) when = t.cronEveryNHoursAt.replace('{n}', step(hf!)!).replace('{m}', String(oneMinute))
164
+ else if (oneMinute !== null && s.hours.length <= 6) when = t.cronAt.replace('{time}', list(s.hours.map((h) => time(h, oneMinute))))
165
+ else {
166
+ when = t.cronMinutesOfHours
167
+ .replace('{minutes}', list(compact(s.minutes, String, t.cronRange)))
168
+ .replace('{hours}', list(compact(s.hours, String, t.cronRange)))
169
+ }
170
+
171
+ // Which days
172
+ const parts = [when]
173
+ const domText = s.any.days ? '' : t.cronOnDaysOfMonth.replace('{days}', list(compact(s.days, String, t.cronRange)))
174
+ const dowText = s.any.weekdays ? '' : list(compact(s.weekdays, weekday, t.cronRange))
175
+ if (domText && dowText) parts.push(list([domText, dowText], 'disjunction'))
176
+ else if (domText || dowText) parts.push(domText || dowText)
177
+ if (!s.any.months) parts.push(t.cronInMonths.replace('{months}', list(compact(s.months, month, t.cronRange))))
178
+ return parts.join(', ')
179
+ }