@codenhub/styles 0.7.0 → 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.es.md +8 -7
- package/README.md +7 -6
- package/README.pt-BR.md +8 -7
- package/dist/aesthetics/chunky-tile.css +1 -1
- package/dist/aesthetics/cyber.css +1 -1
- package/dist/aesthetics/glass.css +1 -1
- package/dist/aesthetics/index.css +2 -2
- package/dist/aesthetics/neobrutalism.css +1 -1
- package/dist/aesthetics/sketch.css +1 -1
- package/dist/cli.js +189 -0
- package/dist/components.css +2 -2
- package/dist/index.css +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/native.css +2 -2
- package/dist/palette.css +1 -1
- package/dist/theme.css +2 -2
- package/docs/accessibility.md +46 -27
- package/docs/changelog/0.8.0.md +70 -0
- package/docs/changelog/index.md +1 -0
- package/docs/es/accessibility.md +47 -28
- package/docs/es/index.md +3 -2
- package/docs/es/integrating/index.md +38 -10
- package/docs/es/integrating/tailwind.md +78 -8
- package/docs/es/integrating/without-a-bundler.md +128 -5
- package/docs/es/setup.md +42 -34
- package/docs/es/usage/aesthetics.md +19 -13
- package/docs/es/usage/buttons.md +6 -2
- package/docs/es/usage/composing.md +6 -2
- package/docs/es/usage/content-and-layout.md +8 -4
- package/docs/es/usage/customizing.md +19 -13
- package/docs/es/usage/feedback.md +5 -1
- package/docs/es/usage/forms.md +29 -4
- package/docs/es/usage/index.md +6 -2
- package/docs/es/usage/presets.md +92 -0
- package/docs/es/usage/solo.md +4 -2
- package/docs/es/usage/theming.md +28 -15
- package/docs/index.md +2 -1
- package/docs/integrating/index.md +38 -10
- package/docs/integrating/tailwind.md +77 -7
- package/docs/integrating/without-a-bundler.md +127 -4
- package/docs/pt-BR/accessibility.md +47 -28
- package/docs/pt-BR/index.md +3 -2
- package/docs/pt-BR/integrating/index.md +38 -10
- package/docs/pt-BR/integrating/tailwind.md +78 -8
- package/docs/pt-BR/integrating/without-a-bundler.md +128 -5
- package/docs/pt-BR/setup.md +42 -34
- package/docs/pt-BR/usage/aesthetics.md +19 -13
- package/docs/pt-BR/usage/buttons.md +6 -2
- package/docs/pt-BR/usage/composing.md +6 -2
- package/docs/pt-BR/usage/content-and-layout.md +8 -4
- package/docs/pt-BR/usage/customizing.md +19 -13
- package/docs/pt-BR/usage/feedback.md +5 -1
- package/docs/pt-BR/usage/forms.md +29 -4
- package/docs/pt-BR/usage/index.md +6 -2
- package/docs/pt-BR/usage/presets.md +92 -0
- package/docs/pt-BR/usage/solo.md +4 -2
- package/docs/pt-BR/usage/theming.md +21 -8
- package/docs/setup.md +30 -22
- package/docs/usage/aesthetics.md +18 -12
- package/docs/usage/buttons.md +5 -1
- package/docs/usage/composing.md +5 -1
- package/docs/usage/content-and-layout.md +7 -3
- package/docs/usage/customizing.md +18 -12
- package/docs/usage/feedback.md +4 -0
- package/docs/usage/forms.md +28 -3
- package/docs/usage/index.md +5 -1
- package/docs/usage/presets.md +91 -0
- package/docs/usage/solo.md +3 -1
- package/docs/usage/theming.md +20 -7
- package/llms-full.txt +592 -115
- package/package.json +113 -63
- package/{dist/tw → tw}/aesthetics/chunky-tile.css +39 -19
- package/{dist/tw → tw}/aesthetics/cyber.css +15 -24
- package/{dist/tw → tw}/aesthetics/glass.css +105 -36
- package/{dist/tw → tw}/aesthetics/neobrutalism.css +37 -20
- package/{dist/tw → tw}/aesthetics/sketch.css +152 -133
- package/{dist/tw → tw}/box.css +89 -12
- package/tw/components/button.css +11 -0
- package/tw/components/button.rules.css +187 -0
- package/tw/components/feedback.css +11 -0
- package/{dist/tw/components/feedback.css → tw/components/feedback.rules.css} +134 -30
- package/tw/components/form.css +11 -0
- package/{dist/tw/components/form.css → tw/components/form.rules.css} +524 -111
- package/tw/components/index.css +16 -0
- package/tw/components/rules.css +41 -0
- package/tw/components/surface.css +11 -0
- package/tw/components/surface.rules.css +222 -0
- package/tw/components/tooltip.css +11 -0
- package/{dist/tw/components/tooltip.css → tw/components/tooltip.rules.css} +43 -27
- package/{dist/tw → tw}/corner.css +18 -12
- package/{dist/tw → tw}/elevation.css +23 -17
- package/{dist/tw → tw}/index.css +11 -9
- package/tw/index.d.ts +1 -0
- package/tw/intent.css +312 -0
- package/tw/modifiers.css +127 -0
- package/tw/native.css +320 -0
- package/tw/presentation.css +139 -0
- package/tw/reset.css +10 -0
- package/{dist/tw/reset.css → tw/reset.rules.css} +7 -8
- package/tw/size.css +34 -0
- package/tw/surface.css +9 -0
- package/tw/surface.rules.css +212 -0
- package/{dist/tw → tw}/theme.css +92 -28
- package/tw/typography.css +8 -0
- package/{dist/tw/typography.css → tw/typography.rules.css} +0 -3
- package/{dist/tw → tw}/utilities/content.css +183 -63
- package/tw/utilities/index.css +11 -0
- package/tw/utilities/layout.css +208 -0
- package/tw/utilities/rules.css +8 -0
- package/dist/tw/components/button.css +0 -139
- package/dist/tw/components/index.css +0 -35
- package/dist/tw/components/surface.css +0 -184
- package/dist/tw/intent.css +0 -229
- package/dist/tw/native.css +0 -203
- package/dist/tw/palette.css +0 -460
- package/dist/tw/presentation.css +0 -68
- package/dist/tw/surface.css +0 -61
- package/dist/tw/utilities/index.css +0 -6
- package/dist/tw/utilities/layout.css +0 -144
- /package/{dist/tw → tw}/aesthetics/index.css +0 -0
- /package/{dist/tw → tw}/aesthetics/pixel.css +0 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import * as fs from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import { parseArgs } from "node:util";
|
|
8
|
+
// src/cli/run.ts
|
|
9
|
+
const BIN = "codenhub-styles";
|
|
10
|
+
const MIN_NODE_MAJOR = 24;
|
|
11
|
+
const TAILWIND_PACKAGES = ["@tailwindcss/cli", "tailwindcss"];
|
|
12
|
+
const TW_AESTHETIC_EXPORT = /^\.\/tw\/aesthetics\/([^/]+)$/;
|
|
13
|
+
const USAGE = `Usage: ${BIN} build --content <glob> [--content <glob> ...] --output <file> [options]
|
|
14
|
+
|
|
15
|
+
Builds a StyleKit stylesheet holding only the classes your templates use.
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
-c, --content <glob> Files to scan for class names, relative to the current
|
|
19
|
+
directory. Repeat for more globs. Quote each glob.
|
|
20
|
+
-o, --output <file> Stylesheet to write. Parent directories are created.
|
|
21
|
+
--aesthetic <name> Add an aesthetic: {names}. Repeatable.
|
|
22
|
+
--no-minify Write readable CSS instead of minified CSS.
|
|
23
|
+
--help Show this help.
|
|
24
|
+
--version Show the version.`;
|
|
25
|
+
const POLYFILLS_NONE = 0;
|
|
26
|
+
async function run(argv, io) {
|
|
27
|
+
try {
|
|
28
|
+
const parsed = parseCommandLine(argv);
|
|
29
|
+
if (parsed === "help") io.stdout(USAGE.replace("{names}", readAestheticNames().join(", ")));
|
|
30
|
+
else if (parsed === "version") io.stdout(readManifest().version);
|
|
31
|
+
else {
|
|
32
|
+
const output = await build(parsed, io);
|
|
33
|
+
const { size } = await fs.stat(output);
|
|
34
|
+
io.stdout(`${output} ${size} bytes`);
|
|
35
|
+
}
|
|
36
|
+
return 0;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
io.stderr(`${BIN}: ${error instanceof Error ? error.message : String(error)}`);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function parseCommandLine(argv) {
|
|
43
|
+
const { values, positionals } = parseFlags(argv);
|
|
44
|
+
if (values.help) return "help";
|
|
45
|
+
if (values.version) return "version";
|
|
46
|
+
const [command, ...extra] = positionals;
|
|
47
|
+
if (command === void 0) throw new Error(`missing command; run "${BIN} build --content <glob> --output <file>".`);
|
|
48
|
+
if (command !== "build") throw new Error(`unknown command "${command}"; the only command is "build".`);
|
|
49
|
+
if (extra.length > 0) throw new Error(`unexpected argument "${extra[0]}"; quote each --content glob so the shell does not expand it, as in --content "app/views/**/*.erb".`);
|
|
50
|
+
if (!values.content?.length) throw new Error(`missing --content; name the templates to scan, as in --content "app/views/**/*.erb".`);
|
|
51
|
+
const output = values.output?.trim();
|
|
52
|
+
if (!output) throw new Error("missing --output; name the stylesheet to write, as in --output public/app.css.");
|
|
53
|
+
return {
|
|
54
|
+
contentGlobs: values.content,
|
|
55
|
+
output,
|
|
56
|
+
aesthetics: [...new Set(values.aesthetic ?? [])],
|
|
57
|
+
shouldMinify: !values["no-minify"]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function parseFlags(argv) {
|
|
61
|
+
try {
|
|
62
|
+
return parseArgs({
|
|
63
|
+
args: [...argv],
|
|
64
|
+
allowPositionals: true,
|
|
65
|
+
options: {
|
|
66
|
+
content: {
|
|
67
|
+
type: "string",
|
|
68
|
+
short: "c",
|
|
69
|
+
multiple: true
|
|
70
|
+
},
|
|
71
|
+
output: {
|
|
72
|
+
type: "string",
|
|
73
|
+
short: "o"
|
|
74
|
+
},
|
|
75
|
+
aesthetic: {
|
|
76
|
+
type: "string",
|
|
77
|
+
multiple: true
|
|
78
|
+
},
|
|
79
|
+
"no-minify": { type: "boolean" },
|
|
80
|
+
help: { type: "boolean" },
|
|
81
|
+
version: { type: "boolean" }
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const flag = error instanceof Error ? /'([^']+)'/.exec(error.message)?.[1] : void 0;
|
|
86
|
+
if (flag === void 0) throw error;
|
|
87
|
+
const code = error.code;
|
|
88
|
+
throw new Error(code === "ERR_PARSE_ARGS_UNKNOWN_OPTION" ? `unknown option "${flag}"; run "${BIN} --help" for the options.` : `option "${/--[\w-]+/.exec(flag)?.[0] ?? flag}" is missing its value or does not take one; run "${BIN} --help" for the options.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function build(options, io) {
|
|
92
|
+
assertNodeVersion(io.nodeVersion);
|
|
93
|
+
const tailwind = loadTailwind(io);
|
|
94
|
+
const validAesthetics = readAestheticNames();
|
|
95
|
+
const unknown = options.aesthetics.find((name) => !validAesthetics.includes(name));
|
|
96
|
+
if (unknown !== void 0) throw new Error(`unknown aesthetic "${unknown}"; choose from ${validAesthetics.join(", ")}.`);
|
|
97
|
+
await Promise.all(options.contentGlobs.map((pattern) => assertMatches(pattern, io.cwd)));
|
|
98
|
+
const output = path.resolve(io.cwd, options.output);
|
|
99
|
+
const input = [
|
|
100
|
+
`@import ${cssString(resolveExport("./tw"))};`,
|
|
101
|
+
...options.aesthetics.map((name) => `@import ${cssString(resolveExport(`./tw/aesthetics/${name}`))};`),
|
|
102
|
+
...options.contentGlobs.map((pattern) => `@source ${cssString(toCssPath(path.resolve(io.cwd, pattern)))};`)
|
|
103
|
+
].join("\n");
|
|
104
|
+
try {
|
|
105
|
+
const css = await compileStylesheet(tailwind, input, io.cwd, options.shouldMinify);
|
|
106
|
+
await fs.mkdir(path.dirname(output), { recursive: true });
|
|
107
|
+
await fs.writeFile(output, css);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
throw new Error(`Tailwind failed to build the stylesheet: ${error instanceof Error ? error.message : String(error)}`);
|
|
110
|
+
}
|
|
111
|
+
return output;
|
|
112
|
+
}
|
|
113
|
+
async function assertMatches(pattern, cwd) {
|
|
114
|
+
for await (const entry of fs.glob(pattern, {
|
|
115
|
+
cwd,
|
|
116
|
+
withFileTypes: true
|
|
117
|
+
})) if (entry.isFile()) return;
|
|
118
|
+
throw new Error(`--content "${pattern}" matches no file in ${cwd}; check the path, or run from the project root.`);
|
|
119
|
+
}
|
|
120
|
+
async function compileStylesheet(tailwind, input, cwd, shouldMinify) {
|
|
121
|
+
const compiler = await tailwind.compile(input, {
|
|
122
|
+
base: cwd,
|
|
123
|
+
from: path.join(cwd, "codenhub-styles.css"),
|
|
124
|
+
polyfills: POLYFILLS_NONE,
|
|
125
|
+
onDependency() {}
|
|
126
|
+
});
|
|
127
|
+
const scanner = new tailwind.Scanner({ sources: compiler.sources });
|
|
128
|
+
const css = compiler.build(scanner.scan());
|
|
129
|
+
return shouldMinify ? tailwind.optimize(css, { minify: true }).code : css;
|
|
130
|
+
}
|
|
131
|
+
function readAestheticNames() {
|
|
132
|
+
const { exports } = readManifest();
|
|
133
|
+
return Object.keys(exports).map((subpath) => TW_AESTHETIC_EXPORT.exec(subpath)?.[1]).filter((name) => name !== void 0).sort();
|
|
134
|
+
}
|
|
135
|
+
/** Returns the nearest folder at or above `from` that holds a `package.json`. */
|
|
136
|
+
function findPackageRoot(from) {
|
|
137
|
+
for (let dir = from;; dir = path.dirname(dir)) {
|
|
138
|
+
if (existsSync(path.join(dir, "package.json"))) return dir;
|
|
139
|
+
if (path.dirname(dir) === dir) throw new Error(`cannot find the package.json of @codenhub/styles above ${from}.`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const packageRoot = findPackageRoot(path.dirname(fileURLToPath(import.meta.url)));
|
|
143
|
+
function readManifest() {
|
|
144
|
+
return JSON.parse(readFileSync(path.join(packageRoot, "package.json"), "utf8"));
|
|
145
|
+
}
|
|
146
|
+
function resolveExport(subpath) {
|
|
147
|
+
const target = readManifest().exports[subpath].import;
|
|
148
|
+
return pathToFileURL(path.resolve(packageRoot, target)).href;
|
|
149
|
+
}
|
|
150
|
+
function assertNodeVersion(nodeVersion) {
|
|
151
|
+
if (Number.parseInt(nodeVersion, 10) < MIN_NODE_MAJOR) throw new Error(`this command needs Node.js ${MIN_NODE_MAJOR} or newer; this is Node.js ${nodeVersion}.`);
|
|
152
|
+
}
|
|
153
|
+
/** Loads Tailwind's compiler from where `@tailwindcss/cli` is installed, after checking both Tailwind packages are. */
|
|
154
|
+
function loadTailwind(io) {
|
|
155
|
+
const manifests = TAILWIND_PACKAGES.map((name) => resolveManifest(name, io));
|
|
156
|
+
const missing = TAILWIND_PACKAGES.filter((_, index) => manifests[index] === void 0);
|
|
157
|
+
if (missing.length > 0) throw new Error(`this command needs ${missing.join(" and ")}, which ${missing.length > 1 ? "are" : "is"} not installed. Run: npm install --save-dev ${missing.join(" ")}`);
|
|
158
|
+
const requireFromCli = createRequire(manifests[0]);
|
|
159
|
+
const { compile, optimize } = requireFromCli("@tailwindcss/node");
|
|
160
|
+
const { Scanner } = requireFromCli("@tailwindcss/oxide");
|
|
161
|
+
return {
|
|
162
|
+
compile,
|
|
163
|
+
optimize,
|
|
164
|
+
Scanner
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function resolveManifest(name, io) {
|
|
168
|
+
try {
|
|
169
|
+
return io.resolvePackage(`${name}/package.json`);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error.code === "MODULE_NOT_FOUND") return;
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function toCssPath(filePath) {
|
|
176
|
+
return filePath.split(path.sep).join("/");
|
|
177
|
+
}
|
|
178
|
+
function cssString(value) {
|
|
179
|
+
return `"${value.replace(/["\\]/g, "\\$&")}"`;
|
|
180
|
+
}
|
|
181
|
+
// src/cli/cli.ts
|
|
182
|
+
process.exitCode = await run(process.argv.slice(2), {
|
|
183
|
+
cwd: process.cwd(),
|
|
184
|
+
nodeVersion: process.versions.node,
|
|
185
|
+
resolvePackage: createRequire(import.meta.url).resolve,
|
|
186
|
+
stdout: (line) => process.stdout.write(`${line}\n`),
|
|
187
|
+
stderr: (line) => process.stderr.write(`${line}\n`)
|
|
188
|
+
});
|
|
189
|
+
export {};
|