react-text-swap-animation 1.3.0 → 1.5.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
@@ -45,22 +45,19 @@ To control the animation speed and timing, you can pass an object of `animationO
45
45
  randomReverseMax: 6000,
46
46
  loopAnimation: 20000,
47
47
  waitToStart: 5000,
48
+ transitionDuration: 2000,
49
+ timingFunction: 'ease-in-out',
48
50
  }} />
49
51
  ```
50
52
 
51
53
  If you are using an embedded font and need to wait for it to load before animating,
52
- then you should specify the `fontToObserve` object with the font family name and/or other font specifics.
54
+ then you should specify the `fontToObserve` property with the font family name.
53
55
 
54
56
  ```js
55
- <TextSwap fontToObserve={{ family: 'Open Sans' }} />
57
+ <TextSwap fontToObserve="Open Sans" />
56
58
  ```
57
59
  ```js
58
- <TextSwap fontToObserve={{
59
- family: 'Roboto',
60
- weight: 600,
61
- style: 'italic',
62
- stretch: 'expanded',
63
- }} />
60
+ <TextSwap fontToObserve="Roboto" />
64
61
  ```
65
62
 
66
63
  API
@@ -68,44 +65,26 @@ API
68
65
 
69
66
  ### Props
70
67
 
71
- | Prop | Type | Default | Description |
72
- | :----------------- | :----- | :------------------------------------------------| :------------------------------------------------------ |
73
- | `words` | array | `['Text Swap Animation', 'Antitoxin Swamp Tea']` | An array containing exactly 2 words which are an anagram of each other. |
74
- | `animationOptions` | object | `AnimationOptions` | Timing options for when to start, how fast to animate forwards, backwards, and when to loop (optional). |
75
- | `fontToObserve` | object | `FontToObserve` | A description of an embedded font to observe and wait until loaded. If not specified, animation will loaded immediately (optional). |
68
+ | Prop | Type | Default | Description |
69
+ | :----------------- | :----- |:-------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------|
70
+ | `words` | array | `['Text Swap Animation', 'Antitoxin Swamp Tea']` | An array containing exactly 2 words which are an anagram of each other. |
71
+ | `animationOptions` | object | `AnimationOptions` | Timing options for when to start, how fast to animate forwards, backwards, and when to loop (optional). |
72
+ | `fontToObserve` | string | | The name of an embedded font to wait until loaded. If not specified, animation will be loaded immediately (optional). |
76
73
 
77
74
  #### AnimationOptions
78
75
 
79
- | Property | Type | Default | Description |
80
- | :----------------- | :----- | :------ | :-------------------------------------------------------------------------------------------- |
81
- | `randomStartMin` | number | `0` | The minimum amount of time to randomly wait before starting to animate each letter |
82
- | `randomStartMax` | number | `3000` | The maximum amount of time to randomly wait before starting to animate each letter |
83
- | `randomReverseMin` | number | `6000` | The minimum amount of time to randomly wait before starting to animate each letter in reverse |
84
- | `randomReverseMax` | number | `9000` | The maximum amount of time to randomly wait before starting to animate each letter in reverse |
85
- | `loopAnimation` | number | `12000` | The amount of time for each full loop of the animation |
86
- | `waitToStart` | number | `0` | The amount of time to wait before beginning the animation on start up |
87
-
88
- #### FontToObserve
76
+ All time values are in # of milliseconds. The randomness allows a nice jumble effect. You can use any values you want to create some fascinating animations.
89
77
 
