react-awesome-reveal 4.1.0 → 4.2.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.
package/dist/index.mjs CHANGED
@@ -345,10 +345,7 @@ var wobble = keyframes13`
345
345
  `;
346
346
 
347
347
  // src/Reveal.tsx
348
- import {
349
- ClassNames,
350
- css as css2
351
- } from "@emotion/react";
348
+ import { ClassNames } from "@emotion/react";
352
349
  import { Children, isValidElement, useMemo } from "react";
353
350
  import { InView, useInView } from "react-intersection-observer";
354
351
  import { isFragment } from "react-is";
@@ -550,10 +547,14 @@ function getAnimationCss({
550
547
  animation-direction: normal;
551
548
  animation-fill-mode: both;
552
549
  animation-iteration-count: ${iterationCount};
550
+
551
+ @media (prefers-reduced-motion: reduce) {
552
+ animation: none;
553
+ }
553
554
  `;
554
555
  }
555
556
 
556
- // src/utils/react.ts
557
+ // src/utils/guards.ts
557
558
  function isNullable(a) {
558
559
  return a == void 0;
559
560
  }
@@ -561,15 +562,22 @@ function isStringLike(value) {
561
562
  return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
562
563
  }
563
564
 
565
+ // src/utils/patterns.ts
566
+ function matchIf(onTrue, onFalse) {
567
+ return (condition) => condition ? onTrue() : onFalse();
568
+ }
569
+ function matchIfOrNull(onTrue) {
570
+ return matchIf(onTrue, () => null);
571
+ }
572
+
564
573
  // src/Reveal.tsx
565
574
  import { Fragment, jsx } from "@emotion/react/jsx-runtime";
566
- var hiddenStyles = css2`
567
- opacity: 0;
568
- `;
569
- var textBaseStyles = css2`
570
- display: inline-block;
571
- white-space: pre;
572
- `;
575
+ function hideWhen(condition) {
576
+ return matchIf(
577
+ () => ({ opacity: 0 }),
578
+ () => ({ opacity: 1 })
579
+ )(condition);
580
+ }
573
581
  var Reveal = (props) => {
574
582
  const {
575
583
  cascade = false,
@@ -579,7 +587,6 @@ var Reveal = (props) => {
579
587
  fraction = 0,
580
588
  keyframes: keyframes87 = fadeInLeft,
581
589
  triggerOnce = false,
582
- css: revealCss,
583
590
  className,
584
591
  style,
585
592
  childClassName,
@@ -594,83 +601,91 @@ var Reveal = (props) => {
594
601
  }),
595
602
  [duration, keyframes87]
596
603
  );
597
- if (isNullable(children)) {
604
+ if (isNullable(children))
598
605
  return null;
599
- }
600
- if (isStringLike(children)) {
601
- return /* @__PURE__ */ jsx(TextReveal, {
602
- ...props,
603
- animationStyles,
604
- children: String(children)
605
- });
606
- }
607
- if (isFragment(children)) {
608
- return /* @__PURE__ */ jsx(FragmentReveal, {
609
- ...props,
610
- animationStyles
611
- });
612
- }
613
- return /* @__PURE__ */ jsx(Fragment, {
614
- children: Children.map(children, (node, index) => {
615
- if (!isValidElement(node))
616
- return null;
617
- const inViewStyles = [revealCss, animationStyles];
618
- const nodeDelay = delay + (cascade ? index * duration * damping : 0);
619
- switch (node.type) {
620
- case "ol":
621
- case "ul":
622
- return /* @__PURE__ */ jsx(ClassNames, {
623
- children: ({ cx }) => /* @__PURE__ */ jsx(node.type, {
624
- ...node.props,
625
- className: cx(className, node.props.className),
626
- style: { ...style, ...node.props.style },
627
- children: /* @__PURE__ */ jsx(Reveal, {
628
- ...props,
629
- children: node.props.children
630
- })
631
- })
632
- });
633
- case "li":
634
- return /* @__PURE__ */ jsx(InView, {
606
+ if (isStringLike(children))
607
+ return /* @__PURE__ */ jsx(TextReveal, { ...props, animationStyles, children: String(children) });
608
+ if (isFragment(children))
609
+ return /* @__PURE__ */ jsx(FragmentReveal, { ...props, animationStyles });
610
+ return /* @__PURE__ */ jsx(Fragment, { children: Children.map(children, (node, index) => {
611
+ if (!isValidElement(node))
612
+ return null;
613
+ const nodeDelay = delay + (cascade ? index * duration * damping : 0);
614
+ switch (node.type) {
615
+ case "ol":
616
+ case "ul":
617
+ return /* @__PURE__ */ jsx(ClassNames, { children: ({ cx }) => /* @__PURE__ */ jsx(
618
+ node.type,
619
+ {
620
+ ...node.props,
621
+ className: cx(className, node.props.className),
622
+ style: Object.assign({}, style, node.props.style),
623
+ children: /* @__PURE__ */ jsx(Reveal, { ...props, children: node.props.children })
624
+ }
625
+ ) });
626
+ case "li":
627
+ return /* @__PURE__ */ jsx(
628
+ InView,
629
+ {
635
630
  threshold: fraction,
636
631
  triggerOnce,
637
632
  onChange: onVisibilityChange,
638
- children: ({ inView, ref }) => /* @__PURE__ */ jsx(ClassNames, {
639
- children: ({ cx }) => /* @__PURE__ */ jsx(node.type, {
633
+ children: ({ inView, ref }) => /* @__PURE__ */ jsx(ClassNames, { children: ({ cx }) => /* @__PURE__ */ jsx(
634
+ node.type,
635
+ {
640
636
  ...node.props,
641
637
  ref,
642
638
  className: cx(childClassName, node.props.className),
643
- css: inView ? inViewStyles : hiddenStyles,
644
- style: {
645
- ...childStyle,
646
- ...node.props.style,
647
- animationDelay: nodeDelay + "ms"
648
- }
649
- })
650
- })
651
- });
652
- default:
653
- return /* @__PURE__ */ jsx(InView, {
639
+ css: matchIfOrNull(() => animationStyles)(inView),
640
+ style: Object.assign(
641
+ {},
642
+ childStyle,
643
+ node.props.style,
644
+ hideWhen(!inView),
645
+ { animationDelay: nodeDelay + "ms" }
646
+ )
647
+ }
648
+ ) })
649
+ }
650
+ );
651
+ default:
652
+ return /* @__PURE__ */ jsx(
653
+ InView,
654
+ {
654
655
  threshold: fraction,
655
656
  triggerOnce,
656
657
  onChange: onVisibilityChange,
657
- children: ({ inView, ref }) => /* @__PURE__ */ jsx("div", {
658
- ref,
659
- className,
660
- css: inView ? inViewStyles : hiddenStyles,
661
- style: { ...style, animationDelay: nodeDelay + "ms" },
662
- children: /* @__PURE__ */ jsx(ClassNames, {
663
- children: ({ cx }) => /* @__PURE__ */ jsx(node.type, {
664
- ...node.props,
665
- className: cx(childClassName, node.props.className),
666
- style: { ...childStyle, ...node.props.style }
667
- })
668
- })
669
- })
670
- });
671
- }
672
- })
673
- });
658
+ children: ({ inView, ref }) => /* @__PURE__ */ jsx(
659
+ "div",
660
+ {
661
+ ref,
662
+ className,
663
+ css: matchIfOrNull(() => animationStyles)(inView),
664
+ style: Object.assign({}, style, {
665
+ animationDelay: nodeDelay + "ms"
666
+ }),
667
+ children: /* @__PURE__ */ jsx(ClassNames, { children: ({ cx }) => /* @__PURE__ */ jsx(
668
+ node.type,
669
+ {
670
+ ...node.props,
671
+ className: cx(childClassName, node.props.className),
672
+ style: Object.assign(
673
+ {},
674
+ childStyle,
675
+ node.props.style
676
+ )
677
+ }
678
+ ) })
679
+ }
680
+ )
681
+ }
682
+ );
683
+ }
684
+ }) });
685
+ };
686
+ var textBaseStyles = {
687
+ display: "inline-block",
688
+ whiteSpace: "pre"
674
689
  };
675
690
  var TextReveal = (props) => {
676
691
  const {
@@ -681,7 +696,6 @@ var TextReveal = (props) => {
681
696
  duration = 1e3,
682
697
  fraction = 0,
683
698
  triggerOnce = false,
684
- css: revealCss,
685
699
  className,
686
700
  style,
687
701
  children,
@@ -692,29 +706,34 @@ var TextReveal = (props) => {
692
706
  threshold: fraction,
693
707
  onChange: onVisibilityChange
694
708
  });
695
- return cascade ? /* @__PURE__ */ jsx("div", {
696
- ref,
697
- className,
698
- css: [revealCss, textBaseStyles],
699
- style,
700
- children: children.split("").map((char, index) => /* @__PURE__ */ jsx("span", {
701
- css: inView ? animationStyles : hiddenStyles,
702
- style: {
703
- animationDelay: delay + index * duration * damping + "ms"
704
- },
705
- children: char
706
- }, index))
707
- }) : /* @__PURE__ */ jsx(FragmentReveal, {
708
- ...props,
709
- children
710
- });
709
+ return matchIf(
710
+ () => /* @__PURE__ */ jsx(
711
+ "div",
712
+ {
713
+ ref,
714
+ className,
715
+ style: Object.assign({}, style, textBaseStyles),
716
+ children: children.split("").map((char, index) => /* @__PURE__ */ jsx(
717
+ "span",
718
+ {
719
+ css: matchIfOrNull(() => animationStyles)(inView),
720
+ style: Object.assign({}, hideWhen(!inView), {
721
+ animationDelay: delay + index * duration * damping + "ms"
722
+ }),
723
+ children: char
724
+ },
725
+ index
726
+ ))
727
+ }
728
+ ),
729
+ () => /* @__PURE__ */ jsx(FragmentReveal, { ...props, children })
730
+ )(cascade);
711
731
  };
712
732
  var FragmentReveal = (props) => {
713
733
  const {
714
734
  animationStyles,
715
735
  fraction = 0,
716
736
  triggerOnce = false,
717
- css: revealCss,
718
737
  className,
719
738
  style,
720
739
  children,
@@ -725,20 +744,24 @@ var FragmentReveal = (props) => {
725
744
  threshold: fraction,
726
745
  onChange: onVisibilityChange
727
746
  });
728
- const inViewStyles = [revealCss, animationStyles];
729
- return /* @__PURE__ */ jsx("div", {
730
- ref,
731
- className,
732
- css: inView ? inViewStyles : hiddenStyles,
733
- style,
734
- children
735
- });
747
+ return /* @__PURE__ */ jsx(
748
+ "div",
749
+ {
750
+ ref,
751
+ className,
752
+ css: matchIfOrNull(() => animationStyles)(inView),
753
+ style: Object.assign({}, style, hideWhen(!inView)),
754
+ children
755
+ }
756
+ );
736
757
  };
737
758
 
738
759
  // src/components/AttentionSeeker.tsx
739
760
  import { jsx as jsx2 } from "@emotion/react/jsx-runtime";
740
761
  function getStyles(effect) {
741
762
  switch (effect) {
763
+ case "bounce":
764
+ return [bounce, { transformOrigin: "center bottom" }];
742
765
  case "flash":
743
766
  return [flash];
744
767
  case "headShake":
@@ -763,19 +786,19 @@ function getStyles(effect) {
763
786
  return [tada];
764
787
  case "wobble":
765
788
  return [wobble];
766
- case "bounce":
767
- default:
768
- return [bounce, { transformOrigin: "center bottom" }];
769
789
  }
770
790
  }
771
791
  var AttentionSeeker = (props) => {
772
- const { effect = "bounce", ...rest } = props;
792
+ const { effect = "bounce", style, ...rest } = props;
773
793
  const [keyframes87, animationCss3] = useMemo2(() => getStyles(effect), [effect]);
774
- return /* @__PURE__ */ jsx2(Reveal, {
775
- keyframes: keyframes87,
776
- css: animationCss3,
777
- ...rest
778
- });
794
+ return /* @__PURE__ */ jsx2(
795
+ Reveal,
796
+ {
797
+ keyframes: keyframes87,
798
+ style: Object.assign({}, style, animationCss3),
799
+ ...rest
800
+ }
801
+ );
779
802
  };
780
803
 
781
804
  // src/components/Bounce.tsx
@@ -1064,10 +1087,7 @@ var Bounce = (props) => {
1064
1087
  () => getStyles2(reverse, direction),
1065
1088
  [direction, reverse]
1066
1089
  );
1067
- return /* @__PURE__ */ jsx3(Reveal, {
1068
- keyframes: keyframes87,
1069
- ...rest
1070
- });
1090
+ return /* @__PURE__ */ jsx3(Reveal, { keyframes: keyframes87, ...rest });
1071
1091
  };
1072
1092
 
1073
1093
  // src/components/Fade.tsx
@@ -1275,14 +1295,10 @@ var Fade = (props) => {
1275
1295
  () => getStyles3(big, reverse, direction),
1276
1296
  [big, direction, reverse]
1277
1297
  );
1278
- return /* @__PURE__ */ jsx4(Reveal, {
1279
- keyframes: keyframes87,
1280
- ...rest
1281
- });
1298
+ return /* @__PURE__ */ jsx4(Reveal, { keyframes: keyframes87, ...rest });
1282
1299
  };
1283
1300
 
1284
1301
  // src/components/Flip.tsx
1285
- import { css as css3 } from "@emotion/react";
1286
1302
  import { useMemo as useMemo5 } from "react";
1287
1303
 
1288
1304
  // src/animations/flippers/flip.ts
@@ -1421,25 +1437,25 @@ function getStyles4(reverse, direction) {
1421
1437
  return flip;
1422
1438
  }
1423
1439
  }
1424
- var animationCss = css3`
1425
- backface-visibility: visible;
1426
- `;
1440
+ var animationCss = {
1441
+ backfaceVisibility: "visible"
1442
+ };
1427
1443
  var Flip = (props) => {
1428
- const { direction, reverse = false, ...rest } = props;
1444
+ const { direction, reverse = false, style, ...rest } = props;
1429
1445
  const keyframes87 = useMemo5(
1430
1446
  () => getStyles4(reverse, direction),
1431
1447
  [direction, reverse]
1432
1448
  );
1433
- return /* @__PURE__ */ jsx5(Reveal, {
1434
- css: animationCss,
1435
- keyframes: keyframes87,
1436
- ...rest
1437
- });
1449
+ return /* @__PURE__ */ jsx5(
1450
+ Reveal,
1451
+ {
1452
+ keyframes: keyframes87,
1453
+ style: Object.assign({}, style, animationCss),
1454
+ ...rest
1455
+ }
1456
+ );
1438
1457
  };
1439
1458
 
1440
- // src/components/Hinge.tsx
1441
- import { css as css4 } from "@emotion/react";
1442
-
1443
1459
  // src/animations/specials/hinge.ts
1444
1460
  import { keyframes as keyframes55 } from "@emotion/react";
1445
1461
  var hinge = keyframes55`
@@ -1518,24 +1534,25 @@ var rollOut = keyframes58`
1518
1534
 
1519
1535
  // src/components/Hinge.tsx
1520
1536
  import { jsx as jsx6 } from "@emotion/react/jsx-runtime";
1521
- var animationCss2 = css4`
1522
- transform-origin: top left;
1523
- `;
1537
+ var animationCss2 = {
1538
+ transformOrigin: "top left"
1539
+ };
1524
1540
  var Hinge = (props) => {
1525
- return /* @__PURE__ */ jsx6(Reveal, {
1526
- css: animationCss2,
1527
- keyframes: hinge,
1528
- ...props
1529
- });
1541
+ const { style, ...rest } = props;
1542
+ return /* @__PURE__ */ jsx6(
1543
+ Reveal,
1544
+ {
1545
+ keyframes: hinge,
1546
+ style: Object.assign({}, style, animationCss2),
1547
+ ...rest
1548
+ }
1549
+ );
1530
1550
  };
1531
1551
 
1532
1552
  // src/components/JackInTheBox.tsx
1533
1553
  import { jsx as jsx7 } from "@emotion/react/jsx-runtime";
1534
1554
  var JackInTheBox = (props) => {
1535
- return /* @__PURE__ */ jsx7(Reveal, {
1536
- keyframes: jackInTheBox,
1537
- ...props
1538
- });
1555
+ return /* @__PURE__ */ jsx7(Reveal, { keyframes: jackInTheBox, ...props });
1539
1556
  };
1540
1557
 
1541
1558
  // src/components/Roll.tsx
@@ -1547,10 +1564,7 @@ function getStyles5(reverse) {
1547
1564
  var Roll = (props) => {
1548
1565
  const { reverse = false, ...rest } = props;
1549
1566
  const keyframes87 = useMemo6(() => getStyles5(reverse), [reverse]);
1550
- return /* @__PURE__ */ jsx8(Reveal, {
1551
- keyframes: keyframes87,
1552
- ...rest
1553
- });
1567
+ return /* @__PURE__ */ jsx8(Reveal, { keyframes: keyframes87, ...rest });
1554
1568
  };
1555
1569
 
1556
1570
  // src/components/Rotate.tsx
@@ -1708,16 +1722,19 @@ function getStyles6(reverse, direction) {
1708
1722
  }
1709
1723
  }
1710
1724
  var Rotate = (props) => {
1711
- const { direction, reverse = false, ...rest } = props;
1725
+ const { direction, reverse = false, style, ...rest } = props;
1712
1726
  const [keyframes87, animationCss3] = useMemo7(
1713
1727
  () => getStyles6(reverse, direction),
1714
1728
  [direction, reverse]
1715
1729
  );
1716
- return /* @__PURE__ */ jsx9(Reveal, {
1717
- css: animationCss3,
1718
- keyframes: keyframes87,
1719
- ...rest
1720
- });
1730
+ return /* @__PURE__ */ jsx9(
1731
+ Reveal,
1732
+ {
1733
+ keyframes: keyframes87,
1734
+ style: Object.assign({}, style, animationCss3),
1735
+ ...rest
1736
+ }
1737
+ );
1721
1738
  };
1722
1739
 
1723
1740
  // src/components/Slide.tsx
@@ -1848,10 +1865,7 @@ var Slide = (props) => {
1848
1865
  () => getStyles7(reverse, direction),
1849
1866
  [direction, reverse]
1850
1867
  );
1851
- return /* @__PURE__ */ jsx10(Reveal, {
1852
- keyframes: keyframes87,
1853
- ...rest
1854
- });
1868
+ return /* @__PURE__ */ jsx10(Reveal, { keyframes: keyframes87, ...rest });
1855
1869
  };
1856
1870
 
1857
1871
  // src/components/Zoom.tsx
@@ -2033,10 +2047,7 @@ var Zoom = (props) => {
2033
2047
  () => getStyles8(reverse, direction),
2034
2048
  [direction, reverse]
2035
2049
  );
2036
- return /* @__PURE__ */ jsx11(Reveal, {
2037
- keyframes: keyframes87,
2038
- ...rest
2039
- });
2050
+ return /* @__PURE__ */ jsx11(Reveal, { keyframes: keyframes87, ...rest });
2040
2051
  };
2041
2052
  export {
2042
2053
  AttentionSeeker,