Skip to content

Update splittext plan with CSS, a11y, SEO, BiDi, nesting, and line detection amendments#132

Open
tombigel wants to merge 5 commits intomasterfrom
tombigel/splittext-plan-revisions
Open

Update splittext plan with CSS, a11y, SEO, BiDi, nesting, and line detection amendments#132
tombigel wants to merge 5 commits intomasterfrom
tombigel/splittext-plan-revisions

Conversation

@tombigel
Copy link
Contributor

  • 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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

  • SplitTextResult is typed as returning HTMLSpanElement[], but the implementation sketch (cache + getters + _performSplit) uses HTMLElement[]. This should be consistent (ideally HTMLSpanElement[] 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.

tombigel and others added 2 commits February 23, 2026 14:18
Co-authored-by: Cursor <cursoragent@cursor.com>
…iv, HTMLSpanElement types, doc numbering

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

tombigel and others added 2 commits February 24, 2026 11:39
…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>
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