nucleation 0.2.18 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/Autostack.d.ts +43 -0
  2. package/Autostack.mjs +134 -0
  3. package/BlockPos.d.ts +28 -0
  4. package/BlockPos.mjs +129 -0
  5. package/BlockState.d.ts +39 -0
  6. package/BlockState.mjs +134 -0
  7. package/Brush.d.ts +68 -0
  8. package/Brush.mjs +220 -0
  9. package/BuildingTool.d.ts +29 -0
  10. package/BuildingTool.mjs +74 -0
  11. package/ChunkMeshResult.d.ts +75 -0
  12. package/ChunkMeshResult.mjs +253 -0
  13. package/CircuitBuilder.d.ts +118 -0
  14. package/CircuitBuilder.mjs +516 -0
  15. package/DefinitionRegion.d.ts +274 -0
  16. package/DefinitionRegion.mjs +973 -0
  17. package/Diff.d.ts +88 -0
  18. package/Diff.mjs +316 -0
  19. package/Dimensions.d.ts +28 -0
  20. package/Dimensions.mjs +129 -0
  21. package/ExecutionMode.d.ts +42 -0
  22. package/ExecutionMode.mjs +127 -0
  23. package/Fingerprint.d.ts +44 -0
  24. package/Fingerprint.mjs +197 -0
  25. package/InterpolationSpace.d.ts +25 -0
  26. package/InterpolationSpace.mjs +73 -0
  27. package/IoLayout.d.ts +26 -0
  28. package/IoLayout.mjs +81 -0
  29. package/IoLayoutBuilder.d.ts +73 -0
  30. package/IoLayoutBuilder.mjs +315 -0
  31. package/IoType.d.ts +41 -0
  32. package/IoType.mjs +125 -0
  33. package/ItemModelConfig.d.ts +65 -0
  34. package/ItemModelConfig.mjs +223 -0
  35. package/ItemModelPackBuilder.d.ts +32 -0
  36. package/ItemModelPackBuilder.mjs +104 -0
  37. package/ItemModelResult.d.ts +72 -0
  38. package/ItemModelResult.mjs +268 -0
  39. package/ItemScale.d.ts +31 -0
  40. package/ItemScale.mjs +132 -0
  41. package/LayoutFunction.d.ts +52 -0
  42. package/LayoutFunction.mjs +159 -0
  43. package/MchprsWorld.d.ts +131 -0
  44. package/MchprsWorld.mjs +423 -0
  45. package/MeshBounds.d.ts +40 -0
  46. package/MeshBounds.mjs +180 -0
  47. package/MeshConfig.d.ts +101 -0
  48. package/MeshConfig.mjs +306 -0
  49. package/MeshJob.d.ts +44 -0
  50. package/MeshJob.mjs +116 -0
  51. package/MeshPhase.d.ts +38 -0
  52. package/MeshPhase.mjs +90 -0
  53. package/MeshProgress.d.ts +32 -0
  54. package/MeshProgress.mjs +133 -0
  55. package/MeshResult.d.ts +60 -0
  56. package/MeshResult.mjs +206 -0
  57. package/MultiMeshResult.d.ts +50 -0
  58. package/MultiMeshResult.mjs +166 -0
  59. package/Nbt.d.ts +50 -0
  60. package/Nbt.mjs +161 -0
  61. package/NucleationError.d.ts +36 -0
  62. package/NucleationError.mjs +104 -0
  63. package/OutputCondition.d.ts +45 -0
  64. package/OutputCondition.mjs +129 -0
  65. package/Palette.d.ts +84 -0
  66. package/Palette.mjs +269 -0
  67. package/PaletteBuilder.d.ts +76 -0
  68. package/PaletteBuilder.mjs +297 -0
  69. package/README.md +28 -197
  70. package/RawMeshExport.d.ts +74 -0
  71. package/RawMeshExport.mjs +243 -0
  72. package/RedstoneGraph.d.ts +58 -0
  73. package/RedstoneGraph.mjs +242 -0
  74. package/RegionBounds.d.ts +41 -0
  75. package/RegionBounds.mjs +181 -0
  76. package/RenderConfig.d.ts +66 -0
  77. package/RenderConfig.mjs +170 -0
  78. package/Renderer.d.ts +35 -0
  79. package/Renderer.mjs +139 -0
  80. package/ResourcePack.d.ts +105 -0
  81. package/ResourcePack.mjs +447 -0
  82. package/ResourcePackList.d.ts +32 -0
  83. package/ResourcePackList.mjs +96 -0
  84. package/Schematic.d.ts +655 -0
  85. package/Schematic.mjs +2647 -0
  86. package/SchematicBuilder.d.ts +103 -0
  87. package/SchematicBuilder.mjs +401 -0
  88. package/SchematicRegions.d.ts +93 -0
  89. package/SchematicRegions.mjs +411 -0
  90. package/Scripting.d.ts +40 -0
  91. package/Scripting.mjs +138 -0
  92. package/Sdf.d.ts +31 -0
  93. package/Sdf.mjs +107 -0
  94. package/Shape.d.ts +108 -0
  95. package/Shape.mjs +336 -0
  96. package/SortStrategy.d.ts +86 -0
  97. package/SortStrategy.mjs +272 -0
  98. package/Store.d.ts +83 -0
  99. package/Store.mjs +369 -0
  100. package/StoreIo.d.ts +71 -0
  101. package/StoreIo.mjs +292 -0
  102. package/TextureAtlas.d.ts +40 -0
  103. package/TextureAtlas.mjs +122 -0
  104. package/TextureInfo.d.ts +34 -0
  105. package/TextureInfo.mjs +148 -0
  106. package/TypedCircuitExecutor.d.ts +101 -0
  107. package/TypedCircuitExecutor.mjs +378 -0
  108. package/Value.d.ts +73 -0
  109. package/Value.mjs +275 -0
  110. package/WorldChunkView.d.ts +63 -0
  111. package/WorldChunkView.mjs +201 -0
  112. package/WorldSink.d.ts +50 -0
  113. package/WorldSink.mjs +177 -0
  114. package/WorldStream.d.ts +45 -0
  115. package/WorldStream.mjs +184 -0
  116. package/diplomat-runtime.d.ts +15 -0
  117. package/diplomat-runtime.mjs +774 -0
  118. package/diplomat-wasm.mjs +52 -0
  119. package/diplomat.config.mjs +6 -0
  120. package/index.d.ts +117 -0
  121. package/index.mjs +120 -0
  122. package/{nucleation_bg.wasm → nucleation.wasm} +0 -0
  123. package/package.json +19 -41
  124. package/LICENSE +0 -21
  125. package/api.js +0 -608
  126. package/nucleation-cdn-loader.js +0 -15
  127. package/nucleation-original.js +0 -8383
  128. package/nucleation.d.ts +0 -2947
  129. package/nucleation.js +0 -36
