unpic-img icon indicating copy to clipboard operation
unpic-img copied to clipboard

Support Brisa JSX Framework

Open aralroca opened this issue 1 year ago • 0 comments

I see that the implementation with Brisa it looks very simple:

import { transformProps, type UnpicImageProps } from "@unpic/core";

export type ImageProps = UnpicImageProps<JSX.HTMLAttributes<HTMLImageElement>>;

export function Image(props: ImageProps) {
  return <img {...transformProps(props)} />;
}

This is currently working as Server Component to optimize CDN images, ex of usage:

import { Image } from "@/components/image";

export default function Homepage() {
  return (
    <>
      <Image
        src="https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&auto=format&fit=crop&w=900&q=60"
        layout="fullWidth"
        alt=""
        priority
        height={400}
        crossOrigin="anonymous"
        background="auto"
      ></Image>
      <Image
        src="https://cdn.shopify.com/static/sample-images/garnished.jpeg"
        layout="constrained"
        width={800}
        height={600}
        alt="Shopify"
      ></Image>
      <Image
        src="https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=300"
        width={400}
        height={300}
        layout="fixed"
        alt="Bunny.net"
      ></Image>
    </>
  );
}

Result HTML:

<img alt="" crossorigin="anonymous" loading="eager" fetchpriority="high" role="presentation" style="object-fit:cover;background-image:url(https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=24&amp;q=60);background-size:cover;background-repeat:no-repeat;width:100%;height:400px;" srcset="https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=640&amp;q=60 640w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=750&amp;q=60 750w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=828&amp;q=60 828w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=960&amp;q=60 960w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1080&amp;q=60 1080w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1280&amp;q=60 1280w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1668&amp;q=60 1668w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=1920&amp;q=60 1920w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=2048&amp;q=60 2048w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=2560&amp;q=60 2560w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=3200&amp;q=60 3200w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=3840&amp;q=60 3840w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=4480&amp;q=60 4480w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=5120&amp;q=60 5120w,
https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=6016&amp;q=60 6016w" src="https://images.unsplash.com/photo-1617718295766-0f839c2853e7?ixlib=rb-4.0.3&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTczfHxyYWluZm9yZXN0JTIwYmVhY2h8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;q=60&amp;h=400">

<img alt="Shopify" loading="lazy" decoding="async" sizes="(min-width: 800px) 800px, 100vw" style="object-fit:cover;max-width:800px;max-height:600px;aspect-ratio:1.3333333333333333;width:100%;" srcset="https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=640&amp;height=480 640w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=750&amp;height=563 750w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=800&amp;height=600 800w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=828&amp;height=621 828w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=960&amp;height=720 960w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=1080&amp;height=810 1080w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=1280&amp;height=960 1280w,
https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=1600&amp;height=1200 1600w" src="https://cdn.shopify.com/static/sample-images/garnished.jpeg?width=800&amp;height=600">

<img alt="Bunny.net" loading="lazy" decoding="async" sizes="400px" style="object-fit:cover;width:400px;height:300px;" srcset="https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=400&amp;aspect_ratio=400%3A300 400w,
https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=800&amp;aspect_ratio=800%3A600 800w" src="https://bunnyoptimizerdemo.b-cdn.net/bunny7.jpg?width=400&amp;aspect_ratio=400%3A300" width="400" height="300">

The only problem I see is with the integration in this repo as another package because of the workspace resolution with pnpm and the use of vitest, since all the tooling of Brisa is through bun, and the testing is part of brisa/test. Brisa also does not use vite, it uses bun (brisa dev).

See this fork https://github.com/aralroca/unpic-img/commit/b62d0994892d8dcae38c6c468c01b34f034f97a2

aralroca avatar Jan 01 '25 21:01 aralroca