@diagrammo/dgmo 0.47.0 → 0.48.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.
Files changed (345) hide show
  1. package/dist/advanced.js +11 -11
  2. package/dist/auto.js +16 -16
  3. package/dist/auto.mjs +41 -12
  4. package/dist/block.js +4 -4
  5. package/dist/{chunk-FNB3PNGF.js → chunk-7DTWEFUE.js} +3 -3
  6. package/dist/{chunk-2DXMZRWJ.js → chunk-B65G5DNL.js} +8 -1
  7. package/dist/{chunk-RZCF2VVM.js → chunk-B7JUCQUA.js} +3 -1
  8. package/dist/{chunk-DU7W62N5.js → chunk-FANX6UJR.js} +3 -3
  9. package/dist/{chunk-6FZYCKXB.js → chunk-HSH73DP6.js} +2 -2
  10. package/dist/{chunk-P4RH4OSP.js → chunk-ILKORZ3H.js} +2 -2
  11. package/dist/{chunk-Y5QGVTVC.js → chunk-JTSMEYIZ.js} +7 -3
  12. package/dist/{chunk-RCERWOJR.js → chunk-ODZVHU3R.js} +1 -2
  13. package/dist/{chunk-DZAQBW35.js → chunk-SGZYXELT.js} +3 -7
  14. package/dist/{chunk-CUVHQHZ7.js → chunk-THXCFRTU.js} +3 -3
  15. package/dist/{chunk-IH6ZMVQ5.js → chunk-UC7TFHUM.js} +29 -11
  16. package/dist/{chunk-EMS2SK26.js → chunk-ZBWMSD5N.js} +3 -1
  17. package/dist/cli.cjs +15 -15
  18. package/dist/{dgmo-router-DZCIDUO5.js → dgmo-router-X35VLZLM.js} +3 -3
  19. package/dist/element.js +16 -16
  20. package/dist/element.mjs +41 -12
  21. package/dist/{flowchart-renderer-ZAEOL4DX.js → flowchart-renderer-SNDSII4D.js} +2 -2
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.js +4 -4
  24. package/dist/{parser-FUSKFGZN.js → parser-2EWECDSA.js} +2 -2
  25. package/dist/{renderer-UWA5XS74.js → renderer-4JHRUBE6.js} +3 -3
  26. package/dist/{renderer-WZRREQ2P.js → renderer-5MYBMBYO.js} +2 -2
  27. package/dist/{renderer-TOCOVLHS.js → renderer-B2OMQIQG.js} +3 -3
  28. package/dist/{renderer-2XQQQ6QR.js → renderer-N43WR5GV.js} +3 -3
  29. package/dist/{renderer-T7YKC5VP.js → renderer-ZRNG54CW.js} +3 -3
  30. package/dist/{state-renderer-RFYHSP4K.js → state-renderer-B4DQBM6M.js} +2 -2
  31. package/package.json +23 -71
  32. package/dist/advanced.cjs +0 -71648
  33. package/dist/advanced.d.cts +0 -5719
  34. package/dist/auto.cjs +0 -70648
  35. package/dist/auto.d.cts +0 -54
  36. package/dist/block.cjs +0 -70208
  37. package/dist/block.d.cts +0 -115
  38. package/dist/editor.cjs +0 -526
  39. package/dist/editor.d.cts +0 -26
  40. package/dist/element.cjs +0 -70530
  41. package/dist/element.d.cts +0 -62
  42. package/dist/highlight.cjs +0 -852
  43. package/dist/highlight.d.cts +0 -49
  44. package/dist/index.cjs +0 -70491
  45. package/dist/index.d.cts +0 -160
  46. package/dist/pert.cjs +0 -325
  47. package/dist/pert.d.cts +0 -559
  48. package/dist/themes-1-CuKpeH.d.cts +0 -908
  49. package/src/advanced.ts +0 -873
  50. package/src/arc/parser.ts +0 -15
  51. package/src/arc/renderer.ts +0 -633
  52. package/src/auto/index.ts +0 -621
  53. package/src/auto/shared.ts +0 -370
  54. package/src/auto/styles.ts +0 -73
  55. package/src/block/layout.ts +0 -198
  56. package/src/block/parser.ts +0 -427
  57. package/src/block/renderer.ts +0 -484
  58. package/src/block/types.ts +0 -67
  59. package/src/boxes-and-lines/collapse.ts +0 -96
  60. package/src/boxes-and-lines/focus.ts +0 -257
  61. package/src/boxes-and-lines/label-placement.ts +0 -339
  62. package/src/boxes-and-lines/layout-grouped.ts +0 -912
  63. package/src/boxes-and-lines/layout-layered.ts +0 -722
  64. package/src/boxes-and-lines/layout-search.ts +0 -1678
  65. package/src/boxes-and-lines/layout.ts +0 -398
  66. package/src/boxes-and-lines/parser.ts +0 -1181
  67. package/src/boxes-and-lines/renderer.ts +0 -1465
  68. package/src/boxes-and-lines/types.ts +0 -66
  69. package/src/c4/layout.ts +0 -2441
  70. package/src/c4/parser.ts +0 -1158
  71. package/src/c4/renderer.ts +0 -2008
  72. package/src/c4/types.ts +0 -89
  73. package/src/chart-type-registry.ts +0 -529
  74. package/src/chart-types.ts +0 -225
  75. package/src/chart.ts +0 -685
  76. package/src/charts-d3/bar.ts +0 -338
  77. package/src/charts-d3/chord.ts +0 -140
  78. package/src/charts-d3/function.ts +0 -147
  79. package/src/charts-d3/funnel.ts +0 -104
  80. package/src/charts-d3/heatmap.ts +0 -145
  81. package/src/charts-d3/index.ts +0 -337
  82. package/src/charts-d3/interactions.ts +0 -477
  83. package/src/charts-d3/line.ts +0 -344
  84. package/src/charts-d3/mount.ts +0 -151
  85. package/src/charts-d3/pie.ts +0 -117
  86. package/src/charts-d3/polar.ts +0 -89
  87. package/src/charts-d3/radar.ts +0 -0
  88. package/src/charts-d3/sankey.ts +0 -0
  89. package/src/charts-d3/scatter.ts +0 -185
  90. package/src/charts-d3/shared.ts +0 -208
  91. package/src/class/layout.ts +0 -326
  92. package/src/class/parser.ts +0 -635
  93. package/src/class/renderer.ts +0 -793
  94. package/src/class/types.ts +0 -58
  95. package/src/cli-banner.ts +0 -106
  96. package/src/cli.ts +0 -1080
  97. package/src/colors-diagnostics.ts +0 -35
  98. package/src/colors.ts +0 -379
  99. package/src/completion-types.ts +0 -27
  100. package/src/completion.ts +0 -2668
  101. package/src/cycle/layout.ts +0 -1026
  102. package/src/cycle/parser.ts +0 -387
  103. package/src/cycle/renderer.ts +0 -653
  104. package/src/cycle/types.ts +0 -101
  105. package/src/d3.ts +0 -1434
  106. package/src/data-chart-parser.ts +0 -1007
  107. package/src/dgmo-router.ts +0 -296
  108. package/src/diagnostics-registry.ts +0 -108
  109. package/src/diagnostics.ts +0 -0
  110. package/src/dimensions.ts +0 -20
  111. package/src/directives-registry.ts +0 -396
  112. package/src/editor/dgmo.grammar +0 -76
  113. package/src/editor/dgmo.grammar.d.ts +0 -2
  114. package/src/editor/dgmo.grammar.js +0 -18
  115. package/src/editor/dgmo.grammar.terms.d.ts +0 -5
  116. package/src/editor/dgmo.grammar.terms.js +0 -35
  117. package/src/editor/highlight-api.ts +0 -596
  118. package/src/editor/highlight.ts +0 -36
  119. package/src/editor/index.ts +0 -27
  120. package/src/editor/keywords.ts +0 -128
  121. package/src/editor/tokens.ts +0 -30
  122. package/src/element/index.ts +0 -432
  123. package/src/embed/css.ts +0 -312
  124. package/src/embed/escape.ts +0 -15
  125. package/src/embed/index.ts +0 -280
  126. package/src/er/classify.ts +0 -228
  127. package/src/er/layout.ts +0 -530
  128. package/src/er/parser.ts +0 -750
  129. package/src/er/renderer.ts +0 -725
  130. package/src/er/types.ts +0 -52
  131. package/src/error-card.ts +0 -269
  132. package/src/event-line/diagnostics.ts +0 -117
  133. package/src/event-line/parser.ts +0 -643
  134. package/src/event-line/renderer.ts +0 -1742
  135. package/src/event-line/types.ts +0 -74
  136. package/src/fonts.ts +0 -3
  137. package/src/gantt/calculator.ts +0 -979
  138. package/src/gantt/parser.ts +0 -1641
  139. package/src/gantt/renderer.ts +0 -3787
  140. package/src/gantt/resolver.ts +0 -172
  141. package/src/gantt/types.ts +0 -206
  142. package/src/graph/diagnostics.ts +0 -64
  143. package/src/graph/edge-spline.ts +0 -29
  144. package/src/graph/flowchart-parser.ts +0 -759
  145. package/src/graph/flowchart-renderer.ts +0 -817
  146. package/src/graph/layout.ts +0 -472
  147. package/src/graph/notes.ts +0 -21
  148. package/src/graph/state-collapse.ts +0 -78
  149. package/src/graph/state-parser.ts +0 -574
  150. package/src/graph/state-renderer.ts +0 -653
  151. package/src/graph/types.ts +0 -65
  152. package/src/index.ts +0 -261
  153. package/src/infra/compute.ts +0 -1385
  154. package/src/infra/layout.ts +0 -888
  155. package/src/infra/parser.ts +0 -1234
  156. package/src/infra/renderer.ts +0 -2534
  157. package/src/infra/roles.ts +0 -75
  158. package/src/infra/types.ts +0 -216
  159. package/src/infra/validation.ts +0 -201
  160. package/src/journey-map/layout.ts +0 -490
  161. package/src/journey-map/parser.ts +0 -557
  162. package/src/journey-map/renderer.ts +0 -1580
  163. package/src/journey-map/types.ts +0 -47
  164. package/src/kanban/mutations.ts +0 -175
  165. package/src/kanban/parser.ts +0 -509
  166. package/src/kanban/renderer.ts +0 -1449
  167. package/src/kanban/types.ts +0 -39
  168. package/src/label-layout.ts +0 -368
  169. package/src/map/colorize.ts +0 -54
  170. package/src/map/completion.ts +0 -316
  171. package/src/map/context-labels.ts +0 -609
  172. package/src/map/data/PROVENANCE.json +0 -1
  173. package/src/map/data/README.md +0 -40
  174. package/src/map/data/airport-collisions.json +0 -1
  175. package/src/map/data/airports.json +0 -1
  176. package/src/map/data/gazetteer.json +0 -1
  177. package/src/map/data/lakes.json +0 -1
  178. package/src/map/data/mountain-ranges.json +0 -1
  179. package/src/map/data/na-lakes.json +0 -1
  180. package/src/map/data/na-land.json +0 -1
  181. package/src/map/data/region-names.json +0 -1
  182. package/src/map/data/rivers.json +0 -1
  183. package/src/map/data/types.ts +0 -121
  184. package/src/map/data/us-states.json +0 -1
  185. package/src/map/data/water-bodies.json +0 -1
  186. package/src/map/data/world-coarse.json +0 -1
  187. package/src/map/data/world-detail.json +0 -1
  188. package/src/map/diagnostics.ts +0 -134
  189. package/src/map/dimensions.ts +0 -150
  190. package/src/map/geo-query.ts +0 -295
  191. package/src/map/geo.ts +0 -438
  192. package/src/map/invert.ts +0 -111
  193. package/src/map/layout.ts +0 -5069
  194. package/src/map/legend-band.ts +0 -127
  195. package/src/map/load-data.ts +0 -186
  196. package/src/map/parser.ts +0 -783
  197. package/src/map/renderer.ts +0 -1445
  198. package/src/map/resolved-types.ts +0 -160
  199. package/src/map/resolver.ts +0 -1146
  200. package/src/map/types.ts +0 -194
  201. package/src/mindmap/collapse.ts +0 -67
  202. package/src/mindmap/layout.ts +0 -649
  203. package/src/mindmap/parser.ts +0 -430
  204. package/src/mindmap/renderer.ts +0 -637
  205. package/src/mindmap/text-wrap.ts +0 -218
  206. package/src/mindmap/types.ts +0 -56
  207. package/src/org/collapse.ts +0 -151
  208. package/src/org/layout.ts +0 -1262
  209. package/src/org/parser.ts +0 -519
  210. package/src/org/renderer.ts +0 -866
  211. package/src/org/resolver.ts +0 -636
  212. package/src/palettes/atlas.ts +0 -77
  213. package/src/palettes/blueprint.ts +0 -73
  214. package/src/palettes/catppuccin.ts +0 -84
  215. package/src/palettes/color-utils.ts +0 -443
  216. package/src/palettes/index.ts +0 -67
  217. package/src/palettes/nord.ts +0 -67
  218. package/src/palettes/registry.ts +0 -114
  219. package/src/palettes/slate.ts +0 -73
  220. package/src/palettes/tidewater.ts +0 -73
  221. package/src/palettes/tokyo-night.ts +0 -86
  222. package/src/palettes/types.ts +0 -88
  223. package/src/pert/analyzer.ts +0 -1183
  224. package/src/pert/diagnostics.ts +0 -110
  225. package/src/pert/index.ts +0 -43
  226. package/src/pert/internal.ts +0 -252
  227. package/src/pert/layout.ts +0 -971
  228. package/src/pert/monte-carlo.ts +0 -446
  229. package/src/pert/parser.ts +0 -1606
  230. package/src/pert/renderer.ts +0 -4009
  231. package/src/pert/share-normalize.ts +0 -62
  232. package/src/pert/types.ts +0 -604
  233. package/src/pyramid/parser.ts +0 -185
  234. package/src/pyramid/renderer.ts +0 -768
  235. package/src/pyramid/types.ts +0 -28
  236. package/src/quadrant/parser.ts +0 -18
  237. package/src/quadrant/renderer.ts +0 -638
  238. package/src/raci/diagnostics.ts +0 -213
  239. package/src/raci/index.ts +0 -23
  240. package/src/raci/mutations.ts +0 -321
  241. package/src/raci/parser.ts +0 -699
  242. package/src/raci/renderer.ts +0 -1627
  243. package/src/raci/types.ts +0 -82
  244. package/src/raci/variants.ts +0 -320
  245. package/src/render.ts +0 -268
  246. package/src/ring/parser.ts +0 -212
  247. package/src/ring/renderer.ts +0 -490
  248. package/src/ring/types.ts +0 -27
  249. package/src/sequence/collapse.ts +0 -174
  250. package/src/sequence/parser.ts +0 -1596
  251. package/src/sequence/participant-inference.ts +0 -152
  252. package/src/sequence/renderer.ts +0 -3168
  253. package/src/sequence/tag-resolution.ts +0 -164
  254. package/src/sharing.ts +0 -211
  255. package/src/sitemap/collapse.ts +0 -100
  256. package/src/sitemap/layout.ts +0 -925
  257. package/src/sitemap/parser.ts +0 -755
  258. package/src/sitemap/renderer.ts +0 -828
  259. package/src/sitemap/types.ts +0 -42
  260. package/src/slope/parser.ts +0 -18
  261. package/src/slope/renderer.ts +0 -378
  262. package/src/swimlane/diagnostics.ts +0 -94
  263. package/src/swimlane/layout.ts +0 -597
  264. package/src/swimlane/parser.ts +0 -613
  265. package/src/swimlane/renderer.ts +0 -681
  266. package/src/swimlane/types.ts +0 -151
  267. package/src/tech-radar/interactive.ts +0 -1129
  268. package/src/tech-radar/layout.ts +0 -197
  269. package/src/tech-radar/parser.ts +0 -436
  270. package/src/tech-radar/renderer.ts +0 -1239
  271. package/src/tech-radar/shared.ts +0 -151
  272. package/src/tech-radar/types.ts +0 -86
  273. package/src/themes.ts +0 -22
  274. package/src/timeline/parser.ts +0 -472
  275. package/src/timeline/renderer.ts +0 -3024
  276. package/src/timeline/types.ts +0 -33
  277. package/src/timeline/viz-parser.ts +0 -21
  278. package/src/treemap/diagnostics.ts +0 -62
  279. package/src/treemap/layout-radial.ts +0 -233
  280. package/src/treemap/layout.ts +0 -189
  281. package/src/treemap/parser.ts +0 -463
  282. package/src/treemap/renderer-radial.ts +0 -438
  283. package/src/treemap/renderer.ts +0 -572
  284. package/src/treemap/treemap-shared.ts +0 -309
  285. package/src/treemap/types.ts +0 -60
  286. package/src/utils/arrow-markers.ts +0 -51
  287. package/src/utils/arrows-diagnostics.ts +0 -62
  288. package/src/utils/arrows.ts +0 -227
  289. package/src/utils/brand.ts +0 -61
  290. package/src/utils/card.ts +0 -183
  291. package/src/utils/collapse-engine/tree-edges.ts +0 -115
  292. package/src/utils/collapse-engine/tree.ts +0 -117
  293. package/src/utils/d3-helpers.ts +0 -219
  294. package/src/utils/d3-types.ts +0 -9
  295. package/src/utils/description-helpers.ts +0 -38
  296. package/src/utils/duration.ts +0 -312
  297. package/src/utils/export-container.ts +0 -41
  298. package/src/utils/expr-eval.ts +0 -27
  299. package/src/utils/fit-canvas.ts +0 -64
  300. package/src/utils/hover-styles.ts +0 -673
  301. package/src/utils/inline-markdown.ts +0 -96
  302. package/src/utils/legend-constants.ts +0 -48
  303. package/src/utils/legend-d3.ts +0 -618
  304. package/src/utils/legend-integration.ts +0 -107
  305. package/src/utils/legend-layout.ts +0 -776
  306. package/src/utils/legend-svg.ts +0 -214
  307. package/src/utils/legend-types.ts +0 -272
  308. package/src/utils/name-normalize.ts +0 -163
  309. package/src/utils/note-box/constants.ts +0 -25
  310. package/src/utils/note-box/index.ts +0 -11
  311. package/src/utils/note-box/metrics.ts +0 -90
  312. package/src/utils/note-box/svg.ts +0 -331
  313. package/src/utils/notes/bounds.ts +0 -30
  314. package/src/utils/notes/build.ts +0 -131
  315. package/src/utils/notes/index.ts +0 -18
  316. package/src/utils/notes/model.ts +0 -19
  317. package/src/utils/notes/parse.ts +0 -131
  318. package/src/utils/notes/place.ts +0 -177
  319. package/src/utils/notes/resolve.ts +0 -88
  320. package/src/utils/number-format.ts +0 -36
  321. package/src/utils/parsing.ts +0 -953
  322. package/src/utils/reserved-key-registry.ts +0 -239
  323. package/src/utils/safe-href.ts +0 -38
  324. package/src/utils/scaling.ts +0 -97
  325. package/src/utils/svg-embed.ts +0 -251
  326. package/src/utils/tag-groups.ts +0 -607
  327. package/src/utils/text-measure.ts +0 -122
  328. package/src/utils/time-ticks.ts +0 -253
  329. package/src/utils/title-constants.ts +0 -24
  330. package/src/utils/visual-conventions.ts +0 -61
  331. package/src/utils/wrapped-desc.ts +0 -87
  332. package/src/venn/parser.ts +0 -18
  333. package/src/venn/renderer.ts +0 -1047
  334. package/src/version-control/diagnostics.ts +0 -67
  335. package/src/version-control/parser.ts +0 -544
  336. package/src/version-control/renderer.ts +0 -724
  337. package/src/version-control/types.ts +0 -100
  338. package/src/visualizations/parse.ts +0 -1560
  339. package/src/visualizations/types.ts +0 -262
  340. package/src/wireframe/layout.ts +0 -479
  341. package/src/wireframe/parser.ts +0 -1114
  342. package/src/wireframe/renderer.ts +0 -1318
  343. package/src/wireframe/types.ts +0 -110
  344. package/src/wordcloud/parser.ts +0 -18
  345. package/src/wordcloud/renderer.ts +0 -357
