@windi-ui/tailwind 0.7.1 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,198 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/windi-ui/windi-ui/main/docs/public/logo-lockup.svg" alt="WindiUI" width="292">
3
+ </p>
4
+
5
+ # WindiUI
6
+
7
+ 🚧 under development 🚧
8
+
9
+ WindiUI is a modern, modular, and customizable UI component library designed to work seamlessly with Tailwind CSS. It provides developers with a set of reusable components and utilities to build beautiful and consistent user interfaces efficiently.
10
+
11
+ ## Features
12
+
13
+ - **Core Components**: A collection of essential UI components such as buttons, badges, and cards.
14
+ - **Tailwind Integration**: Utilities and themes tailored for Tailwind CSS.
15
+ - **Customizable**: Easily extend and modify components to fit your design system.
16
+ - **Extensible**: Build your own components and variants with advanced utilities.
17
+ - **Dark mode**: Automatically detect your dark mode config and apply appropriate style.
18
+
19
+ ## Getting Started
20
+
21
+ ### Prerequisites
22
+
23
+ - Node.js (v22 or higher)
24
+ - Tailwind v3/v4
25
+
26
+ ### Installation
27
+
28
+ ```bash
29
+ npm install -D @windi-ui/tailwind
30
+ ```
31
+
32
+ On Tailwind v4, load it from your stylesheet:
33
+
34
+ ```css
35
+ @import "tailwindcss";
36
+ @plugin "@windi-ui/tailwind";
37
+ ```
38
+
39
+ Options go in the `@plugin` block, in a `windiui.config.ts` config file that exports them with `defineConfig`, or in
40
+ a `windiui.plugin.ts` plugin module that exports `windiui({ ... })` and is loaded with `@plugin "./windiui.plugin.ts"`;
41
+ see [Installation](https://windi-ui.github.io/windi-ui/guide/installation) and [Config file and plugin module](https://windi-ui.github.io/windi-ui/reference/config-file).
42
+
43
+ On Tailwind v3, add the plugin to your `tailwind.config.ts` / `tailwind.config.js` file:
44
+
45
+ ```ts
46
+ import type { Config } from 'tailwindcss';
47
+ import windiui from '@windi-ui/tailwind';
48
+
49
+ export default {
50
+ // ...
51
+ plugins: [
52
+ windiui()
53
+ ],
54
+ } satisfies Config;
55
+ ```
56
+
57
+ ### Usage
58
+
59
+ #### Colors
60
+
61
+ WindiUI automatically detect all the colors in your theme and make them available to be used with components and utility classes.
62
+
63
+ First you choose the color you want with `c-*` (e.g. `c-blue`, ...), then apply it with Tailwind class (e.g. `bg-c-800`, ...)
64
+
65
+ ```html
66
+ <div class="c-blue bg-c-800/50 text-c-300 border border-c-500 p-5">Hello World</div>
67
+ ```
68
+
69
+ #### Variants
70
+
71
+ Make your component more flexible by styling it with variant utilities classes, use (`bg-v`, `text-v`, `border-v`, ...) to apply the colors, then use `v-*` to change the style, WindiUI has the following built-in variants styles: `v-default`, `v-solid`, `v-outline`, `v-light`.
72
+
73
+ ```html
74
+ <span class="inline-block c-red v-solid bg-v-soft/60 text-v border border-v py-1 px-2 rounded">Test</span>
75
+ ```
76
+
77
+ #### Components
78
+
79
+ WindiUI comes with a few built-in components (e.g. `btn`, `badge`, ... more to come) that can be styled with `c-*`, `v-*` utilities, some components also support `s-*` utility to control its size.
80
+
81
+ ```html
82
+ <button class="btn v-light c-blue s-lg">
83
+ Primary
84
+ <span class="badge v-solid c-red leading-none rounded-full absolute top-0 start-full -translate-1/2">32</span>
85
+ </button>
86
+ ```
87
+
88
+ You can find more code examples in the [playground](https://github.com/windi-ui/windi-ui/blob/main/playground/vue-tailwindv4/src/App.vue).
89
+
90
+ #### Class names built at runtime
91
+
92
+ Tailwind only emits the classes it finds in your source. A class built at runtime, such as `c-${color}` from a
93
+ component prop, has to be safelisted.
94
+
95
+ On Tailwind v4, add one line to the stylesheet. `safelistSource()` returns the string for your config:
96
+
97
+ ```css
98
+ @source inline("{c-{accent,accent-accent,accent-blue,accent-default,accent-red,blue,default,red},v-{default,light,outline,solid},s-{default,lg,sm,xl,xs}}");
99
+ ```
100
+
101
+ ```ts
102
+ import { safelistSource } from '@windi-ui/tailwind';
103
+
104
+ safelistSource({}, { palettes: ['blue', 'red'] }); // the string above; without `palettes`, every palette of the default theme
105
+ ```
106
+
107
+ On Tailwind v3, `windiui({ safelist: true })` emits every `c-*`, `v-*` and `s-*` class.
108
+
109
+ See [the `safelist` option](https://windi-ui.github.io/windi-ui/reference/options#safelist) for the details.
110
+
111
+ ## Upgrading from 0.7
112
+
113
+ See [Changes in 0.8](https://windi-ui.github.io/windi-ui/changes-0.8). The one thing to check: 0.8 no longer sets the default variant on every
114
+ element with a `*` rule (the new `variantScope` option, default `'element'`). `btn`, `badge` and the `bg-v`,
115
+ `text-v`, `border-v` utilities look the same, but your own CSS that reads a variant variable directly, such as
116
+ `background: var(--wui-v-bg)`, on an element without a `v-*` class no longer gets a value. Either set
117
+ `windiui({ variantScope: 'universal' })` to keep the 0.7 output, or give the rule a variant with
118
+ `@apply v-default v-scope`. A rule that uses `@apply v-*` should also apply `v-scope`, so its children do not
119
+ inherit the variant.
120
+
121
+ ## Documentation
122
+
123
+ The full guide and reference are on [the docs site](https://windi-ui.github.io/windi-ui/guide/introduction), a VitePress site
124
+ in `docs/` with live examples.
125
+ Run it locally with `pnpm build && pnpm docs:dev`.
126
+
127
+ ## Contributing
128
+
129
+ Contributions are welcome! Please submit issues or pull requests.
130
+
131
+ 1. Clone the repository:
132
+
133
+ ```bash
134
+ git clone https://github.com/windi-ui/windi-ui.git
135
+ cd windi-ui
136
+ ```
137
+
138
+ 2. Install dependencies:
139
+
140
+ ```bash
141
+ pnpm install
142
+ ```
143
+
144
+ 3. Start the development server for the playground:
145
+
146
+ ```bash
147
+ pnpm dev
148
+ # or for Tailwind v4
149
+ pnpm devv4
150
+ ```
151
+
152
+ The playgrounds use the built packages. To rebuild them on change, run `pnpm watch` in a second terminal.
153
+
154
+ ### Tests
155
+
156
+ ```bash
157
+ pnpm build # the tests load the built packages
158
+ pnpm test # run once
159
+ pnpm test -u # rewrite the snapshots after an intended change in the output
160
+ ```
161
+
162
+ The tests are in `test/` and run on Vitest.
163
+
164
+ - **Snapshots.** `test/__snapshots__/<fixture>/*.css` hold the CSS the plugin emits on each supported Tailwind:
165
+ `tw3` (3.4, through PostCSS), `tw4.1` (the oldest supported v4, pinned below 4.1.17, where `@variant dark` is
166
+ not expanded yet) and `tw4` (the current v4), both through Tailwind's `compile()`. Each is a package in
167
+ `test/fixtures/` that pins its Tailwind version.
168
+ A change in the output fails the test; if the change is intended, run `pnpm test -u` and commit the
169
+ snapshot diff with the code, so the review shows what changed for users.
170
+ - **Browser.** `test/browser.test.ts` checks what a snapshot cannot: how the CSS cascades and inherits.
171
+ It drives the Chrome or Edge already installed on the machine, and is skipped locally if there is neither.
172
+ - A test file works with one fixture only, because the helper that loads a fixture changes the working directory.
173
+
174
+ ### Project Structure
175
+
176
+ The repository is organized as a monorepo with the following packages:
177
+
178
+ #### Packages
179
+
180
+ - **`windiui-core`**: Contains the core components and utilities.
181
+ - **`windiui-tailwind`**: Tailwind CSS-specific utilities and themes.
182
+
183
+ #### Playgrounds
184
+
185
+ - **`vue-tailwind`**: A Vue 3 project showcasing WindiUI with Tailwind CSS v3.
186
+ - **`vue-tailwindv4`**: Another Vue 3 project demonstrating WindiUI with Tailwind CSS v4.
187
+
188
+ #### Tests
189
+
190
+ - **`test`**: The test harness, with one fixture package per supported Tailwind version in `test/fixtures`.
191
+
192
+ #### Docs
193
+
194
+ - **`docs`**: The VitePress documentation site (`pnpm docs:dev`, `pnpm docs:build`, `pnpm docs:preview`). It loads the built packages, so run `pnpm build` first.
195
+
196
+ ## License
197
+
198
+ This project is licensed under the MIT License. See the [LICENSE](https://github.com/windi-ui/windi-ui/blob/main/LICENSE) file for details.
@@ -0,0 +1,92 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let node_fs = require("node:fs");
3
+ let node_module = require("node:module");
4
+ let node_path = require("node:path");
5
+ let _windi_ui_core = require("@windi-ui/core");
6
+ const require_configState = require("./configState-BnylRpdM.cjs");
7
+ // src/config.ts
8
+ const EXTENSIONS = [
9
+ "ts",
10
+ "mts",
11
+ "cts",
12
+ "js",
13
+ "mjs",
14
+ "cjs",
15
+ "json"
16
+ ];
17
+ const ROOT_MARKERS = [
18
+ "pnpm-workspace.yaml",
19
+ ".git",
20
+ "pnpm-lock.yaml",
21
+ "package-lock.json",
22
+ "yarn.lock",
23
+ "bun.lock",
24
+ "bun.lockb"
25
+ ];
26
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
27
+ const cache = /* @__PURE__ */ new Map();
28
+ const mtime = (file) => (0, node_fs.statSync)(file, { throwIfNoEntry: false })?.mtimeMs;
29
+ function workspaceRoot(cwd) {
30
+ for (let dir = cwd;; dir = (0, node_path.dirname)(dir)) {
31
+ if (ROOT_MARKERS.some((m) => (0, node_fs.existsSync)((0, node_path.join)(dir, m)))) return dir;
32
+ if ((0, node_path.dirname)(dir) === dir) return;
33
+ }
34
+ }
35
+ /**
36
+ * Loads the WindiUI config file: the one `config` names, or else the nearest `windiui.config.{ts,mts,cts,js,mjs,cjs,json}`
37
+ * or `package.json#windiui`, from `cwd` up to the workspace root. Node only.
38
+ */
39
+ function loadWindiUIConfig({ cwd = process.cwd(), config } = {}) {
40
+ const key = `${cwd}\0${config ?? ""}`;
41
+ const cached = cache.get(key);
42
+ if (cached?.result.sources.every((s, i) => mtime(s) === cached.mtimes[i])) return cached.result;
43
+ for (const source of cached?.result.sources ?? []) delete require$1.cache[(0, node_path.resolve)(source)];
44
+ const file = config == null ? void 0 : (0, node_path.resolve)(cwd, config);
45
+ if (file && !(0, node_fs.existsSync)(file)) throw new Error(`WindiUI: config file not found: ${file}`);
46
+ let loadConfigSync;
47
+ try {
48
+ ({loadConfigSync} = require$1("unconfig"));
49
+ } catch (e) {
50
+ if (file || e.code !== "ERR_REQUIRE_ESM") throw e;
51
+ return {
52
+ config: {},
53
+ sources: []
54
+ };
55
+ }
56
+ const root = file ? void 0 : workspaceRoot(cwd);
57
+ const loaded = require_configState.whileLoadingConfig(() => loadConfigSync({
58
+ cwd: file ? (0, node_path.dirname)(file) : cwd,
59
+ stopAt: root && (0, node_path.dirname)(root) !== root ? (0, node_path.dirname)(root) : void 0,
60
+ sources: file ? {
61
+ files: file,
62
+ extensions: [],
63
+ rewrite: require_configState.unwrap
64
+ } : [{
65
+ files: "windiui.config",
66
+ extensions: EXTENSIONS,
67
+ rewrite: require_configState.unwrap
68
+ }, {
69
+ files: "package.json",
70
+ extensions: [],
71
+ rewrite: (pkg) => pkg.windiui
72
+ }]
73
+ }));
74
+ const result = {
75
+ config: loaded.config ?? {},
76
+ sources: loaded.sources
77
+ };
78
+ if (result.sources.length) cache.set(key, {
79
+ result,
80
+ mtimes: result.sources.map(mtime)
81
+ });
82
+ else cache.delete(key);
83
+ return result;
84
+ }
85
+ Object.defineProperty(exports, "defineConfig", {
86
+ enumerable: true,
87
+ get: function() {
88
+ return _windi_ui_core.defineConfig;
89
+ }
90
+ });
91
+ exports.loadWindiUIConfig = loadWindiUIConfig;
92
+
@@ -0,0 +1,18 @@
1
+ import { Config, defineConfig } from "@windi-ui/core";
2
+ export interface LoadConfigOptions {
3
+ /** Where the search starts, and what a relative `config` path is resolved against. Defaults to the working directory. */
4
+ cwd?: string;
5
+ /** Loads this file instead of searching for one. */
6
+ config?: string;
7
+ }
8
+ export interface LoadedConfig {
9
+ config: Config;
10
+ /** The files the config came from; empty when none was found. */
11
+ sources: string[];
12
+ }
13
+ /**
14
+ * Loads the WindiUI config file: the one `config` names, or else the nearest `windiui.config.{ts,mts,cts,js,mjs,cjs,json}`
15
+ * or `package.json#windiui`, from `cwd` up to the workspace root. Node only.
16
+ */
17
+ export declare function loadWindiUIConfig({ cwd, config }?: LoadConfigOptions): LoadedConfig;
18
+ export { type Config, defineConfig };
@@ -0,0 +1,18 @@
1
+ import { Config, defineConfig } from "@windi-ui/core";
2
+ export interface LoadConfigOptions {
3
+ /** Where the search starts, and what a relative `config` path is resolved against. Defaults to the working directory. */
4
+ cwd?: string;
5
+ /** Loads this file instead of searching for one. */
6
+ config?: string;
7
+ }
8
+ export interface LoadedConfig {
9
+ config: Config;
10
+ /** The files the config came from; empty when none was found. */
11
+ sources: string[];
12
+ }
13
+ /**
14
+ * Loads the WindiUI config file: the one `config` names, or else the nearest `windiui.config.{ts,mts,cts,js,mjs,cjs,json}`
15
+ * or `package.json#windiui`, from `cwd` up to the workspace root. Node only.
16
+ */
17
+ export declare function loadWindiUIConfig({ cwd, config }?: LoadConfigOptions): LoadedConfig;
18
+ export { type Config, defineConfig };
@@ -0,0 +1,85 @@
1
+ import { existsSync, statSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { defineConfig } from "@windi-ui/core";
5
+ import { i as whileLoadingConfig, r as unwrap } from "./configState-DfiH-8b9.mjs";
6
+ // src/config.ts
7
+ const EXTENSIONS = [
8
+ "ts",
9
+ "mts",
10
+ "cts",
11
+ "js",
12
+ "mjs",
13
+ "cjs",
14
+ "json"
15
+ ];
16
+ const ROOT_MARKERS = [
17
+ "pnpm-workspace.yaml",
18
+ ".git",
19
+ "pnpm-lock.yaml",
20
+ "package-lock.json",
21
+ "yarn.lock",
22
+ "bun.lock",
23
+ "bun.lockb"
24
+ ];
25
+ const require = createRequire(import.meta.url);
26
+ const cache = /* @__PURE__ */ new Map();
27
+ const mtime = (file) => statSync(file, { throwIfNoEntry: false })?.mtimeMs;
28
+ function workspaceRoot(cwd) {
29
+ for (let dir = cwd;; dir = dirname(dir)) {
30
+ if (ROOT_MARKERS.some((m) => existsSync(join(dir, m)))) return dir;
31
+ if (dirname(dir) === dir) return;
32
+ }
33
+ }
34
+ /**
35
+ * Loads the WindiUI config file: the one `config` names, or else the nearest `windiui.config.{ts,mts,cts,js,mjs,cjs,json}`
36
+ * or `package.json#windiui`, from `cwd` up to the workspace root. Node only.
37
+ */
38
+ function loadWindiUIConfig({ cwd = process.cwd(), config } = {}) {
39
+ const key = `${cwd}\0${config ?? ""}`;
40
+ const cached = cache.get(key);
41
+ if (cached?.result.sources.every((s, i) => mtime(s) === cached.mtimes[i])) return cached.result;
42
+ for (const source of cached?.result.sources ?? []) delete require.cache[resolve(source)];
43
+ const file = config == null ? void 0 : resolve(cwd, config);
44
+ if (file && !existsSync(file)) throw new Error(`WindiUI: config file not found: ${file}`);
45
+ let loadConfigSync;
46
+ try {
47
+ ({loadConfigSync} = require("unconfig"));
48
+ } catch (e) {
49
+ if (file || e.code !== "ERR_REQUIRE_ESM") throw e;
50
+ return {
51
+ config: {},
52
+ sources: []
53
+ };
54
+ }
55
+ const root = file ? void 0 : workspaceRoot(cwd);
56
+ const loaded = whileLoadingConfig(() => loadConfigSync({
57
+ cwd: file ? dirname(file) : cwd,
58
+ stopAt: root && dirname(root) !== root ? dirname(root) : void 0,
59
+ sources: file ? {
60
+ files: file,
61
+ extensions: [],
62
+ rewrite: unwrap
63
+ } : [{
64
+ files: "windiui.config",
65
+ extensions: EXTENSIONS,
66
+ rewrite: unwrap
67
+ }, {
68
+ files: "package.json",
69
+ extensions: [],
70
+ rewrite: (pkg) => pkg.windiui
71
+ }]
72
+ }));
73
+ const result = {
74
+ config: loaded.config ?? {},
75
+ sources: loaded.sources
76
+ };
77
+ if (result.sources.length) cache.set(key, {
78
+ result,
79
+ mtimes: result.sources.map(mtime)
80
+ });
81
+ else cache.delete(key);
82
+ return result;
83
+ }
84
+ export { defineConfig, loadWindiUIConfig };
85
+
@@ -0,0 +1,42 @@
1
+ // src/utils/configState.ts
2
+ /** Set on the plugin `windiui()` returns, so that `safelistSource()` and the config loader also take the plugin a plugin module exports. */
3
+ const CONFIG = Symbol.for("windiui.config");
4
+ /** The config of the options themselves, or of the plugin made from them. */
5
+ const unwrap = (exported) => exported[CONFIG] ?? exported;
6
+ const LOADING = Symbol.for("windiui.config.loading");
7
+ const state = globalThis;
8
+ /** True while a config file is being evaluated: a `windiui()` call made by that file must not look for a config file itself. */
9
+ const isLoadingConfig = () => state[LOADING] === true;
10
+ function whileLoadingConfig(load) {
11
+ state[LOADING] = true;
12
+ try {
13
+ return load();
14
+ } finally {
15
+ state[LOADING] = false;
16
+ }
17
+ }
18
+ Object.defineProperty(exports, "CONFIG", {
19
+ enumerable: true,
20
+ get: function() {
21
+ return CONFIG;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "isLoadingConfig", {
25
+ enumerable: true,
26
+ get: function() {
27
+ return isLoadingConfig;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "unwrap", {
31
+ enumerable: true,
32
+ get: function() {
33
+ return unwrap;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "whileLoadingConfig", {
37
+ enumerable: true,
38
+ get: function() {
39
+ return whileLoadingConfig;
40
+ }
41
+ });
42
+
@@ -0,0 +1,19 @@
1
+ // src/utils/configState.ts
2
+ /** Set on the plugin `windiui()` returns, so that `safelistSource()` and the config loader also take the plugin a plugin module exports. */
3
+ const CONFIG = Symbol.for("windiui.config");
4
+ /** The config of the options themselves, or of the plugin made from them. */
5
+ const unwrap = (exported) => exported[CONFIG] ?? exported;
6
+ const LOADING = Symbol.for("windiui.config.loading");
7
+ const state = globalThis;
8
+ /** True while a config file is being evaluated: a `windiui()` call made by that file must not look for a config file itself. */
9
+ const isLoadingConfig = () => state[LOADING] === true;
10
+ function whileLoadingConfig(load) {
11
+ state[LOADING] = true;
12
+ try {
13
+ return load();
14
+ } finally {
15
+ state[LOADING] = false;
16
+ }
17
+ }
18
+ export { whileLoadingConfig as i, isLoadingConfig as n, unwrap as r, CONFIG as t };
19
+