@cube-drone/marquee-react-renderer 0.10.2 → 0.10.4
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/dist/render.js +42 -15
- package/package.json +7 -7
- package/src/render.ts +54 -20
package/dist/render.js
CHANGED
|
@@ -142,6 +142,15 @@ function withNotes(ctx, element, key) {
|
|
|
142
142
|
ctx.note.pending = [];
|
|
143
143
|
return h("div", { key, style: { display: "contents" } }, element, h("aside", { key: "notes", className: "mq-notes" }, notes.map((n, i) => h("p", { key: i, className: "mq-note" }, n))));
|
|
144
144
|
}
|
|
145
|
+
/** HTML's ladder stops at h6; 7 and 8 keep heading semantics via ARIA on a
|
|
146
|
+
* styled element - `deep` names it: a block in the flow, a span where only
|
|
147
|
+
* phrasing content may go. */
|
|
148
|
+
function headingEl(node, deep, ctx, key) {
|
|
149
|
+
const inner = renderChildren(node.children, ctx);
|
|
150
|
+
return node.level <= 6
|
|
151
|
+
? h(`h${node.level}`, nodeProps(node, ctx, { key }), ...inner)
|
|
152
|
+
: h(deep, nodeProps(node, ctx, { key, className: `mq-h${node.level}`, role: "heading", "aria-level": node.level }), ...inner);
|
|
153
|
+
}
|
|
145
154
|
export function renderNode(node, ctx, key) {
|
|
146
155
|
switch (node.type) {
|
|
147
156
|
case "document":
|
|
@@ -150,19 +159,8 @@ export function renderNode(node, ctx, key) {
|
|
|
150
159
|
const el = h("p", nodeProps(node, ctx, { key }), ...renderChildren(node.children, ctx));
|
|
151
160
|
return withNotes(ctx, el, key);
|
|
152
161
|
}
|
|
153
|
-
case "heading":
|
|
154
|
-
|
|
155
|
-
// HTML's ladder stops at h6; 7 and 8 keep heading semantics via ARIA.
|
|
156
|
-
const el = node.level <= 6
|
|
157
|
-
? h(`h${node.level}`, nodeProps(node, ctx, { key }), ...inner)
|
|
158
|
-
: h("p", nodeProps(node, ctx, {
|
|
159
|
-
key,
|
|
160
|
-
className: `mq-h${node.level}`,
|
|
161
|
-
role: "heading",
|
|
162
|
-
"aria-level": node.level,
|
|
163
|
-
}), ...inner);
|
|
164
|
-
return withNotes(ctx, el, key);
|
|
165
|
-
}
|
|
162
|
+
case "heading":
|
|
163
|
+
return withNotes(ctx, headingEl(node, "p", ctx, key), key);
|
|
166
164
|
case "code_block": {
|
|
167
165
|
const lang = infoToken(node.info);
|
|
168
166
|
return h("pre", nodeProps(node, ctx, { key, className: "mq-code" }), h("code", { className: lang === null ? undefined : `language-${lang}` }, node.text === "" ? null : `${node.text}\n`));
|
|
@@ -300,8 +298,12 @@ function directive(node, ctx, key) {
|
|
|
300
298
|
// Built-ins that lay their children out themselves (table, stack) probe
|
|
301
299
|
// the hooks instead of rendering the children for them: rendering them
|
|
302
300
|
// twice per level is exponential in nesting, and a note would count twice.
|
|
303
|
-
if ((name === "table" || name === "stack") && !claimed("directive", name, attrs, ctx)) {
|
|
304
|
-
return name === "table"
|
|
301
|
+
if ((name === "table" || name === "stack" || name === "expand") && !claimed("directive", name, attrs, ctx)) {
|
|
302
|
+
return name === "table"
|
|
303
|
+
? renderTable(node, ctx, key)
|
|
304
|
+
: name === "stack"
|
|
305
|
+
? renderStack(node, ctx, key)
|
|
306
|
+
: renderExpand(node, ctx, key);
|
|
305
307
|
}
|
|
306
308
|
const kids = renderChildren(node.children, ctx);
|
|
307
309
|
const custom = ctx.hooks.directive?.(name, attrs, kids);
|
|
@@ -390,6 +392,31 @@ function directive(node, ctx, key) {
|
|
|
390
392
|
? h("div", nodeProps(node, ctx, { key, className: "mq-unknown", "data-directive": name }), ...kids)
|
|
391
393
|
: h("div", nodeProps(node, ctx, { key, className: "mq-placeholder", "data-directive": name }));
|
|
392
394
|
}
|
|
395
|
+
/** :::expand - native <details>/<summary> (SPEC.md, "Expand"): the browser
|
|
396
|
+
* owns the fold, so there is no state here. The title is the first child
|
|
397
|
+
* when it is a paragraph (its inline content; the summary registers as that
|
|
398
|
+
* paragraph for scroll sync) or a heading (the heading itself, inside the
|
|
399
|
+
* summary); otherwise the browser supplies its own label. */
|
|
400
|
+
function renderExpand(node, ctx, key) {
|
|
401
|
+
const first = node.children[0];
|
|
402
|
+
if (first === undefined || (first.type !== "paragraph" && first.type !== "heading")) {
|
|
403
|
+
return h("details", nodeProps(node, ctx, { key, className: "mq-expand" }), ...renderChildren(node.children, ctx));
|
|
404
|
+
}
|
|
405
|
+
// A summary holds phrasing content or a heading: a deep heading is a span.
|
|
406
|
+
const summary = first.type === "paragraph"
|
|
407
|
+
? h("summary", nodeProps(first, ctx, { key: "summary" }), ...renderChildren(first.children, ctx))
|
|
408
|
+
: h("summary", { key: "summary" }, headingEl(first, "span", ctx, "0"));
|
|
409
|
+
// A title's sidenotes land at the top of the body, just below it. Not
|
|
410
|
+
// withNotes: its wrapper would stop the summary being the details' first
|
|
411
|
+
// child, and a summary anywhere else is not a summary.
|
|
412
|
+
const pending = ctx.note.pending;
|
|
413
|
+
ctx.note.pending = [];
|
|
414
|
+
const notes = pending.length === 0
|
|
415
|
+
? null
|
|
416
|
+
: h("aside", { key: "notes", className: "mq-notes" }, pending.map((n, i) => h("p", { key: i, className: "mq-note" }, n)));
|
|
417
|
+
const body = node.children.slice(1).map((child, i) => renderNode(child, ctx, String(i + 1)));
|
|
418
|
+
return h("details", nodeProps(node, ctx, { key, className: "mq-expand" }), summary, notes, ...body);
|
|
419
|
+
}
|
|
393
420
|
/** :::table - paragraph-rows, [c] cell spans (SPEC.md, "Tables"). */
|
|
394
421
|
function renderTable(node, ctx, key) {
|
|
395
422
|
const header = node.attrs["header"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cube-drone/marquee-react-renderer",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Interactive React renderer for the Marquee markup language: the JS halves of the animation contract (start-on-visible, tap-to-skip) plus source-position scroll sync for side-by-side editors",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"demo": "node --conditions=marquee-src scripts/demo.ts"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@cube-drone/marquee-html-renderer": "^0.10.
|
|
38
|
-
"@cube-drone/marquee-parser": "^0.10.
|
|
37
|
+
"@cube-drone/marquee-html-renderer": "^0.10.4",
|
|
38
|
+
"@cube-drone/marquee-parser": "^0.10.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=18"
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"react": "^19.0.0",
|
|
49
49
|
"react-dom": "^19.0.0",
|
|
50
50
|
"typescript": "^5.9.0",
|
|
51
|
-
"@cube-drone/marquee-css": "^0.10.
|
|
52
|
-
"@cube-drone/marquee-fonts": "^0.10.
|
|
53
|
-
"@cube-drone/marquee-emoji": "^0.10.
|
|
54
|
-
"@cube-drone/marquee-turbolink": "^0.10.
|
|
51
|
+
"@cube-drone/marquee-css": "^0.10.4",
|
|
52
|
+
"@cube-drone/marquee-fonts": "^0.10.4",
|
|
53
|
+
"@cube-drone/marquee-emoji": "^0.10.4",
|
|
54
|
+
"@cube-drone/marquee-turbolink": "^0.10.4"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/render.ts
CHANGED
|
@@ -204,6 +204,20 @@ function withNotes(ctx: Ctx, element: ReactNode, key: string): ReactNode {
|
|
|
204
204
|
);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/** HTML's ladder stops at h6; 7 and 8 keep heading semantics via ARIA on a
|
|
208
|
+
* styled element - `deep` names it: a block in the flow, a span where only
|
|
209
|
+
* phrasing content may go. */
|
|
210
|
+
function headingEl(node: Node & { type: "heading" }, deep: "p" | "span", ctx: Ctx, key: string): ReactNode {
|
|
211
|
+
const inner = renderChildren(node.children, ctx);
|
|
212
|
+
return node.level <= 6
|
|
213
|
+
? h(`h${node.level}`, nodeProps(node, ctx, { key }), ...inner)
|
|
214
|
+
: h(
|
|
215
|
+
deep,
|
|
216
|
+
nodeProps(node, ctx, { key, className: `mq-h${node.level}`, role: "heading", "aria-level": node.level }),
|
|
217
|
+
...inner,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
207
221
|
export function renderNode(node: Node, ctx: Ctx, key: string): ReactNode {
|
|
208
222
|
switch (node.type) {
|
|
209
223
|
case "document":
|
|
@@ -212,24 +226,8 @@ export function renderNode(node: Node, ctx: Ctx, key: string): ReactNode {
|
|
|
212
226
|
const el = h("p", nodeProps(node, ctx, { key }), ...renderChildren(node.children, ctx));
|
|
213
227
|
return withNotes(ctx, el, key);
|
|
214
228
|
}
|
|
215
|
-
case "heading":
|
|
216
|
-
|
|
217
|
-
// HTML's ladder stops at h6; 7 and 8 keep heading semantics via ARIA.
|
|
218
|
-
const el =
|
|
219
|
-
node.level <= 6
|
|
220
|
-
? h(`h${node.level}`, nodeProps(node, ctx, { key }), ...inner)
|
|
221
|
-
: h(
|
|
222
|
-
"p",
|
|
223
|
-
nodeProps(node, ctx, {
|
|
224
|
-
key,
|
|
225
|
-
className: `mq-h${node.level}`,
|
|
226
|
-
role: "heading",
|
|
227
|
-
"aria-level": node.level,
|
|
228
|
-
}),
|
|
229
|
-
...inner,
|
|
230
|
-
);
|
|
231
|
-
return withNotes(ctx, el, key);
|
|
232
|
-
}
|
|
229
|
+
case "heading":
|
|
230
|
+
return withNotes(ctx, headingEl(node, "p", ctx, key), key);
|
|
233
231
|
case "code_block": {
|
|
234
232
|
const lang = infoToken(node.info);
|
|
235
233
|
return h(
|
|
@@ -412,8 +410,12 @@ function directive(node: Node & { type: "directive" }, ctx: Ctx, key: string): R
|
|
|
412
410
|
// Built-ins that lay their children out themselves (table, stack) probe
|
|
413
411
|
// the hooks instead of rendering the children for them: rendering them
|
|
414
412
|
// twice per level is exponential in nesting, and a note would count twice.
|
|
415
|
-
if ((name === "table" || name === "stack") && !claimed("directive", name, attrs, ctx)) {
|
|
416
|
-
return name === "table"
|
|
413
|
+
if ((name === "table" || name === "stack" || name === "expand") && !claimed("directive", name, attrs, ctx)) {
|
|
414
|
+
return name === "table"
|
|
415
|
+
? renderTable(node, ctx, key)
|
|
416
|
+
: name === "stack"
|
|
417
|
+
? renderStack(node, ctx, key)
|
|
418
|
+
: renderExpand(node, ctx, key);
|
|
417
419
|
}
|
|
418
420
|
const kids = renderChildren(node.children, ctx);
|
|
419
421
|
|
|
@@ -525,6 +527,38 @@ function directive(node: Node & { type: "directive" }, ctx: Ctx, key: string): R
|
|
|
525
527
|
: h("div", nodeProps(node, ctx, { key, className: "mq-placeholder", "data-directive": name }));
|
|
526
528
|
}
|
|
527
529
|
|
|
530
|
+
/** :::expand - native <details>/<summary> (SPEC.md, "Expand"): the browser
|
|
531
|
+
* owns the fold, so there is no state here. The title is the first child
|
|
532
|
+
* when it is a paragraph (its inline content; the summary registers as that
|
|
533
|
+
* paragraph for scroll sync) or a heading (the heading itself, inside the
|
|
534
|
+
* summary); otherwise the browser supplies its own label. */
|
|
535
|
+
function renderExpand(node: Node & { type: "directive" }, ctx: Ctx, key: string): ReactNode {
|
|
536
|
+
const first = node.children[0];
|
|
537
|
+
if (first === undefined || (first.type !== "paragraph" && first.type !== "heading")) {
|
|
538
|
+
return h("details", nodeProps(node, ctx, { key, className: "mq-expand" }), ...renderChildren(node.children, ctx));
|
|
539
|
+
}
|
|
540
|
+
// A summary holds phrasing content or a heading: a deep heading is a span.
|
|
541
|
+
const summary =
|
|
542
|
+
first.type === "paragraph"
|
|
543
|
+
? h("summary", nodeProps(first, ctx, { key: "summary" }), ...renderChildren(first.children, ctx))
|
|
544
|
+
: h("summary", { key: "summary" }, headingEl(first, "span", ctx, "0"));
|
|
545
|
+
// A title's sidenotes land at the top of the body, just below it. Not
|
|
546
|
+
// withNotes: its wrapper would stop the summary being the details' first
|
|
547
|
+
// child, and a summary anywhere else is not a summary.
|
|
548
|
+
const pending = ctx.note.pending;
|
|
549
|
+
ctx.note.pending = [];
|
|
550
|
+
const notes =
|
|
551
|
+
pending.length === 0
|
|
552
|
+
? null
|
|
553
|
+
: h(
|
|
554
|
+
"aside",
|
|
555
|
+
{ key: "notes", className: "mq-notes" },
|
|
556
|
+
pending.map((n, i) => h("p", { key: i, className: "mq-note" }, n)),
|
|
557
|
+
);
|
|
558
|
+
const body = node.children.slice(1).map((child, i) => renderNode(child, ctx, String(i + 1)));
|
|
559
|
+
return h("details", nodeProps(node, ctx, { key, className: "mq-expand" }), summary, notes, ...body);
|
|
560
|
+
}
|
|
561
|
+
|
|
528
562
|
/** :::table - paragraph-rows, [c] cell spans (SPEC.md, "Tables"). */
|
|
529
563
|
function renderTable(node: Node & { type: "directive" }, ctx: Ctx, key: string): ReactNode {
|
|
530
564
|
const header = node.attrs["header"];
|