payload-markdown 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/agent/access.d.ts +1 -1
- package/dist/agent/access.js.map +1 -1
- package/dist/agent/guide.d.ts +3 -0
- package/dist/agent/guide.js +28 -2
- package/dist/agent/guide.js.map +1 -1
- package/dist/agent/palettes.d.ts +55 -0
- package/dist/agent/palettes.js +194 -0
- package/dist/agent/palettes.js.map +1 -0
- package/dist/agent/skill.d.ts +2 -2
- package/dist/agent/skill.js +2 -2
- package/dist/agent/skill.js.map +1 -1
- package/dist/agent/validate.d.ts +1 -1
- package/dist/agent/validate.js +3 -0
- package/dist/agent/validate.js.map +1 -1
- package/dist/appearance/PaletteRowLabel.client.d.ts +2 -0
- package/dist/appearance/PaletteRowLabel.client.js +70 -0
- package/dist/appearance/PaletteRowLabel.client.js.map +1 -0
- package/dist/appearance/config.d.ts +8 -0
- package/dist/appearance/config.js +172 -0
- package/dist/appearance/config.js.map +1 -0
- package/dist/appearance/options.d.ts +11 -0
- package/dist/appearance/options.js +15 -0
- package/dist/appearance/options.js.map +1 -0
- package/dist/appearance/runtime.d.ts +25 -0
- package/dist/appearance/runtime.js +126 -0
- package/dist/appearance/runtime.js.map +1 -0
- package/dist/components/MarkdownRenderer/Component.js +4 -0
- package/dist/components/MarkdownRenderer/Component.js.map +1 -1
- package/dist/core/plugins/directiveButton.d.ts +1 -1
- package/dist/core/plugins/directiveButton.js +27 -10
- package/dist/core/plugins/directiveButton.js.map +1 -1
- package/dist/core/plugins/rehypeResolveIcons.js +10 -1
- package/dist/core/plugins/rehypeResolveIcons.js.map +1 -1
- package/dist/core/plugins/remarkValidatePalettes.d.ts +9 -0
- package/dist/core/plugins/remarkValidatePalettes.js +51 -0
- package/dist/core/plugins/remarkValidatePalettes.js.map +1 -0
- package/dist/core/renderMarkdown.js +13 -1
- package/dist/core/renderMarkdown.js.map +1 -1
- package/dist/directive-spec.json +60 -0
- package/dist/directives/definitions/button.d.ts +1 -1
- package/dist/directives/definitions/button.js +9 -2
- package/dist/directives/definitions/button.js.map +1 -1
- package/dist/directives/definitions/callout.js +9 -2
- package/dist/directives/definitions/callout.js.map +1 -1
- package/dist/directives/definitions/card.d.ts +0 -2
- package/dist/directives/definitions/card.js +13 -8
- package/dist/directives/definitions/card.js.map +1 -1
- package/dist/directives/definitions/cards.js +9 -0
- package/dist/directives/definitions/cards.js.map +1 -1
- package/dist/directives/definitions/details.js +4 -0
- package/dist/directives/definitions/details.js.map +1 -1
- package/dist/directives/definitions/section.js +4 -0
- package/dist/directives/definitions/section.js.map +1 -1
- package/dist/directives/definitions/steps.js +4 -0
- package/dist/directives/definitions/steps.js.map +1 -1
- package/dist/directives/definitions/tabs.js +4 -0
- package/dist/directives/definitions/tabs.js.map +1 -1
- package/dist/directives/definitions/toc.js +1 -1
- package/dist/directives/definitions/toc.js.map +1 -1
- package/dist/directives/diagnostics.d.ts +5 -0
- package/dist/directives/diagnostics.js +26 -10
- package/dist/directives/diagnostics.js.map +1 -1
- package/dist/directives/iconPlaceholder.d.ts +9 -3
- package/dist/directives/iconPlaceholder.js +8 -1
- package/dist/directives/iconPlaceholder.js.map +1 -1
- package/dist/directives/palette.d.ts +23 -0
- package/dist/directives/palette.js +40 -0
- package/dist/directives/palette.js.map +1 -0
- package/dist/directives/spec.d.ts +6 -2
- package/dist/directives/spec.js +5 -0
- package/dist/directives/spec.js.map +1 -1
- package/dist/editor/directiveConfig.d.ts +15 -1
- package/dist/editor/directiveConfig.js +21 -1
- package/dist/editor/directiveConfig.js.map +1 -1
- package/dist/editor/directives/completions.d.ts +4 -2
- package/dist/editor/directives/completions.js +22 -3
- package/dist/editor/directives/completions.js.map +1 -1
- package/dist/editor/directives/diagnostics.d.ts +2 -2
- package/dist/editor/directives/diagnostics.js +10 -3
- package/dist/editor/directives/diagnostics.js.map +1 -1
- package/dist/exports/client.d.ts +4 -1
- package/dist/exports/client.js +5 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/field/MarkdownField/Component.js +54 -3
- package/dist/field/MarkdownField/Component.js.map +1 -1
- package/dist/icons/entries.d.ts +22 -0
- package/dist/icons/entries.js +50 -0
- package/dist/icons/entries.js.map +1 -0
- package/dist/icons/resolve.d.ts +2 -1
- package/dist/icons/resolve.js +2 -2
- package/dist/icons/resolve.js.map +1 -1
- package/dist/icons/sanitizeSvg.d.ts +12 -2
- package/dist/icons/sanitizeSvg.js +104 -3
- package/dist/icons/sanitizeSvg.js.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +65 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/palettes/colors.d.ts +21 -0
- package/dist/palettes/colors.js +43 -0
- package/dist/palettes/colors.js.map +1 -0
- package/dist/palettes/contrast.d.ts +7 -0
- package/dist/palettes/contrast.js +63 -0
- package/dist/palettes/contrast.js.map +1 -0
- package/dist/palettes/defaults.d.ts +8 -0
- package/dist/palettes/defaults.js +275 -0
- package/dist/palettes/defaults.js.map +1 -0
- package/dist/palettes/diagnostics.d.ts +10 -0
- package/dist/palettes/diagnostics.js +38 -0
- package/dist/palettes/diagnostics.js.map +1 -0
- package/dist/palettes/index.d.ts +61 -0
- package/dist/palettes/index.js +246 -0
- package/dist/palettes/index.js.map +1 -0
- package/dist/render/renderMarkdown.d.ts +3 -1
- package/dist/render/renderMarkdown.js +9 -1
- package/dist/render/renderMarkdown.js.map +1 -1
- package/dist/runtime/index.d.ts +12 -1
- package/dist/runtime/index.js +21 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/types/core.d.ts +43 -0
- package/dist/types/core.js.map +1 -1
- package/dist/types.d.ts +46 -2
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/skills/payload-markdown/claude/SKILL.md +1 -0
- package/skills/payload-markdown/claude/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/claude/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/claude/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/claude/skill.json +2 -2
- package/skills/payload-markdown/codex/SKILL.md +1 -0
- package/skills/payload-markdown/codex/reference/directive-spec.json +60 -0
- package/skills/payload-markdown/codex/reference/mcp-content-workflow.md +7 -0
- package/skills/payload-markdown/codex/reference/payload-markdown-directives.md +22 -2
- package/skills/payload-markdown/codex/skill.json +2 -2
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in palettes: one per Tailwind hue, tuned for both colour schemes (icons
|
|
3
|
+
* use the 600 shade on light surfaces and 400 on dark ones; accents 700/300;
|
|
4
|
+
* surfaces a soft tint). Configured and admin palettes with the same name
|
|
5
|
+
* replace them; `palettes: { extendDefaults: false }` drops them.
|
|
6
|
+
*/ export const DEFAULT_PALETTES = Object.freeze([
|
|
7
|
+
{
|
|
8
|
+
name: 'red',
|
|
9
|
+
accent: '#b91c1c',
|
|
10
|
+
background: '#fef2f2',
|
|
11
|
+
border: '#fecaca',
|
|
12
|
+
color: '#dc2626',
|
|
13
|
+
dark: {
|
|
14
|
+
accent: '#fca5a5',
|
|
15
|
+
background: '#450a0a66',
|
|
16
|
+
border: '#f8717140',
|
|
17
|
+
color: '#f87171'
|
|
18
|
+
},
|
|
19
|
+
label: 'Red'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'orange',
|
|
23
|
+
accent: '#c2410c',
|
|
24
|
+
background: '#fff7ed',
|
|
25
|
+
border: '#fed7aa',
|
|
26
|
+
color: '#ea580c',
|
|
27
|
+
dark: {
|
|
28
|
+
accent: '#fdba74',
|
|
29
|
+
background: '#43140766',
|
|
30
|
+
border: '#fb923c40',
|
|
31
|
+
color: '#fb923c'
|
|
32
|
+
},
|
|
33
|
+
label: 'Orange'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'amber',
|
|
37
|
+
accent: '#b45309',
|
|
38
|
+
background: '#fffbeb',
|
|
39
|
+
border: '#fde68a',
|
|
40
|
+
color: '#d97706',
|
|
41
|
+
dark: {
|
|
42
|
+
accent: '#fcd34d',
|
|
43
|
+
background: '#451a0366',
|
|
44
|
+
border: '#fbbf2440',
|
|
45
|
+
color: '#fbbf24'
|
|
46
|
+
},
|
|
47
|
+
label: 'Amber'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'yellow',
|
|
51
|
+
accent: '#a16207',
|
|
52
|
+
background: '#fefce8',
|
|
53
|
+
border: '#fef08a',
|
|
54
|
+
color: '#ca8a04',
|
|
55
|
+
dark: {
|
|
56
|
+
accent: '#fde047',
|
|
57
|
+
background: '#42200666',
|
|
58
|
+
border: '#facc1540',
|
|
59
|
+
color: '#facc15'
|
|
60
|
+
},
|
|
61
|
+
label: 'Yellow'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'lime',
|
|
65
|
+
accent: '#4d7c0f',
|
|
66
|
+
background: '#f7fee7',
|
|
67
|
+
border: '#d9f99d',
|
|
68
|
+
color: '#65a30d',
|
|
69
|
+
dark: {
|
|
70
|
+
accent: '#bef264',
|
|
71
|
+
background: '#1a2e0566',
|
|
72
|
+
border: '#a3e63540',
|
|
73
|
+
color: '#a3e635'
|
|
74
|
+
},
|
|
75
|
+
label: 'Lime'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'green',
|
|
79
|
+
accent: '#15803d',
|
|
80
|
+
background: '#f0fdf4',
|
|
81
|
+
border: '#bbf7d0',
|
|
82
|
+
color: '#16a34a',
|
|
83
|
+
dark: {
|
|
84
|
+
accent: '#86efac',
|
|
85
|
+
background: '#052e1666',
|
|
86
|
+
border: '#4ade8040',
|
|
87
|
+
color: '#4ade80'
|
|
88
|
+
},
|
|
89
|
+
label: 'Green'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'emerald',
|
|
93
|
+
accent: '#047857',
|
|
94
|
+
background: '#ecfdf5',
|
|
95
|
+
border: '#a7f3d0',
|
|
96
|
+
color: '#059669',
|
|
97
|
+
dark: {
|
|
98
|
+
accent: '#6ee7b7',
|
|
99
|
+
background: '#022c2266',
|
|
100
|
+
border: '#34d39940',
|
|
101
|
+
color: '#34d399'
|
|
102
|
+
},
|
|
103
|
+
label: 'Emerald'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'teal',
|
|
107
|
+
accent: '#0f766e',
|
|
108
|
+
background: '#f0fdfa',
|
|
109
|
+
border: '#99f6e4',
|
|
110
|
+
color: '#0d9488',
|
|
111
|
+
dark: {
|
|
112
|
+
accent: '#5eead4',
|
|
113
|
+
background: '#042f2e66',
|
|
114
|
+
border: '#2dd4bf40',
|
|
115
|
+
color: '#2dd4bf'
|
|
116
|
+
},
|
|
117
|
+
label: 'Teal'
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'cyan',
|
|
121
|
+
accent: '#0e7490',
|
|
122
|
+
background: '#ecfeff',
|
|
123
|
+
border: '#a5f3fc',
|
|
124
|
+
color: '#0891b2',
|
|
125
|
+
dark: {
|
|
126
|
+
accent: '#67e8f9',
|
|
127
|
+
background: '#08334466',
|
|
128
|
+
border: '#22d3ee40',
|
|
129
|
+
color: '#22d3ee'
|
|
130
|
+
},
|
|
131
|
+
label: 'Cyan'
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'sky',
|
|
135
|
+
accent: '#0369a1',
|
|
136
|
+
background: '#f0f9ff',
|
|
137
|
+
border: '#bae6fd',
|
|
138
|
+
color: '#0284c7',
|
|
139
|
+
dark: {
|
|
140
|
+
accent: '#7dd3fc',
|
|
141
|
+
background: '#082f4966',
|
|
142
|
+
border: '#38bdf840',
|
|
143
|
+
color: '#38bdf8'
|
|
144
|
+
},
|
|
145
|
+
label: 'Sky'
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'blue',
|
|
149
|
+
accent: '#1d4ed8',
|
|
150
|
+
background: '#eff6ff',
|
|
151
|
+
border: '#bfdbfe',
|
|
152
|
+
color: '#2563eb',
|
|
153
|
+
dark: {
|
|
154
|
+
accent: '#93c5fd',
|
|
155
|
+
background: '#17255466',
|
|
156
|
+
border: '#60a5fa40',
|
|
157
|
+
color: '#60a5fa'
|
|
158
|
+
},
|
|
159
|
+
label: 'Blue'
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'indigo',
|
|
163
|
+
accent: '#4338ca',
|
|
164
|
+
background: '#eef2ff',
|
|
165
|
+
border: '#c7d2fe',
|
|
166
|
+
color: '#4f46e5',
|
|
167
|
+
dark: {
|
|
168
|
+
accent: '#a5b4fc',
|
|
169
|
+
background: '#1e1b4b66',
|
|
170
|
+
border: '#818cf840',
|
|
171
|
+
color: '#818cf8'
|
|
172
|
+
},
|
|
173
|
+
label: 'Indigo'
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'violet',
|
|
177
|
+
accent: '#6d28d9',
|
|
178
|
+
background: '#f5f3ff',
|
|
179
|
+
border: '#ddd6fe',
|
|
180
|
+
color: '#7c3aed',
|
|
181
|
+
dark: {
|
|
182
|
+
accent: '#c4b5fd',
|
|
183
|
+
background: '#2e106566',
|
|
184
|
+
border: '#a78bfa40',
|
|
185
|
+
color: '#a78bfa'
|
|
186
|
+
},
|
|
187
|
+
label: 'Violet'
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: 'purple',
|
|
191
|
+
accent: '#7e22ce',
|
|
192
|
+
background: '#faf5ff',
|
|
193
|
+
border: '#e9d5ff',
|
|
194
|
+
color: '#9333ea',
|
|
195
|
+
dark: {
|
|
196
|
+
accent: '#d8b4fe',
|
|
197
|
+
background: '#3b076466',
|
|
198
|
+
border: '#c084fc40',
|
|
199
|
+
color: '#c084fc'
|
|
200
|
+
},
|
|
201
|
+
label: 'Purple'
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: 'fuchsia',
|
|
205
|
+
accent: '#a21caf',
|
|
206
|
+
background: '#fdf4ff',
|
|
207
|
+
border: '#f5d0fe',
|
|
208
|
+
color: '#c026d3',
|
|
209
|
+
dark: {
|
|
210
|
+
accent: '#f0abfc',
|
|
211
|
+
background: '#4a044e66',
|
|
212
|
+
border: '#e879f940',
|
|
213
|
+
color: '#e879f9'
|
|
214
|
+
},
|
|
215
|
+
label: 'Fuchsia'
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: 'pink',
|
|
219
|
+
accent: '#be185d',
|
|
220
|
+
background: '#fdf2f8',
|
|
221
|
+
border: '#fbcfe8',
|
|
222
|
+
color: '#db2777',
|
|
223
|
+
dark: {
|
|
224
|
+
accent: '#f9a8d4',
|
|
225
|
+
background: '#50072466',
|
|
226
|
+
border: '#f472b640',
|
|
227
|
+
color: '#f472b6'
|
|
228
|
+
},
|
|
229
|
+
label: 'Pink'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'rose',
|
|
233
|
+
accent: '#be123c',
|
|
234
|
+
background: '#fff1f2',
|
|
235
|
+
border: '#fecdd3',
|
|
236
|
+
color: '#e11d48',
|
|
237
|
+
dark: {
|
|
238
|
+
accent: '#fda4af',
|
|
239
|
+
background: '#4c051966',
|
|
240
|
+
border: '#fb718540',
|
|
241
|
+
color: '#fb7185'
|
|
242
|
+
},
|
|
243
|
+
label: 'Rose'
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: 'slate',
|
|
247
|
+
accent: '#334155',
|
|
248
|
+
background: '#f8fafc',
|
|
249
|
+
border: '#e2e8f0',
|
|
250
|
+
color: '#475569',
|
|
251
|
+
dark: {
|
|
252
|
+
accent: '#cbd5e1',
|
|
253
|
+
background: '#02061766',
|
|
254
|
+
border: '#94a3b840',
|
|
255
|
+
color: '#94a3b8'
|
|
256
|
+
},
|
|
257
|
+
label: 'Slate'
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: 'neutral',
|
|
261
|
+
accent: '#404040',
|
|
262
|
+
background: '#fafafa',
|
|
263
|
+
border: '#e5e5e5',
|
|
264
|
+
color: '#525252',
|
|
265
|
+
dark: {
|
|
266
|
+
accent: '#d4d4d4',
|
|
267
|
+
background: '#0a0a0a66',
|
|
268
|
+
border: '#a3a3a340',
|
|
269
|
+
color: '#a3a3a3'
|
|
270
|
+
},
|
|
271
|
+
label: 'Neutral'
|
|
272
|
+
}
|
|
273
|
+
]);
|
|
274
|
+
|
|
275
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/palettes/defaults.ts"],"sourcesContent":["import type { MarkdownPalette } from '../types/core.js'\n\n/**\n * Built-in palettes: one per Tailwind hue, tuned for both colour schemes (icons\n * use the 600 shade on light surfaces and 400 on dark ones; accents 700/300;\n * surfaces a soft tint). Configured and admin palettes with the same name\n * replace them; `palettes: { extendDefaults: false }` drops them.\n */\nexport const DEFAULT_PALETTES: readonly MarkdownPalette[] = Object.freeze([\n {\n name: 'red',\n accent: '#b91c1c',\n background: '#fef2f2',\n border: '#fecaca',\n color: '#dc2626',\n dark: { accent: '#fca5a5', background: '#450a0a66', border: '#f8717140', color: '#f87171' },\n label: 'Red',\n },\n {\n name: 'orange',\n accent: '#c2410c',\n background: '#fff7ed',\n border: '#fed7aa',\n color: '#ea580c',\n dark: { accent: '#fdba74', background: '#43140766', border: '#fb923c40', color: '#fb923c' },\n label: 'Orange',\n },\n {\n name: 'amber',\n accent: '#b45309',\n background: '#fffbeb',\n border: '#fde68a',\n color: '#d97706',\n dark: { accent: '#fcd34d', background: '#451a0366', border: '#fbbf2440', color: '#fbbf24' },\n label: 'Amber',\n },\n {\n name: 'yellow',\n accent: '#a16207',\n background: '#fefce8',\n border: '#fef08a',\n color: '#ca8a04',\n dark: { accent: '#fde047', background: '#42200666', border: '#facc1540', color: '#facc15' },\n label: 'Yellow',\n },\n {\n name: 'lime',\n accent: '#4d7c0f',\n background: '#f7fee7',\n border: '#d9f99d',\n color: '#65a30d',\n dark: { accent: '#bef264', background: '#1a2e0566', border: '#a3e63540', color: '#a3e635' },\n label: 'Lime',\n },\n {\n name: 'green',\n accent: '#15803d',\n background: '#f0fdf4',\n border: '#bbf7d0',\n color: '#16a34a',\n dark: { accent: '#86efac', background: '#052e1666', border: '#4ade8040', color: '#4ade80' },\n label: 'Green',\n },\n {\n name: 'emerald',\n accent: '#047857',\n background: '#ecfdf5',\n border: '#a7f3d0',\n color: '#059669',\n dark: { accent: '#6ee7b7', background: '#022c2266', border: '#34d39940', color: '#34d399' },\n label: 'Emerald',\n },\n {\n name: 'teal',\n accent: '#0f766e',\n background: '#f0fdfa',\n border: '#99f6e4',\n color: '#0d9488',\n dark: { accent: '#5eead4', background: '#042f2e66', border: '#2dd4bf40', color: '#2dd4bf' },\n label: 'Teal',\n },\n {\n name: 'cyan',\n accent: '#0e7490',\n background: '#ecfeff',\n border: '#a5f3fc',\n color: '#0891b2',\n dark: { accent: '#67e8f9', background: '#08334466', border: '#22d3ee40', color: '#22d3ee' },\n label: 'Cyan',\n },\n {\n name: 'sky',\n accent: '#0369a1',\n background: '#f0f9ff',\n border: '#bae6fd',\n color: '#0284c7',\n dark: { accent: '#7dd3fc', background: '#082f4966', border: '#38bdf840', color: '#38bdf8' },\n label: 'Sky',\n },\n {\n name: 'blue',\n accent: '#1d4ed8',\n background: '#eff6ff',\n border: '#bfdbfe',\n color: '#2563eb',\n dark: { accent: '#93c5fd', background: '#17255466', border: '#60a5fa40', color: '#60a5fa' },\n label: 'Blue',\n },\n {\n name: 'indigo',\n accent: '#4338ca',\n background: '#eef2ff',\n border: '#c7d2fe',\n color: '#4f46e5',\n dark: { accent: '#a5b4fc', background: '#1e1b4b66', border: '#818cf840', color: '#818cf8' },\n label: 'Indigo',\n },\n {\n name: 'violet',\n accent: '#6d28d9',\n background: '#f5f3ff',\n border: '#ddd6fe',\n color: '#7c3aed',\n dark: { accent: '#c4b5fd', background: '#2e106566', border: '#a78bfa40', color: '#a78bfa' },\n label: 'Violet',\n },\n {\n name: 'purple',\n accent: '#7e22ce',\n background: '#faf5ff',\n border: '#e9d5ff',\n color: '#9333ea',\n dark: { accent: '#d8b4fe', background: '#3b076466', border: '#c084fc40', color: '#c084fc' },\n label: 'Purple',\n },\n {\n name: 'fuchsia',\n accent: '#a21caf',\n background: '#fdf4ff',\n border: '#f5d0fe',\n color: '#c026d3',\n dark: { accent: '#f0abfc', background: '#4a044e66', border: '#e879f940', color: '#e879f9' },\n label: 'Fuchsia',\n },\n {\n name: 'pink',\n accent: '#be185d',\n background: '#fdf2f8',\n border: '#fbcfe8',\n color: '#db2777',\n dark: { accent: '#f9a8d4', background: '#50072466', border: '#f472b640', color: '#f472b6' },\n label: 'Pink',\n },\n {\n name: 'rose',\n accent: '#be123c',\n background: '#fff1f2',\n border: '#fecdd3',\n color: '#e11d48',\n dark: { accent: '#fda4af', background: '#4c051966', border: '#fb718540', color: '#fb7185' },\n label: 'Rose',\n },\n {\n name: 'slate',\n accent: '#334155',\n background: '#f8fafc',\n border: '#e2e8f0',\n color: '#475569',\n dark: { accent: '#cbd5e1', background: '#02061766', border: '#94a3b840', color: '#94a3b8' },\n label: 'Slate',\n },\n {\n name: 'neutral',\n accent: '#404040',\n background: '#fafafa',\n border: '#e5e5e5',\n color: '#525252',\n dark: { accent: '#d4d4d4', background: '#0a0a0a66', border: '#a3a3a340', color: '#a3a3a3' },\n label: 'Neutral',\n },\n])\n"],"names":["DEFAULT_PALETTES","Object","freeze","name","accent","background","border","color","dark","label"],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MarkdownRenderConfig } from '../types/core.js';
|
|
2
|
+
/** The unknown-palette message, shared by the renderer and the editor lint. */
|
|
3
|
+
export declare function formatUnknownPaletteMessage(name: string, directive: string, known: readonly string[]): string;
|
|
4
|
+
/** Warning for a palette name the render cannot resolve, or `undefined` when it is known. */
|
|
5
|
+
export declare function getUnknownPaletteWarning(name: string, directive: string, config: Pick<MarkdownRenderConfig, 'palettes'>): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Palette names a directive references: its `palette` / `iconPalette` and the
|
|
8
|
+
* `palette=` of its icon entries, limited to the attributes it accepts.
|
|
9
|
+
*/
|
|
10
|
+
export declare function collectPaletteNames(allowedAttributes: readonly string[], attributes: null | Record<string, unknown> | undefined): string[];
|
|
@@ -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
|