payload-markdown 1.7.2 → 1.8.1

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.
Files changed (169) hide show
  1. package/README.md +17 -0
  2. package/dist/agent/access.d.ts +1 -1
  3. package/dist/agent/access.js.map +1 -1
  4. package/dist/agent/guide.d.ts +3 -0
  5. package/dist/agent/guide.js +28 -2
  6. package/dist/agent/guide.js.map +1 -1
  7. package/dist/agent/palettes.d.ts +55 -0
  8. package/dist/agent/palettes.js +194 -0
  9. package/dist/agent/palettes.js.map +1 -0
  10. package/dist/agent/skill.d.ts +2 -2
  11. package/dist/agent/skill.js +2 -2
  12. package/dist/agent/skill.js.map +1 -1
  13. package/dist/agent/validate.d.ts +1 -1
  14. package/dist/agent/validate.js +3 -0
  15. package/dist/agent/validate.js.map +1 -1
  16. package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
  17. package/dist/appearance/PaletteRowLabel.client.js +70 -0
  18. package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
  19. package/dist/appearance/config.d.ts +8 -0
  20. package/dist/appearance/config.js +172 -0
  21. package/dist/appearance/config.js.map +1 -0
  22. package/dist/appearance/options.d.ts +11 -0
  23. package/dist/appearance/options.js +15 -0
  24. package/dist/appearance/options.js.map +1 -0
  25. package/dist/appearance/runtime.d.ts +25 -0
  26. package/dist/appearance/runtime.js +126 -0
  27. package/dist/appearance/runtime.js.map +1 -0
  28. package/dist/components/MarkdownRenderer/Component.client.js +9 -19
  29. package/dist/components/MarkdownRenderer/Component.client.js.map +1 -1
  30. package/dist/components/MarkdownRenderer/Component.js +59 -21
  31. package/dist/components/MarkdownRenderer/Component.js.map +1 -1
  32. package/dist/components/MarkdownRenderer/index.css +93 -42
  33. package/dist/components/MarkdownRenderer/index.scss +128 -57
  34. package/dist/core/codeToHtml.js +6 -0
  35. package/dist/core/codeToHtml.js.map +1 -1
  36. package/dist/core/plugins/directiveBadge.js +2 -0
  37. package/dist/core/plugins/directiveBadge.js.map +1 -1
  38. package/dist/core/plugins/directiveButton.d.ts +1 -1
  39. package/dist/core/plugins/directiveButton.js +26 -6
  40. package/dist/core/plugins/directiveButton.js.map +1 -1
  41. package/dist/core/plugins/rehypeContentLayout.d.ts +12 -0
  42. package/dist/core/plugins/rehypeContentLayout.js +64 -0
  43. package/dist/core/plugins/rehypeContentLayout.js.map +1 -0
  44. package/dist/core/plugins/rehypeResolveIcons.js +10 -1
  45. package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
  46. package/dist/core/plugins/remarkHeadingAnchorsAndToc.js +8 -0
  47. package/dist/core/plugins/remarkHeadingAnchorsAndToc.js.map +1 -1
  48. package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
  49. package/dist/core/plugins/remarkValidatePalettes.js +51 -0
  50. package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
  51. package/dist/core/renderMarkdown.js +19 -4
  52. package/dist/core/renderMarkdown.js.map +1 -1
  53. package/dist/directive-spec.json +60 -0
  54. package/dist/directives/definitions/button.d.ts +1 -1
  55. package/dist/directives/definitions/button.js +9 -2
  56. package/dist/directives/definitions/button.js.map +1 -1
  57. package/dist/directives/definitions/callout.js +29 -13
  58. package/dist/directives/definitions/callout.js.map +1 -1
  59. package/dist/directives/definitions/card.d.ts +2 -2
  60. package/dist/directives/definitions/card.js +44 -11
  61. package/dist/directives/definitions/card.js.map +1 -1
  62. package/dist/directives/definitions/cards.js +19 -6
  63. package/dist/directives/definitions/cards.js.map +1 -1
  64. package/dist/directives/definitions/cell.js +4 -2
  65. package/dist/directives/definitions/cell.js.map +1 -1
  66. package/dist/directives/definitions/columns.js +2 -1
  67. package/dist/directives/definitions/columns.js.map +1 -1
  68. package/dist/directives/definitions/details.js +9 -3
  69. package/dist/directives/definitions/details.js.map +1 -1
  70. package/dist/directives/definitions/section.js +5 -1
  71. package/dist/directives/definitions/section.js.map +1 -1
  72. package/dist/directives/definitions/steps.js +38 -14
  73. package/dist/directives/definitions/steps.js.map +1 -1
  74. package/dist/directives/definitions/tab.js +2 -1
  75. package/dist/directives/definitions/tab.js.map +1 -1
  76. package/dist/directives/definitions/tabs.js +13 -6
  77. package/dist/directives/definitions/tabs.js.map +1 -1
  78. package/dist/directives/definitions/toc.js +2 -1
  79. package/dist/directives/definitions/toc.js.map +1 -1
  80. package/dist/directives/diagnostics.d.ts +5 -0
  81. package/dist/directives/diagnostics.js +26 -10
  82. package/dist/directives/diagnostics.js.map +1 -1
  83. package/dist/directives/iconPlaceholder.d.ts +9 -3
  84. package/dist/directives/iconPlaceholder.js +8 -1
  85. package/dist/directives/iconPlaceholder.js.map +1 -1
  86. package/dist/directives/palette.d.ts +23 -0
  87. package/dist/directives/palette.js +40 -0
  88. package/dist/directives/palette.js.map +1 -0
  89. package/dist/directives/shields.js +16 -3
  90. package/dist/directives/shields.js.map +1 -1
  91. package/dist/directives/spec.d.ts +6 -2
  92. package/dist/directives/spec.js +5 -0
  93. package/dist/directives/spec.js.map +1 -1
  94. package/dist/directives/themes.js +13 -13
  95. package/dist/directives/themes.js.map +1 -1
  96. package/dist/editor/directiveConfig.d.ts +15 -1
  97. package/dist/editor/directiveConfig.js +21 -1
  98. package/dist/editor/directiveConfig.js.map +1 -1
  99. package/dist/editor/directives/completions.d.ts +4 -2
  100. package/dist/editor/directives/completions.js +22 -3
  101. package/dist/editor/directives/completions.js.map +1 -1
  102. package/dist/editor/directives/diagnostics.d.ts +2 -2
  103. package/dist/editor/directives/diagnostics.js +10 -3
  104. package/dist/editor/directives/diagnostics.js.map +1 -1
  105. package/dist/exports/client.d.ts +4 -1
  106. package/dist/exports/client.js +5 -2
  107. package/dist/exports/client.js.map +1 -1
  108. package/dist/exports/render.d.ts +2 -1
  109. package/dist/exports/render.js +1 -0
  110. package/dist/exports/render.js.map +1 -1
  111. package/dist/field/MarkdownField/Component.js +54 -3
  112. package/dist/field/MarkdownField/Component.js.map +1 -1
  113. package/dist/icons/entries.d.ts +22 -0
  114. package/dist/icons/entries.js +50 -0
  115. package/dist/icons/entries.js.map +1 -0
  116. package/dist/icons/resolve.d.ts +2 -1
  117. package/dist/icons/resolve.js +2 -2
  118. package/dist/icons/resolve.js.map +1 -1
  119. package/dist/icons/sanitizeSvg.d.ts +12 -2
  120. package/dist/icons/sanitizeSvg.js +104 -3
  121. package/dist/icons/sanitizeSvg.js.map +1 -1
  122. package/dist/index.d.ts +11 -4
  123. package/dist/index.js +34 -3
  124. package/dist/index.js.map +1 -1
  125. package/dist/mcp/index.d.ts +2 -2
  126. package/dist/mcp/index.js +65 -4
  127. package/dist/mcp/index.js.map +1 -1
  128. package/dist/palettes/colors.d.ts +21 -0
  129. package/dist/palettes/colors.js +43 -0
  130. package/dist/palettes/colors.js.map +1 -0
  131. package/dist/palettes/contrast.d.ts +7 -0
  132. package/dist/palettes/contrast.js +63 -0
  133. package/dist/palettes/contrast.js.map +1 -0
  134. package/dist/palettes/defaults.d.ts +8 -0
  135. package/dist/palettes/defaults.js +275 -0
  136. package/dist/palettes/defaults.js.map +1 -0
  137. package/dist/palettes/diagnostics.d.ts +10 -0
  138. package/dist/palettes/diagnostics.js +38 -0
  139. package/dist/palettes/diagnostics.js.map +1 -0
  140. package/dist/palettes/index.d.ts +61 -0
  141. package/dist/palettes/index.js +246 -0
  142. package/dist/palettes/index.js.map +1 -0
  143. package/dist/render/renderMarkdown.d.ts +3 -1
  144. package/dist/render/renderMarkdown.js +9 -1
  145. package/dist/render/renderMarkdown.js.map +1 -1
  146. package/dist/runtime/index.d.ts +12 -1
  147. package/dist/runtime/index.js +23 -2
  148. package/dist/runtime/index.js.map +1 -1
  149. package/dist/styles/directiveSurface.d.ts +39 -5
  150. package/dist/styles/directiveSurface.js +56 -13
  151. package/dist/styles/directiveSurface.js.map +1 -1
  152. package/dist/types/core.d.ts +56 -0
  153. package/dist/types/core.js.map +1 -1
  154. package/dist/types.d.ts +46 -2
  155. package/dist/types.js.map +1 -1
  156. package/dist/version.d.ts +1 -1
  157. package/dist/version.js +1 -1
  158. package/dist/version.js.map +1 -1
  159. package/package.json +2 -1
  160. package/skills/payload-markdown/claude/SKILL.md +1 -0
  161. package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
  162. package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
  163. package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
  164. package/skills/payload-markdown/claude/skill.json +2 -2
  165. package/skills/payload-markdown/codex/SKILL.md +1 -0
  166. package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
  167. package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
  168. package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
  169. package/skills/payload-markdown/codex/skill.json +2 -2
