gemi 0.3.2 → 0.3.3

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/dist/bin/gemi CHANGED
Binary file
@@ -6,4 +6,5 @@ export { Mutation, FormError, useMutationStatus, ValidationErrors, } from "./Mut
6
6
  export { Link, useLocation, useParams, useRouter } from "./ClientRouterContext";
7
7
  export { init } from "./init";
8
8
  export { createRoot } from "./createRoot";
9
+ export { Image } from "./Image";
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EACL,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EACL,QAAQ,EACR,SAAS,EACT,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
@@ -29453,9 +29453,60 @@ function createRoot(RootLayout) {
29453
29453
  }
29454
29454
  ) });
29455
29455
  }
29456
+ const defaultScreen = [390, 768, 1024];
29457
+ const defaultContainer = [100, 100, 100, 100];
29458
+ function generateImageProps(src, width, container = defaultContainer, screen = defaultScreen, quality) {
29459
+ const baseUrl = src;
29460
+ const widths = [...container.map((c, i) => screen[i] * c / 100), width * 2];
29461
+ return {
29462
+ srcSet: [
29463
+ ...screen.map((size, i) => {
29464
+ return `/__gemi__/image?url=${baseUrl}&q=${quality}&w=${widths[i]} ${size}${isNaN(Number(size)) ? "" : "w"}`;
29465
+ }),
29466
+ `/__gemi__/image?url=${baseUrl}&q=${quality}&w=${width * 2} 2x`
29467
+ ].join(", "),
29468
+ sources: [
29469
+ ...container.map((c, i) => {
29470
+ if (!screen[i]) {
29471
+ return `${c}vw`;
29472
+ }
29473
+ return `(max-width: ${screen[i]}px) ${c}vw`;
29474
+ })
29475
+ ].join(", ")
29476
+ };
29477
+ }
29478
+ function fillRestWithLast(arr, length) {
29479
+ return [
29480
+ ...arr,
29481
+ ...Array.from({ length: length - arr.length }).fill(arr[arr.length - 1])
29482
+ ];
29483
+ }
29484
+ const Image = (props) => {
29485
+ const {
29486
+ screen = defaultScreen,
29487
+ container = defaultContainer,
29488
+ src,
29489
+ width,
29490
+ quality = 80,
29491
+ srcSet: __,
29492
+ ...rest
29493
+ } = props;
29494
+ if (!src) {
29495
+ return null;
29496
+ }
29497
+ const srcProps = generateImageProps(
29498
+ src,
29499
+ width,
29500
+ fillRestWithLast(container, 4),
29501
+ screen,
29502
+ quality
29503
+ );
29504
+ return /* @__PURE__ */ jsx("img", { ...srcProps, width, ...rest });
29505
+ };
29456
29506
  export {
29457
29507
  Form,
29458
29508
  FormError,
29509
+ Image,
29459
29510
  Link,
29460
29511
  Mutation,
29461
29512
  ValidationErrors,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemi",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "devDependencies": {
5
5
  "@repo/eslint-config": "*",
6
6
  "@repo/typescript-config": "*",