@plasmicapp/react-web 0.2.200 → 0.2.202

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 (148) hide show
  1. package/dist/all.d.ts +1926 -1925
  2. package/dist/auth/PlasmicPageGuard.d.ts +11 -11
  3. package/dist/common.d.ts +10 -10
  4. package/dist/data-sources/index.d.ts +1 -1
  5. package/dist/host/index.d.ts +1 -1
  6. package/dist/index-common.d.ts +18 -18
  7. package/dist/index-skinny.d.ts +1 -1
  8. package/dist/index.cjs.js +3495 -3495
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.d.ts +11 -11
  11. package/dist/plume/button/index.d.ts +36 -36
  12. package/dist/plume/checkbox/index.d.ts +47 -47
  13. package/dist/plume/collection-utils.d.ts +191 -191
  14. package/dist/plume/collection-utils.spec.d.ts +1 -1
  15. package/dist/plume/menu/context.d.ts +8 -8
  16. package/dist/plume/menu/index.d.ts +3 -3
  17. package/dist/plume/menu/menu-group.d.ts +23 -23
  18. package/dist/plume/menu/menu-item.d.ts +23 -23
  19. package/dist/plume/menu/menu.d.ts +39 -39
  20. package/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  21. package/dist/plume/menu-button/index.d.ts +2 -2
  22. package/dist/plume/menu-button/menu-button.d.ts +72 -72
  23. package/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  24. package/dist/plume/plume-utils.d.ts +41 -41
  25. package/dist/plume/props-utils.d.ts +15 -15
  26. package/dist/plume/select/context.d.ts +3 -3
  27. package/dist/plume/select/index.d.ts +4 -4
  28. package/dist/plume/select/select-option-group.d.ts +23 -23
  29. package/dist/plume/select/select-option.d.ts +23 -23
  30. package/dist/plume/select/select.d.ts +111 -111
  31. package/dist/plume/switch/index.d.ts +39 -39
  32. package/dist/plume/text-input/index.d.ts +36 -36
  33. package/dist/plume/triggered-overlay/context.d.ts +14 -14
  34. package/dist/plume/triggered-overlay/index.d.ts +2 -2
  35. package/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  36. package/dist/query/index.d.ts +1 -1
  37. package/dist/react-utils.d.ts +21 -21
  38. package/dist/react-utils.spec.d.ts +1 -1
  39. package/dist/react-web.esm.js +3496 -3496
  40. package/dist/react-web.esm.js.map +1 -1
  41. package/dist/render/PlasmicHead/index.d.ts +37 -37
  42. package/dist/render/PlasmicIcon.d.ts +4 -4
  43. package/dist/render/PlasmicImg/index.d.ts +81 -81
  44. package/dist/render/PlasmicLink.d.ts +2 -2
  45. package/dist/render/PlasmicSlot.d.ts +11 -11
  46. package/dist/render/Stack.d.ts +51 -51
  47. package/dist/render/elements.d.ts +74 -74
  48. package/dist/render/global-variants.d.ts +1 -1
  49. package/dist/render/screen-variants.d.ts +5 -5
  50. package/dist/render/ssr.d.ts +21 -21
  51. package/dist/render/translation.d.ts +19 -19
  52. package/dist/render/triggers.d.ts +39 -39
  53. package/dist/states/errors.d.ts +13 -13
  54. package/dist/states/graph.d.ts +25 -25
  55. package/dist/states/helpers.d.ts +43 -43
  56. package/dist/states/index.d.ts +4 -4
  57. package/dist/states/types.d.ts +66 -66
  58. package/dist/states/valtio.d.ts +10 -10
  59. package/dist/states/vanilla.d.ts +3 -3
  60. package/dist/stories/PlasmicImg.stories.d.ts +6 -6
  61. package/dist/stories/UseDollarState.stories.d.ts +78 -78
  62. package/lib/data-sources/index.d.ts +1 -1
  63. package/lib/host/index.d.ts +1 -1
  64. package/lib/query/index.d.ts +1 -1
  65. package/package.json +9 -10
  66. package/skinny/dist/auth/PlasmicPageGuard.d.ts +11 -11
  67. package/skinny/dist/{collection-utils-0967eaf0.js → collection-utils-2f28e4eb.js} +297 -297
  68. package/skinny/dist/{collection-utils-0967eaf0.js.map → collection-utils-2f28e4eb.js.map} +1 -1
  69. package/skinny/dist/{common-9d6d348d.js → common-ed411407.js} +130 -130
  70. package/skinny/dist/{common-9d6d348d.js.map → common-ed411407.js.map} +1 -1
  71. package/skinny/dist/common.d.ts +10 -10
  72. package/skinny/dist/data-sources/index.d.ts +1 -1
  73. package/skinny/dist/host/index.d.ts +1 -1
  74. package/skinny/dist/index-common.d.ts +18 -18
  75. package/skinny/dist/index-skinny.d.ts +1 -1
  76. package/skinny/dist/index.d.ts +11 -11
  77. package/skinny/dist/index.js +1559 -1559
  78. package/skinny/dist/index.js.map +1 -1
  79. package/skinny/dist/plume/button/index.d.ts +36 -36
  80. package/skinny/dist/plume/button/index.js +21 -21
  81. package/skinny/dist/plume/checkbox/index.d.ts +47 -47
  82. package/skinny/dist/plume/checkbox/index.js +64 -64
  83. package/skinny/dist/plume/collection-utils.d.ts +191 -191
  84. package/skinny/dist/plume/collection-utils.spec.d.ts +1 -1
  85. package/skinny/dist/plume/menu/context.d.ts +8 -8
  86. package/skinny/dist/plume/menu/index.d.ts +3 -3
  87. package/skinny/dist/plume/menu/index.js +165 -165
  88. package/skinny/dist/plume/menu/menu-group.d.ts +23 -23
  89. package/skinny/dist/plume/menu/menu-item.d.ts +23 -23
  90. package/skinny/dist/plume/menu/menu.d.ts +39 -39
  91. package/skinny/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
  92. package/skinny/dist/plume/menu-button/index.d.ts +2 -2
  93. package/skinny/dist/plume/menu-button/index.js +125 -125
  94. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  95. package/skinny/dist/plume/menu-button/menu-button.d.ts +72 -72
  96. package/skinny/dist/plume/menu-button/menu-trigger.d.ts +21 -21
  97. package/skinny/dist/plume/plume-utils.d.ts +41 -41
  98. package/skinny/dist/plume/props-utils.d.ts +15 -15
  99. package/skinny/dist/plume/select/context.d.ts +3 -3
  100. package/skinny/dist/plume/select/index.d.ts +4 -4
  101. package/skinny/dist/plume/select/index.js +250 -250
  102. package/skinny/dist/plume/select/index.js.map +1 -1
  103. package/skinny/dist/plume/select/select-option-group.d.ts +23 -23
  104. package/skinny/dist/plume/select/select-option.d.ts +23 -23
  105. package/skinny/dist/plume/select/select.d.ts +111 -111
  106. package/skinny/dist/plume/switch/index.d.ts +39 -39
  107. package/skinny/dist/plume/switch/index.js +61 -61
  108. package/skinny/dist/plume/text-input/index.d.ts +36 -36
  109. package/skinny/dist/plume/text-input/index.js +45 -45
  110. package/skinny/dist/plume/triggered-overlay/context.d.ts +14 -14
  111. package/skinny/dist/plume/triggered-overlay/index.d.ts +2 -2
  112. package/skinny/dist/plume/triggered-overlay/index.js +100 -100
  113. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  114. package/skinny/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
  115. package/skinny/dist/{plume-utils-7d68bcc0.js → plume-utils-e699cd08.js} +30 -30
  116. package/skinny/dist/{plume-utils-7d68bcc0.js.map → plume-utils-e699cd08.js.map} +1 -1
  117. package/skinny/dist/{props-utils-9f9c761a.js → props-utils-9d74371f.js} +4 -4
  118. package/skinny/dist/{props-utils-9f9c761a.js.map → props-utils-9d74371f.js.map} +1 -1
  119. package/skinny/dist/query/index.d.ts +1 -1
  120. package/skinny/dist/{react-utils-ee4e03ba.js → react-utils-5ff031c2.js} +195 -195
  121. package/skinny/dist/{react-utils-ee4e03ba.js.map → react-utils-5ff031c2.js.map} +1 -1
  122. package/skinny/dist/react-utils.d.ts +21 -21
  123. package/skinny/dist/react-utils.spec.d.ts +1 -1
  124. package/skinny/dist/render/PlasmicHead/index.d.ts +37 -37
  125. package/skinny/dist/render/PlasmicHead/index.js +54 -54
  126. package/skinny/dist/render/PlasmicIcon.d.ts +4 -4
  127. package/skinny/dist/render/PlasmicImg/index.d.ts +81 -81
  128. package/skinny/dist/render/PlasmicImg/index.js +297 -297
  129. package/skinny/dist/render/PlasmicLink.d.ts +2 -2
  130. package/skinny/dist/render/PlasmicSlot.d.ts +11 -11
  131. package/skinny/dist/render/Stack.d.ts +51 -51
  132. package/skinny/dist/render/elements.d.ts +74 -74
  133. package/skinny/dist/render/global-variants.d.ts +1 -1
  134. package/skinny/dist/render/screen-variants.d.ts +5 -5
  135. package/skinny/dist/render/ssr.d.ts +21 -21
  136. package/skinny/dist/render/translation.d.ts +19 -19
  137. package/skinny/dist/render/triggers.d.ts +39 -39
  138. package/skinny/dist/{ssr-c9834f50.js → ssr-8625df04.js} +107 -107
  139. package/skinny/dist/{ssr-c9834f50.js.map → ssr-8625df04.js.map} +1 -1
  140. package/skinny/dist/states/errors.d.ts +13 -13
  141. package/skinny/dist/states/graph.d.ts +25 -25
  142. package/skinny/dist/states/helpers.d.ts +43 -43
  143. package/skinny/dist/states/index.d.ts +4 -4
  144. package/skinny/dist/states/types.d.ts +66 -66
  145. package/skinny/dist/states/valtio.d.ts +10 -10
  146. package/skinny/dist/states/vanilla.d.ts +3 -3
  147. package/skinny/dist/stories/PlasmicImg.stories.d.ts +6 -6
  148. package/skinny/dist/stories/UseDollarState.stories.d.ts +78 -78
