@airalogy/aimd-renderer 2.4.1

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/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @airalogy/aimd-renderer
2
+
3
+ Rendering engine for AIMD: HTML output, Vue output, and field extraction.
4
+
5
+ Assigner blocks are hidden from normal rendered output by default. You can opt into collapsed or expanded assigner display when building authoring/debug views, while extracted field metadata remains available through `parseAndExtract`.
6
+
7
+ > Protocol-level AIMD syntax, assigner semantics, and validation rules are normative in Airalogy docs. `@airalogy/aimd-*` docs describe how the frontend parser, renderer, and recorder implement those rules.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @airalogy/aimd-renderer @airalogy/aimd-core
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```ts
18
+ import { renderToHtml, parseAndExtract } from "@airalogy/aimd-renderer"
19
+
20
+ const content = "{{step|sample_preparation}}"
21
+ const { html } = await renderToHtml(content)
22
+ const fields = parseAndExtract(content)
23
+
24
+ console.log(html)
25
+ console.log(fields)
26
+ ```
27
+
28
+ ## Assigner Visibility
29
+
30
+ ```ts
31
+ import { renderToHtml } from "@airalogy/aimd-renderer"
32
+
33
+ const { html } = await renderToHtml(content, {
34
+ assignerVisibility: "collapsed", // "hidden" | "collapsed" | "expanded"
35
+ })
36
+ ```
37
+
38
+ `assignerVisibility` defaults to `"hidden"`.
39
+
40
+ ## Localization
41
+
42
+ ```ts
43
+ import { renderToHtml } from "@airalogy/aimd-renderer"
44
+
45
+ const content = "{{quiz|q1}}"
46
+
47
+ const { html } = await renderToHtml(content, {
48
+ locale: "zh-CN",
49
+ })
50
+ ```
51
+
52
+ ## Host Custom Elements
53
+
54
+ ```ts
55
+ import {
56
+ createCustomElementAimdRenderer,
57
+ renderToHtml,
58
+ } from "@airalogy/aimd-renderer"
59
+
60
+ const { html } = await renderToHtml("{{step|verify, 2, title='Verify Output', check=True}}", {
61
+ groupStepBodies: true,
62
+ aimdElementRenderers: {
63
+ step: createCustomElementAimdRenderer("step-card", (node) => ({
64
+ "step-id": node.id,
65
+ "step-number": (node as any).step,
66
+ title: (node as any).title,
67
+ level: String((node as any).level),
68
+ "has-check": (node as any).check ? "true" : undefined,
69
+ }), {
70
+ container: true,
71
+ stripDefaultChildren: true,
72
+ }),
73
+ },
74
+ })
75
+ ```
76
+
77
+ This is intended for host apps that already have their own preview components and need AIMD HTML output to target those custom elements directly. Enable `groupStepBodies` when step containers should absorb following block content as their body/slot.
78
+
79
+ ## Reusable Step Card UI
80
+
81
+ ```ts
82
+ import { createStepCardRenderer, renderToVue } from "@airalogy/aimd-renderer"
83
+
84
+ const { nodes } = await renderToVue(content, {
85
+ groupStepBodies: true,
86
+ aimdRenderers: {
87
+ step: createStepCardRenderer(),
88
+ },
89
+ })
90
+ ```
91
+
92
+ Use this when you want a ready-made Vue step-card surface without first mapping AIMD nodes into your own custom elements.
93
+
94
+ Math styles are loaded automatically when calling async render APIs (`renderToHtml` / `renderToVue`) in browser environments.
95
+ Use `@airalogy/aimd-renderer/styles` only if you want to preload styles manually.
96
+
97
+ ## Documentation
98
+
99
+ - EN: <https://airalogy.github.io/aimd/en/packages/aimd-renderer>
100
+ - 中文: <https://airalogy.github.io/aimd/zh/packages/aimd-renderer>
101
+ - Source docs: `aimd/docs/en/packages/aimd-renderer.md`, `aimd/docs/zh/packages/aimd-renderer.md`
102
+
103
+ ## Citation
104
+
105
+ If `@airalogy/aimd-renderer` is useful in your work, please cite the Airalogy paper:
106
+
107
+ ```bibtex
108
+ @misc{yang2025airalogyaiempowereduniversaldata,
109
+ title={Airalogy: AI-empowered universal data digitization for research automation},
110
+ author={Zijie Yang and Qiji Zhou and Fang Guo and Sijie Zhang and Yexun Xi and Jinglei Nie and Yudian Zhu and Liping Huang and Chou Wu and Yonghe Xia and Xiaoyu Ma and Yingming Pu and Panzhong Lu and Junshu Pan and Mingtao Chen and Tiannan Guo and Yanmei Dou and Hongyu Chen and Anping Zeng and Jiaxing Huang and Tian Xu and Yue Zhang},
111
+ year={2025},
112
+ eprint={2506.18586},
113
+ archivePrefix={arXiv},
114
+ primaryClass={cs.AI},
115
+ url={https://arxiv.org/abs/2506.18586},
116
+ }
117
+ ```
@@ -0,0 +1,101 @@
1
+ # @airalogy/aimd-renderer
2
+
3
+ AIMD 渲染引擎:支持 HTML 渲染、Vue 渲染与字段提取。
4
+
5
+ 默认情况下,assigner 代码块不会出现在普通渲染输出中。只有在作者视图或调试视图中显式开启时,才会以折叠或展开形式显示;`parseAndExtract` 仍会保留相关字段元数据。
6
+
7
+ > 协议级 AIMD 语法、assigner 语义与校验规则以 Airalogy 文档为准;`@airalogy/aimd-*` 文档只描述前端 parser、renderer、recorder 如何实现这些规范。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ pnpm add @airalogy/aimd-renderer @airalogy/aimd-core
13
+ ```
14
+
15
+ ## 快速开始
16
+
17
+ ```ts
18
+ import { renderToHtml, parseAndExtract } from "@airalogy/aimd-renderer"
19
+
20
+ const content = "{{step|sample_preparation}}"
21
+ const { html } = await renderToHtml(content)
22
+ const fields = parseAndExtract(content)
23
+
24
+ console.log(html)
25
+ console.log(fields)
26
+ ```
27
+
28
+ ## Assigner 可见性
29
+
30
+ ```ts
31
+ import { renderToHtml } from "@airalogy/aimd-renderer"
32
+
33
+ const { html } = await renderToHtml(content, {
34
+ assignerVisibility: "collapsed", // "hidden" | "collapsed" | "expanded"
35
+ })
36
+ ```
37
+
38
+ `assignerVisibility` 默认值是 `"hidden"`。
39
+
40
+ ## 本地化
41
+
42
+ ```ts
43
+ import { renderToHtml } from "@airalogy/aimd-renderer"
44
+
45
+ const content = "{{quiz|q1}}"
46
+
47
+ const { html } = await renderToHtml(content, {
48
+ locale: "zh-CN",
49
+ })
50
+ ```
51
+
52
+ ## 宿主自定义元素
53
+
54
+ ```ts
55
+ import {
56
+ createCustomElementAimdRenderer,
57
+ renderToHtml,
58
+ } from "@airalogy/aimd-renderer"
59
+
60
+ const { html } = await renderToHtml("{{step|verify, 2, title='Verify Output', check=True}}", {
61
+ groupStepBodies: true,
62
+ aimdElementRenderers: {
63
+ step: createCustomElementAimdRenderer("step-card", (node) => ({
64
+ "step-id": node.id,
65
+ "step-number": (node as any).step,
66
+ title: (node as any).title,
67
+ level: String((node as any).level),
68
+ "has-check": (node as any).check ? "true" : undefined,
69
+ }), {
70
+ container: true,
71
+ stripDefaultChildren: true,
72
+ }),
73
+ },
74
+ })
75
+ ```
76
+
77
+ 当宿主应用已经有自己的预览组件时,可以用这种方式把 AIMD HTML 输出直接映射到自定义元素。若希望步骤节点把后续块级正文一起吸收到 body / slot 中,请启用 `groupStepBodies`。
78
+
79
+ ## 可复用 Step Card UI
80
+
81
+ ```ts
82
+ import { createStepCardRenderer, renderToVue } from "@airalogy/aimd-renderer"
83
+
84
+ const { nodes } = await renderToVue(content, {
85
+ groupStepBodies: true,
86
+ aimdRenderers: {
87
+ step: createStepCardRenderer(),
88
+ },
89
+ })
90
+ ```
91
+
92
+ 当你想直接得到现成的 Vue 步骤卡片渲染,而不是先把 AIMD 节点映射到自定义元素时,可以使用这组 API。
93
+
94
+ 在浏览器环境中调用异步渲染 API(`renderToHtml` / `renderToVue`)时,会自动加载公式样式。
95
+ 只有在你希望手动预加载样式时,才需要引入 `@airalogy/aimd-renderer/styles`。
96
+
97
+ ## 文档
98
+
99
+ - EN: <https://airalogy.github.io/aimd/en/packages/aimd-renderer>
100
+ - 中文: <https://airalogy.github.io/aimd/zh/packages/aimd-renderer>
101
+ - 文档源码:`aimd/docs/en/packages/aimd-renderer.md`、`aimd/docs/zh/packages/aimd-renderer.md`