fetta 1.5.1 → 1.5.3
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 +4 -4
- package/dist/{chunk-UPF3IYHC.js → chunk-OUXSJF3P.js} +68 -75
- package/dist/chunk-PA22PLRB.js +73 -0
- package/dist/helpers.js +5 -9
- package/dist/index.js +1 -2
- package/dist/motion.js +216 -340
- package/dist/react.js +45 -94
- package/package.json +1 -1
- package/dist/chunk-FP4I6OR2.js +0 -43
- package/dist/chunk-ORMEWXMH.js +0 -33
package/dist/react.js
CHANGED
|
@@ -1,47 +1,28 @@
|
|
|
1
|
-
import { waitForFontsReady, reapplyInitialStyles, reapplyInitialClasses } from './chunk-
|
|
2
|
-
import { splitText, normalizeToPromise } from './chunk-
|
|
3
|
-
import { __objRest, __spreadProps, __spreadValues } from './chunk-ORMEWXMH.js';
|
|
1
|
+
import { waitForFontsReady, createViewportObserver, reapplyInitialStyles, reapplyInitialClasses } from './chunk-PA22PLRB.js';
|
|
2
|
+
import { splitText, normalizeToPromise } from './chunk-OUXSJF3P.js';
|
|
4
3
|
import { forwardRef, useRef, useCallback, useState, useLayoutEffect, useEffect, isValidElement, createElement } from 'react';
|
|
5
4
|
|
|
6
5
|
var SplitText = forwardRef(
|
|
7
|
-
function SplitText2(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"children",
|
|
28
|
-
"as",
|
|
29
|
-
"className",
|
|
30
|
-
"style",
|
|
31
|
-
"onSplit",
|
|
32
|
-
"onResplit",
|
|
33
|
-
"options",
|
|
34
|
-
"autoSplit",
|
|
35
|
-
"revertOnComplete",
|
|
36
|
-
"viewport",
|
|
37
|
-
"onViewportEnter",
|
|
38
|
-
"onViewportLeave",
|
|
39
|
-
"onRevert",
|
|
40
|
-
"initialStyles",
|
|
41
|
-
"initialClasses",
|
|
42
|
-
"resetOnViewportLeave",
|
|
43
|
-
"waitForFonts"
|
|
44
|
-
]);
|
|
6
|
+
function SplitText2({
|
|
7
|
+
children,
|
|
8
|
+
as: Component = "div",
|
|
9
|
+
className,
|
|
10
|
+
style: userStyle,
|
|
11
|
+
onSplit,
|
|
12
|
+
onResplit,
|
|
13
|
+
options,
|
|
14
|
+
autoSplit = false,
|
|
15
|
+
revertOnComplete = false,
|
|
16
|
+
viewport,
|
|
17
|
+
onViewportEnter,
|
|
18
|
+
onViewportLeave,
|
|
19
|
+
onRevert,
|
|
20
|
+
initialStyles,
|
|
21
|
+
initialClasses,
|
|
22
|
+
resetOnViewportLeave = false,
|
|
23
|
+
waitForFonts = true,
|
|
24
|
+
...wrapperProps
|
|
25
|
+
}, forwardedRef) {
|
|
45
26
|
const containerRef = useRef(null);
|
|
46
27
|
const mergedRef = useCallback(
|
|
47
28
|
(node) => {
|
|
@@ -88,8 +69,7 @@ var SplitText = forwardRef(
|
|
|
88
69
|
const observerRef = useRef(null);
|
|
89
70
|
const hasTriggeredOnceRef = useRef(false);
|
|
90
71
|
useLayoutEffect(() => {
|
|
91
|
-
|
|
92
|
-
const element = (_a2 = containerRef.current) == null ? void 0 : _a2.firstElementChild;
|
|
72
|
+
const element = containerRef.current?.firstElementChild;
|
|
93
73
|
setChildElement(element instanceof HTMLElement ? element : null);
|
|
94
74
|
}, [children]);
|
|
95
75
|
useEffect(() => {
|
|
@@ -101,22 +81,21 @@ var SplitText = forwardRef(
|
|
|
101
81
|
if (!containerRef.current) return;
|
|
102
82
|
let coreRevert = null;
|
|
103
83
|
const revert = () => {
|
|
104
|
-
var _a2;
|
|
105
84
|
if (hasRevertedRef.current) return;
|
|
106
85
|
hasRevertedRef.current = true;
|
|
107
86
|
try {
|
|
108
|
-
|
|
87
|
+
onRevertRef.current?.();
|
|
109
88
|
} finally {
|
|
110
|
-
coreRevert
|
|
89
|
+
coreRevert?.();
|
|
111
90
|
}
|
|
112
91
|
};
|
|
113
|
-
const result = splitText(childElement,
|
|
92
|
+
const result = splitText(childElement, {
|
|
93
|
+
...optionsRef.current,
|
|
114
94
|
autoSplit,
|
|
115
95
|
revertOnComplete: revertOnCompleteRef.current,
|
|
116
96
|
initialStyles: initialStylesRef.current,
|
|
117
97
|
initialClasses: initialClassesRef.current,
|
|
118
98
|
onResplit: (resizeResult) => {
|
|
119
|
-
var _a2;
|
|
120
99
|
const newSplitTextElements = {
|
|
121
100
|
chars: resizeResult.chars,
|
|
122
101
|
words: resizeResult.words,
|
|
@@ -124,9 +103,9 @@ var SplitText = forwardRef(
|
|
|
124
103
|
revert
|
|
125
104
|
};
|
|
126
105
|
splitResultRef.current = newSplitTextElements;
|
|
127
|
-
|
|
106
|
+
onResplitRef.current?.(newSplitTextElements);
|
|
128
107
|
}
|
|
129
|
-
})
|
|
108
|
+
});
|
|
130
109
|
coreRevert = result.revert;
|
|
131
110
|
revertFnRef.current = revert;
|
|
132
111
|
hasSplitRef.current = true;
|
|
@@ -157,43 +136,15 @@ var SplitText = forwardRef(
|
|
|
157
136
|
}
|
|
158
137
|
}
|
|
159
138
|
if (needsViewport && containerRef.current) {
|
|
160
|
-
|
|
139
|
+
observerRef.current = createViewportObserver(
|
|
140
|
+
viewportRef.current,
|
|
141
|
+
hasTriggeredOnceRef,
|
|
142
|
+
() => setIsInView(true),
|
|
143
|
+
() => setIsInView(false)
|
|
144
|
+
);
|
|
145
|
+
observerRef.current.observe(containerRef.current);
|
|
161
146
|
}
|
|
162
147
|
});
|
|
163
|
-
function setupViewportObserver(container) {
|
|
164
|
-
var _a2, _b2, _c, _d, _e;
|
|
165
|
-
const vpOptions = viewportRef.current || {};
|
|
166
|
-
const amount = (_a2 = vpOptions.amount) != null ? _a2 : 0;
|
|
167
|
-
const leave = (_b2 = vpOptions.leave) != null ? _b2 : 0;
|
|
168
|
-
const threshold = amount === "some" ? 0 : amount === "all" ? 1 : amount;
|
|
169
|
-
const leaveThreshold = leave === "some" ? 0 : leave === "all" ? 1 : leave;
|
|
170
|
-
const rootMargin = (_c = vpOptions.margin) != null ? _c : "0px";
|
|
171
|
-
const root = (_e = (_d = vpOptions.root) == null ? void 0 : _d.current) != null ? _e : void 0;
|
|
172
|
-
const thresholdValues = Array.from(
|
|
173
|
-
/* @__PURE__ */ new Set([0, threshold, leaveThreshold])
|
|
174
|
-
).sort((a, b) => a - b);
|
|
175
|
-
const thresholds = thresholdValues.length === 1 ? thresholdValues[0] : thresholdValues;
|
|
176
|
-
observerRef.current = new IntersectionObserver(
|
|
177
|
-
(entries) => {
|
|
178
|
-
const entry = entries[0];
|
|
179
|
-
if (!entry) return;
|
|
180
|
-
const isOnce = vpOptions.once;
|
|
181
|
-
if (entry.isIntersecting && entry.intersectionRatio >= threshold) {
|
|
182
|
-
if (isOnce && hasTriggeredOnceRef.current) return;
|
|
183
|
-
hasTriggeredOnceRef.current = true;
|
|
184
|
-
setIsInView(true);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (isOnce) return;
|
|
188
|
-
const shouldLeave = leaveThreshold === 0 ? !entry.isIntersecting : entry.intersectionRatio <= leaveThreshold;
|
|
189
|
-
if (shouldLeave) {
|
|
190
|
-
setIsInView(false);
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
{ threshold: thresholds, rootMargin, root }
|
|
194
|
-
);
|
|
195
|
-
observerRef.current.observe(container);
|
|
196
|
-
}
|
|
197
148
|
return () => {
|
|
198
149
|
isMounted = false;
|
|
199
150
|
if (observerRef.current) {
|
|
@@ -216,9 +167,8 @@ var SplitText = forwardRef(
|
|
|
216
167
|
const promise = normalizeToPromise(callbackResult);
|
|
217
168
|
if (revertOnCompleteRef.current && promise) {
|
|
218
169
|
promise.then(() => {
|
|
219
|
-
var _a2;
|
|
220
170
|
if (hasRevertedRef.current) return;
|
|
221
|
-
|
|
171
|
+
splitResultRef.current?.revert();
|
|
222
172
|
}).catch(() => {
|
|
223
173
|
console.warn("[fetta] Animation rejected, text not reverted");
|
|
224
174
|
});
|
|
@@ -251,16 +201,17 @@ var SplitText = forwardRef(
|
|
|
251
201
|
const Wrapper = Component;
|
|
252
202
|
return createElement(
|
|
253
203
|
Wrapper,
|
|
254
|
-
|
|
204
|
+
{
|
|
255
205
|
ref: mergedRef,
|
|
256
|
-
"data-fetta-auto-split-wrapper": "true"
|
|
257
|
-
|
|
206
|
+
"data-fetta-auto-split-wrapper": "true",
|
|
207
|
+
...wrapperProps,
|
|
258
208
|
className,
|
|
259
|
-
style:
|
|
209
|
+
style: {
|
|
260
210
|
visibility: waitForFonts ? "hidden" : "visible",
|
|
261
|
-
position: "relative"
|
|
262
|
-
|
|
263
|
-
|
|
211
|
+
position: "relative",
|
|
212
|
+
...userStyle
|
|
213
|
+
}
|
|
214
|
+
},
|
|
264
215
|
children
|
|
265
216
|
);
|
|
266
217
|
}
|
package/package.json
CHANGED
package/dist/chunk-FP4I6OR2.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// src/internal/initialStyles.ts
|
|
2
|
-
function reapplyInitialStyles(elements, style) {
|
|
3
|
-
if (!style || elements.length === 0) return;
|
|
4
|
-
const isFn = typeof style === "function";
|
|
5
|
-
for (let i = 0; i < elements.length; i++) {
|
|
6
|
-
const el = elements[i];
|
|
7
|
-
const styles = isFn ? style(el, i) : style;
|
|
8
|
-
for (const [key, value] of Object.entries(styles)) {
|
|
9
|
-
if (value == null) continue;
|
|
10
|
-
if (key === "cssText") {
|
|
11
|
-
if (typeof value === "string") {
|
|
12
|
-
el.style.cssText = value;
|
|
13
|
-
}
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (typeof value !== "string" && typeof value !== "number") continue;
|
|
17
|
-
const cssValue = typeof value === "number" ? String(value) : value;
|
|
18
|
-
const cssKey = key.startsWith("--") ? key : key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
19
|
-
el.style.setProperty(cssKey, cssValue);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function reapplyInitialClasses(elements, className) {
|
|
24
|
-
if (!className || elements.length === 0) return;
|
|
25
|
-
const classes = className.split(/\s+/).filter(Boolean);
|
|
26
|
-
for (const el of elements) {
|
|
27
|
-
el.classList.add(...classes);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// src/internal/waitForFontsReady.ts
|
|
32
|
-
async function waitForFontsReady(waitForFonts) {
|
|
33
|
-
if (!waitForFonts) return;
|
|
34
|
-
const fonts = document.fonts;
|
|
35
|
-
const ready = fonts == null ? void 0 : fonts.ready;
|
|
36
|
-
if (!ready || typeof ready.then !== "function") return;
|
|
37
|
-
try {
|
|
38
|
-
await ready;
|
|
39
|
-
} catch (e) {
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { reapplyInitialClasses, reapplyInitialStyles, waitForFontsReady };
|
package/dist/chunk-ORMEWXMH.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export { __objRest, __spreadProps, __spreadValues };
|