@@ -1,303 +1,303 @@
1
- import { d as __spreadArray, e as __read, c as __rest, b as __assign, p as pick } from '../../common-9d6d348d.js';
1
+ import { d as __spreadArray, e as __read, c as __rest, b as __assign, p as pick } from '../../common-ed411407.js';
2
2
  import classNames from 'classnames';
3
3
  import React__default from 'react';
4
- import { d as mergeRefs } from '../../react-utils-ee4e03ba.js';
4
+ import { d as mergeRefs } from '../../react-utils-5ff031c2.js';
5
5
 
6
- /**
7
- * Responsive `<img/>` replacement, based on `next/image`
8
- */
9
- // Default image sizes to snap to
10
- // TODO: make this configurable?
11
- var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
12
- var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
13
- var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
14
- var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef) {
15
- 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, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = __rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
16
- var imgProps = Object.assign({}, rest, {
17
- // Default loading to "lazy" if not specified (which is different from the
18
- // html img, which defaults to eager!)
19
- loading: loading !== null && loading !== void 0 ? loading : "lazy"
20
- });
21
- var _a = typeof src === "string" || !src
22
- ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }
23
- : src, fullWidth = _a.fullWidth, fullHeight = _a.fullHeight, aspectRatio = _a.aspectRatio;
24
- var srcStr = src
25
- ? typeof src === "string"
26
- ? src
27
- : typeof src.src === "string"
28
- ? src.src
29
- : src.src.src
30
- : "";
31
- // Assume external image if either dimension is null and use usual <img>
32
- if (fullHeight == null || fullWidth == null) {
33
- return (React__default.createElement("img", __assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
34
- }
35
- if (isSvg(srcStr) &&
36
- (displayHeight == null || displayHeight === "auto") &&
37
- (displayWidth == null || displayWidth === "auto")) {
38
- displayWidth = "100%";
39
- }
40
- var computedDisplayWidth = displayWidth;
41
- if (fullWidth &&
42
- fullHeight &&
43
- (!displayWidth || displayWidth === "auto") &&
44
- !!getPixelLength(displayHeight)) {
45
- // If there's a pixel length specified for displayHeight but not displayWidth,
46
- // then we can derive the pixel length for displayWidth. Having an explicit
47
- // displayWidth makes this a fixed-size image, which makes it possible for us to
48
- // generate better markup!
49
- if (!isSvg(srcStr)) {
50
- // We shouldn't do it for SVGs though, because `fullWidth` and
51
- // `fullHeight` might have rounded values so the final
52
- // `displayWidth` could differ by 1px or so.
53
- computedDisplayWidth =
54
- (getPixelLength(displayHeight) * fullWidth) / fullHeight;
55
- }
56
- }
57
- var spacerWidth = fullWidth;
58
- var spacerHeight = fullHeight;
59
- if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
60
- // For SVGs, fullWidth and fullHeight can be rounded values, which would
61
- // cause some discrepancy between the actual aspect ratio and the aspect
62
- // ratio from those values. So, for those cases, we set large width / height
63
- // values to get a more precise ratio from the spacer.
64
- spacerWidth = DEFAULT_SVG_WIDTH;
65
- spacerHeight = Math.round(spacerWidth / aspectRatio);
66
- }
67
- var _b = getWidths(computedDisplayWidth, fullWidth, {
68
- minWidth: displayMinWidth
69
- }), sizes = _b.sizes, widthDescs = _b.widthDescs;
70
- var imageLoader = getImageLoader(loader);
71
- var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
72
- var spacerSvgBase64 = typeof window === "undefined"
73
- ? Buffer.from(spacerSvg).toString("base64")
74
- : window.btoa(spacerSvg);
75
- var wrapperStyle = __assign({}, (style || {}));
76
- var spacerStyle = __assign({}, pick(style || {}, "objectFit", "objectPosition"));
77
- if (displayWidth != null && displayWidth !== "auto") {
78
- // If width is set, set it on the wrapper along with min/max width
79
- // and just use `width: 100%` on the spacer
80
- spacerStyle.width = "100%";
81
- // Rely on the styles set by `classname` on the wrapper:
82
- // wrapperStyle.width = displayWidth;
83
- // wrapperStyle.minWidth = displayMinWidth;
84
- // wrapperStyle.maxWidth = displayMaxWidth;
85
- }
86
- else {
87
- // Otherwise, we want auto sizing from the spacer, so set width there.
88
- //
89
- // But if we have min/max width, it should be set in the wrapper and it
90
- // can be percentage values (and we add corresponding min/max width to
91
- // 100% in the spacer). In general it ends up with the correct effect,
92
- // but some edge cases might make `min-width: 100%` shrink the image more
93
- // than it should.
94
- spacerStyle.width = displayWidth;
95
- wrapperStyle.width = "auto";
96
- if (displayMinWidth) {
97
- spacerStyle.minWidth = "100%";
98
- // Rely on min-width set by `classname` on the wrapper:
99
- // wrapperStyle.minWidth = displayMinWidth;
100
- }
101
- if (displayMaxWidth != null && displayMaxWidth !== "none") {
102
- spacerStyle.maxWidth = "100%";
103
- // Rely on max-width set by `classname` on the wrapper:
104
- // wrapperStyle.maxWidth = displayMaxWidth;
105
- }
106
- }
107
- if (displayHeight != null && displayHeight !== "auto") {
108
- spacerStyle.height = "100%";
109
- // wrapperStyle.height = displayHeight;
110
- // wrapperStyle.minHeight = displayMinHeight;
111
- // wrapperStyle.maxHeight = displayMaxHeight;
112
- }
113
- else {
114
- spacerStyle.height = displayHeight;
115
- wrapperStyle.height = "auto";
116
- if (displayMinHeight) {
117
- spacerStyle.minHeight = "100%";
118
- // wrapperStyle.minHeight = displayMinHeight;
119
- }
120
- if (displayMaxHeight != null && displayMaxHeight !== "none") {
121
- spacerStyle.maxHeight = "100%";
122
- // wrapperStyle.maxHeight = displayMaxHeight;
123
- }
124
- }
125
- return (React__default.createElement("div", { className: classNames(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
126
- React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
127
- makePicture({
128
- imageLoader: imageLoader,
129
- widthDescs: widthDescs,
130
- sizes: sizes,
131
- src: srcStr,
132
- quality: quality,
133
- ref: imgRef,
134
- style: style ? pick(style, "objectFit", "objectPosition") : undefined,
135
- imgProps: imgProps,
136
- className: "__wab_img"
137
- })));
138
- });
139
- function makePicture(opts) {
140
- // If imageLoader is undefined, then this renders to just a normal
141
- // <img />. Else it will render to a <picture> with a <source> for
142
- // webp, and srcSet/sizes set according to width requirements.
143
- var imageLoader = opts.imageLoader, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
144
- return (React__default.createElement("picture", { className: "__wab_picture" },
145
- imageLoader && imageLoader.supportsUrl(src) && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
146
- .map(function (wd) {
147
- return "".concat(imageLoader.transformUrl({
148
- src: src,
149
- quality: quality,
150
- width: wd.width,
151
- format: "webp"
152
- }), " ").concat(wd.desc);
153
- })
154
- .join(", ") })),
155
- React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
156
- ? imageLoader.transformUrl({
157
- src: src,
158
- quality: quality,
159
- width: widthDescs[widthDescs.length - 1].width
160
- })
161
- : src, srcSet: imageLoader && imageLoader.supportsUrl(src)
162
- ? widthDescs
163
- .map(function (wd) {
164
- return "".concat(imageLoader.transformUrl({
165
- src: src,
166
- quality: quality,
167
- width: wd.width
168
- }), " ").concat(wd.desc);
169
- })
170
- .join(", ")
171
- : undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
172
- }
173
- var DEFAULT_SVG_WIDTH = 10000;
174
- function isSvg(src) {
175
- return src.endsWith(".svg") || src.startsWith("data:image/svg");
176
- }
177
- function getClosestPresetSize(width, fullWidth) {
178
- var _a;
179
- var nextBiggerIndex = (_a = ALL_SIZES.findIndex(function (w) { return w >= width; })) !== null && _a !== void 0 ? _a : ALL_SIZES.length - 1;
180
- var nextBigger = ALL_SIZES[nextBiggerIndex];
181
- if (nextBigger >= fullWidth) {
182
- // If the requested width is larger than the fullWidth,
183
- // we just use the original width instead. It's impossible
184
- // to make an image bigger than fullWidth!
185
- return undefined;
186
- }
187
- else if (nextBiggerIndex + 1 < ALL_SIZES.length &&
188
- fullWidth <= ALL_SIZES[nextBiggerIndex + 1]) {
189
- // If the fullWidth is just between nextBigger and the one after that,
190
- // then also might as well just use the original size (so, width is 30,
191
- // nextBigger is 32, then we just use the original as long as fullWidth is
192
- // less than 48)
193
- return undefined;
194
- }
195
- return nextBigger;
196
- }
197
- /**
198
- * Computes the appropriate srcSet and sizes to use
199
- */
200
- function getWidths(width, fullWidth, extra) {
201
- var minWidth = extra === null || extra === void 0 ? void 0 : extra.minWidth;
202
- var pixelWidth = getPixelLength(width);
203
- var pixelMinWidth = getPixelLength(minWidth);
204
- if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
205
- // If there's an exact width, then we just need to display it at 1x and 2x density
206
- return {
207
- widthDescs: [
208
- {
209
- width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0), fullWidth),
210
- desc: "1x"
211
- },
212
- {
213
- width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0) * 2, fullWidth),
214
- desc: "2x"
215
- },
216
- ],
217
- sizes: undefined
218
- };
219
- }
220
- // Otherwise we don't know what sizes we'll end up, so we just cap it at
221
- // device width. TODO: do better!
222
- var usefulSizes = DEVICE_SIZES.filter(function (size) { return !fullWidth || size < fullWidth; });
223
- if (!!fullWidth && usefulSizes.length === 0) {
224
- // image fullWidth is smaller than all device sizes. So all we can do
225
- // is offer 1x
226
- return {
227
- widthDescs: [
228
- {
229
- width: getClosestPresetSize(fullWidth, fullWidth),
230
- desc: "1x"
231
- },
232
- ],
233
- sizes: undefined
234
- };
235
- }
236
- return {
237
- widthDescs: usefulSizes.map(function (size) { return ({
238
- width: getClosestPresetSize(size, fullWidth),
239
- // If this is the last (buggest) useful width, but it is
240
- // still within the bounds set by DEVICE_SIZES, then just
241
- // use the original, unresized image. This means if we match
242
- // the largest size, we use unresized and best quality image.
243
- // We only do this, though, if fullWidth is "reasonable" --
244
- // smaller than the largest size we would consider.
245
- // i === usefulSizes.length - 1 &&
246
- // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
247
- // ? undefined
248
- // : size,
249
- desc: "".concat(size, "w")
250
- }); }),
251
- sizes: "100vw"
252
- };
253
- }
254
- function getPixelLength(length) {
255
- if (length == null || length == "") {
256
- return undefined;
257
- }
258
- if (typeof length === "number") {
259
- return length;
260
- }
261
- var parsed = parseNumeric(length);
262
- if (parsed && (!parsed.units || parsed.units === "px")) {
263
- return parsed.num;
264
- }
265
- return undefined;
266
- }
267
- function parseNumeric(val) {
268
- // Parse strings like "30", "30px", "30%", "30px /* blah blah */"
269
- var res = val.match(/^\s*(-?(?:\d+\.\d*|\d*\.\d+|\d+))\s*([a-z]*|%)\s*(?:\/\*.*)?$/i);
270
- if (res == null) {
271
- return undefined;
272
- }
273
- var num = res[1];
274
- var units = res[2];
275
- return { num: +num, units: units };
276
- }
277
- function getImageLoader(loader) {
278
- if (loader == null) {
279
- return undefined;
280
- }
281
- else if (loader === "plasmic") {
282
- return PLASMIC_IMAGE_LOADER;
283
- }
284
- else {
285
- return loader;
286
- }
287
- }
288
- var PLASMIC_IMAGE_LOADER = {
289
- supportsUrl: function (src) {
290
- return src.startsWith("https://img.plasmic.app") && !isSvg(src);
291
- },
292
- transformUrl: function (opts) {
293
- var _a;
294
- var params = [
295
- opts.width ? "w=".concat(opts.width) : undefined,
296
- "q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
297
- opts.format ? "f=".concat(opts.format) : undefined,
298
- ].filter(function (x) { return !!x; });
299
- return "".concat(opts.src, "?").concat(params.join("&"));
300
- }
6
+ /**
7
+ * Responsive `<img/>` replacement, based on `next/image`
8
+ */
9
+ // Default image sizes to snap to
10
+ // TODO: make this configurable?
11
+ var IMG_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
12
+ var DEVICE_SIZES = [640, 750, 828, 1080, 1200, 1920, 2048, 3840];
13
+ var ALL_SIZES = __spreadArray(__spreadArray([], __read(IMG_SIZES), false), __read(DEVICE_SIZES), false);
14
+ var PlasmicImg = React__default.forwardRef(function PlasmicImg(props, outerRef) {
15
+ 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, loader = props.loader, imgRef = props.imgRef, style = props.style, loading = props.loading, rest = __rest(props, ["src", "className", "displayWidth", "displayHeight", "displayMinWidth", "displayMinHeight", "displayMaxWidth", "displayMaxHeight", "quality", "loader", "imgRef", "style", "loading"]);
16
+ var imgProps = Object.assign({}, rest, {
17
+ // Default loading to "lazy" if not specified (which is different from the
18
+ // html img, which defaults to eager!)
19
+ loading: loading !== null && loading !== void 0 ? loading : "lazy",
20
+ });
21
+ var _a = typeof src === "string" || !src
22
+ ? { fullWidth: undefined, fullHeight: undefined, aspectRatio: undefined }
23
+ : src, fullWidth = _a.fullWidth, fullHeight = _a.fullHeight, aspectRatio = _a.aspectRatio;
24
+ var srcStr = src
25
+ ? typeof src === "string"
26
+ ? src
27
+ : typeof src.src === "string"
28
+ ? src.src
29
+ : src.src.src
30
+ : "";
31
+ // Assume external image if either dimension is null and use usual <img>
32
+ if (fullHeight == null || fullWidth == null) {
33
+ return (React__default.createElement("img", __assign({ src: srcStr, className: className, style: style }, imgProps, { loading: loading, ref: mergeRefs(imgRef, outerRef) })));
34
+ }
35
+ if (isSvg(srcStr) &&
36
+ (displayHeight == null || displayHeight === "auto") &&
37
+ (displayWidth == null || displayWidth === "auto")) {
38
+ displayWidth = "100%";
39
+ }
40
+ var computedDisplayWidth = displayWidth;
41
+ if (fullWidth &&
42
+ fullHeight &&
43
+ (!displayWidth || displayWidth === "auto") &&
44
+ !!getPixelLength(displayHeight)) {
45
+ // If there's a pixel length specified for displayHeight but not displayWidth,
46
+ // then we can derive the pixel length for displayWidth. Having an explicit
47
+ // displayWidth makes this a fixed-size image, which makes it possible for us to
48
+ // generate better markup!
49
+ if (!isSvg(srcStr)) {
50
+ // We shouldn't do it for SVGs though, because `fullWidth` and
51
+ // `fullHeight` might have rounded values so the final
52
+ // `displayWidth` could differ by 1px or so.
53
+ computedDisplayWidth =
54
+ (getPixelLength(displayHeight) * fullWidth) / fullHeight;
55
+ }
56
+ }
57
+ var spacerWidth = fullWidth;
58
+ var spacerHeight = fullHeight;
59
+ if (aspectRatio && isFinite(aspectRatio) && isSvg(srcStr)) {
60
+ // For SVGs, fullWidth and fullHeight can be rounded values, which would
61
+ // cause some discrepancy between the actual aspect ratio and the aspect
62
+ // ratio from those values. So, for those cases, we set large width / height
63
+ // values to get a more precise ratio from the spacer.
64
+ spacerWidth = DEFAULT_SVG_WIDTH;
65
+ spacerHeight = Math.round(spacerWidth / aspectRatio);
66
+ }
67
+ var _b = getWidths(computedDisplayWidth, fullWidth, {
68
+ minWidth: displayMinWidth,
69
+ }), sizes = _b.sizes, widthDescs = _b.widthDescs;
70
+ var imageLoader = getImageLoader(loader);
71
+ var spacerSvg = "<svg width=\"".concat(spacerWidth, "\" height=\"").concat(spacerHeight, "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>");
72
+ var spacerSvgBase64 = typeof window === "undefined"
73
+ ? Buffer.from(spacerSvg).toString("base64")
74
+ : window.btoa(spacerSvg);
75
+ var wrapperStyle = __assign({}, (style || {}));
76
+ var spacerStyle = __assign({}, pick(style || {}, "objectFit", "objectPosition"));
77
+ if (displayWidth != null && displayWidth !== "auto") {
78
+ // If width is set, set it on the wrapper along with min/max width
79
+ // and just use `width: 100%` on the spacer
80
+ spacerStyle.width = "100%";
81
+ // Rely on the styles set by `classname` on the wrapper:
82
+ // wrapperStyle.width = displayWidth;
83
+ // wrapperStyle.minWidth = displayMinWidth;
84
+ // wrapperStyle.maxWidth = displayMaxWidth;
85
+ }
86
+ else {
87
+ // Otherwise, we want auto sizing from the spacer, so set width there.
88
+ //
89
+ // But if we have min/max width, it should be set in the wrapper and it
90
+ // can be percentage values (and we add corresponding min/max width to
91
+ // 100% in the spacer). In general it ends up with the correct effect,
92
+ // but some edge cases might make `min-width: 100%` shrink the image more
93
+ // than it should.
94
+ spacerStyle.width = displayWidth;
95
+ wrapperStyle.width = "auto";
96
+ if (displayMinWidth) {
97
+ spacerStyle.minWidth = "100%";
98
+ // Rely on min-width set by `classname` on the wrapper:
99
+ // wrapperStyle.minWidth = displayMinWidth;
100
+ }
101
+ if (displayMaxWidth != null && displayMaxWidth !== "none") {
102
+ spacerStyle.maxWidth = "100%";
103
+ // Rely on max-width set by `classname` on the wrapper:
104
+ // wrapperStyle.maxWidth = displayMaxWidth;
105
+ }
106
+ }
107
+ if (displayHeight != null && displayHeight !== "auto") {
108
+ spacerStyle.height = "100%";
109
+ // wrapperStyle.height = displayHeight;
110
+ // wrapperStyle.minHeight = displayMinHeight;
111
+ // wrapperStyle.maxHeight = displayMaxHeight;
112
+ }
113
+ else {
114
+ spacerStyle.height = displayHeight;
115
+ wrapperStyle.height = "auto";
116
+ if (displayMinHeight) {
117
+ spacerStyle.minHeight = "100%";
118
+ // wrapperStyle.minHeight = displayMinHeight;
119
+ }
120
+ if (displayMaxHeight != null && displayMaxHeight !== "none") {
121
+ spacerStyle.maxHeight = "100%";
122
+ // wrapperStyle.maxHeight = displayMaxHeight;
123
+ }
124
+ }
125
+ return (React__default.createElement("div", { className: classNames(className, "__wab_img-wrapper"), ref: outerRef, style: wrapperStyle },
126
+ React__default.createElement("img", { alt: "", "aria-hidden": true, className: "__wab_img-spacer-svg", src: "data:image/svg+xml;base64,".concat(spacerSvgBase64), style: spacerStyle }),
127
+ makePicture({
128
+ imageLoader: imageLoader,
129
+ widthDescs: widthDescs,
130
+ sizes: sizes,
131
+ src: srcStr,
132
+ quality: quality,
133
+ ref: imgRef,
134
+ style: style ? pick(style, "objectFit", "objectPosition") : undefined,
135
+ imgProps: imgProps,
136
+ className: "__wab_img",
137
+ })));
138
+ });
139
+ function makePicture(opts) {
140
+ // If imageLoader is undefined, then this renders to just a normal
141
+ // <img />. Else it will render to a <picture> with a <source> for
142
+ // webp, and srcSet/sizes set according to width requirements.
143
+ var imageLoader = opts.imageLoader, widthDescs = opts.widthDescs, src = opts.src, quality = opts.quality, style = opts.style, className = opts.className, sizes = opts.sizes, imgProps = opts.imgProps, ref = opts.ref;
144
+ return (React__default.createElement("picture", { className: "__wab_picture" },
145
+ imageLoader && imageLoader.supportsUrl(src) && (React__default.createElement("source", { type: "image/webp", srcSet: widthDescs
146
+ .map(function (wd) {
147
+ return "".concat(imageLoader.transformUrl({
148
+ src: src,
149
+ quality: quality,
150
+ width: wd.width,
151
+ format: "webp",
152
+ }), " ").concat(wd.desc);
153
+ })
154
+ .join(", ") })),
155
+ React__default.createElement("img", __assign({}, imgProps, { ref: ref, className: className, decoding: "async", src: imageLoader && imageLoader.supportsUrl(src)
156
+ ? imageLoader.transformUrl({
157
+ src: src,
158
+ quality: quality,
159
+ width: widthDescs[widthDescs.length - 1].width,
160
+ })
161
+ : src, srcSet: imageLoader && imageLoader.supportsUrl(src)
162
+ ? widthDescs
163
+ .map(function (wd) {
164
+ return "".concat(imageLoader.transformUrl({
165
+ src: src,
166
+ quality: quality,
167
+ width: wd.width,
168
+ }), " ").concat(wd.desc);
169
+ })
170
+ .join(", ")
171
+ : undefined, sizes: imageLoader && imageLoader.supportsUrl(src) ? sizes : undefined, style: __assign(__assign({}, (style ? pick(style, "objectFit", "objectPosition") : {})), { width: 0, height: 0 }) }))));
172
+ }
173
+ var DEFAULT_SVG_WIDTH = 10000;
174
+ function isSvg(src) {
175
+ return src.endsWith(".svg") || src.startsWith("data:image/svg");
176
+ }
177
+ function getClosestPresetSize(width, fullWidth) {
178
+ var _a;
179
+ var nextBiggerIndex = (_a = ALL_SIZES.findIndex(function (w) { return w >= width; })) !== null && _a !== void 0 ? _a : ALL_SIZES.length - 1;
180
+ var nextBigger = ALL_SIZES[nextBiggerIndex];
181
+ if (nextBigger >= fullWidth) {
182
+ // If the requested width is larger than the fullWidth,
183
+ // we just use the original width instead. It's impossible
184
+ // to make an image bigger than fullWidth!
185
+ return undefined;
186
+ }
187
+ else if (nextBiggerIndex + 1 < ALL_SIZES.length &&
188
+ fullWidth <= ALL_SIZES[nextBiggerIndex + 1]) {
189
+ // If the fullWidth is just between nextBigger and the one after that,
190
+ // then also might as well just use the original size (so, width is 30,
191
+ // nextBigger is 32, then we just use the original as long as fullWidth is
192
+ // less than 48)
193
+ return undefined;
194
+ }
195
+ return nextBigger;
196
+ }
197
+ /**
198
+ * Computes the appropriate srcSet and sizes to use
199
+ */
200
+ function getWidths(width, fullWidth, extra) {
201
+ var minWidth = extra === null || extra === void 0 ? void 0 : extra.minWidth;
202
+ var pixelWidth = getPixelLength(width);
203
+ var pixelMinWidth = getPixelLength(minWidth);
204
+ if (pixelWidth != null && (!minWidth || pixelMinWidth != null)) {
205
+ // If there's an exact width, then we just need to display it at 1x and 2x density
206
+ return {
207
+ widthDescs: [
208
+ {
209
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0), fullWidth),
210
+ desc: "1x",
211
+ },
212
+ {
213
+ width: getClosestPresetSize(Math.max(pixelWidth, pixelMinWidth !== null && pixelMinWidth !== void 0 ? pixelMinWidth : 0) * 2, fullWidth),
214
+ desc: "2x",
215
+ },
216
+ ],
217
+ sizes: undefined,
218
+ };
219
+ }
220
+ // Otherwise we don't know what sizes we'll end up, so we just cap it at
221
+ // device width. TODO: do better!
222
+ var usefulSizes = DEVICE_SIZES.filter(function (size) { return !fullWidth || size < fullWidth; });
223
+ if (!!fullWidth && usefulSizes.length === 0) {
224
+ // image fullWidth is smaller than all device sizes. So all we can do
225
+ // is offer 1x
226
+ return {
227
+ widthDescs: [
228
+ {
229
+ width: getClosestPresetSize(fullWidth, fullWidth),
230
+ desc: "1x",
231
+ },
232
+ ],
233
+ sizes: undefined,
234
+ };
235
+ }
236
+ return {
237
+ widthDescs: usefulSizes.map(function (size) { return ({
238
+ width: getClosestPresetSize(size, fullWidth),
239
+ // If this is the last (buggest) useful width, but it is
240
+ // still within the bounds set by DEVICE_SIZES, then just
241
+ // use the original, unresized image. This means if we match
242
+ // the largest size, we use unresized and best quality image.
243
+ // We only do this, though, if fullWidth is "reasonable" --
244
+ // smaller than the largest size we would consider.
245
+ // i === usefulSizes.length - 1 &&
246
+ // fullWidth < DEVICE_SIZES[DEVICE_SIZES.length - 1]
247
+ // ? undefined
248
+ // : size,
249
+ desc: "".concat(size, "w"),
250
+ }); }),
251
+ sizes: "100vw",
252
+ };
253
+ }
254
+ function getPixelLength(length) {
255
+ if (length == null || length == "") {
256
+ return undefined;
257
+ }
258
+ if (typeof length === "number") {
259
+ return length;
260
+ }
261
+ var parsed = parseNumeric(length);
262
+ if (parsed && (!parsed.units || parsed.units === "px")) {
263
+ return parsed.num;
264
+ }
265
+ return undefined;
266
+ }
267
+ function parseNumeric(val) {
268
+ // Parse strings like "30", "30px", "30%", "30px /* blah blah */"
269
+ var res = val.match(/^\s*(-?(?:\d+\.\d*|\d*\.\d+|\d+))\s*([a-z]*|%)\s*(?:\/\*.*)?$/i);
270
+ if (res == null) {
271
+ return undefined;
272
+ }
273
+ var num = res[1];
274
+ var units = res[2];
275
+ return { num: +num, units: units };
276
+ }
277
+ function getImageLoader(loader) {
278
+ if (loader == null) {
279
+ return undefined;
280
+ }
281
+ else if (loader === "plasmic") {
282
+ return PLASMIC_IMAGE_LOADER;
283
+ }
284
+ else {
285
+ return loader;
286
+ }
287
+ }
288
+ var PLASMIC_IMAGE_LOADER = {
289
+ supportsUrl: function (src) {
290
+ return src.startsWith("https://img.plasmic.app") && !isSvg(src);
291
+ },
292
+ transformUrl: function (opts) {
293
+ var _a;
294
+ var params = [
295
+ opts.width ? "w=".concat(opts.width) : undefined,
296
+ "q=".concat((_a = opts.quality) !== null && _a !== void 0 ? _a : 75),
297
+ opts.format ? "f=".concat(opts.format) : undefined,
298
+ ].filter(function (x) { return !!x; });
299
+ return "".concat(opts.src, "?").concat(params.join("&"));
300
+ },
301
301
  };