@@ -1,4 +1,5 @@
1
- import { DIRECTIVE_SURFACE_DIVIDER_CLASS } from '../../styles/directiveSurface.js';
1
+ import { DIRECTIVE_BODY_CLASS, DIRECTIVE_SURFACE_DIVIDER_CLASS } from '../../styles/directiveSurface.js';
2
+ import { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js';
2
3
  import { resolveDirectiveTheme } from '../themes.js';
3
4
  import { getTabLabel as getTabDirectiveLabel, getTabRawValue, getTabValue, resolveTabsDefault, slugTabValue, toTabSlug } from './tab.js';
4
5
  function isContainerDirective(node) {
@@ -53,7 +54,9 @@ function makeTabTrigger(tab, active) {
53
54
  const className = [
54
55
  'vl-md-tabs-trigger',
55
56
  active ? 'vl-md-tabs-trigger--active' : undefined,
56
- 'rounded-lg px-3 py-2 text-sm font-medium text-foreground/70 transition-colors hover:text-foreground aria-selected:bg-white/10 aria-selected:text-foreground'
57
+ // Inactive labels stay at 75% of the text colour: enough for AA contrast in
58
+ // both colour schemes while still reading as secondary.
59
+ 'rounded-lg px-3 py-2 text-sm font-medium text-current/75 transition-colors hover:bg-[color:color-mix(in_oklab,rgb(255_255_255/0.05)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.04))] hover:text-current aria-selected:bg-[color:color-mix(in_oklab,rgb(255_255_255/0.1)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.06))] aria-selected:text-current focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:color-mix(in_oklab,rgb(255_255_255/0.25)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent'
57
60
  ].filter((value)=>Boolean(value));
58
61
  return {
59
62
  type: 'element',
@@ -88,7 +91,8 @@ function makeTabPanel(tab, active, config, mergeClassNames, fallbackThemeName) {
88
91
  properties: {
89
92
  id: tab.panelId,
90
93
  ariaLabelledby: tab.triggerId,
91
- className: mergeClassNames('vl-md-tabs-panel', theme.hookClassName, theme.modifierClassName, theme.classes, '[&>:first-child]:mt-0 [&>:last-child]:mb-0'),
94
+ className: mergeClassNames('vl-md-tabs-panel', theme.hookClassName, theme.modifierClassName, theme.classes, DIRECTIVE_BODY_CLASS, // A panel holding only a code block shows just the code block.
95
+ 'has-[>pre:only-child]:border-0 has-[>pre:only-child]:bg-transparent has-[>pre:only-child]:p-0 has-[>pre:only-child]:shadow-none'),
92
96
  dataTabPanel: '',
93
97
  dataTabValue: tab.value,
94
98
  dataTheme: theme.name,
@@ -105,7 +109,7 @@ function makeTabList(tabs, activeValue) {
105
109
  children: tabs.map((tab)=>makeTabTrigger(tab, tab.value === activeValue)),
106
110
  properties: {
107
111
  className: [
108
- `vl-md-tabs-list flex flex-wrap gap-1 border-b ${DIRECTIVE_SURFACE_DIVIDER_CLASS} pb-2`
112
+ `not-prose vl-md-tabs-list flex flex-wrap gap-1 border-b ${DIRECTIVE_SURFACE_DIVIDER_CLASS} pb-2`
109
113
  ],
110
114
  dataTabsList: '',
111
115
  role: 'tablist'
@@ -133,6 +137,7 @@ export const tabsDirective = {
133
137
  name: 'tabs',
134
138
  allowedAttributes: [
135
139
  'default',
140
+ 'palette',
136
141
  'tabTheme',
137
142
  'theme'
138
143
  ],
@@ -143,7 +148,8 @@ export const tabsDirective = {
143
148
  const tabTheme = typeof node.properties.dataTabTheme === 'string' ? node.properties.dataTabTheme : undefined;
144
149
  node.properties.dataTheme = theme.name;
145
150
  node.properties.dataDefault = activeTab?.value;
146
- node.properties.className = mergeClassNames('not-prose', theme.hookClassName, theme.modifierClassName, theme.classes);
151
+ applyDirectivePalette(node, config);
152
+ node.properties.className = mergeClassNames(theme.hookClassName, theme.modifierClassName, theme.classes);
147
153
  if (!activeTab) {
148
154
  node.children = [
149
155
  {
@@ -156,7 +162,7 @@ export const tabsDirective = {
156
162
  ],
157
163
  properties: {
158
164
  className: [
159
- 'text-sm text-muted-foreground'
165
+ 'not-prose text-sm text-(--tw-prose-body)/80'
160
166
  ]
161
167
  },
162
168
  tagName: 'p'
@@ -178,6 +184,7 @@ export const tabsDirective = {
178
184
  getMdastRenderProperties (node) {
179
185
  const requestedDefault = typeof node.attributes?.default === 'string' ? node.attributes.default : undefined;
180
186
  return {
187
+ ...getPaletteRenderProperties(node),
181
188
  dataDefault: requestedDefault ? resolveTabsDefault(requestedDefault, getTabsDefaultCandidates(node)) ?? requestedDefault : undefined,
182
189
  dataDirective: 'tabs',
183
190
  dataTabTheme: typeof node.attributes?.tabTheme === 'string' ? node.attributes.tabTheme : undefined,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/directives/definitions/tabs.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_SURFACE_DIVIDER_CLASS } from '../../styles/directiveSurface.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport {\n getTabLabel as getTabDirectiveLabel,\n getTabRawValue,\n getTabValue,\n resolveTabsDefault,\n slugTabValue,\n toTabSlug,\n} from './tab.js'\n\ntype TabModel = {\n disabled: boolean\n label: string\n node: Element\n panelId: string\n themeName?: string\n triggerId: string\n value: string\n}\n\nfunction isContainerDirective(node: unknown): node is ContainerDirective {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n (node as { type?: string }).type === 'containerDirective',\n )\n}\n\nfunction isTabElement(node: ElementContent): node is Element {\n return node.type === 'element' && node.properties?.dataVlLayout === 'tab'\n}\n\nfunction getStringProperty(\n properties: Element['properties'] | undefined,\n name: string,\n): string | undefined {\n const value = properties?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanProperty(properties: Element['properties'] | undefined, name: string): boolean {\n const value = properties?.[name]\n\n return value === true || value === 'true'\n}\n\nfunction getTabLabel(node: Element, index: number): string {\n return (\n getStringProperty(node.properties, 'dataLabel') ??\n getStringProperty(node.properties, 'dataValue') ??\n `Tab ${index + 1}`\n )\n}\n\nfunction getRequestedDefault(node: Element): string | undefined {\n return getStringProperty(node.properties, 'dataDefault')\n}\n\nfunction makeUniqueValue(rawValue: string, index: number, seen: Map<string, number>): string {\n const base = slugTabValue(rawValue, index)\n const count = seen.get(base) ?? 0\n seen.set(base, count + 1)\n\n return count === 0 ? base : `${base}-${count}`\n}\n\nfunction collectTabs(\n node: Element,\n reserveIds: (bases: string[]) => string[],\n): TabModel[] {\n const seen = new Map<string, number>()\n\n return node.children.filter(isTabElement).map((child, index) => {\n const rawValue = getStringProperty(child.properties, 'dataValue') ?? `tab-${index + 1}`\n const value = makeUniqueValue(rawValue, index, seen)\n // Ids are unique per render: a second identical tabs block (or a heading\n // such as \"Tabs panel npm\") pushes these ids to a -n suffix.\n const [panelId, triggerId] = reserveIds([`tabs-panel-${value}`, `tabs-trigger-${value}`])\n\n return {\n disabled: getBooleanProperty(child.properties, 'dataDisabled'),\n label: getTabLabel(child, index),\n node: child,\n panelId,\n themeName: getStringProperty(child.properties, 'dataTheme'),\n triggerId,\n value,\n }\n })\n}\n\nfunction makeTabTrigger(tab: TabModel, active: boolean): Element {\n const className = [\n 'vl-md-tabs-trigger',\n active ? 'vl-md-tabs-trigger--active' : undefined,\n 'rounded-lg px-3 py-2 text-sm font-medium text-foreground/70 transition-colors hover:text-foreground aria-selected:bg-white/10 aria-selected:text-foreground',\n ].filter((value): value is string => Boolean(value))\n\n return {\n type: 'element',\n children: [{ type: 'text', value: tab.label }],\n properties: {\n id: tab.triggerId,\n type: 'button',\n ariaControls: [tab.panelId],\n ariaSelected: active ? 'true' : 'false',\n className,\n dataTabTrigger: '',\n dataTabValue: tab.value,\n disabled: tab.disabled || undefined,\n role: 'tab',\n tabIndex: active ? 0 : -1,\n },\n tagName: 'button',\n }\n}\n\nfunction makeTabPanel(\n tab: TabModel,\n active: boolean,\n config: Parameters<NonNullable<LayoutDirectiveDefinition['applyHast']>>[1],\n mergeClassNames: Parameters<NonNullable<LayoutDirectiveDefinition['applyHast']>>[2]['mergeClassNames'],\n fallbackThemeName?: string,\n): Element {\n const theme = resolveDirectiveTheme('tab', tab.themeName ?? fallbackThemeName, config.themes)\n\n return {\n type: 'element',\n children: tab.node.children,\n properties: {\n id: tab.panelId,\n ariaLabelledby: tab.triggerId,\n className: mergeClassNames(\n 'vl-md-tabs-panel',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n '[&>:first-child]:mt-0 [&>:last-child]:mb-0',\n ),\n dataTabPanel: '',\n dataTabValue: tab.value,\n dataTheme: theme.name,\n hidden: active ? undefined : true,\n role: 'tabpanel',\n tabIndex: 0,\n },\n tagName: 'div',\n }\n}\n\nfunction makeTabList(tabs: TabModel[], activeValue: string): Element {\n return {\n type: 'element',\n children: tabs.map((tab) => makeTabTrigger(tab, tab.value === activeValue)),\n properties: {\n className: [`vl-md-tabs-list flex flex-wrap gap-1 border-b ${DIRECTIVE_SURFACE_DIVIDER_CLASS} pb-2`],\n dataTabsList: '',\n role: 'tablist',\n },\n tagName: 'div',\n }\n}\n\nfunction findActiveTab(tabs: TabModel[], requestedDefault?: string): TabModel | undefined {\n // remarkLayoutDirectives already resolved authored defaults to a tab value.\n const requested = requestedDefault ? toTabSlug(requestedDefault) || undefined : undefined\n const requestedMatch = requested\n ? tabs.find((tab) => tab.value === requested && !tab.disabled) ??\n tabs.find((tab) => tab.value === requested)\n : undefined\n\n return requestedMatch ?? tabs.find((tab) => !tab.disabled) ?? tabs[0]\n}\n\nfunction getTabsDefaultCandidates(node: ContainerDirective) {\n return getDirectTabDirectives(node).map((tab, index) => ({\n label: getTabDirectiveLabel(tab, index),\n raw: getTabRawValue(tab.attributes),\n value: getTabValue(tab, index),\n }))\n}\n\nfunction getDirectTabDirectives(node: ContainerDirective): ContainerDirective[] {\n return node.children.filter(\n (child): child is ContainerDirective => isContainerDirective(child) && child.name === 'tab',\n )\n}\n\nexport const tabsDirective: LayoutDirectiveDefinition = {\n name: 'tabs',\n allowedAttributes: ['default', 'tabTheme', 'theme'],\n applyHast(node, config, { mergeClassNames, reserveIds }) {\n const tabs = collectTabs(node, reserveIds)\n const activeTab = findActiveTab(tabs, getRequestedDefault(node))\n const theme = resolveDirectiveTheme(\n 'tabs',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const tabTheme =\n typeof node.properties.dataTabTheme === 'string' ? node.properties.dataTabTheme : undefined\n\n node.properties.dataTheme = theme.name\n node.properties.dataDefault = activeTab?.value\n node.properties.className = mergeClassNames(\n 'not-prose',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n\n if (!activeTab) {\n node.children = [\n {\n type: 'element',\n children: [{ type: 'text', value: 'No tabs configured.' }],\n properties: {\n className: ['text-sm text-muted-foreground'],\n },\n tagName: 'p',\n },\n ]\n return\n }\n\n node.children = [\n makeTabList(tabs, activeTab.value),\n ...tabs.map((tab) =>\n makeTabPanel(tab, tab.value === activeTab.value, config, mergeClassNames, tabTheme),\n ),\n ]\n },\n description: 'Accessible tabbed content block with server-rendered panels.',\n editor: {\n detail: 'Tabs directive',\n label: 'Tabs',\n snippet:\n ':::tabs{\\n default=\"${pnpm}\"\\n}\\n\\n:::tab[${pnpm}]{\\n value=\"${pnpm}\"\\n}\\n```bash\\npnpm add ${package-name}\\n```\\n:::\\n\\n:::tab[${npm}]{\\n value=\"${npm}\"\\n}\\n```bash\\nnpm install ${package-name}\\n```\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const requestedDefault =\n typeof node.attributes?.default === 'string' ? node.attributes.default : undefined\n\n return {\n dataDefault: requestedDefault\n ? (resolveTabsDefault(requestedDefault, getTabsDefaultCandidates(node)) ?? requestedDefault)\n : undefined,\n dataDirective: 'tabs',\n dataTabTheme:\n typeof node.attributes?.tabTheme === 'string' ? node.attributes.tabTheme : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'tabs',\n openMarker: ':::tabs',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n tabTheme: 'tab',\n theme: 'tabs',\n },\n transformMdast(node) {\n getDirectTabDirectives(node).forEach((tab, index) => {\n const data = (tab.data ??= {})\n data.vlTabIndex = index\n })\n },\n validateMdast(node) {\n const warnings: string[] = []\n const tabs = getDirectTabDirectives(node)\n const values = new Map<string, number>()\n\n if (tabs.length === 0) warnings.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n tabs.forEach((tab, index) => {\n const value = getTabValue(tab, index)\n values.set(value, (values.get(value) ?? 0) + 1)\n })\n\n for (const [value, count] of values)\n if (count > 1) warnings.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (\n typeof node.attributes?.default === 'string' &&\n !resolveTabsDefault(node.attributes.default, getTabsDefaultCandidates(node))\n )\n warnings.push(`Invalid tabs default \"${node.attributes.default}\". Falling back to the first tab.`)\n\n return warnings\n },\n}\n"],"names":["DIRECTIVE_SURFACE_DIVIDER_CLASS","resolveDirectiveTheme","getTabLabel","getTabDirectiveLabel","getTabRawValue","getTabValue","resolveTabsDefault","slugTabValue","toTabSlug","isContainerDirective","node","Boolean","type","isTabElement","properties","dataVlLayout","getStringProperty","name","value","trim","undefined","getBooleanProperty","index","getRequestedDefault","makeUniqueValue","rawValue","seen","base","count","get","set","collectTabs","reserveIds","Map","children","filter","map","child","panelId","triggerId","disabled","label","themeName","makeTabTrigger","tab","active","className","id","ariaControls","ariaSelected","dataTabTrigger","dataTabValue","role","tabIndex","tagName","makeTabPanel","config","mergeClassNames","fallbackThemeName","theme","themes","ariaLabelledby","hookClassName","modifierClassName","classes","dataTabPanel","dataTheme","hidden","makeTabList","tabs","activeValue","dataTabsList","findActiveTab","requestedDefault","requested","requestedMatch","find","getTabsDefaultCandidates","getDirectTabDirectives","raw","attributes","tabsDirective","allowedAttributes","applyHast","activeTab","tabTheme","dataTabTheme","dataDefault","description","editor","detail","snippet","getMdastRenderProperties","default","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","transformMdast","forEach","data","vlTabIndex","validateMdast","warnings","values","length","push"],"mappings":"AAKA,SAASA,+BAA+B,QAAQ,mCAAkC;AAClF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SACEC,eAAeC,oBAAoB,EACnCC,cAAc,EACdC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,EACZC,SAAS,QACJ,WAAU;AAYjB,SAASC,qBAAqBC,IAAa;IACzC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV,AAACA,KAA2BE,IAAI,KAAK;AAE3C;AAEA,SAASC,aAAaH,IAAoB;IACxC,OAAOA,KAAKE,IAAI,KAAK,aAAaF,KAAKI,UAAU,EAAEC,iBAAiB;AACtE;AAEA,SAASC,kBACPF,UAA6C,EAC7CG,IAAY;IAEZ,MAAMC,QAAQJ,YAAY,CAACG,KAAK;IAEhC,OAAO,OAAOC,UAAU,YAAYA,MAAMC,IAAI,KAAKD,MAAMC,IAAI,KAAKC;AACpE;AAEA,SAASC,mBAAmBP,UAA6C,EAAEG,IAAY;IACrF,MAAMC,QAAQJ,YAAY,CAACG,KAAK;IAEhC,OAAOC,UAAU,QAAQA,UAAU;AACrC;AAEA,SAAShB,YAAYQ,IAAa,EAAEY,KAAa;IAC/C,OACEN,kBAAkBN,KAAKI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AS;IACT6C,iBAAiB;QACfd,UAAU;QACV1B,OAAO;IACT;IACAyC,gBAAe1F,IAAI;QACjBoE,uBAAuBpE,MAAM2F,OAAO,CAAC,CAACzD,KAAKtB;YACzC,MAAMgF,OAAQ1D,IAAI0D,IAAI,KAAK,CAAC;YAC5BA,KAAKC,UAAU,GAAGjF;QACpB;IACF;IACAkF,eAAc9F,IAAI;QAChB,MAAM+F,WAAqB,EAAE;QAC7B,MAAMpC,OAAOS,uBAAuBpE;QACpC,MAAMgG,SAAS,IAAIzE;QAEnB,IAAIoC,KAAKsC,MAAM,KAAK,GAAGF,SAASG,IAAI,CAAC;QAErCvC,KAAKgC,OAAO,CAAC,CAACzD,KAAKtB;YACjB,MAAMJ,QAAQb,YAAYuC,KAAKtB;YAC/BoF,OAAO5E,GAAG,CAACZ,OAAO,AAACwF,CAAAA,OAAO7E,GAAG,CAACX,UAAU,CAAA,IAAK;QAC/C;QAEA,KAAK,MAAM,CAACA,OAAOU,MAAM,IAAI8E,OAC3B,IAAI9E,QAAQ,GAAG6E,SAASG,IAAI,CAAC,CAAC,qBAAqB,EAAE1F,MAAM,YAAY,CAAC;QAE1E,IACE,OAAOR,KAAKsE,UAAU,EAAEa,YAAY,YACpC,CAACvF,mBAAmBI,KAAKsE,UAAU,CAACa,OAAO,EAAEhB,yBAAyBnE,QAEtE+F,SAASG,IAAI,CAAC,CAAC,sBAAsB,EAAElG,KAAKsE,UAAU,CAACa,OAAO,CAAC,iCAAiC,CAAC;QAEnG,OAAOY;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/directives/definitions/tabs.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_BODY_CLASS, DIRECTIVE_SURFACE_DIVIDER_CLASS } from '../../styles/directiveSurface.js'\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport {\n getTabLabel as getTabDirectiveLabel,\n getTabRawValue,\n getTabValue,\n resolveTabsDefault,\n slugTabValue,\n toTabSlug,\n} from './tab.js'\n\ntype TabModel = {\n disabled: boolean\n label: string\n node: Element\n panelId: string\n themeName?: string\n triggerId: string\n value: string\n}\n\nfunction isContainerDirective(node: unknown): node is ContainerDirective {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n (node as { type?: string }).type === 'containerDirective',\n )\n}\n\nfunction isTabElement(node: ElementContent): node is Element {\n return node.type === 'element' && node.properties?.dataVlLayout === 'tab'\n}\n\nfunction getStringProperty(\n properties: Element['properties'] | undefined,\n name: string,\n): string | undefined {\n const value = properties?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanProperty(properties: Element['properties'] | undefined, name: string): boolean {\n const value = properties?.[name]\n\n return value === true || value === 'true'\n}\n\nfunction getTabLabel(node: Element, index: number): string {\n return (\n getStringProperty(node.properties, 'dataLabel') ??\n getStringProperty(node.properties, 'dataValue') ??\n `Tab ${index + 1}`\n )\n}\n\nfunction getRequestedDefault(node: Element): string | undefined {\n return getStringProperty(node.properties, 'dataDefault')\n}\n\nfunction makeUniqueValue(rawValue: string, index: number, seen: Map<string, number>): string {\n const base = slugTabValue(rawValue, index)\n const count = seen.get(base) ?? 0\n seen.set(base, count + 1)\n\n return count === 0 ? base : `${base}-${count}`\n}\n\nfunction collectTabs(\n node: Element,\n reserveIds: (bases: string[]) => string[],\n): TabModel[] {\n const seen = new Map<string, number>()\n\n return node.children.filter(isTabElement).map((child, index) => {\n const rawValue = getStringProperty(child.properties, 'dataValue') ?? `tab-${index + 1}`\n const value = makeUniqueValue(rawValue, index, seen)\n // Ids are unique per render: a second identical tabs block (or a heading\n // such as \"Tabs panel npm\") pushes these ids to a -n suffix.\n const [panelId, triggerId] = reserveIds([`tabs-panel-${value}`, `tabs-trigger-${value}`])\n\n return {\n disabled: getBooleanProperty(child.properties, 'dataDisabled'),\n label: getTabLabel(child, index),\n node: child,\n panelId,\n themeName: getStringProperty(child.properties, 'dataTheme'),\n triggerId,\n value,\n }\n })\n}\n\nfunction makeTabTrigger(tab: TabModel, active: boolean): Element {\n const className = [\n 'vl-md-tabs-trigger',\n active ? 'vl-md-tabs-trigger--active' : undefined,\n // Inactive labels stay at 75% of the text colour: enough for AA contrast in\n // both colour schemes while still reading as secondary.\n 'rounded-lg px-3 py-2 text-sm font-medium text-current/75 transition-colors hover:bg-[color:color-mix(in_oklab,rgb(255_255_255/0.05)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.04))] hover:text-current aria-selected:bg-[color:color-mix(in_oklab,rgb(255_255_255/0.1)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.06))] aria-selected:text-current focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:color-mix(in_oklab,rgb(255_255_255/0.25)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent',\n ].filter((value): value is string => Boolean(value))\n\n return {\n type: 'element',\n children: [{ type: 'text', value: tab.label }],\n properties: {\n id: tab.triggerId,\n type: 'button',\n ariaControls: [tab.panelId],\n ariaSelected: active ? 'true' : 'false',\n className,\n dataTabTrigger: '',\n dataTabValue: tab.value,\n disabled: tab.disabled || undefined,\n role: 'tab',\n tabIndex: active ? 0 : -1,\n },\n tagName: 'button',\n }\n}\n\nfunction makeTabPanel(\n tab: TabModel,\n active: boolean,\n config: Parameters<NonNullable<LayoutDirectiveDefinition['applyHast']>>[1],\n mergeClassNames: Parameters<NonNullable<LayoutDirectiveDefinition['applyHast']>>[2]['mergeClassNames'],\n fallbackThemeName?: string,\n): Element {\n const theme = resolveDirectiveTheme('tab', tab.themeName ?? fallbackThemeName, config.themes)\n\n return {\n type: 'element',\n children: tab.node.children,\n properties: {\n id: tab.panelId,\n ariaLabelledby: tab.triggerId,\n className: mergeClassNames(\n 'vl-md-tabs-panel',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n DIRECTIVE_BODY_CLASS,\n // A panel holding only a code block shows just the code block.\n 'has-[>pre:only-child]:border-0 has-[>pre:only-child]:bg-transparent has-[>pre:only-child]:p-0 has-[>pre:only-child]:shadow-none',\n ),\n dataTabPanel: '',\n dataTabValue: tab.value,\n dataTheme: theme.name,\n hidden: active ? undefined : true,\n role: 'tabpanel',\n tabIndex: 0,\n },\n tagName: 'div',\n }\n}\n\nfunction makeTabList(tabs: TabModel[], activeValue: string): Element {\n return {\n type: 'element',\n children: tabs.map((tab) => makeTabTrigger(tab, tab.value === activeValue)),\n properties: {\n className: [`not-prose vl-md-tabs-list flex flex-wrap gap-1 border-b ${DIRECTIVE_SURFACE_DIVIDER_CLASS} pb-2`],\n dataTabsList: '',\n role: 'tablist',\n },\n tagName: 'div',\n }\n}\n\nfunction findActiveTab(tabs: TabModel[], requestedDefault?: string): TabModel | undefined {\n // remarkLayoutDirectives already resolved authored defaults to a tab value.\n const requested = requestedDefault ? toTabSlug(requestedDefault) || undefined : undefined\n const requestedMatch = requested\n ? tabs.find((tab) => tab.value === requested && !tab.disabled) ??\n tabs.find((tab) => tab.value === requested)\n : undefined\n\n return requestedMatch ?? tabs.find((tab) => !tab.disabled) ?? tabs[0]\n}\n\nfunction getTabsDefaultCandidates(node: ContainerDirective) {\n return getDirectTabDirectives(node).map((tab, index) => ({\n label: getTabDirectiveLabel(tab, index),\n raw: getTabRawValue(tab.attributes),\n value: getTabValue(tab, index),\n }))\n}\n\nfunction getDirectTabDirectives(node: ContainerDirective): ContainerDirective[] {\n return node.children.filter(\n (child): child is ContainerDirective => isContainerDirective(child) && child.name === 'tab',\n )\n}\n\nexport const tabsDirective: LayoutDirectiveDefinition = {\n name: 'tabs',\n allowedAttributes: ['default', 'palette', 'tabTheme', 'theme'],\n applyHast(node, config, { mergeClassNames, reserveIds }) {\n const tabs = collectTabs(node, reserveIds)\n const activeTab = findActiveTab(tabs, getRequestedDefault(node))\n const theme = resolveDirectiveTheme(\n 'tabs',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const tabTheme =\n typeof node.properties.dataTabTheme === 'string' ? node.properties.dataTabTheme : undefined\n\n node.properties.dataTheme = theme.name\n node.properties.dataDefault = activeTab?.value\n applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n\n if (!activeTab) {\n node.children = [\n {\n type: 'element',\n children: [{ type: 'text', value: 'No tabs configured.' }],\n properties: {\n className: ['not-prose text-sm text-(--tw-prose-body)/80'],\n },\n tagName: 'p',\n },\n ]\n return\n }\n\n node.children = [\n makeTabList(tabs, activeTab.value),\n ...tabs.map((tab) =>\n makeTabPanel(tab, tab.value === activeTab.value, config, mergeClassNames, tabTheme),\n ),\n ]\n },\n description: 'Accessible tabbed content block with server-rendered panels.',\n editor: {\n detail: 'Tabs directive',\n label: 'Tabs',\n snippet:\n ':::tabs{\\n default=\"${pnpm}\"\\n}\\n\\n:::tab[${pnpm}]{\\n value=\"${pnpm}\"\\n}\\n```bash\\npnpm add ${package-name}\\n```\\n:::\\n\\n:::tab[${npm}]{\\n value=\"${npm}\"\\n}\\n```bash\\nnpm install ${package-name}\\n```\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const requestedDefault =\n typeof node.attributes?.default === 'string' ? node.attributes.default : undefined\n\n return {\n ...getPaletteRenderProperties(node),\n dataDefault: requestedDefault\n ? (resolveTabsDefault(requestedDefault, getTabsDefaultCandidates(node)) ?? requestedDefault)\n : undefined,\n dataDirective: 'tabs',\n dataTabTheme:\n typeof node.attributes?.tabTheme === 'string' ? node.attributes.tabTheme : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'tabs',\n openMarker: ':::tabs',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n tabTheme: 'tab',\n theme: 'tabs',\n },\n transformMdast(node) {\n getDirectTabDirectives(node).forEach((tab, index) => {\n const data = (tab.data ??= {})\n data.vlTabIndex = index\n })\n },\n validateMdast(node) {\n const warnings: string[] = []\n const tabs = getDirectTabDirectives(node)\n const values = new Map<string, number>()\n\n if (tabs.length === 0) warnings.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n tabs.forEach((tab, index) => {\n const value = getTabValue(tab, index)\n values.set(value, (values.get(value) ?? 0) + 1)\n })\n\n for (const [value, count] of values)\n if (count > 1) warnings.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (\n typeof node.attributes?.default === 'string' &&\n !resolveTabsDefault(node.attributes.default, getTabsDefaultCandidates(node))\n )\n warnings.push(`Invalid tabs default \"${node.attributes.default}\". Falling back to the first tab.`)\n\n return warnings\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","DIRECTIVE_SURFACE_DIVIDER_CLASS","applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","getTabLabel","getTabDirectiveLabel","getTabRawValue","getTabValue","resolveTabsDefault","slugTabValue","toTabSlug","isContainerDirective","node","Boolean","type","isTabElement","properties","dataVlLayout","getStringProperty","name","value","trim","undefined","getBooleanProperty","index","getRequestedDefault","makeUniqueValue","rawValue","seen","base","count","get","set","collectTabs","reserveIds","Map","children","filter","map","child","panelId","triggerId","disabled","label","themeName","makeTabTrigger","tab","active","className","id","ariaControls","ariaSelected","dataTabTrigger","dataTabValue","role","tabIndex","tagName","makeTabPanel","config","mergeClassNames","fallbackThemeName","theme","themes","ariaLabelledby","hookClassName","modifierClassName","classes","dataTabPanel","dataTheme","hidden","makeTabList","tabs","activeValue","dataTabsList","findActiveTab","requestedDefault","requested","requestedMatch","find","getTabsDefaultCandidates","getDirectTabDirectives","raw","attributes","tabsDirective","allowedAttributes","applyHast","activeTab","tabTheme","dataTabTheme","dataDefault","description","editor","detail","snippet","getMdastRenderProperties","default","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","transformMdast","forEach","data","vlTabIndex","validateMdast","warnings","values","length","push"],"mappings":"AAKA,SAASA,oBAAoB,EAAEC,+BAA+B,QAAQ,mCAAkC;AACxG,SAASC,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SACEC,eAAeC,oBAAoB,EACnCC,cAAc,EACdC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,EACZC,SAAS,QACJ,WAAU;AAYjB,SAASC,qBAAqBC,IAAa;IACzC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV,AAACA,KAA2BE,IAAI,KAAK;AAE3C;AAEA,SAASC,aAAaH,IAAoB;IACxC,OAAOA,KAAKE,IAAI,KAAK,aAAaF,KAAKI,UAAU,EAAEC,iBAAiB;AACtE;AAEA,SAASC,kBACPF,UAA6C,EAC7CG,IAAY;IAEZ,MAAMC,QAAQJ,YAAY,CAACG,KAAK;IAEhC,OAAO,OAAOC,UAAU,YAAYA,MAAMC,IAAI,KAAKD,MAAMC,IAAI,KAAKC;AACpE;AAEA,SAASC,mBAAmBP,UAA6C,EAAEG,IAAY;IACrF,MAAMC,QAAQJ,YAAY,CAACG,KAAK;IAEhC,OAAOC,UAAU,QAAQA,UAAU;AACrC;AAEA,SAAShB,YAAYQ,IAAa,EAAEY,KAAa;IAC/C,OACEN,kBAAkBN,KAAKI,UAAU,EAAE,gBACnCE,kBAAkBN,KAAKI,UAAU,EAAE,gBACnC,CAAC,IAAI,EAAEQ,QAAQ,GAAG;AAEtB;AAEA,SAASC,oBAAoBb,IAAa;IACxC,OAAOM,kBAAkBN,KAAKI,UAAU,EAAE;AAC5C;AAEA,SAASU,gBAAgBC,QAAgB,EAAEH,KAAa,EAAEI,IAAyB;IACjF,MAAMC,OAAOpB,aAAakB,UAAUH;IACpC,MAAMM,QAAQF,KAAKG,GAAG,CAACF,SAAS;IAChCD,KAAKI,GAAG,CAACH,MAAMC,QAAQ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AAI;QAChB,MAAM+F,WAAqB,EAAE;QAC7B,MAAMpC,OAAOS,uBAAuBpE;QACpC,MAAMgG,SAAS,IAAIzE;QAEnB,IAAIoC,KAAKsC,MAAM,KAAK,GAAGF,SAASG,IAAI,CAAC;QAErCvC,KAAKgC,OAAO,CAAC,CAACzD,KAAKtB;YACjB,MAAMJ,QAAQb,YAAYuC,KAAKtB;YAC/BoF,OAAO5E,GAAG,CAACZ,OAAO,AAACwF,CAAAA,OAAO7E,GAAG,CAACX,UAAU,CAAA,IAAK;QAC/C;QAEA,KAAK,MAAM,CAACA,OAAOU,MAAM,IAAI8E,OAC3B,IAAI9E,QAAQ,GAAG6E,SAASG,IAAI,CAAC,CAAC,qBAAqB,EAAE1F,MAAM,YAAY,CAAC;QAE1E,IACE,OAAOR,KAAKsE,UAAU,EAAEa,YAAY,YACpC,CAACvF,mBAAmBI,KAAKsE,UAAU,CAACa,OAAO,EAAEhB,yBAAyBnE,QAEtE+F,SAASG,IAAI,CAAC,CAAC,sBAAsB,EAAElG,KAAKsE,UAAU,CAACa,OAAO,CAAC,iCAAiC,CAAC;QAEnG,OAAOY;IACT;AACF,EAAC"}
@@ -21,7 +21,8 @@ export const tocDirective = {
21
21
  applyHast (node, config, { mergeClassNames }) {
22
22
  const theme = resolveDirectiveTheme('toc', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
23
23
  node.properties.dataTheme = theme.name;
24
- node.properties.className = mergeClassNames('not-prose', theme.hookClassName, theme.modifierClassName, theme.classes);
24
+ node.properties.className = mergeClassNames('not-prose', // Title reads as a label; entries indent by heading level.
25
+ '[&>p:first-child]:mb-2 [&>p:first-child]:text-xs [&>p:first-child]:font-semibold [&>p:first-child]:uppercase [&>p:first-child]:tracking-[0.18em] [&>p:first-child]:text-(--tw-prose-body)/80', '[&_ol]:mt-0 [&_ol]:mb-2 [&_ol]:list-none [&_ol]:p-0 [&_li+li]:mt-1', "[&_li[data-toc-level='1']]:pl-4 [&_li[data-toc-level='2']]:pl-8 [&_li[data-toc-level='3']]:pl-12 [&_li[data-toc-level='4']]:pl-16 [&_li[data-toc-level='5']]:pl-20", '[&_a]:text-(--tw-prose-body) [&_a]:transition-colors [&_a:hover]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))]', theme.hookClassName, theme.modifierClassName, theme.classes);
25
26
  },
26
27
  defaultAttributes: {
27
28
  depth: String(DEFAULT_TOC_DEPTH),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/directives/definitions/toc.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const DEFAULT_TOC_DEPTH = 3\nexport const DEFAULT_TOC_TITLE = 'On this page'\n\nexport function resolveTocDepth(node: ContainerDirective): number {\n const value = node.attributes?.depth\n const parsed = typeof value === 'string' ? Number.parseInt(value, 10) : DEFAULT_TOC_DEPTH\n\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 6 ? parsed : DEFAULT_TOC_DEPTH\n}\n\nexport function resolveTocTitle(node: ContainerDirective): string {\n const title = getDirectiveLabelOrAttribute(node, 'title')\n\n return title ?? DEFAULT_TOC_TITLE\n}\n\nexport const tocDirective: LayoutDirectiveDefinition = {\n name: 'toc',\n allowedAttributes: ['depth', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'toc',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n 'not-prose',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n },\n defaultAttributes: {\n depth: String(DEFAULT_TOC_DEPTH),\n title: DEFAULT_TOC_TITLE,\n },\n description: 'Table of contents generated from document headings.',\n editor: {\n detail: 'Docs directive',\n label: 'Table of contents',\n snippet: ':::toc[${On this page}]{\\n depth=\"${3}\"\\n}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const title = resolveTocTitle(node)\n\n return {\n ariaLabel: title,\n dataDirective: 'toc',\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataTitle: title,\n }\n },\n kind: 'toc',\n openMarker: ':::toc',\n public: true,\n supportsAttributes: true,\n tagName: 'nav',\n themeAttributes: {\n theme: 'toc',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (\n typeof attributes.depth === 'string' &&\n (!Number.isInteger(Number.parseInt(attributes.depth, 10)) ||\n Number.parseInt(attributes.depth, 10) < 1 ||\n Number.parseInt(attributes.depth, 10) > 6)\n )\n warnings.push(`Invalid toc depth \"${attributes.depth}\". Falling back to \"${DEFAULT_TOC_DEPTH}\".`)\n\n return warnings\n },\n validateMdast(node) {\n return node.children.length > 0\n ? [\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.',\n ]\n : []\n },\n}\n"],"names":["getDirectiveLabelOrAttribute","resolveDirectiveTheme","DEFAULT_TOC_DEPTH","DEFAULT_TOC_TITLE","resolveTocDepth","node","value","attributes","depth","parsed","Number","parseInt","isInteger","resolveTocTitle","title","tocDirective","name","allowedAttributes","applyHast","config","mergeClassNames","theme","properties","dataTheme","undefined","themes","className","hookClassName","modifierClassName","classes","defaultAttributes","String","description","editor","detail","label","snippet","getMdastRenderProperties","ariaLabel","dataDirective","dataTitle","kind","openMarker","public","supportsAttributes","tagName","themeAttributes","validateAttributes","warnings","push","validateMdast","children","length"],"mappings":"AAIA,SAASA,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,oBAAoB,EAAC;AAClC,OAAO,MAAMC,oBAAoB,eAAc;AAE/C,OAAO,SAASC,gBAAgBC,IAAwB;IACtD,MAAMC,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QAE7B,IACE,OAAOzC,WAAWC,KAAK,KAAK,YAC3B,CAAA,CAACE,OAAOE,SAAS,CAACF,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,QACnDE,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,MAAM,KACxCE,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,MAAM,CAAA,GAE1CwC,SAASC,IAAI,CAAC,CAAC,mBAAmB,EAAE1C,WAAWC,KAAK,CAAC,oBAAoB,EAAEN,kBAAkB,EAAE,CAAC;QAElG,OAAO8C;IACT;IACAE,eAAc7C,IAAI;QAChB,OAAOA,KAAK8C,QAAQ,CAACC,MAAM,GAAG,IAC1B;YACE;SACD,GACD,EAAE;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/directives/definitions/toc.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const DEFAULT_TOC_DEPTH = 3\nexport const DEFAULT_TOC_TITLE = 'On this page'\n\nexport function resolveTocDepth(node: ContainerDirective): number {\n const value = node.attributes?.depth\n const parsed = typeof value === 'string' ? Number.parseInt(value, 10) : DEFAULT_TOC_DEPTH\n\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 6 ? parsed : DEFAULT_TOC_DEPTH\n}\n\nexport function resolveTocTitle(node: ContainerDirective): string {\n const title = getDirectiveLabelOrAttribute(node, 'title')\n\n return title ?? DEFAULT_TOC_TITLE\n}\n\nexport const tocDirective: LayoutDirectiveDefinition = {\n name: 'toc',\n allowedAttributes: ['depth', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'toc',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n 'not-prose',\n // Title reads as a label; entries indent by heading level.\n '[&>p:first-child]:mb-2 [&>p:first-child]:text-xs [&>p:first-child]:font-semibold [&>p:first-child]:uppercase [&>p:first-child]:tracking-[0.18em] [&>p:first-child]:text-(--tw-prose-body)/80',\n '[&_ol]:mt-0 [&_ol]:mb-2 [&_ol]:list-none [&_ol]:p-0 [&_li+li]:mt-1',\n \"[&_li[data-toc-level='1']]:pl-4 [&_li[data-toc-level='2']]:pl-8 [&_li[data-toc-level='3']]:pl-12 [&_li[data-toc-level='4']]:pl-16 [&_li[data-toc-level='5']]:pl-20\",\n '[&_a]:text-(--tw-prose-body) [&_a]:transition-colors [&_a:hover]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))]',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n },\n defaultAttributes: {\n depth: String(DEFAULT_TOC_DEPTH),\n title: DEFAULT_TOC_TITLE,\n },\n description: 'Table of contents generated from document headings.',\n editor: {\n detail: 'Docs directive',\n label: 'Table of contents',\n snippet: ':::toc[${On this page}]{\\n depth=\"${3}\"\\n}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const title = resolveTocTitle(node)\n\n return {\n ariaLabel: title,\n dataDirective: 'toc',\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataTitle: title,\n }\n },\n kind: 'toc',\n openMarker: ':::toc',\n public: true,\n supportsAttributes: true,\n tagName: 'nav',\n themeAttributes: {\n theme: 'toc',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (\n typeof attributes.depth === 'string' &&\n (!Number.isInteger(Number.parseInt(attributes.depth, 10)) ||\n Number.parseInt(attributes.depth, 10) < 1 ||\n Number.parseInt(attributes.depth, 10) > 6)\n )\n warnings.push(`Invalid toc depth \"${attributes.depth}\". Falling back to \"${DEFAULT_TOC_DEPTH}\".`)\n\n return warnings\n },\n validateMdast(node) {\n return node.children.length > 0\n ? [\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.',\n ]\n : []\n },\n}\n"],"names":["getDirectiveLabelOrAttribute","resolveDirectiveTheme","DEFAULT_TOC_DEPTH","DEFAULT_TOC_TITLE","resolveTocDepth","node","value","attributes","depth","parsed","Number","parseInt","isInteger","resolveTocTitle","title","tocDirective","name","allowedAttributes","applyHast","config","mergeClassNames","theme","properties","dataTheme","undefined","themes","className","hookClassName","modifierClassName","classes","defaultAttributes","String","description","editor","detail","label","snippet","getMdastRenderProperties","ariaLabel","dataDirective","dataTitle","kind","openMarker","public","supportsAttributes","tagName","themeAttributes","validateAttributes","warnings","push","validateMdast","children","length"],"mappings":"AAIA,SAASA,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,oBAAoB,EAAC;AAClC,OAAO,MAAMC,oBAAoB,eAAc;AAE/C,OAAO,SAASC,gBAAgBC,IAAwB;IACtD,MAAMC,QAAQD,KAAKE,UAAU,EAAEC;IAC/B,MAAMC,SAAS,OAAOH,UAAU,WAAWI,OAAOC,QAAQ,CAACL,OAAO,MAAMJ;IAExE,OAAOQ,OAAOE,SAAS,CAACH,WAAWA,UAAU,KAAKA,UAAU,IAAIA,SAASP;AAC3E;AAEA,OAAO,SAASW,gBAAgBR,IAAwB;IACtD,MAAMS,QAAQd,6BAA6BK,MAAM;IAEjD,OAAOS,SAASX;AAClB;AAEA,OAAO,MAAMY,eAA0C;IACrDC,MAAM;IACNC,mBAAmB;QAAC;QAAS;QAAS;KAAQ;IAC9CC,WAAUb,IAAI,EAAEc,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMC,QAAQpB,sBACZ,OACA,OAAOI,KAAKiB,UAAU,CAACC,SAAS,KAAK,WAAWlB,KAAKiB,UAAU,CAACC,SAAS,GAAGC,WAC5EL,OAAOM,MAAM;QAGfpB,KAAKiB,UAAU,CAACC,SAAS,GAAGF,MAAML,IAAI;QACtCX,KAAKiB,UAAU,CAACI,SAAS,GAAGN,gBAC1B,aACA,2DAA2D;QAC3D,gMACA,sEACA,sKACA,iLACAC,MAAMM,aAAa,EACnBN,MAAMO,iBAAiB,EACvBP,MAAMQ,OAAO;IAEjB;IACAC,mBAAmB;QACjBtB,OAAOuB,OAAO7B;QACdY,OAAOX;IACT;IACA6B,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyBhC,IAAI;QAC3B,MAAMS,QAAQD,gBAAgBR;QAE9B,OAAO;YACLiC,WAAWxB;YACXyB,eAAe;YACfhB,WAAW,OAAOlB,KAAKE,UAAU,EAAEc,UAAU,WAAWhB,KAAKE,UAAU,CAACc,KAAK,GAAG;YAChFmB,WAAW1B;QACb;IACF;IACA2B,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBC,SAAS;IACTC,iBAAiB;QACfzB,OAAO;IACT;IACA0B,oBAAmB,EAAExC,UAAU,EAAE;QAC/B,MAAMyC,WAAqB,EAAE;QAE7B,IACE,OAAOzC,WAAWC,KAAK,KAAK,YAC3B,CAAA,CAACE,OAAOE,SAAS,CAACF,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,QACnDE,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,MAAM,KACxCE,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,MAAM,CAAA,GAE1CwC,SAASC,IAAI,CAAC,CAAC,mBAAmB,EAAE1C,WAAWC,KAAK,CAAC,oBAAoB,EAAEN,kBAAkB,EAAE,CAAC;QAElG,OAAO8C;IACT;IACAE,eAAc7C,IAAI;QAChB,OAAOA,KAAK8C,QAAQ,CAACC,MAAM,GAAG,IAC1B;YACE;SACD,GACD,EAAE;IACR;AACF,EAAC"}
@@ -12,6 +12,11 @@ export type LintMarkdownDirectivesOptions = {
12
12
  * reported exactly like the renderer does ("Unknown icon pack").
13
13
  */
14
14
  iconPacks?: readonly string[];
15
+ /**
16
+ * Known palette names. When provided, unknown `palette` / `iconPalette`
17
+ * values and icon-entry palettes are reported like the renderer does.
18
+ */
19
+ palettes?: readonly string[];
15
20
  /** Configured directive themes (names are what matters). */
16
21
  themes?: MarkdownDirectiveThemes;
17
22
  };
@@ -1,4 +1,6 @@
1
+ import { getExtraIconWarnings, parseIconEntries } from '../icons/entries.js';
1
2
  import { normalizePayloadMarkdownIconRef } from '../icons/refs.js';
3
+ import { collectPaletteNames, formatUnknownPaletteMessage } from '../palettes/diagnostics.js';
2
4
  import { parseButtonDirectiveLine } from './buttonSyntax.js';
3
5
  import { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js';
4
6
  import { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js';
@@ -8,13 +10,24 @@ import { resolveShieldsBadge } from './shields.js';
8
10
  import { parseDirectiveSourceTree } from './sourceTree.js';
9
11
  import { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js';
10
12
  import { isSafeHref } from './urls.js';
11
- function getIconPackDiagnostics(icon, options) {
12
- if (typeof icon !== 'string' || !options.iconPacks) return [];
13
- const normalized = normalizePayloadMarkdownIconRef(icon);
14
- if (!normalized.icon || options.iconPacks.includes(normalized.icon.packAlias)) return [];
15
- return [
16
- `Unknown icon pack "${normalized.icon.packAlias}".`
13
+ /** Icon-entry option problems, extra icons, then unknown icon packs (one per entry). */ function getIconDiagnostics(directive, icon, options) {
14
+ if (typeof icon !== 'string') return [];
15
+ const { entries, warnings } = parseIconEntries(icon);
16
+ const diagnostics = [
17
+ ...warnings,
18
+ ...getExtraIconWarnings(directive, entries)
17
19
  ];
20
+ if (options.iconPacks) for (const entry of entries){
21
+ const normalized = normalizePayloadMarkdownIconRef(entry.ref);
22
+ if (normalized.icon && !options.iconPacks.includes(normalized.icon.packAlias)) diagnostics.push(`Unknown icon pack "${normalized.icon.packAlias}".`);
23
+ }
24
+ return diagnostics;
25
+ }
26
+ function getPaletteDiagnostics(directive, attributes, options) {
27
+ const known = options.palettes;
28
+ if (!known) return [];
29
+ const allowed = layoutDirectiveRegistry.get(directive)?.allowedAttributes ?? [];
30
+ return collectPaletteNames(allowed, attributes).filter((name)=>!known.includes(name)).map((name)=>formatUnknownPaletteMessage(name, directive, known));
18
31
  }
19
32
  function findNearestFrameIndex(stack, predicate) {
20
33
  for(let index = stack.length - 1; index >= 0; --index){
@@ -154,7 +167,8 @@ function getThemeDiagnostics(text, options) {
154
167
  if (!token || token.action !== 'open') return [];
155
168
  const definition = layoutDirectiveRegistry.get(token.name);
156
169
  const diagnostics = [
157
- ...getIconPackDiagnostics(token.attributes?.icon, options)
170
+ ...getIconDiagnostics(token.name, token.attributes?.icon, options),
171
+ ...getPaletteDiagnostics(token.name, token.attributes, options)
158
172
  ];
159
173
  if (!definition?.themeAttributes) return diagnostics;
160
174
  for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
@@ -179,14 +193,16 @@ function getButtonDiagnostics(text, options) {
179
193
  }) ?? []
180
194
  ];
181
195
  const icon = parsed.attributes.icon;
182
- if (typeof icon === 'string') {
183
- const normalized = normalizePayloadMarkdownIconRef(icon);
196
+ const [iconEntry] = typeof icon === 'string' ? parseIconEntries(icon).entries : [];
197
+ if (iconEntry) {
198
+ const normalized = normalizePayloadMarkdownIconRef(iconEntry.ref);
184
199
  if (normalized.warning) diagnostics.push(normalized.warning);
185
200
  }
186
201
  if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string') diagnostics.push('Icon-only button requires an ariaLabel attribute.');
187
202
  return [
188
203
  ...diagnostics,
189
- ...getIconPackDiagnostics(icon, options)
204
+ ...getIconDiagnostics('button', icon, options),
205
+ ...getPaletteDiagnostics('button', parsed.attributes, options)
190
206
  ];
191
207
  }
192
208
  function getBadgeDiagnostics(text) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/directives/diagnostics.ts"],"sourcesContent":["import type { Root } from 'mdast'\n\nimport type { MarkdownDirectiveThemes } from '../types/core.js'\nimport type { TabsDefaultCandidate } from './definitions/tab.js'\nimport type { ScannedDirectiveLine, SourceIndex } from './lineScanner.js'\n\nimport { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\nimport { parseButtonDirectiveLine } from './buttonSyntax.js'\nimport { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js'\nimport { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from './lineScanner.js'\nimport { layoutDirectiveRegistry } from './registry.js'\nimport { resolveShieldsBadge } from './shields.js'\nimport { parseDirectiveSourceTree } from './sourceTree.js'\nimport { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js'\nimport { isSafeHref } from './urls.js'\n\nexport type DirectiveDiagnostic = {\n from: number\n line: number\n message: string\n severity: 'warning'\n to: number\n}\n\ntype OpenFrame = {\n cardsHasHref?: boolean\n cardsLinkScope?: string\n defaultValue?: string\n from: number\n hasContent?: boolean\n line: number\n name: string\n parentHeadingDepth?: number\n tabCandidates?: TabsDefaultCandidate[]\n tabCount?: number\n tabValues?: Map<string, number>\n}\n\ntype LintState = {\n currentHeadingDepth?: number\n options: LintMarkdownDirectivesOptions\n stack: OpenFrame[]\n}\n\nexport type LintMarkdownDirectivesOptions = {\n /**\n * Configured icon pack aliases. When provided, icon refs to other packs are\n * reported exactly like the renderer does (\"Unknown icon pack\").\n */\n iconPacks?: readonly string[]\n /** Configured directive themes (names are what matters). */\n themes?: MarkdownDirectiveThemes\n}\n\nfunction getIconPackDiagnostics(icon: unknown, options: LintMarkdownDirectivesOptions): string[] {\n if (typeof icon !== 'string' || !options.iconPacks) return []\n\n const normalized = normalizePayloadMarkdownIconRef(icon)\n if (!normalized.icon || options.iconPacks.includes(normalized.icon.packAlias)) return []\n\n return [`Unknown icon pack \"${normalized.icon.packAlias}\".`]\n}\n\nfunction findNearestFrameIndex(stack: OpenFrame[], predicate: (frame: OpenFrame) => boolean) {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (predicate(frame)) return index\n }\n\n return -1\n}\n\nfunction getTabValue(\n attributes: Record<string, boolean | string> | undefined,\n index: number,\n label?: string,\n): string {\n return slugTabValue(getTabRawValue(attributes, label) ?? `tab-${index + 1}`, index)\n}\n\nconst TOC_CONTENT_DIAGNOSTIC =\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.'\n\nfunction finalizeFrame(frame: OpenFrame): string[] {\n if (frame.name === 'toc') return frame.hasContent ? [TOC_CONTENT_DIAGNOSTIC] : []\n\n return finalizeTabsFrame(frame)\n}\n\nfunction finalizeTabsFrame(frame: OpenFrame): string[] {\n if (frame.name !== 'tabs') return []\n\n const diagnostics: string[] = []\n const tabValues = frame.tabValues ?? new Map<string, number>()\n\n if (!frame.tabCount) diagnostics.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n for (const [value, count] of tabValues)\n if (count > 1) diagnostics.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (frame.defaultValue && !resolveTabsDefault(frame.defaultValue, frame.tabCandidates ?? []))\n diagnostics.push(`Invalid tabs default \"${frame.defaultValue}\". Falling back to the first tab.`)\n\n return diagnostics\n}\n\nfunction findNearestTabsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'tabs') return frame\n }\n\n return undefined\n}\n\nfunction findNearestCardsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'cards') return frame\n }\n\n return undefined\n}\n\nfunction hasAttribute(\n attributes: Record<string, boolean | string> | undefined,\n name: string,\n): boolean {\n return Object.prototype.hasOwnProperty.call(attributes ?? {}, name)\n}\n\nfunction popFrames(stack: OpenFrame[], index: number): string[] {\n return stack.splice(index).flatMap((frame) => finalizeFrame(frame))\n}\n\nfunction markTopFrameContent(state: LintState) {\n const top = state.stack[state.stack.length - 1]\n if (top) top.hasContent = true\n}\n\n/** Mirrors remarkCompileLayouts: a heading shallower than a grid's parent heading closes the grid. */\nfunction applyHeading(state: LintState, depth: number): string[] {\n markTopFrameContent(state)\n\n const top = state.stack[state.stack.length - 1]\n const diagnostics =\n top &&\n layoutDirectiveRegistry.isGridName(top.name) &&\n typeof top.parentHeadingDepth === 'number' &&\n depth < top.parentHeadingDepth\n ? popFrames(state.stack, state.stack.length - 1)\n : []\n\n state.currentHeadingDepth = depth\n\n return diagnostics\n}\n\nfunction updateOpenStack(\n state: LintState,\n text: string,\n line: number,\n from: number,\n): string[] {\n const { stack } = state\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n const diagnostics: string[] = []\n\n if (!token) return diagnostics\n\n if (token.action === 'open') {\n markTopFrameContent(state)\n\n if (token.name === 'card') {\n const cardsFrame = findNearestCardsFrame(stack)\n const cardsSectionLink =\n cardsFrame?.cardsHasHref &&\n (cardsFrame.cardsLinkScope === undefined || cardsFrame.cardsLinkScope === 'section')\n\n if (\n cardsSectionLink &&\n (hasAttribute(token.attributes, 'href') ||\n hasAttribute(token.attributes, 'linkScope') ||\n hasAttribute(token.attributes, 'newTab'))\n )\n diagnostics.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n if (token.name === 'tab') {\n const tabsFrame = findNearestTabsFrame(stack)\n\n if (!tabsFrame) diagnostics.push('Directive \"tab\" is usually intended inside \"tabs\".')\n else {\n const nextIndex = tabsFrame.tabCount ?? 0\n const value = getTabValue(token.attributes, nextIndex, token.label)\n\n tabsFrame.tabCandidates ??= []\n tabsFrame.tabCandidates.push({\n label: getTabRawValue({ label: token.attributes?.label ?? '' }, token.label) ?? `Tab ${nextIndex + 1}`,\n raw: getTabRawValue(token.attributes),\n value,\n })\n tabsFrame.tabCount = nextIndex + 1\n tabsFrame.tabValues ??= new Map<string, number>()\n tabsFrame.tabValues.set(value, (tabsFrame.tabValues.get(value) ?? 0) + 1)\n }\n }\n\n const isGrid = layoutDirectiveRegistry.isGridName(token.name)\n\n if (isGrid) {\n // remarkCompileLayouts closes an open grid inside the nearest section.\n const gridIndex = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n const sectionIndex = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n\n if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex)\n diagnostics.push(...popFrames(stack, gridIndex))\n }\n\n stack.push({\n name: token.name,\n from,\n line,\n ...(isGrid ? { parentHeadingDepth: state.currentHeadingDepth ?? 1 } : {}),\n ...(token.name === 'cards'\n ? {\n cardsHasHref:\n typeof token.attributes?.href === 'string' && isSafeHref(token.attributes.href.trim()),\n cardsLinkScope:\n typeof token.attributes?.linkScope === 'string'\n ? token.attributes.linkScope\n : undefined,\n }\n : {}),\n ...(token.name === 'tabs'\n ? {\n defaultValue:\n typeof token.attributes?.default === 'string'\n ? token.attributes.default\n : undefined,\n tabCount: 0,\n tabValues: new Map<string, number>(),\n }\n : {}),\n })\n return diagnostics\n }\n\n if (token.action === 'close') {\n if (stack.length === 0) return ['Encountered ::: with no open layout block.']\n\n return popFrames(stack, stack.length - 1)\n }\n\n if (token.action === 'closeGrid') {\n const index = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n\n if (index < 0) return ['Encountered :::endcol with no open grid.']\n\n return popFrames(stack, index)\n }\n\n const index = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n if (index < 0) return ['Encountered :::end or :::endsection with no open section.']\n\n return popFrames(stack, index)\n}\n\nfunction getThemeDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n if (!token || token.action !== 'open') return []\n\n const definition = layoutDirectiveRegistry.get(token.name)\n const diagnostics: string[] = [...getIconPackDiagnostics(token.attributes?.icon, options)]\n\n if (!definition?.themeAttributes) return diagnostics\n\n for (const [attribute, groupName] of Object.entries(definition.themeAttributes)) {\n if (!groupName) continue\n\n const value = token.attributes?.[attribute]\n if (typeof value !== 'string' || !value.trim()) continue\n if (hasDirectiveTheme(groupName, value, options.themes)) continue\n\n const label = attribute === 'theme' ? 'theme' : attribute\n diagnostics.push(\n `Unknown ${label} \"${value}\" on \"${token.name}\". Falling back to \"${getDirectiveFallbackThemeName(groupName, options.themes)}\".`,\n )\n }\n\n return diagnostics\n}\n\nfunction getButtonDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const parsed = parseButtonDirectiveLine(text)\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('button')\n const diagnostics = [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'button', attributes: parsed.attributes }) ?? []),\n ]\n const icon = parsed.attributes.icon\n\n if (typeof icon === 'string') {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n if (normalized.warning) diagnostics.push(normalized.warning)\n }\n\n if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string')\n diagnostics.push('Icon-only button requires an ariaLabel attribute.')\n\n return [...diagnostics, ...getIconPackDiagnostics(icon, options)]\n}\n\nfunction getBadgeDiagnostics(text: string): string[] {\n const parsed = parseLeafDirectiveLine(text, 'badge')\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('badge')\n const resolved = resolveShieldsBadge(parsed.attributes)\n\n return [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'badge', attributes: parsed.attributes }) ?? []),\n ...resolved.warnings,\n ]\n}\n\ntype DiagnosticSink = (message: string, from: number, to: number, line: number) => void\n\nfunction lintContainerLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const result = layoutDirectiveRegistry.parseMarkdownLineDetailed(scanned.text)\n\n for (const message of result.diagnostics) report(message)\n for (const message of getThemeDiagnostics(scanned.text, state.options)) report(message)\n for (const message of updateOpenStack(state, scanned.text, scanned.startLine, scanned.from))\n report(message)\n\n // Tokens that do not open/close anything render as prose inside the frame.\n if (!result.token) markTopFrameContent(state)\n}\n\nfunction lintLeafLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const leafName = getLeafDirectiveName(scanned.text)\n\n markTopFrameContent(state)\n\n if (!leafName) return\n\n if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {\n report(`Unknown directive \"${leafName}\".`)\n return\n }\n\n const problem = getLeafDirectiveProblem(scanned.text, leafName)\n\n if (problem) {\n report(problem)\n return\n }\n\n const messages =\n leafName === 'button'\n ? getButtonDiagnostics(scanned.text, state.options)\n : getBadgeDiagnostics(scanned.text)\n\n for (const message of messages) report(message)\n}\n\nfunction lintParagraph(\n state: LintState,\n paragraph: Root['children'][number],\n index: SourceIndex,\n push: DiagnosticSink,\n) {\n if (paragraph.type !== 'paragraph') return\n\n const lines = splitParagraphIntoLines(paragraph)\n\n for (let lineIndex = 0; lineIndex < lines.length; ++lineIndex) {\n const scanned = scanDirectiveLineAt(lines, lineIndex, index)\n\n if (!scanned) {\n markTopFrameContent(state)\n continue\n }\n\n if (scanned.kind === 'container') lintContainerLine(state, scanned, push)\n else lintLeafLine(state, scanned, push)\n\n lineIndex = scanned.phrasingEnd\n }\n}\n\n/**\n * Editor-side directive diagnostics. The document is parsed with the same\n * remark/GFM front end and the same directive line scanner as the renderer,\n * so code blocks, lists, blockquotes and prose are classified identically.\n * Every renderer warning about directive syntax has an editor counterpart;\n * the renderer's \"Auto-closing unclosed layout block: X\" is reported here as\n * \"Unclosed directive \"X\".\" at the opening marker.\n */\nexport function lintMarkdownDirectives(\n markdown: string,\n options: LintMarkdownDirectivesOptions = {},\n): DirectiveDiagnostic[] {\n const diagnostics: DirectiveDiagnostic[] = []\n const state: LintState = { options, stack: [] }\n const index = createSourceIndex(markdown)\n const tree = parseDirectiveSourceTree(markdown)\n\n const push: DiagnosticSink = (message, from, to, line) =>\n diagnostics.push({ from, line, message, severity: 'warning', to })\n\n const nested = findNestedDirectiveMarkers(tree, index)\n let nestedIndex = 0\n\n const flushNestedBefore = (line: number) => {\n while (nestedIndex < nested.length && nested[nestedIndex].line < line) {\n const marker = nested[nestedIndex++]\n push(getNestedDirectiveMarkerDiagnostic(marker), marker.from, marker.to, marker.line)\n }\n }\n\n for (const node of tree.children) {\n flushNestedBefore(\n ('position' in node ? node.position?.start.line : undefined) ?? Number.POSITIVE_INFINITY,\n )\n\n if (node.type === 'paragraph') {\n lintParagraph(state, node, index, push)\n continue\n }\n\n if (node.type === 'heading') {\n const line = node.position?.start.line ?? 1\n const from = index.lineStarts[line] ?? 0\n\n for (const message of applyHeading(state, node.depth)) push(message, from, from, line)\n continue\n }\n\n markTopFrameContent(state)\n }\n\n flushNestedBefore(Number.POSITIVE_INFINITY)\n\n for (const frame of state.stack) {\n for (const message of finalizeFrame(frame))\n push(message, frame.from, frame.from + frame.name.length + 3, frame.line)\n\n push(`Unclosed directive \"${frame.name}\".`, frame.from, frame.from + frame.name.length + 3, frame.line)\n }\n\n return diagnostics\n}\n"],"names":["normalizePayloadMarkdownIconRef","parseButtonDirectiveLine","getTabRawValue","resolveTabsDefault","slugTabValue","getLeafDirectiveName","getLeafDirectiveProblem","parseLeafDirectiveLine","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","scanDirectiveLineAt","splitParagraphIntoLines","layoutDirectiveRegistry","resolveShieldsBadge","parseDirectiveSourceTree","getDirectiveFallbackThemeName","hasDirectiveTheme","isSafeHref","getIconPackDiagnostics","icon","options","iconPacks","normalized","includes","packAlias","findNearestFrameIndex","stack","predicate","index","length","frame","getTabValue","attributes","label","TOC_CONTENT_DIAGNOSTIC","finalizeFrame","name","hasContent","finalizeTabsFrame","diagnostics","tabValues","Map","tabCount","push","value","count","defaultValue","tabCandidates","findNearestTabsFrame","undefined","findNearestCardsFrame","hasAttribute","Object","prototype","hasOwnProperty","call","popFrames","splice","flatMap","markTopFrameContent","state","top","applyHeading","depth","isGridName","parentHeadingDepth","currentHeadingDepth","updateOpenStack","text","line","from","token","parseMarkdownLineDetailed","action","cardsFrame","cardsSectionLink","cardsHasHref","cardsLinkScope","tabsFrame","nextIndex","raw","set","get","isGrid","gridIndex","sectionIndex","href","trim","linkScope","default","getThemeDiagnostics","definition","themeAttributes","attribute","groupName","entries","themes","getButtonDiagnostics","parsed","warnings","validateAttributes","warning","ariaLabel","getBadgeDiagnostics","resolved","lintContainerLine","scanned","report","message","to","startLine","result","lintLeafLine","leafName","isLeafDirectiveName","problem","messages","lintParagraph","paragraph","type","lines","lineIndex","kind","phrasingEnd","lintMarkdownDirectives","markdown","tree","severity","nested","nestedIndex","flushNestedBefore","marker","node","children","position","start","Number","POSITIVE_INFINITY","lineStarts"],"mappings":"AAMA,SAASA,+BAA+B,QAAQ,mBAAkB;AAClE,SAASC,wBAAwB,QAAQ,oBAAmB;AAC5D,SAASC,cAAc,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,uBAAsB;AACvF,SAASC,oBAAoB,EAAEC,uBAAuB,EAAEC,sBAAsB,QAAQ,kBAAiB;AACvG,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,kCAAkC,EAClCC,mBAAmB,EACnBC,uBAAuB,QAClB,mBAAkB;AACzB,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,mBAAmB,QAAQ,eAAc;AAClD,SAASC,wBAAwB,QAAQ,kBAAiB;AAC1D,SAASC,6BAA6B,EAAEC,iBAAiB,QAAQ,cAAa;AAC9E,SAASC,UAAU,QAAQ,YAAW;AAwCtC,SAASC,uBAAuBC,IAAa,EAAEC,OAAsC;IACnF,IAAI,OAAOD,SAAS,YAAY,CAACC,QAAQC,SAAS,EA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AAC,CAAA,cAAcE,OAAOA,KAAKE,QAAQ,EAAEC,MAAMlE,OAAOpB,SAAQ,KAAMuF,OAAOC,iBAAiB;QAG1F,IAAIL,KAAKb,IAAI,KAAK,aAAa;YAC7BF,cAAczD,OAAOwE,MAAMxG,OAAOe;YAClC;QACF;QAEA,IAAIyF,KAAKb,IAAI,KAAK,WAAW;YAC3B,MAAMlD,OAAO+D,KAAKE,QAAQ,EAAEC,MAAMlE,QAAQ;YAC1C,MAAMC,OAAO1C,MAAM8G,UAAU,CAACrE,KAAK,IAAI;YAEvC,KAAK,MAAMuC,WAAW9C,aAAaF,OAAOwE,KAAKrE,KAAK,EAAGpB,KAAKiE,SAAStC,MAAMA,MAAMD;YACjF;QACF;QAEAV,oBAAoBC;IACtB;IAEAsE,kBAAkBM,OAAOC,iBAAiB;IAE1C,KAAK,MAAM3G,SAAS8B,MAAMlC,KAAK,CAAE;QAC/B,KAAK,MAAMkF,WAAWzE,cAAcL,OAClCa,KAAKiE,SAAS9E,MAAMwC,IAAI,EAAExC,MAAMwC,IAAI,GAAGxC,MAAMM,IAAI,CAACP,MAAM,GAAG,GAAGC,MAAMuC,IAAI;QAE1E1B,KAAK,CAAC,oBAAoB,EAAEb,MAAMM,IAAI,CAAC,EAAE,CAAC,EAAEN,MAAMwC,IAAI,EAAExC,MAAMwC,IAAI,GAAGxC,MAAMM,IAAI,CAACP,MAAM,GAAG,GAAGC,MAAMuC,IAAI;IACxG;IAEA,OAAO9B;AACT"}
1
+ {"version":3,"sources":["../../src/directives/diagnostics.ts"],"sourcesContent":["import type { Root } from 'mdast'\n\nimport type { MarkdownDirectiveThemes } from '../types/core.js'\nimport type { TabsDefaultCandidate } from './definitions/tab.js'\nimport type { ScannedDirectiveLine, SourceIndex } from './lineScanner.js'\n\nimport { getExtraIconWarnings, parseIconEntries } from '../icons/entries.js'\nimport { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\nimport { collectPaletteNames, formatUnknownPaletteMessage } from '../palettes/diagnostics.js'\nimport { parseButtonDirectiveLine } from './buttonSyntax.js'\nimport { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js'\nimport { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from './lineScanner.js'\nimport { layoutDirectiveRegistry } from './registry.js'\nimport { resolveShieldsBadge } from './shields.js'\nimport { parseDirectiveSourceTree } from './sourceTree.js'\nimport { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js'\nimport { isSafeHref } from './urls.js'\n\nexport type DirectiveDiagnostic = {\n from: number\n line: number\n message: string\n severity: 'warning'\n to: number\n}\n\ntype OpenFrame = {\n cardsHasHref?: boolean\n cardsLinkScope?: string\n defaultValue?: string\n from: number\n hasContent?: boolean\n line: number\n name: string\n parentHeadingDepth?: number\n tabCandidates?: TabsDefaultCandidate[]\n tabCount?: number\n tabValues?: Map<string, number>\n}\n\ntype LintState = {\n currentHeadingDepth?: number\n options: LintMarkdownDirectivesOptions\n stack: OpenFrame[]\n}\n\nexport type LintMarkdownDirectivesOptions = {\n /**\n * Configured icon pack aliases. When provided, icon refs to other packs are\n * reported exactly like the renderer does (\"Unknown icon pack\").\n */\n iconPacks?: readonly string[]\n /**\n * Known palette names. When provided, unknown `palette` / `iconPalette`\n * values and icon-entry palettes are reported like the renderer does.\n */\n palettes?: readonly string[]\n /** Configured directive themes (names are what matters). */\n themes?: MarkdownDirectiveThemes\n}\n\n/** Icon-entry option problems, extra icons, then unknown icon packs (one per entry). */\nfunction getIconDiagnostics(directive: string, icon: unknown, options: LintMarkdownDirectivesOptions): string[] {\n if (typeof icon !== 'string') return []\n\n const { entries, warnings } = parseIconEntries(icon)\n const diagnostics = [...warnings, ...getExtraIconWarnings(directive, entries)]\n\n if (options.iconPacks)\n for (const entry of entries) {\n const normalized = normalizePayloadMarkdownIconRef(entry.ref)\n if (normalized.icon && !options.iconPacks.includes(normalized.icon.packAlias))\n diagnostics.push(`Unknown icon pack \"${normalized.icon.packAlias}\".`)\n }\n\n return diagnostics\n}\n\nfunction getPaletteDiagnostics(\n directive: string,\n attributes: Record<string, unknown> | undefined,\n options: LintMarkdownDirectivesOptions,\n): string[] {\n const known = options.palettes\n if (!known) return []\n\n const allowed = layoutDirectiveRegistry.get(directive)?.allowedAttributes ?? []\n\n return collectPaletteNames(allowed, attributes)\n .filter((name) => !known.includes(name))\n .map((name) => formatUnknownPaletteMessage(name, directive, known))\n}\n\nfunction findNearestFrameIndex(stack: OpenFrame[], predicate: (frame: OpenFrame) => boolean) {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (predicate(frame)) return index\n }\n\n return -1\n}\n\nfunction getTabValue(\n attributes: Record<string, boolean | string> | undefined,\n index: number,\n label?: string,\n): string {\n return slugTabValue(getTabRawValue(attributes, label) ?? `tab-${index + 1}`, index)\n}\n\nconst TOC_CONTENT_DIAGNOSTIC =\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.'\n\nfunction finalizeFrame(frame: OpenFrame): string[] {\n if (frame.name === 'toc') return frame.hasContent ? [TOC_CONTENT_DIAGNOSTIC] : []\n\n return finalizeTabsFrame(frame)\n}\n\nfunction finalizeTabsFrame(frame: OpenFrame): string[] {\n if (frame.name !== 'tabs') return []\n\n const diagnostics: string[] = []\n const tabValues = frame.tabValues ?? new Map<string, number>()\n\n if (!frame.tabCount) diagnostics.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n for (const [value, count] of tabValues)\n if (count > 1) diagnostics.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (frame.defaultValue && !resolveTabsDefault(frame.defaultValue, frame.tabCandidates ?? []))\n diagnostics.push(`Invalid tabs default \"${frame.defaultValue}\". Falling back to the first tab.`)\n\n return diagnostics\n}\n\nfunction findNearestTabsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'tabs') return frame\n }\n\n return undefined\n}\n\nfunction findNearestCardsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'cards') return frame\n }\n\n return undefined\n}\n\nfunction hasAttribute(\n attributes: Record<string, boolean | string> | undefined,\n name: string,\n): boolean {\n return Object.prototype.hasOwnProperty.call(attributes ?? {}, name)\n}\n\nfunction popFrames(stack: OpenFrame[], index: number): string[] {\n return stack.splice(index).flatMap((frame) => finalizeFrame(frame))\n}\n\nfunction markTopFrameContent(state: LintState) {\n const top = state.stack[state.stack.length - 1]\n if (top) top.hasContent = true\n}\n\n/** Mirrors remarkCompileLayouts: a heading shallower than a grid's parent heading closes the grid. */\nfunction applyHeading(state: LintState, depth: number): string[] {\n markTopFrameContent(state)\n\n const top = state.stack[state.stack.length - 1]\n const diagnostics =\n top &&\n layoutDirectiveRegistry.isGridName(top.name) &&\n typeof top.parentHeadingDepth === 'number' &&\n depth < top.parentHeadingDepth\n ? popFrames(state.stack, state.stack.length - 1)\n : []\n\n state.currentHeadingDepth = depth\n\n return diagnostics\n}\n\nfunction updateOpenStack(\n state: LintState,\n text: string,\n line: number,\n from: number,\n): string[] {\n const { stack } = state\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n const diagnostics: string[] = []\n\n if (!token) return diagnostics\n\n if (token.action === 'open') {\n markTopFrameContent(state)\n\n if (token.name === 'card') {\n const cardsFrame = findNearestCardsFrame(stack)\n const cardsSectionLink =\n cardsFrame?.cardsHasHref &&\n (cardsFrame.cardsLinkScope === undefined || cardsFrame.cardsLinkScope === 'section')\n\n if (\n cardsSectionLink &&\n (hasAttribute(token.attributes, 'href') ||\n hasAttribute(token.attributes, 'linkScope') ||\n hasAttribute(token.attributes, 'newTab'))\n )\n diagnostics.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n if (token.name === 'tab') {\n const tabsFrame = findNearestTabsFrame(stack)\n\n if (!tabsFrame) diagnostics.push('Directive \"tab\" is usually intended inside \"tabs\".')\n else {\n const nextIndex = tabsFrame.tabCount ?? 0\n const value = getTabValue(token.attributes, nextIndex, token.label)\n\n tabsFrame.tabCandidates ??= []\n tabsFrame.tabCandidates.push({\n label: getTabRawValue({ label: token.attributes?.label ?? '' }, token.label) ?? `Tab ${nextIndex + 1}`,\n raw: getTabRawValue(token.attributes),\n value,\n })\n tabsFrame.tabCount = nextIndex + 1\n tabsFrame.tabValues ??= new Map<string, number>()\n tabsFrame.tabValues.set(value, (tabsFrame.tabValues.get(value) ?? 0) + 1)\n }\n }\n\n const isGrid = layoutDirectiveRegistry.isGridName(token.name)\n\n if (isGrid) {\n // remarkCompileLayouts closes an open grid inside the nearest section.\n const gridIndex = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n const sectionIndex = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n\n if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex)\n diagnostics.push(...popFrames(stack, gridIndex))\n }\n\n stack.push({\n name: token.name,\n from,\n line,\n ...(isGrid ? { parentHeadingDepth: state.currentHeadingDepth ?? 1 } : {}),\n ...(token.name === 'cards'\n ? {\n cardsHasHref:\n typeof token.attributes?.href === 'string' && isSafeHref(token.attributes.href.trim()),\n cardsLinkScope:\n typeof token.attributes?.linkScope === 'string'\n ? token.attributes.linkScope\n : undefined,\n }\n : {}),\n ...(token.name === 'tabs'\n ? {\n defaultValue:\n typeof token.attributes?.default === 'string'\n ? token.attributes.default\n : undefined,\n tabCount: 0,\n tabValues: new Map<string, number>(),\n }\n : {}),\n })\n return diagnostics\n }\n\n if (token.action === 'close') {\n if (stack.length === 0) return ['Encountered ::: with no open layout block.']\n\n return popFrames(stack, stack.length - 1)\n }\n\n if (token.action === 'closeGrid') {\n const index = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n\n if (index < 0) return ['Encountered :::endcol with no open grid.']\n\n return popFrames(stack, index)\n }\n\n const index = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n if (index < 0) return ['Encountered :::end or :::endsection with no open section.']\n\n return popFrames(stack, index)\n}\n\nfunction getThemeDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n if (!token || token.action !== 'open') return []\n\n const definition = layoutDirectiveRegistry.get(token.name)\n const diagnostics: string[] = [\n ...getIconDiagnostics(token.name, token.attributes?.icon, options),\n ...getPaletteDiagnostics(token.name, token.attributes, options),\n ]\n\n if (!definition?.themeAttributes) return diagnostics\n\n for (const [attribute, groupName] of Object.entries(definition.themeAttributes)) {\n if (!groupName) continue\n\n const value = token.attributes?.[attribute]\n if (typeof value !== 'string' || !value.trim()) continue\n if (hasDirectiveTheme(groupName, value, options.themes)) continue\n\n const label = attribute === 'theme' ? 'theme' : attribute\n diagnostics.push(\n `Unknown ${label} \"${value}\" on \"${token.name}\". Falling back to \"${getDirectiveFallbackThemeName(groupName, options.themes)}\".`,\n )\n }\n\n return diagnostics\n}\n\nfunction getButtonDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const parsed = parseButtonDirectiveLine(text)\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('button')\n const diagnostics = [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'button', attributes: parsed.attributes }) ?? []),\n ]\n const icon = parsed.attributes.icon\n const [iconEntry] = typeof icon === 'string' ? parseIconEntries(icon).entries : []\n\n if (iconEntry) {\n const normalized = normalizePayloadMarkdownIconRef(iconEntry.ref)\n if (normalized.warning) diagnostics.push(normalized.warning)\n }\n\n if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string')\n diagnostics.push('Icon-only button requires an ariaLabel attribute.')\n\n return [\n ...diagnostics,\n ...getIconDiagnostics('button', icon, options),\n ...getPaletteDiagnostics('button', parsed.attributes, options),\n ]\n}\n\nfunction getBadgeDiagnostics(text: string): string[] {\n const parsed = parseLeafDirectiveLine(text, 'badge')\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('badge')\n const resolved = resolveShieldsBadge(parsed.attributes)\n\n return [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'badge', attributes: parsed.attributes }) ?? []),\n ...resolved.warnings,\n ]\n}\n\ntype DiagnosticSink = (message: string, from: number, to: number, line: number) => void\n\nfunction lintContainerLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const result = layoutDirectiveRegistry.parseMarkdownLineDetailed(scanned.text)\n\n for (const message of result.diagnostics) report(message)\n for (const message of getThemeDiagnostics(scanned.text, state.options)) report(message)\n for (const message of updateOpenStack(state, scanned.text, scanned.startLine, scanned.from))\n report(message)\n\n // Tokens that do not open/close anything render as prose inside the frame.\n if (!result.token) markTopFrameContent(state)\n}\n\nfunction lintLeafLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const leafName = getLeafDirectiveName(scanned.text)\n\n markTopFrameContent(state)\n\n if (!leafName) return\n\n if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {\n report(`Unknown directive \"${leafName}\".`)\n return\n }\n\n const problem = getLeafDirectiveProblem(scanned.text, leafName)\n\n if (problem) {\n report(problem)\n return\n }\n\n const messages =\n leafName === 'button'\n ? getButtonDiagnostics(scanned.text, state.options)\n : getBadgeDiagnostics(scanned.text)\n\n for (const message of messages) report(message)\n}\n\nfunction lintParagraph(\n state: LintState,\n paragraph: Root['children'][number],\n index: SourceIndex,\n push: DiagnosticSink,\n) {\n if (paragraph.type !== 'paragraph') return\n\n const lines = splitParagraphIntoLines(paragraph)\n\n for (let lineIndex = 0; lineIndex < lines.length; ++lineIndex) {\n const scanned = scanDirectiveLineAt(lines, lineIndex, index)\n\n if (!scanned) {\n markTopFrameContent(state)\n continue\n }\n\n if (scanned.kind === 'container') lintContainerLine(state, scanned, push)\n else lintLeafLine(state, scanned, push)\n\n lineIndex = scanned.phrasingEnd\n }\n}\n\n/**\n * Editor-side directive diagnostics. The document is parsed with the same\n * remark/GFM front end and the same directive line scanner as the renderer,\n * so code blocks, lists, blockquotes and prose are classified identically.\n * Every renderer warning about directive syntax has an editor counterpart;\n * the renderer's \"Auto-closing unclosed layout block: X\" is reported here as\n * \"Unclosed directive \"X\".\" at the opening marker.\n */\nexport function lintMarkdownDirectives(\n markdown: string,\n options: LintMarkdownDirectivesOptions = {},\n): DirectiveDiagnostic[] {\n const diagnostics: DirectiveDiagnostic[] = []\n const state: LintState = { options, stack: [] }\n const index = createSourceIndex(markdown)\n const tree = parseDirectiveSourceTree(markdown)\n\n const push: DiagnosticSink = (message, from, to, line) =>\n diagnostics.push({ from, line, message, severity: 'warning', to })\n\n const nested = findNestedDirectiveMarkers(tree, index)\n let nestedIndex = 0\n\n const flushNestedBefore = (line: number) => {\n while (nestedIndex < nested.length && nested[nestedIndex].line < line) {\n const marker = nested[nestedIndex++]\n push(getNestedDirectiveMarkerDiagnostic(marker), marker.from, marker.to, marker.line)\n }\n }\n\n for (const node of tree.children) {\n flushNestedBefore(\n ('position' in node ? node.position?.start.line : undefined) ?? Number.POSITIVE_INFINITY,\n )\n\n if (node.type === 'paragraph') {\n lintParagraph(state, node, index, push)\n continue\n }\n\n if (node.type === 'heading') {\n const line = node.position?.start.line ?? 1\n const from = index.lineStarts[line] ?? 0\n\n for (const message of applyHeading(state, node.depth)) push(message, from, from, line)\n continue\n }\n\n markTopFrameContent(state)\n }\n\n flushNestedBefore(Number.POSITIVE_INFINITY)\n\n for (const frame of state.stack) {\n for (const message of finalizeFrame(frame))\n push(message, frame.from, frame.from + frame.name.length + 3, frame.line)\n\n push(`Unclosed directive \"${frame.name}\".`, frame.from, frame.from + frame.name.length + 3, frame.line)\n }\n\n return diagnostics\n}\n"],"names":["getExtraIconWarnings","parseIconEntries","normalizePayloadMarkdownIconRef","collectPaletteNames","formatUnknownPaletteMessage","parseButtonDirectiveLine","getTabRawValue","resolveTabsDefault","slugTabValue","getLeafDirectiveName","getLeafDirectiveProblem","parseLeafDirectiveLine","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","scanDirectiveLineAt","splitParagraphIntoLines","layoutDirectiveRegistry","resolveShieldsBadge","parseDirectiveSourceTree","getDirectiveFallbackThemeName","hasDirectiveTheme","isSafeHref","getIconDiagnostics","directive","icon","options","entries","warnings","diagnostics","iconPacks","entry","normalized","ref","includes","packAlias","push","getPaletteDiagnostics","attributes","known","palettes","allowed","get","allowedAttributes","filter","name","map","findNearestFrameIndex","stack","predicate","index","length","frame","getTabValue","label","TOC_CONTENT_DIAGNOSTIC","finalizeFrame","hasContent","finalizeTabsFrame","tabValues","Map","tabCount","value","count","defaultValue","tabCandidates","findNearestTabsFrame","undefined","findNearestCardsFrame","hasAttribute","Object","prototype","hasOwnProperty","call","popFrames","splice","flatMap","markTopFrameContent","state","top","applyHeading","depth","isGridName","parentHeadingDepth","currentHeadingDepth","updateOpenStack","text","line","from","token","parseMarkdownLineDetailed","action","cardsFrame","cardsSectionLink","cardsHasHref","cardsLinkScope","tabsFrame","nextIndex","raw","set","isGrid","gridIndex","sectionIndex","href","trim","linkScope","default","getThemeDiagnostics","definition","themeAttributes","attribute","groupName","themes","getButtonDiagnostics","parsed","validateAttributes","iconEntry","warning","ariaLabel","getBadgeDiagnostics","resolved","lintContainerLine","scanned","report","message","to","startLine","result","lintLeafLine","leafName","isLeafDirectiveName","problem","messages","lintParagraph","paragraph","type","lines","lineIndex","kind","phrasingEnd","lintMarkdownDirectives","markdown","tree","severity","nested","nestedIndex","flushNestedBefore","marker","node","children","position","start","Number","POSITIVE_INFINITY","lineStarts"],"mappings":"AAMA,S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/**
2
+ * A placeholder that rehypeResolveIcons replaces with the sanitized SVG.
3
+ * `palette` (optional) paints that icon; without it the icon renders exactly
4
+ * as before palettes existed.
5
+ */
6
+ export declare function makeDirectiveIconPlaceholder(icon: string, className: string[], palette?: string): {
2
7
  type: "element";
3
8
  children: never[];
4
9
  properties: {
10
+ dataPmdIconRef: string;
11
+ focusable: string;
12
+ dataPmdIconPalette?: string | undefined;
5
13
  ariaHidden: string;
6
14
  className: string[];
7
15
  dataPmdIcon: string;
8
- dataPmdIconRef: string;
9
- focusable: string;
10
16
  };
11
17
  tagName: string;
12
18
  };
@@ -1,5 +1,9 @@
1
1
  import { normalizePayloadMarkdownIconRef } from '../icons/refs.js';
2
- export function makeDirectiveIconPlaceholder(icon, className) {
2
+ /**
3
+ * A placeholder that rehypeResolveIcons replaces with the sanitized SVG.
4
+ * `palette` (optional) paints that icon; without it the icon renders exactly
5
+ * as before palettes existed.
6
+ */ export function makeDirectiveIconPlaceholder(icon, className, palette) {
3
7
  const normalized = normalizePayloadMarkdownIconRef(icon);
4
8
  const iconKey = normalized.icon?.key ?? icon;
5
9
  return {
@@ -9,6 +13,9 @@ export function makeDirectiveIconPlaceholder(icon, className) {
9
13
  ariaHidden: 'true',
10
14
  className,
11
15
  dataPmdIcon: iconKey,
16
+ ...palette ? {
17
+ dataPmdIconPalette: palette
18
+ } : {},
12
19
  dataPmdIconRef: icon,
13
20
  focusable: 'false'
14
21
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/directives/iconPlaceholder.ts"],"sourcesContent":["import { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\n\nexport function makeDirectiveIconPlaceholder(icon: string, className: string[]) {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n const iconKey = normalized.icon?.key ?? icon\n\n return {\n type: 'element' as const,\n children: [],\n properties: {\n ariaHidden: 'true',\n className,\n dataPmdIcon: iconKey,\n dataPmdIconRef: icon,\n focusable: 'false',\n },\n tagName: 'span',\n }\n}\n"],"names":["normalizePayloadMarkdownIconRef","makeDirectiveIconPlaceholder","icon","className","normalized","iconKey","key","type","children","properties","ariaHidden","dataPmdIcon","dataPmdIconRef","focusable","tagName"],"mappings":"AAAA,SAASA,+BAA+B,QAAQ,mBAAkB;AAElE,OAAO,SAASC,6BAA6BC,IAAY,EAAEC,SAAmB;IAC5E,MAAMC,aAAaJ,gCAAgCE;IACnD,MAAMG,UAAUD,WAAWF,IAAI,EAAEI,OAAOJ;IAExC,OAAO;QACLK,MAAM;QACNC,UAAU,EAAE;QACZC,YAAY;YACVC,YAAY;YACZP;YACAQ,aAAaN;YACbO,gBAAgBV;YAChBW,WAAW;QACb;QACAC,SAAS;IACX;AACF"}
1
+ {"version":3,"sources":["../../src/directives/iconPlaceholder.ts"],"sourcesContent":["import { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\n\n/**\n * A placeholder that rehypeResolveIcons replaces with the sanitized SVG.\n * `palette` (optional) paints that icon; without it the icon renders exactly\n * as before palettes existed.\n */\nexport function makeDirectiveIconPlaceholder(icon: string, className: string[], palette?: string) {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n const iconKey = normalized.icon?.key ?? icon\n\n return {\n type: 'element' as const,\n children: [],\n properties: {\n ariaHidden: 'true',\n className,\n dataPmdIcon: iconKey,\n ...(palette ? { dataPmdIconPalette: palette } : {}),\n dataPmdIconRef: icon,\n focusable: 'false',\n },\n tagName: 'span',\n }\n}\n"],"names":["normalizePayloadMarkdownIconRef","makeDirectiveIconPlaceholder","icon","className","palette","normalized","iconKey","key","type","children","properties","ariaHidden","dataPmdIcon","dataPmdIconPalette","dataPmdIconRef","focusable","tagName"],"mappings":"AAAA,SAASA,+BAA+B,QAAQ,mBAAkB;AAElE;;;;CAIC,GACD,OAAO,SAASC,6BAA6BC,IAAY,EAAEC,SAAmB,EAAEC,OAAgB;IAC9F,MAAMC,aAAaL,gCAAgCE;IACnD,MAAMI,UAAUD,WAAWH,IAAI,EAAEK,OAAOL;IAExC,OAAO;QACLM,MAAM;QACNC,UAAU,EAAE;QACZC,YAAY;YACVC,YAAY;YACZR;YACAS,aAAaN;YACb,GAAIF,UAAU;gBAAES,oBAAoBT;YAAQ,IAAI,CAAC,CAAC;YAClDU,gBAAgBZ;YAChBa,WAAW;QACb;QACAC,SAAS;IACX;AACF"}
@@ -0,0 +1,23 @@
1
+ import type { Element } from 'hast';
2
+ import type { ContainerDirective } from 'mdast-util-directive';
3
+ import type { IconEntry } from '../icons/entries.js';
4
+ import type { MarkdownRenderConfig } from '../types/core.js';
5
+ /** Attributes every palette-aware directive accepts. */
6
+ export declare const PALETTE_ATTRIBUTES: readonly ["iconPalette", "palette"];
7
+ /** Render properties carrying `palette` / `iconPalette` from mdast to hast. */
8
+ export declare function getPaletteRenderProperties(node: ContainerDirective): {
9
+ dataIconPalette: string | undefined;
10
+ dataPalette: string | undefined;
11
+ };
12
+ /**
13
+ * The palette an icon of this directive is painted with: its own entry, then
14
+ * the directive's `iconPalette`, then the directive's `palette`.
15
+ */
16
+ export declare function resolveIconPaletteName(node: Element, entry?: IconEntry): string | undefined;
17
+ /**
18
+ * Scopes the directive's palette to it: the palette colours become the public
19
+ * `--pmd-*` tokens (or button tokens) on the directive element, which the
20
+ * default themes read first. Unknown palettes were reported during validation
21
+ * and leave the directive unchanged.
22
+ */
23
+ export declare function applyDirectivePalette(node: Element, config: MarkdownRenderConfig, kind?: 'button' | 'surface'): void;
@@ -0,0 +1,40 @@
1
+ import { buttonPaletteStyle, directivePaletteStyle, getPaletteRegistry } from '../palettes/index.js';
2
+ /** Attributes every palette-aware directive accepts. */ export const PALETTE_ATTRIBUTES = [
3
+ 'iconPalette',
4
+ 'palette'
5
+ ];
6
+ function getAttribute(node, name) {
7
+ const value = node.attributes?.[name];
8
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
9
+ }
10
+ /** Render properties carrying `palette` / `iconPalette` from mdast to hast. */ export function getPaletteRenderProperties(node) {
11
+ return {
12
+ dataIconPalette: getAttribute(node, 'iconPalette'),
13
+ dataPalette: getAttribute(node, 'palette')
14
+ };
15
+ }
16
+ function readProperty(node, name) {
17
+ const value = node.properties[name];
18
+ return typeof value === 'string' && value ? value : undefined;
19
+ }
20
+ /**
21
+ * The palette an icon of this directive is painted with: its own entry, then
22
+ * the directive's `iconPalette`, then the directive's `palette`.
23
+ */ export function resolveIconPaletteName(node, entry) {
24
+ return entry?.palette ?? readProperty(node, 'dataIconPalette') ?? readProperty(node, 'dataPalette');
25
+ }
26
+ /**
27
+ * Scopes the directive's palette to it: the palette colours become the public
28
+ * `--pmd-*` tokens (or button tokens) on the directive element, which the
29
+ * default themes read first. Unknown palettes were reported during validation
30
+ * and leave the directive unchanged.
31
+ */ export function applyDirectivePalette(node, config, kind = 'surface') {
32
+ const name = readProperty(node, 'dataPalette');
33
+ if (!name) return;
34
+ const palette = getPaletteRegistry(config.palettes).get(name);
35
+ if (!palette) return;
36
+ const style = kind === 'button' ? buttonPaletteStyle(palette) : directivePaletteStyle(palette);
37
+ if (style) node.properties.style = style;
38
+ }
39
+
40
+ //# sourceMappingURL=palette.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/directives/palette.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { IconEntry } from '../icons/entries.js'\nimport type { MarkdownRenderConfig } from '../types/core.js'\n\nimport { buttonPaletteStyle, directivePaletteStyle, getPaletteRegistry } from '../palettes/index.js'\n\n/** Attributes every palette-aware directive accepts. */\nexport const PALETTE_ATTRIBUTES = ['iconPalette', 'palette'] as const\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\n/** Render properties carrying `palette` / `iconPalette` from mdast to hast. */\nexport function getPaletteRenderProperties(node: ContainerDirective) {\n return {\n dataIconPalette: getAttribute(node, 'iconPalette'),\n dataPalette: getAttribute(node, 'palette'),\n }\n}\n\nfunction readProperty(node: Element, name: 'dataIconPalette' | 'dataPalette'): string | undefined {\n const value = node.properties[name]\n\n return typeof value === 'string' && value ? value : undefined\n}\n\n/**\n * The palette an icon of this directive is painted with: its own entry, then\n * the directive's `iconPalette`, then the directive's `palette`.\n */\nexport function resolveIconPaletteName(node: Element, entry?: IconEntry): string | undefined {\n return entry?.palette ?? readProperty(node, 'dataIconPalette') ?? readProperty(node, 'dataPalette')\n}\n\n/**\n * Scopes the directive's palette to it: the palette colours become the public\n * `--pmd-*` tokens (or button tokens) on the directive element, which the\n * default themes read first. Unknown palettes were reported during validation\n * and leave the directive unchanged.\n */\nexport function applyDirectivePalette(\n node: Element,\n config: MarkdownRenderConfig,\n kind: 'button' | 'surface' = 'surface',\n): void {\n const name = readProperty(node, 'dataPalette')\n if (!name) return\n\n const palette = getPaletteRegistry(config.palettes).get(name)\n if (!palette) return\n\n const style = kind === 'button' ? buttonPaletteStyle(palette) : directivePaletteStyle(palette)\n if (style) node.properties.style = style\n}\n"],"names":["buttonPaletteStyle","directivePaletteStyle","getPaletteRegistry","PALETTE_ATTRIBUTES","getAttribute","node","name","value","attributes","trim","undefined","getPaletteRenderProperties","dataIconPalette","dataPalette","readProperty","properties","resolveIconPaletteName","entry","palette","applyDirectivePalette","config","kind","palettes","get","style"],"mappings":"AAMA,SAASA,kBAAkB,EAAEC,qBAAqB,EAAEC,kBAAkB,QAAQ,uBAAsB;AAEpG,sDAAsD,GACtD,OAAO,MAAMC,qBAAqB;IAAC;IAAe;CAAU,CAAS;AAErE,SAASC,aAAaC,IAAwB,EAAEC,IAAY;IAC1D,MAAMC,QAAQF,KAAKG,UAAU,EAAE,CAACF,KAAK;IAErC,OAAO,OAAOC,UAAU,YAAYA,MAAME,IAAI,KAAKF,MAAME,IAAI,KAAKC;AACpE;AAEA,6EAA6E,GAC7E,OAAO,SAASC,2BAA2BN,IAAwB;IACjE,OAAO;QACLO,iBAAiBR,aAAaC,MAAM;QACpCQ,aAAaT,aAAaC,MAAM;IAClC;AACF;AAEA,SAASS,aAAaT,IAAa,EAAEC,IAAuC;IAC1E,MAAMC,QAAQF,KAAKU,UAAU,CAACT,KAAK;IAEnC,OAAO,OAAOC,UAAU,YAAYA,QAAQA,QAAQG;AACtD;AAEA;;;CAGC,GACD,OAAO,SAASM,uBAAuBX,IAAa,EAAEY,KAAiB;IACrE,OAAOA,OAAOC,WAAWJ,aAAaT,MAAM,sBAAsBS,aAAaT,MAAM;AACvF;AAEA;;;;;CAKC,GACD,OAAO,SAASc,sBACdd,IAAa,EACbe,MAA4B,EAC5BC,OAA6B,SAAS;IAEtC,MAAMf,OAAOQ,aAAaT,MAAM;IAChC,IAAI,CAACC,MAAM;IAEX,MAAMY,UAAUhB,mBAAmBkB,OAAOE,QAAQ,EAAEC,GAAG,CAACjB;IACxD,IAAI,CAACY,SAAS;IAEd,MAAMM,QAAQH,SAAS,WAAWrB,mBAAmBkB,WAAWjB,sBAAsBiB;IACtF,IAAIM,OAAOnB,KAAKU,UAAU,CAACS,KAAK,GAAGA;AACrC"}
@@ -75,15 +75,28 @@ function getRequiredStringAttributes(attributes, names) {
75
75
  }
76
76
  return out;
77
77
  }
78
+ // Shields splits a static badge path on single dashes after decoding it, so a
79
+ // literal dash must use its own escape (`--`), not `%2D`.
78
80
  function encodeStaticPathPart(value) {
79
- return encodeURIComponent(value).replace(/-/g, '%2D');
81
+ return encodeURIComponent(value.replace(/-/g, '--'));
82
+ }
83
+ // A `path` is often copied from shields.io already percent-encoded
84
+ // (`coverage-95%25-green`), or written raw (`coverage-95%-green`). Decode a
85
+ // valid escape first so both forms encode once instead of `95%2525`.
86
+ function decodePathPart(part) {
87
+ try {
88
+ return decodeURIComponent(part);
89
+ } catch {
90
+ return part;
91
+ }
80
92
  }
81
93
  function normalizePathValue(value) {
82
94
  const trimmed = value.trim();
83
95
  if (!trimmed) return undefined;
84
96
  if (hasUnsafePathCharacter(trimmed)) return undefined;
85
- const parts = trimmed.split('/');
86
- if (parts.some((part)=>part === '.' || part === '..')) return undefined;
97
+ // Safety checks run on the decoded segments, so `%2E%2E` and `%0A` are caught too.
98
+ const parts = trimmed.split('/').map(decodePathPart);
99
+ if (parts.some((part)=>part === '.' || part === '..' || hasUnsafePathCharacter(part))) return undefined;
87
100
  return parts.map((part)=>encodeURIComponent(part)).join('/');
88
101
  }
89
102
  function hasUnsafePathCharacter(value) {