swatchkit 0.0.12 → 0.0.13

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
@@ -21,8 +21,10 @@ This will create:
21
21
  ```
22
22
  my-project/
23
23
  ├── css/
24
- │ ├── tokens.css # Generated design tokens (CSS custom properties)
25
- └── styles.css # Starter stylesheet (imports tokens.css)
24
+ │ ├── compositions/ # Layout primitives (flow, sidebar, etc.)
25
+ ├── tokens.css # Generated design tokens
26
+ │ ├── styles.css # Starter stylesheet (imports tokens + compositions)
27
+ │ └── swatchkit-ui.css # UI styles for the documentation sidebar
26
28
  ├── swatchkit/
27
29
  │ ├── _layout.html # Layout template (you own this)
28
30
  │ └── tokens/ # Token definitions + documentation patterns
@@ -55,6 +57,7 @@ Then add it to your `package.json` scripts:
55
57
  ## Features
56
58
 
57
59
  ### 1. The Magic Folder & Project Structure
60
+
58
61
  By default, SwatchKit looks for a `swatchkit/` folder in your project root.
59
62
 
60
63
  **Organize by Folder:**
@@ -74,19 +77,21 @@ swatchkit/
74
77
  └── flow.html
75
78
  ```
76
79
 
77
- * **Files at root:** Go to the "Patterns" section.
78
- * **Subfolders:** Create a new section (e.g. `utilities/` -> "Utilities").
79
- * **Tokens:** Special folder for JSON definitions.
80
+ - **Files at root:** Go to the "Patterns" section.
81
+ - **Subfolders:** Create a new section (e.g. `utilities/` -> "Utilities").
82
+ - **Tokens:** Special folder for JSON definitions.
80
83
 
81
84
  ### 2. Design Token Engine
85
+
82
86
  SwatchKit scaffolds a design system for you. Edit the JSON files in `swatchkit/tokens/`, and SwatchKit auto-generates `css/tokens.css`.
83
87
 
84
88
  **Supported Tokens:**
85
- * **Colors** (`colors.json`): Generates palettes.
86
- * **Fluid Typography** (`text-sizes.json`): Generates `clamp()` based type scales using Utopia methodology.
87
- * **Fluid Spacing** (`spacing.json`): Generates `clamp()` based spacing.
88
- * **Modular Leading** (`text-leading.json`): Generates line-heights using `pow()` modular scales.
89
- * **Fonts & Weights**: Manages font families and weights.
89
+
90
+ - **Colors** (`colors.json`): Generates palettes.
91
+ - **Fluid Typography** (`text-sizes.json`): Generates `clamp()` based type scales using Utopia methodology.
92
+ - **Fluid Spacing** (`spacing.json`): Generates `clamp()` based spacing.
93
+ - **Modular Leading** (`text-leading.json`): Generates line-heights using `pow()` modular scales.
94
+ - **Fonts & Weights**: Manages font families and weights.
90
95
 
91
96
  Documentation patterns for these are automatically created alongside the JSON files.
92
97
 
@@ -95,33 +100,36 @@ Documentation patterns for these are automatically created alongside the JSON fi
95
100
  SwatchKit can auto-calculate fluid typography and spacing scales.
96
101
 
97
102
  **Static vs Fluid:**
98
- * **Static:** Provide a `value` (e.g. `"16px"`).
99
- * **Fluid:** Provide `min` and `max` (e.g. `16` and `18`).
100
- * **Auto-Fluid:** Provide just ONE side (`min` or `max`), and SwatchKit calculates the other using a default ratio (1.125).
103
+
104
+ - **Static:** Provide a `value` (e.g. `"16px"`).
105
+ - **Fluid:** Provide `min` and `max` (e.g. `16` and `18`).
106
+ - **Auto-Fluid:** Provide just ONE side (`min` or `max`), and SwatchKit calculates the other using a default ratio (1.125).
101
107
 
102
108
  **Example (`swatchkit/tokens/text-sizes.json`):**
