@pure-ds/core 0.4.34 → 0.4.36

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.
@@ -0,0 +1,599 @@
1
+ # Getting Started with Pure Design System
2
+
3
+ From zero to hero with PDS.
4
+
5
+ ## 1. Installation (or not)
6
+
7
+ ### Option A: NPM Package (Recommended)
8
+
9
+ ```bash
10
+ npm install @pure-ds/core
11
+ ```
12
+
13
+ **What happens during install:**
14
+
15
+ PDS automatically sets up your project:
16
+ - ✅ Creates `pds.config.js` with commented examples (if it doesn't exist)
17
+ - ✅ Exports static assets to your web root (components, icons, styles)
18
+ - ✅ Copies AI/Copilot instructions to `.github/copilot-instructions.md`
19
+ - ✅ Adds helper scripts to your `package.json` (`pds:export`, `pds:build-icons`)
20
+
21
+ The generated `pds.config.js` includes:
22
+
23
+ ```javascript
24
+ // pds.config.js (auto-generated)
25
+ export const config = {
26
+ mode: "live",
27
+ preset: "default",
28
+
29
+ // Uncomment and customize as needed:
30
+ // design: { colors: { primary: '#007acc' } },
31
+ // enhancers: [ /* custom enhancements */ ],
32
+ // autoDefine: { predefine: ['pds-icon'] }
33
+ }
34
+ ```
35
+
36
+ Then initialize in your app:
37
+
38
+ ```javascript
39
+ import { PDS } from '@pure-ds/core';
40
+ import { config } from "./pds.config.js"; // project root
41
+
42
+ await PDS.start(config); // That's it! Start writing semantic HTML.
43
+ ```
44
+
45
+ **Manual config generation:**
46
+
47
+ ```bash
48
+ # Create or regenerate config with examples
49
+ npx pds-init-config
50
+
51
+ # Force overwrite existing config
52
+ npx pds-init-config --force
53
+ ```
54
+
55
+ ### Option B: CDN (Zero Install)
56
+
57
+ Perfect for quick prototypes and learning:
58
+
59
+ ```html
60
+ <!DOCTYPE html>
61
+ <html lang="en">
62
+ <head>
63
+ <meta charset="UTF-8">
64
+ <title>My PDS App</title>
65
+ <script type="module" defer>
66
+ import { PDS } from "https://unpkg.com/pure-ds@latest/public/assets/js/pds.js";
67
+
68
+ await PDS.start({
69
+ mode: "live",
70
+ preset: "social-feed"
71
+ });
72
+ </script>
73
+ </head>
74
+ <body class="container">
75
+ [...]
76
+ </body>
77
+ </html>
78
+ ```
79
+
80
+ > See the [**PDS CodePen Collection**](https://codepen.io/collection/rBjkOy)
81
+ > These live examples let you see PDS in action and fork them for your own experiments.
82
+
83
+ ---
84
+
85
+ ### Power Through Composition
86
+
87
+ PDS gives you high-level primitives that compose naturally. No atomic utility classes to memorize—just semantic HTML with meaningful class names:
88
+
89
+ ```html
90
+ <!-- A complete card with surface treatment -->
91
+ <article class="card surface-elevated">
92
+ <header>
93
+ <h3>Welcome to PDS</h3>
94
+ <p class="text-muted">The browser is the framework</p>
95
+ </header>
96
+ <p>Write semantic HTML, get beautiful results.</p>
97
+ <footer class="flex gap-sm justify-end">
98
+ <button class="btn-secondary">Learn More</button>
99
+ <button class="btn-primary">Get Started</button>
100
+ </footer>
101
+ </article>
102
+ ```
103
+
104
+ **What's happening here:**
105
+ - `article.card` → semantic card primitive with proper spacing and borders
106
+ - `.surface-elevated` → contextual surface with shadow and background
107
+ - `header` with `h3` + `.text-muted` → automatic title/subtitle hierarchy
108
+ - `footer.flex.gap-sm.justify-end` → action area with button alignment
109
+
110
+ Each class represents a **design decision**, not a CSS property. That's the PDS difference.
111
+
112
+ ---
113
+
114
+ ## 2. Understanding pds.config.js
115
+
116
+ The heart of PDS is a simple JavaScript configuration file:
117
+
118
+ ```javascript
119
+ // pds.config.js
120
+ export const config = {
121
+ // Runtime mode: 'live' generates CSS at runtime, 'static' uses pre-built files
122
+ mode: "live",
123
+
124
+ // Start with a preset (optional)
125
+ preset: "default", // ocean-breeze, midnight-steel, sunset-vibes...
126
+
127
+ // Design tokens - override any preset values
128
+ design: {
129
+ colors: {
130
+ primary: '#007acc',
131
+ secondary: '#5c2d91'
132
+ },
133
+ typography: {
134
+ baseFontSize: 16,
135
+ fontScale: 1.25,
136
+ fontFamilyHeadings: 'Inter, sans-serif',
137
+ fontFamilyBody: 'Inter, sans-serif'
138
+ },
139
+ spatialRhythm: {
140
+ baseUnit: 8,
141
+ scaleRatio: 1.5
142
+ }
143
+ },
144
+
145
+ // Web Component auto-loading
146
+ autoDefine: {
147
+ predefine: ["pds-icon", "pds-drawer", "pds-toaster"]
148
+ },
149
+
150
+ // Custom progressive enhancements (optional)
151
+ enhancers: [
152
+ {
153
+ selector: '[data-tooltip]',
154
+ description: 'Adds tooltip on hover',
155
+ run: (element) => { /* enhancement logic */ }
156
+ }
157
+ ],
158
+
159
+ // Logging callback (optional)
160
+ log(level, message, ...data) {
161
+ console[level](message, ...data);
162
+ }
163
+ };
164
+ ```
165
+
166
+ ### Available Presets
167
+
168
+ ```javascript
169
+ Object.keys(PDS.presets);
170
+ // ['default', 'ocean-breeze', 'midnight-steel', 'sunset-vibes',
171
+ // 'forest-calm', 'lavender-dream', 'coral-energy', 'arctic-frost',
172
+ // 'golden-hour', 'neon-city', 'travel-market', 'mobility-app']
173
+ ```
174
+
175
+ ### Live vs Static Mode
176
+
177
+ | Feature | Live Mode | Static Mode |
178
+ |---------|-----------|-------------|
179
+ | CSS Generation | Runtime (in browser) | Build time |
180
+ | Config changes | Instant preview | Requires rebuild |
181
+ | Best for | Development, configurators | Production |
182
+ | `PDS.compiled` | Full access | Not available |
183
+
184
+ ---
185
+
186
+ ## 3. Running a Local Storybook
187
+
188
+ Want to explore all PDS features interactively? Set up the reference Storybook:
189
+
190
+ ### Install the Storybook Package
191
+
192
+ ```bash
193
+ npm install @pure-ds/storybook
194
+ ```
195
+
196
+ ### Integration into Your Project
197
+
198
+ ```bash
199
+ # Run integration from your project root
200
+ npx pds-storybook
201
+
202
+ # Start your Storybook
203
+ npm run storybook
204
+ ```
205
+
206
+ **What happens:**
207
+ - ✅ Validates your environment
208
+ - ✅ Exports PDS assets to `public/assets/pds/`
209
+ - ✅ Copies stories to `.storybook/pds-stories/`
210
+ - ✅ Patches `.storybook/preview.js` to initialize PDS
211
+
212
+ ### Storybook Features
213
+
214
+ Once running, you'll find:
215
+
216
+ - **🎨 Configurator** - Click the circle icon in the toolbar to open a live configuration panel
217
+ - **🔍 Quick Search** - Query tokens and components with natural language
218
+ - **📚 Stories** organized by design system standards:
219
+ - **Foundations** - Colors, typography, spacing, icons
220
+ - **Primitives** - Buttons, forms, cards, badges, alerts
221
+ - **Components** - Web Components (`<pds-*>`)
222
+ - **Patterns** - Layout utilities, border effects
223
+ - **Enhancements** - Progressive HTML enhancements
224
+
225
+ ---
226
+
227
+ ## 4. Using PDS (Pure Web Manifesto in Practice)
228
+
229
+ ### Semantic HTML First
230
+
231
+ Just write HTML. PDS makes it look right:
232
+
233
+ ```html
234
+ <!-- Card with semantic markup -->
235
+ <article class="card">
236
+ <header>
237
+ <h3>Card Title</h3>
238
+ </header>
239
+ <p>Content that speaks for itself.</p>
240
+ <footer>
241
+ <button class="btn-primary">Action</button>
242
+ </footer>
243
+ </article>
244
+
245
+ <!-- Buttons - no component imports needed -->
246
+ <button class="btn-primary">Primary</button>
247
+ <button class="btn-secondary">Secondary</button>
248
+ <button class="btn-outline">Outline</button>
249
+
250
+ <!-- Alerts with semantic meaning -->
251
+ <div class="alert alert-success">Operation completed!</div>
252
+ <div class="alert alert-warning">Please review before continuing.</div>
253
+ ```
254
+
255
+ ### Layout Utilities (Sparingly)
256
+
257
+ PDS provides a small set of layout utilities for composition:
258
+
259
+ ```html
260
+ <!-- Flex layout -->
261
+ <div class="flex gap-md items-center">
262
+ <pds-icon icon="user"></pds-icon>
263
+ <span>Profile</span>
264
+ </div>
265
+
266
+ <!-- Stack layout (vertical) -->
267
+ <section class="stack-lg">
268
+ <h2>Section Title</h2>
269
+ <p>First paragraph.</p>
270
+ <p>Second paragraph.</p>
271
+ </section>
272
+
273
+ <!-- Grid -->
274
+ <div class="grid grid-cols-3 gap-md">
275
+ <div class="card">Item 1</div>
276
+ <div class="card">Item 2</div>
277
+ <div class="card">Item 3</div>
278
+ </div>
279
+ ```
280
+
281
+ ### Using CSS Tokens
282
+
283
+ All design values are CSS custom properties:
284
+
285
+ ```css
286
+ /* In your CSS */
287
+ .my-component {
288
+ background: var(--surface-bg);
289
+ color: var(--surface-text);
290
+ padding: var(--spacing-4);
291
+ border-radius: var(--radius-md);
292
+ box-shadow: var(--shadow-md);
293
+ }
294
+
295
+ .highlight {
296
+ color: var(--color-primary-600);
297
+ border-color: var(--color-primary-300);
298
+ }
299
+ ```
300
+
301
+ ### Using Web Components
302
+
303
+ PDS components auto-load when used:
304
+
305
+ ```html
306
+ <!-- Icons from sprite -->
307
+ <pds-icon icon="heart"></pds-icon>
308
+ <pds-icon icon="star" size="lg"></pds-icon>
309
+
310
+ <!-- Drawer panel -->
311
+ <pds-drawer id="menu" position="left">
312
+ <h2 slot="header">Menu</h2>
313
+ <nav>...</nav>
314
+ </pds-drawer>
315
+ <button onclick="document.getElementById('menu').open()">Open Menu</button>
316
+
317
+ <!-- Tabs -->
318
+ <pds-tabstrip>
319
+ <button slot="tab">Overview</button>
320
+ <div slot="panel">Overview content</div>
321
+ <button slot="tab">Details</button>
322
+ <div slot="panel">Details content</div>
323
+ </pds-tabstrip>
324
+
325
+ <!-- Toast notifications -->
326
+ <pds-toaster id="toaster"></pds-toaster>
327
+ <script>
328
+ PDS.toast("Saved successfully!", { type: "success" });
329
+ </script>
330
+ ```
331
+
332
+ ---
333
+
334
+ ## 5. Progressive Enhancements
335
+
336
+ Enhancements add behavior to semantic HTML without requiring JavaScript frameworks.
337
+
338
+ ### Built-in Enhancements
339
+
340
+ **Dropdown menus** – `<nav data-dropdown>`
341
+ ```html
342
+ <nav data-dropdown>
343
+ <button>Menu</button>
344
+ <menu>
345
+ <li><a href="#home">Home</a></li>
346
+ <li><a href="#about">About</a></li>
347
+ </menu>
348
+ </nav>
349
+ ```
350
+
351
+ **Toggle switches** – `<label data-toggle>`
352
+ ```html
353
+ <label data-toggle>
354
+ <span data-label>Enable notifications</span>
355
+ <input type="checkbox">
356
+ </label>
357
+ ```
358
+
359
+ **Required field indicators** – automatic on `[required]`
360
+ ```html
361
+ <label>
362
+ <span>Email</span>
363
+ <input type="email" required>
364
+ </label>
365
+ <!-- Asterisk added automatically! -->
366
+ ```
367
+
368
+ **Range sliders** – enhanced `<input type="range">`
369
+ ```html
370
+ <label class="range-output">
371
+ <span>Volume</span>
372
+ <input type="range" min="0" max="100" value="50">
373
+ </label>
374
+ <!-- Value display added automatically! -->
375
+ ```
376
+
377
+ ### Creating Custom Enhancers
378
+
379
+ Add your own enhancements in `pds.config.js`:
380
+
381
+ ```javascript
382
+ export const config = {
383
+ enhancers: [
384
+ {
385
+ selector: '[data-copy]',
386
+ description: 'Copy text to clipboard on click',
387
+ run: (element) => {
388
+ element.addEventListener('click', () => {
389
+ navigator.clipboard.writeText(element.dataset.copy);
390
+ PDS.toast('Copied!', { type: 'success' });
391
+ });
392
+ }
393
+ },
394
+ {
395
+ selector: '[data-animate-in]',
396
+ description: 'Animate elements as they enter viewport',
397
+ run: (element) => {
398
+ const observer = new IntersectionObserver((entries) => {
399
+ entries.forEach(entry => {
400
+ if (entry.isIntersecting) {
401
+ element.classList.add('animated');
402
+ observer.unobserve(element);
403
+ }
404
+ });
405
+ });
406
+ observer.observe(element);
407
+ }
408
+ }
409
+ ]
410
+ };
411
+ ```
412
+
413
+ ### Testing Enhancements
414
+
415
+ 1. Add your enhancer to `pds.config.js`
416
+ 2. Restart PDS (or call `PDS.start()` again)
417
+ 3. Add matching HTML to your page
418
+ 4. Check the browser console for PDS logs
419
+ 5. Verify the enhancement runs on matching elements
420
+
421
+ ---
422
+
423
+ ## 6. Auto-Defining Your Own Web Components
424
+
425
+ The `autoDefine` system can load your custom components alongside PDS components.
426
+
427
+ ### Configure Custom Mappings
428
+
429
+ ```javascript
430
+ export const config = {
431
+ autoDefine: {
432
+ baseURL: '/assets/pds/components/',
433
+
434
+ // Eagerly load these at startup
435
+ predefine: ['pds-icon', 'my-header'],
436
+
437
+ // Map custom tags to files
438
+ mapper: (tag) => {
439
+ // Your custom components
440
+ if (tag.startsWith('my-')) {
441
+ return `/components/${tag}.js`;
442
+ }
443
+ // Return nothing to use PDS default mapping for pds-* tags
444
+ }
445
+ }
446
+ };
447
+ ```
448
+
449
+ ### Create Your Component
450
+
451
+ ```javascript
452
+ // /components/my-header.js
453
+ import { html, css, LitElement } from '#pds/lit';
454
+
455
+ class MyHeader extends LitElement {
456
+ static styles = css`
457
+ :host {
458
+ display: block;
459
+ }
460
+ `;
461
+
462
+ async connectedCallback() {
463
+ super.connectedCallback();
464
+ // Adopt PDS styles into Shadow DOM
465
+ await PDS.adoptPrimitives(this.shadowRoot);
466
+ }
467
+
468
+ render() {
469
+ return html`
470
+ <header class="surface-elevated">
471
+ <nav class="flex gap-md items-center">
472
+ <slot name="logo"></slot>
473
+ <slot></slot>
474
+ </nav>
475
+ </header>
476
+ `;
477
+ }
478
+ }
479
+
480
+ customElements.define('my-header', MyHeader);
481
+ ```
482
+
483
+ ### Use in HTML
484
+
485
+ ```html
486
+ <my-header>
487
+ <img slot="logo" src="logo.svg" alt="Logo">
488
+ <a href="/">Home</a>
489
+ <a href="/about">About</a>
490
+ </my-header>
491
+ ```
492
+
493
+ The component auto-loads when the tag is encountered in the DOM!
494
+
495
+ ---
496
+
497
+ ## 7. Working with PDS in the Console
498
+
499
+ PDS exposes a rich API for debugging and exploration in DevTools.
500
+
501
+ ### Open DevTools and Try:
502
+
503
+ ```javascript
504
+ // Check PDS is loaded
505
+ PDS
506
+
507
+ // View current configuration
508
+ PDS.currentConfig
509
+
510
+ // Access compiled tokens (live mode)
511
+ PDS.compiled.tokens.colors.primary
512
+ PDS.compiled.tokens.spacing
513
+
514
+ // List available presets
515
+ Object.keys(PDS.presets)
516
+
517
+ // Get a specific preset config
518
+ PDS.presets['ocean-breeze']
519
+
520
+ // Query the design system with natural language
521
+ await PDS.query("button hover color")
522
+ await PDS.query("what spacing values are available?")
523
+ await PDS.query("how do I create a card?")
524
+
525
+ // Theme management
526
+ PDS.theme // Get current theme
527
+ PDS.theme = 'dark' // Set theme
528
+ PDS.theme = 'system' // Follow OS preference
529
+
530
+ // Show a toast notification
531
+ PDS.toast("Hello from the console!", { type: "info" });
532
+
533
+ // Show a dialog
534
+ await PDS.ask("Are you sure?", { type: "confirm" });
535
+
536
+ // Validate design accessibility
537
+ PDS.validateDesign({
538
+ colors: { primary: '#007acc', background: '#ffffff' }
539
+ }, { minContrast: 4.5 });
540
+
541
+ // List all enhancers
542
+ PDS.defaultEnhancers
543
+
544
+ // Access design system metadata
545
+ PDS.ontology.primitives
546
+ PDS.ontology.layout
547
+ ```
548
+
549
+ ### Listening to Events
550
+
551
+ ```javascript
552
+ // System ready
553
+ PDS.addEventListener('pds:ready', (e) => console.log('Ready!', e.detail));
554
+
555
+ // Theme changed
556
+ PDS.addEventListener('pds:theme:changed', (e) => console.log('Theme:', e.detail.theme));
557
+
558
+ // Design updated (from configurator)
559
+ PDS.addEventListener('pds:design:updated', (e) => console.log('Config:', e.detail.config));
560
+ ```
561
+
562
+ ---
563
+
564
+ ## 8. Resources
565
+
566
+ ### Official Links
567
+
568
+ - 🏠 [**GitHub Repository**](https://github.com/mvneerven/pure-ds)
569
+ - 📦 [**NPM: @pure-ds/core**](https://www.npmjs.com/package/@pure-ds/core)
570
+ - 📖 [**Pure Web Manifesto**](https://pureweb.dev/manifesto)
571
+ - 🎮 [**CodePen Collection**](https://codepen.io/collection/rBjkOy)
572
+
573
+ ### Documentation
574
+
575
+ - Browse the **Foundations** section to understand tokens
576
+ - Check **Primitives** for available CSS classes
577
+ - Explore **Components** for Web Component APIs
578
+ - Review **Enhancements** for progressive upgrade patterns
579
+
580
+ ### Quick Reference
581
+
582
+ | Task | Solution |
583
+ |------|----------|
584
+ | Show a dialog | `await PDS.ask("Message", { type: "confirm" })` |
585
+ | Toast notification | `PDS.toast("Message", { type: "success" })` |
586
+ | Change theme | `PDS.theme = 'dark'` |
587
+ | Query tokens | `await PDS.query("primary color")` |
588
+ | Adopt styles in Shadow DOM | `await PDS.adoptPrimitives(shadowRoot)` |
589
+
590
+ ### Getting Help
591
+
592
+ - Use the **Quick Search** (🔍 icon in toolbar) to ask natural language questions
593
+ - Open the **Configurator** (⚙️ icon) to experiment with design values
594
+ - Check browser DevTools console for PDS logging
595
+ - Explore `PDS.compiled` in live mode for full introspection
596
+
597
+ ---
598
+
599
+ **Happy building with PDS!** Remember: The browser is the framework. Write semantic HTML, let PDS handle the rest.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pure-ds/core",
3
3
  "shortname": "pds",
4
- "version": "0.4.34",
4
+ "version": "0.4.36",
5
5
  "description": "Pure Design System - Why develop a Design System when you can generate one?",
6
6
  "repository": {
7
7
  "type": "git",
@@ -44,6 +44,7 @@
44
44
  "files": [
45
45
  ".github/copilot-instructions.md",
46
46
  ".cursorrules",
47
+ "getting-started.md",
47
48
  "dist/types/",
48
49
  "public/assets/js/",
49
50
  "public/assets/pds/components/",
@@ -435,6 +435,16 @@ async function copyPdsAssets() {
435
435
  // Copy Copilot instructions to consumer project
436
436
  await copyCopilotInstructions(consumerRoot);
437
437
 
438
+ // Copy getting started guide
439
+ try {
440
+ const sourceFile = path.join(repoRoot, 'getting-started.md');
441
+ const targetFile = path.join(consumerRoot, 'getting-started.md');
442
+ await copyFile(sourceFile, targetFile);
443
+ console.log('📖 Copied getting-started.md to project root');
444
+ } catch (e) {
445
+ console.warn('⚠️ Could not copy getting-started.md:', e.message);
446
+ }
447
+
438
448
  // Proactively add export & build-icons scripts to consumer package.json (still helpful)
439
449
  await ensureExportScript(consumerRoot);
440
450
  try {
@@ -526,18 +536,18 @@ async function copyPdsAssets() {
526
536
  console.warn('⚠️ Could not write tracking file:', e?.message || e);
527
537
  }
528
538
 
529
- // Success summary
530
- console.log('\n✅ PDS installation complete!\n');
539
+ // Success summary (write to stderr so npm displays it)
540
+ console.error('\n✅ PDS installation complete!\n');
531
541
  try {
532
542
  const webRoot = await discoverWebRoot(consumerRoot);
533
- console.log(`📁 Assets installed to: ${webRoot.relative}/assets/pds/`);
534
- console.log('⚙️ Configuration file: pds.config.js');
535
- console.log('📋 Copilot instructions: .github/copilot-instructions.md');
536
- console.log('➤ Cursor instructions: .cursorrules');
537
- console.log('📚 Get your own PDS Storybook via \'npm install @pure-ds/storybook\'');
538
- console.log('📖 See readme.md\n');
543
+ console.error(`📁 Assets installed to: ${webRoot.relative}/assets/pds/`);
544
+ console.error('⚙️ Configuration file: pds.config.js');
545
+ console.error('📋 Copilot instructions: .github/copilot-instructions.md');
546
+ console.error('➤ Cursor instructions: .cursorrules');
547
+ console.error(' Getting started guide: getting-started.md');
548
+ console.error('📚 Get your own PDS Storybook via \'npm install @pure-ds/storybook\'\n');
539
549
  } catch {
540
- console.log('📦 Run "npm run pds:export" to generate assets\n');
550
+ console.error('📦 Run "npm run pds:export" to generate assets\n');
541
551
  }
542
552
  } catch (error) {
543
553
  console.error('❌ PDS postinstall failed (non-fatal):', error.message);