@cwcss/crosswind 0.1.5 → 0.1.6
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/LICENSE.md +21 -0
- package/README.md +390 -0
- package/dist/build.d.ts +24 -0
- package/dist/config.d.ts +5 -0
- package/dist/generator.d.ts +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +12798 -0
- package/dist/parser.d.ts +42 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/preflight-forms.d.ts +5 -0
- package/dist/preflight.d.ts +2 -0
- package/dist/rules-advanced.d.ts +27 -0
- package/dist/rules-effects.d.ts +25 -0
- package/dist/rules-forms.d.ts +7 -0
- package/dist/rules-grid.d.ts +13 -0
- package/dist/rules-interactivity.d.ts +41 -0
- package/dist/rules-layout.d.ts +26 -0
- package/dist/rules-transforms.d.ts +33 -0
- package/dist/rules-typography.d.ts +41 -0
- package/dist/rules.d.ts +39 -0
- package/dist/scanner.d.ts +18 -0
- package/dist/transformer-compile-class.d.ts +37 -0
- package/{src/types.ts → dist/types.d.ts} +17 -86
- package/package.json +1 -1
- package/PLUGIN.md +0 -235
- package/benchmark/framework-comparison.bench.ts +0 -850
- package/bin/cli.ts +0 -365
- package/bin/crosswind +0 -0
- package/bin/headwind +0 -0
- package/build.ts +0 -8
- package/crosswind.config.ts +0 -9
- package/example/comprehensive.html +0 -70
- package/example/index.html +0 -21
- package/example/output.css +0 -236
- package/examples/plugin/README.md +0 -112
- package/examples/plugin/build.ts +0 -32
- package/examples/plugin/src/index.html +0 -34
- package/examples/plugin/src/index.ts +0 -7
- package/headwind +0 -2
- package/src/build.ts +0 -101
- package/src/config.ts +0 -529
- package/src/generator.ts +0 -2173
- package/src/index.ts +0 -10
- package/src/parser.ts +0 -1471
- package/src/plugin.ts +0 -118
- package/src/preflight-forms.ts +0 -229
- package/src/preflight.ts +0 -388
- package/src/rules-advanced.ts +0 -477
- package/src/rules-effects.ts +0 -461
- package/src/rules-forms.ts +0 -103
- package/src/rules-grid.ts +0 -241
- package/src/rules-interactivity.ts +0 -525
- package/src/rules-layout.ts +0 -385
- package/src/rules-transforms.ts +0 -412
- package/src/rules-typography.ts +0 -486
- package/src/rules.ts +0 -809
- package/src/scanner.ts +0 -84
- package/src/transformer-compile-class.ts +0 -275
- package/test/advanced-features.test.ts +0 -911
- package/test/arbitrary.test.ts +0 -396
- package/test/attributify.test.ts +0 -592
- package/test/bracket-syntax.test.ts +0 -1133
- package/test/build.test.ts +0 -99
- package/test/colors.test.ts +0 -934
- package/test/flexbox.test.ts +0 -669
- package/test/generator.test.ts +0 -597
- package/test/grid.test.ts +0 -584
- package/test/layout.test.ts +0 -404
- package/test/modifiers.test.ts +0 -417
- package/test/parser.test.ts +0 -564
- package/test/performance-regression.test.ts +0 -376
- package/test/performance.test.ts +0 -568
- package/test/plugin.test.ts +0 -160
- package/test/scanner.test.ts +0 -94
- package/test/sizing.test.ts +0 -481
- package/test/spacing.test.ts +0 -394
- package/test/transformer-compile-class.test.ts +0 -287
- package/test/transforms.test.ts +0 -448
- package/test/typography.test.ts +0 -632
- package/test/variants-form-states.test.ts +0 -225
- package/test/variants-group-peer.test.ts +0 -66
- package/test/variants-media.test.ts +0 -213
- package/test/variants-positional.test.ts +0 -58
- package/test/variants-pseudo-elements.test.ts +0 -47
- package/test/variants-state.test.ts +0 -62
- package/tsconfig.json +0 -18
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# Crosswind Bun Plugin Example
|
|
2
|
-
|
|
3
|
-
This example demonstrates how to use the Crosswind Bun plugin to automatically generate and inject CSS into your HTML files during the build process.
|
|
4
|
-
|
|
5
|
-
## Project Structure
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
examples/plugin/
|
|
9
|
-
├── src/
|
|
10
|
-
│ ├── index.ts # TypeScript entrypoint that imports HTML
|
|
11
|
-
│ └── index.html # HTML file with utility classes
|
|
12
|
-
├── build.ts # Build script
|
|
13
|
-
└── README.md
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
17
|
-
|
|
18
|
-
The plugin works by intercepting HTML imports in your TypeScript/JavaScript code. When you import an HTML file, the plugin:
|
|
19
|
-
|
|
20
|
-
1. Scans the HTML for Crosswind utility classes
|
|
21
|
-
2. Generates the corresponding CSS
|
|
22
|
-
3. Injects the CSS into the `<head>` section
|
|
23
|
-
4. Returns the processed HTML
|
|
24
|
-
|
|
25
|
-
### Basic Setup
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { plugin } from '@cwcss/crosswind'
|
|
29
|
-
|
|
30
|
-
await Bun.build({
|
|
31
|
-
entrypoints: ['./src/index.ts'],
|
|
32
|
-
outdir: './dist',
|
|
33
|
-
plugins: [plugin()],
|
|
34
|
-
})
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Your TypeScript file** (`src/index.ts`):
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import html from './index.html'
|
|
41
|
-
|
|
42
|
-
// Use the HTML content (it will have CSS injected)
|
|
43
|
-
document.body.innerHTML = html
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### With Custom Configuration
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
import { plugin } from '@cwcss/crosswind'
|
|
50
|
-
|
|
51
|
-
await Bun.build({
|
|
52
|
-
entrypoints: ['./src/index.ts'],
|
|
53
|
-
outdir: './dist',
|
|
54
|
-
plugins: [
|
|
55
|
-
plugin({
|
|
56
|
-
config: {
|
|
57
|
-
minify: true,
|
|
58
|
-
theme: {
|
|
59
|
-
colors: {
|
|
60
|
-
primary: '#3b82f6',
|
|
61
|
-
secondary: '#10b981',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
includePreflight: true,
|
|
66
|
-
}),
|
|
67
|
-
],
|
|
68
|
-
})
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Running This Example
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
# Build the example
|
|
75
|
-
bun run build.ts
|
|
76
|
-
|
|
77
|
-
# The output will be in ./dist/
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
## How It Works
|
|
81
|
-
|
|
82
|
-
1. The plugin hooks into Bun's module loading system via `onLoad`
|
|
83
|
-
2. When a `.html` file is imported, the plugin intercepts the load
|
|
84
|
-
3. It extracts utility classes from the HTML using Crosswind's parser
|
|
85
|
-
4. It generates CSS for those classes using Crosswind's generator
|
|
86
|
-
5. The generated CSS is injected into the `<head>` section
|
|
87
|
-
6. The processed HTML is returned as a string in the bundled output
|
|
88
|
-
|
|
89
|
-
## Options
|
|
90
|
-
|
|
91
|
-
### `config`
|
|
92
|
-
|
|
93
|
-
Custom Crosswind configuration to override defaults. This can include:
|
|
94
|
-
|
|
95
|
-
- `minify`: Minify the generated CSS
|
|
96
|
-
- `theme`: Custom theme colors, spacing, fonts, etc.
|
|
97
|
-
- `shortcuts`: Define utility class shortcuts
|
|
98
|
-
- `safelist`: Classes to always include
|
|
99
|
-
- And more...
|
|
100
|
-
|
|
101
|
-
### `includePreflight`
|
|
102
|
-
|
|
103
|
-
Whether to include preflight (reset) CSS. Default: `true`
|
|
104
|
-
|
|
105
|
-
## Use Cases
|
|
106
|
-
|
|
107
|
-
This plugin is ideal for:
|
|
108
|
-
|
|
109
|
-
- Single Page Applications (SPAs) that import HTML templates
|
|
110
|
-
- Component-based architectures where HTML is imported as strings
|
|
111
|
-
- Build processes that need automatic CSS generation from HTML
|
|
112
|
-
- Projects using Bun's native bundler with HTML assets
|
package/examples/plugin/build.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { plugin } from '@cwcss/crosswind'
|
|
2
|
-
|
|
3
|
-
// Build with crosswind plugin
|
|
4
|
-
// The plugin will automatically process HTML files that are imported in your TypeScript/JavaScript code
|
|
5
|
-
const result = await Bun.build({
|
|
6
|
-
entrypoints: ['./src/index.ts'], // Your TS entrypoint that imports HTML files
|
|
7
|
-
outdir: './dist',
|
|
8
|
-
plugins: [
|
|
9
|
-
plugin({
|
|
10
|
-
// Optional: provide custom config
|
|
11
|
-
config: {
|
|
12
|
-
minify: true,
|
|
13
|
-
theme: {
|
|
14
|
-
colors: {
|
|
15
|
-
primary: '#3b82f6',
|
|
16
|
-
secondary: '#10b981',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
// Optional: include preflight CSS
|
|
21
|
-
includePreflight: true,
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
if (result.success) {
|
|
27
|
-
console.log('Build complete!')
|
|
28
|
-
console.log(`Generated ${result.outputs.length} output(s)`)
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
console.error('Build failed:', result.logs)
|
|
32
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>Crosswind Bun Plugin Example</title>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<div class="flex items-center justify-between p-4 bg-blue-500 text-white rounded-lg shadow-md hover:bg-blue-600">
|
|
10
|
-
<h1 class="text-2xl font-bold">Hello Crosswind!</h1>
|
|
11
|
-
<button class="px-4 py-2 bg-white text-blue-500 rounded hover:bg-gray-100">
|
|
12
|
-
Click me
|
|
13
|
-
</button>
|
|
14
|
-
</div>
|
|
15
|
-
|
|
16
|
-
<div class="container mx-auto mt-8 p-6">
|
|
17
|
-
<h2 class="text-xl font-semibold mb-4">Features</h2>
|
|
18
|
-
<ul class="space-y-2">
|
|
19
|
-
<li class="flex items-center gap-2">
|
|
20
|
-
<span class="w-2 h-2 bg-green-500 rounded-full"></span>
|
|
21
|
-
<span class="text-gray-700">Automatic CSS generation</span>
|
|
22
|
-
</li>
|
|
23
|
-
<li class="flex items-center gap-2">
|
|
24
|
-
<span class="w-2 h-2 bg-green-500 rounded-full"></span>
|
|
25
|
-
<span class="text-gray-700">On-demand utilities</span>
|
|
26
|
-
</li>
|
|
27
|
-
<li class="flex items-center gap-2">
|
|
28
|
-
<span class="w-2 h-2 bg-green-500 rounded-full"></span>
|
|
29
|
-
<span class="text-gray-700">Tailwind-compatible</span>
|
|
30
|
-
</li>
|
|
31
|
-
</ul>
|
|
32
|
-
</div>
|
|
33
|
-
</body>
|
|
34
|
-
</html>
|
package/headwind
DELETED
package/src/build.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { CrosswindConfig } from './types'
|
|
2
|
-
import { CSSGenerator } from './generator'
|
|
3
|
-
import { Scanner } from './scanner'
|
|
4
|
-
import { CompileClassTransformer } from './transformer-compile-class'
|
|
5
|
-
|
|
6
|
-
export interface BuildResult {
|
|
7
|
-
css: string
|
|
8
|
-
classes: Set<string>
|
|
9
|
-
duration: number
|
|
10
|
-
compiledClasses?: Map<string, { className: string, utilities: string[] }>
|
|
11
|
-
transformedFiles?: Map<string, string>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Build CSS from content patterns
|
|
16
|
-
*/
|
|
17
|
-
export async function build(config: CrosswindConfig): Promise<BuildResult> {
|
|
18
|
-
const startTime = performance.now()
|
|
19
|
-
|
|
20
|
-
// Initialize compile class transformer if enabled
|
|
21
|
-
const transformer = config.compileClass?.enabled
|
|
22
|
-
? new CompileClassTransformer({
|
|
23
|
-
trigger: config.compileClass.trigger,
|
|
24
|
-
classPrefix: config.compileClass.classPrefix,
|
|
25
|
-
layer: config.compileClass.layer,
|
|
26
|
-
})
|
|
27
|
-
: null
|
|
28
|
-
|
|
29
|
-
// Scan files for utility classes
|
|
30
|
-
const scanner = new Scanner(config.content, transformer, {
|
|
31
|
-
attributify: config.attributify,
|
|
32
|
-
bracketSyntax: config.bracketSyntax,
|
|
33
|
-
})
|
|
34
|
-
const { classes, transformedFiles } = await scanner.scan()
|
|
35
|
-
|
|
36
|
-
// Add safelist classes
|
|
37
|
-
for (const cls of config.safelist) {
|
|
38
|
-
classes.add(cls)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// If using compile class transformer, also add compiled utilities
|
|
42
|
-
if (transformer) {
|
|
43
|
-
const compiledClasses = transformer.getCompiledClasses()
|
|
44
|
-
for (const [, { utilities }] of compiledClasses) {
|
|
45
|
-
for (const utility of utilities) {
|
|
46
|
-
classes.add(utility)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Generate CSS
|
|
52
|
-
const generator = new CSSGenerator(config)
|
|
53
|
-
|
|
54
|
-
for (const className of classes) {
|
|
55
|
-
generator.generate(className)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Preflight CSS is now added by generator.toCSS()
|
|
59
|
-
const css = generator.toCSS(true, config.minify)
|
|
60
|
-
const duration = performance.now() - startTime
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
css,
|
|
64
|
-
classes,
|
|
65
|
-
duration,
|
|
66
|
-
compiledClasses: transformer?.getCompiledClasses(),
|
|
67
|
-
transformedFiles,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Write CSS to output file
|
|
73
|
-
*/
|
|
74
|
-
export async function writeCSS(css: string, outputPath: string): Promise<void> {
|
|
75
|
-
await Bun.write(outputPath, css)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Write transformed files to disk
|
|
80
|
-
*/
|
|
81
|
-
export async function writeTransformedFiles(transformedFiles: Map<string, string>): Promise<void> {
|
|
82
|
-
const writes = Array.from(transformedFiles.entries()).map(([path, content]) =>
|
|
83
|
-
Bun.write(path, content),
|
|
84
|
-
)
|
|
85
|
-
await Promise.all(writes)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Build and write CSS to output file
|
|
90
|
-
*/
|
|
91
|
-
export async function buildAndWrite(config: CrosswindConfig): Promise<BuildResult> {
|
|
92
|
-
const result = await build(config)
|
|
93
|
-
await writeCSS(result.css, config.output)
|
|
94
|
-
|
|
95
|
-
// Write transformed files if compile class is enabled
|
|
96
|
-
if (result.transformedFiles && result.transformedFiles.size > 0) {
|
|
97
|
-
await writeTransformedFiles(result.transformedFiles)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return result
|
|
101
|
-
}
|