109
+
103
110
  ```json
104
111
  {
105
112
  "title": "Text Sizes",
106
113
  "fluidRatio": 1.25,
107
114
  "items": [
108
- { "name": "base", "value": "1rem" }, // Static: 1rem always
109
- { "name": "md", "min": 16, "max": 20 }, // Fluid: 16px -> 20px
110
- { "name": "lg", "max": 24 }, // Auto: 19.2px -> 24px (24 / 1.25)
111
- { "name": "xl", "min": 32 }, // Auto: 32px -> 40px (32 * 1.25)
115
+ { "name": "base", "value": "1rem" }, // Static: 1rem always
116
+ { "name": "md", "min": 16, "max": 20 }, // Fluid: 16px -> 20px
117
+ { "name": "lg", "max": 24 }, // Auto: 19.2px -> 24px (24 / 1.25)
118
+ { "name": "xl", "min": 32 }, // Auto: 32px -> 40px (32 * 1.25)
112
119
  { "name": "jumbo", "max": 64, "fluidRatio": 1.5 } // Auto: 42.6px -> 64px (64 / 1.5)
113
120
  ]
114
121
  }
115
122
  ```
116
123
 
117
124
  **Generated CSS:**
125
+
118
126
  ```css
119
127
  :root {
120
128
  --s-base: 1rem;
121
- --s-md: clamp(1rem, ... , 1.25rem);
122
- --s-lg: clamp(1.2rem, ... , 1.5rem);
123
- --s-xl: clamp(2rem, ... , 2.5rem);
124
- --s-jumbo: clamp(2.66rem, ... , 4rem);
129
+ --s-md: clamp(1rem, ..., 1.25rem);
130
+ --s-lg: clamp(1.2rem, ..., 1.5rem);
131
+ --s-xl: clamp(2rem, ..., 2.5rem);
132
+ --s-jumbo: clamp(2.66rem, ..., 4rem);
125
133
  }
126
134
  ```
127
135
 
@@ -130,49 +138,56 @@ SwatchKit can auto-calculate fluid typography and spacing scales.
130
138
  You can mix modular scales with manual overrides.
131
139
 
132
140
  **Example (`swatchkit/tokens/text-leading.json`):**
141
+
133
142
  ```json
134
143
  {
135
144
  "base": 1,
136
145
  "ratio": 1.2,
137
146
  "items": [
138
- { "name": "tight", "step": -1 }, // Modular: 1 * (1.2 ^ -1)
139
- { "name": "flat", "value": 1 }, // Manual: 1
140
- { "name": "loose", "step": 1 } // Modular: 1 * (1.2 ^ 1)
147
+ { "name": "tight", "step": -1 }, // Modular: 1 * (1.2 ^ -1)
148
+ { "name": "flat", "value": 1 }, // Manual: 1
149
+ { "name": "loose", "step": 1 } // Modular: 1 * (1.2 ^ 1)
141
150
  ]
142
151
  }
143
152
  ```
144
153
 
145
154
  ### 5. CSS Workflow
146
155
 
147
- SwatchKit generates `css/tokens.css` with your design tokens as CSS custom properties. The starter `css/styles.css` imports this file:
156
+ SwatchKit generates `css/tokens.css` with your design tokens. The starter `css/styles.css` imports this file along with layout primitives:
148
157
 
149
158
  ```css
150
159
  @import 'tokens.css';
160
+ @import 'compositions/index.css';
151
161
 
152
162
  body {
153
163
  font-family: var(--font-base);
154
164
  color: var(--color-dark);
155
165
  }
156
-
157
- /* Add your app styles here */
158
166
  ```
159
167
 
160
- The pattern library uses **your stylesheet**, so components render exactly as they will in your app.
168
+ The pattern library uses **your stylesheet** (`styles.css`), so components render exactly as they will in your app.
169
+
170
+ **Documentation Styling:**
171
+ The sidebar and documentation layout are styled by `css/swatchkit-ui.css`. This file is separate from your app styles so you can customize the docs UI without affecting your production CSS.
161
172
 
162
173
  ### 6. Custom Layouts
174
+
163
175
  When you run `swatchkit init`, we create `swatchkit/_layout.html`.
164
176
  **You own this file.**
165
- * Link to your own stylesheets.
166
- * Add custom fonts, scripts, or meta tags.
167
- * Change the HTML structure, logo, or classes.
177
+
178
+ - Link to your own stylesheets.
179
+ - Add custom fonts, scripts, or meta tags.
180
+ - Change the HTML structure, logo, or classes.
168
181
 
169
182
  SwatchKit injects content into the `<!-- PATTERNS -->`, `<!-- SIDEBAR_LINKS -->`, and `<!-- HEAD_EXTRAS -->` placeholders.
170
183
 
171
184
  ### 7. JavaScript Bundling
185
+
172
186
  If your component needs client-side JS:
