@bpmn-ld/bpmn-ld 0.0.0-stage → 0.2.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 (339) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +125 -2
  3. package/contexts/combined.jsonld +3 -0
  4. package/contexts/core.jsonld +170 -0
  5. package/contexts/di.jsonld +37 -0
  6. package/dist/analyze/analyze.d.ts +3 -0
  7. package/dist/analyze/analyze.js +11 -0
  8. package/dist/analyze/findings.d.ts +8 -0
  9. package/dist/analyze/findings.js +1 -0
  10. package/dist/analyze/report.d.ts +3 -0
  11. package/dist/analyze/report.js +9 -0
  12. package/dist/analyze/rules/ad-hoc-completion-condition.d.ts +2 -0
  13. package/dist/analyze/rules/ad-hoc-completion-condition.js +7 -0
  14. package/dist/analyze/rules/cannot-reach-end.d.ts +2 -0
  15. package/dist/analyze/rules/cannot-reach-end.js +28 -0
  16. package/dist/analyze/rules/compensation-association.d.ts +2 -0
  17. package/dist/analyze/rules/compensation-association.js +13 -0
  18. package/dist/analyze/rules/dead-end.d.ts +2 -0
  19. package/dist/analyze/rules/dead-end.js +13 -0
  20. package/dist/analyze/rules/end-event.d.ts +2 -0
  21. package/dist/analyze/rules/end-event.js +8 -0
  22. package/dist/analyze/rules/error-catch.d.ts +2 -0
  23. package/dist/analyze/rules/error-catch.js +14 -0
  24. package/dist/analyze/rules/escalation-catch.d.ts +2 -0
  25. package/dist/analyze/rules/escalation-catch.js +14 -0
  26. package/dist/analyze/rules/gateway-cardinality.d.ts +3 -0
  27. package/dist/analyze/rules/gateway-cardinality.js +17 -0
  28. package/dist/analyze/rules/index.d.ts +4 -0
  29. package/dist/analyze/rules/index.js +21 -0
  30. package/dist/analyze/rules/instantiating-gateway.d.ts +2 -0
  31. package/dist/analyze/rules/instantiating-gateway.js +14 -0
  32. package/dist/analyze/rules/non-interrupting-start.d.ts +2 -0
  33. package/dist/analyze/rules/non-interrupting-start.js +14 -0
  34. package/dist/analyze/rules/reachability.d.ts +2 -0
  35. package/dist/analyze/rules/reachability.js +25 -0
  36. package/dist/analyze/rules/rule.d.ts +7 -0
  37. package/dist/analyze/rules/rule.js +1 -0
  38. package/dist/analyze/rules/signal-catch.d.ts +2 -0
  39. package/dist/analyze/rules/signal-catch.js +12 -0
  40. package/dist/analyze/rules/split-join-pairing.d.ts +3 -0
  41. package/dist/analyze/rules/split-join-pairing.js +50 -0
  42. package/dist/analyze/rules/start-event.d.ts +2 -0
  43. package/dist/analyze/rules/start-event.js +8 -0
  44. package/dist/analyze/rules/task-message-flow.d.ts +2 -0
  45. package/dist/analyze/rules/task-message-flow.js +19 -0
  46. package/dist/analyze/scope-graph.d.ts +56 -0
  47. package/dist/analyze/scope-graph.js +89 -0
  48. package/dist/analyze-cli.d.ts +1 -0
  49. package/dist/analyze-cli.js +5 -0
  50. package/dist/analyze-run.d.ts +12 -0
  51. package/dist/analyze-run.js +85 -0
  52. package/dist/bpmn-ld-cli.d.ts +2 -0
  53. package/dist/bpmn-ld-cli.js +97 -0
  54. package/dist/build-cli.d.ts +1 -0
  55. package/dist/build-cli.js +2 -0
  56. package/dist/build.d.ts +3 -0
  57. package/dist/build.js +38 -0
  58. package/dist/cheat-sheet-catalog.d.ts +10 -0
  59. package/dist/cheat-sheet-catalog.js +72 -0
  60. package/dist/cheat-sheet-cli.d.ts +1 -0
  61. package/dist/cheat-sheet-cli.js +7 -0
  62. package/dist/cheat-sheet-compose.d.ts +13 -0
  63. package/dist/cheat-sheet-compose.js +107 -0
  64. package/dist/cheat-sheet-run.d.ts +11 -0
  65. package/dist/cheat-sheet-run.js +65 -0
  66. package/dist/cheat-sheet-svg.d.ts +2 -0
  67. package/dist/cheat-sheet-svg.js +2 -0
  68. package/dist/cheat-sheet.d.ts +2 -0
  69. package/dist/cheat-sheet.js +2 -0
  70. package/dist/check-xml/check.d.ts +3 -0
  71. package/dist/check-xml/check.js +11 -0
  72. package/dist/check-xml/lint.d.ts +2 -0
  73. package/dist/check-xml/lint.js +47 -0
  74. package/dist/check-xml/moddle.d.ts +6 -0
  75. package/dist/check-xml/moddle.js +23 -0
  76. package/dist/check-xml/types.d.ts +20 -0
  77. package/dist/check-xml/types.js +1 -0
  78. package/dist/check-xml/xsd.d.ts +2 -0
  79. package/dist/check-xml/xsd.js +25 -0
  80. package/dist/check-xml-cli.d.ts +1 -0
  81. package/dist/check-xml-cli.js +5 -0
  82. package/dist/check-xml-run.d.ts +10 -0
  83. package/dist/check-xml-run.js +77 -0
  84. package/dist/convert/analyze-output.d.ts +3 -0
  85. package/dist/convert/analyze-output.js +8 -0
  86. package/dist/convert/convert.d.ts +19 -0
  87. package/dist/convert/convert.js +96 -0
  88. package/dist/convert/errors.d.ts +5 -0
  89. package/dist/convert/errors.js +8 -0
  90. package/dist/convert/extensions.d.ts +23 -0
  91. package/dist/convert/extensions.js +103 -0
  92. package/dist/convert/mapping-check.d.ts +15 -0
  93. package/dist/convert/mapping-check.js +66 -0
  94. package/dist/convert/mapping.d.ts +52 -0
  95. package/dist/convert/mapping.js +273 -0
  96. package/dist/convert/namespaces.d.ts +2 -0
  97. package/dist/convert/namespaces.js +19 -0
  98. package/dist/convert/validate-output.d.ts +2 -0
  99. package/dist/convert/validate-output.js +28 -0
  100. package/dist/convert/warnings.d.ts +9 -0
  101. package/dist/convert/warnings.js +67 -0
  102. package/dist/convert/xml-reader.d.ts +11 -0
  103. package/dist/convert/xml-reader.js +84 -0
  104. package/dist/convert-cli.d.ts +1 -0
  105. package/dist/convert-cli.js +5 -0
  106. package/dist/convert-run.d.ts +10 -0
  107. package/dist/convert-run.js +125 -0
  108. package/dist/coverage-cli.d.ts +1 -0
  109. package/dist/coverage-cli.js +8 -0
  110. package/dist/coverage-mappings.d.ts +3 -0
  111. package/dist/coverage-mappings.js +34 -0
  112. package/dist/coverage-scope.d.ts +11 -0
  113. package/dist/coverage-scope.js +187 -0
  114. package/dist/coverage-xsd.d.ts +15 -0
  115. package/dist/coverage-xsd.js +55 -0
  116. package/dist/coverage.d.ts +35 -0
  117. package/dist/coverage.js +152 -0
  118. package/dist/docs-cli.d.ts +1 -0
  119. package/dist/docs-cli.js +18 -0
  120. package/dist/docs.d.ts +8 -0
  121. package/dist/docs.js +136 -0
  122. package/dist/eval/checks.d.ts +19 -0
  123. package/dist/eval/checks.js +252 -0
  124. package/dist/eval/regenerate.d.ts +10 -0
  125. package/dist/eval/regenerate.js +48 -0
  126. package/dist/eval-regenerate-cli.d.ts +1 -0
  127. package/dist/eval-regenerate-cli.js +16 -0
  128. package/dist/export/data.d.ts +10 -0
  129. package/dist/export/data.js +127 -0
  130. package/dist/export/diagram.d.ts +8 -0
  131. package/dist/export/diagram.js +112 -0
  132. package/dist/export/element.d.ts +27 -0
  133. package/dist/export/element.js +175 -0
  134. package/dist/export/export.d.ts +22 -0
  135. package/dist/export/export.js +124 -0
  136. package/dist/export/extensions.d.ts +18 -0
  137. package/dist/export/extensions.js +122 -0
  138. package/dist/export/layout-export.d.ts +4 -0
  139. package/dist/export/layout-export.js +25 -0
  140. package/dist/export/mapping-check.d.ts +39 -0
  141. package/dist/export/mapping-check.js +175 -0
  142. package/dist/export/normalize.d.ts +3 -0
  143. package/dist/export/normalize.js +67 -0
  144. package/dist/export-cli.d.ts +1 -0
  145. package/dist/export-cli.js +5 -0
  146. package/dist/export-run.d.ts +10 -0
  147. package/dist/export-run.js +157 -0
  148. package/dist/index.d.ts +10 -0
  149. package/dist/index.js +10 -0
  150. package/dist/install-skill-run.d.ts +8 -0
  151. package/dist/install-skill-run.js +30 -0
  152. package/dist/install-skill.d.ts +23 -0
  153. package/dist/install-skill.js +76 -0
  154. package/dist/layout/collaboration.d.ts +36 -0
  155. package/dist/layout/collaboration.js +152 -0
  156. package/dist/layout/di.d.ts +15 -0
  157. package/dist/layout/di.js +52 -0
  158. package/dist/layout/extract.d.ts +2 -0
  159. package/dist/layout/extract.js +99 -0
  160. package/dist/layout/lanes.d.ts +30 -0
  161. package/dist/layout/lanes.js +112 -0
  162. package/dist/layout/layering.d.ts +7 -0
  163. package/dist/layout/layering.js +53 -0
  164. package/dist/layout/layout.d.ts +12 -0
  165. package/dist/layout/layout.js +299 -0
  166. package/dist/layout/model.d.ts +52 -0
  167. package/dist/layout/model.js +10 -0
  168. package/dist/layout/placement.d.ts +25 -0
  169. package/dist/layout/placement.js +256 -0
  170. package/dist/layout/standalone.d.ts +8 -0
  171. package/dist/layout/standalone.js +50 -0
  172. package/dist/layout-cli.d.ts +1 -0
  173. package/dist/layout-cli.js +5 -0
  174. package/dist/layout-run.d.ts +9 -0
  175. package/dist/layout-run.js +105 -0
  176. package/dist/loader.d.ts +5 -0
  177. package/dist/loader.js +7 -0
  178. package/dist/namespace.d.ts +5 -0
  179. package/dist/namespace.js +5 -0
  180. package/dist/ontology.d.ts +19 -0
  181. package/dist/ontology.js +94 -0
  182. package/dist/paths.d.ts +1 -0
  183. package/dist/paths.js +2 -0
  184. package/dist/render/geometry.d.ts +40 -0
  185. package/dist/render/geometry.js +81 -0
  186. package/dist/render/renderer.d.ts +31 -0
  187. package/dist/render/renderer.js +369 -0
  188. package/dist/render/symbols.d.ts +10 -0
  189. package/dist/render/symbols.js +26 -0
  190. package/dist/render/text.d.ts +20 -0
  191. package/dist/render/text.js +28 -0
  192. package/dist/render-cli.d.ts +1 -0
  193. package/dist/render-cli.js +7 -0
  194. package/dist/render-run.d.ts +9 -0
  195. package/dist/render-run.js +161 -0
  196. package/dist/render.d.ts +4 -0
  197. package/dist/render.js +4 -0
  198. package/dist/schema-overrides.d.ts +14 -0
  199. package/dist/schema-overrides.js +36 -0
  200. package/dist/schema-validate.d.ts +5 -0
  201. package/dist/schema-validate.js +8 -0
  202. package/dist/schema.d.ts +6 -0
  203. package/dist/schema.js +114 -0
  204. package/dist/shacl.d.ts +15 -0
  205. package/dist/shacl.js +37 -0
  206. package/dist/validate-cli.d.ts +1 -0
  207. package/dist/validate-cli.js +5 -0
  208. package/dist/validate-run.d.ts +8 -0
  209. package/dist/validate-run.js +58 -0
  210. package/dist/validate.d.ts +11 -0
  211. package/dist/validate.js +94 -0
  212. package/dist/versioning-cli.d.ts +1 -0
  213. package/dist/versioning-cli.js +18 -0
  214. package/dist/versioning.d.ts +17 -0
  215. package/dist/versioning.js +45 -0
  216. package/ontology/core.ttl +993 -0
  217. package/ontology/di.ttl +167 -0
  218. package/package.json +77 -4
  219. package/reference/bpmn-xsd/BPMN20.xsd +37 -0
  220. package/reference/bpmn-xsd/BPMNDI.xsd +100 -0
  221. package/reference/bpmn-xsd/DC.xsd +29 -0
  222. package/reference/bpmn-xsd/DI.xsd +100 -0
  223. package/reference/bpmn-xsd/Semantic.xsd +1562 -0
  224. package/reference/rospocher/ATTRIBUTION.md +22 -0
  225. package/reference/rospocher/BPMNOntology.owl +8937 -0
  226. package/reference/rospocher-verified.json +221 -0
  227. package/schema/bpmn-ld.schema.json +15230 -0
  228. package/shapes/core.shapes.ttl +398 -0
  229. package/skills/bpmn-ld/SKILL.md +154 -0
  230. package/skills/bpmn-ld/evals/models/order-approval-di.jsonld +296 -0
  231. package/skills/bpmn-ld/evals/models/refund-di.bpmn +82 -0
  232. package/skills/bpmn-ld/evals/models/refund.bpmn +18 -0
  233. package/skills/bpmn-ld/evals/outputs/explain-collaboration.md +22 -0
  234. package/skills/bpmn-ld/evals/outputs/explain-order-approval.md +24 -0
  235. package/skills/bpmn-ld/evals/outputs/explain-refund.md +17 -0
  236. package/skills/bpmn-ld/evals/outputs/generate-activity-compensation.jsonld +39 -0
  237. package/skills/bpmn-ld/evals/outputs/generate-ad-hoc-sub-process.jsonld +52 -0
  238. package/skills/bpmn-ld/evals/outputs/generate-boundary-event.jsonld +27 -0
  239. package/skills/bpmn-ld/evals/outputs/generate-collaboration.jsonld +49 -0
  240. package/skills/bpmn-ld/evals/outputs/generate-conditions.jsonld +93 -0
  241. package/skills/bpmn-ld/evals/outputs/generate-diagram-properties.jsonld +340 -0
  242. package/skills/bpmn-ld/evals/outputs/generate-error.jsonld +217 -0
  243. package/skills/bpmn-ld/evals/outputs/generate-escalation.jsonld +231 -0
  244. package/skills/bpmn-ld/evals/outputs/generate-event-definition-ref.jsonld +67 -0
  245. package/skills/bpmn-ld/evals/outputs/generate-event-sub-process.jsonld +54 -0
  246. package/skills/bpmn-ld/evals/outputs/generate-exclusive-choice.jsonld +32 -0
  247. package/skills/bpmn-ld/evals/outputs/generate-instantiating-gateway.jsonld +24 -0
  248. package/skills/bpmn-ld/evals/outputs/generate-lane-partition.jsonld +46 -0
  249. package/skills/bpmn-ld/evals/outputs/generate-link-event.expect.json +11 -0
  250. package/skills/bpmn-ld/evals/outputs/generate-link-event.jsonld +57 -0
  251. package/skills/bpmn-ld/evals/outputs/generate-loop.jsonld +30 -0
  252. package/skills/bpmn-ld/evals/outputs/generate-message.jsonld +61 -0
  253. package/skills/bpmn-ld/evals/outputs/generate-parallel-branches.jsonld +25 -0
  254. package/skills/bpmn-ld/evals/outputs/generate-process-attributes.jsonld +49 -0
  255. package/skills/bpmn-ld/evals/outputs/generate-script-task.jsonld +18 -0
  256. package/skills/bpmn-ld/evals/outputs/generate-signal.jsonld +178 -0
  257. package/skills/bpmn-ld/evals/outputs/generate-sub-process.jsonld +31 -0
  258. package/skills/bpmn-ld/evals/outputs/generate-targeted-compensation.jsonld +40 -0
  259. package/skills/bpmn-ld/evals/outputs/generate-task-implementation.jsonld +18 -0
  260. package/skills/bpmn-ld/evals/outputs/generate-task-message-references.jsonld +49 -0
  261. package/skills/bpmn-ld/evals/outputs/generate-transaction.jsonld +48 -0
  262. package/skills/bpmn-ld/evals/outputs/modify-order-approval.jsonld +376 -0
  263. package/skills/bpmn-ld/evals/outputs/modify-refund.jsonld +373 -0
  264. package/skills/bpmn-ld/evals/outputs/order-approval.jsonld +29 -0
  265. package/skills/bpmn-ld/evals/outputs/refine-order-approval.jsonld +377 -0
  266. package/skills/bpmn-ld/evals/prompts/explain-collaboration.md +3 -0
  267. package/skills/bpmn-ld/evals/prompts/explain-order-approval.md +3 -0
  268. package/skills/bpmn-ld/evals/prompts/explain-refund.md +3 -0
  269. package/skills/bpmn-ld/evals/prompts/generate-activity-compensation.md +1 -0
  270. package/skills/bpmn-ld/evals/prompts/generate-ad-hoc-sub-process.md +1 -0
  271. package/skills/bpmn-ld/evals/prompts/generate-boundary-event.md +1 -0
  272. package/skills/bpmn-ld/evals/prompts/generate-collaboration.md +1 -0
  273. package/skills/bpmn-ld/evals/prompts/generate-conditions.md +1 -0
  274. package/skills/bpmn-ld/evals/prompts/generate-diagram-properties.md +1 -0
  275. package/skills/bpmn-ld/evals/prompts/generate-error.md +1 -0
  276. package/skills/bpmn-ld/evals/prompts/generate-escalation.md +1 -0
  277. package/skills/bpmn-ld/evals/prompts/generate-event-definition-ref.md +1 -0
  278. package/skills/bpmn-ld/evals/prompts/generate-event-sub-process.md +1 -0
  279. package/skills/bpmn-ld/evals/prompts/generate-exclusive-choice.md +1 -0
  280. package/skills/bpmn-ld/evals/prompts/generate-instantiating-gateway.md +1 -0
  281. package/skills/bpmn-ld/evals/prompts/generate-lane-partition.md +1 -0
  282. package/skills/bpmn-ld/evals/prompts/generate-link-event.md +1 -0
  283. package/skills/bpmn-ld/evals/prompts/generate-loop.md +1 -0
  284. package/skills/bpmn-ld/evals/prompts/generate-message.md +1 -0
  285. package/skills/bpmn-ld/evals/prompts/generate-parallel-branches.md +1 -0
  286. package/skills/bpmn-ld/evals/prompts/generate-process-attributes.md +1 -0
  287. package/skills/bpmn-ld/evals/prompts/generate-script-task.md +1 -0
  288. package/skills/bpmn-ld/evals/prompts/generate-signal.md +1 -0
  289. package/skills/bpmn-ld/evals/prompts/generate-sub-process.md +1 -0
  290. package/skills/bpmn-ld/evals/prompts/generate-targeted-compensation.md +1 -0
  291. package/skills/bpmn-ld/evals/prompts/generate-task-implementation.md +1 -0
  292. package/skills/bpmn-ld/evals/prompts/generate-task-message-references.md +1 -0
  293. package/skills/bpmn-ld/evals/prompts/generate-transaction.md +1 -0
  294. package/skills/bpmn-ld/evals/prompts/modify-order-approval.md +4 -0
  295. package/skills/bpmn-ld/evals/prompts/modify-refund.md +4 -0
  296. package/skills/bpmn-ld/evals/prompts/order-approval.md +1 -0
  297. package/skills/bpmn-ld/evals/prompts/refine-order-approval.md +8 -0
  298. package/skills/bpmn-ld/examples/positive/activity-compensation.jsonld +39 -0
  299. package/skills/bpmn-ld/examples/positive/ad-hoc-sub-process.jsonld +52 -0
  300. package/skills/bpmn-ld/examples/positive/boundary-event.jsonld +27 -0
  301. package/skills/bpmn-ld/examples/positive/collaboration.jsonld +49 -0
  302. package/skills/bpmn-ld/examples/positive/conditions.jsonld +93 -0
  303. package/skills/bpmn-ld/examples/positive/diagram-properties.jsonld +340 -0
  304. package/skills/bpmn-ld/examples/positive/error.jsonld +208 -0
  305. package/skills/bpmn-ld/examples/positive/escalation.jsonld +231 -0
  306. package/skills/bpmn-ld/examples/positive/event-definition-ref.jsonld +142 -0
  307. package/skills/bpmn-ld/examples/positive/event-sub-process.jsonld +54 -0
  308. package/skills/bpmn-ld/examples/positive/exclusive-choice.jsonld +32 -0
  309. package/skills/bpmn-ld/examples/positive/instantiating-gateway.jsonld +24 -0
  310. package/skills/bpmn-ld/examples/positive/lane-partition.jsonld +46 -0
  311. package/skills/bpmn-ld/examples/positive/link-event.expect.json +10 -0
  312. package/skills/bpmn-ld/examples/positive/link-event.jsonld +138 -0
  313. package/skills/bpmn-ld/examples/positive/loop.jsonld +30 -0
  314. package/skills/bpmn-ld/examples/positive/message.jsonld +60 -0
  315. package/skills/bpmn-ld/examples/positive/order-approval.jsonld +29 -0
  316. package/skills/bpmn-ld/examples/positive/parallel-branches.jsonld +25 -0
  317. package/skills/bpmn-ld/examples/positive/process-attributes.jsonld +49 -0
  318. package/skills/bpmn-ld/examples/positive/script-task.jsonld +18 -0
  319. package/skills/bpmn-ld/examples/positive/signal.jsonld +150 -0
  320. package/skills/bpmn-ld/examples/positive/sub-process.jsonld +31 -0
  321. package/skills/bpmn-ld/examples/positive/targeted-compensation.jsonld +40 -0
  322. package/skills/bpmn-ld/examples/positive/task-implementation.jsonld +18 -0
  323. package/skills/bpmn-ld/examples/positive/task-message-references.jsonld +151 -0
  324. package/skills/bpmn-ld/examples/positive/transaction.jsonld +48 -0
  325. package/skills/bpmn-ld/references/clarification-and-refinement.md +60 -0
  326. package/skills/bpmn-ld/references/common-mistakes.md +110 -0
  327. package/skills/bpmn-ld/references/explain-and-document.md +36 -0
  328. package/skills/bpmn-ld/references/modify-existing-model.md +49 -0
  329. package/skills/bpmn-ld/references/patterns.md +292 -0
  330. package/skills/bpmn-ld/references/render-output.md +1 -0
  331. package/skills/bpmn-ld/references/rule-catalogue.md +183 -0
  332. package/skills/bpmn-ld/references/vocabulary-summary.md +65 -0
  333. package/skills/bpmn-ld/template.jsonld +14 -0
  334. package/templates/combined.jsonld +3 -0
  335. package/templates/core.jsonld +170 -0
  336. package/templates/core.shapes.ttl +398 -0
  337. package/templates/core.ttl +993 -0
  338. package/templates/di.jsonld +37 -0
  339. package/templates/di.ttl +167 -0
