fetta 1.3.2 → 1.3.4

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.
@@ -580,7 +580,7 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
580
580
  i++;
581
581
  }
582
582
  }
583
- if (splitChars && allWords.length > 0) {
583
+ if (!(options == null ? void 0 : options.disableKerning) && splitChars && allWords.length > 0) {
584
584
  for (const wordSpan of allWords) {
585
585
  const wordChars = Array.from(wordSpan.querySelectorAll(`.${charClass}`));
586
586
  if (wordChars.length < 2) continue;
@@ -640,6 +640,26 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
640
640
  targetElement.style.marginLeft = `${totalKerning}px`;
641
641
  }
642
642
  }
643
+ } else if (!(options == null ? void 0 : options.disableKerning) && splitWords && allWords.length > 1) {
644
+ for (let wordIdx = 1; wordIdx < allWords.length; wordIdx++) {
645
+ if (noSpaceBeforeSet.has(allWords[wordIdx])) continue;
646
+ const prevWord = allWords[wordIdx - 1];
647
+ const currWord = allWords[wordIdx];
648
+ const prevText = prevWord.textContent || "";
649
+ const currText = currWord.textContent || "";
650
+ if (!prevText || !currText) continue;
651
+ const lastChar = prevText[prevText.length - 1];
652
+ const firstChar = currText[0];
653
+ const styles = getComputedStyle(currWord);
654
+ const kerningMap = measureKerning(element, currWord, [lastChar, " ", firstChar], styles);
655
+ let totalKerning = 0;
656
+ if (kerningMap.has(1)) totalKerning += kerningMap.get(1);
657
+ if (kerningMap.has(2)) totalKerning += kerningMap.get(2);
658
+ if (Math.abs(totalKerning) > 0.01 && Math.abs(totalKerning) < 20) {
659
+ const targetElement = (options == null ? void 0 : options.mask) === "words" && currWord.parentElement ? currWord.parentElement : currWord;
660
+ targetElement.style.marginLeft = `${totalKerning}px`;
661
+ }
662
+ }
643
663
  }
644
664
  if (splitLines) {
645
665
  const lineGroups = groupIntoLines(allWords, element);
@@ -785,7 +805,8 @@ function splitText(element, {
785
805
  onResize,
786
806
  onSplit,
787
807
  revertOnComplete = false,
788
- propIndex = false
808
+ propIndex = false,
809
+ disableKerning = false
789
810
  } = {}) {
790
811
  var _a;
791
812
  if (!(element instanceof HTMLElement)) {
@@ -836,7 +857,7 @@ function splitText(element, {
836
857
  splitChars,
837
858
  splitWords,
838
859
  splitLines,
839
- { propIndex, mask, ariaHidden: !trackAncestors }
860
+ { propIndex, mask, ariaHidden: !trackAncestors, disableKerning }
840
861
  );
841
862
  currentChars = chars;
842
863
  currentWords = words;
@@ -911,7 +932,7 @@ function splitText(element, {
911
932
  splitChars,
912
933
  splitWords,
913
934
  splitLines,
914
- { propIndex, mask, ariaHidden: !trackAncestors }
935
+ { propIndex, mask, ariaHidden: !trackAncestors, disableKerning }
915
936
  );
916
937
  currentChars = result.chars;
917
938
  currentWords = result.words;
package/dist/index.d.ts CHANGED
@@ -42,6 +42,10 @@ interface SplitTextOptions {
42
42
  revertOnComplete?: boolean;
43
43
  /** Add CSS custom properties (--char-index, --word-index, --line-index) */
44
44
  propIndex?: boolean;
45
+ /** Skip kerning compensation (no margin adjustments applied).
46
+ * Kerning is naturally lost when splitting into inline-block spans.
47
+ * Use this if you prefer no compensation over imperfect Safari compensation. */
48
+ disableKerning?: boolean;
45
49
  }
46
50
  /**
47
51
  * Result returned by splitText containing arrays of split elements and a revert function.
@@ -108,6 +112,6 @@ interface SplitTextResult {
108
112
  * });
109
113
  * ```
110
114
  */
111
- declare function splitText(element: HTMLElement, { type, charClass, wordClass, lineClass, mask, autoSplit, onResize, onSplit, revertOnComplete, propIndex, }?: SplitTextOptions): SplitTextResult;
115
+ declare function splitText(element: HTMLElement, { type, charClass, wordClass, lineClass, mask, autoSplit, onResize, onSplit, revertOnComplete, propIndex, disableKerning, }?: SplitTextOptions): SplitTextResult;
112
116
 
113
117
  export { type SplitTextOptions, type SplitTextResult, splitText };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { splitText } from './chunk-INF3II55.js';
1
+ export { splitText } from './chunk-BXFBPQNP.js';
package/dist/react.d.ts CHANGED
@@ -10,6 +10,10 @@ interface SplitTextOptions {
10
10
  /** Apply overflow mask wrapper to elements for reveal animations */
11
11
  mask?: "lines" | "words" | "chars";
12
12
  propIndex?: boolean;
13
+ /** Skip kerning compensation (no margin adjustments applied).
14
+ * Kerning is naturally lost when splitting into inline-block spans.
15
+ * Use this if you prefer no compensation over imperfect Safari compensation. */
16
+ disableKerning?: boolean;
13
17
  }
14
18
  interface InViewOptions {
15
19
  /** 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-INF3II55.js';
1
+ import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-BXFBPQNP.js';
2
2
  import { forwardRef, useRef, useCallback, useState, useLayoutEffect, useEffect, isValidElement, cloneElement } from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fetta",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Text splitting library with kerning compensation for animations",
5
5
  "type": "module",
6
6
  "sideEffects": false,