A framework-agnostic TypeScript SDK for the Portable Content System, providing intelligent content rendering, payload source selection, and type-safe data models.
- π¨ Framework-Agnostic Rendering: Works with React Native, Vue, React Web, and any UI framework
- π§ Intelligent Content Selection: Automatically selects optimal content sources based on device capabilities
- π Network-Aware Optimization: Adapts content delivery for different network conditions
- π Type-Safe: Full TypeScript support with strict type checking
- π± Capability Detection: Automatic client capability detection (screen size, formats, network)
- π― Content Processing: Advanced content optimization with primary/source/alternatives pattern
- π§ͺ Well-Tested: 95+ tests with comprehensive coverage
- β‘ Performance Focused: Efficient algorithms with minimal bundle size
npm install @portable-content/typescript-sdk
import {
PayloadSourceSelector,
DefaultContentProcessor,
CapabilityDetector,
MockContentFactory
} from '@portable-content/typescript-sdk';
// Detect client capabilities automatically
const detector = new CapabilityDetector();
const capabilities = detector.detectCapabilities();
// Process content for optimal delivery
const processor = new DefaultContentProcessor();
const manifest = MockContentFactory.createContentManifest(); // Or fetch from your API
const optimizedManifest = await processor.processContent(manifest, capabilities);
// Each block now has the best payload source selected for the client
const selector = new PayloadSourceSelector();
const bestSource = selector.selectBestPayloadSource(optimizedManifest.blocks[0], capabilities);
console.log(bestSource); // Best payload source for this client
import { BaseBlockRenderer } from '@portable-content/typescript-sdk';
class MyMarkdownRenderer extends BaseBlockRenderer {
readonly kind = 'markdown';
readonly priority = 1;
async render(block, props, context) {
const payloadSource = this.selectPayloadSource(block, context);
// Render with your framework (React Native, Vue, etc.)
return {
content: renderMarkdownWithMyFramework(payloadSource),
payloadSource
};
}
}
- Node.js 18+
- npm or yarn
# Install dependencies
npm install
# Run type checking
npm run type-check
# Run tests
npm test
# Build the package
npm run build
# Run linting
npm run lint
npm run build
- Build the package for distributionnpm run test
- Run the test suitenpm run test:coverage
- Run tests with coverage reportnpm run lint
- Run ESLintnpm run format
- Format code with Prettiernpm run type-check
- Run TypeScript type checking
This SDK is designed with a modular, framework-agnostic architecture:
-
π¨ Rendering System: Framework-agnostic rendering foundation
VariantSelector
: Intelligent variant selection with network awarenessRendererRegistry
: Priority-based renderer managementContentProcessor
: Content optimization and representation filtering- Base renderer classes for different content types
-
π± Capability Detection: Automatic client capability detection
- Media type support (WebP, AVIF, SVG)
- Screen dimensions and pixel density
- Network conditions (4G, 3G, 2G)
- Interactive features
-
π§ Core Infrastructure:
- Types: Comprehensive TypeScript definitions
- Transport: Abstract transport layer for real-time communication
- Events: Event-driven architecture with lifecycle management
- Validation: Runtime data validation with Zod
- Utils: Common utility functions
- Framework Independence: No UI framework dependencies
- Mock-First Development: Works without backend dependencies
- Extensible Architecture: Easy to add new block types and renderers
- Performance Focused: Efficient algorithms and minimal bundle size
- Type Safety: Full TypeScript support with strict checking
π― Production-Ready Quality: Achieved exceptional test coverage with 87.58% overall coverage and near-perfect coverage for critical components:
- Types/Elements: 100% coverage - Perfect element utilities testing
- Types/Utils: 100% coverage - Complete builder pattern validation
- ElementLifecycleManager: 96.49% coverage - Near-perfect event system
- EventManager: 84.21% coverage - Comprehensive event handling
β 439 Tests Passing: All green with comprehensive coverage of error scenarios, edge cases, and critical paths β Zero Issues: Clean ESLint, perfect TypeScript compilation, production-ready reliability
π¨ Universal Styling System - Framework-agnostic styling with adapter pattern
- β StyleAdapter Interface: Works with any styling system (CSS-in-JS, utility frameworks, native styling)
- β Universal Theme System: Design tokens with colors, spacing, typography, shadows
- β Comprehensive Documentation: Step-by-step guides for any framework or styling system
- β 224 Tests: Extensive test coverage including edge cases and styling system
- β Production Ready: Robust validation, error handling, and performance optimization
π Initial Release - Complete framework-agnostic rendering system
- β Task 5A Complete: Framework-Agnostic Rendering Base
- β 95+ Tests: Comprehensive test coverage
- β Production Ready: Full TypeScript support with strict linting
- β Zero Dependencies: No UI framework lock-in
- Intelligent Variant Selection: Automatically chooses the best content variant
- Network Optimization: Adapts to slow/fast/cellular networks
- Capability Detection: Detects WebP, AVIF, screen size, density
- Content Processing: Representation filtering and optimization
- Extensible Renderers: Easy to add custom block types
π Complete documentation available in the docs/ directory:
- Renderer Guide - Step-by-step guide to building custom renderers for any UI framework
- API Reference - Complete API documentation with all classes and interfaces
- Examples - Real-world usage examples for React Native, Vue, React Web, and more
- Documentation Index - Complete documentation overview
π Project Information:
- CHANGELOG.md - Release notes and version history
- Task 5A Implementation - Detailed technical specification
- llms.txt - LLM-friendly project overview
Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.