payload-markdown 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/README.md +16 -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.js +4 -0
  29. package/dist/components/MarkdownRenderer/Component.js.map +1 -1
  30. package/dist/core/plugins/rehypeResolveIcons.js +10 -1
  31. package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
  32. package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
  33. package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
  34. package/dist/core/plugins/remarkDirectiveLines.js +29 -18
  35. package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
  36. package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
  37. package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
  38. package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
  39. package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
  40. package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
  41. package/dist/core/plugins/remarkValidatePalettes.js +51 -0
  42. package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
  43. package/dist/core/renderMarkdown.js +4 -221
  44. package/dist/core/renderMarkdown.js.map +1 -1
  45. package/dist/core/sanitizeSchema.d.ts +11 -0
  46. package/dist/core/sanitizeSchema.js +176 -0
  47. package/dist/core/sanitizeSchema.js.map +1 -0
  48. package/dist/directive-spec.json +60 -0
  49. package/dist/directives/definitions/badge.d.ts +5 -2
  50. package/dist/directives/definitions/badge.js +138 -10
  51. package/dist/directives/definitions/badge.js.map +1 -1
  52. package/dist/directives/definitions/badges.d.ts +1 -2
  53. package/dist/directives/definitions/badges.js +12 -3
  54. package/dist/directives/definitions/badges.js.map +1 -1
  55. package/dist/directives/definitions/button.d.ts +7 -3
  56. package/dist/directives/definitions/button.js +211 -14
  57. package/dist/directives/definitions/button.js.map +1 -1
  58. package/dist/directives/definitions/buttons.d.ts +1 -2
  59. package/dist/directives/definitions/buttons.js +12 -3
  60. package/dist/directives/definitions/buttons.js.map +1 -1
  61. package/dist/directives/definitions/callout.d.ts +1 -2
  62. package/dist/directives/definitions/callout.js +46 -5
  63. package/dist/directives/definitions/callout.js.map +1 -1
  64. package/dist/directives/definitions/card.d.ts +6 -4
  65. package/dist/directives/definitions/card.js +64 -11
  66. package/dist/directives/definitions/card.js.map +1 -1
  67. package/dist/directives/definitions/cards.d.ts +1 -2
  68. package/dist/directives/definitions/cards.js +49 -4
  69. package/dist/directives/definitions/cards.js.map +1 -1
  70. package/dist/directives/definitions/cell.d.ts +2 -2
  71. package/dist/directives/definitions/cell.js +9 -3
  72. package/dist/directives/definitions/cell.js.map +1 -1
  73. package/dist/directives/definitions/columns.d.ts +3 -4
  74. package/dist/directives/definitions/columns.js +17 -3
  75. package/dist/directives/definitions/columns.js.map +1 -1
  76. package/dist/directives/definitions/details.d.ts +1 -2
  77. package/dist/directives/definitions/details.js +28 -3
  78. package/dist/directives/definitions/details.js.map +1 -1
  79. package/dist/directives/definitions/section.d.ts +1 -2
  80. package/dist/directives/definitions/section.js +26 -3
  81. package/dist/directives/definitions/section.js.map +1 -1
  82. package/dist/directives/definitions/steps.d.ts +1 -2
  83. package/dist/directives/definitions/steps.js +26 -3
  84. package/dist/directives/definitions/steps.js.map +1 -1
  85. package/dist/directives/definitions/tab.d.ts +8 -2
  86. package/dist/directives/definitions/tab.js +45 -3
  87. package/dist/directives/definitions/tab.js.map +1 -1
  88. package/dist/directives/definitions/tabs.d.ts +1 -1
  89. package/dist/directives/definitions/tabs.js +44 -3
  90. package/dist/directives/definitions/tabs.js.map +1 -1
  91. package/dist/directives/definitions/toc.d.ts +1 -2
  92. package/dist/directives/definitions/toc.js +33 -5
  93. package/dist/directives/definitions/toc.js.map +1 -1
  94. package/dist/directives/diagnostics.d.ts +2 -10
  95. package/dist/directives/diagnostics.js +27 -141
  96. package/dist/directives/diagnostics.js.map +1 -1
  97. package/dist/directives/iconPlaceholder.d.ts +9 -3
  98. package/dist/directives/iconPlaceholder.js +8 -1
  99. package/dist/directives/iconPlaceholder.js.map +1 -1
  100. package/dist/directives/lint.d.ts +11 -0
  101. package/dist/directives/lint.js +33 -0
  102. package/dist/directives/lint.js.map +1 -0
  103. package/dist/directives/palette.d.ts +23 -0
  104. package/dist/directives/palette.js +40 -0
  105. package/dist/directives/palette.js.map +1 -0
  106. package/dist/directives/registry.d.ts +23 -5
  107. package/dist/directives/registry.js +52 -40
  108. package/dist/directives/registry.js.map +1 -1
  109. package/dist/directives/spec.d.ts +6 -2
  110. package/dist/directives/spec.js +29 -50
  111. package/dist/directives/spec.js.map +1 -1
  112. package/dist/directives/themeDiagnostics.d.ts +8 -0
  113. package/dist/directives/themeDiagnostics.js +21 -0
  114. package/dist/directives/themeDiagnostics.js.map +1 -0
  115. package/dist/directives/types.d.ts +157 -14
  116. package/dist/directives/types.js +6 -1
  117. package/dist/directives/types.js.map +1 -1
  118. package/dist/editor/directiveConfig.d.ts +15 -1
  119. package/dist/editor/directiveConfig.js +21 -1
  120. package/dist/editor/directiveConfig.js.map +1 -1
  121. package/dist/editor/directives/completions.d.ts +4 -2
  122. package/dist/editor/directives/completions.js +33 -7
  123. package/dist/editor/directives/completions.js.map +1 -1
  124. package/dist/editor/directives/diagnostics.d.ts +2 -2
  125. package/dist/editor/directives/diagnostics.js +10 -3
  126. package/dist/editor/directives/diagnostics.js.map +1 -1
  127. package/dist/editor/themes/payload.js +2 -1
  128. package/dist/editor/themes/payload.js.map +1 -1
  129. package/dist/exports/client.d.ts +4 -1
  130. package/dist/exports/client.js +5 -2
  131. package/dist/exports/client.js.map +1 -1
  132. package/dist/field/MarkdownField/Component.js +54 -3
  133. package/dist/field/MarkdownField/Component.js.map +1 -1
  134. package/dist/icons/entries.d.ts +22 -0
  135. package/dist/icons/entries.js +50 -0
  136. package/dist/icons/entries.js.map +1 -0
  137. package/dist/icons/resolve.d.ts +2 -1
  138. package/dist/icons/resolve.js +2 -2
  139. package/dist/icons/resolve.js.map +1 -1
  140. package/dist/icons/sanitizeSvg.d.ts +12 -2
  141. package/dist/icons/sanitizeSvg.js +104 -3
  142. package/dist/icons/sanitizeSvg.js.map +1 -1
  143. package/dist/index.d.ts +11 -4
  144. package/dist/index.js +34 -3
  145. package/dist/index.js.map +1 -1
  146. package/dist/mcp/index.d.ts +2 -2
  147. package/dist/mcp/index.js +65 -4
  148. package/dist/mcp/index.js.map +1 -1
  149. package/dist/palettes/colors.d.ts +21 -0
  150. package/dist/palettes/colors.js +43 -0
  151. package/dist/palettes/colors.js.map +1 -0
  152. package/dist/palettes/contrast.d.ts +7 -0
  153. package/dist/palettes/contrast.js +63 -0
  154. package/dist/palettes/contrast.js.map +1 -0
  155. package/dist/palettes/defaults.d.ts +8 -0
  156. package/dist/palettes/defaults.js +275 -0
  157. package/dist/palettes/defaults.js.map +1 -0
  158. package/dist/palettes/diagnostics.d.ts +10 -0
  159. package/dist/palettes/diagnostics.js +38 -0
  160. package/dist/palettes/diagnostics.js.map +1 -0
  161. package/dist/palettes/index.d.ts +61 -0
  162. package/dist/palettes/index.js +246 -0
  163. package/dist/palettes/index.js.map +1 -0
  164. package/dist/render/renderMarkdown.d.ts +3 -1
  165. package/dist/render/renderMarkdown.js +9 -1
  166. package/dist/render/renderMarkdown.js.map +1 -1
  167. package/dist/runtime/index.d.ts +12 -1
  168. package/dist/runtime/index.js +21 -2
  169. package/dist/runtime/index.js.map +1 -1
  170. package/dist/types/core.d.ts +43 -0
  171. package/dist/types/core.js.map +1 -1
  172. package/dist/types.d.ts +46 -2
  173. package/dist/types.js.map +1 -1
  174. package/dist/version.d.ts +1 -1
  175. package/dist/version.js +1 -1
  176. package/dist/version.js.map +1 -1
  177. package/package.json +1 -1
  178. package/skills/payload-markdown/claude/SKILL.md +1 -0
  179. package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
  180. package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
  181. package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
  182. package/skills/payload-markdown/claude/skill.json +2 -2
  183. package/skills/payload-markdown/codex/SKILL.md +1 -0
  184. package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
  185. package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
  186. package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
  187. package/skills/payload-markdown/codex/skill.json +2 -2
  188. package/dist/core/plugins/directiveBadge.d.ts +0 -6
  189. package/dist/core/plugins/directiveBadge.js +0 -94
  190. package/dist/core/plugins/directiveBadge.js.map +0 -1
  191. package/dist/core/plugins/directiveButton.d.ts +0 -6
  192. package/dist/core/plugins/directiveButton.js +0 -115
  193. package/dist/core/plugins/directiveButton.js.map +0 -1
  194. package/dist/directives/buttonSyntax.d.ts +0 -7
  195. package/dist/directives/buttonSyntax.js +0 -6
  196. package/dist/directives/buttonSyntax.js.map +0 -1
