payload-markdown 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.js +4 -0
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/core/plugins/directiveButton.d.ts +1 -1
- package/dist/core/plugins/directiveButton.js +27 -10
- package/dist/core/plugins/directiveButton.js.map +1 -1
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +13 -1
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/button.d.ts +1 -1
- package/dist/directives/definitions/button.js +9 -2
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/callout.js +9 -2
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +0 -2
- package/dist/directives/definitions/card.js +13 -8
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.js +9 -0
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/details.js +4 -0
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.js +4 -0
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.js +4 -0
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tabs.js +4 -0
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.js +1 -1
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +5 -0
- package/dist/directives/diagnostics.js +26 -10
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +5 -0
- package/dist/directives/spec.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +22 -3
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +21 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/types/core.d.ts +43 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
2
|
+
import { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js';
|
|
2
3
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
3
4
|
import { CARD_BODY_CLASS_NAMES } from './card.js';
|
|
4
5
|
const STEP_VARIANTS = [
|
|
@@ -183,6 +184,7 @@ export const stepsDirective = {
|
|
|
183
184
|
'columns',
|
|
184
185
|
'layout',
|
|
185
186
|
'numbered',
|
|
187
|
+
'palette',
|
|
186
188
|
'stepTheme',
|
|
187
189
|
'theme',
|
|
188
190
|
'variant'
|
|
@@ -195,6 +197,7 @@ export const stepsDirective = {
|
|
|
195
197
|
const theme = resolveDirectiveTheme('steps', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
196
198
|
const stepTheme = resolveDirectiveTheme('card', typeof node.properties.dataStepTheme === 'string' ? node.properties.dataStepTheme : undefined, config.themes);
|
|
197
199
|
node.properties.dataTheme = theme.name;
|
|
200
|
+
applyDirectivePalette(node, config);
|
|
198
201
|
node.properties.className = mergeClassNames(theme.hookClassName, theme.modifierClassName, theme.classes);
|
|
199
202
|
node.children = groupStepChildren(node.children, columns, layout, numbered, variant, stepTheme);
|
|
200
203
|
},
|
|
@@ -231,6 +234,7 @@ export const stepsDirective = {
|
|
|
231
234
|
const numbered = resolveCardStepNumbered(node);
|
|
232
235
|
const columns = resolveCardStepColumns(node);
|
|
233
236
|
return {
|
|
237
|
+
...getPaletteRenderProperties(node),
|
|
234
238
|
dataColumns: variant === 'cards' && layout === 'grid' ? columns : undefined,
|
|
235
239
|
dataDirective: 'steps',
|
|
236
240
|
dataLayout: variant === 'cards' ? layout : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/steps.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 } from '../../styles/directiveSurface.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { CARD_BODY_CLASS_NAMES } from './card.js'\n\nconst STEP_VARIANTS = ['default', 'cards'] as const\nconst STEP_CARD_LAYOUTS = ['stack', 'grid'] as const\nconst STEP_CARD_COLUMNS = ['1', '2', '3', '4', 'auto'] as const\n\ntype StepVariant = (typeof STEP_VARIANTS)[number]\ntype StepCardLayout = (typeof STEP_CARD_LAYOUTS)[number]\ntype StepCardColumns = (typeof STEP_CARD_COLUMNS)[number]\n\nfunction isStepVariant(value: unknown): value is StepVariant {\n return typeof value === 'string' && STEP_VARIANTS.includes(value as StepVariant)\n}\n\nfunction isStepCardLayout(value: unknown): value is StepCardLayout {\n return typeof value === 'string' && STEP_CARD_LAYOUTS.includes(value as StepCardLayout)\n}\n\nfunction isStepCardColumns(value: unknown): value is StepCardColumns {\n return typeof value === 'string' && STEP_CARD_COLUMNS.includes(value as StepCardColumns)\n}\n\nfunction resolveStepsVariant(node: ContainerDirective): StepVariant {\n const variant = node.attributes?.variant\n\n return isStepVariant(variant) ? variant : 'default'\n}\n\nfunction resolveCardStepLayout(node: ContainerDirective): StepCardLayout {\n const layout = node.attributes?.layout\n\n return isStepCardLayout(layout) ? layout : 'stack'\n}\n\nfunction resolveCardStepColumns(node: ContainerDirective): StepCardColumns {\n const columns = node.attributes?.columns\n\n return isStepCardColumns(columns) ? columns : '2'\n}\n\nfunction resolveCardStepNumbered(node: ContainerDirective): boolean {\n const numbered = node.attributes?.numbered\n\n if (numbered === undefined) return true\n if (typeof numbered !== 'string') return true\n\n return numbered !== 'false'\n}\n\nconst STEP_CARDS_LIST_CLASS_NAMES =\n 'm-0! list-none! gap-4 p-0! [&>li]:m-0! [&>li]:p-0! [&>li]:[font-size:inherit]'\n\nfunction isElement(node: ElementContent): node is Element {\n return node.type === 'element'\n}\n\nfunction isStepHeading(node: ElementContent): node is Element {\n return isElement(node) && ['h2', 'h3', 'h4'].includes(node.tagName)\n}\n\nfunction makeStep(children: ElementContent[], index: number): Element {\n return {\n type: 'element',\n children: [\n {\n type: 'element',\n children,\n properties: {\n className: [DIRECTIVE_BODY_CLASS],\n dataDirectiveBody: 'step',\n },\n tagName: 'div',\n },\n ],\n properties: {\n className: ['relative'],\n dataStep: String(index + 1),\n },\n tagName: 'li',\n }\n}\n\nfunction makeCardStep(\n children: ElementContent[],\n index: number,\n numbered: boolean,\n stepTheme: ReturnType<typeof resolveDirectiveTheme>,\n): Element {\n return {\n type: 'element',\n children: [\n {\n type: 'element',\n children: [\n ...(numbered\n ? [\n {\n type: 'element' as const,\n children: [{ type: 'text' as const, value: String(index + 1) }],\n properties: {\n className: [\n 'pmd-step-number not-prose mb-3 inline-flex h-8 w-8 items-center justify-center rounded-full border border-current/25 bg-[color:color-mix(in_oklab,rgb(255_255_255/0.1)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.05))] text-sm font-semibold',\n ],\n dataStepNumber: String(index + 1),\n },\n tagName: 'span',\n },\n ]\n : []),\n ...children,\n ],\n properties: {\n className: [\n stepTheme.hookClassName,\n stepTheme.modifierClassName,\n stepTheme.classes,\n 'h-full',\n CARD_BODY_CLASS_NAMES,\n // The step title sits right under its number badge.\n '[&>.pmd-step-number+*]:mt-0',\n ],\n dataDirectiveBody: 'step',\n dataStepCard: '',\n dataTheme: stepTheme.name,\n },\n tagName: 'article',\n },\n ],\n properties: {\n className: ['list-none'],\n dataStep: String(index + 1),\n },\n tagName: 'li',\n }\n}\n\nfunction groupStepChildren(\n children: ElementContent[],\n columns: StepCardColumns,\n layout: StepCardLayout,\n numbered: boolean,\n variant: StepVariant,\n stepTheme: ReturnType<typeof resolveDirectiveTheme>,\n): ElementContent[] {\n const groups: ElementContent[][] = []\n let current: ElementContent[] = []\n const makeStepElement =\n variant === 'cards'\n ? (group: ElementContent[], index: number) => makeCardStep(group, index, numbered, stepTheme)\n : makeStep\n // Same container-width columns as `:::cards` (see cardGridColumnClasses).\n const gridColumnsClassNames: Record<StepCardColumns, string> = {\n '1': 'grid-cols-1',\n '2': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2rem)/2))),1fr))]',\n '3': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2*2rem)/3))),1fr))]',\n '4': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_3*2rem)/4))),1fr))]',\n auto: 'grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))]',\n }\n\n for (const child of children) {\n if (isStepHeading(child) && current.length > 0) {\n groups.push(current)\n current = [child]\n continue\n }\n\n current.push(child)\n }\n\n if (current.length > 0) groups.push(current)\n\n return [\n {\n type: 'element',\n children: groups.map(makeStepElement),\n properties: {\n // Step lists are structure, not prose lists: the `!` resets win over\n // Typography's list styles and the renderer's list spacing.\n className:\n variant === 'cards'\n ? layout === 'grid'\n ? [STEP_CARDS_LIST_CLASS_NAMES, 'grid', gridColumnsClassNames[columns]]\n : [STEP_CARDS_LIST_CLASS_NAMES, 'flex flex-col']\n : [\n 'm-0! list-decimal pl-6! [&>li]:my-0! [&>li]:pl-4! [&>li+li]:mt-6! [&>li]:[font-size:inherit] [&>li]:marker:font-semibold',\n ],\n },\n tagName: 'ol',\n },\n ]\n}\n\nexport const stepsDirective: LayoutDirectiveDefinition = {\n name: 'steps',\n allowedAttributes: ['columns', 'layout', 'numbered', 'stepTheme', 'theme', 'variant'],\n applyHast(node, config, { mergeClassNames }) {\n const variant =\n typeof node.properties.dataVariant === 'string' && isStepVariant(node.properties.dataVariant)\n ? node.properties.dataVariant\n : 'default'\n const layout =\n typeof node.properties.dataLayout === 'string' && isStepCardLayout(node.properties.dataLayout)\n ? node.properties.dataLayout\n : 'stack'\n const columns =\n typeof node.properties.dataColumns === 'string' && isStepCardColumns(node.properties.dataColumns)\n ? node.properties.dataColumns\n : '2'\n const numbered = node.properties.dataNumbered !== 'false'\n const theme = resolveDirectiveTheme(\n 'steps',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const stepTheme = resolveDirectiveTheme(\n 'card',\n typeof node.properties.dataStepTheme === 'string'\n ? node.properties.dataStepTheme\n : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n node.children = groupStepChildren(node.children, columns, layout, numbered, variant, stepTheme)\n },\n attributeValues: {\n columns: STEP_CARD_COLUMNS,\n layout: STEP_CARD_LAYOUTS,\n numbered: ['true', 'false'],\n variant: STEP_VARIANTS,\n },\n description: 'Structured ordered flow for tutorials and install steps.',\n editor: {\n detail: 'Docs directive',\n label: 'Steps',\n snippet: ':::steps\\n\\n### ${Step title}\\n\\n${Content}\\n\\n:::\\n${}',\n snippets: [\n {\n detail: 'Docs directive',\n label: 'Steps cards stack',\n snippet:\n ':::steps {variant=\"cards\" layout=\"stack\" numbered}\\n\\n### ${Step title}\\n\\n${Content}\\n\\n:::\\n${}',\n },\n {\n detail: 'Docs directive',\n label: 'Steps cards grid',\n snippet:\n ':::steps {variant=\"cards\" layout=\"grid\" columns=\"${2}\" numbered}\\n\\n### ${First step}\\n\\n${Content}\\n\\n### ${Second step}\\n\\n${Content}\\n\\n:::\\n${}',\n },\n ],\n },\n getMdastRenderProperties(node) {\n const variant = resolveStepsVariant(node)\n const layout = resolveCardStepLayout(node)\n const numbered = resolveCardStepNumbered(node)\n const columns = resolveCardStepColumns(node)\n\n return {\n dataColumns: variant === 'cards' && layout === 'grid' ? columns : undefined,\n dataDirective: 'steps',\n dataLayout: variant === 'cards' ? layout : undefined,\n dataNumbered: variant === 'cards' ? String(numbered) : undefined,\n dataStepTheme:\n typeof node.attributes?.stepTheme === 'string' ? node.attributes.stepTheme : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataVariant: variant === 'default' ? undefined : variant,\n }\n },\n kind: 'steps',\n openMarker: ':::steps',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n stepTheme: 'card',\n theme: 'steps',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (typeof attributes.variant === 'string' && !isStepVariant(attributes.variant))\n warnings.push(\n `Unsupported steps variant \"${attributes.variant}\". Falling back to \"default\".`,\n )\n if (typeof attributes.layout === 'string' && !isStepCardLayout(attributes.layout))\n warnings.push(`Unsupported steps layout \"${attributes.layout}\". Falling back to \"stack\".`)\n if (typeof attributes.columns === 'string' && !isStepCardColumns(attributes.columns))\n warnings.push(`Invalid steps columns \"${attributes.columns}\". Falling back to \"2\".`)\n if (\n typeof attributes.numbered === 'string' &&\n attributes.numbered !== 'true' &&\n attributes.numbered !== 'false'\n )\n warnings.push(\n `Invalid steps numbered value \"${attributes.numbered}\". Falling back to \"true\".`,\n )\n\n return warnings\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","resolveDirectiveTheme","CARD_BODY_CLASS_NAMES","STEP_VARIANTS","STEP_CARD_LAYOUTS","STEP_CARD_COLUMNS","isStepVariant","value","includes","isStepCardLayout","isStepCardColumns","resolveStepsVariant","node","variant","attributes","resolveCardStepLayout","layout","resolveCardStepColumns","columns","resolveCardStepNumbered","numbered","undefined","STEP_CARDS_LIST_CLASS_NAMES","isElement","type","isStepHeading","tagName","makeStep","children","index","properties","className","dataDirectiveBody","dataStep","String","makeCardStep","stepTheme","dataStepNumber","hookClassName","modifierClassName","classes","dataStepCard","dataTheme","name","groupStepChildren","groups","current","makeStepElement","group","gridColumnsClassNames","auto","child","length","push","map","stepsDirective","allowedAttributes","applyHast","config","mergeClassNames","dataVariant","dataLayout","dataColumns","dataNumbered","theme","themes","dataStepTheme","attributeValues","description","editor","detail","label","snippet","snippets","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,qBAAqB,QAAQ,YAAW;AAEjD,MAAMC,gBAAgB;IAAC;IAAW;CAAQ;AAC1C,MAAMC,oBAAoB;IAAC;IAAS;CAAO;AAC3C,MAAMC,oBAAoB;IAAC;IAAK;IAAK;IAAK;IAAK;CAAO;AAMtD,SAASC,cAAcC,KAAc;IACnC,OAAO,OAAOA,UAAU,YAAYJ,cAAcK,QAAQ,CAACD;AAC7D;AAEA,SAASE,iBAAiBF,KAAc;IACtC,OAAO,OAAOA,UAAU,YAAYH,kBAAkBI,QAAQ,CAACD;AACjE;AAEA,SAASG,kBAAkBH,KAAc;IACvC,OAAO,OAAOA,UAAU,YAAYF,kBAAkBG,QAAQ,CAACD;AACjE;AAEA,SAASI,oBAAoBC,IAAwB;IACnD,MAAMC,UAAUD,KAAKE,UAAU,EAAED;IAEjC,OAAOP,cAAcO,WAAWA,UAAU;AAC5C;AAEA,SAASE,sBAAsBH,IAAwB;IACrD,MAAMI,SAASJ,KAAKE,UAAU,EAAEE;IAEhC,OAAOP,iBAAiBO,UAAUA,SAAS;AAC7C;AAEA,SAASC,uBAAuBL,IAAwB;IACtD,MAAMM,UAAUN,KAAKE,UAAU,EAAEI;IAEjC,OAAOR,kBAAkBQ,WAAWA,UAAU;AAChD;AAEA,SAASC,wBAAwBP,IAAwB;IACvD,M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J,WAAWM,QAAQ,KAAK,YAC/BN,WAAWM,QAAQ,KAAK,UACxBN,WAAWM,QAAQ,KAAK,SAExB8D,SAAS7B,IAAI,CACX,CAAC,8BAA8B,EAAEvC,WAAWM,QAAQ,CAAC,0BAA0B,CAAC;QAGpF,OAAO8D;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/steps.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 } from '../../styles/directiveSurface.js'\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { CARD_BODY_CLASS_NAMES } from './card.js'\n\nconst STEP_VARIANTS = ['default', 'cards'] as const\nconst STEP_CARD_LAYOUTS = ['stack', 'grid'] as const\nconst STEP_CARD_COLUMNS = ['1', '2', '3', '4', 'auto'] as const\n\ntype StepVariant = (typeof STEP_VARIANTS)[number]\ntype StepCardLayout = (typeof STEP_CARD_LAYOUTS)[number]\ntype StepCardColumns = (typeof STEP_CARD_COLUMNS)[number]\n\nfunction isStepVariant(value: unknown): value is StepVariant {\n return typeof value === 'string' && STEP_VARIANTS.includes(value as StepVariant)\n}\n\nfunction isStepCardLayout(value: unknown): value is StepCardLayout {\n return typeof value === 'string' && STEP_CARD_LAYOUTS.includes(value as StepCardLayout)\n}\n\nfunction isStepCardColumns(value: unknown): value is StepCardColumns {\n return typeof value === 'string' && STEP_CARD_COLUMNS.includes(value as StepCardColumns)\n}\n\nfunction resolveStepsVariant(node: ContainerDirective): StepVariant {\n const variant = node.attributes?.variant\n\n return isStepVariant(variant) ? variant : 'default'\n}\n\nfunction resolveCardStepLayout(node: ContainerDirective): StepCardLayout {\n const layout = node.attributes?.layout\n\n return isStepCardLayout(layout) ? layout : 'stack'\n}\n\nfunction resolveCardStepColumns(node: ContainerDirective): StepCardColumns {\n const columns = node.attributes?.columns\n\n return isStepCardColumns(columns) ? columns : '2'\n}\n\nfunction resolveCardStepNumbered(node: ContainerDirective): boolean {\n const numbered = node.attributes?.numbered\n\n if (numbered === undefined) return true\n if (typeof numbered !== 'string') return true\n\n return numbered !== 'false'\n}\n\nconst STEP_CARDS_LIST_CLASS_NAMES =\n 'm-0! list-none! gap-4 p-0! [&>li]:m-0! [&>li]:p-0! [&>li]:[font-size:inherit]'\n\nfunction isElement(node: ElementContent): node is Element {\n return node.type === 'element'\n}\n\nfunction isStepHeading(node: ElementContent): node is Element {\n return isElement(node) && ['h2', 'h3', 'h4'].includes(node.tagName)\n}\n\nfunction makeStep(children: ElementContent[], index: number): Element {\n return {\n type: 'element',\n children: [\n {\n type: 'element',\n children,\n properties: {\n className: [DIRECTIVE_BODY_CLASS],\n dataDirectiveBody: 'step',\n },\n tagName: 'div',\n },\n ],\n properties: {\n className: ['relative'],\n dataStep: String(index + 1),\n },\n tagName: 'li',\n }\n}\n\nfunction makeCardStep(\n children: ElementContent[],\n index: number,\n numbered: boolean,\n stepTheme: ReturnType<typeof resolveDirectiveTheme>,\n): Element {\n return {\n type: 'element',\n children: [\n {\n type: 'element',\n children: [\n ...(numbered\n ? [\n {\n type: 'element' as const,\n children: [{ type: 'text' as const, value: String(index + 1) }],\n properties: {\n className: [\n 'pmd-step-number not-prose mb-3 inline-flex h-8 w-8 items-center justify-center rounded-full border border-current/25 bg-[color:color-mix(in_oklab,rgb(255_255_255/0.1)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.05))] text-sm font-semibold',\n ],\n dataStepNumber: String(index + 1),\n },\n tagName: 'span',\n },\n ]\n : []),\n ...children,\n ],\n properties: {\n className: [\n stepTheme.hookClassName,\n stepTheme.modifierClassName,\n stepTheme.classes,\n 'h-full',\n CARD_BODY_CLASS_NAMES,\n // The step title sits right under its number badge.\n '[&>.pmd-step-number+*]:mt-0',\n ],\n dataDirectiveBody: 'step',\n dataStepCard: '',\n dataTheme: stepTheme.name,\n },\n tagName: 'article',\n },\n ],\n properties: {\n className: ['list-none'],\n dataStep: String(index + 1),\n },\n tagName: 'li',\n }\n}\n\nfunction groupStepChildren(\n children: ElementContent[],\n columns: StepCardColumns,\n layout: StepCardLayout,\n numbered: boolean,\n variant: StepVariant,\n stepTheme: ReturnType<typeof resolveDirectiveTheme>,\n): ElementContent[] {\n const groups: ElementContent[][] = []\n let current: ElementContent[] = []\n const makeStepElement =\n variant === 'cards'\n ? (group: ElementContent[], index: number) => makeCardStep(group, index, numbered, stepTheme)\n : makeStep\n // Same container-width columns as `:::cards` (see cardGridColumnClasses).\n const gridColumnsClassNames: Record<StepCardColumns, string> = {\n '1': 'grid-cols-1',\n '2': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2rem)/2))),1fr))]',\n '3': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2*2rem)/3))),1fr))]',\n '4': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_3*2rem)/4))),1fr))]',\n auto: 'grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))]',\n }\n\n for (const child of children) {\n if (isStepHeading(child) && current.length > 0) {\n groups.push(current)\n current = [child]\n continue\n }\n\n current.push(child)\n }\n\n if (current.length > 0) groups.push(current)\n\n return [\n {\n type: 'element',\n children: groups.map(makeStepElement),\n properties: {\n // Step lists are structure, not prose lists: the `!` resets win over\n // Typography's list styles and the renderer's list spacing.\n className:\n variant === 'cards'\n ? layout === 'grid'\n ? [STEP_CARDS_LIST_CLASS_NAMES, 'grid', gridColumnsClassNames[columns]]\n : [STEP_CARDS_LIST_CLASS_NAMES, 'flex flex-col']\n : [\n 'm-0! list-decimal pl-6! [&>li]:my-0! [&>li]:pl-4! [&>li+li]:mt-6! [&>li]:[font-size:inherit] [&>li]:marker:font-semibold',\n ],\n },\n tagName: 'ol',\n },\n ]\n}\n\nexport const stepsDirective: LayoutDirectiveDefinition = {\n name: 'steps',\n allowedAttributes: ['columns', 'layout', 'numbered', 'palette', 'stepTheme', 'theme', 'variant'],\n applyHast(node, config, { mergeClassNames }) {\n const variant =\n typeof node.properties.dataVariant === 'string' && isStepVariant(node.properties.dataVariant)\n ? node.properties.dataVariant\n : 'default'\n const layout =\n typeof node.properties.dataLayout === 'string' && isStepCardLayout(node.properties.dataLayout)\n ? node.properties.dataLayout\n : 'stack'\n const columns =\n typeof node.properties.dataColumns === 'string' && isStepCardColumns(node.properties.dataColumns)\n ? node.properties.dataColumns\n : '2'\n const numbered = node.properties.dataNumbered !== 'false'\n const theme = resolveDirectiveTheme(\n 'steps',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const stepTheme = resolveDirectiveTheme(\n 'card',\n typeof node.properties.dataStepTheme === 'string'\n ? node.properties.dataStepTheme\n : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n node.children = groupStepChildren(node.children, columns, layout, numbered, variant, stepTheme)\n },\n attributeValues: {\n columns: STEP_CARD_COLUMNS,\n layout: STEP_CARD_LAYOUTS,\n numbered: ['true', 'false'],\n variant: STEP_VARIANTS,\n },\n description: 'Structured ordered flow for tutorials and install steps.',\n editor: {\n detail: 'Docs directive',\n label: 'Steps',\n snippet: ':::steps\\n\\n### ${Step title}\\n\\n${Content}\\n\\n:::\\n${}',\n snippets: [\n {\n detail: 'Docs directive',\n label: 'Steps cards stack',\n snippet:\n ':::steps {variant=\"cards\" layout=\"stack\" numbered}\\n\\n### ${Step title}\\n\\n${Content}\\n\\n:::\\n${}',\n },\n {\n detail: 'Docs directive',\n label: 'Steps cards grid',\n snippet:\n ':::steps {variant=\"cards\" layout=\"grid\" columns=\"${2}\" numbered}\\n\\n### ${First step}\\n\\n${Content}\\n\\n### ${Second step}\\n\\n${Content}\\n\\n:::\\n${}',\n },\n ],\n },\n getMdastRenderProperties(node) {\n const variant = resolveStepsVariant(node)\n const layout = resolveCardStepLayout(node)\n const numbered = resolveCardStepNumbered(node)\n const columns = resolveCardStepColumns(node)\n\n return {\n ...getPaletteRenderProperties(node),\n dataColumns: variant === 'cards' && layout === 'grid' ? columns : undefined,\n dataDirective: 'steps',\n dataLayout: variant === 'cards' ? layout : undefined,\n dataNumbered: variant === 'cards' ? String(numbered) : undefined,\n dataStepTheme:\n typeof node.attributes?.stepTheme === 'string' ? node.attributes.stepTheme : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataVariant: variant === 'default' ? undefined : variant,\n }\n },\n kind: 'steps',\n openMarker: ':::steps',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n stepTheme: 'card',\n theme: 'steps',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (typeof attributes.variant === 'string' && !isStepVariant(attributes.variant))\n warnings.push(\n `Unsupported steps variant \"${attributes.variant}\". Falling back to \"default\".`,\n )\n if (typeof attributes.layout === 'string' && !isStepCardLayout(attributes.layout))\n warnings.push(`Unsupported steps layout \"${attributes.layout}\". Falling back to \"stack\".`)\n if (typeof attributes.columns === 'string' && !isStepCardColumns(attributes.columns))\n warnings.push(`Invalid steps columns \"${attributes.columns}\". Falling back to \"2\".`)\n if (\n typeof attributes.numbered === 'string' &&\n attributes.numbered !== 'true' &&\n attributes.numbered !== 'false'\n )\n warnings.push(\n `Invalid steps numbered value \"${attributes.numbered}\". Falling back to \"true\".`,\n )\n\n return warnings\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","CARD_BODY_CLASS_NAMES","STEP_VARIANTS","STEP_CARD_LAYOUTS","STEP_CARD_COLUMNS","isStepVariant","value","includes","isStepCardLayout","isStepCardColumns","resolveStepsVariant","node","variant","attributes","resolveCardStepLayout","layout","resolveCardStepColumns","columns","resolveCardStepNumbered","numbered","undefined","STEP_CARDS_LIST_CLASS_NAMES","isElement","type","isStepHeading","tagName","makeStep","children","index","properties","className","dataDirectiveBody","dataStep","String","makeCardStep","stepTheme","dataStepNumber","hookClassName","modifierClassName","classes","dataStepCard","dataTheme","name","groupStepChildren","groups","current","makeStepElement","group","gridColumnsClassNames","auto","child","length","push","map","stepsDirective","allowedAttributes","applyHast","config","mergeClassNames","dataVariant","dataLayout","dataColumns","dataNumbered","theme","themes","dataStepTheme","attributeValues","description","editor","detail","label","snippet","snippets","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,qBAAqB,QAAQ,YAAW;AAEjD,MAAMC,gBAAgB;IAAC;IAAW;CAAQ;AAC1C,MAAMC,oBAAoB;IAAC;IAAS;CAAO;AAC3C,MAAMC,oBAAoB;IAAC;IAAK;IAAK;IAAK;IAAK;CAAO;AAMtD,SAASC,cAAcC,KAAc;IACnC,OAAO,OAAOA,UAAU,YAAYJ,cAAcK,QAAQ,CAACD;AAC7D;AAEA,SAASE,iBAAiBF,KAAc;IACtC,OAAO,OAAOA,UAAU,YAAYH,kBAAkBI,QAAQ,CAACD;AACjE;AAEA,SAASG,kBAAkBH,KAAc;IACvC,OAAO,OAAOA,UAAU,YAAYF,kBAAkBG,QAAQ,CAACD;AACjE;AAEA,SAASI,oBAAoBC,IAAwB;IACnD,MAAMC,UAAUD,KAAKE,UAAU,EAAED;IAEjC,OAAOP,cAAcO,WAAWA,UAAU;AAC5C;AAEA,SAASE,sBAAsBH,IAAwB;IACrD,MAAMI,SAASJ,KAAKE,UAAU,EAAEE;IAEhC,OAAOP,iBAAiBO,UAAUA,SAAS;AAC7C;AAEA,SAASC,uBAAuBL,IAAwB;IACtD,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C;QAC3F,IAAI,OAAOF,WAAWI,OAAO,KAAK,YAAY,CAACR,kBAAkBI,WAAWI,OAAO,GACjFgE,SAAS7B,IAAI,CAAC,CAAC,uBAAuB,EAAEvC,WAAWI,OAAO,CAAC,uBAAuB,CAAC;QACrF,IACE,OAAOJ,WAAWM,QAAQ,KAAK,YAC/BN,WAAWM,QAAQ,KAAK,UACxBN,WAAWM,QAAQ,KAAK,SAExB8D,SAAS7B,IAAI,CACX,CAAC,8BAA8B,EAAEvC,WAAWM,QAAQ,CAAC,0BAA0B,CAAC;QAGpF,OAAO8D;IACT;AACF,EAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
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';
|
|
3
4
|
import { getTabLabel as getTabDirectiveLabel, getTabRawValue, getTabValue, resolveTabsDefault, slugTabValue, toTabSlug } from './tab.js';
|
|
4
5
|
function isContainerDirective(node) {
|
|
@@ -136,6 +137,7 @@ export const tabsDirective = {
|
|
|
136
137
|
name: 'tabs',
|
|
137
138
|
allowedAttributes: [
|
|
138
139
|
'default',
|
|
140
|
+
'palette',
|
|
139
141
|
'tabTheme',
|
|
140
142
|
'theme'
|
|
141
143
|
],
|
|
@@ -146,6 +148,7 @@ export const tabsDirective = {
|
|
|
146
148
|
const tabTheme = typeof node.properties.dataTabTheme === 'string' ? node.properties.dataTabTheme : undefined;
|
|
147
149
|
node.properties.dataTheme = theme.name;
|
|
148
150
|
node.properties.dataDefault = activeTab?.value;
|
|
151
|
+
applyDirectivePalette(node, config);
|
|
149
152
|
node.properties.className = mergeClassNames(theme.hookClassName, theme.modifierClassName, theme.classes);
|
|
150
153
|
if (!activeTab) {
|
|
151
154
|
node.children = [
|
|
@@ -181,6 +184,7 @@ export const tabsDirective = {
|
|
|
181
184
|
getMdastRenderProperties (node) {
|
|
182
185
|
const requestedDefault = typeof node.attributes?.default === 'string' ? node.attributes.default : undefined;
|
|
183
186
|
return {
|
|
187
|
+
...getPaletteRenderProperties(node),
|
|
184
188
|
dataDefault: requestedDefault ? resolveTabsDefault(requestedDefault, getTabsDefaultCandidates(node)) ?? requestedDefault : undefined,
|
|
185
189
|
dataDirective: 'tabs',
|
|
186
190
|
dataTabTheme: typeof node.attributes?.tabTheme === 'string' ? node.attributes.tabTheme : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/tabs.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_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;IA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WAAW,OAAOxD,KAAKsE,UAAU,EAAErB,UAAU,WAAWjD,KAAKsE,UAAU,CAACrB,KAAK,GAAG;QAClF;IACF;IACAoC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpB5C,SAAS;IACT6C,iBAAiB;QACfd,UAAU;QACV1B,OAAO;IACT;IACAyC,gBAAe1F,IAAI;QACjBoE,uBAAuBpE,MAAM2F,OAAO,CAAC,CAACzD,KAAKtB;YACzC,MAAMgF,OAAQ1D,IAAI0D,IAAI,KAAK,CAAC;YAC5BA,KAAKC,UAAU,GAAGjF;QACpB;IACF;IACAkF,eAAc9F,IAAI;QAChB,MAAM+F,WAAqB,EAAE;QAC7B,MAAMpC,OAAOS,uBAAuBpE;QACpC,MAAMgG,SAAS,IAAIzE;QAEnB,IAAIoC,KAAKsC,MAAM,KAAK,GAAGF,SAASG,IAAI,CAAC;QAErCvC,KAAKgC,OAAO,CAAC,CAACzD,KAAKtB;YACjB,MAAMJ,QAAQb,YAAYuC,KAAKtB;YAC/BoF,OAAO5E,GAAG,CAACZ,OAAO,AAACwF,CAAAA,OAAO7E,GAAG,CAACX,UAAU,CAAA,IAAK;QAC/C;QAEA,KAAK,MAAM,CAACA,OAAOU,MAAM,IAAI8E,OAC3B,IAAI9E,QAAQ,GAAG6E,SAASG,IAAI,CAAC,CAAC,qBAAqB,EAAE1F,MAAM,YAAY,CAAC;QAE1E,IACE,OAAOR,KAAKsE,UAAU,EAAEa,YAAY,YACpC,CAACvF,mBAAmBI,KAAKsE,UAAU,CAACa,OAAO,EAAEhB,yBAAyBnE,QAEtE+F,SAASG,IAAI,CAAC,CAAC,sBAAsB,EAAElG,KAAKsE,UAAU,CAACa,OAAO,CAAC,iCAAiC,CAAC;QAEnG,OAAOY;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/tabs.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_BODY_CLASS, DIRECTIVE_SURFACE_DIVIDER_CLASS } from '../../styles/directiveSurface.js'\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport {\n getTabLabel as getTabDirectiveLabel,\n getTabRawValue,\n getTabValue,\n resolveTabsDefault,\n slugTabValue,\n toTabSlug,\n} from './tab.js'\n\ntype TabModel = {\n disabled: boolean\n label: string\n node: Element\n panelId: string\n themeName?: string\n triggerId: string\n value: string\n}\n\nfunction isContainerDirective(node: unknown): node is ContainerDirective {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n (node as { type?: string }).type === 'containerDirective',\n )\n}\n\nfunction isTabElement(node: ElementContent): node is Element {\n return node.type === 'element' && node.properties?.dataVlLayout === 'tab'\n}\n\nfunction getStringProperty(\n properties: Element['properties'] | undefined,\n name: string,\n): string | undefined {\n const value = properties?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanProperty(properties: Element['properties'] | undefined, name: string): boolean {\n const value = properties?.[name]\n\n return value === true || value === 'true'\n}\n\nfunction getTabLabel(node: Element, index: number): string {\n return (\n getStringProperty(node.properties, 'dataLabel') ??\n getStringProperty(node.properties, 'dataValue') ??\n `Tab ${index + 1}`\n )\n}\n\nfunction getRequestedDefault(node: Element): string | undefined {\n return getStringProperty(node.properties, 'dataDefault')\n}\n\nfunction makeUniqueValue(rawValue: string, index: number, seen: Map<string, number>): string {\n const base = slugTabValue(rawValue, index)\n const count = seen.get(base) ?? 0\n seen.set(base, count + 1)\n\n return count === 0 ? base : `${base}-${count}`\n}\n\nfunction collectTabs(\n node: Element,\n reserveIds: (bases: string[]) => string[],\n): TabModel[] {\n const seen = new Map<string, number>()\n\n return node.children.filter(isTabElement).map((child, index) => {\n const rawValue = getStringProperty(child.properties, 'dataValue') ?? `tab-${index + 1}`\n const value = makeUniqueValue(rawValue, index, seen)\n // Ids are unique per render: a second identical tabs block (or a heading\n // such as \"Tabs panel npm\") pushes these ids to a -n suffix.\n const [panelId, triggerId] = reserveIds([`tabs-panel-${value}`, `tabs-trigger-${value}`])\n\n return {\n disabled: getBooleanProperty(child.properties, 'dataDisabled'),\n label: getTabLabel(child, index),\n node: child,\n panelId,\n themeName: getStringProperty(child.properties, 'dataTheme'),\n triggerId,\n value,\n }\n })\n}\n\nfunction makeTabTrigger(tab: TabModel, active: boolean): Element {\n const className = [\n 'vl-md-tabs-trigger',\n active ? 'vl-md-tabs-trigger--active' : undefined,\n // Inactive labels stay at 75% of the text colour: enough for AA contrast in\n // both colour schemes while still reading as secondary.\n 'rounded-lg px-3 py-2 text-sm font-medium text-current/75 transition-colors hover:bg-[color:color-mix(in_oklab,rgb(255_255_255/0.05)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.04))] hover:text-current aria-selected:bg-[color:color-mix(in_oklab,rgb(255_255_255/0.1)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.06))] aria-selected:text-current focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:color-mix(in_oklab,rgb(255_255_255/0.25)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent',\n ].filter((value): value is string => Boolean(value))\n\n return {\n type: 'element',\n children: [{ type: 'text', value: tab.label }],\n properties: {\n id: tab.triggerId,\n type: 'button',\n ariaControls: [tab.panelId],\n ariaSelected: active ? 'true' : 'false',\n className,\n dataTabTrigger: '',\n dataTabValue: tab.value,\n disabled: tab.disabled || undefined,\n role: 'tab',\n tabIndex: active ? 0 : -1,\n },\n tagName: 'button',\n }\n}\n\nfunction makeTabPanel(\n tab: TabModel,\n active: boolean,\n config: Parameters<NonNullable<LayoutDirectiveDefinition['applyHast']>>[1],\n mergeClassNames: Parameters<NonNullable<LayoutDirectiveDefinition['applyHast']>>[2]['mergeClassNames'],\n fallbackThemeName?: string,\n): Element {\n const theme = resolveDirectiveTheme('tab', tab.themeName ?? fallbackThemeName, config.themes)\n\n return {\n type: 'element',\n children: tab.node.children,\n properties: {\n id: tab.panelId,\n ariaLabelledby: tab.triggerId,\n className: mergeClassNames(\n 'vl-md-tabs-panel',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n DIRECTIVE_BODY_CLASS,\n // A panel holding only a code block shows just the code block.\n 'has-[>pre:only-child]:border-0 has-[>pre:only-child]:bg-transparent has-[>pre:only-child]:p-0 has-[>pre:only-child]:shadow-none',\n ),\n dataTabPanel: '',\n dataTabValue: tab.value,\n dataTheme: theme.name,\n hidden: active ? undefined : true,\n role: 'tabpanel',\n tabIndex: 0,\n },\n tagName: 'div',\n }\n}\n\nfunction makeTabList(tabs: TabModel[], activeValue: string): Element {\n return {\n type: 'element',\n children: tabs.map((tab) => makeTabTrigger(tab, tab.value === activeValue)),\n properties: {\n className: [`not-prose vl-md-tabs-list flex flex-wrap gap-1 border-b ${DIRECTIVE_SURFACE_DIVIDER_CLASS} pb-2`],\n dataTabsList: '',\n role: 'tablist',\n },\n tagName: 'div',\n }\n}\n\nfunction findActiveTab(tabs: TabModel[], requestedDefault?: string): TabModel | undefined {\n // remarkLayoutDirectives already resolved authored defaults to a tab value.\n const requested = requestedDefault ? toTabSlug(requestedDefault) || undefined : undefined\n const requestedMatch = requested\n ? tabs.find((tab) => tab.value === requested && !tab.disabled) ??\n tabs.find((tab) => tab.value === requested)\n : undefined\n\n return requestedMatch ?? tabs.find((tab) => !tab.disabled) ?? tabs[0]\n}\n\nfunction getTabsDefaultCandidates(node: ContainerDirective) {\n return getDirectTabDirectives(node).map((tab, index) => ({\n label: getTabDirectiveLabel(tab, index),\n raw: getTabRawValue(tab.attributes),\n value: getTabValue(tab, index),\n }))\n}\n\nfunction getDirectTabDirectives(node: ContainerDirective): ContainerDirective[] {\n return node.children.filter(\n (child): child is ContainerDirective => isContainerDirective(child) && child.name === 'tab',\n )\n}\n\nexport const tabsDirective: LayoutDirectiveDefinition = {\n name: 'tabs',\n allowedAttributes: ['default', 'palette', 'tabTheme', 'theme'],\n applyHast(node, config, { mergeClassNames, reserveIds }) {\n const tabs = collectTabs(node, reserveIds)\n const activeTab = findActiveTab(tabs, getRequestedDefault(node))\n const theme = resolveDirectiveTheme(\n 'tabs',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const tabTheme =\n typeof node.properties.dataTabTheme === 'string' ? node.properties.dataTabTheme : undefined\n\n node.properties.dataTheme = theme.name\n node.properties.dataDefault = activeTab?.value\n applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n\n if (!activeTab) {\n node.children = [\n {\n type: 'element',\n children: [{ type: 'text', value: 'No tabs configured.' }],\n properties: {\n className: ['not-prose text-sm text-(--tw-prose-body)/80'],\n },\n tagName: 'p',\n },\n ]\n return\n }\n\n node.children = [\n makeTabList(tabs, activeTab.value),\n ...tabs.map((tab) =>\n makeTabPanel(tab, tab.value === activeTab.value, config, mergeClassNames, tabTheme),\n ),\n ]\n },\n description: 'Accessible tabbed content block with server-rendered panels.',\n editor: {\n detail: 'Tabs directive',\n label: 'Tabs',\n snippet:\n ':::tabs{\\n default=\"${pnpm}\"\\n}\\n\\n:::tab[${pnpm}]{\\n value=\"${pnpm}\"\\n}\\n```bash\\npnpm add ${package-name}\\n```\\n:::\\n\\n:::tab[${npm}]{\\n value=\"${npm}\"\\n}\\n```bash\\nnpm install ${package-name}\\n```\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const requestedDefault =\n typeof node.attributes?.default === 'string' ? node.attributes.default : undefined\n\n return {\n ...getPaletteRenderProperties(node),\n dataDefault: requestedDefault\n ? (resolveTabsDefault(requestedDefault, getTabsDefaultCandidates(node)) ?? requestedDefault)\n : undefined,\n dataDirective: 'tabs',\n dataTabTheme:\n typeof node.attributes?.tabTheme === 'string' ? node.attributes.tabTheme : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'tabs',\n openMarker: ':::tabs',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n tabTheme: 'tab',\n theme: 'tabs',\n },\n transformMdast(node) {\n getDirectTabDirectives(node).forEach((tab, index) => {\n const data = (tab.data ??= {})\n data.vlTabIndex = index\n })\n },\n validateMdast(node) {\n const warnings: string[] = []\n const tabs = getDirectTabDirectives(node)\n const values = new Map<string, number>()\n\n if (tabs.length === 0) warnings.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n tabs.forEach((tab, index) => {\n const value = getTabValue(tab, index)\n values.set(value, (values.get(value) ?? 0) + 1)\n })\n\n for (const [value, count] of values)\n if (count > 1) warnings.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (\n typeof node.attributes?.default === 'string' &&\n !resolveTabsDefault(node.attributes.default, getTabsDefaultCandidates(node))\n )\n warnings.push(`Invalid tabs default \"${node.attributes.default}\". Falling back to the first tab.`)\n\n return warnings\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","DIRECTIVE_SURFACE_DIVIDER_CLASS","applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","getTabLabel","getTabDirectiveLabel","getTabRawValue","getTabValue","resolveTabsDefault","slugTabValue","toTabSlug","isContainerDirective","node","Boolean","type","isTabElement","properties","dataVlLayout","getStringProperty","name","value","trim","undefined","getBooleanProperty","index","getRequestedDefault","makeUniqueValue","rawValue","seen","base","count","get","set","collectTabs","reserveIds","Map","children","filter","map","child","panelId","triggerId","disabled","label","themeName","makeTabTrigger","tab","active","className","id","ariaControls","ariaSelected","dataTabTrigger","dataTabValue","role","tabIndex","tagName","makeTabPanel","config","mergeClassNames","fallbackThemeName","theme","themes","ariaLabelledby","hookClassName","modifierClassName","classes","dataTabPanel","dataTheme","hidden","makeTabList","tabs","activeValue","dataTabsList","findActiveTab","requestedDefault","requested","requestedMatch","find","getTabsDefaultCandidates","getDirectTabDirectives","raw","attributes","tabsDirective","allowedAttributes","applyHast","activeTab","tabTheme","dataTabTheme","dataDefault","description","editor","detail","snippet","getMdastRenderProperties","default","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","transformMdast","forEach","data","vlTabIndex","validateMdast","warnings","values","length","push"],"mappings":"AAKA,SAASA,oBAAoB,EAAEC,+BAA+B,QAAQ,mCAAkC;AACxG,SAASC,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SACEC,eAAeC,oBAAoB,EACnCC,cAAc,EACdC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,EACZC,SAAS,QACJ,WAAU;AAYjB,SAASC,qBAAqBC,IAAa;IACzC,OAAOC,QACLD,QACE,OAAOA,SAAS,YAChB,UAAUA,QACV,AAACA,KAA2BE,IAAI,KAAK;AAE3C;AAEA,SAASC,aAAaH,IAAoB;IACxC,OAAOA,KAAKE,IAAI,KAAK,aAAaF,KAAKI,UAAU,EAAEC,iBAAiB;AACtE;AAEA,SAASC,kBACPF,UAA6C,EAC7CG,IAAY;IAEZ,MAAMC,QAAQJ,YAAY,CAACG,KAAK;IAEhC,OAAO,OAAOC,UAAU,YAAYA,MAAMC,IAAI,KAAKD,MAAMC,IAAI,KAAKC;AACpE;AAEA,SAASC,mBAAmBP,UAA6C,EAAEG,IAAY;IACrF,MAAMC,QAAQJ,YAAY,CAACG,KAAK;IAEhC,OAAOC,UAAU,QAAQA,UAAU;AACrC;AAEA,SAAShB,YAAYQ,IAAa,EAAEY,KAAa;IAC/C,OACEN,kBAAkBN,KAAKI,UAAU,EAAE,gBACnCE,kBAAkBN,KAAKI,UAAU,EAAE,gBACnC,CAAC,IAAI,EAAEQ,QAAQ,GAAG;AAEtB;AAEA,SAASC,oBAAoBb,IAAa;IACxC,OAAOM,kBAAkBN,KAAKI,UAAU,EAAE;AAC5C;AAEA,SAASU,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I;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"}
|
|
@@ -22,7 +22,7 @@ export const tocDirective = {
|
|
|
22
22
|
const theme = resolveDirectiveTheme('toc', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
23
23
|
node.properties.dataTheme = theme.name;
|
|
24
24
|
node.properties.className = mergeClassNames('not-prose', // Title reads as a label; entries indent by heading level.
|
|
25
|
-
'[&>p:first-child]:mb-2 [&>p:first-child]:text-xs [&>p:first-child]:font-semibold [&>p:first-child]:uppercase [&>p:first-child]:tracking-[0.18em] [&>p:first-child]:text-(--tw-prose-body)/80', '[&_ol]:
|
|
25
|
+
'[&>p:first-child]:mb-2 [&>p:first-child]:text-xs [&>p:first-child]:font-semibold [&>p:first-child]:uppercase [&>p:first-child]:tracking-[0.18em] [&>p:first-child]:text-(--tw-prose-body)/80', '[&_ol]:mt-0 [&_ol]:mb-2 [&_ol]:list-none [&_ol]:p-0 [&_li+li]:mt-1', "[&_li[data-toc-level='1']]:pl-4 [&_li[data-toc-level='2']]:pl-8 [&_li[data-toc-level='3']]:pl-12 [&_li[data-toc-level='4']]:pl-16 [&_li[data-toc-level='5']]:pl-20", '[&_a]:text-(--tw-prose-body) [&_a]:transition-colors [&_a:hover]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))]', theme.hookClassName, theme.modifierClassName, theme.classes);
|
|
26
26
|
},
|
|
27
27
|
defaultAttributes: {
|
|
28
28
|
depth: String(DEFAULT_TOC_DEPTH),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/toc.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const DEFAULT_TOC_DEPTH = 3\nexport const DEFAULT_TOC_TITLE = 'On this page'\n\nexport function resolveTocDepth(node: ContainerDirective): number {\n const value = node.attributes?.depth\n const parsed = typeof value === 'string' ? Number.parseInt(value, 10) : DEFAULT_TOC_DEPTH\n\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 6 ? parsed : DEFAULT_TOC_DEPTH\n}\n\nexport function resolveTocTitle(node: ContainerDirective): string {\n const title = getDirectiveLabelOrAttribute(node, 'title')\n\n return title ?? DEFAULT_TOC_TITLE\n}\n\nexport const tocDirective: LayoutDirectiveDefinition = {\n name: 'toc',\n allowedAttributes: ['depth', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'toc',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n 'not-prose',\n // 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]:
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/toc.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const DEFAULT_TOC_DEPTH = 3\nexport const DEFAULT_TOC_TITLE = 'On this page'\n\nexport function resolveTocDepth(node: ContainerDirective): number {\n const value = node.attributes?.depth\n const parsed = typeof value === 'string' ? Number.parseInt(value, 10) : DEFAULT_TOC_DEPTH\n\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 6 ? parsed : DEFAULT_TOC_DEPTH\n}\n\nexport function resolveTocTitle(node: ContainerDirective): string {\n const title = getDirectiveLabelOrAttribute(node, 'title')\n\n return title ?? DEFAULT_TOC_TITLE\n}\n\nexport const tocDirective: LayoutDirectiveDefinition = {\n name: 'toc',\n allowedAttributes: ['depth', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'toc',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n 'not-prose',\n // Title reads as a label; entries indent by heading level.\n '[&>p:first-child]:mb-2 [&>p:first-child]:text-xs [&>p:first-child]:font-semibold [&>p:first-child]:uppercase [&>p:first-child]:tracking-[0.18em] [&>p:first-child]:text-(--tw-prose-body)/80',\n '[&_ol]:mt-0 [&_ol]:mb-2 [&_ol]:list-none [&_ol]:p-0 [&_li+li]:mt-1',\n \"[&_li[data-toc-level='1']]:pl-4 [&_li[data-toc-level='2']]:pl-8 [&_li[data-toc-level='3']]:pl-12 [&_li[data-toc-level='4']]:pl-16 [&_li[data-toc-level='5']]:pl-20\",\n '[&_a]:text-(--tw-prose-body) [&_a]:transition-colors [&_a:hover]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))]',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n },\n defaultAttributes: {\n depth: String(DEFAULT_TOC_DEPTH),\n title: DEFAULT_TOC_TITLE,\n },\n description: 'Table of contents generated from document headings.',\n editor: {\n detail: 'Docs directive',\n label: 'Table of contents',\n snippet: ':::toc[${On this page}]{\\n depth=\"${3}\"\\n}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const title = resolveTocTitle(node)\n\n return {\n ariaLabel: title,\n dataDirective: 'toc',\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataTitle: title,\n }\n },\n kind: 'toc',\n openMarker: ':::toc',\n public: true,\n supportsAttributes: true,\n tagName: 'nav',\n themeAttributes: {\n theme: 'toc',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (\n typeof attributes.depth === 'string' &&\n (!Number.isInteger(Number.parseInt(attributes.depth, 10)) ||\n Number.parseInt(attributes.depth, 10) < 1 ||\n Number.parseInt(attributes.depth, 10) > 6)\n )\n warnings.push(`Invalid toc depth \"${attributes.depth}\". Falling back to \"${DEFAULT_TOC_DEPTH}\".`)\n\n return warnings\n },\n validateMdast(node) {\n return node.children.length > 0\n ? [\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.',\n ]\n : []\n },\n}\n"],"names":["getDirectiveLabelOrAttribute","resolveDirectiveTheme","DEFAULT_TOC_DEPTH","DEFAULT_TOC_TITLE","resolveTocDepth","node","value","attributes","depth","parsed","Number","parseInt","isInteger","resolveTocTitle","title","tocDirective","name","allowedAttributes","applyHast","config","mergeClassNames","theme","properties","dataTheme","undefined","themes","className","hookClassName","modifierClassName","classes","defaultAttributes","String","description","editor","detail","label","snippet","getMdastRenderProperties","ariaLabel","dataDirective","dataTitle","kind","openMarker","public","supportsAttributes","tagName","themeAttributes","validateAttributes","warnings","push","validateMdast","children","length"],"mappings":"AAIA,SAASA,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,oBAAoB,EAAC;AAClC,OAAO,MAAMC,oBAAoB,eAAc;AAE/C,OAAO,SAASC,gBAAgBC,IAAwB;IACtD,MAAMC,QAAQD,KAAKE,UAAU,EAAEC;IAC/B,MAAMC,SAAS,OAAOH,UAAU,WAAWI,OAAOC,QAAQ,CAACL,OAAO,MAAMJ;IAExE,OAAOQ,OAAOE,SAAS,CAACH,WAAWA,UAAU,KAAKA,UAAU,IAAIA,SAASP;AAC3E;AAEA,OAAO,SAASW,gBAAgBR,IAAwB;IACtD,MAAMS,QAAQd,6BAA6BK,MAAM;IAEjD,OAAOS,SAASX;AAClB;AAEA,OAAO,MAAMY,eAA0C;IACrDC,MAAM;IACNC,mBAAmB;QAAC;QAAS;QAAS;KAAQ;IAC9CC,WAAUb,IAAI,EAAEc,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMC,QAAQpB,sBACZ,OACA,OAAOI,KAAKiB,UAAU,CAACC,SAAS,KAAK,WAAWlB,KAAKiB,UAAU,CAACC,SAAS,GAAGC,WAC5EL,OAAOM,MAAM;QAGfpB,KAAKiB,UAAU,CAACC,SAAS,GAAGF,MAAML,IAAI;QACtCX,KAAKiB,UAAU,CAACI,SAAS,GAAGN,gBAC1B,aACA,2DAA2D;QAC3D,gMACA,sEACA,sKACA,iLACAC,MAAMM,aAAa,EACnBN,MAAMO,iBAAiB,EACvBP,MAAMQ,OAAO;IAEjB;IACAC,mBAAmB;QACjBtB,OAAOuB,OAAO7B;QACdY,OAAOX;IACT;IACA6B,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyBhC,IAAI;QAC3B,MAAMS,QAAQD,gBAAgBR;QAE9B,OAAO;YACLiC,WAAWxB;YACXyB,eAAe;YACfhB,WAAW,OAAOlB,KAAKE,UAAU,EAAEc,UAAU,WAAWhB,KAAKE,UAAU,CAACc,KAAK,GAAG;YAChFmB,WAAW1B;QACb;IACF;IACA2B,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBC,SAAS;IACTC,iBAAiB;QACfzB,OAAO;IACT;IACA0B,oBAAmB,EAAExC,UAAU,EAAE;QAC/B,MAAMyC,WAAqB,EAAE;QAE7B,IACE,OAAOzC,WAAWC,KAAK,KAAK,YAC3B,CAAA,CAACE,OAAOE,SAAS,CAACF,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,QACnDE,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,MAAM,KACxCE,OAAOC,QAAQ,CAACJ,WAAWC,KAAK,EAAE,MAAM,CAAA,GAE1CwC,SAASC,IAAI,CAAC,CAAC,mBAAmB,EAAE1C,WAAWC,KAAK,CAAC,oBAAoB,EAAEN,kBAAkB,EAAE,CAAC;QAElG,OAAO8C;IACT;IACAE,eAAc7C,IAAI;QAChB,OAAOA,KAAK8C,QAAQ,CAACC,MAAM,GAAG,IAC1B;YACE;SACD,GACD,EAAE;IACR;AACF,EAAC"}
|
|
@@ -12,6 +12,11 @@ export type LintMarkdownDirectivesOptions = {
|
|
|
12
12
|
* reported exactly like the renderer does ("Unknown icon pack").
|
|
13
13
|
*/
|
|
14
14
|
iconPacks?: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Known palette names. When provided, unknown `palette` / `iconPalette`
|
|
17
|
+
* values and icon-entry palettes are reported like the renderer does.
|
|
18
|
+
*/
|
|
19
|
+
palettes?: readonly string[];
|
|
15
20
|
/** Configured directive themes (names are what matters). */
|
|
16
21
|
themes?: MarkdownDirectiveThemes;
|
|
17
22
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getExtraIconWarnings, parseIconEntries } from '../icons/entries.js';
|
|
1
2
|
import { normalizePayloadMarkdownIconRef } from '../icons/refs.js';
|
|
3
|
+
import { collectPaletteNames, formatUnknownPaletteMessage } from '../palettes/diagnostics.js';
|
|
2
4
|
import { parseButtonDirectiveLine } from './buttonSyntax.js';
|
|
3
5
|
import { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js';
|
|
4
6
|
import { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js';
|
|
@@ -8,13 +10,24 @@ import { resolveShieldsBadge } from './shields.js';
|
|
|
8
10
|
import { parseDirectiveSourceTree } from './sourceTree.js';
|
|
9
11
|
import { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js';
|
|
10
12
|
import { isSafeHref } from './urls.js';
|
|
11
|
-
function
|
|
12
|
-
if (typeof icon !== 'string'
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
/** Icon-entry option problems, extra icons, then unknown icon packs (one per entry). */ function getIconDiagnostics(directive, icon, options) {
|
|
14
|
+
if (typeof icon !== 'string') return [];
|
|
15
|
+
const { entries, warnings } = parseIconEntries(icon);
|
|
16
|
+
const diagnostics = [
|
|
17
|
+
...warnings,
|
|
18
|
+
...getExtraIconWarnings(directive, entries)
|
|
17
19
|
];
|
|
20
|
+
if (options.iconPacks) for (const entry of entries){
|
|
21
|
+
const normalized = normalizePayloadMarkdownIconRef(entry.ref);
|
|
22
|
+
if (normalized.icon && !options.iconPacks.includes(normalized.icon.packAlias)) diagnostics.push(`Unknown icon pack "${normalized.icon.packAlias}".`);
|
|
23
|
+
}
|
|
24
|
+
return diagnostics;
|
|
25
|
+
}
|
|
26
|
+
function getPaletteDiagnostics(directive, attributes, options) {
|
|
27
|
+
const known = options.palettes;
|
|
28
|
+
if (!known) return [];
|
|
29
|
+
const allowed = layoutDirectiveRegistry.get(directive)?.allowedAttributes ?? [];
|
|
30
|
+
return collectPaletteNames(allowed, attributes).filter((name)=>!known.includes(name)).map((name)=>formatUnknownPaletteMessage(name, directive, known));
|
|
18
31
|
}
|
|
19
32
|
function findNearestFrameIndex(stack, predicate) {
|
|
20
33
|
for(let index = stack.length - 1; index >= 0; --index){
|
|
@@ -154,7 +167,8 @@ function getThemeDiagnostics(text, options) {
|
|
|
154
167
|
if (!token || token.action !== 'open') return [];
|
|
155
168
|
const definition = layoutDirectiveRegistry.get(token.name);
|
|
156
169
|
const diagnostics = [
|
|
157
|
-
...
|
|
170
|
+
...getIconDiagnostics(token.name, token.attributes?.icon, options),
|
|
171
|
+
...getPaletteDiagnostics(token.name, token.attributes, options)
|
|
158
172
|
];
|
|
159
173
|
if (!definition?.themeAttributes) return diagnostics;
|
|
160
174
|
for (const [attribute, groupName] of Object.entries(definition.themeAttributes)){
|
|
@@ -179,14 +193,16 @@ function getButtonDiagnostics(text, options) {
|
|
|
179
193
|
}) ?? []
|
|
180
194
|
];
|
|
181
195
|
const icon = parsed.attributes.icon;
|
|
182
|
-
|
|
183
|
-
|
|
196
|
+
const [iconEntry] = typeof icon === 'string' ? parseIconEntries(icon).entries : [];
|
|
197
|
+
if (iconEntry) {
|
|
198
|
+
const normalized = normalizePayloadMarkdownIconRef(iconEntry.ref);
|
|
184
199
|
if (normalized.warning) diagnostics.push(normalized.warning);
|
|
185
200
|
}
|
|
186
201
|
if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string') diagnostics.push('Icon-only button requires an ariaLabel attribute.');
|
|
187
202
|
return [
|
|
188
203
|
...diagnostics,
|
|
189
|
-
...
|
|
204
|
+
...getIconDiagnostics('button', icon, options),
|
|
205
|
+
...getPaletteDiagnostics('button', parsed.attributes, options)
|
|
190
206
|
];
|
|
191
207
|
}
|
|
192
208
|
function getBadgeDiagnostics(text) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/directives/diagnostics.ts"],"sourcesContent":["import type { Root } from 'mdast'\n\nimport type { MarkdownDirectiveThemes } from '../types/core.js'\nimport type { TabsDefaultCandidate } from './definitions/tab.js'\nimport type { ScannedDirectiveLine, SourceIndex } from './lineScanner.js'\n\nimport { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\nimport { parseButtonDirectiveLine } from './buttonSyntax.js'\nimport { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js'\nimport { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from './lineScanner.js'\nimport { layoutDirectiveRegistry } from './registry.js'\nimport { resolveShieldsBadge } from './shields.js'\nimport { parseDirectiveSourceTree } from './sourceTree.js'\nimport { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js'\nimport { isSafeHref } from './urls.js'\n\nexport type DirectiveDiagnostic = {\n from: number\n line: number\n message: string\n severity: 'warning'\n to: number\n}\n\ntype OpenFrame = {\n cardsHasHref?: boolean\n cardsLinkScope?: string\n defaultValue?: string\n from: number\n hasContent?: boolean\n line: number\n name: string\n parentHeadingDepth?: number\n tabCandidates?: TabsDefaultCandidate[]\n tabCount?: number\n tabValues?: Map<string, number>\n}\n\ntype LintState = {\n currentHeadingDepth?: number\n options: LintMarkdownDirectivesOptions\n stack: OpenFrame[]\n}\n\nexport type LintMarkdownDirectivesOptions = {\n /**\n * Configured icon pack aliases. When provided, icon refs to other packs are\n * reported exactly like the renderer does (\"Unknown icon pack\").\n */\n iconPacks?: readonly string[]\n /** Configured directive themes (names are what matters). */\n themes?: MarkdownDirectiveThemes\n}\n\nfunction getIconPackDiagnostics(icon: unknown, options: LintMarkdownDirectivesOptions): string[] {\n if (typeof icon !== 'string' || !options.iconPacks) return []\n\n const normalized = normalizePayloadMarkdownIconRef(icon)\n if (!normalized.icon || options.iconPacks.includes(normalized.icon.packAlias)) return []\n\n return [`Unknown icon pack \"${normalized.icon.packAlias}\".`]\n}\n\nfunction findNearestFrameIndex(stack: OpenFrame[], predicate: (frame: OpenFrame) => boolean) {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (predicate(frame)) return index\n }\n\n return -1\n}\n\nfunction getTabValue(\n attributes: Record<string, boolean | string> | undefined,\n index: number,\n label?: string,\n): string {\n return slugTabValue(getTabRawValue(attributes, label) ?? `tab-${index + 1}`, index)\n}\n\nconst TOC_CONTENT_DIAGNOSTIC =\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.'\n\nfunction finalizeFrame(frame: OpenFrame): string[] {\n if (frame.name === 'toc') return frame.hasContent ? [TOC_CONTENT_DIAGNOSTIC] : []\n\n return finalizeTabsFrame(frame)\n}\n\nfunction finalizeTabsFrame(frame: OpenFrame): string[] {\n if (frame.name !== 'tabs') return []\n\n const diagnostics: string[] = []\n const tabValues = frame.tabValues ?? new Map<string, number>()\n\n if (!frame.tabCount) diagnostics.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n for (const [value, count] of tabValues)\n if (count > 1) diagnostics.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (frame.defaultValue && !resolveTabsDefault(frame.defaultValue, frame.tabCandidates ?? []))\n diagnostics.push(`Invalid tabs default \"${frame.defaultValue}\". Falling back to the first tab.`)\n\n return diagnostics\n}\n\nfunction findNearestTabsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'tabs') return frame\n }\n\n return undefined\n}\n\nfunction findNearestCardsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'cards') return frame\n }\n\n return undefined\n}\n\nfunction hasAttribute(\n attributes: Record<string, boolean | string> | undefined,\n name: string,\n): boolean {\n return Object.prototype.hasOwnProperty.call(attributes ?? {}, name)\n}\n\nfunction popFrames(stack: OpenFrame[], index: number): string[] {\n return stack.splice(index).flatMap((frame) => finalizeFrame(frame))\n}\n\nfunction markTopFrameContent(state: LintState) {\n const top = state.stack[state.stack.length - 1]\n if (top) top.hasContent = true\n}\n\n/** Mirrors remarkCompileLayouts: a heading shallower than a grid's parent heading closes the grid. */\nfunction applyHeading(state: LintState, depth: number): string[] {\n markTopFrameContent(state)\n\n const top = state.stack[state.stack.length - 1]\n const diagnostics =\n top &&\n layoutDirectiveRegistry.isGridName(top.name) &&\n typeof top.parentHeadingDepth === 'number' &&\n depth < top.parentHeadingDepth\n ? popFrames(state.stack, state.stack.length - 1)\n : []\n\n state.currentHeadingDepth = depth\n\n return diagnostics\n}\n\nfunction updateOpenStack(\n state: LintState,\n text: string,\n line: number,\n from: number,\n): string[] {\n const { stack } = state\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n const diagnostics: string[] = []\n\n if (!token) return diagnostics\n\n if (token.action === 'open') {\n markTopFrameContent(state)\n\n if (token.name === 'card') {\n const cardsFrame = findNearestCardsFrame(stack)\n const cardsSectionLink =\n cardsFrame?.cardsHasHref &&\n (cardsFrame.cardsLinkScope === undefined || cardsFrame.cardsLinkScope === 'section')\n\n if (\n cardsSectionLink &&\n (hasAttribute(token.attributes, 'href') ||\n hasAttribute(token.attributes, 'linkScope') ||\n hasAttribute(token.attributes, 'newTab'))\n )\n diagnostics.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n if (token.name === 'tab') {\n const tabsFrame = findNearestTabsFrame(stack)\n\n if (!tabsFrame) diagnostics.push('Directive \"tab\" is usually intended inside \"tabs\".')\n else {\n const nextIndex = tabsFrame.tabCount ?? 0\n const value = getTabValue(token.attributes, nextIndex, token.label)\n\n tabsFrame.tabCandidates ??= []\n tabsFrame.tabCandidates.push({\n label: getTabRawValue({ label: token.attributes?.label ?? '' }, token.label) ?? `Tab ${nextIndex + 1}`,\n raw: getTabRawValue(token.attributes),\n value,\n })\n tabsFrame.tabCount = nextIndex + 1\n tabsFrame.tabValues ??= new Map<string, number>()\n tabsFrame.tabValues.set(value, (tabsFrame.tabValues.get(value) ?? 0) + 1)\n }\n }\n\n const isGrid = layoutDirectiveRegistry.isGridName(token.name)\n\n if (isGrid) {\n // remarkCompileLayouts closes an open grid inside the nearest section.\n const gridIndex = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n const sectionIndex = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n\n if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex)\n diagnostics.push(...popFrames(stack, gridIndex))\n }\n\n stack.push({\n name: token.name,\n from,\n line,\n ...(isGrid ? { parentHeadingDepth: state.currentHeadingDepth ?? 1 } : {}),\n ...(token.name === 'cards'\n ? {\n cardsHasHref:\n typeof token.attributes?.href === 'string' && isSafeHref(token.attributes.href.trim()),\n cardsLinkScope:\n typeof token.attributes?.linkScope === 'string'\n ? token.attributes.linkScope\n : undefined,\n }\n : {}),\n ...(token.name === 'tabs'\n ? {\n defaultValue:\n typeof token.attributes?.default === 'string'\n ? token.attributes.default\n : undefined,\n tabCount: 0,\n tabValues: new Map<string, number>(),\n }\n : {}),\n })\n return diagnostics\n }\n\n if (token.action === 'close') {\n if (stack.length === 0) return ['Encountered ::: with no open layout block.']\n\n return popFrames(stack, stack.length - 1)\n }\n\n if (token.action === 'closeGrid') {\n const index = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n\n if (index < 0) return ['Encountered :::endcol with no open grid.']\n\n return popFrames(stack, index)\n }\n\n const index = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n if (index < 0) return ['Encountered :::end or :::endsection with no open section.']\n\n return popFrames(stack, index)\n}\n\nfunction getThemeDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n if (!token || token.action !== 'open') return []\n\n const definition = layoutDirectiveRegistry.get(token.name)\n const diagnostics: string[] = [...getIconPackDiagnostics(token.attributes?.icon, options)]\n\n if (!definition?.themeAttributes) return diagnostics\n\n for (const [attribute, groupName] of Object.entries(definition.themeAttributes)) {\n if (!groupName) continue\n\n const value = token.attributes?.[attribute]\n if (typeof value !== 'string' || !value.trim()) continue\n if (hasDirectiveTheme(groupName, value, options.themes)) continue\n\n const label = attribute === 'theme' ? 'theme' : attribute\n diagnostics.push(\n `Unknown ${label} \"${value}\" on \"${token.name}\". Falling back to \"${getDirectiveFallbackThemeName(groupName, options.themes)}\".`,\n )\n }\n\n return diagnostics\n}\n\nfunction getButtonDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const parsed = parseButtonDirectiveLine(text)\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('button')\n const diagnostics = [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'button', attributes: parsed.attributes }) ?? []),\n ]\n const icon = parsed.attributes.icon\n\n if (typeof icon === 'string') {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n if (normalized.warning) diagnostics.push(normalized.warning)\n }\n\n if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string')\n diagnostics.push('Icon-only button requires an ariaLabel attribute.')\n\n return [...diagnostics, ...getIconPackDiagnostics(icon, options)]\n}\n\nfunction getBadgeDiagnostics(text: string): string[] {\n const parsed = parseLeafDirectiveLine(text, 'badge')\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('badge')\n const resolved = resolveShieldsBadge(parsed.attributes)\n\n return [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'badge', attributes: parsed.attributes }) ?? []),\n ...resolved.warnings,\n ]\n}\n\ntype DiagnosticSink = (message: string, from: number, to: number, line: number) => void\n\nfunction lintContainerLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const result = layoutDirectiveRegistry.parseMarkdownLineDetailed(scanned.text)\n\n for (const message of result.diagnostics) report(message)\n for (const message of getThemeDiagnostics(scanned.text, state.options)) report(message)\n for (const message of updateOpenStack(state, scanned.text, scanned.startLine, scanned.from))\n report(message)\n\n // Tokens that do not open/close anything render as prose inside the frame.\n if (!result.token) markTopFrameContent(state)\n}\n\nfunction lintLeafLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const leafName = getLeafDirectiveName(scanned.text)\n\n markTopFrameContent(state)\n\n if (!leafName) return\n\n if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {\n report(`Unknown directive \"${leafName}\".`)\n return\n }\n\n const problem = getLeafDirectiveProblem(scanned.text, leafName)\n\n if (problem) {\n report(problem)\n return\n }\n\n const messages =\n leafName === 'button'\n ? getButtonDiagnostics(scanned.text, state.options)\n : getBadgeDiagnostics(scanned.text)\n\n for (const message of messages) report(message)\n}\n\nfunction lintParagraph(\n state: LintState,\n paragraph: Root['children'][number],\n index: SourceIndex,\n push: DiagnosticSink,\n) {\n if (paragraph.type !== 'paragraph') return\n\n const lines = splitParagraphIntoLines(paragraph)\n\n for (let lineIndex = 0; lineIndex < lines.length; ++lineIndex) {\n const scanned = scanDirectiveLineAt(lines, lineIndex, index)\n\n if (!scanned) {\n markTopFrameContent(state)\n continue\n }\n\n if (scanned.kind === 'container') lintContainerLine(state, scanned, push)\n else lintLeafLine(state, scanned, push)\n\n lineIndex = scanned.phrasingEnd\n }\n}\n\n/**\n * Editor-side directive diagnostics. The document is parsed with the same\n * remark/GFM front end and the same directive line scanner as the renderer,\n * so code blocks, lists, blockquotes and prose are classified identically.\n * Every renderer warning about directive syntax has an editor counterpart;\n * the renderer's \"Auto-closing unclosed layout block: X\" is reported here as\n * \"Unclosed directive \"X\".\" at the opening marker.\n */\nexport function lintMarkdownDirectives(\n markdown: string,\n options: LintMarkdownDirectivesOptions = {},\n): DirectiveDiagnostic[] {\n const diagnostics: DirectiveDiagnostic[] = []\n const state: LintState = { options, stack: [] }\n const index = createSourceIndex(markdown)\n const tree = parseDirectiveSourceTree(markdown)\n\n const push: DiagnosticSink = (message, from, to, line) =>\n diagnostics.push({ from, line, message, severity: 'warning', to })\n\n const nested = findNestedDirectiveMarkers(tree, index)\n let nestedIndex = 0\n\n const flushNestedBefore = (line: number) => {\n while (nestedIndex < nested.length && nested[nestedIndex].line < line) {\n const marker = nested[nestedIndex++]\n push(getNestedDirectiveMarkerDiagnostic(marker), marker.from, marker.to, marker.line)\n }\n }\n\n for (const node of tree.children) {\n flushNestedBefore(\n ('position' in node ? node.position?.start.line : undefined) ?? Number.POSITIVE_INFINITY,\n )\n\n if (node.type === 'paragraph') {\n lintParagraph(state, node, index, push)\n continue\n }\n\n if (node.type === 'heading') {\n const line = node.position?.start.line ?? 1\n const from = index.lineStarts[line] ?? 0\n\n for (const message of applyHeading(state, node.depth)) push(message, from, from, line)\n continue\n }\n\n markTopFrameContent(state)\n }\n\n flushNestedBefore(Number.POSITIVE_INFINITY)\n\n for (const frame of state.stack) {\n for (const message of finalizeFrame(frame))\n push(message, frame.from, frame.from + frame.name.length + 3, frame.line)\n\n push(`Unclosed directive \"${frame.name}\".`, frame.from, frame.from + frame.name.length + 3, frame.line)\n }\n\n return diagnostics\n}\n"],"names":["normalizePayloadMarkdownIconRef","parseButtonDirectiveLine","getTabRawValue","resolveTabsDefault","slugTabValue","getLeafDirectiveName","getLeafDirectiveProblem","parseLeafDirectiveLine","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","scanDirectiveLineAt","splitParagraphIntoLines","layoutDirectiveRegistry","resolveShieldsBadge","parseDirectiveSourceTree","getDirectiveFallbackThemeName","hasDirectiveTheme","isSafeHref","getIconPackDiagnostics","icon","options","iconPacks","normalized","includes","packAlias","findNearestFrameIndex","stack","predicate","index","length","frame","getTabValue","attributes","label","TOC_CONTENT_DIAGNOSTIC","finalizeFrame","name","hasContent","finalizeTabsFrame","diagnostics","tabValues","Map","tabCount","push","value","count","defaultValue","tabCandidates","findNearestTabsFrame","undefined","findNearestCardsFrame","hasAttribute","Object","prototype","hasOwnProperty","call","popFrames","splice","flatMap","markTopFrameContent","state","top","applyHeading","depth","isGridName","parentHeadingDepth","currentHeadingDepth","updateOpenStack","text","line","from","token","parseMarkdownLineDetailed","action","cardsFrame","cardsSectionLink","cardsHasHref","cardsLinkScope","tabsFrame","nextIndex","raw","set","get","isGrid","gridIndex","sectionIndex","href","trim","linkScope","default","getThemeDiagnostics","definition","themeAttributes","attribute","groupName","entries","themes","getButtonDiagnostics","parsed","warnings","validateAttributes","warning","ariaLabel","getBadgeDiagnostics","resolved","lintContainerLine","scanned","report","message","to","startLine","result","lintLeafLine","leafName","isLeafDirectiveName","problem","messages","lintParagraph","paragraph","type","lines","lineIndex","kind","phrasingEnd","lintMarkdownDirectives","markdown","tree","severity","nested","nestedIndex","flushNestedBefore","marker","node","children","position","start","Number","POSITIVE_INFINITY","lineStarts"],"mappings":"AAMA,SAASA,+BAA+B,QAAQ,mBAAkB;AAClE,SAASC,wBAAwB,QAAQ,oBAAmB;AAC5D,SAASC,cAAc,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,uBAAsB;AACvF,SAASC,oBAAoB,EAAEC,uBAAuB,EAAEC,sBAAsB,QAAQ,kBAAiB;AACvG,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,kCAAkC,EAClCC,mBAAmB,EACnBC,uBAAuB,QAClB,mBAAkB;AACzB,SAASC,uBAAuB,QAAQ,gBAAe;AACvD,SAASC,mBAAmB,QAAQ,eAAc;AAClD,SAASC,wBAAwB,QAAQ,kBAAiB;AAC1D,SAASC,6BAA6B,EAA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KlC,mCAAmC0H,SAASA,OAAO7D,IAAI,EAAE6D,OAAOtB,EAAE,EAAEsB,OAAO9D,IAAI;QACtF;IACF;IAEA,KAAK,MAAM+D,QAAQN,KAAKO,QAAQ,CAAE;QAChCH,kBACE,AAAC,CAAA,cAAcE,OAAOA,KAAKE,QAAQ,EAAEC,MAAMlE,OAAOpB,SAAQ,KAAMuF,OAAOC,iBAAiB;QAG1F,IAAIL,KAAKb,IAAI,KAAK,aAAa;YAC7BF,cAAczD,OAAOwE,MAAMxG,OAAOe;YAClC;QACF;QAEA,IAAIyF,KAAKb,IAAI,KAAK,WAAW;YAC3B,MAAMlD,OAAO+D,KAAKE,QAAQ,EAAEC,MAAMlE,QAAQ;YAC1C,MAAMC,OAAO1C,MAAM8G,UAAU,CAACrE,KAAK,IAAI;YAEvC,KAAK,MAAMuC,WAAW9C,aAAaF,OAAOwE,KAAKrE,KAAK,EAAGpB,KAAKiE,SAAStC,MAAMA,MAAMD;YACjF;QACF;QAEAV,oBAAoBC;IACtB;IAEAsE,kBAAkBM,OAAOC,iBAAiB;IAE1C,KAAK,MAAM3G,SAAS8B,MAAMlC,KAAK,CAAE;QAC/B,KAAK,MAAMkF,WAAWzE,cAAcL,OAClCa,KAAKiE,SAAS9E,MAAMwC,IAAI,EAAExC,MAAMwC,IAAI,GAAGxC,MAAMM,IAAI,CAACP,MAAM,GAAG,GAAGC,MAAMuC,IAAI;QAE1E1B,KAAK,CAAC,oBAAoB,EAAEb,MAAMM,IAAI,CAAC,EAAE,CAAC,EAAEN,MAAMwC,IAAI,EAAExC,MAAMwC,IAAI,GAAGxC,MAAMM,IAAI,CAACP,MAAM,GAAG,GAAGC,MAAMuC,IAAI;IACxG;IAEA,OAAO9B;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/directives/diagnostics.ts"],"sourcesContent":["import type { Root } from 'mdast'\n\nimport type { MarkdownDirectiveThemes } from '../types/core.js'\nimport type { TabsDefaultCandidate } from './definitions/tab.js'\nimport type { ScannedDirectiveLine, SourceIndex } from './lineScanner.js'\n\nimport { getExtraIconWarnings, parseIconEntries } from '../icons/entries.js'\nimport { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\nimport { collectPaletteNames, formatUnknownPaletteMessage } from '../palettes/diagnostics.js'\nimport { parseButtonDirectiveLine } from './buttonSyntax.js'\nimport { getTabRawValue, resolveTabsDefault, slugTabValue } from './definitions/tab.js'\nimport { getLeafDirectiveName, getLeafDirectiveProblem, parseLeafDirectiveLine } from './leafSyntax.js'\nimport {\n createSourceIndex,\n findNestedDirectiveMarkers,\n getNestedDirectiveMarkerDiagnostic,\n scanDirectiveLineAt,\n splitParagraphIntoLines,\n} from './lineScanner.js'\nimport { layoutDirectiveRegistry } from './registry.js'\nimport { resolveShieldsBadge } from './shields.js'\nimport { parseDirectiveSourceTree } from './sourceTree.js'\nimport { getDirectiveFallbackThemeName, hasDirectiveTheme } from './themes.js'\nimport { isSafeHref } from './urls.js'\n\nexport type DirectiveDiagnostic = {\n from: number\n line: number\n message: string\n severity: 'warning'\n to: number\n}\n\ntype OpenFrame = {\n cardsHasHref?: boolean\n cardsLinkScope?: string\n defaultValue?: string\n from: number\n hasContent?: boolean\n line: number\n name: string\n parentHeadingDepth?: number\n tabCandidates?: TabsDefaultCandidate[]\n tabCount?: number\n tabValues?: Map<string, number>\n}\n\ntype LintState = {\n currentHeadingDepth?: number\n options: LintMarkdownDirectivesOptions\n stack: OpenFrame[]\n}\n\nexport type LintMarkdownDirectivesOptions = {\n /**\n * Configured icon pack aliases. When provided, icon refs to other packs are\n * reported exactly like the renderer does (\"Unknown icon pack\").\n */\n iconPacks?: readonly string[]\n /**\n * Known palette names. When provided, unknown `palette` / `iconPalette`\n * values and icon-entry palettes are reported like the renderer does.\n */\n palettes?: readonly string[]\n /** Configured directive themes (names are what matters). */\n themes?: MarkdownDirectiveThemes\n}\n\n/** Icon-entry option problems, extra icons, then unknown icon packs (one per entry). */\nfunction getIconDiagnostics(directive: string, icon: unknown, options: LintMarkdownDirectivesOptions): string[] {\n if (typeof icon !== 'string') return []\n\n const { entries, warnings } = parseIconEntries(icon)\n const diagnostics = [...warnings, ...getExtraIconWarnings(directive, entries)]\n\n if (options.iconPacks)\n for (const entry of entries) {\n const normalized = normalizePayloadMarkdownIconRef(entry.ref)\n if (normalized.icon && !options.iconPacks.includes(normalized.icon.packAlias))\n diagnostics.push(`Unknown icon pack \"${normalized.icon.packAlias}\".`)\n }\n\n return diagnostics\n}\n\nfunction getPaletteDiagnostics(\n directive: string,\n attributes: Record<string, unknown> | undefined,\n options: LintMarkdownDirectivesOptions,\n): string[] {\n const known = options.palettes\n if (!known) return []\n\n const allowed = layoutDirectiveRegistry.get(directive)?.allowedAttributes ?? []\n\n return collectPaletteNames(allowed, attributes)\n .filter((name) => !known.includes(name))\n .map((name) => formatUnknownPaletteMessage(name, directive, known))\n}\n\nfunction findNearestFrameIndex(stack: OpenFrame[], predicate: (frame: OpenFrame) => boolean) {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (predicate(frame)) return index\n }\n\n return -1\n}\n\nfunction getTabValue(\n attributes: Record<string, boolean | string> | undefined,\n index: number,\n label?: string,\n): string {\n return slugTabValue(getTabRawValue(attributes, label) ?? `tab-${index + 1}`, index)\n}\n\nconst TOC_CONTENT_DIAGNOSTIC =\n 'Directive \"toc\" contains authored content; it is rendered after the generated table of contents. Close \":::toc\" with \":::\" on the next line.'\n\nfunction finalizeFrame(frame: OpenFrame): string[] {\n if (frame.name === 'toc') return frame.hasContent ? [TOC_CONTENT_DIAGNOSTIC] : []\n\n return finalizeTabsFrame(frame)\n}\n\nfunction finalizeTabsFrame(frame: OpenFrame): string[] {\n if (frame.name !== 'tabs') return []\n\n const diagnostics: string[] = []\n const tabValues = frame.tabValues ?? new Map<string, number>()\n\n if (!frame.tabCount) diagnostics.push('Directive \"tabs\" has no child \"tab\" directives.')\n\n for (const [value, count] of tabValues)\n if (count > 1) diagnostics.push(`Duplicate tab value \"${value}\" in \"tabs\".`)\n\n if (frame.defaultValue && !resolveTabsDefault(frame.defaultValue, frame.tabCandidates ?? []))\n diagnostics.push(`Invalid tabs default \"${frame.defaultValue}\". Falling back to the first tab.`)\n\n return diagnostics\n}\n\nfunction findNearestTabsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'tabs') return frame\n }\n\n return undefined\n}\n\nfunction findNearestCardsFrame(stack: OpenFrame[]): OpenFrame | undefined {\n for (let index = stack.length - 1; index >= 0; --index) {\n const frame = stack[index]\n if (frame.name === 'cards') return frame\n }\n\n return undefined\n}\n\nfunction hasAttribute(\n attributes: Record<string, boolean | string> | undefined,\n name: string,\n): boolean {\n return Object.prototype.hasOwnProperty.call(attributes ?? {}, name)\n}\n\nfunction popFrames(stack: OpenFrame[], index: number): string[] {\n return stack.splice(index).flatMap((frame) => finalizeFrame(frame))\n}\n\nfunction markTopFrameContent(state: LintState) {\n const top = state.stack[state.stack.length - 1]\n if (top) top.hasContent = true\n}\n\n/** Mirrors remarkCompileLayouts: a heading shallower than a grid's parent heading closes the grid. */\nfunction applyHeading(state: LintState, depth: number): string[] {\n markTopFrameContent(state)\n\n const top = state.stack[state.stack.length - 1]\n const diagnostics =\n top &&\n layoutDirectiveRegistry.isGridName(top.name) &&\n typeof top.parentHeadingDepth === 'number' &&\n depth < top.parentHeadingDepth\n ? popFrames(state.stack, state.stack.length - 1)\n : []\n\n state.currentHeadingDepth = depth\n\n return diagnostics\n}\n\nfunction updateOpenStack(\n state: LintState,\n text: string,\n line: number,\n from: number,\n): string[] {\n const { stack } = state\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n const diagnostics: string[] = []\n\n if (!token) return diagnostics\n\n if (token.action === 'open') {\n markTopFrameContent(state)\n\n if (token.name === 'card') {\n const cardsFrame = findNearestCardsFrame(stack)\n const cardsSectionLink =\n cardsFrame?.cardsHasHref &&\n (cardsFrame.cardsLinkScope === undefined || cardsFrame.cardsLinkScope === 'section')\n\n if (\n cardsSectionLink &&\n (hasAttribute(token.attributes, 'href') ||\n hasAttribute(token.attributes, 'linkScope') ||\n hasAttribute(token.attributes, 'newTab'))\n )\n diagnostics.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n if (token.name === 'tab') {\n const tabsFrame = findNearestTabsFrame(stack)\n\n if (!tabsFrame) diagnostics.push('Directive \"tab\" is usually intended inside \"tabs\".')\n else {\n const nextIndex = tabsFrame.tabCount ?? 0\n const value = getTabValue(token.attributes, nextIndex, token.label)\n\n tabsFrame.tabCandidates ??= []\n tabsFrame.tabCandidates.push({\n label: getTabRawValue({ label: token.attributes?.label ?? '' }, token.label) ?? `Tab ${nextIndex + 1}`,\n raw: getTabRawValue(token.attributes),\n value,\n })\n tabsFrame.tabCount = nextIndex + 1\n tabsFrame.tabValues ??= new Map<string, number>()\n tabsFrame.tabValues.set(value, (tabsFrame.tabValues.get(value) ?? 0) + 1)\n }\n }\n\n const isGrid = layoutDirectiveRegistry.isGridName(token.name)\n\n if (isGrid) {\n // remarkCompileLayouts closes an open grid inside the nearest section.\n const gridIndex = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n const sectionIndex = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n\n if (gridIndex >= 0 && sectionIndex >= 0 && gridIndex > sectionIndex)\n diagnostics.push(...popFrames(stack, gridIndex))\n }\n\n stack.push({\n name: token.name,\n from,\n line,\n ...(isGrid ? { parentHeadingDepth: state.currentHeadingDepth ?? 1 } : {}),\n ...(token.name === 'cards'\n ? {\n cardsHasHref:\n typeof token.attributes?.href === 'string' && isSafeHref(token.attributes.href.trim()),\n cardsLinkScope:\n typeof token.attributes?.linkScope === 'string'\n ? token.attributes.linkScope\n : undefined,\n }\n : {}),\n ...(token.name === 'tabs'\n ? {\n defaultValue:\n typeof token.attributes?.default === 'string'\n ? token.attributes.default\n : undefined,\n tabCount: 0,\n tabValues: new Map<string, number>(),\n }\n : {}),\n })\n return diagnostics\n }\n\n if (token.action === 'close') {\n if (stack.length === 0) return ['Encountered ::: with no open layout block.']\n\n return popFrames(stack, stack.length - 1)\n }\n\n if (token.action === 'closeGrid') {\n const index = findNearestFrameIndex(stack, (frame) =>\n layoutDirectiveRegistry.isGridName(frame.name),\n )\n\n if (index < 0) return ['Encountered :::endcol with no open grid.']\n\n return popFrames(stack, index)\n }\n\n const index = findNearestFrameIndex(stack, (frame) => frame.name === 'section')\n if (index < 0) return ['Encountered :::end or :::endsection with no open section.']\n\n return popFrames(stack, index)\n}\n\nfunction getThemeDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const token = layoutDirectiveRegistry.parseMarkdownLineDetailed(text).token\n if (!token || token.action !== 'open') return []\n\n const definition = layoutDirectiveRegistry.get(token.name)\n const diagnostics: string[] = [\n ...getIconDiagnostics(token.name, token.attributes?.icon, options),\n ...getPaletteDiagnostics(token.name, token.attributes, options),\n ]\n\n if (!definition?.themeAttributes) return diagnostics\n\n for (const [attribute, groupName] of Object.entries(definition.themeAttributes)) {\n if (!groupName) continue\n\n const value = token.attributes?.[attribute]\n if (typeof value !== 'string' || !value.trim()) continue\n if (hasDirectiveTheme(groupName, value, options.themes)) continue\n\n const label = attribute === 'theme' ? 'theme' : attribute\n diagnostics.push(\n `Unknown ${label} \"${value}\" on \"${token.name}\". Falling back to \"${getDirectiveFallbackThemeName(groupName, options.themes)}\".`,\n )\n }\n\n return diagnostics\n}\n\nfunction getButtonDiagnostics(text: string, options: LintMarkdownDirectivesOptions): string[] {\n const parsed = parseButtonDirectiveLine(text)\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('button')\n const diagnostics = [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'button', attributes: parsed.attributes }) ?? []),\n ]\n const icon = parsed.attributes.icon\n const [iconEntry] = typeof icon === 'string' ? parseIconEntries(icon).entries : []\n\n if (iconEntry) {\n const normalized = normalizePayloadMarkdownIconRef(iconEntry.ref)\n if (normalized.warning) diagnostics.push(normalized.warning)\n }\n\n if (!parsed.label.trim() && typeof parsed.attributes.ariaLabel !== 'string')\n diagnostics.push('Icon-only button requires an ariaLabel attribute.')\n\n return [\n ...diagnostics,\n ...getIconDiagnostics('button', icon, options),\n ...getPaletteDiagnostics('button', parsed.attributes, options),\n ]\n}\n\nfunction getBadgeDiagnostics(text: string): string[] {\n const parsed = parseLeafDirectiveLine(text, 'badge')\n if (!parsed) return []\n\n const definition = layoutDirectiveRegistry.get('badge')\n const resolved = resolveShieldsBadge(parsed.attributes)\n\n return [\n ...parsed.warnings,\n ...(definition?.validateAttributes?.({ name: 'badge', attributes: parsed.attributes }) ?? []),\n ...resolved.warnings,\n ]\n}\n\ntype DiagnosticSink = (message: string, from: number, to: number, line: number) => void\n\nfunction lintContainerLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const result = layoutDirectiveRegistry.parseMarkdownLineDetailed(scanned.text)\n\n for (const message of result.diagnostics) report(message)\n for (const message of getThemeDiagnostics(scanned.text, state.options)) report(message)\n for (const message of updateOpenStack(state, scanned.text, scanned.startLine, scanned.from))\n report(message)\n\n // Tokens that do not open/close anything render as prose inside the frame.\n if (!result.token) markTopFrameContent(state)\n}\n\nfunction lintLeafLine(state: LintState, scanned: ScannedDirectiveLine, push: DiagnosticSink) {\n const report = (message: string) => push(message, scanned.from, scanned.to, scanned.startLine)\n const leafName = getLeafDirectiveName(scanned.text)\n\n markTopFrameContent(state)\n\n if (!leafName) return\n\n if (!layoutDirectiveRegistry.isLeafDirectiveName(leafName)) {\n report(`Unknown directive \"${leafName}\".`)\n return\n }\n\n const problem = getLeafDirectiveProblem(scanned.text, leafName)\n\n if (problem) {\n report(problem)\n return\n }\n\n const messages =\n leafName === 'button'\n ? getButtonDiagnostics(scanned.text, state.options)\n : getBadgeDiagnostics(scanned.text)\n\n for (const message of messages) report(message)\n}\n\nfunction lintParagraph(\n state: LintState,\n paragraph: Root['children'][number],\n index: SourceIndex,\n push: DiagnosticSink,\n) {\n if (paragraph.type !== 'paragraph') return\n\n const lines = splitParagraphIntoLines(paragraph)\n\n for (let lineIndex = 0; lineIndex < lines.length; ++lineIndex) {\n const scanned = scanDirectiveLineAt(lines, lineIndex, index)\n\n if (!scanned) {\n markTopFrameContent(state)\n continue\n }\n\n if (scanned.kind === 'container') lintContainerLine(state, scanned, push)\n else lintLeafLine(state, scanned, push)\n\n lineIndex = scanned.phrasingEnd\n }\n}\n\n/**\n * Editor-side directive diagnostics. The document is parsed with the same\n * remark/GFM front end and the same directive line scanner as the renderer,\n * so code blocks, lists, blockquotes and prose are classified identically.\n * Every renderer warning about directive syntax has an editor counterpart;\n * the renderer's \"Auto-closing unclosed layout block: X\" is reported here as\n * \"Unclosed directive \"X\".\" at the opening marker.\n */\nexport function lintMarkdownDirectives(\n markdown: string,\n options: LintMarkdownDirectivesOptions = {},\n): DirectiveDiagnostic[] {\n const diagnostics: DirectiveDiagnostic[] = []\n const state: LintState = { options, stack: [] }\n const index = createSourceIndex(markdown)\n const tree = parseDirectiveSourceTree(markdown)\n\n const push: DiagnosticSink = (message, from, to, line) =>\n diagnostics.push({ from, line, message, severity: 'warning', to })\n\n const nested = findNestedDirectiveMarkers(tree, index)\n let nestedIndex = 0\n\n const flushNestedBefore = (line: number) => {\n while (nestedIndex < nested.length && nested[nestedIndex].line < line) {\n const marker = nested[nestedIndex++]\n push(getNestedDirectiveMarkerDiagnostic(marker), marker.from, marker.to, marker.line)\n }\n }\n\n for (const node of tree.children) {\n flushNestedBefore(\n ('position' in node ? node.position?.start.line : undefined) ?? Number.POSITIVE_INFINITY,\n )\n\n if (node.type === 'paragraph') {\n lintParagraph(state, node, index, push)\n continue\n }\n\n if (node.type === 'heading') {\n const line = node.position?.start.line ?? 1\n const from = index.lineStarts[line] ?? 0\n\n for (const message of applyHeading(state, node.depth)) push(message, from, from, line)\n continue\n }\n\n markTopFrameContent(state)\n }\n\n flushNestedBefore(Number.POSITIVE_INFINITY)\n\n for (const frame of state.stack) {\n for (const message of finalizeFrame(frame))\n push(message, frame.from, frame.from + frame.name.length + 3, frame.line)\n\n push(`Unclosed directive \"${frame.name}\".`, frame.from, frame.from + frame.name.length + 3, frame.line)\n }\n\n return diagnostics\n}\n"],"names":["getExtraIconWarnings","parseIconEntries","normalizePayloadMarkdownIconRef","collectPaletteNames","formatUnknownPaletteMessage","parseButtonDirectiveLine","getTabRawValue","resolveTabsDefault","slugTabValue","getLeafDirectiveName","getLeafDirectiveProblem","parseLeafDirectiveLine","createSourceIndex","findNestedDirectiveMarkers","getNestedDirectiveMarkerDiagnostic","scanDirectiveLineAt","splitParagraphIntoLines","layoutDirectiveRegistry","resolveShieldsBadge","parseDirectiveSourceTree","getDirectiveFallbackThemeName","hasDirectiveTheme","isSafeHref","getIconDiagnostics","directive","icon","options","entries","warnings","diagnostics","iconPacks","entry","normalized","ref","includes","packAlias","push","getPaletteDiagnostics","attributes","known","palettes","allowed","get","allowedAttributes","filter","name","map","findNearestFrameIndex","stack","predicate","index","length","frame","getTabValue","label","TOC_CONTENT_DIAGNOSTIC","finalizeFrame","hasContent","finalizeTabsFrame","tabValues","Map","tabCount","value","count","defaultValue","tabCandidates","findNearestTabsFrame","undefined","findNearestCardsFrame","hasAttribute","Object","prototype","hasOwnProperty","call","popFrames","splice","flatMap","markTopFrameContent","state","top","applyHeading","depth","isGridName","parentHeadingDepth","currentHeadingDepth","updateOpenStack","text","line","from","token","parseMarkdownLineDetailed","action","cardsFrame","cardsSectionLink","cardsHasHref","cardsLinkScope","tabsFrame","nextIndex","raw","set","isGrid","gridIndex","sectionIndex","href","trim","linkScope","default","getThemeDiagnostics","definition","themeAttributes","attribute","groupName","themes","getButtonDiagnostics","parsed","validateAttributes","iconEntry","warning","ariaLabel","getBadgeDiagnostics","resolved","lintContainerLine","scanned","report","message","to","startLine","result","lintLeafLine","leafName","isLeafDirectiveName","problem","messages","lintParagraph","paragraph","type","lines","lineIndex","kind","phrasingEnd","lintMarkdownDirectives","markdown","tree","severity","nested","nestedIndex","flushNestedBefore","marker","node","children","position","start","Number","POSITIVE_INFINITY","lineStarts"],"mappings":"AAMA,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;IAE9E,IAAID,QAAQI,SAAS,EACnB,KAAK,MAAMC,SAASJ,QAAS;QAC3B,MAAMK,aAAa9B,gCAAgC6B,MAAME,GAAG;QAC5D,IAAID,WAAWP,IAAI,IAAI,CAACC,QAAQI,SAAS,CAACI,QAAQ,CAACF,WAAWP,IAAI,CAACU,SAAS,GAC1EN,YAAYO,IAAI,CAAC,CAAC,mBAA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IAAI,GAAGpC,MAAMP,IAAI,CAACM,MAAM,GAAG,GAAGC,MAAMmC,IAAI;IACxG;IAEA,OAAO1D;AACT"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A placeholder that rehypeResolveIcons replaces with the sanitized SVG.
|
|
3
|
+
* `palette` (optional) paints that icon; without it the icon renders exactly
|
|
4
|
+
* as before palettes existed.
|
|
5
|
+
*/
|
|
6
|
+
export declare function makeDirectiveIconPlaceholder(icon: string, className: string[], palette?: string): {
|
|
2
7
|
type: "element";
|
|
3
8
|
children: never[];
|
|
4
9
|
properties: {
|
|
10
|
+
dataPmdIconRef: string;
|
|
11
|
+
focusable: string;
|
|
12
|
+
dataPmdIconPalette?: string | undefined;
|
|
5
13
|
ariaHidden: string;
|
|
6
14
|
className: string[];
|
|
7
15
|
dataPmdIcon: string;
|
|
8
|
-
dataPmdIconRef: string;
|
|
9
|
-
focusable: string;
|
|
10
16
|
};
|
|
11
17
|
tagName: string;
|
|
12
18
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { normalizePayloadMarkdownIconRef } from '../icons/refs.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A placeholder that rehypeResolveIcons replaces with the sanitized SVG.
|
|
4
|
+
* `palette` (optional) paints that icon; without it the icon renders exactly
|
|
5
|
+
* as before palettes existed.
|
|
6
|
+
*/ export function makeDirectiveIconPlaceholder(icon, className, palette) {
|
|
3
7
|
const normalized = normalizePayloadMarkdownIconRef(icon);
|
|
4
8
|
const iconKey = normalized.icon?.key ?? icon;
|
|
5
9
|
return {
|
|
@@ -9,6 +13,9 @@ export function makeDirectiveIconPlaceholder(icon, className) {
|
|
|
9
13
|
ariaHidden: 'true',
|
|
10
14
|
className,
|
|
11
15
|
dataPmdIcon: iconKey,
|
|
16
|
+
...palette ? {
|
|
17
|
+
dataPmdIconPalette: palette
|
|
18
|
+
} : {},
|
|
12
19
|
dataPmdIconRef: icon,
|
|
13
20
|
focusable: 'false'
|
|
14
21
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/directives/iconPlaceholder.ts"],"sourcesContent":["import { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\n\nexport function makeDirectiveIconPlaceholder(icon: string, className: string[]) {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n const iconKey = normalized.icon?.key ?? icon\n\n return {\n type: 'element' as const,\n children: [],\n properties: {\n ariaHidden: 'true',\n className,\n dataPmdIcon: iconKey,\n dataPmdIconRef: icon,\n focusable: 'false',\n },\n tagName: 'span',\n }\n}\n"],"names":["normalizePayloadMarkdownIconRef","makeDirectiveIconPlaceholder","icon","className","normalized","iconKey","key","type","children","properties","ariaHidden","dataPmdIcon","dataPmdIconRef","focusable","tagName"],"mappings":"AAAA,SAASA,+BAA+B,QAAQ,mBAAkB;AAElE,OAAO,SAASC,6BAA6BC,IAAY,EAAEC,SAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/directives/iconPlaceholder.ts"],"sourcesContent":["import { normalizePayloadMarkdownIconRef } from '../icons/refs.js'\n\n/**\n * A placeholder that rehypeResolveIcons replaces with the sanitized SVG.\n * `palette` (optional) paints that icon; without it the icon renders exactly\n * as before palettes existed.\n */\nexport function makeDirectiveIconPlaceholder(icon: string, className: string[], palette?: string) {\n const normalized = normalizePayloadMarkdownIconRef(icon)\n const iconKey = normalized.icon?.key ?? icon\n\n return {\n type: 'element' as const,\n children: [],\n properties: {\n ariaHidden: 'true',\n className,\n dataPmdIcon: iconKey,\n ...(palette ? { dataPmdIconPalette: palette } : {}),\n dataPmdIconRef: icon,\n focusable: 'false',\n },\n tagName: 'span',\n }\n}\n"],"names":["normalizePayloadMarkdownIconRef","makeDirectiveIconPlaceholder","icon","className","palette","normalized","iconKey","key","type","children","properties","ariaHidden","dataPmdIcon","dataPmdIconPalette","dataPmdIconRef","focusable","tagName"],"mappings":"AAAA,SAASA,+BAA+B,QAAQ,mBAAkB;AAElE;;;;CAIC,GACD,OAAO,SAASC,6BAA6BC,IAAY,EAAEC,SAAmB,EAAEC,OAAgB;IAC9F,MAAMC,aAAaL,gCAAgCE;IACnD,MAAMI,UAAUD,WAAWH,IAAI,EAAEK,OAAOL;IAExC,OAAO;QACLM,MAAM;QACNC,UAAU,EAAE;QACZC,YAAY;YACVC,YAAY;YACZR;YACAS,aAAaN;YACb,GAAIF,UAAU;gBAAES,oBAAoBT;YAAQ,IAAI,CAAC,CAAC;YAClDU,gBAAgBZ;YAChBa,WAAW;QACb;QACAC,SAAS;IACX;AACF"}
|