@depup/lottie-react 2.4.1-depup.0 → 3.0.0-depup.0

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 (154) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +4 -10
  3. package/build/_virtual/_rolldown/runtime.cjs +23 -0
  4. package/build/animation/Lottie.cjs +39 -0
  5. package/build/animation/Lottie.d.cts +47 -0
  6. package/build/animation/Lottie.d.ts +47 -0
  7. package/build/animation/Lottie.js +37 -0
  8. package/build/animation/LottieDisplay.cjs +55 -0
  9. package/build/animation/LottieDisplay.d.cts +46 -0
  10. package/build/animation/LottieDisplay.d.ts +46 -0
  11. package/build/animation/LottieDisplay.js +53 -0
  12. package/build/animation/LottieInstanceContext.cjs +16 -0
  13. package/build/animation/LottieInstanceContext.js +17 -0
  14. package/build/animation/LottieLight.cjs +19 -0
  15. package/build/animation/LottieLight.d.cts +23 -0
  16. package/build/animation/LottieLight.d.ts +23 -0
  17. package/build/animation/LottieLight.js +17 -0
  18. package/build/animation/LottieRegistryContext.cjs +36 -0
  19. package/build/animation/LottieRegistryContext.js +35 -0
  20. package/build/animation/LottieSvg.cjs +20 -0
  21. package/build/animation/LottieSvg.d.cts +24 -0
  22. package/build/animation/LottieSvg.d.ts +24 -0
  23. package/build/animation/LottieSvg.js +18 -0
  24. package/build/animation/collectMarkerCrossings.cjs +38 -0
  25. package/build/animation/collectMarkerCrossings.js +38 -0
  26. package/build/animation/createLottieComponent.cjs +131 -0
  27. package/build/animation/createLottieComponent.d.cts +45 -0
  28. package/build/animation/createLottieComponent.d.ts +45 -0
  29. package/build/animation/createLottieComponent.js +131 -0
  30. package/build/animation/hasExpressions.cjs +25 -0
  31. package/build/animation/hasExpressions.js +25 -0
  32. package/build/animation/normalizeAnimationSource.cjs +38 -0
  33. package/build/animation/normalizeAnimationSource.js +38 -0
  34. package/build/animation/polymorphicForwardRef.cjs +18 -0
  35. package/build/animation/polymorphicForwardRef.js +19 -0
  36. package/build/animation/renderStyledElement.cjs +31 -0
  37. package/build/animation/renderStyledElement.js +31 -0
  38. package/build/animation/resolveSeekTarget.cjs +97 -0
  39. package/build/animation/resolveSeekTarget.js +95 -0
  40. package/build/animation/styleLayer.cjs +24 -0
  41. package/build/animation/styleLayer.js +24 -0
  42. package/build/animation/stylePrecedence.cjs +12 -0
  43. package/build/animation/stylePrecedence.js +12 -0
  44. package/build/animation/types.cjs +71 -0
  45. package/build/animation/types.d.cts +461 -0
  46. package/build/animation/types.d.ts +461 -0
  47. package/build/animation/types.js +68 -0
  48. package/build/animation/useLottie.cjs +40 -0
  49. package/build/animation/useLottie.d.cts +36 -0
  50. package/build/animation/useLottie.d.ts +36 -0
  51. package/build/animation/useLottie.js +38 -0
  52. package/build/animation/useLottieAnimation.cjs +434 -0
  53. package/build/animation/useLottieAnimation.d.cts +40 -0
  54. package/build/animation/useLottieAnimation.d.ts +40 -0
  55. package/build/animation/useLottieAnimation.js +434 -0
  56. package/build/animation/useLottieInstance.cjs +20 -0
  57. package/build/animation/useLottieInstance.d.cts +14 -0
  58. package/build/animation/useLottieInstance.d.ts +14 -0
  59. package/build/animation/useLottieInstance.js +20 -0
  60. package/build/animation/useLottieLight.cjs +20 -0
  61. package/build/animation/useLottieLight.d.cts +16 -0
  62. package/build/animation/useLottieLight.d.ts +16 -0
  63. package/build/animation/useLottieLight.js +18 -0
  64. package/build/animation/useLottieSvg.cjs +18 -0
  65. package/build/animation/useLottieSvg.d.cts +14 -0
  66. package/build/animation/useLottieSvg.d.ts +14 -0
  67. package/build/animation/useLottieSvg.js +16 -0
  68. package/build/controls/LottieControls.cjs +180 -0
  69. package/build/controls/LottieControls.d.cts +58 -0
  70. package/build/controls/LottieControls.d.ts +58 -0
  71. package/build/controls/LottieControls.js +178 -0
  72. package/build/controls/LottieDirectionButton.cjs +36 -0
  73. package/build/controls/LottieDirectionButton.js +35 -0
  74. package/build/controls/LottieFullscreenButton.cjs +35 -0
  75. package/build/controls/LottieFullscreenButton.js +34 -0
  76. package/build/controls/LottieLoopButton.cjs +32 -0
  77. package/build/controls/LottieLoopButton.js +31 -0
  78. package/build/controls/LottiePlayButton.cjs +34 -0
  79. package/build/controls/LottiePlayButton.js +33 -0
  80. package/build/controls/LottieReadout.cjs +61 -0
  81. package/build/controls/LottieReadout.d.cts +13 -0
  82. package/build/controls/LottieReadout.d.ts +13 -0
  83. package/build/controls/LottieReadout.js +60 -0
  84. package/build/controls/LottieSeekBar.cjs +87 -0
  85. package/build/controls/LottieSeekBar.js +86 -0
  86. package/build/controls/LottieSpeedSelect.cjs +51 -0
  87. package/build/controls/LottieSpeedSelect.js +50 -0
  88. package/build/controls/LottieStopButton.cjs +29 -0
  89. package/build/controls/LottieStopButton.js +28 -0
  90. package/build/controls/controlIcon.cjs +25 -0
  91. package/build/controls/controlIcon.js +25 -0
  92. package/build/controls/useFullscreen.cjs +46 -0
  93. package/build/controls/useFullscreen.js +46 -0
  94. package/build/controls/useShortcuts.cjs +70 -0
  95. package/build/controls/useShortcuts.js +70 -0
  96. package/build/index.cjs +36 -0
  97. package/build/index.d.cts +19 -0
  98. package/build/index.d.ts +19 -80
  99. package/build/index.js +17 -667
  100. package/build/interactions/LottieInteractions.cjs +41 -0
  101. package/build/interactions/LottieInteractions.d.cts +37 -0
  102. package/build/interactions/LottieInteractions.d.ts +37 -0
  103. package/build/interactions/LottieInteractions.js +41 -0
  104. package/build/interactions/coverProgress.cjs +55 -0
  105. package/build/interactions/coverProgress.js +53 -0
  106. package/build/interactions/lottieInView.cjs +109 -0
  107. package/build/interactions/lottieInView.d.cts +44 -0
  108. package/build/interactions/lottieInView.d.ts +44 -0
  109. package/build/interactions/lottieInView.js +109 -0
  110. package/build/interactions/lottieScrollScrub.cjs +152 -0
  111. package/build/interactions/lottieScrollScrub.d.cts +47 -0
  112. package/build/interactions/lottieScrollScrub.d.ts +47 -0
  113. package/build/interactions/lottieScrollScrub.js +152 -0
  114. package/build/interactions/types.d.cts +46 -0
  115. package/build/interactions/types.d.ts +46 -0
  116. package/build/interactions/useInteractionsRunner.cjs +142 -0
  117. package/build/interactions/useInteractionsRunner.js +141 -0
  118. package/build/interactions/useLottieInteractions.cjs +21 -0
  119. package/build/interactions/useLottieInteractions.d.cts +19 -0
  120. package/build/interactions/useLottieInteractions.d.ts +19 -0
  121. package/build/interactions/useLottieInteractions.js +21 -0
  122. package/build/overlays/LottieError.cjs +74 -0
  123. package/build/overlays/LottieError.d.cts +40 -0
  124. package/build/overlays/LottieError.d.ts +40 -0
  125. package/build/overlays/LottieError.js +72 -0
  126. package/build/overlays/LottieLoading.cjs +89 -0
  127. package/build/overlays/LottieLoading.d.cts +45 -0
  128. package/build/overlays/LottieLoading.d.ts +45 -0
  129. package/build/overlays/LottieLoading.js +87 -0
  130. package/build/overlays/overlayStyles.cjs +33 -0
  131. package/build/overlays/overlayStyles.js +33 -0
  132. package/build/utils/SubscriptionManager.cjs +42 -0
  133. package/build/utils/SubscriptionManager.d.cts +30 -0
  134. package/build/utils/SubscriptionManager.d.ts +30 -0
  135. package/build/utils/SubscriptionManager.js +42 -0
  136. package/build/utils/createLogger.cjs +25 -0
  137. package/build/utils/createLogger.js +25 -0
  138. package/build/utils/isSameJson.cjs +37 -0
  139. package/build/utils/isSameJson.js +37 -0
  140. package/build/utils/mergeRefs.cjs +37 -0
  141. package/build/utils/mergeRefs.js +37 -0
  142. package/build/utils/useStableValue.cjs +26 -0
  143. package/build/utils/useStableValue.js +26 -0
  144. package/changes.json +3 -8
  145. package/package.json +144 -89
  146. package/LICENSE +0 -46
  147. package/build/index.es.js +0 -653
  148. package/build/index.es.js.map +0 -1
  149. package/build/index.es.min.js +0 -3
  150. package/build/index.js.map +0 -1
  151. package/build/index.min.js +0 -3
  152. package/build/index.umd.js +0 -670
  153. package/build/index.umd.js.map +0 -1
  154. package/build/index.umd.min.js +0 -3
