@makeswift/runtime 0.4.2 → 0.5.1

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 (121) hide show
  1. package/dist/Box.cjs.js +35 -273
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +34 -272
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +4 -4
  6. package/dist/Button.es.js +5 -5
  7. package/dist/Carousel.cjs.js +8 -7
  8. package/dist/Carousel.cjs.js.map +1 -1
  9. package/dist/Carousel.es.js +7 -6
  10. package/dist/Carousel.es.js.map +1 -1
  11. package/dist/Countdown.cjs.js +3 -3
  12. package/dist/Countdown.es.js +4 -4
  13. package/dist/Divider.cjs.js +3 -3
  14. package/dist/Divider.es.js +4 -4
  15. package/dist/Embed.cjs.js +5 -4
  16. package/dist/Embed.cjs.js.map +1 -1
  17. package/dist/Embed.es.js +5 -4
  18. package/dist/Embed.es.js.map +1 -1
  19. package/dist/Form.cjs.js +4 -4
  20. package/dist/Form.es.js +5 -5
  21. package/dist/Image.cjs.js +21 -13
  22. package/dist/Image.cjs.js.map +1 -1
  23. package/dist/Image.es.js +22 -14
  24. package/dist/Image.es.js.map +1 -1
  25. package/dist/LiveProvider.cjs.js +62 -0
  26. package/dist/LiveProvider.cjs.js.map +1 -0
  27. package/dist/LiveProvider.es.js +60 -0
  28. package/dist/LiveProvider.es.js.map +1 -0
  29. package/dist/Navigation.cjs.js +9 -6
  30. package/dist/Navigation.cjs.js.map +1 -1
  31. package/dist/Navigation.es.js +9 -6
  32. package/dist/Navigation.es.js.map +1 -1
  33. package/dist/{react-builder-preview.cjs.js → PreviewProvider.cjs.js} +43 -16
  34. package/dist/PreviewProvider.cjs.js.map +1 -0
  35. package/dist/{react-builder-preview.es.js → PreviewProvider.es.js} +47 -15
  36. package/dist/PreviewProvider.es.js.map +1 -0
  37. package/dist/Root.cjs.js +10 -8
  38. package/dist/Root.cjs.js.map +1 -1
  39. package/dist/Root.es.js +8 -6
  40. package/dist/Root.es.js.map +1 -1
  41. package/dist/SocialLinks.cjs.js +5 -5
  42. package/dist/SocialLinks.es.js +6 -6
  43. package/dist/Text.cjs.js +4 -4
  44. package/dist/Text.cjs.js.map +1 -1
  45. package/dist/Text.es.js +5 -5
  46. package/dist/Text.es.js.map +1 -1
  47. package/dist/Video.cjs.js +3 -3
  48. package/dist/Video.es.js +4 -4
  49. package/dist/actions.es.js +1 -1
  50. package/dist/components.cjs.js +15 -12
  51. package/dist/components.cjs.js.map +1 -1
  52. package/dist/components.es.js +14 -11
  53. package/dist/components.es.js.map +1 -1
  54. package/dist/index.cjs.js +70 -69
  55. package/dist/index.cjs.js.map +1 -1
  56. package/dist/index.cjs2.js +710 -92
  57. package/dist/index.cjs2.js.map +1 -1
  58. package/dist/index.cjs3.js +107 -20
  59. package/dist/index.cjs3.js.map +1 -1
  60. package/dist/index.cjs4.js +59 -0
  61. package/dist/index.cjs4.js.map +1 -0
  62. package/dist/index.es.js +65 -68
  63. package/dist/index.es.js.map +1 -1
  64. package/dist/index.es2.js +707 -93
  65. package/dist/index.es2.js.map +1 -1
  66. package/dist/index.es3.js +103 -21
  67. package/dist/index.es3.js.map +1 -1
  68. package/dist/index.es4.js +58 -0
  69. package/dist/index.es4.js.map +1 -0
  70. package/dist/next-version.cjs.js +10 -0
  71. package/dist/next-version.cjs.js.map +1 -0
  72. package/dist/next-version.es.js +5 -0
  73. package/dist/next-version.es.js.map +1 -0
  74. package/dist/next.cjs.js +3 -3
  75. package/dist/next.es.js +4 -4
  76. package/dist/react-page.es.js +1 -1
  77. package/dist/react.cjs.js +4 -4
  78. package/dist/react.es.js +4 -4
  79. package/dist/types/src/components/builtin/Box/Box.d.ts +18 -26
  80. package/dist/types/src/components/builtin/Box/Box.d.ts.map +1 -1
  81. package/dist/types/src/components/builtin/Box/animations.d.ts +13 -60
  82. package/dist/types/src/components/builtin/Box/animations.d.ts.map +1 -1
  83. package/dist/types/src/components/builtin/Button/Button.d.ts +1 -1
  84. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  85. package/dist/types/src/components/builtin/Image/Image.d.ts.map +1 -1
  86. package/dist/types/src/components/hooks/useMediaQuery.d.ts +1 -1
  87. package/dist/types/src/components/hooks/useMediaQuery.d.ts.map +1 -1
  88. package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts.map +1 -1
  89. package/dist/types/src/components/shared/BackgroundsContainer/index.d.ts +1 -254
  90. package/dist/types/src/components/shared/BackgroundsContainer/index.d.ts.map +1 -1
  91. package/dist/types/src/components/shared/Link/index.d.ts.map +1 -1
  92. package/dist/types/src/components/shared/grid-item.d.ts +9 -6
  93. package/dist/types/src/components/shared/grid-item.d.ts.map +1 -1
  94. package/dist/types/src/next/client.d.ts +1 -0
  95. package/dist/types/src/next/client.d.ts.map +1 -1
  96. package/dist/types/src/next/index.d.ts.map +1 -1
  97. package/dist/types/src/next/next-version.d.ts +3 -0
  98. package/dist/types/src/next/next-version.d.ts.map +1 -0
  99. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts +11 -0
  100. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -0
  101. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts +11 -0
  102. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts.map +1 -0
  103. package/dist/types/src/runtimes/react/index.d.ts +3 -1
  104. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  105. package/dist/types/src/state/react-builder-preview.d.ts +3 -1
  106. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  107. package/dist/useIsomorphicLayoutEffect.cjs.js +6 -0
  108. package/dist/useIsomorphicLayoutEffect.cjs.js.map +1 -0
  109. package/dist/useIsomorphicLayoutEffect.es.js +5 -0
  110. package/dist/useIsomorphicLayoutEffect.es.js.map +1 -0
  111. package/package.json +4 -4
  112. package/dist/grid-item.cjs.js +0 -592
  113. package/dist/grid-item.cjs.js.map +0 -1
  114. package/dist/grid-item.es.js +0 -584
  115. package/dist/grid-item.es.js.map +0 -1
  116. package/dist/react-builder-preview.cjs.js.map +0 -1
  117. package/dist/react-builder-preview.es.js.map +0 -1
  118. package/dist/useMediaQuery.cjs.js +0 -26
  119. package/dist/useMediaQuery.cjs.js.map +0 -1
  120. package/dist/useMediaQuery.es.js +0 -25
  121. package/dist/useMediaQuery.es.js.map +0 -1
