payload-markdown 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.client.js +9 -19
- package/dist/components/MarkdownRenderer/Component.client.js.map +1 -1
- package/dist/components/MarkdownRenderer/Component.js +59 -21
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/components/MarkdownRenderer/index.css +93 -42
- package/dist/components/MarkdownRenderer/index.scss +128 -57
- package/dist/core/codeToHtml.js +6 -0
- package/dist/core/codeToHtml.js.map +1 -1
- package/dist/core/plugins/directiveBadge.js +2 -0
- package/dist/core/plugins/directiveBadge.js.map +1 -1
- package/dist/core/plugins/directiveButton.d.ts +1 -1
- package/dist/core/plugins/directiveButton.js +26 -6
- package/dist/core/plugins/directiveButton.js.map +1 -1
- package/dist/core/plugins/rehypeContentLayout.d.ts +12 -0
- package/dist/core/plugins/rehypeContentLayout.js +64 -0
- package/dist/core/plugins/rehypeContentLayout.js.map +1 -0
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js +8 -0
- package/dist/core/plugins/remarkHeadingAnchorsAndToc.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +19 -4
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/button.d.ts +1 -1
- package/dist/directives/definitions/button.js +9 -2
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/callout.js +29 -13
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +2 -2
- package/dist/directives/definitions/card.js +44 -11
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.js +19 -6
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/cell.js +4 -2
- package/dist/directives/definitions/cell.js.map +1 -1
- package/dist/directives/definitions/columns.js +2 -1
- package/dist/directives/definitions/columns.js.map +1 -1
- package/dist/directives/definitions/details.js +9 -3
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.js +5 -1
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.js +38 -14
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tab.js +2 -1
- package/dist/directives/definitions/tab.js.map +1 -1
- package/dist/directives/definitions/tabs.js +13 -6
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.js +2 -1
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +5 -0
- package/dist/directives/diagnostics.js +26 -10
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/shields.js +16 -3
- package/dist/directives/shields.js.map +1 -1
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +5 -0
- package/dist/directives/spec.js.map +1 -1
- package/dist/directives/themes.js +13 -13
- package/dist/directives/themes.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +22 -3
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/render.d.ts +2 -1
- package/dist/exports/render.js +1 -0
- package/dist/exports/render.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +23 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/styles/directiveSurface.d.ts +39 -5
- package/dist/styles/directiveSurface.js +56 -13
- package/dist/styles/directiveSurface.js.map +1 -1
- package/dist/types/core.d.ts +56 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
|
@@ -401,13 +401,99 @@ function toClassList(value) {
|
|
|
401
401
|
if (typeof value === 'string') return value.split(/\s+/).filter(Boolean);
|
|
402
402
|
return [];
|
|
403
403
|
}
|
|
404
|
+
/** Classes that mark a duotone icon's secondary layer (Font Awesome and our own). */ const SECONDARY_LAYER_CLASSES = [
|
|
405
|
+
'fa-secondary',
|
|
406
|
+
'pmd-icon-secondary'
|
|
407
|
+
];
|
|
408
|
+
/** Paint values a palette may replace: real colours, not `none`, `currentColor` or `url(#…)` refs. */ function isRecolorablePaint(value) {
|
|
409
|
+
if (typeof value !== 'string') return false;
|
|
410
|
+
const paint = value.trim().toLowerCase();
|
|
411
|
+
return Boolean(paint) && ![
|
|
412
|
+
'currentcolor',
|
|
413
|
+
'inherit',
|
|
414
|
+
'none',
|
|
415
|
+
'transparent'
|
|
416
|
+
].includes(paint) && !paint.startsWith('url(');
|
|
417
|
+
}
|
|
418
|
+
function recolorStyle(value, replacement) {
|
|
419
|
+
if (typeof value !== 'string') return undefined;
|
|
420
|
+
const declarations = value.split(';').map((declaration)=>declaration.trim()).filter(Boolean).flatMap((declaration)=>{
|
|
421
|
+
const separator = declaration.indexOf(':');
|
|
422
|
+
const property = declaration.slice(0, separator).trim().toLowerCase();
|
|
423
|
+
if ((property === 'fill' || property === 'stroke') && isRecolorablePaint(declaration.slice(separator + 1))) return replacement ? [
|
|
424
|
+
`${property}:${replacement}`
|
|
425
|
+
] : [];
|
|
426
|
+
return [
|
|
427
|
+
declaration
|
|
428
|
+
];
|
|
429
|
+
});
|
|
430
|
+
return declarations.length > 0 ? declarations.join(';') : undefined;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Recolours a palette-painted icon in place. Explicit fill/stroke colours
|
|
434
|
+
* become `currentColor` (the palette colour); the duotone secondary layer is
|
|
435
|
+
* painted with `--pmd-icon-secondary` and its own subtree inherits from it.
|
|
436
|
+
*/ /**
|
|
437
|
+
* Elements whose colours define coverage or a paint server rather than what
|
|
438
|
+
* the icon looks like (a white mask rect means "fully visible"). Painting
|
|
439
|
+
* never touches their subtrees.
|
|
440
|
+
*/ const UNPAINTED_TAG_NAMES = new Set([
|
|
441
|
+
'clipPath',
|
|
442
|
+
'filter',
|
|
443
|
+
'linearGradient',
|
|
444
|
+
'mask',
|
|
445
|
+
'pattern',
|
|
446
|
+
'radialGradient'
|
|
447
|
+
]);
|
|
448
|
+
const SECONDARY_PAINT = 'var(--pmd-icon-secondary, currentColor)';
|
|
449
|
+
/**
|
|
450
|
+
* Recolours a palette-painted icon in place. Explicit fill/stroke colours
|
|
451
|
+
* become `currentColor` (the palette colour); inside the duotone secondary
|
|
452
|
+
* layer they become the secondary colour, and the layer itself is filled
|
|
453
|
+
* with it unless it draws with `fill="none"`.
|
|
454
|
+
*/ function applyPaint(node, paint, inSecondary) {
|
|
455
|
+
if (UNPAINTED_TAG_NAMES.has(node.tagName)) return;
|
|
456
|
+
const layerRoot = !inSecondary && toClassList(node.properties.className).some((name)=>SECONDARY_LAYER_CLASSES.includes(name));
|
|
457
|
+
const secondary = inSecondary || layerRoot;
|
|
458
|
+
const replacement = secondary ? SECONDARY_PAINT : 'currentColor';
|
|
459
|
+
// Attributes cannot hold var(), so secondary colours go into the style.
|
|
460
|
+
const declarations = [];
|
|
461
|
+
for (const property of [
|
|
462
|
+
'fill',
|
|
463
|
+
'stroke'
|
|
464
|
+
])if (isRecolorablePaint(node.properties[property])) {
|
|
465
|
+
if (secondary) {
|
|
466
|
+
delete node.properties[property];
|
|
467
|
+
declarations.push(`${property}:${SECONDARY_PAINT}`);
|
|
468
|
+
} else {
|
|
469
|
+
node.properties[property] = 'currentColor';
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const style = recolorStyle(node.properties.style, replacement);
|
|
473
|
+
if (layerRoot && node.properties.fill !== 'none' && !declarations.some((declaration)=>declaration.startsWith('fill:')) && !/(?:^|;)\s*fill\s*:/.test(style ?? '')) declarations.push(`fill:${SECONDARY_PAINT}`);
|
|
474
|
+
if (layerRoot && paint.secondaryOpacity !== undefined) node.properties.opacity = String(paint.secondaryOpacity);
|
|
475
|
+
const combined = [
|
|
476
|
+
style,
|
|
477
|
+
...declarations
|
|
478
|
+
].filter(Boolean).join(';');
|
|
479
|
+
if (combined) node.properties.style = combined;
|
|
480
|
+
else delete node.properties.style;
|
|
481
|
+
for (const child of node.children)if (child.type === 'element') applyPaint(child, paint, secondary);
|
|
482
|
+
}
|
|
404
483
|
/**
|
|
405
484
|
* Returns a deep copy of a sanitized icon with the runtime class names and
|
|
406
|
-
* accessibility attributes the renderer adds to every inline icon.
|
|
407
|
-
|
|
485
|
+
* accessibility attributes the renderer adds to every inline icon. With a
|
|
486
|
+
* `paint`, the copy is recoloured with its palette (see `applyPaint`); without
|
|
487
|
+
* one it is left exactly as the icon file draws it.
|
|
488
|
+
*/ export function instantiateSanitizedSvg(svg, className, paint) {
|
|
408
489
|
const copy = structuredClone(svg);
|
|
409
490
|
const properties = {};
|
|
410
|
-
const runtimeClasses =
|
|
491
|
+
const runtimeClasses = [
|
|
492
|
+
...className.split(/\s+/).filter(Boolean),
|
|
493
|
+
...paint ? [
|
|
494
|
+
'pmd-icon--palette'
|
|
495
|
+
] : []
|
|
496
|
+
];
|
|
411
497
|
let hasClass = false;
|
|
412
498
|
for (const [name, value] of Object.entries(copy.properties)){
|
|
413
499
|
if (name === 'ariaHidden' || name === 'focusable') continue;
|
|
@@ -425,6 +511,21 @@ function toClassList(value) {
|
|
|
425
511
|
properties.ariaHidden = 'true';
|
|
426
512
|
properties.focusable = 'false';
|
|
427
513
|
copy.properties = properties;
|
|
514
|
+
if (paint) {
|
|
515
|
+
for (const child of copy.children)if (child.type === 'element') applyPaint(child, paint, false);
|
|
516
|
+
// Icons that set no fill (Font Awesome brands, for one) would paint black.
|
|
517
|
+
if (properties.fill === undefined) properties.fill = 'currentColor';
|
|
518
|
+
else if (isRecolorablePaint(properties.fill)) properties.fill = 'currentColor';
|
|
519
|
+
if (isRecolorablePaint(properties.stroke)) properties.stroke = 'currentColor';
|
|
520
|
+
const declarations = [
|
|
521
|
+
recolorStyle(properties.style, 'currentColor'),
|
|
522
|
+
paint.primary ? `color:${paint.primary}` : undefined,
|
|
523
|
+
paint.secondary ? `--pmd-icon-secondary:${paint.secondary}` : undefined
|
|
524
|
+
].filter(Boolean);
|
|
525
|
+
if (declarations.length > 0) properties.style = declarations.join(';');
|
|
526
|
+
else delete properties.style;
|
|
527
|
+
properties.dataPmdPalette = paint.name;
|
|
528
|
+
}
|
|
428
529
|
return copy;
|
|
429
530
|
}
|
|
430
531
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/icons/sanitizeSvg.ts"],"sourcesContent":["import type { Element, ElementContent, Properties, Root, RootContent } from 'hast'\n\nimport { fromHtml } from 'hast-util-from-html'\n\n/**\n * Structured sanitizer for icon SVG files (CORE-4).\n *\n * Icons are inlined into rendered markdown after rehype-sanitize has run, so\n * this is the only line of defence for icon file content. The file is parsed\n * with a real HTML parser (foreign-content SVG rules), only the first top-level\n * `<svg>` is kept, and its subtree is filtered through a strict allowlist:\n *\n * - elements outside the allowlist are dropped with their content\n * (`script`, `style`, `foreignObject`, `animate*`, `set`, `image`, `iframe`, …);\n * `<a>` is unwrapped so its drawing content survives without the link\n * - attributes outside the allowlist are dropped, which includes every `on*`\n * handler and `data-*` attribute\n * - `href` / `xlink:href` are kept only as same-document `#fragment` refs\n * - `style` attributes are kept only when they cannot load or reference\n * anything (`url(`, `@import`, `expression(`, `javascript:`, escapes)\n * - `<style>` elements are never emitted (inlined into the page they would apply\n * to the whole document). Simple class rules that only set paint/opacity —\n * e.g. Font Awesome duotone's `.fa-secondary{opacity:.4}` — are translated into\n * presentation attributes on the matching elements of the same icon, so icons\n * keep their appearance without carrying CSS. Any rule that is not a plain\n * class selector with allowlisted properties and plain values is ignored.\n */\n\nconst ALLOWED_SVG_TAG_NAMES = new Set([\n 'circle',\n 'clipPath',\n 'defs',\n 'desc',\n 'ellipse',\n 'feBlend',\n 'feColorMatrix',\n 'feComponentTransfer',\n 'feComposite',\n 'feConvolveMatrix',\n 'feDiffuseLighting',\n 'feDisplacementMap',\n 'feDistantLight',\n 'feDropShadow',\n 'feFlood',\n 'feFuncA',\n 'feFuncB',\n 'feFuncG',\n 'feFuncR',\n 'feGaussianBlur',\n 'feMerge',\n 'feMergeNode',\n 'feMorphology',\n 'feOffset',\n 'fePointLight',\n 'feSpecularLighting',\n 'feSpotLight',\n 'feTile',\n 'feTurbulence',\n 'filter',\n 'g',\n 'line',\n 'linearGradient',\n 'marker',\n 'mask',\n 'path',\n 'pattern',\n 'polygon',\n 'polyline',\n 'radialGradient',\n 'rect',\n 'stop',\n 'svg',\n 'symbol',\n 'text',\n 'textPath',\n 'title',\n 'tspan',\n 'use',\n])\n\n/** Elements whose children are kept while the element itself is removed. */\nconst UNWRAP_SVG_TAG_NAMES = new Set(['a'])\n\n/** Allowed attributes, written as they appear in SVG source. */\nconst ALLOWED_SVG_ATTRIBUTES = [\n 'alignment-baseline',\n 'amplitude',\n 'aria-hidden',\n 'aria-label',\n 'azimuth',\n 'baseFrequency',\n 'baseline-shift',\n 'bias',\n 'class',\n 'clip-path',\n 'clip-rule',\n 'clipPathUnits',\n 'color',\n 'color-interpolation-filters',\n 'cx',\n 'cy',\n 'd',\n 'diffuseConstant',\n 'display',\n 'divisor',\n 'dominant-baseline',\n 'dx',\n 'dy',\n 'edgeMode',\n 'elevation',\n 'exponent',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'filter',\n 'filterUnits',\n 'flood-color',\n 'flood-opacity',\n 'focusable',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'fr',\n 'fx',\n 'fy',\n 'gradientTransform',\n 'gradientUnits',\n 'height',\n 'id',\n 'in',\n 'in2',\n 'intercept',\n 'k1',\n 'k2',\n 'k3',\n 'k4',\n 'kernelMatrix',\n 'lengthAdjust',\n 'letter-spacing',\n 'lighting-color',\n 'limitingConeAngle',\n 'marker-end',\n 'marker-mid',\n 'marker-start',\n 'markerHeight',\n 'markerUnits',\n 'markerWidth',\n 'mask',\n 'maskContentUnits',\n 'maskUnits',\n 'mode',\n 'numOctaves',\n 'offset',\n 'opacity',\n 'operator',\n 'order',\n 'orient',\n 'overflow',\n 'paint-order',\n 'pathLength',\n 'patternContentUnits',\n 'patternTransform',\n 'patternUnits',\n 'points',\n 'pointsAtX',\n 'pointsAtY',\n 'pointsAtZ',\n 'preserveAlpha',\n 'preserveAspectRatio',\n 'primitiveUnits',\n 'r',\n 'radius',\n 'refX',\n 'refY',\n 'result',\n 'role',\n 'rx',\n 'ry',\n 'scale',\n 'seed',\n 'shape-rendering',\n 'slope',\n 'specularConstant',\n 'specularExponent',\n 'spreadMethod',\n 'startOffset',\n 'stdDeviation',\n 'stitchTiles',\n 'stop-color',\n 'stop-opacity',\n 'stroke',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n 'style',\n 'surfaceScale',\n 'tableValues',\n 'targetX',\n 'targetY',\n 'text-anchor',\n 'text-decoration',\n 'textLength',\n 'transform',\n 'type',\n 'values',\n 'vector-effect',\n 'version',\n 'viewBox',\n 'visibility',\n 'width',\n 'word-spacing',\n 'x',\n 'x1',\n 'x2',\n 'xChannelSelector',\n 'xmlns',\n 'xmlns:xlink',\n 'y',\n 'y1',\n 'y2',\n 'yChannelSelector',\n 'z',\n]\n\nconst FRAGMENT_ONLY_ATTRIBUTES = ['href', 'xlink:href']\n\nfunction getSvgPropertyNames(attributes: readonly string[]): Set<string> {\n // Let the same parser that reads icon files tell us the hast property name\n // for each attribute, so the allowlist cannot drift from parsing.\n const markup = `<svg ${attributes.map((attribute) => `${attribute}=\"\"`).join(' ')}></svg>`\n const svg = fromHtml(markup, { fragment: true }).children[0] as Element | undefined\n\n return new Set(Object.keys(svg?.properties ?? {}))\n}\n\nconst ALLOWED_SVG_PROPERTIES = getSvgPropertyNames(ALLOWED_SVG_ATTRIBUTES)\nconst FRAGMENT_ONLY_PROPERTIES = getSvgPropertyNames(FRAGMENT_ONLY_ATTRIBUTES)\n\nconst UNSAFE_STYLE_PATTERN = /url\\s*\\(|@import|expression\\s*\\(|javascript:|\\\\|<|behavior\\s*:|-moz-binding/i\n\nfunction isSafeStyle(value: Properties[string]): boolean {\n return typeof value === 'string' && !UNSAFE_STYLE_PATTERN.test(value)\n}\n\nfunction sanitizeProperties(properties: Properties | undefined): Properties {\n const output: Properties = {}\n\n for (const [name, value] of Object.entries(properties ?? {})) {\n if (FRAGMENT_ONLY_PROPERTIES.has(name)) {\n if (typeof value === 'string' && value.trim().startsWith('#')) output[name] = value.trim()\n continue\n }\n\n if (!ALLOWED_SVG_PROPERTIES.has(name)) continue\n if (name === 'style' && !isSafeStyle(value)) continue\n\n output[name] = value\n }\n\n return output\n}\n\n/**\n * Presentation properties a `<style>` class rule may set (they are also allowed as SVG attributes).\n * Design-tool exports (Illustrator, Figma, Sketch) put their paint in such rules, for example\n * `.cls-1{fill:#0a84ff;stroke-miterlimit:10}`.\n */\nconst STYLE_RULE_PROPERTIES = [\n 'clip-rule',\n 'color',\n 'display',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'flood-color',\n 'flood-opacity',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'letter-spacing',\n 'lighting-color',\n 'opacity',\n 'paint-order',\n 'shape-rendering',\n 'stop-color',\n 'stop-opacity',\n 'stroke',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n 'text-anchor',\n 'vector-effect',\n 'visibility',\n]\nconst STYLE_RULE_PROPERTY_NAMES = new Map(\n STYLE_RULE_PROPERTIES.map((attribute) => [attribute, [...getSvgPropertyNames([attribute])][0]]),\n)\n/**\n * A plain value: numbers and lengths (also space/comma-separated lists such as dash arrays), hex\n * colours, keywords, quoted font names, and rgb()/rgba()/hsl()/hsla() with numeric arguments.\n * Anything that can load or reference something (`url(`, other functions, escapes) is rejected.\n */\nconst SAFE_STYLE_VALUE =\n /^(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?)\\([\\d\\s.,%/-]+\\)|[\\w\\s.,%\"'-]+)$/i\nconst CLASS_SELECTOR = /^\\.(-?[_a-z][\\w-]*)$/i\n\ntype StyleRule = { className: string; declarations: Array<[string, string]> }\n\nfunction collectText(node: Element): string {\n return node.children.map((child) => (child.type === 'text' ? child.value : child.type === 'element' ? collectText(child) : '')).join('')\n}\n\nfunction collectStyleText(children: readonly (ElementContent | RootContent)[]): string {\n let text = ''\n\n for (const child of children) {\n if (child.type !== 'element') continue\n if (child.tagName === 'style') text += `${collectText(child)}\\n`\n else text += collectStyleText(child.children)\n }\n\n return text\n}\n\n/** Parses only `.class[, .class] { prop: value; … }` rules with allowlisted properties and plain values. */\nfunction parseClassStyleRules(css: string): StyleRule[] {\n const rules: StyleRule[] = []\n const withoutComments = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n\n for (const match of withoutComments.matchAll(/([^{}]+)\\{([^{}]*)\\}/g)) {\n const selectors = match[1].split(',').map((selector) => selector.trim())\n const classNames = selectors.map((selector) => CLASS_SELECTOR.exec(selector)?.[1])\n if (classNames.some((name) => !name)) continue\n\n const declarations: Array<[string, string]> = []\n\n // Each declaration stands alone, like CSS: unsupported properties (e.g. `isolation`) and\n // unsafe values are skipped without discarding the rule's other, safe declarations.\n for (const declaration of match[2].split(';')) {\n const separator = declaration.indexOf(':')\n if (separator < 0) continue\n const property = declaration.slice(0, separator).trim().toLowerCase()\n const value = declaration.slice(separator + 1).replace(/\\s*!important\\s*$/i, '').trim()\n const propertyName = STYLE_RULE_PROPERTY_NAMES.get(property)\n\n if (!propertyName || !value || !SAFE_STYLE_VALUE.test(value)) continue\n\n declarations.push([propertyName, value])\n }\n\n if (declarations.length === 0) continue\n for (const className of classNames) rules.push({ className: className!, declarations })\n }\n\n return rules\n}\n\nfunction applyClassStyleRules(node: Element, rules: readonly StyleRule[]): void {\n const classes = toClassList(node.properties.className)\n\n // Later rules win, like the stylesheet they replace; class rules outrank presentation attributes.\n for (const rule of rules) {\n if (!classes.includes(rule.className)) continue\n for (const [name, value] of rule.declarations) node.properties[name] = value\n }\n\n for (const child of node.children) if (child.type === 'element') applyClassStyleRules(child, rules)\n}\n\nfunction sanitizeChildren(children: readonly (ElementContent | RootContent)[]): ElementContent[] {\n const output: ElementContent[] = []\n\n for (const child of children) {\n if (child.type === 'text') {\n output.push({ type: 'text', value: child.value })\n continue\n }\n\n if (child.type !== 'element') continue\n\n if (UNWRAP_SVG_TAG_NAMES.has(child.tagName)) {\n output.push(...sanitizeChildren(child.children))\n continue\n }\n\n if (!ALLOWED_SVG_TAG_NAMES.has(child.tagName)) continue\n\n output.push({\n type: 'element',\n children: sanitizeChildren(child.children),\n properties: sanitizeProperties(child.properties),\n tagName: child.tagName,\n })\n }\n\n return output\n}\n\n/**\n * Parses SVG file content and returns the sanitized first top-level `<svg>`\n * element, or `undefined` when the file has none.\n */\nexport function parseAndSanitizeSvg(content: string): Element | undefined {\n const root: Root = fromHtml(content, { fragment: true })\n const svg = root.children.find(\n (node): node is Element => node.type === 'element' && node.tagName === 'svg',\n )\n\n if (!svg) return undefined\n\n const sanitized: Element = {\n type: 'element',\n children: sanitizeChildren(svg.children),\n properties: sanitizeProperties(svg.properties),\n tagName: 'svg',\n }\n const styleRules = parseClassStyleRules(collectStyleText(svg.children))\n\n if (styleRules.length > 0) applyClassStyleRules(sanitized, styleRules)\n\n return sanitized\n}\n\nfunction toClassList(value: Properties[string]): string[] {\n if (Array.isArray(value)) return value.map(String)\n if (typeof value === 'string') return value.split(/\\s+/).filter(Boolean)\n\n return []\n}\n\n/**\n * Returns a deep copy of a sanitized icon with the runtime class names and\n * accessibility attributes the renderer adds to every inline icon.\n */\nexport function instantiateSanitizedSvg(svg: Element, className: string): Element {\n const copy = structuredClone(svg)\n const properties: Properties = {}\n const runtimeClasses = className.split(/\\s+/).filter(Boolean)\n let hasClass = false\n\n for (const [name, value] of Object.entries(copy.properties)) {\n if (name === 'ariaHidden' || name === 'focusable') continue\n\n if (name === 'className') {\n hasClass = true\n properties.className = [...toClassList(value), ...runtimeClasses]\n continue\n }\n\n properties[name] = value\n }\n\n if (!hasClass) properties.className = runtimeClasses\n\n properties.ariaHidden = 'true'\n properties.focusable = 'false'\n copy.properties = properties\n\n return copy\n}\n"],"names":["fromHtml","ALLOWED_SVG_TAG_NAMES","Set","UNWRAP_SVG_TAG_NAMES","ALLOWED_SVG_ATTRIBUTES","FRAGMENT_ONLY_ATTRIBUTES","getSvgPropertyNames","attributes","markup","map","attribute","join","svg","fragment","children","Object","keys","properties","ALLOWED_SVG_PROPERTIES","FRAGMENT_ONLY_PROPERTIES","UNSAFE_STYLE_PATTERN","isSafeStyle","value","test","sanitizeProperties","output","name","entries","has","trim","startsWith","STYLE_RULE_PROPERTIES","STYLE_RULE_PROPERTY_NAMES","Map","SAFE_STYLE_VALUE","CLASS_SELECTOR","collectText","node","child","type","collectStyleText","text","tagName","parseClassStyleRules","css","rules","withoutComments","replace","match","matchAll","selectors","split","selector","classNames","exec","some","declarations","declaration","separator","indexOf","property","slice","toLowerCase","propertyName","get","push","length","className","applyClassStyleRules","classes","toClassList","rule","includes","sanitizeChildren","parseAndSanitizeSvg","content","root","find","undefined","sanitized","styleRules","Array","isArray","String","filter","Boolean","instantiateSanitizedSvg","copy","structuredClone","runtimeClasses","hasClass","ariaHidden","focusable"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,sBAAqB;AAE9C;;;;;;;;;;;;;;;;;;;;;;CAsBC,GAED,MAAMC,wBAAwB,IAAIC,IAAI;IACpC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,0EAA0E,GAC1E,MAAMC,uBAAuB,IAAID,IAAI;IAAC;CAAI;AAE1C,8DAA8D,GAC9D,MAAME,yBAAyB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,2BAA2B;IAAC;IAAQ;CAAa;AAEvD,SAASC,oBAAoBC,UAA6B;IACxD,2EAA2E;IAC3E,kEAAkE;IAClE,MAAMC,SAAS,CAAC,KAAK,EAAED,WAAWE,GAAG,CAAC,CAACC,YAAc,GAAGA,UAAU,GAAG,CAAC,EAAEC,IAAI,CAAC,KAAK,OAAO,CAAC;IAC1F,MAAMC,MAAMZ,SAASQ,QAAQ;QAAEK,UAAU;IAAK,GAAGC,QAAQ,CAAC,EAAE;IAE5D,OAAO,IAAIZ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ACjE;QACF;QAEAxE,UAAU,CAACS,KAAK,GAAGJ;IACrB;IAEA,IAAI,CAACoE,UAAUzE,WAAWkD,SAAS,GAAGsB;IAEtCxE,WAAW0E,UAAU,GAAG;IACxB1E,WAAW2E,SAAS,GAAG;IACvBL,KAAKtE,UAAU,GAAGA;IAElB,OAAOsE;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/icons/sanitizeSvg.ts"],"sourcesContent":["import type { Element, ElementContent, Properties, Root, RootContent } from 'hast'\n\nimport { fromHtml } from 'hast-util-from-html'\n\n/**\n * Structured sanitizer for icon SVG files (CORE-4).\n *\n * Icons are inlined into rendered markdown after rehype-sanitize has run, so\n * this is the only line of defence for icon file content. The file is parsed\n * with a real HTML parser (foreign-content SVG rules), only the first top-level\n * `<svg>` is kept, and its subtree is filtered through a strict allowlist:\n *\n * - elements outside the allowlist are dropped with their content\n * (`script`, `style`, `foreignObject`, `animate*`, `set`, `image`, `iframe`, …);\n * `<a>` is unwrapped so its drawing content survives without the link\n * - attributes outside the allowlist are dropped, which includes every `on*`\n * handler and `data-*` attribute\n * - `href` / `xlink:href` are kept only as same-document `#fragment` refs\n * - `style` attributes are kept only when they cannot load or reference\n * anything (`url(`, `@import`, `expression(`, `javascript:`, escapes)\n * - `<style>` elements are never emitted (inlined into the page they would apply\n * to the whole document). Simple class rules that only set paint/opacity —\n * e.g. Font Awesome duotone's `.fa-secondary{opacity:.4}` — are translated into\n * presentation attributes on the matching elements of the same icon, so icons\n * keep their appearance without carrying CSS. Any rule that is not a plain\n * class selector with allowlisted properties and plain values is ignored.\n */\n\nconst ALLOWED_SVG_TAG_NAMES = new Set([\n 'circle',\n 'clipPath',\n 'defs',\n 'desc',\n 'ellipse',\n 'feBlend',\n 'feColorMatrix',\n 'feComponentTransfer',\n 'feComposite',\n 'feConvolveMatrix',\n 'feDiffuseLighting',\n 'feDisplacementMap',\n 'feDistantLight',\n 'feDropShadow',\n 'feFlood',\n 'feFuncA',\n 'feFuncB',\n 'feFuncG',\n 'feFuncR',\n 'feGaussianBlur',\n 'feMerge',\n 'feMergeNode',\n 'feMorphology',\n 'feOffset',\n 'fePointLight',\n 'feSpecularLighting',\n 'feSpotLight',\n 'feTile',\n 'feTurbulence',\n 'filter',\n 'g',\n 'line',\n 'linearGradient',\n 'marker',\n 'mask',\n 'path',\n 'pattern',\n 'polygon',\n 'polyline',\n 'radialGradient',\n 'rect',\n 'stop',\n 'svg',\n 'symbol',\n 'text',\n 'textPath',\n 'title',\n 'tspan',\n 'use',\n])\n\n/** Elements whose children are kept while the element itself is removed. */\nconst UNWRAP_SVG_TAG_NAMES = new Set(['a'])\n\n/** Allowed attributes, written as they appear in SVG source. */\nconst ALLOWED_SVG_ATTRIBUTES = [\n 'alignment-baseline',\n 'amplitude',\n 'aria-hidden',\n 'aria-label',\n 'azimuth',\n 'baseFrequency',\n 'baseline-shift',\n 'bias',\n 'class',\n 'clip-path',\n 'clip-rule',\n 'clipPathUnits',\n 'color',\n 'color-interpolation-filters',\n 'cx',\n 'cy',\n 'd',\n 'diffuseConstant',\n 'display',\n 'divisor',\n 'dominant-baseline',\n 'dx',\n 'dy',\n 'edgeMode',\n 'elevation',\n 'exponent',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'filter',\n 'filterUnits',\n 'flood-color',\n 'flood-opacity',\n 'focusable',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'fr',\n 'fx',\n 'fy',\n 'gradientTransform',\n 'gradientUnits',\n 'height',\n 'id',\n 'in',\n 'in2',\n 'intercept',\n 'k1',\n 'k2',\n 'k3',\n 'k4',\n 'kernelMatrix',\n 'lengthAdjust',\n 'letter-spacing',\n 'lighting-color',\n 'limitingConeAngle',\n 'marker-end',\n 'marker-mid',\n 'marker-start',\n 'markerHeight',\n 'markerUnits',\n 'markerWidth',\n 'mask',\n 'maskContentUnits',\n 'maskUnits',\n 'mode',\n 'numOctaves',\n 'offset',\n 'opacity',\n 'operator',\n 'order',\n 'orient',\n 'overflow',\n 'paint-order',\n 'pathLength',\n 'patternContentUnits',\n 'patternTransform',\n 'patternUnits',\n 'points',\n 'pointsAtX',\n 'pointsAtY',\n 'pointsAtZ',\n 'preserveAlpha',\n 'preserveAspectRatio',\n 'primitiveUnits',\n 'r',\n 'radius',\n 'refX',\n 'refY',\n 'result',\n 'role',\n 'rx',\n 'ry',\n 'scale',\n 'seed',\n 'shape-rendering',\n 'slope',\n 'specularConstant',\n 'specularExponent',\n 'spreadMethod',\n 'startOffset',\n 'stdDeviation',\n 'stitchTiles',\n 'stop-color',\n 'stop-opacity',\n 'stroke',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n 'style',\n 'surfaceScale',\n 'tableValues',\n 'targetX',\n 'targetY',\n 'text-anchor',\n 'text-decoration',\n 'textLength',\n 'transform',\n 'type',\n 'values',\n 'vector-effect',\n 'version',\n 'viewBox',\n 'visibility',\n 'width',\n 'word-spacing',\n 'x',\n 'x1',\n 'x2',\n 'xChannelSelector',\n 'xmlns',\n 'xmlns:xlink',\n 'y',\n 'y1',\n 'y2',\n 'yChannelSelector',\n 'z',\n]\n\nconst FRAGMENT_ONLY_ATTRIBUTES = ['href', 'xlink:href']\n\nfunction getSvgPropertyNames(attributes: readonly string[]): Set<string> {\n // Let the same parser that reads icon files tell us the hast property name\n // for each attribute, so the allowlist cannot drift from parsing.\n const markup = `<svg ${attributes.map((attribute) => `${attribute}=\"\"`).join(' ')}></svg>`\n const svg = fromHtml(markup, { fragment: true }).children[0] as Element | undefined\n\n return new Set(Object.keys(svg?.properties ?? {}))\n}\n\nconst ALLOWED_SVG_PROPERTIES = getSvgPropertyNames(ALLOWED_SVG_ATTRIBUTES)\nconst FRAGMENT_ONLY_PROPERTIES = getSvgPropertyNames(FRAGMENT_ONLY_ATTRIBUTES)\n\nconst UNSAFE_STYLE_PATTERN = /url\\s*\\(|@import|expression\\s*\\(|javascript:|\\\\|<|behavior\\s*:|-moz-binding/i\n\nfunction isSafeStyle(value: Properties[string]): boolean {\n return typeof value === 'string' && !UNSAFE_STYLE_PATTERN.test(value)\n}\n\nfunction sanitizeProperties(properties: Properties | undefined): Properties {\n const output: Properties = {}\n\n for (const [name, value] of Object.entries(properties ?? {})) {\n if (FRAGMENT_ONLY_PROPERTIES.has(name)) {\n if (typeof value === 'string' && value.trim().startsWith('#')) output[name] = value.trim()\n continue\n }\n\n if (!ALLOWED_SVG_PROPERTIES.has(name)) continue\n if (name === 'style' && !isSafeStyle(value)) continue\n\n output[name] = value\n }\n\n return output\n}\n\n/**\n * Presentation properties a `<style>` class rule may set (they are also allowed as SVG attributes).\n * Design-tool exports (Illustrator, Figma, Sketch) put their paint in such rules, for example\n * `.cls-1{fill:#0a84ff;stroke-miterlimit:10}`.\n */\nconst STYLE_RULE_PROPERTIES = [\n 'clip-rule',\n 'color',\n 'display',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'flood-color',\n 'flood-opacity',\n 'font-family',\n 'font-size',\n 'font-style',\n 'font-weight',\n 'letter-spacing',\n 'lighting-color',\n 'opacity',\n 'paint-order',\n 'shape-rendering',\n 'stop-color',\n 'stop-opacity',\n 'stroke',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n 'text-anchor',\n 'vector-effect',\n 'visibility',\n]\nconst STYLE_RULE_PROPERTY_NAMES = new Map(\n STYLE_RULE_PROPERTIES.map((attribute) => [attribute, [...getSvgPropertyNames([attribute])][0]]),\n)\n/**\n * A plain value: numbers and lengths (also space/comma-separated lists such as dash arrays), hex\n * colours, keywords, quoted font names, and rgb()/rgba()/hsl()/hsla() with numeric arguments.\n * Anything that can load or reference something (`url(`, other functions, escapes) is rejected.\n */\nconst SAFE_STYLE_VALUE =\n /^(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?)\\([\\d\\s.,%/-]+\\)|[\\w\\s.,%\"'-]+)$/i\nconst CLASS_SELECTOR = /^\\.(-?[_a-z][\\w-]*)$/i\n\ntype StyleRule = { className: string; declarations: Array<[string, string]> }\n\nfunction collectText(node: Element): string {\n return node.children.map((child) => (child.type === 'text' ? child.value : child.type === 'element' ? collectText(child) : '')).join('')\n}\n\nfunction collectStyleText(children: readonly (ElementContent | RootContent)[]): string {\n let text = ''\n\n for (const child of children) {\n if (child.type !== 'element') continue\n if (child.tagName === 'style') text += `${collectText(child)}\\n`\n else text += collectStyleText(child.children)\n }\n\n return text\n}\n\n/** Parses only `.class[, .class] { prop: value; … }` rules with allowlisted properties and plain values. */\nfunction parseClassStyleRules(css: string): StyleRule[] {\n const rules: StyleRule[] = []\n const withoutComments = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n\n for (const match of withoutComments.matchAll(/([^{}]+)\\{([^{}]*)\\}/g)) {\n const selectors = match[1].split(',').map((selector) => selector.trim())\n const classNames = selectors.map((selector) => CLASS_SELECTOR.exec(selector)?.[1])\n if (classNames.some((name) => !name)) continue\n\n const declarations: Array<[string, string]> = []\n\n // Each declaration stands alone, like CSS: unsupported properties (e.g. `isolation`) and\n // unsafe values are skipped without discarding the rule's other, safe declarations.\n for (const declaration of match[2].split(';')) {\n const separator = declaration.indexOf(':')\n if (separator < 0) continue\n const property = declaration.slice(0, separator).trim().toLowerCase()\n const value = declaration.slice(separator + 1).replace(/\\s*!important\\s*$/i, '').trim()\n const propertyName = STYLE_RULE_PROPERTY_NAMES.get(property)\n\n if (!propertyName || !value || !SAFE_STYLE_VALUE.test(value)) continue\n\n declarations.push([propertyName, value])\n }\n\n if (declarations.length === 0) continue\n for (const className of classNames) rules.push({ className: className!, declarations })\n }\n\n return rules\n}\n\nfunction applyClassStyleRules(node: Element, rules: readonly StyleRule[]): void {\n const classes = toClassList(node.properties.className)\n\n // Later rules win, like the stylesheet they replace; class rules outrank presentation attributes.\n for (const rule of rules) {\n if (!classes.includes(rule.className)) continue\n for (const [name, value] of rule.declarations) node.properties[name] = value\n }\n\n for (const child of node.children) if (child.type === 'element') applyClassStyleRules(child, rules)\n}\n\nfunction sanitizeChildren(children: readonly (ElementContent | RootContent)[]): ElementContent[] {\n const output: ElementContent[] = []\n\n for (const child of children) {\n if (child.type === 'text') {\n output.push({ type: 'text', value: child.value })\n continue\n }\n\n if (child.type !== 'element') continue\n\n if (UNWRAP_SVG_TAG_NAMES.has(child.tagName)) {\n output.push(...sanitizeChildren(child.children))\n continue\n }\n\n if (!ALLOWED_SVG_TAG_NAMES.has(child.tagName)) continue\n\n output.push({\n type: 'element',\n children: sanitizeChildren(child.children),\n properties: sanitizeProperties(child.properties),\n tagName: child.tagName,\n })\n }\n\n return output\n}\n\n/**\n * Parses SVG file content and returns the sanitized first top-level `<svg>`\n * element, or `undefined` when the file has none.\n */\nexport function parseAndSanitizeSvg(content: string): Element | undefined {\n const root: Root = fromHtml(content, { fragment: true })\n const svg = root.children.find(\n (node): node is Element => node.type === 'element' && node.tagName === 'svg',\n )\n\n if (!svg) return undefined\n\n const sanitized: Element = {\n type: 'element',\n children: sanitizeChildren(svg.children),\n properties: sanitizeProperties(svg.properties),\n tagName: 'svg',\n }\n const styleRules = parseClassStyleRules(collectStyleText(svg.children))\n\n if (styleRules.length > 0) applyClassStyleRules(sanitized, styleRules)\n\n return sanitized\n}\n\nfunction toClassList(value: Properties[string]): string[] {\n if (Array.isArray(value)) return value.map(String)\n if (typeof value === 'string') return value.split(/\\s+/).filter(Boolean)\n\n return []\n}\n\n/** How a palette paints an icon (all values are validated CSS colours). */\nexport type SvgPaint = {\n /** Palette name, emitted as `data-pmd-palette`. */\n name: string\n primary?: string\n secondary?: string\n secondaryOpacity?: number\n}\n\n/** Classes that mark a duotone icon's secondary layer (Font Awesome and our own). */\nconst SECONDARY_LAYER_CLASSES = ['fa-secondary', 'pmd-icon-secondary']\n\n/** Paint values a palette may replace: real colours, not `none`, `currentColor` or `url(#…)` refs. */\nfunction isRecolorablePaint(value: unknown): boolean {\n if (typeof value !== 'string') return false\n\n const paint = value.trim().toLowerCase()\n\n return Boolean(paint) && !['currentcolor', 'inherit', 'none', 'transparent'].includes(paint) && !paint.startsWith('url(')\n}\n\nfunction recolorStyle(value: Properties[string], replacement: string | undefined): string | undefined {\n if (typeof value !== 'string') return undefined\n\n const declarations = value\n .split(';')\n .map((declaration) => declaration.trim())\n .filter(Boolean)\n .flatMap((declaration) => {\n const separator = declaration.indexOf(':')\n const property = declaration.slice(0, separator).trim().toLowerCase()\n\n if ((property === 'fill' || property === 'stroke') && isRecolorablePaint(declaration.slice(separator + 1)))\n return replacement ? [`${property}:${replacement}`] : []\n\n return [declaration]\n })\n\n return declarations.length > 0 ? declarations.join(';') : undefined\n}\n\n/**\n * Recolours a palette-painted icon in place. Explicit fill/stroke colours\n * become `currentColor` (the palette colour); the duotone secondary layer is\n * painted with `--pmd-icon-secondary` and its own subtree inherits from it.\n */\n/**\n * Elements whose colours define coverage or a paint server rather than what\n * the icon looks like (a white mask rect means \"fully visible\"). Painting\n * never touches their subtrees.\n */\nconst UNPAINTED_TAG_NAMES = new Set(['clipPath', 'filter', 'linearGradient', 'mask', 'pattern', 'radialGradient'])\n\nconst SECONDARY_PAINT = 'var(--pmd-icon-secondary, currentColor)'\n\n/**\n * Recolours a palette-painted icon in place. Explicit fill/stroke colours\n * become `currentColor` (the palette colour); inside the duotone secondary\n * layer they become the secondary colour, and the layer itself is filled\n * with it unless it draws with `fill=\"none\"`.\n */\nfunction applyPaint(node: Element, paint: SvgPaint, inSecondary: boolean): void {\n if (UNPAINTED_TAG_NAMES.has(node.tagName)) return\n\n const layerRoot = !inSecondary && toClassList(node.properties.className).some((name) => SECONDARY_LAYER_CLASSES.includes(name))\n const secondary = inSecondary || layerRoot\n const replacement = secondary ? SECONDARY_PAINT : 'currentColor'\n // Attributes cannot hold var(), so secondary colours go into the style.\n const declarations: string[] = []\n\n for (const property of ['fill', 'stroke'] as const)\n if (isRecolorablePaint(node.properties[property])) {\n if (secondary) {\n delete node.properties[property]\n declarations.push(`${property}:${SECONDARY_PAINT}`)\n } else {\n node.properties[property] = 'currentColor'\n }\n }\n\n const style = recolorStyle(node.properties.style, replacement)\n\n if (\n layerRoot &&\n node.properties.fill !== 'none' &&\n !declarations.some((declaration) => declaration.startsWith('fill:')) &&\n !/(?:^|;)\\s*fill\\s*:/.test(style ?? '')\n )\n declarations.push(`fill:${SECONDARY_PAINT}`)\n\n if (layerRoot && paint.secondaryOpacity !== undefined) node.properties.opacity = String(paint.secondaryOpacity)\n\n const combined = [style, ...declarations].filter(Boolean).join(';')\n\n if (combined) node.properties.style = combined\n else delete node.properties.style\n\n for (const child of node.children) if (child.type === 'element') applyPaint(child, paint, secondary)\n}\n\n/**\n * Returns a deep copy of a sanitized icon with the runtime class names and\n * accessibility attributes the renderer adds to every inline icon. With a\n * `paint`, the copy is recoloured with its palette (see `applyPaint`); without\n * one it is left exactly as the icon file draws it.\n */\nexport function instantiateSanitizedSvg(svg: Element, className: string, paint?: SvgPaint): Element {\n const copy = structuredClone(svg)\n const properties: Properties = {}\n const runtimeClasses = [...className.split(/\\s+/).filter(Boolean), ...(paint ? ['pmd-icon--palette'] : [])]\n let hasClass = false\n\n for (const [name, value] of Object.entries(copy.properties)) {\n if (name === 'ariaHidden' || name === 'focusable') continue\n\n if (name === 'className') {\n hasClass = true\n properties.className = [...toClassList(value), ...runtimeClasses]\n continue\n }\n\n properties[name] = value\n }\n\n if (!hasClass) properties.className = runtimeClasses\n\n properties.ariaHidden = 'true'\n properties.focusable = 'false'\n copy.properties = properties\n\n if (paint) {\n for (const child of copy.children) if (child.type === 'element') applyPaint(child, paint, false)\n\n // Icons that set no fill (Font Awesome brands, for one) would paint black.\n if (properties.fill === undefined) properties.fill = 'currentColor'\n else if (isRecolorablePaint(properties.fill)) properties.fill = 'currentColor'\n if (isRecolorablePaint(properties.stroke)) properties.stroke = 'currentColor'\n\n const declarations = [\n recolorStyle(properties.style, 'currentColor'),\n paint.primary ? `color:${paint.primary}` : undefined,\n paint.secondary ? `--pmd-icon-secondary:${paint.secondary}` : undefined,\n ].filter(Boolean)\n\n if (declarations.length > 0) properties.style = declarations.join(';')\n else delete properties.style\n properties.dataPmdPalette = paint.name\n }\n\n return copy\n}\n"],"names":["fromHtml","ALLOWED_SVG_TAG_NAMES","Set","UNWRAP_SVG_TAG_NAMES","ALLOWED_SVG_ATTRIBUTES","FRAGMENT_ONLY_ATTRIBUTES","getSvgPropertyNames","attributes","markup","map","attribute","join","svg","fragment","children","Object","keys","properties","ALLOWED_SVG_PROPERTIES","FRAGMENT_ONLY_PROPERTIES","UNSAFE_STYLE_PATTERN","isSafeStyle","value","test","sanitizeProperties","output","name","entries","has","trim","startsWith","STYLE_RULE_PROPERTIES","STYLE_RULE_PROPERTY_NAMES","Map","SAFE_STYLE_VALUE","CLASS_SELECTOR","collectText","node","child","type","collectStyleText","text","tagName","parseClassStyleRules","css","rules","withoutComments","replace","match","matchAll","selectors","split","selector","classNames","exec","some","declarations","declaration","separator","indexOf","property","slice","toLowerCase","propertyName","get","push","length","className","applyClassStyleRules","classes","toClassList","rule","includes","sanitizeChildren","parseAndSanitizeSvg","content","root","find","undefined","sanitized","styleRules","Array","isArray","String","filter","Boolean","SECONDARY_LAYER_CLASSES","isRecolorablePaint","paint","recolorStyle","replacement","flatMap","UNPAINTED_TAG_NAMES","SECONDARY_PAINT","applyPaint","inSecondary","layerRoot","secondary","style","fill","secondaryOpacity","opacity","combined","instantiateSanitizedSvg","copy","structuredClone","runtimeClasses","hasClass","ariaHidden","focusable","stroke","primary","dataPmdPalette"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,sBAAqB;AAE9C;;;;;;;;;;;;;;;;;;;;;;CAsBC,GAED,MAAMC,wBAAwB,IAAIC,IAAI;IACpC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,0EAA0E,GAC1E,MAAMC,uBAAuB,IAAID,IAAI;IAAC;CAAI;AAE1C,8DAA8D,GAC9D,MAAME,yBAAyB;IAC7B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,2BAA2B;IAAC;IAAQ;CAAa;AAEvD,SAASC,oBAAoBC,UAA6B;IACxD,2EAA2E;IAC3E,kEAAkE;IAClE,MAAMC,SAAS,CAAC,KAAK,EAAED,WAAWE,GAAG,CAAC,CAACC,YAAc,GAAGA,UAAU,GAAG,CAAC,EAAEC,IAAI,CAAC,KAAK,OAAO,CAAC;IAC1F,MAAMC,MAAMZ,SAASQ,QAAQ;QAAEK,UAAU;IAAK,GAAGC,QAAQ,CAAC,EAAE;IAE5D,OAAO,IA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WkD,SAAS,GAAG;mBAAIG,YAAYhD;mBAAWoF;aAAe;YACjE;QACF;QAEAzF,UAAU,CAACS,KAAK,GAAGJ;IACrB;IAEA,IAAI,CAACqF,UAAU1F,WAAWkD,SAAS,GAAGuC;IAEtCzF,WAAW2F,UAAU,GAAG;IACxB3F,WAAW4F,SAAS,GAAG;IACvBL,KAAKvF,UAAU,GAAGA;IAElB,IAAIuE,OAAO;QACT,KAAK,MAAMlD,SAASkE,KAAK1F,QAAQ,CAAE,IAAIwB,MAAMC,IAAI,KAAK,WAAWuD,WAAWxD,OAAOkD,OAAO;QAE1F,2EAA2E;QAC3E,IAAIvE,WAAWkF,IAAI,KAAKrB,WAAW7D,WAAWkF,IAAI,GAAG;aAChD,IAAIZ,mBAAmBtE,WAAWkF,IAAI,GAAGlF,WAAWkF,IAAI,GAAG;QAChE,IAAIZ,mBAAmBtE,WAAW6F,MAAM,GAAG7F,WAAW6F,MAAM,GAAG;QAE/D,MAAMtD,eAAe;YACnBiC,aAAaxE,WAAWiF,KAAK,EAAE;YAC/BV,MAAMuB,OAAO,GAAG,CAAC,MAAM,EAAEvB,MAAMuB,OAAO,EAAE,GAAGjC;YAC3CU,MAAMS,SAAS,GAAG,CAAC,qBAAqB,EAAET,MAAMS,SAAS,EAAE,GAAGnB;SAC/D,CAACM,MAAM,CAACC;QAET,IAAI7B,aAAaU,MAAM,GAAG,GAAGjD,WAAWiF,KAAK,GAAG1C,aAAa7C,IAAI,CAAC;aAC7D,OAAOM,WAAWiF,KAAK;QAC5BjF,WAAW+F,cAAc,GAAGxB,MAAM9D,IAAI;IACxC;IAEA,OAAO8E;AACT"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { Plugin } from 'payload';
|
|
2
|
-
import type { MarkdownFieldOptions, PayloadMarkdownConfig } from './types.js';
|
|
2
|
+
import type { MarkdownFieldOptions, PayloadMarkdownAppearanceOptions, PayloadMarkdownConfig } from './types.js';
|
|
3
3
|
import { MarkdownBlock } from './blocks/MarkdownBlock/config.js';
|
|
4
4
|
import { DEFAULT_CODE_LANGS } from './core/codeToHtml.js';
|
|
5
5
|
import { DEFAULT_CALLOUT_THEMES, DEFAULT_CARD_THEMES, DEFAULT_CARDS_THEMES, DEFAULT_CELL_THEMES, DEFAULT_COLUMNS_THEMES, DEFAULT_DETAILS_THEMES, DEFAULT_SECTION_THEMES, DEFAULT_STEPS_THEMES, DEFAULT_TAB_THEMES, DEFAULT_TABS_THEMES, DEFAULT_TOC_THEMES } from './directives/themes.js';
|
|
6
6
|
import { DEFAULT_MARKDOWN_MAX_LENGTH, markdownField } from './field/MarkdownField/config.js';
|
|
7
|
+
import { DEFAULT_PALETTES } from './palettes/index.js';
|
|
7
8
|
export declare const payloadMarkdown: (pluginOptions?: PayloadMarkdownConfig) => Plugin;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Palettes managed in the "Markdown Appearance" global (`appearance` option),
|
|
11
|
+
* cached per process. `MarkdownRenderer` loads them itself; pass the result as
|
|
12
|
+
* `runtimePalettes` to `renderMarkdown` to render with them elsewhere.
|
|
13
|
+
*/
|
|
14
|
+
export { loadAppearancePalettes as loadMarkdownPalettes } from './appearance/runtime.js';
|
|
15
|
+
export { DEFAULT_CALLOUT_THEMES, DEFAULT_CARD_THEMES, DEFAULT_CARDS_THEMES, DEFAULT_CELL_THEMES, DEFAULT_CODE_LANGS, DEFAULT_COLUMNS_THEMES, DEFAULT_DETAILS_THEMES, DEFAULT_MARKDOWN_MAX_LENGTH, DEFAULT_PALETTES, DEFAULT_SECTION_THEMES, DEFAULT_STEPS_THEMES, DEFAULT_TAB_THEMES, DEFAULT_TABS_THEMES, DEFAULT_TOC_THEMES, MarkdownBlock, markdownField, };
|
|
16
|
+
export type { MarkdownFieldOptions, PayloadMarkdownAppearanceOptions, PayloadMarkdownConfig };
|
|
17
|
+
export type { MarkdownCodeConfig, MarkdownColorScheme, MarkdownDirectiveTheme, MarkdownDirectiveThemeGroup, MarkdownDirectiveThemes, MarkdownPalette, MarkdownPaletteColors, MarkdownPalettes, PayloadMarkdownIconPack, PayloadMarkdownIconsConfig, } from './types/core.js';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { createAppearanceGlobal, resolveAppearanceOptions } from './appearance/config.js';
|
|
2
|
+
import { attachAppearancePayload, clearAppearance, registerAppearance } from './appearance/runtime.js';
|
|
1
3
|
import { createMarkdownBlock, MarkdownBlock } from './blocks/MarkdownBlock/config.js';
|
|
2
4
|
import { resolveEffectiveMarkdownBlockParams } from './blocks/MarkdownBlock/params.js';
|
|
3
5
|
import { DEFAULT_CODE_LANGS } from './core/codeToHtml.js';
|
|
4
6
|
import { DEFAULT_CALLOUT_THEMES, DEFAULT_CARD_THEMES, DEFAULT_CARDS_THEMES, DEFAULT_CELL_THEMES, DEFAULT_COLUMNS_THEMES, DEFAULT_DETAILS_THEMES, DEFAULT_SECTION_THEMES, DEFAULT_STEPS_THEMES, DEFAULT_TAB_THEMES, DEFAULT_TABS_THEMES, DEFAULT_TOC_THEMES } from './directives/themes.js';
|
|
5
7
|
import { createEditorDirectiveConfig, PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY } from './editor/directiveConfig.js';
|
|
6
8
|
import { DEFAULT_MARKDOWN_MAX_LENGTH, markdownField } from './field/MarkdownField/config.js';
|
|
9
|
+
import { DEFAULT_PALETTES } from './palettes/index.js';
|
|
7
10
|
import { clearPayloadMarkdownSettings, PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY, resolveMarkdownBlockDefaults, resolveMarkdownFieldDefaults, setPayloadMarkdownSettings } from './runtime/index.js';
|
|
8
11
|
function ensureMarkdownBlock(config, block) {
|
|
9
12
|
const blocks = config.blocks ?? [];
|
|
@@ -135,7 +138,7 @@ function resolveCollectionInstallBehavior(collection, collectionOptions) {
|
|
|
135
138
|
* the scope's effective block defaults.
|
|
136
139
|
*/ function createMarkdownBlockForScope(collectionSlug, settings) {
|
|
137
140
|
const blockDefaults = resolveMarkdownBlockDefaults(collectionSlug, settings);
|
|
138
|
-
return createMarkdownBlock(createEditorDirectiveConfig(blockDefaults), resolveEffectiveMarkdownBlockParams(blockDefaults));
|
|
141
|
+
return createMarkdownBlock(createEditorDirectiveConfig(blockDefaults, settings.appearanceSlug), resolveEffectiveMarkdownBlockParams(blockDefaults));
|
|
139
142
|
}
|
|
140
143
|
export const payloadMarkdown = (pluginOptions = {})=>(incomingConfig)=>{
|
|
141
144
|
const config = {
|
|
@@ -145,8 +148,31 @@ export const payloadMarkdown = (pluginOptions = {})=>(incomingConfig)=>{
|
|
|
145
148
|
// A disabled plugin must not leave a previous configuration's render
|
|
146
149
|
// defaults active (CORE-18).
|
|
147
150
|
clearPayloadMarkdownSettings();
|
|
151
|
+
clearAppearance();
|
|
148
152
|
return config;
|
|
149
153
|
}
|
|
154
|
+
// Opt-in runtime palettes: the "Markdown Appearance" global, readable by
|
|
155
|
+
// renders through the Payload instance captured at init.
|
|
156
|
+
const appearance = resolveAppearanceOptions(pluginOptions.appearance);
|
|
157
|
+
if (appearance) {
|
|
158
|
+
// Registered even when the app defines the global itself.
|
|
159
|
+
registerAppearance({
|
|
160
|
+
slug: appearance.slug,
|
|
161
|
+
ttl: appearance.cacheTtl
|
|
162
|
+
});
|
|
163
|
+
const globals = config.globals ?? [];
|
|
164
|
+
if (!globals.some((global)=>global.slug === appearance.slug)) config.globals = [
|
|
165
|
+
...globals,
|
|
166
|
+
createAppearanceGlobal(appearance)
|
|
167
|
+
];
|
|
168
|
+
const incomingOnInit = config.onInit;
|
|
169
|
+
config.onInit = async (payload)=>{
|
|
170
|
+
attachAppearancePayload(payload);
|
|
171
|
+
await incomingOnInit?.(payload);
|
|
172
|
+
};
|
|
173
|
+
} else {
|
|
174
|
+
clearAppearance();
|
|
175
|
+
}
|
|
150
176
|
// The settings are owned by the config being built: a frozen snapshot on
|
|
151
177
|
// its server-only `custom`, also registered process-wide (shared by every
|
|
152
178
|
// installed copy of this package) for renderers without an explicit
|
|
@@ -169,11 +195,16 @@ export const payloadMarkdown = (pluginOptions = {})=>(incomingConfig)=>{
|
|
|
169
195
|
const resolved = resolveCollectionInstallBehavior(collection, collectionOptions);
|
|
170
196
|
let next = collection;
|
|
171
197
|
if (resolved.installIntoBlocks) next = withMarkdownBlockInCollectionBlocks(next, createMarkdownBlockForScope(collection.slug, settings));
|
|
172
|
-
if (resolved.installField) next = withMarkdownField(next, resolved.fieldName, withEditorConfig(resolved.fieldOptions, createEditorDirectiveConfig(resolveMarkdownFieldDefaults(collection.slug, settings))));
|
|
198
|
+
if (resolved.installField) next = withMarkdownField(next, resolved.fieldName, withEditorConfig(resolved.fieldOptions, createEditorDirectiveConfig(resolveMarkdownFieldDefaults(collection.slug, settings), settings.appearanceSlug)));
|
|
173
199
|
return next;
|
|
174
200
|
});
|
|
175
201
|
return config;
|
|
176
202
|
};
|
|
177
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Palettes managed in the "Markdown Appearance" global (`appearance` option),
|
|
205
|
+
* cached per process. `MarkdownRenderer` loads them itself; pass the result as
|
|
206
|
+
* `runtimePalettes` to `renderMarkdown` to render with them elsewhere.
|
|
207
|
+
*/ export { loadAppearancePalettes as loadMarkdownPalettes } from './appearance/runtime.js';
|
|
208
|
+
export { DEFAULT_CALLOUT_THEMES, DEFAULT_CARD_THEMES, DEFAULT_CARDS_THEMES, DEFAULT_CELL_THEMES, DEFAULT_CODE_LANGS, DEFAULT_COLUMNS_THEMES, DEFAULT_DETAILS_THEMES, DEFAULT_MARKDOWN_MAX_LENGTH, DEFAULT_PALETTES, DEFAULT_SECTION_THEMES, DEFAULT_STEPS_THEMES, DEFAULT_TAB_THEMES, DEFAULT_TABS_THEMES, DEFAULT_TOC_THEMES, MarkdownBlock, markdownField, };
|
|
178
209
|
|
|
179
210
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Block, CollectionConfig, Config, Field, Plugin } from 'payload'\n\nimport type { MarkdownEditorDirectiveConfig } from './editor/directiveConfig.js'\nimport type { PayloadMarkdownResolvedSettings } from './runtime/index.js'\nimport type { MarkdownFieldOptions, PayloadMarkdownCollectionConfig, PayloadMarkdownConfig } from './types.js'\n\nimport { createMarkdownBlock, MarkdownBlock } from './blocks/MarkdownBlock/config.js'\nimport { resolveEffectiveMarkdownBlockParams } from './blocks/MarkdownBlock/params.js'\nimport { DEFAULT_CODE_LANGS } from './core/codeToHtml.js'\nimport {\n DEFAULT_CALLOUT_THEMES,\n DEFAULT_CARD_THEMES,\n DEFAULT_CARDS_THEMES,\n DEFAULT_CELL_THEMES,\n DEFAULT_COLUMNS_THEMES,\n DEFAULT_DETAILS_THEMES,\n DEFAULT_SECTION_THEMES,\n DEFAULT_STEPS_THEMES,\n DEFAULT_TAB_THEMES,\n DEFAULT_TABS_THEMES,\n DEFAULT_TOC_THEMES,\n} from './directives/themes.js'\nimport {\n createEditorDirectiveConfig,\n PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY,\n} from './editor/directiveConfig.js'\nimport { DEFAULT_MARKDOWN_MAX_LENGTH, markdownField } from './field/MarkdownField/config.js'\nimport {\n clearPayloadMarkdownSettings,\n PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY,\n resolveMarkdownBlockDefaults,\n resolveMarkdownFieldDefaults,\n setPayloadMarkdownSettings,\n} from './runtime/index.js'\n\nfunction ensureMarkdownBlock(config: Config, block: Block) {\n const blocks = config.blocks ?? []\n const alreadyExists = blocks.some((entry) => entry.slug === block.slug)\n if (alreadyExists) return\n\n // Copy-on-write: never mutate the caller's config arrays (CORE-18).\n config.blocks = [...blocks, block]\n}\n\nfunction withEditorConfig(\n fieldOptions: Omit<MarkdownFieldOptions, 'name'> | undefined,\n editorConfig: MarkdownEditorDirectiveConfig,\n): Omit<MarkdownFieldOptions, 'name'> {\n return {\n ...(fieldOptions ?? {}),\n admin: {\n ...(fieldOptions?.admin ?? {}),\n custom: {\n ...(fieldOptions?.admin?.custom ?? {}),\n [PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY]: editorConfig,\n },\n },\n }\n}\n\nfunction withMarkdownField(\n collection: CollectionConfig,\n fieldName: string,\n fieldOptions?: Omit<MarkdownFieldOptions, 'name'>,\n): CollectionConfig {\n const alreadyExists = collection.fields.some(\n (field) => 'name' in field && field.name === fieldName,\n )\n\n if (alreadyExists) return collection\n\n return {\n ...collection,\n fields: [\n ...collection.fields,\n markdownField({\n name: fieldName,\n label: 'Markdown',\n ...(fieldOptions || {}),\n }),\n ],\n }\n}\n\n/**\n * Returns `fields` with `block` added to every reachable blocks field. Field\n * objects and arrays on the modified paths are copied; the caller's objects\n * are never mutated (CORE-18).\n */\nfunction withBlockInstalled(fields: Field[], block: Block): Field[] {\n let changed = false\n\n const next = fields.map((field): Field => {\n let updated: Field = field\n\n if (field.type === 'blocks') {\n const blocks = field.blocks ?? []\n\n if (!blocks.some((entry) => entry.slug === block.slug)) {\n updated = { ...field, blocks: [...blocks, block] }\n }\n }\n\n if ('fields' in updated && Array.isArray(updated.fields)) {\n const nestedFields = withBlockInstalled(updated.fields, block)\n if (nestedFields !== updated.fields) updated = { ...updated, fields: nestedFields } as Field\n }\n\n if (updated.type === 'tabs' && Array.isArray(updated.tabs)) {\n let tabsChanged = false\n const tabs = updated.tabs.map((tab) => {\n if (!('fields' in tab) || !Array.isArray(tab.fields)) return tab\n\n const tabFields = withBlockInstalled(tab.fields, block)\n if (tabFields === tab.fields) return tab\n\n tabsChanged = true\n return { ...tab, fields: tabFields }\n })\n\n if (tabsChanged) updated = { ...updated, tabs }\n }\n\n if (updated !== field) changed = true\n\n return updated\n })\n\n return changed ? next : fields\n}\n\nfunction withMarkdownBlockInCollectionBlocks(\n collection: CollectionConfig,\n block: Block,\n): CollectionConfig {\n const fields = withBlockInstalled(collection.fields, block)\n\n return fields === collection.fields ? collection : { ...collection, fields }\n}\n\nfunction collectionHasBlocksField(fields: Field[]): boolean {\n for (const field of fields) {\n if (field.type === 'blocks') return true\n\n if ('fields' in field && Array.isArray(field.fields))\n if (collectionHasBlocksField(field.fields)) return true\n\n if (field.type === 'tabs' && Array.isArray(field.tabs))\n for (const tab of field.tabs)\n if ('fields' in tab && Array.isArray(tab.fields))\n if (collectionHasBlocksField(tab.fields)) return true\n }\n\n return false\n}\n\nfunction resolveCollectionInstallBehavior(\n collection: CollectionConfig,\n collectionOptions: PayloadMarkdownCollectionConfig | true,\n) {\n const hasBlocksField = collectionHasBlocksField(collection.fields)\n\n if (collectionOptions === true) {\n return {\n fieldName: 'content',\n fieldOptions: undefined,\n installField: !hasBlocksField,\n installIntoBlocks: hasBlocksField,\n }\n }\n\n return {\n fieldName: collectionOptions.fieldName || 'content',\n fieldOptions: collectionOptions.field,\n installField: collectionOptions.installField ?? !hasBlocksField,\n installIntoBlocks: collectionOptions.installIntoBlocks ?? hasBlocksField,\n }\n}\n\n/**\n * The markdown block for one install scope (global or a collection): its\n * editor gets the scope's themes and icon packs, and its params pre-fill from\n * the scope's effective block defaults.\n */\nfunction createMarkdownBlockForScope(\n collectionSlug: string | undefined,\n settings: PayloadMarkdownResolvedSettings,\n) {\n const blockDefaults = resolveMarkdownBlockDefaults(collectionSlug, settings)\n\n return createMarkdownBlock(\n createEditorDirectiveConfig(blockDefaults),\n resolveEffectiveMarkdownBlockParams(blockDefaults),\n )\n}\n\nexport const payloadMarkdown =\n (pluginOptions: PayloadMarkdownConfig = {}): Plugin =>\n (incomingConfig: Config): Config => {\n const config = { ...incomingConfig }\n\n if (pluginOptions.enabled === false) {\n // A disabled plugin must not leave a previous configuration's render\n // defaults active (CORE-18).\n clearPayloadMarkdownSettings()\n return config\n }\n\n // The settings are owned by the config being built: a frozen snapshot on\n // its server-only `custom`, also registered process-wide (shared by every\n // installed copy of this package) for renderers without an explicit\n // settings source. The last built config wins the registry.\n const settings = setPayloadMarkdownSettings(pluginOptions)\n\n config.custom = { ...(config.custom ?? {}), [PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY]: settings }\n\n // The admin editor gets the resolved theme names and icon pack aliases\n // for its scope through field.admin.custom (CORE-8), computed from the\n // settings this config owns.\n ensureMarkdownBlock(\n config,\n createMarkdownBlockForScope(undefined, settings),\n )\n\n if (!pluginOptions.collections || !config.collections) return config\n\n // Widened to string keys: collection.slug is a plain string here.\n const collectionOptionsBySlug: Partial<Record<string, PayloadMarkdownCollectionConfig | true>> =\n pluginOptions.collections\n\n config.collections = config.collections.map((collection) => {\n const collectionOptions = collectionOptionsBySlug[collection.slug]\n if (!collectionOptions) return collection\n\n const resolved = resolveCollectionInstallBehavior(collection, collectionOptions)\n let next = collection\n\n if (resolved.installIntoBlocks)\n next = withMarkdownBlockInCollectionBlocks(\n next,\n createMarkdownBlockForScope(collection.slug, settings),\n )\n\n if (resolved.installField)\n next = withMarkdownField(\n next,\n resolved.fieldName,\n withEditorConfig(\n resolved.fieldOptions,\n createEditorDirectiveConfig(resolveMarkdownFieldDefaults(collection.slug, settings)),\n ),\n )\n\n return next\n })\n\n return config\n }\n\nexport {\n DEFAULT_CALLOUT_THEMES,\n DEFAULT_CARD_THEMES,\n DEFAULT_CARDS_THEMES,\n DEFAULT_CELL_THEMES,\n DEFAULT_CODE_LANGS,\n DEFAULT_COLUMNS_THEMES,\n DEFAULT_DETAILS_THEMES,\n DEFAULT_MARKDOWN_MAX_LENGTH,\n DEFAULT_SECTION_THEMES,\n DEFAULT_STEPS_THEMES,\n DEFAULT_TAB_THEMES,\n DEFAULT_TABS_THEMES,\n DEFAULT_TOC_THEMES,\n MarkdownBlock,\n markdownField,\n}\nexport type { MarkdownFieldOptions, PayloadMarkdownConfig }\nexport type {\n MarkdownCodeConfig,\n MarkdownDirectiveTheme,\n MarkdownDirectiveThemeGroup,\n MarkdownDirectiveThemes,\n PayloadMarkdownIconPack,\n PayloadMarkdownIconsConfig,\n} from './types/core.js'\n"],"names":["createMarkdownBlock","MarkdownBlock","resolveEffectiveMarkdownBlockParams","DEFAULT_CODE_LANGS","DEFAULT_CALLOUT_THEMES","DEFAULT_CARD_THEMES","DEFAULT_CARDS_THEMES","DEFAULT_CELL_THEMES","DEFAULT_COLUMNS_THEMES","DEFAULT_DETAILS_THEMES","DEFAULT_SECTION_THEMES","DEFAULT_STEPS_THEMES","DEFAULT_TAB_THEMES","DEFAULT_TABS_THEMES","DEFAULT_TOC_THEMES","createEditorDirectiveConfig","PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY","DEFAULT_MARKDOWN_MAX_LENGTH","markdownField","clearPayloadMarkdownSettings","PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY","resolveMarkdownBlockDefaults","resolveMarkdownFieldDefaults","setPayloadMarkdownSettings","ensureMarkdownBlock","config","block","blocks","alreadyExists","some","entry","slug","withEditorConfig","fieldOptions","editorConfig","admin","custom","withMarkdownField","collection","fieldName","fields","field","name","label","withBlockInstalled","changed","next","map","updated","type","Array","isArray","nestedFields","tabs","tabsChanged","tab","tabFields","withMarkdownBlockInCollectionBlocks","collectionHasBlocksField","resolveCollectionInstallBehavior","collectionOptions","hasBlocksField","undefined","installField","installIntoBlocks","createMarkdownBlockForScope","collectionSlug","settings","blockDefaults","payloadMarkdown","pluginOptions","incomingConfig","enabled","collections","collectionOptionsBySlug","resolved"],"mappings":"AAMA,SAASA,mBAAmB,EAAEC,aAAa,QAAQ,mCAAkC;AACrF,SAASC,mCAAmC,QAAQ,mCAAkC;AACtF,SAASC,kBAAkB,QAAQ,uBAAsB;AACzD,SACEC,sBAAsB,EACtBC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,EACnBC,sBAAsB,EACtBC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,kBAAkB,QACb,yBAAwB;AAC/B,SACEC,2BAA2B,EAC3BC,iCAAiC,QAC5B,8BAA6B;AACpC,SA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0E;QAC1E,oEAAoE;QACpE,4DAA4D;QAC5D,MAAM0C,WAAW5C,2BAA2B+C;QAE5C7C,OAAOW,MAAM,GAAG;YAAE,GAAIX,OAAOW,MAAM,IAAI,CAAC,CAAC;YAAG,CAAChB,mCAAmC,EAAE+C;QAAS;QAE3F,uEAAuE;QACvE,uEAAuE;QACvE,6BAA6B;QAC7B3C,oBACEC,QACAwC,4BAA4BH,WAAWK;QAGzC,IAAI,CAACG,cAAcG,WAAW,IAAI,CAAChD,OAAOgD,WAAW,EAAE,OAAOhD;QAE9D,kEAAkE;QAClE,MAAMiD,0BACJJ,cAAcG,WAAW;QAE3BhD,OAAOgD,WAAW,GAAGhD,OAAOgD,WAAW,CAAC1B,GAAG,CAAC,CAACT;YAC3C,MAAMsB,oBAAoBc,uBAAuB,CAACpC,WAAWP,IAAI,CAAC;YAClE,IAAI,CAAC6B,mBAAmB,OAAOtB;YAE/B,MAAMqC,WAAWhB,iCAAiCrB,YAAYsB;YAC9D,IAAId,OAAOR;YAEX,IAAIqC,SAASX,iBAAiB,EAC5BlB,OAAOW,oCACLX,MACAmB,4BAA4B3B,WAAWP,IAAI,EAAEoC;YAGjD,IAAIQ,SAASZ,YAAY,EACvBjB,OAAOT,kBACLS,MACA6B,SAASpC,SAAS,EAClBP,iBACE2C,SAAS1C,YAAY,EACrBlB,4BAA4BO,6BAA6BgB,WAAWP,IAAI,EAAEoC;YAIhF,OAAOrB;QACT;QAEA,OAAOrB;IACT,EAAC;AAEH,SACErB,sBAAsB,EACtBC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,EACnBJ,kBAAkB,EAClBK,sBAAsB,EACtBC,sBAAsB,EACtBQ,2BAA2B,EAC3BP,sBAAsB,EACtBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,kBAAkB,EAClBb,aAAa,EACbiB,aAAa,KACd"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Block, CollectionConfig, Config, Field, Plugin } from 'payload'\n\nimport type { MarkdownEditorDirectiveConfig } from './editor/directiveConfig.js'\nimport type { PayloadMarkdownResolvedSettings } from './runtime/index.js'\nimport type {\n MarkdownFieldOptions,\n PayloadMarkdownAppearanceOptions,\n PayloadMarkdownCollectionConfig,\n PayloadMarkdownConfig,\n} from './types.js'\n\nimport { createAppearanceGlobal, resolveAppearanceOptions } from './appearance/config.js'\nimport { attachAppearancePayload, clearAppearance, registerAppearance } from './appearance/runtime.js'\nimport { createMarkdownBlock, MarkdownBlock } from './blocks/MarkdownBlock/config.js'\nimport { resolveEffectiveMarkdownBlockParams } from './blocks/MarkdownBlock/params.js'\nimport { DEFAULT_CODE_LANGS } from './core/codeToHtml.js'\nimport {\n DEFAULT_CALLOUT_THEMES,\n DEFAULT_CARD_THEMES,\n DEFAULT_CARDS_THEMES,\n DEFAULT_CELL_THEMES,\n DEFAULT_COLUMNS_THEMES,\n DEFAULT_DETAILS_THEMES,\n DEFAULT_SECTION_THEMES,\n DEFAULT_STEPS_THEMES,\n DEFAULT_TAB_THEMES,\n DEFAULT_TABS_THEMES,\n DEFAULT_TOC_THEMES,\n} from './directives/themes.js'\nimport {\n createEditorDirectiveConfig,\n PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY,\n} from './editor/directiveConfig.js'\nimport { DEFAULT_MARKDOWN_MAX_LENGTH, markdownField } from './field/MarkdownField/config.js'\nimport { DEFAULT_PALETTES } from './palettes/index.js'\nimport {\n clearPayloadMarkdownSettings,\n PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY,\n resolveMarkdownBlockDefaults,\n resolveMarkdownFieldDefaults,\n setPayloadMarkdownSettings,\n} from './runtime/index.js'\n\nfunction ensureMarkdownBlock(config: Config, block: Block) {\n const blocks = config.blocks ?? []\n const alreadyExists = blocks.some((entry) => entry.slug === block.slug)\n if (alreadyExists) return\n\n // Copy-on-write: never mutate the caller's config arrays (CORE-18).\n config.blocks = [...blocks, block]\n}\n\nfunction withEditorConfig(\n fieldOptions: Omit<MarkdownFieldOptions, 'name'> | undefined,\n editorConfig: MarkdownEditorDirectiveConfig,\n): Omit<MarkdownFieldOptions, 'name'> {\n return {\n ...(fieldOptions ?? {}),\n admin: {\n ...(fieldOptions?.admin ?? {}),\n custom: {\n ...(fieldOptions?.admin?.custom ?? {}),\n [PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY]: editorConfig,\n },\n },\n }\n}\n\nfunction withMarkdownField(\n collection: CollectionConfig,\n fieldName: string,\n fieldOptions?: Omit<MarkdownFieldOptions, 'name'>,\n): CollectionConfig {\n const alreadyExists = collection.fields.some(\n (field) => 'name' in field && field.name === fieldName,\n )\n\n if (alreadyExists) return collection\n\n return {\n ...collection,\n fields: [\n ...collection.fields,\n markdownField({\n name: fieldName,\n label: 'Markdown',\n ...(fieldOptions || {}),\n }),\n ],\n }\n}\n\n/**\n * Returns `fields` with `block` added to every reachable blocks field. Field\n * objects and arrays on the modified paths are copied; the caller's objects\n * are never mutated (CORE-18).\n */\nfunction withBlockInstalled(fields: Field[], block: Block): Field[] {\n let changed = false\n\n const next = fields.map((field): Field => {\n let updated: Field = field\n\n if (field.type === 'blocks') {\n const blocks = field.blocks ?? []\n\n if (!blocks.some((entry) => entry.slug === block.slug)) {\n updated = { ...field, blocks: [...blocks, block] }\n }\n }\n\n if ('fields' in updated && Array.isArray(updated.fields)) {\n const nestedFields = withBlockInstalled(updated.fields, block)\n if (nestedFields !== updated.fields) updated = { ...updated, fields: nestedFields } as Field\n }\n\n if (updated.type === 'tabs' && Array.isArray(updated.tabs)) {\n let tabsChanged = false\n const tabs = updated.tabs.map((tab) => {\n if (!('fields' in tab) || !Array.isArray(tab.fields)) return tab\n\n const tabFields = withBlockInstalled(tab.fields, block)\n if (tabFields === tab.fields) return tab\n\n tabsChanged = true\n return { ...tab, fields: tabFields }\n })\n\n if (tabsChanged) updated = { ...updated, tabs }\n }\n\n if (updated !== field) changed = true\n\n return updated\n })\n\n return changed ? next : fields\n}\n\nfunction withMarkdownBlockInCollectionBlocks(\n collection: CollectionConfig,\n block: Block,\n): CollectionConfig {\n const fields = withBlockInstalled(collection.fields, block)\n\n return fields === collection.fields ? collection : { ...collection, fields }\n}\n\nfunction collectionHasBlocksField(fields: Field[]): boolean {\n for (const field of fields) {\n if (field.type === 'blocks') return true\n\n if ('fields' in field && Array.isArray(field.fields))\n if (collectionHasBlocksField(field.fields)) return true\n\n if (field.type === 'tabs' && Array.isArray(field.tabs))\n for (const tab of field.tabs)\n if ('fields' in tab && Array.isArray(tab.fields))\n if (collectionHasBlocksField(tab.fields)) return true\n }\n\n return false\n}\n\nfunction resolveCollectionInstallBehavior(\n collection: CollectionConfig,\n collectionOptions: PayloadMarkdownCollectionConfig | true,\n) {\n const hasBlocksField = collectionHasBlocksField(collection.fields)\n\n if (collectionOptions === true) {\n return {\n fieldName: 'content',\n fieldOptions: undefined,\n installField: !hasBlocksField,\n installIntoBlocks: hasBlocksField,\n }\n }\n\n return {\n fieldName: collectionOptions.fieldName || 'content',\n fieldOptions: collectionOptions.field,\n installField: collectionOptions.installField ?? !hasBlocksField,\n installIntoBlocks: collectionOptions.installIntoBlocks ?? hasBlocksField,\n }\n}\n\n/**\n * The markdown block for one install scope (global or a collection): its\n * editor gets the scope's themes and icon packs, and its params pre-fill from\n * the scope's effective block defaults.\n */\nfunction createMarkdownBlockForScope(\n collectionSlug: string | undefined,\n settings: PayloadMarkdownResolvedSettings,\n) {\n const blockDefaults = resolveMarkdownBlockDefaults(collectionSlug, settings)\n\n return createMarkdownBlock(\n createEditorDirectiveConfig(blockDefaults, settings.appearanceSlug),\n resolveEffectiveMarkdownBlockParams(blockDefaults),\n )\n}\n\nexport const payloadMarkdown =\n (pluginOptions: PayloadMarkdownConfig = {}): Plugin =>\n (incomingConfig: Config): Config => {\n const config = { ...incomingConfig }\n\n if (pluginOptions.enabled === false) {\n // A disabled plugin must not leave a previous configuration's render\n // defaults active (CORE-18).\n clearPayloadMarkdownSettings()\n clearAppearance()\n return config\n }\n\n // Opt-in runtime palettes: the \"Markdown Appearance\" global, readable by\n // renders through the Payload instance captured at init.\n const appearance = resolveAppearanceOptions(pluginOptions.appearance)\n\n if (appearance) {\n // Registered even when the app defines the global itself.\n registerAppearance({ slug: appearance.slug, ttl: appearance.cacheTtl })\n\n const globals = config.globals ?? []\n\n if (!globals.some((global) => global.slug === appearance.slug))\n config.globals = [...globals, createAppearanceGlobal(appearance)]\n\n const incomingOnInit = config.onInit\n\n config.onInit = async (payload) => {\n attachAppearancePayload(payload)\n await incomingOnInit?.(payload)\n }\n } else {\n clearAppearance()\n }\n\n // The settings are owned by the config being built: a frozen snapshot on\n // its server-only `custom`, also registered process-wide (shared by every\n // installed copy of this package) for renderers without an explicit\n // settings source. The last built config wins the registry.\n const settings = setPayloadMarkdownSettings(pluginOptions)\n\n config.custom = { ...(config.custom ?? {}), [PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY]: settings }\n\n // The admin editor gets the resolved theme names and icon pack aliases\n // for its scope through field.admin.custom (CORE-8), computed from the\n // settings this config owns.\n ensureMarkdownBlock(\n config,\n createMarkdownBlockForScope(undefined, settings),\n )\n\n if (!pluginOptions.collections || !config.collections) return config\n\n // Widened to string keys: collection.slug is a plain string here.\n const collectionOptionsBySlug: Partial<Record<string, PayloadMarkdownCollectionConfig | true>> =\n pluginOptions.collections\n\n config.collections = config.collections.map((collection) => {\n const collectionOptions = collectionOptionsBySlug[collection.slug]\n if (!collectionOptions) return collection\n\n const resolved = resolveCollectionInstallBehavior(collection, collectionOptions)\n let next = collection\n\n if (resolved.installIntoBlocks)\n next = withMarkdownBlockInCollectionBlocks(\n next,\n createMarkdownBlockForScope(collection.slug, settings),\n )\n\n if (resolved.installField)\n next = withMarkdownField(\n next,\n resolved.fieldName,\n withEditorConfig(\n resolved.fieldOptions,\n createEditorDirectiveConfig(\n resolveMarkdownFieldDefaults(collection.slug, settings),\n settings.appearanceSlug,\n ),\n ),\n )\n\n return next\n })\n\n return config\n }\n\n/**\n * Palettes managed in the \"Markdown Appearance\" global (`appearance` option),\n * cached per process. `MarkdownRenderer` loads them itself; pass the result as\n * `runtimePalettes` to `renderMarkdown` to render with them elsewhere.\n */\nexport { loadAppearancePalettes as loadMarkdownPalettes } from './appearance/runtime.js'\nexport {\n DEFAULT_CALLOUT_THEMES,\n DEFAULT_CARD_THEMES,\n DEFAULT_CARDS_THEMES,\n DEFAULT_CELL_THEMES,\n DEFAULT_CODE_LANGS,\n DEFAULT_COLUMNS_THEMES,\n DEFAULT_DETAILS_THEMES,\n DEFAULT_MARKDOWN_MAX_LENGTH,\n DEFAULT_PALETTES,\n DEFAULT_SECTION_THEMES,\n DEFAULT_STEPS_THEMES,\n DEFAULT_TAB_THEMES,\n DEFAULT_TABS_THEMES,\n DEFAULT_TOC_THEMES,\n MarkdownBlock,\n markdownField,\n}\nexport type { MarkdownFieldOptions, PayloadMarkdownAppearanceOptions, PayloadMarkdownConfig }\nexport type {\n MarkdownCodeConfig,\n MarkdownColorScheme,\n MarkdownDirectiveTheme,\n MarkdownDirectiveThemeGroup,\n MarkdownDirectiveThemes,\n MarkdownPalette,\n MarkdownPaletteColors,\n MarkdownPalettes,\n PayloadMarkdownIconPack,\n PayloadMarkdownIconsConfig,\n} from './types/core.js'\n"],"names":["createAppearanceGlobal","resolveAppearanceOptions","attachAppearancePayload","clearAppearance","registerAppearance","createMarkdownBlock","MarkdownBlock","resolveEffectiveMarkdownBlockParams","DEFAULT_CODE_LANGS","DEFAULT_CALLOUT_THEMES","DEFAULT_CARD_THEMES","DEFAULT_CARDS_THEMES","DEFAULT_CELL_THEMES","DEFAULT_COLUMNS_THEMES","DEFAULT_DETAILS_THEMES","DEFAULT_SECTION_THEMES","DEFAULT_STEPS_THEMES","DEFAULT_TAB_THEMES","DEFAULT_TABS_THEMES","DEFAULT_TOC_THEMES","createEditorDirectiveConfig","PAYLOAD_MARKDOWN_ADMIN_CUSTOM_KEY","DEFAULT_MARKDOWN_MAX_LENGTH","markdownField","DEFAULT_PALETTES","clearPayloadMarkdownSettings","PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY","resolveMarkdownBlockDefaults","resolveMarkdownFieldDefaults","setPayloadMarkdownSettings","ensureMarkdownBlock","config","block","blocks","alreadyExists","some","entry","slug","withEditorConfig","fieldOptions","editorConfig","admin","custom","withMarkdownField","collection","fieldName","fields","field","name","label","withBlockInstalled","changed","next","map","updated","type","Array","isArray","nestedFields","tabs","tabsChanged","tab","tabFields","withMarkdownBlockInCollectionBlocks","collectionHasBlocksField","resolveCollectionInstallBehavior","collectionOptions","hasBlocksField","undefined","installField","installIntoBlocks","createMarkdownBlockForScope","collectionSlug","settings","blockDefaults","appearanceSlug","payloadMarkdown","pluginOptions","incomingConfig","enabled","appearance","ttl","cacheTtl","globals","global","incomingOnInit","onInit","payload","collections","collectionOptionsBySlug","resolved","loadAppearancePalettes","loadMarkdownPalettes"],"mappings":"AAWA,SAASA,sBAAsB,EAAEC,wBAAwB,QAAQ,yBAAwB;AACzF,SAASC,uBAAuB,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,0BAAyB;AACtG,SAASC,mBAAmB,EAAEC,aAAa,QAAQ,mCAAkC;AACrF,SAASC,mCAAmC,QAAQ,mCAAkC;AACtF,SAASC,kBAAkB,QAAQ,uBAAsB;AACzD,SACEC,sBAAsB,EACtBC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,EACnBC,sBAAsB,EACtBC,sBAAsB,EACtBC,sBAAsB,EACtBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,kBAAkB,QACb,yBAAwB;AAC/B,SACEC,2BAA2B,EAC3BC,iCAAiC,QAC5B,8BAA6B;AACpC,SAASC,2BAA2B,EAAEC,aAAa,QAAQ,kCAAiC;AAC5F,SAASC,gBAAgB,QAAQ,sBAAqB;AACtD,SACEC,4BAA4B,EAC5BC,kCAAkC,EAClCC,4BAA4B,EAC5BC,4BAA4B,EAC5BC,0BAA0B,QACrB,qBAAoB;AAE3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D,SAASnD,YAAY,EACrBnB,4BACEQ,6BAA6BgB,WAAWP,IAAI,EAAEoC,WAC9CA,SAASE,cAAc;YAK/B,OAAOvB;QACT;QAEA,OAAOrB;IACT,EAAC;AAEH;;;;CAIC,GACD,SAAS4D,0BAA0BC,oBAAoB,QAAQ,0BAAyB;AACxF,SACEnF,sBAAsB,EACtBC,mBAAmB,EACnBC,oBAAoB,EACpBC,mBAAmB,EACnBJ,kBAAkB,EAClBK,sBAAsB,EACtBC,sBAAsB,EACtBQ,2BAA2B,EAC3BE,gBAAgB,EAChBT,sBAAsB,EACtBC,oBAAoB,EACpBC,kBAAkB,EAClBC,mBAAmB,EACnBC,kBAAkB,EAClBb,aAAa,EACbiB,aAAa,KACd"}
|
package/dist/mcp/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import type { MarkdownAgentAccessMode } from '../agent/access.js';
|
|
4
|
-
export type PayloadMarkdownMcpToolName = 'guide' | 'publish' | 'read' | 'validate' | 'write';
|
|
4
|
+
export type PayloadMarkdownMcpToolName = 'deletePalette' | 'guide' | 'palettes' | 'publish' | 'read' | 'savePalette' | 'validate' | 'write';
|
|
5
5
|
export type PayloadMarkdownMcpOptions = {
|
|
6
6
|
/**
|
|
7
7
|
* `mcpApiKey` (default): tools honor the MCP API key's per-collection and
|
|
@@ -11,7 +11,7 @@ export type PayloadMarkdownMcpOptions = {
|
|
|
11
11
|
access?: MarkdownAgentAccessMode;
|
|
12
12
|
/** Register the `markdownEditDocument` prompt (default `true`). */
|
|
13
13
|
prompts?: boolean;
|
|
14
|
-
/** Tools to register (default: all). Drop `write` and `
|
|
14
|
+
/** Tools to register (default: all). Drop `write`, `publish`, `savePalette` and `deletePalette` for read-only connections. */
|
|
15
15
|
tools?: PayloadMarkdownMcpToolName[];
|
|
16
16
|
};
|
|
17
17
|
type ToolResult = {
|
package/dist/mcp/index.js
CHANGED
|
@@ -2,7 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
import { MARKDOWN_AGENT_ACCESS_CONTEXT_KEY, MarkdownAgentError } from '../agent/access.js';
|
|
3
3
|
import { publishMarkdown, readMarkdownDocuments, writeMarkdown } from '../agent/documents.js';
|
|
4
4
|
import { getMarkdownGuide } from '../agent/guide.js';
|
|
5
|
+
import { deleteMarkdownPalette, listMarkdownPalettes, saveMarkdownPalette } from '../agent/palettes.js';
|
|
5
6
|
import { validateMarkdown } from '../agent/validate.js';
|
|
7
|
+
import { loadAppearancePalettes } from '../appearance/runtime.js';
|
|
6
8
|
const json = (value)=>({
|
|
7
9
|
content: [
|
|
8
10
|
{
|
|
@@ -70,6 +72,20 @@ const entityShape = {
|
|
|
70
72
|
global: z.string().optional().describe('Global slug, instead of "collection" + "id".'),
|
|
71
73
|
locale: z.string().optional().describe('Locale code for localized content. Defaults to the default locale.')
|
|
72
74
|
};
|
|
75
|
+
const colorShape = {
|
|
76
|
+
accent: z.string().optional().describe('Links and hovered titles inside directives.'),
|
|
77
|
+
background: z.string().optional().describe('Surface of directives that use the palette.'),
|
|
78
|
+
border: z.string().optional().describe('Border of directives that use the palette.'),
|
|
79
|
+
color: z.string().optional().describe('Icon colour (duotone primary layer); button label colour.'),
|
|
80
|
+
secondaryColor: z.string().optional().describe('Duotone secondary layer (default: color).')
|
|
81
|
+
};
|
|
82
|
+
const paletteShape = z.object({
|
|
83
|
+
...colorShape,
|
|
84
|
+
name: z.string().describe('Stable name markdown references: lowercase letters, digits and dashes, for example "debian".'),
|
|
85
|
+
dark: z.object(colorShape).optional().describe('Dark-scheme colours; unset ones keep the light value.'),
|
|
86
|
+
label: z.string().optional().describe('Display name.'),
|
|
87
|
+
secondaryOpacity: z.number().min(0).max(1).optional().describe('Opacity of the duotone secondary layer (default: the icon\'s own, 0.4 for Font Awesome).')
|
|
88
|
+
}).describe('Colours are hex (#e95420), rgb()/hsl()/oklch()/lab() with numeric arguments, a CSS colour name, currentColor, transparent, or var(--token).');
|
|
73
89
|
function toEdit(raw, index) {
|
|
74
90
|
const action = raw.action;
|
|
75
91
|
if (action === 'replace') return {
|
|
@@ -101,13 +117,16 @@ function toEdit(raw, index) {
|
|
|
101
117
|
'validate',
|
|
102
118
|
'read',
|
|
103
119
|
'write',
|
|
104
|
-
'publish'
|
|
120
|
+
'publish',
|
|
121
|
+
'palettes',
|
|
122
|
+
'savePalette',
|
|
123
|
+
'deletePalette'
|
|
105
124
|
]);
|
|
106
125
|
const tools = [
|
|
107
126
|
{
|
|
108
127
|
name: 'markdownGuide',
|
|
109
|
-
description: 'Start here. Returns the payload-markdown authoring guide for this site: the agent workflow, which collections and globals hold markdown, the configured directive themes, icons and code languages, and every directive with its attributes. Read it before writing markdown.',
|
|
110
|
-
handler: safely((args, req)=>({
|
|
128
|
+
description: 'Start here. Returns the payload-markdown authoring guide for this site: the agent workflow, which collections and globals hold markdown, the configured directive themes, colour palettes, icons and code languages, and every directive with its attributes. Read it before writing markdown.',
|
|
129
|
+
handler: safely(async (args, req)=>({
|
|
111
130
|
content: [
|
|
112
131
|
{
|
|
113
132
|
type: 'text',
|
|
@@ -115,7 +134,8 @@ function toEdit(raw, index) {
|
|
|
115
134
|
access,
|
|
116
135
|
collection: str(args.collection),
|
|
117
136
|
payload: req.payload,
|
|
118
|
-
req
|
|
137
|
+
req,
|
|
138
|
+
runtimePalettes: await loadAppearancePalettes(req.payload)
|
|
119
139
|
})
|
|
120
140
|
}
|
|
121
141
|
]
|
|
@@ -223,6 +243,47 @@ function toEdit(raw, index) {
|
|
|
223
243
|
allowWarnings: z.boolean().optional().describe('Publish despite validation warnings in the draft. Errors always block.'),
|
|
224
244
|
overrideLock: z.boolean().optional().describe('Publish even if someone has the document open. Ask the user first.')
|
|
225
245
|
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: 'markdownPalettes',
|
|
249
|
+
description: 'Lists the colour palettes markdown can use (built-in, configured in code, and managed in the admin), with their colours, plus the syntax to apply them. Palettes colour icons individually and recolour directives without CSS or code changes.',
|
|
250
|
+
handler: safely(async (args, req)=>json(await listMarkdownPalettes({
|
|
251
|
+
access,
|
|
252
|
+
collection: str(args.collection),
|
|
253
|
+
req
|
|
254
|
+
}))),
|
|
255
|
+
key: 'palettes',
|
|
256
|
+
parameters: {
|
|
257
|
+
collection: z.string().optional().describe('Include the palettes configured for this collection.')
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'markdownPaletteSave',
|
|
262
|
+
description: 'Creates or updates a colour palette in the "Markdown Appearance" global (by name), so markdown can use it right away without code changes or a rebuild. Colours are validated; contrast notes are advisory. Pass previousName to rename. Requires update permission on that global.',
|
|
263
|
+
handler: safely(async (args, req)=>json(await saveMarkdownPalette({
|
|
264
|
+
access,
|
|
265
|
+
palette: args.palette,
|
|
266
|
+
previousName: str(args.previousName),
|
|
267
|
+
req
|
|
268
|
+
}))),
|
|
269
|
+
key: 'savePalette',
|
|
270
|
+
parameters: {
|
|
271
|
+
palette: paletteShape,
|
|
272
|
+
previousName: z.string().optional().describe('Rename: the palette\'s current name. Markdown using the old name then reports an unknown palette.')
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
name: 'markdownPaletteDelete',
|
|
277
|
+
description: 'Deletes a palette from the "Markdown Appearance" global. Markdown that still uses it renders without it and reports an unknown palette. Requires update permission on that global.',
|
|
278
|
+
handler: safely(async (args, req)=>json(await deleteMarkdownPalette({
|
|
279
|
+
name: text(args.name),
|
|
280
|
+
access,
|
|
281
|
+
req
|
|
282
|
+
}))),
|
|
283
|
+
key: 'deletePalette',
|
|
284
|
+
parameters: {
|
|
285
|
+
name: z.string().describe('Name of the admin-managed palette to delete.')
|
|
286
|
+
}
|
|
226
287
|
}
|
|
227
288
|
];
|
|
228
289
|
return tools.filter((tool)=>enabled.has(tool.key)).map(({ key: _key, ...tool })=>tool);
|