@lancom/shared 0.0.474 → 0.0.475
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.
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const IMAGE_VARIANTS = {
|
|
2
|
+
PUBLIC: 'public'
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
const DOMAIN = 'imagedelivery.net';
|
|
6
|
+
|
|
7
|
+
export function getCloudflareImageSrc(cloudflareImageId, variant = IMAGE_VARIANTS.PUBLIC) {
|
|
8
|
+
const accountHash = process.env.CLOUDFLARE_ACCOUNT_HASH;
|
|
9
|
+
const src = (cloudflareImageId || '').split("\n")[0].trim();
|
|
10
|
+
return src ? `https://${DOMAIN}/${accountHash}/${src}${src.includes('/') ? '' : `/${variant}`}` : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getCloudflareImageSrcset(cloudflareImageId) {
|
|
14
|
+
const lines = (cloudflareImageId || '').split("\n").map(l => l.trim()).filter(Boolean);
|
|
15
|
+
if (lines.length < 2) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return lines.map(line => {
|
|
20
|
+
const [idPart, descriptor] = line.split('|');
|
|
21
|
+
const src = getCloudflareImageSrc(idPart.trim());
|
|
22
|
+
return descriptor ? `${src} ${descriptor.trim()}` : src;
|
|
23
|
+
}).join(', ');
|
|
24
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<img
|
|
3
|
+
:src="resolvedSrc"
|
|
4
|
+
:srcset="resolvedSrcset || undefined"
|
|
5
|
+
:alt="alt"
|
|
6
|
+
:loading="loading"
|
|
7
|
+
:decoding="decoding"
|
|
8
|
+
:class="imgClass" />
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
import { getCloudflareImageSrc, getCloudflareImageSrcset } from '../../assets/js/utils/image';
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
name: 'LancomImage',
|
|
16
|
+
props: {
|
|
17
|
+
image: {
|
|
18
|
+
type: Object,
|
|
19
|
+
default: null
|
|
20
|
+
},
|
|
21
|
+
overrideSrc: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: null
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: 'large'
|
|
28
|
+
},
|
|
29
|
+
alt: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: ''
|
|
32
|
+
},
|
|
33
|
+
loading: {
|
|
34
|
+
type: String,
|
|
35
|
+
default: 'lazy'
|
|
36
|
+
},
|
|
37
|
+
decoding: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: 'async'
|
|
40
|
+
},
|
|
41
|
+
imgClass: {
|
|
42
|
+
type: [String, Object, Array],
|
|
43
|
+
default: null
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
computed: {
|
|
47
|
+
resolvedSrc() {
|
|
48
|
+
if (this.overrideSrc) return this.overrideSrc;
|
|
49
|
+
if (!this.image) return null;
|
|
50
|
+
const { large, medium, small, thumb, origin, cloudflareImageId } = this.image;
|
|
51
|
+
return this.image[this.size] || large || medium || small || thumb || origin || getCloudflareImageSrc(cloudflareImageId);
|
|
52
|
+
},
|
|
53
|
+
resolvedSrcset() {
|
|
54
|
+
if (this.overrideSrc) return null;
|
|
55
|
+
return getCloudflareImageSrcset(this.image?.cloudflareImageId);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
</script>
|