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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { parseIconEntries } from '../icons/entries.js';
|
|
2
|
+
import { getPaletteRegistry } from './index.js';
|
|
3
|
+
const LISTED_PALETTES = 12;
|
|
4
|
+
/** The unknown-palette message, shared by the renderer and the editor lint. */ export function formatUnknownPaletteMessage(name, directive, known) {
|
|
5
|
+
const names = [
|
|
6
|
+
...known
|
|
7
|
+
].sort();
|
|
8
|
+
const listed = names.slice(0, LISTED_PALETTES).join(', ');
|
|
9
|
+
const more = names.length > LISTED_PALETTES ? `, … (${names.length} in total)` : '';
|
|
10
|
+
return `Unknown palette "${name}" on "${directive}". It renders without that palette. ${names.length > 0 ? `Known palettes: ${listed}${more}.` : 'No palettes are configured.'}`;
|
|
11
|
+
}
|
|
12
|
+
/** Warning for a palette name the render cannot resolve, or `undefined` when it is known. */ export function getUnknownPaletteWarning(name, directive, config) {
|
|
13
|
+
const registry = getPaletteRegistry(config.palettes);
|
|
14
|
+
return registry.get(name) ? undefined : formatUnknownPaletteMessage(name, directive, registry.names());
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Palette names a directive references: its `palette` / `iconPalette` and the
|
|
18
|
+
* `palette=` of its icon entries, limited to the attributes it accepts.
|
|
19
|
+
*/ export function collectPaletteNames(allowedAttributes, attributes) {
|
|
20
|
+
const names = new Set();
|
|
21
|
+
const read = (name)=>{
|
|
22
|
+
const value = attributes?.[name];
|
|
23
|
+
return allowedAttributes.includes(name) && typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
24
|
+
};
|
|
25
|
+
for (const attribute of [
|
|
26
|
+
'palette',
|
|
27
|
+
'iconPalette'
|
|
28
|
+
]){
|
|
29
|
+
const value = read(attribute);
|
|
30
|
+
if (value) names.add(value);
|
|
31
|
+
}
|
|
32
|
+
for (const entry of parseIconEntries(read('icon')).entries)if (entry.palette) names.add(entry.palette);
|
|
33
|
+
return [
|
|
34
|
+
...names
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/palettes/diagnostics.ts"],"sourcesContent":["import type { MarkdownRenderConfig } from '../types/core.js'\n\nimport { parseIconEntries } from '../icons/entries.js'\nimport { getPaletteRegistry } from './index.js'\n\nconst LISTED_PALETTES = 12\n\n/** The unknown-palette message, shared by the renderer and the editor lint. */\nexport function formatUnknownPaletteMessage(name: string, directive: string, known: readonly string[]): string {\n const names = [...known].sort()\n const listed = names.slice(0, LISTED_PALETTES).join(', ')\n const more = names.length > LISTED_PALETTES ? `, … (${names.length} in total)` : ''\n\n return `Unknown palette \"${name}\" on \"${directive}\". It renders without that palette. ${\n names.length > 0 ? `Known palettes: ${listed}${more}.` : 'No palettes are configured.'\n }`\n}\n\n/** Warning for a palette name the render cannot resolve, or `undefined` when it is known. */\nexport function getUnknownPaletteWarning(\n name: string,\n directive: string,\n config: Pick<MarkdownRenderConfig, 'palettes'>,\n): string | undefined {\n const registry = getPaletteRegistry(config.palettes)\n\n return registry.get(name) ? undefined : formatUnknownPaletteMessage(name, directive, registry.names())\n}\n\n/**\n * Palette names a directive references: its `palette` / `iconPalette` and the\n * `palette=` of its icon entries, limited to the attributes it accepts.\n */\nexport function collectPaletteNames(\n allowedAttributes: readonly string[],\n attributes: null | Record<string, unknown> | undefined,\n): string[] {\n const names = new Set<string>()\n const read = (name: string) => {\n const value = attributes?.[name]\n\n return allowedAttributes.includes(name) && typeof value === 'string' && value.trim() ? value.trim() : undefined\n }\n\n for (const attribute of ['palette', 'iconPalette']) {\n const value = read(attribute)\n if (value) names.add(value)\n }\n\n for (const entry of parseIconEntries(read('icon')).entries) if (entry.palette) names.add(entry.palette)\n\n return [...names]\n}\n"],"names":["parseIconEntries","getPaletteRegistry","LISTED_PALETTES","formatUnknownPaletteMessage","name","directive","known","names","sort","listed","slice","join","more","length","getUnknownPaletteWarning","config","registry","palettes","get","undefined","collectPaletteNames","allowedAttributes","attributes","Set","read","value","includes","trim","attribute","add","entry","entries","palette"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,kBAAkB,QAAQ,aAAY;AAE/C,MAAMC,kBAAkB;AAExB,6EAA6E,GAC7E,OAAO,SAASC,4BAA4BC,IAAY,EAAEC,SAAiB,EAAEC,KAAwB;IACnG,MAAMC,QAAQ;WAAID;KAAM,CAACE,IAAI;IAC7B,MAAMC,SAASF,MAAMG,KAAK,CAAC,GAAGR,iBAAiBS,IAAI,CAAC;IACpD,MAAMC,OAAOL,MAAMM,MAAM,GAAGX,kBAAkB,CAAC,KAAK,EAAEK,MAAMM,MAAM,CAAC,UAAU,CAAC,GAAG;IAEjF,OAAO,CAAC,iBAAiB,EAAET,KAAK,MAAM,EAAEC,UAAU,oCAAoC,EACpFE,MAAMM,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAEJ,SAASG,KAAK,CAAC,CAAC,GAAG,+BACzD;AACJ;AAEA,2FAA2F,GAC3F,OAAO,SAASE,yBACdV,IAAY,EACZC,SAAiB,EACjBU,MAA8C;IAE9C,MAAMC,WAAWf,mBAAmBc,OAAOE,QAAQ;IAEnD,OAAOD,SAASE,GAAG,CAACd,QAAQe,YAAYhB,4BAA4BC,MAAMC,WAAWW,SAAST,KAAK;AACrG;AAEA;;;CAGC,GACD,OAAO,SAASa,oBACdC,iBAAoC,EACpCC,UAAsD;IAEtD,MAAMf,QAAQ,IAAIgB;IAClB,MAAMC,OAAO,CAACpB;QACZ,MAAMqB,QAAQH,YAAY,CAAClB,KAAK;QAEhC,OAAOiB,kBAAkBK,QAAQ,CAACtB,SAAS,OAAOqB,UAAU,YAAYA,MAAME,IAAI,KAAKF,MAAME,IAAI,KAAKR;IACxG;IAEA,KAAK,MAAMS,aAAa;QAAC;QAAW;KAAc,CAAE;QAClD,MAAMH,QAAQD,KAAKI;QACnB,IAAIH,OAAOlB,MAAMsB,GAAG,CAACJ;IACvB;IAEA,KAAK,MAAMK,SAAS9B,iBAAiBwB,KAAK,SAASO,OAAO,CAAE,IAAID,MAAME,OAAO,EAAEzB,MAAMsB,GAAG,CAACC,MAAME,OAAO;IAEtG,OAAO;WAAIzB;KAAM;AACnB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { MarkdownPalette, MarkdownPaletteColors, MarkdownPalettes } from '../types/core.js';
|
|
2
|
+
export { DEFAULT_PALETTES } from './defaults.js';
|
|
3
|
+
/** Palette names: what Markdown references, so they stay simple and stable. */
|
|
4
|
+
export declare const PALETTE_NAME_PATTERN: RegExp;
|
|
5
|
+
declare const COLOR_KEYS: readonly ["accent", "background", "border", "color", "secondaryColor"];
|
|
6
|
+
type PaletteColorKey = (typeof COLOR_KEYS)[number];
|
|
7
|
+
/** A palette whose every value has been validated and normalized. */
|
|
8
|
+
export type ResolvedPalette = {
|
|
9
|
+
dark: MarkdownPaletteColors;
|
|
10
|
+
label?: string;
|
|
11
|
+
light: MarkdownPaletteColors;
|
|
12
|
+
name: string;
|
|
13
|
+
secondaryOpacity?: number;
|
|
14
|
+
};
|
|
15
|
+
export type PaletteValidation = {
|
|
16
|
+
errors: string[];
|
|
17
|
+
palette?: ResolvedPalette;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Validates and normalizes a palette from any source (config, the admin
|
|
21
|
+
* global, an MCP tool). Invalid colours are reported, never passed through.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validatePalette(input: unknown): PaletteValidation;
|
|
24
|
+
/**
|
|
25
|
+
* Combines palette layers, lowest precedence first (plugin, collection,
|
|
26
|
+
* renderer, admin). Later layers replace palettes by name; a layer only
|
|
27
|
+
* changes `extendDefaults` when it sets it explicitly.
|
|
28
|
+
*/
|
|
29
|
+
export declare function mergeMarkdownPalettes(...layers: Array<MarkdownPalettes | undefined>): MarkdownPalettes | undefined;
|
|
30
|
+
export type PaletteRegistry = {
|
|
31
|
+
get: (name: string) => ResolvedPalette | undefined;
|
|
32
|
+
names: () => string[];
|
|
33
|
+
/** Problems with configured palettes (each invalid palette is skipped). */
|
|
34
|
+
warnings: string[];
|
|
35
|
+
};
|
|
36
|
+
/** The palettes a render can reference, by name. Cached by content. */
|
|
37
|
+
export declare function getPaletteRegistry(palettes: MarkdownPalettes | undefined): PaletteRegistry;
|
|
38
|
+
/**
|
|
39
|
+
* The CSS value of one palette colour: the light value, or a mix that follows
|
|
40
|
+
* `--pmd-scheme-dark` (1 = dark, 0 = light) when the dark value differs, the
|
|
41
|
+
* same scheme switch the directive defaults use.
|
|
42
|
+
*/
|
|
43
|
+
export declare function paletteColorValue(palette: ResolvedPalette, key: PaletteColorKey): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Inline custom properties a directive gets from its palette. They are the
|
|
46
|
+
* public tokens the default directive themes read first, so a palette
|
|
47
|
+
* recolours a card or callout while its structural theme stays in charge of
|
|
48
|
+
* shape, spacing and shadow.
|
|
49
|
+
*/
|
|
50
|
+
export declare function directivePaletteStyle(palette: ResolvedPalette): string | undefined;
|
|
51
|
+
/** Button colours from a palette: fill from `background`, label from `color`. */
|
|
52
|
+
export declare function buttonPaletteStyle(palette: ResolvedPalette): string | undefined;
|
|
53
|
+
export type IconPaint = {
|
|
54
|
+
primary?: string;
|
|
55
|
+
secondary?: string;
|
|
56
|
+
secondaryOpacity?: number;
|
|
57
|
+
};
|
|
58
|
+
/** How an icon is painted with a palette. */
|
|
59
|
+
export declare function iconPaint(palette: ResolvedPalette): IconPaint;
|
|
60
|
+
/** Plain, serializable view of a palette (for guides, editors and agents). */
|
|
61
|
+
export declare function describePalette(palette: ResolvedPalette): MarkdownPalette;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { normalizePaletteColor, PALETTE_COLOR_FORMATS } from './colors.js';
|
|
2
|
+
import { DEFAULT_PALETTES } from './defaults.js';
|
|
3
|
+
export { DEFAULT_PALETTES } from './defaults.js';
|
|
4
|
+
/** Palette names: what Markdown references, so they stay simple and stable. */ export const PALETTE_NAME_PATTERN = /^[a-z][\da-z-]{0,47}$/;
|
|
5
|
+
const COLOR_KEYS = [
|
|
6
|
+
'accent',
|
|
7
|
+
'background',
|
|
8
|
+
'border',
|
|
9
|
+
'color',
|
|
10
|
+
'secondaryColor'
|
|
11
|
+
];
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
/** A value as shown in an error message. */ function show(value) {
|
|
16
|
+
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
17
|
+
}
|
|
18
|
+
function readColors(source, prefix, errors) {
|
|
19
|
+
const colors = {};
|
|
20
|
+
for (const key of COLOR_KEYS){
|
|
21
|
+
const raw = source[key];
|
|
22
|
+
if (raw === undefined || raw === null || raw === '') continue;
|
|
23
|
+
const color = normalizePaletteColor(raw);
|
|
24
|
+
if (color) colors[key] = color;
|
|
25
|
+
else errors.push(`${prefix}${key} "${show(raw)}" is not a valid colour. Use ${PALETTE_COLOR_FORMATS}.`);
|
|
26
|
+
}
|
|
27
|
+
return colors;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validates and normalizes a palette from any source (config, the admin
|
|
31
|
+
* global, an MCP tool). Invalid colours are reported, never passed through.
|
|
32
|
+
*/ export function validatePalette(input) {
|
|
33
|
+
if (!isRecord(input)) return {
|
|
34
|
+
errors: [
|
|
35
|
+
'A palette must be an object with a "name".'
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
const errors = [];
|
|
39
|
+
const name = typeof input.name === 'string' ? input.name.trim() : '';
|
|
40
|
+
if (!PALETTE_NAME_PATTERN.test(name)) errors.push(`Palette name "${name}" is invalid. Use 1–48 lowercase letters, digits and dashes, starting with a letter.`);
|
|
41
|
+
const light = readColors(input, '', errors);
|
|
42
|
+
const dark = isRecord(input.dark) ? readColors(input.dark, 'dark.', errors) : {};
|
|
43
|
+
let secondaryOpacity;
|
|
44
|
+
const rawOpacity = input.secondaryOpacity;
|
|
45
|
+
if (rawOpacity !== undefined && rawOpacity !== null && rawOpacity !== '') {
|
|
46
|
+
const value = typeof rawOpacity === 'string' ? Number(rawOpacity) : rawOpacity;
|
|
47
|
+
if (typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1) secondaryOpacity = Math.round(value * 1000) / 1000;
|
|
48
|
+
else errors.push(`secondaryOpacity "${show(rawOpacity)}" must be a number from 0 to 1.`);
|
|
49
|
+
}
|
|
50
|
+
if (errors.length > 0) return {
|
|
51
|
+
errors
|
|
52
|
+
};
|
|
53
|
+
const label = typeof input.label === 'string' && input.label.trim() ? input.label.trim() : undefined;
|
|
54
|
+
return {
|
|
55
|
+
errors,
|
|
56
|
+
palette: {
|
|
57
|
+
name,
|
|
58
|
+
dark,
|
|
59
|
+
...label ? {
|
|
60
|
+
label
|
|
61
|
+
} : {},
|
|
62
|
+
light,
|
|
63
|
+
...secondaryOpacity !== undefined ? {
|
|
64
|
+
secondaryOpacity
|
|
65
|
+
} : {}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function normalizeGroup(palettes) {
|
|
70
|
+
if (!palettes) return {
|
|
71
|
+
extendDefaults: true,
|
|
72
|
+
items: []
|
|
73
|
+
};
|
|
74
|
+
if (Array.isArray(palettes)) return {
|
|
75
|
+
extendDefaults: true,
|
|
76
|
+
items: palettes
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
extendDefaults: palettes.extendDefaults ?? true,
|
|
80
|
+
items: palettes.items ?? []
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Combines palette layers, lowest precedence first (plugin, collection,
|
|
85
|
+
* renderer, admin). Later layers replace palettes by name; a layer only
|
|
86
|
+
* changes `extendDefaults` when it sets it explicitly.
|
|
87
|
+
*/ export function mergeMarkdownPalettes(...layers) {
|
|
88
|
+
let extendDefaults;
|
|
89
|
+
const byName = new Map();
|
|
90
|
+
let present = false;
|
|
91
|
+
for (const layer of layers){
|
|
92
|
+
if (!layer) continue;
|
|
93
|
+
present = true;
|
|
94
|
+
if (!Array.isArray(layer) && typeof layer.extendDefaults === 'boolean') extendDefaults = layer.extendDefaults;
|
|
95
|
+
for (const item of normalizeGroup(layer).items)if (isRecord(item) && typeof item.name === 'string') byName.set(item.name.trim(), item);
|
|
96
|
+
}
|
|
97
|
+
if (!present) return undefined;
|
|
98
|
+
return {
|
|
99
|
+
...extendDefaults !== undefined ? {
|
|
100
|
+
extendDefaults
|
|
101
|
+
} : {},
|
|
102
|
+
items: [
|
|
103
|
+
...byName.values()
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
let defaultPalettes;
|
|
108
|
+
/** The built-in palettes, validated once per process. */ function getDefaultPalettes() {
|
|
109
|
+
defaultPalettes ??= DEFAULT_PALETTES.flatMap((palette)=>validatePalette(palette).palette ?? []);
|
|
110
|
+
return defaultPalettes;
|
|
111
|
+
}
|
|
112
|
+
function buildRegistry(palettes) {
|
|
113
|
+
const group = normalizeGroup(palettes);
|
|
114
|
+
const resolved = new Map();
|
|
115
|
+
const warnings = [];
|
|
116
|
+
if (group.extendDefaults) for (const palette of getDefaultPalettes())resolved.set(palette.name, palette);
|
|
117
|
+
for (const item of group.items){
|
|
118
|
+
const { errors, palette } = validatePalette(item);
|
|
119
|
+
const name = isRecord(item) && typeof item.name === 'string' ? item.name : '(unnamed)';
|
|
120
|
+
if (palette) resolved.set(palette.name, palette);
|
|
121
|
+
else warnings.push(`Palette "${name}" was ignored: ${errors.join(' ')}`);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
get: (name)=>resolved.get(name.trim()),
|
|
125
|
+
names: ()=>[
|
|
126
|
+
...resolved.keys()
|
|
127
|
+
].sort(),
|
|
128
|
+
warnings
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Registries by content: every render builds a fresh merged config object,
|
|
133
|
+
* so caching by identity would never hit. Bounded, oldest entries first out.
|
|
134
|
+
*/ const registryCache = new Map();
|
|
135
|
+
const MAX_CACHED_REGISTRIES = 64;
|
|
136
|
+
/** The palettes a render can reference, by name. Cached by content. */ export function getPaletteRegistry(palettes) {
|
|
137
|
+
const key = palettes ? JSON.stringify(palettes) : '';
|
|
138
|
+
const cached = registryCache.get(key);
|
|
139
|
+
if (cached) return cached;
|
|
140
|
+
const registry = buildRegistry(palettes);
|
|
141
|
+
if (registryCache.size >= MAX_CACHED_REGISTRIES) registryCache.delete(registryCache.keys().next().value);
|
|
142
|
+
registryCache.set(key, registry);
|
|
143
|
+
return registry;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The CSS value of one palette colour: the light value, or a mix that follows
|
|
147
|
+
* `--pmd-scheme-dark` (1 = dark, 0 = light) when the dark value differs, the
|
|
148
|
+
* same scheme switch the directive defaults use.
|
|
149
|
+
*/ export function paletteColorValue(palette, key) {
|
|
150
|
+
const light = palette.light[key];
|
|
151
|
+
const dark = palette.dark[key] ?? light;
|
|
152
|
+
if (!light) return dark;
|
|
153
|
+
if (!dark || dark === light) return light;
|
|
154
|
+
return `color-mix(in oklab, ${dark} calc(var(--pmd-scheme-dark, 1) * 100%), ${light})`;
|
|
155
|
+
}
|
|
156
|
+
function style(declarations) {
|
|
157
|
+
const parts = declarations.filter(([, value])=>value !== undefined).map(([name, value])=>`${name}:${value}`);
|
|
158
|
+
return parts.length > 0 ? parts.join(';') : undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Inline custom properties a directive gets from its palette. They are the
|
|
162
|
+
* public tokens the default directive themes read first, so a palette
|
|
163
|
+
* recolours a card or callout while its structural theme stays in charge of
|
|
164
|
+
* shape, spacing and shadow.
|
|
165
|
+
*/ export function directivePaletteStyle(palette) {
|
|
166
|
+
const background = paletteColorValue(palette, 'background');
|
|
167
|
+
const accent = paletteColorValue(palette, 'accent');
|
|
168
|
+
return style([
|
|
169
|
+
[
|
|
170
|
+
'--pmd-surface',
|
|
171
|
+
background
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
'--pmd-surface-muted',
|
|
175
|
+
background
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
'--pmd-border',
|
|
179
|
+
paletteColorValue(palette, 'border')
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
'--pmd-accent',
|
|
183
|
+
accent
|
|
184
|
+
],
|
|
185
|
+
[
|
|
186
|
+
'--pmd-accent-hover',
|
|
187
|
+
accent
|
|
188
|
+
]
|
|
189
|
+
]);
|
|
190
|
+
}
|
|
191
|
+
/** Button colours from a palette: fill from `background`, label from `color`. */ export function buttonPaletteStyle(palette) {
|
|
192
|
+
const background = paletteColorValue(palette, 'background');
|
|
193
|
+
const border = paletteColorValue(palette, 'border') ?? background;
|
|
194
|
+
// Hover tints the fill toward the label colour, so it reads in both schemes.
|
|
195
|
+
const hover = background ? `color-mix(in oklab, ${background} 85%, currentColor)` : undefined;
|
|
196
|
+
return style([
|
|
197
|
+
[
|
|
198
|
+
'--pmd-button-bg',
|
|
199
|
+
background
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
'--pmd-button-border',
|
|
203
|
+
border
|
|
204
|
+
],
|
|
205
|
+
[
|
|
206
|
+
'--pmd-button-color',
|
|
207
|
+
paletteColorValue(palette, 'color')
|
|
208
|
+
],
|
|
209
|
+
[
|
|
210
|
+
'--pmd-button-hover-bg',
|
|
211
|
+
hover
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
'--pmd-button-hover-border',
|
|
215
|
+
border
|
|
216
|
+
]
|
|
217
|
+
]);
|
|
218
|
+
}
|
|
219
|
+
/** How an icon is painted with a palette. */ export function iconPaint(palette) {
|
|
220
|
+
return {
|
|
221
|
+
primary: paletteColorValue(palette, 'color'),
|
|
222
|
+
secondary: paletteColorValue(palette, 'secondaryColor'),
|
|
223
|
+
...palette.secondaryOpacity !== undefined ? {
|
|
224
|
+
secondaryOpacity: palette.secondaryOpacity
|
|
225
|
+
} : {}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** Plain, serializable view of a palette (for guides, editors and agents). */ export function describePalette(palette) {
|
|
229
|
+
return {
|
|
230
|
+
name: palette.name,
|
|
231
|
+
...palette.label ? {
|
|
232
|
+
label: palette.label
|
|
233
|
+
} : {},
|
|
234
|
+
...palette.light,
|
|
235
|
+
...Object.keys(palette.dark).length > 0 ? {
|
|
236
|
+
dark: {
|
|
237
|
+
...palette.dark
|
|
238
|
+
}
|
|
239
|
+
} : {},
|
|
240
|
+
...palette.secondaryOpacity !== undefined ? {
|
|
241
|
+
secondaryOpacity: palette.secondaryOpacity
|
|
242
|
+
} : {}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/palettes/index.ts"],"sourcesContent":["import type { MarkdownPalette, MarkdownPaletteColors, MarkdownPalettes } from '../types/core.js'\n\nimport { normalizePaletteColor, PALETTE_COLOR_FORMATS } from './colors.js'\nimport { DEFAULT_PALETTES } from './defaults.js'\n\nexport { DEFAULT_PALETTES } from './defaults.js'\n\n/** Palette names: what Markdown references, so they stay simple and stable. */\nexport const PALETTE_NAME_PATTERN = /^[a-z][\\da-z-]{0,47}$/\n\nconst COLOR_KEYS = ['accent', 'background', 'border', 'color', 'secondaryColor'] as const\n\ntype PaletteColorKey = (typeof COLOR_KEYS)[number]\n\n/** A palette whose every value has been validated and normalized. */\nexport type ResolvedPalette = {\n dark: MarkdownPaletteColors\n label?: string\n light: MarkdownPaletteColors\n name: string\n secondaryOpacity?: number\n}\n\nexport type PaletteValidation = {\n errors: string[]\n palette?: ResolvedPalette\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\n/** A value as shown in an error message. */\nfunction show(value: unknown): string {\n return typeof value === 'string' ? value : JSON.stringify(value)\n}\n\nfunction readColors(\n source: Record<string, unknown>,\n prefix: string,\n errors: string[],\n): MarkdownPaletteColors {\n const colors: MarkdownPaletteColors = {}\n\n for (const key of COLOR_KEYS) {\n const raw = source[key]\n if (raw === undefined || raw === null || raw === '') continue\n\n const color = normalizePaletteColor(raw)\n\n if (color) colors[key] = color\n else errors.push(`${prefix}${key} \"${show(raw)}\" is not a valid colour. Use ${PALETTE_COLOR_FORMATS}.`)\n }\n\n return colors\n}\n\n/**\n * Validates and normalizes a palette from any source (config, the admin\n * global, an MCP tool). Invalid colours are reported, never passed through.\n */\nexport function validatePalette(input: unknown): PaletteValidation {\n if (!isRecord(input)) return { errors: ['A palette must be an object with a \"name\".'] }\n\n const errors: string[] = []\n const name = typeof input.name === 'string' ? input.name.trim() : ''\n\n if (!PALETTE_NAME_PATTERN.test(name))\n errors.push(\n `Palette name \"${name}\" is invalid. Use 1–48 lowercase letters, digits and dashes, starting with a letter.`,\n )\n\n const light = readColors(input, '', errors)\n const dark = isRecord(input.dark) ? readColors(input.dark, 'dark.', errors) : {}\n\n let secondaryOpacity: number | undefined\n const rawOpacity = input.secondaryOpacity\n\n if (rawOpacity !== undefined && rawOpacity !== null && rawOpacity !== '') {\n const value = typeof rawOpacity === 'string' ? Number(rawOpacity) : rawOpacity\n\n if (typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1)\n secondaryOpacity = Math.round(value * 1000) / 1000\n else errors.push(`secondaryOpacity \"${show(rawOpacity)}\" must be a number from 0 to 1.`)\n }\n\n if (errors.length > 0) return { errors }\n\n const label = typeof input.label === 'string' && input.label.trim() ? input.label.trim() : undefined\n\n return {\n errors,\n palette: {\n name,\n dark,\n ...(label ? { label } : {}),\n light,\n ...(secondaryOpacity !== undefined ? { secondaryOpacity } : {}),\n },\n }\n}\n\nfunction normalizeGroup(palettes: MarkdownPalettes | undefined): {\n extendDefaults: boolean\n items: unknown[]\n} {\n if (!palettes) return { extendDefaults: true, items: [] }\n if (Array.isArray(palettes)) return { extendDefaults: true, items: palettes }\n\n return { extendDefaults: palettes.extendDefaults ?? true, items: palettes.items ?? [] }\n}\n\n/**\n * Combines palette layers, lowest precedence first (plugin, collection,\n * renderer, admin). Later layers replace palettes by name; a layer only\n * changes `extendDefaults` when it sets it explicitly.\n */\nexport function mergeMarkdownPalettes(\n ...layers: Array<MarkdownPalettes | undefined>\n): MarkdownPalettes | undefined {\n let extendDefaults: boolean | undefined\n const byName = new Map<string, MarkdownPalette>()\n let present = false\n\n for (const layer of layers) {\n if (!layer) continue\n present = true\n\n if (!Array.isArray(layer) && typeof layer.extendDefaults === 'boolean') extendDefaults = layer.extendDefaults\n\n for (const item of normalizeGroup(layer).items)\n if (isRecord(item) && typeof item.name === 'string') byName.set(item.name.trim(), item as MarkdownPalette)\n }\n\n if (!present) return undefined\n\n return {\n ...(extendDefaults !== undefined ? { extendDefaults } : {}),\n items: [...byName.values()],\n }\n}\n\nexport type PaletteRegistry = {\n get: (name: string) => ResolvedPalette | undefined\n names: () => string[]\n /** Problems with configured palettes (each invalid palette is skipped). */\n warnings: string[]\n}\n\nlet defaultPalettes: ResolvedPalette[] | undefined\n\n/** The built-in palettes, validated once per process. */\nfunction getDefaultPalettes(): ResolvedPalette[] {\n defaultPalettes ??= DEFAULT_PALETTES.flatMap((palette) => validatePalette(palette).palette ?? [])\n\n return defaultPalettes\n}\n\nfunction buildRegistry(palettes: MarkdownPalettes | undefined): PaletteRegistry {\n const group = normalizeGroup(palettes)\n const resolved = new Map<string, ResolvedPalette>()\n const warnings: string[] = []\n\n if (group.extendDefaults) for (const palette of getDefaultPalettes()) resolved.set(palette.name, palette)\n\n for (const item of group.items) {\n const { errors, palette } = validatePalette(item)\n const name = isRecord(item) && typeof item.name === 'string' ? item.name : '(unnamed)'\n\n if (palette) resolved.set(palette.name, palette)\n else warnings.push(`Palette \"${name}\" was ignored: ${errors.join(' ')}`)\n }\n\n return {\n get: (name) => resolved.get(name.trim()),\n names: () => [...resolved.keys()].sort(),\n warnings,\n }\n}\n\n/**\n * Registries by content: every render builds a fresh merged config object,\n * so caching by identity would never hit. Bounded, oldest entries first out.\n */\nconst registryCache = new Map<string, PaletteRegistry>()\nconst MAX_CACHED_REGISTRIES = 64\n\n/** The palettes a render can reference, by name. Cached by content. */\nexport function getPaletteRegistry(palettes: MarkdownPalettes | undefined): PaletteRegistry {\n const key = palettes ? JSON.stringify(palettes) : ''\n const cached = registryCache.get(key)\n if (cached) return cached\n\n const registry = buildRegistry(palettes)\n\n if (registryCache.size >= MAX_CACHED_REGISTRIES) registryCache.delete(registryCache.keys().next().value!)\n registryCache.set(key, registry)\n\n return registry\n}\n\n/**\n * The CSS value of one palette colour: the light value, or a mix that follows\n * `--pmd-scheme-dark` (1 = dark, 0 = light) when the dark value differs, the\n * same scheme switch the directive defaults use.\n */\nexport function paletteColorValue(palette: ResolvedPalette, key: PaletteColorKey): string | undefined {\n const light = palette.light[key]\n const dark = palette.dark[key] ?? light\n\n if (!light) return dark\n if (!dark || dark === light) return light\n\n return `color-mix(in oklab, ${dark} calc(var(--pmd-scheme-dark, 1) * 100%), ${light})`\n}\n\nfunction style(declarations: Array<[string, string | undefined]>): string | undefined {\n const parts = declarations.filter(([, value]) => value !== undefined).map(([name, value]) => `${name}:${value}`)\n\n return parts.length > 0 ? parts.join(';') : undefined\n}\n\n/**\n * Inline custom properties a directive gets from its palette. They are the\n * public tokens the default directive themes read first, so a palette\n * recolours a card or callout while its structural theme stays in charge of\n * shape, spacing and shadow.\n */\nexport function directivePaletteStyle(palette: ResolvedPalette): string | undefined {\n const background = paletteColorValue(palette, 'background')\n const accent = paletteColorValue(palette, 'accent')\n\n return style([\n ['--pmd-surface', background],\n ['--pmd-surface-muted', background],\n ['--pmd-border', paletteColorValue(palette, 'border')],\n ['--pmd-accent', accent],\n ['--pmd-accent-hover', accent],\n ])\n}\n\n/** Button colours from a palette: fill from `background`, label from `color`. */\nexport function buttonPaletteStyle(palette: ResolvedPalette): string | undefined {\n const background = paletteColorValue(palette, 'background')\n const border = paletteColorValue(palette, 'border') ?? background\n // Hover tints the fill toward the label colour, so it reads in both schemes.\n const hover = background ? `color-mix(in oklab, ${background} 85%, currentColor)` : undefined\n\n return style([\n ['--pmd-button-bg', background],\n ['--pmd-button-border', border],\n ['--pmd-button-color', paletteColorValue(palette, 'color')],\n ['--pmd-button-hover-bg', hover],\n ['--pmd-button-hover-border', border],\n ])\n}\n\nexport type IconPaint = {\n primary?: string\n secondary?: string\n secondaryOpacity?: number\n}\n\n/** How an icon is painted with a palette. */\nexport function iconPaint(palette: ResolvedPalette): IconPaint {\n return {\n primary: paletteColorValue(palette, 'color'),\n secondary: paletteColorValue(palette, 'secondaryColor'),\n ...(palette.secondaryOpacity !== undefined ? { secondaryOpacity: palette.secondaryOpacity } : {}),\n }\n}\n\n/** Plain, serializable view of a palette (for guides, editors and agents). */\nexport function describePalette(palette: ResolvedPalette): MarkdownPalette {\n return {\n name: palette.name,\n ...(palette.label ? { label: palette.label } : {}),\n ...palette.light,\n ...(Object.keys(palette.dark).length > 0 ? { dark: { ...palette.dark } } : {}),\n ...(palette.secondaryOpacity !== undefined ? { secondaryOpacity: palette.secondaryOpacity } : {}),\n }\n}\n"],"names":["normalizePaletteColor","PALETTE_COLOR_FORMATS","DEFAULT_PALETTES","PALETTE_NAME_PATTERN","COLOR_KEYS","isRecord","value","Boolean","Array","isArray","show","JSON","stringify","readColors","source","prefix","errors","colors","key","raw","undefined","color","push","validatePalette","input","name","trim","test","light","dark","secondaryOpacity","rawOpacity","Number","isFinite","Math","round","length","label","palette","normalizeGroup","palettes","extendDefaults","items","mergeMarkdownPalettes","layers","byName","Map","present","layer","item","set","values","defaultPalettes","getDefaultPalettes","flatMap","buildRegistry","group","resolved","warnings","join","get","names","keys","sort","registryCache","MAX_CACHED_REGISTRIES","getPaletteRegistry","cached","registry","size","delete","next","paletteColorValue","style","declarations","parts","filter","map","directivePaletteStyle","background","accent","buttonPaletteStyle","border","hover","iconPaint","primary","secondary","describePalette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,GAAG,IAAI;YAAEP,MAAM;gBAAE,GAAGS,QAAQT,IAAI;YAAC;QAAE,IAAI,CAAC,CAAC;QAC7E,GAAIS,QAAQR,gBAAgB,KAAKV,YAAY;YAAEU,kBAAkBQ,QAAQR,gBAAgB;QAAC,IAAI,CAAC,CAAC;IAClG;AACF"}
|
|
@@ -2,12 +2,14 @@ import type { RenderedMarkdown } from '../core/renderMarkdown.js';
|
|
|
2
2
|
import type { ResolveMarkdownRenderConfigOptions } from '../runtime/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Options for `renderMarkdown`: any render config (`code`, `themes`, `icons`,
|
|
5
|
-
* …) plus where plugin defaults come from.
|
|
5
|
+
* `palettes`, …) plus where plugin defaults come from.
|
|
6
6
|
*
|
|
7
7
|
* - `settings`: a settings object, a Payload config or a Payload instance.
|
|
8
8
|
* Wins over the process-wide registry that `payloadMarkdown()` fills.
|
|
9
9
|
* `false` renders with `config` only.
|
|
10
10
|
* - `scope` / `collectionSlug`: which plugin defaults apply (`field` by default).
|
|
11
|
+
* - `runtimePalettes`: palettes managed in the admin. Loaded automatically
|
|
12
|
+
* (cached) when `settings` is a Payload instance and `appearance` is enabled.
|
|
11
13
|
*/
|
|
12
14
|
export type RenderMarkdownConfig = ResolveMarkdownRenderConfigOptions;
|
|
13
15
|
/**
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import { loadAppearancePalettes } from '../appearance/runtime.js';
|
|
1
2
|
import { renderMarkdownDocument } from '../core/renderMarkdown.js';
|
|
2
3
|
import { resolveMarkdownRenderConfig } from '../runtime/index.js';
|
|
4
|
+
function canLoadPalettes(settings) {
|
|
5
|
+
return Boolean(settings) && typeof settings.findGlobal === 'function';
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Headless renderer: sanitized HTML plus diagnostics, headings, plain text
|
|
5
9
|
* and links. Produces the same HTML as `MarkdownRenderer` for the same
|
|
6
10
|
* markdown, settings, scope and collection.
|
|
7
11
|
*/ export async function renderMarkdown(markdown, config = {}) {
|
|
8
|
-
|
|
12
|
+
const runtimePalettes = config.runtimePalettes ?? (canLoadPalettes(config.settings) ? await loadAppearancePalettes(config.settings) : undefined);
|
|
13
|
+
return renderMarkdownDocument(markdown, resolveMarkdownRenderConfig({
|
|
14
|
+
...config,
|
|
15
|
+
runtimePalettes
|
|
16
|
+
}));
|
|
9
17
|
}
|
|
10
18
|
|
|
11
19
|
//# sourceMappingURL=renderMarkdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/render/renderMarkdown.ts"],"sourcesContent":["import type { RenderedMarkdown } from '../core/renderMarkdown.js'\nimport type { ResolveMarkdownRenderConfigOptions } from '../runtime/index.js'\n\nimport { renderMarkdownDocument } from '../core/renderMarkdown.js'\nimport { resolveMarkdownRenderConfig } from '../runtime/index.js'\n\n/**\n * Options for `renderMarkdown`: any render config (`code`, `themes`, `icons`,\n * …) plus where plugin defaults come from.\n *\n * - `settings`: a settings object, a Payload config or a Payload instance.\n * Wins over the process-wide registry that `payloadMarkdown()` fills.\n * `false` renders with `config` only.\n * - `scope` / `collectionSlug`: which plugin defaults apply (`field` by default).\n */\nexport type RenderMarkdownConfig = ResolveMarkdownRenderConfigOptions\n\n/**\n * Headless renderer: sanitized HTML plus diagnostics, headings, plain text\n * and links. Produces the same HTML as `MarkdownRenderer` for the same\n * markdown, settings, scope and collection.\n */\nexport async function renderMarkdown(\n markdown: string,\n config: RenderMarkdownConfig = {},\n): Promise<RenderedMarkdown> {\n return renderMarkdownDocument(markdown, resolveMarkdownRenderConfig(config))\n}\n"],"names":["renderMarkdownDocument","resolveMarkdownRenderConfig","renderMarkdown","markdown","config"],"mappings":"AAGA,SAASA,sBAAsB,QAAQ,4BAA2B;AAClE,SAASC,2BAA2B,QAAQ,sBAAqB;
|
|
1
|
+
{"version":3,"sources":["../../src/render/renderMarkdown.ts"],"sourcesContent":["import type { RenderedMarkdown } from '../core/renderMarkdown.js'\nimport type { ResolveMarkdownRenderConfigOptions } from '../runtime/index.js'\n\nimport { loadAppearancePalettes } from '../appearance/runtime.js'\nimport { renderMarkdownDocument } from '../core/renderMarkdown.js'\nimport { resolveMarkdownRenderConfig } from '../runtime/index.js'\n\n/**\n * Options for `renderMarkdown`: any render config (`code`, `themes`, `icons`,\n * `palettes`, …) plus where plugin defaults come from.\n *\n * - `settings`: a settings object, a Payload config or a Payload instance.\n * Wins over the process-wide registry that `payloadMarkdown()` fills.\n * `false` renders with `config` only.\n * - `scope` / `collectionSlug`: which plugin defaults apply (`field` by default).\n * - `runtimePalettes`: palettes managed in the admin. Loaded automatically\n * (cached) when `settings` is a Payload instance and `appearance` is enabled.\n */\nexport type RenderMarkdownConfig = ResolveMarkdownRenderConfigOptions\n\nfunction canLoadPalettes(settings: RenderMarkdownConfig['settings']): boolean {\n return Boolean(settings) && typeof (settings as { findGlobal?: unknown }).findGlobal === 'function'\n}\n\n/**\n * Headless renderer: sanitized HTML plus diagnostics, headings, plain text\n * and links. Produces the same HTML as `MarkdownRenderer` for the same\n * markdown, settings, scope and collection.\n */\nexport async function renderMarkdown(\n markdown: string,\n config: RenderMarkdownConfig = {},\n): Promise<RenderedMarkdown> {\n const runtimePalettes =\n config.runtimePalettes ?? (canLoadPalettes(config.settings) ? await loadAppearancePalettes(config.settings) : undefined)\n\n return renderMarkdownDocument(markdown, resolveMarkdownRenderConfig({ ...config, runtimePalettes }))\n}\n"],"names":["loadAppearancePalettes","renderMarkdownDocument","resolveMarkdownRenderConfig","canLoadPalettes","settings","Boolean","findGlobal","renderMarkdown","markdown","config","runtimePalettes","undefined"],"mappings":"AAGA,SAASA,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,sBAAsB,QAAQ,4BAA2B;AAClE,SAASC,2BAA2B,QAAQ,sBAAqB;AAejE,SAASC,gBAAgBC,QAA0C;IACjE,OAAOC,QAAQD,aAAa,OAAO,AAACA,SAAsCE,UAAU,KAAK;AAC3F;AAEA;;;;CAIC,GACD,OAAO,eAAeC,eACpBC,QAAgB,EAChBC,SAA+B,CAAC,CAAC;IAEjC,MAAMC,kBACJD,OAAOC,eAAe,IAAKP,CAAAA,gBAAgBM,OAAOL,QAAQ,IAAI,MAAMJ,uBAAuBS,OAAOL,QAAQ,IAAIO,SAAQ;IAExH,OAAOV,uBAAuBO,UAAUN,4BAA4B;QAAE,GAAGO,MAAM;QAAEC;IAAgB;AACnG"}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { ConfigOptions, DualMarkdownFieldConfig, PayloadMarkdownCollectionConfig, PayloadMarkdownConfig } from '../types.js';
|
|
2
|
-
import type { MarkdownCodeConfig, MarkdownConfig, MarkdownRenderConfig } from '../types/core.js';
|
|
2
|
+
import type { MarkdownCodeConfig, MarkdownConfig, MarkdownPalette, MarkdownRenderConfig } from '../types/core.js';
|
|
3
3
|
export type PayloadMarkdownResolvedSettings = {
|
|
4
|
+
/** Slug of the "Markdown Appearance" global when `appearance` is enabled. */
|
|
5
|
+
appearanceSlug?: string;
|
|
4
6
|
code?: MarkdownCodeConfig;
|
|
5
7
|
/** Render-relevant collection settings (`code`, `config`, `themes`), or `true`. */
|
|
6
8
|
collections: Partial<Record<string, PayloadMarkdownCollectionConfig | true>>;
|
|
7
9
|
config?: ConfigOptions;
|
|
8
10
|
enabled: boolean;
|
|
9
11
|
icons?: MarkdownRenderConfig['icons'];
|
|
12
|
+
palettes?: MarkdownRenderConfig['palettes'];
|
|
10
13
|
themes?: MarkdownRenderConfig['themes'];
|
|
11
14
|
/** Version of the package copy that created these settings. */
|
|
12
15
|
version?: string;
|
|
@@ -21,6 +24,8 @@ export declare const PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY = "payloadMarkdown";
|
|
|
21
24
|
* detected as duplicate copies too.
|
|
22
25
|
*/
|
|
23
26
|
export declare const PAYLOAD_MARKDOWN_SETTINGS_REGISTRY_KEY: unique symbol;
|
|
27
|
+
/** Process-wide key of the appearance (runtime palettes) cache; shared by every copy like the settings key. */
|
|
28
|
+
export declare const PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY: unique symbol;
|
|
24
29
|
/**
|
|
25
30
|
* Builds the frozen, render-only settings snapshot for plugin options. Field
|
|
26
31
|
* installation options (field, fieldName, installField, installIntoBlocks)
|
|
@@ -86,6 +91,12 @@ export type ResolveMarkdownRenderConfigOptions = {
|
|
|
86
91
|
collectionSlug?: string;
|
|
87
92
|
/** Highest-precedence layer (see `applyMarkdownOverrides`). */
|
|
88
93
|
overrides?: MarkdownRenderConfig;
|
|
94
|
+
/**
|
|
95
|
+
* Palettes managed at runtime (the "Markdown Appearance" global). They
|
|
96
|
+
* override the plugin and collection palettes by name; palettes passed to
|
|
97
|
+
* the render itself still win.
|
|
98
|
+
*/
|
|
99
|
+
runtimePalettes?: MarkdownPalette[];
|
|
89
100
|
scope?: 'blocks' | 'field';
|
|
90
101
|
/** Explicit settings source; wins over the process registry. `false` ignores plugin settings. */
|
|
91
102
|
settings?: false | null | PayloadMarkdownSettingsSource;
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { resolveAppearanceOptions } from '../appearance/options.js';
|
|
1
2
|
import { mergeCodeConfigFromRenderConfigs } from '../core/codeConfig.js';
|
|
2
3
|
import { mergeMarkdownDirectiveThemes } from '../directives/themes.js';
|
|
4
|
+
import { mergeMarkdownPalettes } from '../palettes/index.js';
|
|
3
5
|
import { PAYLOAD_MARKDOWN_VERSION } from '../version.js';
|
|
4
6
|
/** Key of the plugin's settings on the Payload config's server-only `custom`. */ export const PAYLOAD_MARKDOWN_CONFIG_CUSTOM_KEY = 'payloadMarkdown';
|
|
5
7
|
/**
|
|
@@ -9,6 +11,7 @@ import { PAYLOAD_MARKDOWN_VERSION } from '../version.js';
|
|
|
9
11
|
* the same under both package names (scoped and unscoped), so mixing them is
|
|
10
12
|
* detected as duplicate copies too.
|
|
11
13
|
*/ export const PAYLOAD_MARKDOWN_SETTINGS_REGISTRY_KEY = Symbol.for('@valkyrianlabs/payload-markdown/settings');
|
|
14
|
+
/** Process-wide key of the appearance (runtime palettes) cache; shared by every copy like the settings key. */ export const PAYLOAD_MARKDOWN_APPEARANCE_RUNTIME_KEY = Symbol.for('@valkyrianlabs/payload-markdown/appearance');
|
|
12
15
|
function warnAboutDuplicateCopies(registry) {
|
|
13
16
|
if (registry.warned || registry.versions.length < 2) return;
|
|
14
17
|
registry.warned = true;
|
|
@@ -63,6 +66,9 @@ function pickCollectionRenderSettings(collections) {
|
|
|
63
66
|
...entry.config !== undefined ? {
|
|
64
67
|
config: entry.config
|
|
65
68
|
} : {},
|
|
69
|
+
...entry.palettes !== undefined ? {
|
|
70
|
+
palettes: entry.palettes
|
|
71
|
+
} : {},
|
|
66
72
|
...entry.themes !== undefined ? {
|
|
67
73
|
themes: entry.themes
|
|
68
74
|
} : {}
|
|
@@ -76,11 +82,13 @@ function pickCollectionRenderSettings(collections) {
|
|
|
76
82
|
* are not part of it; they only matter while the config is built.
|
|
77
83
|
*/ export function createPayloadMarkdownSettings(pluginOptions = {}) {
|
|
78
84
|
return freezeCopy({
|
|
85
|
+
appearanceSlug: resolveAppearanceOptions(pluginOptions.appearance)?.slug,
|
|
79
86
|
code: pluginOptions.code,
|
|
80
87
|
collections: pickCollectionRenderSettings(pluginOptions.collections),
|
|
81
88
|
config: pluginOptions.config,
|
|
82
89
|
enabled: pluginOptions.enabled !== false,
|
|
83
90
|
icons: pluginOptions.icons,
|
|
91
|
+
palettes: pluginOptions.palettes,
|
|
84
92
|
themes: pluginOptions.themes,
|
|
85
93
|
version: PAYLOAD_MARKDOWN_VERSION
|
|
86
94
|
});
|
|
@@ -163,6 +171,7 @@ export function mergeMarkdownConfigs(...configs) {
|
|
|
163
171
|
if (config.lead !== undefined) merged.lead = config.lead;
|
|
164
172
|
if (config.fullBleedCode !== undefined) merged.fullBleedCode = config.fullBleedCode;
|
|
165
173
|
if (config.mutedHeadings !== undefined) merged.mutedHeadings = config.mutedHeadings;
|
|
174
|
+
if (config.colorScheme !== undefined) merged.colorScheme = config.colorScheme;
|
|
166
175
|
if (config.enableGutter !== undefined) merged.enableGutter = config.enableGutter;
|
|
167
176
|
if (config.options) {
|
|
168
177
|
merged.options = {
|
|
@@ -178,8 +187,9 @@ export function mergeMarkdownRenderConfigs(...configs) {
|
|
|
178
187
|
const code = mergeCodeConfigFromRenderConfigs(...configs);
|
|
179
188
|
let icons;
|
|
180
189
|
const themes = mergeMarkdownDirectiveThemes(...configs.map((config)=>config?.themes));
|
|
190
|
+
const palettes = mergeMarkdownPalettes(...configs.map((config)=>config?.palettes));
|
|
181
191
|
for (const config of configs)if (config?.icons !== undefined) icons = config.icons;
|
|
182
|
-
if (!merged && !code && !icons && !themes) return undefined;
|
|
192
|
+
if (!merged && !code && !icons && !themes && !palettes) return undefined;
|
|
183
193
|
return {
|
|
184
194
|
...merged ?? {},
|
|
185
195
|
...code ? {
|
|
@@ -188,6 +198,9 @@ export function mergeMarkdownRenderConfigs(...configs) {
|
|
|
188
198
|
...icons ? {
|
|
189
199
|
icons
|
|
190
200
|
} : {},
|
|
201
|
+
...palettes ? {
|
|
202
|
+
palettes
|
|
203
|
+
} : {},
|
|
191
204
|
...themes ? {
|
|
192
205
|
themes
|
|
193
206
|
} : {}
|
|
@@ -200,6 +213,7 @@ export function resolveGlobalMarkdownConfigs(settings = maybeGetPayloadMarkdownS
|
|
|
200
213
|
const shared = {
|
|
201
214
|
code: current.code,
|
|
202
215
|
icons: current.icons,
|
|
216
|
+
palettes: current.palettes,
|
|
203
217
|
themes: current.themes
|
|
204
218
|
};
|
|
205
219
|
return {
|
|
@@ -219,6 +233,7 @@ export function resolveCollectionMarkdownConfigs(collectionSlug, settings = mayb
|
|
|
219
233
|
const collectionResolved = resolveConfigOptions(collectionEntry.config);
|
|
220
234
|
const shared = {
|
|
221
235
|
code: collectionEntry.code,
|
|
236
|
+
palettes: collectionEntry.palettes,
|
|
222
237
|
themes: collectionEntry.themes
|
|
223
238
|
};
|
|
224
239
|
return {
|
|
@@ -257,6 +272,7 @@ const OVERRIDE_CLASS_KEYS = [
|
|
|
257
272
|
if (overrides.size !== undefined) next.size = overrides.size;
|
|
258
273
|
if (overrides.enableGutter !== undefined) next.enableGutter = overrides.enableGutter;
|
|
259
274
|
if (overrides.mutedHeadings !== undefined) next.mutedHeadings = overrides.mutedHeadings;
|
|
275
|
+
if (overrides.colorScheme !== undefined) next.colorScheme = overrides.colorScheme;
|
|
260
276
|
if (overrides.fullBleedCode !== undefined) next.fullBleedCode = overrides.fullBleedCode;
|
|
261
277
|
// Code options: fold the inherited legacy `options.*` and `code` together,
|
|
262
278
|
// then apply the override's keys on top, so `code` (which wins over legacy
|
|
@@ -266,6 +282,8 @@ const OVERRIDE_CLASS_KEYS = [
|
|
|
266
282
|
if (overrides.icons !== undefined) next.icons = overrides.icons;
|
|
267
283
|
const themes = mergeMarkdownDirectiveThemes(base?.themes, overrides.themes);
|
|
268
284
|
if (themes) next.themes = themes;
|
|
285
|
+
const palettes = mergeMarkdownPalettes(base?.palettes, overrides.palettes);
|
|
286
|
+
if (palettes) next.palettes = palettes;
|
|
269
287
|
return next;
|
|
270
288
|
}
|
|
271
289
|
/**
|
|
@@ -275,7 +293,10 @@ const OVERRIDE_CLASS_KEYS = [
|
|
|
275
293
|
*/ export function resolveMarkdownRenderConfig(options) {
|
|
276
294
|
const settings = resolvePayloadMarkdownSettings(options.settings);
|
|
277
295
|
const defaults = options.scope === 'blocks' ? resolveMarkdownBlockDefaults(options.collectionSlug, settings) : resolveMarkdownFieldDefaults(options.collectionSlug, settings);
|
|
278
|
-
const
|
|
296
|
+
const runtime = options.runtimePalettes && options.runtimePalettes.length > 0 ? {
|
|
297
|
+
palettes: options.runtimePalettes
|
|
298
|
+
} : undefined;
|
|
299
|
+
const merged = mergeMarkdownRenderConfigs(defaults, runtime, options) ?? options;
|
|
279
300
|
return applyMarkdownOverrides(merged, options.overrides) ?? merged;
|
|
280
301
|
}
|
|
281
302
|
|