@veritree/ui 0.26.0-0 → 0.26.1-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.26.0-0",
3
+ "version": "0.26.1-0",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,14 +1,7 @@
1
1
  <template>
2
2
  <img
3
- :src="srcComputed"
4
- :class="[
5
- headless ? null : isLoaded ? null : 'animate-pulse',
6
- headless
7
- ? null
8
- : hasObjectFit
9
- ? `h-full w-full ${objectFitComputed}`
10
- : null,
11
- ]"
3
+ :src="srcLoaded"
4
+ :class="classComputed"
12
5
  v-bind="$attrs"
13
6
  @load="onLoad"
14
7
  @error="onError"
@@ -18,6 +11,7 @@
18
11
  <script>
19
12
  import { handleImageResizing } from '../../utils/images';
20
13
 
14
+ // @ts-ignore
21
15
  export default {
22
16
  name: 'VTImage',
23
17
 
@@ -48,37 +42,17 @@ export default {
48
42
  return {
49
43
  canLoad: true,
50
44
  isLoaded: false,
45
+ srcLoaded: this.placeholder,
51
46
  };
52
47
  },
53
48
 
54
49
  computed: {
55
- srcComputed() {
56
- if (!this.isLoaded) {
57
- return this.placeholder;
58
- } else {
59
- if (!this.canLoad) {
60
- return this.placeholder;
61
- }
62
-
63
- if (this.src) {
64
- return this.src.includes('cloudfront.net/')
65
- ? handleImageResizing(this.src, this.$attrs.width)
66
- : this.src;
67
- }
68
-
69
- if (this.cdnSrc) {
70
- return handleImageResizing(this.cdnSrc, this.$attrs.width);
71
- }
72
- }
73
-
74
- return null;
75
- },
76
-
77
50
  hasObjectFit() {
78
51
  return this.objectFit;
79
52
  },
80
53
 
81
54
  objectFitComputed() {
55
+ // @ts-ignore
82
56
  return this.hasObjectFit
83
57
  ? this.objectFit === 'cover'
84
58
  ? 'object-cover'
@@ -87,17 +61,55 @@ export default {
87
61
  : null
88
62
  : null;
89
63
  },
64
+
65
+ classComputed() {
66
+ let classList = [];
67
+
68
+ if (!this.headless) {
69
+ if (!this.isLoaded) {
70
+ classList.push('animate-pulse');
71
+ }
72
+
73
+ // @ts-ignore
74
+ if (this.hasObjectFit) {
75
+ classList.push('h-full', 'w-full', this.objectFitComputed);
76
+ }
77
+ }
78
+
79
+ // Remove 'animate-pulse' if isLoaded is true
80
+ if (this.isLoaded && classList.includes('animate-pulse')) {
81
+ classList.splice(classList.indexOf('animate-pulse'), 1);
82
+ }
83
+
84
+ return classList.length > 0 ? classList.join(' ') : null;
85
+ },
86
+ },
87
+
88
+ mounted() {
89
+ this.handleImage();
90
90
  },
91
91
 
92
92
  methods: {
93
+ handleImage() {
94
+ if (this.src) {
95
+ this.srcLoaded = this.src.includes('cloudfront.net/')
96
+ ? handleImageResizing(this.src, this.$attrs.width)
97
+ : this.src;
98
+ }
99
+
100
+ if (this.cdnSrc) {
101
+ this.srcLoaded = handleImageResizing(this.cdnSrc, this.$attrs.width);
102
+ }
103
+ },
104
+
93
105
  handleImageResizing,
94
106
 
95
107
  onLoad() {
96
108
  this.isLoaded = true;
109
+ this.$emit('loaded');
97
110
  },
98
111
 
99
112
  onError() {
100
- this.canLoad = false;
101
113
  this.$emit('error');
102
114
  },
103
115
  },