@depup/lottie-react 2.4.1-depup.0 → 3.1.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 (158) 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 +38 -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 +38 -0
  8. package/build/animation/LottieDisplay.cjs +56 -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 +54 -0
  12. package/build/animation/LottieInstanceContext.cjs +16 -0
  13. package/build/animation/LottieInstanceContext.js +17 -0
  14. package/build/animation/LottieLight.cjs +18 -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 +18 -0
  18. package/build/animation/LottieRegistryContext.cjs +36 -0
  19. package/build/animation/LottieRegistryContext.js +35 -0
  20. package/build/animation/LottieSvg.cjs +19 -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 +19 -0
  24. package/build/animation/collectMarkerCrossings.cjs +38 -0
  25. package/build/animation/collectMarkerCrossings.js +38 -0
  26. package/build/animation/configureLottie.cjs +50 -0
  27. package/build/animation/configureLottie.d.cts +38 -0
  28. package/build/animation/configureLottie.d.ts +38 -0
  29. package/build/animation/configureLottie.js +48 -0
  30. package/build/animation/createLottieComponent.cjs +131 -0
  31. package/build/animation/createLottieComponent.d.cts +45 -0
  32. package/build/animation/createLottieComponent.d.ts +45 -0
  33. package/build/animation/createLottieComponent.js +131 -0
  34. package/build/animation/hasExpressions.cjs +25 -0
  35. package/build/animation/hasExpressions.js +25 -0
  36. package/build/animation/normalizeAnimationSource.cjs +38 -0
  37. package/build/animation/normalizeAnimationSource.js +38 -0
  38. package/build/animation/polymorphicForwardRef.cjs +18 -0
  39. package/build/animation/polymorphicForwardRef.js +19 -0
  40. package/build/animation/renderStyledElement.cjs +31 -0
  41. package/build/animation/renderStyledElement.js +31 -0
  42. package/build/animation/resolveSeekTarget.cjs +97 -0
  43. package/build/animation/resolveSeekTarget.js +95 -0
  44. package/build/animation/styleLayer.cjs +24 -0
  45. package/build/animation/styleLayer.js +24 -0
  46. package/build/animation/stylePrecedence.cjs +12 -0
  47. package/build/animation/stylePrecedence.js +12 -0
  48. package/build/animation/types.cjs +71 -0
  49. package/build/animation/types.d.cts +477 -0
  50. package/build/animation/types.d.ts +477 -0
  51. package/build/animation/types.js +68 -0
  52. package/build/animation/useLottie.cjs +48 -0
  53. package/build/animation/useLottie.d.cts +7 -0
  54. package/build/animation/useLottie.d.ts +7 -0
  55. package/build/animation/useLottie.js +45 -0
  56. package/build/animation/useLottieAnimation.cjs +436 -0
  57. package/build/animation/useLottieAnimation.d.cts +40 -0
  58. package/build/animation/useLottieAnimation.d.ts +40 -0
  59. package/build/animation/useLottieAnimation.js +436 -0
  60. package/build/animation/useLottieInstance.cjs +21 -0
  61. package/build/animation/useLottieInstance.d.cts +14 -0
  62. package/build/animation/useLottieInstance.d.ts +14 -0
  63. package/build/animation/useLottieInstance.js +21 -0
  64. package/build/animation/useLottieLight.cjs +28 -0
  65. package/build/animation/useLottieLight.d.cts +7 -0
  66. package/build/animation/useLottieLight.d.ts +7 -0
  67. package/build/animation/useLottieLight.js +25 -0
  68. package/build/animation/useLottieSvg.cjs +26 -0
  69. package/build/animation/useLottieSvg.d.cts +7 -0
  70. package/build/animation/useLottieSvg.d.ts +7 -0
  71. package/build/animation/useLottieSvg.js +23 -0
  72. package/build/controls/LottieControls.cjs +181 -0
  73. package/build/controls/LottieControls.d.cts +58 -0
  74. package/build/controls/LottieControls.d.ts +58 -0
  75. package/build/controls/LottieControls.js +179 -0
  76. package/build/controls/LottieDirectionButton.cjs +36 -0
  77. package/build/controls/LottieDirectionButton.js +35 -0
  78. package/build/controls/LottieFullscreenButton.cjs +35 -0
  79. package/build/controls/LottieFullscreenButton.js +34 -0
  80. package/build/controls/LottieLoopButton.cjs +32 -0
  81. package/build/controls/LottieLoopButton.js +31 -0
  82. package/build/controls/LottiePlayButton.cjs +34 -0
  83. package/build/controls/LottiePlayButton.js +33 -0
  84. package/build/controls/LottieReadout.cjs +61 -0
  85. package/build/controls/LottieReadout.d.cts +13 -0
  86. package/build/controls/LottieReadout.d.ts +13 -0
  87. package/build/controls/LottieReadout.js +60 -0
  88. package/build/controls/LottieSeekBar.cjs +87 -0
  89. package/build/controls/LottieSeekBar.js +86 -0
  90. package/build/controls/LottieSpeedSelect.cjs +51 -0
  91. package/build/controls/LottieSpeedSelect.js +50 -0
  92. package/build/controls/LottieStopButton.cjs +29 -0
  93. package/build/controls/LottieStopButton.js +28 -0
  94. package/build/controls/controlIcon.cjs +25 -0
  95. package/build/controls/controlIcon.js +25 -0
  96. package/build/controls/useFullscreen.cjs +46 -0
  97. package/build/controls/useFullscreen.js +46 -0
  98. package/build/controls/useShortcuts.cjs +70 -0
  99. package/build/controls/useShortcuts.js +70 -0
  100. package/build/index.cjs +38 -0
  101. package/build/index.d.cts +20 -0
  102. package/build/index.d.ts +20 -80
  103. package/build/index.js +18 -667
  104. package/build/interactions/LottieInteractions.cjs +42 -0
  105. package/build/interactions/LottieInteractions.d.cts +37 -0
  106. package/build/interactions/LottieInteractions.d.ts +37 -0
  107. package/build/interactions/LottieInteractions.js +42 -0
  108. package/build/interactions/coverProgress.cjs +55 -0
  109. package/build/interactions/coverProgress.js +53 -0
  110. package/build/interactions/lottieInView.cjs +110 -0
  111. package/build/interactions/lottieInView.d.cts +44 -0
  112. package/build/interactions/lottieInView.d.ts +44 -0
  113. package/build/interactions/lottieInView.js +110 -0
  114. package/build/interactions/lottieScrollScrub.cjs +166 -0
  115. package/build/interactions/lottieScrollScrub.d.cts +48 -0
  116. package/build/interactions/lottieScrollScrub.d.ts +48 -0
  117. package/build/interactions/lottieScrollScrub.js +166 -0
  118. package/build/interactions/types.d.cts +50 -0
  119. package/build/interactions/types.d.ts +50 -0
  120. package/build/interactions/useInteractionsRunner.cjs +154 -0
  121. package/build/interactions/useInteractionsRunner.js +153 -0
  122. package/build/interactions/useLottieInteractions.cjs +22 -0
  123. package/build/interactions/useLottieInteractions.d.cts +19 -0
  124. package/build/interactions/useLottieInteractions.d.ts +19 -0
  125. package/build/interactions/useLottieInteractions.js +22 -0
  126. package/build/overlays/LottieError.cjs +75 -0
  127. package/build/overlays/LottieError.d.cts +40 -0
  128. package/build/overlays/LottieError.d.ts +40 -0
  129. package/build/overlays/LottieError.js +73 -0
  130. package/build/overlays/LottieLoading.cjs +90 -0
  131. package/build/overlays/LottieLoading.d.cts +45 -0
  132. package/build/overlays/LottieLoading.d.ts +45 -0
  133. package/build/overlays/LottieLoading.js +88 -0
  134. package/build/overlays/overlayStyles.cjs +33 -0
  135. package/build/overlays/overlayStyles.js +33 -0
  136. package/build/utils/SubscriptionManager.cjs +42 -0
  137. package/build/utils/SubscriptionManager.d.cts +30 -0
  138. package/build/utils/SubscriptionManager.d.ts +30 -0
  139. package/build/utils/SubscriptionManager.js +42 -0
  140. package/build/utils/createLogger.cjs +25 -0
  141. package/build/utils/createLogger.js +25 -0
  142. package/build/utils/isSameJson.cjs +37 -0
  143. package/build/utils/isSameJson.js +37 -0
  144. package/build/utils/mergeRefs.cjs +37 -0
  145. package/build/utils/mergeRefs.js +37 -0
  146. package/build/utils/useStableValue.cjs +26 -0
  147. package/build/utils/useStableValue.js +26 -0
  148. package/changes.json +3 -8
  149. package/package.json +144 -89
  150. package/LICENSE +0 -46
  151. package/build/index.es.js +0 -653
  152. package/build/index.es.js.map +0 -1
  153. package/build/index.es.min.js +0 -3
  154. package/build/index.js.map +0 -1
  155. package/build/index.min.js +0 -3
  156. package/build/index.umd.js +0 -670
  157. package/build/index.umd.js.map +0 -1
  158. package/build/index.umd.min.js +0 -3
