This library provides utilities for using css-in-js in Svelte by preprocessing the components and converting to inline styles. This is the basis for a design system that allows for custom styling attributes and element transformations that can be built on top of this library and allow js/typescript to be used for styling to ensure type safety and consistency.
To use this library in your project, simply import the functions you need.
Ensure that you have installed the necessary dependencies, including
svelte/compiler and magic-string.
The threadPreprocessor function creates a Svelte preprocessor group that can
be used in your Svelte configuration.
export function threadPreprocessor(opts: Options): PreprocessorGroup;
To use it, import it and use it in your svelte.config.js file to apply
transformations to your components.
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
import { threadPreprocessor } from "@shopkeep/thread";
const config = {
preprocess: [
vitePreprocess(),
threadPreprocessor({
attributeName: "cs",
elementNames: ["Box", "Flexbox"],
fileIdentifier: "thread",
}),
],
kit: {
adapter: adapter(),
},
};
The Options allows you to configure how the library processes components:
export type Options = {
fileIdentifier?: string;
attributeName: string;
elementNames: string[];
};
.thread.svelte files).cs).Flexbox, Box).TODO comments for adding
features like design system-specific value conversions and improving type
handling.magic-string to simplify AST
modifications while keeping track of offsets.Feel free to contribute by creating pull requests or reporting issues. Improvements to type handling are especially welcome!
This library is licensed under the MIT License.