shru-design-system 0.1.3 → 0.1.5

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.
@@ -139,21 +139,25 @@
139
139
  if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
140
140
  var enteringColor = key === 'color' && prefix === '';
141
141
  var inColorContext = isColorContext || enteringColor;
142
+
142
143
  if (enteringColor) {
143
144
  flattenToCSS(value, '', result, true);
144
145
  } else if (inColorContext) {
145
146
  flattenToCSS(value, '', result, true);
146
147
  } else {
147
- flattenToCSS(value, prefix ? prefix + '-' + key : key, result, false);
148
+ var newPrefix = prefix ? prefix + '-' + key : key;
149
+ flattenToCSS(value, newPrefix, result, false);
148
150
  }
149
151
  } else {
150
- var cssKey = isColorContext || (prefix === '' && key === 'color')
151
- ? '--' + key
152
- : prefix === ''
153
- ? '--' + key
154
- : '--' + prefix + '-' + key;
152
+ var cssKey;
153
+ if (isColorContext || (prefix === '' && key === 'color')) {
154
+ cssKey = '--' + key;
155
+ } else if (prefix === '') {
156
+ cssKey = '--' + key;
157
+ } else {
158
+ cssKey = '--' + prefix + '-' + key;
159
+ }
155
160
 
156
- // Convert hex colors to HSL format for Tailwind compatibility
157
161
  var finalValue = value;
158
162
  if (isColorContext && typeof value === 'string' && isHexColor(value)) {
159
163
  finalValue = hexToHSL(value);
@@ -176,6 +180,14 @@
176
180
  } else if (cssVars['--spacing-component-md']) {
177
181
  mapped['--spacing'] = cssVars['--spacing-component-md'];
178
182
  }
183
+ if (cssVars['--spacing-component-xs']) mapped['--spacing-component-xs'] = cssVars['--spacing-component-xs'];
184
+ if (cssVars['--spacing-component-sm']) mapped['--spacing-component-sm'] = cssVars['--spacing-component-sm'];
185
+ if (cssVars['--spacing-component-md']) mapped['--spacing-component-md'] = cssVars['--spacing-component-md'];
186
+ if (cssVars['--spacing-component-lg']) mapped['--spacing-component-lg'] = cssVars['--spacing-component-lg'];
187
+ if (cssVars['--spacing-component-xl']) mapped['--spacing-component-xl'] = cssVars['--spacing-component-xl'];
188
+ if (cssVars['--duration-fast']) mapped['--duration-fast'] = cssVars['--duration-fast'];
189
+ if (cssVars['--duration-normal']) mapped['--duration-normal'] = cssVars['--duration-normal'];
190
+ if (cssVars['--duration-slow']) mapped['--duration-slow'] = cssVars['--duration-slow'];
179
191
  return mapped;
180
192
  }
181
193
 
package/scripts/init.js CHANGED
@@ -128,6 +128,18 @@ export default {
128
128
  sans: ["var(--font-sans)", "system-ui", "sans-serif"],
129
129
  body: ["var(--font-body)", "var(--font-sans)", "system-ui", "sans-serif"],
130
130
  },
131
+ spacing: {
132
+ 'component-xs': "var(--spacing-component-xs, 0.25rem)",
133
+ 'component-sm': "var(--spacing-component-sm, 0.5rem)",
134
+ 'component-md': "var(--spacing-component-md, 1rem)",
135
+ 'component-lg': "var(--spacing-component-lg, 1.5rem)",
136
+ 'component-xl': "var(--spacing-component-xl, 2rem)",
137
+ },
138
+ transitionDuration: {
139
+ 'fast': "var(--duration-fast, 150ms)",
140
+ 'normal': "var(--duration-normal, 300ms)",
141
+ 'slow': "var(--duration-slow, 500ms)",
142
+ },
131
143
  },
132
144
  },
133
145
  plugins: [],
@@ -276,9 +288,22 @@ function createTokenFiles() {
276
288
  fs.mkdirSync(themesDir, { recursive: true });
277
289
  }
278
290
 
279
- // Create base.json
291
+ // Create base.json (or update if old structure exists)
280
292
  const basePath = path.join(tokensDir, 'base.json');
