@plasmicapp/react-web 0.2.79 → 0.2.83

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.
Files changed (61) hide show
  1. package/dist/all.d.ts +17 -1
  2. package/dist/react-web.cjs.development.js +108 -40
  3. package/dist/react-web.cjs.development.js.map +1 -1
  4. package/dist/react-web.cjs.production.min.js +1 -1
  5. package/dist/react-web.cjs.production.min.js.map +1 -1
  6. package/dist/react-web.esm.js +108 -40
  7. package/dist/react-web.esm.js.map +1 -1
  8. package/dist/render/PlasmicImg/index.d.ts +17 -1
  9. package/lib/plasmic.css +0 -3
  10. package/package.json +1 -1
  11. package/skinny/dist/collection-utils-4dae6efa.js +292 -0
  12. package/skinny/dist/{collection-utils-976df07d.js.map → collection-utils-4dae6efa.js.map} +1 -1
  13. package/skinny/dist/collection-utils-57ec40f9.js +292 -0
  14. package/skinny/dist/{collection-utils-21ad9cae.js.map → collection-utils-57ec40f9.js.map} +1 -1
  15. package/skinny/dist/collection-utils-b0b8f30e.js +287 -234
  16. package/skinny/dist/props-utils-5c0ad25a.js +59 -0
  17. package/skinny/dist/{props-utils-6cf101b2.js.map → props-utils-5c0ad25a.js.map} +1 -1
  18. package/skinny/dist/props-utils-c632595f.js +53 -33
  19. package/skinny/dist/props-utils-fd5f444e.js +59 -0
  20. package/skinny/dist/{props-utils-1f98cfd3.js.map → props-utils-fd5f444e.js.map} +1 -1
  21. package/skinny/dist/react-utils-118d8539.js +186 -168
  22. package/skinny/dist/react-utils-2a2fd6c9.js +339 -0
  23. package/skinny/dist/react-utils-2a2fd6c9.js.map +1 -0
  24. package/skinny/dist/react-utils-675565b4.js +334 -0
  25. package/skinny/dist/react-utils-675565b4.js.map +1 -0
  26. package/skinny/dist/render/PlasmicImg/index.d.ts +17 -1
  27. package/skinny/dist/render/PlasmicImg/index.js +90 -33
  28. package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
  29. package/skinny/dist/render/PlasmicImg.d.ts +62 -55
  30. package/skinny/dist/tslib.es6-00014098.js +143 -123
  31. package/skinny/dist/collection-utils-21ad9cae.js +0 -238
  32. package/skinny/dist/collection-utils-87ffc0ed.js +0 -238
  33. package/skinny/dist/collection-utils-87ffc0ed.js.map +0 -1
  34. package/skinny/dist/collection-utils-976df07d.js +0 -238
  35. package/skinny/dist/collection-utils-aadc3a43.js +0 -238
  36. package/skinny/dist/collection-utils-aadc3a43.js.map +0 -1
  37. package/skinny/dist/collection-utils-b8a2fd59.js +0 -238
  38. package/skinny/dist/collection-utils-b8a2fd59.js.map +0 -1
  39. package/skinny/dist/props-utils-1f98cfd3.js +0 -40
  40. package/skinny/dist/props-utils-40224c71.js +0 -40
  41. package/skinny/dist/props-utils-40224c71.js.map +0 -1
  42. package/skinny/dist/props-utils-69f9ba8b.js +0 -40
  43. package/skinny/dist/props-utils-69f9ba8b.js.map +0 -1
  44. package/skinny/dist/props-utils-6cf101b2.js +0 -39
  45. package/skinny/dist/props-utils-85691c9c.js +0 -40
  46. package/skinny/dist/props-utils-85691c9c.js.map +0 -1
  47. package/skinny/dist/react-utils-06bae09a.js +0 -254
  48. package/skinny/dist/react-utils-06bae09a.js.map +0 -1
  49. package/skinny/dist/react-utils-14af9d28.js +0 -172
  50. package/skinny/dist/react-utils-14af9d28.js.map +0 -1
  51. package/skinny/dist/react-utils-834a65c3.js +0 -254
  52. package/skinny/dist/react-utils-834a65c3.js.map +0 -1
  53. package/skinny/dist/react-utils-ae69f4e0.js +0 -254
  54. package/skinny/dist/react-utils-ae69f4e0.js.map +0 -1
  55. package/skinny/dist/react-utils-cca81efc.js +0 -245
  56. package/skinny/dist/react-utils-cca81efc.js.map +0 -1
  57. package/skinny/dist/stories/Button.d.ts +0 -29
  58. package/skinny/dist/stories/Header.d.ts +0 -10
  59. package/skinny/dist/stories/Page.d.ts +0 -10
  60. package/skinny/dist/tslib.es6-10d3f595.js +0 -132
  61. package/skinny/dist/tslib.es6-10d3f595.js.map +0 -1