90
- This object is passed along to [Font Face Observer](https://github.com/iamskok/use-font-face-observer)
91
-
92
- | Property | Type | Description |
93
- | :---------| :--------------- | :------------------------------------------------------- |
94
- | `family` | string | The font-family: `Roboto`, `Inter`, `Open Sans`, etc |
95
- | `weight` | string or number | The font-weight: `normal`, `bold`, `800`, etc |
96
- | `style` | string | The font-style: `normal`, `italic`, `oblique` |
97
- | `stretch` | string | The font stretch: `normal`, `condensed`, `expanded`, etc |
98
-
99
- Styling
100
- ----
101
-
102
- You can use the CSS transition property to adjust the speed and duration of the animation completely. Can you find a neat transition animation? Please share! :)
103
-
104
- ```css
105
- .text-swap .word .letter {
106
- transition: all, 2s, cubic-bezier(0.1, 0.7, 1.0, 0.1), 2s;
107
- }
108
- ```
78
+ | Property | Type | Default | Description |
79
+ | :------------------- | :----- | :------------ |:---------------------------------------------------------------------------------------------------------------------------------------|
80
+ | `randomStartMin` | number | `0` | The minimum amount of time to randomly wait before starting to animate each letter. |
81
+ | `randomStartMax` | number | `3000` | The maximum amount of time to randomly wait before starting to animate each letter. Should be `>= randomStartMin`. |
82
+ | `randomReverseMin` | number | `6000` | The minimum amount of time to randomly wait before starting to animate each letter in reverse. |
83
+ | `randomReverseMax` | number | `9000` | The maximum amount of time to randomly wait before starting to animate each letter in reverse. Should be `>= randomReverseMin`. |
84
+ | `loopAnimation` | number | `12000` | The amount of time to wait before starting the next full loop of the animation. Should be `>= randomReverseMax + transitionDuration`. |
85
+ | `waitToStart` | number | `0` | The amount of time to wait before beginning the animation on start up the first time. |
86
+ | `transitionDuration` | number | `1000` | How long should it take for a letter to move to its next position. Should be `<= randomReverseMin - randomStartMax`. |
87
+ | `timingFunction` | string | `ease-in-out` | What [timing function](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function) should be used for the animation. |
109
88
 
110
89
  Run Locally
111
90
  ----
@@ -117,10 +96,17 @@ To run demo locally:
117
96
 
118
97
  and a browser will open to the demo.
119
98
 
99
+ If you receive `Invalid hook call` errors because you are linking this module, you may need to point this library's React to your app's installed React so there is only one copy.
100
+
101
+ ```
102
+ npm link ../my-app/node_modules/react
103
+ npm link ../my-app/node_modules/react-dom
104
+ ```
105
+
120
106
  Future Ideas
121
107
  ----
122
108
 
123
- - Supply different animation easing.
109
+ - Supply different animation easing. Done!
124
110
 
125
111
 
126
112
  License
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
2
 
3
- require("core-js/modules/es.symbol.description.js");
3
+ require("core-js/modules/es.iterator.filter.js");
4
+ require("core-js/modules/es.iterator.for-each.js");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.default = TextSwap;
9
+ require("core-js/modules/es.error.cause.js");
10
+ require("core-js/modules/es.array.push.js");
11
+ require("core-js/modules/es.iterator.constructor.js");
12
+ require("core-js/modules/es.iterator.map.js");
8
13
  require("core-js/modules/web.dom-collections.iterator.js");
