tailwind-style-sheets 0.0.2 → 0.0.3

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  # tailwind-style-sheets
2
2
 
3
- Co-locate Tailwind class maps alongside components using `.twss` files a CSS-like syntax that pairs with a Turbopack loader and Next.js plugin.
3
+ Use standard CSS class names in your components `.twss` files map them to Tailwind utilities at build time.
4
4
 
5
5
  ## What it does
6
6
 
7
- `.twss` files use a CSS-like syntax to define named Tailwind class groups. Each class can be written on its own line — this is the preferred style as it keeps diffs clean and classes easy to scan:
7
+ Define your class names and their Tailwind mappings in `.twss` files using familiar CSS syntax with `@apply`:
8
8
 
9
9
  ```css
10
10
  /* Button.styles.twss */
@@ -76,9 +76,10 @@ This scaffolds all required files and installs the package.
76
76
  npm install tailwind-style-sheets
77
77
  ```
78
78
 
79
- ### `next.config.ts`
79
+ ### Next.js (Turbopack)
80
80
 
81
81
  ```ts
82
+ // next.config.ts
82
83
  import type { NextConfig } from "next";
83
84
  import path from "path";
84
85
  import { withTwssPlugin } from "tailwind-style-sheets";
@@ -100,6 +101,22 @@ export default withTwssPlugin(nextConfig, {
100
101
 
101
102
  Both options are optional. Omitting them disables the HMR watcher (the loader still works).
102
103
 
104
+ ### Vite
105
+
106
+ ```ts
107
+ // vite.config.ts
108
+ import { defineConfig } from "vite";
109
+ import react from "@vitejs/plugin-react";
110
+ import tailwindcss from "@tailwindcss/vite";
111
+ import { twssVitePlugin } from "tailwind-style-sheets/vite";
112
+
113
+ export default defineConfig({
114
+ plugins: [react(), tailwindcss(), twssVitePlugin()],
115
+ });
116
+ ```
117
+
118
+ The Vite plugin transforms `.twss` files and handles HMR automatically — no additional options needed.
119
+
103
120
  ### TypeScript
104
121
 
105
122
  Add a declaration file so TypeScript knows `.twss` imports return `Record<string, string>`:
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
21
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
22
+ }) : x)(function(x) {
23
+ if (typeof require !== "undefined") return require.apply(this, arguments);
24
+ throw Error('Dynamic require of "' + x + '" is not supported');
25
+ });
26
+
27
+ export {
28
+ __spreadValues,
29
+ __spreadProps,
30
+ __require
31
+ };
@@ -0,0 +1,38 @@
1
+ import { NextConfig } from 'next';
2
+ import { modcn } from 'modcn';
3
+
4
+ interface TwssPluginOptions {
5
+ /**
6
+ * Absolute path to your global CSS file (e.g. `src/app/globals.css`).
7
+ * Touched on `.twss` file changes to trigger Tailwind's class scan and HMR.
8
+ */
9
+ globalsCSS?: string;
10
+ /**
11
+ * Directory to watch recursively for `.twss` file changes.
12
+ * Only active in `development`. Omit to disable the HMR watcher.
13
+ */
14
+ watchDir?: string;
15
+ }
16
+ /**
17
+ * Next.js plugin that enables `.twss` file imports as Tailwind class maps.
18
+ *
19
+ * Registers the Turbopack loader for `*.twss` files and, in development,
20
+ * watches `watchDir` for changes — touching `globalsCSS` on each change
21
+ * so Next.js re-runs Tailwind's class scan and hot-reloads styles.
22
+ *
23
+ * @example
24
+ * // next.config.ts
25
+ * import path from "path";
26
+ * import { withTwssPlugin } from "tailwind-style-sheets";
27
+ *
28
+ * export default withTwssPlugin({}, {
29
+ * globalsCSS: path.resolve(__dirname, "src/app/globals.css"),
30
+ * watchDir: path.resolve(__dirname, "src"),
31
+ * });
32
+ */
33
+ declare function withTwssPlugin(nextConfig: NextConfig, options?: TwssPluginOptions): NextConfig;
34
+
35
+ type StylesMap = Record<string, string>;
36
+ declare function twcn(styles: StylesMap): (...inputs: Parameters<ReturnType<typeof modcn>>) => string;
37
+
38
+ export { type TwssPluginOptions, twcn, withTwssPlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,42 @@
1
+ import {
2
+ __require,
3
+ __spreadProps,
4
+ __spreadValues
5
+ } from "./chunk-OFTF64MC.mjs";
6
+
7
+ // src/plugin.ts
8
+ import fs from "fs";
9
+ function withTwssPlugin(nextConfig, options = {}) {
10
+ var _a;
11
+ const { globalsCSS, watchDir } = options;
12
+ if (process.env.NODE_ENV === "development" && globalsCSS && watchDir) {
13
+ fs.watch(watchDir, { recursive: true }, (_, filename) => {
14
+ if (filename == null ? void 0 : filename.endsWith(".twss")) {
15
+ const now = /* @__PURE__ */ new Date();
16
+ fs.utimesSync(globalsCSS, now, now);
17
+ }
18
+ });
19
+ }
20
+ return __spreadProps(__spreadValues({}, nextConfig), {
21
+ turbopack: __spreadProps(__spreadValues({}, nextConfig.turbopack), {
22
+ rules: __spreadProps(__spreadValues({}, (_a = nextConfig.turbopack) == null ? void 0 : _a.rules), {
23
+ "*.twss": {
24
+ loaders: [__require.resolve("./loader")],
25
+ as: "*.js"
26
+ }
27
+ })
28
+ })
29
+ });
30
+ }
31
+
32
+ // src/twcn.ts
33
+ import { modcn } from "modcn";
34
+ import { twMerge } from "tailwind-merge";
35
+ function twcn(styles) {
36
+ const cn = modcn(styles);
37
+ return (...inputs) => twMerge(cn(...inputs));
38
+ }
39
+ export {
40
+ twcn,
41
+ withTwssPlugin
42
+ };
package/dist/vite.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import "./chunk-OFTF64MC.mjs";
2
+
1
3
  // src/parse.ts
2
4
  var BLOCK_REGEX = /\.(\w[\w-]*)\s*\{\s*@apply\s+([\s\S]*?)\s*\}/g;
3
5
  function parseTwss(source) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "tailwind-style-sheets",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
- "import": "./dist/index.js",
9
+ "import": "./dist/index.mjs",
10
10
  "require": "./dist/index.js"
11
11
  },
12
12
  "./vite": {
package/tsup.config.ts CHANGED
@@ -8,7 +8,7 @@ export default defineConfig([
8
8
  dts: true,
9
9
  },
10
10
  {
11
- entry: ["src/vite.ts"],
11
+ entry: ["src/index.ts", "src/vite.ts"],
12
12
  format: ["esm"],
13
13
  external: ["vite"],
14
14
  dts: true,