@@ -1,128 +0,0 @@
1
- import {
2
- REGISTRY_DIRECTIVE_TOKENS,
3
- REGISTRY_CONTROL_TOKENS,
4
- REGISTRY_STATUS_TOKENS,
5
- REGISTRY_MODIFIER_TOKENS,
6
- } from '../directives-registry';
7
-
8
- /** All supported DGMO chart types. */
9
- export const CHART_TYPES = new Set([
10
- // Diagram types
11
- 'sequence',
12
- 'flowchart',
13
- 'class',
14
- 'er',
15
- 'org',
16
- 'kanban',
17
- 'c4',
18
- 'state',
19
- 'sitemap',
20
- 'infra',
21
- 'gantt',
22
- 'pert',
23
- 'boxes-and-lines',
24
- 'swimlane',
25
- 'version-control',
26
- 'wireframe',
27
- 'tech-radar',
28
- 'mindmap',
29
- 'journey-map',
30
- 'pyramid',
31
- 'ring',
32
- 'treemap',
33
- 'block',
34
- 'raci',
35
- 'cycle',
36
- // Data chart types
37
- 'bar',
38
- 'line',
39
- 'pie',
40
- 'polar-area',
41
- 'radar',
42
- 'scatter',
43
- 'sankey',
44
- 'function',
45
- 'heatmap',
46
- 'funnel',
47
- // Visualization types
48
- 'slope',
49
- 'wordcloud',
50
- 'arc',
51
- 'timeline',
52
- 'event-line',
53
- 'venn',
54
- 'quadrant',
55
- 'map',
56
- ]);
57
-
58
- /** Metadata keys recognized across chart types. */
59
- export const METADATA_KEYS = new Set([
60
- 'title',
61
- 'series',
62
- // Bar layout headers + pie/line directives (consolidation #23–#26)
63
- 'stack',
64
- 'group',
65
- 'hole',
66
- 'fill',
67
- 'layout',
68
- 'orientation',
69
- 'x-label',
70
- 'y-label',
71
- 'y-right-label',
72
- 'size-label',
73
- 'x',
74
- 'columns',
75
- 'rows',
76
- 'labels',
77
- 'rotate',
78
- 'max',
79
- 'size',
80
- 'order',
81
- 'sort',
82
- 'scale',
83
- 'values',
84
- 'notation',
85
- 'x-axis',
86
- 'y-axis',
87
- 'top-right',
88
- 'top-left',
89
- 'bottom-right',
90
- 'bottom-left',
91
- // Tech-radar pipe metadata
92
- 'quadrant',
93
- 'ring',
94
- 'trend',
95
- // Map (§24B) reserved metadata keys
96
- 'value',
97
- 'label',
98
- 'style',
99
- // Treemap color-by-value metric key
100
- 'heat',
101
- ]);
102
-
103
- /** Tag declaration keyword. */
104
- export const TAG_KEYWORD = 'tag';
105
-
106
- // The four specializer-read keyword sets below are now sourced entirely from
107
- // directives-registry.ts (the single declaration site). Each is a thin spread
108
- // of that registry's category contribution; add or change vocabulary in the
109
- // registry, not here. tests/highlight-coverage.test.ts asserts these sets
110
- // equal the registry contributions exactly (no drift) and pins a full
111
- // inventory snapshot.
112
-
113
- /** Directive keywords — commands that configure chart behavior. */
114
- export const DIRECTIVE_KEYWORDS = new Set([...REGISTRY_DIRECTIVE_TOKENS]);
115
-
116
- /** Control flow keywords — structural blocks + wireframe element leaders. */
117
- export const CONTROL_KEYWORDS = new Set([...REGISTRY_CONTROL_TOKENS]);
118
-
119
- /**
120
- * Status keywords — kanban. (Tech-radar trend values `new`/`up`/`down`/`stable`
121
- * are intentionally absent — they collide with common English prose; the
122
- * tech-radar parser validates them explicitly and completion still suggests
123
- * them in trend-value position.)
124
- */
125
- export const STATUS_KEYWORDS = new Set([...REGISTRY_STATUS_TOKENS]);
126
-
127
- /** Modifier keywords — adjust declarations (incl. ER column types/modifiers). */
128
- export const MODIFIER_KEYWORDS = new Set([...REGISTRY_MODIFIER_TOKENS]);
@@ -1,30 +0,0 @@
1
- import {
2
- ChartType,
3
- TagKeyword,
4
- DirectiveKeyword,
5
- ControlKeyword,
6
- ModifierKeyword,
7
- } from './dgmo.grammar.terms.js';
8
- import {
9
- CHART_TYPES,
10
- TAG_KEYWORD,
11
- DIRECTIVE_KEYWORDS,
12
- CONTROL_KEYWORDS,
13
- STATUS_KEYWORDS,
14
- MODIFIER_KEYWORDS,
15
- } from './keywords';
16
-
17
- /**
18
- * Keyword specializer for the Lezer grammar.
19
- * Called on every Identifier token — returns a specialized term ID
20
- * or -1 to keep it as a plain Identifier.
21
- */
22
- export function specializeKeyword(value: string): number {
23
- if (CHART_TYPES.has(value)) return ChartType;
24
- if (value === TAG_KEYWORD) return TagKeyword;
25
- if (DIRECTIVE_KEYWORDS.has(value)) return DirectiveKeyword;
26
- if (CONTROL_KEYWORDS.has(value)) return ControlKeyword;
27
- if (STATUS_KEYWORDS.has(value)) return ModifierKeyword;
28
- if (MODIFIER_KEYWORDS.has(value)) return ModifierKeyword;
29
- return -1;
30
- }
@@ -1,432 +0,0 @@
1
- /**
2
- * `@diagrammo/dgmo/element` — the universal `<dgmo-diagram>` custom element.
3
- *
4
- * A mermaid-style, framework-agnostic client-side web component. Drop the
5
- * IIFE script (`dist/element.js`) on ANY page — Hugo, Jekyll, MkDocs,
6
- * VitePress, plain HTML — and author diagrams as:
7
- *
8
- * ```html
9
- * <script src="https://unpkg.com/@diagrammo/dgmo/dist/element.js"></script>
10
- * <dgmo-diagram palette="nord">
11
- * flowchart
12
- * [Start] -> [Done]
13
- * </dgmo-diagram>
14
- * ```
15
- *
16
- * The element reads its DGMO source (a nested `<script type="text/dgmo">`,
17
- * a `<pre>`, or its own text content — de-indented), calls the isomorphic
18
- * `render()`, sanitizes the SVG, and injects it. Attributes: `palette`,
19
- * `theme`/`color-mode`, `mode` (diagram|showcase), `editor-base`,
20
- * `map-data-base`.
21
- *
22
- * DOM strategy — **light DOM** (not shadow DOM). Rationale: the rendered
23
- * SVG, source panel, and syntax-highlight token classes are all styled by
24
- * the shared `auto.css` (injected once via `ensureStyles()`). Cloning that
25
- * whole stylesheet into every shadow root would be heavy and would break
26
- * the `.dgmo-tok-*` highlight hooks; the CSS is already namespaced under
27
- * `.dgmo-*` so collision risk is low. See the CLAUDE.md embed notes.
28
- *
29
- * Map-data seam — the base bundle never statically imports the ~380 KB geo
30
- * JSON. Only when a diagram's first token is `map` does the element
31
- * lazy-`fetch()` the map assets from `map-data-base` (default: the pinned
32
- * unpkg `dist/map-data/` path) and inject them as `render({ mapData })`.
33
- * Fetched data is cached across every element on the page. Non-map diagrams
34
- * trigger ZERO extra network requests.
35
- */
36
-
37
- import { render } from '../render';
38
- import { parseDgmoChartType } from '../dgmo-router';
39
- import type { MapData } from '../map/resolved-types';
40
- import '../palettes';
41
- import {
42
- VERSION,
43
- EDITOR_BASE_URL,
44
- ensureStyles,
45
- resolveTheme,
46
- sanitizeSvgInPlace,
47
- deriveAriaLabel,
48
- buildRenderedBlock,
49
- buildErrorBlock,
50
- buildShareUrl,
51
- sharedWarn,
52
- type ThemePreference,
53
- } from '../auto/shared';
54
-
55
- // ============================================================
56
- // Map-data lazy loader (fetch-based, browser DI seam)
57
- // ============================================================
58
-
59
- /** Default CDN base for the map geo JSON, pinned to THIS package version so an
60
- * element loaded from a stale bundle can't fetch mismatched assets. */
61
- const DEFAULT_MAP_DATA_BASE = `https://unpkg.com/@diagrammo/dgmo@${VERSION}/dist/map-data/`;
62
-
63
- // File names mirror src/map/load-data.ts's FILES map (the Node fs loader).
64
- const REQUIRED_MAP_FILES = {
65
- worldCoarse: 'world-coarse.json',
66
- worldDetail: 'world-detail.json',
67
- usStates: 'us-states.json',
68
- gazetteer: 'gazetteer.json',
69
- } as const;
70
- const OPTIONAL_MAP_FILES = {
71
- lakes: 'lakes.json',
72
- rivers: 'rivers.json',
73
- mountainRanges: 'mountain-ranges.json',
74
- naLand: 'na-land.json',
75
- naLakes: 'na-lakes.json',
76
- waterBodies: 'water-bodies.json',
77
- airports: 'airports.json',
78
- } as const;
79
-
80
- /** Cache assembled MapData per base URL so N `<dgmo-diagram map>` elements on a
81
- * page share ONE set of fetches. A rejected load is evicted so a later element
82
- * can retry (mirrors the Node loader's non-poisoning memo). */
83
- const mapDataCache = new Map<string, Promise<MapData>>();
84
-
85
- function normalizeBase(base: string): string {
86
- return base.endsWith('/') ? base : base + '/';
87
- }
88
-
89
- async function fetchJson<T>(base: string, file: string): Promise<T> {
90
- const res = await fetch(base + file);
91
- if (!res.ok) {
92
- throw new Error(`map asset ${file} → HTTP ${res.status}`);
93
- }
94
- return (await res.json()) as T;
95
- }
96
-
97
- async function loadMapDataFromBase(rawBase: string): Promise<MapData> {
98
- const base = normalizeBase(rawBase);
99
- const cached = mapDataCache.get(base);
100
- if (cached) return cached;
101
-
102
- const promise = (async (): Promise<MapData> => {
103
- // Required assets fail the whole load if any are missing.
104
- const [worldCoarse, worldDetail, usStates, gazetteer] = await Promise.all([
105
- fetchJson<MapData['worldCoarse']>(base, REQUIRED_MAP_FILES.worldCoarse),
106
- fetchJson<MapData['worldDetail']>(base, REQUIRED_MAP_FILES.worldDetail),
107
- fetchJson<MapData['usStates']>(base, REQUIRED_MAP_FILES.usStates),
108
- fetchJson<MapData['gazetteer']>(base, REQUIRED_MAP_FILES.gazetteer),
109
- ]);
110
- // Optional assets degrade to `undefined` (older bundles / trimmed CDNs).
111
- const optionalEntries = await Promise.all(
112
- (
113
- Object.entries(OPTIONAL_MAP_FILES) as Array<
114
- [keyof typeof OPTIONAL_MAP_FILES, string]
115
- >
116
- ).map(async ([key, file]) => {
117
- try {
118
- return [key, await fetchJson<unknown>(base, file)] as const;
119
- } catch {
120
- return [key, undefined] as const;
121
- }
122
- })
123
- );
124
- const optional: Record<string, unknown> = {};
125
- for (const [key, value] of optionalEntries) {
126
- if (value !== undefined) optional[key] = value;
127
- }
128
- return {
129
- worldCoarse,
130
- worldDetail,
131
- usStates,
132
- gazetteer,
133
- ...optional,
134
- } as MapData;
135
- })().catch((err: unknown) => {
136
- mapDataCache.delete(base); // don't poison retries with a rejected promise
137
- throw err;
138
- });
139
-
140
- mapDataCache.set(base, promise);
141
- return promise;
142
- }
143
-
144
- // ============================================================
145
- // Source extraction
146
- // ============================================================
147
-
148
- /** Strip a uniform leading indent and surrounding blank lines so authors can
149
- * indent the DGMO block to match their surrounding HTML without the indent
150
- * leaking into the parser. */
151
- function dedent(raw: string): string {
152
- const lines = raw.replace(/\t/g, ' ').split('\n');
153
- // Drop leading/trailing blank lines.
154
- while (lines.length && lines[0]!.trim() === '') lines.shift();
155
- while (lines.length && lines[lines.length - 1]!.trim() === '') lines.pop();
156
- if (lines.length === 0) return '';
157
- let min = Infinity;
158
- for (const line of lines) {
159
- if (line.trim() === '') continue;
160
- const indent = line.length - line.trimStart().length;
161
- if (indent < min) min = indent;
162
- }
163
- if (!Number.isFinite(min) || min === 0) return lines.join('\n');
164
- return lines.map((l) => l.slice(min)).join('\n');
165
- }
166
-
167
- // ============================================================
168
- // The custom element
169
- // ============================================================
170
-
171
- const OBSERVED = [
172
- 'palette',
173
- 'theme',
174
- 'color-mode',
175
- 'mode',
176
- 'editor-base',
177
- 'map-data-base',
178
- ] as const;
179
-
180
- export class DgmoDiagram extends HTMLElement {
181
- static get observedAttributes(): readonly string[] {
182
- return OBSERVED;
183
- }
184
-
185
- /** DGMO source, captured from the original children ONCE before the first
186
- * render replaces them. */
187
- private source: string | null = null;
188
- /** Monotonic render token — a late-resolving render/fetch whose token is
189
- * stale (superseded by a newer attribute-driven render) is discarded. */
190
- private renderToken = 0;
191
- private container: HTMLDivElement | null = null;
192
-
193
- connectedCallback(): void {
194
- if (this.source === null) {
195
- this.source = this.readSource();
196
- ensureStyles();
197
- // Replace authored children with a managed container (light DOM).
198
- this.textContent = '';
199
- this.container = document.createElement('div');
200
- this.appendChild(this.container);
201
- }
202
- void this.rerender();
203
- }
204
-
205
- attributeChangedCallback(
206
- _name: string,
207
- oldValue: string | null,
208
- newValue: string | null
209
- ): void {
210
- // Ignore the initial attribute set (before connect) and no-op changes.
211
- if (this.source === null || oldValue === newValue) return;
212
- void this.rerender();
213
- }
214
-
215
- // ---- source ----
216
-
217
- private readSource(): string {
218
- const script = this.querySelector('script[type="text/dgmo"]');
219
- if (script) return dedent(script.textContent || '');
220
- const pre = this.querySelector('pre');
221
- if (pre) return dedent(pre.textContent || '');
222
- return dedent(this.textContent || '');
223
- }
224
-
225
- // ---- attribute resolution ----
226
-
227
- private themePreference(): ThemePreference {
228
- // `color-mode` is canonical; `theme` is an accepted synonym.
229
- const raw = (
230
- this.getAttribute('color-mode') ||
231
- this.getAttribute('theme') ||
232
- 'auto'
233
- ).toLowerCase();
234
- if (
235
- raw === 'auto' ||
236
- raw === 'light' ||
237
- raw === 'dark' ||
238
- raw === 'transparent'
239
- ) {
240
- return raw;
241
- }
242
- return 'auto';
243
- }
244
-
245
- private palette(): string {
246
- return this.getAttribute('palette') || 'slate';
247
- }
248
-
249
- private editorBase(): string {
250
- return this.getAttribute('editor-base') || EDITOR_BASE_URL;
251
- }
252
-
253
- private mapDataBase(): string {
254
- return this.getAttribute('map-data-base') || DEFAULT_MAP_DATA_BASE;
255
- }
256
-
257
- private isShowcase(): boolean {
258
- return (
259
- (this.getAttribute('mode') || 'diagram').toLowerCase() === 'showcase'
260
- );
261
- }
262
-
263
- // ---- render pipeline ----
264
-
265
- private mount(node: Node, classes: string): void {
266
- if (!this.container) return;
267
- this.container.className = classes;
268
- this.container.textContent = '';
269
- this.container.appendChild(node);
270
- }
271
-
272
- private showError(opts: {
273
- message: string;
274
- severity?: string;
275
- line?: number;
276
- column?: number;
277
- }): void {
278
- // The standard error card carries `.dgmo.dgmo--error` on its own root,
279
- // so the container itself stays class-free.
280
- this.mount(buildErrorBlock({ ...opts, source: this.source ?? '' }), '');
281
- }
282
-
283
- private async rerender(): Promise<void> {
284
- const token = ++this.renderToken;
285
- const src = this.source ?? '';
286
-
287
- if (src.trim() === '') {
288
- this.showError({ message: 'No DGMO source provided', severity: 'error' });
289
- return;
290
- }
291
-
292
- // Loading state (visible only while an async render/fetch is in flight).
293
- const loading = document.createElement('div');
294
- loading.textContent = 'Rendering diagram…';
295
- this.mount(loading, 'dgmo--loading');
296
-
297
- const themePref = this.themePreference();
298
- const resolvedTheme =
299
- themePref === 'transparent' ? 'transparent' : resolveTheme(themePref);
300
- const palette = this.palette();
301
-
302
- // Cheap chart-type detection (first token) — only `map` needs geo data.
303
- let mapData: MapData | undefined;
304
- const chartType = parseDgmoChartType(src);
305
- if (chartType === 'map') {
306
- const base = this.mapDataBase();
307
- if (!base) {
308
- this.showError({
309
- message:
310
- 'Map diagrams need map data — set a "map-data-base" URL on <dgmo-diagram>.',
311
- severity: 'error',
312
- });
313
- return;
314
- }
315
- try {
316
- mapData = await loadMapDataFromBase(base);
317
- } catch (err) {
318
- sharedWarn('map data fetch failed:', err);
319
- this.showError({
320
- message: `Could not load map data from "${base}". Check the "map-data-base" URL.`,
321
- severity: 'error',
322
- });
323
- return;
324
- }
325
- if (token !== this.renderToken) return; // superseded while fetching
326
- }
327
-
328
- let result: Awaited<ReturnType<typeof render>>;
329
- try {
330
- result = await render(src, {
331
- theme: resolvedTheme,
332
- palette,
333
- ...(mapData !== undefined && { mapData }),
334
- });
335
- } catch (err) {
336
- if (token !== this.renderToken) return;
337
- const message =
338
- err instanceof Error ? err.message : 'Render failed unexpectedly';
339
- this.showError({ message, severity: 'error' });
340
- sharedWarn('render() rejected:', err);
341
- return;
342
- }
343
- if (token !== this.renderToken) return;
344
-
345
- if (result.diagnostics && result.diagnostics.length > 0) {
346
- const d = result.diagnostics[0]!;
347
- this.showError({
348
- message: d.message,
349
- severity: d.severity,
350
- ...(d.line !== undefined && { line: d.line }),
351
- ...(d.column !== undefined && { column: d.column }),
352
- });
353
- return;
354
- }
355
-
356
- if (!result.svg) {
357
- this.showError({
358
- message: 'Empty SVG returned from renderer',
359
- severity: 'error',
360
- });
361
- return;
362
- }
363
-
364
- // Parse + sanitize the SVG before it lands in the live DOM.
365
- const holder = document.createElement('div');
366
- holder.innerHTML = result.svg;
367
- const svgEl = holder.querySelector('svg');
368
- if (!svgEl) {
369
- this.showError({
370
- message: 'Empty SVG returned from renderer',
371
- severity: 'error',
372
- });
373
- return;
374
- }
375
- sanitizeSvgInPlace(svgEl);
376
- svgEl.setAttribute('role', 'img');
377
- svgEl.setAttribute('aria-label', deriveAriaLabel(src));
378
-
379
- const themeClass =
380
- resolvedTheme === 'dark'
381
- ? 'dgmo-theme-dark'
382
- : resolvedTheme === 'transparent'
383
- ? 'dgmo-theme-transparent'
384
- : 'dgmo-theme-light';
385
-
386
- // Showcase chrome: standard embed block (BL-114) with the hover-reveal
387
- // toolbar (view-source toggle + Copy + Open-in-editor).
388
- const showcase = this.isShowcase();
389
- const shareUrl = showcase
390
- ? buildShareUrl(src, {
391
- palette,
392
- theme: resolvedTheme === 'dark' ? 'dark' : 'light',
393
- editorBase: this.editorBase(),
394
- campaign: VERSION,
395
- utmSource: 'element-embed',
396
- })
397
- : null;
398
-
399
- const wrapper = buildRenderedBlock({
400
- source: src,
401
- svgEl,
402
- themeClass,
403
- showSource: showcase,
404
- showEditorLink: showcase,
405
- shareUrl,
406
- });
407
-
408
- this.mount(wrapper, 'dgmo--rendered');
409
- }
410
- }
411
-
412
- // ============================================================
413
- // Self-registration
414
- // ============================================================
415
-
416
- /** Idempotently define `<dgmo-diagram>`. Safe to call multiple times and in
417
- * SSR/no-DOM contexts (no-ops when `customElements` is unavailable). */
418
- export function defineDgmoDiagram(): void {
419
- if (typeof customElements === 'undefined') return;
420
- if (customElements.get('dgmo-diagram')) return;
421
- try {
422
- customElements.define('dgmo-diagram', DgmoDiagram);
423
- } catch {
424
- // Another copy of the bundle may have won the race — harmless.
425
- }
426
- }
427
-
428
- // Auto-register on load so `<script src=".../element.js">` + `<dgmo-diagram>`
429
- // works with zero glue code.
430
- defineDgmoDiagram();
431
-
432
- export default DgmoDiagram;