@proj-airi/ui 0.7.2-beta.1 → 0.7.2-beta.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@proj-airi/ui",
3
3
  "type": "module",
4
- "version": "0.7.2-beta.1",
4
+ "version": "0.7.2-beta.2",
5
5
  "description": "A collection of UI components that used by Project AIRI",
6
6
  "author": {
7
7
  "name": "Moeru AI Project AIRI Team",
@@ -48,6 +48,9 @@ function getElementStyle(element: HTMLElement) {
48
48
  }
49
49
  }
50
50
 
51
+ let animation: Animation | null = null
52
+ let lastElement: HTMLElement | null = null
53
+
51
54
  function prepareElement(element: HTMLElement, initialStyle: initialStyle) {
52
55
  const { width } = getComputedStyle(element)
53
56
  element.style.width = width
@@ -72,7 +75,8 @@ function animateTransition(
72
75
  keyframes: Keyframe[] | PropertyIndexedKeyframes | null,
73
76
  options?: number | KeyframeAnimationOptions,
74
77
  ) {
75
- const animation = element.animate(keyframes, options)
78
+ lastElement = element
79
+ animation = element.animate(keyframes, options)
76
80
  // Set height to 'auto' to restore it after animation
77
81
  element.style.height = initialStyle.height
78
82
  animation.onfinish = () => {
@@ -106,9 +110,26 @@ function getEnterKeyframes(height: string, initialStyle: initialStyle) {
106
110
  ]
107
111
  }
108
112
 
113
+ function cancelAnimation(HTMLElement: HTMLElement, overflow: string, done: () => void) {
114
+ if (HTMLElement !== lastElement)
115
+ return false
116
+ if (!animation)
117
+ return false
118
+ if (animation.playState !== 'running')
119
+ return false
120
+ animation.onfinish = () => {
121
+ HTMLElement.style.overflow = overflow
122
+ done()
123
+ }
124
+ animation.reverse()
125
+ return true
126
+ }
127
+
109
128
  function enterTransition(element: Element, done: () => void) {
110
129
  const HTMLElement = element as HTMLElement
111
130
  const initialStyle = getElementStyle(HTMLElement)
131
+ if (cancelAnimation(HTMLElement, initialStyle.overflow, done))
132
+ return
112
133
  const height = prepareElement(HTMLElement, initialStyle)
113
134
  const keyframes = getEnterKeyframes(height, initialStyle)
114
135
  const options = { duration: props.duration, easing: props.easingEnter }
@@ -118,6 +139,8 @@ function enterTransition(element: Element, done: () => void) {
118
139
  function leaveTransition(element: Element, done: () => void) {
119
140
  const HTMLElement = element as HTMLElement
120
141
  const initialStyle = getElementStyle(HTMLElement)
142
+ if (cancelAnimation(HTMLElement, initialStyle.overflow, done))
143
+ return
121
144
  const { height } = getComputedStyle(HTMLElement)
122
145
  HTMLElement.style.height = height
123
146
  HTMLElement.style.overflow = 'hidden'
@@ -17,13 +17,20 @@ const isDragging = ref(false)
17
17
  const isDraggingDebounced = useDebounce(isDragging, 150)
18
18
 
19
19
  function handleFileChange(e: Event) {
20
+ files.value = []
21
+
20
22
  const input = e.target as HTMLInputElement
23
+ if (!input.files)
24
+ return
25
+
26
+ for (let i = 0; i < input.files?.length; i++) {
27
+ files.value.push(input.files[i])
28
+ }
21
29
 
22
- if (input.files && input.files.length > 0) {
23
- firstFile.value = input.files[0]
30
+ if (files.value && files.value.length > 0) {
31
+ firstFile.value = files.value[0]
24
32
  }
25
33
 
26
- files.value = Array.from(input.files || [])
27
34
  isDragging.value = false
28
35
  }
29
36
  </script>
@@ -44,7 +51,7 @@ function handleFileChange(e: Event) {
44
51
  type="file"
45
52
  :accept="accept"
46
53
  :multiple="multiple"
47
- class="absolute inset-0 cursor-pointer appearance-none opacity-0"
54
+ class="absolute inset-0 h-0 w-0 cursor-pointer appearance-none opacity-0"
48
55
  @change="handleFileChange"
49
56
  >
50
57
  <slot :is-dragging="isDraggingDebounced" :first-file="firstFile" :files="files" />