payload-markdown 1.8.1 → 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 (94) hide show
  1. package/dist/core/plugins/remarkCompileLayouts.js.map +1 -1
  2. package/dist/core/plugins/remarkDirectiveLines.d.ts +7 -5
  3. package/dist/core/plugins/remarkDirectiveLines.js +29 -18
  4. package/dist/core/plugins/remarkDirectiveLines.js.map +1 -1
  5. package/dist/core/plugins/remarkLayoutDirectives.js +1 -1
  6. package/dist/core/plugins/remarkLayoutDirectives.js.map +1 -1
  7. package/dist/core/plugins/remarkValidateDirectiveThemes.js +7 -14
  8. package/dist/core/plugins/remarkValidateDirectiveThemes.js.map +1 -1
  9. package/dist/core/renderMarkdown.js +2 -231
  10. package/dist/core/renderMarkdown.js.map +1 -1
  11. package/dist/core/sanitizeSchema.d.ts +11 -0
  12. package/dist/core/sanitizeSchema.js +176 -0
  13. package/dist/core/sanitizeSchema.js.map +1 -0
  14. package/dist/directives/definitions/badge.d.ts +5 -2
  15. package/dist/directives/definitions/badge.js +138 -10
  16. package/dist/directives/definitions/badge.js.map +1 -1
  17. package/dist/directives/definitions/badges.d.ts +1 -2
  18. package/dist/directives/definitions/badges.js +12 -3
  19. package/dist/directives/definitions/badges.js.map +1 -1
  20. package/dist/directives/definitions/button.d.ts +6 -2
  21. package/dist/directives/definitions/button.js +202 -12
  22. package/dist/directives/definitions/button.js.map +1 -1
  23. package/dist/directives/definitions/buttons.d.ts +1 -2
  24. package/dist/directives/definitions/buttons.js +12 -3
  25. package/dist/directives/definitions/buttons.js.map +1 -1
  26. package/dist/directives/definitions/callout.d.ts +1 -2
  27. package/dist/directives/definitions/callout.js +37 -3
  28. package/dist/directives/definitions/callout.js.map +1 -1
  29. package/dist/directives/definitions/card.d.ts +6 -2
  30. package/dist/directives/definitions/card.js +51 -3
  31. package/dist/directives/definitions/card.js.map +1 -1
  32. package/dist/directives/definitions/cards.d.ts +1 -2
  33. package/dist/directives/definitions/cards.js +40 -4
  34. package/dist/directives/definitions/cards.js.map +1 -1
  35. package/dist/directives/definitions/cell.d.ts +2 -2
  36. package/dist/directives/definitions/cell.js +9 -3
  37. package/dist/directives/definitions/cell.js.map +1 -1
  38. package/dist/directives/definitions/columns.d.ts +3 -4
  39. package/dist/directives/definitions/columns.js +17 -3
  40. package/dist/directives/definitions/columns.js.map +1 -1
  41. package/dist/directives/definitions/details.d.ts +1 -2
  42. package/dist/directives/definitions/details.js +24 -3
  43. package/dist/directives/definitions/details.js.map +1 -1
  44. package/dist/directives/definitions/section.d.ts +1 -2
  45. package/dist/directives/definitions/section.js +22 -3
  46. package/dist/directives/definitions/section.js.map +1 -1
  47. package/dist/directives/definitions/steps.d.ts +1 -2
  48. package/dist/directives/definitions/steps.js +22 -3
  49. package/dist/directives/definitions/steps.js.map +1 -1
  50. package/dist/directives/definitions/tab.d.ts +8 -2
  51. package/dist/directives/definitions/tab.js +45 -3
  52. package/dist/directives/definitions/tab.js.map +1 -1
  53. package/dist/directives/definitions/tabs.d.ts +1 -1
  54. package/dist/directives/definitions/tabs.js +40 -3
  55. package/dist/directives/definitions/tabs.js.map +1 -1
  56. package/dist/directives/definitions/toc.d.ts +1 -2
  57. package/dist/directives/definitions/toc.js +32 -4
  58. package/dist/directives/definitions/toc.js.map +1 -1
  59. package/dist/directives/diagnostics.d.ts +2 -15
  60. package/dist/directives/diagnostics.js +27 -157
  61. package/dist/directives/diagnostics.js.map +1 -1
  62. package/dist/directives/lint.d.ts +11 -0
  63. package/dist/directives/lint.js +33 -0
  64. package/dist/directives/lint.js.map +1 -0
  65. package/dist/directives/registry.d.ts +23 -5
  66. package/dist/directives/registry.js +52 -40
  67. package/dist/directives/registry.js.map +1 -1
  68. package/dist/directives/spec.js +25 -51
  69. package/dist/directives/spec.js.map +1 -1
  70. package/dist/directives/themeDiagnostics.d.ts +8 -0
  71. package/dist/directives/themeDiagnostics.js +21 -0
  72. package/dist/directives/themeDiagnostics.js.map +1 -0
  73. package/dist/directives/types.d.ts +157 -14
  74. package/dist/directives/types.js +6 -1
  75. package/dist/directives/types.js.map +1 -1
  76. package/dist/editor/directives/completions.js +11 -4
  77. package/dist/editor/directives/completions.js.map +1 -1
  78. package/dist/editor/themes/payload.js +2 -1
  79. package/dist/editor/themes/payload.js.map +1 -1
  80. package/dist/version.d.ts +1 -1
  81. package/dist/version.js +1 -1
  82. package/dist/version.js.map +1 -1
  83. package/package.json +1 -1
  84. package/skills/payload-markdown/claude/skill.json +1 -1
  85. package/skills/payload-markdown/codex/skill.json +1 -1
  86. package/dist/core/plugins/directiveBadge.d.ts +0 -6
  87. package/dist/core/plugins/directiveBadge.js +0 -94
  88. package/dist/core/plugins/directiveBadge.js.map +0 -1
  89. package/dist/core/plugins/directiveButton.d.ts +0 -6
  90. package/dist/core/plugins/directiveButton.js +0 -132
  91. package/dist/core/plugins/directiveButton.js.map +0 -1
  92. package/dist/directives/buttonSyntax.d.ts +0 -7
  93. package/dist/directives/buttonSyntax.js +0 -6
  94. package/dist/directives/buttonSyntax.js.map +0 -1
