@linked.archi/kernel 0.0.0-stage → 0.1.6

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 (366) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +11 -0
  3. package/README.md +102 -2
  4. package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
  5. package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
  6. package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
  7. package/assets/arch-decision/arch-decision-tax.ttl +129 -0
  8. package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
  9. package/assets/arch-processes/arch-processes-tax.ttl +136 -0
  10. package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
  11. package/assets/arch-processes/archProcesses.ttl +953 -0
  12. package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
  13. package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
  14. package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
  15. package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
  16. package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
  17. package/assets/archimate3/archimate3.2-principle-shapes.ttl +917 -0
  18. package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
  19. package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
  20. package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
  21. package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
  22. package/assets/archimate3/archimate3.2-tax.ttl +724 -0
  23. package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
  24. package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
  25. package/assets/archimate3/icons/and-junction.svg +3 -0
  26. package/assets/archimate3/icons/application-collaboration.svg +22 -0
  27. package/assets/archimate3/icons/application-component.svg +18 -0
  28. package/assets/archimate3/icons/application-event.svg +15 -0
  29. package/assets/archimate3/icons/application-function.svg +14 -0
  30. package/assets/archimate3/icons/application-interaction.svg +17 -0
  31. package/assets/archimate3/icons/application-interface.svg +16 -0
  32. package/assets/archimate3/icons/application-process.svg +14 -0
  33. package/assets/archimate3/icons/application-service.svg +14 -0
  34. package/assets/archimate3/icons/artifact.svg +16 -0
  35. package/assets/archimate3/icons/assessment.svg +17 -0
  36. package/assets/archimate3/icons/business-actor.svg +22 -0
  37. package/assets/archimate3/icons/business-collaboration.svg +21 -0
  38. package/assets/archimate3/icons/business-event.svg +15 -0
  39. package/assets/archimate3/icons/business-function.svg +14 -0
  40. package/assets/archimate3/icons/business-interaction.svg +18 -0
  41. package/assets/archimate3/icons/business-interface.svg +16 -0
  42. package/assets/archimate3/icons/business-object.svg +14 -0
  43. package/assets/archimate3/icons/business-process.svg +15 -0
  44. package/assets/archimate3/icons/business-role.svg +16 -0
  45. package/assets/archimate3/icons/business-service.svg +14 -0
  46. package/assets/archimate3/icons/capability.svg +40 -0
  47. package/assets/archimate3/icons/communication-network.svg +18 -0
  48. package/assets/archimate3/icons/constraint.svg +18 -0
  49. package/assets/archimate3/icons/contract.svg +13 -0
  50. package/assets/archimate3/icons/course-of-action.svg +20 -0
  51. package/assets/archimate3/icons/data-object.svg +14 -0
  52. package/assets/archimate3/icons/deliverable.svg +11 -0
  53. package/assets/archimate3/icons/device.svg +18 -0
  54. package/assets/archimate3/icons/distribution-network.svg +19 -0
  55. package/assets/archimate3/icons/driver.svg +24 -0
  56. package/assets/archimate3/icons/equipment.svg +31 -0
  57. package/assets/archimate3/icons/facility.svg +16 -0
  58. package/assets/archimate3/icons/gap.svg +22 -0
  59. package/assets/archimate3/icons/glyphs/activity.svg +3 -0
  60. package/assets/archimate3/icons/glyphs/actor.svg +14 -0
  61. package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
  62. package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
  63. package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
  64. package/assets/archimate3/icons/glyphs/capability.svg +32 -0
  65. package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
  66. package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
  67. package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
  68. package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
  69. package/assets/archimate3/icons/glyphs/contract.svg +5 -0
  70. package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
  71. package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
  72. package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
  73. package/assets/archimate3/icons/glyphs/device.svg +10 -0
  74. package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
  75. package/assets/archimate3/icons/glyphs/driver.svg +16 -0
  76. package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
  77. package/assets/archimate3/icons/glyphs/event.svg +6 -0
  78. package/assets/archimate3/icons/glyphs/facility.svg +7 -0
  79. package/assets/archimate3/icons/glyphs/function.svg +6 -0
  80. package/assets/archimate3/icons/glyphs/gap.svg +14 -0
  81. package/assets/archimate3/icons/glyphs/goal.svg +10 -0
  82. package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
  83. package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
  84. package/assets/archimate3/icons/glyphs/interface.svg +8 -0
  85. package/assets/archimate3/icons/glyphs/location.svg +6 -0
  86. package/assets/archimate3/icons/glyphs/material.svg +12 -0
  87. package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
  88. package/assets/archimate3/icons/glyphs/node.svg +8 -0
  89. package/assets/archimate3/icons/glyphs/object.svg +4 -0
  90. package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
  91. package/assets/archimate3/icons/glyphs/path.svg +10 -0
  92. package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
  93. package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
  94. package/assets/archimate3/icons/glyphs/principle.svg +12 -0
  95. package/assets/archimate3/icons/glyphs/process.svg +6 -0
  96. package/assets/archimate3/icons/glyphs/product.svg +4 -0
  97. package/assets/archimate3/icons/glyphs/representation.svg +4 -0
  98. package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
  99. package/assets/archimate3/icons/glyphs/resource.svg +14 -0
  100. package/assets/archimate3/icons/glyphs/role.svg +6 -0
  101. package/assets/archimate3/icons/glyphs/service.svg +6 -0
  102. package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
  103. package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
  104. package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
  105. package/assets/archimate3/icons/glyphs/value.svg +3 -0
  106. package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
  107. package/assets/archimate3/icons/goal.svg +18 -0
  108. package/assets/archimate3/icons/grouping.svg +12 -0
  109. package/assets/archimate3/icons/implementation-event.svg +15 -0
  110. package/assets/archimate3/icons/location.svg +14 -0
  111. package/assets/archimate3/icons/material.svg +21 -0
  112. package/assets/archimate3/icons/meaning.svg +11 -0
  113. package/assets/archimate3/icons/node.svg +14 -0
  114. package/assets/archimate3/icons/or-junction.svg +3 -0
  115. package/assets/archimate3/icons/outcome.svg +25 -0
  116. package/assets/archimate3/icons/path.svg +18 -0
  117. package/assets/archimate3/icons/plateau.svg +16 -0
  118. package/assets/archimate3/icons/principle.svg +21 -0
  119. package/assets/archimate3/icons/product.svg +12 -0
  120. package/assets/archimate3/icons/representation.svg +12 -0
  121. package/assets/archimate3/icons/requirement.svg +14 -0
  122. package/assets/archimate3/icons/resource.svg +23 -0
  123. package/assets/archimate3/icons/stakeholder.svg +15 -0
  124. package/assets/archimate3/icons/system-software.svg +22 -0
  125. package/assets/archimate3/icons/technology-collaboration.svg +22 -0
  126. package/assets/archimate3/icons/technology-event.svg +15 -0
  127. package/assets/archimate3/icons/technology-function.svg +14 -0
  128. package/assets/archimate3/icons/technology-interaction.svg +18 -0
  129. package/assets/archimate3/icons/technology-interface.svg +16 -0
  130. package/assets/archimate3/icons/technology-process.svg +14 -0
  131. package/assets/archimate3/icons/technology-service.svg +14 -0
  132. package/assets/archimate3/icons/value-stream.svg +11 -0
  133. package/assets/archimate3/icons/value.svg +11 -0
  134. package/assets/archimate3/icons/work-package.svg +12 -0
  135. package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
  136. package/assets/archimate4/archimate4-metamodel.ttl +179 -0
  137. package/assets/archimate4/archimate4-notation.ttl +1147 -0
  138. package/assets/archimate4/archimate4-onto.ttl +1559 -0
  139. package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
  140. package/assets/archimate4/archimate4-principle-shapes.ttl +895 -0
  141. package/assets/archimate4/archimate4-questions.ttl +1224 -0
  142. package/assets/archimate4/archimate4-reference-data.ttl +56 -0
  143. package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
  144. package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
  145. package/assets/archimate4/archimate4-tax.ttl +749 -0
  146. package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
  147. package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
  148. package/assets/archimate4/icons/and-junction.svg +3 -0
  149. package/assets/archimate4/icons/application-component.svg +18 -0
  150. package/assets/archimate4/icons/application-interface.svg +16 -0
  151. package/assets/archimate4/icons/artifact.svg +16 -0
  152. package/assets/archimate4/icons/assessment.svg +17 -0
  153. package/assets/archimate4/icons/business-actor.svg +22 -0
  154. package/assets/archimate4/icons/business-interface.svg +16 -0
  155. package/assets/archimate4/icons/business-object.svg +14 -0
  156. package/assets/archimate4/icons/capability.svg +40 -0
  157. package/assets/archimate4/icons/collaboration.svg +21 -0
  158. package/assets/archimate4/icons/communication-network.svg +18 -0
  159. package/assets/archimate4/icons/course-of-action.svg +20 -0
  160. package/assets/archimate4/icons/data-object.svg +14 -0
  161. package/assets/archimate4/icons/deliverable.svg +11 -0
  162. package/assets/archimate4/icons/device.svg +18 -0
  163. package/assets/archimate4/icons/distribution-network.svg +19 -0
  164. package/assets/archimate4/icons/driver.svg +24 -0
  165. package/assets/archimate4/icons/equipment.svg +31 -0
  166. package/assets/archimate4/icons/event.svg +15 -0
  167. package/assets/archimate4/icons/facility.svg +16 -0
  168. package/assets/archimate4/icons/function.svg +13 -0
  169. package/assets/archimate4/icons/glyphs/activity.svg +3 -0
  170. package/assets/archimate4/icons/glyphs/actor.svg +14 -0
  171. package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
  172. package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
  173. package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
  174. package/assets/archimate4/icons/glyphs/capability.svg +32 -0
  175. package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
  176. package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
  177. package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
  178. package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
  179. package/assets/archimate4/icons/glyphs/contract.svg +5 -0
  180. package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
  181. package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
  182. package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
  183. package/assets/archimate4/icons/glyphs/device.svg +10 -0
  184. package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
  185. package/assets/archimate4/icons/glyphs/driver.svg +16 -0
  186. package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
  187. package/assets/archimate4/icons/glyphs/event.svg +6 -0
  188. package/assets/archimate4/icons/glyphs/facility.svg +7 -0
  189. package/assets/archimate4/icons/glyphs/function.svg +6 -0
  190. package/assets/archimate4/icons/glyphs/gap.svg +14 -0
  191. package/assets/archimate4/icons/glyphs/goal.svg +10 -0
  192. package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
  193. package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
  194. package/assets/archimate4/icons/glyphs/interface.svg +8 -0
  195. package/assets/archimate4/icons/glyphs/location.svg +6 -0
  196. package/assets/archimate4/icons/glyphs/material.svg +12 -0
  197. package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
  198. package/assets/archimate4/icons/glyphs/node.svg +8 -0
  199. package/assets/archimate4/icons/glyphs/object.svg +4 -0
  200. package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
  201. package/assets/archimate4/icons/glyphs/path.svg +10 -0
  202. package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
  203. package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
  204. package/assets/archimate4/icons/glyphs/principle.svg +12 -0
  205. package/assets/archimate4/icons/glyphs/process.svg +6 -0
  206. package/assets/archimate4/icons/glyphs/product.svg +4 -0
  207. package/assets/archimate4/icons/glyphs/representation.svg +4 -0
  208. package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
  209. package/assets/archimate4/icons/glyphs/resource.svg +14 -0
  210. package/assets/archimate4/icons/glyphs/role.svg +6 -0
  211. package/assets/archimate4/icons/glyphs/service.svg +6 -0
  212. package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
  213. package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
  214. package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
  215. package/assets/archimate4/icons/glyphs/value.svg +3 -0
  216. package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
  217. package/assets/archimate4/icons/goal.svg +18 -0
  218. package/assets/archimate4/icons/grouping.svg +12 -0
  219. package/assets/archimate4/icons/location.svg +14 -0
  220. package/assets/archimate4/icons/material.svg +21 -0
  221. package/assets/archimate4/icons/meaning.svg +11 -0
  222. package/assets/archimate4/icons/node.svg +14 -0
  223. package/assets/archimate4/icons/or-junction.svg +3 -0
  224. package/assets/archimate4/icons/outcome.svg +25 -0
  225. package/assets/archimate4/icons/path.svg +18 -0
  226. package/assets/archimate4/icons/plateau.svg +16 -0
  227. package/assets/archimate4/icons/principle.svg +21 -0
  228. package/assets/archimate4/icons/process.svg +15 -0
  229. package/assets/archimate4/icons/product.svg +12 -0
  230. package/assets/archimate4/icons/requirement.svg +14 -0
  231. package/assets/archimate4/icons/resource.svg +23 -0
  232. package/assets/archimate4/icons/role.svg +16 -0
  233. package/assets/archimate4/icons/service.svg +13 -0
  234. package/assets/archimate4/icons/stakeholder.svg +15 -0
  235. package/assets/archimate4/icons/system-software.svg +22 -0
  236. package/assets/archimate4/icons/technology-interface.svg +16 -0
  237. package/assets/archimate4/icons/value-stream.svg +11 -0
  238. package/assets/archimate4/icons/value.svg +11 -0
  239. package/assets/archimate4/icons/work-package.svg +12 -0
  240. package/assets/basic/basic-metamodel.ttl +100 -0
  241. package/assets/basic/basic-notation-bubble.ttl +175 -0
  242. package/assets/basic/basic-notation.ttl +172 -0
  243. package/assets/basic/basic-onto.ttl +171 -0
  244. package/assets/basic/basic-presentation-contexts.ttl +70 -0
  245. package/assets/basic/basic-tax.ttl +130 -0
  246. package/assets/basic/icons/aggregation.svg +7 -0
  247. package/assets/basic/icons/association.svg +6 -0
  248. package/assets/basic/icons/element.svg +5 -0
  249. package/assets/basic/icons/glyphs/aggregation.svg +6 -0
  250. package/assets/basic/icons/glyphs/association.svg +5 -0
  251. package/assets/basic/icons/glyphs/element.svg +5 -0
  252. package/assets/basic/icons/glyphs/relationship.svg +5 -0
  253. package/assets/basic/icons/relationship.svg +7 -0
  254. package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
  255. package/assets/basic/notation-bubble/icons/association.svg +6 -0
  256. package/assets/basic/notation-bubble/icons/element.svg +5 -0
  257. package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
  258. package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
  259. package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
  260. package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
  261. package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
  262. package/assets/catalog.ttl +7406 -0
  263. package/assets/core/core-notation.ttl +131 -0
  264. package/assets/core/core-onto.ttl +2811 -0
  265. package/assets/core/core-questions.ttl +957 -0
  266. package/assets/core/core-shapes.ttl +915 -0
  267. package/assets/core/core-vis-onto.ttl +1408 -0
  268. package/assets/core/core-vis-shapes.ttl +851 -0
  269. package/assets/core-vis/markers/circle-dot.svg +3 -0
  270. package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
  271. package/assets/core-vis/markers/filled-diamond.svg +3 -0
  272. package/assets/core-vis/markers/half-arrowhead.svg +3 -0
  273. package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
  274. package/assets/core-vis/markers/hollow-diamond.svg +3 -0
  275. package/assets/core-vis/markers/open-arrowhead.svg +3 -0
  276. package/fixtures/interoperability/archimate4-demo.trig +259 -0
  277. package/fixtures/interoperability/expected-findings.json +26 -0
  278. package/fixtures/interoperability/shop-seed.ttl +225 -0
  279. package/package.json +136 -4
  280. package/scripts/sync-assets.mjs +252 -0
  281. package/src/conformance.ts +66 -0
  282. package/src/import-export/model-io.ts +426 -0
  283. package/src/index.ts +11 -0
  284. package/src/metamodel-manager/asset-sources.ts +754 -0
  285. package/src/metamodel-manager/bundled-assets.ts +599 -0
  286. package/src/metamodel-manager/catalogue.ts +114 -0
  287. package/src/metamodel-manager/class-hierarchy.ts +155 -0
  288. package/src/metamodel-manager/index.ts +65 -0
  289. package/src/metamodel-manager/interfaces.ts +422 -0
  290. package/src/metamodel-manager/metamodel-completeness.ts +162 -0
  291. package/src/metamodel-manager/metamodel-loader.ts +864 -0
  292. package/src/metamodel-manager/notation-resolver.ts +284 -0
  293. package/src/metamodel-manager/notation.ts +659 -0
  294. package/src/metamodel-manager/palette-generator.ts +882 -0
  295. package/src/metamodel-manager/property-shapes.ts +290 -0
  296. package/src/metamodel-manager/taxonomy.ts +904 -0
  297. package/src/metamodel-manager/type-guide.ts +241 -0
  298. package/src/metamodel-manager/viewpoint-manager.ts +147 -0
  299. package/src/model-manager/appearance.ts +389 -0
  300. package/src/model-manager/cascade.ts +246 -0
  301. package/src/model-manager/clipboard.ts +566 -0
  302. package/src/model-manager/context-names.ts +108 -0
  303. package/src/model-manager/custom-properties.ts +549 -0
  304. package/src/model-manager/derivations.ts +166 -0
  305. package/src/model-manager/direct-permissions.ts +182 -0
  306. package/src/model-manager/drawing-order.ts +119 -0
  307. package/src/model-manager/element-manager.ts +69 -0
  308. package/src/model-manager/element-pictures.ts +118 -0
  309. package/src/model-manager/field-names.ts +42 -0
  310. package/src/model-manager/folders.ts +354 -0
  311. package/src/model-manager/grid.ts +6 -0
  312. package/src/model-manager/index.ts +43 -0
  313. package/src/model-manager/interfaces.ts +417 -0
  314. package/src/model-manager/iri-conformance.ts +183 -0
  315. package/src/model-manager/label-expression.ts +233 -0
  316. package/src/model-manager/legacy-migration.ts +200 -0
  317. package/src/model-manager/missing-references.ts +86 -0
  318. package/src/model-manager/model-diff-text.ts +150 -0
  319. package/src/model-manager/model-diff.ts +534 -0
  320. package/src/model-manager/model-merge.ts +1160 -0
  321. package/src/model-manager/model-namespace.ts +199 -0
  322. package/src/model-manager/model-operations.ts +132 -0
  323. package/src/model-manager/model-queries.ts +616 -0
  324. package/src/model-manager/model-session.ts +759 -0
  325. package/src/model-manager/multiplicity.ts +74 -0
  326. package/src/model-manager/nested-resources.ts +145 -0
  327. package/src/model-manager/own-metamodel.ts +157 -0
  328. package/src/model-manager/placement-copy.ts +116 -0
  329. package/src/model-manager/property-catalog.ts +787 -0
  330. package/src/model-manager/proposal-order.ts +203 -0
  331. package/src/model-manager/provenance.ts +396 -0
  332. package/src/model-manager/questions.ts +475 -0
  333. package/src/model-manager/rdf-scope.ts +97 -0
  334. package/src/model-manager/relationship-graph.ts +462 -0
  335. package/src/model-manager/relationship-manager.ts +962 -0
  336. package/src/model-manager/relationship-table.ts +189 -0
  337. package/src/model-manager/relationship-validity.ts +261 -0
  338. package/src/model-manager/resource-edits.ts +28 -0
  339. package/src/model-manager/short-hash.ts +104 -0
  340. package/src/model-manager/snapshot-lines.ts +88 -0
  341. package/src/model-manager/version-history.ts +205 -0
  342. package/src/model-manager/view-from-results.ts +81 -0
  343. package/src/model-manager/view-manager.ts +1410 -0
  344. package/src/model-manager/vocabulary.ts +279 -0
  345. package/src/rdf-engine/finding-shape.ts +23 -0
  346. package/src/rdf-engine/graph-scope.ts +163 -0
  347. package/src/rdf-engine/index.ts +7 -0
  348. package/src/rdf-engine/interfaces.ts +144 -0
  349. package/src/rdf-engine/iri.ts +203 -0
  350. package/src/rdf-engine/localized-text.ts +13 -0
  351. package/src/rdf-engine/namespaces.ts +41 -0
  352. package/src/rdf-engine/native-load.ts +37 -0
  353. package/src/rdf-engine/observable-store.ts +609 -0
  354. package/src/rdf-engine/rdf-store.ts +520 -0
  355. package/src/rdf-engine/shacl-validator.ts +602 -0
  356. package/src/rdf-engine/shape-reach.ts +140 -0
  357. package/src/rdf-engine/shape-switches.ts +165 -0
  358. package/src/rdf-engine/single-valued.ts +219 -0
  359. package/src/rdf-engine/sparql-constraints.ts +349 -0
  360. package/src/rdf-engine/term-codec.ts +51 -0
  361. package/src/rdf-engine/ttl-parser.ts +51 -0
  362. package/src/rdf-engine/ttl-serializer.ts +79 -0
  363. package/src/rdf-engine/turtle-writer.ts +284 -0
  364. package/src/rdf-engine/validation-engine.ts +747 -0
  365. package/src/rdf-engine/validation-service.ts +186 -0
  366. package/src/rdf-engine/validation.worker.ts +47 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * How many concepts may be at each end of a relationship (core 0.8.0, linked-archi-meta's DD-46):
3
+ * `arch:sourceMultiplicity` and `arch:targetMultiplicity` on the relationship resource, a plain string in the common
4
+ * notation — `1`, `*`, `0..1`, `1..*`. A language whose specification defines multiplicity says so with its own
5
+ * properties, subproperties of the core's (`am4:sourceMultiplicity`, `uml:targetMultiplicity`), so a relationship's
6
+ * multiplicity is read under the core's properties and every property the loaded metamodels declare a subproperty of
7
+ * them, at any depth (KD-18). Nothing is inferred into the model: the subproperties are read from the metamodels'
8
+ * graphs, the values from the model's.
9
+ *
10
+ * The source multiplicity is the multiplicity at the source end: on a relationship from A to B, how many A one B may
11
+ * be related to.
12
+ */
13
+
14
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
15
+ import { IRI, T, nn } from './vocabulary.js';
16
+
17
+ /** A relationship's multiplicity at each end, as written; an end without one is absent. */
18
+ export interface Multiplicity {
19
+ source?: string;
20
+ target?: string;
21
+ }
22
+
23
+ /** The properties a multiplicity is read under, for each end. */
24
+ export interface MultiplicityProperties {
25
+ source: ReadonlySet<string>;
26
+ target: ReadonlySet<string>;
27
+ }
28
+
29
+ /** `property` and every property declared a subproperty of it, at any depth, in any graph. */
30
+ function withSubproperties(store: RdfStore, property: string): Set<string> {
31
+ const found = new Set([property]);
32
+ const pending = [property];
33
+ while (pending.length > 0) {
34
+ const next = pending.pop()!;
35
+ for (const q of store.getQuads(null, T.subPropertyOf, nn(next))) {
36
+ if (q.subject.termType !== 'NamedNode' || found.has(q.subject.value)) continue;
37
+ found.add(q.subject.value);
38
+ pending.push(q.subject.value);
39
+ }
40
+ }
41
+ return found;
42
+ }
43
+
44
+ /** The core's multiplicity properties and the loaded metamodels' subproperties of them (KD-18). */
45
+ export function multiplicityProperties(store: RdfStore): MultiplicityProperties {
46
+ return {
47
+ source: withSubproperties(store, IRI.sourceMultiplicity),
48
+ target: withSubproperties(store, IRI.targetMultiplicity),
49
+ };
50
+ }
51
+
52
+ /**
53
+ * A relationship's multiplicity at each end, from the model. One value at an end is the multiplicity; more than one —
54
+ * which the core's shape reports — are all given, each once, in order and separated by commas, so that what is drawn
55
+ * is what the model says. A value is a literal; anything else is not a multiplicity and is left out.
56
+ */
57
+ export function multiplicityOf(
58
+ store: RdfStore,
59
+ relationshipIri: string,
60
+ properties: MultiplicityProperties = multiplicityProperties(store),
61
+ ): Multiplicity {
62
+ const source = new Set<string>();
63
+ const target = new Set<string>();
64
+ for (const q of store.getQuads(nn(relationshipIri), null, null)) {
65
+ if (q.graph.termType !== 'DefaultGraph' || q.object.termType !== 'Literal') continue;
66
+ if (properties.source.has(q.predicate.value)) source.add(q.object.value);
67
+ if (properties.target.has(q.predicate.value)) target.add(q.object.value);
68
+ }
69
+ const written = (values: Set<string>) => [...values].sort().join(', ');
70
+ return {
71
+ ...(source.size > 0 ? { source: written(source) } : {}),
72
+ ...(target.size > 0 ? { target: written(target) } : {}),
73
+ };
74
+ }
@@ -0,0 +1,145 @@
1
+ /** Named parts addressed through one model property (KReq 3–5). */
2
+ import { DataFactory } from 'n3';
3
+ import type { NamedNode, Quad, Term } from '@rdfjs/types';
4
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
5
+ import { partIri, uuid } from '../rdf-engine/iri.js';
6
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
7
+ import { isQualifiedPredicate } from './cascade.js';
8
+ import { replacePropertyValues } from './resource-edits.js';
9
+ import { IRI, T, nn, triple } from './vocabulary.js';
10
+
11
+ export interface NestedResourceLink {
12
+ readonly parentIri: string;
13
+ readonly path: string;
14
+ readonly childIri: string;
15
+ }
16
+
17
+ export type NestedResourceAccess = 'missing' | 'owned' | 'reference';
18
+ export interface NestedResourceRemoval {
19
+ readonly paths?: readonly string[];
20
+ readonly classIris?: readonly string[];
21
+ }
22
+
23
+ const MODEL_GRAPH = DataFactory.defaultGraph() as unknown as NamedNode;
24
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
25
+ const PROPERTY_STAMPS = new Set([IRI.dctermsCreated, IRI.dctermsModified, NAMESPACES.prov + 'wasGeneratedBy',
26
+ NAMESPACES.prov + 'generatedAtTime']);
27
+ const STRUCTURAL_PATHS = new Set<string>([
28
+ IRI.rdfType, IRI.inModel, IRI.inView, IRI.dctermsIsPartOf, IRI.source, IRI.target, IRI.reifies,
29
+ IRI.modelConformsToMetamodel, IRI.viewConformsToViewpoint, IRI.legacyConformsToMetamodel,
30
+ IRI.legacyPartOfModel, IRI.legacyRelSource, IRI.legacyRelTarget, IRI.legacyRelPredicate,
31
+ IRI.rdfFirst, IRI.rdfRest, IRI.archElement, IRI.archRelationship, IRI.visView,
32
+ IRI.visSource, IRI.visTarget,
33
+ ]);
34
+
35
+ export function isNestedResourceProperty(store: RdfStore, path: string): boolean {
36
+ return !!path && !STRUCTURAL_PATHS.has(path) && !PROPERTY_STAMPS.has(path) && !path.startsWith(NAMESPACES.prov)
37
+ && !isQualifiedPredicate(store, path) && !store.getQuads(null, T.unqualifiedForm, nn(path)).length;
38
+ }
39
+
40
+ function memberOf(store: RdfStore, iri: string): string | undefined {
41
+ const links = store.getQuads(nn(iri), T.inModel, null, MODEL_GRAPH);
42
+ if (links.length === 1 && links[0].object.termType === 'NamedNode') return links[0].object.value;
43
+ return undefined;
44
+ }
45
+
46
+ function parentModel(store: RdfStore, parentIri: string): string | undefined {
47
+ const parent = nn(parentIri);
48
+ return store.getQuads(parent, T.rdfType, T.Model, MODEL_GRAPH).length ? parentIri : memberOf(store, parentIri);
49
+ }
50
+
51
+ function ownsPart(store: RdfStore, parentIri: string, childIri: string): boolean {
52
+ const key = childIri.slice(-36);
53
+ if (!UUID.test(key) || childIri !== partIri(parentIri, 'part', key)) return false;
54
+ const ownership = store.getQuads(nn(childIri), T.dctermsIsPartOf, null, MODEL_GRAPH);
55
+ if (ownership.length !== 1 || !ownership[0].object.equals(nn(parentIri))) return false;
56
+ const model = parentModel(store, parentIri);
57
+ return model !== undefined && memberOf(store, childIri) === model;
58
+ }
59
+
60
+ function mentions(term: Term, resource: NamedNode): boolean {
61
+ if (term.termType === 'Quad') {
62
+ return mentions(term.subject, resource) || mentions(term.predicate, resource) || mentions(term.object, resource);
63
+ }
64
+ return term.equals(resource);
65
+ }
66
+
67
+ function hasOtherReferences(store: RdfStore, link: NestedResourceLink, assertion: Quad): boolean {
68
+ const child = nn(link.childIri);
69
+ if (store.getQuads(child).some(q => q.graph.termType !== 'DefaultGraph')) return true;
70
+ if (store.getQuads(null, child).length || store.getQuads(null, null, null, child).length) return true;
71
+ for (const q of store.getQuads(null, null, child)) {
72
+ if (q.equals(assertion)) continue;
73
+ // The ownership backlink of a verified descendant does not make its parent a shared reference.
74
+ if (q.graph.termType === 'DefaultGraph' && q.predicate.equals(T.dctermsIsPartOf) && q.subject.termType === 'NamedNode'
75
+ && ownsPart(store, link.childIri, q.subject.value)
76
+ && store.getQuads(child, null, q.subject, MODEL_GRAPH).some(edge => isNestedResourceProperty(store, edge.predicate.value))) continue;
77
+ return true;
78
+ }
79
+ // A reifier or another quoted RDF triple can refer to a part without a direct incoming assertion.
80
+ return store.getQuads().some(q => (q.subject.termType === 'Quad' && mentions(q.subject, child))
81
+ || (q.object.termType === 'Quad' && mentions(q.object, child)));
82
+ }
83
+
84
+ /** Ownership is persisted as data. A name or a sh:node constraint on its own establishes no ownership. */
85
+ export function nestedResourceAccess(store: RdfStore, link: NestedResourceLink): NestedResourceAccess {
86
+ if (!isNestedResourceProperty(store, link.path) || !parentModel(store, link.parentIri)) return 'missing';
87
+ const [assertion] = store.getQuads(nn(link.parentIri), nn(link.path), nn(link.childIri), MODEL_GRAPH);
88
+ if (!assertion) return 'missing';
89
+ return ownsPart(store, link.parentIri, link.childIri) && !hasOtherReferences(store, link, assertion)
90
+ ? 'owned' : 'reference';
91
+ }
92
+
93
+ /** Mint a part under its parent. The calling form supplies classes explicitly required by its shapes. */
94
+ export function createNestedResource(store: RdfStore, parentIri: string, path: string, classIris: readonly string[] = []): string {
95
+ const model = parentModel(store, parentIri);
96
+ if (!model || !isNestedResourceProperty(store, path)) throw new Error('The nested property must belong to a resource in the model.');
97
+ const childIri = partIri(parentIri, 'part', uuid());
98
+ const child = nn(childIri);
99
+ const parent = nn(parentIri);
100
+ const added = [triple(parent, nn(path), child), triple(child, T.dctermsIsPartOf, parent), triple(child, T.inModel, nn(model)),
101
+ ...[...new Set(classIris)].map(type => triple(child, T.rdfType, nn(type)))];
102
+ store.check?.(added);
103
+ store.addQuads(added);
104
+ return childIri;
105
+ }
106
+
107
+ /** Shared values are edited through their own resource, with no writes through nested references. */
108
+ export function replaceNestedResourceValues(store: RdfStore, link: NestedResourceLink, path: string, values: readonly Term[]): void {
109
+ if (nestedResourceAccess(store, link) !== 'owned') throw new Error('This nested resource is a read-only reference.');
110
+ if (!isNestedResourceProperty(store, path)) throw new Error('This nested property cannot be edited.');
111
+ const subject = nn(link.childIri);
112
+ const current = store.getQuads(subject, nn(path), null, MODEL_GRAPH).map(q => q.object);
113
+ if ([...current, ...values].some(term => term.termType !== 'Literal' && term.termType !== 'NamedNode')) {
114
+ throw new Error('This nested property contains an unsupported RDF term.');
115
+ }
116
+ if ([...current, ...values].some(term => term.termType === 'NamedNode' && ownsPart(store, link.childIri, term.value))) {
117
+ throw new Error('Use a nested resource operation to change an owned part.');
118
+ }
119
+ store.check?.(values.map(value => triple(subject, nn(path), value)));
120
+ replacePropertyValues(store, link.childIri, path, values);
121
+ }
122
+
123
+ /** The precise removal set. Keep a subtree or any unrecognised data intact when unlinking its owner. */
124
+ export function collectNestedResourceQuads(store: RdfStore, link: NestedResourceLink, removable: NestedResourceRemoval = {}): Quad[] {
125
+ const access = nestedResourceAccess(store, link);
126
+ if (access === 'missing') return [];
127
+ const child = nn(link.childIri);
128
+ const assertion = store.getQuads(nn(link.parentIri), nn(link.path), child, MODEL_GRAPH);
129
+ if (access !== 'owned' || store.getQuads(null, T.dctermsIsPartOf, child, MODEL_GRAPH).length) return assertion;
130
+ const paths = new Set(removable.paths?.filter(path => isNestedResourceProperty(store, path)));
131
+ const classIris = new Set(removable.classIris);
132
+ const statements = store.getQuads(child, null, null, MODEL_GRAPH);
133
+ const prunable = statements.every(q => {
134
+ if (q.object.termType !== 'Literal' && q.object.termType !== 'NamedNode') return false;
135
+ const predicate = q.predicate.value;
136
+ if (predicate === IRI.rdfType) return q.object.termType === 'NamedNode' && classIris.has(q.object.value);
137
+ return predicate === IRI.dctermsIsPartOf || predicate === IRI.inModel
138
+ || PROPERTY_STAMPS.has(predicate) || paths.has(predicate);
139
+ });
140
+ return prunable ? [...assertion, ...statements] : assertion;
141
+ }
142
+
143
+ export function removeNestedResource(store: RdfStore, link: NestedResourceLink, removable?: NestedResourceRemoval): void {
144
+ store.removeQuads(collectNestedResourceQuads(store, link, removable));
145
+ }
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Which metamodel a relationship type belongs to, and so which elements it relates where its hints do not say.
3
+ *
4
+ * A language's relationship types relate its own elements; between elements of different languages the core's
5
+ * types are offered (DD-40). A type's `arch:domainIncludes` / `arch:rangeIncludes` say which of its language's
6
+ * classes it relates: C4's Uses names C4's. `arch:Element` or `arch:ModelConcept` in a hint stands for any element
7
+ * of any language, and is for the types meant to relate concepts across languages: the decision extension names
8
+ * its own Option at one end and `arch:ModelConcept` at the other. A type whose hints name only core classes, or
9
+ * nothing, says nothing about any language's elements, and is offered only between its own metamodel's
10
+ * ({@link namesNoLanguageClass}).
11
+ *
12
+ * A relationship type's metamodel is made of the documents that declare it, the documents a loaded manifest names
13
+ * beside one of them as its concepts (`arch:modelConcepts`: C4's names its ontology and the Structurizr extension),
14
+ * and what those import. The core's documents are no metamodel's. A type that no named graph declares, from a
15
+ * metamodel loaded into the default graph, is of its namespace. An element type is of the metamodel when it, or a
16
+ * class it specializes, is declared in one of those documents: a model's own subclass of a C4 container is C4's.
17
+ */
18
+
19
+ import type { RdfStore } from '../rdf-engine/interfaces.js';
20
+ import { NAMESPACES } from '../rdf-engine/namespaces.js';
21
+ import { nn } from './vocabulary.js';
22
+
23
+ /** Every core document's IRI starts so: the ontology, core-vis, their shapes, the core notation. */
24
+ const CORE_DOCUMENTS = 'https://meta.linked.archi/core';
25
+ const RDF_TYPE = nn(NAMESPACES.rdf + 'type');
26
+ const RDFS_SUBCLASS_OF = nn(NAMESPACES.rdfs + 'subClassOf');
27
+ const OWL_IMPORTS = nn(NAMESPACES.owl + 'imports');
28
+ const OWL_VERSION_IRI = nn(NAMESPACES.owl + 'versionIRI');
29
+ const ARCH_MODEL_CONCEPTS = nn(NAMESPACES.arch + 'modelConcepts');
30
+
31
+ /**
32
+ * Whether a relationship type's hints name no class of a metamodel: only core classes (`arch:Element`,
33
+ * `arch:ModelConcept`), or none at all.
34
+ */
35
+ export function namesNoLanguageClass(domainTypes: readonly string[], rangeTypes: readonly string[]): boolean {
36
+ return [...domainTypes, ...rangeTypes].every((iri) => iri.startsWith(NAMESPACES.arch));
37
+ }
38
+
39
+ /** The namespace of an IRI: up to and including its last `#` or `/`. */
40
+ function namespaceOf(iri: string): string {
41
+ const cut = Math.max(iri.lastIndexOf('#'), iri.lastIndexOf('/'));
42
+ return cut === -1 ? iri : iri.slice(0, cut + 1);
43
+ }
44
+
45
+ /** The loaded metamodels' documents, read for one set of loaded graphs. */
46
+ export class OwnMetamodels {
47
+ /** Each relationship type's metamodel documents; `null` for a type no named graph declares. */
48
+ private readonly documentsByType = new Map<string, ReadonlySet<string> | null>();
49
+ /** The named graphs that declare each class. */
50
+ private readonly graphsByClass = new Map<string, readonly string[]>();
51
+ /** Each loaded manifest's concept documents, as loaded graphs. */
52
+ private conceptDocuments?: ReadonlyMap<string, readonly string[]>;
53
+ private readonly loaded: ReadonlySet<string>;
54
+
55
+ /**
56
+ * @param store The store, every graph of which is read.
57
+ * @param namedGraphs The loaded documents' graphs.
58
+ */
59
+ constructor(
60
+ private readonly store: RdfStore,
61
+ namedGraphs: readonly string[],
62
+ ) {
63
+ this.loaded = new Set(namedGraphs);
64
+ }
65
+
66
+ /**
67
+ * Whether an element type, given its `rdfs:subClassOf*` closure (the type included), is of the metamodel a
68
+ * relationship type belongs to.
69
+ */
70
+ includes(relationshipTypeIri: string, closure: readonly string[]): boolean {
71
+ const documents = this.documentsOf(relationshipTypeIri);
72
+ if (!documents) {
73
+ const namespace = namespaceOf(relationshipTypeIri);
74
+ return closure.some((iri) => namespaceOf(iri) === namespace);
75
+ }
76
+ return closure.some((iri) => this.graphsDeclaring(iri).some((graph) => documents.has(graph)));
77
+ }
78
+
79
+ /** The documents of a relationship type's metamodel; `null` when no named graph declares the type. */
80
+ private documentsOf(relationshipTypeIri: string): ReadonlySet<string> | null {
81
+ const known = this.documentsByType.get(relationshipTypeIri);
82
+ if (known !== undefined) return known;
83
+ const declaring = this.graphsDeclaring(relationshipTypeIri).filter((graph) => !graph.startsWith(CORE_DOCUMENTS));
84
+ let documents: ReadonlySet<string> | null = null;
85
+ if (declaring.length > 0) {
86
+ const seeds = new Set(declaring);
87
+ for (const concepts of this.manifests().values()) {
88
+ if (concepts.some((document) => declaring.includes(document))) for (const document of concepts) seeds.add(document);
89
+ }
90
+ documents = this.withImports(seeds);
91
+ }
92
+ this.documentsByType.set(relationshipTypeIri, documents);
93
+ return documents;
94
+ }
95
+
96
+ /** Documents and what they import, and so on, among the loaded ones; the core's left out. */
97
+ private withImports(seeds: Iterable<string>): Set<string> {
98
+ const documents = new Set<string>();
99
+ const queue = [...seeds];
100
+ while (queue.length > 0) {
101
+ const document = queue.pop() as string;
102
+ if (documents.has(document) || document.startsWith(CORE_DOCUMENTS)) continue;
103
+ documents.add(document);
104
+ for (const q of this.store.getQuads(null, OWL_IMPORTS, null, nn(document))) {
105
+ const imported = this.loadedDocument(q.object.value);
106
+ if (imported) queue.push(imported);
107
+ }
108
+ }
109
+ return documents;
110
+ }
111
+
112
+ /** Each loaded manifest's concept documents (`arch:modelConcepts`), those loaded. */
113
+ private manifests(): ReadonlyMap<string, readonly string[]> {
114
+ if (!this.conceptDocuments) {
115
+ const byManifest = new Map<string, string[]>();
116
+ for (const q of this.store.getQuads(null, ARCH_MODEL_CONCEPTS, null)) {
117
+ const document = this.loadedDocument(q.object.value);
118
+ if (!document) continue;
119
+ const documents = byManifest.get(q.subject.value) ?? [];
120
+ if (!documents.includes(document)) documents.push(document);
121
+ byManifest.set(q.subject.value, documents);
122
+ }
123
+ this.conceptDocuments = byManifest;
124
+ }
125
+ return this.conceptDocuments;
126
+ }
127
+
128
+ /**
129
+ * The loaded graph of a document a manifest or an import names: by its IRI, by its IRI up to the `#` (with one
130
+ * added), or, for a version IRI, the graph of the ontology that declares it.
131
+ */
132
+ private loadedDocument(iri: string): string | undefined {
133
+ if (this.loaded.has(iri)) return iri;
134
+ const hash = iri.indexOf('#');
135
+ const document = hash === -1 ? `${iri}#` : iri.slice(0, hash + 1);
136
+ if (this.loaded.has(document)) return document;
137
+ const declared = this.store.getQuads(null, OWL_VERSION_IRI, nn(iri))[0]?.graph;
138
+ return declared?.termType === 'NamedNode' && this.loaded.has(declared.value) ? declared.value : undefined;
139
+ }
140
+
141
+ /** The named graphs that declare a class: type it or name a superclass of it. */
142
+ private graphsDeclaring(iri: string): readonly string[] {
143
+ let graphs = this.graphsByClass.get(iri);
144
+ if (!graphs) {
145
+ const subject = nn(iri);
146
+ const found = new Set<string>();
147
+ for (const predicate of [RDF_TYPE, RDFS_SUBCLASS_OF]) {
148
+ for (const q of this.store.getQuads(subject, predicate, null)) {
149
+ if (q.graph.termType === 'NamedNode') found.add(q.graph.value);
150
+ }
151
+ }
152
+ graphs = [...found];
153
+ this.graphsByClass.set(iri, graphs);
154
+ }
155
+ return graphs;
156
+ }
157
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Placing a view's nodes and links again, in another view or the same one — what *Duplicate view*
3
+ * (`ViewManager.duplicateView`) and paste (`clipboard.ts`) both do, in one place.
4
+ *
5
+ * Node by node: a figure is a figure; an element placed twice is placed twice (`another: true`), what was
6
+ * inside a node inside its copy; each with its appearance, its appearances per presentation, its label
7
+ * expressions and its drawing order (core-vis 0.10). Then link by link, in passes — a link ending on another link waits for that one's copy: a
8
+ * connector between the copied figures, a relationship between the copied placements of its ends, each with
9
+ * its route, its looks and a name moved off its line. The source and the target may be different stores:
10
+ * paste reads a copy's placements through a view manager over the copy and places them in the open view.
11
+ */
12
+
13
+ import type { Bounds, FigureInfo, Point, ViewManager } from './interfaces.js';
14
+
15
+ /**
16
+ * A figure as the target can place it. A reference opens a view of its own model: pasted into a model without
17
+ * that view it would open nothing, so it is placed as a note with its text (core-vis-shapes 0.5.0).
18
+ */
19
+ function placeable(figure: FigureInfo | undefined, target: ViewManager): FigureInfo | undefined {
20
+ if (figure?.kind !== 'reference' || !figure.view || target.getView(figure.view)) return figure;
21
+ const note: FigureInfo = { ...figure, kind: 'note' };
22
+ delete note.view;
23
+ return note;
24
+ }
25
+
26
+ export interface PlacementCopyOptions {
27
+ /** Only these placements of the source view, by node IRI; every node when absent. */
28
+ nodes?: ReadonlySet<string>;
29
+ /** Only these links, by link IRI; every link when absent. A link is copied only when both its ends are. */
30
+ links?: ReadonlySet<string>;
31
+ /** The concept a copied placement draws in the target: a copy's IRI for its original's. The same by default. */
32
+ concept?: (iri: string) => string;
33
+ /** Every position moved by this much. */
34
+ offset?: Point;
35
+ }
36
+
37
+ /** The placements made, by the source placement they copy. */
38
+ export interface PlacementCopy {
39
+ nodes: Map<string, string>;
40
+ links: Map<string, string>;
41
+ }
42
+
43
+ export function copyPlacements(
44
+ source: ViewManager,
45
+ sourceViewIri: string,
46
+ target: ViewManager,
47
+ targetViewIri: string,
48
+ options: PlacementCopyOptions = {},
49
+ ): PlacementCopy {
50
+ const concept = options.concept ?? ((iri: string) => iri);
51
+ const dx = options.offset?.x ?? 0;
52
+ const dy = options.offset?.y ?? 0;
53
+ const moved = (b: Bounds): Bounds => ({ ...b, x: b.x + dx, y: b.y + dy });
54
+ const route = (points: Point[]): Point[] => points.map((p) => ({ x: p.x + dx, y: p.y + dy }));
55
+
56
+ const nodes = source.getNodes(sourceViewIri).filter((node) => !options.nodes || options.nodes.has(node.nodeIri));
57
+ const copies = new Map<string, string>();
58
+ for (const node of nodes) {
59
+ const figure = placeable(node.figure, target);
60
+ const copied = figure
61
+ ? target.addFigure!(targetViewIri, { ...figure, bounds: moved(node.bounds) })
62
+ : target.addElementToView(targetViewIri, concept(node.elementIri), moved(node.bounds), { another: true });
63
+ copies.set(node.nodeIri, copied);
64
+ // Looking as it did: a figure's appearance is copied with it; its label saying what it said.
65
+ if (node.appearance) target.setAppearance!(targetViewIri, copied, node.appearance);
66
+ for (const [context, look] of Object.entries(node.contextAppearances ?? {})) target.setAppearance!(targetViewIri, copied, look, context);
67
+ for (const label of node.labelExpressions ?? []) target.setLabelExpression!(targetViewIri, copied, label.context, label.expression);
68
+ if (node.zOrder) target.setNodeZOrder?.(targetViewIri, copied, node.zOrder);
69
+ }
70
+ for (const node of nodes) {
71
+ const parent = node.parentNodeIri ? copies.get(node.parentNodeIri) : undefined;
72
+ if (parent) target.setNodeParent!(targetViewIri, copies.get(node.nodeIri)!, parent);
73
+ }
74
+
75
+ const linkCopies = new Map<string, string>();
76
+ let pending = source.getLinks(sourceViewIri).filter((link) => !options.links || options.links.has(link.linkIri));
77
+ for (;;) {
78
+ const waiting = pending.filter((link) => {
79
+ const end = (iri: string) => copies.get(iri) ?? linkCopies.get(iri);
80
+ const sourceNodeIri = end(link.sourceNodeIri);
81
+ const targetNodeIri = end(link.targetNodeIri);
82
+ // A connector joins figures, copied already.
83
+ if (link.connector) {
84
+ const copied =
85
+ sourceNodeIri && targetNodeIri ? target.addConnector!(targetViewIri, { sourceNodeIri, targetNodeIri }, route(link.waypoints)) : undefined;
86
+ if (!copied) return false;
87
+ linkCopies.set(link.linkIri, copied);
88
+ if (link.appearance) target.setAppearance!(targetViewIri, copied, link.appearance);
89
+ for (const [context, look] of Object.entries(link.contextAppearances ?? {})) target.setAppearance!(targetViewIri, copied, look, context);
90
+ if (link.text) target.setConnectorText!(targetViewIri, copied, link.text);
91
+ if (link.label) target.setLinkLabel!(targetViewIri, copied, moved(link.label));
92
+ return false;
93
+ }
94
+ // Copied only between copied ends: a link to a placement not copied is left out (the selection
95
+ // decides; *Duplicate view* copies every node). Its ends may yet be copied in a later pass.
96
+ if (options.nodes && (!sourceNodeIri || !targetNodeIri)) return true;
97
+ const copied = target.addRelationshipToView(
98
+ targetViewIri,
99
+ concept(link.relationshipIri),
100
+ route(link.waypoints),
101
+ { ...(sourceNodeIri ? { sourceNodeIri } : {}), ...(targetNodeIri ? { targetNodeIri } : {}) },
102
+ { another: true },
103
+ );
104
+ if (!copied) return true;
105
+ linkCopies.set(link.linkIri, copied);
106
+ if (link.appearance) target.setAppearance!(targetViewIri, copied, link.appearance);
107
+ for (const [context, look] of Object.entries(link.contextAppearances ?? {})) target.setAppearance!(targetViewIri, copied, look, context);
108
+ // A name moved off the middle of its line stays where it was put.
109
+ if (link.label) target.setLinkLabel!(targetViewIri, copied, moved(link.label));
110
+ return false;
111
+ });
112
+ if (waiting.length === 0 || waiting.length === pending.length) break;
113
+ pending = waiting;
114
+ }
115
+ return { nodes: copies, links: linkCopies };
116
+ }