nucleation 0.10.22 → 0.10.24

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 (303) hide show
  1. package/README.md +12 -0
  2. package/Schematic.d.mts +23 -0
  3. package/Schematic.d.ts +23 -0
  4. package/Schematic.mjs +70 -0
  5. package/nucleation.wasm +0 -0
  6. package/package.json +7 -2
  7. package/renderer/AnimationEffect.d.mts +44 -0
  8. package/renderer/AnimationEffect.d.ts +44 -0
  9. package/renderer/AnimationEffect.mjs +204 -0
  10. package/renderer/Autostack.d.mts +43 -0
  11. package/renderer/Autostack.d.ts +43 -0
  12. package/renderer/Autostack.mjs +134 -0
  13. package/renderer/BlockPos.d.mts +28 -0
  14. package/renderer/BlockPos.d.ts +28 -0
  15. package/renderer/BlockPos.mjs +130 -0
  16. package/renderer/BlockState.d.mts +39 -0
  17. package/renderer/BlockState.d.ts +39 -0
  18. package/renderer/BlockState.mjs +134 -0
  19. package/renderer/Blocks.d.mts +91 -0
  20. package/renderer/Blocks.d.ts +91 -0
  21. package/renderer/Blocks.mjs +308 -0
  22. package/renderer/Brush.d.mts +99 -0
  23. package/renderer/Brush.d.ts +99 -0
  24. package/renderer/Brush.mjs +335 -0
  25. package/renderer/BuildAnimation.d.mts +179 -0
  26. package/renderer/BuildAnimation.d.ts +179 -0
  27. package/renderer/BuildAnimation.mjs +1148 -0
  28. package/renderer/BuildingTool.d.mts +46 -0
  29. package/renderer/BuildingTool.d.ts +46 -0
  30. package/renderer/BuildingTool.mjs +121 -0
  31. package/renderer/CellExecutor.d.mts +51 -0
  32. package/renderer/CellExecutor.d.ts +51 -0
  33. package/renderer/CellExecutor.mjs +171 -0
  34. package/renderer/CellularSdfConfig.d.mts +22 -0
  35. package/renderer/CellularSdfConfig.d.ts +22 -0
  36. package/renderer/CellularSdfConfig.mjs +69 -0
  37. package/renderer/ChunkMeshResult.d.mts +75 -0
  38. package/renderer/ChunkMeshResult.d.ts +75 -0
  39. package/renderer/ChunkMeshResult.mjs +253 -0
  40. package/renderer/CircuitBuilder.d.mts +118 -0
  41. package/renderer/CircuitBuilder.d.ts +118 -0
  42. package/renderer/CircuitBuilder.mjs +516 -0
  43. package/renderer/Curve3D.d.mts +27 -0
  44. package/renderer/Curve3D.d.ts +27 -0
  45. package/renderer/Curve3D.mjs +101 -0
  46. package/renderer/DefinitionRegion.d.mts +274 -0
  47. package/renderer/DefinitionRegion.d.ts +274 -0
  48. package/renderer/DefinitionRegion.mjs +973 -0
  49. package/renderer/Design.d.mts +348 -0
  50. package/renderer/Design.d.ts +348 -0
  51. package/renderer/Design.mjs +1334 -0
  52. package/renderer/Diff.d.mts +88 -0
  53. package/renderer/Diff.d.ts +88 -0
  54. package/renderer/Diff.mjs +316 -0
  55. package/renderer/Dimensions.d.mts +28 -0
  56. package/renderer/Dimensions.d.ts +28 -0
  57. package/renderer/Dimensions.mjs +130 -0
  58. package/renderer/DistanceField.d.mts +39 -0
  59. package/renderer/DistanceField.d.ts +39 -0
  60. package/renderer/DistanceField.mjs +114 -0
  61. package/renderer/ExecutionMode.d.mts +42 -0
  62. package/renderer/ExecutionMode.d.ts +42 -0
  63. package/renderer/ExecutionMode.mjs +127 -0
  64. package/renderer/Field3.d.mts +40 -0
  65. package/renderer/Field3.d.ts +40 -0
  66. package/renderer/Field3.mjs +160 -0
  67. package/renderer/FieldProgram.d.mts +40 -0
  68. package/renderer/FieldProgram.d.ts +40 -0
  69. package/renderer/FieldProgram.mjs +167 -0
  70. package/renderer/FieldProgramBinaryOp.d.mts +42 -0
  71. package/renderer/FieldProgramBinaryOp.d.ts +42 -0
  72. package/renderer/FieldProgramBinaryOp.mjs +118 -0
  73. package/renderer/FieldProgramBuilder.d.mts +104 -0
  74. package/renderer/FieldProgramBuilder.d.ts +104 -0
  75. package/renderer/FieldProgramBuilder.mjs +486 -0
  76. package/renderer/FieldProgramDistanceKind.d.mts +26 -0
  77. package/renderer/FieldProgramDistanceKind.d.ts +26 -0
  78. package/renderer/FieldProgramDistanceKind.mjs +78 -0
  79. package/renderer/FieldProgramUnaryOp.d.mts +34 -0
  80. package/renderer/FieldProgramUnaryOp.d.ts +34 -0
  81. package/renderer/FieldProgramUnaryOp.mjs +102 -0
  82. package/renderer/FieldProgramValueType.d.mts +25 -0
  83. package/renderer/FieldProgramValueType.d.ts +25 -0
  84. package/renderer/FieldProgramValueType.mjs +75 -0
  85. package/renderer/FieldRange.d.mts +15 -0
  86. package/renderer/FieldRange.d.ts +15 -0
  87. package/renderer/FieldRange.mjs +109 -0
  88. package/renderer/Fingerprint.d.mts +44 -0
  89. package/renderer/Fingerprint.d.ts +44 -0
  90. package/renderer/Fingerprint.mjs +197 -0
  91. package/renderer/GeneratedChunk.d.mts +35 -0
  92. package/renderer/GeneratedChunk.d.ts +35 -0
  93. package/renderer/GeneratedChunk.mjs +178 -0
  94. package/renderer/GeneratedChunkCoverage.d.mts +25 -0
  95. package/renderer/GeneratedChunkCoverage.d.ts +25 -0
  96. package/renderer/GeneratedChunkCoverage.mjs +75 -0
  97. package/renderer/GeneratedChunkOverlayMode.d.mts +24 -0
  98. package/renderer/GeneratedChunkOverlayMode.d.ts +24 -0
  99. package/renderer/GeneratedChunkOverlayMode.mjs +72 -0
  100. package/renderer/GeneratedWorldStream.d.mts +28 -0
  101. package/renderer/GeneratedWorldStream.d.ts +28 -0
  102. package/renderer/GeneratedWorldStream.mjs +86 -0
  103. package/renderer/Geo.d.mts +41 -0
  104. package/renderer/Geo.d.ts +41 -0
  105. package/renderer/Geo.mjs +121 -0
  106. package/renderer/Hdl.d.mts +56 -0
  107. package/renderer/Hdl.d.ts +56 -0
  108. package/renderer/Hdl.mjs +163 -0
  109. package/renderer/InterpolationSpace.d.mts +25 -0
  110. package/renderer/InterpolationSpace.d.ts +25 -0
  111. package/renderer/InterpolationSpace.mjs +73 -0
  112. package/renderer/IoLayout.d.mts +26 -0
  113. package/renderer/IoLayout.d.ts +26 -0
  114. package/renderer/IoLayout.mjs +81 -0
  115. package/renderer/IoLayoutBuilder.d.mts +73 -0
  116. package/renderer/IoLayoutBuilder.d.ts +73 -0
  117. package/renderer/IoLayoutBuilder.mjs +315 -0
  118. package/renderer/IoType.d.mts +41 -0
  119. package/renderer/IoType.d.ts +41 -0
  120. package/renderer/IoType.mjs +125 -0
  121. package/renderer/ItemModelConfig.d.mts +65 -0
  122. package/renderer/ItemModelConfig.d.ts +65 -0
  123. package/renderer/ItemModelConfig.mjs +223 -0
  124. package/renderer/ItemModelPackBuilder.d.mts +32 -0
  125. package/renderer/ItemModelPackBuilder.d.ts +32 -0
  126. package/renderer/ItemModelPackBuilder.mjs +104 -0
  127. package/renderer/ItemModelResult.d.mts +72 -0
  128. package/renderer/ItemModelResult.d.ts +72 -0
  129. package/renderer/ItemModelResult.mjs +268 -0
  130. package/renderer/ItemScale.d.mts +31 -0
  131. package/renderer/ItemScale.d.ts +31 -0
  132. package/renderer/ItemScale.mjs +133 -0
  133. package/renderer/LayoutFunction.d.mts +52 -0
  134. package/renderer/LayoutFunction.d.ts +52 -0
  135. package/renderer/LayoutFunction.mjs +159 -0
  136. package/renderer/MchprsWorld.d.mts +131 -0
  137. package/renderer/MchprsWorld.d.ts +131 -0
  138. package/renderer/MchprsWorld.mjs +423 -0
  139. package/renderer/MeshBounds.d.mts +40 -0
  140. package/renderer/MeshBounds.d.ts +40 -0
  141. package/renderer/MeshBounds.mjs +181 -0
  142. package/renderer/MeshConfig.d.mts +101 -0
  143. package/renderer/MeshConfig.d.ts +101 -0
  144. package/renderer/MeshConfig.mjs +306 -0
  145. package/renderer/MeshJob.d.mts +44 -0
  146. package/renderer/MeshJob.d.ts +44 -0
  147. package/renderer/MeshJob.mjs +116 -0
  148. package/renderer/MeshPhase.d.mts +38 -0
  149. package/renderer/MeshPhase.d.ts +38 -0
  150. package/renderer/MeshPhase.mjs +90 -0
  151. package/renderer/MeshProgress.d.mts +32 -0
  152. package/renderer/MeshProgress.d.ts +32 -0
  153. package/renderer/MeshProgress.mjs +134 -0
  154. package/renderer/MeshResult.d.mts +76 -0
  155. package/renderer/MeshResult.d.ts +76 -0
  156. package/renderer/MeshResult.mjs +269 -0
  157. package/renderer/MultiMeshResult.d.mts +50 -0
  158. package/renderer/MultiMeshResult.d.ts +50 -0
  159. package/renderer/MultiMeshResult.mjs +166 -0
  160. package/renderer/Nbt.d.mts +50 -0
  161. package/renderer/Nbt.d.ts +50 -0
  162. package/renderer/Nbt.mjs +161 -0
  163. package/renderer/NucleationError.d.mts +53 -0
  164. package/renderer/NucleationError.d.ts +53 -0
  165. package/renderer/NucleationError.mjs +136 -0
  166. package/renderer/OutputCondition.d.mts +45 -0
  167. package/renderer/OutputCondition.d.ts +45 -0
  168. package/renderer/OutputCondition.mjs +129 -0
  169. package/renderer/Palette.d.mts +157 -0
  170. package/renderer/Palette.d.ts +157 -0
  171. package/renderer/Palette.mjs +487 -0
  172. package/renderer/PaletteBuilder.d.mts +119 -0
  173. package/renderer/PaletteBuilder.d.ts +119 -0
  174. package/renderer/PaletteBuilder.mjs +457 -0
  175. package/renderer/README.md +67 -0
  176. package/renderer/RawMeshExport.d.mts +74 -0
  177. package/renderer/RawMeshExport.d.ts +74 -0
  178. package/renderer/RawMeshExport.mjs +243 -0
  179. package/renderer/RedstoneGraph.d.mts +58 -0
  180. package/renderer/RedstoneGraph.d.ts +58 -0
  181. package/renderer/RedstoneGraph.mjs +242 -0
  182. package/renderer/RegionBounds.d.mts +41 -0
  183. package/renderer/RegionBounds.d.ts +41 -0
  184. package/renderer/RegionBounds.mjs +182 -0
  185. package/renderer/RenderConfig.d.mts +101 -0
  186. package/renderer/RenderConfig.d.ts +101 -0
  187. package/renderer/RenderConfig.mjs +271 -0
  188. package/renderer/Renderer.d.mts +51 -0
  189. package/renderer/Renderer.d.ts +51 -0
  190. package/renderer/Renderer.mjs +219 -0
  191. package/renderer/ResourcePack.d.mts +105 -0
  192. package/renderer/ResourcePack.d.ts +105 -0
  193. package/renderer/ResourcePack.mjs +447 -0
  194. package/renderer/ResourcePackList.d.mts +32 -0
  195. package/renderer/ResourcePackList.d.ts +32 -0
  196. package/renderer/ResourcePackList.mjs +96 -0
  197. package/renderer/Routing.d.mts +66 -0
  198. package/renderer/Routing.d.ts +66 -0
  199. package/renderer/Routing.mjs +220 -0
  200. package/renderer/Schematic.d.mts +977 -0
  201. package/renderer/Schematic.d.ts +977 -0
  202. package/renderer/Schematic.mjs +3820 -0
  203. package/renderer/SchematicBuilder.d.mts +103 -0
  204. package/renderer/SchematicBuilder.d.ts +103 -0
  205. package/renderer/SchematicBuilder.mjs +401 -0
  206. package/renderer/SchematicRegions.d.mts +93 -0
  207. package/renderer/SchematicRegions.d.ts +93 -0
  208. package/renderer/SchematicRegions.mjs +411 -0
  209. package/renderer/SchematicSplitResult.d.mts +26 -0
  210. package/renderer/SchematicSplitResult.d.ts +26 -0
  211. package/renderer/SchematicSplitResult.mjs +84 -0
  212. package/renderer/Scripting.d.mts +40 -0
  213. package/renderer/Scripting.d.ts +40 -0
  214. package/renderer/Scripting.mjs +138 -0
  215. package/renderer/Sdf.d.mts +234 -0
  216. package/renderer/Sdf.d.ts +234 -0
  217. package/renderer/Sdf.mjs +1234 -0
  218. package/renderer/SdfAxis.d.mts +25 -0
  219. package/renderer/SdfAxis.d.ts +25 -0
  220. package/renderer/SdfAxis.mjs +75 -0
  221. package/renderer/SdfBounds.d.mts +19 -0
  222. package/renderer/SdfBounds.d.ts +19 -0
  223. package/renderer/SdfBounds.mjs +161 -0
  224. package/renderer/SdfCellMode.d.mts +26 -0
  225. package/renderer/SdfCellMode.d.ts +26 -0
  226. package/renderer/SdfCellMode.mjs +78 -0
  227. package/renderer/SdfNormal.d.mts +16 -0
  228. package/renderer/SdfNormal.d.ts +16 -0
  229. package/renderer/SdfNormal.mjs +122 -0
  230. package/renderer/Shape.d.mts +143 -0
  231. package/renderer/Shape.d.ts +143 -0
  232. package/renderer/Shape.mjs +458 -0
  233. package/renderer/SortStrategy.d.mts +86 -0
  234. package/renderer/SortStrategy.d.ts +86 -0
  235. package/renderer/SortStrategy.mjs +272 -0
  236. package/renderer/Store.d.mts +83 -0
  237. package/renderer/Store.d.ts +83 -0
  238. package/renderer/Store.mjs +369 -0
  239. package/renderer/StoreIo.d.mts +71 -0
  240. package/renderer/StoreIo.d.ts +71 -0
  241. package/renderer/StoreIo.mjs +292 -0
  242. package/renderer/TextureAtlas.d.mts +40 -0
  243. package/renderer/TextureAtlas.d.ts +40 -0
  244. package/renderer/TextureAtlas.mjs +122 -0
  245. package/renderer/TextureInfo.d.mts +34 -0
  246. package/renderer/TextureInfo.d.ts +34 -0
  247. package/renderer/TextureInfo.mjs +149 -0
  248. package/renderer/TickSettleMode.d.mts +34 -0
  249. package/renderer/TickSettleMode.d.ts +34 -0
  250. package/renderer/TickSettleMode.mjs +84 -0
  251. package/renderer/TickSimulation.d.mts +572 -0
  252. package/renderer/TickSimulation.d.ts +572 -0
  253. package/renderer/TickSimulation.mjs +1299 -0
  254. package/renderer/TypedCircuitExecutor.d.mts +101 -0
  255. package/renderer/TypedCircuitExecutor.d.ts +101 -0
  256. package/renderer/TypedCircuitExecutor.mjs +378 -0
  257. package/renderer/Value.d.mts +73 -0
  258. package/renderer/Value.d.ts +73 -0
  259. package/renderer/Value.mjs +275 -0
  260. package/renderer/VideoConfig.d.mts +15 -0
  261. package/renderer/VideoConfig.d.ts +15 -0
  262. package/renderer/VideoConfig.mjs +44 -0
  263. package/renderer/VoxelModel.d.mts +34 -0
  264. package/renderer/VoxelModel.d.ts +34 -0
  265. package/renderer/VoxelModel.mjs +113 -0
  266. package/renderer/Voxelizer.d.mts +80 -0
  267. package/renderer/Voxelizer.d.ts +80 -0
  268. package/renderer/Voxelizer.mjs +261 -0
  269. package/renderer/WorldChunkView.d.mts +75 -0
  270. package/renderer/WorldChunkView.d.ts +75 -0
  271. package/renderer/WorldChunkView.mjs +224 -0
  272. package/renderer/WorldGenerator.d.mts +75 -0
  273. package/renderer/WorldGenerator.d.ts +75 -0
  274. package/renderer/WorldGenerator.mjs +255 -0
  275. package/renderer/WorldSink.d.mts +50 -0
  276. package/renderer/WorldSink.d.ts +50 -0
  277. package/renderer/WorldSink.mjs +177 -0
  278. package/renderer/WorldStream.d.mts +45 -0
  279. package/renderer/WorldStream.d.ts +45 -0
  280. package/renderer/WorldStream.mjs +184 -0
  281. package/renderer/WsPartitionHints.d.mts +29 -0
  282. package/renderer/WsPartitionHints.d.ts +29 -0
  283. package/renderer/WsPartitionHints.mjs +102 -0
  284. package/renderer/WsProfile.d.mts +46 -0
  285. package/renderer/WsProfile.d.ts +46 -0
  286. package/renderer/WsProfile.mjs +152 -0
  287. package/renderer/WsRunResult.d.mts +83 -0
  288. package/renderer/WsRunResult.d.ts +83 -0
  289. package/renderer/WsRunResult.mjs +326 -0
  290. package/renderer/WsSegmentJob.d.mts +28 -0
  291. package/renderer/WsSegmentJob.d.ts +28 -0
  292. package/renderer/WsSegmentJob.mjs +81 -0
  293. package/renderer/diplomat-runtime.d.mts +15 -0
  294. package/renderer/diplomat-runtime.d.ts +15 -0
  295. package/renderer/diplomat-runtime.mjs +779 -0
  296. package/renderer/diplomat-wasm.mjs +52 -0
  297. package/renderer/diplomat.config.mjs +5 -0
  298. package/renderer/index.d.mts +193 -0
  299. package/renderer/index.d.ts +193 -0
  300. package/renderer/index.mjs +196 -0
  301. package/renderer/nucleation.wasm +0 -0
  302. package/renderer/veneer/design.d.ts +167 -0
  303. package/renderer/veneer/design.mjs +480 -0
