@veritree/ui 0.11.0 → 0.12.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 +1 -1
- package/src/Image/VTImage.vue +7 -3
- package/src/utils/images.js +38 -0
package/package.json
CHANGED
package/src/Image/VTImage.vue
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
</template>
|
|
10
10
|
|
|
11
11
|
<script>
|
|
12
|
-
import {
|
|
12
|
+
import { handleImageResizing } from "../utils/images";
|
|
13
13
|
|
|
14
14
|
export default {
|
|
15
15
|
name: "VTImage",
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (this.cdnSrc) {
|
|
49
|
-
return this.
|
|
49
|
+
return this.handleImageResizing(this.cdnSrc, this.$attrs.width);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (this.src) {
|
|
@@ -58,8 +58,12 @@ export default {
|
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
60
|
|
|
61
|
+
mounted() {
|
|
62
|
+
console.log("mounted");
|
|
63
|
+
},
|
|
64
|
+
|
|
61
65
|
methods: {
|
|
62
|
-
|
|
66
|
+
handleImageResizing,
|
|
63
67
|
|
|
64
68
|
onLoad() {
|
|
65
69
|
this.isLoaded = true;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const handleImageResizing = (url, width) => {
|
|
2
|
+
// early exit if url is null for whatever reason
|
|
3
|
+
if (!url) {
|
|
4
|
+
return '';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
let cdn;
|
|
8
|
+
|
|
9
|
+
if (typeof url === 'object') {
|
|
10
|
+
cdn = url.cdn_url;
|
|
11
|
+
} else if (typeof url === 'string') {
|
|
12
|
+
cdn = JSON.parse(url).cdn_url;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const base64String = cdn.split('net/');
|
|
16
|
+
const firstPart = base64String[0];
|
|
17
|
+
|
|
18
|
+
// if atob is crossed and your editor says is not supported,
|
|
19
|
+
// don't worry, it seems to be about NodeJS and not about
|
|
20
|
+
// browsers.
|
|
21
|
+
//
|
|
22
|
+
// Details: https://developer.mozilla.org/en-US/docs/Web/API/atob
|
|
23
|
+
const decodedString = JSON.parse(atob(base64String[1]));
|
|
24
|
+
|
|
25
|
+
width
|
|
26
|
+
? (decodedString.edits.resize.width = width)
|
|
27
|
+
: (decodedString.edits.resize.width = 450);
|
|
28
|
+
|
|
29
|
+
// if btoa is crossed and your editor says is not supported,
|
|
30
|
+
// don't worry, it seems to be about NodeJS and not about
|
|
31
|
+
// browsers.
|
|
32
|
+
//
|
|
33
|
+
// Details: https://developer.mozilla.org/en-US/docs/Web/API/atob
|
|
34
|
+
const encodedString = btoa(JSON.stringify(decodedString));
|
|
35
|
+
const encodedUrl = `${firstPart}net/${encodedString}`;
|
|
36
|
+
|
|
37
|
+
return encodedUrl;
|
|
38
|
+
};
|