@bagelink/vue 0.0.726 → 0.0.728

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.
@@ -1,4 +1,4 @@
1
- import type { App, DirectiveBinding } from 'vue'
1
+ import type { App, Directive, DirectiveBinding } from 'vue'
2
2
  import { createApp } from 'vue'
3
3
  import { IMAGE_FORMATS_REGEXP, VIDEO_FORMATS_REGEXP } from '@bagelink/vue'
4
4
  import Lightbox from './Lightbox.vue'
@@ -6,44 +6,37 @@ import type { LightboxItem } from './lightbox.types'
6
6
 
7
7
  type OpenFunction = (item: LightboxItem, groupItems?: LightboxItem[]) => void
8
8
  const groups: Record<string, LightboxItem[]> = {}
9
- const lightboxDirective = {
10
- mounted(el: HTMLElement, binding: DirectiveBinding) {
11
- const lightboxInstance = createLightboxInstance()
12
- if (!lightboxInstance || !lightboxInstance.open) return
13
- if (binding.value.group) {
14
- if (!groups[binding.value.group]) groups[binding.value.group] = []
15
- const src = binding.value.src || binding.value || el.getAttribute('src') || ''
16
- groups[binding.value.group].push({
17
- src,
18
- type: binding.value.type || determineFileType(src),
19
- name: binding.value.name || ''
20
- })
9
+ const lightboxDirective: Directive = {
10
+ mounted(el: HTMLElement, binding) {
11
+ el.classList.add('hover')
12
+ let { group, src, type, name, thumbnail } = binding.value || {}
13
+ src = src || binding.value || el.getAttribute('src') || ''
14
+ type = type || determineFileType(src)
15
+ const item: LightboxItem = { src, type, name, thumbnail }
16
+ if (group) {
17
+ if (!groups[group]) groups[group] = []
18
+ groups[group].push(item)
21
19
  }
22
20
  el.addEventListener('click', (e) => {
23
21
  e.stopPropagation()
24
- const group = binding.value.group || null
25
- const item: LightboxItem = {
26
- src: binding.value.src || binding.value,
27
- type: binding.value.type || determineFileType(binding.value.src || binding.value),
28
- name: binding.value.name || '',
29
- thumbnail: binding.value.thumbnail || '',
30
- }
31
22
  const lightboxInstance = createLightboxInstance()
32
23
  if (!lightboxInstance || !lightboxInstance.open) return
33
- if (binding.value.group) {
34
- if (!groups[binding.value.group]) groups[binding.value.group] = []
35
- groups[binding.value.group].push(item)
36
- }
37
24
  const open = lightboxInstance.open as OpenFunction
38
25
  open(item, groups[group])
39
26
  })
40
27
  },
28
+ unmounted(el: HTMLElement, binding) {
29
+ // TODO: remove click event handler
30
+ }
41
31
  }
42
32
 
33
+ const youtubeRegex = /youtube\.com|youtu\.be/
34
+ const vimeoRegex = /vimeo\.com/
35
+
43
36
  function determineFileType(url: string): string {
44
37
  const extension = url.split('.').pop()?.toLowerCase() || ''
45
38
  if (IMAGE_FORMATS_REGEXP.test(extension)) return 'image'
46
- if (VIDEO_FORMATS_REGEXP.test(extension)) return 'video'
39
+ if (VIDEO_FORMATS_REGEXP.test(extension) || youtubeRegex.test(url) || vimeoRegex.test(url)) return 'video'
47
40
  if (['pdf'].includes(extension)) return 'pdf'
48
41
  return 'unknown'
49
42
  }
@@ -34,6 +34,24 @@
34
34
  height: fit-content;
35
35
  }
36
36
 
37
+ .is-active .modal {
38
+ animation: 200ms ease bgl-modal-animation;
39
+
40
+ }
41
+
42
+ @keyframes bgl-modal-animation {
43
+ from {
44
+ scale: 0.7;
45
+ transform: translateY(2rem);
46
+ }
47
+
48
+ to {
49
+ scale: 1;
50
+ transform: translateY(0);
51
+
52
+ }
53
+ }
54
+
37
55
  .small-modal .modal {
38
56
  max-width: 300px;
39
57
  text-align: center;