ReviewOS

also looking at this

stacks/ts-css

Merge @stacksjs/ts-css into this repo as packages/toolkit

#27
Merged glennmichael123 wants to merge merge/ts-css-toolkit into main
128 files +9797 -201
docs/features/typescript.mdmodified+25-25
Changes to docs/features/typescript.md
@@ -8,7 +8,7 @@ Use TypeScript for your configuration file to get autocompletion and type checki
88
99```typescript
1010// css.config.ts
11import type { TsCssOptions } from 'ts-css'
11import type { TsCssOptions } from '@ts-css/core'
1212
1313const config = {
1414 content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
@@ -31,7 +31,7 @@ export default config
3131```## Type Checking
3232
3333The`satisfies`keyword provides type checking while preserving literal types:```typescript
34import type { TsCssOptions } from 'ts-css'
34import type { TsCssOptions } from '@ts-css/core'
3535
3636// ✅ Type-safe with autocompletion
3737const config = {
@@ -107,7 +107,7 @@ Get IntelliSense and autocompletion in your IDE:
1071071. Install the TypeScript extension (comes pre-installed)
1081082. Create`css.config.ts`with the type import:```typescript
109109
110import type { TsCssOptions } from 'ts-css'
110import type { TsCssOptions } from '@ts-css/core'
111111
112112const config = {
113113 // Press Ctrl+Space here for autocompletion
@@ -161,8 +161,8 @@ const config = {
161161
162162### Build Function```typescript
163163
164import type { BuildResult, TsCssConfig } from 'ts-css'
165import { build } from 'ts-css'
164import type { BuildResult, TsCssConfig } from '@ts-css/core'
165import { build } from '@ts-css/core'
166166
167167const result: BuildResult = await build({
168168 content: ['./src/**/*.tsx'],
@@ -185,7 +185,7 @@ interface BuildResult {
185185}
186186
187187```### Using with async/await```typescript
188import { build, buildAndWrite } from 'ts-css'
188import { build, buildAndWrite } from '@ts-css/core'
189189
190190async function buildStyles() {
191191 // With build
@@ -207,7 +207,7 @@ async function buildStyles() {
207207```## Custom Rules with Types
208208
209209Define type-safe custom rules:```typescript
210import type { CustomRule, TsCssConfig } from 'ts-css'
210import type { CustomRule, TsCssConfig } from '@ts-css/core'
211211
212212const customRules: CustomRule[] = [
213213 // Pattern and handler with types
@@ -229,7 +229,7 @@ const config = {
229229```## Preset Types
230230
231231Create type-safe presets:```typescript
232import type { Preset, Theme } from 'ts-css'
232import type { Preset, Theme } from '@ts-css/core'
233233
234234const myPreset: Preset = {
235235 name: 'my-design-system',
@@ -264,7 +264,7 @@ const config = {
264264### Custom Theme Values
265265
266266Extend the theme with custom properties:```typescript
267import type { TsCssOptions, Theme } from 'ts-css'
267import type { TsCssOptions, Theme } from '@ts-css/core'
268268
269269interface CustomTheme extends Theme {
270270 customSpacing: Record<string, string>
@@ -286,7 +286,7 @@ const config = {
286286```### Custom Config
287287
288288Create a custom config interface:```typescript
289import type { TsCssOptions } from 'ts-css'
289import type { TsCssOptions } from '@ts-css/core'
290290
291291interface MyConfig extends Partial<TsCssConfig> {
292292 // Add custom properties
@@ -310,7 +310,7 @@ const config: MyConfig = {
310310```## Type Guards
311311
312312Use type guards for runtime type checking:```typescript
313import type { TsCssOptions } from 'ts-css'
313import type { TsCssOptions } from '@ts-css/core'
314314
315315function isValidConfig(config: unknown): config is TsCssConfig {
316316 return (
@@ -333,7 +333,7 @@ if (isValidConfig(config)) {
333333```## Generics
334334
335335Use generics for flexible, type-safe functions:```typescript
336import type { TsCssOptions } from 'ts-css'
336import type { TsCssOptions } from '@ts-css/core'
337337
338338function createConfig<T extends Partial<TsCssConfig>>(config: T): T {
339339 return {
@@ -356,12 +356,12 @@ const config = createConfig({
356356
357357Extend ts-css types globally:```typescript
358358// Now use in config
359import type { TsCssOptions } from 'ts-css'
359import type { TsCssOptions } from '@ts-css/core'
360360
361361// types/ts-css.d.ts
362import 'ts-css'
362import '@ts-css/core'
363363
364declare module 'ts-css' {
364declare module '@ts-css/core' {
365365 interface TsCssConfig {
366366 // Add your custom properties
367367 customFeature?: {
@@ -392,8 +392,8 @@ const config = {
392392
393393### Vite```typescript
394394
395import type { TsCssOptions } from 'ts-css'
396import { build } from 'ts-css'
395import type { TsCssOptions } from '@ts-css/core'
396import { build } from '@ts-css/core'
397397// vite.config.ts
398398import { defineConfig } from 'vite'
399399
@@ -415,10 +415,10 @@ export default defineConfig({
415415})
416416```### Next.js```typescript
417417
418import type { TsCssOptions } from 'ts-css'
418import type { TsCssOptions } from '@ts-css/core'
419419// next.config.ts
420420import type { NextConfig } from 'next'
421import { buildAndWrite } from 'ts-css'
421import { buildAndWrite } from '@ts-css/core'
422422
423423const tsCssConfig: TsCssConfig = {
424424 content: ['./src/**/*.tsx', './app/**/*.tsx'],
@@ -446,7 +446,7 @@ import type {
446446 ParsedClass,
447447 Preset,
448448 Theme,
449} from 'ts-css'
449} from '@ts-css/core'
450450
451451// Extract specific types
452452type ConfigColors = Theme['colors']
@@ -460,10 +460,10 @@ type PartialTheme = Partial<Theme>
460460### 1. Always Use Type Imports```typescript
461461
462462// ✅ Type-only import
463import type { TsCssOptions } from 'ts-css'
463import type { TsCssOptions } from '@ts-css/core'
464464
465465// ❌ Value import (unnecessary)
466import { TsCssConfig } from 'ts-css'
466import { TsCssConfig } from '@ts-css/core'
467467
468468```### 2. Use`satisfies`for Validation```typescript
469469// ✅ Validates types while preserving literals
@@ -478,7 +478,7 @@ const config: Partial<TsCssConfig> = {
478478```### 3. Separate Type Definitions```typescript
479479
480480// types/ts-css.ts
481import type { TsCssOptions, Preset } from 'ts-css'
481import type { TsCssOptions, Preset } from '@ts-css/core'
482482
483483// css.config.ts
484484import type { MyConfig } from './types/ts-css'
@@ -528,14 +528,14 @@ bun add --dev typescript
528528
529529# Ensure types are imported
530530
531import type { TsCssOptions } from 'ts-css'
531import type { TsCssOptions } from '@ts-css/core'
532532
533533```### Autocomplete Not Working**Problem:**No autocompletion in IDE**Solutions:**1. Restart TypeScript server
534534
5355352. Check tsconfig.json includes the config file
5365363. Ensure proper imports:```typescript
537537
538 import type { TsCssOptions } from 'ts-css'
538 import type { TsCssOptions } from '@ts-css/core'
539539 ```
540540
541541## Related*[Configuration](../config.md) - Full configuration guide*[Custom Rules](../advanced/custom-rules.md) - Creating custom utilities*[Presets](../advanced/presets.md) - Reusable configurations*[API Reference](../api-reference.md) - Programmatic API