fetta 1.3.1 → 1.3.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.
@@ -618,6 +618,48 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
618
618
  }
619
619
  }
620
620
  }
621
+ for (let wordIdx = 1; wordIdx < allWords.length; wordIdx++) {
622
+ if (noSpaceBeforeSet.has(allWords[wordIdx])) continue;
623
+ const prevWord = allWords[wordIdx - 1];
624
+ const currWord = allWords[wordIdx];
625
+ const prevChars = Array.from(prevWord.querySelectorAll(`.${charClass}`));
626
+ const currChars = Array.from(currWord.querySelectorAll(`.${charClass}`));
627
+ if (prevChars.length === 0 || currChars.length === 0) continue;
628
+ const lastCharSpan = prevChars[prevChars.length - 1];
629
+ const firstCharSpan = currChars[0];
630
+ const lastChar = lastCharSpan.textContent || "";
631
+ const firstChar = firstCharSpan.textContent || "";
632
+ if (!lastChar || !firstChar) continue;
633
+ const styles = getComputedStyle(firstCharSpan);
634
+ const kerningMap = measureKerning(element, firstCharSpan, [lastChar, " ", firstChar], styles);
635
+ let totalKerning = 0;
636
+ if (kerningMap.has(1)) totalKerning += kerningMap.get(1);
637
+ if (kerningMap.has(2)) totalKerning += kerningMap.get(2);
638
+ if (Math.abs(totalKerning) > 0.01 && Math.abs(totalKerning) < 20) {
639
+ const targetElement = (options == null ? void 0 : options.mask) === "chars" && firstCharSpan.parentElement ? firstCharSpan.parentElement : firstCharSpan;
640
+ targetElement.style.marginLeft = `${totalKerning}px`;
641
+ }
642
+ }
643
+ } else if (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
+ }
621
663
  }
622
664
  if (splitLines) {
623
665
  const lineGroups = groupIntoLines(allWords, element);
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { splitText } from './chunk-SGSZGY77.js';
1
+ export { splitText } from './chunk-RJ7GQ53Y.js';
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-SGSZGY77.js';
1
+ import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-RJ7GQ53Y.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.1",
3
+ "version": "1.3.3",
4
4
  "description": "Text splitting library with kerning compensation for animations",
5
5
  "type": "module",
6
6
  "sideEffects": false,