@@ -0,0 +1,50 @@
1
+ import { arrangeLanes, bandsBottom, buildLaneLayout, extendLastBand, laneBoxes, laneBoxesFromNodes, LANE_HEADER } from "./lanes.js";
2
+ import { allNodes } from "./model.js";
3
+ import { measure, ORIGIN, placeScope } from "./placement.js";
4
+ const MARGIN = 20;
5
+ export const placeStandalone = (model, lanes, existing = { fixed: new Map(), obstacles: new Map() }) => {
6
+ measure(model);
7
+ const laneLayout = lanes ? buildLaneLayout(lanes, model) : undefined;
8
+ const context = {
9
+ fixed: existing.fixed,
10
+ obstacles: existing.obstacles,
11
+ missingFlows: existing.missingFlows,
12
+ boxes: new Map(),
13
+ routes: new Map(),
14
+ lanes: new Map(),
15
+ arrange: laneLayout ? (scope, layering, layered, origin) => (scope === model ? arrangeLanes(laneLayout, scope, layering, layered, origin) : undefined) : undefined,
16
+ };
17
+ const indent = laneLayout ? LANE_HEADER * (laneLayout.depth + 1) + MARGIN : 0;
18
+ placeScope(model, { x: ORIGIN.x + indent, y: ORIGIN.y }, context);
19
+ const result = { boxes: context.boxes, routes: context.routes, lanes: new Map() };
20
+ const nested = () => {
21
+ for (const [id, box] of context.lanes)
22
+ result.lanes.set(id, existing.fixed.get(id) ?? box);
23
+ };
24
+ if (!laneLayout) {
25
+ nested();
26
+ return result;
27
+ }
28
+ const anchored = allNodes(model).some((node) => existing.fixed.has(node.id));
29
+ const boxes = [...context.boxes.values()];
30
+ const points = [...context.routes.values()].flat();
31
+ const right = Math.max(...boxes.map((box) => box.x + box.width), ...points.map((point) => point.x)) + MARGIN;
32
+ let frame;
33
+ let computed;
34
+ if (anchored) {
35
+ const x = Math.min(...boxes.map((box) => box.x)) - indent;
36
+ const y = Math.min(...boxes.map((box) => box.y)) - MARGIN;
37
+ const bottom = Math.max(...boxes.map((box) => box.y + box.height), ...points.map((point) => point.y)) + MARGIN;
38
+ frame = { x, y, width: right - x, height: bottom - y };
39
+ computed = laneBoxesFromNodes(laneLayout, frame, context.boxes, 0);
40
+ }
41
+ else {
42
+ extendLastBand(laneLayout, Math.max(...points.map((point) => point.y), ...boxes.map((box) => box.y + box.height), 0) + MARGIN / 2);
43
+ frame = { x: ORIGIN.x, y: ORIGIN.y, width: right - ORIGIN.x, height: bandsBottom(laneLayout) - ORIGIN.y };
44
+ computed = laneBoxes(laneLayout, frame, 0);
45
+ }
46
+ for (const lane of laneLayout.lanes)
47
+ result.lanes.set(lane.id, existing.fixed.get(lane.id) ?? computed.get(lane.id));
48
+ nested();
49
+ return result;
50
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { runLayout } from "./layout-run.js";
2
+ const { exitCode, stdout, stderr } = runLayout(process.argv.slice(2));
3
+ process.stdout.write(stdout);
4
+ process.stderr.write(stderr);
5
+ process.exitCode = exitCode;
@@ -0,0 +1,9 @@
1
+ export declare const EXIT_OK = 0;
2
+ export declare const EXIT_BAD_INPUT = 2;
3
+ export interface CliResult {
4
+ exitCode: number;
5
+ stdout: string;
6
+ stderr: string;
7
+ }
8
+ export declare const USAGE = "Usage: layout <input.jsonld> [options]\n\nAdds BPMN DI (shapes, edges and waypoints) to a BPMN-LD document and writes the\nresult as JSON-LD. A process that already has a diagram is completed: shapes and\nedges are added only for flow nodes and sequence flows that lack them, placed\naround the existing shapes, and existing diagram content is never changed.\nWith --force the diagram of each process is replaced by a fresh full layout.\n\nOptions:\n -o, --output <file> Write the document to <file> instead of standard output\n --force Recompute all shapes and edges, replacing existing diagrams\n -h, --help Show this help\n\nExit codes:\n 0 Laid out successfully\n 2 Usage error or unusable input (missing file, invalid JSON, invalid BPMN-LD)\n";
9
+ export declare const runLayout: (argv: string[]) => CliResult;
@@ -0,0 +1,105 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { layoutDocument, LayoutInputError } from "./layout/layout.js";
3
+ export const EXIT_OK = 0;
4
+ export const EXIT_BAD_INPUT = 2;
5
+ const MAX_REPORTED_ERRORS = 10;
6
+ export const USAGE = `Usage: layout <input.jsonld> [options]
7
+
8
+ Adds BPMN DI (shapes, edges and waypoints) to a BPMN-LD document and writes the
9
+ result as JSON-LD. A process that already has a diagram is completed: shapes and
10
+ edges are added only for flow nodes and sequence flows that lack them, placed
11
+ around the existing shapes, and existing diagram content is never changed.
12
+ With --force the diagram of each process is replaced by a fresh full layout.
13
+
14
+ Options:
15
+ -o, --output <file> Write the document to <file> instead of standard output
16
+ --force Recompute all shapes and edges, replacing existing diagrams
17
+ -h, --help Show this help
18
+
19
+ Exit codes:
20
+ 0 Laid out successfully
21
+ 2 Usage error or unusable input (missing file, invalid JSON, invalid BPMN-LD)
22
+ `;
23
+ class UsageError extends Error {
24
+ }
25
+ const parseArgs = (argv) => {
26
+ let output;
27
+ let input;
28
+ let force = false;
29
+ for (let i = 0; i < argv.length; i++) {
30
+ const arg = argv[i];
31
+ if (arg === "-h" || arg === "--help")
32
+ return "help";
33
+ else if (arg === "--force")
34
+ force = true;
35
+ else if (arg === "-o" || arg === "--output") {
36
+ const value = argv[++i];
37
+ if (value === undefined || value.startsWith("-"))
38
+ throw new UsageError(`${arg} requires a value`);
39
+ output = value;
40
+ }
41
+ else if (arg.startsWith("-"))
42
+ throw new UsageError(`unknown option ${arg}`);
43
+ else if (input !== undefined)
44
+ throw new UsageError(`unexpected extra argument ${arg}`);
45
+ else
46
+ input = arg;
47
+ }
48
+ if (input === undefined)
49
+ throw new UsageError("missing input file");
50
+ return { input, output, force };
51
+ };
52
+ const failure = (stderr) => ({ exitCode: EXIT_BAD_INPUT, stdout: "", stderr });
53
+ const readJson = (path) => {
54
+ let text;
55
+ try {
56
+ text = readFileSync(path, "utf8");
57
+ }
58
+ catch (error) {
59
+ const reason = error.code === "ENOENT" ? "no such file" : (error.message ?? "cannot read");
60
+ throw new UsageError(`cannot read ${path}: ${reason}`);
61
+ }
62
+ try {
63
+ return JSON.parse(text);
64
+ }
65
+ catch (error) {
66
+ throw new UsageError(`${path} is not valid JSON: ${error.message}`);
67
+ }
68
+ };
69
+ export const runLayout = (argv) => {
70
+ let options;
71
+ let document;
72
+ try {
73
+ options = parseArgs(argv);
74
+ if (options === "help")
75
+ return { exitCode: EXIT_OK, stdout: USAGE, stderr: "" };
76
+ document = readJson(options.input);
77
+ }
78
+ catch (error) {
79
+ if (error instanceof UsageError)
80
+ return failure(`error: ${error.message}\n\n${USAGE}`);
81
+ throw error;
82
+ }
83
+ let text;
84
+ try {
85
+ text = `${JSON.stringify(layoutDocument(document, { force: options.force }).document, null, 2)}\n`;
86
+ }
87
+ catch (error) {
88
+ if (!(error instanceof LayoutInputError))
89
+ throw error;
90
+ const shown = error.errors.slice(0, MAX_REPORTED_ERRORS).map((e) => `error: ${options.input}: invalid BPMN-LD: ${e}`);
91
+ const more = error.errors.length - shown.length;
92
+ if (more > 0)
93
+ shown.push(`error: ... and ${more} more`);
94
+ return failure(`${shown.join("\n")}\n`);
95
+ }
96
+ if (options.output === undefined)
97
+ return { exitCode: EXIT_OK, stdout: text, stderr: "" };
98
+ try {
99
+ writeFileSync(options.output, text);
100
+ }
101
+ catch (error) {
102
+ return failure(`error: cannot write ${options.output}: ${error.message}\n`);
103
+ }
104
+ return { exitCode: EXIT_OK, stdout: "", stderr: "" };
105
+ };
@@ -0,0 +1,5 @@
1
+ export declare const fileDocumentLoader: (url: string) => Promise<{
2
+ contextUrl: undefined;
3
+ document: any;
4
+ documentUrl: string;
5
+ }>;
package/dist/loader.js ADDED
@@ -0,0 +1,7 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ export const fileDocumentLoader = async (url) => {
4
+ if (!url.startsWith("file:"))
5
+ throw new Error(`Only file: URLs can be loaded, got ${url}`);
6
+ return { contextUrl: undefined, document: JSON.parse(await readFile(fileURLToPath(url), "utf8")), documentUrl: url };
7
+ };
@@ -0,0 +1,5 @@
1
+ export declare const BPMN_NAMESPACE = "https://bpmn-ld.example.org/ns#";
2
+ export declare const BPMN_ONTOLOGY_IRI: string;
3
+ export declare const BPMNDI_NAMESPACE = "https://bpmn-ld.example.org/di#";
4
+ export declare const BPMNDI_ONTOLOGY_IRI: string;
5
+ export declare const BPMN_SHAPES_NAMESPACE: string;
@@ -0,0 +1,5 @@
1
+ export const BPMN_NAMESPACE = "https://bpmn-ld.example.org/ns#";
2
+ export const BPMN_ONTOLOGY_IRI = BPMN_NAMESPACE.replace(/#$/, "");
3
+ export const BPMNDI_NAMESPACE = "https://bpmn-ld.example.org/di#";
4
+ export const BPMNDI_ONTOLOGY_IRI = BPMNDI_NAMESPACE.replace(/#$/, "");
5
+ export const BPMN_SHAPES_NAMESPACE = `${BPMN_ONTOLOGY_IRI}/shapes#`;
@@ -0,0 +1,19 @@
1
+ import { Store } from "n3";
2
+ export declare const RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
3
+ export declare const RDFS_SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
4
+ export declare const RDFS_DOMAIN = "http://www.w3.org/2000/01/rdf-schema#domain";
5
+ export declare const RDFS_RANGE = "http://www.w3.org/2000/01/rdf-schema#range";
6
+ export declare const parseOntology: (turtle: string) => Store<import("n3").Quad, import("n3").Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>;
7
+ export declare const ONTOLOGY_FILES: string[];
8
+ export declare const isOwnedIri: (iri: string) => boolean;
9
+ export declare const loadOntology: () => Store<import("n3").Quad, import("n3").Quad, import("@rdfjs/types").Quad, import("@rdfjs/types").Quad>;
10
+ export declare const declaredClasses: (store: Store) => Set<string>;
11
+ export declare const declaredProperties: (store: Store) => Set<string>;
12
+ export declare const declaredIndividuals: (store: Store) => Set<string>;
13
+ export declare const declaredTerms: (store: Store) => Set<string>;
14
+ export declare const typesOf: (store: Store, subject: string) => string[];
15
+ export declare const superClasses: (store: Store, cls: string) => Set<string>;
16
+ export declare const isSubClassOf: (store: Store, cls: string, ancestor: string) => boolean;
17
+ export declare const domainAlternatives: (store: Store, property: string) => string[][];
18
+ export declare const rangeAlternatives: (store: Store, property: string) => string[][];
19
+ export declare const checkOntology: (store: Store) => string[];
@@ -0,0 +1,94 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { Parser, Store } from "n3";
4
+ import { ROOT } from "./paths.js";
5
+ import { BPMN_NAMESPACE, BPMNDI_NAMESPACE } from "./namespace.js";
6
+ export const RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
7
+ export const RDFS_SUBCLASS_OF = "http://www.w3.org/2000/01/rdf-schema#subClassOf";
8
+ export const RDFS_DOMAIN = "http://www.w3.org/2000/01/rdf-schema#domain";
9
+ export const RDFS_RANGE = "http://www.w3.org/2000/01/rdf-schema#range";
10
+ const OWL = "http://www.w3.org/2002/07/owl#";
11
+ const OWL_UNION_OF = `${OWL}unionOf`;
12
+ const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
13
+ const RDF_FIRST = `${RDF}first`;
14
+ const RDF_REST = `${RDF}rest`;
15
+ const RDF_NIL = `${RDF}nil`;
16
+ const XSD = "http://www.w3.org/2001/XMLSchema#";
17
+ const CLASS_TYPES = [`${OWL}Class`];
18
+ const PROPERTY_TYPES = [`${OWL}ObjectProperty`, `${OWL}DatatypeProperty`];
19
+ export const parseOntology = (turtle) => new Store(new Parser().parse(turtle));
20
+ export const ONTOLOGY_FILES = ["ontology/core.ttl", "ontology/di.ttl"];
21
+ export const isOwnedIri = (iri) => iri.startsWith(BPMN_NAMESPACE) || iri.startsWith(BPMNDI_NAMESPACE);
22
+ export const loadOntology = () => parseOntology(ONTOLOGY_FILES.map((file) => readFileSync(join(ROOT, file), "utf8")).join("\n"));
23
+ const subjectsOfTypes = (store, types) => types.flatMap((type) => store.getSubjects(RDF_TYPE, type, null).map((s) => s.value));
24
+ export const declaredClasses = (store) => new Set(subjectsOfTypes(store, CLASS_TYPES));
25
+ export const declaredProperties = (store) => new Set(subjectsOfTypes(store, PROPERTY_TYPES));
26
+ export const declaredIndividuals = (store) => new Set(subjectsOfTypes(store, [`${OWL}NamedIndividual`]));
27
+ export const declaredTerms = (store) => new Set([...declaredClasses(store), ...declaredProperties(store), ...declaredIndividuals(store)]);
28
+ export const typesOf = (store, subject) => store.getObjects(subject, RDF_TYPE, null).map((o) => o.value);
29
+ export const superClasses = (store, cls) => {
30
+ const seen = new Set();
31
+ const pending = [cls];
32
+ while (pending.length) {
33
+ for (const parent of store.getObjects(pending.pop(), RDFS_SUBCLASS_OF, null)) {
34
+ if (!seen.has(parent.value)) {
35
+ seen.add(parent.value);
36
+ pending.push(parent.value);
37
+ }
38
+ }
39
+ }
40
+ return seen;
41
+ };
42
+ export const isSubClassOf = (store, cls, ancestor) => cls === ancestor || superClasses(store, cls).has(ancestor);
43
+ const listMembers = (store, head) => {
44
+ const members = [];
45
+ let node = head;
46
+ while (node.value !== RDF_NIL) {
47
+ const [first] = store.getObjects(node, RDF_FIRST, null);
48
+ const [rest] = store.getObjects(node, RDF_REST, null);
49
+ if (!first || !rest)
50
+ break;
51
+ members.push(first.value);
52
+ node = rest;
53
+ }
54
+ return members;
55
+ };
56
+ const alternativesOf = (store, property, predicate) => store.getObjects(property, predicate, null).map((target) => {
57
+ const [union] = store.getObjects(target, OWL_UNION_OF, null);
58
+ return union ? listMembers(store, union) : [target.value];
59
+ });
60
+ export const domainAlternatives = (store, property) => alternativesOf(store, property, RDFS_DOMAIN);
61
+ export const rangeAlternatives = (store, property) => alternativesOf(store, property, RDFS_RANGE);
62
+ export const checkOntology = (store) => {
63
+ const errors = [];
64
+ const classes = declaredClasses(store);
65
+ const properties = declaredProperties(store);
66
+ const declared = declaredTerms(store);
67
+ for (const quad of store.getQuads(null, null, null, null)) {
68
+ for (const term of [quad.subject, quad.predicate, quad.object]) {
69
+ if (term.termType === "NamedNode" && isOwnedIri(term.value) && !declared.has(term.value)) {
70
+ errors.push(`${term.value} is used but not declared`);
71
+ }
72
+ }
73
+ }
74
+ for (const property of properties) {
75
+ for (const alternatives of domainAlternatives(store, property)) {
76
+ for (const domain of alternatives) {
77
+ if (!classes.has(domain))
78
+ errors.push(`domain ${domain} of ${property} is not a declared class`);
79
+ }
80
+ }
81
+ for (const alternatives of rangeAlternatives(store, property)) {
82
+ for (const range of alternatives) {
83
+ if (!classes.has(range) && !range.startsWith(XSD)) {
84
+ errors.push(`range ${range} of ${property} is not a declared class or datatype`);
85
+ }
86
+ }
87
+ }
88
+ }
89
+ for (const cls of classes) {
90
+ if (superClasses(store, cls).has(cls))
91
+ errors.push(`class hierarchy has a cycle through ${cls}`);
92
+ }
93
+ return [...new Set(errors)];
94
+ };
@@ -0,0 +1 @@
1
+ export declare const ROOT: string;
package/dist/paths.js ADDED
@@ -0,0 +1,2 @@
1
+ import { fileURLToPath } from "node:url";
2
+ export const ROOT = fileURLToPath(new URL("..", import.meta.url));
@@ -0,0 +1,40 @@
1
+ import type { Json } from "../export/element.ts";
2
+ export interface Bounds {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export interface Point {
9
+ x: number;
10
+ y: number;
11
+ }
12
+ export interface DiagramLabel {
13
+ bounds?: Bounds;
14
+ }
15
+ export interface DiagramShape {
16
+ id: string;
17
+ bpmnElement: string;
18
+ element?: Json;
19
+ bounds: Bounds;
20
+ isExpanded?: boolean;
21
+ isHorizontal?: boolean;
22
+ isMarkerVisible?: boolean;
23
+ label?: DiagramLabel;
24
+ }
25
+ export interface DiagramEdge {
26
+ id: string;
27
+ bpmnElement: string;
28
+ element?: Json;
29
+ waypoints: Point[];
30
+ label?: DiagramLabel;
31
+ }
32
+ export interface Diagram {
33
+ id: string;
34
+ name?: string;
35
+ bpmnElement?: string;
36
+ resolution?: number;
37
+ shapes: DiagramShape[];
38
+ edges: DiagramEdge[];
39
+ }
40
+ export declare const geometryDiagrams: (document: Json) => Diagram[];
@@ -0,0 +1,81 @@
1
+ const isBounds = (value) => typeof value === "object" && value !== null && ["x", "y", "width", "height"].every((key) => Number.isFinite(value[key]));
2
+ const point = (value) => {
3
+ if (!Number.isFinite(value.x) || !Number.isFinite(value.y))
4
+ return undefined;
5
+ return { x: Number(value.x), y: Number(value.y) };
6
+ };
7
+ const shapeFrom = (node, byId) => {
8
+ if (typeof node.id !== "string" || typeof node.bpmnElement !== "string" || !isBounds(node.bounds))
9
+ return undefined;
10
+ return {
11
+ id: node.id,
12
+ bpmnElement: node.bpmnElement,
13
+ element: byId.get(node.bpmnElement),
14
+ bounds: node.bounds,
15
+ isExpanded: node.isExpanded === false ? false : node.isExpanded === true ? true : undefined,
16
+ isHorizontal: node.isHorizontal === true ? true : undefined,
17
+ isMarkerVisible: node.isMarkerVisible === true ? true : undefined,
18
+ label: typeof node.label === "object" && node.label !== null ? { bounds: isBounds(node.label.bounds) ? node.label.bounds : undefined } : undefined,
19
+ };
20
+ };
21
+ const edgeFrom = (node, byId) => {
22
+ if (typeof node.id !== "string" || typeof node.bpmnElement !== "string")
23
+ return undefined;
24
+ const waypoints = Array.isArray(node.waypoints) ? node.waypoints.map((item) => point(item)).filter((item) => item !== undefined) : [];
25
+ if (waypoints.length === 0)
26
+ return undefined;
27
+ return {
28
+ id: node.id,
29
+ bpmnElement: node.bpmnElement,
30
+ element: byId.get(node.bpmnElement),
31
+ waypoints,
32
+ label: typeof node.label === "object" && node.label !== null ? { bounds: isBounds(node.label.bounds) ? node.label.bounds : undefined } : undefined,
33
+ };
34
+ };
35
+ export const geometryDiagrams = (document) => {
36
+ const graph = Array.isArray(document["@graph"]) ? document["@graph"] : [document];
37
+ const byId = new Map();
38
+ const visit = (value) => {
39
+ if (Array.isArray(value))
40
+ value.forEach(visit);
41
+ else if (value && typeof value === "object") {
42
+ const node = value;
43
+ if (typeof node.id === "string")
44
+ byId.set(node.id, node);
45
+ Object.values(node).forEach(visit);
46
+ }
47
+ };
48
+ visit(graph);
49
+ const diagrams = [];
50
+ for (const node of graph) {
51
+ if (node?.type !== "BPMNDiagram" || typeof node.id !== "string")
52
+ continue;
53
+ const plane = node.plane;
54
+ if (!plane || typeof plane !== "object")
55
+ continue;
56
+ const elements = Array.isArray(plane.planeElements) ? plane.planeElements : [];
57
+ const shapes = [];
58
+ const edges = [];
59
+ for (const element of elements) {
60
+ if (element?.type === "BPMNShape") {
61
+ const shape = shapeFrom(element, byId);
62
+ if (shape)
63
+ shapes.push(shape);
64
+ }
65
+ else if (element?.type === "BPMNEdge") {
66
+ const edge = edgeFrom(element, byId);
67
+ if (edge)
68
+ edges.push(edge);
69
+ }
70
+ }
71
+ diagrams.push({
72
+ id: node.id,
73
+ name: typeof node.name === "string" ? node.name : undefined,
74
+ bpmnElement: typeof plane.bpmnElement === "string" ? plane.bpmnElement : undefined,
75
+ resolution: typeof node.resolution === "number" ? node.resolution : undefined,
76
+ shapes,
77
+ edges,
78
+ });
79
+ }
80
+ return diagrams;
81
+ };
@@ -0,0 +1,31 @@
1
+ import { type Diagram } from "./geometry.ts";
2
+ import type { Json } from "../export/element.ts";
3
+ export interface RenderWarning {
4
+ kind: "unsupported";
5
+ code: string;
6
+ construct: string;
7
+ location: string;
8
+ node?: string;
9
+ message?: string;
10
+ }
11
+ export interface RenderError {
12
+ code: string;
13
+ message: string;
14
+ }
15
+ export interface RenderedDiagram {
16
+ id: string;
17
+ name?: string;
18
+ svg: string;
19
+ warnings: RenderWarning[];
20
+ errors: RenderError[];
21
+ }
22
+ export interface RenderedDocument {
23
+ diagrams: RenderedDiagram[];
24
+ warnings: RenderWarning[];
25
+ errors: RenderError[];
26
+ }
27
+ export declare const renderDiagramSvg: (diagram: Diagram) => {
28
+ svg: string;
29
+ warnings: RenderWarning[];
30
+ };
31
+ export declare const renderDocument: (document: Json) => RenderedDocument;