@plasmicapp/react-web 1.0.46 → 1.0.48
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/README.md +3 -0
- package/dist/index.cjs.js +50 -49
- package/dist/index.cjs.js.map +1 -1
- package/dist/react-web.esm.js +50 -49
- package/dist/react-web.esm.js.map +1 -1
- package/package.json +4 -4
- package/skinny/dist/render/PlasmicImg/index.js +49 -48
- package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,9 @@ This is the runtime for code generated by Plasmic, the visual builder for React.
|
|
|
4
4
|
This package contains functions
|
|
5
5
|
and type definitions used by generated presentational code.
|
|
6
6
|
|
|
7
|
+
`PlasmicImg` serves external images directly when using the built-in loader.
|
|
8
|
+
To resize external images, pass a custom `ImageLoader` object.
|
|
9
|
+
|
|
7
10
|
Learn more about Plasmic:
|
|
8
11
|
|
|
9
12
|
https://www.plasmic.app
|
package/dist/index.cjs.js
CHANGED
|
@@ -748,7 +748,7 @@ var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
|
748
748
|
var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
|
|
749
749
|
var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
|
|
750
750
|
var PlasmicImg = React.forwardRef(function PlasmicImg(props, outerRef) {
|
|
751
|
-
var src = props.src, className = props.className,
|
|
751
|
+
var src = props.src, className = props.className, requestedWidth = props.displayWidth, displayHeight = props.displayHeight, displayMinWidth = props.displayMinWidth, displayMinHeight = props.displayMinHeight, displayMaxWidth = props.displayMaxWidth, displayMaxHeight = props.displayMaxHeight, quality = props.quality, format = props.format, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = __rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "format", "loader", "imgRef", "style", "loading"]);
|
|
752
752
|
var imgProps = Object.assign({}, rest, {
|
|
753
753
|
// Default loading to "lazy" if not specified (which is different from the
|
|
754
754
|
// html img, which defaults to eager!)
|
|
@@ -770,11 +770,11 @@ var PlasmicImg = React.forwardRef(function PlasmicImg(props, outerRef) {
|
|
|
770
770
|
if (fullHeight == null || fullWidth == null) {
|
|
771
771
|
return (React.createElement("img", __assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
|
|
772
772
|
}
|
|
773
|
-
|
|
773
|
+
var displayWidth = isSvg(srcStr) &&
|
|
774
774
|
(displayHeight == null || displayHeight === "auto") &&
|
|
775
|
-
(
|
|
776
|
-
|
|
777
|
-
|
|
775
|
+
(requestedWidth == null || requestedWidth === "auto")
|
|
776
|
+
? "100%"
|
|
777
|
+
: requestedWidth;
|
|
778
778
|
var computedDisplayWidth = displayWidth;
|
|
779
779
|
if (fullWidth &&
|
|
780
780
|
fullHeight &&
|
|
@@ -794,7 +794,7 @@ var PlasmicImg = React.forwardRef(function PlasmicImg(props, outerRef) {
|
|
|
794
794
|
}
|
|
795
795
|
var spacerWidth = fullWidth;
|
|
796
796
|
var spacerHeight = fullHeight;
|
|
797
|
-
if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
|
|
797
|
+
if (aspectRatio && Number.isFinite(aspectRatio) && isSvg(srcStr)) {
|
|
798
798
|
// For SVGs, fullWidth and fullHeight can be rounded values, which would
|
|
799
799
|
// cause some discrepancy between the actual aspect ratio and the aspect
|
|
800
800
|
// ratio from those values. So, for those cases, we size the spacer from
|
|
@@ -806,7 +806,7 @@ var PlasmicImg = React.forwardRef(function PlasmicImg(props, outerRef) {
|
|
|
806
806
|
var _b = getWidths(computedDisplayWidth, fullWidth, {
|
|
807
807
|
minWidth: displayMinWidth,
|
|
808
808
|
}), sizes = _b.sizes, widthDescs = _b.widthDescs;
|
|
809
|
-
var
|
|
809
|
+
var transformUrl = getImageTransform(loader, srcStr);
|
|
810
810
|
var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
|
|
811
811
|
var spacerSvgBase64 =
|
|
812
812
|
// if btoa exists, use btoa, as it works in browser and in
|
|
@@ -867,7 +867,7 @@ var PlasmicImg = React.forwardRef(function PlasmicImg(props, outerRef) {
|
|
|
867
867
|
return (React.createElement("div", { className: classNames$1(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
|
|
868
868
|
React.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
|
|
869
869
|
makePicture({
|
|
870
|
-
|
|
870
|
+
transformUrl: transformUrl,
|
|
871
871
|
widthDescs: widthDescs,
|
|
872
872
|
sizes: sizes,
|
|
873
873
|
src: srcStr,
|
|
@@ -880,14 +880,11 @@ var PlasmicImg = React.forwardRef(function PlasmicImg(props, outerRef) {
|
|
|
880
880
|
})));
|
|
881
881
|
});
|
|
882
882
|
function makePicture(opts) {
|
|
883
|
-
|
|
884
|
-
// <img />. Else it will render to a <picture> with a <source> for
|
|
885
|
-
// webp, and srcSet/sizes set according to width requirements.
|
|
886
|
-
var imageLoader = opts.imageLoader, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, format = opts.format, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
|
|
883
|
+
var transformUrl = opts.transformUrl, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, format = opts.format, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
|
|
887
884
|
return (React.createElement("picture", { className: "__wab_picture" },
|
|
888
|
-
|
|
885
|
+
transformUrl && !format && (React.createElement("source", { type: "image/webp", srcSet: widthDescs
|
|
889
886
|
.map(function (wd) {
|
|
890
|
-
return "".concat(
|
|
887
|
+
return "".concat(transformUrl({
|
|
891
888
|
src: src,
|
|
892
889
|
quality: quality,
|
|
893
890
|
width: wd.width,
|
|
@@ -895,17 +892,17 @@ function makePicture(opts) {
|
|
|
895
892
|
}), " ").concat(wd.desc);
|
|
896
893
|
})
|
|
897
894
|
.join(", ") })),
|
|
898
|
-
React.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src:
|
|
899
|
-
?
|
|
895
|
+
React.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: transformUrl
|
|
896
|
+
? transformUrl({
|
|
900
897
|
src: src,
|
|
901
898
|
quality: quality,
|
|
902
899
|
format: format,
|
|
903
900
|
width: widthDescs[widthDescs.length - 1].width,
|
|
904
901
|
})
|
|
905
|
-
: src, srcSet:
|
|
902
|
+
: src, srcSet: transformUrl
|
|
906
903
|
? widthDescs
|
|
907
904
|
.map(function (wd) {
|
|
908
|
-
return "".concat(
|
|
905
|
+
return "".concat(transformUrl({
|
|
909
906
|
src: src,
|
|
910
907
|
quality: quality,
|
|
911
908
|
format: format,
|
|
@@ -913,7 +910,7 @@ function makePicture(opts) {
|
|
|
913
910
|
}), " ").concat(wd.desc);
|
|
914
911
|
})
|
|
915
912
|
.join(", ")
|
|
916
|
-
: undefined, sizes:
|
|
913
|
+
: undefined, sizes: transformUrl ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
|
|
917
914
|
}
|
|
918
915
|
var DEFAULT_SVG_WIDTH = 10000;
|
|
919
916
|
function isSvg(src) {
|
|
@@ -1024,41 +1021,45 @@ function getImageSizeData(width, height) {
|
|
|
1024
1021
|
return {
|
|
1025
1022
|
fullWidth: width,
|
|
1026
1023
|
fullHeight: height,
|
|
1027
|
-
aspectRatio: aspectRatio && isFinite(aspectRatio) ? aspectRatio : undefined,
|
|
1024
|
+
aspectRatio: aspectRatio && Number.isFinite(aspectRatio) ? aspectRatio : undefined,
|
|
1028
1025
|
};
|
|
1029
1026
|
}
|
|
1030
|
-
function
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1027
|
+
function getImageTransform(loader, src) {
|
|
1028
|
+
var _a;
|
|
1029
|
+
if (typeof loader !== "string") {
|
|
1030
|
+
return (loader === null || loader === void 0 ? void 0 : loader.supportsUrl(src))
|
|
1031
|
+
? loader.transformUrl.bind(loader)
|
|
1032
|
+
: undefined;
|
|
1033
|
+
}
|
|
1034
|
+
var host = loader === "plasmic" ? IMG_OPTIMIZER_HOST : loader.replace(/\/+$/, "");
|
|
1035
|
+
var key = src;
|
|
1036
|
+
if (/^https?:\/\//i.test(src)) {
|
|
1037
|
+
try {
|
|
1038
|
+
var url = new URL(src);
|
|
1039
|
+
if (url.hostname !== "site-assets.plasmic.app" &&
|
|
1040
|
+
url.hostname !== "img.plasmic.app" &&
|
|
1041
|
+
url.origin !== new URL(host).origin) {
|
|
1042
|
+
return undefined;
|
|
1043
|
+
}
|
|
1044
|
+
key = (_a = url.pathname.split("/").pop()) !== null && _a !== void 0 ? _a : "";
|
|
1045
|
+
}
|
|
1046
|
+
catch (_b) {
|
|
1047
|
+
return undefined;
|
|
1048
|
+
}
|
|
1039
1049
|
}
|
|
1040
|
-
|
|
1041
|
-
return
|
|
1050
|
+
if (!/^[a-f0-9]{32}\.[a-z0-9]{1,16}$/i.test(key) || /\.svg$/i.test(key)) {
|
|
1051
|
+
return undefined;
|
|
1042
1052
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
return /^([a-f0-9]{32})\..{1,16}$/i.test(src);
|
|
1046
|
-
}
|
|
1047
|
-
var makePlasmicImageLoader = function (host) { return ({
|
|
1048
|
-
supportsUrl: function (src) {
|
|
1049
|
-
return (src.startsWith("http") || isInternalKey(src)) && !isSvg(src);
|
|
1050
|
-
},
|
|
1051
|
-
transformUrl: function (opts) {
|
|
1052
|
-
var _a;
|
|
1053
|
+
return function (_a) {
|
|
1054
|
+
var width = _a.width, quality = _a.quality, format = _a.format;
|
|
1053
1055
|
var params = [
|
|
1054
|
-
"
|
|
1055
|
-
|
|
1056
|
-
"
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}); };
|
|
1056
|
+
width ? "w=".concat(width) : undefined,
|
|
1057
|
+
"q=".concat(quality !== null && quality !== void 0 ? quality : 75),
|
|
1058
|
+
format ? "f=".concat(format) : undefined,
|
|
1059
|
+
].filter(Boolean);
|
|
1060
|
+
return "".concat(host, "/i/").concat(key, "?").concat(params.join("&"));
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1062
1063
|
|
|
1063
1064
|
// These props are used internally by PlasmicLink to determine how to render the link
|
|
1064
1065
|
var INTERNAL_PROPS = ["component", "platform", "legacyBehavior"];
|