@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,141 @@
1
+ import { isSameJson } from "../utils/isSameJson.js";
2
+ import { useStableValue } from "../utils/useStableValue.js";
3
+ import { createLottieRegistry } from "../animation/LottieRegistryContext.js";
4
+ import { useEffect, useRef, useState } from "react";
5
+ //#region src/interactions/useInteractionsRunner.ts
6
+ function isRecord(value) {
7
+ return typeof value === "object" && value !== null && !Array.isArray(value);
8
+ }
9
+ /**
10
+ * The options with every function replaced by a marker, so the whole slot can
11
+ * be compared by content. A callback's identity changes on every render at an
12
+ * inline call site, which must not read as a configuration change; a callback
13
+ * appearing or disappearing must.
14
+ */
15
+ function projectData(value) {
16
+ if (typeof value === "function") return "[function]";
17
+ if (Array.isArray(value)) return value.map(projectData);
18
+ if (isRecord(value)) {
19
+ const projected = {};
20
+ for (const [key, entry] of Object.entries(value)) projected[key] = projectData(entry);
21
+ return projected;
22
+ }
23
+ return value;
24
+ }
25
+ /**
26
+ * Arms every interaction on every animation a source holds, and keeps that
27
+ * true as animations come and go, options change, and values move.
28
+ *
29
+ * The granularity is deliberate: an animation arriving arms only itself, a
30
+ * changed option re-arms only its own slot on each animation, and a moved
31
+ * value re-arms nothing and only signals `onChange`. A re-arm caused by an
32
+ * option change hands the new attachment the old one's `memory` when the
33
+ * implementation is the same one, which is what lets a once-latch survive
34
+ * reconfiguration.
35
+ */
36
+ function useInteractionsRunner(source, interactions) {
37
+ const latest = useRef(interactions);
38
+ latest.current = interactions;
39
+ const projected = useStableValue(interactions.map((interaction) => ({
40
+ attach: interaction.attach,
41
+ options: projectData(interaction.options)
42
+ })));
43
+ const runtime = useRef(/* @__PURE__ */ new Map()).current;
44
+ const armSlot = (box, slot, memory) => {
45
+ const interaction = latest.current[slot];
46
+ const record = {
47
+ key: projected[slot],
48
+ attachIdentity: interaction.attach,
49
+ cleanup: void 0,
50
+ listeners: /* @__PURE__ */ new Set(),
51
+ memory: memory ?? {}
52
+ };
53
+ const context = {
54
+ get lottie() {
55
+ return box.current;
56
+ },
57
+ options: () => latest.current[slot]?.options,
58
+ onChange: (listener) => {
59
+ record.listeners.add(listener);
60
+ return () => {
61
+ record.listeners.delete(listener);
62
+ };
63
+ },
64
+ memory: record.memory
65
+ };
66
+ record.cleanup = interaction.attach(context, interaction.options);
67
+ return record;
68
+ };
69
+ const armRef = useRef(armSlot);
70
+ armRef.current = armSlot;
71
+ useEffect(() => {
72
+ const attachBox = (box) => {
73
+ runtime.set(box, projected.map((_, slot) => armRef.current(box, slot)));
74
+ };
75
+ const syncSlots = () => {
76
+ for (const [box, attachments] of runtime) {
77
+ for (let slot = 0; slot < projected.length; slot += 1) {
78
+ const existing = attachments[slot];
79
+ if (existing !== void 0 && isSameJson(existing.key, projected[slot])) continue;
80
+ const inherited = existing !== void 0 && existing.attachIdentity === latest.current[slot]?.attach ? existing.memory : void 0;
81
+ existing?.cleanup?.();
82
+ attachments[slot] = armRef.current(box, slot, inherited);
83
+ }
84
+ for (const removed of attachments.splice(projected.length)) removed.cleanup?.();
85
+ }
86
+ };
87
+ const syncBoxes = () => {
88
+ const current = new Set(source.boxes());
89
+ for (const box of current) if (!runtime.has(box)) attachBox(box);
90
+ for (const [box, attachments] of [...runtime]) if (!current.has(box)) {
91
+ for (const attachment of attachments) attachment.cleanup?.();
92
+ runtime.delete(box);
93
+ }
94
+ };
95
+ const notifyChange = () => {
96
+ for (const attachments of runtime.values()) for (const attachment of attachments) for (const listener of [...attachment.listeners]) listener();
97
+ };
98
+ syncSlots();
99
+ syncBoxes();
100
+ return source.subscribe(() => {
101
+ syncBoxes();
102
+ notifyChange();
103
+ });
104
+ }, [
105
+ source,
106
+ projected,
107
+ runtime
108
+ ]);
109
+ useEffect(() => {
110
+ return () => {
111
+ for (const attachments of runtime.values()) for (const attachment of attachments) attachment.cleanup?.();
112
+ runtime.clear();
113
+ };
114
+ }, [runtime]);
115
+ }
116
+ /**
117
+ * A source holding exactly one animation, for the positions where the
118
+ * component or the hook was handed an instance rather than wrapping a subtree.
119
+ * Mirrors the registration the animation itself performs toward a surrounding
120
+ * wrapper, so the runner cannot tell the two apart.
121
+ */
122
+ function useSingleInstanceSource(instance) {
123
+ const [store] = useState(createLottieRegistry);
124
+ const box = useRef(null);
125
+ if (instance !== null) {
126
+ if (box.current === null) box.current = { current: instance };
127
+ else box.current.current = instance;
128
+ }
129
+ const present = instance !== null;
130
+ useEffect(() => {
131
+ const current = box.current;
132
+ if (!present || current === null) return;
133
+ return store.register(current);
134
+ }, [store, present]);
135
+ useEffect(() => {
136
+ if (present) store.bump();
137
+ });
138
+ return store;
139
+ }
140
+ //#endregion
141
+ export { useInteractionsRunner, useSingleInstanceSource };
@@ -0,0 +1,21 @@
1
+ const require_useInteractionsRunner = require("./useInteractionsRunner.cjs");
2
+ //#region src/interactions/useLottieInteractions.ts
3
+ /**
4
+ * Attaches behaviours to one animation on the hook path.
5
+ *
6
+ * ```jsx
7
+ * const lottie = useLottie({ src, autoplay: false });
8
+ * useLottieInteractions(lottie, [lottieScrollScrub({ range: [0.2, 0.45] })]);
9
+ * ```
10
+ *
11
+ * The list is safe to write inline: implementations compare by identity and
12
+ * options by content, so a fresh array every render re-arms nothing, and a
13
+ * changed option re-arms only its own behaviour. The same runner serves
14
+ * `<LottieInteractions>`, so the two paths cannot drift.
15
+ */
16
+ function useLottieInteractions(lottie, interactions) {
17
+ const single = require_useInteractionsRunner.useSingleInstanceSource(lottie);
18
+ require_useInteractionsRunner.useInteractionsRunner(single, interactions);
19
+ }
20
+ //#endregion
21
+ exports.useLottieInteractions = useLottieInteractions;
@@ -0,0 +1,19 @@
1
+ import { LottieInstance } from "../animation/types.cjs";
2
+ import { LottieInteraction } from "./types.cjs";
3
+ //#region src/interactions/useLottieInteractions.d.ts
4
+ /**
5
+ * Attaches behaviours to one animation on the hook path.
6
+ *
7
+ * ```jsx
8
+ * const lottie = useLottie({ src, autoplay: false });
9
+ * useLottieInteractions(lottie, [lottieScrollScrub({ range: [0.2, 0.45] })]);
10
+ * ```
11
+ *
12
+ * The list is safe to write inline: implementations compare by identity and
13
+ * options by content, so a fresh array every render re-arms nothing, and a
14
+ * changed option re-arms only its own behaviour. The same runner serves
15
+ * `<LottieInteractions>`, so the two paths cannot drift.
16
+ */
17
+ declare function useLottieInteractions(lottie: LottieInstance, interactions: readonly LottieInteraction[]): void;
18
+ //#endregion
19
+ export { useLottieInteractions };
@@ -0,0 +1,19 @@
1
+ import { LottieInstance } from "../animation/types.js";
2
+ import { LottieInteraction } from "./types.js";
3
+ //#region src/interactions/useLottieInteractions.d.ts
4
+ /**
5
+ * Attaches behaviours to one animation on the hook path.
6
+ *
7
+ * ```jsx
8
+ * const lottie = useLottie({ src, autoplay: false });
9
+ * useLottieInteractions(lottie, [lottieScrollScrub({ range: [0.2, 0.45] })]);
10
+ * ```
11
+ *
12
+ * The list is safe to write inline: implementations compare by identity and
13
+ * options by content, so a fresh array every render re-arms nothing, and a
14
+ * changed option re-arms only its own behaviour. The same runner serves
15
+ * `<LottieInteractions>`, so the two paths cannot drift.
16
+ */
17
+ declare function useLottieInteractions(lottie: LottieInstance, interactions: readonly LottieInteraction[]): void;
18
+ //#endregion
19
+ export { useLottieInteractions };
@@ -0,0 +1,21 @@
1
+ import { useInteractionsRunner, useSingleInstanceSource } from "./useInteractionsRunner.js";
2
+ //#region src/interactions/useLottieInteractions.ts
3
+ /**
4
+ * Attaches behaviours to one animation on the hook path.
5
+ *
6
+ * ```jsx
7
+ * const lottie = useLottie({ src, autoplay: false });
8
+ * useLottieInteractions(lottie, [lottieScrollScrub({ range: [0.2, 0.45] })]);
9
+ * ```
10
+ *
11
+ * The list is safe to write inline: implementations compare by identity and
12
+ * options by content, so a fresh array every render re-arms nothing, and a
13
+ * changed option re-arms only its own behaviour. The same runner serves
14
+ * `<LottieInteractions>`, so the two paths cannot drift.
15
+ */
16
+ function useLottieInteractions(lottie, interactions) {
17
+ const single = useSingleInstanceSource(lottie);
18
+ useInteractionsRunner(single, interactions);
19
+ }
20
+ //#endregion
21
+ export { useLottieInteractions };
@@ -0,0 +1,74 @@
1
+ const require_renderStyledElement = require("../animation/renderStyledElement.cjs");
2
+ const require_useLottieInstance = require("../animation/useLottieInstance.cjs");
3
+ const require_types = require("../animation/types.cjs");
4
+ const require_overlayStyles = require("./overlayStyles.cjs");
5
+ let react = require("react");
6
+ //#region src/overlays/LottieError.tsx
7
+ /**
8
+ * The class the overlay carries, and the name React deduplicates its stylesheet
9
+ * by. One string does both, so two components can only collide in the document
10
+ * if they already collide in CSS.
11
+ */
12
+ const lottieErrorClass = "lottie-error";
13
+ /**
14
+ * What it says when nobody has said otherwise.
15
+ *
16
+ * A sentence written for whoever is looking at the page rather than for whoever
17
+ * wrote it: the reason itself is on the animation as `error`, and it describes
18
+ * a path or a payload, which is a developer's problem and not a reader's.
19
+ * Anything else, in any language, is passed as children.
20
+ */
21
+ const defaultMessage = "The animation could not be loaded.";
22
+ /**
23
+ * The overlay's own defaults, at zero specificity and inside the library's
24
+ * cascade layer, so that any rule the consumer
25
+ * writes beats them per property.
26
+ *
27
+ * There is nothing here beyond the shared positioning. It appears immediately,
28
+ * unlike the loading overlay, which waits: waiting exists so that a load
29
+ * finishing quickly is never announced, and a failure has already finished.
30
+ */
31
+ const lottieErrorStyles = require_overlayStyles.overlayStyles(lottieErrorClass);
32
+ /**
33
+ * What to show when the animation could not be loaded.
34
+ *
35
+ * Render it among the children of a component that publishes an animation, or
36
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
37
+ * once a load has failed and renders nothing the rest of the time.
38
+ *
39
+ * ```jsx
40
+ * <Lottie src="/hero.json">
41
+ * <LottieDisplay />
42
+ * <LottieError />
43
+ * </Lottie>
44
+ * ```
45
+ *
46
+ * The reason is on the animation as `error`, and `reload()` is what tries
47
+ * again, so a button of your own passed as children can offer both.
48
+ *
49
+ * It takes every attribute of the `div` it renders, and `ref` names that same
50
+ * element. Its own rules are all zero-specificity, so any of them can be
51
+ * replaced one property at a time from your own stylesheet. If your CSS lives
52
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
53
+ * the library's layer ranks below them.
54
+ */
55
+ const LottieError = (0, react.forwardRef)(function LottieError({ lottie, className, children, ...rest }, ref) {
56
+ const { state } = require_useLottieInstance.useLottieInstance(lottie);
57
+ if (state !== require_types.LottieState.error) return null;
58
+ return require_renderStyledElement.renderStyledElement({
59
+ tag: "div",
60
+ styleClass: lottieErrorClass,
61
+ styles: lottieErrorStyles,
62
+ className,
63
+ attributes: {
64
+ role: "alert",
65
+ ...rest
66
+ },
67
+ ref,
68
+ children: children ?? defaultMessage
69
+ });
70
+ });
71
+ //#endregion
72
+ exports.LottieError = LottieError;
73
+ exports.lottieErrorClass = lottieErrorClass;
74
+ exports.lottieErrorStyles = lottieErrorStyles;
@@ -0,0 +1,40 @@
1
+ import { FixedElementProps, LottieInstance } from "../animation/types.cjs";
2
+ import { ReactNode } from "react";
3
+ //#region src/overlays/LottieError.d.ts
4
+ /** What this component owns. Every other prop belongs to the element. */
5
+ interface LottieErrorOwnProps {
6
+ /** The animation to watch. Omit it inside a component that publishes one. */
7
+ lottie?: LottieInstance;
8
+ /** What to show when it fails. A short sentence unless you say otherwise. */
9
+ children?: ReactNode;
10
+ /** Added to the library's class rather than replacing it. */
11
+ className?: string;
12
+ }
13
+ /** What {@link LottieError} accepts. */
14
+ type LottieErrorProps = FixedElementProps<LottieErrorOwnProps, "div">;
15
+ /**
16
+ * What to show when the animation could not be loaded.
17
+ *
18
+ * Render it among the children of a component that publishes an animation, or
19
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
20
+ * once a load has failed and renders nothing the rest of the time.
21
+ *
22
+ * ```jsx
23
+ * <Lottie src="/hero.json">
24
+ * <LottieDisplay />
25
+ * <LottieError />
26
+ * </Lottie>
27
+ * ```
28
+ *
29
+ * The reason is on the animation as `error`, and `reload()` is what tries
30
+ * again, so a button of your own passed as children can offer both.
31
+ *
32
+ * It takes every attribute of the `div` it renders, and `ref` names that same
33
+ * element. Its own rules are all zero-specificity, so any of them can be
34
+ * replaced one property at a time from your own stylesheet. If your CSS lives
35
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
36
+ * the library's layer ranks below them.
37
+ */
38
+ declare const LottieError: import("react").ForwardRefExoticComponent<LottieErrorOwnProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, keyof LottieErrorOwnProps> & import("react").RefAttributes<HTMLDivElement>>;
39
+ //#endregion
40
+ export { LottieError, LottieErrorProps };
@@ -0,0 +1,40 @@
1
+ import { FixedElementProps, LottieInstance } from "../animation/types.js";
2
+ import { ReactNode } from "react";
3
+ //#region src/overlays/LottieError.d.ts
4
+ /** What this component owns. Every other prop belongs to the element. */
5
+ interface LottieErrorOwnProps {
6
+ /** The animation to watch. Omit it inside a component that publishes one. */
7
+ lottie?: LottieInstance;
8
+ /** What to show when it fails. A short sentence unless you say otherwise. */
9
+ children?: ReactNode;
10
+ /** Added to the library's class rather than replacing it. */
11
+ className?: string;
12
+ }
13
+ /** What {@link LottieError} accepts. */
14
+ type LottieErrorProps = FixedElementProps<LottieErrorOwnProps, "div">;
15
+ /**
16
+ * What to show when the animation could not be loaded.
17
+ *
18
+ * Render it among the children of a component that publishes an animation, or
19
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
20
+ * once a load has failed and renders nothing the rest of the time.
21
+ *
22
+ * ```jsx
23
+ * <Lottie src="/hero.json">
24
+ * <LottieDisplay />
25
+ * <LottieError />
26
+ * </Lottie>
27
+ * ```
28
+ *
29
+ * The reason is on the animation as `error`, and `reload()` is what tries
30
+ * again, so a button of your own passed as children can offer both.
31
+ *
32
+ * It takes every attribute of the `div` it renders, and `ref` names that same
33
+ * element. Its own rules are all zero-specificity, so any of them can be
34
+ * replaced one property at a time from your own stylesheet. If your CSS lives
35
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
36
+ * the library's layer ranks below them.
37
+ */
38
+ declare const LottieError: import("react").ForwardRefExoticComponent<LottieErrorOwnProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, keyof LottieErrorOwnProps> & import("react").RefAttributes<HTMLDivElement>>;
39
+ //#endregion
40
+ export { LottieError, LottieErrorProps };
@@ -0,0 +1,72 @@
1
+ import { renderStyledElement } from "../animation/renderStyledElement.js";
2
+ import { useLottieInstance } from "../animation/useLottieInstance.js";
3
+ import { LottieState } from "../animation/types.js";
4
+ import { overlayStyles } from "./overlayStyles.js";
5
+ import { forwardRef } from "react";
6
+ //#region src/overlays/LottieError.tsx
7
+ /**
8
+ * The class the overlay carries, and the name React deduplicates its stylesheet
9
+ * by. One string does both, so two components can only collide in the document
10
+ * if they already collide in CSS.
11
+ */
12
+ const lottieErrorClass = "lottie-error";
13
+ /**
14
+ * What it says when nobody has said otherwise.
15
+ *
16
+ * A sentence written for whoever is looking at the page rather than for whoever
17
+ * wrote it: the reason itself is on the animation as `error`, and it describes
18
+ * a path or a payload, which is a developer's problem and not a reader's.
19
+ * Anything else, in any language, is passed as children.
20
+ */
21
+ const defaultMessage = "The animation could not be loaded.";
22
+ /**
23
+ * The overlay's own defaults, at zero specificity and inside the library's
24
+ * cascade layer, so that any rule the consumer
25
+ * writes beats them per property.
26
+ *
27
+ * There is nothing here beyond the shared positioning. It appears immediately,
28
+ * unlike the loading overlay, which waits: waiting exists so that a load
29
+ * finishing quickly is never announced, and a failure has already finished.
30
+ */
31
+ const lottieErrorStyles = overlayStyles(lottieErrorClass);
32
+ /**
33
+ * What to show when the animation could not be loaded.
34
+ *
35
+ * Render it among the children of a component that publishes an animation, or
36
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
37
+ * once a load has failed and renders nothing the rest of the time.
38
+ *
39
+ * ```jsx
40
+ * <Lottie src="/hero.json">
41
+ * <LottieDisplay />
42
+ * <LottieError />
43
+ * </Lottie>
44
+ * ```
45
+ *
46
+ * The reason is on the animation as `error`, and `reload()` is what tries
47
+ * again, so a button of your own passed as children can offer both.
48
+ *
49
+ * It takes every attribute of the `div` it renders, and `ref` names that same
50
+ * element. Its own rules are all zero-specificity, so any of them can be
51
+ * replaced one property at a time from your own stylesheet. If your CSS lives
52
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
53
+ * the library's layer ranks below them.
54
+ */
55
+ const LottieError = forwardRef(function LottieError({ lottie, className, children, ...rest }, ref) {
56
+ const { state } = useLottieInstance(lottie);
57
+ if (state !== LottieState.error) return null;
58
+ return renderStyledElement({
59
+ tag: "div",
60
+ styleClass: lottieErrorClass,
61
+ styles: lottieErrorStyles,
62
+ className,
63
+ attributes: {
64
+ role: "alert",
65
+ ...rest
66
+ },
67
+ ref,
68
+ children: children ?? defaultMessage
69
+ });
70
+ });
71
+ //#endregion
72
+ export { LottieError, lottieErrorClass, lottieErrorStyles };
@@ -0,0 +1,89 @@
1
+ const require_renderStyledElement = require("../animation/renderStyledElement.cjs");
2
+ const require_useLottieInstance = require("../animation/useLottieInstance.cjs");
3
+ const require_types = require("../animation/types.cjs");
4
+ const require_overlayStyles = require("./overlayStyles.cjs");
5
+ let react = require("react");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ //#region src/overlays/LottieLoading.tsx
8
+ /**
9
+ * The class the overlay carries, and the name React deduplicates its stylesheet
10
+ * by. One string does both, so two components can only collide in the document
11
+ * if they already collide in CSS.
12
+ */
13
+ const lottieLoadingClass = "lottie-loading";
14
+ /** The class the built-in indicator carries. */
15
+ const spinnerClass = "lottie-spinner";
16
+ const spinKeyframes = "lottie-spin";
17
+ const loadingInKeyframes = "lottie-loading-in";
18
+ /** The two knobs a consumer's stylesheet can set. `showAfter` writes the first. */
19
+ const delayProperty = "--lottie-loading-delay";
20
+ /**
21
+ * The overlay's own defaults, at zero specificity and inside the library's
22
+ * cascade layer, so that any rule the consumer
23
+ * writes beats them per property.
24
+ *
25
+ * The indicator is drawn in `currentColor` and sized in `em`, so it takes the
26
+ * surrounding text's colour and size rather than any this library picked.
27
+ *
28
+ * Three of these are load-bearing.
29
+ *
30
+ * The wait is expressed as a fade **in** from a keyframe, never as a hidden
31
+ * element the animation reveals. The two look equivalent and are not: with the
32
+ * element hidden by its own rule, anything that switches the animation off
33
+ * leaves it hidden for good, while written this way the same switch shows it
34
+ * immediately, which is the right way round for an indicator.
35
+ *
36
+ * Both durations read a custom property with the default in the fallback, which
37
+ * is what lets a stylesheet change either one, at any level from the element to
38
+ * the document. `showAfter` sets the same property, so the prop and the CSS are
39
+ * one mechanism rather than two that can disagree.
40
+ *
41
+ * Under a reduced-motion preference the indicator is **slowed rather than
42
+ * stopped**, because the preference asks for less motion and a stationary
43
+ * indicator no longer says the page is working.
44
+ */
45
+ const lottieLoadingStyles = `${require_overlayStyles.overlayStyles(lottieLoadingClass)}:where(.${lottieLoadingClass}) > :where(.${spinnerClass}){box-sizing:border-box;width:2em;height:2em;border:0.15em solid currentColor;border-top-color:transparent;border-radius:50%;animation-name:${spinKeyframes};animation-duration:0.8s;animation-timing-function:linear;animation-iteration-count:infinite}:where(.${lottieLoadingClass}){animation-name:${loadingInKeyframes};animation-duration:var(--lottie-loading-fade,150ms);animation-delay:var(${delayProperty},400ms);animation-fill-mode:both}@media (prefers-reduced-motion:reduce){:where(.${lottieLoadingClass}) > :where(.${spinnerClass}){animation-duration:1.6s}}@keyframes ${spinKeyframes}{to{transform:rotate(360deg)}}@keyframes ${loadingInKeyframes}{from{opacity:0}}`;
46
+ /**
47
+ * What to show while the animation loads.
48
+ *
49
+ * Render it among the children of a component that publishes an animation, or
50
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
51
+ * while the animation is loading and renders nothing the rest of the time.
52
+ *
53
+ * ```jsx
54
+ * <Lottie src="/hero.json">
55
+ * <LottieDisplay />
56
+ * <LottieLoading />
57
+ * </Lottie>
58
+ * ```
59
+ *
60
+ * It takes every attribute of the `div` it renders, and `ref` names that same
61
+ * element. Its own rules are all zero-specificity, so any of them can be
62
+ * replaced one property at a time from your own stylesheet. If your CSS lives
63
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
64
+ * the library's layer ranks below them.
65
+ */
66
+ const LottieLoading = (0, react.forwardRef)(function LottieLoading({ lottie, className, children, showAfter, style, ...rest }, ref) {
67
+ const { state } = require_useLottieInstance.useLottieInstance(lottie);
68
+ if (state !== require_types.LottieState.loading) return null;
69
+ return require_renderStyledElement.renderStyledElement({
70
+ tag: "div",
71
+ styleClass: lottieLoadingClass,
72
+ styles: lottieLoadingStyles,
73
+ className,
74
+ attributes: {
75
+ role: "status",
76
+ ...rest,
77
+ style: showAfter === void 0 ? style : {
78
+ [delayProperty]: `${String(showAfter)}ms`,
79
+ ...style
80
+ }
81
+ },
82
+ ref,
83
+ children: children ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: spinnerClass })
84
+ });
85
+ });
86
+ //#endregion
87
+ exports.LottieLoading = LottieLoading;
88
+ exports.lottieLoadingClass = lottieLoadingClass;
89
+ exports.lottieLoadingStyles = lottieLoadingStyles;
@@ -0,0 +1,45 @@
1
+ import { FixedElementProps, LottieInstance } from "../animation/types.cjs";
2
+ import { ReactNode } from "react";
3
+ //#region src/overlays/LottieLoading.d.ts
4
+ /** What this component owns. Every other prop belongs to the element. */
5
+ interface LottieLoadingOwnProps {
6
+ /** The animation to watch. Omit it inside a component that publishes one. */
7
+ lottie?: LottieInstance;
8
+ /** What to show while it loads. A turning indicator unless you say otherwise. */
9
+ children?: ReactNode;
10
+ /** Added to the library's class rather than replacing it. */
11
+ className?: string;
12
+ /**
13
+ * How long to wait before appearing, in milliseconds.
14
+ *
15
+ * An animation that arrives sooner is never covered at all, which is what
16
+ * stops a fast load showing an indicator nobody can read. Setting `0` shows
17
+ * it at once.
18
+ */
19
+ showAfter?: number;
20
+ }
21
+ /** What {@link LottieLoading} accepts. */
22
+ type LottieLoadingProps = FixedElementProps<LottieLoadingOwnProps, "div">;
23
+ /**
24
+ * What to show while the animation loads.
25
+ *
26
+ * Render it among the children of a component that publishes an animation, or
27
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
28
+ * while the animation is loading and renders nothing the rest of the time.
29
+ *
30
+ * ```jsx
31
+ * <Lottie src="/hero.json">
32
+ * <LottieDisplay />
33
+ * <LottieLoading />
34
+ * </Lottie>
35
+ * ```
36
+ *
37
+ * It takes every attribute of the `div` it renders, and `ref` names that same
38
+ * element. Its own rules are all zero-specificity, so any of them can be
39
+ * replaced one property at a time from your own stylesheet. If your CSS lives
40
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
41
+ * the library's layer ranks below them.
42
+ */
43
+ declare const LottieLoading: import("react").ForwardRefExoticComponent<LottieLoadingOwnProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, keyof LottieLoadingOwnProps> & import("react").RefAttributes<HTMLDivElement>>;
44
+ //#endregion
45
+ export { LottieLoading, LottieLoadingProps };
@@ -0,0 +1,45 @@
1
+ import { FixedElementProps, LottieInstance } from "../animation/types.js";
2
+ import { ReactNode } from "react";
3
+ //#region src/overlays/LottieLoading.d.ts
4
+ /** What this component owns. Every other prop belongs to the element. */
5
+ interface LottieLoadingOwnProps {
6
+ /** The animation to watch. Omit it inside a component that publishes one. */
7
+ lottie?: LottieInstance;
8
+ /** What to show while it loads. A turning indicator unless you say otherwise. */
9
+ children?: ReactNode;
10
+ /** Added to the library's class rather than replacing it. */
11
+ className?: string;
12
+ /**
13
+ * How long to wait before appearing, in milliseconds.
14
+ *
15
+ * An animation that arrives sooner is never covered at all, which is what
16
+ * stops a fast load showing an indicator nobody can read. Setting `0` shows
17
+ * it at once.
18
+ */
19
+ showAfter?: number;
20
+ }
21
+ /** What {@link LottieLoading} accepts. */
22
+ type LottieLoadingProps = FixedElementProps<LottieLoadingOwnProps, "div">;
23
+ /**
24
+ * What to show while the animation loads.
25
+ *
26
+ * Render it among the children of a component that publishes an animation, or
27
+ * anywhere at all with the result of `useLottie`. It covers the box it sits in
28
+ * while the animation is loading and renders nothing the rest of the time.
29
+ *
30
+ * ```jsx
31
+ * <Lottie src="/hero.json">
32
+ * <LottieDisplay />
33
+ * <LottieLoading />
34
+ * </Lottie>
35
+ * ```
36
+ *
37
+ * It takes every attribute of the `div` it renders, and `ref` names that same
38
+ * element. Its own rules are all zero-specificity, so any of them can be
39
+ * replaced one property at a time from your own stylesheet. If your CSS lives
40
+ * in cascade layers, declare `@layer lottie-react;` before your own styles so
41
+ * the library's layer ranks below them.
42
+ */
43
+ declare const LottieLoading: import("react").ForwardRefExoticComponent<LottieLoadingOwnProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, keyof LottieLoadingOwnProps> & import("react").RefAttributes<HTMLDivElement>>;
44
+ //#endregion
45
+ export { LottieLoading, LottieLoadingProps };