@@ -0,0 +1,127 @@
1
+ // generated by diplomat-tool
2
+ import { NucleationError } from "./NucleationError.mjs"
3
+ import { OutputCondition } from "./OutputCondition.mjs"
4
+ import wasm from "./diplomat-wasm.mjs";
5
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
6
+
7
+ const ExecutionMode_box_destroy_registry = new FinalizationRegistry((ptr) => {
8
+ wasm.ExecutionMode_destroy(ptr);
9
+ });
10
+
11
+ /**
12
+ * How long to run the circuit for one `execute` call (PORTING rule 10).
13
+ */
14
+ export class ExecutionMode {
15
+ // Internal ptr reference:
16
+ #ptr = null;
17
+
18
+ // Lifetimes are only to keep dependencies alive.
19
+ // Since JS won't garbage collect until there are no incoming edges.
20
+ #selfEdge = [];
21
+
22
+ #internalConstructor(symbol, ptr, selfEdge) {
23
+ if (symbol !== diplomatRuntime.internalConstructor) {
24
+ console.error("ExecutionMode is an Opaque type. You cannot call its constructor.");
25
+ return;
26
+ }
27
+ this.#ptr = ptr;
28
+ this.#selfEdge = selfEdge;
29
+
30
+ // Are we being borrowed? If not, we can register.
31
+ if (this.#selfEdge.length === 0) {
32
+ ExecutionMode_box_destroy_registry.register(this, this.#ptr);
33
+ }
34
+
35
+ return this;
36
+ }
37
+ /** @internal */
38
+ get ffiValue() {
39
+ return this.#ptr;
40
+ }
41
+
42
+
43
+ /**
44
+ * Run for exactly `ticks` ticks.
45
+ */
46
+ static fixedTicks(ticks) {
47
+
48
+ const result = wasm.ExecutionMode_fixed_ticks(ticks);
49
+
50
+ try {
51
+ return new ExecutionMode(diplomatRuntime.internalConstructor, result, []);
52
+ }
53
+
54
+ finally {
55
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Run until the output named `output_name` meets `condition`,
61
+ * checking every `check_interval` ticks, giving up after `max_ticks`
62
+ * ticks (the result's `condition_met` reports which happened).
63
+ */
64
+ static untilCondition(outputName, condition, maxTicks, checkInterval) {
65
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
66
+
67
+ const outputNameSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, outputName)));
68
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
69
+
70
+
71
+ const result = wasm.ExecutionMode_until_condition(diplomatReceive.buffer, outputNameSlice.ptr, condition.ffiValue, maxTicks, checkInterval);
72
+
73
+ try {
74
+ if (!diplomatReceive.resultFlag) {
75
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
76
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
77
+ }
78
+ return new ExecutionMode(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []);
79
+ }
80
+
81
+ finally {
82
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
83
+ functionCleanupArena.free();
84
+
85
+ diplomatReceive.free();
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Run until any output changes from its initial reading, checking
91
+ * every `check_interval` ticks, giving up after `max_ticks` ticks.
92
+ */
93
+ static untilChange(maxTicks, checkInterval) {
94
+
95
+ const result = wasm.ExecutionMode_until_change(maxTicks, checkInterval);
96
+
97
+ try {
98
+ return new ExecutionMode(diplomatRuntime.internalConstructor, result, []);
99
+ }
100
+
101
+ finally {
102
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Run (one tick at a time) until all outputs have been unchanged for
108
+ * `stable_ticks` consecutive ticks, giving up after `max_ticks`
109
+ * ticks (the result's `condition_met` reports stability).
110
+ */
111
+ static untilStable(stableTicks, maxTicks) {
112
+
113
+ const result = wasm.ExecutionMode_until_stable(stableTicks, maxTicks);
114
+
115
+ try {
116
+ return new ExecutionMode(diplomatRuntime.internalConstructor, result, []);
117
+ }
118
+
119
+ finally {
120
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
121
+ }
122
+ }
123
+
124
+ constructor(symbol, ptr, selfEdge) {
125
+ return this.#internalConstructor(...arguments)
126
+ }
127
+ }
@@ -0,0 +1,44 @@
1
+ // generated by diplomat-tool
2
+ import type { NucleationError } from "./NucleationError"
3
+ import type { Schematic } from "./Schematic"
4
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
5
+
6
+
7
+
8
+ /**
9
+ * Namespace type for the fingerprint free functions (PORTING rule 12).
10
+ */
11
+ export class Fingerprint {
12
+ /** @internal */
13
+ get ffiValue(): pointer;
14
+ /** @internal */
15
+ constructor();
16
+
17
+
18
+ /**
19
+ * The fingerprint of a schematic for the given preset, as a hex string.
20
+ * Errors with `InvalidArgument` on an unknown preset.
21
+ */
22
+ static compute(schematic: Schematic, preset: string): string;
23
+
24
+ /**
25
+ * The structural signature (JSON) of a schematic for the given preset.
26
+ */
27
+ static signatureJson(schematic: Schematic, preset: string): string;
28
+
29
+ /**
30
+ * Translation-invariant fuzzy distance between two builds' footprints.
31
+ */
32
+ static footprintDistance(a: Schematic, b: Schematic, preset: string): number;
33
+
34
+ /**
35
+ * The schematic's translation/scale-invariant FFT shape footprint as a
36
+ * JSON array of floats.
37
+ */
38
+ static footprintJson(schematic: Schematic, preset: string): string;
39
+
40
+ /**
41
+ * Whether two schematics share the same fingerprint for the given preset.
42
+ */
43
+ static isDuplicate(a: Schematic, b: Schematic, preset: string): boolean;
44
+ }
@@ -0,0 +1,197 @@
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 Fingerprint_box_destroy_registry = new FinalizationRegistry((ptr) => {
8
+ wasm.Fingerprint_destroy(ptr);
9
+ });
10
+
11
+ /**
12
+ * Namespace type for the fingerprint free functions (PORTING rule 12).
13
+ */
14
+ export class Fingerprint {
15
+ // Internal ptr reference:
16
+ #ptr = null;
17
+
18
+ // Lifetimes are only to keep dependencies alive.
19
+ // Since JS won't garbage collect until there are no incoming edges.
20
+ #selfEdge = [];
21
+
22
+ #internalConstructor(symbol, ptr, selfEdge) {
23
+ if (symbol !== diplomatRuntime.internalConstructor) {
24
+ console.error("Fingerprint is an Opaque type. You cannot call its constructor.");
25
+ return;
26
+ }
27
+ this.#ptr = ptr;
28
+ this.#selfEdge = selfEdge;
29
+
30
+ // Are we being borrowed? If not, we can register.
31
+ if (this.#selfEdge.length === 0) {
32
+ Fingerprint_box_destroy_registry.register(this, this.#ptr);
33
+ }
34
+
35
+ return this;
36
+ }
37
+ /** @internal */
38
+ get ffiValue() {
39
+ return this.#ptr;
40
+ }
41
+
42
+
43
+ /**
44
+ * The fingerprint of a schematic for the given preset, as a hex string.
45
+ * Errors with `InvalidArgument` on an unknown preset.
46
+ */
47
+ static compute(schematic, preset) {
48
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
49
+
50
+ const presetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, preset)));
51
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
52
+
53
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
54
+
55
+
56
+ const result = wasm.Fingerprint_compute(diplomatReceive.buffer, schematic.ffiValue, presetSlice.ptr, write.buffer);
57
+
58
+ try {
59
+ if (!diplomatReceive.resultFlag) {
60
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
61
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
62
+ }
63
+ return write.readString8();
64
+ }
65
+
66
+ finally {
67
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
68
+ functionCleanupArena.free();
69
+
70
+ diplomatReceive.free();
71
+ write.free();
72
+ }
73
+ }
74
+
75
+ /**
76
+ * The structural signature (JSON) of a schematic for the given preset.
77
+ */
78
+ static signatureJson(schematic, preset) {
79
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
80
+
81
+ const presetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, preset)));
82
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
83
+
84
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
85
+
86
+
87
+ const result = wasm.Fingerprint_signature_json(diplomatReceive.buffer, schematic.ffiValue, presetSlice.ptr, write.buffer);
88
+
89
+ try {
90
+ if (!diplomatReceive.resultFlag) {
91
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
92
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
93
+ }
94
+ return write.readString8();
95
+ }
96
+
97
+ finally {
98
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
99
+ functionCleanupArena.free();
100
+
101
+ diplomatReceive.free();
102
+ write.free();
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Translation-invariant fuzzy distance between two builds' footprints.
108
+ */
109
+ static footprintDistance(a, b, preset) {
110
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
111
+
112
+ const presetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, preset)));
113
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
114
+
115
+
116
+ const result = wasm.Fingerprint_footprint_distance(diplomatReceive.buffer, a.ffiValue, b.ffiValue, presetSlice.ptr);
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 (new Float32Array(wasm.memory.buffer, diplomatReceive.buffer, 1))[0];
124
+ }
125
+
126
+ finally {
127
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
128
+ functionCleanupArena.free();
129
+
130
+ diplomatReceive.free();
131
+ }
132
+ }
133
+
134
+ /**
135
+ * The schematic's translation/scale-invariant FFT shape footprint as a
136
+ * JSON array of floats.
137
+ */
138
+ static footprintJson(schematic, preset) {
139
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
140
+
141
+ const presetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, preset)));
142
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
143
+
144
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
145
+
146
+
147
+ const result = wasm.Fingerprint_footprint_json(diplomatReceive.buffer, schematic.ffiValue, presetSlice.ptr, write.buffer);
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
+ return write.readString8();
155
+ }
156
+
157
+ finally {
158
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
159
+ functionCleanupArena.free();
160
+
161
+ diplomatReceive.free();
162
+ write.free();
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Whether two schematics share the same fingerprint for the given preset.
168
+ */
169
+ static isDuplicate(a, b, preset) {
170
+ let functionCleanupArena = new diplomatRuntime.CleanupArena();
171
+
172
+ const presetSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.sliceWrapper(wasm, diplomatRuntime.DiplomatBuf.str8(wasm, preset)));
173
+ const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 1, true);
174
+
175
+
176
+ const result = wasm.Fingerprint_is_duplicate(diplomatReceive.buffer, a.ffiValue, b.ffiValue, presetSlice.ptr);
177
+
178
+ try {
179
+ if (!diplomatReceive.resultFlag) {
180
+ const cause = new NucleationError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
181
+ throw new globalThis.Error('NucleationError.' + cause.value, { cause });
182
+ }
183
+ return (new Uint8Array(wasm.memory.buffer, diplomatReceive.buffer, 1))[0] === 1;
184
+ }
185
+
186
+ finally {
187
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
188
+ functionCleanupArena.free();
189
+
190
+ diplomatReceive.free();
191
+ }
192
+ }
193
+
194
+ constructor(symbol, ptr, selfEdge) {
195
+ return this.#internalConstructor(...arguments)
196
+ }
197
+ }
@@ -0,0 +1,25 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
3
+
4
+
5
+
6
+ /**
7
+ * Color interpolation space for gradient brushes. The old ABI passed this as
8
+ * `space: c_int` (`1` = Oklab, anything else = RGB).
9
+ */
10
+ export class InterpolationSpace {
11
+
12
+ /** @internal */
13
+ static fromValue(value: InterpolationSpace | string): InterpolationSpace;
14
+
15
+ get value(): string;
16
+
17
+ /** @internal */
18
+ get ffiValue(): number;
19
+
20
+ static Rgb : InterpolationSpace;
21
+ static Oklab : InterpolationSpace;
22
+
23
+
24
+ constructor(value: InterpolationSpace | string );
25
+ }
@@ -0,0 +1,73 @@
1
+ // generated by diplomat-tool
2
+ import wasm from "./diplomat-wasm.mjs";
3
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
+
5
+
6
+
7
+ /**
8
+ * Color interpolation space for gradient brushes. The old ABI passed this as
9
+ * `space: c_int` (`1` = Oklab, anything else = RGB).
10
+ */
11
+ export class InterpolationSpace {
12
+ #value = undefined;
13
+
14
+ static #values = new Map([
15
+ ["Rgb", 0],
16
+ ["Oklab", 1]
17
+ ]);
18
+
19
+ static getAllEntries() {
20
+ return InterpolationSpace.#values.entries();
21
+ }
22
+
23
+ #internalConstructor(value) {
24
+ if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
25
+ // We pass in two internalConstructor arguments to create *new*
26
+ // instances of this type, otherwise the enums are treated as singletons.
27
+ if (arguments[1] === diplomatRuntime.internalConstructor ) {
28
+ this.#value = arguments[2];
29
+ return this;
30
+ }
31
+ return InterpolationSpace.#objectValues[arguments[1]];
32
+ }
33
+
34
+ if (value instanceof InterpolationSpace) {
35
+ return value;
36
+ }
37
+
38
+ let intVal = InterpolationSpace.#values.get(value);
39
+
40
+ // Nullish check, checks for null or undefined
41
+ if (intVal != null) {
42
+ return InterpolationSpace.#objectValues[intVal];
43
+ }
44
+
45
+ throw TypeError(value + " is not a InterpolationSpace and does not correspond to any of its enumerator values.");
46
+ }
47
+
48
+ /** @internal */
49
+ static fromValue(value) {
50
+ return new InterpolationSpace(value);
51
+ }
52
+
53
+ get value(){
54
+ return [...InterpolationSpace.#values.keys()][this.#value];
55
+ }
56
+
57
+ /** @internal */
58
+ get ffiValue(){
59
+ return this.#value;
60
+ }
61
+ static #objectValues = [
62
+ new InterpolationSpace(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
63
+ new InterpolationSpace(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
64
+ ];
65
+
66
+ static Rgb = InterpolationSpace.#objectValues[0];
67
+ static Oklab = InterpolationSpace.#objectValues[1];
68
+
69
+
70
+ constructor(value) {
71
+ return this.#internalConstructor(...arguments)
72
+ }
73
+ }
package/IoLayout.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ // generated by diplomat-tool
2
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
3
+
4
+
5
+
6
+ /**
7
+ * An immutable IO layout. Wraps
8
+ * {@link crate::simulation::typed_executor::IoLayout}.
9
+ */
10
+ export class IoLayout {
11
+ /** @internal */
12
+ get ffiValue(): pointer;
13
+ /** @internal */
14
+ constructor();
15
+
16
+
17
+ /**
18
+ * Input names as a JSON array string.
19
+ */
20
+ inputNamesJson(): string;
21
+
22
+ /**
23
+ * Output names as a JSON array string.
24
+ */
25
+ outputNamesJson(): string;
26
+ }
package/IoLayout.mjs ADDED
@@ -0,0 +1,81 @@
1
+ // generated by diplomat-tool
2
+ import wasm from "./diplomat-wasm.mjs";
3
+ import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
+
5
+ const IoLayout_box_destroy_registry = new FinalizationRegistry((ptr) => {
6
+ wasm.IoLayout_destroy(ptr);
7
+ });
8
+
9
+ /**
10
+ * An immutable IO layout. Wraps
11
+ * {@link crate::simulation::typed_executor::IoLayout}.
12
+ */
13
+ export class IoLayout {
14
+ // Internal ptr reference:
15
+ #ptr = null;
16
+
17
+ // Lifetimes are only to keep dependencies alive.
18
+ // Since JS won't garbage collect until there are no incoming edges.
19
+ #selfEdge = [];
20
+
21
+ #internalConstructor(symbol, ptr, selfEdge) {
22
+ if (symbol !== diplomatRuntime.internalConstructor) {
23
+ console.error("IoLayout is an Opaque type. You cannot call its constructor.");
24
+ return;
25
+ }
26
+ this.#ptr = ptr;
27
+ this.#selfEdge = selfEdge;
28
+
29
+ // Are we being borrowed? If not, we can register.
30
+ if (this.#selfEdge.length === 0) {
31
+ IoLayout_box_destroy_registry.register(this, this.#ptr);
32
+ }
33
+
34
+ return this;
35
+ }
36
+ /** @internal */
37
+ get ffiValue() {
38
+ return this.#ptr;
39
+ }
40
+
41
+
42
+ /**
43
+ * Input names as a JSON array string.
44
+ */
45
+ inputNamesJson() {
46
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
47
+
48
+ wasm.IoLayout_input_names_json(this.ffiValue, write.buffer);
49
+
50
+ try {
51
+ return write.readString8();
52
+ }
53
+
54
+ finally {
55
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
56
+ write.free();
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Output names as a JSON array string.
62
+ */
63
+ outputNamesJson() {
64
+ const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
65
+
66
+ wasm.IoLayout_output_names_json(this.ffiValue, write.buffer);
67
+
68
+ try {
69
+ return write.readString8();
70
+ }
71
+
72
+ finally {
73
+ diplomatRuntime.FUNCTION_PARAM_ALLOC.clean();
74
+ write.free();
75
+ }
76
+ }
77
+
78
+ constructor(symbol, ptr, selfEdge) {
79
+ return this.#internalConstructor(...arguments)
80
+ }
81
+ }
@@ -0,0 +1,73 @@
1
+ // generated by diplomat-tool
2
+ import type { IoLayout } from "./IoLayout"
3
+ import type { IoType } from "./IoType"
4
+ import type { LayoutFunction } from "./LayoutFunction"
5
+ import type { NucleationError } from "./NucleationError"
6
+ import type { pointer, codepoint } from "./diplomat-runtime.d.ts";
7
+
8
+
9
+
10
+ /**
11
+ * Builder for an {@link IoLayout}. `build` consumes it (PORTING rule 11).
12
+ */
13
+ export class IoLayoutBuilder {
14
+ /** @internal */
15
+ get ffiValue(): pointer;
16
+ /** @internal */
17
+ constructor();
18
+
19
+
20
+ /**
21
+ * Create an empty layout builder.
22
+ */
23
+ static create(): IoLayoutBuilder;
24
+
25
+ /**
26
+ * Add an input. `positions` is flat `[x,y,z, x,y,z, ...]`.
27
+ */
28
+ addInput(name: string, ioType: IoType, layout: LayoutFunction, positions: Array<number>): void;
29
+
30
+ /**
31
+ * Add an output. `positions` is flat `[x,y,z, x,y,z, ...]`.
32
+ */
33
+ addOutput(name: string, ioType: IoType, layout: LayoutFunction, positions: Array<number>): void;
34
+
35
+ /**
36
+ * Add an input with automatic layout inference.
37
+ */
38
+ addInputAuto(name: string, ioType: IoType, positions: Array<number>): void;
39
+
40
+ /**
41
+ * Add an output with automatic layout inference.
42
+ */
43
+ addOutputAuto(name: string, ioType: IoType, positions: Array<number>): void;
44
+
45
+ /**
46
+ * Add an input from a region given as flat block positions (sorted by
47
+ * the default YXZ strategy, matching the old region semantics).
48
+ */
49
+ addInputFromRegion(name: string, ioType: IoType, layout: LayoutFunction, regionPositions: Array<number>): void;
50
+
51
+ /**
52
+ * Add an input from a region (flat positions) with automatic layout
53
+ * inference.
54
+ */
55
+ addInputFromRegionAuto(name: string, ioType: IoType, regionPositions: Array<number>): void;
56
+
57
+ /**
58
+ * Add an output from a region given as flat block positions.
59
+ */
60
+ addOutputFromRegion(name: string, ioType: IoType, layout: LayoutFunction, regionPositions: Array<number>): void;
61
+
62
+ /**
63
+ * Add an output from a region (flat positions) with automatic layout
64
+ * inference.
65
+ */
66
+ addOutputFromRegionAuto(name: string, ioType: IoType, regionPositions: Array<number>): void;
67
+
68
+ /**
69
+ * Build the {@link IoLayout}. Consumes the builder (a second call returns
70
+ * `AlreadyConsumed`).
71
+ */
72
+ build(): IoLayout;
73
+ }