302
302
 
303
303
  export { PlasmicImg };
@@ -1,2 +1,2 @@
1
- import React from "react";
2
- export declare const PlasmicLink: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<any>>;
1
+ import React from "react";
2
+ export declare const PlasmicLink: React.ForwardRefExoticComponent<Pick<any, string | number | symbol> & React.RefAttributes<any>>;
@@ -1,11 +1,11 @@
1
- import * as React from "react";
2
- export declare function PlasmicSlot<T extends keyof JSX.IntrinsicElements = "div">(props: React.ComponentProps<T> & {
3
- as?: T;
4
- defaultContents?: React.ReactNode;
5
- value?: React.ReactNode;
6
- }): JSX.Element | null;
7
- export declare function renderPlasmicSlot<T extends keyof JSX.IntrinsicElements = "div">(opts: {
8
- as?: T;
9
- defaultContents?: React.ReactNode;
10
- value?: React.ReactNode;
11
- }): JSX.Element | null;
1
+ import * as React from "react";
2
+ export declare function PlasmicSlot<T extends keyof JSX.IntrinsicElements = "div">(props: React.ComponentProps<T> & {
3
+ as?: T;
4
+ defaultContents?: React.ReactNode;
5
+ value?: React.ReactNode;
6
+ }): JSX.Element | null;
7
+ export declare function renderPlasmicSlot<T extends keyof JSX.IntrinsicElements = "div">(opts: {
8
+ as?: T;
9
+ defaultContents?: React.ReactNode;
10
+ value?: React.ReactNode;
11
+ }): JSX.Element | null;