schematex 0.6.7 → 0.6.9

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.
Files changed (33) hide show
  1. package/README.md +101 -6
  2. package/README.zh-CN.md +783 -0
  3. package/dist/ai/ai-sdk.cjs +8 -8
  4. package/dist/ai/ai-sdk.d.cts +1 -1
  5. package/dist/ai/ai-sdk.d.ts +1 -1
  6. package/dist/ai/ai-sdk.js +3 -3
  7. package/dist/ai/index.cjs +14 -14
  8. package/dist/ai/index.js +3 -3
  9. package/dist/browser.cjs +9 -9
  10. package/dist/browser.js +3 -3
  11. package/dist/{chunk-WK36Z63Y.cjs → chunk-25TO5A4F.cjs} +5 -5
  12. package/dist/{chunk-WK36Z63Y.cjs.map → chunk-25TO5A4F.cjs.map} +1 -1
  13. package/dist/{chunk-WAKRRGAV.js → chunk-2TUZ3QJA.js} +110 -2
  14. package/dist/chunk-2TUZ3QJA.js.map +1 -0
  15. package/dist/{chunk-TRUJ4Q6V.js → chunk-3DPWFWQU.js} +41 -12
  16. package/dist/{chunk-TRUJ4Q6V.js.map → chunk-3DPWFWQU.js.map} +1 -1
  17. package/dist/{chunk-LDONE225.cjs → chunk-5IZL57YJ.cjs} +42 -13
  18. package/dist/{chunk-LDONE225.cjs.map → chunk-5IZL57YJ.cjs.map} +1 -1
  19. package/dist/{chunk-QBS4F44Q.cjs → chunk-J3EPFZPX.cjs} +110 -2
  20. package/dist/chunk-J3EPFZPX.cjs.map +1 -0
  21. package/dist/{chunk-EVEPI423.js → chunk-Q5V4LUQR.js} +3 -3
  22. package/dist/{chunk-EVEPI423.js.map → chunk-Q5V4LUQR.js.map} +1 -1
  23. package/dist/diagrams/circuit/index.cjs +8 -8
  24. package/dist/diagrams/circuit/index.d.cts +0 -9
  25. package/dist/diagrams/circuit/index.d.ts +0 -9
  26. package/dist/diagrams/circuit/index.js +1 -1
  27. package/dist/index.cjs +27 -27
  28. package/dist/index.js +4 -4
  29. package/dist/react.cjs +3 -3
  30. package/dist/react.js +2 -2
  31. package/package.json +5 -5
  32. package/dist/chunk-QBS4F44Q.cjs.map +0 -1
  33. package/dist/chunk-WAKRRGAV.js.map +0 -1
