@bitrix24/b24ui-nuxt 0.5.10 → 0.5.11
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/meta.cjs +72112 -0
- package/dist/meta.d.cts +72110 -0
- package/dist/meta.d.mts +5060 -5060
- package/dist/meta.d.ts +72110 -0
- package/dist/meta.mjs +5060 -5060
- package/dist/module.cjs +63 -0
- package/dist/module.d.cts +15 -0
- package/dist/module.d.ts +15 -0
- package/dist/module.json +3 -3
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/Advice.vue +54 -47
- package/dist/runtime/components/Alert.vue +96 -71
- package/dist/runtime/components/App.vue +34 -37
- package/dist/runtime/components/Avatar.vue +81 -69
- package/dist/runtime/components/AvatarGroup.vue +76 -53
- package/dist/runtime/components/Badge.vue +83 -83
- package/dist/runtime/components/Button.vue +157 -220
- package/dist/runtime/components/ButtonGroup.vue +51 -35
- package/dist/runtime/components/Calendar.vue +152 -186
- package/dist/runtime/components/Checkbox.vue +73 -84
- package/dist/runtime/components/Chip.vue +74 -59
- package/dist/runtime/components/Collapsible.vue +41 -44
- package/dist/runtime/components/Container.vue +27 -18
- package/dist/runtime/components/Countdown.vue +378 -198
- package/dist/runtime/components/DescriptionList.vue +149 -102
- package/dist/runtime/components/DropdownMenu.vue +139 -83
- package/dist/runtime/components/DropdownMenuContent.vue +84 -137
- package/dist/runtime/components/Form.vue +216 -162
- package/dist/runtime/components/FormField.vue +80 -76
- package/dist/runtime/components/Input.vue +179 -160
- package/dist/runtime/components/InputMenu.vue +380 -300
- package/dist/runtime/components/InputNumber.vue +175 -178
- package/dist/runtime/components/Kbd.vue +45 -33
- package/dist/runtime/components/Link.vue +173 -179
- package/dist/runtime/components/LinkBase.vue +42 -64
- package/dist/runtime/components/Modal.vue +127 -105
- package/dist/runtime/components/ModalDialogClose.vue +8 -4
- package/dist/runtime/components/Navbar.vue +33 -24
- package/dist/runtime/components/NavbarDivider.vue +33 -24
- package/dist/runtime/components/NavbarSection.vue +33 -24
- package/dist/runtime/components/NavbarSpacer.vue +33 -24
- package/dist/runtime/components/NavigationMenu.vue +210 -144
- package/dist/runtime/components/OverlayProvider.vue +17 -13
- package/dist/runtime/components/Popover.vue +81 -81
- package/dist/runtime/components/Progress.vue +136 -109
- package/dist/runtime/components/RadioGroup.vue +134 -120
- package/dist/runtime/components/Range.vue +85 -94
- package/dist/runtime/components/Select.vue +260 -212
- package/dist/runtime/components/SelectMenu.vue +365 -272
- package/dist/runtime/components/Separator.vue +71 -61
- package/dist/runtime/components/Sidebar.vue +33 -24
- package/dist/runtime/components/SidebarBody.vue +38 -30
- package/dist/runtime/components/SidebarFooter.vue +33 -24
- package/dist/runtime/components/SidebarHeader.vue +33 -24
- package/dist/runtime/components/SidebarHeading.vue +33 -24
- package/dist/runtime/components/SidebarLayout.vue +70 -40
- package/dist/runtime/components/SidebarSection.vue +33 -24
- package/dist/runtime/components/SidebarSpacer.vue +33 -24
- package/dist/runtime/components/Skeleton.vue +22 -17
- package/dist/runtime/components/Slideover.vue +131 -108
- package/dist/runtime/components/StackedLayout.vue +73 -40
- package/dist/runtime/components/Switch.vue +95 -100
- package/dist/runtime/components/Tabs.vue +107 -81
- package/dist/runtime/components/Textarea.vue +201 -177
- package/dist/runtime/components/Toast.vue +105 -94
- package/dist/runtime/components/Toaster.vue +116 -94
- package/dist/runtime/components/Tooltip.vue +64 -78
- package/dist/runtime/components/content/TableWrapper.vue +70 -58
- package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
- package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
- package/dist/runtime/composables/useComponentIcons.d.ts +3 -3
- package/dist/runtime/composables/useFormField.d.ts +1 -1
- package/dist/runtime/prose/A.vue +23 -18
- package/dist/runtime/prose/Blockquote.vue +23 -18
- package/dist/runtime/prose/Code.vue +31 -23
- package/dist/runtime/prose/Em.vue +23 -18
- package/dist/runtime/prose/H1.vue +23 -18
- package/dist/runtime/prose/H2.vue +23 -18
- package/dist/runtime/prose/H3.vue +23 -18
- package/dist/runtime/prose/H4.vue +23 -18
- package/dist/runtime/prose/H5.vue +23 -18
- package/dist/runtime/prose/H6.vue +23 -18
- package/dist/runtime/prose/Hr.vue +19 -18
- package/dist/runtime/prose/Img.vue +23 -18
- package/dist/runtime/prose/Li.vue +23 -18
- package/dist/runtime/prose/Ol.vue +23 -18
- package/dist/runtime/prose/P.vue +23 -18
- package/dist/runtime/prose/Pre.vue +33 -28
- package/dist/runtime/prose/Strong.vue +23 -18
- package/dist/runtime/prose/Table.vue +54 -44
- package/dist/runtime/prose/Tbody.vue +23 -18
- package/dist/runtime/prose/Td.vue +23 -18
- package/dist/runtime/prose/Th.vue +23 -18
- package/dist/runtime/prose/Thead.vue +23 -18
- package/dist/runtime/prose/Tr.vue +23 -18
- package/dist/runtime/prose/Ul.vue +23 -18
- package/dist/runtime/vue/components/Link.vue +202 -201
- package/dist/shared/b24ui-nuxt.DrKwIWoc.cjs +7721 -0
- package/dist/types.d.mts +5 -3
- package/dist/types.d.ts +7 -0
- package/dist/unplugin.cjs +236 -0
- package/dist/unplugin.d.cts +33 -0
- package/dist/unplugin.d.ts +33 -0
- package/dist/vite.cjs +21 -0
- package/dist/vite.d.cts +14 -0
- package/dist/vite.d.ts +14 -0
- package/package.json +25 -13
- package/dist/runtime/components/Advice.vue.d.ts +0 -170
- package/dist/runtime/components/Alert.vue.d.ts +0 -464
- package/dist/runtime/components/App.vue.d.ts +0 -23
- package/dist/runtime/components/Avatar.vue.d.ts +0 -281
- package/dist/runtime/components/AvatarGroup.vue.d.ts +0 -204
- package/dist/runtime/components/Badge.vue.d.ts +0 -517
- package/dist/runtime/components/Button.vue.d.ts +0 -640
- package/dist/runtime/components/ButtonGroup.vue.d.ts +0 -116
- package/dist/runtime/components/Calendar.vue.d.ts +0 -437
- package/dist/runtime/components/Checkbox.vue.d.ts +0 -354
- package/dist/runtime/components/Chip.vue.d.ts +0 -271
- package/dist/runtime/components/Collapsible.vue.d.ts +0 -118
- package/dist/runtime/components/Container.vue.d.ts +0 -27
- package/dist/runtime/components/Countdown.vue.d.ts +0 -356
- package/dist/runtime/components/DescriptionList.vue.d.ts +0 -379
- package/dist/runtime/components/DropdownMenu.vue.d.ts +0 -533
- package/dist/runtime/components/DropdownMenuContent.vue.d.ts +0 -228
- package/dist/runtime/components/Form.vue.d.ts +0 -55
- package/dist/runtime/components/FormField.vue.d.ts +0 -282
- package/dist/runtime/components/Input.vue.d.ts +0 -755
- package/dist/runtime/components/InputMenu.vue.d.ts +0 -1504
- package/dist/runtime/components/InputNumber.vue.d.ts +0 -658
- package/dist/runtime/components/Kbd.vue.d.ts +0 -109
- package/dist/runtime/components/Link.vue.d.ts +0 -129
- package/dist/runtime/components/LinkBase.vue.d.ts +0 -48
- package/dist/runtime/components/Modal.vue.d.ts +0 -327
- package/dist/runtime/components/ModalDialogClose.vue.d.ts +0 -10
- package/dist/runtime/components/Navbar.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarDivider.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarSection.vue.d.ts +0 -101
- package/dist/runtime/components/NavbarSpacer.vue.d.ts +0 -101
- package/dist/runtime/components/NavigationMenu.vue.d.ts +0 -824
- package/dist/runtime/components/OverlayProvider.vue.d.ts +0 -2
- package/dist/runtime/components/Popover.vue.d.ts +0 -147
- package/dist/runtime/components/Progress.vue.d.ts +0 -592
- package/dist/runtime/components/RadioGroup.vue.d.ts +0 -723
- package/dist/runtime/components/Range.vue.d.ts +0 -417
- package/dist/runtime/components/Select.vue.d.ts +0 -1200
- package/dist/runtime/components/SelectMenu.vue.d.ts +0 -1298
- package/dist/runtime/components/Separator.vue.d.ts +0 -400
- package/dist/runtime/components/Sidebar.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarBody.vue.d.ts +0 -90
- package/dist/runtime/components/SidebarFooter.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarHeader.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarHeading.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarLayout.vue.d.ts +0 -222
- package/dist/runtime/components/SidebarSection.vue.d.ts +0 -101
- package/dist/runtime/components/SidebarSpacer.vue.d.ts +0 -101
- package/dist/runtime/components/Skeleton.vue.d.ts +0 -26
- package/dist/runtime/components/Slideover.vue.d.ts +0 -360
- package/dist/runtime/components/StackedLayout.vue.d.ts +0 -192
- package/dist/runtime/components/Switch.vue.d.ts +0 -587
- package/dist/runtime/components/Tabs.vue.d.ts +0 -453
- package/dist/runtime/components/Textarea.vue.d.ts +0 -601
- package/dist/runtime/components/Toast.vue.d.ts +0 -438
- package/dist/runtime/components/Toaster.vue.d.ts +0 -219
- package/dist/runtime/components/Tooltip.vue.d.ts +0 -186
- package/dist/runtime/components/content/TableWrapper.vue.d.ts +0 -237
- package/dist/runtime/prose/A.vue.d.ts +0 -84
- package/dist/runtime/prose/Blockquote.vue.d.ts +0 -84
- package/dist/runtime/prose/Code.vue.d.ts +0 -97
- package/dist/runtime/prose/Em.vue.d.ts +0 -84
- package/dist/runtime/prose/H1.vue.d.ts +0 -97
- package/dist/runtime/prose/H2.vue.d.ts +0 -123
- package/dist/runtime/prose/H3.vue.d.ts +0 -123
- package/dist/runtime/prose/H4.vue.d.ts +0 -123
- package/dist/runtime/prose/H5.vue.d.ts +0 -123
- package/dist/runtime/prose/H6.vue.d.ts +0 -123
- package/dist/runtime/prose/Hr.vue.d.ts +0 -74
- package/dist/runtime/prose/Img.vue.d.ts +0 -77
- package/dist/runtime/prose/Li.vue.d.ts +0 -84
- package/dist/runtime/prose/Ol.vue.d.ts +0 -84
- package/dist/runtime/prose/P.vue.d.ts +0 -84
- package/dist/runtime/prose/Pre.vue.d.ts +0 -117
- package/dist/runtime/prose/Strong.vue.d.ts +0 -84
- package/dist/runtime/prose/Table.vue.d.ts +0 -144
- package/dist/runtime/prose/Tbody.vue.d.ts +0 -84
- package/dist/runtime/prose/Td.vue.d.ts +0 -84
- package/dist/runtime/prose/Th.vue.d.ts +0 -84
- package/dist/runtime/prose/Thead.vue.d.ts +0 -84
- package/dist/runtime/prose/Tr.vue.d.ts +0 -84
- package/dist/runtime/prose/Ul.vue.d.ts +0 -84
- package/dist/runtime/vue/components/Link.vue.d.ts +0 -129
|
@@ -1,205 +1,345 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { VariantProps } from 'tailwind-variants'
|
|
3
|
+
import type { AppConfig } from '@nuxt/schema'
|
|
4
|
+
import _appConfig from '#build/app.config'
|
|
5
|
+
import theme from '#build/b24ui/countdown'
|
|
6
|
+
import type { UseComponentIconsProps } from '../composables/useComponentIcons'
|
|
7
|
+
import { tv } from '../utils/tv'
|
|
8
|
+
import type { AvatarProps } from '../types'
|
|
9
|
+
|
|
10
|
+
const appConfigCountdown = _appConfig as AppConfig & { b24ui: { countdown: Partial<typeof theme> } }
|
|
11
|
+
|
|
12
|
+
const countdown = tv({ extend: tv(theme), ...(appConfigCountdown.b24ui?.countdown || {}) })
|
|
13
|
+
|
|
14
|
+
type CountdownVariants = VariantProps<typeof countdown>
|
|
15
|
+
|
|
16
|
+
export interface CountdownData {
|
|
17
|
+
days: number
|
|
18
|
+
hours: number
|
|
19
|
+
minutes: number
|
|
20
|
+
seconds: number
|
|
21
|
+
milliseconds: number
|
|
22
|
+
totalDays: number
|
|
23
|
+
totalHours: number
|
|
24
|
+
totalMinutes: number
|
|
25
|
+
totalSeconds: number
|
|
26
|
+
totalMilliseconds: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CountdownProps extends Omit<UseComponentIconsProps, 'loading' | 'trailing' | 'trailingIcon'> {
|
|
30
|
+
/**
|
|
31
|
+
* The element or component this component should render as
|
|
32
|
+
* @defaultValue 'span'
|
|
33
|
+
*/
|
|
34
|
+
as?: any
|
|
35
|
+
/**
|
|
36
|
+
* @defaultValue 'md'
|
|
37
|
+
*/
|
|
38
|
+
size?: CountdownVariants['size']
|
|
39
|
+
/**
|
|
40
|
+
* Emits the countdown events
|
|
41
|
+
* @defaultValue true
|
|
42
|
+
*/
|
|
43
|
+
emitEvents?: boolean
|
|
44
|
+
/**
|
|
45
|
+
* Number of seconds to countdown
|
|
46
|
+
* @defaultValue 0
|
|
47
|
+
*/
|
|
48
|
+
seconds?: number | string
|
|
49
|
+
/**
|
|
50
|
+
* Should seconds be divided into minutes?
|
|
51
|
+
* @defaultValue true
|
|
52
|
+
*/
|
|
53
|
+
showMinutes?: boolean
|
|
54
|
+
/**
|
|
55
|
+
* Shows a `Circle` around the countdown
|
|
56
|
+
* @defaultValue false
|
|
57
|
+
*/
|
|
58
|
+
useCircle?: boolean
|
|
59
|
+
/**
|
|
60
|
+
* The interval time (in milliseconds) of the countdown progress
|
|
61
|
+
* @defaultValue 1000
|
|
62
|
+
*/
|
|
63
|
+
interval?: number
|
|
64
|
+
/**
|
|
65
|
+
* Starts the countdown automatically when initialized
|
|
66
|
+
* @defaultValue true
|
|
67
|
+
*/
|
|
68
|
+
needStartImmediately?: boolean
|
|
69
|
+
/**
|
|
70
|
+
* Generate the current time of a specific time zone
|
|
71
|
+
* @defaultValue Date.now()
|
|
72
|
+
*/
|
|
73
|
+
now?: () => number
|
|
74
|
+
class?: any
|
|
75
|
+
b24ui?: Partial<typeof countdown.slots>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface CountdownEmits {
|
|
79
|
+
(e: 'start' | 'end' | 'abort'): void
|
|
80
|
+
(e: 'progress', payload: CountdownData): void
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface CountdownSlots {
|
|
84
|
+
leading(props?: {}): any
|
|
85
|
+
default(props: CountdownData & { formatTime: string }): any
|
|
86
|
+
}
|
|
7
87
|
</script>
|
|
8
88
|
|
|
9
|
-
<script setup>
|
|
10
|
-
import { ref, computed, watch, onMounted, onBeforeUnmount } from
|
|
11
|
-
import { useComponentIcons } from
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
emitEvents:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type: Boolean,
|
|
39
|
-
required: false,
|
|
40
|
-
default: true
|
|
41
|
-
},
|
|
42
|
-
useCircle: {
|
|
43
|
-
type: Boolean,
|
|
44
|
-
required: false,
|
|
45
|
-
default: false
|
|
46
|
-
},
|
|
47
|
-
interval: {
|
|
48
|
-
type: Number,
|
|
49
|
-
required: false,
|
|
50
|
-
default: 1e3
|
|
51
|
-
},
|
|
52
|
-
needStartImmediately: {
|
|
53
|
-
type: Boolean,
|
|
54
|
-
required: false,
|
|
55
|
-
default: true
|
|
56
|
-
},
|
|
57
|
-
now: {
|
|
58
|
-
type: Function,
|
|
59
|
-
required: false,
|
|
60
|
-
default: () => Date.now()
|
|
61
|
-
},
|
|
62
|
-
class: {
|
|
63
|
-
type: null,
|
|
64
|
-
required: false
|
|
65
|
-
},
|
|
66
|
-
b24ui: {
|
|
67
|
-
type: Object,
|
|
68
|
-
required: false
|
|
69
|
-
},
|
|
70
|
-
icon: {
|
|
71
|
-
type: [Function, Object],
|
|
72
|
-
required: false
|
|
73
|
-
},
|
|
74
|
-
avatar: {
|
|
75
|
-
type: Object,
|
|
76
|
-
required: false
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
const emits = defineEmits(["start", "end", "abort", "progress"]);
|
|
80
|
-
defineSlots();
|
|
89
|
+
<script setup lang="ts">
|
|
90
|
+
import { ref, computed, watch, onMounted, onBeforeUnmount } from 'vue'
|
|
91
|
+
import { useComponentIcons } from '../composables/useComponentIcons'
|
|
92
|
+
import { Primitive } from 'reka-ui'
|
|
93
|
+
import B24Avatar from './Avatar.vue'
|
|
94
|
+
|
|
95
|
+
const MILLISECONDS_SECOND = 1000
|
|
96
|
+
const MILLISECONDS_MINUTE = 60 * MILLISECONDS_SECOND
|
|
97
|
+
const MILLISECONDS_HOUR = 60 * MILLISECONDS_MINUTE
|
|
98
|
+
const MILLISECONDS_DAY = 24 * MILLISECONDS_HOUR
|
|
99
|
+
|
|
100
|
+
defineOptions({ inheritAttrs: false })
|
|
101
|
+
|
|
102
|
+
// region data ////
|
|
103
|
+
|
|
104
|
+
const props = withDefaults(defineProps<CountdownProps>(), {
|
|
105
|
+
as: 'span',
|
|
106
|
+
needStartImmediately: true,
|
|
107
|
+
emitEvents: true,
|
|
108
|
+
interval: 1000,
|
|
109
|
+
now: () => Date.now(),
|
|
110
|
+
seconds: 0,
|
|
111
|
+
showMinutes: true,
|
|
112
|
+
useCircle: false
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const emits = defineEmits<CountdownEmits>()
|
|
116
|
+
defineSlots<CountdownSlots>()
|
|
117
|
+
|
|
81
118
|
const { isLeading, leadingIconName } = useComponentIcons(
|
|
82
119
|
computed(() => ({ ...props, loading: false }))
|
|
83
|
-
)
|
|
120
|
+
)
|
|
121
|
+
|
|
84
122
|
const b24ui = computed(() => countdown({
|
|
85
123
|
size: props.size,
|
|
86
124
|
leading: Boolean(isLeading.value),
|
|
87
125
|
useCircle: Boolean(props.useCircle)
|
|
88
|
-
}))
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
}))
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* It is counting down.
|
|
130
|
+
*/
|
|
131
|
+
const counting = ref<boolean>(false)
|
|
132
|
+
/**
|
|
133
|
+
* The absolute end time.
|
|
134
|
+
*/
|
|
135
|
+
const endTime = ref<number>(0)
|
|
136
|
+
/**
|
|
137
|
+
* The remaining milliseconds.
|
|
138
|
+
*/
|
|
139
|
+
const totalMilliseconds = ref<number>(0)
|
|
140
|
+
/**
|
|
141
|
+
* The request ID of the requestAnimationFrame.
|
|
142
|
+
*/
|
|
143
|
+
const requestId = ref<number>(0)
|
|
144
|
+
// endregion ////
|
|
145
|
+
|
|
146
|
+
// region events ////
|
|
93
147
|
onMounted(() => {
|
|
94
|
-
document.addEventListener(
|
|
95
|
-
})
|
|
148
|
+
document.addEventListener('visibilitychange', handleVisibilityChange.bind(this))
|
|
149
|
+
})
|
|
150
|
+
|
|
96
151
|
onBeforeUnmount(() => {
|
|
97
|
-
document.removeEventListener(
|
|
98
|
-
pause()
|
|
99
|
-
})
|
|
152
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange.bind(this))
|
|
153
|
+
pause()
|
|
154
|
+
})
|
|
155
|
+
// endregion ////
|
|
156
|
+
|
|
157
|
+
// region watch ////
|
|
158
|
+
/**
|
|
159
|
+
* Update the countdown when props changed.
|
|
160
|
+
*/
|
|
100
161
|
watch(
|
|
101
162
|
() => props,
|
|
102
163
|
() => {
|
|
103
|
-
totalMilliseconds.value = Number(props.seconds) *
|
|
104
|
-
endTime.value = props.now() + Number(props.seconds) *
|
|
164
|
+
totalMilliseconds.value = Number(props.seconds) * 1000
|
|
165
|
+
endTime.value = props.now() + Number(props.seconds) * 1000
|
|
166
|
+
|
|
105
167
|
if (props.needStartImmediately) {
|
|
106
|
-
start()
|
|
168
|
+
start()
|
|
107
169
|
}
|
|
108
170
|
},
|
|
109
171
|
{
|
|
110
172
|
deep: true,
|
|
111
173
|
immediate: true
|
|
112
174
|
}
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
return Math.floor(totalMilliseconds.value
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
175
|
+
)
|
|
176
|
+
// endregion ////
|
|
177
|
+
|
|
178
|
+
// region computed ////
|
|
179
|
+
/**
|
|
180
|
+
* Remaining days.
|
|
181
|
+
*/
|
|
182
|
+
const days = computed((): number => {
|
|
183
|
+
return Math.floor(totalMilliseconds.value / MILLISECONDS_DAY)
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Remaining hours.
|
|
188
|
+
*/
|
|
189
|
+
const hours = computed((): number => {
|
|
190
|
+
return Math.floor((totalMilliseconds.value % MILLISECONDS_DAY) / MILLISECONDS_HOUR)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Remaining minutes.
|
|
195
|
+
*/
|
|
196
|
+
const minutes = computed((): number => {
|
|
197
|
+
return Math.floor((totalMilliseconds.value % MILLISECONDS_HOUR) / MILLISECONDS_MINUTE)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Remaining seconds.
|
|
202
|
+
*/
|
|
203
|
+
const secondsValue = computed((): number => {
|
|
204
|
+
return Math.floor((totalMilliseconds.value % MILLISECONDS_MINUTE) / MILLISECONDS_SECOND)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Remaining milliseconds.
|
|
209
|
+
*/
|
|
210
|
+
const milliseconds = computed((): number => {
|
|
211
|
+
return Math.floor(totalMilliseconds.value % MILLISECONDS_SECOND)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Total remaining days.
|
|
216
|
+
*/
|
|
217
|
+
const totalDays = computed((): number => {
|
|
218
|
+
return days.value
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Total remaining hours.
|
|
223
|
+
*/
|
|
224
|
+
const totalHours = computed((): number => {
|
|
225
|
+
return Math.floor(totalMilliseconds.value / MILLISECONDS_HOUR)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Total remaining minutes.
|
|
230
|
+
*/
|
|
231
|
+
const totalMinutes = computed((): number => {
|
|
232
|
+
return Math.floor(totalMilliseconds.value / MILLISECONDS_MINUTE)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Total remaining seconds.
|
|
237
|
+
*/
|
|
238
|
+
const totalSeconds = computed((): number => {
|
|
239
|
+
return Math.floor(totalMilliseconds.value / MILLISECONDS_SECOND)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const formatTime = computed((): string => {
|
|
142
243
|
if (props.showMinutes && !props.useCircle) {
|
|
143
|
-
return `${totalMinutes.value < 10 ?
|
|
244
|
+
return `${totalMinutes.value < 10 ? '0' : ''}${totalMinutes.value}:${secondsValue.value < 10 ? '0' : ''}${secondsValue.value}`
|
|
144
245
|
} else if (props.useCircle) {
|
|
145
|
-
return `:${totalSeconds.value}
|
|
246
|
+
return `:${totalSeconds.value}`
|
|
146
247
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
248
|
+
|
|
249
|
+
return String(totalSeconds.value)
|
|
250
|
+
})
|
|
251
|
+
// endregion ////
|
|
252
|
+
|
|
253
|
+
// region actions ////
|
|
254
|
+
/**
|
|
255
|
+
* Starts to countdown.
|
|
256
|
+
*/
|
|
257
|
+
function start(): void {
|
|
150
258
|
if (counting.value) {
|
|
151
|
-
return
|
|
259
|
+
return
|
|
152
260
|
}
|
|
153
|
-
|
|
261
|
+
|
|
262
|
+
counting.value = true
|
|
263
|
+
|
|
154
264
|
if (!props.needStartImmediately) {
|
|
155
|
-
totalMilliseconds.value = Number(props.seconds) *
|
|
156
|
-
endTime.value = props.now() + Number(props.seconds) *
|
|
265
|
+
totalMilliseconds.value = Number(props.seconds) * 1000
|
|
266
|
+
endTime.value = props.now() + Number(props.seconds) * 1000
|
|
157
267
|
}
|
|
268
|
+
|
|
158
269
|
if (props.emitEvents) {
|
|
159
|
-
emits(
|
|
270
|
+
emits('start')
|
|
160
271
|
}
|
|
161
|
-
|
|
162
|
-
|
|
272
|
+
|
|
273
|
+
if (document?.visibilityState === 'visible') {
|
|
274
|
+
continueProcess()
|
|
163
275
|
}
|
|
164
276
|
}
|
|
165
|
-
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Continues the countdown.
|
|
280
|
+
*/
|
|
281
|
+
function continueProcess(): void {
|
|
166
282
|
if (!counting.value) {
|
|
167
|
-
return
|
|
283
|
+
return
|
|
168
284
|
}
|
|
169
|
-
|
|
285
|
+
|
|
286
|
+
const delay = Math.min(totalMilliseconds.value, props.interval)
|
|
287
|
+
|
|
170
288
|
if (delay > 0) {
|
|
171
|
-
let init
|
|
172
|
-
let prev
|
|
173
|
-
const step = (now) => {
|
|
289
|
+
let init: number
|
|
290
|
+
let prev: number
|
|
291
|
+
const step = (now: number) => {
|
|
174
292
|
if (!init) {
|
|
175
|
-
init = now
|
|
293
|
+
init = now
|
|
176
294
|
}
|
|
295
|
+
|
|
177
296
|
if (!prev) {
|
|
178
|
-
prev = now
|
|
297
|
+
prev = now
|
|
179
298
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
299
|
+
|
|
300
|
+
const range = now - init
|
|
301
|
+
|
|
302
|
+
if (
|
|
303
|
+
range >= delay
|
|
304
|
+
// Avoid losing time about one second per minute (now - prev ≈ 16ms)
|
|
305
|
+
|| range + ((now - prev) / 2) >= delay
|
|
306
|
+
) {
|
|
307
|
+
progress()
|
|
183
308
|
} else {
|
|
184
|
-
requestId.value = requestAnimationFrame(step)
|
|
309
|
+
requestId.value = requestAnimationFrame(step)
|
|
185
310
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
311
|
+
|
|
312
|
+
prev = now
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
requestId.value = requestAnimationFrame(step)
|
|
189
316
|
} else {
|
|
190
|
-
stop()
|
|
317
|
+
stop()
|
|
191
318
|
}
|
|
192
319
|
}
|
|
193
|
-
|
|
194
|
-
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Pauses the countdown.
|
|
323
|
+
*/
|
|
324
|
+
function pause(): void {
|
|
325
|
+
cancelAnimationFrame(requestId.value)
|
|
195
326
|
}
|
|
196
|
-
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Progresses to countdown.
|
|
330
|
+
*/
|
|
331
|
+
function progress(): void {
|
|
197
332
|
if (!counting.value) {
|
|
198
|
-
return
|
|
333
|
+
return
|
|
199
334
|
}
|
|
200
|
-
|
|
335
|
+
|
|
336
|
+
update()
|
|
337
|
+
|
|
201
338
|
if (props.emitEvents && totalMilliseconds.value > 0) {
|
|
202
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Countdown progress event.
|
|
341
|
+
*/
|
|
342
|
+
emits('progress', {
|
|
203
343
|
days: days.value,
|
|
204
344
|
hours: hours.value,
|
|
205
345
|
minutes: minutes.value,
|
|
@@ -210,74 +350,114 @@ function progress() {
|
|
|
210
350
|
totalMinutes: totalMinutes.value,
|
|
211
351
|
totalSeconds: totalSeconds.value,
|
|
212
352
|
totalMilliseconds: totalMilliseconds.value
|
|
213
|
-
})
|
|
353
|
+
})
|
|
214
354
|
}
|
|
215
|
-
|
|
355
|
+
|
|
356
|
+
continueProcess()
|
|
216
357
|
}
|
|
217
|
-
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Aborts the countdown.
|
|
361
|
+
*/
|
|
362
|
+
function abort(): void {
|
|
218
363
|
if (!counting.value) {
|
|
219
|
-
return
|
|
364
|
+
return
|
|
220
365
|
}
|
|
221
|
-
|
|
222
|
-
|
|
366
|
+
|
|
367
|
+
pause()
|
|
368
|
+
counting.value = false
|
|
369
|
+
|
|
223
370
|
if (props.emitEvents) {
|
|
224
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Countdown abort event.
|
|
373
|
+
*/
|
|
374
|
+
emits('abort')
|
|
225
375
|
}
|
|
226
376
|
}
|
|
227
|
-
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Stop the countdown.
|
|
380
|
+
*/
|
|
381
|
+
function stop(): void {
|
|
228
382
|
if (!counting.value) {
|
|
229
|
-
return
|
|
383
|
+
return
|
|
230
384
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
385
|
+
|
|
386
|
+
pause()
|
|
387
|
+
totalMilliseconds.value = 0
|
|
388
|
+
counting.value = false
|
|
389
|
+
|
|
234
390
|
if (props.emitEvents) {
|
|
235
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Countdown end event.
|
|
393
|
+
*/
|
|
394
|
+
emits('end')
|
|
236
395
|
}
|
|
237
396
|
}
|
|
238
|
-
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Updates the count.
|
|
400
|
+
*/
|
|
401
|
+
function update(): void {
|
|
239
402
|
if (counting.value) {
|
|
240
|
-
totalMilliseconds.value = Math.max(0, endTime.value - props.now())
|
|
403
|
+
totalMilliseconds.value = Math.max(0, endTime.value - props.now())
|
|
241
404
|
}
|
|
242
405
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Restarts the count.
|
|
409
|
+
*/
|
|
410
|
+
function restart(): void {
|
|
411
|
+
pause()
|
|
412
|
+
totalMilliseconds.value = Number(props.seconds) * 1000
|
|
413
|
+
endTime.value = props.now() + Number(props.seconds) * 1000
|
|
414
|
+
counting.value = false
|
|
415
|
+
start()
|
|
249
416
|
}
|
|
250
|
-
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Visibility change event handler.
|
|
420
|
+
*/
|
|
421
|
+
function handleVisibilityChange(): void {
|
|
251
422
|
switch (document?.visibilityState) {
|
|
252
|
-
case
|
|
253
|
-
update()
|
|
254
|
-
continueProcess()
|
|
255
|
-
break
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
423
|
+
case 'visible':
|
|
424
|
+
update()
|
|
425
|
+
continueProcess()
|
|
426
|
+
break
|
|
427
|
+
|
|
428
|
+
case 'hidden':
|
|
429
|
+
pause()
|
|
430
|
+
break
|
|
259
431
|
}
|
|
260
432
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
433
|
+
// endregion ////
|
|
434
|
+
|
|
435
|
+
// region Round ////
|
|
436
|
+
const fullDashArray = computed((): string => {
|
|
437
|
+
const fullDashArray = 283
|
|
438
|
+
|
|
439
|
+
const calculateTimeFraction = (): number => {
|
|
264
440
|
if (Number(props.seconds) < 0) {
|
|
265
|
-
return 1
|
|
441
|
+
return 1
|
|
266
442
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
443
|
+
|
|
444
|
+
const rawTimeFraction = totalSeconds.value / Number(props.seconds)
|
|
445
|
+
return rawTimeFraction - (1 / Number(props.seconds)) * (1 - rawTimeFraction)
|
|
446
|
+
}
|
|
447
|
+
|
|
270
448
|
return [
|
|
271
|
-
(calculateTimeFraction() *
|
|
272
|
-
|
|
273
|
-
].join(
|
|
274
|
-
})
|
|
449
|
+
(calculateTimeFraction() * fullDashArray).toFixed(0),
|
|
450
|
+
fullDashArray
|
|
451
|
+
].join(' ')
|
|
452
|
+
})
|
|
453
|
+
// endregion ////
|
|
454
|
+
|
|
275
455
|
defineExpose({
|
|
276
456
|
start,
|
|
277
457
|
abort,
|
|
278
458
|
stop,
|
|
279
459
|
restart
|
|
280
|
-
})
|
|
460
|
+
})
|
|
281
461
|
</script>
|
|
282
462
|
|
|
283
463
|
<template>
|
|
@@ -311,12 +491,12 @@ defineExpose({
|
|
|
311
491
|
<slot name="leading">
|
|
312
492
|
<Component
|
|
313
493
|
:is="leadingIconName"
|
|
314
|
-
v-if="isLeading && typeof leadingIconName !== 'undefined'"
|
|
494
|
+
v-if="isLeading && (typeof leadingIconName !== 'undefined')"
|
|
315
495
|
:class="b24ui.leadingIcon({ class: props.b24ui?.leadingIcon })"
|
|
316
496
|
/>
|
|
317
497
|
<B24Avatar
|
|
318
498
|
v-else-if="!!avatar"
|
|
319
|
-
:size="props.b24ui?.leadingAvatarSize || b24ui.leadingAvatarSize()"
|
|
499
|
+
:size="((props.b24ui?.leadingAvatarSize || b24ui.leadingAvatarSize()) as AvatarProps['size'])"
|
|
320
500
|
v-bind="avatar"
|
|
321
501
|
:class="b24ui.leadingAvatar({ class: props.b24ui?.leadingAvatar })"
|
|
322
502
|
/>
|