@windi-ui/tailwind 0.7.1 → 0.8.0

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,229 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/windi-ui/windi-ui/main/docs/public/logo-lockup-npm.svg" alt="WindiUI" width="306">
3
+ </p>
4
+
5
+ # WindiUI
6
+
7
+ 🚧 under development 🚧
8
+
9
+ WindiUI is a Tailwind CSS plugin that adds three axes to your classes: a color (`c-*`), a variant (`v-*`) and a size
10
+ (`s-*`). Each one is a class that sets CSS variables, so `btn c-blue v-solid s-lg` is a large, solid, blue button, and
11
+ the same `btn` takes every palette of your theme, in light and dark mode.
12
+
13
+ **[Documentation](https://windi-ui.github.io/windi-ui/guide/introduction)** ·
14
+ [Installation](https://windi-ui.github.io/windi-ui/guide/installation) ·
15
+ [Options](https://windi-ui.github.io/windi-ui/reference/options) ·
16
+ [Builder API](https://windi-ui.github.io/windi-ui/reference/builder) ·
17
+ [Changes in 0.8](https://windi-ui.github.io/windi-ui/changes-0.8)
18
+
19
+ ## Features
20
+
21
+ - **Three axes.** `c-*` picks one of your palettes, `v-*` a variant and `s-*` a size. They combine freely, and colors
22
+ and sizes inherit down the tree.
23
+ - **Calibrated variants.** `default`, `solid`, `outline` and `light` pick shades of the 11-shade palette for the
24
+ background, border and text, with soft, muted and accent levels, a hover state and dark values. A variant can use
25
+ other shades for some colors, such as a darker `solid` yellow.
26
+ - **Presets.** `nuxt-ui` adds `soft`, `subtle`, `ghost` and `link`, with text that passes a contrast of 4.5:1.
27
+ - **Components and utilities.** `btn`, `badge`, `bg-v`, `text-v`, `border-v`, and `apply-v` for your own CSS.
28
+ - **Builder API.** Add, replace, change or remove colors, variants, sizes and components.
29
+ - **Runtime palettes.** A color given by CSS variables follows a theme set at runtime.
30
+ - **Dark mode.** Follows the dark variant of your Tailwind setup, with nothing to configure.
31
+ - **Tailwind v3 and v4**, with the same class names.
32
+
33
+ ## Getting Started
34
+
35
+ ### Prerequisites
36
+
37
+ - Node.js 22 or higher, or 22.12 or higher to load a
38
+ [config file](https://windi-ui.github.io/windi-ui/reference/config-file). The tests run on Node.js 26.
39
+ - Tailwind CSS v3.3 or higher, or v4. The tests run on Tailwind CSS 3.4, 4.1.16 and the current 4.3.
40
+
41
+ ### Installation
42
+
43
+ ```bash
44
+ npm install -D @windi-ui/tailwind
45
+ ```
46
+
47
+ On Tailwind v4, load it from your stylesheet:
48
+
49
+ ```css
50
+ @import "tailwindcss";
51
+ @plugin "@windi-ui/tailwind";
52
+ ```
53
+
54
+ On Tailwind v3, add it to the plugins of your Tailwind config:
55
+
56
+ ```ts
57
+ import type { Config } from 'tailwindcss';
58
+ import windiui from '@windi-ui/tailwind';
59
+
60
+ export default {
61
+ content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
62
+ plugins: [windiui()],
63
+ } satisfies Config;
64
+ ```
65
+
66
+ Options go in the `@plugin` block, in a `windiui.config.ts` config file, or in a plugin module; see
67
+ [Installation](https://windi-ui.github.io/windi-ui/guide/installation) and
68
+ [Options](https://windi-ui.github.io/windi-ui/reference/options).
69
+
70
+ ### Usage
71
+
72
+ ```html
73
+ <button class="btn c-blue v-solid">Save</button>
74
+ <button class="btn c-red v-outline s-sm">Delete</button>
75
+ <button class="btn c-blue v-light s-lg">Inbox <span class="badge c-red v-solid">3</span></button>
76
+ <div class="c-green v-light bg-v text-v border border-v-muted rounded p-4">A box painted by its variant</div>
77
+ <div class="c-amber bg-c-100 text-c-800 p-4">Shades of the current color</div>
78
+ ```
79
+
80
+ A plugin module configures WindiUI with the builder API. This one adds the `nuxt-ui` variants, gives `solid` a darker
81
+ background with yellow, and adds a `c-primary` color whose shades are CSS variables set at runtime:
82
+
83
+ ```ts
84
+ // windiui.plugin.ts
85
+ import windiui from '@windi-ui/tailwind';
86
+
87
+ export default windiui({
88
+ presets: ['nuxt-ui'],
89
+ build: (builder) => builder
90
+ .overrideVariant('solid', 'yellow', { bg: '700', pseudos: { ':hover': { bg: '800' } } })
91
+ .addColor('primary', { vars: '--ui-color-primary' }),
92
+ });
93
+ ```
94
+
95
+ ```css
96
+ @import "tailwindcss";
97
+ @plugin "./windiui.plugin.ts";
98
+ ```
99
+
100
+ ```html
101
+ <button class="btn c-yellow v-solid">Solid yellow, on shade 700</button>
102
+ <button class="btn c-primary v-soft">Soft, in the runtime color</button>
103
+ ```
104
+
105
+ The [guide](https://windi-ui.github.io/windi-ui/guide/introduction) covers each part, with live examples. The
106
+ [playground](https://github.com/windi-ui/windi-ui/blob/main/playground/vue-tailwindv4/src/App.vue) has more.
107
+
108
+ #### Variants and sizes in your own CSS
109
+
110
+ `apply-v` paints the background, border and text from the current variant, at rest and on hover, as `btn` does. A
111
+ list in brackets chooses the properties and the states. The `s-*` classes set size variables that a control of your
112
+ own can read:
113
+
114
+ ```css
115
+ @import "tailwindcss";
116
+ @plugin "@windi-ui/tailwind";
117
+
118
+ .card-action { @apply apply-v; } /* bg, border, text + :hover */
119
+ .tab { @apply apply-v-[bg,text,hover,focus-visible]; } /* chosen properties and states */
120
+ .my-input { /* as tall as a btn of the same size */
121
+ padding: calc(var(--wui-s-spacing-1\.5) - 1px) calc(var(--wui-s-spacing-3) - 1px);
122
+ border: 1px solid;
123
+ font-size: var(--wui-s-text);
124
+ line-height: var(--wui-s-line-height);
125
+ }
126
+ ```
127
+
128
+ | Size variable | Meaning |
129
+ | --- | --- |
130
+ | `--wui-s-spacing-1`, `-1\.5`, `-2`, `-3`, `-4` | Spacing slots |
131
+ | `--wui-s-text`, `--wui-s-line-height` | Font size and line height |
132
+ | `--wui-s-<key>` | A key of your own on a size, such as `height` for an app that wants a fixed control height |
133
+
134
+ The `variantUtilities` option adds color utilities painted from a variant, such as `bg-yellow` with the `solid`
135
+ background of yellow, overrides and dark values included. See
136
+ [Utilities](https://windi-ui.github.io/windi-ui/guide/utilities) and
137
+ [Sizes](https://windi-ui.github.io/windi-ui/guide/sizes).
138
+
139
+ ## Upgrading from 0.7
140
+
141
+ See [Changes in 0.8](https://windi-ui.github.io/windi-ui/changes-0.8#upgrading-from-0-7). The one thing to check: 0.8
142
+ no longer sets the default variant on every element with a `*` rule (the new `variantScope` option, default
143
+ `'element'`). `btn`, `badge` and the `bg-v`, `text-v`, `border-v` utilities look the same, but your own CSS that
144
+ reads a variant variable directly, such as `background: var(--wui-v-bg)`, on an element without a `v-*` class no
145
+ longer gets a value. Either set `windiui({ variantScope: 'universal' })` to keep the 0.7 output, or give the rule a
146
+ variant with `@apply v-default v-scope`. A rule that uses `@apply v-*` should also apply `v-scope`, so its children
147
+ do not inherit the variant.
148
+
149
+ ## Documentation
150
+
151
+ The full guide and reference are on [the docs site](https://windi-ui.github.io/windi-ui/guide/introduction), a VitePress site
152
+ in `docs/` with live examples.
153
+ Run it locally with `pnpm build && pnpm docs:dev`.
154
+
155
+ ## Contributing
156
+
157
+ Contributions are welcome! Please submit issues or pull requests.
158
+
159
+ 1. Clone the repository:
160
+
161
+ ```bash
162
+ git clone https://github.com/windi-ui/windi-ui.git
163
+ cd windi-ui
164
+ ```
165
+
166
+ 2. Install dependencies:
167
+
168
+ ```bash
169
+ pnpm install
170
+ ```
171
+
172
+ 3. Start the development server for the playground:
173
+
174
+ ```bash
175
+ pnpm dev
176
+ # or for Tailwind v4
177
+ pnpm devv4
178
+ ```
179
+
180
+ The playgrounds use the built packages. To rebuild them on change, run `pnpm watch` in a second terminal.
181
+
182
+ ### Tests
183
+
184
+ ```bash
185
+ pnpm build # the tests load the built packages
186
+ pnpm test # run once
187
+ pnpm test -u # rewrite the snapshots after an intended change in the output
188
+ ```
189
+
190
+ The tests are in `test/` and run on Vitest.
191
+
192
+ - **Snapshots.** `test/__snapshots__/<fixture>/*.css` hold the CSS the plugin emits on each supported Tailwind:
193
+ `tw3` (3.4, through PostCSS), `tw4.1` (the oldest supported v4, pinned below 4.1.17, where `@variant dark` is
194
+ not expanded yet) and `tw4` (the current v4), both through Tailwind's `compile()`. Each is a package in
195
+ `test/fixtures/` that pins its Tailwind version.
196
+ A change in the output fails the test; if the change is intended, run `pnpm test -u` and commit the
197
+ snapshot diff with the code, so the review shows what changed for users.
198
+ - **Browser.** `test/browser.test.ts` checks what a snapshot cannot: how the CSS cascades and inherits.
199
+ It drives the Chrome or Edge already installed on the machine, and is skipped locally if there is neither.
200
+ - **README.** `test/readme.ts` compiles every TypeScript sample of this file on each fixture and every CSS sample
201
+ on the Tailwind v4 ones, and checks that the classes of its HTML samples exist. Keep the samples compilable when
202
+ you change them.
203
+ - A test file works with one fixture only, because the helper that loads a fixture changes the working directory.
204
+
205
+ ### Project Structure
206
+
207
+ The repository is organized as a monorepo with the following packages:
208
+
209
+ #### Packages
210
+
211
+ - **`windiui-core`**: Contains the core components and utilities.
212
+ - **`windiui-tailwind`**: Tailwind CSS-specific utilities and themes.
213
+
214
+ #### Playgrounds
215
+
216
+ - **`vue-tailwind`**: A Vue 3 project showcasing WindiUI with Tailwind CSS v3.
217
+ - **`vue-tailwindv4`**: Another Vue 3 project demonstrating WindiUI with Tailwind CSS v4.
218
+
219
+ #### Tests
220
+
221
+ - **`test`**: The test harness, with one fixture package per supported Tailwind version in `test/fixtures`.
222
+
223
+ #### Docs
224
+
225
+ - **`docs`**: The VitePress documentation site (`pnpm docs:dev`, `pnpm docs:build`, `pnpm docs:preview`). It loads the built packages, so run `pnpm build` first.
226
+
227
+ ## License
228
+
229
+ 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
+