@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.
- package/LICENSE.md +9 -0
- package/README.md +4 -10
- package/build/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/animation/Lottie.cjs +38 -0
- package/build/animation/Lottie.d.cts +47 -0
- package/build/animation/Lottie.d.ts +47 -0
- package/build/animation/Lottie.js +38 -0
- package/build/animation/LottieDisplay.cjs +56 -0
- package/build/animation/LottieDisplay.d.cts +46 -0
- package/build/animation/LottieDisplay.d.ts +46 -0
- package/build/animation/LottieDisplay.js +54 -0
- package/build/animation/LottieInstanceContext.cjs +16 -0
- package/build/animation/LottieInstanceContext.js +17 -0
- package/build/animation/LottieLight.cjs +18 -0
- package/build/animation/LottieLight.d.cts +23 -0
- package/build/animation/LottieLight.d.ts +23 -0
- package/build/animation/LottieLight.js +18 -0
- package/build/animation/LottieRegistryContext.cjs +36 -0
- package/build/animation/LottieRegistryContext.js +35 -0
- package/build/animation/LottieSvg.cjs +19 -0
- package/build/animation/LottieSvg.d.cts +24 -0
- package/build/animation/LottieSvg.d.ts +24 -0
- package/build/animation/LottieSvg.js +19 -0
- package/build/animation/collectMarkerCrossings.cjs +38 -0
- package/build/animation/collectMarkerCrossings.js +38 -0
- package/build/animation/configureLottie.cjs +50 -0
- package/build/animation/configureLottie.d.cts +38 -0
- package/build/animation/configureLottie.d.ts +38 -0
- package/build/animation/configureLottie.js +48 -0
- package/build/animation/createLottieComponent.cjs +131 -0
- package/build/animation/createLottieComponent.d.cts +45 -0
- package/build/animation/createLottieComponent.d.ts +45 -0
- package/build/animation/createLottieComponent.js +131 -0
- package/build/animation/hasExpressions.cjs +25 -0
- package/build/animation/hasExpressions.js +25 -0
- package/build/animation/normalizeAnimationSource.cjs +38 -0
- package/build/animation/normalizeAnimationSource.js +38 -0
- package/build/animation/polymorphicForwardRef.cjs +18 -0
- package/build/animation/polymorphicForwardRef.js +19 -0
- package/build/animation/renderStyledElement.cjs +31 -0
- package/build/animation/renderStyledElement.js +31 -0
- package/build/animation/resolveSeekTarget.cjs +97 -0
- package/build/animation/resolveSeekTarget.js +95 -0
- package/build/animation/styleLayer.cjs +24 -0
- package/build/animation/styleLayer.js +24 -0
- package/build/animation/stylePrecedence.cjs +12 -0
- package/build/animation/stylePrecedence.js +12 -0
- package/build/animation/types.cjs +71 -0
- package/build/animation/types.d.cts +477 -0
- package/build/animation/types.d.ts +477 -0
- package/build/animation/types.js +68 -0
- package/build/animation/useLottie.cjs +48 -0
- package/build/animation/useLottie.d.cts +7 -0
- package/build/animation/useLottie.d.ts +7 -0
- package/build/animation/useLottie.js +45 -0
- package/build/animation/useLottieAnimation.cjs +436 -0
- package/build/animation/useLottieAnimation.d.cts +40 -0
- package/build/animation/useLottieAnimation.d.ts +40 -0
- package/build/animation/useLottieAnimation.js +436 -0
- package/build/animation/useLottieInstance.cjs +21 -0
- package/build/animation/useLottieInstance.d.cts +14 -0
- package/build/animation/useLottieInstance.d.ts +14 -0
- package/build/animation/useLottieInstance.js +21 -0
- package/build/animation/useLottieLight.cjs +28 -0
- package/build/animation/useLottieLight.d.cts +7 -0
- package/build/animation/useLottieLight.d.ts +7 -0
- package/build/animation/useLottieLight.js +25 -0
- package/build/animation/useLottieSvg.cjs +26 -0
- package/build/animation/useLottieSvg.d.cts +7 -0
- package/build/animation/useLottieSvg.d.ts +7 -0
- package/build/animation/useLottieSvg.js +23 -0
- package/build/controls/LottieControls.cjs +181 -0
- package/build/controls/LottieControls.d.cts +58 -0
- package/build/controls/LottieControls.d.ts +58 -0
- package/build/controls/LottieControls.js +179 -0
- package/build/controls/LottieDirectionButton.cjs +36 -0
- package/build/controls/LottieDirectionButton.js +35 -0
- package/build/controls/LottieFullscreenButton.cjs +35 -0
- package/build/controls/LottieFullscreenButton.js +34 -0
- package/build/controls/LottieLoopButton.cjs +32 -0
- package/build/controls/LottieLoopButton.js +31 -0
- package/build/controls/LottiePlayButton.cjs +34 -0
- package/build/controls/LottiePlayButton.js +33 -0
- package/build/controls/LottieReadout.cjs +61 -0
- package/build/controls/LottieReadout.d.cts +13 -0
- package/build/controls/LottieReadout.d.ts +13 -0
- package/build/controls/LottieReadout.js +60 -0
- package/build/controls/LottieSeekBar.cjs +87 -0
- package/build/controls/LottieSeekBar.js +86 -0
- package/build/controls/LottieSpeedSelect.cjs +51 -0
- package/build/controls/LottieSpeedSelect.js +50 -0
- package/build/controls/LottieStopButton.cjs +29 -0
- package/build/controls/LottieStopButton.js +28 -0
- package/build/controls/controlIcon.cjs +25 -0
- package/build/controls/controlIcon.js +25 -0
- package/build/controls/useFullscreen.cjs +46 -0
- package/build/controls/useFullscreen.js +46 -0
- package/build/controls/useShortcuts.cjs +70 -0
- package/build/controls/useShortcuts.js +70 -0
- package/build/index.cjs +38 -0
- package/build/index.d.cts +20 -0
- package/build/index.d.ts +20 -80
- package/build/index.js +18 -667
- package/build/interactions/LottieInteractions.cjs +42 -0
- package/build/interactions/LottieInteractions.d.cts +37 -0
- package/build/interactions/LottieInteractions.d.ts +37 -0
- package/build/interactions/LottieInteractions.js +42 -0
- package/build/interactions/coverProgress.cjs +55 -0
- package/build/interactions/coverProgress.js +53 -0
- package/build/interactions/lottieInView.cjs +110 -0
- package/build/interactions/lottieInView.d.cts +44 -0
- package/build/interactions/lottieInView.d.ts +44 -0
- package/build/interactions/lottieInView.js +110 -0
- package/build/interactions/lottieScrollScrub.cjs +166 -0
- package/build/interactions/lottieScrollScrub.d.cts +48 -0
- package/build/interactions/lottieScrollScrub.d.ts +48 -0
- package/build/interactions/lottieScrollScrub.js +166 -0
- package/build/interactions/types.d.cts +50 -0
- package/build/interactions/types.d.ts +50 -0
- package/build/interactions/useInteractionsRunner.cjs +154 -0
- package/build/interactions/useInteractionsRunner.js +153 -0
- package/build/interactions/useLottieInteractions.cjs +22 -0
- package/build/interactions/useLottieInteractions.d.cts +19 -0
- package/build/interactions/useLottieInteractions.d.ts +19 -0
- package/build/interactions/useLottieInteractions.js +22 -0
- package/build/overlays/LottieError.cjs +75 -0
- package/build/overlays/LottieError.d.cts +40 -0
- package/build/overlays/LottieError.d.ts +40 -0
- package/build/overlays/LottieError.js +73 -0
- package/build/overlays/LottieLoading.cjs +90 -0
- package/build/overlays/LottieLoading.d.cts +45 -0
- package/build/overlays/LottieLoading.d.ts +45 -0
- package/build/overlays/LottieLoading.js +88 -0
- package/build/overlays/overlayStyles.cjs +33 -0
- package/build/overlays/overlayStyles.js +33 -0
- package/build/utils/SubscriptionManager.cjs +42 -0
- package/build/utils/SubscriptionManager.d.cts +30 -0
- package/build/utils/SubscriptionManager.d.ts +30 -0
- package/build/utils/SubscriptionManager.js +42 -0
- package/build/utils/createLogger.cjs +25 -0
- package/build/utils/createLogger.js +25 -0
- package/build/utils/isSameJson.cjs +37 -0
- package/build/utils/isSameJson.js +37 -0
- package/build/utils/mergeRefs.cjs +37 -0
- package/build/utils/mergeRefs.js +37 -0
- package/build/utils/useStableValue.cjs +26 -0
- package/build/utils/useStableValue.js +26 -0
- package/changes.json +3 -8
- package/package.json +144 -89
- package/LICENSE +0 -46
- package/build/index.es.js +0 -653
- package/build/index.es.js.map +0 -1
- package/build/index.es.min.js +0 -3
- package/build/index.js.map +0 -1
- package/build/index.min.js +0 -3
- package/build/index.umd.js +0 -670
- package/build/index.umd.js.map +0 -1
- 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,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createLottieComponent } from "./createLottieComponent.js";
|
|
3
|
+
import { svgEngine } from "./useLottieSvg.js";
|
|
4
|
+
//#region src/animation/LottieSvg.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Renders an animation using the svg build of the engine.
|
|
7
|
+
*
|
|
8
|
+
* Identical to {@link Lottie} except that `svg` is the only renderer, which the
|
|
9
|
+
* type enforces: the svg build does not contain the other two, and asking it
|
|
10
|
+
* for one throws at runtime while its own declarations claim otherwise.
|
|
11
|
+
*
|
|
12
|
+
* It sits between the other two builds: smaller than the full one because it
|
|
13
|
+
* carries a single renderer, and unlike {@link LottieLight} it keeps the
|
|
14
|
+
* expression engine, so an animation whose properties are driven by
|
|
15
|
+
* expressions plays as designed.
|
|
16
|
+
*/
|
|
17
|
+
const LottieSvg = createLottieComponent(svgEngine);
|
|
18
|
+
//#endregion
|
|
19
|
+
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,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/animation/configureLottie.ts
|
|
3
|
+
/**
|
|
4
|
+
* The engine builds by the name lottie-web gives each, which is the suffix a
|
|
5
|
+
* build's element IDs carry.
|
|
6
|
+
*/
|
|
7
|
+
const LottieEngineName = {
|
|
8
|
+
full: "lottie",
|
|
9
|
+
svg: "lottie_svg",
|
|
10
|
+
light: "lottie_light"
|
|
11
|
+
};
|
|
12
|
+
let idPrefix = "lottie-react";
|
|
13
|
+
let quality;
|
|
14
|
+
const engines = /* @__PURE__ */ new Map();
|
|
15
|
+
function apply(player, name) {
|
|
16
|
+
player.setIDPrefix(`${idPrefix}-${name}`);
|
|
17
|
+
if (quality !== void 0) player.setQuality(quality);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sets what is global to the engine rather than to one animation: the prefix
|
|
21
|
+
* of the element IDs it mints, and how finely it draws curves.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* configureLottie({ idPrefix: "crm", quality: "low" });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Set it once, at startup, before animations load. It takes effect at once on
|
|
28
|
+
* every engine that has loaded an animation, and on the others when they first
|
|
29
|
+
* do, and it reaches what is already on screen: element IDs for everything the
|
|
30
|
+
* engines build from then on, the drawing quality of every animation on them.
|
|
31
|
+
* A field left out keeps its value.
|
|
32
|
+
*/
|
|
33
|
+
function configureLottie(options) {
|
|
34
|
+
if (options.idPrefix !== void 0) idPrefix = options.idPrefix;
|
|
35
|
+
if (options.quality !== void 0) quality = options.quality;
|
|
36
|
+
for (const [player, name] of engines) apply(player, name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Brings one engine up to the current settings and remembers it for later
|
|
40
|
+
* calls to {@link configureLottie}. The load path calls it right before
|
|
41
|
+
* `loadAnimation`.
|
|
42
|
+
*/
|
|
43
|
+
function applyEngineSettings(engine) {
|
|
44
|
+
engines.set(engine.player, engine.name);
|
|
45
|
+
apply(engine.player, engine.name);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.LottieEngineName = LottieEngineName;
|
|
49
|
+
exports.applyEngineSettings = applyEngineSettings;
|
|
50
|
+
exports.configureLottie = configureLottie;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "lottie-web";
|
|
2
|
+
//#region src/animation/configureLottie.d.ts
|
|
3
|
+
/** What {@link configureLottie} can be told. */
|
|
4
|
+
interface ConfigureLottieOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The base of every element ID the engine mints, so that two copies of the
|
|
7
|
+
* library on one page can be told apart. Each engine build appends its own
|
|
8
|
+
* suffix (`-lottie`, `-lottie_svg`, `-lottie_light`), so the three builds
|
|
9
|
+
* never share an ID with each other. `lottie-react` unless set.
|
|
10
|
+
*/
|
|
11
|
+
idPrefix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* How finely curves are drawn: `low`, `medium`, `high`, or a number of
|
|
14
|
+
* segments above 1. Left alone, the engine draws with 150, between `medium`
|
|
15
|
+
* (50) and `high` (200); the named levels trade smoothness for work. Set it
|
|
16
|
+
* once, before animations load: the engine reads it whenever it builds a
|
|
17
|
+
* curve, so a change reaches every animation on the engine, running ones
|
|
18
|
+
* included.
|
|
19
|
+
*/
|
|
20
|
+
quality?: "low" | "medium" | "high" | number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets what is global to the engine rather than to one animation: the prefix
|
|
24
|
+
* of the element IDs it mints, and how finely it draws curves.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* configureLottie({ idPrefix: "crm", quality: "low" });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Set it once, at startup, before animations load. It takes effect at once on
|
|
31
|
+
* every engine that has loaded an animation, and on the others when they first
|
|
32
|
+
* do, and it reaches what is already on screen: element IDs for everything the
|
|
33
|
+
* engines build from then on, the drawing quality of every animation on them.
|
|
34
|
+
* A field left out keeps its value.
|
|
35
|
+
*/
|
|
36
|
+
declare function configureLottie(options: ConfigureLottieOptions): void;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ConfigureLottieOptions, configureLottie };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "lottie-web";
|
|
2
|
+
//#region src/animation/configureLottie.d.ts
|
|
3
|
+
/** What {@link configureLottie} can be told. */
|
|
4
|
+
interface ConfigureLottieOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The base of every element ID the engine mints, so that two copies of the
|
|
7
|
+
* library on one page can be told apart. Each engine build appends its own
|
|
8
|
+
* suffix (`-lottie`, `-lottie_svg`, `-lottie_light`), so the three builds
|
|
9
|
+
* never share an ID with each other. `lottie-react` unless set.
|
|
10
|
+
*/
|
|
11
|
+
idPrefix?: string;
|
|
12
|
+
/**
|
|
13
|
+
* How finely curves are drawn: `low`, `medium`, `high`, or a number of
|
|
14
|
+
* segments above 1. Left alone, the engine draws with 150, between `medium`
|
|
15
|
+
* (50) and `high` (200); the named levels trade smoothness for work. Set it
|
|
16
|
+
* once, before animations load: the engine reads it whenever it builds a
|
|
17
|
+
* curve, so a change reaches every animation on the engine, running ones
|
|
18
|
+
* included.
|
|
19
|
+
*/
|
|
20
|
+
quality?: "low" | "medium" | "high" | number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets what is global to the engine rather than to one animation: the prefix
|
|
24
|
+
* of the element IDs it mints, and how finely it draws curves.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* configureLottie({ idPrefix: "crm", quality: "low" });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Set it once, at startup, before animations load. It takes effect at once on
|
|
31
|
+
* every engine that has loaded an animation, and on the others when they first
|
|
32
|
+
* do, and it reaches what is already on screen: element IDs for everything the
|
|
33
|
+
* engines build from then on, the drawing quality of every animation on them.
|
|
34
|
+
* A field left out keeps its value.
|
|
35
|
+
*/
|
|
36
|
+
declare function configureLottie(options: ConfigureLottieOptions): void;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ConfigureLottieOptions, configureLottie };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
//#region src/animation/configureLottie.ts
|
|
3
|
+
/**
|
|
4
|
+
* The engine builds by the name lottie-web gives each, which is the suffix a
|
|
5
|
+
* build's element IDs carry.
|
|
6
|
+
*/
|
|
7
|
+
const LottieEngineName = {
|
|
8
|
+
full: "lottie",
|
|
9
|
+
svg: "lottie_svg",
|
|
10
|
+
light: "lottie_light"
|
|
11
|
+
};
|
|
12
|
+
let idPrefix = "lottie-react";
|
|
13
|
+
let quality;
|
|
14
|
+
const engines = /* @__PURE__ */ new Map();
|
|
15
|
+
function apply(player, name) {
|
|
16
|
+
player.setIDPrefix(`${idPrefix}-${name}`);
|
|
17
|
+
if (quality !== void 0) player.setQuality(quality);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sets what is global to the engine rather than to one animation: the prefix
|
|
21
|
+
* of the element IDs it mints, and how finely it draws curves.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* configureLottie({ idPrefix: "crm", quality: "low" });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Set it once, at startup, before animations load. It takes effect at once on
|
|
28
|
+
* every engine that has loaded an animation, and on the others when they first
|
|
29
|
+
* do, and it reaches what is already on screen: element IDs for everything the
|
|
30
|
+
* engines build from then on, the drawing quality of every animation on them.
|
|
31
|
+
* A field left out keeps its value.
|
|
32
|
+
*/
|
|
33
|
+
function configureLottie(options) {
|
|
34
|
+
if (options.idPrefix !== void 0) idPrefix = options.idPrefix;
|
|
35
|
+
if (options.quality !== void 0) quality = options.quality;
|
|
36
|
+
for (const [player, name] of engines) apply(player, name);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Brings one engine up to the current settings and remembers it for later
|
|
40
|
+
* calls to {@link configureLottie}. The load path calls it right before
|
|
41
|
+
* `loadAnimation`.
|
|
42
|
+
*/
|
|
43
|
+
function applyEngineSettings(engine) {
|
|
44
|
+
engines.set(engine.player, engine.name);
|
|
45
|
+
apply(engine.player, engine.name);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { LottieEngineName, applyEngineSettings, configureLottie };
|
|
@@ -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 "./configureLottie.cjs";
|
|
2
|
+
import { AnyTag, ElementProps, LottieHandle, LottieRenderer } from "./types.cjs";
|
|
3
|
+
import { UseLottieOptions } from "./useLottieAnimation.cjs";
|
|
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 "./configureLottie.js";
|
|
2
|
+
import { AnyTag, ElementProps, LottieHandle, LottieRenderer } from "./types.js";
|
|
3
|
+
import { UseLottieOptions } from "./useLottieAnimation.js";
|
|
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 };
|