@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.
Files changed (86) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +390 -0
  3. package/dist/build.d.ts +24 -0
  4. package/dist/config.d.ts +5 -0
  5. package/dist/generator.d.ts +31 -0
  6. package/dist/index.d.ts +10 -0
  7. package/dist/index.js +12798 -0
  8. package/dist/parser.d.ts +42 -0
  9. package/dist/plugin.d.ts +22 -0
  10. package/dist/preflight-forms.d.ts +5 -0
  11. package/dist/preflight.d.ts +2 -0
  12. package/dist/rules-advanced.d.ts +27 -0
  13. package/dist/rules-effects.d.ts +25 -0
  14. package/dist/rules-forms.d.ts +7 -0
  15. package/dist/rules-grid.d.ts +13 -0
  16. package/dist/rules-interactivity.d.ts +41 -0
  17. package/dist/rules-layout.d.ts +26 -0
  18. package/dist/rules-transforms.d.ts +33 -0
  19. package/dist/rules-typography.d.ts +41 -0
  20. package/dist/rules.d.ts +39 -0
  21. package/dist/scanner.d.ts +18 -0
  22. package/dist/transformer-compile-class.d.ts +37 -0
  23. package/{src/types.ts → dist/types.d.ts} +17 -86
  24. package/package.json +1 -1
  25. package/PLUGIN.md +0 -235
  26. package/benchmark/framework-comparison.bench.ts +0 -850
  27. package/bin/cli.ts +0 -365
  28. package/bin/crosswind +0 -0
  29. package/bin/headwind +0 -0
  30. package/build.ts +0 -8
  31. package/crosswind.config.ts +0 -9
  32. package/example/comprehensive.html +0 -70
  33. package/example/index.html +0 -21
  34. package/example/output.css +0 -236
  35. package/examples/plugin/README.md +0 -112
  36. package/examples/plugin/build.ts +0 -32
  37. package/examples/plugin/src/index.html +0 -34
  38. package/examples/plugin/src/index.ts +0 -7
  39. package/headwind +0 -2
  40. package/src/build.ts +0 -101
  41. package/src/config.ts +0 -529
  42. package/src/generator.ts +0 -2173
  43. package/src/index.ts +0 -10
  44. package/src/parser.ts +0 -1471
  45. package/src/plugin.ts +0 -118
  46. package/src/preflight-forms.ts +0 -229
  47. package/src/preflight.ts +0 -388
  48. package/src/rules-advanced.ts +0 -477
  49. package/src/rules-effects.ts +0 -461
  50. package/src/rules-forms.ts +0 -103
  51. package/src/rules-grid.ts +0 -241
  52. package/src/rules-interactivity.ts +0 -525
  53. package/src/rules-layout.ts +0 -385
  54. package/src/rules-transforms.ts +0 -412
  55. package/src/rules-typography.ts +0 -486
  56. package/src/rules.ts +0 -809
  57. package/src/scanner.ts +0 -84
  58. package/src/transformer-compile-class.ts +0 -275
  59. package/test/advanced-features.test.ts +0 -911
  60. package/test/arbitrary.test.ts +0 -396
  61. package/test/attributify.test.ts +0 -592
  62. package/test/bracket-syntax.test.ts +0 -1133
  63. package/test/build.test.ts +0 -99
  64. package/test/colors.test.ts +0 -934
  65. package/test/flexbox.test.ts +0 -669
  66. package/test/generator.test.ts +0 -597
  67. package/test/grid.test.ts +0 -584
  68. package/test/layout.test.ts +0 -404
  69. package/test/modifiers.test.ts +0 -417
  70. package/test/parser.test.ts +0 -564
  71. package/test/performance-regression.test.ts +0 -376
  72. package/test/performance.test.ts +0 -568
  73. package/test/plugin.test.ts +0 -160
  74. package/test/scanner.test.ts +0 -94
  75. package/test/sizing.test.ts +0 -481
  76. package/test/spacing.test.ts +0 -394
  77. package/test/transformer-compile-class.test.ts +0 -287
  78. package/test/transforms.test.ts +0 -448
  79. package/test/typography.test.ts +0 -632
  80. package/test/variants-form-states.test.ts +0 -225
  81. package/test/variants-group-peer.test.ts +0 -66
  82. package/test/variants-media.test.ts +0 -213
  83. package/test/variants-positional.test.ts +0 -58
  84. package/test/variants-pseudo-elements.test.ts +0 -47
  85. package/test/variants-state.test.ts +0 -62
  86. 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
@@ -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>
@@ -1,7 +0,0 @@
1
- // Import HTML file - the plugin will process it and inject Crosswind CSS
2
- import html from './index.html'
3
-
4
- // You can use the HTML content
5
- document.body.innerHTML = html
6
-
7
- export default html
package/headwind DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bun
2
- import('./bin/cli')
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
- }