payload-markdown 1.8.0 → 1.9.0
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 +16 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.js +4 -0
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
- package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
- package/dist/core/plugins/remarkDirectiveLines.js +29 -18
- package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
- package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
- package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
- package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
- package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +4 -221
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/core/sanitizeSchema.d.ts +11 -0
- package/dist/core/sanitizeSchema.js +176 -0
- package/dist/core/sanitizeSchema.js.map +1 -0
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/badge.d.ts +5 -2
- package/dist/directives/definitions/badge.js +138 -10
- package/dist/directives/definitions/badge.js.map +1 -1
- package/dist/directives/definitions/badges.d.ts +1 -2
- package/dist/directives/definitions/badges.js +12 -3
- package/dist/directives/definitions/badges.js.map +1 -1
- package/dist/directives/definitions/button.d.ts +7 -3
- package/dist/directives/definitions/button.js +211 -14
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/buttons.d.ts +1 -2
- package/dist/directives/definitions/buttons.js +12 -3
- package/dist/directives/definitions/buttons.js.map +1 -1
- package/dist/directives/definitions/callout.d.ts +1 -2
- package/dist/directives/definitions/callout.js +46 -5
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +6 -4
- package/dist/directives/definitions/card.js +64 -11
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.d.ts +1 -2
- package/dist/directives/definitions/cards.js +49 -4
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/cell.d.ts +2 -2
- package/dist/directives/definitions/cell.js +9 -3
- package/dist/directives/definitions/cell.js.map +1 -1
- package/dist/directives/definitions/columns.d.ts +3 -4
- package/dist/directives/definitions/columns.js +17 -3
- package/dist/directives/definitions/columns.js.map +1 -1
- package/dist/directives/definitions/details.d.ts +1 -2
- package/dist/directives/definitions/details.js +28 -3
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.d.ts +1 -2
- package/dist/directives/definitions/section.js +26 -3
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.d.ts +1 -2
- package/dist/directives/definitions/steps.js +26 -3
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tab.d.ts +8 -2
- package/dist/directives/definitions/tab.js +45 -3
- package/dist/directives/definitions/tab.js.map +1 -1
- package/dist/directives/definitions/tabs.d.ts +1 -1
- package/dist/directives/definitions/tabs.js +44 -3
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.d.ts +1 -2
- package/dist/directives/definitions/toc.js +33 -5
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +2 -10
- package/dist/directives/diagnostics.js +27 -141
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/lint.d.ts +11 -0
- package/dist/directives/lint.js +33 -0
- package/dist/directives/lint.js.map +1 -0
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/registry.d.ts +23 -5
- package/dist/directives/registry.js +52 -40
- package/dist/directives/registry.js.map +1 -1
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +29 -50
- package/dist/directives/spec.js.map +1 -1
- package/dist/directives/themeDiagnostics.d.ts +8 -0
- package/dist/directives/themeDiagnostics.js +21 -0
- package/dist/directives/themeDiagnostics.js.map +1 -0
- package/dist/directives/types.d.ts +157 -14
- package/dist/directives/types.js +6 -1
- package/dist/directives/types.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +33 -7
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/editor/themes/payload.js +2 -1
- package/dist/editor/themes/payload.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +21 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/types/core.d.ts +43 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
- package/dist/core/plugins/directiveBadge.d.ts +0 -6
- package/dist/core/plugins/directiveBadge.js +0 -94
- package/dist/core/plugins/directiveBadge.js.map +0 -1
- package/dist/core/plugins/directiveButton.d.ts +0 -6
- package/dist/core/plugins/directiveButton.js +0 -115
- package/dist/core/plugins/directiveButton.js.map +0 -1
- package/dist/directives/buttonSyntax.d.ts +0 -7
- package/dist/directives/buttonSyntax.js +0 -6
- package/dist/directives/buttonSyntax.js.map +0 -1
package/dist/directive-spec.json
CHANGED
|
@@ -111,6 +111,11 @@
|
|
|
111
111
|
{
|
|
112
112
|
"name": "section",
|
|
113
113
|
"attributes": [
|
|
114
|
+
{
|
|
115
|
+
"name": "palette",
|
|
116
|
+
"type": "string",
|
|
117
|
+
"format": "palette"
|
|
118
|
+
},
|
|
114
119
|
{
|
|
115
120
|
"name": "theme",
|
|
116
121
|
"type": "string",
|
|
@@ -206,6 +211,11 @@
|
|
|
206
211
|
"type": "string",
|
|
207
212
|
"format": "icon"
|
|
208
213
|
},
|
|
214
|
+
{
|
|
215
|
+
"name": "iconPalette",
|
|
216
|
+
"type": "string",
|
|
217
|
+
"format": "palette"
|
|
218
|
+
},
|
|
209
219
|
{
|
|
210
220
|
"name": "iconPosition",
|
|
211
221
|
"default": "left",
|
|
@@ -224,6 +234,11 @@
|
|
|
224
234
|
"false"
|
|
225
235
|
]
|
|
226
236
|
},
|
|
237
|
+
{
|
|
238
|
+
"name": "palette",
|
|
239
|
+
"type": "string",
|
|
240
|
+
"format": "palette"
|
|
241
|
+
},
|
|
227
242
|
{
|
|
228
243
|
"name": "size",
|
|
229
244
|
"default": "md",
|
|
@@ -470,6 +485,16 @@
|
|
|
470
485
|
"type": "string",
|
|
471
486
|
"format": "icon"
|
|
472
487
|
},
|
|
488
|
+
{
|
|
489
|
+
"name": "iconPalette",
|
|
490
|
+
"type": "string",
|
|
491
|
+
"format": "palette"
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"name": "palette",
|
|
495
|
+
"type": "string",
|
|
496
|
+
"format": "palette"
|
|
497
|
+
},
|
|
473
498
|
{
|
|
474
499
|
"name": "theme",
|
|
475
500
|
"type": "string",
|
|
@@ -514,6 +539,11 @@
|
|
|
514
539
|
"false"
|
|
515
540
|
]
|
|
516
541
|
},
|
|
542
|
+
{
|
|
543
|
+
"name": "palette",
|
|
544
|
+
"type": "string",
|
|
545
|
+
"format": "palette"
|
|
546
|
+
},
|
|
517
547
|
{
|
|
518
548
|
"name": "theme",
|
|
519
549
|
"type": "string",
|
|
@@ -596,6 +626,11 @@
|
|
|
596
626
|
"false"
|
|
597
627
|
]
|
|
598
628
|
},
|
|
629
|
+
{
|
|
630
|
+
"name": "palette",
|
|
631
|
+
"type": "string",
|
|
632
|
+
"format": "palette"
|
|
633
|
+
},
|
|
599
634
|
{
|
|
600
635
|
"name": "stepTheme",
|
|
601
636
|
"type": "string",
|
|
@@ -648,6 +683,11 @@
|
|
|
648
683
|
"name": "href",
|
|
649
684
|
"type": "url"
|
|
650
685
|
},
|
|
686
|
+
{
|
|
687
|
+
"name": "iconPalette",
|
|
688
|
+
"type": "string",
|
|
689
|
+
"format": "palette"
|
|
690
|
+
},
|
|
651
691
|
{
|
|
652
692
|
"name": "linkScope",
|
|
653
693
|
"default": "section",
|
|
@@ -667,6 +707,11 @@
|
|
|
667
707
|
"false"
|
|
668
708
|
]
|
|
669
709
|
},
|
|
710
|
+
{
|
|
711
|
+
"name": "palette",
|
|
712
|
+
"type": "string",
|
|
713
|
+
"format": "palette"
|
|
714
|
+
},
|
|
670
715
|
{
|
|
671
716
|
"name": "theme",
|
|
672
717
|
"type": "string",
|
|
@@ -698,6 +743,11 @@
|
|
|
698
743
|
"type": "string",
|
|
699
744
|
"format": "icon"
|
|
700
745
|
},
|
|
746
|
+
{
|
|
747
|
+
"name": "iconPalette",
|
|
748
|
+
"type": "string",
|
|
749
|
+
"format": "palette"
|
|
750
|
+
},
|
|
701
751
|
{
|
|
702
752
|
"name": "linkScope",
|
|
703
753
|
"default": "full",
|
|
@@ -716,6 +766,11 @@
|
|
|
716
766
|
"false"
|
|
717
767
|
]
|
|
718
768
|
},
|
|
769
|
+
{
|
|
770
|
+
"name": "palette",
|
|
771
|
+
"type": "string",
|
|
772
|
+
"format": "palette"
|
|
773
|
+
},
|
|
719
774
|
{
|
|
720
775
|
"name": "theme",
|
|
721
776
|
"type": "string",
|
|
@@ -743,6 +798,11 @@
|
|
|
743
798
|
"name": "default",
|
|
744
799
|
"type": "string"
|
|
745
800
|
},
|
|
801
|
+
{
|
|
802
|
+
"name": "palette",
|
|
803
|
+
"type": "string",
|
|
804
|
+
"format": "palette"
|
|
805
|
+
},
|
|
746
806
|
{
|
|
747
807
|
"name": "tabTheme",
|
|
748
808
|
"type": "string",
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LeafDirective } from 'mdast-util-directive';
|
|
2
|
+
import type { DirectiveMessageSink } from '../types.js';
|
|
2
3
|
export declare const BADGE_TYPES: readonly ["static", "npm", "github", "debian", "apt"];
|
|
3
4
|
export declare const BADGE_TARGETS: readonly ["version", "downloads", "license", "workflow", "release", "stars"];
|
|
4
5
|
export declare const BADGE_INTERVALS: readonly ["dw", "dm", "dy", "dt"];
|
|
5
6
|
export declare const BADGE_STYLES: readonly ["flat", "flat-square", "plastic", "for-the-badge", "social"];
|
|
6
7
|
export declare const BADGE_ALLOWED_ATTRIBUTES: readonly ["alt", "href", "interval", "message", "newTab", "package", "path", "repo", "src", "target", "type", "workflow", "style", "logo", "logoColor", "logoSize", "label", "labelColor", "color", "cacheSeconds"];
|
|
7
|
-
|
|
8
|
+
/** Builds the `::badge` leaf (the renderer side of `leaf.build`). */
|
|
9
|
+
export declare function makeBadgeDirective(line: string, file: DirectiveMessageSink): LeafDirective | undefined;
|
|
10
|
+
export declare const badgeDirective: import("../types.js").LayoutDirectiveDefinition<"badge", "badge">;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getUnknownAttributeWarnings } from '../attributeDiagnostics.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { parseLeafDirectiveLine } from '../leafSyntax.js';
|
|
3
|
+
import { resolveShieldsBadge, SHIELDS_BADGE_QUERY_ATTRIBUTES } from '../shields.js';
|
|
4
|
+
import { defineDirective } from '../types.js';
|
|
5
|
+
import { getSafeHref, getUnsafeHrefWarnings } from '../urls.js';
|
|
4
6
|
export const BADGE_TYPES = [
|
|
5
7
|
'static',
|
|
6
8
|
'npm',
|
|
@@ -44,9 +46,120 @@ export const BADGE_ALLOWED_ATTRIBUTES = [
|
|
|
44
46
|
'workflow',
|
|
45
47
|
...SHIELDS_BADGE_QUERY_ATTRIBUTES
|
|
46
48
|
];
|
|
47
|
-
|
|
49
|
+
function validateBadgeAttributes(attributes) {
|
|
50
|
+
return [
|
|
51
|
+
...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),
|
|
52
|
+
...getUnsafeHrefWarnings('badge', attributes)
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
function getAttribute(attributes, name) {
|
|
56
|
+
const value = attributes[name];
|
|
57
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
58
|
+
}
|
|
59
|
+
function getBooleanAttribute(attributes, name) {
|
|
60
|
+
const value = attributes[name];
|
|
61
|
+
if (value === true) return true;
|
|
62
|
+
if (typeof value !== 'string') return false;
|
|
63
|
+
return value === 'true';
|
|
64
|
+
}
|
|
65
|
+
function stringifyAttributes(attributes) {
|
|
66
|
+
return Object.fromEntries(Object.entries(attributes).map(([key, value])=>[
|
|
67
|
+
key,
|
|
68
|
+
String(value)
|
|
69
|
+
]));
|
|
70
|
+
}
|
|
71
|
+
function makeBadgeImageProperties(src, alt, includeDirective) {
|
|
72
|
+
return {
|
|
73
|
+
alt,
|
|
74
|
+
// Badge images opt out of Typography's image margins and rounding.
|
|
75
|
+
className: [
|
|
76
|
+
'not-prose',
|
|
77
|
+
'pmd-badge'
|
|
78
|
+
],
|
|
79
|
+
...includeDirective ? {
|
|
80
|
+
dataDirective: 'badge'
|
|
81
|
+
} : {},
|
|
82
|
+
src
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Builds the `::badge` leaf (the renderer side of `leaf.build`). */ export function makeBadgeDirective(line, file) {
|
|
86
|
+
const parsed = parseLeafDirectiveLine(line, 'badge');
|
|
87
|
+
if (!parsed) return undefined;
|
|
88
|
+
const attributes = parsed.attributes;
|
|
89
|
+
const label = parsed.label.trim();
|
|
90
|
+
const href = getSafeHref(getAttribute(attributes, 'href'));
|
|
91
|
+
const newTab = getBooleanAttribute(attributes, 'newTab');
|
|
92
|
+
const alt = getAttribute(attributes, 'alt') ?? label;
|
|
93
|
+
for (const warning of parsed.warnings)file.message(warning);
|
|
94
|
+
for (const warning of validateBadgeAttributes(attributes))file.message(warning);
|
|
95
|
+
const resolved = resolveShieldsBadge(attributes);
|
|
96
|
+
for (const warning of resolved.warnings)file.message(warning);
|
|
97
|
+
if (!resolved.src) return undefined;
|
|
98
|
+
const imgProperties = makeBadgeImageProperties(resolved.src, alt, !href);
|
|
99
|
+
return {
|
|
100
|
+
name: 'badge',
|
|
101
|
+
type: 'leafDirective',
|
|
102
|
+
attributes: stringifyAttributes(attributes),
|
|
103
|
+
children: label ? [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
value: label
|
|
107
|
+
}
|
|
108
|
+
] : [],
|
|
109
|
+
data: href ? {
|
|
110
|
+
hChildren: [
|
|
111
|
+
{
|
|
112
|
+
type: 'element',
|
|
113
|
+
children: [],
|
|
114
|
+
properties: imgProperties,
|
|
115
|
+
tagName: 'img'
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
hName: 'a',
|
|
119
|
+
hProperties: {
|
|
120
|
+
className: [
|
|
121
|
+
'pmd-badge-link'
|
|
122
|
+
],
|
|
123
|
+
dataDirective: 'badge',
|
|
124
|
+
href,
|
|
125
|
+
...newTab ? {
|
|
126
|
+
rel: 'noopener noreferrer',
|
|
127
|
+
target: '_blank'
|
|
128
|
+
} : {}
|
|
129
|
+
}
|
|
130
|
+
} : {
|
|
131
|
+
// <img> is void: the [label] is the alt text and must not also be
|
|
132
|
+
// emitted as visible text after the image.
|
|
133
|
+
hChildren: [],
|
|
134
|
+
hName: 'img',
|
|
135
|
+
hProperties: imgProperties
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Editor diagnostics for a `::badge` line (the editor side of `leaf.lint`). */ function lintBadgeLine(text) {
|
|
140
|
+
const parsed = parseLeafDirectiveLine(text, 'badge');
|
|
141
|
+
if (!parsed) return [];
|
|
142
|
+
return [
|
|
143
|
+
...parsed.warnings,
|
|
144
|
+
...validateBadgeAttributes(parsed.attributes),
|
|
145
|
+
...resolveShieldsBadge(parsed.attributes).warnings
|
|
146
|
+
];
|
|
147
|
+
}
|
|
148
|
+
export const badgeDirective = defineDirective({
|
|
48
149
|
name: 'badge',
|
|
49
150
|
allowedAttributes: BADGE_ALLOWED_ATTRIBUTES,
|
|
151
|
+
attributeTypes: {
|
|
152
|
+
cacheSeconds: {
|
|
153
|
+
type: 'number',
|
|
154
|
+
min: 0
|
|
155
|
+
},
|
|
156
|
+
href: {
|
|
157
|
+
type: 'url'
|
|
158
|
+
},
|
|
159
|
+
src: {
|
|
160
|
+
type: 'url'
|
|
161
|
+
}
|
|
162
|
+
},
|
|
50
163
|
attributeValues: {
|
|
51
164
|
type: BADGE_TYPES,
|
|
52
165
|
interval: BADGE_INTERVALS,
|
|
@@ -67,15 +180,30 @@ export const badgeDirective = {
|
|
|
67
180
|
snippet: '::badge[${npm version}]{\n type="${npm}"\n target="${version}"\n package="${package-name}"\n}\n${}'
|
|
68
181
|
},
|
|
69
182
|
kind: 'badge',
|
|
183
|
+
// No marker: the builder emits the final <img> (or <a><img></a>).
|
|
184
|
+
leaf: {
|
|
185
|
+
build: (line, sink)=>makeBadgeDirective(line, sink),
|
|
186
|
+
lint: (line)=>lintBadgeLine(line)
|
|
187
|
+
},
|
|
70
188
|
public: true,
|
|
189
|
+
sanitize: {
|
|
190
|
+
a: [
|
|
191
|
+
'className',
|
|
192
|
+
'dataDirective',
|
|
193
|
+
'href',
|
|
194
|
+
'rel',
|
|
195
|
+
'target'
|
|
196
|
+
],
|
|
197
|
+
img: [
|
|
198
|
+
'alt',
|
|
199
|
+
'className',
|
|
200
|
+
'dataDirective',
|
|
201
|
+
'src'
|
|
202
|
+
]
|
|
203
|
+
},
|
|
71
204
|
supportsAttributes: true,
|
|
72
205
|
tagName: 'img',
|
|
73
|
-
validateAttributes ({ attributes })
|
|
74
|
-
|
|
75
|
-
...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),
|
|
76
|
-
...getUnsafeHrefWarnings('badge', attributes)
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
};
|
|
206
|
+
validateAttributes: ({ attributes })=>validateBadgeAttributes(attributes)
|
|
207
|
+
});
|
|
80
208
|
|
|
81
209
|
//# sourceMappingURL=badge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/badge.ts"],"sourcesContent":["import type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getUnknownAttributeWarnings } from '../attributeDiagnostics.js'\nimport { SHIELDS_BADGE_QUERY_ATTRIBUTES } from '../shields.js'\nimport { getUnsafeHrefWarnings } from '../urls.js'\n\nexport const BADGE_TYPES = ['static', 'npm', 'github', 'debian', 'apt'] as const\nexport const BADGE_TARGETS = [\n 'version',\n 'downloads',\n 'license',\n 'workflow',\n 'release',\n 'stars',\n] as const\nexport const BADGE_INTERVALS = ['dw', 'dm', 'dy', 'dt'] as const\nexport const BADGE_STYLES = ['flat', 'flat-square', 'plastic', 'for-the-badge', 'social'] as const\nexport const BADGE_ALLOWED_ATTRIBUTES = [\n 'alt',\n 'href',\n 'interval',\n 'message',\n 'newTab',\n 'package',\n 'path',\n 'repo',\n 'src',\n 'target',\n 'type',\n 'workflow',\n ...SHIELDS_BADGE_QUERY_ATTRIBUTES,\n] as const\n\nexport const badgeDirective: LayoutDirectiveDefinition = {\n name: 'badge',\n allowedAttributes: BADGE_ALLOWED_ATTRIBUTES,\n attributeValues: {\n type: BADGE_TYPES,\n interval: BADGE_INTERVALS,\n newTab: ['true', 'false'],\n style: BADGE_STYLES,\n target: BADGE_TARGETS,\n },\n defaultAttributes: {\n newTab: 'false',\n },\n description: 'img.shields.io badge with curated resolvers and strict Shields escape hatches.',\n editor: {\n detail: 'Shields badge leaf directive',\n label: '::badge',\n snippet:\n '::badge[${npm version}]{\\n type=\"${npm}\"\\n target=\"${version}\"\\n package=\"${package-name}\"\\n}\\n${}',\n },\n kind: 'badge',\n public: true,\n supportsAttributes: true,\n tagName: 'img',\n validateAttributes({ attributes }) {\n return [\n ...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),\n ...getUnsafeHrefWarnings('badge', attributes),\n ]\n },\n}\n"],"names":["getUnknownAttributeWarnings","SHIELDS_BADGE_QUERY_ATTRIBUTES","getUnsafeHrefWarnings","BADGE_TYPES","BADGE_TARGETS","BADGE_INTERVALS","BADGE_STYLES","BADGE_ALLOWED_ATTRIBUTES","badgeDirective","name","allowedAttributes","attributeValues","type","interval","newTab","style","target","defaultAttributes","description","editor","detail","label","snippet","kind","public","supportsAttributes","tagName","validateAttributes","attributes"],"mappings":"AAEA,SAASA,2BAA2B,QAAQ,6BAA4B;AACxE,SAASC,8BAA8B,QAAQ,gBAAe;AAC9D,SAASC,qBAAqB,QAAQ,aAAY;AAElD,OAAO,MAAMC,cAAc;IAAC;IAAU;IAAO;IAAU;IAAU;CAAM,CAAS;AAChF,OAAO,MAAMC,gBAAgB;IAC3B;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AACV,OAAO,MAAMC,kBAAkB;IAAC;IAAM;IAAM;IAAM;CAAK,CAAS;AAChE,OAAO,MAAMC,eAAe;IAAC;IAAQ;IAAe;IAAW;IAAiB;CAAS,CAAS;AAClG,OAAO,MAAMC,2BAA2B;IACtC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;OACGN;CACJ,CAAS;AAEV,OAAO,MAAMO,iBAA4C;IACvDC,MAAM;IACNC,mBAAmBH;IACnBI,iBAAiB;QACfC,MAAMT;QACNU,UAAUR;QACVS,QAAQ;YAAC;YAAQ;SAAQ;QACzBC,OAAOT;QACPU,QAAQZ;IACV;IACAa,mBAAmB;QACjBH,QAAQ;IACV;IACAI,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SACE;IACJ;IACAC,MAAM;IACNC,QAAQ;IACRC,oBAAoB;IACpBC,SAAS;IACTC,oBAAmB,EAAEC,UAAU,EAAE;QAC/B,OAAO;eACF5B,4BAA4B,SAASO,0BAA0BqB;eAC/D1B,sBAAsB,SAAS0B;SACnC;IACH;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/badge.ts"],"sourcesContent":["import type { LeafDirective } from 'mdast-util-directive'\n\nimport type { DirectiveAttributes } from '../attributes.js'\nimport type { DirectiveMessageSink } from '../types.js'\n\nimport { getUnknownAttributeWarnings } from '../attributeDiagnostics.js'\nimport { parseLeafDirectiveLine } from '../leafSyntax.js'\nimport { resolveShieldsBadge, SHIELDS_BADGE_QUERY_ATTRIBUTES } from '../shields.js'\nimport { defineDirective } from '../types.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\n\nexport const BADGE_TYPES = ['static', 'npm', 'github', 'debian', 'apt'] as const\nexport const BADGE_TARGETS = [\n 'version',\n 'downloads',\n 'license',\n 'workflow',\n 'release',\n 'stars',\n] as const\nexport const BADGE_INTERVALS = ['dw', 'dm', 'dy', 'dt'] as const\nexport const BADGE_STYLES = ['flat', 'flat-square', 'plastic', 'for-the-badge', 'social'] as const\nexport const BADGE_ALLOWED_ATTRIBUTES = [\n 'alt',\n 'href',\n 'interval',\n 'message',\n 'newTab',\n 'package',\n 'path',\n 'repo',\n 'src',\n 'target',\n 'type',\n 'workflow',\n ...SHIELDS_BADGE_QUERY_ATTRIBUTES,\n] as const\n\nfunction validateBadgeAttributes(attributes: DirectiveAttributes): string[] {\n return [\n ...getUnknownAttributeWarnings('badge', BADGE_ALLOWED_ATTRIBUTES, attributes),\n ...getUnsafeHrefWarnings('badge', attributes),\n ]\n}\n\nfunction getAttribute(attributes: Record<string, boolean | string>, name: string): string | undefined {\n const value = attributes[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(attributes: Record<string, boolean | string>, name: string): boolean {\n const value = attributes[name]\n\n if (value === true) return true\n if (typeof value !== 'string') return false\n\n return value === 'true'\n}\n\nfunction stringifyAttributes(attributes: Record<string, boolean | string>): Record<string, string> {\n return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key, String(value)]))\n}\n\nfunction makeBadgeImageProperties(src: string, alt: string, includeDirective: boolean) {\n return {\n alt,\n // Badge images opt out of Typography's image margins and rounding.\n className: ['not-prose', 'pmd-badge'],\n ...(includeDirective ? { dataDirective: 'badge' } : {}),\n src,\n }\n}\n\n/** Builds the `::badge` leaf (the renderer side of `leaf.build`). */\nexport function makeBadgeDirective(line: string, file: DirectiveMessageSink): LeafDirective | undefined {\n const parsed = parseLeafDirectiveLine(line, 'badge')\n if (!parsed) return undefined\n\n const attributes = parsed.attributes\n const label = parsed.label.trim()\n const href = getSafeHref(getAttribute(attributes, 'href'))\n const newTab = getBooleanAttribute(attributes, 'newTab')\n const alt = getAttribute(attributes, 'alt') ?? label\n\n for (const warning of parsed.warnings) file.message(warning)\n for (const warning of validateBadgeAttributes(attributes)) file.message(warning)\n\n const resolved = resolveShieldsBadge(attributes)\n\n for (const warning of resolved.warnings) file.message(warning)\n if (!resolved.src) return undefined\n\n const imgProperties = makeBadgeImageProperties(resolved.src, alt, !href)\n\n return {\n name: 'badge',\n type: 'leafDirective',\n attributes: stringifyAttributes(attributes),\n children: label ? [{ type: 'text', value: label }] : [],\n data: href\n ? {\n hChildren: [\n {\n type: 'element' as const,\n children: [],\n properties: imgProperties,\n tagName: 'img',\n },\n ],\n hName: 'a',\n hProperties: {\n className: ['pmd-badge-link'],\n dataDirective: 'badge',\n href,\n ...(newTab\n ? {\n rel: 'noopener noreferrer',\n target: '_blank',\n }\n : {}),\n },\n }\n : {\n // <img> is void: the [label] is the alt text and must not also be\n // emitted as visible text after the image.\n hChildren: [],\n hName: 'img',\n hProperties: imgProperties,\n },\n }\n}\n\n/** Editor diagnostics for a `::badge` line (the editor side of `leaf.lint`). */\nfunction lintBadgeLine(text: string): string[] {\n const parsed = parseLeafDirectiveLine(text, 'badge')\n if (!parsed) return []\n\n return [\n ...parsed.warnings,\n ...validateBadgeAttributes(parsed.attributes),\n ...resolveShieldsBadge(parsed.attributes).warnings,\n ]\n}\n\nexport const badgeDirective = defineDirective({\n name: 'badge',\n allowedAttributes: BADGE_ALLOWED_ATTRIBUTES,\n attributeTypes: {\n cacheSeconds: { type: 'number', min: 0 },\n href: { type: 'url' },\n src: { type: 'url' },\n },\n attributeValues: {\n type: BADGE_TYPES,\n interval: BADGE_INTERVALS,\n newTab: ['true', 'false'],\n style: BADGE_STYLES,\n target: BADGE_TARGETS,\n },\n defaultAttributes: {\n newTab: 'false',\n },\n description: 'img.shields.io badge with curated resolvers and strict Shields escape hatches.',\n editor: {\n detail: 'Shields badge leaf directive',\n label: '::badge',\n snippet:\n '::badge[${npm version}]{\\n type=\"${npm}\"\\n target=\"${version}\"\\n package=\"${package-name}\"\\n}\\n${}',\n },\n kind: 'badge',\n // No marker: the builder emits the final <img> (or <a><img></a>).\n leaf: {\n build: (line, sink) => makeBadgeDirective(line, sink),\n lint: (line) => lintBadgeLine(line),\n },\n public: true,\n sanitize: {\n a: ['className', 'dataDirective', 'href', 'rel', 'target'],\n img: ['alt', 'className', 'dataDirective', 'src'],\n },\n supportsAttributes: true,\n tagName: 'img',\n validateAttributes: ({ attributes }) => validateBadgeAttributes(attributes),\n})\n"],"names":["getUnknownAttributeWarnings","parseLeafDirectiveLine","resolveShieldsBadge","SHIELDS_BADGE_QUERY_ATTRIBUTES","defineDirective","getSafeHref","getUnsafeHrefWarnings","BADGE_TYPES","BADGE_TARGETS","BADGE_INTERVALS","BADGE_STYLES","BADGE_ALLOWED_ATTRIBUTES","validateBadgeAttributes","attributes","getAttribute","name","value","trim","undefined","getBooleanAttribute","stringifyAttributes","Object","fromEntries","entries","map","key","String","makeBadgeImageProperties","src","alt","includeDirective","className","dataDirective","makeBadgeDirective","line","file","parsed","label","href","newTab","warning","warnings","message","resolved","imgProperties","type","children","data","hChildren","properties","tagName","hName","hProperties","rel","target","lintBadgeLine","text","badgeDirective","allowedAttributes","attributeTypes","cacheSeconds","min","attributeValues","interval","style","defaultAttributes","description","editor","detail","snippet","kind","leaf","build","sink","lint","public","sanitize","a","img","supportsAttributes","validateAttributes"],"mappings":"AAKA,SAASA,2BAA2B,QAAQ,6BAA4B;AACxE,SAASC,sBAAsB,QAAQ,mBAAkB;AACzD,S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,OAAO;YACPC,aAAaR;QACf;IACN;AACF;AAEA,8EAA8E,GAC9E,SAASW,cAAcC,IAAY;IACjC,MAAMpB,SAASnC,uBAAuBuD,MAAM;IAC5C,IAAI,CAACpB,QAAQ,OAAO,EAAE;IAEtB,OAAO;WACFA,OAAOK,QAAQ;WACf7B,wBAAwBwB,OAAOvB,UAAU;WACzCX,oBAAoBkC,OAAOvB,UAAU,EAAE4B,QAAQ;KACnD;AACH;AAEA,OAAO,MAAMgB,iBAAiBrD,gBAAgB;IAC5CW,MAAM;IACN2C,mBAAmB/C;IACnBgD,gBAAgB;QACdC,cAAc;YAAEf,MAAM;YAAUgB,KAAK;QAAE;QACvCvB,MAAM;YAAEO,MAAM;QAAM;QACpBjB,KAAK;YAAEiB,MAAM;QAAM;IACrB;IACAiB,iBAAiB;QACfjB,MAAMtC;QACNwD,UAAUtD;QACV8B,QAAQ;YAAC;YAAQ;SAAQ;QACzByB,OAAOtD;QACP4C,QAAQ9C;IACV;IACAyD,mBAAmB;QACjB1B,QAAQ;IACV;IACA2B,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACR/B,OAAO;QACPgC,SACE;IACJ;IACAC,MAAM;IACN,kEAAkE;IAClEC,MAAM;QACJC,OAAO,CAACtC,MAAMuC,OAASxC,mBAAmBC,MAAMuC;QAChDC,MAAM,CAACxC,OAASqB,cAAcrB;IAChC;IACAyC,QAAQ;IACRC,UAAU;QACRC,GAAG;YAAC;YAAa;YAAiB;YAAQ;YAAO;SAAS;QAC1DC,KAAK;YAAC;YAAO;YAAa;YAAiB;SAAM;IACnD;IACAC,oBAAoB;IACpB7B,SAAS;IACT8B,oBAAoB,CAAC,EAAEnE,UAAU,EAAE,GAAKD,wBAAwBC;AAClE,GAAE"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { LayoutDirectiveDefinition } from '../types.js';
|
|
2
1
|
export declare const BADGES_ALIGNS: readonly ["left", "center", "right"];
|
|
3
2
|
export declare const BADGES_GAPS: readonly ["sm", "md", "lg"];
|
|
4
3
|
export declare const BADGES_WRAPS: readonly ["true", "false"];
|
|
5
4
|
export declare const DEFAULT_BADGES_ALIGN = "left";
|
|
6
5
|
export declare const DEFAULT_BADGES_GAP = "md";
|
|
7
6
|
export declare const DEFAULT_BADGES_WRAP = "true";
|
|
8
|
-
export declare const badgesDirective: LayoutDirectiveDefinition
|
|
7
|
+
export declare const badgesDirective: import("../types.js").LayoutDirectiveDefinition<"badges", "badges">;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defineDirective } from '../types.js';
|
|
1
2
|
export const BADGES_ALIGNS = [
|
|
2
3
|
'left',
|
|
3
4
|
'center',
|
|
@@ -24,7 +25,7 @@ function isBadgesGap(value) {
|
|
|
24
25
|
function isBadgesWrap(value) {
|
|
25
26
|
return typeof value === 'string' && BADGES_WRAPS.includes(value);
|
|
26
27
|
}
|
|
27
|
-
export const badgesDirective = {
|
|
28
|
+
export const badgesDirective = defineDirective({
|
|
28
29
|
name: 'badges',
|
|
29
30
|
allowedAttributes: [
|
|
30
31
|
'align',
|
|
@@ -45,6 +46,7 @@ export const badgesDirective = {
|
|
|
45
46
|
gap: BADGES_GAPS,
|
|
46
47
|
wrap: BADGES_WRAPS
|
|
47
48
|
},
|
|
49
|
+
container: {},
|
|
48
50
|
defaultAttributes: {
|
|
49
51
|
align: DEFAULT_BADGES_ALIGN,
|
|
50
52
|
gap: DEFAULT_BADGES_GAP,
|
|
@@ -65,8 +67,15 @@ export const badgesDirective = {
|
|
|
65
67
|
};
|
|
66
68
|
},
|
|
67
69
|
kind: 'badges',
|
|
68
|
-
openMarker: ':::badges',
|
|
69
70
|
public: true,
|
|
71
|
+
sanitize: {
|
|
72
|
+
div: [
|
|
73
|
+
'dataAlign',
|
|
74
|
+
'dataDirective',
|
|
75
|
+
'dataGap',
|
|
76
|
+
'dataWrap'
|
|
77
|
+
]
|
|
78
|
+
},
|
|
70
79
|
supportsAttributes: true,
|
|
71
80
|
tagName: 'div',
|
|
72
81
|
validateAttributes ({ attributes }) {
|
|
@@ -76,6 +85,6 @@ export const badgesDirective = {
|
|
|
76
85
|
if (typeof attributes.wrap === 'string' && !isBadgesWrap(attributes.wrap)) warnings.push(`Invalid badges wrap "${attributes.wrap}". Falling back to "${DEFAULT_BADGES_WRAP}".`);
|
|
77
86
|
return warnings;
|
|
78
87
|
}
|
|
79
|
-
};
|
|
88
|
+
});
|
|
80
89
|
|
|
81
90
|
//# sourceMappingURL=badges.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/badges.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/badges.ts"],"sourcesContent":["import { defineDirective } from '../types.js'\n\nexport const BADGES_ALIGNS = ['left', 'center', 'right'] as const\nexport const BADGES_GAPS = ['sm', 'md', 'lg'] as const\nexport const BADGES_WRAPS = ['true', 'false'] as const\n\nexport const DEFAULT_BADGES_ALIGN = 'left'\nexport const DEFAULT_BADGES_GAP = 'md'\nexport const DEFAULT_BADGES_WRAP = 'true'\n\ntype BadgesAlign = (typeof BADGES_ALIGNS)[number]\ntype BadgesGap = (typeof BADGES_GAPS)[number]\ntype BadgesWrap = (typeof BADGES_WRAPS)[number]\n\nfunction isBadgesAlign(value: unknown): value is BadgesAlign {\n return typeof value === 'string' && BADGES_ALIGNS.includes(value as BadgesAlign)\n}\n\nfunction isBadgesGap(value: unknown): value is BadgesGap {\n return typeof value === 'string' && BADGES_GAPS.includes(value as BadgesGap)\n}\n\nfunction isBadgesWrap(value: unknown): value is BadgesWrap {\n return typeof value === 'string' && BADGES_WRAPS.includes(value as BadgesWrap)\n}\n\nexport const badgesDirective = defineDirective({\n name: 'badges',\n allowedAttributes: ['align', 'gap', 'wrap'],\n applyHast(node, _config, { mergeClassNames }) {\n const align =\n typeof node.properties.dataAlign === 'string' && isBadgesAlign(node.properties.dataAlign)\n ? node.properties.dataAlign\n : DEFAULT_BADGES_ALIGN\n const gap =\n typeof node.properties.dataGap === 'string' && isBadgesGap(node.properties.dataGap)\n ? node.properties.dataGap\n : DEFAULT_BADGES_GAP\n const wrap =\n typeof node.properties.dataWrap === 'string' && isBadgesWrap(node.properties.dataWrap)\n ? node.properties.dataWrap\n : DEFAULT_BADGES_WRAP\n\n node.properties.dataAlign = align\n node.properties.dataGap = gap\n node.properties.dataWrap = wrap\n node.properties.className = mergeClassNames(\n 'not-prose',\n 'pmd-badges',\n `pmd-badges--align-${align}`,\n `pmd-badges--gap-${gap}`,\n `pmd-badges--wrap-${wrap}`,\n )\n },\n attributeValues: {\n align: BADGES_ALIGNS,\n gap: BADGES_GAPS,\n wrap: BADGES_WRAPS,\n },\n container: {},\n defaultAttributes: {\n align: DEFAULT_BADGES_ALIGN,\n gap: DEFAULT_BADGES_GAP,\n wrap: DEFAULT_BADGES_WRAP,\n },\n description: 'Badge group wrapper for one or more Shields badge directives.',\n editor: {\n detail: 'Badge group directive',\n label: 'Badges',\n snippet:\n ':::badges{\\n align=\"${left}\"\\n gap=\"${md}\"\\n wrap=${true}\\n}\\n::badge[${npm version}]{\\n type=\"${npm}\"\\n target=\"${version}\"\\n package=\"${package-name}\"\\n}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataAlign: typeof node.attributes?.align === 'string' ? node.attributes.align : DEFAULT_BADGES_ALIGN,\n dataDirective: 'badges',\n dataGap: typeof node.attributes?.gap === 'string' ? node.attributes.gap : DEFAULT_BADGES_GAP,\n dataWrap: typeof node.attributes?.wrap === 'string' ? node.attributes.wrap : DEFAULT_BADGES_WRAP,\n }\n },\n kind: 'badges',\n public: true,\n sanitize: {\n div: ['dataAlign', 'dataDirective', 'dataGap', 'dataWrap'],\n },\n supportsAttributes: true,\n tagName: 'div',\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (typeof attributes.align === 'string' && !isBadgesAlign(attributes.align))\n warnings.push(\n `Invalid badges align \"${attributes.align}\". Falling back to \"${DEFAULT_BADGES_ALIGN}\".`,\n )\n\n if (typeof attributes.gap === 'string' && !isBadgesGap(attributes.gap))\n warnings.push(\n `Invalid badges gap \"${attributes.gap}\". Falling back to \"${DEFAULT_BADGES_GAP}\".`,\n )\n\n if (typeof attributes.wrap === 'string' && !isBadgesWrap(attributes.wrap))\n warnings.push(\n `Invalid badges wrap \"${attributes.wrap}\". Falling back to \"${DEFAULT_BADGES_WRAP}\".`,\n )\n\n return warnings\n },\n})\n"],"names":["defineDirective","BADGES_ALIGNS","BADGES_GAPS","BADGES_WRAPS","DEFAULT_BADGES_ALIGN","DEFAULT_BADGES_GAP","DEFAULT_BADGES_WRAP","isBadgesAlign","value","includes","isBadgesGap","isBadgesWrap","badgesDirective","name","allowedAttributes","applyHast","node","_config","mergeClassNames","align","properties","dataAlign","gap","dataGap","wrap","dataWrap","className","attributeValues","container","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","attributes","dataDirective","kind","public","sanitize","div","supportsAttributes","tagName","validateAttributes","warnings","push"],"mappings":"AAAA,SAASA,eAAe,QAAQ,cAAa;AAE7C,OAAO,MAAMC,gBAAgB;IAAC;IAAQ;IAAU;CAAQ,CAAS;AACjE,OAAO,MAAMC,cAAc;IAAC;IAAM;IAAM;CAAK,CAAS;AACtD,OAAO,MAAMC,eAAe;IAAC;IAAQ;CAAQ,CAAS;AAEtD,OAAO,MAAMC,uBAAuB,OAAM;AAC1C,OAAO,MAAMC,qBAAqB,KAAI;AACtC,OAAO,MAAMC,sBAAsB,OAAM;AAMzC,SAASC,cAAcC,KAAc;IACnC,OAAO,OAAOA,UAAU,YAAYP,cAAcQ,QAAQ,CAACD;AAC7D;AAEA,SAASE,YAAYF,KAAc;IACjC,OAAO,OAAOA,UAAU,YAAYN,YAAYO,QAAQ,CAACD;AAC3D;AAEA,SAASG,aAAaH,KAAc;IAClC,OAAO,OAAOA,UAAU,YAAYL,aAAaM,QAAQ,CAACD;AAC5D;AAEA,OAAO,MAAMI,kBAAkBZ,gBAAgB;IAC7Ca,MAAM;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AACd,GAAG,GAAGjB;YAC1EoB,UAAU,OAAOT,KAAKoB,UAAU,EAAEZ,SAAS,WAAWR,KAAKoB,UAAU,CAACZ,IAAI,GAAGlB;QAC/E;IACF;IACAgC,MAAM;IACNC,QAAQ;IACRC,UAAU;QACRC,KAAK;YAAC;YAAa;YAAiB;YAAW;SAAW;IAC5D;IACAC,oBAAoB;IACpBC,SAAS;IACTC,oBAAmB,EAAER,UAAU,EAAE;QAC/B,MAAMS,WAAqB,EAAE;QAE7B,IAAI,OAAOT,WAAWjB,KAAK,KAAK,YAAY,CAACZ,cAAc6B,WAAWjB,KAAK,GACzE0B,SAASC,IAAI,CACX,CAAC,sBAAsB,EAAEV,WAAWjB,KAAK,CAAC,oBAAoB,EAAEf,qBAAqB,EAAE,CAAC;QAG5F,IAAI,OAAOgC,WAAWd,GAAG,KAAK,YAAY,CAACZ,YAAY0B,WAAWd,GAAG,GACnEuB,SAASC,IAAI,CACX,CAAC,oBAAoB,EAAEV,WAAWd,GAAG,CAAC,oBAAoB,EAAEjB,mBAAmB,EAAE,CAAC;QAGtF,IAAI,OAAO+B,WAAWZ,IAAI,KAAK,YAAY,CAACb,aAAayB,WAAWZ,IAAI,GACtEqB,SAASC,IAAI,CACX,CAAC,qBAAqB,EAAEV,WAAWZ,IAAI,CAAC,oBAAoB,EAAElB,oBAAoB,EAAE,CAAC;QAGzF,OAAOuC;IACT;AACF,GAAE"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LeafDirective } from 'mdast-util-directive';
|
|
2
|
+
import type { MarkdownRenderConfig } from '../../types/core.js';
|
|
3
|
+
import type { DirectiveMessageSink } from '../types.js';
|
|
2
4
|
export declare const BUTTON_VARIANTS: readonly ["primary", "secondary", "outline", "ghost", "link"];
|
|
3
5
|
export declare const BUTTON_SIZES: readonly ["sm", "md", "lg"];
|
|
4
6
|
export declare const BUTTON_ICON_POSITIONS: readonly ["left", "right"];
|
|
5
|
-
export declare const BUTTON_ALLOWED_ATTRIBUTES: readonly ["ariaLabel", "href", "icon", "iconPosition", "newTab", "size", "variant"];
|
|
7
|
+
export declare const BUTTON_ALLOWED_ATTRIBUTES: readonly ["ariaLabel", "href", "icon", "iconPalette", "iconPosition", "newTab", "palette", "size", "variant"];
|
|
6
8
|
export declare const DEFAULT_BUTTON_VARIANT = "primary";
|
|
7
9
|
export declare const DEFAULT_BUTTON_SIZE = "md";
|
|
8
10
|
export declare const DEFAULT_BUTTON_ICON_POSITION = "left";
|
|
@@ -12,4 +14,6 @@ export type ButtonIconPosition = (typeof BUTTON_ICON_POSITIONS)[number];
|
|
|
12
14
|
export declare function isButtonVariant(value: unknown): value is ButtonVariant;
|
|
13
15
|
export declare function isButtonSize(value: unknown): value is ButtonSize;
|
|
14
16
|
export declare function isButtonIconPosition(value: unknown): value is ButtonIconPosition;
|
|
15
|
-
|
|
17
|
+
/** Builds the `::button` leaf (the renderer side of `leaf.build`). */
|
|
18
|
+
export declare function makeButtonDirective(line: string, file: DirectiveMessageSink, config: MarkdownRenderConfig): LeafDirective | undefined;
|
|
19
|
+
export declare const buttonDirective: import("../types.js").LayoutDirectiveDefinition<"button", "button">;
|