cristianbote/goober

background image is no work with base64 img

Ele-Lee opened this issue · 7 comments

"version": "2.1.10"

import { css } from 'goober';

const base64 =
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARcAAAEzCAMAAAAsMLfGAAAANlBMVEUAAAD////////////////////////////////////////////////////////////////////xY8b8AAAAEXRSTlMA3x+/7z8Qn89/YDCPb0+vX6I2utUAAAxrSURBVHja7NlRasMwEEXRkRrbtZ2mffvfbFsGQySNIP4JIbpnDQ/uwNg72nZDIF0NrVWX2VDLklZDbZF0MQRzkX4MpaR/H4bCJjcZqrkwmKjRh2ywQ5Yj1aVFB267ci4MJpB04LYLGk2qC3OSI9V1oxlMK6v2bfBGV0i12S5HqnuN5rYrGh35ssHNSZFPG9wqR6p7jea2KxvNYFq7uoZ+sSU5Ut1pNLfdnZwkBhM3Ojb0iy3Lkeq40aS6MEkM5lSjh36xbTpw20WNJtWdRnPbPdbooV9sixypLtzkSHXTaAYTNprBnGr00C+2qxyp7jWa2+6hRg/9YrvpnGRjSHKkOmw0qW4azWCiRp+32NvLcqS61+iXve3mvE9/8mzPs0kvPJhfZs4Fx3YQBMPgC63aHva/2ZvcTGYytafTY0H7baCJBX5EIKxlQ8ffoC3Vq3661ejH5XY+RT4k0svAnkeYi75Uh2T5DCQPDfIa/TCpDsld8GVaQQk6/uBsg2lOZbDVmEPfzcB7KHJDBiU88gdgE2ukzcVtX7E+8B4AsxKOeWJL/ClkAHSCrrPlZU7MCP6Tl81pS3Ww3IH1ANIajVTzzpBPCgu+2n1u9wghwJecuXx5ToM/72kOvkSlJ7aMzDz7ZLyBY9a/tOcr3IjLpHHM/ICTeUO9psk5w0Oc6JvoQZF0sazwuGNptEkWmnN7jixCMaCEnfIAUPiHZ4aZyDtWeMMTbrAHoAEN3MU74uOCyw8lgDhh3FWojWkPdqY84aXe8G+eqExrZ++Yvrlg3IhKItpsdDdMJsikdRE6EDYXLK8cdteRtVjXZTIYRATTgjbEp9hq4A15IfzUZBauIukLgTKBzyAP5+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LXv6yg66IF8n3ogpbLOqlK+PlQ8WTm2iyvXgjEajhJZiBUloMyDYsZ4d1ZMYH1178Ti+82wt5NTsuyQbIfi2Op+NSsSCnvHzt9GJOQaqcJviGRj30JjOB/wN22GXHYN9tzAAAAABJRU5ErkJggg==';


const calssName = css`
  background-image: url(${base64});
`;

My base64 img url is right.
I found that there is an extra colon in Chorme Dev Tool;
image

In addition,
it worked in the object syntax.

const calssName = css({
  backgroundImage: `url(${base64})`,
});

Hey @Ele-Lee,

Thanks for opening this issue! Indeed this is a real issue with how the inner parser works for now. There's a workaround though, you can use the object syntax if that's possible:

const className = css({
  backgroundImage: `url(${base64})`
});

and this bypasses the css pair parsing. Would that make it work for your case?

thanks. The object syntax is effective.
This problem caused some confusion when using solid-styled-components.
Hope goober be better and better

I am running into the same issue, and don't have the option to use the object syntax as alternative at the moment.
Is there no way to fix this within the parser?

hey @monkeyphysics, not without a full parser refactor. Can I ask what's blocking the option of using the object syntax? Linting?

My use case is a different background image for hover:

.item {
  background-image: url(${img-regular});

  &:hover {
    background-image: url(${img-hover});
  }
}

I've looked at the parser before to fix #375 and can dive in again, but forgot how I set it up so that I can use the source code of goober from /node_modules/. Any tips on setting this up so that I can make changes to the goober core in my project?

An ugly solution without touching the parser would be to restore the error after generating css by replacing the data:{mime};{encoding}:, pattern like so:
css.replace(/(data:[a-z]+\/[a-z]+;[a-z0-9]+):,/, "$1,");

Regarding your use case, if you want to you can still use the object syntax:

const Foo = styled('div')({
  ".item": {
    backgroundImage: `url(${img-regular})`,
    "&:hover": {
      backgroundImage: `url(${img-hover})`
    }
  }
});

In fact that's exactly what the parser does internally.

Any tips on setting this up so that I can make changes to the goober core in my project?

Depends on your setup really. Is it a nextjs project? If it's v13 you could use the transpile package option otherwise there is a next-transpile-package module.

Thanks for this!
Any consideration on the suggested regex replace?