@@ -0,0 +1,1334 @@
1
+ // generated by diplomat-tool
2
+ import { NucleationError } from "./NucleationError.mjs"
3
+ import { Schematic } from "./Schematic.mjs"
4
+ import wasm from "./diplomat-wasm.mjs";
5
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
+
7
+ const Design_box_destroy_registry = new FinalizationRegistry((ptr) => {
8
+ wasm.Design_destroy(ptr);
9
+ });
10
+
11
+ /**
12
+ * A composition document: loose blocks + cell instances + bus layers
13
+ * over a shared coordinate space.
14
+ */
15
+ export class Design {
16
+ // Internal ptr reference:
17
+ #ptr = null;
18
+
19
+ // Lifetimes are only to keep dependencies alive.
20
+ // Since JS won't garbage collect until there are no incoming edges.
21
+ #selfEdge = [];
22
+
23
+ #internalConstructor(symbol, ptr, selfEdge) {
24
+ if (symbol !== diplomatRuntime.internalConstructor) {
25
+ console.error("Design is an Opaque type. You cannot call its constructor.");
26
+ return;
27
+ }
28
+ this.#ptr = ptr;
29
+ this.#selfEdge = selfEdge;
30
+
31
+ // Are we being borrowed? If not, we can register.
32
+ if (this.#selfEdge.length === 0) {
33
+ Design_box_destroy_registry.register(this, this.#ptr);
34
+ }
35
+
36
+ return this;
37
+ }
38
+ /** @internal */
39
+ get ffiValue() {
40
+ return this.#ptr;
41
+ }
42
+
43
+
44
+ /**
45
+ * An empty design.
46
+ */
47
+ static create(name) {
48
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
49
+
50
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
51
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
52
+
53
+
54
+ const result = wasm.Design_create(diplomatReceive.buffer, nameSlice.ptr);
55
+
56
+ try {
57
+ if (!diplomatReceive.resultFlag) {
58
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
59
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
60
+ }
61
+ return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
62
+ }
63
+
64
+ finally {
65
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
66
+ functionCleanupArena.free();
67
+
68
+ diplomatReceive.free();
69
+ }
70
+ }
71
+
72
+ /**
73
+ * A design whose loose block layer is a copy of `base` (endpoint
74
+ * hardware placed with raw `set_block`).
75
+ */
76
+ static forSchematic(name, base) {
77
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
78
+
79
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
80
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
81
+
82
+
83
+ const result = wasm.Design_for_schematic(diplomatReceive.buffer, nameSlice.ptr, base.ffiValue);
84
+
85
+ try {
86
+ if (!diplomatReceive.resultFlag) {
87
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
88
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
89
+ }
90
+ return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
91
+ }
92
+
93
+ finally {
94
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
95
+ functionCleanupArena.free();
96
+
97
+ diplomatReceive.free();
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Register a library cell; its contract is resolved from the
103
+ * schematic (embedded metadata first, Insign signs as fallback)
104
+ * and registration fails loudly when no source defines one.
105
+ * Writes resolution warnings as a JSON array of strings.
106
+ */
107
+ addCell(name, cell) {
108
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
109
+
110
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
111
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
112
+
113
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
114
+
115
+
116
+ const result = wasm.Design_add_cell(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, cell.ffiValue, write.buffer);
117
+
118
+ try {
119
+ if (!diplomatReceive.resultFlag) {
120
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
121
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
122
+ }
123
+ return write.readString8();
124
+ }
125
+
126
+ finally {
127
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
128
+ functionCleanupArena.free();
129
+
130
+ diplomatReceive.free();
131
+ write.free();
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Place an instance layer referencing a library cell. `rot_y` is
137
+ * in degrees, a multiple of 90.
138
+ */
139
+ place(name, cell, x, y, z, rotY) {
140
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
141
+
142
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
143
+ const cellSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, cell)));
144
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
145
+
146
+
147
+ const result = wasm.Design_place(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, cellSlice.ptr, x, y, z, rotY);
148
+
149
+ try {
150
+ if (!diplomatReceive.resultFlag) {
151
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
152
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
153
+ }
154
+ }
155
+
156
+ finally {
157
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
158
+ functionCleanupArena.free();
159
+
160
+ diplomatReceive.free();
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Declare a drivable input port: anchor = bit-0 connection cell,
166
+ * step to the next bit, `width` bits of `ty` (`"uint"` or
167
+ * `"bool"`). The hardware is scanned (adjacent lever per bit) and
168
+ * validated loudly.
169
+ */
170
+ declareInput(name, ax, ay, az, sx, sy, sz, width, ty) {
171
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
172
+
173
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
174
+ const tySlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, ty)));
175
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
176
+
177
+
178
+ const result = wasm.Design_declare_input(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, ax, ay, az, sx, sy, sz, width, tySlice.ptr);
179
+
180
+ try {
181
+ if (!diplomatReceive.resultFlag) {
182
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
183
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
184
+ }
185
+ }
186
+
187
+ finally {
188
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
189
+ functionCleanupArena.free();
190
+
191
+ diplomatReceive.free();
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Declare a readable output port (adjacent lamp per bit); same
197
+ * shape as `declare_input`.
198
+ */
199
+ declareOutput(name, ax, ay, az, sx, sy, sz, width, ty) {
200
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
201
+
202
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
203
+ const tySlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, ty)));
204
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
205
+
206
+
207
+ const result = wasm.Design_declare_output(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, ax, ay, az, sx, sy, sz, width, tySlice.ptr);
208
+
209
+ try {
210
+ if (!diplomatReceive.resultFlag) {
211
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
212
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
213
+ }
214
+ }
215
+
216
+ finally {
217
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
218
+ functionCleanupArena.free();
219
+
220
+ diplomatReceive.free();
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Declare AND realize a bus. `sinks_json` is a JSON array of port
226
+ * names; `gates_json` an array of `{"name", "anchor": [x,y,z],
227
+ * "step": [x,y,z]}` (pass `[]` for none); `style_json` an object
228
+ * with optional `bus_block` / `transparent_block`. Declaration
229
+ * errors are error returns; geometric unroutability is the
230
+ * written STATE: `"routed"` or `"failed: reason"` — realization
231
+ * is atomic, never half-routed.
232
+ */
233
+ routeBus(name, driver, sinksJson, gatesJson, styleJson) {
234
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
235
+
236
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
237
+ const driverSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, driver)));
238
+ const sinksJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sinksJson)));
239
+ const gatesJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gatesJson)));
240
+ const styleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, styleJson)));
241
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
242
+
243
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
244
+
245
+
246
+ const result = wasm.Design_route_bus(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, driverSlice.ptr, sinksJsonSlice.ptr, gatesJsonSlice.ptr, styleJsonSlice.ptr, write.buffer);
247
+
248
+ try {
249
+ if (!diplomatReceive.resultFlag) {
250
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
251
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
252
+ }
253
+ return write.readString8();
254
+ }
255
+
256
+ finally {
257
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
258
+ functionCleanupArena.free();
259
+
260
+ diplomatReceive.free();
261
+ write.free();
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Declare AND realize a wired-OR bus: `drivers_json` is a JSON
267
+ * array of port names — multiple drivers are legal ONLY through
268
+ * this explicit merge (`merge="or"`). Extra drivers join the
269
+ * trunk as diode-isolated dust-merge branches; the LVS intent
270
+ * stays ONE net per bit. Same shapes as `route_bus` otherwise.
271
+ */
272
+ routeBusOr(name, driversJson, sinksJson, gatesJson, styleJson) {
273
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
274
+
275
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
276
+ const driversJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, driversJson)));
277
+ const sinksJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sinksJson)));
278
+ const gatesJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gatesJson)));
279
+ const styleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, styleJson)));
280
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
281
+
282
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
283
+
284
+
285
+ const result = wasm.Design_route_bus_or(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, driversJsonSlice.ptr, sinksJsonSlice.ptr, gatesJsonSlice.ptr, styleJsonSlice.ptr, write.buffer);
286
+
287
+ try {
288
+ if (!diplomatReceive.resultFlag) {
289
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
290
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
291
+ }
292
+ return write.readString8();
293
+ }
294
+
295
+ finally {
296
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
297
+ functionCleanupArena.free();
298
+
299
+ diplomatReceive.free();
300
+ write.free();
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Edit the loose block layer: plain `set_block` on the base
306
+ * schematic (participates in occupancy and flatten).
307
+ */
308
+ setBlock(x, y, z, block) {
309
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
310
+
311
+ const blockSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, block)));
312
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
313
+
314
+
315
+ const result = wasm.Design_set_block(diplomatReceive.buffer, this.ffiValue, x, y, z, blockSlice.ptr);
316
+
317
+ try {
318
+ if (!diplomatReceive.resultFlag) {
319
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
320
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
321
+ }
322
+ }
323
+
324
+ finally {
325
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
326
+ functionCleanupArena.free();
327
+
328
+ diplomatReceive.free();
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Drag an instance layer to a new position/rotation. The move
334
+ * itself ALWAYS succeeds (the document's truth); the affected bus
335
+ * set — fragments intersecting the old or new footprint +
336
+ * influence halo, plus every already-failed bus — is ripped and
337
+ * co-rerouted deterministically with bounded retry rounds.
338
+ * Writes `{"rerouted": [...], "failed": {name: reason}}`.
339
+ */
340
+ moveInstance(name, x, y, z, rotY) {
341
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
342
+
343
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
344
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
345
+
346
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
347
+
348
+
349
+ const result = wasm.Design_move_instance(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, x, y, z, rotY, write.buffer);
350
+
351
+ try {
352
+ if (!diplomatReceive.resultFlag) {
353
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
354
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
355
+ }
356
+ return write.readString8();
357
+ }
358
+
359
+ finally {
360
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
361
+ functionCleanupArena.free();
362
+
363
+ diplomatReceive.free();
364
+ write.free();
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Remove an instance layer. Buses that terminate on one of its
370
+ * ports are DELETED (they lost an endpoint); buses that merely
371
+ * crossed its space are ripped and co-rerouted. Writes
372
+ * `{"removed_buses": [...], "rerouted": [...], "failed": {...}}`.
373
+ */
374
+ removeInstance(name) {
375
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
376
+
377
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
378
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
379
+
380
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
381
+
382
+
383
+ const result = wasm.Design_remove_instance(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
384
+
385
+ try {
386
+ if (!diplomatReceive.resultFlag) {
387
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
388
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
389
+ }
390
+ return write.readString8();
391
+ }
392
+
393
+ finally {
394
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
395
+ functionCleanupArena.free();
396
+
397
+ diplomatReceive.free();
398
+ write.free();
399
+ }
400
+ }
401
+
402
+ /**
403
+ * Re-realize a bus from its stored declaration (the counterpart to
404
+ * `rip`); writes the resulting bus state.
405
+ */
406
+ reroute(name) {
407
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
408
+
409
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
410
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
411
+
412
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
413
+
414
+
415
+ const result = wasm.Design_reroute(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
416
+
417
+ try {
418
+ if (!diplomatReceive.resultFlag) {
419
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
420
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
421
+ }
422
+ return write.readString8();
423
+ }
424
+
425
+ finally {
426
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
427
+ functionCleanupArena.free();
428
+
429
+ diplomatReceive.free();
430
+ write.free();
431
+ }
432
+ }
433
+
434
+ /**
435
+ * Delete a bus outright — fragment AND declaration, freeing the
436
+ * name. `rip` keeps the declaration so the bus can be rerouted.
437
+ */
438
+ removeBus(name) {
439
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
440
+
441
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
442
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
443
+
444
+
445
+ const result = wasm.Design_remove_bus(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr);
446
+
447
+ try {
448
+ if (!diplomatReceive.resultFlag) {
449
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
450
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
451
+ }
452
+ }
453
+
454
+ finally {
455
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
456
+ functionCleanupArena.free();
457
+
458
+ diplomatReceive.free();
459
+ }
460
+ }
461
+
462
+ /**
463
+ * The flattened artifact as `.schem` bytes, base64. Unlike
464
+ * `flatten()` + the schematic writer, this composites the layer
465
+ * stack into ONE region first: `.schem` has no layers, and the
466
+ * region merge drops named-layer cells that the loose layer's
467
+ * bounding box shadows.
468
+ */
469
+ toSchemB64() {
470
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
471
+
472
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
473
+
474
+
475
+ const result = wasm.Design_to_schem_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
476
+
477
+ try {
478
+ if (!diplomatReceive.resultFlag) {
479
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
480
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
481
+ }
482
+ return write.readString8();
483
+ }
484
+
485
+ finally {
486
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
487
+ diplomatReceive.free();
488
+ write.free();
489
+ }
490
+ }
491
+
492
+ /**
493
+ * The flattened artifact composited into ONE region (see
494
+ * `to_schem_b64`) — the shape an interchange export wants.
495
+ */
496
+ flattenComposite() {
497
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
498
+
499
+
500
+ const result = wasm.Design_flatten_composite(diplomatReceive.buffer, this.ffiValue);
501
+
502
+ try {
503
+ if (!diplomatReceive.resultFlag) {
504
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
505
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
506
+ }
507
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
508
+ }
509
+
510
+ finally {
511
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
512
+ diplomatReceive.free();
513
+ }
514
+ }
515
+
516
+ /**
517
+ * Every routing endpoint the placed instances expose, as a JSON
518
+ * array of `{name, instance, port, role, ty, width, hardware,
519
+ * wires, step, routable, blocked}`. `name` is `{instance}.{port}`
520
+ * — exactly what `route_bus` accepts; `role` is the CELL-facing
521
+ * direction, so `"output"` drives a bus and `"input"` receives
522
+ * one. A port whose bits have no dust connection cell (a lever
523
+ * input, say) reports `routable: false` and why in `blocked`.
524
+ */
525
+ instancePorts() {
526
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
527
+
528
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
529
+
530
+
531
+ const result = wasm.Design_instance_ports(diplomatReceive.buffer, this.ffiValue, write.buffer);
532
+
533
+ try {
534
+ if (!diplomatReceive.resultFlag) {
535
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
536
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
537
+ }
538
+ return write.readString8();
539
+ }
540
+
541
+ finally {
542
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
543
+ diplomatReceive.free();
544
+ write.free();
545
+ }
546
+ }
547
+
548
+ /**
549
+ * Switch a port between executor hardware and a routable dust input.
550
+ *
551
+ * `mode` is `"bus"` or `"executor"`. Community cells name LEVERS for
552
+ * their inputs and nothing in redstone drives a lever, so a port must
553
+ * be in `"bus"` mode before a bus can land on it. The switch is a
554
+ * reversible per-instance patch — `"executor"` restores the shipped
555
+ * blocks byte-exactly.
556
+ *
557
+ * Returns the report as JSON: `{port, mode, note, changed:[{at,from,
558
+ * to}], removed_buses, moves, patch}` — `note` is a ready-made toast
559
+ * and `changed` is in WORLD coordinates.
560
+ */
561
+ setPortMode(instance, port, mode) {
562
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
563
+
564
+ const instanceSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, instance)));
565
+ const portSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, port)));
566
+ const modeSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, mode)));
567
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
568
+
569
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
570
+
571
+
572
+ const result = wasm.Design_set_port_mode(diplomatReceive.buffer, this.ffiValue, instanceSlice.ptr, portSlice.ptr, modeSlice.ptr, write.buffer);
573
+
574
+ try {
575
+ if (!diplomatReceive.resultFlag) {
576
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
577
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
578
+ }
579
+ return write.readString8();
580
+ }
581
+
582
+ finally {
583
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
584
+ functionCleanupArena.free();
585
+
586
+ diplomatReceive.free();
587
+ write.free();
588
+ }
589
+ }
590
+
591
+ /**
592
+ * Every port whose mode has been switched, as JSON:
593
+ * `[{"name":"u0.bin","mode":"bus","patch":{..}}]`. Ports absent from
594
+ * the array are in `"executor"` mode.
595
+ */
596
+ portModes() {
597
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
598
+
599
+ wasm.Design_port_modes(this.ffiValue, write.buffer);
600
+
601
+ try {
602
+ return write.readString8();
603
+ }
604
+
605
+ finally {
606
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
607
+ write.free();
608
+ }
609
+ }
610
+
611
+ /**
612
+ * Describe (without applying) what switching a port to `"bus"` mode
613
+ * would do: `{"wires","hardware","step","removed","added","pivoted",
614
+ * "note"}`. Errors when the port cannot be promoted, with the reason.
615
+ */
616
+ planPortPromotion(instance, port) {
617
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
618
+
619
+ const instanceSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, instance)));
620
+ const portSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, port)));
621
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
622
+
623
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
624
+
625
+
626
+ const result = wasm.Design_plan_port_promotion(diplomatReceive.buffer, this.ffiValue, instanceSlice.ptr, portSlice.ptr, write.buffer);
627
+
628
+ try {
629
+ if (!diplomatReceive.resultFlag) {
630
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
631
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
632
+ }
633
+ return write.readString8();
634
+ }
635
+
636
+ finally {
637
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
638
+ functionCleanupArena.free();
639
+
640
+ diplomatReceive.free();
641
+ write.free();
642
+ }
643
+ }
644
+
645
+ /**
646
+ * Resolve one routing endpoint name — a declared design port or an
647
+ * instance port `{instance}.{port}` — to the geometry a bus would
648
+ * use: `{"name","anchor","step","width","direction","connectable"}`.
649
+ * `direction` is DESIGN-facing (`"input"` drives buses).
650
+ */
651
+ resolvePort(name) {
652
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
653
+
654
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
655
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
656
+
657
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
658
+
659
+
660
+ const result = wasm.Design_resolve_port(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
661
+
662
+ try {
663
+ if (!diplomatReceive.resultFlag) {
664
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
665
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
666
+ }
667
+ return write.readString8();
668
+ }
669
+
670
+ finally {
671
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
672
+ functionCleanupArena.free();
673
+
674
+ diplomatReceive.free();
675
+ write.free();
676
+ }
677
+ }
678
+
679
+ /**
680
+ * Add a gate to an existing bus (splitting the segment it lands
681
+ * in) and re-realize it. Writes the resulting bus state.
682
+ */
683
+ addGate(bus, gate, x, y, z, sx, sy, sz) {
684
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
685
+
686
+ const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
687
+ const gateSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gate)));
688
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
689
+
690
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
691
+
692
+
693
+ const result = wasm.Design_add_gate(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, gateSlice.ptr, x, y, z, sx, sy, sz, write.buffer);
694
+
695
+ try {
696
+ if (!diplomatReceive.resultFlag) {
697
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
698
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
699
+ }
700
+ return write.readString8();
701
+ }
702
+
703
+ finally {
704
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
705
+ functionCleanupArena.free();
706
+
707
+ diplomatReceive.free();
708
+ write.free();
709
+ }
710
+ }
711
+
712
+ /**
713
+ * Drag a gate: the anchor moves unconditionally, then EXACTLY the
714
+ * two adjacent segments are ripped and rerouted atomically. An
715
+ * unroutable move leaves the bus `failed: reason` — visible,
716
+ * never half-routed. Writes `{"state": "...",
717
+ * "rerouted_segments": n, "changed": [layer, ...]}`, where `changed`
718
+ * is the COMPLETE redraw set (see `changed_layers_since`).
719
+ */
720
+ moveGate(bus, gate, x, y, z) {
721
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
722
+
723
+ const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
724
+ const gateSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gate)));
725
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
726
+
727
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
728
+
729
+
730
+ const result = wasm.Design_move_gate(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, gateSlice.ptr, x, y, z, write.buffer);
731
+
732
+ try {
733
+ if (!diplomatReceive.resultFlag) {
734
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
735
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
736
+ }
737
+ return write.readString8();
738
+ }
739
+
740
+ finally {
741
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
742
+ functionCleanupArena.free();
743
+
744
+ diplomatReceive.free();
745
+ write.free();
746
+ }
747
+ }
748
+
749
+ /**
750
+ * Remove a gate by index and re-realize the bus, so the two spans it
751
+ * separated MERGE and route as one — removing a checkpoint relaxes a
752
+ * constraint, so the result is shorter and straighter, not the two old
753
+ * legs stitched together. Writes the same JSON as `move_gate`:
754
+ * `{"state", "rerouted_segments", "changed"}`.
755
+ */
756
+ removeGate(bus, index) {
757
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
758
+
759
+ const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
760
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
761
+
762
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
763
+
764
+
765
+ const result = wasm.Design_remove_gate(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, index, write.buffer);
766
+
767
+ try {
768
+ if (!diplomatReceive.resultFlag) {
769
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
770
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
771
+ }
772
+ return write.readString8();
773
+ }
774
+
775
+ finally {
776
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
777
+ functionCleanupArena.free();
778
+
779
+ diplomatReceive.free();
780
+ write.free();
781
+ }
782
+ }
783
+
784
+ /**
785
+ * Undo a design port declaration. Removing an ENDPOINT changes the
786
+ * netlist, so every bus that named it is deleted — pass `force=false`
787
+ * first to be refused with the list and confirm. An instance port is
788
+ * derived from its cell's contract; use `set_port_mode` there.
789
+ *
790
+ * Writes `{"removed_buses":[...],"rerouted":[...],"failed":{...},
791
+ * "changed":[...]}`.
792
+ */
793
+ removePort(name, force) {
794
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
795
+
796
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
797
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
798
+
799
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
800
+
801
+
802
+ const result = wasm.Design_remove_port(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, force, write.buffer);
803
+
804
+ try {
805
+ if (!diplomatReceive.resultFlag) {
806
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
807
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
808
+ }
809
+ return write.readString8();
810
+ }
811
+
812
+ finally {
813
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
814
+ functionCleanupArena.free();
815
+
816
+ diplomatReceive.free();
817
+ write.free();
818
+ }
819
+ }
820
+
821
+ /**
822
+ * Declare and route a bus with an explicit WIDTH-ADAPTATION policy, so
823
+ * a narrower word can drive a wider port.
824
+ *
825
+ * `align`: 0 = lsb (bit 0 to bit 0, magnitude preserved), 1 = msb (top
826
+ * bit to top bit — a shift up by the width difference), 2 = use
827
+ * `shift` verbatim (positive moves toward the MSB). `truncate` permits
828
+ * DROPPING source bits that fall outside the destination; without it a
829
+ * lossy connection is refused, because losing a word's high bits is not
830
+ * the router's call. Destination bits nothing drives read 0 with no
831
+ * hardware at all.
832
+ *
833
+ * Writes the resulting bus state; `bus_width_map` reports the mapping.
834
+ */
835
+ routeBusAdapted(name, driver, sinksCsv, gatesJson, styleJson, align, shift, truncate) {
836
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
837
+
838
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
839
+ const driverSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, driver)));
840
+ const sinksCsvSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, sinksCsv)));
841
+ const gatesJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, gatesJson)));
842
+ const styleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, styleJson)));
843
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
844
+
845
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
846
+
847
+
848
+ const result = wasm.Design_route_bus_adapted(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, driverSlice.ptr, sinksCsvSlice.ptr, gatesJsonSlice.ptr, styleJsonSlice.ptr, align, shift, truncate, write.buffer);
849
+
850
+ try {
851
+ if (!diplomatReceive.resultFlag) {
852
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
853
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
854
+ }
855
+ return write.readString8();
856
+ }
857
+
858
+ finally {
859
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
860
+ functionCleanupArena.free();
861
+
862
+ diplomatReceive.free();
863
+ write.free();
864
+ }
865
+ }
866
+
867
+ /**
868
+ * The resolved bit mapping of a width-adapted bus (`null` when the
869
+ * widths matched): `{"map":{...,"pairs":[[dbit,sbit],..]},"note":".."}`.
870
+ */
871
+ busWidthMap(name) {
872
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
873
+
874
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
875
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
876
+
877
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
878
+
879
+
880
+ const result = wasm.Design_bus_width_map(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
881
+
882
+ try {
883
+ if (!diplomatReceive.resultFlag) {
884
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
885
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
886
+ }
887
+ return write.readString8();
888
+ }
889
+
890
+ finally {
891
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
892
+ functionCleanupArena.free();
893
+
894
+ diplomatReceive.free();
895
+ write.free();
896
+ }
897
+ }
898
+
899
+ /**
900
+ * The current bus-layer GEOMETRY REVISION. Read it before a mutating
901
+ * call, pass it to `changed_layers_since` after, and redraw exactly
902
+ * the layers named.
903
+ */
904
+ layerRevision() {
905
+
906
+ const result = wasm.Design_layer_revision(this.ffiValue);
907
+
908
+ try {
909
+ return result;
910
+ }
911
+
912
+ finally {
913
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
914
+ }
915
+ }
916
+
917
+ /**
918
+ * The COMPLETE set of bus layers whose geometry was rewritten since
919
+ * `rev`, as a JSON array of names.
920
+ *
921
+ * This is the contract a viewer must trust: it is stamped at every
922
+ * write to a layer's fragment, so it also names layers changed
923
+ * INDIRECTLY — a crossing stamps a through-bus station into a bus
924
+ * that was never ripped and appears in no other report. It also names
925
+ * DELETED layers (a name here that `bus_state` no longer knows means
926
+ * drop the mesh). `route_bus`, which returns only a state, is covered
927
+ * by this too: bracket it with `layer_revision`.
928
+ */
929
+ changedLayersSince(rev) {
930
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
931
+
932
+ wasm.Design_changed_layers_since(this.ffiValue, rev, write.buffer);
933
+
934
+ try {
935
+ return write.readString8();
936
+ }
937
+
938
+ finally {
939
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
940
+ write.free();
941
+ }
942
+ }
943
+
944
+ /**
945
+ * Attach a net-class discipline to a bus (JSON `NetClassRule`:
946
+ * optional `max_len_rt` delay budget, `y_band` layer band, …);
947
+ * `check()` enforces it.
948
+ */
949
+ setBusRule(bus, ruleJson) {
950
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
951
+
952
+ const busSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, bus)));
953
+ const ruleJsonSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, ruleJson)));
954
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
955
+
956
+
957
+ const result = wasm.Design_set_bus_rule(diplomatReceive.buffer, this.ffiValue, busSlice.ptr, ruleJsonSlice.ptr);
958
+
959
+ try {
960
+ if (!diplomatReceive.resultFlag) {
961
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
962
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
963
+ }
964
+ }
965
+
966
+ finally {
967
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
968
+ functionCleanupArena.free();
969
+
970
+ diplomatReceive.free();
971
+ }
972
+ }
973
+
974
+ /**
975
+ * Per-bus skew from the routed fragment: writes
976
+ * `{"per_bit_rt": [...], "skew_rt": n, "max_rt": n}`.
977
+ */
978
+ busSkew(name) {
979
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
980
+
981
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
982
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
983
+
984
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
985
+
986
+
987
+ const result = wasm.Design_bus_skew(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
988
+
989
+ try {
990
+ if (!diplomatReceive.resultFlag) {
991
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
992
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
993
+ }
994
+ return write.readString8();
995
+ }
996
+
997
+ finally {
998
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
999
+ functionCleanupArena.free();
1000
+
1001
+ diplomatReceive.free();
1002
+ write.free();
1003
+ }
1004
+ }
1005
+
1006
+ /**
1007
+ * The lifecycle state of a bus: `"intended"`, `"routed"` or
1008
+ * `"failed: reason"`.
1009
+ */
1010
+ busState(name) {
1011
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
1012
+
1013
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
1014
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1015
+
1016
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
1017
+
1018
+
1019
+ const result = wasm.Design_bus_state(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
1020
+
1021
+ try {
1022
+ if (!diplomatReceive.resultFlag) {
1023
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1024
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1025
+ }
1026
+ return write.readString8();
1027
+ }
1028
+
1029
+ finally {
1030
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1031
+ functionCleanupArena.free();
1032
+
1033
+ diplomatReceive.free();
1034
+ write.free();
1035
+ }
1036
+ }
1037
+
1038
+ /**
1039
+ * ONE bus layer's cells as `[[x,y,z,"block"],..]`.
1040
+ *
1041
+ * The live-re-route fast path: `flatten()` rebuilds every layer in the
1042
+ * document to answer "what changed about this one bus". An unrouted bus
1043
+ * yields `[]`.
1044
+ */
1045
+ busBlocksJson(name) {
1046
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
1047
+
1048
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
1049
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1050
+
1051
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
1052
+
1053
+
1054
+ const result = wasm.Design_bus_blocks_json(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
1055
+
1056
+ try {
1057
+ if (!diplomatReceive.resultFlag) {
1058
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1059
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1060
+ }
1061
+ return write.readString8();
1062
+ }
1063
+
1064
+ finally {
1065
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1066
+ functionCleanupArena.free();
1067
+
1068
+ diplomatReceive.free();
1069
+ write.free();
1070
+ }
1071
+ }
1072
+
1073
+ /**
1074
+ * ONE instance's placed cells as `[[x,y,z,"block"],..]`, transform
1075
+ * applied. Same fast path as `bus_blocks_json`.
1076
+ */
1077
+ instanceBlocksJson(name) {
1078
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
1079
+
1080
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
1081
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1082
+
1083
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
1084
+
1085
+
1086
+ const result = wasm.Design_instance_blocks_json(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr, write.buffer);
1087
+
1088
+ try {
1089
+ if (!diplomatReceive.resultFlag) {
1090
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1091
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1092
+ }
1093
+ return write.readString8();
1094
+ }
1095
+
1096
+ finally {
1097
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1098
+ functionCleanupArena.free();
1099
+
1100
+ diplomatReceive.free();
1101
+ write.free();
1102
+ }
1103
+ }
1104
+
1105
+ /**
1106
+ * Rip a bus: clear its fragment, back to `intended`.
1107
+ */
1108
+ rip(name) {
1109
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
1110
+
1111
+ const nameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, name)));
1112
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1113
+
1114
+
1115
+ const result = wasm.Design_rip(diplomatReceive.buffer, this.ffiValue, nameSlice.ptr);
1116
+
1117
+ try {
1118
+ if (!diplomatReceive.resultFlag) {
1119
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1120
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1121
+ }
1122
+ }
1123
+
1124
+ finally {
1125
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1126
+ functionCleanupArena.free();
1127
+
1128
+ diplomatReceive.free();
1129
+ }
1130
+ }
1131
+
1132
+ /**
1133
+ * Collapse the layer stack into ONE self-describing schematic:
1134
+ * named regions per layer (`inst:x`, `bus:y`) and the merged
1135
+ * contract embedded in the metadata — itself placeable as a cell.
1136
+ */
1137
+ flatten() {
1138
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1139
+
1140
+
1141
+ const result = wasm.Design_flatten(diplomatReceive.buffer, this.ffiValue);
1142
+
1143
+ try {
1144
+ if (!diplomatReceive.resultFlag) {
1145
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1146
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1147
+ }
1148
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
1149
+ }
1150
+
1151
+ finally {
1152
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1153
+ diplomatReceive.free();
1154
+ }
1155
+ }
1156
+
1157
+ /**
1158
+ * DRC + LVS over the flattened artifact. Writes `{"clean",
1159
+ * "drc": [...], "lvs": {...}, "buses": {...}}`.
1160
+ */
1161
+ check() {
1162
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1163
+
1164
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
1165
+
1166
+
1167
+ const result = wasm.Design_check(diplomatReceive.buffer, this.ffiValue, write.buffer);
1168
+
1169
+ try {
1170
+ if (!diplomatReceive.resultFlag) {
1171
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1172
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1173
+ }
1174
+ return write.readString8();
1175
+ }
1176
+
1177
+ finally {
1178
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1179
+ diplomatReceive.free();
1180
+ write.free();
1181
+ }
1182
+ }
1183
+
1184
+ /**
1185
+ * Settle the flattened artifact in the vanilla-accurate tick
1186
+ * engine and return it with every settled state written back and
1187
+ * `InitialState::Baked` stamped into the embedded contract (needs
1188
+ * the `mc-tick` feature, else errors).
1189
+ */
1190
+ bake(budget) {
1191
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1192
+
1193
+
1194
+ const result = wasm.Design_bake(diplomatReceive.buffer, this.ffiValue, budget);
1195
+
1196
+ try {
1197
+ if (!diplomatReceive.resultFlag) {
1198
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1199
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1200
+ }
1201
+ return new Schematic(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
1202
+ }
1203
+
1204
+ finally {
1205
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1206
+ diplomatReceive.free();
1207
+ }
1208
+ }
1209
+
1210
+ /**
1211
+ * Serialize the FULL design document to `.nucm` project-tier
1212
+ * bytes (magic `NUCM`): cells deduped by content hash, instance
1213
+ * transforms, ports with scanned hardware, every bus layer with
1214
+ * its fragment, runs and `intended`/`routed`/`failed: reason`
1215
+ * state, and the loose base layer. Base64 across the bridge.
1216
+ */
1217
+ toNucmB64() {
1218
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1219
+
1220
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
1221
+
1222
+
1223
+ const result = wasm.Design_to_nucm_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
1224
+
1225
+ try {
1226
+ if (!diplomatReceive.resultFlag) {
1227
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1228
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1229
+ }
1230
+ return write.readString8();
1231
+ }
1232
+
1233
+ finally {
1234
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1235
+ diplomatReceive.free();
1236
+ write.free();
1237
+ }
1238
+ }
1239
+
1240
+ /**
1241
+ * Reopen a `.nucm` design document from raw bytes. The reloaded
1242
+ * design is the same model mid-edit: rerouting works.
1243
+ */
1244
+ static fromNucm(data) {
1245
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
1246
+
1247
+ const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
1248
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1249
+
1250
+
1251
+ const result = wasm.Design_from_nucm(diplomatReceive.buffer, dataSlice.ptr);
1252
+
1253
+ try {
1254
+ if (!diplomatReceive.resultFlag) {
1255
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1256
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1257
+ }
1258
+ return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
1259
+ }
1260
+
1261
+ finally {
1262
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1263
+ functionCleanupArena.free();
1264
+
1265
+ diplomatReceive.free();
1266
+ }
1267
+ }
1268
+
1269
+ /**
1270
+ * Export the design as a LAYERED `.litematic` (interchange tier):
1271
+ * one named region per layer (`inst:{name}`, `bus:{name}`, loose
1272
+ * base) plus the design manifest as a root-level
1273
+ * `NucleationDesign` tag. Opens in Litematica as a plain
1274
+ * multi-region litematic; reimports as a design whose cell
1275
+ * references have degraded to embedded copies. Base64 across the
1276
+ * bridge.
1277
+ */
1278
+ toLitematicB64() {
1279
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1280
+
1281
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
1282
+
1283
+
1284
+ const result = wasm.Design_to_litematic_b64(diplomatReceive.buffer, this.ffiValue, write.buffer);
1285
+
1286
+ try {
1287
+ if (!diplomatReceive.resultFlag) {
1288
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1289
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1290
+ }
1291
+ return write.readString8();
1292
+ }
1293
+
1294
+ finally {
1295
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1296
+ diplomatReceive.free();
1297
+ write.free();
1298
+ }
1299
+ }
1300
+
1301
+ /**
1302
+ * Import a layered `.litematic` (with a `NucleationDesign`
1303
+ * manifest) from raw bytes; a plain litematic errors loudly —
1304
+ * open those with `Schematic.from_litematic`.
1305
+ */
1306
+ static fromLitematic(data) {
1307
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
1308
+
1309
+ const dataSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.slice(wasm, data, "u8")));
1310
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
1311
+
1312
+
1313
+ const result = wasm.Design_from_litematic(diplomatReceive.buffer, dataSlice.ptr);
1314
+
1315
+ try {
1316
+ if (!diplomatReceive.resultFlag) {
1317
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
1318
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
1319
+ }
1320
+ return new Design(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
1321
+ }
1322
+
1323
+ finally {
1324
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
1325
+ functionCleanupArena.free();
1326
+
1327
+ diplomatReceive.free();
1328
+ }
1329
+ }
1330
+
1331
+ constructor(symbol, ptr, selfEdge) {
1332
+ return this.#internalConstructor(...arguments)
1333
+ }
1334
+ }