swatchkit 0.0.20 → 0.0.22

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
@@ -28,7 +28,7 @@ my-project/
28
28
  ├── css/
29
29
  │ ├── compositions/ # Layout primitives (flow, sidebar, etc.)
30
30
  │ ├── tokens.css # Generated from tokens/*.json
31
- │ ├── styles.css # Starter stylesheet (imports tokens + compositions)
31
+ │ ├── main.css # Main stylesheet (imports tokens + compositions)
32
32
  │ └── swatchkit-ui.css # UI styles for the documentation sidebar
33
33
  ├── swatchkit/
34
34
  │ ├── _layout.html # Layout template (you own this)
@@ -158,7 +158,7 @@ You can mix modular scales with manual overrides.
158
158
 
159
159
  ### 5. CSS Workflow
160
160
 
161
- SwatchKit generates `css/tokens.css` with your design tokens. The starter `css/styles.css` imports this file along with layout primitives:
161
+ SwatchKit generates `css/tokens.css` with your design tokens. Your `css/main.css` imports this file along with layout primitives:
162
162
 
163
163
  ```css
164
164
  @import 'tokens.css';
@@ -170,7 +170,7 @@ body {
170
170
  }
171
171
  ```
172
172
 
173
- The pattern library uses **your stylesheet** (`styles.css`), so components render exactly as they will in your app.
173
+ The pattern library uses **your stylesheet** (`main.css`), so components render exactly as they will in your app.
174
174
 
175
175
  **Documentation Styling:**
176
176
  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.
package/build.js CHANGED
@@ -116,7 +116,7 @@ function resolveSettings(cliOptions, fileConfig) {
116
116
  ? path.resolve(cwd, fileConfig.outDir)
117
117
  : path.join(cwd, "public/swatchkit");
118
118
 
119
- // CSS directory - where tokens.css and user's styles.css live
119
+ // CSS directory - where tokens.css and user's main.css live
120
120
  // Default: css/ at project root
121
121
  const cssDir = fileConfig.cssDir
122
122
  ? path.resolve(cwd, fileConfig.cssDir)
@@ -138,19 +138,22 @@ function resolveSettings(cliOptions, fileConfig) {
138
138
  tokensDir,
139
139
  exclude,
140
140
  fileConfig, // Expose config to init
141
- // Internal layout template (relative to this script)
141
+ // Internal layout templates (relative to this script)
142
142
  internalLayout: path.join(__dirname, "src/layout.html"),
143
- // Project specific layout override
143
+ internalPreviewLayout: path.join(__dirname, "src/preview-layout.html"),
144
+ // Project specific layout overrides
144
145
  projectLayout: path.join(swatchkitDir, "_layout.html"),
146
+ projectPreviewLayout: path.join(swatchkitDir, "_preview.html"),
145
147
 
146
148
  // Derived paths
147
149
  distCssDir: path.join(outDir, "css"),
148
150
  distTokensCssFile: path.join(outDir, "css", "tokens.css"),
149
151
  distJsDir: path.join(outDir, "js"),
152
+ distPreviewDir: path.join(outDir, "preview"),
150
153
  outputFile: path.join(outDir, "index.html"),
151
154
  outputJsFile: path.join(outDir, "js/swatches.js"),
152
155
  tokensCssFile: path.join(cssDir, "tokens.css"),
153
- stylesCssFile: path.join(cssDir, "styles.css"),
156
+ mainCssFile: path.join(cssDir, "main.css"),
154
157
  };
155
158
  }
156
159
 
