@makeswift/runtime 0.5.0 → 0.5.2

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