fetta 1.3.0 → 1.3.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.
@@ -368,6 +368,7 @@ function collectTextStructure(element, trackAncestors) {
368
368
  for (const grapheme of graphemes) {
369
369
  if (grapheme === " " || grapheme === "\n" || grapheme === " ") {
370
370
  pushWord();
371
+ noSpaceBeforeNext = false;
371
372
  continue;
372
373
  }
373
374
  currentWord.push({ char: grapheme, ancestors });
@@ -617,6 +618,28 @@ function performSplit(element, measuredWords, charClass, wordClass, lineClass, s
617
618
  }
618
619
  }
619
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
+ }
620
643
  }
621
644
  if (splitLines) {
622
645
  const lineGroups = groupIntoLines(allWords, element);
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { splitText } from './chunk-Q2D5AQBW.js';
1
+ export { splitText } from './chunk-INF3II55.js';
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-Q2D5AQBW.js';
1
+ import { splitText, __spreadProps, __spreadValues, normalizeToPromise } from './chunk-INF3II55.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.0",
3
+ "version": "1.3.2",
4
4
  "description": "Text splitting library with kerning compensation for animations",
5
5
  "type": "module",
6
6
  "sideEffects": false,