9
- var _react = _interopRequireWildcard(require("react"));
14
+ var _react = require("react");
10
15
  var _utils = require("../utils");
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
17
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- /**
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
21
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable react/no-array-index-key */ /**
19
22
  * Render and animate from one word to another word and back again.
20
23
  *
21
24
  * @param {[{string}]} words The 2 words to animate between.
@@ -44,7 +47,9 @@ function TextSwap(_ref) {
44
47
  randomReverseMin,
45
48
  randomReverseMax,
46
49
  loopAnimation,
47
- waitToStart
50
+ waitToStart,
51
+ transitionDuration,
52
+ timingFunction
48
53
  } = animationOptions;
49
54
  (0, _react.useEffect)(() => {
50
55
  const swaps = [];
@@ -167,57 +172,61 @@ function TextSwap(_ref) {
167
172
  setTimeout(() => {
168
173
  animateFunc();
169
174
  }, waitToStart);
170
- }, [lettersRefs1, lettersRefs2, loopAnimation, updateAnimation, randomReverseMax, randomReverseMin, randomStartMax, randomStartMin, waitToStart, words]);
171
- return /*#__PURE__*/_react.default.createElement("div", {
172
- className: "text-swap"
173
- }, /*#__PURE__*/_react.default.createElement("div", {
174
- className: "word word-1 hidden"
175
- }, [...words[0]].map((letter, i) => {
176
- // eslint-disable-next-line react/no-array-index-key
177
- return /*#__PURE__*/_react.default.createElement("span", {
178
- ref: lettersRefs1.current[i],
179
- className: "letter",
180
- key: "".concat(i).concat(letter)
181
- }, letter);
182
- })), /*#__PURE__*/_react.default.createElement("div", {
183
- className: "word word-2 hidden"
184
- }, [...words[1]].map((letter, i) => {
185
- // eslint-disable-next-line react/no-array-index-key
186
- return /*#__PURE__*/_react.default.createElement("span", {
187
- ref: lettersRefs2.current[i],
188
- className: "letter",
189
- key: "".concat(i).concat(letter)
190
- }, letter);
191
- })), /*#__PURE__*/_react.default.createElement("div", {
192
- className: "word word-animation"
193
- }, swapAnimations.map(renderedLetter => {
194
- const {
195
- id,
196
- letter,
197
- playing,
198
- disappear,
199
- src,
200
- dest
201
- } = renderedLetter;
202
- let letterStyles;
203
- if (playing) {
204
- const left = "".concat(dest.rect.x, "px");
205
- letterStyles = {
206
- left
207
- };
208
- } else {
209
- const left = "".concat(src.rect.x, "px");
210
- letterStyles = {
211
- left
212
- };
213
- }
214
- if (disappear) {
215
- letterStyles.opacity = 0;
216
- }
217
- return /*#__PURE__*/_react.default.createElement("span", {
218
- key: id,
219
- className: "letter",
220
- style: letterStyles
221
- }, letter);
222
- })));
175
+ }, [lettersRefs1, lettersRefs2, loopAnimation, updateAnimation, randomReverseMax, randomReverseMin, randomStartMax, randomStartMin, waitToStart, transitionDuration, timingFunction, words]);
176
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
177
+ className: "text-swap",
178
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
179
+ className: "word word-1 hidden",
180
+ children: [...words[0]].map((letter, i) => {
181
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
182
+ ref: lettersRefs1.current[i],
183
+ className: "letter",
184
+ children: letter
185
+ }, "".concat(i).concat(letter));
186
+ })
187
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
188
+ className: "word word-2 hidden",
189
+ children: [...words[1]].map((letter, i) => {
190
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
191
+ ref: lettersRefs2.current[i],
192
+ className: "letter",
193
+ children: letter
194
+ }, "".concat(i).concat(letter));
195
+ })
196
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
197
+ className: "word word-animation",
198
+ children: swapAnimations.map(renderedLetter => {
199
+ const {
200
+ id,
201
+ letter,
202
+ playing,
203
+ disappear,
204
+ src,
205
+ dest
206
+ } = renderedLetter;
207
+ let letterStyles = {
208
+ transition: "left ".concat(transitionDuration, "ms ").concat(timingFunction, ", top ").concat(transitionDuration, "ms ").concat(timingFunction)
209
+ };
210
+ if (playing) {
211
+ const left = "".concat(dest.rect.x, "px");
212
+ letterStyles = _objectSpread(_objectSpread({}, letterStyles), {}, {
213
+ left
214
+ });
215
+ } else {
216
+ const left = "".concat(src.rect.x, "px");
217
+ letterStyles = _objectSpread(_objectSpread({}, letterStyles), {}, {
218
+ left
219
+ });
220
+ }
221
+ if (disappear) {
222
+ letterStyles.opacity = 0;
223
+ }
224
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
225
+ className: "letter",
226
+ style: letterStyles,
227
+ children: letter
228
+ }, id);
229
+ })
230
+ })]
231
+ });
223
232
  }
@@ -4,26 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DEFAULT_WORDS = exports.DEFAULT_ANIMATION_OPTIONS = void 0;
7
- const DEFAULT_WORDS = ['Text Swap Animation', 'Antitoxin Swamp Tea'];
7
+ const DEFAULT_WORDS = exports.DEFAULT_WORDS = ['Text Swap Animation', 'Antitoxin Swamp Tea'];
8
8
 
