@raketa-builder/builder 0.6.0 → 0.7.0

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.
@@ -4,5 +4,5 @@ CLI Using tsconfig: tsconfig.json
4
4
  CLI tsup v6.5.0
5
5
  CLI Target: es6
6
6
  CJS Build start
7
- CJS dist/index.js 127.15 KB
8
- CJS ⚡️ Build success in 53ms
7
+ CJS dist/index.js 128.17 KB
8
+ CJS ⚡️ Build success in 588ms
@@ -1,13 +1,13 @@
1
1
  $ TIMING=1 eslint "**/*.js"
2
2
  Rule | Time (ms) | Relative
3
3
  :---------------------------------|----------:|--------:
4
- react/display-name | 15.239 | 29.4%
5
- react/no-direct-mutation-state | 14.334 | 27.7%
6
- react/require-render-return | 7.366 | 14.2%
7
- react/no-deprecated | 2.050 | 4.0%
8
- react-hooks/rules-of-hooks | 1.672 | 3.2%
9
- react/no-string-refs | 1.632 | 3.2%
10
- jsx-a11y/role-supports-aria-props | 1.214 | 2.3%
11
- react-hooks/exhaustive-deps | 1.179 | 2.3%
12
- react/no-unescaped-entities | 0.949 | 1.8%
13
- react/jsx-no-comment-textnodes | 0.664 | 1.3%
4
+ react/no-direct-mutation-state | 658.538 | 33.1%
5
+ react/require-render-return | 423.501 | 21.3%
6
+ react/display-name | 391.109 | 19.7%
7
+ react-hooks/rules-of-hooks | 94.085 | 4.7%
8
+ react/no-string-refs | 83.553 | 4.2%
9
+ react/no-deprecated | 63.182 | 3.2%
10
+ react-hooks/exhaustive-deps | 51.678 | 2.6%
11
+ react/no-unescaped-entities | 34.497 | 1.7%
12
+ jsx-a11y/role-supports-aria-props | 34.492 | 1.7%
13
+ react/no-children-prop | 33.963 | 1.7%
package/dist/index.js CHANGED
@@ -2620,76 +2620,99 @@ var ImageInput_default = ImageInput;
2620
2620
  // src/lib/Image.js
2621
2621
  var import_react22 = __toESM(require("react"));
2622
2622
  var import_jsx_runtime18 = require("react/jsx-runtime");