@@ -0,0 +1,436 @@
1
+ import { applyEngineSettings } from "./configureLottie.js";
2
+ import { createLogger } from "../utils/createLogger.js";
3
+ import { SubscriptionManager } from "../utils/SubscriptionManager.js";
4
+ import { useStableValue } from "../utils/useStableValue.js";
5
+ import { collectMarkerCrossings } from "./collectMarkerCrossings.js";
6
+ import { hasExpressions } from "./hasExpressions.js";
7
+ import { LottieRegistryContext } from "./LottieRegistryContext.js";
8
+ import { normalizeAnimationSource } from "./normalizeAnimationSource.js";
9
+ import { readMarkers, resolveSeekTarget, resolveSegments } from "./resolveSeekTarget.js";
10
+ import { LottieDirection, LottieRenderer, LottieState, LottieSubscription } from "./types.js";
11
+ import { useCallback, useContext, useEffect, useRef, useState } from "react";
12
+ //#region src/animation/useLottieAnimation.ts
13
+ /** Nothing guarantees a thrown value is an `Error`, and a reason has to be one. */
14
+ function toError(cause) {
15
+ return cause instanceof Error ? cause : new Error(String(cause));
16
+ }
17
+ /**
18
+ * Everything the animation does, with no opinion about how it is rendered.
19
+ *
20
+ * It takes the engine as an argument so the same logic serves every build.
21
+ * Reach it through `useLottie`, `useLottieSvg` or `useLottieLight` rather than
22
+ * directly.
23
+ */
24
+ function useLottieAnimation(engine, options) {
25
+ const { src, renderer, rendererSettings, loop, speed, direction, autoplay = false, segment, assetsPath, debug = false, subscriptions } = options;
26
+ const [manager] = useState(() => new SubscriptionManager());
27
+ const [display, setDisplay] = useState(null);
28
+ const setDisplayRef = useCallback((node) => {
29
+ setDisplay(node);
30
+ }, []);
31
+ const [root, setRoot] = useState(null);
32
+ const setRootRef = useCallback((node) => {
33
+ setRoot(node);
34
+ }, []);
35
+ const [animationItem, setAnimationItem] = useState(null);
36
+ const [state, setState] = useState(LottieState.loading);
37
+ const [error, setError] = useState(null);
38
+ const [loadAttempt, setLoadAttempt] = useState(1);
39
+ const reload = useCallback(() => {
40
+ setLoadAttempt((previous) => previous + 1);
41
+ }, []);
42
+ const [playableFrames, setPlayableFrames] = useState(0);
43
+ const [playableDuration, setPlayableDuration] = useState(0);
44
+ const [speedValue, setSpeedValue] = useState(speed ?? 1);
45
+ const [directionValue, setDirectionValue] = useState(direction ?? LottieDirection.forward);
46
+ const [loopValue, setLoopValue] = useState(loop ?? false);
47
+ const source = useStableValue(src);
48
+ const loadConfig = useStableValue({
49
+ renderer,
50
+ rendererSettings,
51
+ autoplay,
52
+ segment,
53
+ assetsPath
54
+ });
55
+ const itemRef = useRef(null);
56
+ const valuesRef = useRef({
57
+ speed: speedValue,
58
+ direction: directionValue,
59
+ loop: loopValue
60
+ });
61
+ valuesRef.current.speed = speedValue;
62
+ valuesRef.current.direction = directionValue;
63
+ valuesRef.current.loop = loopValue;
64
+ const stateRef = useRef(state);
65
+ stateRef.current = state;
66
+ const debugRef = useRef(debug);
67
+ debugRef.current = debug;
68
+ const subscriptionsRef = useRef(subscriptions);
69
+ subscriptionsRef.current = subscriptions;
70
+ const driversRef = useRef({});
71
+ const scrubbedFrom = useRef(null);
72
+ const markerMemory = useRef(null);
73
+ /**
74
+ * Warns once per field when a value is driven from a prop and from a setter.
75
+ *
76
+ * Both keep working, per field and last writer wins, but they will disagree
77
+ * the next time the prop changes, and that is worth saying out loud while
78
+ * someone is building rather than leaving them to find it.
79
+ */
80
+ const noteDriver = useCallback((field, driver) => {
81
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
82
+ const previous = driversRef.current[field];
83
+ if (previous === void 0) driversRef.current[field] = driver;
84
+ else if (previous !== driver && previous !== "both") {
85
+ driversRef.current[field] = "both";
86
+ console.warn(`[lottie-react] "${field}" is driven from both the ${field} prop and a setter. Both keep working and the last one to write wins, but they will disagree the next time the prop changes. Drive it from one place.`);
87
+ }
88
+ }
89
+ }, []);
90
+ const applySpeed = useCallback((next, driver) => {
91
+ noteDriver("speed", driver);
92
+ setSpeedValue(next);
93
+ itemRef.current?.setSpeed(next);
94
+ }, [noteDriver]);
95
+ const applyDirection = useCallback((next, driver) => {
96
+ noteDriver("direction", driver);
97
+ setDirectionValue(next);
98
+ itemRef.current?.setDirection(next === LottieDirection.forward ? 1 : -1);
99
+ }, [noteDriver]);
100
+ const applyLoop = useCallback((next, driver) => {
101
+ noteDriver("loop", driver);
102
+ setLoopValue(next);
103
+ const item = itemRef.current;
104
+ if (item) {
105
+ item.playCount = item.playDirection < 0 && typeof next === "number" ? next : 0;
106
+ item.loop = next;
107
+ }
108
+ }, [noteDriver]);
109
+ const setSpeed = useCallback((next) => {
110
+ applySpeed(typeof next === "function" ? next(valuesRef.current.speed) : next, "setter");
111
+ }, [applySpeed]);
112
+ const setDirection = useCallback((next) => {
113
+ applyDirection(typeof next === "function" ? next(valuesRef.current.direction) : next, "setter");
114
+ }, [applyDirection]);
115
+ const setLoop = useCallback((next) => {
116
+ applyLoop(typeof next === "function" ? next(valuesRef.current.loop) : next, "setter");
117
+ }, [applyLoop]);
118
+ /**
119
+ * Plays from wherever the animation is, or from the beginning if it is
120
+ * sitting at the end it plays towards.
121
+ *
122
+ * The restart is not a convenience. Playing forwards from the final frame
123
+ * does nothing, and playing in reverse from frame 0 does nothing either: the
124
+ * engine decides it has already finished, pauses, and reports completion
125
+ * without advancing. Both are the same fault seen from either end.
126
+ */
127
+ const play = useCallback(() => {
128
+ const item = itemRef.current;
129
+ if (item === null) return;
130
+ const reverse = item.playDirection < 0;
131
+ const finished = reverse ? item.currentFrame <= 0 : item.currentFrame >= item.totalFrames - 1;
132
+ const numericLoop = typeof item.loop === "number" ? item.loop : null;
133
+ const exhausted = numericLoop !== null && (reverse ? item.playCount < 0 : item.playCount >= numericLoop);
134
+ if (finished || exhausted) item.playCount = reverse && numericLoop !== null ? numericLoop : 0;
135
+ if (finished) {
136
+ markerMemory.current = null;
137
+ item.goToAndPlay(reverse ? item.totalFrames : 0, true);
138
+ } else item.play();
139
+ setState(LottieState.playing);
140
+ }, []);
141
+ const pause = useCallback(() => {
142
+ const item = itemRef.current;
143
+ if (item === null) return;
144
+ item.pause();
145
+ setState(LottieState.paused);
146
+ }, []);
147
+ const stop = useCallback(() => {
148
+ const item = itemRef.current;
149
+ if (item === null) return;
150
+ markerMemory.current = null;
151
+ item.playCount = 0;
152
+ item.goToAndStop(0, true);
153
+ setState(LottieState.stopped);
154
+ }, []);
155
+ /**
156
+ * Reads the playable range, and how it is being played, back off the engine.
157
+ *
158
+ * A segment rewrites `firstFrame` and `totalFrames`, so the two values we
159
+ * report about length have to follow it or a progress bar keeps measuring
160
+ * whatever was playable before. It settles direction and speed as well: a
161
+ * range whose end precedes its start plays backwards, a forward range played
162
+ * while reversed turns the animation around, and a forward range at a
163
+ * negative speed flips the speed instead. Reporting what was asked for rather
164
+ * than what happened would make each of those a quiet lie.
165
+ */
166
+ const refreshRange = useCallback((item) => {
167
+ setPlayableFrames(item.totalFrames);
168
+ setPlayableDuration(item.getDuration(false));
169
+ setDirectionValue(item.playDirection < 0 ? LottieDirection.reverse : LottieDirection.forward);
170
+ setSpeedValue(item.playSpeed);
171
+ }, []);
172
+ /**
173
+ * Resolves a seek target, and says so in development when it cannot.
174
+ *
175
+ * Shared by `seek` and `scrubTo` so both report the same way. The message is
176
+ * built inside the guard rather than passed in, because an argument built at
177
+ * a call site survives as a discarded expression even once the branch that
178
+ * used it has gone.
179
+ */
180
+ const resolveOrWarn = useCallback((item, target) => {
181
+ const resolved = resolveSeekTarget(item, target);
182
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
183
+ if (resolved === null) console.warn(`[lottie-react] the seek target ${JSON.stringify(target)} could not be resolved, so nothing moved. A marker name has to match one the animation carries, and every other unit has to be a finite number.`);
184
+ else if (resolved.frame !== resolved.requested && typeof target === "object" && target.marker !== void 0) console.warn(`[lottie-react] the marker "${target.marker}" lies outside the playable range, so the seek was held at frame ${resolved.frame}. Markers are placed against the whole animation, while seeking is relative to whatever a segment has left playable.`);
185
+ }
186
+ return resolved === null ? null : resolved.frame;
187
+ }, []);
188
+ const seek = useCallback((target) => {
189
+ const item = itemRef.current;
190
+ if (item === null) return;
191
+ const frame = resolveOrWarn(item, target);
192
+ if (frame === null) return;
193
+ markerMemory.current = null;
194
+ if (item.isPaused) item.goToAndStop(frame, true);
195
+ else item.goToAndPlay(frame, true);
196
+ }, [resolveOrWarn]);
197
+ const scrubStart = useCallback(() => {
198
+ const item = itemRef.current;
199
+ if (item === null) return;
200
+ scrubbedFrom.current = stateRef.current;
201
+ item.pause();
202
+ setState(LottieState.paused);
203
+ }, []);
204
+ const scrubTo = useCallback((frame) => {
205
+ const item = itemRef.current;
206
+ if (item === null) return;
207
+ const resolved = resolveOrWarn(item, frame);
208
+ if (resolved === null) return;
209
+ markerMemory.current = null;
210
+ item.goToAndStop(resolved, true);
211
+ setState(LottieState.paused);
212
+ }, [resolveOrWarn]);
213
+ const scrubEnd = useCallback(() => {
214
+ if (itemRef.current === null) return;
215
+ const before = scrubbedFrom.current;
216
+ scrubbedFrom.current = null;
217
+ if (before === LottieState.playing) play();
218
+ }, [play]);
219
+ const playSegments = useCallback((segments, options) => {
220
+ const item = itemRef.current;
221
+ if (item === null) return;
222
+ const ranges = resolveSegments(item, segments);
223
+ if (ranges === null) {
224
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") console.warn(`[lottie-react] playSegments could not use ${JSON.stringify(segments)}, so nothing changed. A range is two different finite frame numbers, and a marker has to carry a duration. A marker without one labels a position rather than a span: seek to it and play instead.`);
225
+ return;
226
+ }
227
+ item.playSegments(ranges, options?.queue !== true || item.isPaused);
228
+ setState(LottieState.playing);
229
+ }, []);
230
+ const resetSegments = useCallback(() => {
231
+ const item = itemRef.current;
232
+ if (item === null) return;
233
+ const wasPlaying = !item.isPaused;
234
+ const { segment } = loadConfig;
235
+ if (segment === void 0) item.resetSegments(true);
236
+ else item.playSegments([[segment[0], segment[1]]], true);
237
+ if (!wasPlaying) item.pause();
238
+ }, [loadConfig]);
239
+ useEffect(() => {
240
+ const unsubscribers = [
241
+ manager.subscribe(LottieSubscription.ready, () => subscriptionsRef.current?.ready?.()),
242
+ manager.subscribe(LottieSubscription.play, () => subscriptionsRef.current?.play?.()),
243
+ manager.subscribe(LottieSubscription.pause, () => subscriptionsRef.current?.pause?.()),
244
+ manager.subscribe(LottieSubscription.stop, () => subscriptionsRef.current?.stop?.()),
245
+ manager.subscribe(LottieSubscription.complete, () => subscriptionsRef.current?.complete?.()),
246
+ manager.subscribe(LottieSubscription.loopCompleted, () => subscriptionsRef.current?.loopCompleted?.()),
247
+ manager.subscribe(LottieSubscription.frame, (event) => subscriptionsRef.current?.frame?.(event)),
248
+ manager.subscribe(LottieSubscription.marker, (event) => subscriptionsRef.current?.marker?.(event)),
249
+ manager.subscribe(LottieSubscription.newState, (event) => subscriptionsRef.current?.newState?.(event)),
250
+ manager.subscribe(LottieSubscription.error, (event) => subscriptionsRef.current?.error?.(event))
251
+ ];
252
+ return () => {
253
+ for (const unsubscribe of unsubscribers) unsubscribe();
254
+ };
255
+ }, [manager]);
256
+ const notifiedState = useRef(state);
257
+ useEffect(() => {
258
+ const previous = notifiedState.current;
259
+ if (previous === state) return;
260
+ notifiedState.current = state;
261
+ manager.notify(LottieSubscription.newState, { state });
262
+ if (state === LottieState.playing) manager.notify(LottieSubscription.play);
263
+ else if (state === LottieState.paused) manager.notify(LottieSubscription.pause);
264
+ else if (state === LottieState.stopped && previous !== LottieState.loading) manager.notify(LottieSubscription.stop);
265
+ }, [state, manager]);
266
+ useEffect(() => {
267
+ if (display === null) return;
268
+ const logger = createLogger(debugRef.current);
269
+ setState(LottieState.loading);
270
+ setError(null);
271
+ markerMemory.current = null;
272
+ const fail = (cause) => {
273
+ manager.notify(LottieSubscription.error, { error: cause });
274
+ setError(cause);
275
+ setState(LottieState.error);
276
+ };
277
+ const normalized = normalizeAnimationSource(source);
278
+ if (normalized === null) {
279
+ fail(/* @__PURE__ */ new Error("lottie-react: `src` must be a non-empty path or a parsed animation object."));
280
+ return;
281
+ }
282
+ const chosenRenderer = loadConfig.renderer ?? LottieRenderer.svg;
283
+ const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
284
+ const autoplayed = loadConfig.autoplay && !reducedMotion;
285
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
286
+ if (loadConfig.autoplay && reducedMotion) console.warn("[lottie-react] autoplay was not started because this device asks for reduced motion. The animation is loaded and play() works; offer a control rather than starting it for them.");
287
+ }
288
+ logger.log("loading the animation", {
289
+ loadAttempt,
290
+ renderer: chosenRenderer,
291
+ autoplay: autoplayed,
292
+ loop: valuesRef.current.loop,
293
+ segment: loadConfig.segment
294
+ });
295
+ applyEngineSettings(engine);
296
+ let item;
297
+ try {
298
+ item = engine.player.loadAnimation({
299
+ ...normalized,
300
+ container: display,
301
+ renderer: chosenRenderer,
302
+ rendererSettings: loadConfig.rendererSettings,
303
+ loop: valuesRef.current.loop,
304
+ autoplay: autoplayed,
305
+ initialSegment: loadConfig.segment === void 0 ? void 0 : [loadConfig.segment[0], loadConfig.segment[1]],
306
+ assetsPath: loadConfig.assetsPath
307
+ });
308
+ } catch (cause) {
309
+ fail(toError(cause));
310
+ return;
311
+ }
312
+ itemRef.current = item;
313
+ setAnimationItem(item);
314
+ item.setSpeed(valuesRef.current.speed);
315
+ item.setDirection(valuesRef.current.direction === LottieDirection.forward ? 1 : -1);
316
+ let sortedMarkers = [];
317
+ const onDomLoaded = () => {
318
+ sortedMarkers = readMarkers(item).sort((a, b) => a.time - b.time);
319
+ setPlayableFrames(item.totalFrames);
320
+ setPlayableDuration(item.getDuration(false));
321
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
322
+ if (autoplayed) {
323
+ const repeats = valuesRef.current.loop;
324
+ if ((repeats === true ? Number.POSITIVE_INFINITY : item.getDuration(false) * (typeof repeats === "number" ? repeats + 1 : 1)) > 5) console.warn("[lottie-react] this animation starts by itself and moves for more than five seconds, which needs a way to pause it whenever anything else shares the page (WCAG 2.2.2, level A). <LottieControls> is one; any pause affordance satisfies it.");
325
+ }
326
+ if ("expressionsPlugin" in item && item.expressionsPlugin === null && "animationData" in item && hasExpressions(item.animationData)) console.warn("[lottie-react] this animation uses expressions, which the light engine does not evaluate, so it renders without them. LottieSvg and useLottieSvg run them and still draw svg only; Lottie and useLottie run them with every renderer.");
327
+ }
328
+ setState(item.isPaused ? LottieState.stopped : LottieState.playing);
329
+ manager.notify(LottieSubscription.ready);
330
+ };
331
+ const onDataFailed = () => {
332
+ fail(/* @__PURE__ */ new Error("lottie-react: the animation could not be loaded. The engine reported no reason; check that the `src` path resolves and returns animation JSON."));
333
+ };
334
+ const onComplete = () => {
335
+ setState(LottieState.stopped);
336
+ manager.notify(LottieSubscription.complete);
337
+ };
338
+ const onLoopComplete = () => {
339
+ manager.notify(LottieSubscription.loopCompleted);
340
+ };
341
+ const onEnterFrame = () => {
342
+ const current = item.currentFrame;
343
+ manager.notify(LottieSubscription.frame, { currentFrame: current });
344
+ const previous = markerMemory.current;
345
+ markerMemory.current = current;
346
+ if (previous === null || sortedMarkers.length === 0) return;
347
+ const announce = (from, to) => {
348
+ const crossed = collectMarkerCrossings(sortedMarkers, item.firstFrame, from, to);
349
+ if (crossed !== null) for (const name of crossed) manager.notify(LottieSubscription.marker, { marker: name });
350
+ };
351
+ const forward = item.playDirection >= 0;
352
+ if (!(forward ? current < previous : current > previous)) announce(previous, current);
353
+ else if (forward) {
354
+ announce(previous, item.totalFrames);
355
+ announce(-1, current);
356
+ } else {
357
+ announce(previous, -1);
358
+ announce(item.totalFrames, current);
359
+ }
360
+ };
361
+ const onSegmentStart = () => {
362
+ markerMemory.current = null;
363
+ refreshRange(item);
364
+ };
365
+ const listeners = [
366
+ ["DOMLoaded", onDomLoaded],
367
+ ["data_failed", onDataFailed],
368
+ ["complete", onComplete],
369
+ ["loopComplete", onLoopComplete],
370
+ ["enterFrame", onEnterFrame],
371
+ ["segmentStart", onSegmentStart]
372
+ ];
373
+ for (const [name, handler] of listeners) item.addEventListener(name, handler);
374
+ return () => {
375
+ for (const [name, handler] of listeners) item.removeEventListener(name, handler);
376
+ item.destroy();
377
+ itemRef.current = null;
378
+ setAnimationItem(null);
379
+ logger.log("the animation was destroyed");
380
+ };
381
+ }, [
382
+ display,
383
+ source,
384
+ loadConfig,
385
+ engine,
386
+ manager,
387
+ refreshRange,
388
+ loadAttempt
389
+ ]);
390
+ useEffect(() => {
391
+ if (speed !== void 0) applySpeed(speed, "prop");
392
+ }, [speed, applySpeed]);
393
+ useEffect(() => {
394
+ if (direction !== void 0) applyDirection(direction, "prop");
395
+ }, [direction, applyDirection]);
396
+ useEffect(() => {
397
+ if (loop !== void 0) applyLoop(loop, "prop");
398
+ }, [loop, applyLoop]);
399
+ const instance = {
400
+ state,
401
+ error,
402
+ reload,
403
+ speed: speedValue,
404
+ direction: directionValue,
405
+ loop: loopValue,
406
+ playableFrames,
407
+ playableDuration,
408
+ play,
409
+ pause,
410
+ stop,
411
+ seek,
412
+ scrubStart,
413
+ scrubTo,
414
+ scrubEnd,
415
+ playSegments,
416
+ resetSegments,
417
+ setSpeed,
418
+ setDirection,
419
+ setLoop,
420
+ subscribe: manager.subscribe,
421
+ setDisplayRef,
422
+ setRootRef,
423
+ root,
424
+ animationItem
425
+ };
426
+ const registry = useContext(LottieRegistryContext);
427
+ const box = useRef({ current: instance }).current;
428
+ box.current = instance;
429
+ useEffect(() => registry?.register(box), [registry, box]);
430
+ useEffect(() => {
431
+ registry?.bump();
432
+ });
433
+ return instance;
434
+ }
435
+ //#endregion
436
+ export { useLottieAnimation };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ const require_LottieInstanceContext = require("./LottieInstanceContext.cjs");
3
+ let react = require("react");
4
+ //#region src/animation/useLottieInstance.ts
5
+ /**
6
+ * The animation a child component should drive: the one it was handed, else the
7
+ * one its `<Lottie>` published.
8
+ *
9
+ * The prop wins, so a child given an animation explicitly is never quietly
10
+ * driven by a surrounding one. Reaching neither is a thrown error rather than a
11
+ * silent no-op, because a control bar that renders and does nothing is a worse
12
+ * failure than one that never renders.
13
+ */
14
+ function useLottieInstance(explicit) {
15
+ const provided = (0, react.useContext)(require_LottieInstanceContext.LottieInstanceContext);
16
+ const instance = explicit ?? provided;
17
+ if (instance === null) throw new Error("lottie-react: no animation to work with. Render this inside <Lottie>, or pass lottie={…} from useLottie().");
18
+ return instance;
19
+ }
20
+ //#endregion
21
+ exports.useLottieInstance = useLottieInstance;
@@ -0,0 +1,14 @@
1
+ import { LottieInstance } from "./types.cjs";
2
+ //#region src/animation/useLottieInstance.d.ts
3
+ /**
4
+ * The animation a child component should drive: the one it was handed, else the
5
+ * one its `<Lottie>` published.
6
+ *
7
+ * The prop wins, so a child given an animation explicitly is never quietly
8
+ * driven by a surrounding one. Reaching neither is a thrown error rather than a
9
+ * silent no-op, because a control bar that renders and does nothing is a worse
10
+ * failure than one that never renders.
11
+ */
12
+ declare function useLottieInstance(explicit?: LottieInstance): LottieInstance;
13
+ //#endregion
14
+ export { useLottieInstance };
@@ -0,0 +1,14 @@
1
+ import { LottieInstance } from "./types.js";
2
+ //#region src/animation/useLottieInstance.d.ts
3
+ /**
4
+ * The animation a child component should drive: the one it was handed, else the
5
+ * one its `<Lottie>` published.
6
+ *
7
+ * The prop wins, so a child given an animation explicitly is never quietly
8
+ * driven by a surrounding one. Reaching neither is a thrown error rather than a
9
+ * silent no-op, because a control bar that renders and does nothing is a worse
10
+ * failure than one that never renders.
11
+ */
12
+ declare function useLottieInstance(explicit?: LottieInstance): LottieInstance;
13
+ //#endregion
14
+ export { useLottieInstance };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { LottieInstanceContext } from "./LottieInstanceContext.js";
3
+ import { useContext } from "react";
4
+ //#region src/animation/useLottieInstance.ts
5
+ /**
6
+ * The animation a child component should drive: the one it was handed, else the
7
+ * one its `<Lottie>` published.
8
+ *
9
+ * The prop wins, so a child given an animation explicitly is never quietly
10
+ * driven by a surrounding one. Reaching neither is a thrown error rather than a
11
+ * silent no-op, because a control bar that renders and does nothing is a worse
12
+ * failure than one that never renders.
13
+ */
14
+ function useLottieInstance(explicit) {
15
+ const provided = useContext(LottieInstanceContext);
16
+ const instance = explicit ?? provided;
17
+ if (instance === null) throw new Error("lottie-react: no animation to work with. Render this inside <Lottie>, or pass lottie={…} from useLottie().");
18
+ return instance;
19
+ }
20
+ //#endregion
21
+ export { useLottieInstance };
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_configureLottie = require("./configureLottie.cjs");
4
+ const require_useLottieAnimation = require("./useLottieAnimation.cjs");
5
+ let lottie_web_build_player_lottie_light_js = require("lottie-web/build/player/lottie_light.js");
6
+ lottie_web_build_player_lottie_light_js = require_runtime.__toESM(lottie_web_build_player_lottie_light_js, 1);
7
+ //#region src/animation/useLottieLight.ts
8
+ /**
9
+ * Loads and drives an animation using the light build of the engine.
10
+ *
11
+ * Identical to {@link useLottie} except that `svg` is the only renderer, which
12
+ * the type enforces: the light build does not contain the other two, and asking
13
+ * it for one throws at runtime while its own declarations claim otherwise.
14
+ * It also carries no expression engine, so a property an expression drives is
15
+ * drawn at its static value; {@link useLottieSvg} is the smaller build that
16
+ * keeps expressions.
17
+ */
18
+ /** The light engine: svg only, no expressions, no `eval`. */
19
+ const lightEngine = {
20
+ player: lottie_web_build_player_lottie_light_js.default,
21
+ name: require_configureLottie.LottieEngineName.light
22
+ };
23
+ function useLottieLight(options) {
24
+ return require_useLottieAnimation.useLottieAnimation(lightEngine, options);
25
+ }
26
+ //#endregion
27
+ exports.lightEngine = lightEngine;
28
+ exports.useLottieLight = useLottieLight;
@@ -0,0 +1,7 @@
1
+ import "./configureLottie.cjs";
2
+ import { LottieInstance, LottieRenderer } from "./types.cjs";
3
+ import { UseLottieOptions } from "./useLottieAnimation.cjs";
4
+ //#region src/animation/useLottieLight.d.ts
5
+ declare function useLottieLight(options: UseLottieOptions<typeof LottieRenderer.svg>): LottieInstance;
6
+ //#endregion
7
+ export { useLottieLight };
@@ -0,0 +1,7 @@
1
+ import "./configureLottie.js";
2
+ import { LottieInstance, LottieRenderer } from "./types.js";
3
+ import { UseLottieOptions } from "./useLottieAnimation.js";
4
+ //#region src/animation/useLottieLight.d.ts
5
+ declare function useLottieLight(options: UseLottieOptions<typeof LottieRenderer.svg>): LottieInstance;
6
+ //#endregion
7
+ export { useLottieLight };
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { LottieEngineName } from "./configureLottie.js";
3
+ import { useLottieAnimation } from "./useLottieAnimation.js";
4
+ import lottieLight from "lottie-web/build/player/lottie_light.js";
5
+ //#region src/animation/useLottieLight.ts
6
+ /**
7
+ * Loads and drives an animation using the light build of the engine.
8
+ *
9
+ * Identical to {@link useLottie} except that `svg` is the only renderer, which
10
+ * the type enforces: the light build does not contain the other two, and asking
11
+ * it for one throws at runtime while its own declarations claim otherwise.
12
+ * It also carries no expression engine, so a property an expression drives is
13
+ * drawn at its static value; {@link useLottieSvg} is the smaller build that
14
+ * keeps expressions.
15
+ */
16
+ /** The light engine: svg only, no expressions, no `eval`. */
17
+ const lightEngine = {
18
+ player: lottieLight,
19
+ name: LottieEngineName.light
20
+ };
21
+ function useLottieLight(options) {
22
+ return useLottieAnimation(lightEngine, options);
23
+ }
24
+ //#endregion
25
+ export { lightEngine, useLottieLight };
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
3
+ const require_configureLottie = require("./configureLottie.cjs");
4
+ const require_useLottieAnimation = require("./useLottieAnimation.cjs");
5
+ let lottie_web_build_player_lottie_svg_js = require("lottie-web/build/player/lottie_svg.js");
6
+ lottie_web_build_player_lottie_svg_js = require_runtime.__toESM(lottie_web_build_player_lottie_svg_js, 1);
7
+ //#region src/animation/useLottieSvg.ts
8
+ /**
9
+ * Loads and drives an animation using the svg build of the engine.
10
+ *
11
+ * Identical to {@link useLottie} except that `svg` is the only renderer, which
12
+ * the type enforces: the svg build does not contain the other two, and asking
13
+ * it for one throws at runtime while its own declarations claim otherwise.
14
+ * Unlike {@link useLottieLight} it keeps the expression engine.
15
+ */
16
+ /** The svg engine: svg only, expressions kept. */
17
+ const svgEngine = {
18
+ player: lottie_web_build_player_lottie_svg_js.default,
19
+ name: require_configureLottie.LottieEngineName.svg
20
+ };
21
+ function useLottieSvg(options) {
22
+ return require_useLottieAnimation.useLottieAnimation(svgEngine, options);
23
+ }
24
+ //#endregion
25
+ exports.svgEngine = svgEngine;
26
+ exports.useLottieSvg = useLottieSvg;
@@ -0,0 +1,7 @@
1
+ import "./configureLottie.cjs";
2
+ import { LottieInstance, LottieRenderer } from "./types.cjs";
3
+ import { UseLottieOptions } from "./useLottieAnimation.cjs";
4
+ //#region src/animation/useLottieSvg.d.ts
5
+ declare function useLottieSvg(options: UseLottieOptions<typeof LottieRenderer.svg>): LottieInstance;
6
+ //#endregion
7
+ export { useLottieSvg };
@@ -0,0 +1,7 @@
1
+ import "./configureLottie.js";
2
+ import { LottieInstance, LottieRenderer } from "./types.js";
3
+ import { UseLottieOptions } from "./useLottieAnimation.js";
4
+ //#region src/animation/useLottieSvg.d.ts
5
+ declare function useLottieSvg(options: UseLottieOptions<typeof LottieRenderer.svg>): LottieInstance;
6
+ //#endregion
7
+ export { useLottieSvg };
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { LottieEngineName } from "./configureLottie.js";
3
+ import { useLottieAnimation } from "./useLottieAnimation.js";
4
+ import lottieSvg from "lottie-web/build/player/lottie_svg.js";
5
+ //#region src/animation/useLottieSvg.ts
6
+ /**
7
+ * Loads and drives an animation using the svg build of the engine.
8
+ *
9
+ * Identical to {@link useLottie} except that `svg` is the only renderer, which
10
+ * the type enforces: the svg build does not contain the other two, and asking
11
+ * it for one throws at runtime while its own declarations claim otherwise.
12
+ * Unlike {@link useLottieLight} it keeps the expression engine.
13
+ */
14
+ /** The svg engine: svg only, expressions kept. */
15
+ const svgEngine = {
16
+ player: lottieSvg,
17
+ name: LottieEngineName.svg
18
+ };
19
+ function useLottieSvg(options) {
20
+ return useLottieAnimation(svgEngine, options);
21
+ }
22
+ //#endregion
23
+ export { svgEngine, useLottieSvg };