@@ -220,6 +223,7 @@ function runInit(settings, options) {
220
223
  copyTemplate("typography.html", "typography.html");
221
224
  copyTemplate("spacing.html", "spacing.html");
222
225
  copyTemplate("fonts.html", "fonts.html");
226
+ copyTemplate("prose.html", "prose.html");
223
227
 
224
228
  // Create shared script for tokens UI
225
229
  const tokensScriptFile = path.join(tokensUiDir, "script.js");
@@ -230,12 +234,12 @@ function runInit(settings, options) {
230
234
  console.log(`Created tokens script at ${tokensScriptFile}`);
231
235
  }
232
236
 
233
- // Create starter styles.css
234
- if (!fs.existsSync(settings.stylesCssFile)) {
235
- const srcPath = path.join(__dirname, "src/blueprints/styles.css");
237
+ // Create main.css entry point
238
+ if (!fs.existsSync(settings.mainCssFile)) {
239
+ const srcPath = path.join(__dirname, "src/blueprints/main.css");
236
240
  const content = fs.readFileSync(srcPath, "utf-8");
237
- fs.writeFileSync(settings.stylesCssFile, content);
238
- console.log(`Created starter stylesheet at ${settings.stylesCssFile}`);
241
+ fs.writeFileSync(settings.mainCssFile, content);
242
+ console.log(`Created main stylesheet at ${settings.mainCssFile}`);
239
243
  }
240
244
 
241
245
  // Copy CSS Reset
@@ -282,6 +286,19 @@ function runInit(settings, options) {
282
286
  );
283
287
  process.exit(1);
284
288
  }
289
+
290
+ // Copy preview layout template (standalone page for individual swatches)
291
+ const targetPreview = settings.projectPreviewLayout;
292
+ if (!fs.existsSync(targetPreview)) {
293
+ if (fs.existsSync(settings.internalPreviewLayout)) {
294
+ const previewContent = fs.readFileSync(
295
+ settings.internalPreviewLayout,
296
+ "utf-8",
297
+ );
298
+ fs.writeFileSync(targetPreview, previewContent);
299
+ console.log(`Created preview layout at ${targetPreview}`);
300
+ }
301
+ }
285
302
  }
286
303
 
287
304
  // --- 5. Build Logic ---
