@nkstack/tailwind-editor-core
v0.2.2
Published
Core Tailwind class parser and serializer for editor tooling
Readme
@nkstack/tailwind-editor-core
Core parser/serializer utilities for Tailwind class strings.
Use this package when you need Tailwind class parsing, state modeling, and deterministic rebuild behavior without the React UI.
Install
pnpm add @nkstack/tailwind-editor-coreWhat it exports
parseTailwindClassesbuildClassStringsplitTopLevelColons,tokenize,hasTopLevelVariant,clampSizeresolveColorHex,COLOR_HEX_MAP- Types:
InspectorState,ParseResult,PreservedClasses,DisplayMode,SpacingKey, and related enums
Example
import {
parseTailwindClasses,
buildClassString,
type InspectorState,
} from "@nkstack/tailwind-editor-core";
const input = "px-4 py-2 text-sm bg-slate-200 sm:px-6 custom-token";
const parsed = parseTailwindClasses(input);
const nextState: InspectorState = {
...parsed.state,
typography: {
...parsed.state.typography,
fontWeight: "semibold",
},
};
const nextClassString = buildClassString(nextState, parsed.preserved);Notes
- This package is framework-agnostic.
- It is versioned in lockstep with
@nkstack/tailwind-editor-react.
License
MIT