9
9
  /**
10
10
  * @typedef AnimationOptions Timing options for when to start, how fast to animate forwards, backwards, and when to loop.
11
- * @property {number} randomStartMin The minimum amount of time to randomly wait before starting to animate each letter
12
- * @property {number} randomStartMax The maximum amount of time to randomly wait before starting to animate each letter
13
- * @property {number} randomReverseMin The minimum amount of time to randomly wait before starting to animate each letter in reverse
14
- * @property {number} randomReverseMax The maximum amount of time to randomly wait before starting to animate each letter in reverse
15
- * @property {number} loopAnimation The amount of time for each full loop of the animation
16
- * @property {number} waitToStart The amount of time to wait before beginning the animation on start up
11
+ * @property {number} randomStartMin The minimum amount of time to randomly wait before starting to animate each letter.
12
+ * @property {number} randomStartMax The maximum amount of time to randomly wait before starting to animate each letter. Should be `>= randomStartMin`.
13
+ * @property {number} randomReverseMin The minimum amount of time to randomly wait before starting to animate each letter in reverse.
14
+ * @property {number} randomReverseMax The maximum amount of time to randomly wait before starting to animate each letter in reverse. Should be `>= randomReverseMin`.
15
+ * @property {number} loopAnimation The amount of time to wait before starting the next full loop of the animation. Should be `>= randomReverseMax + transitionDuration`.
16
+ * @property {number} waitToStart The amount of time to wait before beginning the animation on start up the first time.
17
+ * @property {number} transitionDuration How long should it take for a letter to move to its next position. Should be `<= randomReverseMin - randomStartMax`.
18
+ * @property {string} timingFunction What [timing function](https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function) should be used for the animation.
17
19
  */
18
20
 
19
21
  /** @type AnimationOptions */
20
- exports.DEFAULT_WORDS = DEFAULT_WORDS;
21
- const DEFAULT_ANIMATION_OPTIONS = {
22
- randomStartMin: 500,
23
- randomStartMax: 500,
24
- randomReverseMin: 8000,
25
- randomReverseMax: 8000,
22
+ const DEFAULT_ANIMATION_OPTIONS = exports.DEFAULT_ANIMATION_OPTIONS = {
23
+ randomStartMin: 0,
24
+ randomStartMax: 3000,
25
+ randomReverseMin: 6000,
26
+ randomReverseMax: 9000,
26
27
  loopAnimation: 12000,
27
- waitToStart: 0
28
- };
29
- exports.DEFAULT_ANIMATION_OPTIONS = DEFAULT_ANIMATION_OPTIONS;
28
+ waitToStart: 0,
29
+ transitionDuration: 1000,
30
+ timingFunction: 'ease-in-out'
31
+ };
@@ -1,32 +1,34 @@
1
- .text-swap {
2
- color: #fff;
3
- flex: 0 0 auto;
4
- align-self: center;
5
- width: 100%;
6
- height: 100%;
7
- margin: 0 auto;
8
- text-align: left;
9
- text-transform: uppercase;
10
- display: flex;
11
- flex-direction: column;
12
- padding: 0;
13
- position: relative; }
14
-
15
- .text-swap .word {
16
- position: relative; }
17
-
18
- .text-swap .word.hidden {
19
- position: absolute;
20
- visibility: hidden;
21
- z-index: -9000; }
22
-
23
- .text-swap .word .letter {
24
- white-space: pre;
25
- z-index: 10;
26
- display: inline-block; }
27
-
28
- .text-swap .word-animation .letter {
29
- z-index: 10;
30
- position: absolute;
31
- /*transition: all, 2s, cubic-bezier(0.1, 0.7, 1.0, 0.1), 2s;*/
32
- transition: all, 2s, ease-in-out, 2s; }
1
+ .text-swap {
2
+ color: #fff;
3
+ flex: 0 0 auto;
4
+ align-self: center;
5
+ width: 100%;
6
+ height: 100%;
7
+ margin: 0 auto;
8
+ text-align: left;
9
+ text-transform: uppercase;
10
+ display: flex;
11
+ flex-direction: column;
12
+ padding: 0;
13
+ position: relative;
14
+ }
15
+ .text-swap .word {
16
+ position: relative;
17
+ }
18
+ .text-swap .word.hidden {
19
+ position: absolute;
20
+ visibility: hidden;
21
+ z-index: -9000;
22
+ }
23
+ .text-swap .word .letter {
24
+ white-space: pre;
25
+ z-index: 10;
26
+ display: inline-block;
27
+ }
28
+ .text-swap .word-animation .letter {
29
+ z-index: 10;
30
+ position: absolute;
31
+ transition: left 2s ease-in-out, top 2s ease-in-out;
32
+ }
33
+
34
+ /*# sourceMappingURL=index.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sourceRoot":"","sources":["index.scss"],"names":[],"mappings":"AAAA;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACI;;AAEA;EACI;EACA;EACA;;AAGJ;EACI;EACA;EACA;;AAKJ;EACI;EACA;EACA","file":"index.css"}
@@ -1,34 +1,29 @@
1
1
  "use strict";
2
2
 
3
+ require("core-js/modules/es.array.push.js");
4
+ require("core-js/modules/es.iterator.constructor.js");
5
+ require("core-js/modules/es.iterator.filter.js");
6
+ require("core-js/modules/es.iterator.for-each.js");
3
7
  Object.defineProperty(exports, "__esModule", {
4
8
  value: true
5
9
  });
6
10
  exports.default = Loader;
7
- require("core-js/modules/es.symbol.description.js");
8
- var _react = _interopRequireDefault(require("react"));
9
- var _useFontFaceObserver = _interopRequireDefault(require("use-font-face-observer"));
11
+ require("core-js/modules/es.error.cause.js");
12
+ var _useFonts = _interopRequireDefault(require("./useFonts"));
10
13
  var _TextSwap = _interopRequireDefault(require("./TextSwap"));
11
14
  var _constants = require("./constants");
12
15
  require("./index.css");
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
19
- /**
20
- * @typedef FontToObserve A description of an embedded font to observe and wait until loaded.
21
- * @property {string} [family] The font-family: Roboto, Inter, Open Sans, etc
22
- * @property {string|number} [weight] The font-weight: normal, bold, 800, etc
23
- * @property {string} [style] The font-style: normal, italic, oblique
24
- * @property {string} [stretch] The font stretch: normal, condensed, expanded, etc
25
- */
26
-
27
- /**
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
22
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
28
23
  * Render and animate from one word to another word and back again.
29
24
  * @param {[string]} [words] The 2 words to animate between.
30
25
  * @param {AnimationOptions} [animationOptions] Timing options for when to start, how fast to animate forwards, backwards, and when to loop.
31
- * @param {FontToObserve} [fontToObserve] A description of an embedded font to observe and wait until loaded.
26
+ * @param {string} [fontToObserve] A description of an embedded font to observe and wait until loaded.
32
27
  * @returns {JSX.Element|null}
33
28
  */
