Skip to content

Commit

Permalink
use currentSrc
Browse files Browse the repository at this point in the history
  • Loading branch information
samijaber committed Nov 23, 2021
1 parent 6f35bc7 commit a381764
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/html-to-figma/helpers/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const getImagePaintWithUrl = ({
};

if (el instanceof HTMLImageElement) {
const url = el.src;
// we use `currentSrc` instead of `src` as that will be the accurate value in dynamic contexts:
// when the img is a child of a picture element, or it has `sizes`/`srcSet` attributes, etc.
const url = el.currentSrc;
if (url) {
return {
url,
Expand Down
9 changes: 7 additions & 2 deletions lib/html-to-figma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ const getLayersForElement = (el: Element) => {
return [];
}

if (el.parentElement instanceof HTMLPictureElement) {
// for `picture`, we only need the `image` element. We can ignore the parent `picture` and
// `source` sibling elements.
if (
(el.parentElement instanceof HTMLPictureElement &&
el instanceof HTMLSourceElement) ||
el instanceof HTMLPictureElement
) {
return [];
}

Expand All @@ -70,7 +76,6 @@ const getLayersForElement = (el: Element) => {
if (
(size(appliedStyles) ||
el instanceof HTMLImageElement ||
el instanceof HTMLPictureElement ||
el instanceof HTMLVideoElement) &&
computedStyle.display !== "none"
) {
Expand Down

0 comments on commit a381764

Please sign in to comment.