shru-design-system 0.1.4 → 0.1.6

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.
@@ -54,8 +54,20 @@
54
54
  var xhr = new XMLHttpRequest();
55
55
  xhr.open('GET', path, false);
56
56
  xhr.send(null);
57
+
58
+ // 404 means file doesn't exist - return null
59
+ if (xhr.status === 404) {
60
+ return null;
61
+ }
62
+
57
63
  if (xhr.status === 200 || xhr.status === 0) {
58
- return JSON.parse(xhr.responseText);
64
+ var contentType = xhr.getResponseHeader('content-type');
65
+ // Check if response is actually JSON (not HTML error page)
66
+ if (contentType && contentType.includes('application/json')) {
67
+ return JSON.parse(xhr.responseText);
68
+ }
69
+ // If not JSON (likely HTML error page), return null
70
+ return null;
59
71
  }
60
72
  } catch (e) {}
61
73
  return null;
@@ -170,24 +182,26 @@
170
182
  }
171
183
 
172
184
  function mapToTailwindVars(cssVars) {
185
+ // Start with all generated variables - they're all valid CSS variables
173
186
  var mapped = {};
174
187
  for (var key in cssVars) mapped[key] = cssVars[key];
175
- if (cssVars['--radius-button']) mapped['--radius'] = cssVars['--radius-button'];
176
- if (cssVars['--radius-card']) mapped['--radius-lg'] = cssVars['--radius-card'];
177
- if (cssVars['--font-body']) mapped['--font-sans'] = cssVars['--font-body'];
178
- if (cssVars['--spacing-base']) {
188
+
189
+ // Only add convenience mappings for Tailwind's expected variable names
190
+ if (cssVars['--radius-button'] && !cssVars['--radius']) {
191
+ mapped['--radius'] = cssVars['--radius-button'];
192
+ }
193
+ if (cssVars['--radius-card'] && !cssVars['--radius-lg']) {
194
+ mapped['--radius-lg'] = cssVars['--radius-card'];
195
+ }
196
+ if (cssVars['--font-body'] && !cssVars['--font-sans']) {
197
+ mapped['--font-sans'] = cssVars['--font-body'];
198
+ }
199
+ if (cssVars['--spacing-base'] && !cssVars['--spacing']) {
179
200
  mapped['--spacing'] = cssVars['--spacing-base'];
180
- } else if (cssVars['--spacing-component-md']) {
201
+ } else if (cssVars['--spacing-component-md'] && !cssVars['--spacing']) {
181
202
  mapped['--spacing'] = cssVars['--spacing-component-md'];
182
203
  }
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'];
204
+
191
205
  return mapped;
192
206
  }
193
207
 
package/scripts/init.js CHANGED
@@ -288,9 +288,22 @@ function createTokenFiles() {
288
288
  fs.mkdirSync(themesDir, { recursive: true });
289
289
  }
290
290
 
291
- // Create base.json
291
+ // Create base.json (or update if old structure exists)
292
292
  const basePath = path.join(tokensDir, 'base.json');
293
- 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) {
294
307
  const baseJson = {
295
308
  "_createdBy": LIBRARY_NAME,
296
309
  "color": {
@@ -338,9 +351,9 @@ function createTokenFiles() {
338
351
  }
339
352
  };
340
353
  fs.writeFileSync(basePath, JSON.stringify(baseJson, null, 2));
341
- log('Created public/tokens/base.json', 'green');
354
+ log('Created/Updated public/tokens/base.json', 'green');
342
355
  } else {
343
- log('public/tokens/base.json already exists. Skipping...', 'yellow');
356
+ log('public/tokens/base.json already exists with correct structure. Skipping...', 'green');
344
357
  }
345
358
 
346
359
  // Create palettes.json
@@ -473,9 +486,22 @@ function createTokenFiles() {
473
486
  log('Created public/tokens/themes/color/dark.json', 'green');
474
487
  }
475
488
 
476
- // Create typography/sans.json
489
+ // Create typography/sans.json (or update if old structure exists)
477
490
  const sansThemePath = path.join(themesDir, 'typography', 'sans.json');
478
- 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) {
479
505
  const sansTheme = {
480
506
  "_createdBy": LIBRARY_NAME,
481
507
  "font": {
@@ -484,12 +510,24 @@ function createTokenFiles() {
484
510
  }
485
511
  };
486
512
  fs.writeFileSync(sansThemePath, JSON.stringify(sansTheme, null, 2));
487
- log('Created public/tokens/themes/typography/sans.json', 'green');
513
+ log('Created/Updated public/tokens/themes/typography/sans.json', 'green');
488
514
  }
489
515
 
490
- // Create typography/serif.json
516
+ // Create typography/serif.json (or update if old structure exists)
491
517
  const serifThemePath = path.join(themesDir, 'typography', 'serif.json');
492
- 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) {
493
531
  const serifTheme = {
494
532
  "_createdBy": LIBRARY_NAME,
495
533
  "font": {
@@ -498,12 +536,24 @@ function createTokenFiles() {
498
536
  }
499
537
  };
500
538
  fs.writeFileSync(serifThemePath, JSON.stringify(serifTheme, null, 2));
501
- log('Created public/tokens/themes/typography/serif.json', 'green');
539
+ log('Created/Updated public/tokens/themes/typography/serif.json', 'green');
502
540
  }
503
541
 
504
- // Create shape/smooth.json
542
+ // Create shape/smooth.json (or update if old structure exists)
505
543
  const smoothThemePath = path.join(themesDir, 'shape', 'smooth.json');
506
- 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) {
507
557
  const smoothTheme = {
508
558
  "_createdBy": LIBRARY_NAME,
509
559
  "radius": {
@@ -513,12 +563,24 @@ function createTokenFiles() {
513
563
  }
514
564
  };
515
565
  fs.writeFileSync(smoothThemePath, JSON.stringify(smoothTheme, null, 2));
516
- log('Created public/tokens/themes/shape/smooth.json', 'green');
566
+ log('Created/Updated public/tokens/themes/shape/smooth.json', 'green');
517
567
  }
518
568
 
519
- // Create shape/sharp.json
569
+ // Create shape/sharp.json (or update if old structure exists)
520
570
  const sharpThemePath = path.join(themesDir, 'shape', 'sharp.json');
521
- 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) {
522
584
  const sharpTheme = {
523
585
  "_createdBy": LIBRARY_NAME,
524
586
  "radius": {
@@ -528,7 +590,7 @@ function createTokenFiles() {
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