173
- 1. Create a folder: `swatchkit/carousel/`.
174
- 2. Add `index.html` (Markup).
175
- 3. Add `script.js` (Logic).
187
+
188
+ 1. Create a folder: `swatchkit/carousel/`.
189
+ 2. Add `index.html` (Markup).
190
+ 3. Add `script.js` (Logic).
176
191
 
177
192
  SwatchKit automatically bundles your JS files, wraps them in a safety scope (IIFE), and injects them into the final build.
178
193
 
@@ -183,33 +198,40 @@ swatchkit [command] [options]
183
198
  ```
184
199
 
185
200
  ### Commands
186
- * `swatchkit` (Default): Builds the library.
187
- * `swatchkit init`: Scaffolds the layout and token files.
201
+
202
+ - `swatchkit` (Default): Builds the library.
203
+ - `swatchkit init`: Scaffolds the layout and token files.
188
204
 
189
205
  ### Flags
190
- | Flag | Short | Description |
191
- | :--- | :--- | :--- |
192
- | `--watch` | `-w` | Watch files and rebuild on change. |
193
- | `--config` | `-c` | Path to config file. |
194
- | `--input` | `-i` | Pattern directory (Default: `swatchkit/`). |
195
- | `--outDir` | `-o` | Output directory (Default: `public/swatchkit`). |
196
- | `--force` | `-f` | Overwrite layout file during init. |
206
+
207
+ | Flag | Short | Description |
208
+ | :--------- | :---- | :---------------------------------------------- |
209
+ | `--watch` | `-w` | Watch files and rebuild on change. |
210
+ | `--config` | `-c` | Path to config file. |
211
+ | `--input` | `-i` | Pattern directory (Default: `swatchkit/`). |
212
+ | `--outDir` | `-o` | Output directory (Default: `public/swatchkit`). |
213
+ | `--force` | `-f` | Overwrite layout file during init. |
197
214
 
198
215
  ## Configuration
216
+
199
217
  Optional. Create `swatchkit.config.js` in your root for persistent settings.
200
218
 
201
219
  ```javascript
202
220
  module.exports = {
203
221
  // Override default pattern directory
204
- input: './patterns',
222
+ input: "./patterns",
205
223
 
206
224
  // Override default output directory
207
- outDir: './dist/patterns',
208
-
225
+ outDir: "./dist/patterns",
226
+
209
227
  // Override CSS directory
210
- css: './assets/css',
211
-
228
+ css: "./assets/css",
229
+
212
230
  // Exclude files (supports glob patterns)
213
- exclude: ['*.test.js', 'temp*']
231
+ exclude: ["*.test.js", "temp*"],
214
232
  };