281
- if (!fs.existsSync(basePath)) {
293
+ let needsUpdate = false;
294
+ if (fs.existsSync(basePath)) {
295
+ try {
296
+ const existing = JSON.parse(fs.readFileSync(basePath, 'utf8'));
297
+ // Check if it has old structure (typography.font or shape.radius instead of font/radius)
298
+ if ((existing.typography && existing.typography.font) || (existing.shape && existing.shape.radius)) {
299
+ needsUpdate = true;
300
+ log('Found old token structure in base.json, updating...', 'yellow');
301
+ }
302
+ } catch (e) {
303
+ needsUpdate = true;
304
+ }
305
+ }
306
+ if (!fs.existsSync(basePath) || needsUpdate) {
282
307
  const baseJson = {
283
308
  "_createdBy": LIBRARY_NAME,
284
309
  "color": {
@@ -314,25 +339,21 @@ function createTokenFiles() {
314
339
  },
315
340
  "base": "0.25rem"
316
341
  },
317
- "typography": {
318
- "font": {
319
- "body": "var(--font-sans)",
320
- "sans": "var(--font-sans)",
321
- "mono": "var(--font-mono)"
322
- }
342
+ "font": {
343
+ "body": "var(--font-sans)",
344
+ "sans": "var(--font-sans)",
345
+ "mono": "var(--font-mono)"
323
346
  },
324
- "shape": {
325
- "radius": {
326
- "button": "0.375rem",
327
- "card": "0.5rem",
328
- "input": "0.375rem"
329
- }
347
+ "radius": {
348
+ "button": "0.375rem",
349
+ "card": "0.5rem",
350
+ "input": "0.375rem"
330
351
  }
331
352
  };
332
353
  fs.writeFileSync(basePath, JSON.stringify(baseJson, null, 2));
333
- log('Created public/tokens/base.json', 'green');
354
+ log('Created/Updated public/tokens/base.json', 'green');
334
355
  } else {
335
- log('public/tokens/base.json already exists. Skipping...', 'yellow');
356
+ log('public/tokens/base.json already exists with correct structure. Skipping...', 'green');
336
357
  }
337
358
 
338
359
  // Create palettes.json
@@ -465,70 +486,111 @@ function createTokenFiles() {
465
486
  log('Created public/tokens/themes/color/dark.json', 'green');
466
487
  }
467
488
 
468
- // Create typography/sans.json
489
+ // Create typography/sans.json (or update if old structure exists)
469
490
  const sansThemePath = path.join(themesDir, 'typography', 'sans.json');
470
- if (!fs.existsSync(sansThemePath)) {
491
+ let needsUpdate = false;
492
+ if (fs.existsSync(sansThemePath)) {
493
+ try {
494
+ const existing = JSON.parse(fs.readFileSync(sansThemePath, 'utf8'));
495
+ // Check if it has old structure (typography.font instead of font)
496
+ if (existing.typography && existing.typography.font) {
497
+ needsUpdate = true;
498
+ log('Found old token structure in typography/sans.json, updating...', 'yellow');
499
+ }
500
+ } catch (e) {
501
+ needsUpdate = true;
502
+ }
503
+ }
504
+ if (!fs.existsSync(sansThemePath) || needsUpdate) {
471
505
  const sansTheme = {
472
506
  "_createdBy": LIBRARY_NAME,
473
- "typography": {
474
- "font": {
475
- "body": "system-ui, -apple-system, sans-serif",
476
- "sans": "system-ui, -apple-system, sans-serif"
477
- }
507
+ "font": {
508
+ "body": "system-ui, -apple-system, sans-serif",
509
+ "sans": "system-ui, -apple-system, sans-serif"
478
510
  }
479
511
  };
480
512
  fs.writeFileSync(sansThemePath, JSON.stringify(sansTheme, null, 2));
481
- log('Created public/tokens/themes/typography/sans.json', 'green');
513
+ log('Created/Updated public/tokens/themes/typography/sans.json', 'green');
482
514
  }
483
515
 
484
- // Create typography/serif.json
516
+ // Create typography/serif.json (or update if old structure exists)
485
517
  const serifThemePath = path.join(themesDir, 'typography', 'serif.json');
486
- if (!fs.existsSync(serifThemePath)) {
518
+ needsUpdate = false;
519
+ if (fs.existsSync(serifThemePath)) {
520
+ try {
521
+ const existing = JSON.parse(fs.readFileSync(serifThemePath, 'utf8'));
522
+ if (existing.typography && existing.typography.font) {
523
+ needsUpdate = true;
524
+ log('Found old token structure in typography/serif.json, updating...', 'yellow');
525
+ }
526
+ } catch (e) {
527
+ needsUpdate = true;
528
+ }
529
+ }
530
+ if (!fs.existsSync(serifThemePath) || needsUpdate) {
487
531
  const serifTheme = {
488
532
  "_createdBy": LIBRARY_NAME,
489
- "typography": {
490
- "font": {
491
- "body": "Georgia, serif",
492
- "sans": "Georgia, serif"
493
- }
533
+ "font": {
534
+ "body": "Georgia, serif",
535
+ "sans": "Georgia, serif"
494
536
  }
495
537
  };
496
538
  fs.writeFileSync(serifThemePath, JSON.stringify(serifTheme, null, 2));
497
- log('Created public/tokens/themes/typography/serif.json', 'green');
539
+ log('Created/Updated public/tokens/themes/typography/serif.json', 'green');
498
540
  }
499
541
 
500
- // Create shape/smooth.json
542
+ // Create shape/smooth.json (or update if old structure exists)
501
543
  const smoothThemePath = path.join(themesDir, 'shape', 'smooth.json');
502
- if (!fs.existsSync(smoothThemePath)) {
544
+ needsUpdate = false;
545
+ if (fs.existsSync(smoothThemePath)) {
546
+ try {
547
+ const existing = JSON.parse(fs.readFileSync(smoothThemePath, 'utf8'));
548
+ if (existing.shape && existing.shape.radius) {
549
+ needsUpdate = true;
550
+ log('Found old token structure in shape/smooth.json, updating...', 'yellow');
551
+ }
552
+ } catch (e) {
553
+ needsUpdate = true;
554
+ }
555
+ }
556
+ if (!fs.existsSync(smoothThemePath) || needsUpdate) {
503
557
  const smoothTheme = {
504
558
  "_createdBy": LIBRARY_NAME,
505
- "shape": {
506
- "radius": {
507
- "button": "0.5rem",
508
- "card": "0.75rem",
509
- "input": "0.5rem"
510
- }
559
+ "radius": {
560
+ "button": "0.5rem",
561
+ "card": "0.75rem",
562
+ "input": "0.5rem"
511
563
  }
512
564
  };
513
565
  fs.writeFileSync(smoothThemePath, JSON.stringify(smoothTheme, null, 2));
514
- log('Created public/tokens/themes/shape/smooth.json', 'green');
566
+ log('Created/Updated public/tokens/themes/shape/smooth.json', 'green');
515
567
  }
516
568
 
517
- // Create shape/sharp.json
569
+ // Create shape/sharp.json (or update if old structure exists)
518
570
  const sharpThemePath = path.join(themesDir, 'shape', 'sharp.json');
519
- if (!fs.existsSync(sharpThemePath)) {
571
+ needsUpdate = false;
572
+ if (fs.existsSync(sharpThemePath)) {
573
+ try {
574
+ const existing = JSON.parse(fs.readFileSync(sharpThemePath, 'utf8'));
575
+ if (existing.shape && existing.shape.radius) {
576
+ needsUpdate = true;
577
+ log('Found old token structure in shape/sharp.json, updating...', 'yellow');
578
+ }
579
+ } catch (e) {
580
+ needsUpdate = true;
581
+ }
582
+ }
583
+ if (!fs.existsSync(sharpThemePath) || needsUpdate) {
520
584
  const sharpTheme = {
521
585
  "_createdBy": LIBRARY_NAME,
522
- "shape": {
523
- "radius": {
524
- "button": "0",
525
- "card": "0",
526
- "input": "0"
527
- }
586
+ "radius": {
587
+ "button": "0",
588
+ "card": "0",
589
+ "input": "0"
528
590
  }
529
591
  };
530
592
  fs.writeFileSync(sharpThemePath, JSON.stringify(sharpTheme, null, 2));
531
- log('Created public/tokens/themes/shape/sharp.json', 'green');
593
+ log('Created/Updated public/tokens/themes/shape/sharp.json', 'green');
532
594
  }
533
595
 
534
596
  // Create density/comfortable.json