valcss 0.0.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 +221 -0
- package/dist/utils/config.js +1 -0
- package/dist/utils/configCache.js +1 -0
- package/dist/utils/constants.js +1 -0
- package/dist/utils/cssGenerator.js +1 -0
- package/dist/utils/fileResolver.js +1 -0
- package/dist/utils/getBreakpointConfig.js +1 -0
- package/dist/utils/getHeaderComment.js +1 -0
- package/dist/utils/injector.js +1 -0
- package/dist/utils/normalizeCalcExpression.js +1 -0
- package/dist/utils/pluginEngine.js +1 -0
- package/dist/utils/stripComments.js +1 -0
- package/dist/utils/validators.js +1 -0
- package/dist/valcss.js +2 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# ā” valcss
|
|
2
|
+
|
|
3
|
+
**valcss** is a tiny, flexible CLI utility to generate atomic and utility-first CSS classes from usage in your HTML and custom plugins. It allows you to configure class patterns, outputs, breakpoints, and even inject CSS directly into your HTML or as a separate file.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Features](#features)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Getting Started](#getting-started)
|
|
10
|
+
- [Configuration](#configuration)
|
|
11
|
+
- [Usage](#usage)
|
|
12
|
+
- [Plugin System](#plugin-system)
|
|
13
|
+
- [Injection Modes](#injection-modes)
|
|
14
|
+
- [Live Example](#live-example)
|
|
15
|
+
- [FAQ](#faq)
|
|
16
|
+
- [License](#license)
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- ā” Instantly extracts and generates a CSS file from your HTML.
|
|
23
|
+
- ā³ Supports watch mode for live editing.
|
|
24
|
+
- š§© Extendable through custom plugins.
|
|
25
|
+
- š CSS injection: inline in HTML or as a <link>.
|
|
26
|
+
- š¦ Zero-dependency CLI.
|
|
27
|
+
- š Supports breakpoints (responsive utilities).
|
|
28
|
+
- š Customizable with a simple JS config file.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g valcss
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
_Or clone and use directly if working locally:_
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/hardik-143/valcss.git
|
|
42
|
+
cd valcss
|
|
43
|
+
npm install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Getting Started
|
|
49
|
+
|
|
50
|
+
### 1. Scaffold a config file
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
valcss init
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This creates a `valcss.config.js` file in your project:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
// valcss.config.js
|
|
60
|
+
module.exports = {
|
|
61
|
+
files: ["index.html", "src/**/*.html"],
|
|
62
|
+
output: "valcss-main.css",
|
|
63
|
+
inject: {
|
|
64
|
+
mode: "link", // or "inline"
|
|
65
|
+
targets: ["index.html"],
|
|
66
|
+
},
|
|
67
|
+
breakpoints: {
|
|
68
|
+
lg: 990,
|
|
69
|
+
},
|
|
70
|
+
plugins: [
|
|
71
|
+
({ addUtilities }) => {
|
|
72
|
+
addUtilities(
|
|
73
|
+
{
|
|
74
|
+
"flex-center": {
|
|
75
|
+
display: "flex",
|
|
76
|
+
"justify-content": "center",
|
|
77
|
+
"align-items": "center",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
"*"
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### 2. Add utility CSS classes in your HTML:
|
|
90
|
+
|
|
91
|
+
Example ([index.html](https://github.com/hardik-143/valcss/blob/main/index.html)):
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<link rel="stylesheet" href="valcss-main.css" />
|
|
95
|
+
<div class="p-[25px] flex-center hover:flex-center lg:flex-center ...">
|
|
96
|
+
<p class="text-[#000] bg-[#00ff00] border-[1px_solid_#000] ...">Hello</p>
|
|
97
|
+
</div>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### 3. Build your CSS
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
valcss
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- This scans your HTML, generates only the CSS classes you actually use, and writes them to `valcss-main.css`.
|
|
109
|
+
- The CSS is injected (as a link or inline) into your specified HTML targets.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
The config file lets you control:
|
|
116
|
+
|
|
117
|
+
- **files**: Files/globs to scan for class usage.
|
|
118
|
+
- **output**: The CSS file output.
|
|
119
|
+
- **inject**: How and where to inject the styles.
|
|
120
|
+
- **breakpoints**: Custom responsive breakpoints.
|
|
121
|
+
- **plugins**: Extendable utility generators.
|
|
122
|
+
|
|
123
|
+
See [`valcss.config.js`](https://github.com/hardik-143/valcss/blob/main/valcss.config.js) for an example.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Usage
|
|
128
|
+
|
|
129
|
+
| Command | Description |
|
|
130
|
+
| ------------------------ | ------------------------------------ |
|
|
131
|
+
| `valcss` | Run CSS extraction/generation |
|
|
132
|
+
| `valcss --output <file>` | Override the default output file |
|
|
133
|
+
| `valcss --watch` | Enable file watching/live rebuilds |
|
|
134
|
+
| `valcss init` | Scaffold a config file |
|
|
135
|
+
| `valcss --dry-run` | Print generated CSS to terminal only |
|
|
136
|
+
| `valcss --help` | Show help message |
|
|
137
|
+
|
|
138
|
+
**Example:**
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
valcss --watch --output custom.css
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Plugin System
|
|
147
|
+
|
|
148
|
+
Define your own utilities with the `plugins` array in your config:
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
plugins: [
|
|
152
|
+
({ addUtilities }) => {
|
|
153
|
+
addUtilities(
|
|
154
|
+
{
|
|
155
|
+
"flex-center": {
|
|
156
|
+
display: "flex",
|
|
157
|
+
"justify-content": "center",
|
|
158
|
+
"align-items": "center",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
"*"
|
|
162
|
+
);
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**This adds the `flex-center` class to your utility set:**
|
|
168
|
+
|
|
169
|
+
```css
|
|
170
|
+
.flex-center {
|
|
171
|
+
display: flex;
|
|
172
|
+
justify-content: center;
|
|
173
|
+
align-items: center;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Injection Modes
|
|
180
|
+
|
|
181
|
+
- `"link"`: Injects your built CSS using `<link rel="stylesheet" ...>`.
|
|
182
|
+
- `"inline"`: Injects the CSS directly inside `<style>` tags.
|
|
183
|
+
- **Targets**: Specify which HTML files receive the injection.
|
|
184
|
+
|
|
185
|
+
Edit these options under `inject` in your config file.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Live Example
|
|
190
|
+
|
|
191
|
+
- [index.html](https://github.com/hardik-143/valcss/blob/main/index.html) with the generated classes applied.
|
|
192
|
+
- [valcss-main.css](https://github.com/hardik-143/valcss/blob/main/valcss-main.css) is the result.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## FAQ
|
|
197
|
+
|
|
198
|
+
### How does valcss work?
|
|
199
|
+
|
|
200
|
+
- Scans your specified files for ALL CSS classes used.
|
|
201
|
+
- Resolves and compiles only the classes you use into a single CSS file.
|
|
202
|
+
- Optionally injects that file into your HTML via link or inline style.
|
|
203
|
+
|
|
204
|
+
### How to add my own utility classes?
|
|
205
|
+
|
|
206
|
+
Use the plugin system in the config. See [Plugin System](#plugin-system).
|
|
207
|
+
|
|
208
|
+
### Does valcss support responsiveness?
|
|
209
|
+
|
|
210
|
+
Yes! Example:
|
|
211
|
+
`.md:utility` or `.lg:flex-center` generates the correct breakpoint selectors.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
MIT Ā© 2025 [@hardik-143](https://github.com/hardik-143)
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
> _Ready to make your CSS minimal, maintainable, and fast? Try valcss and get instant atomic CSS using only what you use!_
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const fs=require("fs"),path=require("path");function loadConfig(){const o=[path.resolve("valcss.config.js"),path.resolve("valcss.config.json")].find(fs.existsSync);if(!o)throw new Error("valcss.config.js or valcss.config.json not found. \n\nRun 'npx valcss init' to create a default config.");let n;try{n=require(o)}catch(n){throw new Error(`Failed to load config at ${o}: ${n.message}`)}if(!n.files||0===n.files.length||!Array.isArray(n.files))throw new Error("'files' array missing or invalid in config.");return n}module.exports={loadConfig:loadConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let config=null;function setConfig(n){config=n}function getConfig(){if(!config)throw new Error("Config not initialized. Call setConfig(config) first.");return config}module.exports={setConfig:setConfig,getConfig:getConfig};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const pseudoPrefixes=["hover","focus","active","visited","disabled"],positionValues=["static","relative","absolute","fixed","sticky"],displayValues=["block","inline","inline-block","flex","grid","hidden","inline-flex","inline-grid"],visibilityValues=["visible","invisible"];export{pseudoPrefixes,positionValues,displayValues,visibilityValues};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const fs=require("fs"),{validators:validators,regex:regex}=require("./validators"),{stripComments:stripComments}=require("./stripComments"),{normalizeCalcExpression:normalizeCalcExpression}=require("./normalizeCalcExpression"),{pseudoPrefixes:pseudoPrefixes,positionValues:positionValues,displayValues:displayValues}=require("./constants"),{getBreakpointConfig:getBreakpointConfig}=require("./getBreakpointConfig"),{breakpoints:breakpoints}=getBreakpointConfig(),{getUtilitiesMap:getUtilitiesMap}=require("./pluginEngine"),individualValues=[...positionValues,...displayValues];function createStyleMap(e,t){const a={};for(const i of t)a[i]={validate:()=>!0,generate:t=>`${e}: ${t};`};return a}const positionStyleMap=createStyleMap("position",positionValues),displayStyleMap=createStyleMap("display",displayValues);function createSpacingUtils(e){const t={"":[""],x:["left","right"],y:["top","bottom"],t:["top"],b:["bottom"],l:["left"],r:["right"]},a={};for(const i in t){const s=i||"";a[e[0]+s]={validate:validators.spacingValues,generate:a=>{let s=normalizeCalcExpression(a);return regex.digit.test(s)&&(s=`${parseFloat(s)}px`),s=s.replaceAll("_"," "),""===t[i][0]?`${e}: ${s};`:t[i].map(t=>`${e}-${t}: ${s};`).join(" ")}}}return a}const spacingUtils={...createSpacingUtils("padding"),...createSpacingUtils("margin")};function createSizeUtils(e){const t={};for(const[a,i]of Object.entries(e))t[a]={validate:validators.lengthUnit,generate:e=>`${i}: ${normalizeCalcExpression(e)};`};return t}const sizeUtils=createSizeUtils({w:"width",h:"height","max-w":"max-width","min-w":"min-width","max-h":"max-height","min-h":"min-height"}),insetUtils=createSizeUtils({top:"top",left:"left",right:"right",bottom:"bottom"}),styleMap={...spacingUtils,...sizeUtils,...insetUtils,text:{validate:e=>validators.color(e)||validators.lengthUnit(e)||validators.textAlign(e)||validators.textTransform(e),generate:e=>validators.color(e)?`color: ${e};`:validators.textAlign(e)?`text-align: ${e};`:validators.textTransform(e)?`text-transform: ${e};`:`font-size: ${e};`},font:{validate:validators.fontWeight,generate:e=>`font-weight: ${e};`},lh:{validate:validators.lineHeight,generate:e=>`line-height: ${e};`},bg:{validate:validators.bg,generate:e=>{const t=e.trim().toLowerCase(),a=regex.hex.test(t)||regex.rgb.test(t)||regex.rgba.test(t)||regex.namedColor.test(t);return`${"none"===t?"background":a?"background-color":"background"}: ${e};`}},d:{validate:validators.display,generate:e=>`display: ${e};`},float:{validate:validators.float,generate:e=>`float: ${e};`},justify:{validate:validators.justify,generate:e=>`justify-content: ${e};`},items:{validate:validators.items,generate:e=>`align-items: ${e};`},gap:{validate:validators.lengthUnit,generate:e=>`gap: ${normalizeCalcExpression(e)};`},border:{validate:validators.border,generate:e=>{const t=e.trim().toLowerCase();return/^-?\d+(\.\d+)?(px|em|rem)?$/.test(t)?`border-width: ${e};`:/^(none|solid|dashed|dotted|double|groove|ridge|inset|outset)$/.test(t)?`border-style: ${e};`:validators.color(e)?`border-color: ${e};`:`border: ${e.replaceAll("_"," ")};`}},radius:{validate:validators.lengthUnit,generate:e=>`border-radius: ${normalizeCalcExpression(e)};`},pos:{validate:validators.position,generate:e=>`position: ${e};`},opacity:{validate:validators.opacity,generate:e=>`opacity: ${e};`},z:{validate:validators.zIndex,generate:e=>`z-index: ${e};`},flex:{validate:validators.flex,generate:e=>`flex: ${e};`},...positionStyleMap,...displayStyleMap};function parseClassString(e){const t=e.split(":"),a=t[t.length-1];let i=null,s=!1,r=null;const n=t[0];if(n.startsWith("max-")){const e=n.slice(4);breakpoints[e]&&(i=e,s=!0)}else breakpoints[n]&&(i=n,s=!1);for(let a=i?1:0;a<t.length-1;a++){const i=t[a];(breakpoints[i]||i.startsWith("max-"))&&console.warn(`ā ļø Media prefix "${i}" must appear only as the first segment: "${e}"`),pseudoPrefixes.includes(i)&&(r=i)}const l=a,o=l.startsWith("!"),d=o?l.slice(1):l;return{mediaPrefix:i,isMax:s,pseudo:r,baseClass:l,cleanBaseClass:d,isImportant:o}}function escapeClass(e){return e.replace(/([ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g,"\\$1")}function generateCSSFromClass(e){const{mediaPrefix:t,isMax:a,pseudo:i,baseClass:s,cleanBaseClass:r,isImportant:n}=parseClassString(e);if(individualValues.includes(r))val=r,rule=styleMap[r];else{const e=r.match(/^([\w-]+)-\[(.+)\]$/);if(e){const t=e[1],a=e[2];rule=styleMap[t],val=a}}const l=getUtilitiesMap(),o=r;if(l[o]){const{styles:s,variants:r}=l[o];if(!t&&!i)return`.${e} { ${Object.entries(s).map(([e,t])=>`${e}: ${t};`).join(" ")} }`;if("string"==typeof r&&"*"===r||r.includes("*")||t&&r.includes(t)||i&&r.includes(i)){const r=Object.entries(s).map(([e,t])=>`${e}: ${t};`).join(" ");let n=`.${escapeClass(e)}`;i&&(n+=`:${i}`);let l=`${n} { ${r} }`;if(t){const e=breakpoints[t];return`${a?`@media (max-width: ${e-1}px)`:`@media (min-width: ${e}px)`} {\n ${l}\n}`}return l}return console.warn(`ā ļø Variant not allowed for: ${e}`),null}if(rule&&rule.validate(val)){let s=`.${escapeClass(e)}`;i&&(s+=`:${i}`);let r=rule.generate(val);n&&(r=r.slice(0,-1)+" !important;");const l=`{ ${r} }`;if(t){const e=breakpoints[t];return`${a?`@media (max-width: ${e-1}px)`:`@media (min-width: ${e}px)`} {\n ${s} ${l}\n}`}return`${s} ${l}`}return console.warn(`ā ļø Invalid class or value: ${e}`),null}function extractAndGenerateCSS(e){const t=[...e.matchAll(/class\s*=\s*["']([^"']+)["']/g)].flatMap(e=>e&&e[1]?e[1].trim().split(/\s+/):[]).filter(e=>{const t=e.split(":").pop();return!!individualValues.includes(t)||(!!e.match(/^((?:[\w-]+:)*)(!?[\w-]+)-\[(.+)\]$/)||!!getUtilitiesMap()[e.split(":").pop()])});return[...new Set(t)].map(generateCSSFromClass).filter(Boolean).join("\n")}function generateCombinedCSS(e){let t="";return e.forEach(e=>{const a=fs.readFileSync(e,"utf8"),i=extractAndGenerateCSS(stripComments(a));t+=i+"\n"}),t.trim()}function writeCSS(e,t){fs.writeFileSync(e,t),console.log(`ā
CSS written to ${e}`)}module.exports={generateCombinedCSS:generateCombinedCSS,writeCSS:writeCSS};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const{globSync:globSync}=require("glob"),fs=require("fs");function resolveFiles(e){const s=e.flatMap(e=>globSync(e));return[...new Set(s.filter(e=>fs.existsSync(e)))]}module.exports={resolveFiles:resolveFiles};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const{getConfig:getConfig}=require("./configCache"),defaultBreakpoints={xs:480,sm:640,md:768,lg:1024,xl:1280,xxl:1536};function getBreakpointConfig(){let e=getConfig().breakpoints||{};Object.keys(e).forEach(t=>{let n=e[t];if("string"==typeof n){n.endsWith("px")&&(n=n.slice(0,-2));const o=parseInt(n,10);isNaN(o)?(console.warn(`ā ļø Invalid breakpoint value for "${t}": ${e[t]}. Using default value instead.`),delete e[t]):e[t]=o}});const t={...defaultBreakpoints,...e};return{breakpoints:t,getValue:e=>t[e]||null}}module.exports={getBreakpointConfig:getBreakpointConfig,defaultBreakpoints:defaultBreakpoints};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function getHeaderComment(e="valcss"){return`/* \nGenerated by ${e} \nLast updated: ${(new Date).toISOString()} \n*/\n`}module.exports={getHeaderComment:getHeaderComment};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const fs=require("fs"),{writeCSS:writeCSS}=require("./cssGenerator"),{getHeaderComment:getHeaderComment}=require("./getHeaderComment");function injectCSSIntoHTML({css:e="",outputPath:t="valcss-main.css",mode:o="link",targets:n=[]}){let s="";"inline"===o?s=e:"link"===o&&(s=getHeaderComment()+e),n.forEach(n=>{if(!fs.existsSync(n))return void console.warn(`ā ļø Target HTML file not found: ${n}`);""===e&&(console.error("ā No CSS provided."),process.exit(1)),""===t&&(console.error("ā No output path provided."),process.exit(1)),""===o&&(console.error("ā No mode provided."),process.exit(1));let r=fs.readFileSync(n,"utf8");if("inline"===o){const e=`<style>\n${s}\n</style>`;r.includes(e)||(r=r.replace(/<\/head>/i,`${e}\n</head>`),console.log(`ā
Inlined styles into ${n}`))}else"link"===o&&(fs.existsSync(t)||(fs.writeFileSync(t,"/* valcss: empty stylesheet created */\n"),console.log(`š Created missing CSS file: ${t}`)),writeCSS(t,s));fs.writeFileSync(n,r,"utf8")})}module.exports={injectCSSIntoHTML:injectCSSIntoHTML};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function normalizeCalcExpression(e){return e.startsWith("calc(")?e.replace(/calc\((.*?)\)/,(e,r)=>`calc(${r.replace(/_/g," ").replace(/([+-/*])/g," $1 ").replace(/\s+/g," ").trim()})`):e}module.exports={normalizeCalcExpression:normalizeCalcExpression};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const utilitiesMap={};function addUtilities(i,t=[]){for(const e in i)utilitiesMap[e]={styles:i[e],variants:t}}function getUtilitiesMap(){return utilitiesMap}function resetUtilitiesMap(){Object.keys(utilitiesMap).forEach(i=>delete utilitiesMap[i])}module.exports={addUtilities:addUtilities,getUtilitiesMap:getUtilitiesMap,resetUtilitiesMap:resetUtilitiesMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function stripComments(e){return e.replace(/<!--[\s\S]*?-->/g,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"")}module.exports={stripComments:stripComments};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const regex={length:/^-?\d+(\.\d+)?(px|em|rem|%|vh|vw)?$/,calc:/^calc\(.+\)$/,clamp:/^clamp\(.+\)$/,min:/^min\(.+\)$/,max:/^max\(.+\)$/,hex:/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,rgb:/^rgb\((\s*\d{1,3}\s*,){2}\s*\d{1,3}\s*\)$/,rgba:/^rgba\((\s*\d{1,3}\s*,){3}\s*(0|1|0?\.\d+)\)$/,namedColor:/^(transparent|[a-zA-Z]+)$/,fontWeight:/^(100|200|300|400|500|600|700|800|900)$/,normal:/^normal$/,none:/^none$/,textAlign:/^(left|right|center|justify)$/,textTransform:/^(uppercase|lowercase|capitalize|none)$/,display:/^(block|inline|inline-block|flex|grid|none|inline-flex|inline-grid)$/,justify:/^(flex-start|flex-end|center|space-between|space-around|space-evenly)$/,items:/^(stretch|flex-start|flex-end|center|baseline)$/,borderStyle:/^(none|solid|dashed|dotted|double|groove|ridge|inset|outset)$/,opacity:/^(0(\.\d+)?|1(\.0+)?)$/,digit:/^[-+]?(?:\d+|\d*\.\d+)$/,position:/^(static|relative|absolute|fixed|sticky)$/,float:/^(left|right|none)$/},validators={lengthUnit:e=>regex.length.test(e)||regex.calc.test(e)||regex.clamp.test(e)||regex.min.test(e)||regex.max.test(e),color:e=>regex.hex.test(e)||regex.rgb.test(e)||regex.rgba.test(e)||regex.namedColor.test(e),fontWeight:e=>regex.fontWeight.test(e),lineHeight:e=>regex.digit.test(e)||regex.normal.test(e),textAlign:e=>regex.textAlign.test(e),textTransform:e=>regex.textTransform.test(e),display:e=>regex.display.test(e),justify:e=>regex.justify.test(e),items:e=>regex.items.test(e),border:e=>e.trim().toLowerCase().split("_").every(e=>regex.length.test(e)||regex.borderStyle.test(e)||regex.hex.test(e)||regex.rgb.test(e)||regex.rgba.test(e)||regex.namedColor.test(e)),opacity:e=>regex.opacity.test(e),zIndex:e=>regex.digit.test(e),position:e=>regex.position.test(e),bg:e=>{const t=e.trim().toLowerCase();return regex.hex.test(t)||regex.rgb.test(t)||regex.none.test(t)||regex.namedColor.test(t)},float:e=>regex.float.test(e),flex:e=>regex.flex.test(e),spacingValues:e=>{const t=e.trim().toLowerCase().split("_");return!(t.length<1||t.length>4)&&t.every(e=>regex.length.test(e)||regex.calc.test(e)||regex.clamp.test(e)||regex.min.test(e)||regex.max.test(e))}};export{validators,regex};
|
package/dist/valcss.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const e=require("fs"),n=require("path"),s=require("chokidar"),{loadConfig:t}=require("./utils/config"),{setConfig:i,getConfig:o}=require("./utils/configCache"),{addUtilities:l,resetUtilitiesMap:r}=require("./utils/pluginEngine"),c=process.argv.slice(2);if("init"===c[0]){const n="valcss.config.js";e.existsSync(n)&&(console.warn("ā ļø valcss.config.js already exists."),process.exit(1));const s='\n// valcss.config.js\nmodule.exports = {\n files: ["index.html", "src/**/*.html"],\n output: "valcss-main.css",\n inject: {\n mode: "link", // "inline" or "link"\n targets: ["index.html"]\n }\n};';e.writeFileSync(n,s.trimStart()),console.log("ā
valcss.config.js created!"),process.exit(0)}r();const a=t();Array.isArray(a.plugins)&&a.plugins.forEach(e=>{"function"==typeof e&&e({addUtilities:l})}),i(a);const{resolveFiles:u}=require("./utils/fileResolver"),{generateCombinedCSS:g}=require("./utils/cssGenerator"),{injectCSSIntoHTML:f}=require("./utils/injector");let d=null,h=!1,p=!1,v=["--output","--watch","-w","--dry-run","--help","-h"];if(c.some(e=>!v.includes(e)&&!c[c.indexOf(e)-1]?.includes("--output"))&&(console.error("ā Invalid argument: "+c.find(e=>!v.includes(e)&&!c[c.indexOf(e)-1]?.includes("--output"))),process.exit(1)),c.includes("--dry-run")&&"--dry-run"===c[0]&&(p=!0),1!==c.length||"--help"!==c[0]&&"-h"!==c[0]||(console.log("\n------------------------------------------------------\n\nš¦ valcss - Utility CSS Extractor\n\nUsage:\n valcss Uses valcss.config.json\n valcss --output <file> Override output file\n valcss --watch Watch input files and regenerate CSS on changes\n valcss --dry-run Output CSS to console without writing files\n valcss --help Show this help message\n\nOptions:\n --output <file> Write final CSS to given file\n --watch | -w Enable watch mode\n --help | -h Show this help message\n\n------------------------------------------------------\n"),process.exit(0)),(c.includes("--watch")||c.includes("-w"))&&(h=!0),c.includes("--output")){const e=c.indexOf("--output");-1!==e&&c[e+1]?d=c[e+1]:(console.error("ā Missing value for --output"),process.exit(1))}function m(){try{const{files:e,output:n="valcss-main.css",inject:s}=o(),t=u(e);if(0===t.length)return void console.error("ā No matching files found.");const i=d||n;console.log(`š Generating CSS for ${t.length} files...`);const l=g(t);if(p)return console.log("\n------------------------------------------------------\nDRY MODE ENABLED\n------------------------------------------------------\n\n"),console.log(l),void console.log("\n------------------------------------------------------");s&&Array.isArray(s.targets)?f({css:l,outputPath:i,mode:s.mode||"link",targets:s.targets}):console.error("ā No inject targets found.")}catch(e){console.error("ā "+e.message)}}if(h)try{const{files:e}=o(),n=u(e);console.log("š Watching files for changes..."),s.watch(n).on("change",e=>{console.log("š File changed: "+e),m()}),m()}catch(e){console.error("ā "+e.message),process.exit(1)}else m();
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "valcss",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Tiny utility to generate CSS",
|
|
5
|
+
"main": "dist/valcss.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"valcss": "./dist/valcss.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "node build-terser.js",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"valcss",
|
|
15
|
+
"css",
|
|
16
|
+
"arbitrary",
|
|
17
|
+
"inline",
|
|
18
|
+
"utility",
|
|
19
|
+
"utility-classes",
|
|
20
|
+
"utility-first"
|
|
21
|
+
],
|
|
22
|
+
"author": "Hardik Desai",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"chokidar": "^4.0.3",
|
|
26
|
+
"glob": "^11.0.3"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist/valcss.js",
|
|
30
|
+
"dist/utils/",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/hardik-143/valcss.git"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/hardik-143/valcss#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/hardik-143/valcss/issues"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"terser": "^5.44.1"
|
|
43
|
+
}
|
|
44
|
+
}
|