axiom-textkit-ref

charleswiltgen/axiom · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/charleswiltgen/axiom --skill axiom-textkit-ref
0 commentsdiscussion
summary

Complete reference for TextKit 2 covering architecture, migration from TextKit 1, Writing Tools integration, and SwiftUI TextEditor with AttributedString through iOS 26.

skill.md

TextKit 2 Reference

Complete reference for TextKit 2 covering architecture, migration from TextKit 1, Writing Tools integration, and SwiftUI TextEditor with AttributedString through iOS 26.

Architecture

TextKit 2 uses MVC pattern with new classes optimized for correctness, safety, and performance.

Model Layer

NSTextContentManager (abstract)

  • Generates NSTextElement objects from backing store
  • Tracks element ranges within document
  • Default implementation: NSTextContentStorage

NSTextContentStorage

  • Uses NSTextStorage as backing store
  • Automatically divides content into NSTextParagraph elements
  • Generates updated elements when text changes

NSTextElement (abstract)

  • Represents portion of content (paragraph, attachment, custom type)
  • Immutable value semantics
  • Properties cannot change after creation
  • Default implementation: NSTextParagraph

NSTextParagraph

  • Represents single paragraph
  • Contains range within document

Controller Layer

NSTextLayoutManager

  • Replaces TextKit 1's NSLayoutManager
  • NO glyph APIs (abstracts away glyphs entirely)
  • Takes elements, lays out into container, generates layout fragments
  • Always uses noncontiguous layout

NSTextLayoutFragment

  • Immutable layout information for one or more elements
  • Key properties:
    • textLineFragments — array of NSTextLineFragment
    • layoutFragmentFrame — layout bounds within container
    • renderingSurfaceBounds — actual drawing bounds (can exceed frame)

NSTextLineFragment

  • Measurement info for single line of text
  • Used for line counting and geometric queries

View Layer

NSTextViewportLayoutController

  • Source of truth for viewport layout
  • Coordinates visible-only layout
  • Calls delegate methods: willLayout, configureRenderingSurface, didLayout

NSTextContainer

  • Provides geometric information for layout destination
  • Can define exclusion paths (non-rectangular layout)

Object-Based Ranges

NSTextLocation (protocol)

  • Represents single location in text
  • Replaces integer indices
  • Supports structured documents (e.g., DOM with nested elements)

NSTextRange

  • Start and end locations (end is excluded)
  • Can represent nested structure
  • Incompatible with NSRange for non-linear documents

NSTextSelection

  • Contains: granularity, affinity, possibly disjoint ranges
  • Read-only properties
  • Immutable value semantics

NSTextSelectionNavigation

  • Performs actions on selections
  • Returns new NSTextSelection instances
  • Handles bidirectional text correctly

Core Design Principles

1. Correctness — No Glyph APIs

From WWDC 2021:

"TextKit 2 abstracts away glyph handling to provide a consistent experience for international text."

Why no glyphs?

Problem: In scripts like Kannada and Arabic:

  • One glyph can represent multiple characters (ligatures)
  • One character can split into multiple glyphs
  • Glyphs reorder during shaping
  • No correct character→glyph mapping

Example (Kannada word "October"):

  • Character 4 splits into 2 glyphs
  • Glyphs reorder before ligature application
  • Glyph 3 becomes conjoining form and moves below another glyph

Solution: Use NSTextLocation, NSTextRange, NSTextSelection instead of glyph indices.

2. Safety — Value Semantics

Immutable objects:

  • NSTextElement
  • NSTextLayoutFragment
  • NSTextLineFragment
  • NSTextSelection

Benefits:

  • No unintended sharing
  • No side effects from mutations
  • Easier to reason about state

Pattern: To change layout/selection, create new instances with desired changes.

3. Performance — Viewport Layout

Always Noncontiguous: TextKit 2 performs layout only for visible content + overscroll region.

TextKit 1:

  • Optional noncontiguous layout (boolean property)
  • No visibility into layout state
  • Can't control which parts get laid out

TextKit 2:

  • Always noncontiguous
  • Viewport defines visible area
  • Consistent layout info for viewport
  • Notifications for viewport layout updates

Viewport Delegate Methods:

  1. textViewportLayoutControllerWillLayout(_:) — setup before layout
  2. textViewportLayoutController(_:configureRenderingSurfaceFor:) — per fragment
  3. textViewportLayoutControllerDidLayout(_:) — cleanup after layout

Migration from TextKit 1

Key Paradigm Shift