package/dist/all.d.ts CHANGED
@@ -106,7 +106,7 @@ interface PlasmicImgProps extends ImgTagProps {
106
106
  * Either an object with the src string, and its full width and height,
107
107
  * or just a src string with unknown intrinsic dimensions.
108
108
  */
109
- src: string | {
109
+ src?: string | {
110
110
  src: string;
111
111
  fullHeight: number;
112
112
  fullWidth: number;
@@ -123,6 +123,22 @@ interface PlasmicImgProps extends ImgTagProps {
123
123
  * css height
124
124
  */
125
125
  displayHeight?: number | string;
126
+ /**
127
+ * css min-width
128
+ */
129
+ displayMinWidth?: number | string;
130
+ /**
131
+ * css min-height
132
+ */
133
+ displayMinHeight?: number | string;
134
+ /**
135
+ * css max-width
136
+ */
137
+ displayMaxWidth?: number | string;
138
+ /**
139
+ * css max-height
140
+ */
141
+ displayMaxHeight?: number | string;
126
142
  /**
127
143
  * For variable quality formats like jpg, the quality from 0 to 100
128
144
  */
@@ -812,23 +812,26 @@ var PlasmicImg = /*#__PURE__*/React__default.forwardRef(function PlasmicImg(prop
812
812
  className = props.className,
813
813
  displayWidth = props.displayWidth,
814
814
  displayHeight = props.displayHeight,
815
+ displayMinWidth = props.displayMinWidth,
816
+ displayMinHeight = props.displayMinHeight,
817
+ displayMaxWidth = props.displayMaxWidth,
818
+ displayMaxHeight = props.displayMaxHeight,
815
819
  quality = props.quality,
816
820
  loader = props.loader,
817
821
  containerRef = props.containerRef,
818
822
  style = props.style,
819
- rest = _objectWithoutPropertiesLoose(props, ["src", "className", "displayWidth", "displayHeight", "quality", "loader", "containerRef", "style"]);
823
+ rest = _objectWithoutPropertiesLoose(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "containerRef", "style"]);
820
824
 
821
- var _ref = typeof src === "string" ? {
825
+ var _ref = typeof src === "string" || !src ? {
822
826
  fullWidth: undefined,
823
827
  fullHeight: undefined
824
828
  } : src,
825
829
  fullWidth = _ref.fullWidth,
826
830
  fullHeight = _ref.fullHeight;
827
831
 
828
- var srcStr = typeof src === "string" ? src : src.src; // Assume external image if either dimension is null and use usual <img>
829
- // (or if the image is an SVG)
832
+ var srcStr = src ? typeof src === "string" ? src : src.src : ""; // Assume external image if either dimension is null and use usual <img>
830
833
 
831
- if (fullHeight == null || fullWidth == null || srcStr.endsWith(".svg")) {
834
+ if (fullHeight == null || fullWidth == null) {
832
835
  return React__default.createElement("img", Object.assign({
833
836
  src: srcStr,
834
837
  className: className,
@@ -838,29 +841,91 @@ var PlasmicImg = /*#__PURE__*/React__default.forwardRef(function PlasmicImg(prop
838
841
  }));
839
842
  }
840
843
 
841
- var _getWidths = getWidths(displayWidth, fullWidth),
844
+ if (isSvg(srcStr) && (displayHeight == null || displayHeight === "auto") && (displayWidth == null || displayWidth === "auto")) {
845
+ displayWidth = "100%";
846
+ }
847
+
848
+ if (fullWidth && fullHeight && (!displayWidth || displayWidth === "auto") && !!getPixelLength(displayHeight)) {
849
+ // If there's a pixel length specified for displayHeight but not displayWidth,
850
+ // then we can derive the pixel length for displayWidth. Having an explicit
851
+ // displayWidth makes this a fixed-size image, which makes it possible for us to
852
+ // generate better markup!
853
+ displayWidth = getPixelLength(displayHeight) * fullWidth / fullHeight;
854
+ }
855
+
856
+ var _getWidths = getWidths(displayWidth, fullWidth, {
857
+ minWidth: displayMinWidth
858
+ }),
842
859
  sizes = _getWidths.sizes,
843
860
  widthDescs = _getWidths.widthDescs;
844
861
 
845
862
  var imageLoader = getImageLoader(loader);
846
863
  var spacerSvg = "<svg width=\"" + fullWidth + "\" height=\"" + fullHeight + "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>";
847
864
  var spacerSvgBase64 = typeof window === "undefined" ? Buffer.from(spacerSvg).toString("base64") : window.btoa(spacerSvg);
865
+
866
+ var wrapperStyle = _extends({}, style || {});
867
+
868
+ var spacerStyle = pick(style || {}, "objectFit", "objectPosition");
869
+
870
+ if (displayWidth != null && displayWidth !== "auto") {
871
+ // If width is set, set it on the wrapper along with min/max width
872
+ // and just use `width: 100%` on the spacer
873
+ spacerStyle.width = "100%";
874
+ wrapperStyle.width = displayWidth;
875
+ wrapperStyle.minWidth = displayMinWidth;
876
+ wrapperStyle.maxWidth = displayMaxWidth;
877
+ } else {
878
+ // Otherwise, we want auto sizing from the spacer, so set width there.
879
+ //
880
+ // But if we have min/max width, it should be set in the wrapper and it
881
+ // can be percentage values (and we add corresponding min/max width to
882
+ // 100% in the spacer). In general it ends up with the correct effect,
883
+ // but some edge cases might make `min-width: 100%` shrink the image more
884
+ // than it should.
885
+ spacerStyle.width = displayWidth;
886
+ wrapperStyle.width = "auto";
887
+
888
+ if (displayMinWidth) {
889
+ spacerStyle.minWidth = "100%";
890
+ wrapperStyle.minWidth = displayMinWidth;
891
+ }
892
+
893
+ if (displayMaxWidth != null && displayMaxWidth !== "none") {
894
+ spacerStyle.maxWidth = "100%";
895
+ wrapperStyle.maxWidth = displayMaxWidth;
896
+ }
897
+ }
898
+
899
+ if (displayHeight != null && displayHeight !== "auto") {
900
+ spacerStyle.height = "100%";
901
+ wrapperStyle.height = displayHeight;
902
+ wrapperStyle.minHeight = displayMinHeight;
903
+ wrapperStyle.maxHeight = displayMaxHeight;
904
+ } else {
905
+ spacerStyle.height = displayHeight;
906
+ wrapperStyle.height = "auto";
907
+
908
+ if (displayMinHeight) {
909
+ spacerStyle.minHeight = "100%";
910
+ wrapperStyle.minHeight = displayMinHeight;
911
+ }
912
+
913
+ if (displayMaxHeight != null && displayMaxHeight !== "none") {
914
+ spacerStyle.maxHeight = "100%";
915
+ wrapperStyle.maxHeight = displayMaxHeight;
916
+ }
917
+ }
918
+
848
919
  return React__default.createElement("div", {
849
920
  className: classNames$1(className, "__wab_img-wrapper"),
850
921
  ref: containerRef,
851
- style: _extends({}, style, {
852
- width: isPercentage(displayWidth) ? displayWidth : undefined,
853
- height: isPercentage(displayHeight) ? displayHeight : undefined
854
- })
922
+ style: wrapperStyle
855
923
  }, React__default.createElement("img", {
856
924
  alt: "",
857
925
  "aria-hidden": true,
858
926
  className: "__wab_img-spacer-svg",
859
927
  src: "data:image/svg+xml;base64," + spacerSvgBase64,
860
- style: _extends({
861
- width: isPercentage(displayWidth) ? "100%" : displayWidth,
862
- height: isPercentage(displayHeight) ? "100%" : displayHeight
863
- }, style ? pick(style, "objectFit", "objectPosition") : {})
928
+ style: spacerStyle
864
929
  }), makePicture({
865
930
  imageLoader: imageLoader,
866
931
  widthDescs: widthDescs,
@@ -915,11 +980,18 @@ function makePicture(opts) {
915
980
  width: wd.width
916
981
  }) + " " + wd.desc;
917
982
  }).join(", ") : undefined,
918
- sizes: imageLoader ? sizes : undefined,
919
- style: style ? pick(style, "objectFit", "objectPosition") : undefined
983
+ sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined,
984
+ style: _extends({}, style ? pick(style, "objectFit", "objectPosition") : {}, {
985
+ width: 0,
986
+ height: 0
987
+ })
920
988
  })));
921
989
  }
922
990
 
991
+ function isSvg(src) {
992
+ return src.endsWith(".svg") || src.startsWith("data:image/svg");
993
+ }
994
+
923
995
  function getClosestPresetSize(width, fullWidth) {
924
996
  var _ALL_SIZES$findIndex;
925
997
 
@@ -948,17 +1020,19 @@ function getClosestPresetSize(width, fullWidth) {
948
1020
  */
949
1021
 
950
1022
 
951
- function getWidths(width, fullWidth) {
952
- var pixelWidth = getPixelWidth(width);
1023
+ function getWidths(width, fullWidth, extra) {
1024
+ var minWidth = extra == null ? void 0 : extra.minWidth;
1025
+ var pixelWidth = getPixelLength(width);
1026
+ var pixelMinWidth = getPixelLength(minWidth);
953
1027
 
954
- if (pixelWidth != null) {
1028
+ if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
955
1029
  // If there's an exact width, then we just need to display it at 1x and 2x density
956
1030
  return {
957
1031
  widthDescs: [{
958
- width: getClosestPresetSize(pixelWidth, fullWidth),
1032
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth != null ? pixelMinWidth : 0), fullWidth),
959
1033
  desc: "1x"
960
1034
  }, {
961
- width: getClosestPresetSize(pixelWidth * 2, fullWidth),
1035
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth != null ? pixelMinWidth : 0) * 2, fullWidth),
962
1036
  desc: "2x"
963
1037
  }],
964
1038
  sizes: undefined
@@ -984,15 +1058,19 @@ function getWidths(width, fullWidth) {
984
1058
  }
985
1059
 
986
1060
  return {
987
- widthDescs: usefulSizes.map(function (size, i) {
1061
+ widthDescs: usefulSizes.map(function (size) {
988
1062
  return {
989
- width: // If this is the last (buggest) useful width, but it is
1063
+ width: getClosestPresetSize(size, fullWidth),
1064
+ // If this is the last (buggest) useful width, but it is
990
1065
  // still within the bounds set by DEVICE_SIZES, then just
991
1066
  // use the original, unresized image. This means if we match
992
1067
  // the largest size, we use unresized and best quality image.
993
1068
  // We only do this, though, if fullWidth is "reasonable" --
994
1069
  // smaller than the largest size we would consider.
995
- i === usefulSizes.length - 1 && fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1] ? undefined : size,
1070
+ // i === usefulSizes.length - 1 &&
1071
+ // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
1072
+ // ? undefined
1073
+ // : size,
996
1074
  desc: size + "w"
997
1075
  };
998
1076
  }),
@@ -1000,26 +1078,16 @@ function getWidths(width, fullWidth) {
1000
1078
  };
1001
1079
  }
1002
1080
 
1003
- function isPercentage(width) {
1004
- var _parseNumeric;
1005
-
1006
- if (typeof width !== "string") {
1007
- return false;
1008
- }
1009
-
1010
- return ((_parseNumeric = parseNumeric(width)) == null ? void 0 : _parseNumeric.units) === "%";
1011
- }
1012
-
1013
- function getPixelWidth(width) {
1014
- if (width == null || width == "") {
1081
+ function getPixelLength(length) {
1082
+ if (length == null || length == "") {
1015
1083
  return undefined;
1016
1084
  }
1017
1085
 
1018
- if (typeof width === "number") {
1019
- return width;
1086
+ if (typeof length === "number") {
1087
+ return length;
1020
1088
  }
1021
1089
 
1022
- var parsed = parseNumeric(width);
1090
+ var parsed = parseNumeric(length);
1023
1091
 
1024
1092
  if (parsed && (!parsed.units || parsed.units === "px")) {
1025
1093
  return parsed.num;
@@ -1056,7 +1124,7 @@ function getImageLoader(loader) {
1056
1124
 
1057
1125
  var PLASMIC_IMAGE_LOADER = {
1058
1126
  supportsUrl: function supportsUrl(src) {
1059
- return src.startsWith("https://img.plasmic.app");
1127
+ return src.startsWith("https://img.plasmic.app") && !isSvg(src);
1060
1128
  },
1061
1129
  transformUrl: function transformUrl(opts) {
1062
1130
  var _opts$quality;