2623
- var Img = (_a) => {
2624
- var _b = _a, {
2625
- src,
2626
- variant,
2627
- className,
2628
- onLoad,
2629
- alt = null,
2630
- title: title2 = null
2631
- } = _b, props = __objRest(_b, [
2632
- "src",
2633
- "variant",
2634
- "className",
2635
- "onLoad",
2636
- "alt",
2637
- "title"
2638
- ]);
2639
- if (!src) {
2640
- console.warn(
2641
- `WARNING: Image with src null or undefined will not be rendered: ${variant} ${className || ""}`
2642
- );
2623
+ var getWebp = (url) => {
2624
+ if (!url)
2643
2625
  return null;
2626
+ const segments = url.split(".");
2627
+ segments[segments.length - 1] = "webp";
2628
+ return segments.join(".");
2629
+ };
2630
+ var getDimensions = (src, variant) => {
2631
+ var _a;
2632
+ if (typeof src === "object" && ((_a = src == null ? void 0 : src.name) == null ? void 0 : _a.includes(".svg"))) {
2633
+ const width = src.width;
2634
+ const height = src.height;
2635
+ return [width, height];
2636
+ }
2637
+ if (typeof src === "object") {
2638
+ const width = src.sizes[variant].width;
2639
+ const height = src.sizes[variant].height;
2640
+ return [width, height];
2641
+ }
2642
+ return [null, null];
2643
+ };
2644
+ var getAlt = (src) => {
2645
+ const type = typeof src;
2646
+ if (type === "object" && src.alt) {
2647
+ return src.alt;
2648
+ }
2649
+ if (type === "object") {
2650
+ const imageObj = src.image || src;
2651
+ const altSetting = imageObj.settings.find(
2652
+ (setting) => setting.key === "alt"
2653
+ );
2654
+ if (altSetting) {
2655
+ return altSetting.value;
2656
+ }
2657
+ }
2658
+ return "";
2659
+ };
2660
+ var getSrc = (src, variant) => {
2661
+ var _a, _b;
2662
+ if (typeof src === "object") {
2663
+ if (((_a = src == null ? void 0 : src.name) == null ? void 0 : _a.includes(".svg")) || ((_b = src == null ? void 0 : src.name) == null ? void 0 : _b.includes(".gif"))) {
2664
+ return [null, src.urls.original];
2665
+ }
2666
+ const fallback = src.urls[variant];
2667
+ const webp = getWebp(fallback);
2668
+ return [webp, fallback];
2669
+ }
2670
+ return [null, src];
2671
+ };
2672
+ var getImageObjOrSrc = (value) => {
2673
+ const type = typeof value;
2674
+ if (type === "object" && value.hasOwnProperty("image")) {
2675
+ return value.image;
2644
2676
  }
2677
+ return value;
2678
+ };
2679
+ var Image = (_a) => {
2680
+ var _b = _a, { variant, src, alt, loading } = _b, props = __objRest(_b, ["variant", "src", "alt", "loading"]);
2645
2681
  if (!variant) {
2646
- console.warn(
2647
- "WARNING: You are using an <Img /> tag without a variant. Unoptimized original is used as a fallback, but you need to specify a size variant"
2648
- );
2682
+ console.error("Image with no variant", { variant, src, alt, props });
2683
+ return null;
2649
2684
  }
2650
- const imgVariant = variant ? variant : "original";
2651
- const imgAlt = alt !== null ? alt : src.alt;
2652
- const imgTitle = title2 !== null ? title2 : "";
2653
- if (typeof src === "object" && !("name" in src))
2654
- console.warn(
2655
- `WARNING: Image with empty {}: ${imgVariant} ${className || ""}`
2656
- );
2657
- if (typeof src === "object" && "name" in src && (src.name.includes(".svg") || src.name.includes(".gif")))
2658
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2659
- "img",
2660
- __spreadValues({
2661
- src: src.urls.original,
2662
- alt: imgAlt !== null ? imgAlt : src.name,
2663
- className,
2664
- onLoad,
2665
- title: imgTitle
2666
- }, props)
2667
- );
2668
- if (typeof src === "object" && "name" in src)
2669
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2670
- "img",
2671
- __spreadValues({
2672
- src: src.urls[imgVariant],
2673
- alt: imgAlt !== null ? imgAlt : src.name,
2674
- className,
2675
- onLoad,
2676
- title: imgTitle
2677
- }, props)
2678
- );
2679
- if (typeof src === "string")
2680
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2685
+ if (!src) {
2686
+ console.error("Image with no src", { variant, src, alt, props });
2687
+ return null;
2688
+ }
2689
+ const imageObjOrSrc = getImageObjOrSrc(src);
2690
+ if (imageObjOrSrc && typeof imageObjOrSrc === "object" && !imageObjOrSrc.sizes) {
2691
+ console.error("Image with no sizes", { variant, src, alt, props });
2692
+ return null;
2693
+ }
2694
+ const [width, height] = getDimensions(imageObjOrSrc, variant);
2695
+ const altAttr = alt || getAlt(src);
2696
+ const [webp, fallback] = getSrc(imageObjOrSrc, variant);
2697
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("picture", { children: [
2698
+ webp && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("source", { srcSet: encodeURI(webp), type: "image/webp" }),
2699
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("source", { srcSet: encodeURI(fallback), type: src.mime_type }),
2700
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2681
2701
  "img",
2682
2702
  __spreadValues({
2683
- src,
2684
- alt: src,
2685
- className,
2686
- onLoad,
2687
- title: imgTitle
2703
+ src: fallback,
2704
+ alt: altAttr,
2705
+ width,
2706
+ height,
2707
+ loading
2688
2708
  }, props)
2689
- );
2690
- return null;
2709
+ )
2710
+ ] });
2711
+ };
2712
+ Image.defaultProps = {
2713
+ loading: "lazy"
2691
2714
  };
2692
- var Image_default = Img;
2715
+ var Image_default = Image;
2693
2716
 
2694
2717
  // src/List.js