@@ -31,117 +31,735 @@ var __objRest = (source, exclude) => {
31
31
  return target;
32
32
  };
33
33
  var React = require("react");
34
- var scrollIntoView = require("scroll-into-view-if-needed");
35
- var NextLink = require("next/link");
36
34
  var next = require("./index.cjs.js");
35
+ require("use-sync-external-store/shim");
36
+ require("./slot.cjs.js");
37
+ var css = require("@emotion/css");
37
38
  var jsxRuntime = require("react/jsx-runtime");
39
+ var reactPage = require("./react-page.cjs.js");
40
+ var NextImage = require("next/image");
41
+ var useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect.cjs.js");
42
+ var ReactPlayer = require("react-player");
43
+ var nextVersion = require("./next-version.cjs.js");
38
44
  function _interopDefaultLegacy(e) {
39
45
  return e && typeof e === "object" && "default" in e ? e : { "default": e };
40
46
  }
41
- var scrollIntoView__default = /* @__PURE__ */ _interopDefaultLegacy(scrollIntoView);
42
- var NextLink__default = /* @__PURE__ */ _interopDefaultLegacy(NextLink);
43
- const Link = React.forwardRef(function Link2(_a, ref) {
47
+ var NextImage__default = /* @__PURE__ */ _interopDefaultLegacy(NextImage);
48
+ var ReactPlayer__default = /* @__PURE__ */ _interopDefaultLegacy(ReactPlayer);
49
+ function useBackgrounds(value) {
50
+ const fileIds = reactPage.getBackgroundsFileIds(value);
51
+ const files = next.useFiles(fileIds);
52
+ const swatchIds = reactPage.getBackgroundsSwatchIds(value);
53
+ const swatches = next.useSwatches(swatchIds);
54
+ return React.useMemo(() => {
55
+ if (value == null)
56
+ return null;
57
+ return value.map((_a) => {
58
+ var _b = _a, { value: backgrounds } = _b, restOfValue = __objRest(_b, ["value"]);
59
+ return __spreadProps(__spreadValues({}, restOfValue), {
60
+ value: backgrounds.map((bg) => {
61
+ if (bg.type === "image" && bg.payload != null && bg.payload.imageId != null) {
62
+ const _a2 = bg.payload, { imageId } = _a2, restOfPayload = __objRest(_a2, ["imageId"]);
63
+ const file = files.find((f) => f && f.id === imageId);
64
+ return file && {
65
+ id: bg.id,
66
+ type: "image",
67
+ payload: __spreadProps(__spreadValues({}, restOfPayload), {
68
+ publicUrl: file.publicUrl,
69
+ dimensions: file.dimensions
70
+ })
71
+ };
72
+ }
73
+ if (bg.type === "color" && bg.payload != null) {
74
+ const { swatchId, alpha } = bg.payload;
75
+ const swatch = swatches.filter(reactPage.isNonNullable).find((s) => s && s.id === swatchId);
76
+ return { id: bg.id, type: "color", payload: { swatch, alpha } };
77
+ }
78
+ if (bg.type === "gradient" && bg.payload != null && bg.payload.stops.length > 0) {
79
+ return {
80
+ id: bg.id,
81
+ type: "gradient",
82
+ payload: {
83
+ angle: bg.payload.angle,
84
+ isRadial: bg.payload.isRadial,
85
+ stops: bg.payload.stops.map((_b2) => {
86
+ var _c = _b2, { color } = _c, restOfStop = __objRest(_c, ["color"]);
87
+ return __spreadProps(__spreadValues({}, restOfStop), {
88
+ color: color && {
89
+ swatch: swatches.filter(reactPage.isNonNullable).find((s) => s && s.id === color.swatchId),
90
+ alpha: color.alpha
91
+ }
92
+ });
93
+ })
94
+ }
95
+ };
96
+ }
97
+ if (bg.type === "video" && bg.payload != null) {
98
+ const _d = bg.payload, { maskColor } = _d, restOfPayload = __objRest(_d, ["maskColor"]);
99
+ const swatch = maskColor && swatches.find((s) => s && s.id === maskColor.swatchId);
100
+ return {
101
+ id: bg.id,
102
+ type: "video",
103
+ payload: __spreadProps(__spreadValues({}, restOfPayload), {
104
+ maskColor: swatch && maskColor && { swatch, alpha: maskColor.alpha }
105
+ })
106
+ };
107
+ }
108
+ return null;
109
+ }).filter(reactPage.isNonNullable)
110
+ });
111
+ });
112
+ }, [files, swatches, value]);
113
+ }
114
+ const gridItemIdentifierClassName = "grid-item";
115
+ function GridItem(_a) {
44
116
  var _b = _a, {
45
- link,
46
- onClick = () => {
47
- }
117
+ grid,
118
+ index,
119
+ columnGap,
120
+ rowGap,
121
+ className,
122
+ itemAnimateDuration,
123
+ itemAnimateDelay,
124
+ itemStaggerDuration
48
125
  } = _b, restOfProps = __objRest(_b, [
49
- "link",
50
- "onClick"
126
+ "grid",
127
+ "index",
128
+ "columnGap",
129
+ "rowGap",
130
+ "className",
131
+ "itemAnimateDuration",
132
+ "itemAnimateDelay",
133
+ "itemStaggerDuration"
51
134
  ]);
52
- var _a2;
53
- const pageId = link && link.type === "OPEN_PAGE" ? link.payload.pageId : null;
54
- const page = next.usePagePathnameSlice(pageId != null ? pageId : null);
55
- const elementKey = (link == null ? void 0 : link.type) === "SCROLL_TO_ELEMENT" ? (_a2 = link.payload.elementIdConfig) == null ? void 0 : _a2.elementKey : null;
56
- const elementId = next.useElementId(elementKey);
57
- let useNextLink;
58
- let href;
59
- let target;
60
- let block;
61
- if (link) {
62
- switch (link.type) {
63
- case "OPEN_PAGE": {
64
- if (page) {
65
- useNextLink = true;
66
- href = `/${page.pathname}`;
67
- }
68
- target = link.payload.openInNewTab ? "_blank" : "_self";
69
- break;
135
+ const gridItemClassName = next.useStyle(next.responsiveGridItem({
136
+ grid,
137
+ index,
138
+ columnGap,
139
+ rowGap
140
+ }));
141
+ const animationClassName = useItemAnimation(itemAnimateDuration, itemAnimateDelay, itemStaggerDuration, index);
142
+ return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, restOfProps), {
143
+ className: css.cx(gridItemClassName, className, animationClassName, gridItemIdentifierClassName)
144
+ }));
145
+ }
146
+ const useElementOnScreen = (element, options) => {
147
+ const [isVisible, setIsVisible] = React.useState(false);
148
+ React.useEffect(() => {
149
+ const observer = new IntersectionObserver(intersectionCallback, options);
150
+ if (element)
151
+ observer.observe(element);
152
+ return () => {
153
+ if (element)
154
+ observer.unobserve(element);
155
+ };
156
+ function intersectionCallback([entry]) {
157
+ if (entry == null ? void 0 : entry.isIntersecting) {
158
+ setIsVisible(true);
70
159
  }
71
- case "OPEN_URL": {
72
- useNextLink = true;
73
- href = link.payload.url;
74
- target = link.payload.openInNewTab ? "_blank" : "_self";
75
- break;
160
+ }
161
+ }, [element, options]);
162
+ return isVisible;
163
+ };
164
+ function compareResponsiveValues(a, b) {
165
+ if (a == null && b == null) {
166
+ return true;
167
+ }
168
+ if (a != null && b != null) {
169
+ let isEqual = true;
170
+ a.forEach((currentA, index) => {
171
+ const currentB = b.at(index);
172
+ if (currentB == null) {
173
+ isEqual = false;
174
+ return;
175
+ }
176
+ if (currentA.deviceId != (currentB == null ? void 0 : currentB.deviceId) || currentA.value != currentB.value) {
177
+ isEqual = false;
76
178
  }
77
- case "SEND_EMAIL": {
78
- useNextLink = false;
179
+ });
180
+ return isEqual;
181
+ }
182
+ return false;
183
+ }
184
+ function areBoxAnimationPropsEqual(prevProps, props) {
185
+ return compareResponsiveValues(prevProps.boxAnimateType, props.boxAnimateType) && compareResponsiveValues(prevProps.boxAnimateDuration, props.boxAnimateDuration) && compareResponsiveValues(prevProps.boxAnimateDelay, props.boxAnimateDelay) && compareResponsiveValues(prevProps.itemAnimateType, props.itemAnimateType) && compareResponsiveValues(prevProps.itemAnimateDuration, props.itemAnimateDuration) && compareResponsiveValues(prevProps.itemAnimateDelay, props.itemAnimateDelay) && compareResponsiveValues(prevProps.itemStaggerDuration, props.itemStaggerDuration);
186
+ }
187
+ const exitedBoxAnimationProperties = {
188
+ none: {
189
+ opacity: 1
190
+ },
191
+ fadeIn: {
192
+ opacity: 0
193
+ },
194
+ fadeLeft: {
195
+ transform: "translate3d(60px,0,0)",
196
+ opacity: 0
197
+ },
198
+ fadeRight: {
199
+ transform: "translate3d(-60px,0,0)",
200
+ opacity: 0
201
+ },
202
+ fadeDown: {
203
+ transform: "translate3d(0,-80px,0)",
204
+ opacity: 0
205
+ },
206
+ fadeUp: {
207
+ transform: "translate3d(0,80px,0)",
208
+ opacity: 0
209
+ },
210
+ blurIn: {
211
+ filter: "blur(20px)",
212
+ opacity: 0
213
+ },
214
+ scaleDown: {
215
+ transform: "scale(1.2)",
216
+ opacity: 0
217
+ },
218
+ scaleUp: {
219
+ transform: "scale(.75)",
220
+ opacity: 0
221
+ }
222
+ };
223
+ const enteredBoxAnimationProperties = {
224
+ none: {
225
+ opacity: 1
226
+ },
227
+ fadeIn: {
228
+ opacity: 1
229
+ },
230
+ fadeLeft: {
231
+ transform: "translate3d(0px,0,0)",
232
+ opacity: 1
233
+ },
234
+ fadeRight: {
235
+ transform: "translate3d(0px,0,0)",
236
+ opacity: 1
237
+ },
238
+ fadeDown: {
239
+ transform: "translate3d(0,0px,0)",
240
+ opacity: 1
241
+ },
242
+ fadeUp: {
243
+ transform: "translate3d(0,0px,0)",
244
+ opacity: 1
245
+ },
246
+ blurIn: {
247
+ filter: "blur(0px)",
248
+ opacity: 1
249
+ },
250
+ scaleDown: {
251
+ transform: "scale(1)",
252
+ opacity: 1
253
+ },
254
+ scaleUp: {
255
+ transform: "scale(1)",
256
+ opacity: 1
257
+ }
258
+ };
259
+ function useBoxAnimation(boxElement, responsiveAnimationType, responsiveDuration, responisveDelay, itemResponsiveAnimationType) {
260
+ const isVisible = useElementOnScreen(boxElement, {
261
+ root: null,
262
+ rootMargin: `0px 0px -10% 0px`,
263
+ threshold: 0.2
264
+ });
265
+ const animationType = next.useMediaQuery(responsiveAnimationType) || next.DEFAULT_BOX_ANIMATE_TYPE;
266
+ const itemAnimationType = next.useMediaQuery(itemResponsiveAnimationType) || next.DEFAULT_ITEM_ANIMATE_TYPE;
267
+ const duration = next.useMediaQuery(responsiveDuration) || next.DEFAULT_BOX_ANIMATE_DURATION;
268
+ const delay = next.useMediaQuery(responisveDelay) || next.DEFAULT_BOX_ANIMATE_DELAY;
269
+ const actualDelay = delay * 1e3;
270
+ const actualDuration = duration * 1e3;
271
+ const entered = __spreadProps(__spreadValues({}, enteredBoxAnimationProperties[animationType]), {
272
+ transition: `transform ${actualDuration}ms cubic-bezier(0.16, 0.84, 0.44, 1) ${actualDelay}ms,filter ${actualDuration}ms cubic-bezier(0.16, 0.84, 0.44, 1) ${actualDelay}ms, opacity ${actualDuration}ms ease ${actualDelay}ms`,
273
+ [`& > div > .${gridItemIdentifierClassName}`]: __spreadValues({}, enteredBoxAnimationProperties[itemAnimationType])
274
+ });
275
+ const exited = __spreadProps(__spreadValues({}, exitedBoxAnimationProperties[animationType]), {
276
+ transition: `all 0ms`,
277
+ [`& > div > .${gridItemIdentifierClassName}`]: __spreadValues({}, exitedBoxAnimationProperties[itemAnimationType])
278
+ });
279
+ const [isEntered, setEntered] = React.useState(false);
280
+ React.useEffect(() => {
281
+ if (isVisible && !isEntered)
282
+ setEntered(true);
283
+ }, [isVisible, entered]);
284
+ const replayAnimation = React.useCallback(() => {
285
+ setEntered(false);
286
+ }, []);
287
+ return [next.useStyle({
288
+ "@media (prefers-reduced-motion: no-preference)": isEntered ? entered : exited
289
+ }), replayAnimation];
290
+ }
291
+ function useItemAnimation(responsiveDuration, responisveDelay, responsiveStagger, index) {
292
+ const duration = next.useMediaQuery(responsiveDuration) || next.DEFAULT_BOX_ANIMATE_DURATION;
293
+ const delay = next.useMediaQuery(responisveDelay) || next.DEFAULT_BOX_ANIMATE_DELAY;
294
+ const stagger = next.useMediaQuery(responsiveStagger) || next.DEFAULT_ITEM_STAGGER_DURATION;
295
+ const delayFromStagger = responsiveStagger == null || index == null ? 0 : stagger * index;
296
+ const actualDelay = (delay + delayFromStagger) * 1e3;
297
+ const actualDuration = duration * 1e3;
298
+ return next.useStyle({
299
+ "@media (prefers-reduced-motion: no-preference)": {
300
+ transition: `transform ${actualDuration}ms cubic-bezier(0.16, 0.84, 0.44, 1) ${actualDelay}ms,filter ${actualDuration}ms cubic-bezier(0.16, 0.84, 0.44, 1) ${actualDelay}ms, opacity ${actualDuration}ms ease ${actualDelay}ms`
301
+ }
302
+ });
303
+ }
304
+ const clamp = (min, val, max) => Math.min(Math.max(min, val), max);
305
+ function isScrollable(element) {
306
+ const {
307
+ overflow,
308
+ overflowY,
309
+ overflowX
310
+ } = element.ownerDocument.defaultView.getComputedStyle(element);
311
+ return /(auto|scroll)/.test(overflow + overflowX + overflowY);
312
+ }
313
+ function getScrollParent(element) {
314
+ const {
315
+ parentElement
316
+ } = element;
317
+ if (!element || !parentElement)
318
+ return element;
319
+ if (isScrollable(element))
320
+ return element;
321
+ return getScrollParent(parentElement);
322
+ }
323
+ function Parallax(_c) {
324
+ var _d = _c, {
325
+ strength,
326
+ children
327
+ } = _d, rest = __objRest(_d, [
328
+ "strength",
329
+ "children"
330
+ ]);
331
+ const container = React.useRef(null);
332
+ const [containerScrollTop, setContainerScrollTop] = React.useState(strength == null ? 0 : strength);
333
+ const lastScrollParentScrollTop = React.useRef(0);
334
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
335
+ if (!container.current || strength == null || strength === 0)
336
+ return void 0;
337
+ const containerDocument = container.current.ownerDocument;
338
+ const scrollParent = getScrollParent(container.current);
339
+ const eventTarget = containerDocument.documentElement === scrollParent ? containerDocument.defaultView : scrollParent;
340
+ lastScrollParentScrollTop.current = scrollParent.scrollTop;
341
+ setContainerScrollTop(strength);
342
+ function handleScroll() {
343
+ containerDocument.defaultView.requestAnimationFrame(() => {
344
+ if (!container.current)
345
+ return;
79
346
  const {
80
- to,
81
- subject = "",
82
- body = ""
83
- } = link.payload;
84
- if (to != null)
85
- href = `mailto:${to}?subject=${subject}&body=${body}`;
86
- break;
347
+ top: containerTop,
348
+ bottom: containerBottom
349
+ } = container.current.getBoundingClientRect();
350
+ const {
351
+ top: scrollParentTop,
352
+ bottom: scrollParentBottom
353
+ } = scrollParent === containerDocument.documentElement ? {
354
+ top: 0,
355
+ bottom: containerDocument.defaultView.innerHeight
356
+ } : scrollParent.getBoundingClientRect();
357
+ const {
358
+ scrollTop: scrollParentScrollTop
359
+ } = scrollParent === containerDocument.documentElement ? {
360
+ scrollTop: containerDocument.defaultView.pageYOffset
361
+ } : scrollParent;
362
+ const scrollParentHeight = scrollParentBottom - scrollParentTop;
363
+ const scrollParentScrollDelta = scrollParentScrollTop - lastScrollParentScrollTop.current;
364
+ lastScrollParentScrollTop.current = scrollParentScrollTop;
365
+ setContainerScrollTop((scrollTop) => {
366
+ const isContainerVisible = containerTop < scrollParentTop + scrollParentHeight && containerBottom > scrollParentTop;
367
+ const containerScrollRemaining = scrollParentScrollDelta > 0 ? 2 * strength - scrollTop : scrollTop;
368
+ const scrollParentScrollRemaining = scrollParentScrollDelta > 0 ? scrollParentTop + containerBottom : scrollParentHeight - containerTop;
369
+ const parallaxRatio = containerScrollRemaining / scrollParentScrollRemaining;
370
+ const containerScrollDelta = isContainerVisible ? parallaxRatio * scrollParentScrollDelta : 0;
371
+ return clamp(0, scrollTop + containerScrollDelta, strength * 2);
372
+ });
373
+ });
374
+ }
375
+ eventTarget.addEventListener("scroll", handleScroll);
376
+ return () => eventTarget.removeEventListener("scroll", handleScroll);
377
+ }, [strength]);
378
+ const getProps = React.useCallback((_a) => {
379
+ var _b = _a, {
380
+ style
381
+ } = _b, restOfChildrenProps = __objRest(_b, [
382
+ "style"
383
+ ]);
384
+ return __spreadProps(__spreadValues({}, restOfChildrenProps), {
385
+ style: __spreadValues(__spreadProps(__spreadValues({}, style), {
386
+ position: "absolute",
387
+ left: 0,
388
+ right: 0,
389
+ top: 0,
390
+ bottom: 0
391
+ }), strength == null || strength === 0 ? {} : {
392
+ top: -strength,
393
+ bottom: -strength,
394
+ transform: `translate3d(0, ${containerScrollTop - strength}px, 0)`
395
+ })
396
+ });
397
+ }, [strength, containerScrollTop]);
398
+ return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, rest), {
399
+ ref: container,
400
+ style: {
401
+ position: "absolute",
402
+ top: 0,
403
+ left: 0,
404
+ right: 0,
405
+ bottom: 0
406
+ },
407
+ children: children(getProps)
408
+ }));
409
+ }
410
+ const Container = React.forwardRef(function Container2(_e, ref) {
411
+ var _f = _e, {
412
+ className
413
+ } = _f, restOfProps = __objRest(_f, [
414
+ "className"
415
+ ]);
416
+ return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, restOfProps), {
417
+ ref,
418
+ className: css.cx(next.useStyle({
419
+ position: "absolute",
420
+ top: 0,
421
+ left: 0,
422
+ right: 0,
423
+ bottom: 0,
424
+ pointerEvents: "none",
425
+ overflow: "hidden"
426
+ }), className)
427
+ }));
428
+ });
429
+ function Mask({
430
+ backgroundColor,
431
+ visible
432
+ }) {
433
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
434
+ className: next.useStyle({
435
+ position: "absolute",
436
+ top: 0,
437
+ left: 0,
438
+ right: 0,
439
+ bottom: 0,
440
+ background: backgroundColor,
441
+ opacity: visible ? 1 : 0,
442
+ transition: "opacity 1s"
443
+ })
444
+ });
445
+ }
446
+ const getScale = (element, aspectRatio, zoom) => {
447
+ const {
448
+ offsetWidth: width,
449
+ offsetHeight: height
450
+ } = element;
451
+ const computedAspectRatio = width / height;
452
+ return Math.max(aspectRatio / computedAspectRatio, computedAspectRatio / aspectRatio) * zoom;
453
+ };
454
+ function BackgroundVideo({
455
+ url = "",
456
+ aspectRatio = 16 / 9,
457
+ zoom = 1,
458
+ maskColor,
459
+ opacity
460
+ }) {
461
+ var _a;
462
+ const [ready, setReady] = React.useState(false);
463
+ const [scale, setScale] = React.useState(1);
464
+ const container = React.useRef(null);
465
+ useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
466
+ const {
467
+ current: containerEl
468
+ } = container;
469
+ if (!containerEl)
470
+ return void 0;
471
+ const {
472
+ defaultView
473
+ } = containerEl.ownerDocument;
474
+ const handleResize = () => setScale(getScale(containerEl, aspectRatio, zoom));
475
+ handleResize();
476
+ defaultView.addEventListener("resize", handleResize);
477
+ return () => defaultView.removeEventListener("resize", handleResize);
478
+ }, [aspectRatio, zoom]);
479
+ if (!ReactPlayer__default["default"].canPlay(url))
480
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
481
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container, {
482
+ ref: container,
483
+ children: [container.current && /* @__PURE__ */ jsxRuntime.jsx(ReactPlayer__default["default"], {
484
+ url,
485
+ config: {
486
+ vimeo: {
487
+ playerOptions: {
488
+ background: true
489
+ }
490
+ },
491
+ youtube: {
492
+ playerVars: {
493
+ origin: (_a = container.current.ownerDocument.defaultView) == null ? void 0 : _a.location.origin
494
+ }
495
+ },
496
+ wistia: {
497
+ options: {
498
+ endVideoBehavior: "loop",
499
+ playbackRateControl: false,
500
+ playbar: false,
501
+ playButton: false,
502
+ volumeControl: false,
503
+ fullscreenButton: false,
504
+ muted: true
505
+ }
506
+ }
507
+ },
508
+ playing: true,
509
+ loop: true,
510
+ muted: true,
511
+ controls: false,
512
+ onReady: () => setReady(true),
513
+ style: {
514
+ transform: `scale3d(${scale}, ${scale}, 1)`,
515
+ opacity
516
+ },
517
+ width: "100%",
518
+ height: "100%"
519
+ }), /* @__PURE__ */ jsxRuntime.jsx(Mask, {
520
+ backgroundColor: maskColor,
521
+ visible: !ready
522
+ })]
523
+ });
524
+ }
525
+ const NextLegacyImage = NextImage__default["default"];
526
+ function getColor(color) {
527
+ if (color == null)
528
+ return "black";
529
+ if (color.swatch == null) {
530
+ return next.colorToString(__spreadProps(__spreadValues({}, color), {
531
+ swatch: {
532
+ hue: 0,
533
+ saturation: 0,
534
+ lightness: 0
87
535
  }
88
- case "CALL_PHONE": {
89
- useNextLink = false;
90
- href = `tel:${link.payload.phoneNumber}`;
91
- break;
536
+ }));
537
+ }
538
+ return next.colorToString(color);
539
+ }
540
+ const getStopsStyle = (stops) => stops.map(({
541
+ color,
542
+ location
543
+ }) => `${getColor(color)} ${location}%`).join(",");
544
+ const absoluteFillStyle = {
545
+ position: "absolute",
546
+ top: 0,
547
+ right: 0,
548
+ bottom: 0,
549
+ left: 0
550
+ };
551
+ const containerStyle = __spreadProps(__spreadValues({}, absoluteFillStyle), {
552
+ borderRadius: "inherit"
553
+ });
554
+ function Backgrounds({
555
+ backgrounds
556
+ }) {
557
+ if (backgrounds == null)
558
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
559
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
560
+ children: backgrounds.map(({
561
+ value,
562
+ deviceId
563
+ }) => {
564
+ const visibility = backgrounds.map((v) => ({
565
+ deviceId: v.deviceId,
566
+ value: v.deviceId === deviceId
567
+ }));
568
+ return /* @__PURE__ */ jsxRuntime.jsx(BackgroundDeviceLayer, {
569
+ layer: value,
570
+ visibility
571
+ }, deviceId);
572
+ })
573
+ });
574
+ }
575
+ function BackgroundDeviceLayer({
576
+ layer,
577
+ visibility
578
+ }) {
579
+ const visibilityStyle = next.responsiveStyle([visibility], ([v]) => ({
580
+ display: v === true ? "block" : "none"
581
+ }));
582
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
583
+ className: next.useStyle(__spreadProps(__spreadValues(__spreadValues({}, containerStyle), visibilityStyle), {
584
+ overflow: "hidden"
585
+ })),
586
+ children: [...layer].reverse().map((bg) => {
587
+ if (bg.type === "color") {
588
+ return /* @__PURE__ */ jsxRuntime.jsx(ColorBackground, {
589
+ color: getColor(bg.payload)
590
+ }, bg.id);
92
591
  }
93
- case "SCROLL_TO_ELEMENT": {
94
- useNextLink = false;
95
- href = `#${elementId != null ? elementId : ""}`;
96
- block = link.payload.block;
97
- break;
592
+ if (bg.type === "image" && bg.payload) {
593
+ return /* @__PURE__ */ React.createElement(ImageBackground, __spreadProps(__spreadValues({}, bg.payload), {
594
+ key: bg.id
595
+ }));
98
596
  }
99
- default:
100
- throw new RangeError(`Invalid link type "${link.type}."`);
101
- }
102
- }
103
- function handleClick(event) {
104
- onClick(event);
105
- if (event.defaultPrevented)
106
- return;
107
- if (event.currentTarget.isContentEditable)
108
- return event.preventDefault();
109
- if (link && link.type === "SCROLL_TO_ELEMENT") {
110
- let hash;
111
- try {
112
- if (href != null)
113
- hash = new URL(`http://www.example.com/${href}`).hash;
114
- } catch (error) {
115
- console.error(`Link received invalid href: ${href}`, error);
597
+ if (bg.type === "gradient" && bg.payload) {
598
+ return /* @__PURE__ */ React.createElement(GradientBackground, __spreadProps(__spreadValues({}, bg.payload), {
599
+ key: bg.id,
600
+ gradient: getStopsStyle(bg.payload.stops)
601
+ }));
116
602
  }
117
- if (href != null && hash != null && href === hash) {
118
- event.preventDefault();
119
- const view = event.view;
120
- scrollIntoView__default["default"](view.document.querySelector(hash), {
121
- behavior: "smooth",
122
- block
123
- });
124
- if (view.location.hash !== hash)
125
- view.history.pushState({}, "", hash);
603
+ if (bg.type === "video" && bg.payload) {
604
+ return /* @__PURE__ */ React.createElement(VideoBackground, __spreadProps(__spreadValues({}, bg.payload), {
605
+ key: bg.id,
606
+ maskColor: getColor(bg.payload.maskColor)
607
+ }));
126
608
  }
127
- }
128
- }
129
- if (useNextLink && href != null) {
130
- return /* @__PURE__ */ jsxRuntime.jsx(NextLink__default["default"], {
131
- href,
132
- children: /* @__PURE__ */ jsxRuntime.jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
133
- ref,
134
- target,
135
- onClick: handleClick
609
+ return null;
610
+ })
611
+ });
612
+ }
613
+ function ColorBackground({
614
+ color
615
+ }) {
616
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
617
+ className: next.useStyle(__spreadProps(__spreadValues({}, containerStyle), {
618
+ backgroundColor: color
619
+ }))
620
+ });
621
+ }
622
+ const ImageBackgroundRepeat = {
623
+ NoRepeat: "no-repeat",
624
+ RepeatX: "repeat-x",
625
+ RepeatY: "repeat-y",
626
+ Repeat: "repeat"
627
+ };
628
+ const ImageBackgroundSize = {
629
+ Cover: "cover",
630
+ Contain: "contain",
631
+ Auto: "auto"
632
+ };
633
+ function ImageBackground({
634
+ publicUrl,
635
+ position,
636
+ repeat = ImageBackgroundRepeat.NoRepeat,
637
+ size = ImageBackgroundSize.Cover,
638
+ opacity,
639
+ parallax
640
+ }) {
641
+ const backgroundPosition = `${position.x}% ${position.y}%`;
642
+ const containerClassName = next.useStyle(containerStyle);
643
+ if (repeat === "no-repeat" && size !== "auto" && publicUrl != null) {
644
+ return /* @__PURE__ */ jsxRuntime.jsx(Parallax, {
645
+ strength: parallax,
646
+ children: (getParallaxProps) => /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, getParallaxProps({
647
+ style: {
648
+ opacity,
649
+ overflow: "hidden"
650
+ }
651
+ })), {
652
+ children: nextVersion.major < 13 ? /* @__PURE__ */ jsxRuntime.jsx(NextLegacyImage, {
653
+ src: publicUrl,
654
+ layout: "fill",
655
+ objectPosition: backgroundPosition,
656
+ objectFit: size
657
+ }) : /* @__PURE__ */ jsxRuntime.jsx(NextImage__default["default"], {
658
+ src: publicUrl,
659
+ alt: "",
660
+ fill: true,
661
+ sizes: "100vw",
662
+ style: {
663
+ objectPosition: backgroundPosition,
664
+ objectFit: size
665
+ }
666
+ })
136
667
  }))
137
668
  });
