fetta 1.1.1 → 1.1.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 +1 -2
- package/dist/{chunk-6EZFFMJ3.js → chunk-WGVCUEOU.js} +16 -16
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -1
- package/dist/react.d.ts +0 -1
- package/dist/react.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,7 +85,6 @@ const result = splitText(element, options);
|
|
|
85
85
|
| `onSplit` | `function` | — | Callback after initial split |
|
|
86
86
|
| `revertOnComplete` | `boolean` | `false` | Auto-revert when animation completes |
|
|
87
87
|
| `propIndex` | `boolean` | `false` | Add CSS custom properties: `--char-index`, `--word-index`, `--line-index` |
|
|
88
|
-
| `willChange` | `boolean` | `false` | Add `will-change: transform, opacity` for performance |
|
|
89
88
|
|
|
90
89
|
#### Return Value
|
|
91
90
|
|
|
@@ -111,7 +110,7 @@ import { SplitText } from 'fetta/react';
|
|
|
111
110
|
| `children` | `ReactElement` | — | Single element to split |
|
|
112
111
|
| `onSplit` | `function` | — | Called after text is split |
|
|
113
112
|
| `onResize` | `function` | — | Called on autoSplit re-split |
|
|
114
|
-
| `options` | `object` | — | Split options (type, classes, mask, propIndex
|
|
113
|
+
| `options` | `object` | — | Split options (type, classes, mask, propIndex) |
|
|
115
114
|
| `autoSplit` | `boolean` | `false` | Re-split on container resize |
|
|
116
115
|
| `revertOnComplete` | `boolean` | `false` | Revert after animation completes |
|
|
117
116
|
| `inView` | `boolean \| InViewOptions` | `false` | Enable viewport detection |
|
|
@@ -259,9 +259,6 @@ function createSpan(className, index, display = "inline-block", options) {
|
|
|
259
259
|
span.style.display = display;
|
|
260
260
|
span.style.position = "relative";
|
|
261
261
|
span.style.textDecoration = "inherit";
|
|
262
|
-
if (options == null ? void 0 : options.willChange) {
|
|
263
|
-
span.style.willChange = "transform, opacity";
|
|
264
|
-
}
|
|
265
262
|
if (options == null ? void 0 : options.ariaHidden) {
|
|
266
263
|
span.setAttribute("aria-hidden", "true");
|
|
267
264
|
}
|
|
@@ -311,7 +308,6 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
311
308
|
measuredWords.forEach((measuredWord, wordIndex) => {
|
|
312
309
|
const wordSpan = createSpan(wordClass, wordIndex, "inline-block", {
|
|
313
310
|
propIndex: options == null ? void 0 : options.propIndex,
|
|
314
|
-
willChange: options == null ? void 0 : options.willChange,
|
|
315
311
|
propName: "word",
|
|
316
312
|
ariaHidden: options == null ? void 0 : options.ariaHidden
|
|
317
313
|
});
|
|
@@ -324,7 +320,6 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
324
320
|
measuredWord.chars.forEach((measuredChar, charIndexInWord) => {
|
|
325
321
|
const charSpan = createSpan(charClass, globalCharIndex, "inline-block", {
|
|
326
322
|
propIndex: options == null ? void 0 : options.propIndex,
|
|
327
|
-
willChange: options == null ? void 0 : options.willChange,
|
|
328
323
|
propName: "char",
|
|
329
324
|
ariaHidden: options == null ? void 0 : options.ariaHidden
|
|
330
325
|
});
|
|
@@ -355,7 +350,6 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
355
350
|
const charIndexInWord = measuredWord.chars.indexOf(measuredChar);
|
|
356
351
|
const charSpan = createSpan(charClass, globalCharIndex, "inline-block", {
|
|
357
352
|
propIndex: options == null ? void 0 : options.propIndex,
|
|
358
|
-
willChange: options == null ? void 0 : options.willChange,
|
|
359
353
|
propName: "char"
|
|
360
354
|
});
|
|
361
355
|
charSpan.textContent = measuredChar.char;
|
|
@@ -462,7 +456,17 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
462
456
|
}
|
|
463
457
|
}
|
|
464
458
|
if (splitChars && allChars.length > 1 && !isSafari) {
|
|
465
|
-
const
|
|
459
|
+
const range = document.createRange();
|
|
460
|
+
const positions = allChars.map((c) => {
|
|
461
|
+
var _a;
|
|
462
|
+
const textNode = c.firstChild;
|
|
463
|
+
if (textNode && textNode.nodeType === Node.TEXT_NODE) {
|
|
464
|
+
range.setStart(textNode, 0);
|
|
465
|
+
range.setEnd(textNode, ((_a = textNode.textContent) == null ? void 0 : _a.length) || 1);
|
|
466
|
+
return range.getBoundingClientRect().left;
|
|
467
|
+
}
|
|
468
|
+
return c.getBoundingClientRect().left;
|
|
469
|
+
});
|
|
466
470
|
for (let i2 = 1; i2 < allChars.length; i2++) {
|
|
467
471
|
const charSpan = allChars[i2];
|
|
468
472
|
const expectedGap = charSpan.dataset.expectedGap;
|
|
@@ -470,10 +474,9 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
470
474
|
const originalGap = parseFloat(expectedGap);
|
|
471
475
|
const currentGap = positions[i2] - positions[i2 - 1];
|
|
472
476
|
const delta = originalGap - currentGap;
|
|
473
|
-
if (Math.abs(delta) < 20) {
|
|
474
|
-
const roundedDelta = Math.round(delta * 100) / 100;
|
|
477
|
+
if (Math.abs(delta) > 0.1 && Math.abs(delta) < 20) {
|
|
475
478
|
const targetElement = (options == null ? void 0 : options.mask) === "chars" && charSpan.parentElement ? charSpan.parentElement : charSpan;
|
|
476
|
-
targetElement.style.marginLeft = `${
|
|
479
|
+
targetElement.style.marginLeft = `${delta}px`;
|
|
477
480
|
}
|
|
478
481
|
delete charSpan.dataset.expectedGap;
|
|
479
482
|
}
|
|
@@ -486,7 +489,6 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
486
489
|
lineGroups.forEach((words, lineIndex) => {
|
|
487
490
|
const lineSpan = createSpan(lineClass, lineIndex, "block", {
|
|
488
491
|
propIndex: options == null ? void 0 : options.propIndex,
|
|
489
|
-
willChange: options == null ? void 0 : options.willChange,
|
|
490
492
|
propName: "line",
|
|
491
493
|
ariaHidden: options == null ? void 0 : options.ariaHidden
|
|
492
494
|
});
|
|
@@ -583,7 +585,6 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
|
|
|
583
585
|
lineGroups.forEach((wrappers, lineIndex) => {
|
|
584
586
|
const lineSpan = createSpan(lineClass, lineIndex, "block", {
|
|
585
587
|
propIndex: options == null ? void 0 : options.propIndex,
|
|
586
|
-
willChange: options == null ? void 0 : options.willChange,
|
|
587
588
|
propName: "line"
|
|
588
589
|
});
|
|
589
590
|
allLines.push(lineSpan);
|
|
@@ -625,8 +626,7 @@ function splitText(element, {
|
|
|
625
626
|
onResize,
|
|
626
627
|
onSplit,
|
|
627
628
|
revertOnComplete = false,
|
|
628
|
-
propIndex = false
|
|
629
|
-
willChange = true
|
|
629
|
+
propIndex = false
|
|
630
630
|
} = {}) {
|
|
631
631
|
var _a;
|
|
632
632
|
if (!(element instanceof HTMLElement)) {
|
|
@@ -681,7 +681,7 @@ function splitText(element, {
|
|
|
681
681
|
splitChars,
|
|
682
682
|
splitWords,
|
|
683
683
|
splitLines,
|
|
684
|
-
{ propIndex,
|
|
684
|
+
{ propIndex, mask, ariaHidden: !trackAncestors }
|
|
685
685
|
);
|
|
686
686
|
currentChars = chars;
|
|
687
687
|
currentWords = words;
|
|
@@ -759,7 +759,7 @@ function splitText(element, {
|
|
|
759
759
|
splitChars,
|
|
760
760
|
splitWords,
|
|
761
761
|
splitLines,
|
|
762
|
-
{ propIndex,
|
|
762
|
+
{ propIndex, mask, ariaHidden: !trackAncestors }
|
|
763
763
|
);
|
|
764
764
|
currentChars = result.chars;
|
|
765
765
|
currentWords = result.words;
|
package/dist/index.d.ts
CHANGED
|
@@ -42,8 +42,6 @@ interface SplitTextOptions {
|
|
|
42
42
|
revertOnComplete?: boolean;
|
|
43
43
|
/** Add CSS custom properties (--char-index, --word-index, --line-index) */
|
|
44
44
|
propIndex?: boolean;
|
|
45
|
-
/** Add will-change: transform, opacity to split elements for better animation performance (default: true) */
|
|
46
|
-
willChange?: boolean;
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
47
|
* Result returned by splitText containing arrays of split elements and a revert function.
|
|
@@ -110,6 +108,6 @@ interface SplitTextResult {
|
|
|
110
108
|
* });
|
|
111
109
|
* ```
|
|
112
110
|
*/
|
|
113
|
-
declare function splitText(element: HTMLElement, { type, charClass, wordClass, lineClass, mask, autoSplit, onResize, onSplit, revertOnComplete, propIndex,
|
|
111
|
+
declare function splitText(element: HTMLElement, { type, charClass, wordClass, lineClass, mask, autoSplit, onResize, onSplit, revertOnComplete, propIndex, }?: SplitTextOptions): SplitTextResult;
|
|
114
112
|
|
|
115
113
|
export { type SplitTextOptions, type SplitTextResult, splitText };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { splitText } from './chunk-
|
|
1
|
+
export { splitText } from './chunk-WGVCUEOU.js';
|
package/dist/react.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ interface SplitTextOptions {
|
|
|
10
10
|
/** Apply overflow mask wrapper to elements for reveal animations */
|
|
11
11
|
mask?: "lines" | "words" | "chars";
|
|
12
12
|
propIndex?: boolean;
|
|
13
|
-
willChange?: boolean;
|
|
14
13
|
}
|
|
15
14
|
interface InViewOptions {
|
|
16
15
|
/** How much of the element must be visible (0-1). Default: 0 */
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-
|
|
1
|
+
import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-WGVCUEOU.js';
|
|
2
2
|
import { forwardRef, useRef, useCallback, useState, useLayoutEffect, useEffect, isValidElement, cloneElement } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
|