@@ -1,5 +1,7 @@
1
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';
4
+ import { defineDirective } from '../types.js';
3
5
  import { getTabLabel as getTabDirectiveLabel, getTabRawValue, getTabValue, resolveTabsDefault, slugTabValue, toTabSlug } from './tab.js';
4
6
  function isContainerDirective(node) {
5
7
  return Boolean(node && typeof node === 'object' && 'type' in node && node.type === 'containerDirective');
@@ -132,10 +134,11 @@ function getTabsDefaultCandidates(node) {
132
134
  function getDirectTabDirectives(node) {
133
135
  return node.children.filter((child)=>isContainerDirective(child) && child.name === 'tab');
134
136
  }
135
- export const tabsDirective = {
137
+ export const tabsDirective = defineDirective({
136
138
  name: 'tabs',
137
139
  allowedAttributes: [
138
140
  'default',
141
+ 'palette',
139
142
  'tabTheme',
140
143
  'theme'
141
144
  ],
@@ -146,6 +149,7 @@ export const tabsDirective = {
146
149
  const tabTheme = typeof node.properties.dataTabTheme === 'string' ? node.properties.dataTabTheme : undefined;
147
150
  node.properties.dataTheme = theme.name;
148
151
  node.properties.dataDefault = activeTab?.value;
152
+ applyDirectivePalette(node, config);
149
153
  node.properties.className = mergeClassNames(theme.hookClassName, theme.modifierClassName, theme.classes);
150
154
  if (!activeTab) {
151
155
  node.children = [
@@ -172,6 +176,12 @@ export const tabsDirective = {
172
176
  ...tabs.map((tab)=>makeTabPanel(tab, tab.value === activeTab.value, config, mergeClassNames, tabTheme))
173
177
  ];
174
178
  },
179
+ attributeTypes: {
180
+ palette: {
181
+ type: 'palette'
182
+ }
183
+ },
184
+ container: {},
175
185
  description: 'Accessible tabbed content block with server-rendered panels.',
176
186
  editor: {
177
187
  detail: 'Tabs directive',
@@ -181,6 +191,7 @@ export const tabsDirective = {
181
191
  getMdastRenderProperties (node) {
182
192
  const requestedDefault = typeof node.attributes?.default === 'string' ? node.attributes.default : undefined;
183
193
  return {
194
+ ...getPaletteRenderProperties(node),
184
195
  dataDefault: requestedDefault ? resolveTabsDefault(requestedDefault, getTabsDefaultCandidates(node)) ?? requestedDefault : undefined,
185
196
  dataDirective: 'tabs',
186
197
  dataTabTheme: typeof node.attributes?.tabTheme === 'string' ? node.attributes.tabTheme : undefined,
@@ -188,8 +199,38 @@ export const tabsDirective = {
188
199
  };
189
200
  },
190
201
  kind: 'tabs',
191
- openMarker: ':::tabs',
202
+ lint: {
203
+ // Mirrors validateMdast below; the tab hooks fill the state.
204
+ close (frame) {
205
+ const tabs = frame.state ?? {};
206
+ const diagnostics = [];
207
+ const tabValues = tabs.tabValues ?? new Map();
208
+ if (!tabs.tabCount) diagnostics.push('Directive "tabs" has no child "tab" directives.');
209
+ for (const [value, count] of tabValues)if (count > 1) diagnostics.push(`Duplicate tab value "${value}" in "tabs".`);
210
+ if (tabs.defaultValue && !resolveTabsDefault(tabs.defaultValue, tabs.tabCandidates ?? [])) diagnostics.push(`Invalid tabs default "${tabs.defaultValue}". Falling back to the first tab.`);
211
+ return diagnostics;
212
+ },
213
+ open ({ attributes, frame }) {
214
+ const state = {
215
+ defaultValue: typeof attributes.default === 'string' ? attributes.default : undefined,
216
+ tabCount: 0,
217
+ tabValues: new Map()
218
+ };
219
+ frame.state = state;
220
+ return [];
221
+ }
222
+ },
192
223
  public: true,
224
+ sanitize: {
225
+ section: [
226
+ 'dataDefault',
227
+ 'dataDirective',
228
+ 'dataIconPalette',
229
+ 'dataPalette',
230
+ 'dataTabTheme',
231
+ 'dataTheme'
232
+ ]
233
+ },
193
234
  supportsAttributes: true,
194
235
  tagName: 'section',
195
236
  themeAttributes: {
@@ -215,6 +256,6 @@ export const tabsDirective = {
215
256
  if (typeof node.attributes?.default === 'string' && !resolveTabsDefault(node.attributes.default, getTabsDefaultCandidates(node))) warnings.push(`Invalid tabs default "${node.attributes.default}". Falling back to the first tab.`);
216
257
  return warnings;
217
258
  }
218
- };
259
+ });
219
260
 
220
261
  //# sourceMappingURL=tabs.js.map
@@ -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_BODY_CLASS, 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 // 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', '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 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 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","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,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,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V1B,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'\nimport type { TabsLintState } from './tab.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 { defineDirective } from '../types.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 = defineDirective({\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 attributeTypes: {\n palette: { type: 'palette' },\n },\n container: {},\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 lint: {\n // Mirrors validateMdast below; the tab hooks fill the state.\n close(frame) {\n const tabs = (frame.state ?? {}) as TabsLintState\n const diagnostics: string[] = []\n const tabValues = tabs.tabValues ?? new Map<string, number>()\n\n if (!tabs.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 (tabs.defaultValue && !resolveTabsDefault(tabs.defaultValue, tabs.tabCandidates ?? []))\n diagnostics.push(`Invalid tabs default \"${tabs.defaultValue}\". Falling back to the first tab.`)\n\n return diagnostics\n },\n open({ attributes, frame }) {\n const state: TabsLintState = {\n defaultValue: typeof attributes.default === 'string' ? attributes.default : undefined,\n tabCount: 0,\n tabValues: new Map<string, number>(),\n }\n\n frame.state = state\n return []\n },\n },\n public: true,\n sanitize: {\n section: ['dataDefault', 'dataDirective', 'dataIconPalette', 'dataPalette', 'dataTabTheme', 'dataTheme'],\n },\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","defineDirective","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","attributeTypes","palette","container","description","editor","detail","snippet","getMdastRenderProperties","default","dataDirective","kind","lint","close","frame","state","diagnostics","tabValues","tabCount","push","defaultValue","tabCandidates","open","public","sanitize","section","supportsAttributes","themeAttributes","transformMdast","forEach","data","vlTabIndex","validateMdast","warnings","values","length"],"mappings":"AAMA,SAASA,oBAAoB,EAAEC,+BAA+B,QAAQ,mCAAkC;AACxG,SAASC,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,eAAe,QAAQ,cAAa;AAC7C,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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ainerDirective } from 'mdast-util-directive';
2
- import type { LayoutDirectiveDefinition } from '../types.js';
3
2
  export declare const DEFAULT_TOC_DEPTH = 3;
4
3
  export declare const DEFAULT_TOC_TITLE = "On this page";
5
4
  export declare function resolveTocDepth(node: ContainerDirective): number;
6
5
  export declare function resolveTocTitle(node: ContainerDirective): string;
7
- export declare const tocDirective: LayoutDirectiveDefinition;
6
+ export declare const tocDirective: import("../types.js").LayoutDirectiveDefinition<"toc", "toc">;
@@ -1,7 +1,9 @@
1
1
  import { getDirectiveLabelOrAttribute } from '../labels.js';
2
2
  import { resolveDirectiveTheme } from '../themes.js';
3
+ import { defineDirective } from '../types.js';
3
4
  export const DEFAULT_TOC_DEPTH = 3;
4
5
  export const DEFAULT_TOC_TITLE = 'On this page';
6
+ const TOC_CONTENT_DIAGNOSTIC = 'Directive "toc" contains authored content; it is rendered after the generated table of contents. Close ":::toc" with ":::" on the next line.';
5
7
  export function resolveTocDepth(node) {
6
8
  const value = node.attributes?.depth;
7
9
  const parsed = typeof value === 'string' ? Number.parseInt(value, 10) : DEFAULT_TOC_DEPTH;
@@ -11,7 +13,7 @@ export function resolveTocTitle(node) {
11
13
  const title = getDirectiveLabelOrAttribute(node, 'title');
12
14
  return title ?? DEFAULT_TOC_TITLE;
13
15
  }
14
- export const tocDirective = {
16
+ export const tocDirective = defineDirective({
15
17
  name: 'toc',
16
18
  allowedAttributes: [
17
19
  'depth',
@@ -22,7 +24,17 @@ export const tocDirective = {
22
24
  const theme = resolveDirectiveTheme('toc', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
23
25
  node.properties.dataTheme = theme.name;
24
26
  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]:m-0 [&_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);
27
+ '[&>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);
28
+ },
29
+ attributeTypes: {
30
+ depth: {
31
+ type: 'number',
32
+ max: 6,
33
+ min: 1
34
+ }
35
+ },
36
+ container: {
37
+ labelAttribute: 'title'
26
38
  },
27
39
  defaultAttributes: {
28
40
  depth: String(DEFAULT_TOC_DEPTH),
@@ -44,8 +56,24 @@ export const tocDirective = {
44
56
  };
45
57
  },
46
58
  kind: 'toc',
47
- openMarker: ':::toc',
59
+ lint: {
60
+ close: (frame)=>frame.hasContent ? [
61
+ TOC_CONTENT_DIAGNOSTIC
62
+ ] : []
63
+ },
48
64
  public: true,
65
+ sanitize: {
66
+ // The generated list (remarkHeadingAnchorsAndToc) indents entries by level.
67
+ li: [
68
+ 'dataTocLevel'
69
+ ],
70
+ nav: [
71
+ 'ariaLabel',
72
+ 'dataDirective',
73
+ 'dataTheme',
74
+ 'dataTitle'
75
+ ]
76
+ },
49
77
  supportsAttributes: true,
50
78
  tagName: 'nav',
51
79
  themeAttributes: {
@@ -58,9 +86,9 @@ export const tocDirective = {
58
86
  },
59
87
  validateMdast (node) {
60
88
  return node.children.length > 0 ? [
61
- 'Directive "toc" contains authored content; it is rendered after the generated table of contents. Close ":::toc" with ":::" on the next line.'
89
+ TOC_CONTENT_DIAGNOSTIC
62
90
  ] : [];
63
91
  }
64
- };
92
+ });
65
93
 
66
94
  //# sourceMappingURL=toc.js.map
@@ -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 // 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]:m-0 [&_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,yDACA,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"}
1
+ {"version":3,"sources":["../../../src/directives/definitions/toc.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { defineDirective } from '../types.js'\n\nexport const DEFAULT_TOC_DEPTH = 3\nexport const DEFAULT_TOC_TITLE = 'On this page'\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\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 = defineDirective({\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 attributeTypes: {\n depth: { type: 'number', max: 6, min: 1 },\n },\n container: {\n labelAttribute: 'title',\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 lint: {\n close: (frame) => (frame.hasContent ? [TOC_CONTENT_DIAGNOSTIC] : []),\n },\n public: true,\n sanitize: {\n // The generated list (remarkHeadingAnchorsAndToc) indents entries by level.\n li: ['dataTocLevel'],\n nav: ['ariaLabel', 'dataDirective', 'dataTheme', 'dataTitle'],\n },\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 ? [TOC_CONTENT_DIAGNOSTIC] : []\n },\n})\n"],"names":["getDirectiveLabelOrAttribute","resolveDirectiveTheme","defineDirective","DEFAULT_TOC_DEPTH","DEFAULT_TOC_TITLE","TOC_CONTENT_DIAGNOSTIC","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","attributeTypes","type","max","min","container","labelAttribute","defaultAttributes","String","description","editor","detail","label","snippet","getMdastRenderProperties","ariaLabel","dataDirective","dataTitle","kind","lint","close","frame","hasContent","public","sanitize","li","nav","supportsAttributes","tagName","themeAttributes","validateAttributes","warnings","push","validateMdast","children","length"],"mappings":"AAEA,SAASA,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,eAAe,QAAQ,cAAa;AAE7C,OAAO,MAAMC,oBAAoB,EAAC;AAClC,OAAO,MAAMC,oBAAoB,eAAc;AAE/C,MAAMC,yBACJ;AAEF,OAAO,SAASC,gBAAgBC,IAAwB;IACtD,MAAMC,QAAQD,KAAKE,UAAU,EAAEC;IAC/B,MAAMC,SAAS,OAAOH,UAAU,WAAWI,OAAOC,QAAQ,CAACL,OAAO,MAAML;IAExE,OAAOS,OAAOE,SAAS,CAACH,WAAWA,UAAU,KAAKA,UAAU,IAAIA,SAASR;AAC3E;AAEA,OAAO,SAASY,gBAAgBR,IAAwB;IACtD,MAAMS,QAAQhB,6BAA6BO,MAAM;IAEjD,OAAOS,SAASZ;AAClB;AAEA,OAAO,MAAMa,eAAef,gBAAgB;IAC1CgB,MAAM;IACNC,mBAAmB;QAAC;QAAS;QAAS;KAAQ;IAC9CC,WAAUb,IAAI,EAAEc,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMC,QAAQtB,sBACZ,OACA,OAAOM,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,gBAAgB;QACdtB,OAAO;YAAEuB,MAAM;YAAUC,KAAK;YAAGC,K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- import type { MarkdownDirectiveThemes } from '../types/core.js';
1
+ import type { LintMarkdownDirectivesOptions } from './types.js';
2
+ export type { LintMarkdownDirectivesOptions } from './types.js';
2
3
  export type DirectiveDiagnostic = {
3
4
  from: number;
4
5
  line: number;
@@ -6,15 +7,6 @@ export type DirectiveDiagnostic = {
6
7
  severity: 'warning';
7
8
  to: number;
8
9
  };
9
- export type LintMarkdownDirectivesOptions = {
10
- /**
11
- * Configured icon pack aliases. When provided, icon refs to other packs are
12
- * reported exactly like the renderer does ("Unknown icon pack").
13
- */
14
- iconPacks?: readonly string[];
15
- /** Configured directive themes (names are what matters). */
16
- themes?: MarkdownDirectiveThemes;
17
- };
18
10
  /**
19
11
  * Editor-side directive diagnostics. The document is parsed with the same
20
12
  * remark/GFM front end and the same directive line scanner as the renderer,
@@ -1,21 +1,9 @@
1
- import { normalizePayloadMarkdownIconRef } from '../icons/refs.js';
2
- import { parseButtonDirectiveLine } from './buttonSyntax.js';
3
- import { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js';
4
- import { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js';
1
+ import { getLeafDirectiveName, getLeafDirectiveProblem } from './leafSyntax.js';
5
2
  import { createSourceIndex, findNestedDirectiveMarkers, getNestedDirectiveMarkerDiagnostic, scanDirectiveLineAt, splitParagraphIntoLines } from './lineScanner.js';
3
+ import { getIconLintDiagnostics, getPaletteLintDiagnostics } from './lint.js';
6
4
  import { layoutDirectiveRegistry } from './registry.js';
7
- import { resolveShieldsBadge } from './shields.js';
8
5
  import { parseDirectiveSourceTree } from './sourceTree.js';
9
- import { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js';
10
- 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}".`
17
- ];
18
- }
6
+ import { getUnknownThemeDiagnostics } from './themeDiagnostics.js';
19
7
  function findNearestFrameIndex(stack, predicate) {
20
8
  for(let index = stack.length - 1; index >= 0; --index){
21
9
  const frame = stack[index];
@@ -23,41 +11,8 @@ function findNearestFrameIndex(stack, predicate) {
23
11
  }
24
12
  return -1;
25
13
  }
26
- function getTabValue(attributes, index, label) {
27
- return slugTabValue(getTabRawValue(attributes, label) ?? `tab-${index + 1}`, index);
28
- }
29
- const TOC_CONTENT_DIAGNOSTIC = 'Directive "toc" contains authored content; it is rendered after the generated table of contents. Close ":::toc" with ":::" on the next line.';
30
- function finalizeFrame(frame) {
31
- if (frame.name === 'toc') return frame.hasContent ? [
32
- TOC_CONTENT_DIAGNOSTIC
33
- ] : [];
34
- return finalizeTabsFrame(frame);
35
- }
36
- function finalizeTabsFrame(frame) {
37
- if (frame.name !== 'tabs') return [];
38
- const diagnostics = [];
39
- const tabValues = frame.tabValues ?? new Map();
40
- if (!frame.tabCount) diagnostics.push('Directive "tabs" has no child "tab" directives.');
41
- for (const [value, count] of tabValues)if (count > 1) diagnostics.push(`Duplicate tab value "${value}" in "tabs".`);
42
- if (frame.defaultValue && !resolveTabsDefault(frame.defaultValue, frame.tabCandidates ?? [])) diagnostics.push(`Invalid tabs default "${frame.defaultValue}". Falling back to the first tab.`);
43
- return diagnostics;
44
- }
45
- function findNearestTabsFrame(stack) {
46
- for(let index = stack.length - 1; index >= 0; --index){
47
- const frame = stack[index];
48
- if (frame.name === 'tabs') return frame;
49
- }
50
- return undefined;
51
- }
52
- function findNearestCardsFrame(stack) {
53
- for(let index = stack.length - 1; index >= 0; --index){
54
- const frame = stack[index];
55
- if (frame.name === 'cards') return frame;
56
- }
57
- return undefined;
58
- }
59
- function hasAttribute(attributes, name) {
60
- return Object.prototype.hasOwnProperty.call(attributes ?? {}, name);
14
+ /** A directive's own checks when its frame closes (definition `lint.close`). */ function finalizeFrame(frame) {
15
+ return layoutDirectiveRegistry.get(frame.name)?.lint?.close?.(frame) ?? [];
61
16
  }
62
17
  function popFrames(stack, index) {
63
18
  return stack.splice(index).flatMap((frame)=>finalizeFrame(frame));
@@ -80,54 +35,29 @@ function updateOpenStack(state, text, line, from) {
80
35
  if (!token) return diagnostics;
81
36
  if (token.action === 'open') {
82
37
  markTopFrameContent(state);
83
- if (token.name === 'card') {
84
- const cardsFrame = findNearestCardsFrame(stack);
85
- const cardsSectionLink = cardsFrame?.cardsHasHref && (cardsFrame.cardsLinkScope === undefined || cardsFrame.cardsLinkScope === 'section');
86
- if (cardsSectionLink && (hasAttribute(token.attributes, 'href') || hasAttribute(token.attributes, 'linkScope') || hasAttribute(token.attributes, 'newTab'))) diagnostics.push('Directive "cards" with linkScope="section" ignores child "card" link overrides.');
87
- }
88
- if (token.name === 'tab') {
89
- const tabsFrame = findNearestTabsFrame(stack);
90
- if (!tabsFrame) diagnostics.push('Directive "tab" is usually intended inside "tabs".');
91
- else {
92
- const nextIndex = tabsFrame.tabCount ?? 0;
93
- const value = getTabValue(token.attributes, nextIndex, token.label);
94
- tabsFrame.tabCandidates ??= [];
95
- tabsFrame.tabCandidates.push({
96
- label: getTabRawValue({
97
- label: token.attributes?.label ?? ''
98
- }, token.label) ?? `Tab ${nextIndex + 1}`,
99
- raw: getTabRawValue(token.attributes),
100
- value
101
- });
102
- tabsFrame.tabCount = nextIndex + 1;
103
- tabsFrame.tabValues ??= new Map();
104
- tabsFrame.tabValues.set(value, (tabsFrame.tabValues.get(value) ?? 0) + 1);
105
- }
106
- }
107
38
  const isGrid = layoutDirectiveRegistry.isGridName(token.name);
108
- if (isGrid) {
109
- // remarkCompileLayouts closes an open grid inside the nearest section.
110
- const gridIndex = findNearestFrameIndex(stack, (frame)=>layoutDirectiveRegistry.isGridName(frame.name));
111
- const sectionIndex = findNearestFrameIndex(stack, (frame)=>frame.name === 'section');
112
- if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex) diagnostics.push(...popFrames(stack, gridIndex));
113
- }
114
- stack.push({
39
+ const frame = {
115
40
  name: token.name,
116
41
  from,
117
42
  line,
118
43
  ...isGrid ? {
119
44
  parentHeadingDepth: state.currentHeadingDepth ?? 1
120
- } : {},
121
- ...token.name === 'cards' ? {
122
- cardsHasHref: typeof token.attributes?.href === 'string' && isSafeHref(token.attributes.href.trim()),
123
- cardsLinkScope: typeof token.attributes?.linkScope === 'string' ? token.attributes.linkScope : undefined
124
- } : {},
125
- ...token.name === 'tabs' ? {
126
- defaultValue: typeof token.attributes?.default === 'string' ? token.attributes.default : undefined,
127
- tabCount: 0,
128
- tabValues: new Map()
129
45
  } : {}
130
- });
46
+ };
47
+ // The directive's own nesting checks see the stack before it opens.
48
+ diagnostics.push(...layoutDirectiveRegistry.get(token.name)?.lint?.open?.({
49
+ attributes: token.attributes ?? {},
50
+ frame,
51
+ label: token.label,
52
+ stack
53
+ }) ?? []);
54
+ if (isGrid) {
55
+ // remarkCompileLayouts closes an open grid inside the nearest section.
56
+ const gridIndex = findNearestFrameIndex(stack, (open)=>layoutDirectiveRegistry.isGridName(open.name));
57
+ const sectionIndex = findNearestFrameIndex(stack, (open)=>open.name === 'section');
58
+ if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex) diagnostics.push(...popFrames(stack, gridIndex));
59
+ }
60
+ stack.push(frame);
131
61
  return diagnostics;
132
62
  }
133
63
  if (token.action === 'close') {
@@ -153,54 +83,10 @@ function getThemeDiagnostics(text, options) {
153
83
  const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token;
154
84
  if (!token || token.action !== 'open') return [];
155
85
  const definition = layoutDirectiveRegistry.get(token.name);
156
- const diagnostics = [
157
- ...getIconPackDiagnostics(token.attributes?.icon, options)
158
- ];
159
- if (!definition?.themeAttributes) return diagnostics;
160
- for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
161
- if (!groupName) continue;
162
- const value = token.attributes?.[attribute];
163
- if (typeof value !== 'string' || !value.trim()) continue;
164
- if (hasDirectiveTheme(groupName, value, options.themes)) continue;
165
- const label = attribute === 'theme' ? 'theme' : attribute;
166
- diagnostics.push(`Unknown ${label} "${value}" on "${token.name}". Falling back to "${getDirectiveFallbackThemeName(groupName, options.themes)}".`);
167
- }
168
- return diagnostics;
169
- }
170
- function getButtonDiagnostics(text, options) {
171
- const parsed = parseButtonDirectiveLine(text);
172
- if (!parsed) return [];
173
- const definition = layoutDirectiveRegistry.get('button');
174
- const diagnostics = [
175
- ...parsed.warnings,
176
- ...definition?.validateAttributes?.({
177
- name: 'button',
178
- attributes: parsed.attributes
179
- }) ?? []
180
- ];
181
- const icon = parsed.attributes.icon;
182
- if (typeof icon === 'string') {
183
- const normalized = normalizePayloadMarkdownIconRef(icon);
184
- if (normalized.warning) diagnostics.push(normalized.warning);
185
- }
186
- if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string') diagnostics.push('Icon-only button requires an ariaLabel attribute.');
187
- return [
188
- ...diagnostics,
189
- ...getIconPackDiagnostics(icon, options)
190
- ];
191
- }
192
- function getBadgeDiagnostics(text) {
193
- const parsed = parseLeafDirectiveLine(text, 'badge');
194
- if (!parsed) return [];
195
- const definition = layoutDirectiveRegistry.get('badge');
196
- const resolved = resolveShieldsBadge(parsed.attributes);
197
86
  return [
198
- ...parsed.warnings,
199
- ...definition?.validateAttributes?.({
200
- name: 'badge',
201
- attributes: parsed.attributes
202
- }) ?? [],
203
- ...resolved.warnings
87
+ ...getIconLintDiagnostics(token.name, token.attributes?.icon, options),
88
+ ...getPaletteLintDiagnostics(token.name, definition?.allowedAttributes, token.attributes, options),
89
+ ...definition ? getUnknownThemeDiagnostics(definition, token.attributes, options.themes) : []
204
90
  ];
205
91
  }
206
92
  function lintContainerLine(state, scanned, push) {
@@ -217,7 +103,8 @@ function lintLeafLine(state, scanned, push) {
217
103
  const leafName = getLeafDirectiveName(scanned.text);
218
104
  markTopFrameContent(state);
219
105
  if (!leafName) return;
220
- if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {
106
+ const leaf = layoutDirectiveRegistry.get(leafName)?.leaf;
107
+ if (!leaf) {
221
108
  report(`Unknown directive "${leafName}".`);
222
109
  return;
223
110
  }
@@ -226,8 +113,7 @@ function lintLeafLine(state, scanned, push) {
226
113
  report(problem);
227
114
  return;
228
115
  }
229
- const messages = leafName === 'button' ? getButtonDiagnostics(scanned.text, state.options) : getBadgeDiagnostics(scanned.text);
230
- for (const message of messages)report(message);
116
+ for (const message of leaf.lint(scanned.text, state.options))report(message);
231
117
  }
232
118
  function lintParagraph(state, paragraph, index, push) {
233
119
  if (paragraph.type !== 'paragraph') return;