TextKit 1 TextKit 2
Glyphs Elements
NSRange NSTextLocation/NSTextRange
NSLayoutManager NSTextLayoutManager
Glyph APIs NO glyph APIs
Optional noncontiguous Always noncontiguous
NSTextStorage directly Via NSTextContentManager

API Naming Heuristics

From WWDC 2022:

  • .offset in name → TextKit 1
  • .location in name → TextKit 2

NSRange ↔ NSTextRange Conversion

NSRange → NSTextRange:

// UITextView/NSTextView
let nsRange = NSRange(location: 0, length: 10)

// Via content manager
let startLocation = textContentManager.location(
    textContentManager.documentRange.location,
    offsetBy: nsRange.location
)!
let endLocation = textContentManager.location(
    startLocation,
    offsetBy: nsRange.length
)!
let textRange = NSTextRange(location: startLocation, end: endLocation)

NSTextRange → NSRange:

let startOffset = textContentManager.offset(
    from: textContentManager.documentRange.location,
    to: textRange.location
)
let length = textContentManager.offset(
    from: textRange.location,
    to: textRange.endLocation
)
let nsRange = NSRange(location: startOffset, length: length)

Glyph API Replacements

NO direct glyph API equivalents. Must use higher-level structures.

Example (TextKit 1 - counting lines):

// TextKit 1 - iterate glyphs
var lineCount = 0
let glyphRange = layoutManager.glyphRange(for: textContainer)
for glyphIndex in glyphRange.location..<NSMaxRange(glyphRange) {
    let lineRect = layoutManager.lineFragmentRect(
        forGlyphAt: glyphIndex,
        effectiveRange: nil
    )
    // Count unique rects...
}

Replacement (TextKit 2 - enumerate fragments):

// TextKit 2 - enumerate layout fragments
var lineCount = 0
textLayoutManager.enumerateTextLayoutFragments(
    from: textLayoutManager.documentRange.location,
    options: [.ensuresLayout]
) { fragment in
    lineCount += fragment.textLineFragments.count
    return true
}

Compatibility Mode (UITextView/NSTextView)

Automatic Fallback to TextKit 1: Happens when you access .layoutManager property.

Warning (WWDC 2022):

"Accessing textView.layoutManager triggers TK1 fallback"

Once fallback occurs:

  • No automatic way back to TextKit 2
  • Expensive to switch
  • Lose UI state (selection, scroll position)
  • One-way operation

Prevent Fallback:

  1. Check .textLayoutManager first (TextKit 2)
  2. Only access .layoutManager in else clause
  3. Opt out at initialization if TK1 required
// Check TextKit 2 first
if let textLayoutManager = textView.textLayoutManager {
    // TextKit 2 code
} else if let layoutManager = textView.layoutManager {
    // TextKit 1 fallback (old OS versions)
}

Debug Fallback:

  • UIKit: Breakpoint on _UITextViewEnablingCompatibilityMode
  • AppKit: Subscribe to willSwitchToNSLayoutManagerNotification

NSTextView Opt-In (macOS)

Create TextKit 2 NSTextView:

let textLayoutManager = NSTextLayoutManager()
let textContainer = NSTextContainer()
textLayoutManager.textContainer = textContainer

let textView = NSTextView(frame: .zero, textContainer: textContainer)
// textView.textLayoutManager now available

New Convenience Constructor:

// iOS 16+ / macOS 13+
let textView = UITextView(usingTextLayoutManager: true)
let nsTextView = NSTextView(usingTextLayoutManager: true)

Delegate Hooks

NSTextContentStorageDelegate

Customize attributes without modifying storage:

func textContentStorage(
    _ textContentStorage: NSTextContentStorage,
    textParagraphWith range: NSRange
) -> NSTextParagraph? {
    // Modify attributes for display
    var attributedString = textContentStorage.attributedString!
        .attributedSubstring(from: range)

    // Add custom attributes
    if isComment(range) {
        attributedString.addAttribute(
            .foregroundColor,
            value: UIColor.systemIndigo,
            range: NSRange(location: 0, length: attributedString.length)
        )
    }

    return NSTextParagraph(attributedString: attributedString)
}

Filter elements (hide/show content):

