@sccharts-lab/diagram 0.0.0-stage → 0.1.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.
Files changed (44) hide show
  1. package/LICENSE +277 -0
  2. package/README.md +169 -2
  3. package/dist/dataflow.d.ts +18 -0
  4. package/dist/dataflow.js +216 -0
  5. package/dist/dataflow.js.map +1 -0
  6. package/dist/diagram.css +521 -0
  7. package/dist/elk-types.d.ts +50 -0
  8. package/dist/elk-types.js +5 -0
  9. package/dist/elk-types.js.map +1 -0
  10. package/dist/elk-worker.d.ts +10 -0
  11. package/dist/elk-worker.js +18 -0
  12. package/dist/elk-worker.js.map +1 -0
  13. package/dist/font-metrics.d.ts +13 -0
  14. package/dist/font-metrics.js +23 -0
  15. package/dist/font-metrics.js.map +1 -0
  16. package/dist/fonts/atkinson-hyperlegible-mono-latin-ext-wght-normal.woff2 +0 -0
  17. package/dist/fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2 +0 -0
  18. package/dist/fonts/atkinson-hyperlegible-mono.LICENSE.txt +93 -0
  19. package/dist/fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2 +0 -0
  20. package/dist/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2 +0 -0
  21. package/dist/fonts/atkinson-hyperlegible-next.LICENSE.txt +93 -0
  22. package/dist/fonts.css +42 -0
  23. package/dist/geometry.d.ts +24 -0
  24. package/dist/geometry.js +115 -0
  25. package/dist/geometry.js.map +1 -0
  26. package/dist/highlight.d.ts +35 -0
  27. package/dist/highlight.js +83 -0
  28. package/dist/highlight.js.map +1 -0
  29. package/dist/index.d.ts +16 -0
  30. package/dist/index.js +32 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/layout.d.ts +6 -0
  33. package/dist/layout.js +838 -0
  34. package/dist/layout.js.map +1 -0
  35. package/dist/measure.d.ts +23 -0
  36. package/dist/measure.js +73 -0
  37. package/dist/measure.js.map +1 -0
  38. package/dist/render.d.ts +3 -0
  39. package/dist/render.js +327 -0
  40. package/dist/render.js.map +1 -0
  41. package/dist/types.d.ts +221 -0
  42. package/dist/types.js +4 -0
  43. package/dist/types.js.map +1 -0
  44. package/package.json +70 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"font-metrics.js","sourceRoot":"","sources":["../src/font-metrics.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,gGAAgG;AAYhG,MAAM,CAAC,MAAM,YAAY,GAA2D;IAChF,IAAI,EAAE;QACF,MAAM,EAAE,qCAAqC;QAC7C,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,siEAAsiE;QAC/iE,IAAI,EAAE,siEAAsiE;KAC/iE;IACD,IAAI,EAAE;QACF,MAAM,EAAE,qCAAqC;QAC7C,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,qiEAAqiE;QAC9iE,IAAI,EAAE,qiEAAqiE;KAC9iE;CACJ,CAAA","sourcesContent":["// Generated by tools/diagram-metrics.mjs from the fonts in node_modules. Do not edit by hand.\n// Advance widths in 1/1000 em, as runs \"startCodePointHex:w,w,...;...\". Vertical metrics in em.\n\nexport interface EncodedFontMetrics {\n family: string\n ascent: number\n descent: number\n capHeight: number\n xHeight: number\n regular: string\n bold: string\n}\n\nexport const FONT_METRICS: { sans: EncodedFontMetrics; mono: EncodedFontMetrics } = {\n sans: {\n family: \"Atkinson Hyperlegible Next Variable\",\n ascent: 0.984,\n descent: 0.316,\n capHeight: 0.672,\n xHeight: 0.5,\n regular: \"20:280,286,301,651,592,919,731,160,299,299,485,606,210,362,210,387,648,407,548,576,614,588,598,510,615,595,210,210,553,628,553,480,778,626,613,645,669,569,552,694,694,392,512,631,541,824,693,714,592,724,614,592,558,690,593,856,623,575,607,317,387,344,552,372,243,525,566,485,564,538,314,558,550,252,245,492,262,845,550,548,566,574,349,471,326,540,461,684,481,449,460,344,237,344,555;a0:280,286,485,610,580,575,237,528,368,798,371,562,602,0,798,356,352,579,382,383,243;b6:509,240,265,256,380,562,816,820,867,450,626,626,626,626,626,626,891,645,569,569,569,569,392,392,392,392,689,693,714,714,714,714,714,532,714,690,690,690,690,575,592,582,525,525,525,525,525,525,866,485,538,538,538,538,252,252,252,266,565,550,548,548,548,548,548,606,548,540,540,540,540,449,566,449,626,525,626,525,626,525,645,485;10a:645,485,645,485,669,634,689,564,569,538;116:569,538,569,538,569,538;11e:694,558,694,558,694,558;126:694,550,392,252,392,252;12e:392,252,392,252,904,497;136:631,492;139:541,262,541,262,541,317;141:571,296,693,550,693,550,693,550;14c:714,548;150:714,548,1006,924,614,349;158:614,349,592,471;15e:592,471,592,471,558,326,558,326;168:690,540,690,540;16e:690,540,690,540,690,540,856,684,575,449,575,607,460,607,460,607,460;3a2:527;2013:504,824;2018:236,236,236;201c:399,399,399;2020:541;2022:438;2026:670;220f:823;2211:713,606,838,838,598,637,838;221b:637,637,714;221f:979;2221:896,838;2225:500,500;222b:274,789,1057,521,789,1057,521,521,521;2239:838,838,838;223e:838,838,375;2242:838;2246:838;224d:838,838,838,838,838,839,839;2256:838;2258:838,838,838,838,838,838,838;2263:838;2266:838,838,838,838,1047,1047;226d:838;2276:838,838,838,838;227c:838,838,838,838;228a:838,838,732,732;228f:838,838;229d:838,838,838,838,838;22a6:521,521,871,871,871,871;22ad:871,871,871,838,838,838,838;22b6:1000,1000;22b9:838,521,732,732,732,838,838,820,820;22c5:318;22c7:838;22cb:1000,1000;22cf:732;22d2:838,838,838,838,838,838,1422,1422,838,838,838,838,838,838,838,838;22e4:838,838,838,838,838,838,838,838;22ee:1000,1000,1000,1000,1000,871,718,871,871,718,871,871,1000,871,718,871,718,871;2713:838;2717:838\",\n bold: \"20:313,303,390,765,610,969,725,210,335,335,485,595,271,373,272,440,659,440,579,600,624,608,626,537,624,571,272,272,569,612,569,547,781,678,643,658,689,597,566,718,701,425,561,664,552,858,717,747,629,757,650,610,607,686,644,886,685,650,618,340,440,344,582,400,288,552,596,510,596,563,365,593,571,300,259,555,318,882,571,576,596,599,376,508,376,567,530,740,540,521,506,381,254,381,537;a0:313,303,510,634,593,650,254,555,432,798,391,649,615,0,798,383,394,611,402,407,288;b6:521,294,298,284,403,649,846,853,921,526,678,678,678,678,678,678,966,658,597,597,597,597,425,425,425,425,709,717,747,747,747,747,747,536,747,686,686,686,686,650,629,621,552,552,552,552,552,552,878,510,563,563,563,563,300,300,300,314,588,571,576,576,576,576,576,595,576,567,567,567,567,521,596,521,678,552,678,552,678,552,658,510;10a:658,510,658,510,689,694,709,596,597,563;116:597,563,597,563,597,563;11e:718,593,718,593,718,593;126:701,571,425,300,425,300;12e:425,300,425,300,985,559;136:664,555;139:552,318,552,318,552,365;141:582,348,717,571,717,571,717,571;14c:747,576;150:747,576,1024,936,650,376;158:650,376,610,508;15e:610,508,610,508,607,376,607,376;168:686,567,686,567;16e:686,567,686,567,686,567,886,740,650,521,650,618,506,618,506,618,506;3a2:527;2013:501,832;2018:269,269,269;201c:479,479,479;2020:582;2022:438;2026:781;220f:823;2211:713,595,838,838,641,637,838;221b:637,637,714;221f:979;2221:896,838;2225:500,500;222b:274,789,1057,521,789,1057,521,521,521;2239:838,838,838;223e:838,838,375;2242:838;2246:838;224d:838,838,838,838,838,839,839;2256:838;2258:838,838,838,838,838,838,838;2263:838;2266:838,838,838,838,1047,1047;226d:838;2276:838,838,838,838;227c:838,838,838,838;228a:838,838,732,732;228f:838,838;229d:838,838,838,838,838;22a6:521,521,871,871,871,871;22ad:871,871,871,838,838,838,838;22b6:1000,1000;22b9:838,521,732,732,732,838,838,820,820;22c5:318;22c7:838;22cb:1000,1000;22cf:732;22d2:838,838,838,838,838,838,1422,1422,838,838,838,838,838,838,838,838;22e4:838,838,838,838,838,838,838,838;22ee:1000,1000,1000,1000,1000,871,718,871,871,718,871,871,1000,871,718,871,718,871;2713:838;2717:838\",\n },\n mono: {\n family: \"Atkinson Hyperlegible Mono Variable\",\n ascent: 0.984,\n descent: 0.316,\n capHeight: 0.672,\n xHeight: 0.5,\n regular: \"20:632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632;a0:632,632,632,632,632,632,632,632,632,632,632,632,632,0,632,632,632,632,632,632,632;b6:632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632;10a:632,632,632,632,632,632,632,632,632,632;116:632,632,632,632,632,632;11e:632,632,632,632,632,632;126:632,632,632,632,632,632;12e:632,632,632,632,632,632;136:632,632;139:632,632,632,632,632,632;141:632,632,632,632,632,632,632,632;14c:632,632;150:632,632,632,632,632,632;158:632,632,632,632;15e:632,632,632,632,632,632,632,632;168:632,632,632,632;16e:632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632;3a2:632;2013:632,632;2018:632,632,632;201c:632,632,632;2020:632;2022:632;2026:632;220f:823;2211:713,632,838,838,632,637,838;221b:637,637,714;221f:979;2221:896,838;2225:500,500;222b:274,789,1057,521,789,1057,521,521,521;2239:838,838,838;223e:838,838,375;2242:838;2246:838;224d:838,838,838,838,838,839,839;2256:838;2258:838,838,838,838,838,838,838;2263:838;2266:838,838,838,838,1047,1047;226d:838;2276:838,838,838,838;227c:838,838,838,838;228a:838,838,732,732;228f:838,838;229d:838,838,838,838,838;22a6:521,521,871,871,871,871;22ad:871,871,871,838,838,838,838;22b6:1000,1000;22b9:838,521,732,732,732,838,838,820,820;22c5:318;22c7:838;22cb:1000,1000;22cf:732;22d2:838,838,838,838,838,838,1422,1422,838,838,838,838,838,838,838,838;22e4:838,838,838,838,838,838,838,838;22ee:1000,1000,1000,1000,1000,871,718,871,871,718,871,871,1000,871,718,871,718,871;2713:838;2717:838\",\n bold: \"20:632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632;a0:632,632,632,632,632,632,632,632,632,632,632,632,632,0,632,632,632,632,632,632,632;b6:632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632;10a:632,632,632,632,632,632,632,632,632,632;116:632,632,632,632,632,632;11e:632,632,632,632,632,632;126:632,632,632,632,632,632;12e:632,632,632,632,632,632;136:632,632;139:632,632,632,632,632,632;141:632,632,632,632,632,632,632,632;14c:632,632;150:632,632,632,632,632,632;158:632,632,632,632;15e:632,632,632,632,632,632,632,632;168:632,632,632,632;16e:632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632,632;3a2:632;2013:632,632;2018:632,632,632;201c:632,632,632;2020:632;2022:632;2026:632;220f:823;2211:713,632,838,838,632,637,838;221b:637,637,714;221f:979;2221:896,838;2225:500,500;222b:274,789,1057,521,789,1057,521,521,521;2239:838,838,838;223e:838,838,375;2242:838;2246:838;224d:838,838,838,838,838,839,839;2256:838;2258:838,838,838,838,838,838,838;2263:838;2266:838,838,838,838,1047,1047;226d:838;2276:838,838,838,838;227c:838,838,838,838;228a:838,838,732,732;228f:838,838;229d:838,838,838,838,838;22a6:521,521,871,871,871,871;22ad:871,871,871,838,838,838,838;22b6:1000,1000;22b9:838,521,732,732,732,838,838,820,820;22c5:318;22c7:838;22cb:1000,1000;22cf:732;22d2:838,838,838,838,838,838,1422,1422,838,838,838,838,838,838,838,838;22e4:838,838,838,838,838,838,838,838;22ee:1000,1000,1000,1000,1000,871,718,871,871,718,871,871,1000,871,718,871,718,871;2713:838;2717:838\",\n },\n}\n"]}