34
29
  function Loader(_ref) {
@@ -37,14 +32,14 @@ function Loader(_ref) {
37
32
  animationOptions = {},
38
33
  fontToObserve
39
34
  } = _ref;
35
+ const isFontLoaded = (0, _useFonts.default)(fontToObserve);
40
36
  const animOptions = _objectSpread(_objectSpread({}, _constants.DEFAULT_ANIMATION_OPTIONS), animationOptions);
41
- const isFontLoaded = (0, _useFontFaceObserver.default)(fontToObserve ? [fontToObserve] : []);
42
37
  let word1 = words[0];
43
38
  let word2 = words[1];
44
39
  const maxLength = Math.max(word1.length, word2.length);
45
40
  word1 = word1.padEnd(maxLength, ' ');
46
41
  word2 = word2.padEnd(maxLength, ' ');
47
- return isFontLoaded ? /*#__PURE__*/_react.default.createElement(_TextSwap.default, {
42
+ return isFontLoaded ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextSwap.default, {
48
43
  words: [word1, word2],
49
44
  animationOptions: animOptions
50
45
  }) : null;
@@ -32,8 +32,7 @@
32
32
  .letter {
33
33
  z-index: 10;
34
34
  position: absolute;
35
- /*transition: all, 2s, cubic-bezier(0.1, 0.7, 1.0, 0.1), 2s;*/
36
- transition: all, 2s, ease-in-out, 2s;
35
+ transition: left 2s ease-in-out, top 2s ease-in-out;
37
36
  }
38
37
  }
39
38
  }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useFonts;