@@ -0,0 +1,783 @@
1
+ <p align="center">
2
+ <strong>Schematex</strong><br>
3
+ <em>Every diagram a doctor, engineer, or lawyer would actually use.</em><br>
4
+ <em>Free. Fully open source. Made for AI.</em>
5
+ </p>
6
+
7
+ <p align="center">
8
+ McGoldrick 家系图 · NSGC 遗传谱系图 · IEC 61131-3 梯形图 · IEEE 315 单线图 · Newick 系统发育树 · Howard-Raiffa 决策树 · Moreno 社交图 —— 全部由一套极简文本 DSL 生成,零运行时依赖。
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://schematex.dev">官网</a> ·
13
+ <a href="https://schematex.dev/playground">Playground</a> ·
14
+ <a href="https://schematex.dev/docs">文档</a> ·
15
+ <a href="https://www.npmjs.com/package/schematex">npm</a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="./README.md">English</a> · <strong>简体中文</strong>
20
+ </p>
21
+
22
+ <p align="center">
23
+ <a href="https://www.npmjs.com/package/schematex"><img src="https://img.shields.io/npm/v/schematex.svg?color=cb3837&label=npm" alt="npm"></a>
24
+ <a href="https://bundlephobia.com/package/schematex"><img src="https://img.shields.io/bundlephobia/minzip/schematex?label=gzip" alt="bundle size"></a>
25
+ <img src="https://img.shields.io/badge/deps-0-brightgreen" alt="zero deps">
26
+ <img src="https://img.shields.io/badge/TypeScript-strict-3178c6" alt="typescript strict">
27
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-AGPL--3.0-blue" alt="license"></a>
28
+ </p>
29
+
30
+ <p align="center">
31
+ <img src="./website/public/hero-demo.gif" alt="Schematex demo — genogram, pedigree, ladder logic, phylo, entity structure, fishbone, circuit, ecomap, timing" width="720">
32
+ </p>
33
+
34
+ ---
35
+
36
+ **Schematex** 是一个开源渲染引擎,专门画那些专业人士**真正在用**的图 —— 医学、电气、法律、分析领域。**36 种图**,覆盖医学、工程、法律与分析:
37
+
38
+ - 👪 **关系类** —— 家系图(genogram)、生态图(ecomap)、遗传谱系图(pedigree)、社交图(sociogram)、系统发育树(phylo)
39
+ - ⚡ **电气与工业** —— 梯形图(ladder)、单线图(SLD)、电路原理图(circuit)、逻辑门(logic)、时序图(timing)、方框图(block)、**FBD**、**SFC**、面包板(breadboard)、**P&ID**(ISA-5.1)
40
+ - 🔄 **行为与流程建模** —— UML 2.5 / Harel **状态图**(Mermaid 兼容超集)、**BPMN 2.0**(OMG)、**用例图**(UML 2.5.1 §18)、**时序图**(UML 2.5.1 §17 —— 全部 12 种组合片段 + `ref`)
41
+ - 🧩 **软件与数据建模** —— **UML 类图**(UML 2.5.1 §9–§11,命名空间 + 6 种关系)、**ERD** 鸦爪记法
42
+ - 🏢 **公司与法律** —— 实体结构图(entity)、股权结构表(cap table)、组织架构图(orgchart)
43
+ - 🐟 **因果与分析** —— 鱼骨图 / Ishikawa(fishbone)、决策树(Howard-Raiffa EV · CART/sklearn · 分类法)、Venn / Euler 图
44
+ - 🛡️ **风险与可靠性** —— **故障树**(NUREG-0492 / IEC 61025),引擎*计算* MOCUS 最小割集 + P(top);**领结图 bowtie** 基于屏障的风险管理(CCPS / Energy Institute 2018)
45
+ - 🗓️ **项目管理** —— **PERT / CPM** 网络图(PMBOK 7),引擎*计算*进度:ES/EF/LS/LF、时差、关键路径、三点估算、泳道、时间刻度布局
46
+ - 🖧 **网络与基础设施** —— **网络拓扑图**(Cisco 约定图标),设备 / 链路 / 端口完整性校验、IP 网络摄像机系统、三层园区网、spine-leaf 架构、子网与 VLAN
47
+ - ◉ **并发** —— **Petri 网**(Murata 1989 / ISO-IEC 15909),引擎*计算*使能状态并按序列触发 token
48
+ - 🔬 **研究综述** —— **PRISMA 2020** 系统综述流程图
49
+ - 📅 **时间线** —— 比例 / 等距 / 对数轴 · 泳道 · 甘特 · 棒棒糖 · 公元前日期 · 地质 Ma 刻度
50
+ - 🧠 **知识与策略** —— 思维导图(mindmap)、2×2 / N×M 矩阵(matrix)、流程图(flowchart)
51
+
52
+ Mermaid 画的是通用流程图。Schematex 画的是医生、工程师、律师真正会用的图 —— 一张遗传咨询师在临床上认可的家系图、一份与 IEC 61131-3 一一对应的梯形图、一张能扛过 Series A 尽调的股权结构表。
53
+
54
+ 🆓 **免费且完全开源** · 📐 **10+ 行业标准** · 🤖 **为 AI 而生** · 🌱 **SSR 友好的纯 SVG · 零依赖**
55
+
56
+ ## 安装
57
+
58
+ ```bash
59
+ npm install schematex
60
+ ```
61
+
62
+ ## 快速开始
63
+
64
+ ```ts
65
+ import { render } from 'schematex';
66
+
67
+ const svg = render(`
68
+ genogram "The Smiths"
69
+ john [male, 1950]
70
+ mary [female, 1952]
71
+ john -- mary
72
+ alice [female, 1975, index]
73
+ bob [male, 1978]
74
+ `);
75
+ ```
76
+
77
+ 图的类型由第一个关键字自动推断。按需引入即可 tree-shake:
78
+
79
+ ```ts
80
+ import { render } from 'schematex/genogram';
81
+ ```
82
+
83
+ ## 图库
84
+
85
+ 全部 36 种图共用同一条渲染管线,下面展示其中一部分 —— **在 [schematex.dev/playground](https://schematex.dev/playground) 实时试用任意一种。**
86
+
87
+ ### 👪 家系图 Genogram —— *McGoldrick 家庭系统标准*
88
+
89
+ 用于治疗、社工、医学的多代家族树。性别专属形状、疾病填充、情感关系连线、索引人标记。
90
+
91
+ ```
92
+ genogram "The Potter Family"
93
+ fleamont [male, 1909, 1979, deceased]
94
+ euphemia [female, 1920, 1979, deceased]
95
+ fleamont -- euphemia
96
+ james [male, 1960, 1981, deceased]
97
+ mr_evans [male, 1925, deceased]
98
+ mrs_evans [female, 1928, deceased]
99
+ mr_evans -- mrs_evans
100
+ lily [female, 1960, 1981, deceased]
101
+ petunia [female, 1958]
102
+ james -- lily "m. 1978"
103
+ harry [male, 1980, index]
104
+ petunia -- vernon [male, 1951]
105
+ dudley [male, 1980]
106
+ harry -cutoff- petunia
107
+ harry -hostile- dudley
108
+ harry -close- lily
109
+ ```
110
+
111
+ ![Harry Potter Genogram](examples/genogram/harry-potter.svg)
112
+
113
+ [家系图语法 →](https://schematex.dev/docs/genogram)
114
+
115
+ ---
116
+
117
+ ### 🌐 生态图 Ecomap —— *Hartman 1978 标准*
118
+
119
+ 把家庭系统嵌入到机构、社会、文化支持网络中。径向布局、加权连接强度、能量流向。
120
+
121
+ ```
122
+ ecomap "Nguyen Family Resettlement"
123
+ center: family [label: "Nguyen Family"]
124
+ resettlement [label: "IRC Office", category: government]
125
+ school [label: "Lincoln Elementary", category: education]
126
+ clinic [label: "Community Clinic", category: health]
127
+ temple [label: "Vietnamese Temple", category: cultural]
128
+ neighbors [label: "Sponsor Family", category: community]
129
+ family === resettlement [label: "active case"]
130
+ family === school
131
+ clinic --> family [label: "vaccinations"]
132
+ family === temple [label: "anchor"]
133
+ neighbors === family [label: "housing host"]
134
+ ```
135
+
136
+ ![Nguyen Family Ecomap](examples/ecomap/refugee-family.svg)
137
+
138
+ [生态图语法 →](https://schematex.dev/docs/ecomap)
139
+
140
+ ---
141
+
142
+ ### 🧬 遗传谱系图 Pedigree —— *标准化人类谱系命名法*
143
+
144
+ 临床遗传学的多代遗传图。患病 / 携带者 / 症状前状态填充、先证者箭头、近亲婚配。
145
+
146
+ ```
147
+ pedigree "BRCA1 Family — Hereditary Breast/Ovarian Cancer"
148
+ I-1 [male, unaffected]
149
+ I-2 [female, affected, deceased]
150
+ I-1 -- I-2
151
+ II-1 [female, affected]
152
+ II-3 [female, carrier]
153
+ II-1 -- II-4 [male, unaffected]
154
+ III-1 [female, affected, proband]
155
+ III-3 [female, presymptomatic]
156
+ ```
157
+
158
+ ![BRCA1 Pedigree](examples/pedigree/brca-family.svg)
159
+
160
+ [谱系图语法 →](https://schematex.dev/docs/pedigree)
161
+
162
+ ---
163
+
164
+ ### 🌿 系统发育树 Phylogenetic tree —— *Newick + NHX*
165
+
166
+ 进化树,支持 clade 着色、自展支持值(bootstrap)、比例分支长度,以及基于缩进的 DSL 写法。
167
+
168
+ ```
169
+ phylo "Bacterial Diversity"
170
+ newick: "((((Ecoli:0.1,Salmonella:0.12):0.05[&&NHX:B=98],Vibrio:0.2):0.08,((Bacillus:0.15,Staph:0.18):0.06[&&NHX:B=92],Listeria:0.22):0.1):0.15,((Myco_tb:0.3,Myco_leprae:0.28):0.12[&&NHX:B=100],(Strepto:0.25,Lactobacillus:0.2):0.08):0.2);"
171
+ clade Gamma = (Ecoli, Salmonella, Vibrio) [color: "#1E88E5", label: "γ-Proteobacteria"]
172
+ clade Firmi = (Bacillus, Staph, Listeria) [color: "#E53935", label: "Firmicutes"]
173
+ scale "substitutions/site"
174
+ ```
175
+
176
+ ![Bacterial Diversity Phylogenetic Tree](examples/phylo/bacterial-diversity.svg)
177
+
178
+ [系统发育树语法 →](https://schematex.dev/docs/phylo)
179
+
180
+ ---
181
+
182
+ ### 🕸 社交图 Sociogram —— *Moreno 社会计量学*
183
+
184
+ 社会网络图,支持互选、排斥、群组着色。力导向或层级布局。自动检测明星节点、孤立点、小团体。
185
+
186
+ ```
187
+ sociogram "Operation Sunset - Communication Network"
188
+ config: layout = force-directed
189
+ boss [label: "Subject Alpha"]
190
+ lt1 [label: "Lieutenant 1"]
191
+ lt2 [label: "Lieutenant 2"]
192
+ courier1 [label: "Courier A"]
193
+ courier2 [label: "Courier B"]
194
+ contact1 [label: "External Contact 1"]
195
+ contact2 [label: "External Contact 2"]
196
+ associate1 [label: "Associate 1"]
197
+ associate2 [label: "Associate 2"]
198
+ boss <-> lt1 [weight: 4]
199
+ boss <-> lt2 [weight: 4]
200
+ lt1 -> courier1
201
+ lt1 -> courier2
202
+ lt2 -> associate1
203
+ lt2 -> associate2
204
+ courier1 -> contact1 [label: "supplier"]
205
+ courier2 -> contact2 [label: "distributor"]
206
+ lt1 <-> lt2 [weight: 2]
207
+ associate1 -.- courier1
208
+ ```
209
+
210
+ ![Operation Sunset Sociogram](examples/sociogram/criminal-network.svg)
211
+
212
+ [社交图语法 →](https://schematex.dev/docs/sociogram)
213
+
214
+ ---
215
+
216
+ ### ⏱ 时序图 Timing diagram —— *WaveDrom 兼容*
217
+
218
+ 数字波形,支持时钟脉冲、总线段、高阻态、分组标签。
219
+
220
+ ```
221
+ timing "SPI Transaction"
222
+ CLK: pppppppp
223
+ CS_N: 10000001
224
+ MOSI: x======= data: ["0xAB","0xCD","0xEF","0x01","0x02","0x03","0x04","0x05"]
225
+ MISO: zzzz==== data: ["","","","","0xFF","0x12","0x34","0x56"]
226
+ ```
227
+
228
+ ![SPI Transaction Timing Diagram](examples/timing/spi-transaction.svg)
229
+
230
+ [时序图语法 →](https://schematex.dev/docs/timing)
231
+
232
+ ---
233
+
234
+ ### 🔌 逻辑门 Logic gate —— *IEEE 91 & IEC 60617*
235
+
236
+ 组合与时序逻辑,自动 DAG 布局 + 曼哈顿走线。
237
+
238
+ ```
239
+ logic "1-bit Full Adder"
240
+ input A, B, Cin
241
+ output Sum, Cout
242
+ s1 = XOR(A, B)
243
+ Sum = XOR(s1, Cin)
244
+ c1 = AND(A, B)
245
+ c2 = AND(s1, Cin)
246
+ Cout = OR(c1, c2)
247
+ ```
248
+
249
+ ![1-bit Full Adder Logic Gate](examples/logic/full-adder.svg)
250
+
251
+ [逻辑门语法 →](https://schematex.dev/docs/logic)
252
+
253
+ ---
254
+
255
+ ### ⚡ 电路原理图 Circuit schematic —— *SPICE 风格 netlist 或位置式 DSL*
256
+
257
+ 模拟 / 数字电路,自动布线电源 / 地轨 + 正交信号走线。
258
+
259
+ ```
260
+ circuit "CE Amp (netlist)" netlist
261
+ V1 vcc 0 9V
262
+ Rc vcc c 2.2k
263
+ Rb vcc b 100k
264
+ Q1 c b e npn
265
+ Re e 0 1k
266
+ ```
267
+
268
+ ![CE Amp Netlist Schematic](examples/circuit/ce-amp-netlist.svg)
269
+
270
+ [电路语法 →](https://schematex.dev/docs/circuit)
271
+
272
+ ---
273
+
274
+ ### 🪜 梯形图 Ladder logic —— *IEC 61131-3 / Allen-Bradley*
275
+
276
+ 工业 PLC 程序,支持「标签 + 地址 + 描述」三行标注、并联分支、Set/Reset 线圈对。
277
+
278
+ ```
279
+ ladder "System Mode Selection"
280
+ rung 1 "Set Auto, reset Manual":
281
+ XIC(AUTO_HMIPB, "BIT 5.10", name="Auto Mode HMI Pushbutton")
282
+ XIO(MANL_HMIPB, "BIT 5.11", name="Manual Mode HMI Pushbutton")
283
+ XIO(SYS_FAULT, "BIT 3.0", name="System Fault")
284
+ parallel:
285
+ branch: OTL(SYS_AUTO, "BIT 3.1", name="System Auto Mode")
286
+ branch: OTU(SYS_MANUAL, "BIT 3.2", name="System Manual Mode")
287
+ ```
288
+
289
+ ![System Mode Selection Ladder](examples/ladder/mode-selection.svg)
290
+
291
+ [梯形图语法 →](https://schematex.dev/docs/ladder)
292
+
293
+ ---
294
+
295
+ ### ⚡ 单线图 Single-line diagram —— *IEEE 315 电力一次接线图*
296
+
297
+ 变电站与配电一次接线图,含变压器、断路器、母线、保护继电器。
298
+
299
+ ```
300
+ sld "Utility with generator backup"
301
+ UTIL = utility [voltage: "480V", label: "Utility"]
302
+ GEN = generator [rating: "500 kW", voltage: "480V", label: "Emergency Gen"]
303
+ ATS1 = ats [rating: "800A", label: "ATS-1"]
304
+ BUS1 = bus [voltage: "480V", label: "Critical Load Bus"]
305
+ CB1 = breaker [rating: "200A"]
306
+ CB2 = breaker [rating: "200A"]
307
+ L1 = load [rating: "100A", label: "Critical Load 1"]
308
+ L2 = load [rating: "100A", label: "Critical Load 2"]
309
+ UTIL -> ATS1
310
+ GEN -> ATS1
311
+ ATS1 -> BUS1
312
+ BUS1 -> CB1
313
+ BUS1 -> CB2
314
+ CB1 -> L1
315
+ CB2 -> L2
316
+ ```
317
+
318
+ ![Utility with Generator Backup SLD](examples/sld/generator-ats.svg)
319
+
320
+ [单线图语法 →](https://schematex.dev/docs/sld)
321
+
322
+ ---
323
+
324
+ ### 🏢 实体结构图 Entity structure —— *股权结构表与公司所有权*
325
+
326
+ 公司母 / 子公司结构,含持股比例、按司法辖区聚类、实体类型形状(C-corp / LLC / trust / fund)。
327
+
328
+ ```
329
+ entity "Acme Holdings"
330
+ acme_inc [type: corp, jurisdiction: DE]
331
+ acme_uk [type: ltd, jurisdiction: UK]
332
+ acme_fund [type: fund, jurisdiction: KY]
333
+ trust_a [type: trust, jurisdiction: SD]
334
+ trust_a --100%--> acme_inc
335
+ acme_inc --100%--> acme_uk
336
+ acme_inc --60%--> acme_fund
337
+ ```
338
+
339
+ ![Acme Holdings Entity Structure](examples/entity/holding-company.svg)
340
+
341
+ [实体结构语法 →](https://schematex.dev/docs/entity)
342
+
343
+ ---
344
+
345
+ ### 📦 方框图 Block diagram
346
+
347
+ 信号流方框图,含求和节点、增益方块、反馈回路。
348
+
349
+ ```
350
+ blockdiagram "Nested Feedback Loops"
351
+ G1 = block("G1(s)") [role: plant]
352
+ G2 = block("G2(s)") [role: plant]
353
+ G3 = block("G3(s)") [role: plant]
354
+ H1 = block("H1(s)") [role: sensor]
355
+ H2 = block("H2(s)") [role: sensor, route: above]
356
+ s1 = sum(+R, -h2)
357
+ s2 = sum(+a, -h1)
358
+ in -> s1 ["R(s)"]
359
+ s1 -> G1 -> s2
360
+ s2 -> G2 -> G3
361
+ G3 -> out ["Y(s)"]
362
+ G2 -> H1
363
+ H1 -> s2
364
+ G3 -> H2
365
+ H2 -> s1
366
+ ```
367
+
368
+ ![Nested Feedback Loops Block Diagram](examples/block/nested-feedback.svg)
369
+
370
+ [方框图语法 →](https://schematex.dev/docs/block)
371
+
372
+ ---
373
+
374
+ ### 🐟 鱼骨图 Fishbone —— *Ishikawa 因果图*
375
+
376
+ 因果分析图,自动分类分支 + 交替排布的鱼骨。
377
+
378
+ ```
379
+ fishbone "Website Traffic Drop — Root Cause Analysis"
380
+ effect "Traffic Drop"
381
+ category content "Content"
382
+ category tech "Technical"
383
+ category links "Backlinks"
384
+ category ux "UX"
385
+ category competition "Competition"
386
+ category algo "Algorithm"
387
+ content : "Lower update frequency" : "Thin content" : "Keyword gaps"
388
+ tech : "Poor Core Web Vitals" : "WAF blocking crawlers"
389
+ links : "High-DA backlink loss" : "Referring domain plateau"
390
+ ux : "Bounce rate spike" : "Slow LCP" : "Intrusive interstitials"
391
+ competition : "New entrants" : "AI overviews displacing clicks"
392
+ algo : "Core Update penalty" : "Weak E-E-A-T signals" : "SGE traffic diversion"
393
+ ```
394
+
395
+ ![Website Traffic Drop Fishbone](examples/fishbone/website-traffic-drop.svg)
396
+
397
+ [鱼骨图语法 →](https://schematex.dev/docs/fishbone)
398
+
399
+ ### 🌳 决策树 Decision Tree —— *Howard-Raiffa · CART/sklearn · 分类法*
400
+
401
+ 一套 DSL,三种模式:决策分析(Howard-Raiffa EV 回溯)、ML 树可视化(sklearn `plot_tree` 风格)、yes/no 分类树。对角边走线、收益对齐列、最优路径高亮。
402
+
403
+ **决策分析 —— EV 回溯:**
404
+ ```
405
+ decisiontree:decision "Oil drilling"
406
+
407
+ decision "Drill or sell rights?"
408
+ choice "Sell rights"
409
+ end payoff=90000 "Guaranteed sale"
410
+ choice "Drill"
411
+ chance "Well outcome"
412
+ prob 0.3 end payoff=500000 "Major strike"
413
+ prob 0.5 end payoff=50000 "Minor strike"
414
+ prob 0.2 end payoff=-200000 "Dry hole"
415
+ ```
416
+
417
+ **ML 树 —— sklearn CART 风格:**
418
+ ```
419
+ decisiontree:ml "Iris classification"
420
+ classes: setosa, versicolor, virginica
421
+ impurity: gini
422
+ branchLabels: relation
423
+
424
+ split feature=petal_width op=<= threshold=0.8 samples=120 value=[50,35,35] gini=0.66
425
+ true leaf samples=50 value=[50,0,0] gini=0 class=setosa
426
+ false split feature=petal_width op=<= threshold=1.75 samples=70 value=[0,35,35] gini=0.5
427
+ true leaf samples=36 value=[0,32,4] gini=0.198 class=versicolor
428
+ false leaf samples=34 value=[0,3,31] gini=0.162 class=virginica
429
+ ```
430
+
431
+ **分类法 —— yes/no 分类:**
432
+ ```
433
+ decisiontree:taxonomy "ED Triage Level"
434
+ direction: left-right
435
+
436
+ q "Airway compromise?"
437
+ yes: a "Level 1 — Resuscitation"
438
+ no: q "Vital signs unstable?"
439
+ yes: a "Level 2 — Emergent"
440
+ no: q "Multiple resources needed?"
441
+ yes: a "Level 3 — Urgent"
442
+ no: a "Level 4/5 — Less urgent"
443
+ ```
444
+
445
+ [决策树语法 →](https://schematex.dev/docs/decisiontree)
446
+
447
+ ---
448
+
449
+ ### 📅 时间线 Timeline
450
+
451
+ 历史事件、人物生平、产品路线图、地质年代,落在比例 / 等距 / 对数轴上。三种视觉样式:**泳道**(多轨生平)、**甘特**(项目计划,含图钉 + 分类泳道 + 图例)、**棒棒糖**(中轴上下交替的卡片)。支持公元前 / 公元日期、季度日期(`2026-Q1`)、地质百万年(`Ma`)刻度。
452
+
453
+ ```
454
+ timeline "Apollo program"
455
+
456
+ 1961-05-25: milestone "Kennedy Moon speech"
457
+ 1967-01-27: "Apollo 1 fire"
458
+ 1968-12-21 - 1968-12-27: "Apollo 8 — first lunar orbit"
459
+ 1969-07-16 - 1969-07-24: "Apollo 11 — Moon landing" [icon:🚀]
460
+ 1970-04-11 - 1970-04-17: "Apollo 13 — abort"
461
+ 1972-12-07 - 1972-12-19: "Apollo 17 — last crewed Moon mission"
462
+ ```
463
+
464
+ ```
465
+ timeline "Brand story"
466
+ config: style = lollipop
467
+
468
+ era 2015 - 2019: "Scrappy startup"
469
+ era 2019 - 2023: "Scale-up"
470
+ era 2023 - 2027: "Enterprise era"
471
+
472
+ 2015: "Founded in a coffee shop" [icon:☕]
473
+ 2017: milestone "First 1000 users" [icon:👥]
474
+ 2019: "Series A" [icon:💰]
475
+ 2021: "Opened NYC office" [icon:🏙]
476
+ 2023: milestone "Crossed $50M ARR" [icon:📊]
477
+ 2025: "Acquired Acme Inc." [icon:🤝]
478
+ ```
479
+
480
+ ```
481
+ timeline "Q2 Launch plan"
482
+ config: style = gantt
483
+
484
+ 2026-04-01: milestone "Kickoff"
485
+ 2026-06-30: milestone "GA launch" [icon:🚀]
486
+
487
+ 2026-04-01 - 2026-04-30: "Research & specs" [category: "Design"]
488
+ 2026-04-10 - 2026-06-10: "API build" [category: "Eng"]
489
+ 2026-05-15 - 2026-06-25: "Campaign prep" [category: "Marketing"]
490
+ ```
491
+
492
+ [时间线语法 →](https://schematex.dev/docs/timeline)
493
+
494
+ ### 🗓️ PERT / CPM —— *PMI PMBOK 7 活动节点网络图*
495
+
496
+ 唯一一个**会计算进度**的文本 DSL PERT 工具。你写任务、工期、依赖关系 —— 引擎跑前向 / 后向遍历,返回最早 / 最迟开始与完成、总时差、项目工期,以及关键路径(红色高亮)。支持 FS/SS/FF/SF 依赖 + lag/lead、三点估算(`te + 方差`)、里程碑、泳道(`lane:`)和时间刻度布局。
497
+
498
+ ```
499
+ pert
500
+ title: "Q3 Product Launch"
501
+ unit: days
502
+
503
+ task A "Market research" duration: 5
504
+ task B "Design mockups" duration: 8 after: A
505
+ task C "Backend API" duration: 15 after: A
506
+ task D "Frontend build" duration: 10 after: B, C
507
+ task E "QA / testing" duration: 5 after: D
508
+ task F "Marketing collateral" duration: 7 after: B
509
+ task G "Launch event" duration: 2 after: E, F
510
+ ```
511
+
512
+ [PERT / CPM 语法 →](https://schematex.dev/docs/pert)
513
+
514
+ ---
515
+
516
+ ### ◉ Petri 网 —— *Murata 1989 / ISO-IEC 15909 库所-变迁网*
517
+
518
+ 唯一一个**理解动态语义**、而不只是画形状的文本 DSL Petri 网工具。你声明库所(装 token 的圆)、变迁(横条)和加权弧;引擎校验二部结构、计算当前标识下哪些变迁**使能**(绿色高亮),并能 `fire:` 一个序列前推到任意可达标识。即时 vs 定时变迁、弧权重、容量,以及抑制弧 / 读弧 / 复位弧 —— 完整的并发词汇。
519
+
520
+ ```
521
+ petri "Mutual Exclusion — two processes, one resource"
522
+ place idleA *1 "A idle"
523
+ place idleB *1 "B idle"
524
+ place mutex *1 "resource"
525
+ place critA "A critical"
526
+ place critB "B critical"
527
+ transition enterA
528
+ transition exitA
529
+ transition enterB
530
+ transition exitB
531
+ idleA -> enterA
532
+ mutex -> enterA
533
+ enterA -> critA
534
+ critA -> exitA
535
+ exitA -> idleA
536
+ exitA -> mutex
537
+ idleB -> enterB
538
+ mutex -> enterB
539
+ enterB -> critB
540
+ critB -> exitB
541
+ exitB -> idleB
542
+ exitB -> mutex
543
+ ```
544
+
545
+ ![Mutual Exclusion Petri Net](examples/petri/mutual-exclusion.svg)
546
+
547
+ [Petri 网语法 →](https://schematex.dev/docs/petri)
548
+
549
+ ---
550
+
551
+ ### 🖧 网络拓扑图 Network topology —— *Cisco 约定图标 · 设备 / 链路 / 端口完整性*
552
+
553
+ 免费、文本优先、零依赖的网络拓扑引擎。声明带类型的设备(路由器、交换机、防火墙、AP、服务器、**IP 摄像机 / NVR / PoE 交换机** ……)和带类型、带标注的链路(copper / fiber / wireless / serial / **PoE** / VPN / LAG,携带 VLAN / 速率 / 端口 / 模式),把它们组进站点、机柜、子网、VLAN,引擎按拓扑类别正确布局 —— `tiered`(三层园区网)、`star`、`ring`、`bus`、`mesh`、`spine-leaf`(自动 mesh 的 Clos)、`tree`。和直接吐原始 Mermaid 的 LLM 不同,它**绝不丢设备、丢端口、丢链路**,还校验 IP 是否在子网内、VLAN 范围是否合法。
554
+
555
+ ```
556
+ network "Acme HQ — CCTV"
557
+ layout: tiered
558
+ internet net "Internet"
559
+ firewall fw1 "Perimeter FW" tier: edge
560
+ l3switch core1 "Core SW" tier: core
561
+ poeswitch poe1 "PoE Switch A" tier: access
562
+ poeswitch poe2 "PoE Switch B" tier: access
563
+ nvr nvr1 "Video Recorder"
564
+ monitor wall1 "Guard Station"
565
+ subnet cams "192.168.20.0/24" {
566
+ camera cam1 "Lobby Dome" type: dome ip: 192.168.20.11
567
+ camera cam2 "Gate PTZ" type: ptz ip: 192.168.20.12
568
+ camera cam3 "Dock Bullet" type: bullet ip: 192.168.20.13
569
+ poe1
570
+ poe2
571
+ }
572
+ net -- fw1 : wan "ISP 1Gbps"
573
+ fw1 -- core1 : fiber 10G
574
+ core1 -- poe1 : trunk vlan: 20 1G
575
+ core1 -- poe2 : trunk vlan: 20 1G
576
+ core1 -- nvr1 : 1G
577
+ core1 -- wall1
578
+ poe1 -- cam1 : poe
579
+ poe1 -- cam2 : poe
580
+ poe2 -- cam3 : poe
581
+ ```
582
+
583
+ ![CCTV camera network topology](examples/network/cctv-camera-network.svg)
584
+
585
+ [网络拓扑语法 →](https://schematex.dev/docs/network)
586
+
587
+ ---
588
+
589
+ ### 📐 UML 类图 —— *UML 2.5.1 §9–§11*
590
+
591
+ 分类器(class / interface / enum / datatype / primitive)、全部 6 种关系及标准正确的修饰符,以及**由泛化关系驱动的分层布局**(父类浮到顶部,连线绝不穿过方块)。命名空间渲染为嵌套的包含框。接受 Mermaid `classDiagram` 字形,一行即可迁移。
592
+
593
+ ```
594
+ umlclass
595
+ title: "Shape hierarchy"
596
+
597
+ «interface» Shape {
598
+ + area() : double
599
+ + perimeter() : double
600
+ }
601
+
602
+ abstract class AbstractShape {
603
+ # name : String
604
+ + area() : double {abstract}
605
+ + perimeter() : double {abstract}
606
+ + describe() : String
607
+ }
608
+
609
+ class Circle {
610
+ + radius : double
611
+ + area() : double
612
+ }
613
+
614
+ class Square {
615
+ + side : double
616
+ + area() : double
617
+ }
618
+
619
+ Shape <|.. AbstractShape
620
+ AbstractShape <|-- Circle
621
+ AbstractShape <|-- Square
622
+ ```
623
+
624
+ ![UML class shape hierarchy](examples/umlclass/shape-hierarchy.svg)
625
+
626
+ [UML 类图语法 →](https://schematex.dev/docs/umlclass)
627
+
628
+ ---
629
+
630
+ ### 🛡️ 故障树 Fault tree —— *NUREG-0492 / IEC 61025 · MOCUS*
631
+
632
+ 可靠性故障树,引擎**计算结果**:跑 MOCUS 枚举最小割集(红框)、标记单点失效、计算顶事件概率。AND 圆顶、OR/XOR 盾形、k-of-n 表决、INHIBIT、PAND。
633
+
634
+ ```
635
+ faulttree "Both pumps fail"
636
+ analysis: cutsets, probability
637
+ top T "Both redundant pumps fail" = AND(PA, PB)
638
+ basic PA "Pump A fails" p: 0.01
639
+ basic PB "Pump B fails" p: 0.01
640
+ ```
641
+
642
+ ![Redundant pump fault tree](examples/faulttree/pump-redundancy.svg)
643
+
644
+ [故障树语法 →](https://schematex.dev/docs/faulttree)
645
+
646
+ ---
647
+
648
+ ### 🎀 领结图 Bowtie —— *CCPS / Energy Institute 2018 屏障模型*
649
+
650
+ 针对单个重大事故场景的、基于屏障的风险管理:威胁从左侧经预防性屏障链汇入,后果从右侧经缓解性屏障链发散,中间是顶事件「结」。**构造即正确** —— 任何没有屏障的威胁或后果会被拒绝,而不是悄悄画出来。
651
+
652
+ ```
653
+ bowtie "LPG storage — loss of containment"
654
+ hazard "LPG stored under pressure"
655
+ topevent "Loss of containment"
656
+ threat "Corrosion of vessel wall"
657
+ prevent "Corrosion-resistant coating"
658
+ prevent "UT thickness inspection"
659
+ threat "Overpressure during filling"
660
+ prevent "High-pressure trip (SIL 2)"
661
+ prevent "Pressure relief valve"
662
+ consequence "Jet fire"
663
+ mitigate "Gas detection + ESD"
664
+ mitigate "Deluge / water spray"
665
+ consequence "Vapour cloud explosion"
666
+ mitigate "Ignition-source control (ATEX)"
667
+ mitigate "Blast-resistant control room"
668
+ ```
669
+
670
+ ![LPG loss-of-containment bowtie](examples/bowtie/lpg-loss-of-containment.svg)
671
+
672
+ [领结图语法 →](https://schematex.dev/docs/bowtie)
673
+
674
+ ## 为什么选 SchemaTex?
675
+
676
+ **通用流程图工具画不出专业图。** 每个图领域都有发布的标准 —— 符号约定、布局规则、标注文法 —— 一旦忽略,领域专家就不认:
677
+
678
+ - **家系图**遵循 [McGoldrick (2020)](https://en.wikipedia.org/wiki/Genogram) 标准 —— 性别专属形状、疾病填充图案、情感关系线型、按代布局。流程图里一个标着「女性」的圆圈不是家系图。
679
+ - **梯形图**遵循 [IEC 61131-3](https://en.wikipedia.org/wiki/IEC_61131-3) + Allen-Bradley 标签约定 —— 三行标注(标签 / 地址 / 描述)、Set/Reset 线圈、输入侧自锁、并联梯级。
680
+ - **单线图**遵循 [IEEE 315](https://standards.ieee.org/ieee/315/5052/) —— 保护设备聚类、电压层级、变压器符号。
681
+ - **谱系图**遵循 NSGC 人类谱系命名法;**系统发育树**与 Newick + NHX 双向往返;**股权结构表**计算层级感知的所有权汇总。
682
+
683
+ SchemaTex 把每个标准当作一等公民,配以自己的 parser、布局算法、SVG 渲染器 —— **标准即代码**,而不是套了领域标签的通用形状。
684
+
685
+ 没有任何现存开源库覆盖这个广度。GoJS 有零散样例但 **$7k+/席位**。Schemdraw 只支持 Python。draw.io 是个重型 GUI。其余的要么闭源、要么已弃维护。
686
+
687
+ ### 为 LLM 代码生成而设计
688
+
689
+ SchemaTex 的 DSL 小巧、一致,并且是按「LLM 常犯什么错」来塑形的:
690
+
691
+ - 每种图都有一份极简、文档化的文法,LLM 看一个示例就能学会。
692
+ - 错误信息对 AI 友好 —— 行号 + 具体修复建议,而不是 `Parse error at line 42`。
693
+ - 语法规避了常见的 LLM 失败模式(CJK 引号、模糊嵌套、位置参数 vs 命名参数)。
694
+
695
+ 由人编写,由 LLM 的常见错误塑形。
696
+
697
+ ## 特性
698
+
699
+ - **零运行时依赖。** 无 D3、无 dagre、无 parser 生成器。手写 parser 与布局引擎。自包含 TypeScript。
700
+ - **标准合规输出。** 每种图实现一份已发布的规范,而非我们自创。
701
+ - **语义化 SVG。** 每个元素都有可访问的 `<title>` / `<desc>`、可主题化的 CSS class、可交互的 `data-*` 属性。无 inline style。
702
+ - **可 tree-shake 的插件架构。** 每种图是独立插件,自带 parser、布局、渲染器。`schematex/genogram` → ~30 KB。
703
+ - **SSR 友好。** 纯字符串输出,不需要 DOM。可在 Node、edge runtime、浏览器中运行。
704
+ - **TypeScript strict。** 无 `any`,无未类型化的逃逸口子。
705
+
706
+ ## API
707
+
708
+ ```ts
709
+ // 通用入口 —— 从第一个关键字自动推断图类型
710
+ import { render, renderPreview, renderResult, parse, parseResult } from 'schematex';
711
+
712
+ const svg = render(text, config?); // 严格模式 → SVG 字符串,否则抛错
713
+ const ast = parse(text, config?); // 严格模式 → AST,否则抛错
714
+ const previewSvg = renderPreview(text, config?); // 总是 → SVG,含可见的诊断兜底
715
+ const renderState = renderResult(text, config?); // → SVG + 诊断 + valid/partial/invalid 状态
716
+ const parseState = parseResult(text, config?); // → AST 或诊断,不抛错
717
+
718
+ // 按图 tree-shake
719
+ import { render } from 'schematex/genogram';
720
+
721
+ // 浏览器 DOM
722
+ import {
723
+ renderToElement,
724
+ renderToContainer,
725
+ renderPreviewToElement,
726
+ renderPreviewToContainer,
727
+ } from 'schematex/browser';
728
+ container.appendChild(renderToElement(dsl));
729
+
730
+ // React
731
+ import { SchematexDiagram } from 'schematex/react';
732
+ // <SchematexDiagram dsl="genogram ..." theme="monochrome" />
733
+
734
+ // 导出(浏览器 Canvas)
735
+ import { svgToPngBlob, downloadBlob, printSvgAsPdf } from 'schematex/export';
736
+ const blob = await svgToPngBlob(svg, { scale: 2 }); // 透明 PNG
737
+ const opaque = await svgToPngBlob(svg, { background: 'white' }); // 选择性填充背景
738
+ downloadBlob(blob, 'diagram.png');
739
+ ```
740
+
741
+ 参见 [API 参考 →](https://schematex.dev/docs/api)。
742
+
743
+ ### 背景与暗色模式
744
+
745
+ Schematex 的 SVG **默认与背景无关** —— 输出里不烘焙任何填充,所以图会继承宿主元素提供的颜色。同一个 SVG 因此能嵌入浅色页面、暗色画布或打印 PDF。
746
+
747
+ 使用 `theme: "dark"` 时,图的描边和文字是为暗色表面设计的 —— 请把 SVG 包进一个暗色背景的容器,例如:
748
+
749
+ ```html
750
+ <div style="background: #0f172a; padding: 16px;">
751
+ <!-- 使用 theme: "dark" 的 schematex SVG -->
752
+ </div>
753
+ ```
754
+
755
+ PNG 导出(`svgToPngBlob`)默认透明背景。传 `background: 'white'`(或任意颜色)来烘焙一个背景。
756
+
757
+ ## 生态
758
+
759
+ - **React** —— `schematex/react` —— `<SchematexDiagram dsl="..." />` 组件
760
+ - **浏览器** —— `schematex/browser` —— `renderToElement()` / `renderToContainer()`
761
+ - **导出** —— `schematex/export` —— PNG(@2×)+ 经浏览器 Canvas 打印 PDF
762
+ - **Obsidian** —— 代码块渲染插件 *(即将推出)*
763
+ - **Markdown-it / remark** —— 图围栏支持 *(即将推出)*
764
+ - **CLI** —— `npx schematex input.txt > output.svg` *(即将推出)*
765
+
766
+ ## 贡献
767
+
768
+ 欢迎贡献。见 [CONTRIBUTING.md](./CONTRIBUTING.md)。
769
+
770
+ 新增一种图遵循 5 文件模式(parser、symbols、layout、renderer、集成)。每种类型在 [`docs/reference/`](./docs/reference/) 都有一份标准文档。
771
+
772
+ ```bash
773
+ npm install
774
+ npm run typecheck
775
+ npm run test
776
+ npm run build
777
+ ```
778
+
779
+ ## 许可证
780
+
781
+ [AGPL-3.0](./LICENSE) 用于开源用途。若需无 AGPL 义务的商业使用(将 SchemaTex 嵌入专有 / 闭源产品),提供商业授权 —— 联系 **victor@mymap.ai**。
782
+
783
+ <p align="center"><sub>由 <a href="https://mymap.ai">MyMap.ai</a> 打造。</sub></p>