@cube-drone/marquee-react-renderer 0.7.2 → 0.8.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/dist/render.js +18 -3
- package/package.json +7 -7
- package/src/render.ts +26 -2
package/dist/render.js
CHANGED
|
@@ -10,7 +10,18 @@
|
|
|
10
10
|
// author bytes only ever reach it as a target string, which the hook escapes.
|
|
11
11
|
// Pass React-returning `hooks` instead to avoid the string path entirely.
|
|
12
12
|
import { createElement as h, useState } from "react";
|
|
13
|
-
import { FONTS, } from "@cube-drone/marquee-html-renderer";
|
|
13
|
+
import { FONTS, render as renderHtml, } from "@cube-drone/marquee-html-renderer";
|
|
14
|
+
/** The string-hook path for embedder vocabulary (no React hook supplied):
|
|
15
|
+
* probe with empty children - the contract says a claim never depends on
|
|
16
|
+
* them - and only for a claim pay for the children as HTML, through the
|
|
17
|
+
* html renderer under the same profile, so the hook can place them. Without
|
|
18
|
+
* this the hook saw "" and the span's words vanished behind innerHTML. */
|
|
19
|
+
function stringHook(hook, name, attrs, children, profile) {
|
|
20
|
+
if (hook(name, attrs, "") === null)
|
|
21
|
+
return null;
|
|
22
|
+
const childrenHtml = children.map((child) => renderHtml(child, profile)).join("");
|
|
23
|
+
return hook(name, attrs, childrenHtml);
|
|
24
|
+
}
|
|
14
25
|
/** Effects whose elements the visibility observer watches, and which the
|
|
15
26
|
* skip gesture stills. Named, closed: the vocabulary decides, not the DOM. */
|
|
16
27
|
const ANIMATED = new Set([
|
|
@@ -268,7 +279,9 @@ function directive(node, ctx, key) {
|
|
|
268
279
|
if (custom !== undefined && custom !== null) {
|
|
269
280
|
return h("div", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
|
|
270
281
|
}
|
|
271
|
-
const customHtml = ctx.hooks.directive === undefined
|
|
282
|
+
const customHtml = ctx.hooks.directive === undefined
|
|
283
|
+
? stringHook(ctx.profile.directive.bind(ctx.profile), name, attrs, node.children, ctx.profile)
|
|
284
|
+
: null;
|
|
272
285
|
if (customHtml !== null) {
|
|
273
286
|
return h("div", nodeProps(node, ctx, { key, style: { display: "contents" }, dangerouslySetInnerHTML: { __html: customHtml } }));
|
|
274
287
|
}
|
|
@@ -392,7 +405,9 @@ function span(node, ctx, key) {
|
|
|
392
405
|
if (custom !== undefined && custom !== null) {
|
|
393
406
|
return h("span", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
|
|
394
407
|
}
|
|
395
|
-
const customHtml = ctx.hooks.span === undefined
|
|
408
|
+
const customHtml = ctx.hooks.span === undefined
|
|
409
|
+
? stringHook(ctx.profile.span.bind(ctx.profile), name, attrs, node.children, ctx.profile)
|
|
410
|
+
: null;
|
|
396
411
|
if (customHtml !== null) {
|
|
397
412
|
return h("span", nodeProps(node, ctx, { key, dangerouslySetInnerHTML: { __html: customHtml } }));
|
|
398
413
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cube-drone/marquee-react-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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.
|
|
38
|
-
"@cube-drone/marquee-parser": "^0.
|
|
37
|
+
"@cube-drone/marquee-html-renderer": "^0.8.0",
|
|
38
|
+
"@cube-drone/marquee-parser": "^0.8.0"
|
|
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.
|
|
52
|
-
"@cube-drone/marquee-fonts": "^0.
|
|
53
|
-
"@cube-drone/marquee-emoji": "^0.
|
|
54
|
-
"@cube-drone/marquee-turbolink": "^0.
|
|
51
|
+
"@cube-drone/marquee-css": "^0.8.0",
|
|
52
|
+
"@cube-drone/marquee-fonts": "^0.8.0",
|
|
53
|
+
"@cube-drone/marquee-emoji": "^0.8.0",
|
|
54
|
+
"@cube-drone/marquee-turbolink": "^0.8.0"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/render.ts
CHANGED
|
@@ -14,11 +14,29 @@ import { createElement as h, useState, type KeyboardEvent, type ReactNode } from
|
|
|
14
14
|
import type { Attrs, Node, Span } from "@cube-drone/marquee-parser";
|
|
15
15
|
import {
|
|
16
16
|
FONTS,
|
|
17
|
+
render as renderHtml,
|
|
17
18
|
type EmojiResolution,
|
|
18
19
|
type Profile,
|
|
19
20
|
type TurbolinkLevel,
|
|
20
21
|
} from "@cube-drone/marquee-html-renderer";
|
|
21
22
|
|
|
23
|
+
/** The string-hook path for embedder vocabulary (no React hook supplied):
|
|
24
|
+
* probe with empty children - the contract says a claim never depends on
|
|
25
|
+
* them - and only for a claim pay for the children as HTML, through the
|
|
26
|
+
* html renderer under the same profile, so the hook can place them. Without
|
|
27
|
+
* this the hook saw "" and the span's words vanished behind innerHTML. */
|
|
28
|
+
function stringHook(
|
|
29
|
+
hook: (name: string, attrs: Attrs, renderedChildren: string) => string | null,
|
|
30
|
+
name: string,
|
|
31
|
+
attrs: Attrs,
|
|
32
|
+
children: Node[],
|
|
33
|
+
profile: Profile,
|
|
34
|
+
): string | null {
|
|
35
|
+
if (hook(name, attrs, "") === null) return null;
|
|
36
|
+
const childrenHtml = children.map((child) => renderHtml(child, profile)).join("");
|
|
37
|
+
return hook(name, attrs, childrenHtml);
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
/** React-returning versions of the rendering hooks. When present these win
|
|
23
41
|
* over the string-returning `Profile` hooks (no innerHTML at all). */
|
|
24
42
|
export interface ReactHooks {
|
|
@@ -367,7 +385,10 @@ function directive(node: Node & { type: "directive" }, ctx: Ctx, key: string): R
|
|
|
367
385
|
if (custom !== undefined && custom !== null) {
|
|
368
386
|
return h("div", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
|
|
369
387
|
}
|
|
370
|
-
const customHtml =
|
|
388
|
+
const customHtml =
|
|
389
|
+
ctx.hooks.directive === undefined
|
|
390
|
+
? stringHook(ctx.profile.directive.bind(ctx.profile), name, attrs, node.children, ctx.profile)
|
|
391
|
+
: null;
|
|
371
392
|
if (customHtml !== null) {
|
|
372
393
|
return h(
|
|
373
394
|
"div",
|
|
@@ -527,7 +548,10 @@ function span(node: Node & { type: "span" }, ctx: Ctx, key: string): ReactNode {
|
|
|
527
548
|
if (custom !== undefined && custom !== null) {
|
|
528
549
|
return h("span", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
|
|
529
550
|
}
|
|
530
|
-
const customHtml =
|
|
551
|
+
const customHtml =
|
|
552
|
+
ctx.hooks.span === undefined
|
|
553
|
+
? stringHook(ctx.profile.span.bind(ctx.profile), name, attrs, node.children, ctx.profile)
|
|
554
|
+
: null;
|
|
531
555
|
if (customHtml !== null) {
|
|
532
556
|
return h(
|
|
533
557
|
"span",
|