@cube-drone/marquee-react-renderer 0.7.1 → 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 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([
@@ -236,6 +247,10 @@ function embed(node, ctx, key) {
236
247
  if (media.kind === "audio") {
237
248
  return h("audio", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
238
249
  }
250
+ if (media.loop === true) {
251
+ // A silent animation: the gif's own manners - looping, muted, autoplaying, no controls.
252
+ return h("video", nodeProps(node, ctx, { ...common, src: media.url, autoPlay: true, loop: true, muted: true, playsInline: true }));
253
+ }
239
254
  return h("video", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
240
255
  }
241
256
  const TURBOLINK_LEVELS = new Set(["full", "title", "bare"]);
@@ -264,7 +279,9 @@ function directive(node, ctx, key) {
264
279
  if (custom !== undefined && custom !== null) {
265
280
  return h("div", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
266
281
  }
267
- const customHtml = ctx.hooks.directive === undefined ? ctx.profile.directive(name, attrs, "") : null;
282
+ const customHtml = ctx.hooks.directive === undefined
283
+ ? stringHook(ctx.profile.directive.bind(ctx.profile), name, attrs, node.children, ctx.profile)
284
+ : null;
268
285
  if (customHtml !== null) {
269
286
  return h("div", nodeProps(node, ctx, { key, style: { display: "contents" }, dangerouslySetInnerHTML: { __html: customHtml } }));
270
287
  }
@@ -388,7 +405,9 @@ function span(node, ctx, key) {
388
405
  if (custom !== undefined && custom !== null) {
389
406
  return h("span", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
390
407
  }
391
- const customHtml = ctx.hooks.span === undefined ? ctx.profile.span(name, attrs, "") : null;
408
+ const customHtml = ctx.hooks.span === undefined
409
+ ? stringHook(ctx.profile.span.bind(ctx.profile), name, attrs, node.children, ctx.profile)
410
+ : null;
392
411
  if (customHtml !== null) {
393
412
  return h("span", nodeProps(node, ctx, { key, dangerouslySetInnerHTML: { __html: customHtml } }));
394
413
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cube-drone/marquee-react-renderer",
3
- "version": "0.7.1",
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.7.1",
38
- "@cube-drone/marquee-parser": "^0.7.1"
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.7.1",
52
- "@cube-drone/marquee-fonts": "^0.7.1",
53
- "@cube-drone/marquee-emoji": "^0.7.1",
54
- "@cube-drone/marquee-turbolink": "^0.7.1"
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 {
@@ -312,6 +330,13 @@ function embed(node: Node & { type: "embed" }, ctx: Ctx, key: string): ReactNode
312
330
  if (media.kind === "audio") {
313
331
  return h("audio", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
314
332
  }
333
+ if (media.loop === true) {
334
+ // A silent animation: the gif's own manners - looping, muted, autoplaying, no controls.
335
+ return h(
336
+ "video",
337
+ nodeProps(node, ctx, { ...common, src: media.url, autoPlay: true, loop: true, muted: true, playsInline: true }),
338
+ );
339
+ }
315
340
  return h("video", nodeProps(node, ctx, { ...common, src: media.url, controls: true }));
316
341
  }
317
342
 
@@ -360,7 +385,10 @@ function directive(node: Node & { type: "directive" }, ctx: Ctx, key: string): R
360
385
  if (custom !== undefined && custom !== null) {
361
386
  return h("div", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
362
387
  }
363
- const customHtml = ctx.hooks.directive === undefined ? ctx.profile.directive(name, attrs, "") : null;
388
+ const customHtml =
389
+ ctx.hooks.directive === undefined
390
+ ? stringHook(ctx.profile.directive.bind(ctx.profile), name, attrs, node.children, ctx.profile)
391
+ : null;
364
392
  if (customHtml !== null) {
365
393
  return h(
366
394
  "div",
@@ -520,7 +548,10 @@ function span(node: Node & { type: "span" }, ctx: Ctx, key: string): ReactNode {
520
548
  if (custom !== undefined && custom !== null) {
521
549
  return h("span", nodeProps(node, ctx, { key, style: { display: "contents" } }), custom);
522
550
  }
523
- const customHtml = ctx.hooks.span === undefined ? ctx.profile.span(name, attrs, "") : null;
551
+ const customHtml =
552
+ ctx.hooks.span === undefined
553
+ ? stringHook(ctx.profile.span.bind(ctx.profile), name, attrs, node.children, ctx.profile)
554
+ : null;
524
555
  if (customHtml !== null) {
525
556
  return h(
526
557
  "span",