swatchkit 0.0.7 → 0.0.8

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 (3) hide show
  1. package/README.md +56 -3
  2. package/build.js +32 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -71,7 +71,57 @@ SwatchKit scaffolds a design system for you. Edit the JSON files in `swatches/to
71
71
 
72
72
  Documentation patterns for these are automatically created alongside the JSON files.
73
73
 
74
- ### 3. CSS Workflow
74
+ ### 3. Intelligent Fluid Logic (New!)
75
+
76
+ SwatchKit can auto-calculate fluid typography and spacing scales.
77
+
78
+ **Static vs Fluid:**
79
+ * **Static:** Provide a `value` (e.g. `"16px"`).
80
+ * **Fluid:** Provide `min` and `max` (e.g. `16` and `18`).
81
+ * **Auto-Fluid:** Provide just ONE side (`min` or `max`), and SwatchKit calculates the other using a default ratio (1.125).
82
+
83
+ **Example (`swatches/tokens/text-sizes.json`):**
84
+ ```json
85
+ {
86
+ "title": "Text Sizes",
87
+ "fluidRatio": 1.25,
88
+ "items": [
89
+ { "name": "base", "value": "1rem" }, // Static: 1rem always
90
+ { "name": "md", "min": 16, "max": 20 }, // Fluid: 16px -> 20px
91
+ { "name": "lg", "max": 24 }, // Auto: 19.2px -> 24px (24 / 1.25)
92
+ { "name": "xl", "min": 32 } // Auto: 32px -> 40px (32 * 1.25)
93
+ ]
94
+ }
95
+ ```
96
+
97
+ **Generated CSS:**
98
+ ```css
99
+ :root {
100
+ --s-base: 1rem;
101
+ --s-md: clamp(1rem, ... , 1.25rem);
102
+ --s-lg: clamp(1.2rem, ... , 1.5rem);
103
+ --s-xl: clamp(2rem, ... , 2.5rem);
104
+ }
105
+ ```
106
+
107
+ ### 4. Hybrid Text Leading
108
+
109
+ You can mix modular scales with manual overrides.
110
+
111
+ **Example (`swatches/tokens/text-leading.json`):**
112
+ ```json
113
+ {
114
+ "base": 1,
115
+ "ratio": 1.2,
116
+ "items": [
117
+ { "name": "tight", "step": -1 }, // Modular: 1 * (1.2 ^ -1)
118
+ { "name": "flat", "value": 1 }, // Manual: 1
119
+ { "name": "loose", "step": 1 } // Modular: 1 * (1.2 ^ 1)
120
+ ]
121
+ }
122
+ ```
123
+
124
+ ### 5. CSS Workflow
75
125
 
76
126
  SwatchKit generates `css/tokens.css` with your design tokens as CSS custom properties. The starter `css/styles.css` imports this file:
77
127
 
@@ -88,7 +138,7 @@ body {
88
138
 
89
139
  The pattern library uses **your stylesheet**, so components render exactly as they will in your app.
90
140
 
91
- ### 4. Custom Layouts
141
+ ### 6. Custom Layouts
92
142
  When you run `swatchkit init`, we create `swatches/_layout.html`.
93
143
  **You own this file.**
94
144
  * Link to your own stylesheets.
@@ -97,7 +147,7 @@ When you run `swatchkit init`, we create `swatches/_layout.html`.
97
147
 
98
148
  SwatchKit injects content into the `<!-- PATTERNS -->`, `<!-- SIDEBAR_LINKS -->`, and `<!-- HEAD_EXTRAS -->` placeholders.
99
149
 
100
- ### 5. JavaScript Bundling
150
+ ### 7. JavaScript Bundling
101
151
  If your component needs client-side JS:
102
152
  1. Create a folder: `swatches/carousel/`.
103
153
  2. Add `index.html` (Markup).
@@ -138,6 +188,9 @@ module.exports = {
138
188
  // Override CSS directory
139
189
  css: './assets/css',
140
190
 
191
+ // Exclude files (supports glob patterns)
192
+ exclude: ['*.test.js', 'temp*'],
193
+
141
194
  // Override token settings
142
195
  tokens: {
143
196
  input: './design-tokens', // Where token JSON files live
package/build.js CHANGED
@@ -66,6 +66,27 @@ function loadConfig(configPath) {
66
66
  return {};
67
67
  }
68
68
 
69
+ // --- 2.5 Glob Matching Helper ---
70
+ function matchesPattern(filename, pattern) {
71
+ // Simple wildcard support
72
+ if (pattern.includes("*")) {
73
+ const parts = pattern.split("*");
74
+ // Handle "foo*"
75
+ if (pattern.endsWith("*") && !pattern.startsWith("*")) {
76
+ return filename.startsWith(parts[0]);
77
+ }
78
+ // Handle "*bar"
79
+ if (pattern.startsWith("*") && !pattern.endsWith("*")) {
80
+ return filename.endsWith(parts[1]);
81
+ }
82
+ // Handle "*bar*"
83
+ if (pattern.startsWith("*") && pattern.endsWith("*")) {
84
+ return filename.includes(parts[1]);
85
+ }
86
+ }
87
+ return filename === pattern;
88
+ }
89
+
69
90
  // --- 3. Smart Defaults & Path Resolution ---
70
91
  function resolveSettings(cliOptions, fileConfig) {
71
92
  const cwd = process.cwd();
@@ -108,12 +129,16 @@ function resolveSettings(cliOptions, fileConfig) {
108
129
  const tokensDir = fileConfig.tokens?.input
109
130
  ? path.resolve(cwd, fileConfig.tokens.input)
110
131
  : path.join(patternsDir, "tokens");
132
+
133
+ // Exclude patterns
134
+ const exclude = fileConfig.exclude || [];
111
135
 
112
136
  return {
113
137
  patternsDir,
114
138
  outDir,
115
139
  cssDir,
116
140
  tokensDir,
141
+ exclude,
117
142
  fileConfig, // Expose config to init
118
143
  // Internal layout template (relative to this script)
119
144
  internalLayout: path.join(__dirname, "src/layout.html"),
@@ -264,8 +289,10 @@ function scanDirectory(dir, scriptsCollector, exclude = []) {
264
289
  const items = fs.readdirSync(dir);
265
290
 
266
291
  items.forEach((item) => {
267
- // Skip excluded items, _layout.html, or hidden files
268
- if (exclude.includes(item)) return;
292
+ // Skip excluded items
293
+ if (exclude.some(pattern => matchesPattern(item, pattern))) return;
294
+
295
+ // Skip _layout.html or hidden files
269
296
  if (item.startsWith("_") || item.startsWith(".")) return;
270
297
 
271
298
  const itemPath = path.join(dir, item);
@@ -372,8 +399,9 @@ function build(settings) {
372
399
  const tokensDir = path.join(settings.patternsDir, "tokens");
373
400
  const tokenPages = scanDirectory(tokensDir, scripts);
374
401
 
375
- // Pass 2: Patterns (in [patternsDir], excluding 'tokens')
376
- const patternPages = scanDirectory(settings.patternsDir, scripts, ["tokens"]);
402
+ // Pass 2: Patterns (in [patternsDir], excluding 'tokens' and user excludes)
403
+ const userExcludes = settings.exclude || [];
404
+ const patternPages = scanDirectory(settings.patternsDir, scripts, ["tokens", ...userExcludes]);
377
405
 
378
406
  // Combine for content generation (Tokens first, then Patterns)
379
407
  const allPatterns = [...tokenPages, ...patternPages];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swatchkit",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "A lightweight tool for creating HTML pattern libraries.",
5
5
  "main": "build.js",
6
6
  "bin": {