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 { 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,M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CAACrB,IAAI,IAC9DmB,SAASC,IAAI,CAAC;aACXD,SAASC,IAAI,IAAInD,sBAAsB,UAAUiD;QAEtD,OAAOC;IACT;AACF,EAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { parseIconEntries } from '../../icons/entries.js';
|
|
1
2
|
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
2
3
|
import { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js';
|
|
3
4
|
import { getDirectiveLabelOrAttribute } from '../labels.js';
|
|
5
|
+
import { applyDirectivePalette, getPaletteRenderProperties, PALETTE_ATTRIBUTES, resolveIconPaletteName } from '../palette.js';
|
|
4
6
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
5
7
|
export const CALLOUT_VARIANTS = [
|
|
6
8
|
'note',
|
|
@@ -36,6 +38,7 @@ export const calloutDirective = {
|
|
|
36
38
|
name: 'callout',
|
|
37
39
|
allowedAttributes: [
|
|
38
40
|
'icon',
|
|
41
|
+
...PALETTE_ATTRIBUTES,
|
|
39
42
|
'theme',
|
|
40
43
|
'title',
|
|
41
44
|
'variant'
|
|
@@ -43,13 +46,16 @@ export const calloutDirective = {
|
|
|
43
46
|
applyHast (node, config, { mergeClassNames }) {
|
|
44
47
|
const variant = typeof node.properties.dataVariant === 'string' ? node.properties.dataVariant : 'note';
|
|
45
48
|
const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : undefined;
|
|
46
|
-
|
|
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;
|
|
47
52
|
const theme = resolveDirectiveTheme('callout', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : 'soft', config.themes);
|
|
48
53
|
const children = node.children;
|
|
49
54
|
// An icon without a title sits beside the body instead of on its own row.
|
|
50
55
|
const iconBesideBody = Boolean(icon && !title);
|
|
51
56
|
node.properties.dataTheme = theme.name;
|
|
52
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);
|
|
53
59
|
node.children = [
|
|
54
60
|
...title || icon ? [
|
|
55
61
|
{
|
|
@@ -59,7 +65,7 @@ export const calloutDirective = {
|
|
|
59
65
|
makeDirectiveIconPlaceholder(icon, [
|
|
60
66
|
'pmd-callout__icon inline-flex size-4 shrink-0 text-current',
|
|
61
67
|
iconBesideBody ? 'mt-1.5' : 'mt-0.5'
|
|
62
|
-
])
|
|
68
|
+
], resolveIconPaletteName(node, iconEntry))
|
|
63
69
|
] : [],
|
|
64
70
|
...title ? [
|
|
65
71
|
{
|
|
@@ -104,6 +110,7 @@ export const calloutDirective = {
|
|
|
104
110
|
return {
|
|
105
111
|
dataDirective: 'callout',
|
|
106
112
|
dataIcon: typeof node.attributes?.icon === 'string' ? node.attributes.icon : undefined,
|
|
113
|
+
...getPaletteRenderProperties(node),
|
|
107
114
|
dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'soft',
|
|
108
115
|
dataTitle: getTitle(node),
|
|
109
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 { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\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\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', '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 // 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 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 iconBesideBody ? 'mt-1.5' : 'mt-0.5',\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 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":["DIRECTIVE_BODY_CLASS","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","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,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,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,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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AE,GAAG,EAAE;qBAC3D;oBACDF,YAAY;wBACVa,WAAW;4BACTF,iBACI,4BACA;yBACL;wBACDO,oBAAoB;oBACtB;oBACAC,SAAS;gBACX;aACD,GACD,EAAE;YACN;gBACEF,MAAM;gBACNP;gBACAV,YAAY;oBACVa,WAAW;wBAACvC;wBAAsBqC,iBAAiB,mBAAmB;qBAAG,CAACS,MAAM,CAACR;oBACjFS,mBAAmB;gBACrB;gBACAF,SAAS;YACX;SACD;IACH;IACAG,mBAAmB;QACjB/B,SAAS;IACX;IACAgC,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyBtC,IAAI;QAC3B,OAAO;YACLuC,eAAe;YACfvB,UAAU,OAAOhB,KAAKE,UAAU,EAAEa,SAAS,WAAWf,KAAKE,UAAU,CAACa,IAAI,GAAGD;YAC7EI,WAAW,OAAOlB,KAAKE,UAAU,EAAEe,UAAU,WAAWjB,KAAKE,UAAU,CAACe,KAAK,GAAG;YAChFJ,WAAWV,SAASH;YACpBW,aAAaZ,sBAAsBC;QACrC;IACF;IACAwC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBd,SAAS;IACTe,iBAAiB;QACf3B,OAAO;IACT;IACA4B,oBAAmB,EAAE3C,UAAU,EAAE;QAC/B,MAAM4C,WAAqB,EAAE;QAE7B,IAAI,OAAO5C,WAAWD,OAAO,KAAK,YAAY,CAACL,iBAAiBM,WAAWD,OAAO,GAChF6C,SAASC,IAAI,CACX,CAAC,6BAA6B,EAAE7C,WAAWD,OAAO,CAAC,0BAA0B,CAAC;QAGlF,OAAO6C;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":"A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BzC,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"}
|
|
@@ -5,6 +5,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];
|
|
7
7
|
export declare function isCardLinkScope(value: unknown): value is CardLinkScope;
|
|
8
|
-
/** `icon` takes one icon ref or a comma-separated list (`@fa/debian, @fa/ubuntu`). */
|
|
9
|
-
export declare function parseCardIcons(value: string | undefined): string[];
|
|
10
8
|
export declare const cardDirective: LayoutDirectiveDefinition;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { parseIconEntries } from '../../icons/entries.js';
|
|
1
2
|
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
2
3
|
import { makeDirectiveIconPlaceholder } from '../iconPlaceholder.js';
|
|
3
4
|
import { getDirectiveLabelOrAttribute } from '../labels.js';
|
|
5
|
+
import { applyDirectivePalette, getPaletteRenderProperties, PALETTE_ATTRIBUTES, resolveIconPaletteName } from '../palette.js';
|
|
4
6
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
5
7
|
import { getSafeHref, getUnsafeHrefWarnings } from '../urls.js';
|
|
6
8
|
export const CARD_BODY_CLASS_NAMES = DIRECTIVE_BODY_CLASS;
|
|
@@ -93,15 +95,15 @@ function makeFullCardLink(href, title, newTab) {
|
|
|
93
95
|
tagName: 'a'
|
|
94
96
|
};
|
|
95
97
|
}
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function makeIcons(icons, hasEyebrow) {
|
|
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) {
|
|
100
102
|
return {
|
|
101
103
|
type: 'element',
|
|
102
|
-
children: icons.map((icon)=>makeDirectiveIconPlaceholder(icon, [
|
|
104
|
+
children: icons.map((icon)=>makeDirectiveIconPlaceholder(icon.ref, [
|
|
103
105
|
'pmd-card__icon inline-flex size-5 text-current'
|
|
104
|
-
])),
|
|
106
|
+
], resolveIconPaletteName(card, icon))),
|
|
105
107
|
properties: {
|
|
106
108
|
className: [
|
|
107
109
|
'not-prose pmd-card__icons mb-3 flex flex-wrap items-center gap-2',
|
|
@@ -142,6 +144,7 @@ export const cardDirective = {
|
|
|
142
144
|
'icon',
|
|
143
145
|
'linkScope',
|
|
144
146
|
'newTab',
|
|
147
|
+
...PALETTE_ATTRIBUTES,
|
|
145
148
|
'theme',
|
|
146
149
|
'title'
|
|
147
150
|
],
|
|
@@ -153,7 +156,7 @@ export const cardDirective = {
|
|
|
153
156
|
const linkScope = typeof node.properties.dataLinkScope === 'string' && isCardLinkScope(node.properties.dataLinkScope) ? node.properties.dataLinkScope : DEFAULT_CARD_LINK_SCOPE;
|
|
154
157
|
const newTab = node.properties.dataNewTab === 'true';
|
|
155
158
|
const eyebrow = typeof node.properties.dataEyebrow === 'string' ? node.properties.dataEyebrow : undefined;
|
|
156
|
-
const icons =
|
|
159
|
+
const { entries: icons } = parseIconEntries(typeof node.properties.dataIcon === 'string' ? node.properties.dataIcon : undefined);
|
|
157
160
|
const theme = resolveDirectiveTheme('card', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
158
161
|
const children = node.children;
|
|
159
162
|
node.properties.dataTheme = theme.name;
|
|
@@ -162,6 +165,7 @@ export const cardDirective = {
|
|
|
162
165
|
node.properties.dataNewTab = newTab ? 'true' : 'false';
|
|
163
166
|
}
|
|
164
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);
|
|
165
169
|
node.children = [
|
|
166
170
|
...href && linkScope === 'full' ? [
|
|
167
171
|
makeFullCardLink(href, title, newTab)
|
|
@@ -170,7 +174,7 @@ export const cardDirective = {
|
|
|
170
174
|
makeEyebrow(eyebrow)
|
|
171
175
|
] : [],
|
|
172
176
|
...icons.length > 0 ? [
|
|
173
|
-
makeIcons(icons, Boolean(eyebrow))
|
|
177
|
+
makeIcons(node, icons, Boolean(eyebrow))
|
|
174
178
|
] : [],
|
|
175
179
|
...title ? [
|
|
176
180
|
makeTitle(title, href && linkScope === 'title' ? href : undefined, newTab)
|
|
@@ -211,6 +215,7 @@ export const cardDirective = {
|
|
|
211
215
|
dataEyebrow: getAttribute(node, 'eyebrow'),
|
|
212
216
|
dataHref: getSafeHref(getAttribute(node, 'href')),
|
|
213
217
|
dataIcon: getAttribute(node, 'icon'),
|
|
218
|
+
...getPaletteRenderProperties(node),
|
|
214
219
|
dataLinkScope: getLinkScope(node),
|
|
215
220
|
dataNewTab: 'newTab' in (node.attributes ?? {}) ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false' : undefined,
|
|
216
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 { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\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 = 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/** `icon` takes one icon ref or a comma-separated list (`@fa/debian, @fa/ubuntu`). */\nexport function parseCardIcons(value: string | undefined): string[] {\n return value?.split(',').map((icon) => icon.trim()).filter(Boolean) ?? []\n}\n\nfunction makeIcons(icons: string[], hasEyebrow: boolean): Element {\n return {\n type: 'element',\n children: icons.map((icon) =>\n makeDirectiveIconPlaceholder(icon, ['pmd-card__icon inline-flex size-5 text-current']),\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', '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 icons = parseCardIcons(\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 node.children = [\n ...(href && linkScope === 'full' ? [makeFullCardLink(href, title, newTab)] : []),\n ...(eyebrow ? [makeEyebrow(eyebrow)] : []),\n ...(icons.length > 0 ? [makeIcons(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 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":["DIRECTIVE_BODY_CLASS","makeDirectiveIconPlaceholder","getDirectiveLabelOrAttribute","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","parseCardIcons","split","map","icon","filter","Boolean","makeIcons","icons","hasEyebrow","makeEyebrow","eyebrow","dataDirectiveEyebrow","cardDirective","allowedAttributes","applyHast","config","mergeClassNames","dataTitle","dataHref","dataLinkScope","dataNewTab","dataEyebrow","dataIcon","theme","dataTheme","themes","hookClassName","modifierClassName","classes","length","dataDirectiveBody","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push"],"mappings":"AAKA,SAASA,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,wBAAuB;AACpE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAE/D,OAAO,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,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
|
+
{"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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AgE,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';
|
|
@@ -98,8 +99,10 @@ export const cardsDirective = {
|
|
|
98
99
|
'cardTheme',
|
|
99
100
|
'columns',
|
|
100
101
|
'href',
|
|
102
|
+
'iconPalette',
|
|
101
103
|
'linkScope',
|
|
102
104
|
'newTab',
|
|
105
|
+
'palette',
|
|
103
106
|
'theme'
|
|
104
107
|
],
|
|
105
108
|
applyHast (node, config, { mergeClassNames }) {
|
|
@@ -115,6 +118,10 @@ export const cardsDirective = {
|
|
|
115
118
|
for (const child of node.children){
|
|
116
119
|
if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue;
|
|
117
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;
|
|
118
125
|
if (href && linkScope === 'section') {
|
|
119
126
|
delete child.properties.dataHref;
|
|
120
127
|
delete child.properties.dataLinkScope;
|
|
@@ -131,6 +138,7 @@ export const cardsDirective = {
|
|
|
131
138
|
node.properties.dataLinkScope = linkScope;
|
|
132
139
|
node.properties.dataNewTab = newTab ? 'true' : 'false';
|
|
133
140
|
}
|
|
141
|
+
applyDirectivePalette(node, config);
|
|
134
142
|
node.properties.className = mergeClassNames(// Spacing lives in the theme; the base only sets what every grid needs.
|
|
135
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]);
|
|
136
144
|
if (href && linkScope === 'section') node.children = [
|
|
@@ -160,6 +168,7 @@ export const cardsDirective = {
|
|
|
160
168
|
getMdastRenderProperties (node) {
|
|
161
169
|
const href = getSafeHref(getAttribute(node, 'href'));
|
|
162
170
|
return {
|
|
171
|
+
...getPaletteRenderProperties(node),
|
|
163
172
|
dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,
|
|
164
173
|
dataColumns: resolveCardGridColumns(node),
|
|
165
174
|
dataDirective: 'cards',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/cards.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\nimport { DEFAULT_CARD_LINK_SCOPE } from './card.js'\n\nexport const CARD_GRID_COLUMNS = ['1', '2', '3', '4', 'auto'] as const\nexport const DEFAULT_CARD_GRID_COLUMNS = '3'\nexport const CARDS_LINK_SCOPES = ['section', 'card', 'title'] as const\nexport const DEFAULT_CARDS_LINK_SCOPE = 'section'\nexport const FALLBACK_CARDS_LINK_SCOPE = 'card'\n\nexport type CardGridColumns = (typeof CARD_GRID_COLUMNS)[number]\nexport type CardsLinkScope = (typeof CARDS_LINK_SCOPES)[number]\n\n// Columns collapse on the grid's own width (not the viewport): up to N\n// columns while each stays at least 14rem wide. The 2rem term covers the\n// widest theme gap, so a theme's gap never costs a column that would fit.\nconst cardGridColumnClasses: Record<CardGridColumns, 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\nfunction isCardGridColumns(value: unknown): value is CardGridColumns {\n return typeof value === 'string' && CARD_GRID_COLUMNS.includes(value as CardGridColumns)\n}\n\nfunction isCardsLinkScope(value: unknown): value is CardsLinkScope {\n return typeof value === 'string' && CARDS_LINK_SCOPES.includes(value as CardsLinkScope)\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 hasAttribute(node: ContainerDirective, name: string): boolean {\n return Object.prototype.hasOwnProperty.call(node.attributes ?? {}, name)\n}\n\nfunction getCardsLinkScope(node: ContainerDirective): CardsLinkScope {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return DEFAULT_CARDS_LINK_SCOPE\n\n return isCardsLinkScope(value) ? value : FALLBACK_CARDS_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 makeSectionLink(href: string, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: 'Open card section',\n className: [\n '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))]',\n ],\n dataDirectiveLink: 'cards',\n },\n tagName: 'a',\n }\n}\n\nfunction hasCardLinkOverride(node: ContainerDirective): boolean {\n return ['href', 'linkScope', 'newTab'].some((name) => hasAttribute(node, name))\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\nexport function resolveCardGridColumns(node: ContainerDirective): CardGridColumns {\n const columns = node.attributes?.columns\n\n return isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS\n}\n\nexport const cardsDirective: LayoutDirectiveDefinition = {\n name: 'cards',\n allowedAttributes: ['cardTheme', 'columns', 'href', 'linkScope', 'newTab', 'theme'],\n applyHast(node, config, { mergeClassNames }) {\n const columns =\n typeof node.properties.dataColumns === 'string'\n ? node.properties.dataColumns\n : DEFAULT_CARD_GRID_COLUMNS\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' && isCardsLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARDS_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const theme = resolveDirectiveTheme(\n 'cards',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const cardTheme =\n typeof node.properties.dataCardTheme === 'string' ? node.properties.dataCardTheme : undefined\n const childLinkScope = linkScope === 'title' ? 'title' : DEFAULT_CARD_LINK_SCOPE\n\n for (const child of node.children) {\n if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue\n\n if (typeof child.properties.dataTheme !== 'string' && cardTheme)\n child.properties.dataTheme = cardTheme\n\n if (href && linkScope === 'section') {\n delete child.properties.dataHref\n delete child.properties.dataLinkScope\n delete child.properties.dataNewTab\n continue\n }\n\n if (!href) continue\n\n if (typeof child.properties.dataHref !== 'string') child.properties.dataHref = href\n if (typeof child.properties.dataLinkScope !== 'string')\n child.properties.dataLinkScope = childLinkScope\n if (typeof child.properties.dataNewTab !== 'string')\n child.properties.dataNewTab = newTab ? 'true' : 'false'\n }\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 // Spacing lives in the theme; the base only sets what every grid needs.\n 'grid [&>article]:my-0',\n href && linkScope === 'section'\n ? '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'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n cardGridColumnClasses[isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS],\n )\n\n if (href && linkScope === 'section') node.children = [makeSectionLink(href, newTab), ...node.children]\n },\n attributeValues: {\n columns: CARD_GRID_COLUMNS,\n linkScope: CARDS_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n defaultAttributes: {\n columns: DEFAULT_CARD_GRID_COLUMNS,\n linkScope: DEFAULT_CARDS_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Responsive card grid for docs and landing-page content.',\n editor: {\n detail: 'Layout directive',\n label: 'Cards',\n snippet:\n ':::cards{\\n columns=\"${3}\"\\n}\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const href = getSafeHref(getAttribute(node, 'href'))\n\n return {\n dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,\n dataColumns: resolveCardGridColumns(node),\n dataDirective: 'cards',\n dataHref: href,\n dataLinkScope: href || hasAttribute(node, 'linkScope') ? getCardsLinkScope(node) : undefined,\n dataNewTab: href && hasAttribute(node, 'newTab')\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'cards',\n openMarker: ':::cards',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n cardTheme: 'card',\n theme: 'cards',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('cards', attributes)]\n\n if (typeof attributes.columns === 'string' && !isCardGridColumns(attributes.columns))\n warnings.push(\n `Invalid cards columns \"${attributes.columns}\". Falling back to \"${DEFAULT_CARD_GRID_COLUMNS}\".`,\n )\n\n if (typeof attributes.linkScope === 'string' && !isCardsLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid cards linkScope \"${attributes.linkScope}\". Falling back to \"${FALLBACK_CARDS_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n validateMdast(node) {\n const warnings: string[] = []\n\n if (getSafeHref(getAttribute(node, 'href')) && getCardsLinkScope(node) === 'section') {\n const hasOverrides = node.children.some(\n (child) => isContainerDirective(child) && child.name === 'card' && hasCardLinkOverride(child),\n )\n\n if (hasOverrides)\n warnings.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n return warnings\n },\n}\n"],"names":["resolveDirectiveTheme","getSafeHref","getUnsafeHrefWarnings","DEFAULT_CARD_LINK_SCOPE","CARD_GRID_COLUMNS","DEFAULT_CARD_GRID_COLUMNS","CARDS_LINK_SCOPES","DEFAULT_CARDS_LINK_SCOPE","FALLBACK_CARDS_LINK_SCOPE","cardGridColumnClasses","auto","isCardGridColumns","value","includes","isCardsLinkScope","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","hasAttribute","Object","prototype","hasOwnProperty","call","getCardsLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeSectionLink","type","children","properties","ariaLabel","className","dataDirectiveLink","tagName","hasCardLinkOverride","some","isContainerDirective","Boolean","resolveCardGridColumns","columns","cardsDirective","allowedAttributes","applyHast","config","mergeClassNames","dataColumns","dataHref","dataLinkScope","dataNewTab","theme","dataTheme","themes","cardTheme","dataCardTheme","childLinkScope","child","dataVlLayout","hookClassName","modifierClassName","classes","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push","validateMdast","hasOverrides"],"mappings":"AAKA,SAASA,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAC/D,SAASC,uBAAuB,QAAQ,YAAW;AAEnD,OAAO,MAAMC,oBAAoB;IAAC;IAAK;IAAK;IAAK;IAAK;CAAO,CAAS;AACtE,OAAO,MAAMC,4BAA4B,IAAG;AAC5C,OAAO,MAAMC,oBAAoB;IAAC;IAAW;IAAQ;CAAQ,CAAS;AACtE,OAAO,MAAMC,2BAA2B,UAAS;A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,SAASC,IAAI,CACX,CAAC,uBAAuB,EAAElE,WAAW6B,OAAO,CAAC,oBAAoB,EAAE1C,0BAA0B,EAAE,CAAC;QAGpG,IAAI,OAAOa,WAAWU,SAAS,KAAK,YAAY,CAACd,iBAAiBI,WAAWU,SAAS,GACpFuD,SAASC,IAAI,CACX,CAAC,yBAAyB,EAAElE,WAAWU,SAAS,CAAC,oBAAoB,EAAEpB,0BAA0B,EAAE,CAAC;QAGxG,OAAO2E;IACT;IACAE,eAAcrE,IAAI;QAChB,MAAMmE,WAAqB,EAAE;QAE7B,IAAIlF,YAAYc,aAAaC,MAAM,YAAYW,kBAAkBX,UAAU,WAAW;YACpF,MAAMsE,eAAetE,KAAKoB,QAAQ,CAACO,IAAI,CACrC,CAACoB,QAAUnB,qBAAqBmB,UAAUA,MAAM9C,IAAI,KAAK,UAAUyB,oBAAoBqB;YAGzF,IAAIuB,cACFH,SAASC,IAAI,CACX;QAEN;QAEA,OAAOD;IACT;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/cards.ts"],"sourcesContent":["import type { Element } from 'hast'\nimport type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\nimport { getSafeHref, getUnsafeHrefWarnings } from '../urls.js'\nimport { DEFAULT_CARD_LINK_SCOPE } from './card.js'\n\nexport const CARD_GRID_COLUMNS = ['1', '2', '3', '4', 'auto'] as const\nexport const DEFAULT_CARD_GRID_COLUMNS = '3'\nexport const CARDS_LINK_SCOPES = ['section', 'card', 'title'] as const\nexport const DEFAULT_CARDS_LINK_SCOPE = 'section'\nexport const FALLBACK_CARDS_LINK_SCOPE = 'card'\n\nexport type CardGridColumns = (typeof CARD_GRID_COLUMNS)[number]\nexport type CardsLinkScope = (typeof CARDS_LINK_SCOPES)[number]\n\n// Columns collapse on the grid's own width (not the viewport): up to N\n// columns while each stays at least 14rem wide. The 2rem term covers the\n// widest theme gap, so a theme's gap never costs a column that would fit.\nconst cardGridColumnClasses: Record<CardGridColumns, 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\nfunction isCardGridColumns(value: unknown): value is CardGridColumns {\n return typeof value === 'string' && CARD_GRID_COLUMNS.includes(value as CardGridColumns)\n}\n\nfunction isCardsLinkScope(value: unknown): value is CardsLinkScope {\n return typeof value === 'string' && CARDS_LINK_SCOPES.includes(value as CardsLinkScope)\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 hasAttribute(node: ContainerDirective, name: string): boolean {\n return Object.prototype.hasOwnProperty.call(node.attributes ?? {}, name)\n}\n\nfunction getCardsLinkScope(node: ContainerDirective): CardsLinkScope {\n const value = node.attributes?.linkScope\n\n if (typeof value !== 'string') return DEFAULT_CARDS_LINK_SCOPE\n\n return isCardsLinkScope(value) ? value : FALLBACK_CARDS_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 makeSectionLink(href: string, newTab: boolean): Element {\n return {\n type: 'element',\n children: [],\n properties: {\n ...getLinkProperties(href, newTab),\n ariaLabel: 'Open card section',\n className: [\n '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))]',\n ],\n dataDirectiveLink: 'cards',\n },\n tagName: 'a',\n }\n}\n\nfunction hasCardLinkOverride(node: ContainerDirective): boolean {\n return ['href', 'linkScope', 'newTab'].some((name) => hasAttribute(node, name))\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\nexport function resolveCardGridColumns(node: ContainerDirective): CardGridColumns {\n const columns = node.attributes?.columns\n\n return isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS\n}\n\nexport const cardsDirective: LayoutDirectiveDefinition = {\n name: 'cards',\n allowedAttributes: ['cardTheme', 'columns', 'href', 'iconPalette', 'linkScope', 'newTab', 'palette', 'theme'],\n applyHast(node, config, { mergeClassNames }) {\n const columns =\n typeof node.properties.dataColumns === 'string'\n ? node.properties.dataColumns\n : DEFAULT_CARD_GRID_COLUMNS\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' && isCardsLinkScope(node.properties.dataLinkScope)\n ? node.properties.dataLinkScope\n : DEFAULT_CARDS_LINK_SCOPE\n const newTab = node.properties.dataNewTab === 'true'\n const theme = resolveDirectiveTheme(\n 'cards',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n const cardTheme =\n typeof node.properties.dataCardTheme === 'string' ? node.properties.dataCardTheme : undefined\n const childLinkScope = linkScope === 'title' ? 'title' : DEFAULT_CARD_LINK_SCOPE\n\n for (const child of node.children) {\n if (child.type !== 'element' || child.properties?.dataVlLayout !== 'card') continue\n\n if (typeof child.properties.dataTheme !== 'string' && cardTheme)\n child.properties.dataTheme = cardTheme\n\n // Cards without a palette of their own paint their icons with the\n // grid's iconPalette (or palette); the grid's surface tokens are inherited.\n const iconPaletteDefault = node.properties.dataIconPalette ?? node.properties.dataPalette\n if (\n typeof iconPaletteDefault === 'string' &&\n typeof child.properties.dataPalette !== 'string' &&\n typeof child.properties.dataIconPalette !== 'string'\n )\n child.properties.dataIconPalette = iconPaletteDefault\n\n if (href && linkScope === 'section') {\n delete child.properties.dataHref\n delete child.properties.dataLinkScope\n delete child.properties.dataNewTab\n continue\n }\n\n if (!href) continue\n\n if (typeof child.properties.dataHref !== 'string') child.properties.dataHref = href\n if (typeof child.properties.dataLinkScope !== 'string')\n child.properties.dataLinkScope = childLinkScope\n if (typeof child.properties.dataNewTab !== 'string')\n child.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n\n node.properties.dataTheme = theme.name\n if (href) {\n node.properties.dataLinkScope = linkScope\n node.properties.dataNewTab = newTab ? 'true' : 'false'\n }\n applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n // Spacing lives in the theme; the base only sets what every grid needs.\n 'grid [&>article]:my-0',\n href && linkScope === 'section'\n ? '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'\n : undefined,\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n cardGridColumnClasses[isCardGridColumns(columns) ? columns : DEFAULT_CARD_GRID_COLUMNS],\n )\n\n if (href && linkScope === 'section') node.children = [makeSectionLink(href, newTab), ...node.children]\n },\n attributeValues: {\n columns: CARD_GRID_COLUMNS,\n linkScope: CARDS_LINK_SCOPES,\n newTab: ['true', 'false'],\n },\n defaultAttributes: {\n columns: DEFAULT_CARD_GRID_COLUMNS,\n linkScope: DEFAULT_CARDS_LINK_SCOPE,\n newTab: 'false',\n },\n description: 'Responsive card grid for docs and landing-page content.',\n editor: {\n detail: 'Layout directive',\n label: 'Cards',\n snippet:\n ':::cards{\\n columns=\"${3}\"\\n}\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::card[${Title}]\\n${Content}\\n:::\\n\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n const href = getSafeHref(getAttribute(node, 'href'))\n\n return {\n ...getPaletteRenderProperties(node),\n dataCardTheme: typeof node.attributes?.cardTheme === 'string' ? node.attributes.cardTheme : undefined,\n dataColumns: resolveCardGridColumns(node),\n dataDirective: 'cards',\n dataHref: href,\n dataLinkScope: href || hasAttribute(node, 'linkScope') ? getCardsLinkScope(node) : undefined,\n dataNewTab: href && hasAttribute(node, 'newTab')\n ? getBooleanAttribute(node, 'newTab') ? 'true' : 'false'\n : undefined,\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'cards',\n openMarker: ':::cards',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n cardTheme: 'card',\n theme: 'cards',\n },\n validateAttributes({ attributes }) {\n const warnings: string[] = [...getUnsafeHrefWarnings('cards', attributes)]\n\n if (typeof attributes.columns === 'string' && !isCardGridColumns(attributes.columns))\n warnings.push(\n `Invalid cards columns \"${attributes.columns}\". Falling back to \"${DEFAULT_CARD_GRID_COLUMNS}\".`,\n )\n\n if (typeof attributes.linkScope === 'string' && !isCardsLinkScope(attributes.linkScope))\n warnings.push(\n `Invalid cards linkScope \"${attributes.linkScope}\". Falling back to \"${FALLBACK_CARDS_LINK_SCOPE}\".`,\n )\n\n return warnings\n },\n validateMdast(node) {\n const warnings: string[] = []\n\n if (getSafeHref(getAttribute(node, 'href')) && getCardsLinkScope(node) === 'section') {\n const hasOverrides = node.children.some(\n (child) => isContainerDirective(child) && child.name === 'card' && hasCardLinkOverride(child),\n )\n\n if (hasOverrides)\n warnings.push(\n 'Directive \"cards\" with linkScope=\"section\" ignores child \"card\" link overrides.',\n )\n }\n\n return warnings\n },\n}\n"],"names":["applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","getSafeHref","getUnsafeHrefWarnings","DEFAULT_CARD_LINK_SCOPE","CARD_GRID_COLUMNS","DEFAULT_CARD_GRID_COLUMNS","CARDS_LINK_SCOPES","DEFAULT_CARDS_LINK_SCOPE","FALLBACK_CARDS_LINK_SCOPE","cardGridColumnClasses","auto","isCardGridColumns","value","includes","isCardsLinkScope","getAttribute","node","name","attributes","trim","undefined","getBooleanAttribute","hasAttribute","Object","prototype","hasOwnProperty","call","getCardsLinkScope","linkScope","getLinkProperties","href","newTab","rel","target","makeSectionLink","type","children","properties","ariaLabel","className","dataDirectiveLink","tagName","hasCardLinkOverride","some","isContainerDirective","Boolean","resolveCardGridColumns","columns","cardsDirective","allowedAttributes","applyHast","config","mergeClassNames","dataColumns","dataHref","dataLinkScope","dataNewTab","theme","dataTheme","themes","cardTheme","dataCardTheme","childLinkScope","child","dataVlLayout","iconPaletteDefault","dataIconPalette","dataPalette","hookClassName","modifierClassName","classes","attributeValues","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","kind","openMarker","public","supportsAttributes","themeAttributes","validateAttributes","warnings","push","validateMdast","hasOverrides"],"mappings":"AAKA,SAASA,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AACpD,SAASC,WAAW,EAAEC,qBAAqB,QAAQ,aAAY;AAC/D,SAASC,uBAAuB,QAAQ,YAAW;AAEnD,OAAO,MAAMC,oBAAoB;IAAC;IAAK;IAAK;IAAK;IAAK;CAAO,CAAS;AACtE,OAAO,MAAMC,4BAA4B,IAAG;AAC5C,OAAO,MAAMC,oBAAoB;IAAC;IAAW;IAAQ;CAAQ,CAAS;AACtE,OAAO,MAAMC,2BAA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OAAO1C,KAAKE,UAAU,EAAEuC,UAAU,WAAWzC,KAAKE,UAAU,CAACuC,KAAK,GAAG;QAClF;IACF;IACAuB,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpB1C,SAAS;IACT2C,iBAAiB;QACfxB,WAAW;QACXH,OAAO;IACT;IACA4B,oBAAmB,EAAEnE,UAAU,EAAE;QAC/B,MAAMoE,WAAqB;eAAIpF,sBAAsB,SAASgB;SAAY;QAE1E,IAAI,OAAOA,WAAW6B,OAAO,KAAK,YAAY,CAACpC,kBAAkBO,WAAW6B,OAAO,GACjFuC,SAASC,IAAI,CACX,CAAC,uBAAuB,EAAErE,WAAW6B,OAAO,CAAC,oBAAoB,EAAE1C,0BAA0B,EAAE,CAAC;QAGpG,IAAI,OAAOa,WAAWU,SAAS,KAAK,YAAY,CAACd,iBAAiBI,WAAWU,SAAS,GACpF0D,SAASC,IAAI,CACX,CAAC,yBAAyB,EAAErE,WAAWU,SAAS,CAAC,oBAAoB,EAAEpB,0BAA0B,EAAE,CAAC;QAGxG,OAAO8E;IACT;IACAE,eAAcxE,IAAI;QAChB,MAAMsE,WAAqB,EAAE;QAE7B,IAAIrF,YAAYc,aAAaC,MAAM,YAAYW,kBAAkBX,UAAU,WAAW;YACpF,MAAMyE,eAAezE,KAAKoB,QAAQ,CAACO,IAAI,CACrC,CAACoB,QAAUnB,qBAAqBmB,UAAUA,MAAM9C,IAAI,KAAK,UAAUyB,oBAAoBqB;YAGzF,IAAI0B,cACFH,SAASC,IAAI,CACX;QAEN;QAEA,OAAOD;IACT;AACF,EAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js';
|
|
2
2
|
import { getDirectiveLabelOrAttribute } from '../labels.js';
|
|
3
|
+
import { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js';
|
|
3
4
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
4
5
|
const DEFAULT_DETAILS_TITLE = 'Details';
|
|
5
6
|
function getTitle(node) {
|
|
@@ -10,6 +11,7 @@ export const detailsDirective = {
|
|
|
10
11
|
name: 'details',
|
|
11
12
|
allowedAttributes: [
|
|
12
13
|
'open',
|
|
14
|
+
'palette',
|
|
13
15
|
'theme',
|
|
14
16
|
'title'
|
|
15
17
|
],
|
|
@@ -18,6 +20,7 @@ export const detailsDirective = {
|
|
|
18
20
|
const theme = resolveDirectiveTheme('details', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
19
21
|
const children = node.children;
|
|
20
22
|
node.properties.dataTheme = theme.name;
|
|
23
|
+
applyDirectivePalette(node, config);
|
|
21
24
|
node.properties.className = mergeClassNames(theme.hookClassName, theme.modifierClassName, theme.classes);
|
|
22
25
|
node.children = [
|
|
23
26
|
{
|
|
@@ -60,6 +63,7 @@ export const detailsDirective = {
|
|
|
60
63
|
},
|
|
61
64
|
getMdastRenderProperties (node) {
|
|
62
65
|
return {
|
|
66
|
+
...getPaletteRenderProperties(node),
|
|
63
67
|
dataDirective: 'details',
|
|
64
68
|
dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',
|
|
65
69
|
dataTitle: getTitle(node),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/details.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nconst DEFAULT_DETAILS_TITLE = 'Details'\n\nfunction getTitle(node: ContainerDirective): string {\n const title = getDirectiveLabelOrAttribute(node, 'title')\n\n return title ?? DEFAULT_DETAILS_TITLE\n}\n\nexport const detailsDirective: LayoutDirectiveDefinition = {\n name: 'details',\n allowedAttributes: ['open', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : DEFAULT_DETAILS_TITLE\n const theme = resolveDirectiveTheme(\n 'details',\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 node.properties.className = mergeClassNames(\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n\n node.children = [\n {\n type: 'element',\n children: [{ type: 'text', value: title }],\n properties: {\n className: [\n 'not-prose ml-4 cursor-pointer list-outside text-sm font-semibold tracking-wide transition-colors hover:text-(--tw-prose-headings) marker:text-(--tw-prose-captions)',\n ],\n },\n tagName: 'summary',\n },\n {\n type: 'element',\n children,\n properties: {\n className: ['mt-3', DIRECTIVE_BODY_CLASS],\n dataDirectiveBody: 'details',\n },\n tagName: 'div',\n },\n ]\n },\n defaultAttributes: {\n title: DEFAULT_DETAILS_TITLE,\n },\n description: 'Native disclosure block for optional details.',\n editor: {\n detail: 'Static directive',\n label: 'Details',\n snippet: ':::details[${Details}]\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataDirective: 'details',\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataTitle: getTitle(node),\n open: node.attributes?.open === 'true',\n }\n },\n kind: 'details',\n openMarker: ':::details',\n public: true,\n supportsAttributes: true,\n tagName: 'details',\n themeAttributes: {\n theme: 'details',\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","getDirectiveLabelOrAttribute","resolveDirectiveTheme","DEFAULT_DETAILS_TITLE","getTitle","node","title","detailsDirective","name","allowedAttributes","applyHast","config","mergeClassNames","properties","dataTitle","theme","dataTheme","undefined","themes","children","className","hookClassName","modifierClassName","classes","type","value","tagName","dataDirectiveBody","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","attributes","open","kind","openMarker","public","supportsAttributes","themeAttributes"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,MAAMC,wBAAwB;AAE9B,SAASC,SAASC,IAAwB;IACxC,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/details.ts"],"sourcesContent":["import type { ContainerDirective } from 'mdast-util-directive'\n\nimport type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { DIRECTIVE_BODY_CLASS } from '../../styles/directiveSurface.js'\nimport { getDirectiveLabelOrAttribute } from '../labels.js'\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nconst DEFAULT_DETAILS_TITLE = 'Details'\n\nfunction getTitle(node: ContainerDirective): string {\n const title = getDirectiveLabelOrAttribute(node, 'title')\n\n return title ?? DEFAULT_DETAILS_TITLE\n}\n\nexport const detailsDirective: LayoutDirectiveDefinition = {\n name: 'details',\n allowedAttributes: ['open', 'palette', 'theme', 'title'],\n applyHast(node, config, { mergeClassNames }) {\n const title = typeof node.properties.dataTitle === 'string' ? node.properties.dataTitle : DEFAULT_DETAILS_TITLE\n const theme = resolveDirectiveTheme(\n 'details',\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 applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n )\n\n node.children = [\n {\n type: 'element',\n children: [{ type: 'text', value: title }],\n properties: {\n className: [\n 'not-prose ml-4 cursor-pointer list-outside text-sm font-semibold tracking-wide transition-colors hover:text-(--tw-prose-headings) marker:text-(--tw-prose-captions)',\n ],\n },\n tagName: 'summary',\n },\n {\n type: 'element',\n children,\n properties: {\n className: ['mt-3', DIRECTIVE_BODY_CLASS],\n dataDirectiveBody: 'details',\n },\n tagName: 'div',\n },\n ]\n },\n defaultAttributes: {\n title: DEFAULT_DETAILS_TITLE,\n },\n description: 'Native disclosure block for optional details.',\n editor: {\n detail: 'Static directive',\n label: 'Details',\n snippet: ':::details[${Details}]\\n${Content}\\n:::\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n ...getPaletteRenderProperties(node),\n dataDirective: 'details',\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n dataTitle: getTitle(node),\n open: node.attributes?.open === 'true',\n }\n },\n kind: 'details',\n openMarker: ':::details',\n public: true,\n supportsAttributes: true,\n tagName: 'details',\n themeAttributes: {\n theme: 'details',\n },\n}\n"],"names":["DIRECTIVE_BODY_CLASS","getDirectiveLabelOrAttribute","applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","DEFAULT_DETAILS_TITLE","getTitle","node","title","detailsDirective","name","allowedAttributes","applyHast","config","mergeClassNames","properties","dataTitle","theme","dataTheme","undefined","themes","children","className","hookClassName","modifierClassName","classes","type","value","tagName","dataDirectiveBody","defaultAttributes","description","editor","detail","label","snippet","getMdastRenderProperties","dataDirective","attributes","open","kind","openMarker","public","supportsAttributes","themeAttributes"],"mappings":"AAIA,SAASA,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,MAAMC,wBAAwB;AAE9B,SAASC,SAASC,IAAwB;IACxC,MAAMC,QAAQP,6BAA6BM,MAAM;IAEjD,OAAOC,SAASH;AAClB;AAEA,OAAO,MAAMI,mBAA8C;IACzDC,MAAM;IACNC,mBAAmB;QAAC;QAAQ;QAAW;QAAS;KAAQ;IACxDC,WAAUL,IAAI,EAAEM,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMN,QAAQ,OAAOD,KAAKQ,UAAU,CAACC,SAAS,KAAK,WAAWT,KAAKQ,UAAU,CAACC,SAAS,GAAGX;QAC1F,MAAMY,QAAQb,sBACZ,WACA,OAAOG,KAAKQ,UAAU,CAACG,SAAS,KAAK,WAAWX,KAAKQ,UAAU,CAACG,SAAS,GAAGC,WAC5EN,OAAOO,MAAM;QAEf,MAAMC,WAAWd,KAAKc,QAAQ;QAE9Bd,KAAKQ,UAAU,CAACG,SAAS,GAAGD,MAAMP,IAAI;QACtCR,sBAAsBK,MAAMM;QAC5BN,KAAKQ,UAAU,CAACO,SAAS,GAAGR,gBAC1BG,MAAMM,aAAa,EACnBN,MAAMO,iBAAiB,EACvBP,MAAMQ,OAAO;QAGflB,KAAKc,QAAQ,GAAG;YACd;gBACEK,MAAM;gBACNL,UAAU;oBAAC;wBAAEK,MAAM;wBAAQC,OAAOnB;oBAAM;iBAAE;gBAC1CO,YAAY;oBACVO,WAAW;wBACT;qBACD;gBACH;gBACAM,SAAS;YACX;YACA;gBACEF,MAAM;gBACNL;gBACAN,YAAY;oBACVO,WAAW;wBAAC;wBAAQtB;qBAAqB;oBACzC6B,mBAAmB;gBACrB;gBACAD,SAAS;YACX;SACD;IACH;IACAE,mBAAmB;QACjBtB,OAAOH;IACT;IACA0B,aAAa;IACbC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyB7B,IAAI;QAC3B,OAAO;YACL,GAAGJ,2BAA2BI,KAAK;YACnC8B,eAAe;YACfnB,WAAW,OAAOX,KAAK+B,UAAU,EAAErB,UAAU,WAAWV,KAAK+B,UAAU,CAACrB,KAAK,GAAG;YAChFD,WAAWV,SAASC;YACpBgC,MAAMhC,KAAK+B,UAAU,EAAEC,SAAS;QAClC;IACF;IACAC,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBf,SAAS;IACTgB,iBAAiB;QACf3B,OAAO;IACT;AACF,EAAC"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js';
|
|
1
2
|
import { resolveDirectiveTheme } from '../themes.js';
|
|
2
3
|
export const sectionDirective = {
|
|
3
4
|
name: 'section',
|
|
4
5
|
allowedAttributes: [
|
|
6
|
+
'palette',
|
|
5
7
|
'theme'
|
|
6
8
|
],
|
|
7
9
|
applyHast (node, config, { mergeClassNames }) {
|
|
8
10
|
const theme = resolveDirectiveTheme('section', typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined, config.themes);
|
|
9
11
|
node.properties.dataTheme = theme.name;
|
|
12
|
+
applyDirectivePalette(node, config);
|
|
10
13
|
node.properties.className = mergeClassNames('[&>:first-child]:mt-0 [&>:last-child]:mb-0', theme.hookClassName, theme.modifierClassName, theme.classes, config.sectionClassName);
|
|
11
14
|
},
|
|
12
15
|
editor: {
|
|
@@ -16,6 +19,7 @@ export const sectionDirective = {
|
|
|
16
19
|
},
|
|
17
20
|
getMdastRenderProperties (node) {
|
|
18
21
|
return {
|
|
22
|
+
...getPaletteRenderProperties(node),
|
|
19
23
|
dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default'
|
|
20
24
|
};
|
|
21
25
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/directives/definitions/section.ts"],"sourcesContent":["import type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const sectionDirective: LayoutDirectiveDefinition = {\n name: 'section',\n allowedAttributes: ['theme'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'section',\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 '[&>:first-child]:mt-0 [&>:last-child]:mb-0',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n config.sectionClassName,\n )\n },\n editor: {\n detail: 'Layout directive',\n label: 'Layout section',\n snippet: ':::section\\n${Content}\\n:::endsection\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'section',\n openMarker: ':::section',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n theme: 'section',\n },\n}\n"],"names":["resolveDirectiveTheme","sectionDirective","name","allowedAttributes","applyHast","node","config","mergeClassNames","theme","properties","dataTheme","undefined","themes","className","hookClassName","modifierClassName","classes","sectionClassName","editor","detail","label","snippet","getMdastRenderProperties","attributes","kind","openMarker","public","supportsAttributes","tagName","themeAttributes"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,mBAA8C;IACzDC,MAAM;IACNC,mBAAmB;QAAC;KAAQ;
|
|
1
|
+
{"version":3,"sources":["../../../src/directives/definitions/section.ts"],"sourcesContent":["import type { LayoutDirectiveDefinition } from '../types.js'\n\nimport { applyDirectivePalette, getPaletteRenderProperties } from '../palette.js'\nimport { resolveDirectiveTheme } from '../themes.js'\n\nexport const sectionDirective: LayoutDirectiveDefinition = {\n name: 'section',\n allowedAttributes: ['palette', 'theme'],\n applyHast(node, config, { mergeClassNames }) {\n const theme = resolveDirectiveTheme(\n 'section',\n typeof node.properties.dataTheme === 'string' ? node.properties.dataTheme : undefined,\n config.themes,\n )\n\n node.properties.dataTheme = theme.name\n applyDirectivePalette(node, config)\n node.properties.className = mergeClassNames(\n '[&>:first-child]:mt-0 [&>:last-child]:mb-0',\n theme.hookClassName,\n theme.modifierClassName,\n theme.classes,\n config.sectionClassName,\n )\n },\n editor: {\n detail: 'Layout directive',\n label: 'Layout section',\n snippet: ':::section\\n${Content}\\n:::endsection\\n${}',\n },\n getMdastRenderProperties(node) {\n return {\n ...getPaletteRenderProperties(node),\n dataTheme: typeof node.attributes?.theme === 'string' ? node.attributes.theme : 'default',\n }\n },\n kind: 'section',\n openMarker: ':::section',\n public: true,\n supportsAttributes: true,\n tagName: 'section',\n themeAttributes: {\n theme: 'section',\n },\n}\n"],"names":["applyDirectivePalette","getPaletteRenderProperties","resolveDirectiveTheme","sectionDirective","name","allowedAttributes","applyHast","node","config","mergeClassNames","theme","properties","dataTheme","undefined","themes","className","hookClassName","modifierClassName","classes","sectionClassName","editor","detail","label","snippet","getMdastRenderProperties","attributes","kind","openMarker","public","supportsAttributes","tagName","themeAttributes"],"mappings":"AAEA,SAASA,qBAAqB,EAAEC,0BAA0B,QAAQ,gBAAe;AACjF,SAASC,qBAAqB,QAAQ,eAAc;AAEpD,OAAO,MAAMC,mBAA8C;IACzDC,MAAM;IACNC,mBAAmB;QAAC;QAAW;KAAQ;IACvCC,WAAUC,IAAI,EAAEC,MAAM,EAAE,EAAEC,eAAe,EAAE;QACzC,MAAMC,QAAQR,sBACZ,WACA,OAAOK,KAAKI,UAAU,CAACC,SAAS,KAAK,WAAWL,KAAKI,UAAU,CAACC,SAAS,GAAGC,WAC5EL,OAAOM,MAAM;QAGfP,KAAKI,UAAU,CAACC,SAAS,GAAGF,MAAMN,IAAI;QACtCJ,sBAAsBO,MAAMC;QAC5BD,KAAKI,UAAU,CAACI,SAAS,GAAGN,gBAC1B,8CACAC,MAAMM,aAAa,EACnBN,MAAMO,iBAAiB,EACvBP,MAAMQ,OAAO,EACbV,OAAOW,gBAAgB;IAE3B;IACAC,QAAQ;QACNC,QAAQ;QACRC,OAAO;QACPC,SAAS;IACX;IACAC,0BAAyBjB,IAAI;QAC3B,OAAO;YACL,GAAGN,2BAA2BM,KAAK;YACnCK,WAAW,OAAOL,KAAKkB,UAAU,EAAEf,UAAU,WAAWH,KAAKkB,UAAU,CAACf,KAAK,GAAG;QAClF;IACF;IACAgB,MAAM;IACNC,YAAY;IACZC,QAAQ;IACRC,oBAAoB;IACpBC,SAAS;IACTC,iBAAiB;QACfrB,OAAO;IACT;AACF,EAAC"}
|