payload-markdown 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -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.client.js +9 -19
- package/dist/components/MarkdownRenderer/Component.client.js.map +1 -1
- package/dist/components/MarkdownRenderer/Component.js +59 -21
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/components/MarkdownRenderer/index.css +93 -42
- package/dist/components/MarkdownRenderer/index.scss +128 -57
- package/dist/core/codeToHtml.js +6 -0
- package/dist/core/codeToHtml.js.map +1 -1
- package/dist/core/plugins/directiveBadge.js +2 -0
- package/dist/core/plugins/directiveBadge.js.map +1 -1
- package/dist/core/plugins/directiveButton.d.ts +1 -1
- package/dist/core/plugins/directiveButton.js +26 -6
- package/dist/core/plugins/directiveButton.js.map +1 -1
- package/dist/core/plugins/rehypeContentLayout.d.ts +12 -0
- package/dist/core/plugins/rehypeContentLayout.js +64 -0
- package/dist/core/plugins/rehypeContentLayout.js.map +1 -0
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js +8 -0
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.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 +19 -4
- 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 +29 -13
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +2 -2
- package/dist/directives/definitions/card.js +44 -11
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.js +19 -6
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/cell.js +4 -2
- package/dist/directives/definitions/cell.js.map +1 -1
- package/dist/directives/definitions/columns.js +2 -1
- package/dist/directives/definitions/columns.js.map +1 -1
- package/dist/directives/definitions/details.js +9 -3
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.js +5 -1
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.js +38 -14
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tab.js +2 -1
- package/dist/directives/definitions/tab.js.map +1 -1
- package/dist/directives/definitions/tabs.js +13 -6
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.js +2 -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/shields.js +16 -3
- package/dist/directives/shields.js.map +1 -1
- 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/directives/themes.js +13 -13
- package/dist/directives/themes.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/exports/render.d.ts +2 -1
- package/dist/exports/render.js +1 -0
- package/dist/exports/render.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 +23 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/styles/directiveSurface.d.ts +39 -5
- package/dist/styles/directiveSurface.js +56 -13
- package/dist/styles/directiveSurface.js.map +1 -1
- package/dist/types/core.d.ts +56 -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 +2 -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 { getUnknownAttributeWarnings } from '../attributeDiagnostics.js';
|
|
2
|
+
import { applyDirectivePalette } from '../palette.js';
|
|
2
3
|
import { getUnsafeHrefWarnings } from '../urls.js';
|
|
3
4
|
export const BUTTON_VARIANTS = [
|
|
4
5
|
'primary',
|
|
@@ -20,8 +21,10 @@ export const BUTTON_ALLOWED_ATTRIBUTES = [
|
|
|
20
21
|
'ariaLabel',
|
|
21
22
|
'href',
|
|
22
23
|
'icon',
|
|
24
|
+
'iconPalette',
|
|
23
25
|
'iconPosition',
|
|
24
26
|
'newTab',
|
|
27
|
+
'palette',
|
|
25
28
|
'size',
|
|
26
29
|
'variant'
|
|
27
30
|
];
|
|
@@ -40,12 +43,16 @@ export function isButtonIconPosition(value) {
|
|
|
40
43
|
export const buttonDirective = {
|
|
41
44
|
name: 'button',
|
|
42
45
|
allowedAttributes: BUTTON_ALLOWED_ATTRIBUTES,
|
|
43
|
-
applyHast (node,
|
|
46
|
+
applyHast (node, config, { mergeClassNames }) {
|
|
44
47
|
const variant = isButtonVariant(node.properties.dataVariant) ? node.properties.dataVariant : DEFAULT_BUTTON_VARIANT;
|
|
45
48
|
const size = isButtonSize(node.properties.dataSize) ? node.properties.dataSize : DEFAULT_BUTTON_SIZE;
|
|
49
|
+
// The sanitizer strips classes on links, so icon-only is read from the
|
|
50
|
+
// content: no label text, only the icon.
|
|
51
|
+
const iconOnly = node.children.length > 0 && node.children.every((child)=>child.type === 'element' || child.type === 'text' && !child.value.trim());
|
|
46
52
|
node.properties.dataVariant = variant;
|
|
47
53
|
node.properties.dataSize = size;
|
|
48
|
-
node.properties.className = mergeClassNames('pmd-button', `pmd-button--${variant}`, `pmd-button--${size}
|
|
54
|
+
node.properties.className = mergeClassNames('pmd-button', `pmd-button--${variant}`, `pmd-button--${size}`, iconOnly ? 'pmd-button--icon-only' : undefined);
|
|
55
|
+
applyDirectivePalette(node, config, 'button');
|
|
49
56
|
},
|
|
50
57
|
attributeValues: {
|
|
51
58
|
iconPosition: BUTTON_ICON_POSITIONS,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/button.ts"],"sourcesContent":["import type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getUnknownAttributeWarnings } from '../attributeDiagnostics.js'\nimport { getUnsafeHrefWarnings } from '../urls.js'\n\nexport const BUTTON_VARIANTS = ['primary', 'secondary', 'outline', 'ghost', 'link'] as const\nexport const BUTTON_SIZES = ['sm', 'md', 'lg'] as const\nexport const BUTTON_ICON_POSITIONS = ['left', 'right'] as const\nexport const BUTTON_ALLOWED_ATTRIBUTES = [\n 'ariaLabel',\n 'href',\n 'icon',\n 'iconPosition',\n 'newTab',\n 'size',\n 'variant',\n] as const\n\nexport const DEFAULT_BUTTON_VARIANT = 'primary'\nexport const DEFAULT_BUTTON_SIZE = 'md'\nexport const DEFAULT_BUTTON_ICON_POSITION = 'left'\n\nexport type ButtonVariant = (typeof BUTTON_VARIANTS)[number]\nexport type ButtonSize = (typeof BUTTON_SIZES)[number]\nexport type ButtonIconPosition = (typeof BUTTON_ICON_POSITIONS)[number]\n\nexport function isButtonVariant(value: unknown): value is ButtonVariant {\n return typeof value === 'string' && BUTTON_VARIANTS.includes(value as ButtonVariant)\n}\n\nexport function isButtonSize(value: unknown): value is ButtonSize {\n return typeof value === 'string' && BUTTON_SIZES.includes(value as ButtonSize)\n}\n\nexport function isButtonIconPosition(value: unknown): value is ButtonIconPosition {\n return typeof value === 'string' && BUTTON_ICON_POSITIONS.includes(value as ButtonIconPosition)\n}\n\nexport const buttonDirective: LayoutDirectiveDefinition = {\n name: 'button',\n allowedAttributes: BUTTON_ALLOWED_ATTRIBUTES,\n applyHast(node,
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/button.ts"],"sourcesContent":["import type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { getUnknownAttributeWarnings } from '../attributeDiagnostics.js'\nimport { applyDirectivePalette } from '../palette.js'\nimport { getUnsafeHrefWarnings } from '../urls.js'\n\nexport const BUTTON_VARIANTS = ['primary', 'secondary', 'outline', 'ghost', 'link'] as const\nexport const BUTTON_SIZES = ['sm', 'md', 'lg'] as const\nexport const BUTTON_ICON_POSITIONS = ['left', 'right'] as const\nexport const BUTTON_ALLOWED_ATTRIBUTES = [\n 'ariaLabel',\n 'href',\n 'icon',\n 'iconPalette',\n 'iconPosition',\n 'newTab',\n 'palette',\n 'size',\n 'variant',\n] as const\n\nexport const DEFAULT_BUTTON_VARIANT = 'primary'\nexport const DEFAULT_BUTTON_SIZE = 'md'\nexport const DEFAULT_BUTTON_ICON_POSITION = 'left'\n\nexport type ButtonVariant = (typeof BUTTON_VARIANTS)[number]\nexport type ButtonSize = (typeof BUTTON_SIZES)[number]\nexport type ButtonIconPosition = (typeof BUTTON_ICON_POSITIONS)[number]\n\nexport function isButtonVariant(value: unknown): value is ButtonVariant {\n return typeof value === 'string' && BUTTON_VARIANTS.includes(value as ButtonVariant)\n}\n\nexport function isButtonSize(value: unknown): value is ButtonSize {\n return typeof value === 'string' && BUTTON_SIZES.includes(value as ButtonSize)\n}\n\nexport function isButtonIconPosition(value: unknown): value is ButtonIconPosition {\n return typeof value === 'string' && BUTTON_ICON_POSITIONS.includes(value as ButtonIconPosition)\n}\n\nexport const buttonDirective: LayoutDirectiveDefinition = {\n name: 'button',\n allowedAttributes: BUTTON_ALLOWED_ATTRIBUTES,\n applyHast(node, config, { mergeClassNames }) {\n const variant = isButtonVariant(node.properties.dataVariant)\n ? node.properties.dataVariant\n : DEFAULT_BUTTON_VARIANT\n const size = isButtonSize(node.properties.dataSize) ? node.properties.dataSize : DEFAULT_BUTTON_SIZE\n // The sanitizer strips classes on links, so icon-only is read from the\n // content: no label text, only the icon.\n const iconOnly =\n node.children.length > 0 &&\n node.children.every((child) => child.type === 'element' || (child.type === 'text' && !child.value.trim()))\n\n node.properties.dataVariant = variant\n node.properties.dataSize = size\n node.properties.className = mergeClassNames(\n 'pmd-button',\n `pmd-button--${variant}`,\n `pmd-button--${size}`,\n iconOnly ? 'pmd-button--icon-only' : undefined,\n )\n applyDirectivePalette(node, config, 'button')\n },\n attributeValues: {\n iconPosition: BUTTON_ICON_POSITIONS,\n newTab: ['true', 'false'],\n size: BUTTON_SIZES,\n variant: BUTTON_VARIANTS,\n },\n defaultAttributes: {\n iconPosition: DEFAULT_BUTTON_ICON_POSITION,\n newTab: 'false',\n size: DEFAULT_BUTTON_SIZE,\n variant: DEFAULT_BUTTON_VARIANT,\n },\n description: 'Link button with optional icon, variant, size, and new-tab behavior.',\n editor: {\n detail: 'Button leaf directive',\n label: '::button',\n snippet: '::button[${Label}]{\\n href=\"${/docs}\"\\n variant=\"${primary}\"\\n}\\n${}',\n snippets: [\n {\n detail: 'Button snippet variant; inserts canonical ::button',\n label: '::button_icon',\n snippet:\n '::button[${Label}]{\\n href=\"${/docs}\"\\n variant=\"${primary}\"\\n icon=\"${@fa-duotone/book-open}\"\\n}\\n${}',\n },\n {\n detail: 'Button snippet variant; inserts canonical ::button',\n label: '::button_full',\n snippet:\n '::button[${Label}]{\\n href=\"${/docs}\"\\n variant=\"${primary}\"\\n size=\"${md}\"\\n icon=\"${@fa-duotone/book-open}\"\\n iconPosition=\"${left}\"\\n newTab=${false}\\n ariaLabel=\"${}\"\\n}',\n },\n ],\n },\n kind: 'button',\n public: true,\n supportsAttributes: true,\n tagName: 'a',\n validateAttributes({ attributes }) {\n const warnings: string[] = getUnknownAttributeWarnings(\n 'button',\n BUTTON_ALLOWED_ATTRIBUTES,\n attributes,\n )\n\n if (typeof attributes.variant === 'string' && !isButtonVariant(attributes.variant))\n warnings.push(\n `Invalid button variant \"${attributes.variant}\". Falling back to \"${DEFAULT_BUTTON_VARIANT}\".`,\n )\n\n if (typeof attributes.size === 'string' && !isButtonSize(attributes.size))\n warnings.push(\n `Invalid button size \"${attributes.size}\". Falling back to \"${DEFAULT_BUTTON_SIZE}\".`,\n )\n\n if (\n typeof attributes.iconPosition === 'string' &&\n !isButtonIconPosition(attributes.iconPosition)\n )\n warnings.push(\n `Invalid button iconPosition \"${attributes.iconPosition}\". Falling back to \"${DEFAULT_BUTTON_ICON_POSITION}\".`,\n )\n\n if (typeof attributes.href !== 'string' || !attributes.href.trim())\n warnings.push('Directive \"button\" requires an href attribute.')\n else warnings.push(...getUnsafeHrefWarnings('button', attributes))\n\n return warnings\n },\n}\n"],"names":["getUnknownAttributeWarnings","applyDirectivePalette","getUnsafeHrefWarnings","BUTTON_VARIANTS","BUTTON_SIZES","BUTTON_ICON_POSITIONS","BUTTON_ALLOWED_ATTRIBUTES","DEFAULT_BUTTON_VARIANT","DEFAULT_BUTTON_SIZE","DEFAULT_BUTTON_ICON_POSITION","isButtonVariant","value","includes","isButtonSize","isButtonIconPosition","buttonDirective","name","allowedAttributes","applyHast","node","config","mergeClassNames","variant","properties","dataVariant","size","dataSize","iconOnly","children","length","every","child","type","trim","className","undefined","attributeValues","iconPosition","newTab","defaultAttributes","description","editor","detail","label","snippet","snippets","kind","public","supportsAttributes","tagName","validateAttributes","attributes","warnings","push","href"],"mappings":"AAEA,SAASA,2BAA2B,QAAQ,6BAA4B;AACxE,SAASC,qBAAqB,QAAQ,gBAAe;AACrD,SAASC,qBAAqB,QAAQ,aAAY;AAElD,OAAO,MAAMC,kBAAkB;IAAC;IAAW;IAAa;IAAW;IAAS;CAAO,CAAS;AAC5F,OAAO,MAAMC,eAAe;IAAC;IAAM;IAAM;CAAK,CAAS;AACvD,OAAO,MAAMC,wBAAwB;IAAC;IAAQ;CAAQ,CAAS;AAC/D,OAAO,MAAMC,4BAA4B;IACvC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAEV,OAAO,MAAMC,yBAAyB,UAAS;AAC/C,OAAO,MAAMC,sBAAsB,KAAI;AACvC,OAAO,MAAMC,+BAA+B,OAAM;AAMlD,OAAO,SAASC,gBAAgBC,KAAc;IAC5C,OAAO,OAAOA,UAA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QACRC,OAAO;QACPC,SAAS;QACTC,UAAU;YACR;gBACEH,QAAQ;gBACRC,OAAO;gBACPC,SACE;YACJ;YACA;gBACEF,QAAQ;gBACRC,OAAO;gBACPC,SACE;YACJ;SACD;IACH;IACAE,MAAM;IACNC,QAAQ;IACRC,oBAAoB;IACpBC,SAAS;IACTC,oBAAmB,EAAEC,UAAU,EAAE;QAC/B,MAAMC,WAAqBpD,4BACzB,UACAM,2BACA6C;QAGF,IAAI,OAAOA,WAAW7B,OAAO,KAAK,YAAY,CAACZ,gBAAgByC,WAAW7B,OAAO,GAC/E8B,SAASC,IAAI,CACX,CAAC,wBAAwB,EAAEF,WAAW7B,OAAO,CAAC,oBAAoB,EAAEf,uBAAuB,EAAE,CAAC;QAGlG,IAAI,OAAO4C,WAAW1B,IAAI,KAAK,YAAY,CAACZ,aAAasC,WAAW1B,IAAI,GACtE2B,SAASC,IAAI,CACX,CAAC,qBAAqB,EAAEF,WAAW1B,IAAI,CAAC,oBAAoB,EAAEjB,oBAAoB,EAAE,CAAC;QAGzF,IACE,OAAO2C,WAAWd,YAAY,KAAK,YACnC,CAACvB,qBAAqBqC,WAAWd,YAAY,GAE7Ce,SAASC,IAAI,CACX,CAAC,6BAA6B,EAAEF,WAAWd,YAAY,CAAC,oBAAoB,EAAE5B,6BAA6B,EAAE,CAAC;QAGlH,IAAI,OAAO0C,WAAWG,IAAI,KAAK,YAAY,CAACH,WAAWG,IAAI,CAACrB,IAAI,IAC9DmB,SAASC,IAAI,CAAC;aACXD,SAASC,IAAI,IAAInD,sBAAsB,UAAUiD;QAEtD,OAAOC;IACT;AACF,EAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { parseIconEntries } from '../../icons/entries.js';
|
|
2
|
+
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
1
3
|
import { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js';
|
|
2
4
|
import { getDirectiveLabelOrAttribute } from '../labels.js';
|
|
5
|
+
import { applyDirectivePalette, getPaletteRenderProperties, PALETTE_ATTRIBUTES, resolveIconPaletteName } from '../palette.js';
|
|
3
6
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
4
7
|
export const CALLOUT_VARIANTS = [
|
|
5
8
|
'note',
|
|
@@ -9,13 +12,17 @@ export const CALLOUT_VARIANTS = [
|
|
|
9
12
|
'danger',
|
|
10
13
|
'success'
|
|
11
14
|
];
|
|
15
|
+
// The tint is a background-image so it layers over the theme's background
|
|
16
|
+
// color instead of competing with it, and the ring composes with the theme's
|
|
17
|
+
// shadow. Text, title and ring colours follow the colour scheme through
|
|
18
|
+
// `--pmd-scheme-dark` (see styles/directiveSurface.ts).
|
|
12
19
|
const calloutVariantClasses = {
|
|
13
|
-
danger: 'bg-red-500/10
|
|
14
|
-
info: 'bg-sky-500/10
|
|
15
|
-
note: 'bg-slate-500/10
|
|
16
|
-
success: 'bg-emerald-500/10
|
|
17
|
-
tip: 'bg-
|
|
18
|
-
warning: 'bg-amber-500/10
|
|
20
|
+
danger: 'bg-linear-to-r from-red-500/10 to-red-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(248_113_113/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(220_38_38/0.2))] text-[color:color-mix(in_oklab,rgb(254_242_242)_calc(var(--pmd-scheme-dark,1)*100%),rgb(69_10_10))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(252_165_165)_calc(var(--pmd-scheme-dark,1)*100%),rgb(185_28_28))]',
|
|
21
|
+
info: 'bg-linear-to-r from-sky-500/10 to-sky-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(56_189_248/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(2_132_199/0.2))] text-[color:color-mix(in_oklab,rgb(240_249_255)_calc(var(--pmd-scheme-dark,1)*100%),rgb(8_47_73))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(125_211_252)_calc(var(--pmd-scheme-dark,1)*100%),rgb(3_105_161))]',
|
|
22
|
+
note: 'bg-linear-to-r from-slate-500/10 to-slate-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(148_163_184/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(100_116_139/0.2))] text-[color:color-mix(in_oklab,rgb(248_250_252)_calc(var(--pmd-scheme-dark,1)*100%),rgb(15_23_42))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(203_213_225)_calc(var(--pmd-scheme-dark,1)*100%),rgb(71_85_105))]',
|
|
23
|
+
success: 'bg-linear-to-r from-emerald-500/10 to-emerald-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(52_211_153/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(5_150_105/0.2))] text-[color:color-mix(in_oklab,rgb(236_253_245)_calc(var(--pmd-scheme-dark,1)*100%),rgb(2_44_34))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(110_231_183)_calc(var(--pmd-scheme-dark,1)*100%),rgb(4_120_87))]',
|
|
24
|
+
tip: 'bg-linear-to-r from-violet-500/10 to-violet-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(167_139_250/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(124_58_237/0.2))] text-[color:color-mix(in_oklab,rgb(245_243_255)_calc(var(--pmd-scheme-dark,1)*100%),rgb(46_16_101))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(196_181_253)_calc(var(--pmd-scheme-dark,1)*100%),rgb(109_40_217))]',
|
|
25
|
+
warning: 'bg-linear-to-r from-amber-500/10 to-amber-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(251_191_36/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(217_119_6/0.2))] text-[color:color-mix(in_oklab,rgb(255_251_235)_calc(var(--pmd-scheme-dark,1)*100%),rgb(69_26_3))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(252_211_77)_calc(var(--pmd-scheme-dark,1)*100%),rgb(146_64_14))]'
|
|
19
26
|
};
|
|
20
27
|
function isCalloutVariant(value) {
|
|
21
28
|
return typeof value === 'string' && CALLOUT_VARIANTS.includes(value);
|
|
@@ -31,6 +38,7 @@ export const calloutDirective = {
|
|
|
31
38
|
name: 'callout',
|
|
32
39
|
allowedAttributes: [
|
|
33
40
|
'icon',
|
|
41
|
+
...PALETTE_ATTRIBUTES,
|
|
34
42
|
'theme',
|
|
35
43
|
'title',
|
|
36
44
|
'variant'
|
|
@@ -38,11 +46,16 @@ export const calloutDirective = {
|
|
|
38
46
|
applyHast (node, config, { mergeClassNames }) {
|
|
39
47
|
const variant = typeof node.properties.dataVariant === 'string' ? node.properties.dataVariant : 'note';
|
|
40
48
|
const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined;
|
|
41
|
-
|
|
49
|
+
// A callout shows one icon; it may carry its own palette (`@pack/name palette=x`).
|
|
50
|
+
const [iconEntry] = parseIconEntries(typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined).entries;
|
|
51
|
+
const icon = iconEntry?.ref;
|
|
42
52
|
const theme = resolveDirectiveTheme('callout', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : 'soft', config.themes);
|
|
43
53
|
const children = node.children;
|
|
54
|
+
// An icon without a title sits beside the body instead of on its own row.
|
|
55
|
+
const iconBesideBody = Boolean(icon && !title);
|
|
44
56
|
node.properties.dataTheme = theme.name;
|
|
45
|
-
node.properties.className = mergeClassNames('
|
|
57
|
+
node.properties.className = mergeClassNames(iconBesideBody ? 'flex items-start gap-3' : undefined, theme.hookClassName, theme.modifierClassName, theme.classes, calloutVariantClasses[isCalloutVariant(variant) ? variant : 'note']);
|
|
58
|
+
applyDirectivePalette(node, config);
|
|
46
59
|
node.children = [
|
|
47
60
|
...title || icon ? [
|
|
48
61
|
{
|
|
@@ -50,8 +63,9 @@ export const calloutDirective = {
|
|
|
50
63
|
children: [
|
|
51
64
|
...icon ? [
|
|
52
65
|
makeDirectiveIconPlaceholder(icon, [
|
|
53
|
-
'pmd-callout__icon inline-flex size-4 shrink-0 text-current'
|
|
54
|
-
|
|
66
|
+
'pmd-callout__icon inline-flex size-4 shrink-0 text-current',
|
|
67
|
+
iconBesideBody ? 'mt-1.5' : 'mt-0.5'
|
|
68
|
+
], resolveIconPaletteName(node, iconEntry))
|
|
55
69
|
] : [],
|
|
56
70
|
...title ? [
|
|
57
71
|
{
|
|
@@ -62,7 +76,7 @@ export const calloutDirective = {
|
|
|
62
76
|
],
|
|
63
77
|
properties: {
|
|
64
78
|
className: [
|
|
65
|
-
'mb-2 flex items-
|
|
79
|
+
iconBesideBody ? 'not-prose flex shrink-0' : 'not-prose mb-2 flex items-start gap-2 text-sm font-semibold tracking-wide'
|
|
66
80
|
],
|
|
67
81
|
dataDirectiveTitle: 'callout'
|
|
68
82
|
},
|
|
@@ -74,8 +88,9 @@ export const calloutDirective = {
|
|
|
74
88
|
children,
|
|
75
89
|
properties: {
|
|
76
90
|
className: [
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
DIRECTIVE_BODY_CLASS,
|
|
92
|
+
iconBesideBody ? 'min-w-0 flex-1' : ''
|
|
93
|
+
].filter(Boolean),
|
|
79
94
|
dataDirectiveBody: 'callout'
|
|
80
95
|
},
|
|
81
96
|
tagName: 'div'
|
|
@@ -95,6 +110,7 @@ export const calloutDirective = {
|
|
|
95
110
|
return {
|
|
96
111
|
dataDirective: 'callout',
|
|
97
112
|
dataIcon: typeof node.attributes?.icon === 'string' ? node.attributes.icon : undefined,
|
|
113
|
+
...getPaletteRenderProperties(node),
|
|
98
114
|
dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'soft',
|
|
99
115
|
dataTitle: getTitle(node),
|
|
100
116
|
dataVariant: resolveCalloutVariant(node)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/callout.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const CALLOUT_VARIANTS = [\n 'note',\n 'info',\n 'tip',\n 'warning',\n 'danger',\n 'success',\n] as const\n\nexport type CalloutVariant = (typeof CALLOUT_VARIANTS)[number]\n\nconst calloutVariantClasses: Record<CalloutVariant, string> = {\n danger: 'bg-red-500/10 text-red-50',\n info: 'bg-sky-500/10 text-sky-50',\n note: 'bg-slate-500/10 text-slate-50',\n success: 'bg-emerald-500/10 text-emerald-50',\n tip: 'bg-cyan-500/10 text-cyan-50',\n warning: 'bg-amber-500/10 text-amber-50',\n}\n\nfunction isCalloutVariant(value: unknown): value is CalloutVariant {\n return typeof value === 'string' && CALLOUT_VARIANTS.includes(value as CalloutVariant)\n}\n\nexport function resolveCalloutVariant(node: ContainerDirective): CalloutVariant {\n const variant = node.attributes?.variant\n\n return isCalloutVariant(variant) ? variant : 'note'\n}\n\nfunction getTitle(node: ContainerDirective): string | undefined {\n return getDirectiveLabelOrAttribute(node, 'title')\n}\n\nexport const calloutDirective: LayoutDirectiveDefinition = {\n name: 'callout',\n allowedAttributes: ['icon', 'theme', 'title', 'variant'],\n applyHast(node, config, { mergeClassNames }) {\n const variant = typeof node.properties.dataVariant === 'string' ? node.properties.dataVariant : 'note'\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined\n const icon = typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined\n const theme = resolveDirectiveTheme(\n 'callout',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : 'soft',\n config.themes,\n )\n const children = node.children\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n 'not-prose',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n calloutVariantClasses[isCalloutVariant(variant) ? variant : 'note'],\n )\n\n node.children = [\n ...(title || icon\n ? [\n {\n type: 'element' as const,\n children: [\n ...(icon\n ? [\n makeDirectiveIconPlaceholder(icon, [\n 'pmd-callout__icon inline-flex size-4 shrink-0 text-current',\n ]),\n ]\n : []),\n ...(title ? [{ type: 'text' as const, value: title }] : []),\n ],\n properties: {\n className: ['mb-2 flex items-center gap-2 text-sm font-semibold tracking-wide'],\n dataDirectiveTitle: 'callout',\n },\n tagName: 'div',\n },\n ]\n : []),\n {\n type: 'element',\n children,\n properties: {\n className: ['space-y-3 [&>:first-child]:mt-0 [&>:last-child]:mb-0'],\n dataDirectiveBody: 'callout',\n },\n tagName: 'div',\n },\n ]\n },\n defaultAttributes: {\n variant: 'note',\n },\n description: 'Emphasized content block with note, info, tip, warning, danger, or success variants.',\n editor: {\n detail: 'Static directive',\n label: 'Callout',\n snippet: ':::callout[${Title}]{\\n variant=\"${note}\"\\n}\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'callout',\n dataIcon: typeof node.attributes?.icon === 'string' ? node.attributes.icon : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'soft',\n dataTitle: getTitle(node),\n dataVariant: resolveCalloutVariant(node),\n }\n },\n kind: 'callout',\n openMarker: ':::callout',\n public: true,\n supportsAttributes: true,\n tagName: 'div',\n themeAttributes: {\n theme: 'callout',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (typeof attributes.variant === 'string' && !isCalloutVariant(attributes.variant))\n warnings.push(\n `Unsupported callout variant \"${attributes.variant}\". Falling back to \"note\".`,\n )\n\n return warnings\n },\n}\n"],"names":["makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","resolveDirectiveTheme","CALLOUT_VARIANTS","calloutVariantClasses","danger","info","note","success","tip","warning","isCalloutVariant","value","includes","resolveCalloutVariant","node","variant","attributes","getTitle","calloutDirective","name","allowedAttributes","applyHast","config","mergeClassNames","properties","dataVariant","title","dataTitle","undefined","icon","dataIcon","theme","dataTheme","themes","children","className","hookClassName","modifierClassName","classes","type","dataDirectiveTitle","tagName","dataDirectiveBody","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAIA,SAASA,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,mBAAmB;IAC9B;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAIV,MAAMC,wBAAwD;IAC5DC,QAAQ;IACRC,MAAM;IACNC,MAAM;IACNC,SAAS;IACTC,KAAK;IACLC,SAAS;AACX;AAEA,SAASC,iBAAiBC,KAAc;IACtC,OAAO,OAAOA,UAAU,YAAYT,iBAAiBU,QAAQ,CAACD;AAChE;AAEA,OAAO,SAASE,sBAAsBC,IAAwB;IAC5D,MAAMC,UAAUD,KAAKE,UAAU,EAAED;IAEjC,OAAOL,iBAAiBK,WAAWA,UAAU;AAC/C;AAEA,SAASE,SAASH,IAAwB;IACxC,OAAOd,6BAA6Bc,MAAM;AAC5C;AAEA,OAAO,MAAMI,mBAA8C;IACzDC,MAAM;IACNC,mBAAmB;QAAC;QAAQ;QAAS;QAAS;KAAU;IACxDC,WAAUP,IAAI,EAAEQ,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMR,UAAU,OAAOD,KAAKU,UAAU,CAACC,WAAW,KAAK,WAAWX,KAAKU,UAAU,CAACC,WAAW,GAAG;QAChG,MAAMC,QAAQ,OAAOZ,KAAKU,UAAU,CAACG,SAAS,KAAK,WAAWb,KAAKU,UAAU,CAACG,SAAS,GAAGC;QAC1F,MAAMC,OAAO,OAAOf,KAAKU,UAAU,CAACM,QAAQ,KAAK,WAAWhB,KAAKU,UAAU,CAACM,QAAQ,GAAGF;QACvF,MAAMG,QAAQ9B,sBACZ,WACA,OAAOa,KAAKU,UAAU,CAACQ,SAAS,KAAK,WAAWlB,KAAKU,U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B,OAAO;IACT;IACAyB,oBAAmB,EAAExC,UAAU,EAAE;QAC/B,MAAMyC,WAAqB,EAAE;QAE7B,IAAI,OAAOzC,WAAWD,OAAO,KAAK,YAAY,CAACL,iBAAiBM,WAAWD,OAAO,GAChF0C,SAASC,IAAI,CACX,CAAC,6BAA6B,EAAE1C,WAAWD,OAAO,CAAC,0BAA0B,CAAC;QAGlF,OAAO0C;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/callout.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { parseIconEntries } from '../../icons/entries.js'\nimport { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\nimport { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport {\n applyDirectivePalette,\n getPaletteRenderProperties,\n PALETTE_ATTRIBUTES,\n resolveIconPaletteName,\n} from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const CALLOUT_VARIANTS = [\n 'note',\n 'info',\n 'tip',\n 'warning',\n 'danger',\n 'success',\n] as const\n\nexport type CalloutVariant = (typeof CALLOUT_VARIANTS)[number]\n\n// The tint is a background-image so it layers over the theme's background\n// color instead of competing with it, and the ring composes with the theme's\n// shadow. Text, title and ring colours follow the colour scheme through\n// `--pmd-scheme-dark` (see styles/directiveSurface.ts).\nconst calloutVariantClasses: Record<CalloutVariant, string> = {\n danger:\n 'bg-linear-to-r from-red-500/10 to-red-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(248_113_113/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(220_38_38/0.2))] text-[color:color-mix(in_oklab,rgb(254_242_242)_calc(var(--pmd-scheme-dark,1)*100%),rgb(69_10_10))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(252_165_165)_calc(var(--pmd-scheme-dark,1)*100%),rgb(185_28_28))]',\n info:\n 'bg-linear-to-r from-sky-500/10 to-sky-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(56_189_248/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(2_132_199/0.2))] text-[color:color-mix(in_oklab,rgb(240_249_255)_calc(var(--pmd-scheme-dark,1)*100%),rgb(8_47_73))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(125_211_252)_calc(var(--pmd-scheme-dark,1)*100%),rgb(3_105_161))]',\n note:\n 'bg-linear-to-r from-slate-500/10 to-slate-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(148_163_184/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(100_116_139/0.2))] text-[color:color-mix(in_oklab,rgb(248_250_252)_calc(var(--pmd-scheme-dark,1)*100%),rgb(15_23_42))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(203_213_225)_calc(var(--pmd-scheme-dark,1)*100%),rgb(71_85_105))]',\n success:\n 'bg-linear-to-r from-emerald-500/10 to-emerald-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(52_211_153/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(5_150_105/0.2))] text-[color:color-mix(in_oklab,rgb(236_253_245)_calc(var(--pmd-scheme-dark,1)*100%),rgb(2_44_34))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(110_231_183)_calc(var(--pmd-scheme-dark,1)*100%),rgb(4_120_87))]',\n tip:\n 'bg-linear-to-r from-violet-500/10 to-violet-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(167_139_250/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(124_58_237/0.2))] text-[color:color-mix(in_oklab,rgb(245_243_255)_calc(var(--pmd-scheme-dark,1)*100%),rgb(46_16_101))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(196_181_253)_calc(var(--pmd-scheme-dark,1)*100%),rgb(109_40_217))]',\n warning:\n 'bg-linear-to-r from-amber-500/10 to-amber-500/10 inset-ring inset-ring-[color:color-mix(in_oklab,rgb(251_191_36/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(217_119_6/0.2))] text-[color:color-mix(in_oklab,rgb(255_251_235)_calc(var(--pmd-scheme-dark,1)*100%),rgb(69_26_3))] [&>[data-directive-title]]:text-[color:color-mix(in_oklab,rgb(252_211_77)_calc(var(--pmd-scheme-dark,1)*100%),rgb(146_64_14))]',\n}\n\nfunction isCalloutVariant(value: unknown): value is CalloutVariant {\n return typeof value === 'string' && CALLOUT_VARIANTS.includes(value as CalloutVariant)\n}\n\nexport function resolveCalloutVariant(node: ContainerDirective): CalloutVariant {\n const variant = node.attributes?.variant\n\n return isCalloutVariant(variant) ? variant : 'note'\n}\n\nfunction getTitle(node: ContainerDirective): string | undefined {\n return getDirectiveLabelOrAttribute(node, 'title')\n}\n\nexport const calloutDirective: LayoutDirectiveDefinition = {\n name: 'callout',\n allowedAttributes: ['icon', ...PALETTE_ATTRIBUTES, 'theme', 'title', 'variant'],\n applyHast(node, config, { mergeClassNames }) {\n const variant = typeof node.properties.dataVariant === 'string' ? node.properties.dataVariant : 'note'\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined\n // A callout shows one icon; it may carry its own palette (`@pack/name palette=x`).\n const [iconEntry] = parseIconEntries(\n typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined,\n ).entries\n const icon = iconEntry?.ref\n const theme = resolveDirectiveTheme(\n 'callout',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : 'soft',\n config.themes,\n )\n const children = node.children\n // An icon without a title sits beside the body instead of on its own row.\n const iconBesideBody = Boolean(icon && !title)\n\n node.properties.dataTheme = theme.name\n node.properties.className = mergeClassNames(\n iconBesideBody ? 'flex items-start gap-3' : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n calloutVariantClasses[isCalloutVariant(variant) ? variant : 'note'],\n )\n\n applyDirectivePalette(node, config)\n\n node.children = [\n ...(title || icon\n ? [\n {\n type: 'element' as const,\n children: [\n ...(icon\n ? [\n makeDirectiveIconPlaceholder(\n icon,\n [\n 'pmd-callout__icon inline-flex size-4 shrink-0 text-current',\n iconBesideBody ? 'mt-1.5' : 'mt-0.5',\n ],\n resolveIconPaletteName(node, iconEntry),\n ),\n ]\n : []),\n ...(title ? [{ type: 'text' as const, value: title }] : []),\n ],\n properties: {\n className: [\n iconBesideBody\n ? 'not-prose flex shrink-0'\n : 'not-prose mb-2 flex items-start gap-2 text-sm font-semibold tracking-wide',\n ],\n dataDirectiveTitle: 'callout',\n },\n tagName: 'div',\n },\n ]\n : []),\n {\n type: 'element',\n children,\n properties: {\n className: [DIRECTIVE_BODY_CLASS, iconBesideBody ? 'min-w-0 flex-1' : ''].filter(Boolean),\n dataDirectiveBody: 'callout',\n },\n tagName: 'div',\n },\n ]\n },\n defaultAttributes: {\n variant: 'note',\n },\n description: 'Emphasized content block with note, info, tip, warning, danger, or success variants.',\n editor: {\n detail: 'Static directive',\n label: 'Callout',\n snippet: ':::callout[${Title}]{\\n variant=\"${note}\"\\n}\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'callout',\n dataIcon: typeof node.attributes?.icon === 'string' ? node.attributes.icon : undefined,\n ...getPaletteRenderProperties(node),\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'soft',\n dataTitle: getTitle(node),\n dataVariant: resolveCalloutVariant(node),\n }\n },\n kind: 'callout',\n openMarker: ':::callout',\n public: true,\n supportsAttributes: true,\n tagName: 'div',\n themeAttributes: {\n theme: 'callout',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = []\n\n if (typeof attributes.variant === 'string' && !isCalloutVariant(attributes.variant))\n warnings.push(\n `Unsupported callout variant \"${attributes.variant}\". Falling back to \"note\".`,\n )\n\n return warnings\n },\n}\n"],"names":["parseIconEntries","DIRECTIVE_BODY_CLASS","makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","applyDirectivePalette","getPaletteRenderProperties","PALETTE_ATTRIBUTES","resolveIconPaletteName","resolveDirectiveTheme","CALLOUT_VARIANTS","calloutVariantClasses","danger","info","note","success","tip","warning","isCalloutVariant","value","includes","resolveCalloutVariant","node","variant","attributes","getTitle","calloutDirective","name","allowedAttributes","applyHast","config","mergeClassNames","properties","dataVariant","title","dataTitle","undefined","iconEntry","dataIcon","entries","icon","ref","theme","dataTheme","themes","children","iconBesideBody","Boolean","className","hookClassName","modifierClassName","classes","type","dataDirectiveTitle","tagName","filter","dataDirectiveBody","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,sBAAsB,QACjB,gBAAe;AACtB,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,mBAAmB;IAC9B;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAIV,0EAA0E;AAC1E,6EAA6E;AAC7E,wEAAwE;AACxE,wDAAwD;AACxD,MAAMC,wBAAwD;IAC5DC,QACE;IACFC,MACE;IACFC,MACE;IACFC,SACE;IACFC,KACE;IACFC,SACE;AACJ;AAEA,SAASC,iBAAiBC,KAAc;IACtC,OAAO,OAAOA,UAAU,YAAYT,iBAAiBU,QAAQ,CAACD;AAChE;AAEA,OAAO,SAASE,sBAAsBC,IAAwB;IAC5D,MAAMC,UAAUD,KAAKE,UAAU,EAAED;IAEjC,OAAOL,iBAAiBK,WAAWA,UAAU;AAC/C;AAEA,SAASE,SAASH,IAAwB;IACxC,OAAOlB,6BAA6BkB,MAAM;AAC5C;AAEA,OAAO,MA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gCAAEkB,MAAM;gCAAiBjC,OAAOe;4BAAM;yBAAE,GAAG,EAAE;qBAC3D;oBACDF,YAAY;wBACVgB,WAAW;4BACTF,iBACI,4BACA;yBACL;wBACDO,oBAAoB;oBACtB;oBACAC,SAAS;gBACX;aACD,GACD,EAAE;YACN;gBACEF,MAAM;gBACNP;gBACAb,YAAY;oBACVgB,WAAW;wBAAC9C;wBAAsB4C,iBAAiB,mBAAmB;qBAAG,CAACS,MAAM,CAACR;oBACjFS,mBAAmB;gBACrB;gBACAF,SAAS;YACX;SACD;IACH;IACAG,mBAAmB;QACjBlC,SAAS;IACX;IACAmC,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyBzC,IAAI;QAC3B,OAAO;YACL0C,eAAe;YACf1B,UAAU,OAAOhB,KAAKE,UAAU,EAAEgB,SAAS,WAAWlB,KAAKE,UAAU,CAACgB,IAAI,GAAGJ;YAC7E,GAAG9B,2BAA2BgB,KAAK;YACnCqB,WAAW,OAAOrB,KAAKE,UAAU,EAAEkB,UAAU,WAAWpB,KAAKE,UAAU,CAACkB,KAAK,GAAG;YAChFP,WAAWV,SAASH;YACpBW,aAAaZ,sBAAsBC;QACrC;IACF;IACA2C,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBd,SAAS;IACTe,iBAAiB;QACf3B,OAAO;IACT;IACA4B,oBAAmB,EAAE9C,UAAU,EAAE;QAC/B,MAAM+C,WAAqB,EAAE;QAE7B,IAAI,OAAO/C,WAAWD,OAAO,KAAK,YAAY,CAACL,iBAAiBM,WAAWD,OAAO,GAChFgD,SAASC,IAAI,CACX,CAAC,6BAA6B,EAAEhD,WAAWD,OAAO,CAAC,0BAA0B,CAAC;QAGlF,OAAOgD;IACT;AACF,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LayoutDirectiveDefinition } from '../types.js';
|
|
2
|
-
export declare const CARD_BODY_CLASS_NAMES
|
|
3
|
-
export declare const CARD_TITLE_CLASS_NAMES = "mb-3 text-lg font-semibold tracking-tight";
|
|
2
|
+
export declare const CARD_BODY_CLASS_NAMES: string;
|
|
3
|
+
export declare const CARD_TITLE_CLASS_NAMES = "not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)";
|
|
4
4
|
export declare const CARD_LINK_SCOPES: readonly ["full", "title"];
|
|
5
5
|
export declare const DEFAULT_CARD_LINK_SCOPE = "full";
|
|
6
6
|
export type CardLinkScope = (typeof CARD_LINK_SCOPES)[number];
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { parseIconEntries } from '../../icons/entries.js';
|
|
2
|
+
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
1
3
|
import { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js';
|
|
2
4
|
import { getDirectiveLabelOrAttribute } from '../labels.js';
|
|
5
|
+
import { applyDirectivePalette, getPaletteRenderProperties, PALETTE_ATTRIBUTES, resolveIconPaletteName } from '../palette.js';
|
|
3
6
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
4
7
|
import { getSafeHref, getUnsafeHrefWarnings } from '../urls.js';
|
|
5
|
-
export const CARD_BODY_CLASS_NAMES =
|
|
6
|
-
export const CARD_TITLE_CLASS_NAMES = 'mb-3 text-lg font-semibold tracking-tight';
|
|
8
|
+
export const CARD_BODY_CLASS_NAMES = DIRECTIVE_BODY_CLASS;
|
|
9
|
+
export const CARD_TITLE_CLASS_NAMES = 'not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)';
|
|
10
|
+
const CARD_TITLE_LINK_CLASS_NAMES = 'rounded-sm transition-colors hover:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]';
|
|
7
11
|
export const CARD_LINK_SCOPES = [
|
|
8
12
|
'full',
|
|
9
13
|
'title'
|
|
@@ -50,7 +54,12 @@ function makeTitle(title, href, newTab = false) {
|
|
|
50
54
|
value: title
|
|
51
55
|
}
|
|
52
56
|
],
|
|
53
|
-
properties:
|
|
57
|
+
properties: {
|
|
58
|
+
...getLinkProperties(href, newTab),
|
|
59
|
+
className: [
|
|
60
|
+
CARD_TITLE_LINK_CLASS_NAMES
|
|
61
|
+
]
|
|
62
|
+
},
|
|
54
63
|
tagName: 'a'
|
|
55
64
|
}
|
|
56
65
|
] : [
|
|
@@ -79,13 +88,34 @@ function makeFullCardLink(href, title, newTab) {
|
|
|
79
88
|
...getLinkProperties(href, newTab),
|
|
80
89
|
ariaLabel: title ? `Open ${title}` : 'Open card',
|
|
81
90
|
className: [
|
|
82
|
-
'absolute inset-0 z-10 rounded-[inherit] focus:outline-none focus-visible:ring-2 focus-visible:ring-
|
|
91
|
+
'not-prose absolute inset-0 z-10 rounded-[inherit] focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]'
|
|
83
92
|
],
|
|
84
93
|
dataDirectiveLink: 'card'
|
|
85
94
|
},
|
|
86
95
|
tagName: 'a'
|
|
87
96
|
};
|
|
88
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* `icon` takes one icon or a comma-separated list; each entry may carry its
|
|
100
|
+
* own palette (`@fa-brands/debian palette=debian`, see icons/entries.ts).
|
|
101
|
+
*/ function makeIcons(card, icons, hasEyebrow) {
|
|
102
|
+
return {
|
|
103
|
+
type: 'element',
|
|
104
|
+
children: icons.map((icon)=>makeDirectiveIconPlaceholder(icon.ref, [
|
|
105
|
+
'pmd-card__icon inline-flex size-5 text-current'
|
|
106
|
+
], resolveIconPaletteName(card, icon))),
|
|
107
|
+
properties: {
|
|
108
|
+
className: [
|
|
109
|
+
'not-prose pmd-card__icons mb-3 flex flex-wrap items-center gap-2',
|
|
110
|
+
// Clear of the eyebrow; its mb-2 collapses into this margin.
|
|
111
|
+
...hasEyebrow ? [
|
|
112
|
+
'mt-4'
|
|
113
|
+
] : []
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
tagName: 'div'
|
|
117
|
+
};
|
|
118
|
+
}
|
|
89
119
|
function makeEyebrow(eyebrow) {
|
|
90
120
|
return {
|
|
91
121
|
type: 'element',
|
|
@@ -96,8 +126,10 @@ function makeEyebrow(eyebrow) {
|
|
|
96
126
|
}
|
|
97
127
|
],
|
|
98
128
|
properties: {
|
|
129
|
+
// Muted relative to the body text rather than a fixed grey, so small
|
|
130
|
+
// uppercase labels keep AA contrast on tinted or custom surfaces.
|
|
99
131
|
className: [
|
|
100
|
-
'mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-
|
|
132
|
+
'not-prose mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-(--tw-prose-body)/80'
|
|
101
133
|
],
|
|
102
134
|
dataDirectiveEyebrow: 'card'
|
|
103
135
|
},
|
|
@@ -112,6 +144,7 @@ export const cardDirective = {
|
|
|
112
144
|
'icon',
|
|
113
145
|
'linkScope',
|
|
114
146
|
'newTab',
|
|
147
|
+
...PALETTE_ATTRIBUTES,
|
|
115
148
|
'theme',
|
|
116
149
|
'title'
|
|
117
150
|
],
|
|
@@ -123,7 +156,7 @@ export const cardDirective = {
|
|
|
123
156
|
const linkScope = typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope) ? node.properties.dataLinkScope : DEFAULT_CARD_LINK_SCOPE;
|
|
124
157
|
const newTab = node.properties.dataNewTab === 'true';
|
|
125
158
|
const eyebrow = typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined;
|
|
126
|
-
const
|
|
159
|
+
const { entries: icons } = parseIconEntries(typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined);
|
|
127
160
|
const theme = resolveDirectiveTheme('card', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
128
161
|
const children = node.children;
|
|
129
162
|
node.properties.dataTheme = theme.name;
|
|
@@ -131,7 +164,8 @@ export const cardDirective = {
|
|
|
131
164
|
node.properties.dataLinkScope = linkScope;
|
|
132
165
|
node.properties.dataNewTab = newTab ? 'true' : 'false';
|
|
133
166
|
}
|
|
134
|
-
node.properties.className = mergeClassNames('
|
|
167
|
+
node.properties.className = mergeClassNames('my-6', href && linkScope === 'full' ? 'relative cursor-pointer transition-colors hover:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&>[data-directive-title]]:transition-colors hover:[&>[data-directive-title]]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20' : undefined, theme.hookClassName, theme.modifierClassName, theme.classes);
|
|
168
|
+
applyDirectivePalette(node, config);
|
|
135
169
|
node.children = [
|
|
136
170
|
...href && linkScope === 'full' ? [
|
|
137
171
|
makeFullCardLink(href, title, newTab)
|
|
@@ -139,10 +173,8 @@ export const cardDirective = {
|
|
|
139
173
|
...eyebrow ? [
|
|
140
174
|
makeEyebrow(eyebrow)
|
|
141
175
|
] : [],
|
|
142
|
-
...
|
|
143
|
-
|
|
144
|
-
'pmd-card__icon mb-3 inline-flex size-5 text-current'
|
|
145
|
-
])
|
|
176
|
+
...icons.length > 0 ? [
|
|
177
|
+
makeIcons(node, icons, Boolean(eyebrow))
|
|
146
178
|
] : [],
|
|
147
179
|
...title ? [
|
|
148
180
|
makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)
|
|
@@ -183,6 +215,7 @@ export const cardDirective = {
|
|
|
183
215
|
dataEyebrow: getAttribute(node, 'eyebrow'),
|
|
184
216
|
dataHref: getSafeHref(getAttribute(node, 'href')),
|
|
185
217
|
dataIcon: getAttribute(node, 'icon'),
|
|
218
|
+
...getPaletteRenderProperties(node),
|
|
186
219
|
dataLinkScope: getLinkScope(node),
|
|
187
220
|
dataNewTab: 'newTab' in (node.attributes ?? {}) ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false' : undefined,
|
|
188
221
|
dataTheme: getAttribute(node, 'theme'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/card.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\n\nexport const CARD_BODY_CLASS_NAMES = 'space-y-3 [&>:first-child]:mt-0 [&>:last-child]:mb-0'\nexport const CARD_TITLE_CLASS_NAMES = 'mb-3 text-lg font-semibold tracking-tight'\nexport const CARD_LINK_SCOPES = ['full', 'title'] as const\nexport const DEFAULT_CARD_LINK_SCOPE = 'full'\n\nexport type CardLinkScope = (typeof CARD_LINK_SCOPES)[number]\n\nexport function isCardLinkScope(value: unknown): value is CardLinkScope {\n return typeof value === 'string' && CARD_LINK_SCOPES.includes(value as CardLinkScope)\n}\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(node: ContainerDirective, name: string): boolean {\n const attributes = node.attributes as\n | null\n | Record<string, boolean | null | string | undefined>\n | undefined\n const value = attributes?.[name]\n\n if (value === true) return true\n if (typeof value !== 'string') return false\n\n return value === 'true'\n}\n\nfunction getLinkScope(node: ContainerDirective): CardLinkScope | undefined {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return undefined\n\n return isCardLinkScope(value) ? value : DEFAULT_CARD_LINK_SCOPE\n}\n\nfunction getLinkProperties(href: string, newTab: boolean): Element['properties'] {\n return {\n href,\n ...(newTab\n ? {\n rel: ['noopener', 'noreferrer'],\n target: '_blank',\n }\n : {}),\n }\n}\n\nfunction makeTitle(title: string, href?: string, newTab = false): Element {\n const children: ElementContent[] = href\n ? [\n {\n type: 'element',\n children: [{ type: 'text', value: title }],\n properties: getLinkProperties(href, newTab),\n tagName: 'a',\n },\n ]\n : [{ type: 'text', value: title }]\n\n return {\n type: 'element',\n children,\n properties: {\n className: [CARD_TITLE_CLASS_NAMES],\n dataDirectiveTitle: 'card',\n },\n tagName: 'h3',\n }\n}\n\nfunction makeFullCardLink(href: string, title: string | undefined, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: title ? `Open ${title}` : 'Open card',\n className: [\n 'absolute inset-0 z-10 rounded-[inherit] focus:outline-none focus-visible:ring-2 focus-visible:ring-cyan-300',\n ],\n dataDirectiveLink: 'card',\n },\n tagName: 'a',\n }\n}\n\nfunction makeEyebrow(eyebrow: string): Element {\n return {\n type: 'element',\n children: [{ type: 'text', value: eyebrow }],\n properties: {\n className: ['mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-muted-foreground'],\n dataDirectiveEyebrow: 'card',\n },\n tagName: 'p',\n }\n}\n\nexport const cardDirective: LayoutDirectiveDefinition = {\n name: 'card',\n allowedAttributes: ['eyebrow', 'href', 'icon', 'linkScope', 'newTab', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined\n // Re-validate at the hast stage: this is where the live <a href> is built.\n const href = getSafeHref(node.properties.dataHref)\n if (!href) delete node.properties.dataHref\n const linkScope =\n typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARD_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const eyebrow =\n typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined\n const icon = typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined\n const theme = resolveDirectiveTheme(\n 'card',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const children = node.children\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n node.properties.className = mergeClassNames(\n 'not-prose',\n href && linkScope === 'full' ? 'relative cursor-pointer [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20' : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n node.children = [\n ...(href && linkScope === 'full' ? [makeFullCardLink(href, title, newTab)] : []),\n ...(eyebrow ? [makeEyebrow(eyebrow)] : []),\n ...(icon\n ? [\n makeDirectiveIconPlaceholder(icon, [\n 'pmd-card__icon mb-3 inline-flex size-5 text-current',\n ]),\n ]\n : []),\n ...(title ? [makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)] : []),\n {\n type: 'element',\n children,\n properties: {\n className: [CARD_BODY_CLASS_NAMES],\n dataDirectiveBody: 'card',\n },\n tagName: 'div',\n },\n ]\n },\n attributeValues: {\n linkScope: CARD_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n defaultAttributes: {\n linkScope: DEFAULT_CARD_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Card content block with optional title, eyebrow, and card link.',\n editor: {\n detail: 'Layout directive',\n label: 'Card',\n snippet: ':::card[${Title}]\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'card',\n dataEyebrow: getAttribute(node, 'eyebrow'),\n dataHref: getSafeHref(getAttribute(node, 'href')),\n dataIcon: getAttribute(node, 'icon'),\n dataLinkScope: getLinkScope(node),\n dataNewTab: 'newTab' in (node.attributes ?? {})\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: getAttribute(node, 'theme'),\n dataTitle: getDirectiveLabelOrAttribute(node, 'title'),\n }\n },\n kind: 'card',\n openMarker: ':::card',\n public: true,\n supportsAttributes: true,\n tagName: 'article',\n themeAttributes: {\n theme: 'card',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('card', attributes)]\n\n if (typeof attributes.linkScope === 'string' && !isCardLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid card linkScope \"${attributes.linkScope}\". Falling back to \"${DEFAULT_CARD_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n}\n"],"names":["makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","resolveDirectiveTheme","getSafeHref","getUnsafeHrefWarnings","CARD_BODY_CLASS_NAMES","CARD_TITLE_CLASS_NAMES","CARD_LINK_SCOPES","DEFAULT_CARD_LINK_SCOPE","isCardLinkScope","value","includes","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","getLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeTitle","title","children","type","properties","tagName","className","dataDirectiveTitle","makeFullCardLink","ariaLabel","dataDirectiveLink","makeEyebrow","eyebrow","dataDirectiveEyebrow","cardDirective","allowedAttributes","applyHast","config","mergeClassNames","dataTitle","dataHref","dataLinkScope","dataNewTab","dataEyebrow","icon","dataIcon","theme","dataTheme","themes","hookClassName","modifierClassName","classes","dataDirectiveBody","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAKA,SAASA,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAE/D,OAAO,MAAMC,wBAAwB,uDAAsD;AAC3F,OAAO,MAAMC,yBAAyB,4CAA2C;AACjF,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SAAS;IACX;IACAC,0BAAyBrD,IAAI;QAC3B,OAAO;YACLsD,eAAe;YACflB,aAAarC,aAAaC,MAAM;YAChCiC,UAAU3C,YAAYS,aAAaC,MAAM;YACzCsC,UAAUvC,aAAaC,MAAM;YAC7BkC,eAAe5B,aAAaN;YAC5BmC,YAAY,YAAanC,CAAAA,KAAKE,UAAU,IAAI,CAAC,CAAA,IACzCG,oBAAoBL,MAAM,YAAY,SAAS,UAC/CI;YACJoC,WAAWzC,aAAaC,MAAM;YAC9BgC,WAAW5C,6BAA6BY,MAAM;QAChD;IACF;IACAuD,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBxC,SAAS;IACTyC,iBAAiB;QACfpB,OAAO;IACT;IACAqB,oBAAmB,EAAE1D,UAAU,EAAE;QAC/B,MAAM2D,WAAqB;eAAItE,sBAAsB,QAAQW;SAAY;QAEzE,IAAI,OAAOA,WAAWK,SAAS,KAAK,YAAY,CAACX,gBAAgBM,WAAWK,SAAS,GACnFsD,SAASC,IAAI,CACX,CAAC,wBAAwB,EAAE5D,WAAWK,SAAS,CAAC,oBAAoB,EAAEZ,wBAAwB,EAAE,CAAC;QAGrG,OAAOkE;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/card.ts"],"sourcesContent":["import type { Element, ElementContent } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { type IconEntry, parseIconEntries } from '../../icons/entries.js'\nimport { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\nimport { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport {\n applyDirectivePalette,\n getPaletteRenderProperties,\n PALETTE_ATTRIBUTES,\n resolveIconPaletteName,\n} from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\n\nexport const CARD_BODY_CLASS_NAMES = DIRECTIVE_BODY_CLASS\nexport const CARD_TITLE_CLASS_NAMES =\n 'not-prose mb-3 text-lg font-semibold tracking-tight text-(--tw-prose-headings)'\nconst CARD_TITLE_LINK_CLASS_NAMES =\n 'rounded-sm transition-colors hover:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]'\nexport const CARD_LINK_SCOPES = ['full', 'title'] as const\nexport const DEFAULT_CARD_LINK_SCOPE = 'full'\n\nexport type CardLinkScope = (typeof CARD_LINK_SCOPES)[number]\n\nexport function isCardLinkScope(value: unknown): value is CardLinkScope {\n return typeof value === 'string' && CARD_LINK_SCOPES.includes(value as CardLinkScope)\n}\n\nfunction getAttribute(node: ContainerDirective, name: string): string | undefined {\n const value = node.attributes?.[name]\n\n return typeof value === 'string' && value.trim() ? value.trim() : undefined\n}\n\nfunction getBooleanAttribute(node: ContainerDirective, name: string): boolean {\n const attributes = node.attributes as\n | null\n | Record<string, boolean | null | string | undefined>\n | undefined\n const value = attributes?.[name]\n\n if (value === true) return true\n if (typeof value !== 'string') return false\n\n return value === 'true'\n}\n\nfunction getLinkScope(node: ContainerDirective): CardLinkScope | undefined {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return undefined\n\n return isCardLinkScope(value) ? value : DEFAULT_CARD_LINK_SCOPE\n}\n\nfunction getLinkProperties(href: string, newTab: boolean): Element['properties'] {\n return {\n href,\n ...(newTab\n ? {\n rel: ['noopener', 'noreferrer'],\n target: '_blank',\n }\n : {}),\n }\n}\n\nfunction makeTitle(title: string, href?: string, newTab = false): Element {\n const children: ElementContent[] = href\n ? [\n {\n type: 'element',\n children: [{ type: 'text', value: title }],\n properties: { ...getLinkProperties(href, newTab), className: [CARD_TITLE_LINK_CLASS_NAMES] },\n tagName: 'a',\n },\n ]\n : [{ type: 'text', value: title }]\n\n return {\n type: 'element',\n children,\n properties: {\n className: [CARD_TITLE_CLASS_NAMES],\n dataDirectiveTitle: 'card',\n },\n tagName: 'h3',\n }\n}\n\nfunction makeFullCardLink(href: string, title: string | undefined, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: title ? `Open ${title}` : 'Open card',\n className: [\n 'not-prose absolute inset-0 z-10 rounded-[inherit] focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]',\n ],\n dataDirectiveLink: 'card',\n },\n tagName: 'a',\n }\n}\n\n/**\n * `icon` takes one icon or a comma-separated list; each entry may carry its\n * own palette (`@fa-brands/debian palette=debian`, see icons/entries.ts).\n */\nfunction makeIcons(card: Element, icons: IconEntry[], hasEyebrow: boolean): Element {\n return {\n type: 'element',\n children: icons.map((icon) =>\n makeDirectiveIconPlaceholder(\n icon.ref,\n ['pmd-card__icon inline-flex size-5 text-current'],\n resolveIconPaletteName(card, icon),\n ),\n ),\n properties: {\n className: [\n 'not-prose pmd-card__icons mb-3 flex flex-wrap items-center gap-2',\n // Clear of the eyebrow; its mb-2 collapses into this margin.\n ...(hasEyebrow ? ['mt-4'] : []),\n ],\n },\n tagName: 'div',\n }\n}\n\nfunction makeEyebrow(eyebrow: string): Element {\n return {\n type: 'element',\n children: [{ type: 'text', value: eyebrow }],\n properties: {\n // Muted relative to the body text rather than a fixed grey, so small\n // uppercase labels keep AA contrast on tinted or custom surfaces.\n className: ['not-prose mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-(--tw-prose-body)/80'],\n dataDirectiveEyebrow: 'card',\n },\n tagName: 'p',\n }\n}\n\nexport const cardDirective: LayoutDirectiveDefinition = {\n name: 'card',\n allowedAttributes: ['eyebrow', 'href', 'icon', 'linkScope', 'newTab', ...PALETTE_ATTRIBUTES, 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined\n // Re-validate at the hast stage: this is where the live <a href> is built.\n const href = getSafeHref(node.properties.dataHref)\n if (!href) delete node.properties.dataHref\n const linkScope =\n typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARD_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const eyebrow =\n typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined\n const { entries: icons } = parseIconEntries(\n typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined,\n )\n const theme = resolveDirectiveTheme(\n 'card',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const children = node.children\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n node.properties.className = mergeClassNames(\n 'my-6',\n href && linkScope === 'full'\n ? 'relative cursor-pointer transition-colors hover:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&>[data-directive-title]]:transition-colors hover:[&>[data-directive-title]]:text-[color:var(--pmd-accent-hover,color-mix(in_oklab,#67e8f9_calc(var(--pmd-scheme-dark,1)*100%),#155e75))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n applyDirectivePalette(node, config)\n\n node.children = [\n ...(href && linkScope === 'full' ? [makeFullCardLink(href, title, newTab)] : []),\n ...(eyebrow ? [makeEyebrow(eyebrow)] : []),\n ...(icons.length > 0 ? [makeIcons(node, icons, Boolean(eyebrow))] : []),\n ...(title ? [makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)] : []),\n {\n type: 'element',\n children,\n properties: {\n className: [CARD_BODY_CLASS_NAMES],\n dataDirectiveBody: 'card',\n },\n tagName: 'div',\n },\n ]\n },\n attributeValues: {\n linkScope: CARD_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n defaultAttributes: {\n linkScope: DEFAULT_CARD_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Card content block with optional title, eyebrow, and card link.',\n editor: {\n detail: 'Layout directive',\n label: 'Card',\n snippet: ':::card[${Title}]\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'card',\n dataEyebrow: getAttribute(node, 'eyebrow'),\n dataHref: getSafeHref(getAttribute(node, 'href')),\n dataIcon: getAttribute(node, 'icon'),\n ...getPaletteRenderProperties(node),\n dataLinkScope: getLinkScope(node),\n dataNewTab: 'newTab' in (node.attributes ?? {})\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: getAttribute(node, 'theme'),\n dataTitle: getDirectiveLabelOrAttribute(node, 'title'),\n }\n },\n kind: 'card',\n openMarker: ':::card',\n public: true,\n supportsAttributes: true,\n tagName: 'article',\n themeAttributes: {\n theme: 'card',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('card', attributes)]\n\n if (typeof attributes.linkScope === 'string' && !isCardLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid card linkScope \"${attributes.linkScope}\". Falling back to \"${DEFAULT_CARD_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n}\n"],"names":["parseIconEntries","DIRECTIVE_BODY_CLASS","makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","applyDirectivePalette","getPaletteRenderProperties","PALETTE_ATTRIBUTES","resolveIconPaletteName","resolveDirectiveTheme","getSafeHref","getUnsafeHrefWarnings","CARD_BODY_CLASS_NAMES","CARD_TITLE_CLASS_NAMES","CARD_TITLE_LINK_CLASS_NAMES","CARD_LINK_SCOPES","DEFAULT_CARD_LINK_SCOPE","isCardLinkScope","value","includes","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","getLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeTitle","title","children","type","properties","className","tagName","dataDirectiveTitle","makeFullCardLink","ariaLabel","dataDirectiveLink","makeIcons","card","icons","hasEyebrow","map","icon","ref","makeEyebrow","eyebrow","dataDirectiveEyebrow","cardDirective","allowedAttributes","applyHast","config","mergeClassNames","dataTitle","dataHref","dataLinkScope","dataNewTab","dataEyebrow","entries","dataIcon","theme","dataTheme","themes","hookClassName","modifierClassName","classes","length","Boolean","dataDirectiveBody","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAKA,SAAyBA,gBAAgB,QAAQ,yBAAwB;AACzE,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,kBAAkB,EAClBC,sBAAsB,QACjB,gBAAe;AACtB,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAE/D,OAAO,MAAMC,wBAAwBV,qBAAoB;AACzD,OAAO,MAAMW,yBACX,iFAAgF;AAClF,MAAMC,8BACJ;AACF,OAAO,MAAMC,mBAAmB;IAAC;IAAQ;CAAQ,CAAS;AAC1D,OAAO,MAAMC,0BAA0B,OAAM;AAI7C,OAAO,SAASC,gBAAgBC,KAAc;IAC5C,OAAO,OAAOA,UAAU,YAAYH,iBAAiBI,QAAQ,CAACD;AAChE;AAEA,SAASE,aAAaC,IAAwB,EAAEC,IAAY;IAC1D,MAAMJ,QAAQG,KAAKE,UAAU,EAAE,CAACD,KAAK;IAErC,OAAO,OAAOJ,UAAU,YAAYA,MAAMM,IAAI,KAAKN,MAAMM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AS;YACX;SACD;IACH;IACAoC,iBAAiB;QACfhD,WAAWb;QACXgB,QAAQ;YAAC;YAAQ;SAAQ;IAC3B;IACA8C,mBAAmB;QACjBjD,WAAWZ;QACXe,QAAQ;IACV;IACA+C,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyB9D,IAAI;QAC3B,OAAO;YACL+D,eAAe;YACfpB,aAAa5C,aAAaC,MAAM;YAChCwC,UAAUnD,YAAYU,aAAaC,MAAM;YACzC6C,UAAU9C,aAAaC,MAAM;YAC7B,GAAGf,2BAA2Be,KAAK;YACnCyC,eAAenC,aAAaN;YAC5B0C,YAAY,YAAa1C,CAAAA,KAAKE,UAAU,IAAI,CAAC,CAAA,IACzCG,oBAAoBL,MAAM,YAAY,SAAS,UAC/CI;YACJ2C,WAAWhD,aAAaC,MAAM;YAC9BuC,WAAWxD,6BAA6BiB,MAAM;QAChD;IACF;IACAgE,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBhD,SAAS;IACTiD,iBAAiB;QACftB,OAAO;IACT;IACAuB,oBAAmB,EAAEnE,UAAU,EAAE;QAC/B,MAAMoE,WAAqB;eAAIhF,sBAAsB,QAAQY;SAAY;QAEzE,IAAI,OAAOA,WAAWK,SAAS,KAAK,YAAY,CAACX,gBAAgBM,WAAWK,SAAS,GACnF+D,SAASC,IAAI,CACX,CAAC,wBAAwB,EAAErE,WAAWK,SAAS,CAAC,oBAAoB,EAAEZ,wBAAwB,EAAE,CAAC;QAGrG,OAAO2E;IACT;AACF,EAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js';
|
|
1
2
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
2
3
|
import { getSafeHref, getUnsafeHrefWarnings } from '../urls.js';
|
|
3
4
|
import { DEFAULT_CARD_LINK_SCOPE } from './card.js';
|
|
@@ -16,12 +17,15 @@ export const CARDS_LINK_SCOPES = [
|
|
|
16
17
|
];
|
|
17
18
|
export const DEFAULT_CARDS_LINK_SCOPE = 'section';
|
|
18
19
|
export const FALLBACK_CARDS_LINK_SCOPE = 'card';
|
|
20
|
+
// Columns collapse on the grid's own width (not the viewport): up to N
|
|
21
|
+
// columns while each stays at least 14rem wide. The 2rem term covers the
|
|
22
|
+
// widest theme gap, so a theme's gap never costs a column that would fit.
|
|
19
23
|
const cardGridColumnClasses = {
|
|
20
24
|
'1': 'grid-cols-1',
|
|
21
|
-
'2': 'grid-cols-
|
|
22
|
-
'3': 'grid-cols-
|
|
23
|
-
'4': 'grid-cols-
|
|
24
|
-
auto: 'grid-cols-
|
|
25
|
+
'2': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2rem)/2))),1fr))]',
|
|
26
|
+
'3': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_2*2rem)/3))),1fr))]',
|
|
27
|
+
'4': 'grid-cols-[repeat(auto-fill,minmax(min(100%,max(14rem,calc((100%_-_3*2rem)/4))),1fr))]',
|
|
28
|
+
auto: 'grid-cols-[repeat(auto-fit,minmax(min(100%,16rem),1fr))]'
|
|
25
29
|
};
|
|
26
30
|
function isCardGridColumns(value) {
|
|
27
31
|
return typeof value === 'string' && CARD_GRID_COLUMNS.includes(value);
|
|
@@ -68,7 +72,7 @@ function makeSectionLink(href, newTab) {
|
|
|
68
72
|
...getLinkProperties(href, newTab),
|
|
69
73
|
ariaLabel: 'Open card section',
|
|
70
74
|
className: [
|
|
71
|
-
'absolute inset-
|
|
75
|
+
'not-prose absolute -inset-2 z-10 rounded-3xl focus:outline-none focus-visible:ring-2 focus-visible:ring-[color:var(--pmd-accent,color-mix(in_oklab,#22d3ee_calc(var(--pmd-scheme-dark,1)*100%),#0e7490))]'
|
|
72
76
|
],
|
|
73
77
|
dataDirectiveLink: 'cards'
|
|
74
78
|
},
|
|
@@ -95,8 +99,10 @@ export const cardsDirective = {
|
|
|
95
99
|
'cardTheme',
|
|
96
100
|
'columns',
|
|
97
101
|
'href',
|
|
102
|
+
'iconPalette',
|
|
98
103
|
'linkScope',
|
|
99
104
|
'newTab',
|
|
105
|
+
'palette',
|
|
100
106
|
'theme'
|
|
101
107
|
],
|
|
102
108
|
applyHast (node, config, { mergeClassNames }) {
|
|
@@ -112,6 +118,10 @@ export const cardsDirective = {
|
|
|
112
118
|
for (const child of node.children){
|
|
113
119
|
if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue;
|
|
114
120
|
if (typeof child.properties.dataTheme !== 'string' && cardTheme) child.properties.dataTheme = cardTheme;
|
|
121
|
+
// Cards without a palette of their own paint their icons with the
|
|
122
|
+
// grid's iconPalette (or palette); the grid's surface tokens are inherited.
|
|
123
|
+
const iconPaletteDefault = node.properties.dataIconPalette ?? node.properties.dataPalette;
|
|
124
|
+
if (typeof iconPaletteDefault === 'string' && typeof child.properties.dataPalette !== 'string' && typeof child.properties.dataIconPalette !== 'string') child.properties.dataIconPalette = iconPaletteDefault;
|
|
115
125
|
if (href && linkScope === 'section') {
|
|
116
126
|
delete child.properties.dataHref;
|
|
117
127
|
delete child.properties.dataLinkScope;
|
|
@@ -128,7 +138,9 @@ export const cardsDirective = {
|
|
|
128
138
|
node.properties.dataLinkScope = linkScope;
|
|
129
139
|
node.properties.dataNewTab = newTab ? 'true' : 'false';
|
|
130
140
|
}
|
|
131
|
-
node
|
|
141
|
+
applyDirectivePalette(node, config);
|
|
142
|
+
node.properties.className = mergeClassNames(// Spacing lives in the theme; the base only sets what every grid needs.
|
|
143
|
+
'grid [&>article]:my-0', href && linkScope === 'section' ? 'relative cursor-pointer [&>article]:transition-colors hover:[&>article]:border-[color:color-mix(in_oklab,rgb(255_255_255/0.15)_calc(var(--pmd-scheme-dark,1)*100%),rgb(0_0_0/0.2))] [&_a:not([data-directive-link])]:relative [&_a:not([data-directive-link])]:z-20' : undefined, theme.hookClassName, theme.modifierClassName, theme.classes, cardGridColumnClasses[isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS]);
|
|
132
144
|
if (href && linkScope === 'section') node.children = [
|
|
133
145
|
makeSectionLink(href, newTab),
|
|
134
146
|
...node.children
|
|
@@ -156,6 +168,7 @@ export const cardsDirective = {
|
|
|
156
168
|
getMdastRenderProperties (node) {
|
|
157
169
|
const href = getSafeHref(getAttribute(node, 'href'));
|
|
158
170
|
return {
|
|
171
|
+
...getPaletteRenderProperties(node),
|
|
159
172
|
dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,
|
|
160
173
|
dataColumns: resolveCardGridColumns(node),
|
|
161
174
|
dataDirective: 'cards',
|