Skip to content

Implement splitText#241

Merged
ydaniv merged 16 commits into
masterfrom
splittext-implement
Jun 23, 2026
Merged

Implement splitText#241
ydaniv merged 16 commits into
masterfrom
splittext-implement

Conversation

@ydaniv

@ydaniv ydaniv commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Implement SplitText package

@ameerf-wix ameerf-wix left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went through everything but the tests. Will update after I go through them too.

Comment thread packages/splittext/README.md Outdated
Comment thread packages/splittext/README.md
Comment thread packages/splittext/README.md
Comment thread packages/splittext/README.md Outdated
Comment thread packages/splittext/README.md Outdated
Comment thread packages/splittext/src/wrappers.ts
Comment thread packages/splittext/src/utils.ts Outdated
Comment thread packages/splittext/src/utils.ts
Comment thread packages/splittext/src/utils.ts Outdated
Comment thread packages/splittext/src/utils.ts
Comment thread packages/splittext/README.md Outdated
| Option | Type | Default | Description |
| ------------------ | ---------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------- |
| `type` | `'chars' \| 'words' \| 'lines' \| 'sentences'` or array of those | — | Split eagerly on call instead of lazily |
| `wrapperClass` | `string` or `{ chars?, words?, lines?, sentences? }` | — | Extra CSS class(es) on wrapper spans |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ chars?: string, words?: string, lines?: string, sentences?: string }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

Comment thread packages/splittext/src/splitText.ts
Comment thread packages/splittext/src/splitText.ts Outdated
if (!this._cache.chars) this._compute('chars');
if (this._activeType !== 'chars') this._activate('chars');
return this._cache.chars!;
if (this._domBuilt && this._builtTypes.length >= 2) return this._cache.chars ?? [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that it returns empty array when_domBuilt is true and this._builtTypes is ['lines', 'words'] which kind of breaks the promise of the lazy getters.. From what I understand in the documentation, this getter should recompute the split for chars when this getter is used.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs another review, maybe I allowed this as part of the design.

Comment thread packages/splittext/src/splitText.ts Outdated
Comment on lines +208 to +209
this._detachObservers();
this._resetState();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.revert();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible

Comment thread packages/splittext/src/splitText.ts Outdated
Comment on lines +215 to +217
const merged = this._builtTypes.length
? [...new Set([...this._builtTypes, requested])]
: [requested];

@ameerf-wix ameerf-wix Jun 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.builtTypes is always an array - can't this be simply
const merged = [...new Set([...this._builtTypes, requested])] ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread packages/splittext/src/nestedSplit.ts Outdated
);
}

function mergeSpans(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concatSpansPerType ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggesting this because from the current name I expected to see some clever merging of splitting of different types. The actual code is more like concatenating consecutive split spans

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread packages/splittext/src/nestedSplit.ts Outdated
Comment on lines +210 to +217
if (rest.length === 1 && rest[0] === 'chars') {
mergeSpans(spansByType, nestCharsInsideSpan(wordSpan, options, offsets));
} else {
const inner = buildNestedNodes(innerText, rest, options, offsets);
wordSpan.textContent = '';
wordSpan.append(...inner.nodes);
mergeSpans(spansByType, inner.spansByType);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly the same code as in 184-191

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to remove duplicate code if possible

@ydaniv ydaniv merged commit 8bc392f into master Jun 23, 2026
1 check passed
@ydaniv ydaniv deleted the splittext-implement branch June 23, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants