fetta 1.5.0 → 1.5.2
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 +108 -9
- package/dist/{chunk-UPF3IYHC.js → chunk-OUXSJF3P.js} +68 -75
- package/dist/{chunk-FP4I6OR2.js → chunk-V7FJXNWJ.js} +2 -2
- package/dist/helpers.js +5 -9
- package/dist/index.js +1 -2
- package/dist/motion.js +213 -310
- package/dist/react.js +42 -64
- package/package.json +1 -1
- package/dist/chunk-ORMEWXMH.js +0 -33
package/dist/motion.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { waitForFontsReady, reapplyInitialStyles, reapplyInitialClasses } from './chunk-
|
|
2
|
-
import { splitTextData, normalizeToPromise, resolveAutoSplitTargets, getObservedWidth, recordWidthChange,
|
|
3
|
-
import { __objRest, __spreadValues, __spreadProps } from './chunk-ORMEWXMH.js';
|
|
1
|
+
import { waitForFontsReady, reapplyInitialStyles, reapplyInitialClasses } from './chunk-V7FJXNWJ.js';
|
|
2
|
+
import { splitTextData, buildLineFingerprintFromData, normalizeToPromise, buildKerningStyleKey, resolveAutoSplitTargets, getObservedWidth, recordWidthChange, resolveAutoSplitWidth, querySplitWords, clearKerningCompensation, applyKerningCompensation } from './chunk-OUXSJF3P.js';
|
|
4
3
|
import { scroll, animate } from 'motion';
|
|
5
4
|
import { usePresence, useReducedMotion, MotionConfig, motion } from 'motion/react';
|
|
6
|
-
import {
|
|
7
|
-
import { forwardRef, useRef, useState, useId, useCallback, useMemo, useLayoutEffect, useEffect, isValidElement, createElement, cloneElement } from 'react';
|
|
5
|
+
import { forwardRef, useRef, useState, useCallback, useMemo, useLayoutEffect, isValidElement, useEffect, createElement, cloneElement } from 'react';
|
|
8
6
|
|
|
9
7
|
var ELEMENT_TYPE_KEYS = ["chars", "words", "lines"];
|
|
10
8
|
var VOID_HTML_TAGS = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "meta", "link"]);
|
|
@@ -54,7 +52,7 @@ function getVariantTransition(def) {
|
|
|
54
52
|
}
|
|
55
53
|
function withDefaultTransition(target, defaultTransition, delayScope) {
|
|
56
54
|
const needsDelayResolution = (transition) => {
|
|
57
|
-
const delay = transition
|
|
55
|
+
const delay = transition?.delay;
|
|
58
56
|
if (typeof delay === "function") return true;
|
|
59
57
|
if (typeof delay === "number") return !Number.isFinite(delay);
|
|
60
58
|
return false;
|
|
@@ -74,7 +72,10 @@ function withDefaultTransition(target, defaultTransition, delayScope) {
|
|
|
74
72
|
return void 0;
|
|
75
73
|
};
|
|
76
74
|
const mergeTransitions = (base, override, info) => {
|
|
77
|
-
const merged =
|
|
75
|
+
const merged = {
|
|
76
|
+
...base ?? {},
|
|
77
|
+
...override ?? {}
|
|
78
|
+
};
|
|
78
79
|
if ("delay" in merged) {
|
|
79
80
|
const resolved = resolveDelay(merged.delay, info);
|
|
80
81
|
if (resolved == null) {
|
|
@@ -93,9 +94,9 @@ function withDefaultTransition(target, defaultTransition, delayScope) {
|
|
|
93
94
|
resolved.transition,
|
|
94
95
|
info
|
|
95
96
|
);
|
|
96
|
-
if (transition) return
|
|
97
|
+
if (transition) return { ...resolved, transition };
|
|
97
98
|
if (resolved.transition) {
|
|
98
|
-
const
|
|
99
|
+
const { transition: _removed, ...rest } = resolved;
|
|
99
100
|
return rest;
|
|
100
101
|
}
|
|
101
102
|
return resolved;
|
|
@@ -108,31 +109,30 @@ function withDefaultTransition(target, defaultTransition, delayScope) {
|
|
|
108
109
|
target.transition,
|
|
109
110
|
info
|
|
110
111
|
);
|
|
111
|
-
return transition ?
|
|
112
|
+
return transition ? { ...target, transition } : target;
|
|
112
113
|
};
|
|
113
114
|
}
|
|
114
115
|
if (!defaultTransition) return target;
|
|
115
116
|
if (!target.transition) {
|
|
116
|
-
return
|
|
117
|
+
return { ...target, transition: defaultTransition };
|
|
117
118
|
}
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
return {
|
|
120
|
+
...target,
|
|
121
|
+
transition: { ...defaultTransition, ...target.transition }
|
|
122
|
+
};
|
|
121
123
|
}
|
|
122
124
|
function getTargetType(data, type) {
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
if (
|
|
129
|
-
if ((type == null ? void 0 : type.includes("lines")) && hasLines) return "lines";
|
|
125
|
+
const hasChars = data.meta.type?.includes("chars");
|
|
126
|
+
const hasWords = data.meta.type?.includes("words");
|
|
127
|
+
const hasLines = data.meta.type?.includes("lines");
|
|
128
|
+
if (type?.includes("chars") && hasChars) return "chars";
|
|
129
|
+
if (type?.includes("words") && hasWords) return "words";
|
|
130
|
+
if (type?.includes("lines") && hasLines) return "lines";
|
|
130
131
|
if (hasChars) return "chars";
|
|
131
132
|
if (hasWords) return "words";
|
|
132
133
|
return "lines";
|
|
133
134
|
}
|
|
134
135
|
function buildVariantsByType(variants, targetType, childDefaultTransition, delayScope, forceInstant = false) {
|
|
135
|
-
var _a;
|
|
136
136
|
if (!variants) return { types: {}, wrapper: {} };
|
|
137
137
|
const result = {};
|
|
138
138
|
const wrapperVariants = {};
|
|
@@ -141,22 +141,22 @@ function buildVariantsByType(variants, targetType, childDefaultTransition, delay
|
|
|
141
141
|
if (typeof target === "function") {
|
|
142
142
|
return (info) => {
|
|
143
143
|
const resolved = target(info);
|
|
144
|
-
return
|
|
144
|
+
return { ...resolved, transition: instantTransition };
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
-
return
|
|
147
|
+
return { ...target, transition: instantTransition };
|
|
148
148
|
};
|
|
149
149
|
const applyInstantWrapper = (target) => {
|
|
150
150
|
if (typeof target === "function") {
|
|
151
151
|
return ({ custom }) => {
|
|
152
152
|
const resolved = target({ custom });
|
|
153
|
-
return
|
|
153
|
+
return { ...resolved, transition: instantTransition };
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
-
return
|
|
156
|
+
return { ...target, transition: instantTransition };
|
|
157
157
|
};
|
|
158
158
|
for (const [name, def] of Object.entries(variants)) {
|
|
159
|
-
const defaultTransition = isPerTypeVariant(def) ?
|
|
159
|
+
const defaultTransition = isPerTypeVariant(def) ? def.transition ?? childDefaultTransition : childDefaultTransition;
|
|
160
160
|
const resolvedDefault = forceInstant ? instantTransition : defaultTransition;
|
|
161
161
|
if (isPerTypeVariant(def)) {
|
|
162
162
|
if (def.wrapper) {
|
|
@@ -190,14 +190,14 @@ function collectRelations(nodes) {
|
|
|
190
190
|
let nextContext = context;
|
|
191
191
|
if (node.split === "line") {
|
|
192
192
|
const lineIndex = counts.lines++;
|
|
193
|
-
nextContext =
|
|
193
|
+
nextContext = { ...context, lineIndex };
|
|
194
194
|
}
|
|
195
195
|
if (node.split === "word") {
|
|
196
196
|
const wordIndex = counts.words++;
|
|
197
197
|
if (nextContext.lineIndex != null) {
|
|
198
198
|
wordToLine[wordIndex] = nextContext.lineIndex;
|
|
199
199
|
}
|
|
200
|
-
nextContext =
|
|
200
|
+
nextContext = { ...nextContext, wordIndex };
|
|
201
201
|
}
|
|
202
202
|
if (node.split === "char") {
|
|
203
203
|
const charIndex = counts.chars++;
|
|
@@ -313,24 +313,24 @@ function buildVariantInfo(elementType, globalIndex, total, maps, isPresent, cust
|
|
|
313
313
|
};
|
|
314
314
|
}
|
|
315
315
|
function getTargetElements(result, type) {
|
|
316
|
-
if (type
|
|
317
|
-
if (type
|
|
318
|
-
if (type
|
|
316
|
+
if (type?.includes("chars")) return result.chars;
|
|
317
|
+
if (type?.includes("words")) return result.words;
|
|
318
|
+
if (type?.includes("lines")) return result.lines;
|
|
319
319
|
if (result.chars.length) return result.chars;
|
|
320
320
|
if (result.words.length) return result.words;
|
|
321
321
|
if (result.lines.length) return result.lines;
|
|
322
322
|
return [];
|
|
323
323
|
}
|
|
324
324
|
function getTargetTypeForElements(result, type) {
|
|
325
|
-
if (type
|
|
326
|
-
if (type
|
|
327
|
-
if (type
|
|
325
|
+
if (type?.includes("chars")) return "chars";
|
|
326
|
+
if (type?.includes("words")) return "words";
|
|
327
|
+
if (type?.includes("lines")) return "lines";
|
|
328
328
|
if (result.chars.length) return "chars";
|
|
329
329
|
if (result.words.length) return "words";
|
|
330
330
|
return "lines";
|
|
331
331
|
}
|
|
332
332
|
function extractTransition(variant) {
|
|
333
|
-
const
|
|
333
|
+
const { transition, ...props } = variant;
|
|
334
334
|
return { props, transition };
|
|
335
335
|
}
|
|
336
336
|
function buildIndexMapsDom(result) {
|
|
@@ -394,7 +394,7 @@ function buildStaticItems(elements, elementType, props, transition, maps, isPres
|
|
|
394
394
|
isPresent,
|
|
395
395
|
custom
|
|
396
396
|
);
|
|
397
|
-
let merged = transition ?
|
|
397
|
+
let merged = transition ? { ...transition } : void 0;
|
|
398
398
|
if (merged && "delay" in merged) {
|
|
399
399
|
const rawDelay = merged.delay;
|
|
400
400
|
const resolvedDelay = typeof rawDelay === "function" ? rawDelay(
|
|
@@ -404,7 +404,7 @@ function buildStaticItems(elements, elementType, props, transition, maps, isPres
|
|
|
404
404
|
if (resolvedDelay != null && Number.isFinite(resolvedDelay)) {
|
|
405
405
|
merged.delay = resolvedDelay;
|
|
406
406
|
} else {
|
|
407
|
-
const
|
|
407
|
+
const { delay: _removed, ...restNoDelay } = merged;
|
|
408
408
|
merged = restNoDelay;
|
|
409
409
|
}
|
|
410
410
|
}
|
|
@@ -418,7 +418,7 @@ function buildStaticItems(elements, elementType, props, transition, maps, isPres
|
|
|
418
418
|
}
|
|
419
419
|
function buildSequenceFromItems(items) {
|
|
420
420
|
return items.map((item) => {
|
|
421
|
-
const sequenceTransition = item.transition ?
|
|
421
|
+
const sequenceTransition = item.transition ? { ...item.transition } : {};
|
|
422
422
|
const delay = sequenceTransition.delay;
|
|
423
423
|
const hasExplicitAt = sequenceTransition.at != null;
|
|
424
424
|
const at = hasExplicitAt ? sequenceTransition.at : typeof delay === "number" && Number.isFinite(delay) ? delay : 0;
|
|
@@ -430,9 +430,8 @@ function buildSequenceFromItems(items) {
|
|
|
430
430
|
});
|
|
431
431
|
}
|
|
432
432
|
function buildFnItems(elements, elementType, fn, maps, transition, isPresent, delayScope, custom, forceInstant = false) {
|
|
433
|
-
var _c;
|
|
434
433
|
const t = transition;
|
|
435
|
-
const
|
|
434
|
+
const { delay: outerDelay, duration, ...rest } = t || {};
|
|
436
435
|
const items = [];
|
|
437
436
|
const total = elements.length;
|
|
438
437
|
const instantTransition = { duration: 0, delay: 0 };
|
|
@@ -445,24 +444,24 @@ function buildFnItems(elements, elementType, fn, maps, transition, isPresent, de
|
|
|
445
444
|
isPresent,
|
|
446
445
|
custom
|
|
447
446
|
);
|
|
448
|
-
const
|
|
447
|
+
const { transition: localT, ...props } = fn(info);
|
|
449
448
|
let merged;
|
|
450
449
|
if (forceInstant) {
|
|
451
450
|
merged = instantTransition;
|
|
452
451
|
} else {
|
|
453
|
-
merged = localT ?
|
|
452
|
+
merged = localT ? { ...rest, ...localT } : { ...rest };
|
|
454
453
|
if (duration != null && merged.duration == null) {
|
|
455
|
-
merged =
|
|
454
|
+
merged = { ...merged, duration };
|
|
456
455
|
}
|
|
457
|
-
const rawDelay =
|
|
456
|
+
const rawDelay = merged.delay ?? outerDelay;
|
|
458
457
|
const resolvedDelay = typeof rawDelay === "function" ? rawDelay(
|
|
459
458
|
delayScope === "local" ? info.index : info.globalIndex,
|
|
460
459
|
delayScope === "local" ? info.count : info.globalCount
|
|
461
460
|
) : rawDelay;
|
|
462
461
|
if (resolvedDelay != null && Number.isFinite(resolvedDelay)) {
|
|
463
|
-
merged =
|
|
462
|
+
merged = { ...merged, delay: resolvedDelay };
|
|
464
463
|
} else if ("delay" in merged) {
|
|
465
|
-
const
|
|
464
|
+
const { delay: _removed, ...restNoDelay } = merged;
|
|
466
465
|
merged = restNoDelay;
|
|
467
466
|
}
|
|
468
467
|
}
|
|
@@ -683,7 +682,7 @@ function serializeInitial(value) {
|
|
|
683
682
|
if (typeof value === "string") return value;
|
|
684
683
|
try {
|
|
685
684
|
return JSON.stringify(value);
|
|
686
|
-
} catch
|
|
685
|
+
} catch {
|
|
687
686
|
return String(value);
|
|
688
687
|
}
|
|
689
688
|
}
|
|
@@ -699,22 +698,21 @@ function serializeNode(node) {
|
|
|
699
698
|
const elementType = node.type;
|
|
700
699
|
const type = typeof elementType === "string" ? elementType : elementType.displayName || elementType.name || "Component";
|
|
701
700
|
const props = node.props;
|
|
702
|
-
const className = typeof
|
|
701
|
+
const className = typeof props?.className === "string" ? props.className : "";
|
|
703
702
|
return `<${type}${className ? `.${className}` : ""}>${serializeNode(
|
|
704
|
-
props
|
|
703
|
+
props?.children
|
|
705
704
|
)}</${type}>`;
|
|
706
705
|
}
|
|
707
706
|
return "";
|
|
708
707
|
}
|
|
709
708
|
function buildSplitSignature(child, options, initialStyles, initialClasses) {
|
|
710
|
-
|
|
711
|
-
const opt = options != null ? options : {};
|
|
709
|
+
const opt = options ?? {};
|
|
712
710
|
const signature = {
|
|
713
|
-
type:
|
|
714
|
-
charClass:
|
|
715
|
-
wordClass:
|
|
716
|
-
lineClass:
|
|
717
|
-
mask:
|
|
711
|
+
type: opt.type ?? "",
|
|
712
|
+
charClass: opt.charClass ?? "",
|
|
713
|
+
wordClass: opt.wordClass ?? "",
|
|
714
|
+
lineClass: opt.lineClass ?? "",
|
|
715
|
+
mask: opt.mask ?? "",
|
|
718
716
|
propIndex: !!opt.propIndex,
|
|
719
717
|
disableKerning: !!opt.disableKerning,
|
|
720
718
|
isolateKerningMeasurement: opt.isolateKerningMeasurement !== false,
|
|
@@ -724,25 +722,23 @@ function buildSplitSignature(child, options, initialStyles, initialClasses) {
|
|
|
724
722
|
};
|
|
725
723
|
try {
|
|
726
724
|
return JSON.stringify(signature);
|
|
727
|
-
} catch
|
|
725
|
+
} catch {
|
|
728
726
|
return String(signature);
|
|
729
727
|
}
|
|
730
728
|
}
|
|
731
729
|
function getMotionComponent(tag) {
|
|
732
|
-
var _a;
|
|
733
730
|
const registry = motion;
|
|
734
|
-
return
|
|
731
|
+
return registry[tag] ?? motion.span;
|
|
735
732
|
}
|
|
736
733
|
function collectSplitElements(element, options) {
|
|
737
|
-
var _a, _b, _c;
|
|
738
734
|
const normalizeSelector = (value) => {
|
|
739
735
|
const tokens = value.split(/\s+/).filter(Boolean);
|
|
740
736
|
if (tokens.length === 0) return "";
|
|
741
737
|
return `.${tokens.join(".")}`;
|
|
742
738
|
};
|
|
743
|
-
const charClass = normalizeSelector(
|
|
744
|
-
const wordClass = normalizeSelector(
|
|
745
|
-
const lineClass = normalizeSelector(
|
|
739
|
+
const charClass = normalizeSelector(options?.charClass ?? "split-char");
|
|
740
|
+
const wordClass = normalizeSelector(options?.wordClass ?? "split-word");
|
|
741
|
+
const lineClass = normalizeSelector(options?.lineClass ?? "split-line");
|
|
746
742
|
const chars = Array.from(
|
|
747
743
|
element.querySelectorAll(charClass)
|
|
748
744
|
);
|
|
@@ -756,7 +752,7 @@ function collectSplitElements(element, options) {
|
|
|
756
752
|
} };
|
|
757
753
|
}
|
|
758
754
|
function resolveSplitFlags(type) {
|
|
759
|
-
const resolvedType = type
|
|
755
|
+
const resolvedType = type ?? "chars,words,lines";
|
|
760
756
|
let splitChars = resolvedType.includes("chars");
|
|
761
757
|
let splitWords = resolvedType.includes("words");
|
|
762
758
|
let splitLines = resolvedType.includes("lines");
|
|
@@ -767,28 +763,6 @@ function resolveSplitFlags(type) {
|
|
|
767
763
|
}
|
|
768
764
|
return { splitChars, splitWords, splitLines };
|
|
769
765
|
}
|
|
770
|
-
function normalizeLineFingerprintText(value) {
|
|
771
|
-
return value.replace(/\u00A0/g, " ").replace(/\s+/g, " ").trim();
|
|
772
|
-
}
|
|
773
|
-
function collectNodeText(node) {
|
|
774
|
-
if (node.type === "text") return node.text;
|
|
775
|
-
return node.children.map((child) => collectNodeText(child)).join("");
|
|
776
|
-
}
|
|
777
|
-
function collectLineTextsFromData(nodes, lineTexts) {
|
|
778
|
-
for (const node of nodes) {
|
|
779
|
-
if (node.type !== "element") continue;
|
|
780
|
-
if (node.split === "line") {
|
|
781
|
-
lineTexts.push(normalizeLineFingerprintText(collectNodeText(node)));
|
|
782
|
-
continue;
|
|
783
|
-
}
|
|
784
|
-
collectLineTextsFromData(node.children, lineTexts);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
function buildLineFingerprintFromData(data) {
|
|
788
|
-
const lineTexts = [];
|
|
789
|
-
collectLineTextsFromData(data.nodes, lineTexts);
|
|
790
|
-
return lineTexts.join("\n");
|
|
791
|
-
}
|
|
792
766
|
function buildSplitDataLayout(data) {
|
|
793
767
|
const relations = collectRelations(data.nodes);
|
|
794
768
|
const maps = buildIndexMaps(relations);
|
|
@@ -822,81 +796,44 @@ function buildVariantInfos(splitDataLayout, isPresent, custom) {
|
|
|
822
796
|
counts: relations.counts
|
|
823
797
|
};
|
|
824
798
|
}
|
|
825
|
-
var SplitText = forwardRef(function SplitText2(
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
"children",
|
|
864
|
-
"as",
|
|
865
|
-
"className",
|
|
866
|
-
"style",
|
|
867
|
-
"onSplit",
|
|
868
|
-
"onResplit",
|
|
869
|
-
"options",
|
|
870
|
-
"autoSplit",
|
|
871
|
-
"animateOnResplit",
|
|
872
|
-
"revertOnComplete",
|
|
873
|
-
"viewport",
|
|
874
|
-
"onViewportEnter",
|
|
875
|
-
"onViewportLeave",
|
|
876
|
-
"onRevert",
|
|
877
|
-
"initialStyles",
|
|
878
|
-
"initialClasses",
|
|
879
|
-
"resetOnViewportLeave",
|
|
880
|
-
"waitForFonts",
|
|
881
|
-
"variants",
|
|
882
|
-
"initial",
|
|
883
|
-
"animate",
|
|
884
|
-
"whileInView",
|
|
885
|
-
"whileOutOfView",
|
|
886
|
-
"whileScroll",
|
|
887
|
-
"exit",
|
|
888
|
-
"scroll",
|
|
889
|
-
"whileHover",
|
|
890
|
-
"whileTap",
|
|
891
|
-
"whileFocus",
|
|
892
|
-
"reducedMotion",
|
|
893
|
-
"custom",
|
|
894
|
-
"onHoverStart",
|
|
895
|
-
"onHoverEnd",
|
|
896
|
-
"transition",
|
|
897
|
-
"delayScope"
|
|
898
|
-
]);
|
|
899
|
-
var _a2, _b2, _c, _d, _e, _f;
|
|
799
|
+
var SplitText = forwardRef(function SplitText2({
|
|
800
|
+
children,
|
|
801
|
+
as: Component = "div",
|
|
802
|
+
className,
|
|
803
|
+
style: userStyle,
|
|
804
|
+
onSplit,
|
|
805
|
+
onResplit,
|
|
806
|
+
options,
|
|
807
|
+
autoSplit = false,
|
|
808
|
+
animateOnResplit = false,
|
|
809
|
+
revertOnComplete = false,
|
|
810
|
+
viewport,
|
|
811
|
+
onViewportEnter,
|
|
812
|
+
onViewportLeave,
|
|
813
|
+
onRevert,
|
|
814
|
+
initialStyles,
|
|
815
|
+
initialClasses,
|
|
816
|
+
resetOnViewportLeave = false,
|
|
817
|
+
waitForFonts = true,
|
|
818
|
+
variants,
|
|
819
|
+
initial: initialVariant,
|
|
820
|
+
animate: animateVariantName,
|
|
821
|
+
whileInView,
|
|
822
|
+
whileOutOfView,
|
|
823
|
+
whileScroll,
|
|
824
|
+
exit,
|
|
825
|
+
scroll: scrollProp,
|
|
826
|
+
whileHover,
|
|
827
|
+
whileTap,
|
|
828
|
+
whileFocus,
|
|
829
|
+
reducedMotion,
|
|
830
|
+
custom,
|
|
831
|
+
onHoverStart,
|
|
832
|
+
onHoverEnd,
|
|
833
|
+
transition,
|
|
834
|
+
delayScope = "global",
|
|
835
|
+
...wrapperProps
|
|
836
|
+
}, forwardedRef) {
|
|
900
837
|
const containerRef = useRef(null);
|
|
901
838
|
const [childElement, setChildElement] = useState(null);
|
|
902
839
|
const [data, setData] = useState(null);
|
|
@@ -905,7 +842,6 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
905
842
|
const [isInView, setIsInView] = useState(false);
|
|
906
843
|
const [isPresent, safeToRemove] = usePresence();
|
|
907
844
|
const presenceEnabled = typeof safeToRemove === "function";
|
|
908
|
-
const instanceId = useId();
|
|
909
845
|
const prefersReducedMotion = useReducedMotion();
|
|
910
846
|
const reduceMotionActive = reducedMotion === "always" || reducedMotion === "user" && !!prefersReducedMotion;
|
|
911
847
|
const [isHovered, setIsHovered] = useState(false);
|
|
@@ -938,16 +874,18 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
938
874
|
const whileTapLabel = inlineWhileTapVariant ? "__fetta_whileTap__" : whileTap;
|
|
939
875
|
const whileFocusLabel = inlineWhileFocusVariant ? "__fetta_whileFocus__" : whileFocus;
|
|
940
876
|
const needsViewport = !!(whileInViewLabel || whileOutOfViewLabel || onViewportEnter || onViewportLeave || resetOnViewportLeave || viewport);
|
|
941
|
-
const viewportAmount =
|
|
942
|
-
const viewportLeave =
|
|
943
|
-
const viewportMargin =
|
|
944
|
-
const viewportOnce =
|
|
945
|
-
const viewportRoot =
|
|
877
|
+
const viewportAmount = viewport?.amount ?? 0;
|
|
878
|
+
const viewportLeave = viewport?.leave ?? 0;
|
|
879
|
+
const viewportMargin = viewport?.margin ?? "0px";
|
|
880
|
+
const viewportOnce = viewport?.once ?? false;
|
|
881
|
+
const viewportRoot = viewport?.root?.current ?? null;
|
|
946
882
|
const resolvedVariants = useMemo(() => {
|
|
947
883
|
if (!variants && !inlineInitialVariant && !inlineAnimateVariant && !inlineExitVariant && !inlineWhileInViewVariant && !inlineWhileOutOfViewVariant && !inlineWhileScrollVariant && !inlineWhileHoverVariant && !inlineWhileTapVariant && !inlineWhileFocusVariant) {
|
|
948
884
|
return variants;
|
|
949
885
|
}
|
|
950
|
-
const merged =
|
|
886
|
+
const merged = {
|
|
887
|
+
...variants ?? {}
|
|
888
|
+
};
|
|
951
889
|
if (inlineInitialVariant) {
|
|
952
890
|
merged.__fetta_initial__ = initialVariant;
|
|
953
891
|
}
|
|
@@ -1016,7 +954,6 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1016
954
|
const initialVariantRef = useRef(initialLabel);
|
|
1017
955
|
const whileInViewRef = useRef(whileInViewLabel);
|
|
1018
956
|
const whileOutOfViewRef = useRef(whileOutOfViewLabel);
|
|
1019
|
-
const debugPresence = (options == null ? void 0 : options.__debugPresence) === true;
|
|
1020
957
|
useLayoutEffect(() => {
|
|
1021
958
|
onSplitRef.current = onSplit;
|
|
1022
959
|
onResplitRef.current = onResplit;
|
|
@@ -1033,26 +970,6 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1033
970
|
whileInViewRef.current = whileInViewLabel;
|
|
1034
971
|
whileOutOfViewRef.current = whileOutOfViewLabel;
|
|
1035
972
|
});
|
|
1036
|
-
useEffect(() => {
|
|
1037
|
-
if (!debugPresence) return;
|
|
1038
|
-
console.log(
|
|
1039
|
-
"[fetta][SplitText]",
|
|
1040
|
-
instanceId,
|
|
1041
|
-
"present",
|
|
1042
|
-
isPresent,
|
|
1043
|
-
"ready",
|
|
1044
|
-
isReady,
|
|
1045
|
-
"data",
|
|
1046
|
-
!!data
|
|
1047
|
-
);
|
|
1048
|
-
}, [debugPresence, instanceId, isPresent, isReady, data]);
|
|
1049
|
-
useEffect(() => {
|
|
1050
|
-
if (!debugPresence) return;
|
|
1051
|
-
console.log("[fetta][SplitText]", instanceId, "mount");
|
|
1052
|
-
return () => {
|
|
1053
|
-
console.log("[fetta][SplitText]", instanceId, "unmount");
|
|
1054
|
-
};
|
|
1055
|
-
}, [debugPresence, instanceId]);
|
|
1056
973
|
const hasSplitRef = useRef(false);
|
|
1057
974
|
const hasRevertedRef = useRef(false);
|
|
1058
975
|
const splitResultRef = useRef(null);
|
|
@@ -1072,8 +989,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1072
989
|
const hasRunOnSplitForCycleRef = useRef(false);
|
|
1073
990
|
const originalHTMLRef = useRef(null);
|
|
1074
991
|
useLayoutEffect(() => {
|
|
1075
|
-
|
|
1076
|
-
const element = (_a3 = containerRef.current) == null ? void 0 : _a3.firstElementChild;
|
|
992
|
+
const element = containerRef.current?.firstElementChild;
|
|
1077
993
|
setChildElement(element instanceof HTMLElement ? element : null);
|
|
1078
994
|
}, [children, data]);
|
|
1079
995
|
const splitSignature = useMemo(() => {
|
|
@@ -1120,14 +1036,13 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1120
1036
|
resetSplitState(next);
|
|
1121
1037
|
}, [isPresent, resetSplitState]);
|
|
1122
1038
|
function setupViewportObserver(container) {
|
|
1123
|
-
var _a3, _b3, _c2, _d2, _e2;
|
|
1124
1039
|
const vpOptions = viewportRef.current || {};
|
|
1125
|
-
const amount =
|
|
1126
|
-
const leave =
|
|
1040
|
+
const amount = vpOptions.amount ?? 0;
|
|
1041
|
+
const leave = vpOptions.leave ?? 0;
|
|
1127
1042
|
const threshold = amount === "some" ? 0 : amount === "all" ? 1 : amount;
|
|
1128
1043
|
const leaveThreshold = leave === "some" ? 0 : leave === "all" ? 1 : leave;
|
|
1129
|
-
const rootMargin =
|
|
1130
|
-
const root =
|
|
1044
|
+
const rootMargin = vpOptions.margin ?? "0px";
|
|
1045
|
+
const root = vpOptions.root?.current ?? void 0;
|
|
1131
1046
|
const thresholdValues = Array.from(
|
|
1132
1047
|
/* @__PURE__ */ new Set([0, threshold, leaveThreshold])
|
|
1133
1048
|
).sort((a, b) => a - b);
|
|
@@ -1154,15 +1069,13 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1154
1069
|
observerRef.current.observe(container);
|
|
1155
1070
|
}
|
|
1156
1071
|
const buildSplitDataFromProbe = useCallback((width) => {
|
|
1157
|
-
var _a3;
|
|
1158
1072
|
const currentChild = childElement && childElement.isConnected ? childElement : (() => {
|
|
1159
|
-
|
|
1160
|
-
const element = (_a4 = containerRef.current) == null ? void 0 : _a4.firstElementChild;
|
|
1073
|
+
const element = containerRef.current?.firstElementChild;
|
|
1161
1074
|
return element instanceof HTMLElement ? element : null;
|
|
1162
1075
|
})();
|
|
1163
1076
|
if (!currentChild) return null;
|
|
1164
1077
|
if (!currentChild.parentElement) return null;
|
|
1165
|
-
const originalHTML =
|
|
1078
|
+
const originalHTML = originalHTMLRef.current ?? currentChild.innerHTML;
|
|
1166
1079
|
originalHTMLRef.current = originalHTML;
|
|
1167
1080
|
const probeHost = currentChild.ownerDocument.createElement("div");
|
|
1168
1081
|
probeHost.setAttribute("data-fetta-auto-split-probe", "true");
|
|
@@ -1172,17 +1085,18 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1172
1085
|
probeHost.style.visibility = "hidden";
|
|
1173
1086
|
probeHost.style.pointerEvents = "none";
|
|
1174
1087
|
probeHost.style.contain = "layout style paint";
|
|
1175
|
-
const measuredWidth = width
|
|
1088
|
+
const measuredWidth = width ?? currentChild.getBoundingClientRect().width;
|
|
1176
1089
|
probeHost.style.width = `${Math.max(1, measuredWidth)}px`;
|
|
1177
1090
|
const probeElement = currentChild.cloneNode(false);
|
|
1178
1091
|
probeElement.innerHTML = originalHTML;
|
|
1179
1092
|
probeHost.appendChild(probeElement);
|
|
1180
1093
|
currentChild.parentElement.appendChild(probeHost);
|
|
1181
1094
|
try {
|
|
1182
|
-
const probeData = splitTextData(probeElement,
|
|
1095
|
+
const probeData = splitTextData(probeElement, {
|
|
1096
|
+
...optionsRef.current,
|
|
1183
1097
|
initialStyles: initialStylesRef.current,
|
|
1184
1098
|
initialClasses: initialClassesRef.current
|
|
1185
|
-
})
|
|
1099
|
+
});
|
|
1186
1100
|
return probeData;
|
|
1187
1101
|
} finally {
|
|
1188
1102
|
probeHost.remove();
|
|
@@ -1192,13 +1106,11 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1192
1106
|
(isResize = false, width) => {
|
|
1193
1107
|
const nextData = buildSplitDataFromProbe(width);
|
|
1194
1108
|
if (!nextData) return;
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
setData(nextData);
|
|
1201
|
-
});
|
|
1109
|
+
setChildTreeVersion((current) => current + 1);
|
|
1110
|
+
if (!isResize) {
|
|
1111
|
+
setIsReady(false);
|
|
1112
|
+
}
|
|
1113
|
+
setData(nextData);
|
|
1202
1114
|
},
|
|
1203
1115
|
[buildSplitDataFromProbe]
|
|
1204
1116
|
);
|
|
@@ -1208,9 +1120,8 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1208
1120
|
return buildLineFingerprintFromData(probeData);
|
|
1209
1121
|
}, [buildSplitDataFromProbe]);
|
|
1210
1122
|
const resolveLineMeasureWidth = useCallback((fallbackWidth) => {
|
|
1211
|
-
var _a3;
|
|
1212
1123
|
const safeFallbackWidth = Number.isFinite(fallbackWidth) && fallbackWidth > 0 ? fallbackWidth : 1;
|
|
1213
|
-
const observedChild =
|
|
1124
|
+
const observedChild = containerRef.current?.firstElementChild;
|
|
1214
1125
|
if (observedChild instanceof HTMLElement) {
|
|
1215
1126
|
const childWidth = observedChild.getBoundingClientRect().width;
|
|
1216
1127
|
if (Number.isFinite(childWidth) && childWidth > 0) {
|
|
@@ -1238,12 +1149,11 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1238
1149
|
[data]
|
|
1239
1150
|
);
|
|
1240
1151
|
useEffect(() => {
|
|
1241
|
-
var _a3;
|
|
1242
1152
|
if (!data) {
|
|
1243
1153
|
currentLineFingerprintRef.current = null;
|
|
1244
1154
|
return;
|
|
1245
1155
|
}
|
|
1246
|
-
const { splitLines } = resolveSplitFlags(
|
|
1156
|
+
const { splitLines } = resolveSplitFlags(optionsRef.current?.type);
|
|
1247
1157
|
currentLineFingerprintRef.current = splitLines ? buildLineFingerprintFromData(data) : null;
|
|
1248
1158
|
}, [data]);
|
|
1249
1159
|
const variantInfo = useMemo(
|
|
@@ -1252,7 +1162,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1252
1162
|
);
|
|
1253
1163
|
const targetType = useMemo(() => {
|
|
1254
1164
|
if (!data) return "words";
|
|
1255
|
-
return getTargetType(data, options
|
|
1165
|
+
return getTargetType(data, options?.type);
|
|
1256
1166
|
}, [data, options]);
|
|
1257
1167
|
const orchestrationTransition = useMemo(
|
|
1258
1168
|
() => pickOrchestration(transition),
|
|
@@ -1288,7 +1198,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1288
1198
|
reduceMotionActive
|
|
1289
1199
|
]
|
|
1290
1200
|
);
|
|
1291
|
-
const nodePropsMap = splitDataLayout
|
|
1201
|
+
const nodePropsMap = splitDataLayout?.propsByNode;
|
|
1292
1202
|
const exitTypes = useMemo(() => {
|
|
1293
1203
|
const exitKey = typeof exitLabel === "string" ? exitLabel : null;
|
|
1294
1204
|
if (!exitKey) return [];
|
|
@@ -1315,15 +1225,13 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1315
1225
|
}, [variantsByType, animateLabel]);
|
|
1316
1226
|
const exitTotalCount = useMemo(() => {
|
|
1317
1227
|
return exitTypes.reduce((sum, type) => {
|
|
1318
|
-
|
|
1319
|
-
const count = (_a3 = variantInfo.counts[type]) != null ? _a3 : 0;
|
|
1228
|
+
const count = variantInfo.counts[type] ?? 0;
|
|
1320
1229
|
return sum + count;
|
|
1321
1230
|
}, 0);
|
|
1322
1231
|
}, [exitTypes, variantInfo.counts]);
|
|
1323
1232
|
const revertTotalCount = useMemo(() => {
|
|
1324
1233
|
return revertTypes.reduce((sum, type) => {
|
|
1325
|
-
|
|
1326
|
-
const count = (_a3 = variantInfo.counts[type]) != null ? _a3 : 0;
|
|
1234
|
+
const count = variantInfo.counts[type] ?? 0;
|
|
1327
1235
|
return sum + count;
|
|
1328
1236
|
}, 0);
|
|
1329
1237
|
}, [revertTypes, variantInfo.counts]);
|
|
@@ -1342,23 +1250,27 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1342
1250
|
const applyWrapperTransition = (target) => {
|
|
1343
1251
|
if (!wrapperBaseTransition) return target;
|
|
1344
1252
|
if (target.transition) {
|
|
1345
|
-
return
|
|
1346
|
-
|
|
1347
|
-
|
|
1253
|
+
return {
|
|
1254
|
+
...target,
|
|
1255
|
+
transition: { ...wrapperBaseTransition, ...target.transition }
|
|
1256
|
+
};
|
|
1348
1257
|
}
|
|
1349
|
-
return
|
|
1258
|
+
return { ...target, transition: wrapperBaseTransition };
|
|
1350
1259
|
};
|
|
1351
1260
|
if (wrapperVariant) {
|
|
1352
1261
|
if (typeof wrapperVariant === "function") {
|
|
1353
1262
|
const resolved = wrapperVariant({ custom });
|
|
1354
|
-
result[key] = reduceMotionActive ?
|
|
1263
|
+
result[key] = reduceMotionActive ? { ...resolved, transition: { duration: 0, delay: 0 } } : applyWrapperTransition(resolved);
|
|
1355
1264
|
} else {
|
|
1356
|
-
const resolved = reduceMotionActive ?
|
|
1265
|
+
const resolved = reduceMotionActive ? { ...wrapperVariant, transition: { duration: 0, delay: 0 } } : wrapperVariant;
|
|
1357
1266
|
result[key] = applyWrapperTransition(resolved);
|
|
1358
1267
|
}
|
|
1359
1268
|
continue;
|
|
1360
1269
|
}
|
|
1361
|
-
const transitionValue = reduceMotionActive ? { duration: 0, delay: 0 } : orchestrationTransition || localOrchestration ?
|
|
1270
|
+
const transitionValue = reduceMotionActive ? { duration: 0, delay: 0 } : orchestrationTransition || localOrchestration ? {
|
|
1271
|
+
...orchestrationTransition ?? {},
|
|
1272
|
+
...localOrchestration ?? {}
|
|
1273
|
+
} : void 0;
|
|
1362
1274
|
result[key] = transitionValue ? { transition: transitionValue } : {};
|
|
1363
1275
|
}
|
|
1364
1276
|
return result;
|
|
@@ -1382,21 +1294,15 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1382
1294
|
}, [hasHover]);
|
|
1383
1295
|
const hasTap = !!(whileTapLabel && hasVariants);
|
|
1384
1296
|
const hasFocus = !!(whileFocusLabel && hasVariants);
|
|
1385
|
-
const
|
|
1297
|
+
const {
|
|
1386
1298
|
onTapStart: userOnTapStart,
|
|
1387
1299
|
onTapCancel: userOnTapCancel,
|
|
1388
1300
|
onTap: userOnTap,
|
|
1389
1301
|
onFocus: userOnFocus,
|
|
1390
1302
|
onBlur: userOnBlur,
|
|
1391
|
-
onAnimationComplete: userOnAnimationComplete
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
"onTapCancel",
|
|
1395
|
-
"onTap",
|
|
1396
|
-
"onFocus",
|
|
1397
|
-
"onBlur",
|
|
1398
|
-
"onAnimationComplete"
|
|
1399
|
-
]);
|
|
1303
|
+
onAnimationComplete: userOnAnimationComplete,
|
|
1304
|
+
...passthroughWrapperProps
|
|
1305
|
+
} = wrapperProps;
|
|
1400
1306
|
useEffect(() => {
|
|
1401
1307
|
if (!hasTap) {
|
|
1402
1308
|
setIsTapped(false);
|
|
@@ -1428,7 +1334,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1428
1334
|
tracker.total = trackedExitCount;
|
|
1429
1335
|
if (isPresent) return;
|
|
1430
1336
|
if (!exitLabel || trackedExitCount === 0) {
|
|
1431
|
-
safeToRemove
|
|
1337
|
+
safeToRemove?.();
|
|
1432
1338
|
}
|
|
1433
1339
|
}, [
|
|
1434
1340
|
presenceEnabled,
|
|
@@ -1446,7 +1352,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1446
1352
|
if (definition !== exitLabel) return;
|
|
1447
1353
|
tracker.completed += 1;
|
|
1448
1354
|
if (tracker.completed >= tracker.total) {
|
|
1449
|
-
safeToRemove
|
|
1355
|
+
safeToRemove?.();
|
|
1450
1356
|
}
|
|
1451
1357
|
},
|
|
1452
1358
|
[presenceEnabled, exitLabel, safeToRemove]
|
|
@@ -1455,13 +1361,13 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1455
1361
|
if (hasHover) {
|
|
1456
1362
|
setIsHovered(true);
|
|
1457
1363
|
}
|
|
1458
|
-
onHoverStart
|
|
1364
|
+
onHoverStart?.();
|
|
1459
1365
|
}, [hasHover, onHoverStart]);
|
|
1460
1366
|
const handleHoverEnd = useCallback(() => {
|
|
1461
1367
|
if (hasHover) {
|
|
1462
1368
|
setIsHovered(false);
|
|
1463
1369
|
}
|
|
1464
|
-
onHoverEnd
|
|
1370
|
+
onHoverEnd?.();
|
|
1465
1371
|
}, [hasHover, onHoverEnd]);
|
|
1466
1372
|
const handleTapStart = useCallback((...args) => {
|
|
1467
1373
|
if (hasTap) {
|
|
@@ -1516,7 +1422,6 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1516
1422
|
[hasWrapperExitVariant, handleExitComplete, userOnAnimationComplete]
|
|
1517
1423
|
);
|
|
1518
1424
|
useEffect(() => {
|
|
1519
|
-
var _a3;
|
|
1520
1425
|
if (!hasVariants) return;
|
|
1521
1426
|
if (!resolvedVariants) return;
|
|
1522
1427
|
if (!isPresent) return;
|
|
@@ -1534,7 +1439,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1534
1439
|
setActiveVariant(outName);
|
|
1535
1440
|
return;
|
|
1536
1441
|
}
|
|
1537
|
-
if (!
|
|
1442
|
+
if (!viewportRef.current?.once && resetOnViewportLeaveRef.current) {
|
|
1538
1443
|
const initName = initialVariantRef.current;
|
|
1539
1444
|
if (initName && typeof initName === "string" && vDefs[initName]) {
|
|
1540
1445
|
setActiveVariant(initName);
|
|
@@ -1555,12 +1460,11 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1555
1460
|
isPresent
|
|
1556
1461
|
]);
|
|
1557
1462
|
useEffect(() => {
|
|
1558
|
-
var _a3, _b3;
|
|
1559
1463
|
if (!data || !childElement) return;
|
|
1560
|
-
const liveChildElement =
|
|
1464
|
+
const liveChildElement = containerRef.current?.firstElementChild;
|
|
1561
1465
|
if (!(liveChildElement instanceof HTMLElement)) return;
|
|
1562
1466
|
const splitElements = collectSplitElements(liveChildElement, optionsRef.current);
|
|
1563
|
-
const expectedCounts =
|
|
1467
|
+
const expectedCounts = splitDataLayout?.relations.counts ?? {
|
|
1564
1468
|
chars: 0,
|
|
1565
1469
|
words: 0,
|
|
1566
1470
|
lines: 0
|
|
@@ -1570,25 +1474,32 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1570
1474
|
return;
|
|
1571
1475
|
}
|
|
1572
1476
|
const revert = () => {
|
|
1573
|
-
var _a4;
|
|
1574
1477
|
if (hasRevertedRef.current) return;
|
|
1575
1478
|
hasRevertedRef.current = true;
|
|
1576
1479
|
try {
|
|
1577
|
-
|
|
1480
|
+
onRevertRef.current?.();
|
|
1578
1481
|
} finally {
|
|
1579
1482
|
setData(null);
|
|
1580
1483
|
setIsReady(true);
|
|
1581
1484
|
}
|
|
1582
1485
|
};
|
|
1583
|
-
splitResultRef.current =
|
|
1486
|
+
splitResultRef.current = { ...splitElements, revert };
|
|
1584
1487
|
splitResultVersionRef.current = childTreeVersion;
|
|
1585
1488
|
if (pendingFullResplitRef.current) {
|
|
1586
1489
|
if (onResplitRef.current) {
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1490
|
+
queueMicrotask(() => {
|
|
1491
|
+
const currentChild = containerRef.current?.firstElementChild;
|
|
1492
|
+
if (!(currentChild instanceof HTMLElement)) return;
|
|
1493
|
+
const currentSplitElements = collectSplitElements(
|
|
1494
|
+
currentChild,
|
|
1495
|
+
optionsRef.current
|
|
1496
|
+
);
|
|
1497
|
+
onResplitRef.current?.({
|
|
1498
|
+
chars: currentSplitElements.chars,
|
|
1499
|
+
words: currentSplitElements.words,
|
|
1500
|
+
lines: currentSplitElements.lines,
|
|
1501
|
+
revert
|
|
1502
|
+
});
|
|
1592
1503
|
});
|
|
1593
1504
|
}
|
|
1594
1505
|
pendingFullResplitRef.current = false;
|
|
@@ -1605,9 +1516,8 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1605
1516
|
const promise = normalizeToPromise(callbackResult);
|
|
1606
1517
|
if (promise) {
|
|
1607
1518
|
promise.then(() => {
|
|
1608
|
-
var _a4;
|
|
1609
1519
|
if (hasRevertedRef.current) return;
|
|
1610
|
-
|
|
1520
|
+
splitResultRef.current?.revert();
|
|
1611
1521
|
}).catch(() => {
|
|
1612
1522
|
console.warn("[fetta] Animation rejected, text not reverted");
|
|
1613
1523
|
});
|
|
@@ -1621,28 +1531,23 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1621
1531
|
return void 0;
|
|
1622
1532
|
}, [data, childElement, needsViewport, hasVariants, splitDataLayout, childTreeVersion]);
|
|
1623
1533
|
useEffect(() => {
|
|
1624
|
-
var _a3, _b3, _c2, _d2, _e2, _f2, _g2, _h, _i;
|
|
1625
1534
|
if (!data) return;
|
|
1626
|
-
const observedElement =
|
|
1535
|
+
const observedElement = containerRef.current?.firstElementChild;
|
|
1627
1536
|
if (!(observedElement instanceof HTMLElement)) return;
|
|
1628
1537
|
const { splitChars, splitWords, splitLines } = resolveSplitFlags(
|
|
1629
|
-
|
|
1538
|
+
optionsRef.current?.type
|
|
1630
1539
|
);
|
|
1631
|
-
const supportsKerningUpkeep = !
|
|
1540
|
+
const supportsKerningUpkeep = !optionsRef.current?.disableKerning && (splitChars || splitWords);
|
|
1632
1541
|
if (!supportsKerningUpkeep) return;
|
|
1633
1542
|
const ownerWindow = observedElement.ownerDocument.defaultView;
|
|
1634
|
-
const wordClass =
|
|
1635
|
-
const charClass =
|
|
1636
|
-
const mask =
|
|
1637
|
-
const isolateKerningMeasurement =
|
|
1638
|
-
const readKerningStyleSnapshot = (element) => {
|
|
1639
|
-
var _a4;
|
|
1640
|
-
return `${buildKerningStyleKey(getComputedStyle(element))}|${(_a4 = element.getAttribute("style")) != null ? _a4 : ""}`;
|
|
1641
|
-
};
|
|
1543
|
+
const wordClass = optionsRef.current?.wordClass ?? "split-word";
|
|
1544
|
+
const charClass = optionsRef.current?.charClass ?? "split-char";
|
|
1545
|
+
const mask = optionsRef.current?.mask;
|
|
1546
|
+
const isolateKerningMeasurement = optionsRef.current?.isolateKerningMeasurement;
|
|
1547
|
+
const readKerningStyleSnapshot = (element) => `${buildKerningStyleKey(getComputedStyle(element))}|${element.getAttribute("style") ?? ""}`;
|
|
1642
1548
|
lastKerningStyleKeyRef.current = readKerningStyleSnapshot(observedElement);
|
|
1643
1549
|
const runKerningUpkeep = () => {
|
|
1644
|
-
|
|
1645
|
-
const currentElement = (_a4 = containerRef.current) == null ? void 0 : _a4.firstElementChild;
|
|
1550
|
+
const currentElement = containerRef.current?.firstElementChild;
|
|
1646
1551
|
if (!(currentElement instanceof HTMLElement)) return;
|
|
1647
1552
|
if (!currentElement.isConnected) return;
|
|
1648
1553
|
const nextKerningStyleKey = readKerningStyleSnapshot(currentElement);
|
|
@@ -1684,7 +1589,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1684
1589
|
splitChars,
|
|
1685
1590
|
splitWords,
|
|
1686
1591
|
{
|
|
1687
|
-
disableKerning:
|
|
1592
|
+
disableKerning: optionsRef.current?.disableKerning,
|
|
1688
1593
|
isolateKerningMeasurement,
|
|
1689
1594
|
mask
|
|
1690
1595
|
}
|
|
@@ -1771,25 +1676,23 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1771
1676
|
const shouldRevertOnComplete = hasVariants && !!animateLabel && !whileInViewLabel && !needsViewport && !whileScrollLabel && revertOnComplete;
|
|
1772
1677
|
const pendingRevertRef = useRef(null);
|
|
1773
1678
|
useEffect(() => {
|
|
1774
|
-
var _a3;
|
|
1775
1679
|
if (!shouldRevertOnComplete) {
|
|
1776
1680
|
pendingRevertRef.current = null;
|
|
1777
1681
|
revertTrackerRef.current.total = 0;
|
|
1778
1682
|
revertTrackerRef.current.completed = 0;
|
|
1779
1683
|
return;
|
|
1780
1684
|
}
|
|
1781
|
-
pendingRevertRef.current = animateLabel
|
|
1685
|
+
pendingRevertRef.current = animateLabel ?? null;
|
|
1782
1686
|
const tracker = revertTrackerRef.current;
|
|
1783
1687
|
tracker.total = revertTotalCount;
|
|
1784
1688
|
tracker.completed = 0;
|
|
1785
1689
|
if (revertTotalCount === 0) {
|
|
1786
|
-
|
|
1690
|
+
splitResultRef.current?.revert();
|
|
1787
1691
|
pendingRevertRef.current = null;
|
|
1788
1692
|
}
|
|
1789
1693
|
}, [shouldRevertOnComplete, animateLabel, revertTotalCount]);
|
|
1790
1694
|
const handleRevertComplete = useCallback(
|
|
1791
1695
|
(definition) => {
|
|
1792
|
-
var _a3;
|
|
1793
1696
|
const label = pendingRevertRef.current;
|
|
1794
1697
|
if (!label) return;
|
|
1795
1698
|
if (typeof definition === "string" && definition !== label) {
|
|
@@ -1798,14 +1701,13 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1798
1701
|
const tracker = revertTrackerRef.current;
|
|
1799
1702
|
tracker.completed += 1;
|
|
1800
1703
|
if (tracker.completed >= tracker.total) {
|
|
1801
|
-
|
|
1704
|
+
splitResultRef.current?.revert();
|
|
1802
1705
|
pendingRevertRef.current = null;
|
|
1803
1706
|
}
|
|
1804
1707
|
},
|
|
1805
1708
|
[]
|
|
1806
1709
|
);
|
|
1807
1710
|
useEffect(() => {
|
|
1808
|
-
var _a3;
|
|
1809
1711
|
if (!autoSplit || !containerRef.current) return;
|
|
1810
1712
|
if (!data) return;
|
|
1811
1713
|
const child2 = containerRef.current.firstElementChild;
|
|
@@ -1813,7 +1715,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1813
1715
|
const targets = resolveAutoSplitTargets(child2);
|
|
1814
1716
|
if (targets.length === 0) return;
|
|
1815
1717
|
autoSplitWidthByTargetRef.current = /* @__PURE__ */ new Map();
|
|
1816
|
-
const { splitLines } = resolveSplitFlags(
|
|
1718
|
+
const { splitLines } = resolveSplitFlags(optionsRef.current?.type);
|
|
1817
1719
|
const handleResize = () => {
|
|
1818
1720
|
const currentWidth = resolveAutoSplitWidth(
|
|
1819
1721
|
targets,
|
|
@@ -1894,8 +1796,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1894
1796
|
const promise = normalizeToPromise(callbackResult);
|
|
1895
1797
|
if (revertOnCompleteRef.current && promise) {
|
|
1896
1798
|
promise.then(() => {
|
|
1897
|
-
|
|
1898
|
-
(_a3 = splitResultRef.current) == null ? void 0 : _a3.revert();
|
|
1799
|
+
splitResultRef.current?.revert();
|
|
1899
1800
|
}).catch(() => {
|
|
1900
1801
|
console.warn("[fetta] Animation rejected, text not reverted");
|
|
1901
1802
|
});
|
|
@@ -1924,12 +1825,11 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1924
1825
|
}
|
|
1925
1826
|
}, [isInView, needsViewport, hasVariants]);
|
|
1926
1827
|
useEffect(() => {
|
|
1927
|
-
var _a3, _b3, _c2, _d2, _e2, _f2;
|
|
1928
1828
|
if (!whileScrollLabel) return;
|
|
1929
1829
|
if (!resolvedVariants) return;
|
|
1930
1830
|
if (!splitResultRef.current) return;
|
|
1931
1831
|
if (splitResultVersionRef.current !== childTreeVersion) return;
|
|
1932
|
-
const liveChildElement =
|
|
1832
|
+
const liveChildElement = containerRef.current?.firstElementChild;
|
|
1933
1833
|
if (!(liveChildElement instanceof HTMLElement)) return;
|
|
1934
1834
|
const variantName = whileScrollLabel;
|
|
1935
1835
|
const def = resolvedVariants[variantName];
|
|
@@ -1939,7 +1839,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1939
1839
|
splitResultRef.current,
|
|
1940
1840
|
def,
|
|
1941
1841
|
{ duration: 0, delay: 0 },
|
|
1942
|
-
|
|
1842
|
+
optionsRef.current?.type,
|
|
1943
1843
|
isPresent,
|
|
1944
1844
|
delayScope,
|
|
1945
1845
|
custom,
|
|
@@ -1951,7 +1851,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1951
1851
|
splitResultRef.current,
|
|
1952
1852
|
def,
|
|
1953
1853
|
transition,
|
|
1954
|
-
|
|
1854
|
+
optionsRef.current?.type,
|
|
1955
1855
|
isPresent,
|
|
1956
1856
|
delayScope,
|
|
1957
1857
|
custom
|
|
@@ -1959,10 +1859,10 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1959
1859
|
if (!scrollAnimation) return;
|
|
1960
1860
|
const scrollOpts = scrollProp;
|
|
1961
1861
|
const cleanup = scroll(scrollAnimation, {
|
|
1962
|
-
target:
|
|
1963
|
-
offset: scrollOpts
|
|
1964
|
-
axis: scrollOpts
|
|
1965
|
-
container:
|
|
1862
|
+
target: containerRef.current ?? void 0,
|
|
1863
|
+
offset: scrollOpts?.offset,
|
|
1864
|
+
axis: scrollOpts?.axis,
|
|
1865
|
+
container: scrollOpts?.container?.current ?? void 0
|
|
1966
1866
|
});
|
|
1967
1867
|
return () => {
|
|
1968
1868
|
cleanup();
|
|
@@ -1991,7 +1891,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
1991
1891
|
const focusVariant = hasFocus ? whileFocusLabel : void 0;
|
|
1992
1892
|
const hasWrapperVariants = Object.keys(wrapperVariantsByName).length > 0;
|
|
1993
1893
|
const interactionVariant = isTapped && tapVariant || isFocused && focusVariant || isHovered && hoverVariant || void 0;
|
|
1994
|
-
const displayVariant = interactionVariant
|
|
1894
|
+
const displayVariant = interactionVariant ?? activeVariant;
|
|
1995
1895
|
const shouldInheritVariants = hasOrchestrationVariants || !!whileScrollLabel || hasHover || hasTap || hasFocus || hasWrapperVariants;
|
|
1996
1896
|
const suppressInitialOnResplit = !animateOnResplit && pendingFullResplitRef.current;
|
|
1997
1897
|
const childInitial = suppressInitialOnResplit ? false : shouldInheritVariants || initialLabel === void 0 ? void 0 : initialLabel;
|
|
@@ -2002,11 +1902,10 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2002
1902
|
const wrapperExit = shouldInheritVariants ? exitProp : void 0;
|
|
2003
1903
|
const wrapperTransition = shouldInheritVariants && hasVariants ? reduceMotionActive ? { duration: 0, delay: 0 } : orchestrationTransition : void 0;
|
|
2004
1904
|
function renderNode(node, key) {
|
|
2005
|
-
var _a3;
|
|
2006
1905
|
if (node.type === "text") {
|
|
2007
1906
|
return node.text;
|
|
2008
1907
|
}
|
|
2009
|
-
const props =
|
|
1908
|
+
const props = nodePropsMap?.get(node) ?? attrsToProps(node.attrs);
|
|
2010
1909
|
const renderedChildren = renderNodes(node.children, key);
|
|
2011
1910
|
const isVoidTag = VOID_HTML_TAGS.has(node.tag);
|
|
2012
1911
|
if (node.split) {
|
|
@@ -2018,9 +1917,9 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2018
1917
|
const renderAsMotionSplitNode = hasVariants;
|
|
2019
1918
|
if (!renderAsMotionSplitNode) {
|
|
2020
1919
|
if (isVoidTag) {
|
|
2021
|
-
return createElement(node.tag,
|
|
1920
|
+
return createElement(node.tag, { key, ...props });
|
|
2022
1921
|
}
|
|
2023
|
-
return createElement(node.tag,
|
|
1922
|
+
return createElement(node.tag, { key, ...props }, renderedChildren);
|
|
2024
1923
|
}
|
|
2025
1924
|
const MotionTag = getMotionComponent(node.tag);
|
|
2026
1925
|
const variantsForType = variantsByType[splitType];
|
|
@@ -2037,23 +1936,23 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2037
1936
|
} : void 0;
|
|
2038
1937
|
return createElement(
|
|
2039
1938
|
MotionTag,
|
|
2040
|
-
|
|
2041
|
-
key
|
|
2042
|
-
|
|
1939
|
+
{
|
|
1940
|
+
key,
|
|
1941
|
+
...props,
|
|
2043
1942
|
custom: info,
|
|
2044
1943
|
variants: variantsForType,
|
|
2045
1944
|
initial: childInitial,
|
|
2046
1945
|
animate: childAnimate,
|
|
2047
1946
|
exit: exitProp,
|
|
2048
1947
|
onAnimationComplete: onCompleteHandler
|
|
2049
|
-
}
|
|
1948
|
+
},
|
|
2050
1949
|
renderedChildren
|
|
2051
1950
|
);
|
|
2052
1951
|
}
|
|
2053
1952
|
if (isVoidTag) {
|
|
2054
|
-
return createElement(node.tag,
|
|
1953
|
+
return createElement(node.tag, { key, ...props });
|
|
2055
1954
|
}
|
|
2056
|
-
return createElement(node.tag,
|
|
1955
|
+
return createElement(node.tag, { key, ...props }, renderedChildren);
|
|
2057
1956
|
}
|
|
2058
1957
|
function renderNodes(nodes, keyPrefix) {
|
|
2059
1958
|
return nodes.map(
|
|
@@ -2061,7 +1960,9 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2061
1960
|
);
|
|
2062
1961
|
}
|
|
2063
1962
|
const child = data ? (() => {
|
|
2064
|
-
const childProps =
|
|
1963
|
+
const childProps = {
|
|
1964
|
+
...children.props
|
|
1965
|
+
};
|
|
2065
1966
|
if ("dangerouslySetInnerHTML" in childProps) {
|
|
2066
1967
|
delete childProps.dangerouslySetInnerHTML;
|
|
2067
1968
|
}
|
|
@@ -2070,9 +1971,10 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2070
1971
|
}
|
|
2071
1972
|
return createElement(
|
|
2072
1973
|
children.type,
|
|
2073
|
-
|
|
1974
|
+
{
|
|
1975
|
+
...childProps,
|
|
2074
1976
|
key: `split-${childTreeVersion}`
|
|
2075
|
-
}
|
|
1977
|
+
},
|
|
2076
1978
|
renderNodes(data.nodes, "split")
|
|
2077
1979
|
);
|
|
2078
1980
|
})() : cloneElement(children, {
|
|
@@ -2081,15 +1983,16 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2081
1983
|
const Wrapper = getMotionComponent(Component);
|
|
2082
1984
|
const content = createElement(
|
|
2083
1985
|
Wrapper,
|
|
2084
|
-
|
|
1986
|
+
{
|
|
2085
1987
|
ref: mergedRef,
|
|
2086
|
-
"data-fetta-auto-split-wrapper": "true"
|
|
2087
|
-
|
|
1988
|
+
"data-fetta-auto-split-wrapper": "true",
|
|
1989
|
+
...passthroughWrapperProps,
|
|
2088
1990
|
className,
|
|
2089
|
-
style:
|
|
1991
|
+
style: {
|
|
2090
1992
|
visibility: isReady || !waitForFonts ? "visible" : "hidden",
|
|
2091
|
-
position: "relative"
|
|
2092
|
-
|
|
1993
|
+
position: "relative",
|
|
1994
|
+
...userStyle
|
|
1995
|
+
},
|
|
2093
1996
|
variants: wrapperVariants,
|
|
2094
1997
|
initial: wrapperInitial,
|
|
2095
1998
|
animate: wrapperAnimate,
|
|
@@ -2104,7 +2007,7 @@ var SplitText = forwardRef(function SplitText2(_a, forwardedRef) {
|
|
|
2104
2007
|
onFocus: handleFocus,
|
|
2105
2008
|
onBlur: handleBlur,
|
|
2106
2009
|
onAnimationComplete: handleWrapperAnimationComplete
|
|
2107
|
-
}
|
|
2010
|
+
},
|
|
2108
2011
|
child
|
|
2109
2012
|
);
|
|
2110
2013
|
if (reducedMotion) {
|