', async () => {
const indexPath = path.resolve('index.md');
diff --git a/packages/vue-components/src/Pic.vue b/packages/vue-components/src/Pic.vue
index 2d17bba5a4..5218410180 100644
--- a/packages/vue-components/src/Pic.vue
+++ b/packages/vue-components/src/Pic.vue
@@ -5,8 +5,10 @@
:src="src"
:alt="alt"
:width="computedWidth"
+ :height="computedHeight"
+ :loading="computedLoadType"
class="img-fluid rounded"
- @load.once="computeWidth"
+ @load.once="computeWidthAndHeight"
/>
@@ -35,6 +37,10 @@ export default {
type: String,
default: '',
},
+ lazy: {
+ type: Boolean,
+ default: false,
+ },
addClass: {
type: String,
default: '',
@@ -53,20 +59,30 @@ export default {
}
return this.widthFromHeight;
},
+ computedHeight() {
+ return this.heightFromWidth;
+ },
+ computedLoadType() {
+ return this.lazy ? 'lazy' : 'eager';
+ },
},
data() {
return {
widthFromHeight: '',
+ heightFromWidth: '',
};
},
methods: {
- computeWidth() {
- if (!this.hasWidth && this.hasHeight) {
- const renderedImg = this.$refs.pic;
- const imgHeight = renderedImg.naturalHeight;
- const imgWidth = renderedImg.naturalWidth;
- const aspectRatio = imgWidth / imgHeight;
+ computeWidthAndHeight() {
+ const renderedImg = this.$refs.pic;
+ const imgHeight = renderedImg.naturalHeight;
+ const imgWidth = renderedImg.naturalWidth;
+ const aspectRatio = imgWidth / imgHeight;
+ if (this.hasWidth) { // if width is present, overwrite the height (if any) to maintain aspect ratio
+ this.heightFromWidth = Math.round(toNumber(this.width) / aspectRatio).toString();
+ } else if (this.hasHeight) {
this.widthFromHeight = Math.round(toNumber(this.height) * aspectRatio).toString();
+ this.heightFromWidth = this.height;
}
},
},
diff --git a/packages/vue-components/src/__tests__/__snapshots__/Annotation.spec.js.snap b/packages/vue-components/src/__tests__/__snapshots__/Annotation.spec.js.snap
index 318783c4b1..8b8bfe2693 100644
--- a/packages/vue-components/src/__tests__/__snapshots__/Annotation.spec.js.snap
+++ b/packages/vue-components/src/__tests__/__snapshots__/Annotation.spec.js.snap
@@ -6,6 +6,8 @@ exports[`Annotation with customised annotation points 1`] = `
>
@@ -92,6 +94,8 @@ exports[`Annotation with different visual annotation points 1`] = `
>
@@ -380,6 +384,8 @@ exports[`Annotation with markdown in header, content and label 1`] = `
>
diff --git a/packages/vue-components/src/annotations/Annotate.vue b/packages/vue-components/src/annotations/Annotate.vue
index 62235637c6..528b560d3c 100644
--- a/packages/vue-components/src/annotations/Annotate.vue
+++ b/packages/vue-components/src/annotations/Annotate.vue
@@ -5,8 +5,10 @@
:src="src"
:alt="alt"
:width="computedWidth"
+ :height="computedHeight"
+ :loading="computedLoadType"
class="annotate-image"
- @load.once="getWidth"
+ @load.once="computeWidthAndHeight"
/>
@@ -35,6 +37,10 @@ export default {
type: String,
default: '',
},
+ lazy: {
+ type: Boolean,
+ default: false,
+ },
addClass: {
type: String,
default: '',
@@ -53,20 +59,30 @@ export default {
}
return this.widthFromHeight;
},
+ computedHeight() {
+ return this.heightFromWidth;
+ },
+ computedLoadType() {
+ return this.lazy ? 'lazy' : 'eager';
+ },
},
data() {
return {
widthFromHeight: '',
+ heightFromWidth: '',
};
},
methods: {
- getWidth() {
- if (!this.hasWidth && this.hasHeight) {
- const renderedImg = this.$refs.pic;
- const imgHeight = renderedImg.naturalHeight;
- const imgWidth = renderedImg.naturalWidth;
- const imageAspectRatio = imgWidth / imgHeight;
- this.widthFromHeight = Math.round(toNumber(this.height) * imageAspectRatio);
+ computeWidthAndHeight() {
+ const renderedImg = this.$refs.pic;
+ const imgHeight = renderedImg.naturalHeight;
+ const imgWidth = renderedImg.naturalWidth;
+ const aspectRatio = imgWidth / imgHeight;
+ if (this.hasWidth) { // if width is present, overwrite the height (if any) to maintain aspect ratio
+ this.heightFromWidth = Math.round(toNumber(this.width) / aspectRatio).toString();
+ } else if (this.hasHeight) {
+ this.widthFromHeight = Math.round(toNumber(this.height) * aspectRatio).toString();
+ this.heightFromWidth = this.height;
}
},
},