@plasmicapp/react-web 1.0.46 → 1.0.47

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.
@@ -729,7 +729,7 @@ var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
729
729
  var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
730
730
  var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
731
731
  var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef) {
732
- var src = props.src, className = props.className, displayWidth = 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"]);
732
+ 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"]);
733
733
  var imgProps = Object.assign({}, rest, {
734
734
  // Default loading to "lazy" if not specified (which is different from the
735
735
  // html img, which defaults to eager!)
@@ -751,11 +751,11 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
751
751
  if (fullHeight == null || fullWidth == null) {
752
752
  return (React__default.createElement("img", __assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
753
753
  }
754
- if (isSvg(srcStr) &&
754
+ var displayWidth = isSvg(srcStr) &&
755
755
  (displayHeight == null || displayHeight === "auto") &&
756
- (displayWidth == null || displayWidth === "auto")) {
757
- displayWidth = "100%";
758
- }
756
+ (requestedWidth == null || requestedWidth === "auto")
757
+ ? "100%"
758
+ : requestedWidth;
759
759
  var computedDisplayWidth = displayWidth;
760
760
  if (fullWidth &&
761
761
  fullHeight &&
@@ -775,7 +775,7 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
775
775
  }
776
776
  var spacerWidth = fullWidth;
777
777
  var spacerHeight = fullHeight;
778
- if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
778
+ if (aspectRatio && Number.isFinite(aspectRatio) && isSvg(srcStr)) {
779
779
  // For SVGs, fullWidth and fullHeight can be rounded values, which would
780
780
  // cause some discrepancy between the actual aspect ratio and the aspect
781
781
  // ratio from those values. So, for those cases, we size the spacer from
@@ -787,7 +787,7 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
787
787
  var _b = getWidths(computedDisplayWidth, fullWidth, {
788
788
  minWidth: displayMinWidth,
789
789
  }), sizes = _b.sizes, widthDescs = _b.widthDescs;
790
- var imageLoader = getImageLoader(loader);
790
+ var transformUrl = getImageTransform(loader, srcStr);
791
791
  var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
792
792
  var spacerSvgBase64 =
793
793
  // if btoa exists, use btoa, as it works in browser and in
@@ -848,7 +848,7 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
848
848
  return (React__default.createElement("div", { className: classNames$1(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
849
849
  React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
850
850
  makePicture({
851
- imageLoader: imageLoader,
851
+ transformUrl: transformUrl,
852
852
  widthDescs: widthDescs,
853
853
  sizes: sizes,
854
854
  src: srcStr,
@@ -861,14 +861,11 @@ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef)
861
861
  })));
862
862
  });
863
863
  function makePicture(opts) {
864
- // If imageLoader is undefined, then this renders to just a normal
865
- // <img />. Else it will render to a <picture> with a <source> for
866
- // webp, and srcSet/sizes set according to width requirements.
867
- 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;
864
+ 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;
868
865
  return (React__default.createElement("picture", { className: "__wab_picture" },
869
- imageLoader && imageLoader.supportsUrl(src) && !format && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
866
+ transformUrl && !format && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
870
867
  .map(function (wd) {
871
- return "".concat(imageLoader.transformUrl({
868
+ return "".concat(transformUrl({
872
869
  src: src,
873
870
  quality: quality,
874
871
  width: wd.width,
@@ -876,17 +873,17 @@ function makePicture(opts) {
876
873
  }), " ").concat(wd.desc);
877
874
  })
878
875
  .join(", ") })),
879
- React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
880
- ? imageLoader.transformUrl({
876
+ React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: transformUrl
877
+ ? transformUrl({
881
878
  src: src,
882
879
  quality: quality,
883
880
  format: format,
884
881
  width: widthDescs[widthDescs.length - 1].width,
885
882
  })
886
- : src, srcSet: imageLoader && imageLoader.supportsUrl(src)
883
+ : src, srcSet: transformUrl
887
884
  ? widthDescs
888
885
  .map(function (wd) {
889
- return "".concat(imageLoader.transformUrl({
886
+ return "".concat(transformUrl({
890
887
  src: src,
891
888
  quality: quality,
892
889
  format: format,
@@ -894,7 +891,7 @@ function makePicture(opts) {
894
891
  }), " ").concat(wd.desc);
895
892
  })
896
893
  .join(", ")
897
- : undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
894
+ : undefined, sizes: transformUrl ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
898
895
  }
899
896
  var DEFAULT_SVG_WIDTH = 10000;
900
897
  function isSvg(src) {
@@ -1005,41 +1002,45 @@ function getImageSizeData(width, height) {
1005
1002
  return {
1006
1003
  fullWidth: width,
1007
1004
  fullHeight: height,
1008
- aspectRatio: aspectRatio && isFinite(aspectRatio) ? aspectRatio : undefined,
1005
+ aspectRatio: aspectRatio && Number.isFinite(aspectRatio) ? aspectRatio : undefined,
1009
1006
  };
1010
1007
  }
1011
- function getImageLoader(loader) {
1012
- if (loader == null) {
1013
- return undefined;
1014
- }
1015
- else if (loader === "plasmic") {
1016
- return makePlasmicImageLoader(IMG_OPTIMIZER_HOST);
1017
- }
1018
- else if (typeof loader === "string") {
1019
- return makePlasmicImageLoader(loader);
1008
+ function getImageTransform(loader, src) {
1009
+ var _a;
1010
+ if (typeof loader !== "string") {
1011
+ return (loader === null || loader === void 0 ? void 0 : loader.supportsUrl(src))
1012
+ ? loader.transformUrl.bind(loader)
1013
+ : undefined;
1014
+ }
1015
+ var host = loader === "plasmic" ? IMG_OPTIMIZER_HOST : loader.replace(/\/+$/, "");
1016
+ var key = src;
1017
+ if (/^https?:\/\//i.test(src)) {
1018
+ try {
1019
+ var url = new URL(src);
1020
+ if (url.hostname !== "site-assets.plasmic.app" &&
1021
+ url.hostname !== "img.plasmic.app" &&
1022
+ url.origin !== new URL(host).origin) {
1023
+ return undefined;
1024
+ }
1025
+ key = (_a = url.pathname.split("/").pop()) !== null && _a !== void 0 ? _a : "";
1026
+ }
1027
+ catch (_b) {
1028
+ return undefined;
1029
+ }
1020
1030
  }
1021
- else {
1022
- return loader;
1031
+ if (!/^[a-f0-9]{32}\.[a-z0-9]{1,16}$/i.test(key) || /\.svg$/i.test(key)) {
1032
+ return undefined;
1023
1033
  }
1024
- }
1025
- function isInternalKey(src) {
1026
- return /^([a-f0-9]{32})\..{1,16}$/i.test(src);
1027
- }
1028
- var makePlasmicImageLoader = function (host) { return ({
1029
- supportsUrl: function (src) {
1030
- return (src.startsWith("http") || isInternalKey(src)) && !isSvg(src);
1031
- },
1032
- transformUrl: function (opts) {
1033
- var _a;
1034
+ return function (_a) {
1035
+ var width = _a.width, quality = _a.quality, format = _a.format;
1034
1036
  var params = [
1035
- "src=".concat(encodeURIComponent(opts.src)),
1036
- opts.width ? "w=".concat(opts.width) : undefined,
1037
- "q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
1038
- opts.format ? "f=".concat(opts.format) : undefined,
1039
- ].filter(function (x) { return !!x; });
1040
- return "".concat(host, "/img-optimizer/v1/img?").concat(params.join("&"));
1041
- },
1042
- }); };
1037
+ width ? "w=".concat(width) : undefined,
1038
+ "q=".concat(quality !== null && quality !== void 0 ? quality : 75),
1039
+ format ? "f=".concat(format) : undefined,
1040
+ ].filter(Boolean);
1041
+ return "".concat(host, "/i/").concat(key, "?").concat(params.join("&"));
1042
+ };
1043
+ }
1043
1044
 
1044
1045
  // These props are used internally by PlasmicLink to determine how to render the link
1045
1046
  var INTERNAL_PROPS = ["component", "platform", "legacyBehavior"];