oklchtohex 0.4.1 → 0.5.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 CHANGED
@@ -29,12 +29,11 @@ Add the plugin to `vite.config.js` or `vite.config.ts`:
29
29
 
30
30
  ```js
31
31
  import { defineConfig } from "vite";
32
- import react from "@vitejs/plugin-react";
33
32
  import { oklchToHexVitePlugin } from "oklchtohex/vite";
34
33
 
35
34
  export default defineConfig({
36
35
  plugins: [
37
- react(),
36
+ // ...your existing Vite plugins
38
37
  oklchToHexVitePlugin()
39
38
  ]
40
39
  });
@@ -48,6 +47,49 @@ Default behavior:
48
47
 
49
48
  No changes are required to your existing `dev` or `build` commands.
50
49
 
50
+ ## PostCSS Plugin (Next.js and others)
51
+
52
+ Use the PostCSS plugin when your framework runs PostCSS (Next.js, many Tailwind pipelines).
53
+
54
+ `postcss.config.mjs`:
55
+
56
+ ```js
57
+ import tailwind from "@tailwindcss/postcss";
58
+ import { oklchToHexPostcssPlugin } from "oklchtohex/postcss";
59
+
60
+ export default {
61
+ plugins: [
62
+ tailwind(),
63
+ oklchToHexPostcssPlugin({ gamut: "clip" })
64
+ ]
65
+ };
66
+ ```
67
+
68
+ If your config uses object-style plugins (common in some templates), use:
69
+
70
+ ```js
71
+ const config = {
72
+ plugins: {
73
+ "@tailwindcss/postcss": {},
74
+ "oklchtohex/postcss": { gamut: "clip" }
75
+ }
76
+ };
77
+
78
+ export default config;
79
+ ```
80
+
81
+ For Next.js, keep your standard commands:
82
+
83
+ ```json
84
+ {
85
+ "scripts": {
86
+ "dev": "next dev",
87
+ "build": "next build",
88
+ "start": "next start"
89
+ }
90
+ }
91
+ ```
92
+
51
93
  ## Vite Plugin Options
52
94
 
53
95
  ```js
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "oklchtohex",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Convert OKLCH colors to HEX as a JavaScript package.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
9
9
  "./vite": "./src/vite-plugin.js",
10
+ "./postcss": "./src/postcss-plugin.js",
10
11
  "./converter": "./src/converter.js"
11
12
  },
12
13
  "files": [
@@ -20,6 +21,8 @@
20
21
  "tailwindcss",
21
22
  "vite",
22
23
  "vite-plugin",
24
+ "postcss",
25
+ "postcss-plugin",
23
26
  "color",
24
27
  "converter"
25
28
  ],
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from "./converter.js";
2
2
  export { oklchToHexVitePlugin } from "./vite-plugin.js";
3
-
3
+ export { oklchToHexPostcssPlugin } from "./postcss-plugin.js";
@@ -0,0 +1,22 @@
1
+ import { replaceOklchInText } from "./converter.js";
2
+
3
+ export function oklchToHexPostcssPlugin(options = {}) {
4
+ return {
5
+ postcssPlugin: "oklchtohex-postcss-plugin",
6
+ Once(root) {
7
+ const originalCss = root.toString();
8
+ if (!originalCss.toLowerCase().includes("oklch(")) {
9
+ return;
10
+ }
11
+
12
+ const convertedCss = replaceOklchInText(originalCss, options);
13
+ if (convertedCss !== originalCss) {
14
+ root.removeAll();
15
+ root.append(convertedCss);
16
+ }
17
+ }
18
+ };
19
+ }
20
+
21
+ oklchToHexPostcssPlugin.postcss = true;
22
+ export default oklchToHexPostcssPlugin;