7
+ require("core-js/modules/es.promise.js");
8
+ require("core-js/modules/web.dom-collections.iterator.js");
9
+ var _react = require("react");
10
+ function useFonts() {
11
+ for (var _len = arguments.length, fontNames = new Array(_len), _key = 0; _key < _len; _key++) {
12
+ fontNames[_key] = arguments[_key];
13
+ }
14
+ const [isLoaded, setIsLoaded] = (0, _react.useState)(false);
15
+ (0, _react.useEffect)(() => {
16
+ // Inspired by https://stackoverflow.com/a/60138011
17
+ if (!document || !document.fonts) {
18
+ // eslint-disable-next-line no-console
19
+ console.warn('Browser does not support document.fonts API');
20
+ setIsLoaded(true);
21
+ return;
22
+ }
23
+ Promise.all(fontNames.map(fontName => document.fonts.load("16px \"".concat(fontName, "\"")))).then(() => {
24
+ setIsLoaded(true);
25
+ });
26
+ }, [fontNames]);
27
+ return isLoaded;
28
+ }
29
+ ;
package/dist/index.js CHANGED
@@ -5,6 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _index = _interopRequireDefault(require("./components/index"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- var _default = _index.default;
10
- exports.default = _default;
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ var _default = exports.default = _index.default;
package/dist/utils.js CHANGED
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.randomMinMax = randomMinMax;
7
7
  exports.uuidv4 = uuidv4;
8
8
  require("core-js/modules/es.regexp.exec.js");
9
- require("core-js/modules/es.string.replace.js");
10
9
  require("core-js/modules/es.regexp.to-string.js");
10
+ require("core-js/modules/es.string.replace.js");
11
11
  /**
12
12
  * Get a random number between `min` and `max`
13
13
  * @param {number} min The minimum number you want to include in the random output
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "react-text-swap-animation",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "author": "Scott Canoni",
5
5
  "description": "A React component to use CSS animations to swap letters in 2 words. The text is animated in position after calculating initial and final positions of each letter. Words which are anagrams will animate well, but you can use any words or phrases.",
6
6
  "license": "WTFPL",
7
7
  "main": "dist/index.js",
8
+ "files": [
9
+ "dist"
10
+ ],
8
11
  "private": false,
9
12
  "scripts": {
10
- "analyze": "source-map-explorer 'build/static/js/*.js'",
11
- "start-js": "react-scripts start",
12
- "start": "npm-run-all -p watch-css start-js",
13
- "build": "del /Q dist\\* && NODE_ENV=production babel src/lib --out-dir dist --copy-files",
14
- "build-fresh": "NODE_ENV=production babel src/lib --out-dir dist --copy-files",
15
- "build-css": "sass src/:src/",
16
- "watch-css": "sass --watch src/:src/",
17
- "eject": "react-scripts eject"
13
+ "start": "vite",
14
+ "build-demo": "vite build --outDir demo-build",
15
+ "preview": "vite preview --outDir demo-build",
16
+ "build": "rimraf dist && cross-env NODE_ENV=production babel src/lib --out-dir dist --copy-files",
17
+ "build-css": "sass src/:src/"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -29,27 +29,30 @@
29
29
  "rearrange"
30
30
  ],
31
31
  "dependencies": {
32
- "core-js": "^3.18.3",
33
- "use-font-face-observer": "^1.1.39"
32
+ "core-js": "^3.49.0"
34
33
  },
35
34
  "peerDependencies": {
36
- "react": "^17.0.2 || ^18.2.0",
37
- "react-dom": "^17.0.2 || ^18.2.0"
35
+ "react": "^17.0.0 || ^18.0.0 || >=19.0.0",
36
+ "react-dom": "^17.0.0 || ^18.0.0 || >=19.0.0"
38
37
  },
39
38
  "devDependencies": {
40
- "@babel/cli": "^7.20.7",
41
- "@babel/core": "^7.20.12",
42
- "@babel/polyfill": "^7.12.1",
43
- "@babel/preset-env": "^7.15.6",
44
- "@babel/preset-react": "^7.14.5",
45
- "npm-run-all": "^4.1.5",
46
- "react": "^17.0.2",
47
- "react-dom": "^17.0.2",
48
- "react-scripts": "4.0.3",
49
- "sass": "^1.57.1"
50
- },
51
- "eslintConfig": {
52
- "extends": "react-app"
39
+ "@babel/cli": "^7.28.6",
40
+ "@babel/core": "^7.29.0",
41
+ "@babel/eslint-parser": "^7.28.6",
42
+ "@babel/preset-env": "^7.29.2",
43
+ "@babel/preset-react": "^7.28.5",
44
+ "@vitejs/plugin-react": "^6.0.1",
45
+ "cross-env": "^10.1.0",
46
+ "eslint": "^8.57.1",
47
+ "eslint-plugin-import": "^2.32.0",
48
+ "eslint-plugin-jsx-a11y": "^6.10.2",
49
+ "eslint-plugin-react": "^7.37.5",
50
+ "eslint-plugin-react-hooks": "^4.6.2",
51
+ "react": "^19.2.4",
52
+ "react-dom": "^19.2.4",
53
+ "rimraf": "^6.1.3",
54
+ "sass": "^1.98.0",
55
+ "vite": "^8.0.3"
53
56
  },
54
57
  "browserslist": {
55
58
  "production": [