@@ -0,0 +1,24 @@
1
+ import { AnyTag, LottieRenderer, RendererInSvg } from "./types.cjs";
2
+ import { LottieComponent, LottieComponentProps } from "./createLottieComponent.cjs";
3
+ import { ReactNode } from "react";
4
+ //#region src/animation/LottieSvg.d.ts
5
+ /**
6
+ * What {@link LottieSvg} accepts. Identical to `LottieProps` except that
7
+ * `renderer` admits only what the svg build contains.
8
+ */
9
+ type LottieSvgProps<As extends AnyTag = "div", Children extends ReactNode = undefined, Renderer extends RendererInSvg = typeof LottieRenderer.svg> = LottieComponentProps<As, Children, Renderer>;
10
+ /**
11
+ * Renders an animation using the svg build of the engine.
12
+ *
13
+ * Identical to {@link Lottie} except that `svg` is the only renderer, which the
14
+ * type enforces: the svg build does not contain the other two, and asking it
15
+ * for one throws at runtime while its own declarations claim otherwise.
16
+ *
17
+ * It sits between the other two builds: smaller than the full one because it
18
+ * carries a single renderer, and unlike {@link LottieLight} it keeps the
19
+ * expression engine, so an animation whose properties are driven by
20
+ * expressions plays as designed.
21
+ */
22
+ declare const LottieSvg: LottieComponent<"svg">;
23
+ //#endregion
24
+ export { LottieSvg, LottieSvgProps };
@@ -0,0 +1,24 @@
1
+ import { AnyTag, LottieRenderer, RendererInSvg } from "./types.js";
2
+ import { LottieComponent, LottieComponentProps } from "./createLottieComponent.js";
3
+ import { ReactNode } from "react";
4
+ //#region src/animation/LottieSvg.d.ts
5
+ /**
6
+ * What {@link LottieSvg} accepts. Identical to `LottieProps` except that
7
+ * `renderer` admits only what the svg build contains.
8
+ */
9
+ type LottieSvgProps<As extends AnyTag = "div", Children extends ReactNode = undefined, Renderer extends RendererInSvg = typeof LottieRenderer.svg> = LottieComponentProps<As, Children, Renderer>;
10
+ /**
11
+ * Renders an animation using the svg build of the engine.
12
+ *
13
+ * Identical to {@link Lottie} except that `svg` is the only renderer, which the
14
+ * type enforces: the svg build does not contain the other two, and asking it
15
+ * for one throws at runtime while its own declarations claim otherwise.
16
+ *
17
+ * It sits between the other two builds: smaller than the full one because it
18
+ * carries a single renderer, and unlike {@link LottieLight} it keeps the
19
+ * expression engine, so an animation whose properties are driven by
20
+ * expressions plays as designed.
21
+ */
22
+ declare const LottieSvg: LottieComponent<"svg">;
23
+ //#endregion
24
+ export { LottieSvg, LottieSvgProps };
@@ -0,0 +1,18 @@
1
+ import { createLottieComponent } from "./createLottieComponent.js";
2
+ import lottieSvg from "lottie-web/build/player/lottie_svg.js";
3
+ //#region src/animation/LottieSvg.tsx
4
+ /**
5
+ * Renders an animation using the svg build of the engine.
6
+ *
7
+ * Identical to {@link Lottie} except that `svg` is the only renderer, which the
8
+ * type enforces: the svg build does not contain the other two, and asking it
9
+ * for one throws at runtime while its own declarations claim otherwise.
10
+ *
11
+ * It sits between the other two builds: smaller than the full one because it
12
+ * carries a single renderer, and unlike {@link LottieLight} it keeps the
13
+ * expression engine, so an animation whose properties are driven by
14
+ * expressions plays as designed.
15
+ */
16
+ const LottieSvg = createLottieComponent(lottieSvg);
17
+ //#endregion
18
+ export { LottieSvg };
@@ -0,0 +1,38 @@
1
+ //#region src/animation/collectMarkerCrossings.ts
2
+ /**
3
+ * The markers a playhead movement passed, in the order it passed them.
4
+ *
5
+ * Positions are compared in the playable range's own coordinates: a marker sits
6
+ * at `time - firstFrame`, which follows a segment the way the playhead does.
7
+ * Moving forward passes a marker when the playhead goes from before it to on or
8
+ * beyond it, so landing exactly on one announces it and the next movement away
9
+ * does not repeat it; moving backward mirrors that. A loop's wrap is not a
10
+ * movement this understands: the caller splits it into the two straight runs it
11
+ * really is and calls twice.
12
+ *
13
+ * The markers must be sorted ascending by `time`, which is what lets a scan
14
+ * stop at the first one past the movement. Returns `null` rather than an empty
15
+ * list when nothing was passed, so the per-frame path allocates nothing.
16
+ */
17
+ function collectMarkerCrossings(markers, firstFrame, previous, current) {
18
+ if (markers.length === 0 || previous === current) return null;
19
+ let crossed = null;
20
+ if (current > previous) for (const marker of markers) {
21
+ const frame = marker.time - firstFrame;
22
+ if (frame <= previous) continue;
23
+ if (frame > current) break;
24
+ if (crossed === null) crossed = [];
25
+ crossed.push(marker.payload.name);
26
+ }
27
+ else for (let index = markers.length - 1; index >= 0; index -= 1) {
28
+ const marker = markers[index];
29
+ const frame = marker.time - firstFrame;
30
+ if (frame >= previous) continue;
31
+ if (frame < current) break;
32
+ if (crossed === null) crossed = [];
33
+ crossed.push(marker.payload.name);
34
+ }
35
+ return crossed;
36
+ }
37
+ //#endregion
38
+ exports.collectMarkerCrossings = collectMarkerCrossings;
@@ -0,0 +1,38 @@
1
+ //#region src/animation/collectMarkerCrossings.ts
2
+ /**
3
+ * The markers a playhead movement passed, in the order it passed them.
4
+ *
5
+ * Positions are compared in the playable range's own coordinates: a marker sits
6
+ * at `time - firstFrame`, which follows a segment the way the playhead does.
7
+ * Moving forward passes a marker when the playhead goes from before it to on or
8
+ * beyond it, so landing exactly on one announces it and the next movement away
9
+ * does not repeat it; moving backward mirrors that. A loop's wrap is not a
10
+ * movement this understands: the caller splits it into the two straight runs it
11
+ * really is and calls twice.
12
+ *
13
+ * The markers must be sorted ascending by `time`, which is what lets a scan
14
+ * stop at the first one past the movement. Returns `null` rather than an empty
15
+ * list when nothing was passed, so the per-frame path allocates nothing.
16
+ */
17
+ function collectMarkerCrossings(markers, firstFrame, previous, current) {
18
+ if (markers.length === 0 || previous === current) return null;
19
+ let crossed = null;
20
+ if (current > previous) for (const marker of markers) {
21
+ const frame = marker.time - firstFrame;
22
+ if (frame <= previous) continue;
23
+ if (frame > current) break;
24
+ if (crossed === null) crossed = [];
25
+ crossed.push(marker.payload.name);
26
+ }
27
+ else for (let index = markers.length - 1; index >= 0; index -= 1) {
28
+ const marker = markers[index];
29
+ const frame = marker.time - firstFrame;
30
+ if (frame >= previous) continue;
31
+ if (frame < current) break;
32
+ if (crossed === null) crossed = [];
33
+ crossed.push(marker.payload.name);
34
+ }
35
+ return crossed;
36
+ }
37
+ //#endregion
38
+ export { collectMarkerCrossings };
@@ -0,0 +1,131 @@
1
+ const require_mergeRefs = require("../utils/mergeRefs.cjs");
2
+ const require_polymorphicForwardRef = require("./polymorphicForwardRef.cjs");
3
+ const require_renderStyledElement = require("./renderStyledElement.cjs");
4
+ const require_LottieInstanceContext = require("./LottieInstanceContext.cjs");
5
+ const require_LottieDisplay = require("./LottieDisplay.cjs");
6
+ const require_useLottieAnimation = require("./useLottieAnimation.cjs");
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ //#region src/animation/createLottieComponent.tsx
10
+ /**
11
+ * The class the element around the animation carries when you place the
12
+ * animation yourself, and the name React deduplicates its stylesheet by.
13
+ */
14
+ const lottieRootClass = "lottie-root";
15
+ /**
16
+ * The rules that element carries, at zero specificity and inside the library's
17
+ * cascade layer, so any rule the consumer writes beats them per property.
18
+ *
19
+ * The column is what puts the controls below the animation, and `position` is
20
+ * what the overlays anchor to. The second rule is what lets the animation take
21
+ * the space the controls leave, since the display's own default height is a
22
+ * full 100% that would otherwise push them out of the box.
23
+ *
24
+ * The descendant rule is written as two separate `:where()` selectors rather
25
+ * than one wrapping the combinator. The two are identical CSS at identical zero
26
+ * specificity, so the split form costs nothing and reads as two independent
27
+ * claims about specificity.
28
+ *
29
+ * The third rule is what this element looks like once it fills the screen. A
30
+ * browser paints a black backdrop behind whatever goes fullscreen and leaves
31
+ * the element itself transparent, so without a surface of its own the animation
32
+ * sits on black and the control bar, whose colours are all inherited, keeps the
33
+ * page's dark text and becomes close to unreadable. Measured in Chromium
34
+ * against the real bar. `Canvas` and `CanvasText` are the system page colours
35
+ * and are taken as a pair, so the two can never contradict each other the way a
36
+ * background without a matching foreground can; they follow the consumer's
37
+ * declared colour scheme rather than a colour this library picked, and the rule
38
+ * is zero-specificity like every other, so one line of their own CSS replaces
39
+ * either. It cannot be verified here, since this environment has no Fullscreen
40
+ * API at all.
41
+ */
42
+ const lottieRootStyles = `:where(.${lottieRootClass}){position:relative;display:flex;flex-direction:column}:where(.${lottieRootClass}) > :where(.${require_LottieDisplay.lottieDisplayClass}){flex:1;height:auto}:where(.${lottieRootClass}:fullscreen){background:Canvas;color:CanvasText}`;
43
+ /**
44
+ * Builds the component all three public ones are: the full, svg and light
45
+ * builds differ in the engine they load and in the renderers they admit, and in
46
+ * nothing else.
47
+ *
48
+ * `Renderers` is what narrows a smaller build to the renderers it actually
49
+ * contains, so asking it for one it does not have is a compile error rather
50
+ * than a blank animation and a runtime throw.
51
+ */
52
+ function createLottieComponent(engine) {
53
+ return require_polymorphicForwardRef.polymorphicForwardRef(function Lottie({ as, children, className, lottieRef, src, renderer, rendererSettings, loop, speed, direction, autoplay, segment, assetsPath, debug, subscriptions, ...rest }, ref) {
54
+ const instance = require_useLottieAnimation.useLottieAnimation(engine, {
55
+ src,
56
+ renderer,
57
+ rendererSettings,
58
+ loop,
59
+ speed,
60
+ direction,
61
+ autoplay,
62
+ segment,
63
+ assetsPath,
64
+ debug,
65
+ subscriptions
66
+ });
67
+ const { setDisplayRef, setRootRef } = instance;
68
+ (0, react.useImperativeHandle)(lottieRef, () => ({
69
+ reload: instance.reload,
70
+ play: instance.play,
71
+ pause: instance.pause,
72
+ stop: instance.stop,
73
+ seek: instance.seek,
74
+ scrubStart: instance.scrubStart,
75
+ scrubTo: instance.scrubTo,
76
+ scrubEnd: instance.scrubEnd,
77
+ playSegments: instance.playSegments,
78
+ resetSegments: instance.resetSegments,
79
+ setSpeed: instance.setSpeed,
80
+ setDirection: instance.setDirection,
81
+ setLoop: instance.setLoop,
82
+ animationItem: instance.animationItem
83
+ }));
84
+ const attached = (0, react.useRef)(0);
85
+ const countDisplay = (0, react.useCallback)((node) => {
86
+ attached.current += node === null ? -1 : 1;
87
+ setDisplayRef(node);
88
+ }, [setDisplayRef]);
89
+ const published = (0, react.useMemo)(() => ({
90
+ ...instance,
91
+ setDisplayRef: countDisplay
92
+ }), [instance, countDisplay]);
93
+ const hasChildren = children !== void 0;
94
+ (0, react.useEffect)(() => {
95
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
96
+ if (!hasChildren || attached.current === 1) return;
97
+ if (attached.current === 0) console.warn("[lottie-react] <Lottie> was given children and none of them is a <LottieDisplay>, so the animation has nowhere to be drawn. Add one where the animation should go. A display rendered conditionally has not appeared yet on this pass, which is the one case where this warning is expected.");
98
+ else console.warn(`[lottie-react] <Lottie> was given ${attached.current} <LottieDisplay> children and an animation can only be drawn in one of them, so the last to attach is the one that gets it. Render one display per animation.`);
99
+ }
100
+ }, [hasChildren]);
101
+ const attachDisplay = (0, react.useMemo)(() => require_mergeRefs.mergeRefs(ref, countDisplay, setRootRef), [
102
+ ref,
103
+ countDisplay,
104
+ setRootRef
105
+ ]);
106
+ const attachWrapper = (0, react.useMemo)(() => require_mergeRefs.mergeRefs(ref, setRootRef), [ref, setRootRef]);
107
+ const tag = typeof as === "string" ? as : "div";
108
+ if (!hasChildren) return require_renderStyledElement.renderStyledElement({
109
+ tag,
110
+ styleClass: require_LottieDisplay.lottieDisplayClass,
111
+ styles: require_LottieDisplay.lottieDisplayStyles,
112
+ className,
113
+ attributes: rest,
114
+ ref: attachDisplay
115
+ });
116
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_LottieInstanceContext.LottieInstanceContext.Provider, {
117
+ value: published,
118
+ children: require_renderStyledElement.renderStyledElement({
119
+ tag,
120
+ styleClass: lottieRootClass,
121
+ styles: lottieRootStyles,
122
+ className,
123
+ attributes: rest,
124
+ ref: attachWrapper,
125
+ children
126
+ })
127
+ });
128
+ });
129
+ }
130
+ //#endregion
131
+ exports.createLottieComponent = createLottieComponent;
@@ -0,0 +1,45 @@
1
+ import { AnyTag, ElementProps, LottieHandle, LottieRenderer } from "./types.cjs";
2
+ import { UseLottieOptions } from "./useLottieAnimation.cjs";
3
+ import "lottie-web";
4
+ import { ReactNode, Ref } from "react";
5
+ //#region src/animation/createLottieComponent.d.ts
6
+ /**
7
+ * What a Lottie component owns, on top of everything the animation takes.
8
+ *
9
+ * Every name here is checked against the attributes of the elements `as`
10
+ * permits, so none of them can quietly take an attribute away from a consumer.
11
+ */
12
+ interface LottieOwnProps<Children extends ReactNode, Renderer extends LottieRenderer> extends UseLottieOptions<Renderer> {
13
+ /** Which element to render. A `div` unless you say otherwise. */
14
+ as?: unknown;
15
+ /**
16
+ * Anything at all. Passing children means you place the animation yourself
17
+ * with `<LottieDisplay>`, and this component renders only the box around it.
18
+ */
19
+ children?: Children;
20
+ /** Added to the library's class rather than replacing it. */
21
+ className?: string;
22
+ /**
23
+ * Where to put the imperative handle: the commands, without the values.
24
+ *
25
+ * `ref` names the element, because this component accepts that element's
26
+ * whole attribute set, so the handle needs somewhere of its own to go. Write
27
+ * `useRef<LottieHandle>(null)`; no ref type is exported.
28
+ */
29
+ lottieRef?: Ref<LottieHandle>;
30
+ }
31
+ /** What a Lottie component accepts for a given element. */
32
+ type LottieComponentProps<As extends AnyTag, Children extends ReactNode, Renderer extends LottieRenderer> = ElementProps<LottieOwnProps<Children, Renderer>, As, Children, Renderer>;
33
+ /**
34
+ * A component that renders an animation, still generic in its element, its
35
+ * children and its renderer once the engine has been chosen.
36
+ *
37
+ * Written out as a call signature rather than inferred, because a function that
38
+ * returns a component would otherwise settle those parameters at the moment the
39
+ * component is created and hand back something that is no longer polymorphic.
40
+ */
41
+ type LottieComponent<Renderers extends LottieRenderer> = <As extends AnyTag = "div", Children extends ReactNode = undefined, Renderer extends Renderers = Extract<Renderers, typeof LottieRenderer.svg>>(props: LottieComponentProps<As, Children, Renderer> & {
42
+ ref?: Ref<HTMLElement>;
43
+ }) => ReactNode;
44
+ //#endregion
45
+ export { LottieComponent, LottieComponentProps, LottieOwnProps };
@@ -0,0 +1,45 @@
1
+ import { AnyTag, ElementProps, LottieHandle, LottieRenderer } from "./types.js";
2
+ import { UseLottieOptions } from "./useLottieAnimation.js";
3
+ import "lottie-web";
4
+ import { ReactNode, Ref } from "react";
5
+ //#region src/animation/createLottieComponent.d.ts
6
+ /**
7
+ * What a Lottie component owns, on top of everything the animation takes.
8
+ *
9
+ * Every name here is checked against the attributes of the elements `as`
10
+ * permits, so none of them can quietly take an attribute away from a consumer.
11
+ */
12
+ interface LottieOwnProps<Children extends ReactNode, Renderer extends LottieRenderer> extends UseLottieOptions<Renderer> {
13
+ /** Which element to render. A `div` unless you say otherwise. */
14
+ as?: unknown;
15
+ /**
16
+ * Anything at all. Passing children means you place the animation yourself
17
+ * with `<LottieDisplay>`, and this component renders only the box around it.
18
+ */
19
+ children?: Children;
20
+ /** Added to the library's class rather than replacing it. */
21
+ className?: string;
22
+ /**
23
+ * Where to put the imperative handle: the commands, without the values.
24
+ *
25
+ * `ref` names the element, because this component accepts that element's
26
+ * whole attribute set, so the handle needs somewhere of its own to go. Write
27
+ * `useRef<LottieHandle>(null)`; no ref type is exported.
28
+ */
29
+ lottieRef?: Ref<LottieHandle>;
30
+ }
31
+ /** What a Lottie component accepts for a given element. */
32
+ type LottieComponentProps<As extends AnyTag, Children extends ReactNode, Renderer extends LottieRenderer> = ElementProps<LottieOwnProps<Children, Renderer>, As, Children, Renderer>;
33
+ /**
34
+ * A component that renders an animation, still generic in its element, its
35
+ * children and its renderer once the engine has been chosen.
36
+ *
37
+ * Written out as a call signature rather than inferred, because a function that
38
+ * returns a component would otherwise settle those parameters at the moment the
39
+ * component is created and hand back something that is no longer polymorphic.
40
+ */
41
+ type LottieComponent<Renderers extends LottieRenderer> = <As extends AnyTag = "div", Children extends ReactNode = undefined, Renderer extends Renderers = Extract<Renderers, typeof LottieRenderer.svg>>(props: LottieComponentProps<As, Children, Renderer> & {
42
+ ref?: Ref<HTMLElement>;
43
+ }) => ReactNode;
44
+ //#endregion
45
+ export { LottieComponent, LottieComponentProps, LottieOwnProps };
@@ -0,0 +1,131 @@
1
+ import { mergeRefs } from "../utils/mergeRefs.js";
2
+ import { polymorphicForwardRef } from "./polymorphicForwardRef.js";
3
+ import { renderStyledElement } from "./renderStyledElement.js";
4
+ import { LottieInstanceContext } from "./LottieInstanceContext.js";
5
+ import { lottieDisplayClass, lottieDisplayStyles } from "./LottieDisplay.js";
6
+ import { useLottieAnimation } from "./useLottieAnimation.js";
7
+ import { useCallback, useEffect, useImperativeHandle, useMemo, useRef } from "react";
8
+ import { jsx } from "react/jsx-runtime";
9
+ //#region src/animation/createLottieComponent.tsx
10
+ /**
11
+ * The class the element around the animation carries when you place the
12
+ * animation yourself, and the name React deduplicates its stylesheet by.
13
+ */
14
+ const lottieRootClass = "lottie-root";
15
+ /**
16
+ * The rules that element carries, at zero specificity and inside the library's
17
+ * cascade layer, so any rule the consumer writes beats them per property.
18
+ *
19
+ * The column is what puts the controls below the animation, and `position` is
20
+ * what the overlays anchor to. The second rule is what lets the animation take
21
+ * the space the controls leave, since the display's own default height is a
22
+ * full 100% that would otherwise push them out of the box.
23
+ *
24
+ * The descendant rule is written as two separate `:where()` selectors rather
25
+ * than one wrapping the combinator. The two are identical CSS at identical zero
26
+ * specificity, so the split form costs nothing and reads as two independent
27
+ * claims about specificity.
28
+ *
29
+ * The third rule is what this element looks like once it fills the screen. A
30
+ * browser paints a black backdrop behind whatever goes fullscreen and leaves
31
+ * the element itself transparent, so without a surface of its own the animation
32
+ * sits on black and the control bar, whose colours are all inherited, keeps the
33
+ * page's dark text and becomes close to unreadable. Measured in Chromium
34
+ * against the real bar. `Canvas` and `CanvasText` are the system page colours
35
+ * and are taken as a pair, so the two can never contradict each other the way a
36
+ * background without a matching foreground can; they follow the consumer's
37
+ * declared colour scheme rather than a colour this library picked, and the rule
38
+ * is zero-specificity like every other, so one line of their own CSS replaces
39
+ * either. It cannot be verified here, since this environment has no Fullscreen
40
+ * API at all.
41
+ */
42
+ const lottieRootStyles = `:where(.${lottieRootClass}){position:relative;display:flex;flex-direction:column}:where(.${lottieRootClass}) > :where(.${lottieDisplayClass}){flex:1;height:auto}:where(.${lottieRootClass}:fullscreen){background:Canvas;color:CanvasText}`;
43
+ /**
44
+ * Builds the component all three public ones are: the full, svg and light
45
+ * builds differ in the engine they load and in the renderers they admit, and in
46
+ * nothing else.
47
+ *
48
+ * `Renderers` is what narrows a smaller build to the renderers it actually
49
+ * contains, so asking it for one it does not have is a compile error rather
50
+ * than a blank animation and a runtime throw.
51
+ */
52
+ function createLottieComponent(engine) {
53
+ return polymorphicForwardRef(function Lottie({ as, children, className, lottieRef, src, renderer, rendererSettings, loop, speed, direction, autoplay, segment, assetsPath, debug, subscriptions, ...rest }, ref) {
54
+ const instance = useLottieAnimation(engine, {
55
+ src,
56
+ renderer,
57
+ rendererSettings,
58
+ loop,
59
+ speed,
60
+ direction,
61
+ autoplay,
62
+ segment,
63
+ assetsPath,
64
+ debug,
65
+ subscriptions
66
+ });
67
+ const { setDisplayRef, setRootRef } = instance;
68
+ useImperativeHandle(lottieRef, () => ({
69
+ reload: instance.reload,
70
+ play: instance.play,
71
+ pause: instance.pause,
72
+ stop: instance.stop,
73
+ seek: instance.seek,
74
+ scrubStart: instance.scrubStart,
75
+ scrubTo: instance.scrubTo,
76
+ scrubEnd: instance.scrubEnd,
77
+ playSegments: instance.playSegments,
78
+ resetSegments: instance.resetSegments,
79
+ setSpeed: instance.setSpeed,
80
+ setDirection: instance.setDirection,
81
+ setLoop: instance.setLoop,
82
+ animationItem: instance.animationItem
83
+ }));
84
+ const attached = useRef(0);
85
+ const countDisplay = useCallback((node) => {
86
+ attached.current += node === null ? -1 : 1;
87
+ setDisplayRef(node);
88
+ }, [setDisplayRef]);
89
+ const published = useMemo(() => ({
90
+ ...instance,
91
+ setDisplayRef: countDisplay
92
+ }), [instance, countDisplay]);
93
+ const hasChildren = children !== void 0;
94
+ useEffect(() => {
95
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
96
+ if (!hasChildren || attached.current === 1) return;
97
+ if (attached.current === 0) console.warn("[lottie-react] <Lottie> was given children and none of them is a <LottieDisplay>, so the animation has nowhere to be drawn. Add one where the animation should go. A display rendered conditionally has not appeared yet on this pass, which is the one case where this warning is expected.");
98
+ else console.warn(`[lottie-react] <Lottie> was given ${attached.current} <LottieDisplay> children and an animation can only be drawn in one of them, so the last to attach is the one that gets it. Render one display per animation.`);
99
+ }
100
+ }, [hasChildren]);
101
+ const attachDisplay = useMemo(() => mergeRefs(ref, countDisplay, setRootRef), [
102
+ ref,
103
+ countDisplay,
104
+ setRootRef
105
+ ]);
106
+ const attachWrapper = useMemo(() => mergeRefs(ref, setRootRef), [ref, setRootRef]);
107
+ const tag = typeof as === "string" ? as : "div";
108
+ if (!hasChildren) return renderStyledElement({
109
+ tag,
110
+ styleClass: lottieDisplayClass,
111
+ styles: lottieDisplayStyles,
112
+ className,
113
+ attributes: rest,
114
+ ref: attachDisplay
115
+ });
116
+ return /* @__PURE__ */ jsx(LottieInstanceContext.Provider, {
117
+ value: published,
118
+ children: renderStyledElement({
119
+ tag,
120
+ styleClass: lottieRootClass,
121
+ styles: lottieRootStyles,
122
+ className,
123
+ attributes: rest,
124
+ ref: attachWrapper,
125
+ children
126
+ })
127
+ });
128
+ });
129
+ }
130
+ //#endregion
131
+ export { createLottieComponent };
@@ -0,0 +1,25 @@
1
+ //#region src/animation/hasExpressions.ts
2
+ function isRecord(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ /**
6
+ * Whether a parsed animation carries an expression anywhere in it.
7
+ *
8
+ * An expression is a non-empty string under the key `x` on an animatable
9
+ * property, which is also how the engine finds them. The type of the value is
10
+ * what decides, not the key: inside keyframes `x` names the numeric easing
11
+ * handles, and on a mask it names the expansion property, an object which may
12
+ * itself carry an expression one level down. The walk covers objects and
13
+ * arrays across the whole document rather than `layers` alone, because a
14
+ * precomp's layers live under `assets`, and it stops at the first find. It
15
+ * assumes the tree shape parsed JSON always has: an object that referenced
16
+ * itself would recurse without end.
17
+ */
18
+ function hasExpressions(value) {
19
+ if (Array.isArray(value)) return value.some(hasExpressions);
20
+ if (!isRecord(value)) return false;
21
+ if (typeof value.x === "string" && value.x !== "") return true;
22
+ return Object.values(value).some(hasExpressions);
23
+ }
24
+ //#endregion
25
+ exports.hasExpressions = hasExpressions;
@@ -0,0 +1,25 @@
1
+ //#region src/animation/hasExpressions.ts
2
+ function isRecord(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+ /**
6
+ * Whether a parsed animation carries an expression anywhere in it.
7
+ *
8
+ * An expression is a non-empty string under the key `x` on an animatable
9
+ * property, which is also how the engine finds them. The type of the value is
10
+ * what decides, not the key: inside keyframes `x` names the numeric easing
11
+ * handles, and on a mask it names the expansion property, an object which may
12
+ * itself carry an expression one level down. The walk covers objects and
13
+ * arrays across the whole document rather than `layers` alone, because a
14
+ * precomp's layers live under `assets`, and it stops at the first find. It
15
+ * assumes the tree shape parsed JSON always has: an object that referenced
16
+ * itself would recurse without end.
17
+ */
18
+ function hasExpressions(value) {
19
+ if (Array.isArray(value)) return value.some(hasExpressions);
20
+ if (!isRecord(value)) return false;
21
+ if (typeof value.x === "string" && value.x !== "") return true;
22
+ return Object.values(value).some(hasExpressions);
23
+ }
24
+ //#endregion
25
+ export { hasExpressions };
@@ -0,0 +1,38 @@
1
+ //#region src/animation/normalizeAnimationSource.ts
2
+ /**
3
+ * Turns the `src` prop into the pair of fields lottie-web understands, or
4
+ * `null` when it is not something an animation could be loaded from.
5
+ *
6
+ * A non-empty string is a URL or path that the engine fetches and parses as
7
+ * JSON. A `.lottie` archive is **not** supported: it is a zip, and nothing here
8
+ * or in lottie-web unpacks one.
9
+ *
10
+ * An object is the parsed animation itself, and it is **always** shallow-copied
11
+ * before the engine sees it. lottie-web writes `__complete` onto whatever it is
12
+ * handed, so a frozen object throws `TypeError: Cannot add property __complete`
13
+ * and takes the whole load down with it. That happens with `import * as data
14
+ * from "./animation.json"` under Node's own JSON modules, whose namespace is
15
+ * not extensible.
16
+ *
17
+ * The copy is unconditional rather than guarded by `Object.isExtensible`,
18
+ * because the shape of that namespace object differs by toolchain: Node's is
19
+ * not extensible while a bundler's usually is. A guard would therefore behave
20
+ * differently depending on who built the consumer's application, and a copy
21
+ * behaves the same everywhere. It costs about 70 nanoseconds and does not grow
22
+ * with the animation, since only the top level is copied.
23
+ *
24
+ * The copy does not protect the objects inside `layers`, which the engine
25
+ * annotates in place. That is harmless, because those writes are idempotent
26
+ * flags, and avoiding it would mean deep-copying the entire animation on every
27
+ * load.
28
+ */
29
+ function normalizeAnimationSource(source) {
30
+ if (typeof source === "string") {
31
+ const path = source.trim();
32
+ return path.length > 0 ? { path } : null;
33
+ }
34
+ if (typeof source === "object" && source !== null && !Array.isArray(source)) return { animationData: { ...source } };
35
+ return null;
36
+ }
37
+ //#endregion
38
+ exports.normalizeAnimationSource = normalizeAnimationSource;
@@ -0,0 +1,38 @@
1
+ //#region src/animation/normalizeAnimationSource.ts
2
+ /**
3
+ * Turns the `src` prop into the pair of fields lottie-web understands, or
4
+ * `null` when it is not something an animation could be loaded from.
5
+ *
6
+ * A non-empty string is a URL or path that the engine fetches and parses as
7
+ * JSON. A `.lottie` archive is **not** supported: it is a zip, and nothing here
8
+ * or in lottie-web unpacks one.
9
+ *
10
+ * An object is the parsed animation itself, and it is **always** shallow-copied
11
+ * before the engine sees it. lottie-web writes `__complete` onto whatever it is
12
+ * handed, so a frozen object throws `TypeError: Cannot add property __complete`
13
+ * and takes the whole load down with it. That happens with `import * as data
14
+ * from "./animation.json"` under Node's own JSON modules, whose namespace is
15
+ * not extensible.
16
+ *
17
+ * The copy is unconditional rather than guarded by `Object.isExtensible`,
18
+ * because the shape of that namespace object differs by toolchain: Node's is
19
+ * not extensible while a bundler's usually is. A guard would therefore behave
20
+ * differently depending on who built the consumer's application, and a copy
21
+ * behaves the same everywhere. It costs about 70 nanoseconds and does not grow
22
+ * with the animation, since only the top level is copied.
23
+ *
24
+ * The copy does not protect the objects inside `layers`, which the engine
25
+ * annotates in place. That is harmless, because those writes are idempotent
26
+ * flags, and avoiding it would mean deep-copying the entire animation on every
27
+ * load.
28
+ */
29
+ function normalizeAnimationSource(source) {
30
+ if (typeof source === "string") {
31
+ const path = source.trim();
32
+ return path.length > 0 ? { path } : null;
33
+ }
34
+ if (typeof source === "object" && source !== null && !Array.isArray(source)) return { animationData: { ...source } };
35
+ return null;
36
+ }
37
+ //#endregion
38
+ export { normalizeAnimationSource };
@@ -0,0 +1,18 @@
1
+ //#region src/animation/polymorphicForwardRef.ts
2
+ /**
3
+ * `forwardRef`, with the render function's own type parameters kept.
4
+ *
5
+ * A component that chooses its element through `as` is generic in that tag, and
6
+ * React's `forwardRef` is not: its signature settles the props at one type, so
7
+ * the tag is lost and `as="button" type="button"` stops typechecking while
8
+ * invented props start passing. Handing the same runtime function a signature
9
+ * that carries the parameters through is what restores per-element props.
10
+ *
11
+ * The assertion lives here, alone, so that there is one of it and so that what
12
+ * removes it is written beside it. React 18 is the whole reason it exists,
13
+ * because a function component receives a `ref` only through `forwardRef`
14
+ * there.
15
+ */
16
+ const polymorphicForwardRef = require("react").forwardRef;
17
+ //#endregion
18
+ exports.polymorphicForwardRef = polymorphicForwardRef;