solid-drift 0.10.0 → 0.11.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/README.md +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/typography.d.ts +39 -0
- package/dist/typography.js +45 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -776,6 +776,25 @@ createTextWave(() => headline, {
|
|
|
776
776
|
|
|
777
777
|
Options: `amplitude`, `wavelength` (characters per wave), `period`, `tilt` (default true), `progress`. Returns `{ stop }`. Under reduced motion the text sits still.
|
|
778
778
|
|
|
779
|
+
### `createCountUp(source, options?)`
|
|
780
|
+
|
|
781
|
+
A signal that counts toward a source number with an eased tween, rendering as a formatted string: dashboard stats, prices, scores. When the source changes mid-count the tween retargets from the current displayed value, with no snapping.
|
|
782
|
+
|
|
783
|
+
```tsx
|
|
784
|
+
import { createCountUp } from "solid-drift"
|
|
785
|
+
|
|
786
|
+
const [revenue, setRevenue] = createSignal(0)
|
|
787
|
+
const display = createCountUp(revenue, {
|
|
788
|
+
decimals: 2,
|
|
789
|
+
prefix: "$",
|
|
790
|
+
separator: ",",
|
|
791
|
+
})
|
|
792
|
+
<div>{display()}</div> // "$1,234.50" gliding up from "$0.00"
|
|
793
|
+
setRevenue(1234.5)
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
Options: `decimals` (default 0), `duration` (ms, default 1000), `easing` (default `"easeOutExpo"`), `prefix` (default `""`), `suffix` (default `""`), `separator` (thousands separator, default `""`). Returns an accessor of the formatted string. SSR-safe: renders the formatted source value. Under reduced motion the text jumps straight to each new value.
|
|
797
|
+
|
|
779
798
|
### `createKineticType(ref, options?)`
|
|
780
799
|
|
|
781
800
|
Kinetic typography: each character (or word) flies in with position, blur, scale, and opacity, staggered for that showreel title feel. One master clock drives every unit, so a 40-character headline costs a single rAF task.
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export { createTimeline, type TimelineStep, type TimelineStatus, type TimelineCo
|
|
|
22
22
|
export { animateFlip, type FlipOptions, createSharedLayout, type SharedLayoutOptions, type SharedLayoutResult, } from "./flip.js";
|
|
23
23
|
export { createSquashStretch, type SquashStretchOptions, type SquashStretchResult, createFollowThrough, type FollowThroughOptions, createAnticipation, type AnticipationOptions, createWobble, type WobbleOptions, type WobbleResult, } from "./cartoon.js";
|
|
24
24
|
export { createGravity, type GravityOptions, type GravityResult, createPendulum, type PendulumOptions, type PendulumResult, createFling, type FlingOptions, type FlingResult, } from "./physics.js";
|
|
25
|
-
export { createFontSwap, type FontSwapOptions, type FontSwapResult, createTyping, type TypingOptions, type TypingResult, createTextPhysics, type TextPhysicsOptions, type TextPhysicsResult, createTextTunnel, type TextTunnelOptions, type TextTunnelResult, createTextCutout, type TextCutoutOptions, createTextGradient, type TextGradientOptions, createTextScramble, type TextScrambleOptions, type TextScrambleResult, createTextWave, type TextWaveOptions, } from "./typography.js";
|
|
25
|
+
export { createFontSwap, type FontSwapOptions, type FontSwapResult, createTyping, type TypingOptions, type TypingResult, createTextPhysics, type TextPhysicsOptions, type TextPhysicsResult, createTextTunnel, type TextTunnelOptions, type TextTunnelResult, createTextCutout, type TextCutoutOptions, createTextGradient, type TextGradientOptions, createTextScramble, type TextScrambleOptions, type TextScrambleResult, createTextWave, type TextWaveOptions, createCountUp, type CountUpOptions, } from "./typography.js";
|
|
26
26
|
export { easings, cubicBezier, linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeOutExpo, easeOutBack, easeInBack, easeInOutBack, easeOutElastic, easeOutBounce, resolveEasing, type Easing, type EasingName, } from "./easing.js";
|
|
27
27
|
export { createKineticType, createScenePlayer, createShowreel, createCamera, createColorShift, createTransition, createBeat, createBeatCuts, } from "./motion.js";
|
|
28
28
|
export type { KineticTypeFrom, KineticTypeOptions, KineticTypeStatus, KineticTypeControls, MotionScene, ScenePlayerStatus, ScenePlayerControls, ShowreelScene, ShowreelSceneKind, CameraKeyframe, CameraOptions, ColorShiftOptions, ColorShiftStatus, ColorShiftControls, TransitionType, TransitionDirection, TransitionOptions, TransitionLayerStyle, TransitionStatus, TransitionControls, BeatOptions, BeatStatus, BeatControls, BeatCutOptions, } from "./motion.js";
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ export { createTimeline, } from "./timeline.js";
|
|
|
22
22
|
export { animateFlip, createSharedLayout, } from "./flip.js";
|
|
23
23
|
export { createSquashStretch, createFollowThrough, createAnticipation, createWobble, } from "./cartoon.js";
|
|
24
24
|
export { createGravity, createPendulum, createFling, } from "./physics.js";
|
|
25
|
-
export { createFontSwap, createTyping, createTextPhysics, createTextTunnel, createTextCutout, createTextGradient, createTextScramble, createTextWave, } from "./typography.js";
|
|
25
|
+
export { createFontSwap, createTyping, createTextPhysics, createTextTunnel, createTextCutout, createTextGradient, createTextScramble, createTextWave, createCountUp, } from "./typography.js";
|
|
26
26
|
export { easings, cubicBezier, linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeOutExpo, easeOutBack, easeInBack, easeInOutBack, easeOutElastic, easeOutBounce, resolveEasing, } from "./easing.js";
|
|
27
27
|
export { createKineticType, createScenePlayer, createShowreel, createCamera, createColorShift, createTransition, createBeat, createBeatCuts, } from "./motion.js";
|
|
28
28
|
export { createDrag, } from "./gesture.js";
|
package/dist/typography.d.ts
CHANGED
|
@@ -238,4 +238,43 @@ export interface TextWaveOptions {
|
|
|
238
238
|
export declare function createTextWave(ref: MaybeElement, options?: TextWaveOptions): {
|
|
239
239
|
stop: () => void;
|
|
240
240
|
};
|
|
241
|
+
export interface CountUpOptions {
|
|
242
|
+
/** Decimal places in the output. Default 0. */
|
|
243
|
+
decimals?: number;
|
|
244
|
+
/** Tween duration in milliseconds when the source changes. Default 1000. */
|
|
245
|
+
duration?: number;
|
|
246
|
+
/** Easing for the count. Default "easeOutExpo". */
|
|
247
|
+
easing?: Easing | EasingName;
|
|
248
|
+
/** String placed before the number, e.g. "$". Default "". */
|
|
249
|
+
prefix?: string;
|
|
250
|
+
/** String placed after the number, e.g. "%". Default "". */
|
|
251
|
+
suffix?: string;
|
|
252
|
+
/** Thousands separator, e.g. ",". Default "" (no grouping). */
|
|
253
|
+
separator?: string;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* A signal that counts toward a source number with an eased tween,
|
|
257
|
+
* rendering as a formatted string: dashboard stats, prices, scores.
|
|
258
|
+
*
|
|
259
|
+
* When the source changes mid-count the tween retargets from the
|
|
260
|
+
* current displayed value, with no snapping. Formatting (decimals,
|
|
261
|
+
* prefix, suffix, thousands separator) applies to every frame.
|
|
262
|
+
*
|
|
263
|
+
* SSR-safe: renders the formatted source value. Under reduced motion
|
|
264
|
+
* the text jumps straight to each new value with no tween.
|
|
265
|
+
*
|
|
266
|
+
* ```tsx
|
|
267
|
+
* import { createCountUp } from "solid-drift"
|
|
268
|
+
*
|
|
269
|
+
* const [revenue, setRevenue] = createSignal(0)
|
|
270
|
+
* const display = createCountUp(revenue, {
|
|
271
|
+
* decimals: 2,
|
|
272
|
+
* prefix: "$",
|
|
273
|
+
* separator: ",",
|
|
274
|
+
* })
|
|
275
|
+
* <div>{display()}</div> // "$1,234.50" gliding up from "$0.00"
|
|
276
|
+
* setRevenue(1234.5)
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export declare function createCountUp(source: Accessor<number>, options?: CountUpOptions): Accessor<string>;
|
|
241
280
|
export {};
|
package/dist/typography.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createEffect, createSignal, onCleanup, untrack, } from "solid-js";
|
|
2
2
|
import { animate } from "./animate.js";
|
|
3
|
+
import { createTween } from "./tween.js";
|
|
3
4
|
import { resolveEasing } from "./easing.js";
|
|
4
5
|
import { now, schedule } from "./engine.js";
|
|
5
6
|
import { prefersReducedMotion } from "./reduced-motion.js";
|
|
@@ -810,3 +811,47 @@ export function createTextWave(ref, options = {}) {
|
|
|
810
811
|
},
|
|
811
812
|
};
|
|
812
813
|
}
|
|
814
|
+
function groupInteger(int, separator) {
|
|
815
|
+
if (!separator)
|
|
816
|
+
return int;
|
|
817
|
+
const negative = int.startsWith("-");
|
|
818
|
+
const digits = negative ? int.slice(1) : int;
|
|
819
|
+
const grouped = digits.replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
820
|
+
return (negative ? "-" : "") + grouped;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* A signal that counts toward a source number with an eased tween,
|
|
824
|
+
* rendering as a formatted string: dashboard stats, prices, scores.
|
|
825
|
+
*
|
|
826
|
+
* When the source changes mid-count the tween retargets from the
|
|
827
|
+
* current displayed value, with no snapping. Formatting (decimals,
|
|
828
|
+
* prefix, suffix, thousands separator) applies to every frame.
|
|
829
|
+
*
|
|
830
|
+
* SSR-safe: renders the formatted source value. Under reduced motion
|
|
831
|
+
* the text jumps straight to each new value with no tween.
|
|
832
|
+
*
|
|
833
|
+
* ```tsx
|
|
834
|
+
* import { createCountUp } from "solid-drift"
|
|
835
|
+
*
|
|
836
|
+
* const [revenue, setRevenue] = createSignal(0)
|
|
837
|
+
* const display = createCountUp(revenue, {
|
|
838
|
+
* decimals: 2,
|
|
839
|
+
* prefix: "$",
|
|
840
|
+
* separator: ",",
|
|
841
|
+
* })
|
|
842
|
+
* <div>{display()}</div> // "$1,234.50" gliding up from "$0.00"
|
|
843
|
+
* setRevenue(1234.5)
|
|
844
|
+
* ```
|
|
845
|
+
*/
|
|
846
|
+
export function createCountUp(source, options = {}) {
|
|
847
|
+
const { decimals = 0, duration = 1000, easing = "easeOutExpo", prefix = "", suffix = "", separator = "", } = options;
|
|
848
|
+
const tweened = createTween(source, { duration, easing });
|
|
849
|
+
const format = (value) => {
|
|
850
|
+
const fixed = value.toFixed(decimals);
|
|
851
|
+
const dot = fixed.indexOf(".");
|
|
852
|
+
const head = dot === -1 ? fixed : fixed.slice(0, dot);
|
|
853
|
+
const tail = dot === -1 ? "" : fixed.slice(dot);
|
|
854
|
+
return prefix + groupInteger(head, separator) + tail + suffix;
|
|
855
|
+
};
|
|
856
|
+
return () => format(tweened());
|
|
857
|
+
}
|
package/package.json
CHANGED