@@ -428,6 +445,8 @@ function build(settings) {
428
445
  const sectionName =
429
446
  item === "tokens" ? "Design Tokens" : toTitleCase(item);
430
447
  const swatches = scanSwatches(itemPath, scripts, exclude);
448
+ // Tag each swatch with its section slug for preview paths
449
+ swatches.forEach((s) => (s.sectionSlug = item));
431
450
  if (swatches.length > 0) {
432
451
  sections[sectionName] = swatches;
433
452
  }
@@ -447,14 +466,14 @@ function build(settings) {
447
466
  if (stat.isFile() && item.endsWith(".html")) {
448
467
  const name = path.basename(item, ".html");
449
468
  const content = fs.readFileSync(itemPath, "utf-8");
450
- rootSwatches.push({ name, id: name, content });
469
+ rootSwatches.push({ name, id: name, content, sectionSlug: null });
451
470
  } else if (stat.isDirectory()) {
452
471
  const indexFile = path.join(itemPath, "index.html");
453
472
  if (fs.existsSync(indexFile)) {
454
473
  // Component folder swatch at root
455
474
  const name = item;
456
475
  const content = fs.readFileSync(indexFile, "utf-8");
457
- rootSwatches.push({ name, id: name, content });
476
+ rootSwatches.push({ name, id: name, content, sectionSlug: null });
458
477
 
459
478
  // Collect JS
460
479
  const jsFiles = fs
@@ -512,10 +531,16 @@ function build(settings) {
512
531
  .replace(/"/g, """)
513
532
  .replace(/'/g, "'");
514
533
 
534
+ // Build preview path: preview/{section}/{name}.html or preview/{name}.html
535
+ const previewPath = p.sectionSlug
536
+ ? `preview/${p.sectionSlug}/${p.id}.html`
537
+ : `preview/${p.id}.html`;
538
+
515
539
  return `
516
540
  <section id="${p.id}">
517
541
  <h2>${p.name} <small style="font-weight: normal; opacity: 0.6; font-size: 0.7em">(${section})</small></h2>
518
542
  <div class="preview">${p.content}</div>
543
+ <div class="swatchkit-preview-link"><a href="${previewPath}">View full screen</a></div>
519
544
  <pre><code>${escapedContent}</code></pre>
520
545
  </section>
521
546
  `;
@@ -533,7 +558,56 @@ function build(settings) {
533
558
  fs.writeFileSync(settings.outputJsFile, "// No swatch scripts found");
534
559
  }
535
560
 
536
- // 7. Load Layout
561
+ // 7. Generate preview pages (standalone full-screen view of each swatch)
562
+ let previewLayoutContent;
563
+ if (fs.existsSync(settings.projectPreviewLayout)) {
564
+ previewLayoutContent = fs.readFileSync(
565
+ settings.projectPreviewLayout,
566
+ "utf-8",
567
+ );
568
+ } else if (fs.existsSync(settings.internalPreviewLayout)) {
569
+ previewLayoutContent = fs.readFileSync(
570
+ settings.internalPreviewLayout,
571
+ "utf-8",
572
+ );
573
+ }
574
+
575
+ if (previewLayoutContent) {
576
+ let previewCount = 0;
577
+ sortedKeys.forEach((section) => {
578
+ const swatches = sections[section];
579
+ swatches.forEach((p) => {
580
+ // Determine output path and relative CSS path
581
+ let previewFile, cssPath;
582
+ if (p.sectionSlug) {
583
+ const sectionDir = path.join(settings.distPreviewDir, p.sectionSlug);
584
+ if (!fs.existsSync(sectionDir))
585
+ fs.mkdirSync(sectionDir, { recursive: true });
586
+ previewFile = path.join(sectionDir, `${p.id}.html`);
587
+ cssPath = "../../"; // preview/section/file.html -> ../../css/
588
+ } else {
589
+ if (!fs.existsSync(settings.distPreviewDir))
590
+ fs.mkdirSync(settings.distPreviewDir, { recursive: true });
591
+ previewFile = path.join(settings.distPreviewDir, `${p.id}.html`);
592
+ cssPath = "../"; // preview/file.html -> ../css/
593
+ }
594
+
595
+ const previewHtml = previewLayoutContent
596
+ .replace("<!-- PREVIEW_TITLE -->", p.name)
597
+ .replace("<!-- PREVIEW_CONTENT -->", p.content)
598
+ .replaceAll("<!-- CSS_PATH -->", cssPath)
599
+ .replace("<!-- HEAD_EXTRAS -->", "");
600
+
601
+ fs.writeFileSync(previewFile, previewHtml);
602
+ previewCount++;
603
+ });
604
+ });
605
+ console.log(
606
+ `Generated ${previewCount} preview pages in ${settings.distPreviewDir}`,
607
+ );
608
+ }
609
+
610
+ // 8. Load Layout
537
611
  let layoutContent;
538
612
  if (fs.existsSync(settings.projectLayout)) {
539
613
  console.log(`Using custom layout: ${settings.projectLayout}`);
@@ -551,7 +625,7 @@ function build(settings) {
551
625
  .replace("<!-- SWATCHES -->", swatchBlocks)
552
626
  .replace("<!-- HEAD_EXTRAS -->", headExtras);
553
627
 
554
- // 8. Write output
628
+ // 9. Write output
555
629
  fs.writeFileSync(settings.outputFile, finalHtml);
556
630
 
557
631
  console.log(`Build complete! Generated ${settings.outputFile}`);
@@ -563,7 +637,7 @@ function watch(settings) {
563
637
  settings.swatchkitDir,
564
638
  settings.tokensDir,
565
639
  settings.projectLayout,
566
- settings.stylesCssFile,
640
+ settings.mainCssFile,
567
641
  ].filter((p) => fs.existsSync(p)); // Only watch files that exist
568
642
 
569
643
  console.log("[SwatchKit] Watch mode enabled.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swatchkit",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "A lightweight tool for creating HTML pattern libraries.",
5
5
  "main": "build.js",
6
6
  "bin": {
package/src/layout.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>SwatchKit</title>
7
- <link rel="stylesheet" href="css/styles.css" />
7
+ <link rel="stylesheet" href="css/main.css" />
8
8
  <link rel="stylesheet" href="css/swatchkit-ui.css" />
9
9
  <!-- HEAD_EXTRAS -->
10
10
  </head>