@primer/primitives 0.0.0-20260129092016 → 0.0.0-20260129093932
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.
|
@@ -227,7 +227,8 @@ function outputPatternCompressedCategory(category, tokens, config, lines) {
|
|
|
227
227
|
if (formattedPatterns.length > 1) {
|
|
228
228
|
// Check if they share a common structure
|
|
229
229
|
const suffixes = formattedPatterns.map(p => {
|
|
230
|
-
const
|
|
230
|
+
const escapedSizeNotation = sizeNotation.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
231
|
+
const match = p.match(new RegExp(`${escapedSizeNotation}-(.+)$`));
|
|
231
232
|
return match ? match[1] : null;
|
|
232
233
|
});
|
|
233
234
|
if (suffixes.every(s => s !== null)) {
|
|
@@ -340,17 +341,6 @@ const CATEGORY_INFO = {
|
|
|
340
341
|
stack: { name: 'Stack', description: 'Spacing tokens for Stack layout components.' },
|
|
341
342
|
text: { name: 'Typography', description: 'Text style shorthand tokens for consistent typography across the UI.' },
|
|
342
343
|
};
|
|
343
|
-
/**
|
|
344
|
-
* Gets the typography role for a token name
|
|
345
|
-
*/
|
|
346
|
-
function getTypographyRole(tokenName) {
|
|
347
|
-
for (const { role, patterns } of TYPOGRAPHY_ROLES) {
|
|
348
|
-
if (patterns.some(pattern => tokenName.startsWith(pattern))) {
|
|
349
|
-
return role;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
344
|
/**
|
|
355
345
|
* Densifies description by removing filler words
|
|
356
346
|
*/
|
|
@@ -430,7 +420,7 @@ function extractVariant(tokenName) {
|
|
|
430
420
|
* Formats category name for display
|
|
431
421
|
*/
|
|
432
422
|
function formatCategoryName(category) {
|
|
433
|
-
if (CATEGORY_INFO
|
|
423
|
+
if (category in CATEGORY_INFO) {
|
|
434
424
|
return CATEGORY_INFO[category].name;
|
|
435
425
|
}
|
|
436
426
|
return category.charAt(0).toUpperCase() + category.slice(1);
|
|
@@ -439,7 +429,7 @@ function formatCategoryName(category) {
|
|
|
439
429
|
* Gets category description if available
|
|
440
430
|
*/
|
|
441
431
|
function getCategoryDescription(category) {
|
|
442
|
-
if (CATEGORY_INFO
|
|
432
|
+
if (category in CATEGORY_INFO) {
|
|
443
433
|
return CATEGORY_INFO[category].description;
|
|
444
434
|
}
|
|
445
435
|
return null;
|
|
@@ -518,90 +508,9 @@ function outputTypographyByRole(tokens, lines) {
|
|
|
518
508
|
* Escapes pipe characters for markdown tables
|
|
519
509
|
*/
|
|
520
510
|
function escapeTableCell(text) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
* Groups tokens by description+rules and creates bracket notation
|
|
525
|
-
* e.g., bgColor-danger-emphasis, bgColor-danger-muted -> bgColor-danger-[emphasis, muted]
|
|
526
|
-
* Only groups tokens that share the same category AND subcategory
|
|
527
|
-
*/
|
|
528
|
-
function createBracketNotation(tokens) {
|
|
529
|
-
// Group by category + subcategory + description + rules
|
|
530
|
-
const groups = new Map();
|
|
531
|
-
for (const token of tokens) {
|
|
532
|
-
const category = extractCategory(token.name);
|
|
533
|
-
const subcategory = extractSemanticSubcategory(token.name);
|
|
534
|
-
const key = JSON.stringify({
|
|
535
|
-
category,
|
|
536
|
-
subcategory,
|
|
537
|
-
description: token.description || '',
|
|
538
|
-
rules: token.rules || '',
|
|
539
|
-
});
|
|
540
|
-
if (!groups.has(key)) {
|
|
541
|
-
groups.set(key, []);
|
|
542
|
-
}
|
|
543
|
-
groups.get(key).push(token);
|
|
544
|
-
}
|
|
545
|
-
const result = [];
|
|
546
|
-
for (const [, groupTokens] of groups) {
|
|
547
|
-
if (groupTokens.length === 1) {
|
|
548
|
-
result.push({ name: `**${groupTokens[0].name}**`, guideline: groupTokens[0] });
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
// Extract common prefix and variants
|
|
552
|
-
const category = extractCategory(groupTokens[0].name);
|
|
553
|
-
const subcategory = extractSemanticSubcategory(groupTokens[0].name);
|
|
554
|
-
const variants = groupTokens.map(t => extractVariant(t.name)).filter(Boolean);
|
|
555
|
-
if (subcategory && variants.length > 1) {
|
|
556
|
-
variants.sort();
|
|
557
|
-
const bracketName = `**${category}-${subcategory}-[${variants.join(', ')}]**`;
|
|
558
|
-
result.push({ name: bracketName, guideline: groupTokens[0] });
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
// Fallback to listing all
|
|
562
|
-
for (const token of groupTokens) {
|
|
563
|
-
result.push({ name: `**${token.name}**`, guideline: token });
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
return result;
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Creates wildcard bracket notation for cross-category tokens
|
|
572
|
-
* e.g., bgColor-danger-emphasis + borderColor-danger-emphasis -> *-danger-[emphasis]
|
|
573
|
-
*/
|
|
574
|
-
function createCrossCategyBracketNotation(entries) {
|
|
575
|
-
// Group by subcategory + description + rules (normalized)
|
|
576
|
-
const groups = new Map();
|
|
577
|
-
for (const entry of entries) {
|
|
578
|
-
const key = JSON.stringify({
|
|
579
|
-
subcategory: entry.subcategory,
|
|
580
|
-
description: entry.guideline.description || '',
|
|
581
|
-
rules: entry.guideline.rules || '',
|
|
582
|
-
});
|
|
583
|
-
if (!groups.has(key)) {
|
|
584
|
-
groups.set(key, { subcategory: entry.subcategory, variants: [], guideline: entry.guideline });
|
|
585
|
-
}
|
|
586
|
-
const group = groups.get(key);
|
|
587
|
-
if (!group.variants.includes(entry.variant)) {
|
|
588
|
-
group.variants.push(entry.variant);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
const result = [];
|
|
592
|
-
for (const group of groups.values()) {
|
|
593
|
-
group.variants.sort();
|
|
594
|
-
if (group.variants.length === 1) {
|
|
595
|
-
result.push({ name: `**\\*-${group.subcategory}-${group.variants[0]}**`, guideline: group.guideline });
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
result.push({
|
|
599
|
-
name: `**\\*-${group.subcategory}-[${group.variants.join(', ')}]**`,
|
|
600
|
-
guideline: group.guideline,
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
return result;
|
|
511
|
+
// First escape backslashes, then escape pipe characters, to avoid
|
|
512
|
+
// existing backslashes altering how pipes are interpreted.
|
|
513
|
+
return text.replace(/\\/g, '\\\\').replace(/\|/g, '\\|');
|
|
605
514
|
}
|
|
606
515
|
/**
|
|
607
516
|
* @description Outputs a hyper-optimized markdown file with LLM token guidelines.
|
|
@@ -671,7 +580,7 @@ export const markdownLlmGuidelines = (_a) => __awaiter(void 0, [_a], void 0, fun
|
|
|
671
580
|
// Collect semantic tokens across mergeable categories for cross-category patterns
|
|
672
581
|
const semanticTokensByPattern = new Map();
|
|
673
582
|
for (const category of MERGEABLE_CATEGORIES) {
|
|
674
|
-
if (!grouped
|
|
583
|
+
if (!(category in grouped))
|
|
675
584
|
continue;
|
|
676
585
|
for (const guideline of grouped[category]) {
|
|
677
586
|
const subcategory = extractSemanticSubcategory(guideline.name);
|
|
@@ -767,7 +676,7 @@ export const markdownLlmGuidelines = (_a) => __awaiter(void 0, [_a], void 0, fun
|
|
|
767
676
|
continue;
|
|
768
677
|
}
|
|
769
678
|
// Special handling for pattern-compressed categories (control, overlay, stack, spinner)
|
|
770
|
-
if (PATTERN_COMPRESSED_CATEGORIES
|
|
679
|
+
if (category in PATTERN_COMPRESSED_CATEGORIES) {
|
|
771
680
|
const categoryDesc = getCategoryDescription(category);
|
|
772
681
|
if (categoryDesc) {
|
|
773
682
|
lines.push('');
|