138
669
  }
139
- return /* @__PURE__ */ jsxRuntime.jsx("a", __spreadProps(__spreadValues({}, restOfProps), {
140
- ref,
141
- href,
142
- target,
143
- onClick: handleClick
670
+ return /* @__PURE__ */ jsxRuntime.jsx(Parallax, {
671
+ strength: parallax,
672
+ children: (getParallaxProps) => /* @__PURE__ */ jsxRuntime.jsx("div", __spreadValues({
673
+ className: containerClassName
674
+ }, getParallaxProps({
675
+ style: {
676
+ backgroundImage: publicUrl != null ? `url('${publicUrl}')` : void 0,
677
+ backgroundPosition,
678
+ backgroundRepeat: repeat,
679
+ backgroundSize: size,
680
+ opacity
681
+ }
682
+ })))
683
+ });
684
+ }
685
+ function GradientBackground({
686
+ gradient,
687
+ isRadial = false,
688
+ angle = Math.PI
689
+ }) {
690
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
691
+ className: next.useStyle(__spreadProps(__spreadValues({}, containerStyle), {
692
+ background: isRadial ? `radial-gradient(${gradient})` : `linear-gradient(${angle}rad, ${gradient})`
693
+ }))
694
+ });
695
+ }
696
+ function getAspectRatio(aspectRatio) {
697
+ switch (aspectRatio) {
698
+ case "wide":
699
+ return 16 / 9;
700
+ case "standard":
701
+ return 4 / 3;
702
+ default:
703
+ return 16 / 9;
704
+ }
705
+ }
706
+ function VideoBackground({
707
+ url,
708
+ aspectRatio,
709
+ maskColor,
710
+ zoom,
711
+ opacity,
712
+ parallax
713
+ }) {
714
+ return /* @__PURE__ */ jsxRuntime.jsx(Parallax, {
715
+ strength: parallax,
716
+ children: (getParallaxProps) => /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, getParallaxProps({
717
+ className: next.useStyle(containerStyle)
718
+ })), {
719
+ children: /* @__PURE__ */ jsxRuntime.jsx(BackgroundVideo, {
720
+ url,
721
+ zoom,
722
+ opacity,
723
+ aspectRatio: getAspectRatio(aspectRatio),
724
+ maskColor
725
+ })
726
+ }))
727
+ });
728
+ }
729
+ var BackgroundsContainer = React.forwardRef(function BackgroundsContainer2(_g, ref) {
730
+ var _h = _g, {
731
+ backgrounds,
732
+ children,
733
+ className
734
+ } = _h, restOfProps = __objRest(_h, [
735
+ "backgrounds",
736
+ "children",
737
+ "className"
738
+ ]);
739
+ const [handle, setHandle] = React.useState(null);
740
+ React.useImperativeHandle(ref, () => handle, [handle]);
741
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", __spreadProps(__spreadValues({}, restOfProps), {
742
+ ref: setHandle,
743
+ className: css.cx(next.useStyle({
744
+ position: "relative",
745
+ width: "100%",
746
+ margin: "0 auto",
747
+ "> *": {
748
+ borderRadius: "inherit",
749
+ height: "inherit"
750
+ },
751
+ "> :last-child": {
752
+ position: "relative"
753
+ }
754
+ }), className),
755
+ children: [/* @__PURE__ */ jsxRuntime.jsx(Backgrounds, {
756
+ backgrounds: useBackgrounds(backgrounds)
757
+ }), React.Children.only(children)]
144
758
  }));
145
759
  });
146
- exports.Link = Link;
760
+ exports.BackgroundsContainer = BackgroundsContainer;
761
+ exports.GridItem = GridItem;
762
+ exports.areBoxAnimationPropsEqual = areBoxAnimationPropsEqual;
763
+ exports.useBackgrounds = useBackgrounds;
764
+ exports.useBoxAnimation = useBoxAnimation;
147
765
  //# sourceMappingURL=index.cjs2.js.map