@prismicio/vue 5.2.1 → 5.3.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/README.md +1 -1
- package/dist/PrismicImage.vue.cjs +31 -3
- package/dist/PrismicImage.vue.cjs.map +1 -1
- package/dist/PrismicImage.vue.d.ts +70 -0
- package/dist/PrismicImage.vue.js +31 -3
- package/dist/PrismicImage.vue.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +1 -1
- package/src/PrismicImage.vue +54 -1
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ For more clarity on this project and its structure you can also check out the de
|
|
|
73
73
|
|
|
74
74
|
<!-- Replace link with a more useful one if available -->
|
|
75
75
|
|
|
76
|
-
[prismic-docs]: https://prismic.io/docs/
|
|
76
|
+
[prismic-docs]: https://prismic.io/docs/technical-reference/prismicio-vue/v5
|
|
77
77
|
[changelog]: ./CHANGELOG.md
|
|
78
78
|
[contributing]: ./CONTRIBUTING.md
|
|
79
79
|
[vue]: https://v3.vuejs.org
|
|
@@ -4,7 +4,7 @@ const client = require("@prismicio/client");
|
|
|
4
4
|
const esmEnv = require("esm-env");
|
|
5
5
|
const devMsg = require("./lib/devMsg.cjs");
|
|
6
6
|
const usePrismic = require("./usePrismic.cjs");
|
|
7
|
-
const _hoisted_1 = ["src", "srcset", "alt"];
|
|
7
|
+
const _hoisted_1 = ["src", "srcset", "alt", "width", "height"];
|
|
8
8
|
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
9
9
|
...{ name: "PrismicImage" },
|
|
10
10
|
__name: "PrismicImage",
|
|
@@ -13,6 +13,8 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
13
13
|
imgixParams: {},
|
|
14
14
|
alt: {},
|
|
15
15
|
fallbackAlt: {},
|
|
16
|
+
width: {},
|
|
17
|
+
height: {},
|
|
16
18
|
widths: {},
|
|
17
19
|
pixelDensities: {}
|
|
18
20
|
},
|
|
@@ -42,6 +44,18 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
42
44
|
}
|
|
43
45
|
});
|
|
44
46
|
}
|
|
47
|
+
const castInt = (input) => {
|
|
48
|
+
if (typeof input === "number" || typeof input === "undefined") {
|
|
49
|
+
return input;
|
|
50
|
+
} else {
|
|
51
|
+
const parsed = Number.parseInt(input);
|
|
52
|
+
if (Number.isNaN(parsed)) {
|
|
53
|
+
return void 0;
|
|
54
|
+
} else {
|
|
55
|
+
return parsed;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
45
59
|
const image = vue.computed(() => {
|
|
46
60
|
var _a, _b;
|
|
47
61
|
if (!client.isFilled.imageThumbnail(props.field)) {
|
|
@@ -64,10 +78,22 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
64
78
|
src = res.src;
|
|
65
79
|
srcSet = res.srcset;
|
|
66
80
|
}
|
|
81
|
+
const ar = props.field.dimensions.width / props.field.dimensions.height;
|
|
82
|
+
const castedWidth = castInt(props.width);
|
|
83
|
+
const castedHeight = castInt(props.height);
|
|
84
|
+
let resolvedWidth = castedWidth ?? props.field.dimensions.width;
|
|
85
|
+
let resolvedHeight = castedHeight ?? props.field.dimensions.height;
|
|
86
|
+
if (castedWidth != null && castedHeight == null) {
|
|
87
|
+
resolvedHeight = castedWidth / ar;
|
|
88
|
+
} else if (castedWidth == null && castedHeight != null) {
|
|
89
|
+
resolvedWidth = castedHeight * ar;
|
|
90
|
+
}
|
|
67
91
|
return {
|
|
68
92
|
src,
|
|
69
93
|
srcSet,
|
|
70
|
-
alt: props.alt ?? (props.field.alt || props.fallbackAlt)
|
|
94
|
+
alt: props.alt ?? (props.field.alt || props.fallbackAlt),
|
|
95
|
+
width: Math.round(resolvedWidth),
|
|
96
|
+
height: Math.round(resolvedHeight)
|
|
71
97
|
};
|
|
72
98
|
});
|
|
73
99
|
return (_ctx, _cache) => {
|
|
@@ -75,7 +101,9 @@ const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
|
75
101
|
key: 0,
|
|
76
102
|
src: image.value.src,
|
|
77
103
|
srcset: image.value.srcSet,
|
|
78
|
-
alt: image.value.alt
|
|
104
|
+
alt: image.value.alt,
|
|
105
|
+
width: image.value.width,
|
|
106
|
+
height: image.value.height
|
|
79
107
|
}, null, 8, _hoisted_1)) : vue.createCommentVNode("", true);
|
|
80
108
|
};
|
|
81
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicImage.vue.cjs","sources":["../src/PrismicImage.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { ImageField, asImageSrc } from \"@prismicio/client\"\nimport {\n\tasImagePixelDensitySrcSet,\n\tasImageWidthSrcSet,\n\tisFilled,\n} from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport { computed, watchEffect } from \"vue\"\n\nimport { devMsg } from \"./lib/devMsg\"\n\nimport { usePrismic } from \"./usePrismic\"\n\n/**\n * Props for `<PrismicImage />`.\n */\nexport type PrismicImageProps = {\n\t/**\n\t * The Prismic image field or thumbnail to render.\n\t */\n\tfield: ImageField | ImageField<string>\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * See: https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: Parameters<typeof asImageSrc>[1]\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\"\n\n\t/**\n\t * Declare an image as decorative only if the image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\"\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * Widths used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `widths` prop is not given or `\"defaults\"` is passed, the\n\t\t\t * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,\n\t\t\t * 3840.\n\t\t\t *\n\t\t\t * If the image field contains responsive views, each responsive view can\n\t\t\t * be used as a width in the resulting `srcset` by passing `\"thumbnails\"`\n\t\t\t * as the `widths` prop.\n\t\t\t */\n\t\t\twidths?:\n\t\t\t\t| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>[\"widths\"]\n\t\t\t\t| \"thumbnails\"\n\t\t\t\t| \"defaults\"\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\tpixelDensities?: never\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\twidths?: never\n\t\t\t/**\n\t\t\t * Pixel densities used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `pixelDensities` prop is passed `\"defaults\"`, the following pixel\n\t\t\t * densities will be used: 1, 2, 3.\n\t\t\t */\n\t\t\tpixelDensities:\n\t\t\t\t| NonNullable<\n\t\t\t\t\t\tParameters<typeof asImagePixelDensitySrcSet>[1]\n\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t| \"defaults\"\n\t }\n)\n\nconst props = defineProps<PrismicImageProps>()\ndefineOptions({ name: \"PrismicImage\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\twatchEffect(() => {\n\t\tif (typeof props.alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (typeof props.fallbackAlt === \"string\" && props.fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (props.widths && props.pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\n\t\t\t)\n\t\t}\n\t})\n}\n\nconst image = computed(() => {\n\tif (!isFilled.imageThumbnail(props.field)) {\n\t\treturn\n\t}\n\n\tlet src: string | undefined\n\tlet srcSet: string | undefined\n\tif (props.widths || !props.pixelDensities) {\n\t\tconst res = asImageWidthSrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\twidths:\n\t\t\t\tprops.widths === \"defaults\"\n\t\t\t\t\t? options.components?.imageWidthSrcSetDefaults\n\t\t\t\t\t: props.widths,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t} else if (props.pixelDensities) {\n\t\tconst res = asImagePixelDensitySrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\tpixelDensities:\n\t\t\t\tprops.pixelDensities === \"defaults\"\n\t\t\t\t\t? options.components?.imagePixelDensitySrcSetDefaults\n\t\t\t\t\t: props.pixelDensities,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t}\n\n\treturn {\n\t\tsrc,\n\t\tsrcSet,\n\t\talt: props.alt ?? (props.field.alt || props.fallbackAlt),\n\t}\n})\n</script>\n\n<template>\n\t<img
|
|
1
|
+
{"version":3,"file":"PrismicImage.vue.cjs","sources":["../src/PrismicImage.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { ImageField, asImageSrc } from \"@prismicio/client\"\nimport {\n\tasImagePixelDensitySrcSet,\n\tasImageWidthSrcSet,\n\tisFilled,\n} from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport { computed, watchEffect } from \"vue\"\n\nimport { devMsg } from \"./lib/devMsg\"\n\nimport { usePrismic } from \"./usePrismic\"\n\n/**\n * Props for `<PrismicImage />`.\n */\nexport type PrismicImageProps = {\n\t/**\n\t * The Prismic image field or thumbnail to render.\n\t */\n\tfield: ImageField | ImageField<string>\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * See: https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: Parameters<typeof asImageSrc>[1]\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\"\n\n\t/**\n\t * Declare an image as decorative only if the image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\"\n\n\t/**\n\t * The width attribute of the image element.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width\n\t */\n\twidth?: number | string\n\n\t/**\n\t * The height attribute of the image element.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height\n\t */\n\theight?: number | string\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * Widths used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `widths` prop is not given or `\"defaults\"` is passed, the\n\t\t\t * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,\n\t\t\t * 3840.\n\t\t\t *\n\t\t\t * If the image field contains responsive views, each responsive view can\n\t\t\t * be used as a width in the resulting `srcset` by passing `\"thumbnails\"`\n\t\t\t * as the `widths` prop.\n\t\t\t */\n\t\t\twidths?:\n\t\t\t\t| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>[\"widths\"]\n\t\t\t\t| \"thumbnails\"\n\t\t\t\t| \"defaults\"\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\tpixelDensities?: never\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\twidths?: never\n\t\t\t/**\n\t\t\t * Pixel densities used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `pixelDensities` prop is passed `\"defaults\"`, the following pixel\n\t\t\t * densities will be used: 1, 2, 3.\n\t\t\t */\n\t\t\tpixelDensities:\n\t\t\t\t| NonNullable<\n\t\t\t\t\t\tParameters<typeof asImagePixelDensitySrcSet>[1]\n\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t| \"defaults\"\n\t }\n)\n\nconst props = defineProps<PrismicImageProps>()\ndefineOptions({ name: \"PrismicImage\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\twatchEffect(() => {\n\t\tif (typeof props.alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (typeof props.fallbackAlt === \"string\" && props.fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (props.widths && props.pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\n\t\t\t)\n\t\t}\n\t})\n}\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input\n\t} else {\n\t\tconst parsed = Number.parseInt(input)\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined\n\t\t} else {\n\t\t\treturn parsed\n\t\t}\n\t}\n}\n\nconst image = computed(() => {\n\tif (!isFilled.imageThumbnail(props.field)) {\n\t\treturn\n\t}\n\n\tlet src: string | undefined\n\tlet srcSet: string | undefined\n\tif (props.widths || !props.pixelDensities) {\n\t\tconst res = asImageWidthSrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\twidths:\n\t\t\t\tprops.widths === \"defaults\"\n\t\t\t\t\t? options.components?.imageWidthSrcSetDefaults\n\t\t\t\t\t: props.widths,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t} else if (props.pixelDensities) {\n\t\tconst res = asImagePixelDensitySrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\tpixelDensities:\n\t\t\t\tprops.pixelDensities === \"defaults\"\n\t\t\t\t\t? options.components?.imagePixelDensitySrcSetDefaults\n\t\t\t\t\t: props.pixelDensities,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t}\n\n\tconst ar = props.field.dimensions.width / props.field.dimensions.height\n\n\tconst castedWidth = castInt(props.width)\n\tconst castedHeight = castInt(props.height)\n\n\tlet resolvedWidth = castedWidth ?? props.field.dimensions.width\n\tlet resolvedHeight = castedHeight ?? props.field.dimensions.height\n\n\tif (castedWidth != null && castedHeight == null) {\n\t\tresolvedHeight = castedWidth / ar\n\t} else if (castedWidth == null && castedHeight != null) {\n\t\tresolvedWidth = castedHeight * ar\n\t}\n\n\treturn {\n\t\tsrc,\n\t\tsrcSet,\n\t\talt: props.alt ?? (props.field.alt || props.fallbackAlt),\n\t\twidth: Math.round(resolvedWidth),\n\t\theight: Math.round(resolvedHeight),\n\t}\n})\n</script>\n\n<template>\n\t<img\n\t\tv-if=\"image\"\n\t\t:src=\"image.src\"\n\t\t:srcset=\"image.srcSet\"\n\t\t:alt=\"image.alt\"\n\t\t:width=\"image.width\"\n\t\t:height=\"image.height\"\n\t/>\n</template>\n"],"names":["usePrismic","DEV","watchEffect","devMsg","computed","isFilled","asImageWidthSrcSet","asImagePixelDensitySrcSet"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuGA,UAAM,QAAQ;AAGR,UAAA,EAAE,QAAQ,IAAIA,sBAAW;AAE/B,QAAIC,YAAK;AACRC,UAAAA,YAAY,MAAM;AACjB,YAAI,OAAO,MAAM,QAAQ,YAAY,MAAM,QAAQ,IAAI;AAC9C,kBAAA;AAAA,YACP,qQAAqQC,OAAA;AAAA,cACpQ;AAAA,YAAA,CACA;AAAA,UACF;AAAA,QAAA;AAGD,YAAI,OAAO,MAAM,gBAAgB,YAAY,MAAM,gBAAgB,IAAI;AAC9D,kBAAA;AAAA,YACP,qSAAqSA,OAAA;AAAA,cACpS;AAAA,YAAA,CACA;AAAA,UACF;AAAA,QAAA;AAGG,YAAA,MAAM,UAAU,MAAM,gBAAgB;AACjC,kBAAA;AAAA,YACP;AAAA,UACD;AAAA,QAAA;AAAA,MACD,CACA;AAAA,IAAA;AAGI,UAAA,UAAU,CAAC,UAA2D;AAC3E,UAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,eAAA;AAAA,MAAA,OACD;AACA,cAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,YAAA,OAAO,MAAM,MAAM,GAAG;AAClB,iBAAA;AAAA,QAAA,OACD;AACC,iBAAA;AAAA,QAAA;AAAA,MACR;AAAA,IAEF;AAEM,UAAA,QAAQC,IAAAA,SAAS,MAAM;;AAC5B,UAAI,CAACC,OAAAA,SAAS,eAAe,MAAM,KAAK,GAAG;AAC1C;AAAA,MAAA;AAGG,UAAA;AACA,UAAA;AACJ,UAAI,MAAM,UAAU,CAAC,MAAM,gBAAgB;AACpC,cAAA,MAAMC,OAAAA,mBAAmB,MAAM,OAAO;AAAA,UAC3C,GAAG,MAAM;AAAA,UACT,QACC,MAAM,WAAW,cACd,aAAQ,eAAR,mBAAoB,2BACpB,MAAM;AAAA,QAAA,CACV;AAED,cAAM,IAAI;AACV,iBAAS,IAAI;AAAA,MAAA,WACH,MAAM,gBAAgB;AAC1B,cAAA,MAAMC,OAAAA,0BAA0B,MAAM,OAAO;AAAA,UAClD,GAAG,MAAM;AAAA,UACT,gBACC,MAAM,mBAAmB,cACtB,aAAQ,eAAR,mBAAoB,kCACpB,MAAM;AAAA,QAAA,CACV;AAED,cAAM,IAAI;AACV,iBAAS,IAAI;AAAA,MAAA;AAGd,YAAM,KAAK,MAAM,MAAM,WAAW,QAAQ,MAAM,MAAM,WAAW;AAE3D,YAAA,cAAc,QAAQ,MAAM,KAAK;AACjC,YAAA,eAAe,QAAQ,MAAM,MAAM;AAEzC,UAAI,gBAAgB,eAAe,MAAM,MAAM,WAAW;AAC1D,UAAI,iBAAiB,gBAAgB,MAAM,MAAM,WAAW;AAExD,UAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,yBAAiB,cAAc;AAAA,MACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,wBAAgB,eAAe;AAAA,MAAA;AAGzB,aAAA;AAAA,QACN;AAAA,QACA;AAAA,QACA,KAAK,MAAM,QAAQ,MAAM,MAAM,OAAO,MAAM;AAAA,QAC5C,OAAO,KAAK,MAAM,aAAa;AAAA,QAC/B,QAAQ,KAAK,MAAM,cAAc;AAAA,MAClC;AAAA,IAAA,CACA;;;;;;;;;;;;;;"}
|
|
@@ -28,6 +28,20 @@ export type PrismicImageProps = {
|
|
|
28
28
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
29
|
*/
|
|
30
30
|
fallbackAlt?: "";
|
|
31
|
+
/**
|
|
32
|
+
* The width attribute of the image element.
|
|
33
|
+
*
|
|
34
|
+
* See:
|
|
35
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width
|
|
36
|
+
*/
|
|
37
|
+
width?: number | string;
|
|
38
|
+
/**
|
|
39
|
+
* The height attribute of the image element.
|
|
40
|
+
*
|
|
41
|
+
* See:
|
|
42
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height
|
|
43
|
+
*/
|
|
44
|
+
height?: number | string;
|
|
31
45
|
} & ({
|
|
32
46
|
/**
|
|
33
47
|
* Widths used to build a `srcset` value for the image field.
|
|
@@ -84,6 +98,20 @@ declare const _default: import('vue').DefineComponent<({
|
|
|
84
98
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
85
99
|
*/
|
|
86
100
|
fallbackAlt?: "";
|
|
101
|
+
/**
|
|
102
|
+
* The width attribute of the image element.
|
|
103
|
+
*
|
|
104
|
+
* See:
|
|
105
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width
|
|
106
|
+
*/
|
|
107
|
+
width?: number | string;
|
|
108
|
+
/**
|
|
109
|
+
* The height attribute of the image element.
|
|
110
|
+
*
|
|
111
|
+
* See:
|
|
112
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height
|
|
113
|
+
*/
|
|
114
|
+
height?: number | string;
|
|
87
115
|
} & {
|
|
88
116
|
/**
|
|
89
117
|
* Widths used to build a `srcset` value for the image field.
|
|
@@ -127,6 +155,20 @@ declare const _default: import('vue').DefineComponent<({
|
|
|
127
155
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
128
156
|
*/
|
|
129
157
|
fallbackAlt?: "";
|
|
158
|
+
/**
|
|
159
|
+
* The width attribute of the image element.
|
|
160
|
+
*
|
|
161
|
+
* See:
|
|
162
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width
|
|
163
|
+
*/
|
|
164
|
+
width?: number | string;
|
|
165
|
+
/**
|
|
166
|
+
* The height attribute of the image element.
|
|
167
|
+
*
|
|
168
|
+
* See:
|
|
169
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height
|
|
170
|
+
*/
|
|
171
|
+
height?: number | string;
|
|
130
172
|
} & {
|
|
131
173
|
/**
|
|
132
174
|
* Not used when the `widths` prop is used.
|
|
@@ -165,6 +207,20 @@ declare const _default: import('vue').DefineComponent<({
|
|
|
165
207
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
166
208
|
*/
|
|
167
209
|
fallbackAlt?: "";
|
|
210
|
+
/**
|
|
211
|
+
* The width attribute of the image element.
|
|
212
|
+
*
|
|
213
|
+
* See:
|
|
214
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width
|
|
215
|
+
*/
|
|
216
|
+
width?: number | string;
|
|
217
|
+
/**
|
|
218
|
+
* The height attribute of the image element.
|
|
219
|
+
*
|
|
220
|
+
* See:
|
|
221
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height
|
|
222
|
+
*/
|
|
223
|
+
height?: number | string;
|
|
168
224
|
} & {
|
|
169
225
|
/**
|
|
170
226
|
* Widths used to build a `srcset` value for the image field.
|
|
@@ -208,6 +264,20 @@ declare const _default: import('vue').DefineComponent<({
|
|
|
208
264
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
209
265
|
*/
|
|
210
266
|
fallbackAlt?: "";
|
|
267
|
+
/**
|
|
268
|
+
* The width attribute of the image element.
|
|
269
|
+
*
|
|
270
|
+
* See:
|
|
271
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width
|
|
272
|
+
*/
|
|
273
|
+
width?: number | string;
|
|
274
|
+
/**
|
|
275
|
+
* The height attribute of the image element.
|
|
276
|
+
*
|
|
277
|
+
* See:
|
|
278
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height
|
|
279
|
+
*/
|
|
280
|
+
height?: number | string;
|
|
211
281
|
} & {
|
|
212
282
|
/**
|
|
213
283
|
* Not used when the `widths` prop is used.
|
package/dist/PrismicImage.vue.js
CHANGED
|
@@ -3,7 +3,7 @@ import { isFilled, asImageWidthSrcSet, asImagePixelDensitySrcSet } from "@prismi
|
|
|
3
3
|
import { DEV } from "esm-env";
|
|
4
4
|
import { devMsg } from "./lib/devMsg.js";
|
|
5
5
|
import { usePrismic } from "./usePrismic.js";
|
|
6
|
-
const _hoisted_1 = ["src", "srcset", "alt"];
|
|
6
|
+
const _hoisted_1 = ["src", "srcset", "alt", "width", "height"];
|
|
7
7
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
8
|
...{ name: "PrismicImage" },
|
|
9
9
|
__name: "PrismicImage",
|
|
@@ -12,6 +12,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
12
12
|
imgixParams: {},
|
|
13
13
|
alt: {},
|
|
14
14
|
fallbackAlt: {},
|
|
15
|
+
width: {},
|
|
16
|
+
height: {},
|
|
15
17
|
widths: {},
|
|
16
18
|
pixelDensities: {}
|
|
17
19
|
},
|
|
@@ -41,6 +43,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
41
43
|
}
|
|
42
44
|
});
|
|
43
45
|
}
|
|
46
|
+
const castInt = (input) => {
|
|
47
|
+
if (typeof input === "number" || typeof input === "undefined") {
|
|
48
|
+
return input;
|
|
49
|
+
} else {
|
|
50
|
+
const parsed = Number.parseInt(input);
|
|
51
|
+
if (Number.isNaN(parsed)) {
|
|
52
|
+
return void 0;
|
|
53
|
+
} else {
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
44
58
|
const image = computed(() => {
|
|
45
59
|
var _a, _b;
|
|
46
60
|
if (!isFilled.imageThumbnail(props.field)) {
|
|
@@ -63,10 +77,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
63
77
|
src = res.src;
|
|
64
78
|
srcSet = res.srcset;
|
|
65
79
|
}
|
|
80
|
+
const ar = props.field.dimensions.width / props.field.dimensions.height;
|
|
81
|
+
const castedWidth = castInt(props.width);
|
|
82
|
+
const castedHeight = castInt(props.height);
|
|
83
|
+
let resolvedWidth = castedWidth ?? props.field.dimensions.width;
|
|
84
|
+
let resolvedHeight = castedHeight ?? props.field.dimensions.height;
|
|
85
|
+
if (castedWidth != null && castedHeight == null) {
|
|
86
|
+
resolvedHeight = castedWidth / ar;
|
|
87
|
+
} else if (castedWidth == null && castedHeight != null) {
|
|
88
|
+
resolvedWidth = castedHeight * ar;
|
|
89
|
+
}
|
|
66
90
|
return {
|
|
67
91
|
src,
|
|
68
92
|
srcSet,
|
|
69
|
-
alt: props.alt ?? (props.field.alt || props.fallbackAlt)
|
|
93
|
+
alt: props.alt ?? (props.field.alt || props.fallbackAlt),
|
|
94
|
+
width: Math.round(resolvedWidth),
|
|
95
|
+
height: Math.round(resolvedHeight)
|
|
70
96
|
};
|
|
71
97
|
});
|
|
72
98
|
return (_ctx, _cache) => {
|
|
@@ -74,7 +100,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
74
100
|
key: 0,
|
|
75
101
|
src: image.value.src,
|
|
76
102
|
srcset: image.value.srcSet,
|
|
77
|
-
alt: image.value.alt
|
|
103
|
+
alt: image.value.alt,
|
|
104
|
+
width: image.value.width,
|
|
105
|
+
height: image.value.height
|
|
78
106
|
}, null, 8, _hoisted_1)) : createCommentVNode("", true);
|
|
79
107
|
};
|
|
80
108
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicImage.vue.js","sources":["../src/PrismicImage.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { ImageField, asImageSrc } from \"@prismicio/client\"\nimport {\n\tasImagePixelDensitySrcSet,\n\tasImageWidthSrcSet,\n\tisFilled,\n} from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport { computed, watchEffect } from \"vue\"\n\nimport { devMsg } from \"./lib/devMsg\"\n\nimport { usePrismic } from \"./usePrismic\"\n\n/**\n * Props for `<PrismicImage />`.\n */\nexport type PrismicImageProps = {\n\t/**\n\t * The Prismic image field or thumbnail to render.\n\t */\n\tfield: ImageField | ImageField<string>\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * See: https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: Parameters<typeof asImageSrc>[1]\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\"\n\n\t/**\n\t * Declare an image as decorative only if the image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\"\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * Widths used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `widths` prop is not given or `\"defaults\"` is passed, the\n\t\t\t * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,\n\t\t\t * 3840.\n\t\t\t *\n\t\t\t * If the image field contains responsive views, each responsive view can\n\t\t\t * be used as a width in the resulting `srcset` by passing `\"thumbnails\"`\n\t\t\t * as the `widths` prop.\n\t\t\t */\n\t\t\twidths?:\n\t\t\t\t| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>[\"widths\"]\n\t\t\t\t| \"thumbnails\"\n\t\t\t\t| \"defaults\"\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\tpixelDensities?: never\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\twidths?: never\n\t\t\t/**\n\t\t\t * Pixel densities used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `pixelDensities` prop is passed `\"defaults\"`, the following pixel\n\t\t\t * densities will be used: 1, 2, 3.\n\t\t\t */\n\t\t\tpixelDensities:\n\t\t\t\t| NonNullable<\n\t\t\t\t\t\tParameters<typeof asImagePixelDensitySrcSet>[1]\n\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t| \"defaults\"\n\t }\n)\n\nconst props = defineProps<PrismicImageProps>()\ndefineOptions({ name: \"PrismicImage\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\twatchEffect(() => {\n\t\tif (typeof props.alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (typeof props.fallbackAlt === \"string\" && props.fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (props.widths && props.pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\n\t\t\t)\n\t\t}\n\t})\n}\n\nconst image = computed(() => {\n\tif (!isFilled.imageThumbnail(props.field)) {\n\t\treturn\n\t}\n\n\tlet src: string | undefined\n\tlet srcSet: string | undefined\n\tif (props.widths || !props.pixelDensities) {\n\t\tconst res = asImageWidthSrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\twidths:\n\t\t\t\tprops.widths === \"defaults\"\n\t\t\t\t\t? options.components?.imageWidthSrcSetDefaults\n\t\t\t\t\t: props.widths,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t} else if (props.pixelDensities) {\n\t\tconst res = asImagePixelDensitySrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\tpixelDensities:\n\t\t\t\tprops.pixelDensities === \"defaults\"\n\t\t\t\t\t? options.components?.imagePixelDensitySrcSetDefaults\n\t\t\t\t\t: props.pixelDensities,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t}\n\n\treturn {\n\t\tsrc,\n\t\tsrcSet,\n\t\talt: props.alt ?? (props.field.alt || props.fallbackAlt),\n\t}\n})\n</script>\n\n<template>\n\t<img
|
|
1
|
+
{"version":3,"file":"PrismicImage.vue.js","sources":["../src/PrismicImage.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { ImageField, asImageSrc } from \"@prismicio/client\"\nimport {\n\tasImagePixelDensitySrcSet,\n\tasImageWidthSrcSet,\n\tisFilled,\n} from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport { computed, watchEffect } from \"vue\"\n\nimport { devMsg } from \"./lib/devMsg\"\n\nimport { usePrismic } from \"./usePrismic\"\n\n/**\n * Props for `<PrismicImage />`.\n */\nexport type PrismicImageProps = {\n\t/**\n\t * The Prismic image field or thumbnail to render.\n\t */\n\tfield: ImageField | ImageField<string>\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * See: https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: Parameters<typeof asImageSrc>[1]\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\"\n\n\t/**\n\t * Declare an image as decorative only if the image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\"\n\n\t/**\n\t * The width attribute of the image element.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width\n\t */\n\twidth?: number | string\n\n\t/**\n\t * The height attribute of the image element.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height\n\t */\n\theight?: number | string\n} & (\n\t| {\n\t\t\t/**\n\t\t\t * Widths used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `widths` prop is not given or `\"defaults\"` is passed, the\n\t\t\t * following widths will be used: 640, 750, 828, 1080, 1200, 1920, 2048,\n\t\t\t * 3840.\n\t\t\t *\n\t\t\t * If the image field contains responsive views, each responsive view can\n\t\t\t * be used as a width in the resulting `srcset` by passing `\"thumbnails\"`\n\t\t\t * as the `widths` prop.\n\t\t\t */\n\t\t\twidths?:\n\t\t\t\t| NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>[\"widths\"]\n\t\t\t\t| \"thumbnails\"\n\t\t\t\t| \"defaults\"\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\tpixelDensities?: never\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * Not used when the `widths` prop is used.\n\t\t\t */\n\t\t\twidths?: never\n\t\t\t/**\n\t\t\t * Pixel densities used to build a `srcset` value for the image field.\n\t\t\t *\n\t\t\t * If a `pixelDensities` prop is passed `\"defaults\"`, the following pixel\n\t\t\t * densities will be used: 1, 2, 3.\n\t\t\t */\n\t\t\tpixelDensities:\n\t\t\t\t| NonNullable<\n\t\t\t\t\t\tParameters<typeof asImagePixelDensitySrcSet>[1]\n\t\t\t\t >[\"pixelDensities\"]\n\t\t\t\t| \"defaults\"\n\t }\n)\n\nconst props = defineProps<PrismicImageProps>()\ndefineOptions({ name: \"PrismicImage\" })\n\nconst { options } = usePrismic()\n\nif (DEV) {\n\twatchEffect(() => {\n\t\tif (typeof props.alt === \"string\" && props.alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (typeof props.fallbackAlt === \"string\" && props.fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t)\n\t\t}\n\n\t\tif (props.widths && props.pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\n\t\t\t)\n\t\t}\n\t})\n}\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input\n\t} else {\n\t\tconst parsed = Number.parseInt(input)\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined\n\t\t} else {\n\t\t\treturn parsed\n\t\t}\n\t}\n}\n\nconst image = computed(() => {\n\tif (!isFilled.imageThumbnail(props.field)) {\n\t\treturn\n\t}\n\n\tlet src: string | undefined\n\tlet srcSet: string | undefined\n\tif (props.widths || !props.pixelDensities) {\n\t\tconst res = asImageWidthSrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\twidths:\n\t\t\t\tprops.widths === \"defaults\"\n\t\t\t\t\t? options.components?.imageWidthSrcSetDefaults\n\t\t\t\t\t: props.widths,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t} else if (props.pixelDensities) {\n\t\tconst res = asImagePixelDensitySrcSet(props.field, {\n\t\t\t...props.imgixParams,\n\t\t\tpixelDensities:\n\t\t\t\tprops.pixelDensities === \"defaults\"\n\t\t\t\t\t? options.components?.imagePixelDensitySrcSetDefaults\n\t\t\t\t\t: props.pixelDensities,\n\t\t})\n\n\t\tsrc = res.src\n\t\tsrcSet = res.srcset\n\t}\n\n\tconst ar = props.field.dimensions.width / props.field.dimensions.height\n\n\tconst castedWidth = castInt(props.width)\n\tconst castedHeight = castInt(props.height)\n\n\tlet resolvedWidth = castedWidth ?? props.field.dimensions.width\n\tlet resolvedHeight = castedHeight ?? props.field.dimensions.height\n\n\tif (castedWidth != null && castedHeight == null) {\n\t\tresolvedHeight = castedWidth / ar\n\t} else if (castedWidth == null && castedHeight != null) {\n\t\tresolvedWidth = castedHeight * ar\n\t}\n\n\treturn {\n\t\tsrc,\n\t\tsrcSet,\n\t\talt: props.alt ?? (props.field.alt || props.fallbackAlt),\n\t\twidth: Math.round(resolvedWidth),\n\t\theight: Math.round(resolvedHeight),\n\t}\n})\n</script>\n\n<template>\n\t<img\n\t\tv-if=\"image\"\n\t\t:src=\"image.src\"\n\t\t:srcset=\"image.srcSet\"\n\t\t:alt=\"image.alt\"\n\t\t:width=\"image.width\"\n\t\t:height=\"image.height\"\n\t/>\n</template>\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAuGA,UAAM,QAAQ;AAGR,UAAA,EAAE,QAAQ,IAAI,WAAW;AAE/B,QAAI,KAAK;AACR,kBAAY,MAAM;AACjB,YAAI,OAAO,MAAM,QAAQ,YAAY,MAAM,QAAQ,IAAI;AAC9C,kBAAA;AAAA,YACP,qQAAqQ;AAAA,cACpQ;AAAA,YAAA,CACA;AAAA,UACF;AAAA,QAAA;AAGD,YAAI,OAAO,MAAM,gBAAgB,YAAY,MAAM,gBAAgB,IAAI;AAC9D,kBAAA;AAAA,YACP,qSAAqS;AAAA,cACpS;AAAA,YAAA,CACA;AAAA,UACF;AAAA,QAAA;AAGG,YAAA,MAAM,UAAU,MAAM,gBAAgB;AACjC,kBAAA;AAAA,YACP;AAAA,UACD;AAAA,QAAA;AAAA,MACD,CACA;AAAA,IAAA;AAGI,UAAA,UAAU,CAAC,UAA2D;AAC3E,UAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,eAAA;AAAA,MAAA,OACD;AACA,cAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,YAAA,OAAO,MAAM,MAAM,GAAG;AAClB,iBAAA;AAAA,QAAA,OACD;AACC,iBAAA;AAAA,QAAA;AAAA,MACR;AAAA,IAEF;AAEM,UAAA,QAAQ,SAAS,MAAM;;AAC5B,UAAI,CAAC,SAAS,eAAe,MAAM,KAAK,GAAG;AAC1C;AAAA,MAAA;AAGG,UAAA;AACA,UAAA;AACJ,UAAI,MAAM,UAAU,CAAC,MAAM,gBAAgB;AACpC,cAAA,MAAM,mBAAmB,MAAM,OAAO;AAAA,UAC3C,GAAG,MAAM;AAAA,UACT,QACC,MAAM,WAAW,cACd,aAAQ,eAAR,mBAAoB,2BACpB,MAAM;AAAA,QAAA,CACV;AAED,cAAM,IAAI;AACV,iBAAS,IAAI;AAAA,MAAA,WACH,MAAM,gBAAgB;AAC1B,cAAA,MAAM,0BAA0B,MAAM,OAAO;AAAA,UAClD,GAAG,MAAM;AAAA,UACT,gBACC,MAAM,mBAAmB,cACtB,aAAQ,eAAR,mBAAoB,kCACpB,MAAM;AAAA,QAAA,CACV;AAED,cAAM,IAAI;AACV,iBAAS,IAAI;AAAA,MAAA;AAGd,YAAM,KAAK,MAAM,MAAM,WAAW,QAAQ,MAAM,MAAM,WAAW;AAE3D,YAAA,cAAc,QAAQ,MAAM,KAAK;AACjC,YAAA,eAAe,QAAQ,MAAM,MAAM;AAEzC,UAAI,gBAAgB,eAAe,MAAM,MAAM,WAAW;AAC1D,UAAI,iBAAiB,gBAAgB,MAAM,MAAM,WAAW;AAExD,UAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,yBAAiB,cAAc;AAAA,MACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,wBAAgB,eAAe;AAAA,MAAA;AAGzB,aAAA;AAAA,QACN;AAAA,QACA;AAAA,QACA,KAAK,MAAM,QAAQ,MAAM,MAAM,OAAO,MAAM;AAAA,QAC5C,OAAO,KAAK,MAAM,aAAa;AAAA,QAC/B,QAAQ,KAAK,MAAM,cAAc;AAAA,MAClC;AAAA,IAAA,CACA;;;;;;;;;;;;;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
package/package.json
CHANGED
package/src/PrismicImage.vue
CHANGED
|
@@ -44,6 +44,22 @@ export type PrismicImageProps = {
|
|
|
44
44
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
45
45
|
*/
|
|
46
46
|
fallbackAlt?: ""
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The width attribute of the image element.
|
|
50
|
+
*
|
|
51
|
+
* See:
|
|
52
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/width
|
|
53
|
+
*/
|
|
54
|
+
width?: number | string
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The height attribute of the image element.
|
|
58
|
+
*
|
|
59
|
+
* See:
|
|
60
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/height
|
|
61
|
+
*/
|
|
62
|
+
height?: number | string
|
|
47
63
|
} & (
|
|
48
64
|
| {
|
|
49
65
|
/**
|
|
@@ -116,6 +132,20 @@ if (DEV) {
|
|
|
116
132
|
})
|
|
117
133
|
}
|
|
118
134
|
|
|
135
|
+
const castInt = (input: string | number | undefined): number | undefined => {
|
|
136
|
+
if (typeof input === "number" || typeof input === "undefined") {
|
|
137
|
+
return input
|
|
138
|
+
} else {
|
|
139
|
+
const parsed = Number.parseInt(input)
|
|
140
|
+
|
|
141
|
+
if (Number.isNaN(parsed)) {
|
|
142
|
+
return undefined
|
|
143
|
+
} else {
|
|
144
|
+
return parsed
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
const image = computed(() => {
|
|
120
150
|
if (!isFilled.imageThumbnail(props.field)) {
|
|
121
151
|
return
|
|
@@ -147,14 +177,37 @@ const image = computed(() => {
|
|
|
147
177
|
srcSet = res.srcset
|
|
148
178
|
}
|
|
149
179
|
|
|
180
|
+
const ar = props.field.dimensions.width / props.field.dimensions.height
|
|
181
|
+
|
|
182
|
+
const castedWidth = castInt(props.width)
|
|
183
|
+
const castedHeight = castInt(props.height)
|
|
184
|
+
|
|
185
|
+
let resolvedWidth = castedWidth ?? props.field.dimensions.width
|
|
186
|
+
let resolvedHeight = castedHeight ?? props.field.dimensions.height
|
|
187
|
+
|
|
188
|
+
if (castedWidth != null && castedHeight == null) {
|
|
189
|
+
resolvedHeight = castedWidth / ar
|
|
190
|
+
} else if (castedWidth == null && castedHeight != null) {
|
|
191
|
+
resolvedWidth = castedHeight * ar
|
|
192
|
+
}
|
|
193
|
+
|
|
150
194
|
return {
|
|
151
195
|
src,
|
|
152
196
|
srcSet,
|
|
153
197
|
alt: props.alt ?? (props.field.alt || props.fallbackAlt),
|
|
198
|
+
width: Math.round(resolvedWidth),
|
|
199
|
+
height: Math.round(resolvedHeight),
|
|
154
200
|
}
|
|
155
201
|
})
|
|
156
202
|
</script>
|
|
157
203
|
|
|
158
204
|
<template>
|
|
159
|
-
<img
|
|
205
|
+
<img
|
|
206
|
+
v-if="image"
|
|
207
|
+
:src="image.src"
|
|
208
|
+
:srcset="image.srcSet"
|
|
209
|
+
:alt="image.alt"
|
|
210
|
+
:width="image.width"
|
|
211
|
+
:height="image.height"
|
|
212
|
+
/>
|
|
160
213
|
</template>
|