@sveltejs/enhanced-img
Advanced tools
Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "@sveltejs/enhanced-img", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Image optimization for your Svelte apps", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -21,3 +21,3 @@ import MagicString from 'magic-string'; | ||
* URL to image details | ||
* @type {Map<string, { image: import('vite-imagetools').Picture, name: string }>} | ||
* @type {Map<string, import('vite-imagetools').Picture>} | ||
*/ | ||
@@ -69,18 +69,17 @@ const images = new Map(); | ||
const name = ASSET_PREFIX + images.size; | ||
if (OPTIMIZABLE.test(url)) { | ||
let details = images.get(url); | ||
if (!details) { | ||
let image = images.get(url); | ||
if (!image) { | ||
// resolves the import so that we can build the entire picture template string and don't | ||
// need any logic blocks | ||
const image = await resolve(opts, url, filename); | ||
image = await resolve(opts, url, filename); | ||
if (!image) { | ||
return; | ||
} | ||
details = images.get(url) || { name, image }; | ||
images.set(url, details); | ||
images.set(url, image); | ||
} | ||
s.update(node.start, node.end, img_to_picture(content, node, details)); | ||
s.update(node.start, node.end, img_to_picture(content, node, image)); | ||
} else { | ||
// e.g. <img src="./foo.svg" /> => <img src={___ASSET___0} /> | ||
const name = ASSET_PREFIX + imports.size; | ||
const { start, end } = src_attribute; | ||
@@ -260,5 +259,5 @@ // update src with reference to imported asset | ||
* @param {import('svelte/types/compiler/interfaces').TemplateNode} node | ||
* @param {{ image: import('vite-imagetools').Picture, name: string }} details | ||
* @param {import('vite-imagetools').Picture} image | ||
*/ | ||
function img_to_picture(content, node, details) { | ||
function img_to_picture(content, node, image) { | ||
/** @type {Array<import('svelte/types/compiler/interfaces').BaseDirective | import('svelte/types/compiler/interfaces').Attribute | import('svelte/types/compiler/interfaces').SpreadAttribute>} attributes */ | ||
@@ -274,9 +273,9 @@ const attributes = node.attributes; | ||
let res = '<picture>'; | ||
for (const [format, srcset] of Object.entries(details.image.sources)) { | ||
for (const [format, srcset] of Object.entries(image.sources)) { | ||
res += `<source srcset="${srcset}"${sizes_string} type="image/${format}" />`; | ||
} | ||
res += `<img ${img_attributes_to_markdown(content, attributes, { | ||
src: details.image.img.src, | ||
width: details.image.img.w, | ||
height: details.image.img.h | ||
src: image.img.src, | ||
width: image.img.w, | ||
height: image.img.h | ||
})} />`; | ||
@@ -283,0 +282,0 @@ res += '</picture>'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17705
423