@matteodicristofalo/text-animations 1.0.5 → 1.1.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 CHANGED
@@ -70,8 +70,10 @@ You can decide how to split the text between one of this options:
70
70
 
71
71
  You can also configure the reveal animation by specifying:
72
72
 
73
- - duration
74
- - stagger
73
+ - duration (number in seconds)
74
+ - stagger (number in seconds)
75
+ - threshold (number between 0 and 1)
76
+ - once (boolean)
75
77
 
76
78
  ```js
77
79
  "use client";
@@ -84,6 +86,8 @@ export function MyComponent() {
84
86
  () => ({
85
87
  duration: 1,
86
88
  stagger: 0.5,
89
+ threshold: 0.75,
90
+ once: false,
87
91
  }),
88
92
  []
89
93
  );
@@ -7,5 +7,7 @@ type SplitType = "sentence" | "word" | "char";
7
7
  type RevealOptions = {
8
8
  duration: number;
9
9
  stagger: number;
10
+ threshold: number;
11
+ once: boolean;
10
12
  };
11
13
  export {};
@@ -1,11 +1,9 @@
1
+ import React from "react";
1
2
  import type { StoryObj } from "@storybook/react";
2
3
  import { SplitTextReveal } from "./split-text-reveal";
3
4
  declare const meta: {
4
5
  title: string;
5
6
  component: typeof SplitTextReveal;
6
- parameters: {
7
- layout: string;
8
- };
9
7
  argTypes: {
10
8
  text: {
11
9
  control: "text";
@@ -20,7 +18,18 @@ declare const meta: {
20
18
  };
21
19
  };
22
20
  };
21
+ args: {
22
+ text: string;
23
+ splitType: "char";
24
+ };
25
+ render: (args: import("./split-test-reveal.types").SplitTextRevealProps) => React.JSX.Element;
23
26
  };
24
27
  export default meta;
25
28
  type Story = StoryObj<typeof meta>;
26
29
  export declare const Default: Story;
30
+ export declare const SplitByWord: Story;
31
+ export declare const SplitBySentence: Story;
32
+ export declare const Duration: Story;
33
+ export declare const Stagger: Story;
34
+ export declare const Threshold: Story;
35
+ export declare const NotOnce: Story;
@@ -1,11 +1,9 @@
1
+ import React from "react";
1
2
  import type { StoryObj } from "@storybook/react";
2
3
  import { SplitTextRotate } from "./split-text-rotate";
3
4
  declare const meta: {
4
5
  title: string;
5
6
  component: typeof SplitTextRotate;
6
- parameters: {
7
- layout: string;
8
- };
9
7
  argTypes: {
10
8
  text: {
11
9
  control: "text";
@@ -16,7 +14,13 @@ declare const meta: {
16
14
  };
17
15
  };
18
16
  };
17
+ args: {
18
+ text: string;
19
+ };
20
+ render: (args: import("./split-text-rotate.types").SplitTextRotateProps) => React.JSX.Element;
19
21
  };
20
22
  export default meta;
21
23
  type Story = StoryObj<typeof meta>;
22
24
  export declare const Default: Story;
25
+ export declare const Duration: Story;
26
+ export declare const Stagger: Story;
package/dist/index.js CHANGED
@@ -4,6 +4,9 @@ import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react'
4
4
  function round(num, digits) {
5
5
  return parseFloat(num.toFixed(digits));
6
6
  }
7
+ function clamp(n, min, max) {
8
+ return Math.min(Math.max(min, n), max);
9
+ }
7
10
 
8
11
  function sentences(text) {
9
12
  return segment(text, "sentence");
@@ -81,12 +84,25 @@ var styles$1 = {"text":"split-text-reveal-module_text__-9O5o","is-hidden":"split
81
84
 
82
85
  var DEFAULT_DURATION$1 = 0.5;
83
86
  var DEFAULT_STAGGER$1 = 0.01;
87
+ var MIN_THRESHOLD = 0;
88
+ var MAX_THRESHOLD = 1;
89
+ var DEFAULT_THRESHOLD = 0.25;
84
90
  function SplitTextReveal(_a) {
85
91
  var _b;
86
92
  var text = _a.text, _c = _a.splitType, splitType = _c === void 0 ? "char" : _c, revealOptions = _a.revealOptions;
87
- var _d = useState(false), hasBeenMounted = _d[0], setHasBeenMounted = _d[1];
88
93
  var ref = useRef(null);
89
- var memoizedOptions = useMemo(function () { return ({ once: true, threshold: 0.1 }); }, []);
94
+ var _d = useState(false), hasBeenMounted = _d[0], setHasBeenMounted = _d[1];
95
+ var memoizedOptions = useMemo(function () {
96
+ var _a;
97
+ var once = (_a = revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.once) !== null && _a !== void 0 ? _a : true;
98
+ var threshold = (revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.threshold)
99
+ ? clamp(revealOptions.threshold, MIN_THRESHOLD, MAX_THRESHOLD)
100
+ : DEFAULT_THRESHOLD;
101
+ return {
102
+ once: once,
103
+ threshold: threshold,
104
+ };
105
+ }, [revealOptions]);
90
106
  var isInView = useIntersectionObserver(ref, memoizedOptions);
91
107
  var transitionDuration = (revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.duration) || DEFAULT_DURATION$1;
92
108
  var transitionStagger = (revealOptions === null || revealOptions === void 0 ? void 0 : revealOptions.stagger) || DEFAULT_STAGGER$1;
@@ -1 +1,2 @@
1
1
  export declare function round(num: number, digits: number): number;
2
+ export declare function clamp(n: number, min: number, max: number): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matteodicristofalo/text-animations",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "React library to animate text",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && rollup -c",