@cube-drone/marquee-react-renderer 0.9.1 → 0.9.3
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 +13 -6
- package/package.json +7 -7
- package/src/render.ts +14 -6
package/dist/render.js
CHANGED
|
@@ -182,7 +182,7 @@ export function renderNode(node, ctx, key) {
|
|
|
182
182
|
case "link": {
|
|
183
183
|
const inner = renderChildren(node.children, ctx);
|
|
184
184
|
return ctx.profile.linkAllowed(node.target)
|
|
185
|
-
? h("a", nodeProps(node, ctx, { key, href: node.target }), ...inner)
|
|
185
|
+
? h("a", nodeProps(node, ctx, { key, href: href(node.target, ctx) }), ...inner)
|
|
186
186
|
: h("span", nodeProps(node, ctx, { key, className: "mq-blocked" }), ...inner);
|
|
187
187
|
}
|
|
188
188
|
case "embed":
|
|
@@ -245,19 +245,26 @@ function embed(node, ctx, key) {
|
|
|
245
245
|
return h("span", nodeProps(node, ctx, { key, className: "mq-placeholder" }), node.alt === "" ? node.target : node.alt);
|
|
246
246
|
}
|
|
247
247
|
const common = { key, className: "mq-embed" };
|
|
248
|
+
// Audio and video have no alt attribute; the description labels them for
|
|
249
|
+
// assistive tech instead, as the static renderer does.
|
|
250
|
+
const label = { "aria-label": node.alt === "" ? undefined : node.alt };
|
|
248
251
|
if (media.kind === "image") {
|
|
249
252
|
return h("img", nodeProps(node, ctx, { ...common, src: media.url, alt: node.alt, loading: "lazy" }));
|
|
250
253
|
}
|
|
251
254
|
if (media.kind === "audio") {
|
|
252
|
-
return h("audio", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
|
|
255
|
+
return h("audio", nodeProps(node, ctx, { ...common, ...label, src: media.url, controls: true }));
|
|
253
256
|
}
|
|
254
257
|
if (media.loop === true) {
|
|
255
258
|
// A silent animation: the gif's own manners - looping, muted, autoplaying, no controls.
|
|
256
|
-
return h("video", nodeProps(node, ctx, { ...common, src: media.url, autoPlay: true, loop: true, muted: true, playsInline: true }));
|
|
259
|
+
return h("video", nodeProps(node, ctx, { ...common, ...label, src: media.url, autoPlay: true, loop: true, muted: true, playsInline: true }));
|
|
257
260
|
}
|
|
258
|
-
return h("video", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
|
|
261
|
+
return h("video", nodeProps(node, ctx, { ...common, ...label, src: media.url, controls: true }));
|
|
259
262
|
}
|
|
260
263
|
const TURBOLINK_LEVELS = new Set(["full", "title", "bare"]);
|
|
264
|
+
/** Where an allowed link points: the profile's rewrite, or the target. */
|
|
265
|
+
function href(target, ctx) {
|
|
266
|
+
return ctx.profile.linkTarget?.(target) ?? target;
|
|
267
|
+
}
|
|
261
268
|
function turbolink(node, target, levelAttr, ctx, key) {
|
|
262
269
|
if (!ctx.profile.linkAllowed(target)) {
|
|
263
270
|
return h("p", nodeProps(node, ctx, { key, className: "mq-turbolink" }), target);
|
|
@@ -271,10 +278,10 @@ function turbolink(node, target, levelAttr, ctx, key) {
|
|
|
271
278
|
if (react !== null || html !== null) {
|
|
272
279
|
// Enrichment augments, never replaces: the wrapper carries the
|
|
273
280
|
// original link, so no plugin can eat it - not even by accident.
|
|
274
|
-
return h("div", nodeProps(node, ctx, { key, className: "mq-turbolink mq-turbolink-rich" }), react ?? trustedHtml("span", html, "rich"), h("a", { key: "src", className: "mq-turbolink-source", href: target }, target));
|
|
281
|
+
return h("div", nodeProps(node, ctx, { key, className: "mq-turbolink mq-turbolink-rich" }), react ?? trustedHtml("span", html, "rich"), h("a", { key: "src", className: "mq-turbolink-source", href: href(target, ctx) }, target));
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
|
-
return h("p", nodeProps(node, ctx, { key, className: "mq-turbolink" }), h("a", { href: target }, target));
|
|
284
|
+
return h("p", nodeProps(node, ctx, { key, className: "mq-turbolink" }), h("a", { href: href(target, ctx) }, target));
|
|
278
285
|
}
|
|
279
286
|
function directive(node, ctx, key) {
|
|
280
287
|
const { name, attrs } = node;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cube-drone/marquee-react-renderer",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
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.9.
|
|
38
|
-
"@cube-drone/marquee-parser": "^0.9.
|
|
37
|
+
"@cube-drone/marquee-html-renderer": "^0.9.3",
|
|
38
|
+
"@cube-drone/marquee-parser": "^0.9.3"
|
|
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.9.
|
|
52
|
-
"@cube-drone/marquee-fonts": "^0.9.
|
|
53
|
-
"@cube-drone/marquee-emoji": "^0.9.
|
|
54
|
-
"@cube-drone/marquee-turbolink": "^0.9.
|
|
51
|
+
"@cube-drone/marquee-css": "^0.9.3",
|
|
52
|
+
"@cube-drone/marquee-fonts": "^0.9.3",
|
|
53
|
+
"@cube-drone/marquee-emoji": "^0.9.3",
|
|
54
|
+
"@cube-drone/marquee-turbolink": "^0.9.3"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/render.ts
CHANGED
|
@@ -254,7 +254,7 @@ export function renderNode(node: Node, ctx: Ctx, key: string): ReactNode {
|
|
|
254
254
|
case "link": {
|
|
255
255
|
const inner = renderChildren(node.children, ctx);
|
|
256
256
|
return ctx.profile.linkAllowed(node.target)
|
|
257
|
-
? h("a", nodeProps(node, ctx, { key, href: node.target }), ...inner)
|
|
257
|
+
? h("a", nodeProps(node, ctx, { key, href: href(node.target, ctx) }), ...inner)
|
|
258
258
|
: h("span", nodeProps(node, ctx, { key, className: "mq-blocked" }), ...inner);
|
|
259
259
|
}
|
|
260
260
|
case "embed":
|
|
@@ -332,24 +332,32 @@ function embed(node: Node & { type: "embed" }, ctx: Ctx, key: string): ReactNode
|
|
|
332
332
|
);
|
|
333
333
|
}
|
|
334
334
|
const common = { key, className: "mq-embed" };
|
|
335
|
+
// Audio and video have no alt attribute; the description labels them for
|
|
336
|
+
// assistive tech instead, as the static renderer does.
|
|
337
|
+
const label = { "aria-label": node.alt === "" ? undefined : node.alt };
|
|
335
338
|
if (media.kind === "image") {
|
|
336
339
|
return h("img", nodeProps(node, ctx, { ...common, src: media.url, alt: node.alt, loading: "lazy" }));
|
|
337
340
|
}
|
|
338
341
|
if (media.kind === "audio") {
|
|
339
|
-
return h("audio", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
|
|
342
|
+
return h("audio", nodeProps(node, ctx, { ...common, ...label, src: media.url, controls: true }));
|
|
340
343
|
}
|
|
341
344
|
if (media.loop === true) {
|
|
342
345
|
// A silent animation: the gif's own manners - looping, muted, autoplaying, no controls.
|
|
343
346
|
return h(
|
|
344
347
|
"video",
|
|
345
|
-
nodeProps(node, ctx, { ...common, src: media.url, autoPlay: true, loop: true, muted: true, playsInline: true }),
|
|
348
|
+
nodeProps(node, ctx, { ...common, ...label, src: media.url, autoPlay: true, loop: true, muted: true, playsInline: true }),
|
|
346
349
|
);
|
|
347
350
|
}
|
|
348
|
-
return h("video", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
|
|
351
|
+
return h("video", nodeProps(node, ctx, { ...common, ...label, src: media.url, controls: true }));
|
|
349
352
|
}
|
|
350
353
|
|
|
351
354
|
const TURBOLINK_LEVELS = new Set<TurbolinkLevel>(["full", "title", "bare"]);
|
|
352
355
|
|
|
356
|
+
/** Where an allowed link points: the profile's rewrite, or the target. */
|
|
357
|
+
function href(target: string, ctx: Ctx): string {
|
|
358
|
+
return ctx.profile.linkTarget?.(target) ?? target;
|
|
359
|
+
}
|
|
360
|
+
|
|
353
361
|
function turbolink(
|
|
354
362
|
node: Node,
|
|
355
363
|
target: string,
|
|
@@ -374,14 +382,14 @@ function turbolink(
|
|
|
374
382
|
"div",
|
|
375
383
|
nodeProps(node, ctx, { key, className: "mq-turbolink mq-turbolink-rich" }),
|
|
376
384
|
react ?? trustedHtml("span", html!, "rich"),
|
|
377
|
-
h("a", { key: "src", className: "mq-turbolink-source", href: target }, target),
|
|
385
|
+
h("a", { key: "src", className: "mq-turbolink-source", href: href(target, ctx) }, target),
|
|
378
386
|
);
|
|
379
387
|
}
|
|
380
388
|
}
|
|
381
389
|
return h(
|
|
382
390
|
"p",
|
|
383
391
|
nodeProps(node, ctx, { key, className: "mq-turbolink" }),
|
|
384
|
-
h("a", { href: target }, target),
|
|
392
|
+
h("a", { href: href(target, ctx) }, target),
|
|
385
393
|
);
|
|
386
394
|
}
|
|
387
395
|
|