Update splittext plan with CSS, a11y, SEO, BiDi, nesting, and line detection amendments#132
Open
Update splittext plan with CSS, a11y, SEO, BiDi, nesting, and line detection amendments#132
Conversation
Contributor
tombigel
commented
Feb 23, 2026
- Add base CSS strategy (injectStyles, space handling, direction detection)
- Simplify ARIA to container-level only
- Add SEO strategy with preserveText visually-hidden duplicate
- Add BiDi/shaping injection options (bidiResolver, shaper)
- Add nested option (flatten/preserve/depth) for DOM structure control
- Make line detection opt-in and note binary-search algorithm improvement
- Add Safari whitespace normalization test results and Playwright test case
…tection amendments - Add base CSS strategy (injectStyles, space handling, direction detection) - Simplify ARIA to container-level only - Add SEO strategy with preserveText visually-hidden duplicate - Add BiDi/shaping injection options (bidiResolver, shaper) - Add nested option (flatten/preserve/depth) for DOM structure control - Make line detection opt-in and note binary-search algorithm improvement - Add Safari whitespace normalization test results and Playwright test case Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Updates the SplitText package implementation plan to incorporate new strategies for base CSS injection, accessibility/SEO handling, BiDi/shaping extensibility, nested DOM handling, and opt-in line detection (including Safari/WebKit whitespace quirks and a Playwright test case).
Changes:
- Makes line detection explicitly opt-in and documents a more efficient binary-search-based approach.
- Adds plan-level API/options for CSS injection, preserveText for SEO/a11y, nested DOM handling, and BiDi/shaping injection points.
- Expands testing/documentation sections (Safari whitespace normalization notes + Playwright test case, wrapper/CSS guidance).
Comments suppressed due to low confidence (1)
.cursor/plans/text_splitter_package_1eeee927.plan.md:850
SplitTextResultis typed as returningHTMLSpanElement[], but the implementation sketch (cache + getters +_performSplit) usesHTMLElement[]. This should be consistent (ideallyHTMLSpanElement[]everywhere, since wrappers are spans), otherwise the public API typing and internals will diverge.
private _cache: {
chars?: HTMLElement[];
words?: HTMLElement[];
lines?: HTMLElement[];
sentences?: HTMLElement[];
} = {};
constructor(element: HTMLElement, options?: SplitTextOptions) {
this._element = element;
this._originalHTML = element.innerHTML;
// Eager split if type is provided; track whether 'lines' was requested (lines are opt-in and expensive)
this._linesRequested = false;
if (options?.type) {
const types = Array.isArray(options.type) ? options.type : [options.type];
this._linesRequested = types.includes('lines');
for (const type of types) {
this._performSplit(type);
}
}
}
// Lazy getter - split on first access, return cached thereafter
get chars(): HTMLElement[] {
if (!this._cache.chars) {
this._cache.chars = this._performSplit('chars');
}
return this._cache.chars;
}
get words(): HTMLElement[] {
if (!this._cache.words) {
this._cache.words = this._performSplit('words');
}
return this._cache.words;
}
get lines(): HTMLElement[] {
if (!this._linesRequested) return []; // or throw with message: "Lines not requested; pass type: 'lines' or type: [..., 'lines']"
if (!this._cache.lines) {
this._cache.lines = this._performSplit('lines');
}
return this._cache.lines;
}
get sentences(): HTMLElement[] {
if (!this._cache.sentences) {
this._cache.sentences = this._performSplit('sentences');
}
return this._cache.sentences;
}
private _performSplit(type: 'chars' | 'words' | 'lines' | 'sentences'): HTMLElement[] {
// Actual splitting logic - creates wrapper elements in DOM
// Returns array of created HTMLElements
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Cursor <cursoragent@cursor.com>
…iv, HTMLSpanElement types, doc numbering Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 20 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…requirements - Fix revert() prose, test locator, _handleResize options, remove splitBy/preserveWhitespace - Add Intl.Segmenter browser requirement + polyfill note - BiDi: external plugin API; remove shaper; shaped-languages note - Line detection: binary search pseudocode, naive example, heightTracker fix - Nested: clarify flatten deeper than N with example - Minor: aria inner div, line detection string[] note, numbered lists, Prettier Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.