2695
2718
  var import_react23 = __toESM(require("react"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/builder",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
package/src/lib/Image.js CHANGED
@@ -1,78 +1,123 @@
1
- /* eslint-disable @next/next/no-img-element */
2
1
  import React from "react";
3
2
 
4
- const Img = ({
5
- src,
6
- variant,
7
- className,
8
- onLoad,
9
- alt = null,
10
- title = null,
11
- ...props
12
- }) => {
13
- if (!src) {
14
- console.warn(
15
- `WARNING: Image with src null or undefined will not be rendered: ${variant} ${
16
- className || ""
17
- }`
3
+ const getWebp = (url) => {
4
+ if (!url) return null;
5
+
6
+ const segments = url.split(".");
7
+ segments[segments.length - 1] = "webp";
8
+
9
+ return segments.join(".");
10
+ };
11
+
12
+ const getDimensions = (src, variant) => {
13
+ if (typeof src === "object" && src?.name?.includes(".svg")) {
14
+ const width = src.width;
15
+ const height = src.height;
16
+
17
+ return [width, height];
18
+ }
19
+
20
+ if (typeof src === "object") {
21
+ const width = src.sizes[variant].width;
22
+ const height = src.sizes[variant].height;
23
+
24
+ return [width, height];
25
+ }
26
+
27
+ return [null, null];
28
+ };
29
+
30
+ const getAlt = (src) => {
31
+ const type = typeof src;
32
+
33
+ if (type === "object" && src.alt) {
34
+ return src.alt;
35
+ }
36
+
37
+ if (type === "object") {
38
+ const imageObj = src.image || src;
39
+
40
+ const altSetting = imageObj.settings.find(
41
+ (setting) => setting.key === "alt"
18
42
  );
19
- return null;
43
+
44
+ if (altSetting) {
45
+ return altSetting.value;
46
+ }
47
+ }
48
+
49
+ return "";
50
+ };
51
+
52
+ const getSrc = (src, variant) => {
53
+ if (typeof src === "object") {
54
+ if (src?.name?.includes(".svg") || src?.name?.includes(".gif")) {
55
+ return [null, src.urls.original];
56
+ }
57
+
58
+ const fallback = src.urls[variant];
59
+ const webp = getWebp(fallback);
60
+
61
+ return [webp, fallback];
62
+ }
63
+
64
+ return [null, src];
65
+ };
66
+
67
+ const getImageObjOrSrc = (value) => {
68
+ const type = typeof value;
69
+
70
+ if (type === "object" && value.hasOwnProperty("image")) {
71
+ return value.image;
20
72
  }
21
73
 
74
+ return value;
75
+ };
76
+
77
+ const Image = ({ variant, src, alt, loading, ...props }) => {
22
78
  if (!variant) {
23
- console.warn(
24
- "WARNING: You are using an <Img /> tag without a variant. Unoptimized original is used as a fallback, but you need to specify a size variant"
25
- );
79
+ console.error("Image with no variant", { variant, src, alt, props });
80
+ return null;
26
81
  }
27
82
 
28
- const imgVariant = variant ? variant : "original";
29
- const imgAlt = alt !== null ? alt : src.alt;
30
- const imgTitle = title !== null ? title : "";
83
+ if (!src) {
84
+ console.error("Image with no src", { variant, src, alt, props });
85
+ return null;
86
+ }
31
87
 
32
- if (typeof src === "object" && !("name" in src))
33
- console.warn(
34
- `WARNING: Image with empty {}: ${imgVariant} ${className || ""}`
35
- );
88
+ const imageObjOrSrc = getImageObjOrSrc(src);
36
89
 
37
90
  if (
38
- typeof src === "object" &&
39
- "name" in src &&
40
- (src.name.includes(".svg") || src.name.includes(".gif"))
41
- )
42
- return (
43
- <img
44
- src={src.urls.original}
45
- alt={imgAlt !== null ? imgAlt : src.name}
46
- className={className}
47
- onLoad={onLoad}
48
- title={imgTitle}
49
- {...props}
50
- />
51
- );
52
- if (typeof src === "object" && "name" in src)
53
- return (
54
- <img
55
- src={src.urls[imgVariant]}
56
- alt={imgAlt !== null ? imgAlt : src.name}
57
- className={className}
58
- onLoad={onLoad}
59
- title={imgTitle}
60
- {...props}
61
- />
62
- );
63
- if (typeof src === "string")
64
- return (
91
+ imageObjOrSrc &&
92
+ typeof imageObjOrSrc === "object" &&
93
+ !imageObjOrSrc.sizes
94
+ ) {
95
+ console.error("Image with no sizes", { variant, src, alt, props });
96
+ return null;
97
+ }
98
+
99
+ const [width, height] = getDimensions(imageObjOrSrc, variant);
100
+ const altAttr = alt || getAlt(src);
101
+ const [webp, fallback] = getSrc(imageObjOrSrc, variant);
102
+
103
+ return (
104
+ <picture>
105
+ {webp && <source srcSet={encodeURI(webp)} type="image/webp" />}
106
+ <source srcSet={encodeURI(fallback)} type={src.mime_type} />
65
107
  <img
66
- src={src}
67
- alt={src}
68
- className={className}
69
- onLoad={onLoad}
70
- title={imgTitle}
108
+ src={fallback}
109
+ alt={altAttr}
110
+ width={width}
111
+ height={height}
112
+ loading={loading}
71
113
  {...props}
72
114
  />
73
- );
115
+ </picture>
116
+ );
117
+ };
74
118
 
75
- return null;
119
+ Image.defaultProps = {
120
+ loading: "lazy",
76
121
  };
77
122
 
78
- export default Img;
123
+ export default Image;