@@ -0,0 +1,93 @@
1
+ Copyright 2020-2024 The Atkinson Hyperlegible Mono Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next-mono) AtkinsonHyperlegibleMono-Italic[wght].ttf: Copyright 2020-2024 The Atkinson Hyperlegible Mono Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next-mono)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Copyright 2020-2024 The Atkinson Hyperlegible Next Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next) AtkinsonHyperlegibleNext-Italic[wght].ttf: Copyright 2020-2024 The Atkinson Hyperlegible Next Project Authors (https://github.com/googlefonts/atkinson-hyperlegible-next)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
package/dist/fonts.css ADDED
@@ -0,0 +1,42 @@
1
+ /* The fonts @sccharts-lab/diagram measures its text in (font-metrics.ts). Load this with diagram.css unless the
2
+ page already has Atkinson Hyperlegible Next and Mono as "... Variable" families (as @fontsource-variable names them). */
3
+ /* atkinson-hyperlegible-next from @fontsource-variable/atkinson-hyperlegible-next 5.3.0 (SIL Open Font License 1.1: fonts/atkinson-hyperlegible-next.LICENSE.txt) */
4
+ /* atkinson-hyperlegible-next-latin-ext-wght-normal */
5
+ @font-face {
6
+ font-family: 'Atkinson Hyperlegible Next Variable';
7
+ font-style: normal;
8
+ font-display: swap;
9
+ font-weight: 200 800;
10
+ src: url(./fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2) format('woff2-variations');
11
+ unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
12
+ }
13
+
14
+ /* atkinson-hyperlegible-next-latin-wght-normal */
15
+ @font-face {
16
+ font-family: 'Atkinson Hyperlegible Next Variable';
17
+ font-style: normal;
18
+ font-display: swap;
19
+ font-weight: 200 800;
20
+ src: url(./fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2) format('woff2-variations');
21
+ unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
22
+ }
23
+ /* atkinson-hyperlegible-mono from @fontsource-variable/atkinson-hyperlegible-mono 5.3.0 (SIL Open Font License 1.1: fonts/atkinson-hyperlegible-mono.LICENSE.txt) */
24
+ /* atkinson-hyperlegible-mono-latin-ext-wght-normal */
25
+ @font-face {
26
+ font-family: 'Atkinson Hyperlegible Mono Variable';
27
+ font-style: normal;
28
+ font-display: swap;
29
+ font-weight: 200 800;
30
+ src: url(./fonts/atkinson-hyperlegible-mono-latin-ext-wght-normal.woff2) format('woff2-variations');
31
+ unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
32
+ }
33
+
34
+ /* atkinson-hyperlegible-mono-latin-wght-normal */
35
+ @font-face {
36
+ font-family: 'Atkinson Hyperlegible Mono Variable';
37
+ font-style: normal;
38
+ font-display: swap;
39
+ font-weight: 200 800;
40
+ src: url(./fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2) format('woff2-variations');
41
+ unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
42
+ }
@@ -0,0 +1,24 @@
1
+ import type { Point } from "./types.js";
2
+ /** Rounds to 1/100 for compact, stable output. */
3
+ export declare const r2: (n: number) => number;
4
+ /** True when the points form a cubic Bézier chain: start, then three points per segment. */
5
+ export declare function isBezierChain(points: Point[]): boolean;
6
+ /** SVG path data for routing points: a cubic chain when the count fits, else straight segments. */
7
+ export declare function pathData(points: Point[]): string;
8
+ /** The path as a polyline (16 samples per Bézier segment). */
9
+ export declare function flatten(points: Point[]): Point[];
10
+ export interface PathSample {
11
+ point: Point;
12
+ /** Unit tangent in the direction of travel. */
13
+ tangent: Point;
14
+ }
15
+ /** The point at arc length `distance` from the start (negative: from the end), with the tangent there. */
16
+ export declare function sampleAt(poly: Point[], distance: number): PathSample;
17
+ /** Tangent at the very end of the path (direction of arrival). */
18
+ export declare function endTangent(points: Point[]): Point;
19
+ /** Tangent at the very start of the path (direction of departure). */
20
+ export declare function startTangent(points: Point[]): Point;
21
+ /** Transforms decorator-local points (x along the tangent, y to its right) to diagram coordinates. */
22
+ export declare function place(origin: Point, tangent: Point, local: [number, number][]): Point[];
23
+ /** The polyline point nearest to `p`, with the tangent of its segment. */
24
+ export declare function nearest(poly: Point[], p: Point): PathSample;
@@ -0,0 +1,115 @@
1
+ // Geometry of transition paths: ELK's spline routing points as cubic Bézier segments, flattened for
2
+ // measuring lengths and placing decorators the way KLighD does (at a distance from either end).
3
+ /** Rounds to 1/100 for compact, stable output. */
4
+ export const r2 = (n) => Math.round(n * 100) / 100;
5
+ /** True when the points form a cubic Bézier chain: start, then three points per segment. */
6
+ export function isBezierChain(points) {
7
+ return points.length >= 4 && (points.length - 1) % 3 === 0;
8
+ }
9
+ /** SVG path data for routing points: a cubic chain when the count fits, else straight segments. */
10
+ export function pathData(points) {
11
+ if (points.length === 0)
12
+ return '';
13
+ const p = (q) => `${r2(q.x)} ${r2(q.y)}`;
14
+ let d = `M${p(points[0])}`;
15
+ if (isBezierChain(points)) {
16
+ for (let i = 1; i < points.length; i += 3)
17
+ d += `C${p(points[i])} ${p(points[i + 1])} ${p(points[i + 2])}`;
18
+ }
19
+ else {
20
+ for (let i = 1; i < points.length; i++)
21
+ d += `L${p(points[i])}`;
22
+ }
23
+ return d;
24
+ }
25
+ function cubic(a, b, c, d, t) {
26
+ const u = 1 - t;
27
+ const w0 = u * u * u, w1 = 3 * u * u * t, w2 = 3 * u * t * t, w3 = t * t * t;
28
+ return { x: w0 * a.x + w1 * b.x + w2 * c.x + w3 * d.x, y: w0 * a.y + w1 * b.y + w2 * c.y + w3 * d.y };
29
+ }
30
+ /** The path as a polyline (16 samples per Bézier segment). */
31
+ export function flatten(points) {
32
+ if (!isBezierChain(points))
33
+ return points.slice();
34
+ const out = [points[0]];
35
+ for (let i = 1; i < points.length; i += 3) {
36
+ const a = points[i - 1], b = points[i], c = points[i + 1], d = points[i + 2];
37
+ for (let s = 1; s <= 16; s++)
38
+ out.push(cubic(a, b, c, d, s / 16));
39
+ }
40
+ return out;
41
+ }
42
+ function polylineLength(poly) {
43
+ let len = 0;
44
+ for (let i = 1; i < poly.length; i++)
45
+ len += Math.hypot(poly[i].x - poly[i - 1].x, poly[i].y - poly[i - 1].y);
46
+ return len;
47
+ }
48
+ /** The point at arc length `distance` from the start (negative: from the end), with the tangent there. */
49
+ export function sampleAt(poly, distance) {
50
+ const total = polylineLength(poly);
51
+ let target = distance < 0 ? total + distance : distance;
52
+ target = Math.max(0, Math.min(total, target));
53
+ let walked = 0;
54
+ for (let i = 1; i < poly.length; i++) {
55
+ const a = poly[i - 1], b = poly[i];
56
+ const seg = Math.hypot(b.x - a.x, b.y - a.y);
57
+ if (seg === 0)
58
+ continue;
59
+ if (walked + seg >= target || i === poly.length - 1) {
60
+ const t = Math.min(1, (target - walked) / seg);
61
+ return { point: { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }, tangent: { x: (b.x - a.x) / seg, y: (b.y - a.y) / seg } };
62
+ }
63
+ walked += seg;
64
+ }
65
+ const last = poly[poly.length - 1] ?? { x: 0, y: 0 };
66
+ return { point: last, tangent: { x: 1, y: 0 } };
67
+ }
68
+ /** Tangent at the very end of the path (direction of arrival). */
69
+ export function endTangent(points) {
70
+ const end = points[points.length - 1];
71
+ for (let i = points.length - 2; i >= 0; i--) {
72
+ const dx = end.x - points[i].x, dy = end.y - points[i].y;
73
+ const len = Math.hypot(dx, dy);
74
+ if (len > 1e-6)
75
+ return { x: dx / len, y: dy / len };
76
+ }
77
+ return { x: 1, y: 0 };
78
+ }
79
+ /** Tangent at the very start of the path (direction of departure). */
80
+ export function startTangent(points) {
81
+ const start = points[0];
82
+ for (let i = 1; i < points.length; i++) {
83
+ const dx = points[i].x - start.x, dy = points[i].y - start.y;
84
+ const len = Math.hypot(dx, dy);
85
+ if (len > 1e-6)
86
+ return { x: dx / len, y: dy / len };
87
+ }
88
+ return { x: 1, y: 0 };
89
+ }
90
+ /** Transforms decorator-local points (x along the tangent, y to its right) to diagram coordinates. */
91
+ export function place(origin, tangent, local) {
92
+ return local.map(([x, y]) => ({ x: origin.x + x * tangent.x - y * tangent.y, y: origin.y + x * tangent.y + y * tangent.x }));
93
+ }
94
+ /** The polyline point nearest to `p`, with the tangent of its segment. */
95
+ export function nearest(poly, p) {
96
+ let best = { point: poly[0], tangent: { x: 1, y: 0 } };
97
+ let bestDist = Infinity;
98
+ for (let i = 1; i < poly.length; i++) {
99
+ const a = poly[i - 1], b = poly[i];
100
+ const dx = b.x - a.x, dy = b.y - a.y;
101
+ const len2 = dx * dx + dy * dy;
102
+ if (len2 === 0)
103
+ continue;
104
+ const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2));
105
+ const q = { x: a.x + dx * t, y: a.y + dy * t };
106
+ const dist = Math.hypot(p.x - q.x, p.y - q.y);
107
+ if (dist < bestDist) {
108
+ const len = Math.sqrt(len2);
109
+ bestDist = dist;
110
+ best = { point: q, tangent: { x: dx / len, y: dy / len } };
111
+ }
112
+ }
113
+ return best;
114
+ }
115
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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AAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACpC,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;QAC9B,IAAI,IAAI,KAAK,CAAC;YAAE,SAAQ;QACxB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAChF,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAA;QAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7C,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC3B,QAAQ,GAAG,IAAI,CAAA;YACf,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,EAAE,CAAA;QAC9D,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["// Geometry of transition paths: ELK's spline routing points as cubic Bézier segments, flattened for\n// measuring lengths and placing decorators the way KLighD does (at a distance from either end).\n\nimport type { Point } from './types'\n\n/** Rounds to 1/100 for compact, stable output. */\nexport const r2 = (n: number) => Math.round(n * 100) / 100\n\n/** True when the points form a cubic Bézier chain: start, then three points per segment. */\nexport function isBezierChain(points: Point[]): boolean {\n return points.length >= 4 && (points.length - 1) % 3 === 0\n}\n\n/** SVG path data for routing points: a cubic chain when the count fits, else straight segments. */\nexport function pathData(points: Point[]): string {\n if (points.length === 0) return ''\n const p = (q: Point) => `${r2(q.x)} ${r2(q.y)}`\n let d = `M${p(points[0])}`\n if (isBezierChain(points)) {\n for (let i = 1; i < points.length; i += 3) d += `C${p(points[i])} ${p(points[i + 1])} ${p(points[i + 2])}`\n } else {\n for (let i = 1; i < points.length; i++) d += `L${p(points[i])}`\n }\n return d\n}\n\nfunction cubic(a: Point, b: Point, c: Point, d: Point, t: number): Point {\n const u = 1 - t\n const w0 = u * u * u, w1 = 3 * u * u * t, w2 = 3 * u * t * t, w3 = t * t * t\n return { x: w0 * a.x + w1 * b.x + w2 * c.x + w3 * d.x, y: w0 * a.y + w1 * b.y + w2 * c.y + w3 * d.y }\n}\n\n/** The path as a polyline (16 samples per Bézier segment). */\nexport function flatten(points: Point[]): Point[] {\n if (!isBezierChain(points)) return points.slice()\n const out: Point[] = [points[0]]\n for (let i = 1; i < points.length; i += 3) {\n const a = points[i - 1], b = points[i], c = points[i + 1], d = points[i + 2]\n for (let s = 1; s <= 16; s++) out.push(cubic(a, b, c, d, s / 16))\n }\n return out\n}\n\nexport interface PathSample {\n point: Point\n /** Unit tangent in the direction of travel. */\n tangent: Point\n}\n\nfunction polylineLength(poly: Point[]): number {\n let len = 0\n for (let i = 1; i < poly.length; i++) len += Math.hypot(poly[i].x - poly[i - 1].x, poly[i].y - poly[i - 1].y)\n return len\n}\n\n/** The point at arc length `distance` from the start (negative: from the end), with the tangent there. */\nexport function sampleAt(poly: Point[], distance: number): PathSample {\n const total = polylineLength(poly)\n let target = distance < 0 ? total + distance : distance\n target = Math.max(0, Math.min(total, target))\n let walked = 0\n for (let i = 1; i < poly.length; i++) {\n const a = poly[i - 1], b = poly[i]\n const seg = Math.hypot(b.x - a.x, b.y - a.y)\n if (seg === 0) continue\n if (walked + seg >= target || i === poly.length - 1) {\n const t = Math.min(1, (target - walked) / seg)\n return { point: { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }, tangent: { x: (b.x - a.x) / seg, y: (b.y - a.y) / seg } }\n }\n walked += seg\n }\n const last = poly[poly.length - 1] ?? { x: 0, y: 0 }\n return { point: last, tangent: { x: 1, y: 0 } }\n}\n\n/** Tangent at the very end of the path (direction of arrival). */\nexport function endTangent(points: Point[]): Point {\n const end = points[points.length - 1]\n for (let i = points.length - 2; i >= 0; i--) {\n const dx = end.x - points[i].x, dy = end.y - points[i].y\n const len = Math.hypot(dx, dy)\n if (len > 1e-6) return { x: dx / len, y: dy / len }\n }\n return { x: 1, y: 0 }\n}\n\n/** Tangent at the very start of the path (direction of departure). */\nexport function startTangent(points: Point[]): Point {\n const start = points[0]\n for (let i = 1; i < points.length; i++) {\n const dx = points[i].x - start.x, dy = points[i].y - start.y\n const len = Math.hypot(dx, dy)\n if (len > 1e-6) return { x: dx / len, y: dy / len }\n }\n return { x: 1, y: 0 }\n}\n\n/** Transforms decorator-local points (x along the tangent, y to its right) to diagram coordinates. */\nexport function place(origin: Point, tangent: Point, local: [number, number][]): Point[] {\n return local.map(([x, y]) => ({ x: origin.x + x * tangent.x - y * tangent.y, y: origin.y + x * tangent.y + y * tangent.x }))\n}\n\n/** The polyline point nearest to `p`, with the tangent of its segment. */\nexport function nearest(poly: Point[], p: Point): PathSample {\n let best: PathSample = { point: poly[0], tangent: { x: 1, y: 0 } }\n let bestDist = Infinity\n for (let i = 1; i < poly.length; i++) {\n const a = poly[i - 1], b = poly[i]\n const dx = b.x - a.x, dy = b.y - a.y\n const len2 = dx * dx + dy * dy\n if (len2 === 0) continue\n const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / len2))\n const q = { x: a.x + dx * t, y: a.y + dy * t }\n const dist = Math.hypot(p.x - q.x, p.y - q.y)\n if (dist < bestDist) {\n const len = Math.sqrt(len2)\n bestDist = dist\n best = { point: q, tangent: { x: dx / len, y: dy / len } }\n }\n }\n return best\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import type { Span, TickResult } from "@sccharts-lab/engine/types";
2
+ import type { DiagramLayout } from "./types.js";
3
+ /** The classes this module manages; `applyClasses` removes them before adding the new ones. */
4
+ export declare const HIGHLIGHT_CLASSES: readonly ["is-active", "is-entered", "is-exited", "is-taken", "is-focus", "is-error", "is-dimmed"];
5
+ export type HighlightClass = (typeof HIGHLIGHT_CLASSES)[number];
6
+ export type ClassMap = Record<string, string[]>;
7
+ /** Classes for the state of a simulation after a tick: active states, states entered and exited during the
8
+ * tick, transitions taken. */
9
+ export declare function tickClasses(tick: Pick<TickResult, 'active' | 'entered' | 'exited' | 'taken'>): ClassMap;
10
+ /** Merges class maps (later maps add to earlier ones). */
11
+ export declare function mergeClasses(...maps: (ClassMap | undefined)[]): ClassMap;
12
+ /** Minimal DOM surface used here, so this file needs no DOM type library. */
13
+ interface ElementLike {
14
+ getAttribute(name: string): string | null;
15
+ classList: {
16
+ add(...c: string[]): void;
17
+ remove(...c: string[]): void;
18
+ };
19
+ }
20
+ interface RootLike {
21
+ querySelectorAll(selector: string): ArrayLike<ElementLike> & Iterable<ElementLike>;
22
+ }
23
+ /**
24
+ * Sets the highlight classes on the elements of a rendered diagram (`root` is the <svg> or any ancestor):
25
+ * every element with a data-id loses the managed classes and gains those listed for its id. Declaration lines
26
+ * that show several valued objects match any of their ids (data-ids).
27
+ */
28
+ export declare function applyClasses(root: RootLike, classes: ClassMap, managed?: readonly string[]): void;
29
+ /** Ids of the diagram elements whose source span contains `offset` (a UTF-16 offset into the source), the
30
+ * innermost first: for linking the editor's cursor to the diagram (`is-focus`). */
31
+ export declare function elementsAt(layout: DiagramLayout, offset: number): string[];
32
+ /** The source span of a diagram element (state, region or transition), for jumping from the diagram to the
33
+ * source. */
34
+ export declare function spanOf(layout: DiagramLayout, id: string): Span | undefined;
35
+ export {};
@@ -0,0 +1,83 @@
1
+ // Highlighting a rendered diagram: from a simulation tick to classes, and toggling them on the SVG without
2
+ // re-rendering. The DOM helpers only use standard DOM APIs (no framework).
3
+ /** The classes this module manages; `applyClasses` removes them before adding the new ones. */
4
+ export const HIGHLIGHT_CLASSES = ['is-active', 'is-entered', 'is-exited', 'is-taken', 'is-focus', 'is-error', 'is-dimmed'];
5
+ function add(map, id, cls) {
6
+ const list = (map[id] ??= []);
7
+ if (!list.includes(cls))
8
+ list.push(cls);
9
+ }
10
+ /** Classes for the state of a simulation after a tick: active states, states entered and exited during the
11
+ * tick, transitions taken. */
12
+ export function tickClasses(tick) {
13
+ const map = {};
14
+ for (const id of tick.active)
15
+ add(map, id, 'is-active');
16
+ for (const id of tick.entered)
17
+ add(map, id, 'is-entered');
18
+ for (const id of tick.exited)
19
+ add(map, id, 'is-exited');
20
+ for (const id of tick.taken)
21
+ add(map, id, 'is-taken');
22
+ return map;
23
+ }
24
+ /** Merges class maps (later maps add to earlier ones). */
25
+ export function mergeClasses(...maps) {
26
+ const out = {};
27
+ for (const m of maps)
28
+ if (m)
29
+ for (const [id, list] of Object.entries(m))
30
+ for (const c of list)
31
+ add(out, id, c);
32
+ return out;
33
+ }
34
+ /**
35
+ * Sets the highlight classes on the elements of a rendered diagram (`root` is the <svg> or any ancestor):
36
+ * every element with a data-id loses the managed classes and gains those listed for its id. Declaration lines
37
+ * that show several valued objects match any of their ids (data-ids).
38
+ */
39
+ export function applyClasses(root, classes, managed = HIGHLIGHT_CLASSES) {
40
+ for (const el of root.querySelectorAll('[data-id]')) {
41
+ el.classList.remove(...managed);
42
+ const ids = el.getAttribute('data-ids')?.split(' ') ?? [el.getAttribute('data-id')];
43
+ for (const id of ids) {
44
+ const list = classes[id];
45
+ if (list?.length)
46
+ el.classList.add(...list);
47
+ }
48
+ }
49
+ }
50
+ function walk(layout, visit) {
51
+ const state = (s, depth) => {
52
+ visit(s.id, s.span, depth);
53
+ for (const r of s.regions)
54
+ region(r, depth + 1);
55
+ };
56
+ const region = (r, depth) => {
57
+ visit(r.id, r.span, depth);
58
+ for (const s of r.states)
59
+ state(s, depth + 1);
60
+ for (const t of r.transitions)
61
+ visit(t.id, t.span, depth + 1);
62
+ };
63
+ state(layout.root, 0);
64
+ }
65
+ /** Ids of the diagram elements whose source span contains `offset` (a UTF-16 offset into the source), the
66
+ * innermost first: for linking the editor's cursor to the diagram (`is-focus`). */
67
+ export function elementsAt(layout, offset) {
68
+ const hits = [];
69
+ walk(layout, (id, span, depth) => {
70
+ if (span && span.start <= offset && offset <= span.end)
71
+ hits.push({ id, depth, size: span.end - span.start });
72
+ });
73
+ return hits.sort((a, b) => a.size - b.size || b.depth - a.depth).map(h => h.id);
74
+ }
75
+ /** The source span of a diagram element (state, region or transition), for jumping from the diagram to the
76
+ * source. */
77
+ export function spanOf(layout, id) {
78
+ let found;
79
+ walk(layout, (eid, span) => { if (eid === id)
80
+ found = span; });
81
+ return found;
82
+ }
83
+ //# sourceMappingURL=highlight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"highlight.js","sourceRoot":"","sources":["../src/highlight.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,2EAA2E;AAK3E,+FAA+F;AAC/F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,CAAU,CAAA;AAKnI,SAAS,GAAG,CAAC,GAAa,EAAE,EAAU,EAAE,GAAW;IAC/C,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAA;IAC7B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC3C,CAAC;AAED;+BAC+B;AAC/B,MAAM,UAA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AE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC7B,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,IAAI,MAAM,IAAI,IAAI,CAAC,GAAG;YAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAA;IACjH,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AACnF,CAAC;AAED;cACc;AACd,MAAM,UAAU,MAAM,CAAC,MAAqB,EAAE,EAAU;IACpD,IAAI,KAAuB,CAAA;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,IAAI,GAAG,KAAK,EAAE;QAAE,KAAK,GAAG,IAAI,CAAA,CAAC,CAAC,CAAC,CAAA;IAC7D,OAAO,KAAK,CAAA;AAChB,CAAC","sourcesContent":["// Highlighting a rendered diagram: from a simulation tick to classes, and toggling them on the SVG without\n// re-rendering. The DOM helpers only use standard DOM APIs (no framework).\n\nimport type { Span, TickResult } from '@sccharts-lab/engine/types'\nimport type { DiagramLayout, RegionLayout, StateLayout } from './types'\n\n/** The classes this module manages; `applyClasses` removes them before adding the new ones. */\nexport const HIGHLIGHT_CLASSES = ['is-active', 'is-entered', 'is-exited', 'is-taken', 'is-focus', 'is-error', 'is-dimmed'] as const\nexport type HighlightClass = (typeof HIGHLIGHT_CLASSES)[number]\n\nexport type ClassMap = Record<string, string[]>\n\nfunction add(map: ClassMap, id: string, cls: string) {\n const list = (map[id] ??= [])\n if (!list.includes(cls)) list.push(cls)\n}\n\n/** Classes for the state of a simulation after a tick: active states, states entered and exited during the\n * tick, transitions taken. */\nexport function tickClasses(tick: Pick<TickResult, 'active' | 'entered' | 'exited' | 'taken'>): ClassMap {\n const map: ClassMap = {}\n for (const id of tick.active) add(map, id, 'is-active')\n for (const id of tick.entered) add(map, id, 'is-entered')\n for (const id of tick.exited) add(map, id, 'is-exited')\n for (const id of tick.taken) add(map, id, 'is-taken')\n return map\n}\n\n/** Merges class maps (later maps add to earlier ones). */\nexport function mergeClasses(...maps: (ClassMap | undefined)[]): ClassMap {\n const out: ClassMap = {}\n for (const m of maps) if (m) for (const [id, list] of Object.entries(m)) for (const c of list) add(out, id, c)\n return out\n}\n\n/** Minimal DOM surface used here, so this file needs no DOM type library. */\ninterface ElementLike {\n getAttribute(name: string): string | null\n classList: { add(...c: string[]): void; remove(...c: string[]): void }\n}\ninterface RootLike {\n querySelectorAll(selector: string): ArrayLike<ElementLike> & Iterable<ElementLike>\n}\n\n/**\n * Sets the highlight classes on the elements of a rendered diagram (`root` is the <svg> or any ancestor):\n * every element with a data-id loses the managed classes and gains those listed for its id. Declaration lines\n * that show several valued objects match any of their ids (data-ids).\n */\nexport function applyClasses(root: RootLike, classes: ClassMap, managed: readonly string[] = HIGHLIGHT_CLASSES): void {\n for (const el of root.querySelectorAll('[data-id]')) {\n el.classList.remove(...managed)\n const ids = el.getAttribute('data-ids')?.split(' ') ?? [el.getAttribute('data-id')!]\n for (const id of ids) {\n const list = classes[id]\n if (list?.length) el.classList.add(...list)\n }\n }\n}\n\nfunction walk(layout: DiagramLayout, visit: (id: string, span: Span | undefined, depth: number) => void) {\n const state = (s: StateLayout, depth: number) => {\n visit(s.id, s.span, depth)\n for (const r of s.regions) region(r, depth + 1)\n }\n const region = (r: RegionLayout, depth: number) => {\n visit(r.id, r.span, depth)\n for (const s of r.states) state(s, depth + 1)\n for (const t of r.transitions) visit(t.id, t.span, depth + 1)\n }\n state(layout.root, 0)\n}\n\n/** Ids of the diagram elements whose source span contains `offset` (a UTF-16 offset into the source), the\n * innermost first: for linking the editor's cursor to the diagram (`is-focus`). */\nexport function elementsAt(layout: DiagramLayout, offset: number): string[] {\n const hits: { id: string; depth: number; size: number }[] = []\n walk(layout, (id, span, depth) => {\n if (span && span.start <= offset && offset <= span.end) hits.push({ id, depth, size: span.end - span.start })\n })\n return hits.sort((a, b) => a.size - b.size || b.depth - a.depth).map(h => h.id)\n}\n\n/** The source span of a diagram element (state, region or transition), for jumping from the diagram to the\n * source. */\nexport function spanOf(layout: DiagramLayout, id: string): Span | undefined {\n let found: Span | undefined\n walk(layout, (eid, span) => { if (eid === id) found = span })\n return found\n}\n"]}
@@ -0,0 +1,16 @@
1
+ export { renderSvg } from "./render.js";
2
+ export { measureWithTable, lineMetrics, SANS_FAMILY, MONO_FAMILY } from "./measure.js";
3
+ export { HIGHLIGHT_CLASSES, applyClasses, elementsAt, mergeClasses, spanOf, tickClasses } from "./highlight.js";
4
+ export type { ClassMap, HighlightClass } from "./highlight.js";
5
+ export type { TextMeasurer, TextStyle } from "./measure.js";
6
+ export type * from "./types.js";
7
+ import type { State } from "@sccharts-lab/engine/types";
8
+ import type { DiagramLayout, LayoutOptions, RenderOptions } from "./types.js";
9
+ /**
10
+ * Lays out a chart (a root `State` from the engine's `parse` or `compile`) in KIELER's notation. Without
11
+ * `options.elk`, with elkjs's bundled build, loaded on first use. The layout is plain JSON: `renderSvg` draws it.
12
+ */
13
+ export declare function layoutChart(chart: State, options?: LayoutOptions): Promise<DiagramLayout>;
14
+ /** `layoutChart`, then `renderSvg`: the chart's diagram as SVG markup. */
15
+ export declare function chartToSvg(chart: State, options?: LayoutOptions & RenderOptions): Promise<string>;
16
+ export { workerElk } from "./elk-worker.js";
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ // Public API of the diagram renderer. See README.md for the DOM and class contract.
2
+ export { renderSvg } from "./render.js";
3
+ export { measureWithTable, lineMetrics, SANS_FAMILY, MONO_FAMILY } from "./measure.js";
4
+ export { HIGHLIGHT_CLASSES, applyClasses, elementsAt, mergeClasses, spanOf, tickClasses } from "./highlight.js";
5
+ import { layoutChart as layoutWithElk } from "./layout.js";
6
+ import { renderSvg } from "./render.js";
7
+ let bundledElk;
8
+ /** elkjs's bundled build (in a fake worker on the calling thread, in Node and in a browser), loaded on first use.
9
+ * Browser code that lays out in a Web Worker passes its own instance (elk-api, see README); importing
10
+ * layoutChart from ./layout instead keeps this 1.4 MB file out of a bundle altogether. */
11
+ function defaultElk() {
12
+ bundledElk ??= import("elkjs/lib/elk.bundled.js").then(m => {
13
+ // CommonJS interop differs between Node, Vite and bundlers; the class is also its own `default`.
14
+ const mod = m;
15
+ const ELK = (mod.default?.default ?? mod.default ?? mod);
16
+ return new ELK();
17
+ });
18
+ return bundledElk;
19
+ }
20
+ /**
21
+ * Lays out a chart (a root `State` from the engine's `parse` or `compile`) in KIELER's notation. Without
22
+ * `options.elk`, with elkjs's bundled build, loaded on first use. The layout is plain JSON: `renderSvg` draws it.
23
+ */
24
+ export async function layoutChart(chart, options = {}) {
25
+ return layoutWithElk(chart, options.elk ? options : { ...options, elk: await defaultElk() });
26
+ }
27
+ /** `layoutChart`, then `renderSvg`: the chart's diagram as SVG markup. */
28
+ export async function chartToSvg(chart, options = {}) {
29
+ return renderSvg(await layoutChart(chart, options), options);
30
+ }
31
+ export { workerElk } from "./elk-worker.js";
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,OAAO,EAAE,SAAS,EAAE,oBAAgB;AACpC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,qBAAiB;AACnF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,uBAAmB;AAM5G,OAAO,EAAE,WAAW,IAAI,aAAa,EAAE,oBAAgB;AACvD,OAAO,EAAE,SAAS,EAAE,oBAAgB;AAGpC,IAAI,UAAwC,CAAA;AAE5C;;2FAE2F;AAC3F,SAAS,UAAU;IACf,UAAU,KAAK,MAAM,4BAA4B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QACvD,iGAAiG;QACjG,MAAM,GAAG,GAAG,CAAmD,CAAA;QAC/D,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAsB,CAAA;QAC7E,OAAO,IAAI,GAAG,EAAE,CAAA;IACpB,CAAC,CAAC,CAAA;IACF,OAAO,UAAU,CAAA;AACrB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAY,EAAE,UAAyB,EAAE;IACvE,OAAO,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,EAAE,EAAE,CAAC,CAAA;AAChG,CAAC;AAED,0EAA0E;AAC1E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAY,EAAE,UAAyC,EAAE;IACtF,OAAO,SAAS,CAAC,MAAM,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAA;AAChE,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,wBAAoB","sourcesContent":["// Public API of the diagram renderer. See README.md for the DOM and class contract.\nexport { renderSvg } from './render'\nexport { measureWithTable, lineMetrics, SANS_FAMILY, MONO_FAMILY } from './measure'\nexport { HIGHLIGHT_CLASSES, applyClasses, elementsAt, mergeClasses, spanOf, tickClasses } from './highlight'\nexport type { ClassMap, HighlightClass } from './highlight'\nexport type { TextMeasurer, TextStyle } from './measure'\nexport type * from './types'\n\nimport type { State } from '@sccharts-lab/engine/types'\nimport { layoutChart as layoutWithElk } from './layout'\nimport { renderSvg } from './render'\nimport type { DiagramLayout, ElkLike, LayoutOptions, RenderOptions } from './types'\n\nlet bundledElk: Promise<ElkLike> | undefined\n\n/** elkjs's bundled build (in a fake worker on the calling thread, in Node and in a browser), loaded on first use.\n * Browser code that lays out in a Web Worker passes its own instance (elk-api, see README); importing\n * layoutChart from ./layout instead keeps this 1.4 MB file out of a bundle altogether. */\nfunction defaultElk(): Promise<ElkLike> {\n bundledElk ??= import('elkjs/lib/elk.bundled.js').then(m => {\n // CommonJS interop differs between Node, Vite and bundlers; the class is also its own `default`.\n const mod = m as unknown as { default?: { default?: unknown } }\n const ELK = (mod.default?.default ?? mod.default ?? mod) as new () => ElkLike\n return new ELK()\n })\n return bundledElk\n}\n\n/**\n * Lays out a chart (a root `State` from the engine's `parse` or `compile`) in KIELER's notation. Without\n * `options.elk`, with elkjs's bundled build, loaded on first use. The layout is plain JSON: `renderSvg` draws it.\n */\nexport async function layoutChart(chart: State, options: LayoutOptions = {}): Promise<DiagramLayout> {\n return layoutWithElk(chart, options.elk ? options : { ...options, elk: await defaultElk() })\n}\n\n/** `layoutChart`, then `renderSvg`: the chart's diagram as SVG markup. */\nexport async function chartToSvg(chart: State, options: LayoutOptions & RenderOptions = {}): Promise<string> {\n return renderSvg(await layoutChart(chart, options), options)\n}\n\nexport { workerElk } from './elk-worker'\n"]}
@@ -0,0 +1,6 @@
1
+ import type { State } from "@sccharts-lab/engine/types";
2
+ import type { DiagramLayout, LayoutOptions } from "./types.js";
3
+ /** The id prefix of a referenced chart drawn inside a reference state (`references: 'expanded'`). */
4
+ export declare const REFERENCE_SEPARATOR = "/";
5
+ export declare function layoutChart(chart: State, givenOptions?: LayoutOptions): Promise<DiagramLayout>;
6
+ export { workerElk } from "./elk-worker.js";