func textContentManager(
    _ textContentManager: NSTextContentManager,
    shouldEnumerate textElement: NSTextElement,
    options: NSTextContentManager.EnumerationOptions
) -> Bool {
    // Return false to hide element
    if hideComments && isComment(textElement) 
how to use axiom-textkit-ref

How to use axiom-textkit-ref on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add axiom-textkit-ref
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/charleswiltgen/axiom --skill axiom-textkit-ref

The skills CLI fetches axiom-textkit-ref from GitHub repository charleswiltgen/axiom and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/axiom-textkit-ref

Reload or restart Cursor to activate axiom-textkit-ref. Access the skill through slash commands (e.g., /axiom-textkit-ref) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

User Story & Requirements Generation

Create detailed user stories, acceptance criteria, and feature specs

Example

Generate user stories for 'password reset feature' with acceptance criteria, edge cases, and test scenarios

Reduce spec writing time by 50%, ensure comprehensive coverage

Competitive Analysis

Research competitors, compare features, identify gaps

Example

Analyze 5 competitor products, create feature comparison matrix, suggest differentiation opportunities

Complete competitive research in 2 hours instead of 2 days

Roadmap Prioritization

Evaluate features using frameworks (RICE, ICE, Kano) and create prioritized backlogs

Example

Score 20 feature ideas using RICE framework, generate prioritized roadmap with rationale

Make data-driven prioritization decisions faster

Stakeholder Communication

Draft PRDs, status updates, and stakeholder presentations

Example

Create executive summary of Q3 roadmap, monthly progress report, feature launch announcement

Save 3-5 hours/week on communication overhead

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client
  • Access to product documentation and roadmap tools (Jira, Notion, etc.)
  • Understanding of product management frameworks (RICE, Jobs-to-be-Done, etc.)
  • Stakeholder contact information and communication channels

Time Estimate

30-60 minutes to see productivity improvements

Installation Steps

  1. 1.Install product management skill
  2. 2.Start with user story generation for known feature
  3. 3.Progress to competitive analysis: research 2-3 competitors
  4. 4.Use for roadmap prioritization: apply RICE/ICE scoring
  5. 5.Draft stakeholder communications and refine based on feedback
  6. 6.Build template library for recurring PM tasks
  7. 7.Share effective prompts with product team

Common Pitfalls

  • Not validating competitive research—verify facts before sharing
  • Accepting user stories without involving engineering team
  • Over-relying on frameworks without qualitative judgment
  • Not customizing outputs to company culture and communication style
  • Skipping stakeholder validation of generated requirements

Best Practices

✓ Do

  • +Validate research and competitive analysis with real data
  • +Collaborate with engineering when generating technical requirements
  • +Customize frameworks and templates to your company context
  • +Use skill for first drafts, refine with stakeholder input
  • +Document successful prompt patterns for PM tasks
  • +Combine AI efficiency with human judgment and intuition

✗ Don't

  • Don't publish competitive analysis without fact-checking
  • Don't finalize user stories without engineering review
  • Don't make prioritization decisions solely on AI scoring
  • Don't skip customer validation of generated requirements
  • Don't ignore company-specific context and culture

💡 Pro Tips

  • Provide context: company goals, constraints, customer feedback
  • Ask for alternatives: 'Show 3 ways to prioritize this roadmap'
  • Request stakeholder-specific formatting: 'Executive summary vs. engineering spec'
  • Use skill for 70% generation + 30% customization to company needs

When to Use This

✓ Use When

Use for user story writing, competitive research, roadmap prioritization, stakeholder communication, and PRD drafting. Best for reducing repetitive documentation and research work.

✗ Avoid When

Avoid for strategic product vision (requires deep customer empathy), pricing decisions (needs market and financial expertise), or when face-to-face customer discovery is more valuable than speed.

Learning Path

  1. 1Basic: user stories, feature specs, status updates
  2. 2Intermediate: competitive analysis, prioritization frameworks, PRDs
  3. 3Advanced: product strategy, go-to-market planning, OKR setting
  4. 4Expert: product vision, market positioning, business model innovation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.754 reviews
  • Diya Reddy· Dec 28, 2024

    I recommend axiom-textkit-ref for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Noor Perez· Dec 24, 2024

    We added axiom-textkit-ref from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Sofia Thomas· Dec 24, 2024

    Solid pick for teams standardizing on skills: axiom-textkit-ref is focused, and the summary matches what you get after install.

  • Mia Srinivasan· Dec 20, 2024

    Keeps context tight: axiom-textkit-ref is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Diya Sethi· Dec 20, 2024

    Registry listing for axiom-textkit-ref matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Zaid Abebe· Nov 19, 2024

    axiom-textkit-ref fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Dev Chen· Nov 15, 2024

    axiom-textkit-ref has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Noah Diallo· Nov 11, 2024

    axiom-textkit-ref reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Zaid Iyer· Oct 10, 2024

    axiom-textkit-ref has been reliable in day-to-day use. Documentation quality is above average for community skills.

  • Arya Sanchez· Oct 6, 2024

    axiom-textkit-ref fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

showing 1-10 of 54

1 / 6