@@ -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 { 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,Y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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,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;AAEt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AI;QAChB,MAAM8G,WAAqB,EAAE;QAC7B,MAAMnD,OAAOS,uBAAuBpE;QACpC,MAAM+G,SAAS,IAAIxF;QAEnB,IAAIoC,KAAKqD,MAAM,KAAK,GAAGF,SAASd,IAAI,CAAC;QAErCrC,KAAK+C,OAAO,CAAC,CAACxE,KAAKtB;YACjB,MAAMJ,QAAQb,YAAYuC,KAAKtB;YAC/BmG,OAAO3F,GAAG,CAACZ,OAAO,AAACuG,CAAAA,OAAO5F,GAAG,CAACX,UAAU,CAAA,IAAK;QAC/C;QAEA,KAAK,MAAM,CAACA,OAAOU,MAAM,IAAI6F,OAC3B,IAAI7F,QAAQ,GAAG4F,SAASd,IAAI,CAAC,CAAC,qBAAqB,EAAExF,MAAM,YAAY,CAAC;QAE1E,IACE,OAAOR,KAAKsE,UAAU,EAAEgB,YAAY,YACpC,CAAC1F,mBAAmBI,KAAKsE,UAAU,CAACgB,OAAO,EAAEnB,yBAAyBnE,QAEtE8G,SAASd,IAAI,CAAC,CAAC,sBAAsB,EAAEhG,KAAKsE,UAAU,CAACgB,OAAO,CAAC,iCAAiC,CAAC;QAEnG,OAAOwB;IACT;AACF,GAAE"}
@@ -1,7 +1,6 @@
1
1
  import type { ContainerDirective } 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',
@@ -24,6 +26,16 @@ export const tocDirective = {
24
26
  node.properties.className = mergeClassNames('not-prose', // Title reads as a label; entries indent by heading level.
25
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);
26
28
  },
29
+ attributeTypes: {
30
+ depth: {
31
+ type: 'number',
32
+ max: 6,
33
+ min: 1
34
+ }
35
+ },
36
+ container: {
37
+ labelAttribute: 'title'
38
+ },
27
39
  defaultAttributes: {
28
40
  depth: String(DEFAULT_TOC_DEPTH),
29
41
  title: DEFAULT_TOC_TITLE
@@ -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]: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,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AAM,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;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EAAEtD,WAAWC,KAAK,CAAC,oBAAoB,EAAEP,kBAAkB,EAAE,CAAC;QAElG,OAAO2D;IACT;IACAE,eAAczD,IAAI;QAChB,OAAOA,KAAK0D,QAAQ,CAACC,MAAM,GAAG,IAAI;YAAC7D;SAAuB,GAAG,EAAE;IACjE;AACF,GAAE"}
@@ -1,4 +1,5 @@
1
- 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,20 +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
- /**
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[];
20
- /** Configured directive themes (names are what matters). */
21
- themes?: MarkdownDirectiveThemes;
22
- };
23
10
  /**
24
11
  * Editor-side directive diagnostics. The document is parsed with the same
25
12
  * remark/GFM front end and the same directive line scanner as the renderer,
@@ -1,34 +1,9 @@
1
- import { getExtraIconWarnings, parseIconEntries } from '../icons/entries.js';
2
- import { normalizePayloadMarkdownIconRef } from '../icons/refs.js';
3
- import { collectPaletteNames, formatUnknownPaletteMessage } from '../palettes/diagnostics.js';
4
- import { parseButtonDirectiveLine } from './buttonSyntax.js';
5
- import { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js';
6
- import { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js';
1
+ import { getLeafDirectiveName, getLeafDirectiveProblem } from './leafSyntax.js';
7
2
  import { createSourceIndex, findNestedDirectiveMarkers, getNestedDirectiveMarkerDiagnostic, scanDirectiveLineAt, splitParagraphIntoLines } from './lineScanner.js';
3
+ import { getIconLintDiagnostics, getPaletteLintDiagnostics } from './lint.js';
8
4
  import { layoutDirectiveRegistry } from './registry.js';
9
- import { resolveShieldsBadge } from './shields.js';
10
5
  import { parseDirectiveSourceTree } from './sourceTree.js';
11
- import { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js';
12
- import { isSafeHref } from './urls.js';
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)
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));
31
- }
6
+ import { getUnknownThemeDiagnostics } from './themeDiagnostics.js';
32
7
  function findNearestFrameIndex(stack, predicate) {
33
8
  for(let index = stack.length - 1; index >= 0; --index){
34
9
  const frame = stack[index];
@@ -36,41 +11,8 @@ function findNearestFrameIndex(stack, predicate) {
36
11
  }
37
12
  return -1;
38
13
  }
39
- function getTabValue(attributes, index, label) {
40
- return slugTabValue(getTabRawValue(attributes, label) ?? `tab-${index + 1}`, index);
41
- }
42
- 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.';
43
- function finalizeFrame(frame) {
44
- if (frame.name === 'toc') return frame.hasContent ? [
45
- TOC_CONTENT_DIAGNOSTIC
46
- ] : [];
47
- return finalizeTabsFrame(frame);
48
- }
49
- function finalizeTabsFrame(frame) {
50
- if (frame.name !== 'tabs') return [];
51
- const diagnostics = [];
52
- const tabValues = frame.tabValues ?? new Map();
53
- if (!frame.tabCount) diagnostics.push('Directive "tabs" has no child "tab" directives.');
54
- for (const [value, count] of tabValues)if (count > 1) diagnostics.push(`Duplicate tab value "${value}" in "tabs".`);
55
- if (frame.defaultValue && !resolveTabsDefault(frame.defaultValue, frame.tabCandidates ?? [])) diagnostics.push(`Invalid tabs default "${frame.defaultValue}". Falling back to the first tab.`);
56
- return diagnostics;
57
- }
58
- function findNearestTabsFrame(stack) {
59
- for(let index = stack.length - 1; index >= 0; --index){
60
- const frame = stack[index];
61
- if (frame.name === 'tabs') return frame;
62
- }
63
- return undefined;
64
- }
65
- function findNearestCardsFrame(stack) {
66
- for(let index = stack.length - 1; index >= 0; --index){
67
- const frame = stack[index];
68
- if (frame.name === 'cards') return frame;
69
- }
70
- return undefined;
71
- }
72
- function hasAttribute(attributes, name) {
73
- 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) ?? [];
74
16
  }
75
17
  function popFrames(stack, index) {
76
18
  return stack.splice(index).flatMap((frame)=>finalizeFrame(frame));
@@ -93,54 +35,29 @@ function updateOpenStack(state, text, line, from) {
93
35
  if (!token) return diagnostics;
94
36
  if (token.action === 'open') {
95
37
  markTopFrameContent(state);
96
- if (token.name === 'card') {
97
- const cardsFrame = findNearestCardsFrame(stack);
98
- const cardsSectionLink = cardsFrame?.cardsHasHref && (cardsFrame.cardsLinkScope === undefined || cardsFrame.cardsLinkScope === 'section');
99
- 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.');
100
- }
101
- if (token.name === 'tab') {
102
- const tabsFrame = findNearestTabsFrame(stack);
103
- if (!tabsFrame) diagnostics.push('Directive "tab" is usually intended inside "tabs".');
104
- else {
105
- const nextIndex = tabsFrame.tabCount ?? 0;
106
- const value = getTabValue(token.attributes, nextIndex, token.label);
107
- tabsFrame.tabCandidates ??= [];
108
- tabsFrame.tabCandidates.push({
109
- label: getTabRawValue({
110
- label: token.attributes?.label ?? ''
111
- }, token.label) ?? `Tab ${nextIndex + 1}`,
112
- raw: getTabRawValue(token.attributes),
113
- value
114
- });
115
- tabsFrame.tabCount = nextIndex + 1;
116
- tabsFrame.tabValues ??= new Map();
117
- tabsFrame.tabValues.set(value, (tabsFrame.tabValues.get(value) ?? 0) + 1);
118
- }
119
- }
120
38
  const isGrid = layoutDirectiveRegistry.isGridName(token.name);
121
- if (isGrid) {
122
- // remarkCompileLayouts closes an open grid inside the nearest section.
123
- const gridIndex = findNearestFrameIndex(stack, (frame)=>layoutDirectiveRegistry.isGridName(frame.name));
124
- const sectionIndex = findNearestFrameIndex(stack, (frame)=>frame.name === 'section');
125
- if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex) diagnostics.push(...popFrames(stack, gridIndex));
126
- }
127
- stack.push({
39
+ const frame = {
128
40
  name: token.name,
129
41
  from,
130
42
  line,
131
43
  ...isGrid ? {
132
44
  parentHeadingDepth: state.currentHeadingDepth ?? 1
133
- } : {},
134
- ...token.name === 'cards' ? {
135
- cardsHasHref: typeof token.attributes?.href === 'string' && isSafeHref(token.attributes.href.trim()),
136
- cardsLinkScope: typeof token.attributes?.linkScope === 'string' ? token.attributes.linkScope : undefined
137
- } : {},
138
- ...token.name === 'tabs' ? {
139
- defaultValue: typeof token.attributes?.default === 'string' ? token.attributes.default : undefined,
140
- tabCount: 0,
141
- tabValues: new Map()
142
45
  } : {}
143
- });
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);
144
61
  return diagnostics;
145
62
  }
146
63
  if (token.action === 'close') {
@@ -166,57 +83,10 @@ function getThemeDiagnostics(text, options) {
166
83
  const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token;
167
84
  if (!token || token.action !== 'open') return [];
168
85
  const definition = layoutDirectiveRegistry.get(token.name);
169
- const diagnostics = [
170
- ...getIconDiagnostics(token.name, token.attributes?.icon, options),
171
- ...getPaletteDiagnostics(token.name, token.attributes, options)
172
- ];
173
- if (!definition?.themeAttributes) return diagnostics;
174
- for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
175
- if (!groupName) continue;
176
- const value = token.attributes?.[attribute];
177
- if (typeof value !== 'string' || !value.trim()) continue;
178
- if (hasDirectiveTheme(groupName, value, options.themes)) continue;
179
- const label = attribute === 'theme' ? 'theme' : attribute;
180
- diagnostics.push(`Unknown ${label} "${value}" on "${token.name}". Falling back to "${getDirectiveFallbackThemeName(groupName, options.themes)}".`);
181
- }
182
- return diagnostics;
183
- }
184
- function getButtonDiagnostics(text, options) {
185
- const parsed = parseButtonDirectiveLine(text);
186
- if (!parsed) return [];
187
- const definition = layoutDirectiveRegistry.get('button');
188
- const diagnostics = [
189
- ...parsed.warnings,
190
- ...definition?.validateAttributes?.({
191
- name: 'button',
192
- attributes: parsed.attributes
193
- }) ?? []
194
- ];
195
- const icon = parsed.attributes.icon;
196
- const [iconEntry] = typeof icon === 'string' ? parseIconEntries(icon).entries : [];
197
- if (iconEntry) {
198
- const normalized = normalizePayloadMarkdownIconRef(iconEntry.ref);
199
- if (normalized.warning) diagnostics.push(normalized.warning);
200
- }
201
- if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string') diagnostics.push('Icon-only button requires an ariaLabel attribute.');
202
- return [
203
- ...diagnostics,
204
- ...getIconDiagnostics('button', icon, options),
205
- ...getPaletteDiagnostics('button', parsed.attributes, options)
206
- ];
207
- }
208
- function getBadgeDiagnostics(text) {
209
- const parsed = parseLeafDirectiveLine(text, 'badge');
210
- if (!parsed) return [];
211
- const definition = layoutDirectiveRegistry.get('badge');
212
- const resolved = resolveShieldsBadge(parsed.attributes);
213
86
  return [
214
- ...parsed.warnings,
215
- ...definition?.validateAttributes?.({
216
- name: 'badge',
217
- attributes: parsed.attributes
218
- }) ?? [],
219
- ...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) : []
220
90
  ];
221
91
  }
222
92
  function lintContainerLine(state, scanned, push) {
@@ -233,7 +103,8 @@ function lintLeafLine(state, scanned, push) {
233
103
  const leafName = getLeafDirectiveName(scanned.text);
234
104
  markTopFrameContent(state);
235
105
  if (!leafName) return;
236
- if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {
106
+ const leaf = layoutDirectiveRegistry.get(leafName)?.leaf;
107
+ if (!leaf) {
237
108
  report(`Unknown directive "${leafName}".`);
238
109
  return;
239
110
  }
@@ -242,8 +113,7 @@ function lintLeafLine(state, scanned, push) {
242
113
  report(problem);
243
114
  return;
244
115
  }
245
- const messages = leafName === 'button' ? getButtonDiagnostics(scanned.text, state.options) : getBadgeDiagnostics(scanned.text);
246
- for (const message of messages)report(message);
116
+ for (const message of leaf.lint(scanned.text, state.options))report(message);
247
117
  }
248
118
  function lintParagraph(state, paragraph, index, push) {
249
119
  if (paragraph.type !== 'paragraph') return;
@@ -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 { 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,SAASA,oBAAoB,EAAEC,gBAAgB,QAAQ,sBAAqB;AAC5E,SAASC,+BAA+B,QAAQ,mBAAkB;AAClE,SAASC,mBAAmB,EAAEC,2BAA2B,QAAQ,6BAA4B;AAC7F,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;AA6CtC,sFAAsF,GACtF,SAASC,mBAAmBC,SAAiB,EAAEC,IAAa,EAAEC,OAAsC;IAClG,IAAI,OAAOD,SAAS,UAAU,OAAO,EAAE;IAEvC,MAAM,EAAEE,OAAO,EAAEC,QAAQ,EAAE,GAAG3B,iBAAiBwB;IAC/C,MAAMI,cAAc;WAAID;WAAa5B,qBAAqBwB,WAAWG;KAAS;IAE9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cJ,OAClChB,KAAKwF,SAASxE,MAAMoC,IAAI,EAAEpC,MAAMoC,IAAI,GAAGpC,MAAMP,IAAI,CAACM,MAAM,GAAG,GAAGC,MAAMmC,IAAI;QAE1EnD,KAAK,CAAC,oBAAoB,EAAEgB,MAAMP,IAAI,CAAC,EAAE,CAAC,EAAEO,MAAMoC,IAAI,EAAEpC,MAAMoC,IAAI,GAAGpC,MAAMP,IAAI,CAACM,MAAM,GAAG,GAAGC,MAAMmC,IAAI;IACxG;IAEA,OAAO1D;AACT"}
1
+ {"version":3,"sources":["../../src/directives/diagnostics.ts"],"sourcesContent":["import type { Root } from 'mdast'\n\nimport type { ScannedDirectiveLine, SourceIndex } from './lineScanner.js'\nimport type { DirectiveLintFrame, LintMarkdownDirectivesOptions } from './types.js'\n\nimport { getLeafDirectiveName, getLeafDirectiveProblem } from './leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from './lineScanner.js'\nimport { getIconLintDiagnostics, getPaletteLintDiagnostics } from './lint.js'\nimport { layoutDirectiveRegistry } from './registry.js'\nimport { parseDirectiveSourceTree } from './sourceTree.js'\nimport { getUnknownThemeDiagnostics } from './themeDiagnostics.js'\n\nexport type { LintMarkdownDirectivesOptions } from './types.js'\n\nexport type DirectiveDiagnostic = {\n from: number\n line: number\n message: string\n severity: 'warning'\n to: number\n}\n\ntype LintState = {\n currentHeadingDepth?: number\n options: LintMarkdownDirectivesOptions\n stack: DirectiveLintFrame[]\n}\n\nfunction findNearestFrameIndex(stack: DirectiveLintFrame[], predicate: (frame: DirectiveLintFrame) => 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\n/** A directive's own checks when its frame closes (definition `lint.close`). */\nfunction finalizeFrame(frame: DirectiveLintFrame): string[] {\n return layoutDirectiveRegistry.get(frame.name)?.lint?.close?.(frame) ?? []\n}\n\nfunction popFrames(stack: DirectiveLintFrame[], 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 const isGrid = layoutDirectiveRegistry.isGridName(token.name)\n const frame: DirectiveLintFrame = {\n name: token.name,\n from,\n line,\n ...(isGrid ? { parentHeadingDepth: state.currentHeadingDepth ?? 1 } : {}),\n }\n\n // The directive's own nesting checks see the stack before it opens.\n diagnostics.push(\n ...(layoutDirectiveRegistry.get(token.name)?.lint?.open?.({\n attributes: token.attributes ?? {},\n frame,\n label: token.label,\n stack,\n }) ?? []),\n )\n\n if (isGrid) {\n // remarkCompileLayouts closes an open grid inside the nearest section.\n const gridIndex = findNearestFrameIndex(stack, (open) =>\n layoutDirectiveRegistry.isGridName(open.name),\n )\n const sectionIndex = findNearestFrameIndex(stack, (open) => open.name === 'section')\n\n if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex)\n diagnostics.push(...popFrames(stack, gridIndex))\n }\n\n stack.push(frame)\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\n return [\n ...getIconLintDiagnostics(token.name, token.attributes?.icon, options),\n ...getPaletteLintDiagnostics(token.name, definition?.allowedAttributes, token.attributes, options),\n ...(definition ? getUnknownThemeDiagnostics(definition, token.attributes, options.themes) : []),\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 const leaf = layoutDirectiveRegistry.get(leafName)?.leaf\n\n if (!leaf) {\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 for (const message of leaf.lint(scanned.text, state.options)) 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":["getLeafDirectiveName","getLeafDirectiveProblem","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","scanDirectiveLineAt","splitParagraphIntoLines","getIconLintDiagnostics","getPaletteLintDiagnostics","layoutDirectiveRegistry","parseDirectiveSourceTree","getUnknownThemeDiagnostics","findNearestFrameIndex","stack","predicate","index","length","frame","finalizeFrame","get","name","lint","close","popFrames","splice","flatMap","markTopFrameContent","state","top","hasContent","applyHeading","depth","diagnostics","isGridName","parentHeadingDepth","currentHeadingDepth","updateOpenStack","text","line","from","token","parseMarkdownLineDetailed","action","isGrid","push","open","attributes","label","gridIndex","sectionIndex","getThemeDiagnostics","options","definition","icon","allowedAttributes","themes","lintContainerLine","scanned","report","message","to","startLine","result","lintLeafLine","leafName","leaf","problem","lintParagraph","paragraph","type","lines","lineIndex","kind","phrasingEnd","lintMarkdownDirectives","markdown","tree","severity","nested","nestedIndex","flushNestedBefore","marker","node","children","position","start","undefined","Number","POSITIVE_INFINITY","lineStarts"],"mappings":"AAKA,SAASA,oBAAoB,EAAEC,uBAAuB,QAAQ,kBAAiB;AAC/E,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,kCAAkC,EAClCC,mBAAmB,EACnBC,uBAAuB,QAClB,mBAAkB;AACzB,SAASC,sBAAsB,EAAEC,yBAAyB,QAAQ,YAAW;AAC7E,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,wBAAwB,QAAQ,kBAAiB;AAC1D,SAASC,0BAA0B,QAAQ,wBAAuB;AAk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AAG,GAAGC,MAAMqB,IAAI;QAE1EM,KAAK,CAAC,oBAAoB,EAAE3B,MAAMG,IAAI,CAAC,EAAE,CAAC,EAAEH,MAAMsB,IAAI,EAAEtB,MAAMsB,IAAI,GAAGtB,MAAMG,IAAI,CAACJ,MAAM,GAAG,GAAGC,MAAMqB,IAAI;IACxG;IAEA,OAAON;AACT"}
@@ -0,0 +1,11 @@
1
+ import type { DirectiveLintFrame, LintMarkdownDirectivesOptions } from './types.js';
2
+ /**
3
+ * Helpers shared by the editor linter (diagnostics.ts) and the lint hooks of
4
+ * directive definitions. Nothing here imports the registry.
5
+ */
6
+ /** Nearest open frame named `name`, innermost first. */
7
+ export declare function findNearestLintFrame(stack: readonly DirectiveLintFrame[], name: string): DirectiveLintFrame | undefined;
8
+ /** Icon-entry option problems, extra icons, then unknown icon packs (one per entry). */
9
+ export declare function getIconLintDiagnostics(directive: string, icon: unknown, options: LintMarkdownDirectivesOptions): string[];
10
+ /** Unknown `palette` / `iconPalette` / icon-entry palettes, when the known palettes are given. */
11
+ export declare function getPaletteLintDiagnostics(directive: string, allowedAttributes: readonly string[] | undefined, attributes: Record<string, unknown> | undefined, options: LintMarkdownDirectivesOptions): string[];