@glw907/cairn-cms 0.62.1 → 0.68.0
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/CHANGELOG.md +143 -0
- package/dist/auth/types.d.ts +7 -0
- package/dist/components/ComponentInsertDialog.svelte +17 -6
- package/dist/components/ConceptList.svelte +25 -4
- package/dist/components/cairn-admin.css +175 -2
- package/dist/content/advisories.d.ts +5 -0
- package/dist/content/advisories.js +17 -9
- package/dist/content/field-rules.d.ts +15 -0
- package/dist/content/field-rules.js +39 -0
- package/dist/content/fields.d.ts +121 -0
- package/dist/content/fields.js +30 -0
- package/dist/content/fieldset.d.ts +86 -0
- package/dist/content/fieldset.js +233 -0
- package/dist/content/schema.js +16 -20
- package/dist/delivery/public-routes.d.ts +8 -0
- package/dist/delivery/public-routes.js +10 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/log/events.d.ts +1 -1
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/manifest.d.ts +11 -0
- package/dist/media/manifest.js +13 -0
- package/dist/render/highlight.d.ts +9 -0
- package/dist/render/highlight.js +206 -0
- package/dist/render/pipeline.js +12 -1
- package/dist/render/registry.d.ts +10 -2
- package/dist/render/registry.js +21 -1
- package/dist/render/rehype-dispatch.d.ts +2 -6
- package/dist/render/rehype-dispatch.js +2 -6
- package/dist/render/sanitize-schema.d.ts +10 -0
- package/dist/render/sanitize-schema.js +29 -0
- package/dist/sveltekit/content-routes.js +9 -7
- package/dist/sveltekit/guard.js +10 -0
- package/package.json +13 -2
- package/src/lib/auth/types.ts +7 -0
- package/src/lib/components/ComponentInsertDialog.svelte +17 -6
- package/src/lib/components/ConceptList.svelte +41 -4
- package/src/lib/content/advisories.ts +24 -15
- package/src/lib/content/field-rules.ts +40 -0
- package/src/lib/content/fields.ts +127 -0
- package/src/lib/content/fieldset.ts +307 -0
- package/src/lib/content/schema.ts +9 -13
- package/src/lib/delivery/public-routes.ts +19 -1
- package/src/lib/index.ts +7 -0
- package/src/lib/log/events.ts +1 -0
- package/src/lib/media/index.ts +1 -0
- package/src/lib/media/manifest.ts +14 -0
- package/src/lib/render/highlight.ts +259 -0
- package/src/lib/render/pipeline.ts +12 -1
- package/src/lib/render/registry.ts +30 -3
- package/src/lib/render/rehype-dispatch.ts +2 -6
- package/src/lib/render/sanitize-schema.ts +31 -0
- package/src/lib/sveltekit/content-routes.ts +9 -7
- package/src/lib/sveltekit/guard.ts +15 -0
package/dist/media/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { normalizeAssets, type ResolvedAssetConfig } from './config.js';
|
|
2
|
-
export { parseMediaManifest, findByHash, upsertMediaEntry, removeMediaEntry, serializeMediaManifest, parseMediaEntries, type MediaEntry, type MediaManifest, } from './manifest.js';
|
|
2
|
+
export { parseMediaManifest, readCommittedManifest, findByHash, upsertMediaEntry, removeMediaEntry, serializeMediaManifest, parseMediaEntries, type MediaEntry, type MediaManifest, } from './manifest.js';
|
|
3
3
|
export { hashBytes, shortHash, slugifyFilename, r2Key, publicPath } from './naming.js';
|
|
4
4
|
export { presetUrl, variantUrl, type VariantSpec } from './transform-url.js';
|
|
5
5
|
export { parseMediaToken, mediaToken, type MediaRef } from './reference.js';
|
package/dist/media/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// delivery-route factory and `requireBucket` stay on `/sveltekit`, off this surface, so the public
|
|
7
7
|
// `.d.ts` for `/media` names no kit or workers-types type.
|
|
8
8
|
export { normalizeAssets } from './config.js';
|
|
9
|
-
export { parseMediaManifest, findByHash, upsertMediaEntry, removeMediaEntry, serializeMediaManifest, parseMediaEntries, } from './manifest.js';
|
|
9
|
+
export { parseMediaManifest, readCommittedManifest, findByHash, upsertMediaEntry, removeMediaEntry, serializeMediaManifest, parseMediaEntries, } from './manifest.js';
|
|
10
10
|
export { hashBytes, shortHash, slugifyFilename, r2Key, publicPath } from './naming.js';
|
|
11
11
|
export { presetUrl, variantUrl } from './transform-url.js';
|
|
12
12
|
export { parseMediaToken, mediaToken } from './reference.js';
|
package/dist/media/manifest.d.ts
CHANGED
|
@@ -26,6 +26,17 @@ export type MediaManifest = Record<string, MediaEntry>;
|
|
|
26
26
|
* object is returned as the manifest.
|
|
27
27
|
*/
|
|
28
28
|
export declare function parseMediaManifest(json: unknown): MediaManifest;
|
|
29
|
+
/**
|
|
30
|
+
* Read the committed media manifest from an `import.meta.glob` eager result, degrading a missing
|
|
31
|
+
* file to an empty manifest. A static import of an absent `media.json` fails the Vite build before
|
|
32
|
+
* any runtime degrade can run, so a fresh site with no manifest cannot build. A glob result is the
|
|
33
|
+
* build-safe read: `import.meta.glob` returns `{}` when nothing matches rather than throwing, and
|
|
34
|
+
* this helper extracts the single matched value and parses it, so a missing file reads a clean `{}`.
|
|
35
|
+
* @param globResult - The eager glob result for the committed manifest, an empty object when the
|
|
36
|
+
* file is absent. The consumer passes
|
|
37
|
+
* `import.meta.glob('<path-to-media.json>', { eager: true, import: 'default' })`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readCommittedManifest(globResult: Record<string, unknown>): MediaManifest;
|
|
29
40
|
/**
|
|
30
41
|
* Parse the posted `media` field into a validated list of MediaEntry rows. The field arrives as a
|
|
31
42
|
* JSON string (the usual form-post shape), an already-parsed array, or junk. A string is JSON-parsed
|
package/dist/media/manifest.js
CHANGED
|
@@ -13,6 +13,19 @@ export function parseMediaManifest(json) {
|
|
|
13
13
|
return {};
|
|
14
14
|
return json;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Read the committed media manifest from an `import.meta.glob` eager result, degrading a missing
|
|
18
|
+
* file to an empty manifest. A static import of an absent `media.json` fails the Vite build before
|
|
19
|
+
* any runtime degrade can run, so a fresh site with no manifest cannot build. A glob result is the
|
|
20
|
+
* build-safe read: `import.meta.glob` returns `{}` when nothing matches rather than throwing, and
|
|
21
|
+
* this helper extracts the single matched value and parses it, so a missing file reads a clean `{}`.
|
|
22
|
+
* @param globResult - The eager glob result for the committed manifest, an empty object when the
|
|
23
|
+
* file is absent. The consumer passes
|
|
24
|
+
* `import.meta.glob('<path-to-media.json>', { eager: true, import: 'default' })`.
|
|
25
|
+
*/
|
|
26
|
+
export function readCommittedManifest(globResult) {
|
|
27
|
+
return parseMediaManifest(Object.values(globResult)[0]);
|
|
28
|
+
}
|
|
16
29
|
/**
|
|
17
30
|
* Validate one posted value as a MediaEntry, returning it narrowed or undefined. The trust boundary
|
|
18
31
|
* for an optimistic record the client re-posts: the upload action server-owned each field at
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
/**
|
|
3
|
+
* The Shiki rehype plugin. Highlights every fenced-code block into a `<pre class="shiki">` whose
|
|
4
|
+
* tokens carry the cairn-tok-* classes (no inline style), then leaves the rest of the tree
|
|
5
|
+
* untouched. It runs as an async transformer because Shiki tokenizes asynchronously. Because the
|
|
6
|
+
* output is class-only it needs no special placement; it is safe anywhere after `remarkRehype`.
|
|
7
|
+
* @returns A unified transformer that mutates the hast tree in place.
|
|
8
|
+
*/
|
|
9
|
+
export declare function rehypeCairnHighlight(): (tree: Root) => Promise<void>;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { toString } from 'hast-util-to-string';
|
|
2
|
+
// The curated language set Shiki preloads. Each id pulls its aliases too (loading `bash` also
|
|
3
|
+
// registers `sh`, `shell`, `zsh`; loading `js` registers `javascript`, `mjs`, `cjs`). A fence whose
|
|
4
|
+
// language is absent or outside this set falls back to plaintext rather than throwing.
|
|
5
|
+
const LANGS = [
|
|
6
|
+
'js',
|
|
7
|
+
'ts',
|
|
8
|
+
'jsx',
|
|
9
|
+
'tsx',
|
|
10
|
+
'svelte',
|
|
11
|
+
'html',
|
|
12
|
+
'css',
|
|
13
|
+
'json',
|
|
14
|
+
'bash',
|
|
15
|
+
'markdown',
|
|
16
|
+
'python',
|
|
17
|
+
'yaml',
|
|
18
|
+
'sql',
|
|
19
|
+
];
|
|
20
|
+
// The plaintext language id. Shiki special-cases it (and `plaintext`/`txt`/`ansi`) as always
|
|
21
|
+
// available, so it is the safe fallback for an unknown or absent fence language: it escapes the
|
|
22
|
+
// code text into the same <pre class="shiki"> wrapper with no token coloring.
|
|
23
|
+
const PLAINTEXT = 'text';
|
|
24
|
+
// Sentinel foreground colors, one per ramp slot. Shiki has no class-emitting mode, so the theme
|
|
25
|
+
// assigns each scope group a unique sentinel hex, then the transformer below maps the resolved
|
|
26
|
+
// sentinel back to its cairn-tok-* class and deletes the style. The sentinels never reach the
|
|
27
|
+
// output. They are arbitrary distinct values; only their uniqueness and exact round-trip matter.
|
|
28
|
+
const SENTINEL_INK = '#000000';
|
|
29
|
+
const SENTINEL_TO_CLASS = {
|
|
30
|
+
'#000010': 'cairn-tok-comment',
|
|
31
|
+
'#000020': 'cairn-tok-keyword',
|
|
32
|
+
'#000030': 'cairn-tok-string',
|
|
33
|
+
'#000040': 'cairn-tok-function',
|
|
34
|
+
'#000050': 'cairn-tok-number',
|
|
35
|
+
'#000060': 'cairn-tok-punct',
|
|
36
|
+
};
|
|
37
|
+
// The Shiki theme that drives the class mapping. Every scope group resolves to its sentinel color;
|
|
38
|
+
// the transformer turns the sentinel into a class. The background and default foreground are
|
|
39
|
+
// sentinels too, stripped from the <pre> by the transformer so the site theme owns the surround.
|
|
40
|
+
const CAIRN_CODE_THEME = {
|
|
41
|
+
name: 'cairn-roles',
|
|
42
|
+
type: 'light',
|
|
43
|
+
fg: SENTINEL_INK,
|
|
44
|
+
bg: '#ffffff',
|
|
45
|
+
settings: [
|
|
46
|
+
{ settings: { foreground: SENTINEL_INK, background: '#ffffff' } },
|
|
47
|
+
{
|
|
48
|
+
scope: ['comment', 'punctuation.definition.comment', 'string.comment'],
|
|
49
|
+
settings: { foreground: '#000010' },
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
scope: [
|
|
53
|
+
'keyword',
|
|
54
|
+
'keyword.control',
|
|
55
|
+
'storage',
|
|
56
|
+
'storage.type',
|
|
57
|
+
'storage.modifier',
|
|
58
|
+
'variable.language',
|
|
59
|
+
'keyword.operator.new',
|
|
60
|
+
'keyword.operator.expression',
|
|
61
|
+
],
|
|
62
|
+
settings: { foreground: '#000020' },
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
scope: ['string', 'string.quoted', 'string.template', 'constant.other.symbol'],
|
|
66
|
+
settings: { foreground: '#000030' },
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
scope: [
|
|
70
|
+
'entity.name.function',
|
|
71
|
+
'support.function',
|
|
72
|
+
'meta.function-call',
|
|
73
|
+
'entity.name.tag',
|
|
74
|
+
'support.type.property-name',
|
|
75
|
+
],
|
|
76
|
+
settings: { foreground: '#000040' },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
scope: [
|
|
80
|
+
'constant.numeric',
|
|
81
|
+
'constant.language',
|
|
82
|
+
'constant.character',
|
|
83
|
+
'constant.other',
|
|
84
|
+
'keyword.other.unit',
|
|
85
|
+
],
|
|
86
|
+
settings: { foreground: '#000050' },
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
scope: ['punctuation', 'meta.brace', 'keyword.operator', 'meta.delimiter'],
|
|
90
|
+
settings: { foreground: '#000060' },
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
// Read the `color:#rrggbb` hex out of a token span's inline style, lowercased for the sentinel map.
|
|
95
|
+
function styleColor(style) {
|
|
96
|
+
if (typeof style !== 'string')
|
|
97
|
+
return undefined;
|
|
98
|
+
const match = /color:(#[0-9a-fA-F]{6})/.exec(style);
|
|
99
|
+
return match ? match[1].toLowerCase() : undefined;
|
|
100
|
+
}
|
|
101
|
+
// Append a class to a hast element's class list, building the string form Shiki uses.
|
|
102
|
+
function addClass(node, className) {
|
|
103
|
+
const existing = node.properties?.class;
|
|
104
|
+
const prefix = typeof existing === 'string' && existing.length > 0 ? `${existing} ` : '';
|
|
105
|
+
(node.properties ??= {}).class = `${prefix}${className}`;
|
|
106
|
+
}
|
|
107
|
+
// The transformer that converts Shiki's sentinel-colored inline styles into the cairn-tok-* classes
|
|
108
|
+
// and strips every style attribute, so the output is class-only. The <pre> loses its
|
|
109
|
+
// background/foreground style (the site theme owns the surround); each token <span> trades its
|
|
110
|
+
// sentinel color for the matching class, and a default-foreground span is left unclassed.
|
|
111
|
+
const cairnTokenClasses = {
|
|
112
|
+
name: 'cairn-token-classes',
|
|
113
|
+
pre(node) {
|
|
114
|
+
if (node.properties)
|
|
115
|
+
delete node.properties.style;
|
|
116
|
+
},
|
|
117
|
+
code(node) {
|
|
118
|
+
if (node.properties)
|
|
119
|
+
delete node.properties.style;
|
|
120
|
+
},
|
|
121
|
+
span(node) {
|
|
122
|
+
const hex = styleColor(node.properties?.style);
|
|
123
|
+
if (node.properties)
|
|
124
|
+
delete node.properties.style;
|
|
125
|
+
const className = hex ? SENTINEL_TO_CLASS[hex] : undefined;
|
|
126
|
+
if (className)
|
|
127
|
+
addClass(node, className);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
// The cached highlighter. Created once on first use and reused for every render. The dynamic import
|
|
131
|
+
// keeps Shiki off the static client graph; the promise is cached so the WASM grammar load and the
|
|
132
|
+
// theme registration happen at most once per process.
|
|
133
|
+
let highlighterPromise;
|
|
134
|
+
function getHighlighter() {
|
|
135
|
+
if (!highlighterPromise) {
|
|
136
|
+
highlighterPromise = import('shiki').then((shiki) => shiki.createHighlighter({ themes: [CAIRN_CODE_THEME], langs: [...LANGS] }));
|
|
137
|
+
}
|
|
138
|
+
return highlighterPromise;
|
|
139
|
+
}
|
|
140
|
+
// Read the fenced language off a <code> element's class list. Markdown emits the language as a
|
|
141
|
+
// `language-<id>` class on the inner <code>. An empty or missing language returns undefined, which
|
|
142
|
+
// the caller maps to plaintext.
|
|
143
|
+
function codeLanguage(code) {
|
|
144
|
+
const className = code.properties?.className;
|
|
145
|
+
const classes = Array.isArray(className) ? className.map(String) : [];
|
|
146
|
+
const langClass = classes.find((c) => c.startsWith('language-'));
|
|
147
|
+
const lang = langClass?.slice('language-'.length);
|
|
148
|
+
return lang && lang.length > 0 ? lang : undefined;
|
|
149
|
+
}
|
|
150
|
+
// A fenced-code <pre> is a <pre> whose single element child is a <code>. Inline code (a bare <code>
|
|
151
|
+
// with no <pre> parent) and any other <pre> are left untouched.
|
|
152
|
+
function fencedCode(pre) {
|
|
153
|
+
const child = pre.children.find((c) => c.type === 'element');
|
|
154
|
+
return child?.tagName === 'code' ? child : undefined;
|
|
155
|
+
}
|
|
156
|
+
// Descend the tree and collect every fenced-code <pre>. The walk is synchronous and gathers the
|
|
157
|
+
// targets up front, because the highlight itself is async (unist-util-visit cannot await).
|
|
158
|
+
function collectFencedCode(node, jobs) {
|
|
159
|
+
for (const child of node.children) {
|
|
160
|
+
if (child.type !== 'element')
|
|
161
|
+
continue;
|
|
162
|
+
if (child.tagName === 'pre') {
|
|
163
|
+
const code = fencedCode(child);
|
|
164
|
+
if (code) {
|
|
165
|
+
jobs.push({ pre: child, code, lang: codeLanguage(code) ?? PLAINTEXT });
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
collectFencedCode(child, jobs);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The Shiki rehype plugin. Highlights every fenced-code block into a `<pre class="shiki">` whose
|
|
174
|
+
* tokens carry the cairn-tok-* classes (no inline style), then leaves the rest of the tree
|
|
175
|
+
* untouched. It runs as an async transformer because Shiki tokenizes asynchronously. Because the
|
|
176
|
+
* output is class-only it needs no special placement; it is safe anywhere after `remarkRehype`.
|
|
177
|
+
* @returns A unified transformer that mutates the hast tree in place.
|
|
178
|
+
*/
|
|
179
|
+
export function rehypeCairnHighlight() {
|
|
180
|
+
return async (tree) => {
|
|
181
|
+
const jobs = [];
|
|
182
|
+
collectFencedCode(tree, jobs);
|
|
183
|
+
if (jobs.length === 0)
|
|
184
|
+
return;
|
|
185
|
+
const highlighter = await getHighlighter();
|
|
186
|
+
const loaded = new Set(highlighter.getLoadedLanguages());
|
|
187
|
+
for (const job of jobs) {
|
|
188
|
+
// Fall back to plaintext for any language outside the preloaded set so Shiki never throws on
|
|
189
|
+
// an unknown fence. Plaintext still produces the <pre class="shiki"> wrapper with escaped text.
|
|
190
|
+
const lang = loaded.has(job.lang) ? job.lang : PLAINTEXT;
|
|
191
|
+
const result = highlighter.codeToHast(toString(job.code), {
|
|
192
|
+
lang,
|
|
193
|
+
theme: 'cairn-roles',
|
|
194
|
+
transformers: [cairnTokenClasses],
|
|
195
|
+
});
|
|
196
|
+
const pre = result.children.find((c) => c.type === 'element' && c.tagName === 'pre');
|
|
197
|
+
if (!pre)
|
|
198
|
+
continue;
|
|
199
|
+
// Rewrite the original <pre> into Shiki's <pre> in place: adopt its tag, properties, and
|
|
200
|
+
// children. Mutating the existing node avoids reindexing the parent's children array.
|
|
201
|
+
job.pre.tagName = pre.tagName;
|
|
202
|
+
job.pre.properties = pre.properties;
|
|
203
|
+
job.pre.children = pre.children;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
package/dist/render/pipeline.js
CHANGED
|
@@ -8,7 +8,8 @@ import rehypeSlug from 'rehype-slug';
|
|
|
8
8
|
import rehypeStringify from 'rehype-stringify';
|
|
9
9
|
import rehypeSanitize from 'rehype-sanitize';
|
|
10
10
|
import { VFile } from 'vfile';
|
|
11
|
-
import { buildSanitizeSchema, rehypeAnchorRel, rehypeSinkGuard } from './sanitize-schema.js';
|
|
11
|
+
import { buildSanitizeSchema, rehypeAnchorRel, rehypeSinkGuard, rehypeTaskListA11y } from './sanitize-schema.js';
|
|
12
|
+
import { rehypeCairnHighlight } from './highlight.js';
|
|
12
13
|
import { remarkDirectiveStamp } from './remark-directives.js';
|
|
13
14
|
import { remarkFigure } from './remark-figure.js';
|
|
14
15
|
import { remarkResolveCairnLinks, CAIRN_RESOLVE } from './resolve-links.js';
|
|
@@ -40,6 +41,16 @@ export function createRenderer(registry = defineRegistry({ components: [] }), op
|
|
|
40
41
|
...floor,
|
|
41
42
|
[rehypeDispatch, registry, options.stagger],
|
|
42
43
|
rehypeSlug,
|
|
44
|
+
// Name each GFM task-list checkbox from its item text. It runs after the sanitize floor (which
|
|
45
|
+
// does not allow aria-label) so the added attribute survives, and is content-not-sink, so it is
|
|
46
|
+
// not gated by unsafeDisableSanitize.
|
|
47
|
+
rehypeTaskListA11y,
|
|
48
|
+
// Build-time syntax highlighting. It emits class-only output (the cairn-tok-* ramp, no inline
|
|
49
|
+
// style), so it is class-driven like the rest of the pipeline and needs no special placement
|
|
50
|
+
// relative to the sanitize floor or the sink guard: the token classes survive the floor because
|
|
51
|
+
// `className` is already allowed on `*`. It runs unconditionally (a code fence is content, not a
|
|
52
|
+
// sink) and ships no client highlighter (Shiki is build-only behind a dynamic import).
|
|
53
|
+
rehypeCairnHighlight,
|
|
43
54
|
];
|
|
44
55
|
if (rel !== false)
|
|
45
56
|
rehypePlugins.push([rehypeAnchorRel, rel]);
|
|
@@ -78,7 +78,12 @@ export interface ComponentDef {
|
|
|
78
78
|
* result, so a build fn stays free of any motion concern.
|
|
79
79
|
*/
|
|
80
80
|
build: (ctx: ComponentContext) => Element;
|
|
81
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Optional role-to-default-icon, e.g. `{ caution: 'warning' }`. Maps a free-string role to a
|
|
83
|
+
* glyph key in the site IconSet; choose a logically representative glyph and prefer glyphs
|
|
84
|
+
* distinct across roles so the picker stays scannable. Overrides the engine
|
|
85
|
+
* {@link DEFAULT_ICON_BY_ROLE} fallback for the roles it names.
|
|
86
|
+
*/
|
|
82
87
|
defaultIconByRole?: Record<string, string>;
|
|
83
88
|
/** One line on when to reach for this component; feeds the picker and the reference file. */
|
|
84
89
|
use?: string;
|
|
@@ -86,7 +91,10 @@ export interface ComponentDef {
|
|
|
86
91
|
attributes?: AttributeField[];
|
|
87
92
|
/** The named content regions this component accepts. */
|
|
88
93
|
slots?: SlotDef[];
|
|
89
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* A glyph key from the site IconSet, shown beside the label in the picker. Choose a logically
|
|
96
|
+
* representative glyph and prefer glyphs distinct across components so the picker stays scannable.
|
|
97
|
+
*/
|
|
90
98
|
icon?: string;
|
|
91
99
|
/** A category heading for the picker. Components order by declaration within a group. */
|
|
92
100
|
group?: string;
|
package/dist/render/registry.js
CHANGED
|
@@ -14,6 +14,19 @@ export function dataAttrProp(key) {
|
|
|
14
14
|
function findIconField(def) {
|
|
15
15
|
return def.attributes?.find((field) => field.type === 'icon');
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The engine's role-to-glyph-key fallback for the conventional admonition roles, which a site's
|
|
19
|
+
* IconSet may satisfy. A component's own {@link ComponentDef.defaultIconByRole} overrides it.
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_ICON_BY_ROLE = {
|
|
22
|
+
note: 'info',
|
|
23
|
+
tip: 'lightbulb',
|
|
24
|
+
important: 'star',
|
|
25
|
+
warning: 'warning',
|
|
26
|
+
caution: 'alert-triangle',
|
|
27
|
+
info: 'info',
|
|
28
|
+
danger: 'flame',
|
|
29
|
+
};
|
|
17
30
|
/**
|
|
18
31
|
* Build a registry from a site's component definitions. The single source the render
|
|
19
32
|
* pipeline (directive stamp plus rehype dispatch) and the editor palette both read.
|
|
@@ -32,7 +45,14 @@ export function defineRegistry({ components }) {
|
|
|
32
45
|
defs: components,
|
|
33
46
|
names: components.map((c) => c.name),
|
|
34
47
|
get: (name) => byName.get(name),
|
|
35
|
-
defaultIcon: (name, role) =>
|
|
48
|
+
defaultIcon: (name, role) => {
|
|
49
|
+
if (!role)
|
|
50
|
+
return undefined;
|
|
51
|
+
const def = byName.get(name);
|
|
52
|
+
if (!def || !findIconField(def))
|
|
53
|
+
return undefined;
|
|
54
|
+
return def.defaultIconByRole?.[role] ?? DEFAULT_ICON_BY_ROLE[role];
|
|
55
|
+
},
|
|
36
56
|
iconField: (name) => {
|
|
37
57
|
const def = byName.get(name);
|
|
38
58
|
return def ? findIconField(def) : undefined;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import type { Root, Element, ElementContent } from 'hast';
|
|
2
2
|
import { type ComponentContext, type ComponentRegistry } from './registry.js';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
3
|
+
/** Narrow a hast node to an Element, false for a text node, a comment, or undefined. */
|
|
6
4
|
export declare function isElement(node: ElementContent | undefined): node is Element;
|
|
7
5
|
/**
|
|
8
6
|
* Read a declared string attribute off the component context, returning undefined for a boolean or
|
|
9
7
|
* absent value. Replaces the `typeof ctx.attributes[key] === 'string'` narrowing a build repeats.
|
|
10
8
|
*/
|
|
11
9
|
export declare function strAttr(ctx: ComponentContext, key: string): string | undefined;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
10
|
+
/** Read a hast element property as a string, or undefined when it is absent or non-string. */
|
|
15
11
|
export declare function strProp(node: Element, name: string): string | undefined;
|
|
16
12
|
/** Wrap a pre-built glyph in an ec-icon span; secondary role adds the modifier. */
|
|
17
13
|
export declare function iconSpan(glyphEl: Element, role?: string): Element;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { h } from 'hastscript';
|
|
2
2
|
import { dataAttrProp } from './registry.js';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
3
|
+
/** Narrow a hast node to an Element, false for a text node, a comment, or undefined. */
|
|
6
4
|
export function isElement(node) {
|
|
7
5
|
return !!node && node.type === 'element';
|
|
8
6
|
}
|
|
@@ -17,9 +15,7 @@ export function strAttr(ctx, key) {
|
|
|
17
15
|
// hast Properties values are PropertyValue (string | number | boolean | array | null).
|
|
18
16
|
// Directive markers (dataPrimitive/dataRole/dataAttr<Key>) are always stamped as strings;
|
|
19
17
|
// this reads them back with that guarantee instead of casting at each call site.
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
18
|
+
/** Read a hast element property as a string, or undefined when it is absent or non-string. */
|
|
23
19
|
export function strProp(node, name) {
|
|
24
20
|
const value = node.properties?.[name];
|
|
25
21
|
return typeof value === 'string' ? value : undefined;
|
|
@@ -20,6 +20,16 @@ export declare function buildSanitizeSchema(registry: ComponentRegistry, extend?
|
|
|
20
20
|
* `anchorRel` option (default `noopener noreferrer`); a site can override it or disable it entirely.
|
|
21
21
|
*/
|
|
22
22
|
export declare function rehypeAnchorRel(rel: string): (tree: Root) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Give every GFM task-list checkbox an accessible name from its item text. remark-gfm emits a real
|
|
25
|
+
* `<input type="checkbox" disabled>` with no label, which axe's `label` rule flags as a critical
|
|
26
|
+
* violation even though the control is read-only; the visible label is the surrounding `<li>` text,
|
|
27
|
+
* not associated programmatically. This sets `aria-label` on each task-list checkbox to its item's
|
|
28
|
+
* text so the name travels with the control, keeping the engine's real disabled input (the bar's
|
|
29
|
+
* non-color cue) while clearing the violation on every site. It must run after the sanitize floor,
|
|
30
|
+
* which does not allow `aria-label`, so the attribute is added once the floor has run.
|
|
31
|
+
*/
|
|
32
|
+
export declare function rehypeTaskListA11y(): (tree: Root) => void;
|
|
23
33
|
/**
|
|
24
34
|
* Post-dispatch safety floor over the fully-built tree. The pre-dispatch rehype-sanitize floor
|
|
25
35
|
* cleans author content, but a component build() runs after it and can route a raw author
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defaultSchema } from 'hast-util-sanitize';
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { toString } from 'hast-util-to-string';
|
|
3
4
|
import { dataAttrProp } from './registry.js';
|
|
4
5
|
// The fixed directive markers the stamp writes and the dispatch reads. They are inert data
|
|
5
6
|
// attributes, never a script vector, and must survive the floor so the dispatch still runs.
|
|
@@ -58,6 +59,34 @@ export function rehypeAnchorRel(rel) {
|
|
|
58
59
|
});
|
|
59
60
|
};
|
|
60
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Give every GFM task-list checkbox an accessible name from its item text. remark-gfm emits a real
|
|
64
|
+
* `<input type="checkbox" disabled>` with no label, which axe's `label` rule flags as a critical
|
|
65
|
+
* violation even though the control is read-only; the visible label is the surrounding `<li>` text,
|
|
66
|
+
* not associated programmatically. This sets `aria-label` on each task-list checkbox to its item's
|
|
67
|
+
* text so the name travels with the control, keeping the engine's real disabled input (the bar's
|
|
68
|
+
* non-color cue) while clearing the violation on every site. It must run after the sanitize floor,
|
|
69
|
+
* which does not allow `aria-label`, so the attribute is added once the floor has run.
|
|
70
|
+
*/
|
|
71
|
+
export function rehypeTaskListA11y() {
|
|
72
|
+
return (tree) => {
|
|
73
|
+
visit(tree, 'element', (node) => {
|
|
74
|
+
const className = node.properties?.className;
|
|
75
|
+
const isTaskItem = node.tagName === 'li' && Array.isArray(className) && className.includes('task-list-item');
|
|
76
|
+
if (!isTaskItem)
|
|
77
|
+
return;
|
|
78
|
+
const checkbox = node.children.find((child) => child.type === 'element' &&
|
|
79
|
+
child.tagName === 'input' &&
|
|
80
|
+
child.properties?.type === 'checkbox');
|
|
81
|
+
if (!checkbox)
|
|
82
|
+
return;
|
|
83
|
+
const label = toString(node).trim();
|
|
84
|
+
// Only when there is text to name it; an empty item leaves the box unnamed rather than blank.
|
|
85
|
+
if (label)
|
|
86
|
+
(checkbox.properties ??= {})['ariaLabel'] = label;
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
61
90
|
// URL-bearing hast properties the post-dispatch guard scheme-checks. hast camelCases attribute
|
|
62
91
|
// names through property-information (srcset -> srcSet, xlink:href -> xLinkHref with a capital L,
|
|
63
92
|
// formaction -> formAction). data is the <object data> URL attribute; data-* attributes camelCase
|
|
@@ -8,7 +8,7 @@ import { extractCairnLinks, formatCairnToken, rewriteCairnLink } from '../conten
|
|
|
8
8
|
import { frontmatterFromForm, parseMarkdown, dateInputValue, serializeMarkdown } from '../content/frontmatter.js';
|
|
9
9
|
import { deriveExcerpt } from '../content/excerpt.js';
|
|
10
10
|
import { asString, entryIdentity } from '../content/identity.js';
|
|
11
|
-
import { buildAddressIndex, addressCollision } from '../content/advisories.js';
|
|
11
|
+
import { buildAddressIndex, mainAddressIndex, addressCollision } from '../content/advisories.js';
|
|
12
12
|
import { isValidId, slugify, filenameFromId, composeDatedId, slugFromId, renameId } from '../content/ids.js';
|
|
13
13
|
import { appCredentials } from '../github/credentials.js';
|
|
14
14
|
import { listMarkdown, readRaw, commitFile, commitFiles } from '../github/repo.js';
|
|
@@ -502,14 +502,16 @@ export function createContentRoutes(runtime, deps = {}) {
|
|
|
502
502
|
}));
|
|
503
503
|
inbound = inboundLinks(manifest, concept.id, id);
|
|
504
504
|
}
|
|
505
|
-
// The
|
|
506
|
-
//
|
|
507
|
-
//
|
|
505
|
+
// The address-collision advisory: warn-and-allow, never a gate. At edit-load it checks the
|
|
506
|
+
// published corpus only, built synchronously from the same manifest read above (no extra GitHub
|
|
507
|
+
// read per editor open); publishAction re-checks the full cross-branch index before it lands. The
|
|
508
|
+
// try/catch degrades to no notice if entryIdentity throws on a malformed-date entry. Skip the build
|
|
509
|
+
// with no manifest to index.
|
|
508
510
|
let advisories = [];
|
|
509
511
|
if (manifest !== null) {
|
|
510
512
|
try {
|
|
511
513
|
const identity = entryIdentity(concept, path, parsed.frontmatter);
|
|
512
|
-
const addressIndex =
|
|
514
|
+
const addressIndex = mainAddressIndex(manifest);
|
|
513
515
|
const other = addressCollision(addressIndex, { concept: concept.id, id }, identity.permalink);
|
|
514
516
|
if (other) {
|
|
515
517
|
const otherConcept = findConcept(runtime.concepts, other.concept);
|
|
@@ -524,8 +526,8 @@ export function createContentRoutes(runtime, deps = {}) {
|
|
|
524
526
|
];
|
|
525
527
|
}
|
|
526
528
|
}
|
|
527
|
-
catch
|
|
528
|
-
|
|
529
|
+
catch {
|
|
530
|
+
// A malformed-date entry that cannot resolve its permalink degrades to no advisory, fail open.
|
|
529
531
|
}
|
|
530
532
|
}
|
|
531
533
|
// Project the one committed media manifest read two ways: the minimal resolver triple the preview
|
package/dist/sveltekit/guard.js
CHANGED
|
@@ -32,6 +32,16 @@ function isLocalHost(hostname) {
|
|
|
32
32
|
export function createAuthGuard() {
|
|
33
33
|
return async function handle({ event, resolve }) {
|
|
34
34
|
const { pathname } = event.url;
|
|
35
|
+
// Fail closed if the dev-backend flag is set in a deployed runtime. Read both env sources: a
|
|
36
|
+
// Cloudflare Worker var lands on platform.env, an adapter-node OS var on process.env. A correct
|
|
37
|
+
// production build already eliminated the dev backend (the consumer gates it on the build-foldable
|
|
38
|
+
// `dev`), so a set flag signals a polluted environment; refuse loudly.
|
|
39
|
+
const platformFlag = event.platform?.env?.CAIRN_DEV_BACKEND;
|
|
40
|
+
const processFlag = typeof process !== 'undefined' ? process.env?.CAIRN_DEV_BACKEND : undefined;
|
|
41
|
+
if (platformFlag === '1' || platformFlag === true || processFlag === '1') {
|
|
42
|
+
log.error('guard.rejected', { reason: 'dev_backend_in_prod', path: pathname });
|
|
43
|
+
return new Response('cairn: the dev backend flag is set in a deployed environment. Unset CAIRN_DEV_BACKEND.', { status: 503 });
|
|
44
|
+
}
|
|
35
45
|
// Rule 2 - non-admin: restore the framework's strict Origin check the consumer disabled when
|
|
36
46
|
// they set checkOrigin: false to hand cairn the admin CSRF authority.
|
|
37
47
|
if (!isAdminPath(pathname)) {
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glw907/cairn-cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.68.0",
|
|
4
4
|
"description": "Embedded, magic-link, GitHub-committing CMS for SvelteKit/Cloudflare sites.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"workspaces": [
|
|
7
|
+
"packages/*"
|
|
8
|
+
],
|
|
6
9
|
"sideEffects": [
|
|
7
10
|
"**/*.svelte",
|
|
8
11
|
"**/*.css"
|
|
@@ -34,15 +37,20 @@
|
|
|
34
37
|
"check:docs": "node scripts/docs-links.mjs",
|
|
35
38
|
"check:version": "node scripts/check-version.mjs",
|
|
36
39
|
"check:prose": "node scripts/check-admin-prose.mjs",
|
|
40
|
+
"check:public-tokens": "node scripts/check-public-tokens.mjs",
|
|
41
|
+
"test:reskin": "node scripts/reskin-fixture.mjs",
|
|
37
42
|
"lint": "eslint src/lib",
|
|
38
43
|
"check:comments": "bash scripts/check-comments.sh",
|
|
44
|
+
"check:dev-package": "node scripts/check-dev-package.mjs",
|
|
39
45
|
"prepare": "npm run package",
|
|
40
46
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
41
47
|
"test": "vitest run",
|
|
42
48
|
"test:watch": "vitest",
|
|
43
49
|
"test:unit": "vitest run --project unit",
|
|
44
50
|
"test:integration": "vitest run --project integration",
|
|
45
|
-
"test:component": "vitest run --project component"
|
|
51
|
+
"test:component": "vitest run --project component",
|
|
52
|
+
"emit-template": "node scripts/emit-template.mjs",
|
|
53
|
+
"test:emit": "node --test scripts/emit-template.test.mjs"
|
|
46
54
|
},
|
|
47
55
|
"exports": {
|
|
48
56
|
".": {
|
|
@@ -131,6 +139,7 @@
|
|
|
131
139
|
"codemirror": "^6.0.2",
|
|
132
140
|
"gray-matter": "^4",
|
|
133
141
|
"hast-util-sanitize": "^5.0.2",
|
|
142
|
+
"hast-util-to-string": "^3.0.1",
|
|
134
143
|
"hastscript": "^9.0.1",
|
|
135
144
|
"heic-to": "^1.5.2",
|
|
136
145
|
"mdast-util-directive": "^3.1.0",
|
|
@@ -143,6 +152,7 @@
|
|
|
143
152
|
"remark-parse": "^11.0.0",
|
|
144
153
|
"remark-rehype": "^11.1.2",
|
|
145
154
|
"remark-stringify": "^11.0.0",
|
|
155
|
+
"shiki": "^4.3.0",
|
|
146
156
|
"spellchecker-wasm": "^0.3.3",
|
|
147
157
|
"unified": "^11.0.5",
|
|
148
158
|
"unist-util-visit": "^5.1.0",
|
|
@@ -159,6 +169,7 @@
|
|
|
159
169
|
"@types/node": "^22.19.19",
|
|
160
170
|
"@vitest/browser": "^4.1.7",
|
|
161
171
|
"@vitest/browser-playwright": "^4.1.7",
|
|
172
|
+
"culori": "^4.0.2",
|
|
162
173
|
"daisyui": "^5.5.23",
|
|
163
174
|
"eslint": "^9.39.4",
|
|
164
175
|
"eslint-plugin-jsdoc": "^63.0.7",
|
package/src/lib/auth/types.ts
CHANGED
|
@@ -14,6 +14,13 @@ export interface AuthEnv {
|
|
|
14
14
|
AUTH_DB?: D1Database;
|
|
15
15
|
/** Canonical origin for confirmation links, never read from a request header (spec 7.1, risk H3). */
|
|
16
16
|
PUBLIC_ORIGIN?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Dev-backend tripwire flag. The dev backend sets this in local development; if it is ever set in
|
|
19
|
+
* a deployed runtime the guard refuses (the build-foldable `dev` gate should have eliminated the
|
|
20
|
+
* dev backend, so a set flag signals a polluted environment). A string from a Worker var or a
|
|
21
|
+
* boolean.
|
|
22
|
+
*/
|
|
23
|
+
CAIRN_DEV_BACKEND?: string | boolean;
|
|
17
24
|
/** Cloudflare Email Sending binding. */
|
|
18
25
|
EMAIL?: {
|
|
19
26
|
send(message: {
|