215
233
  ```
234
+
235
+ ## Acknowledgements
236
+
237
+ The CSS compositions included by default in SwatchKit are adapted from [Every Layout](https://every-layout.dev/) by Heydon Pickering and Andy Bell. Highly recommend their documentation for a deep dive into their brilliant CSS techniques.
package/build.js CHANGED
@@ -243,6 +243,21 @@ function runInit(settings, options) {
243
243
  console.log(`Created starter stylesheet at ${settings.stylesCssFile}`);
244
244
  }
245
245
 
246
+ // Copy Compositions
247
+ const compositionsSrc = path.join(__dirname, 'src/blueprints/compositions');
248
+ const compositionsDest = path.join(settings.cssDir, 'compositions');
249
+ if (fs.existsSync(compositionsSrc)) {
250
+ copyDir(compositionsSrc, compositionsDest);
251
+ }
252
+
253
+ // Copy SwatchKit UI Styles
254
+ const uiSrc = path.join(__dirname, 'src/blueprints/swatchkit-ui.css');
255
+ const uiDest = path.join(settings.cssDir, 'swatchkit-ui.css');
256
+ if (fs.existsSync(uiSrc) && !fs.existsSync(uiDest)) {
257
+ fs.copyFileSync(uiSrc, uiDest);
258
+ console.log(`Created UI styles at ${uiDest}`);
259
+ }
260
+
246
261
  // Generate initial tokens.css
247
262
  processTokens(settings.tokensDir, settings.cssDir);
248
263
 
@@ -267,6 +282,25 @@ function runInit(settings, options) {
267
282
  }
268
283
 
269
284
  // --- 5. Build Logic ---
285
+ function copyDir(src, dest, force = false) {
286
+ if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
287
+ const entries = fs.readdirSync(src, { withFileTypes: true });
288
+
289
+ for (const entry of entries) {
290
+ const srcPath = path.join(src, entry.name);
291
+ const destPath = path.join(dest, entry.name);
292
+
293
+ if (entry.isDirectory()) {
294
+ copyDir(srcPath, destPath, force);
295
+ } else {
296
+ if (force || !fs.existsSync(destPath)) {
297
+ fs.copyFileSync(srcPath, destPath);
298
+ if (!force) console.log(`Created file at ${destPath}`);
299
+ }
300
+ }
301
+ }
302
+ }
303
+
270
304
  function scanSwatches(dir, scriptsCollector, exclude = []) {
271
305
  const swatches = [];
272
306
  if (!fs.existsSync(dir)) return swatches;
@@ -362,18 +396,10 @@ function build(settings) {
362
396
  // 2.5 Process Tokens
363
397
  processTokens(settings.tokensDir, settings.cssDir);
364
398
 
365
- // 3. Copy CSS files
399
+ // 3. Copy CSS files (recursively)
366
400
  if (fs.existsSync(settings.cssDir)) {
367
401
  console.log("Copying CSS...");
368
- const cssFiles = fs
369
- .readdirSync(settings.cssDir)
370
- .filter((file) => file.endsWith(".css"));
371
- cssFiles.forEach((file) => {
372
- fs.copyFileSync(
373
- path.join(settings.cssDir, file),
374
- path.join(settings.distCssDir, file),
375
- );
376
- });
402
+ copyDir(settings.cssDir, settings.distCssDir, true);
377
403
  }
378
404
 
379
405
  // 4. Read swatches & JS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swatchkit",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "A lightweight tool for creating HTML pattern libraries.",
5
5
  "main": "build.js",
6
6
  "bin": {
package/src/layout.html CHANGED
@@ -1,90 +1,26 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>SwatchKit</title>
7
7
  <link rel="stylesheet" href="css/styles.css" />
8
+ <link rel="stylesheet" href="css/swatchkit-ui.css" />
8
9
  <!-- HEAD_EXTRAS -->
9
- <style>
10
- body {
11
- display: flex;
12
- margin: 0;
13
- min-height: 100vh;
14
- font-family: system-ui, -apple-system, sans-serif;
15
- }
16
- aside {
17
- width: 250px;
18
- background-color: #f7f7f7;
19
- border-right: 1px solid #e5e5e5;
20
- padding: 2rem 1.5rem;
21
- flex-shrink: 0;
22
- height: 100vh;
23
- position: sticky;
24
- top: 0;
25
- overflow-y: auto;
26
- }
27
- aside h2 {
28
- margin-top: 0;
29
- font-size: 1.25rem;
30
- margin-bottom: 1.5rem;
31
- }
32
- aside nav {
33
- display: flex;
34
- flex-direction: column;
35
- gap: 0.75rem;
36
- }
37
- aside nav a {
38
- text-decoration: none;
39
- color: #333;
40
- }
41
- aside nav a:hover {
42
- color: #000;
43
- text-decoration: underline;
44
- }
45
- main {
46
- flex: 1;
47
- padding: 3rem;
48
- max-width: 1200px;
49
- }
50
- section {
51
- margin-bottom: 4rem;
52
- border-bottom: 1px solid #eee;
53
- padding-bottom: 2rem;
54
- }
55
- section h2 {
56
- margin-top: 0;
57
- font-size: 1.5rem;
58
- margin-bottom: 1rem;
59
- }
60
- .preview {
61
- border: 1px solid #e5e5e5;
62
- padding: 2rem;
63
- border-radius: 4px;
64
- background: white;
65
- margin-bottom: 1.5rem;
66
- }
67
- pre {
68
- background: #2d2d2d;
69
- color: #fff;
70
- padding: 1rem;
71
- border-radius: 4px;
72
- overflow-x: auto;
73
- }
74
- </style>
75
- </head>
76
- <body>
77
- <aside>
10
+ </head>
11
+ <body>
12
+ <div class="sidebar">
13
+ <nav class="swatchkit-nav flow">
78
14
  <header>
79
15
  <h2>SwatchKit</h2>
80
16
  </header>
81
- <nav>
82
- <!-- SIDEBAR_LINKS -->
83
- </nav>
84
- </aside>
85
- <main>
17
+ <!-- SIDEBAR_LINKS -->
18
+ </nav>
19
+ <main class="swatchkit-main flow">
86
20
  <!-- SWATCHES -->
87
- </main>
21
+ </main>
22
+ </div>
88
23
  <script src="js/swatches.js"></script>
89
- </body>
90
- </html>
24
+ </body>
25
+ </html>
26
+