nucleation 0.1.18 → 0.1.20

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.
@@ -1,34 +1,15 @@
1
- // nucleation-cdn-loader.js - Custom loader for CDN usage
2
- import * as bgModule from './nucleation_bg.js';
1
+ // This loader is for use in a browser via <script type="module"> from a CDN.
2
+ // It ensures that the .wasm file is loaded from the correct relative path.
3
3
 
4
- let initialized = false;
4
+ // Import the real init function and all the classes from the original module.
5
+ import init, * as wasm from './nucleation-original.js';
5
6
 
6
- // The init function is the default export for this file.
7
- async function init(wasmPathOrModule) {
8
- if (initialized) {
9
- return { ...bgModule };
10
- }
11
- if (typeof bgModule.__wbg_set_wasm !== 'function') {
12
- throw new Error("Missing __wbg_set_wasm in ./nucleation_bg.js");
13
- }
14
-
15
- let input = wasmPathOrModule;
16
- if (input === undefined) {
17
- input = new URL('./nucleation_bg.wasm', import.meta.url);
18
- }
19
-
20
- const importsObject = { './nucleation_bg.js': bgModule };
21
- const { instance } = await WebAssembly.instantiateStreaming(fetch(input), importsObject);
22
-
23
- bgModule.__wbg_set_wasm(instance.exports);
24
- initialized = true;
25
-
26
- // Return all the exports from the bg module
27
- return { ...bgModule };
7
+ // The default export is a new initializer function for CDN use.
8
+ // It calls the real 'init' but provides the URL to the .wasm file.
9
+ export default async function() {
10
+ const wasmUrl = new URL('./nucleation_bg.wasm', import.meta.url);
11
+ await init(wasmUrl);
28
12
  }
29
13
 
30
- // Re-export the named items so users can do:
31
- // import init, { SchematicWrapper } from '.../loader.js';
32
- // This works because after init() is called, these exports become "live".
33
- export * from './nucleation_bg.js';
34
- export default init;
14
+ // Re-export all the named classes (SchematicWrapper, etc.).
15
+ export * from './nucleation-original.js';
@@ -1,8 +1,4 @@
1
1
  let wasm;
2
- export function __wbg_set_wasm(val) {
3
- wasm = val;
4
- }
5
-
6
2
 
7
3
  function addToExternrefTable0(obj) {
8
4
  const idx = wasm.__externref_table_alloc();
@@ -95,9 +91,7 @@ function getUint8ArrayMemory0() {
95
91
  return cachedUint8ArrayMemory0;
96
92
  }
97
93
 
98
- const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
99
-
100
- let cachedTextEncoder = new lTextEncoder('utf-8');
94
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
101
95
 
102
96
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
103
97
  ? function (arg, view) {
@@ -164,11 +158,9 @@ function isLikeNone(x) {
164
158
  return x === undefined || x === null;
165
159
  }
166
160
 
167
- const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
161
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
168
162
 
169
- let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
170
-
171
- cachedTextDecoder.decode();
163
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
172
164
 
173
165
  function getStringFromWasm0(ptr, len) {
174
166
  ptr = ptr >>> 0;
@@ -695,120 +687,209 @@ export class SchematicWrapper {
695
687
  }
696
688
  }
697
689
 
698
- export function __wbg_get_67b2ba62fc30de12() { return handleError(function (arg0, arg1) {
699
- const ret = Reflect.get(arg0, arg1);
700
- return ret;
701
- }, arguments) };
690
+ async function __wbg_load(module, imports) {
691
+ if (typeof Response === 'function' && module instanceof Response) {
692
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
693
+ try {
694
+ return await WebAssembly.instantiateStreaming(module, imports);
702
695
 
703
- export function __wbg_get_b9b93047fe3cf45b(arg0, arg1) {
704
- const ret = arg0[arg1 >>> 0];
705
- return ret;
706
- };
696
+ } catch (e) {
697
+ if (module.headers.get('Content-Type') != 'application/wasm') {
698
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
707
699
 
708
- export function __wbg_instanceof_Object_7f2dcef8f78644a4(arg0) {
709
- let result;
710
- try {
711
- result = arg0 instanceof Object;
712
- } catch (_) {
713
- result = false;
714
- }
715
- const ret = result;
716
- return ret;
717
- };
718
-
719
- export function __wbg_isArray_a1eab7e0d067391b(arg0) {
720
- const ret = Array.isArray(arg0);
721
- return ret;
722
- };
723
-
724
- export function __wbg_keys_5c77a08ddc2fb8a6(arg0) {
725
- const ret = Object.keys(arg0);
726
- return ret;
727
- };
728
-
729
- export function __wbg_length_e2d2a49132c1b256(arg0) {
730
- const ret = arg0.length;
731
- return ret;
732
- };
733
-
734
- export function __wbg_log_c222819a41e063d3(arg0) {
735
- console.log(arg0);
736
- };
737
-
738
- export function __wbg_new_405e22f390576ce2() {
739
- const ret = new Object();
740
- return ret;
741
- };
742
-
743
- export function __wbg_new_78feb108b6472713() {
744
- const ret = new Array();
745
- return ret;
746
- };
747
-
748
- export function __wbg_now_807e54c39636c349() {
749
- const ret = Date.now();
750
- return ret;
751
- };
752
-
753
- export function __wbg_push_737cfc8c1432c2c6(arg0, arg1) {
754
- const ret = arg0.push(arg1);
755
- return ret;
756
- };
757
-
758
- export function __wbg_set_bb8cecf6a62b9f46() { return handleError(function (arg0, arg1, arg2) {
759
- const ret = Reflect.set(arg0, arg1, arg2);
760
- return ret;
761
- }, arguments) };
762
-
763
- export function __wbindgen_debug_string(arg0, arg1) {
764
- const ret = debugString(arg1);
765
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
766
- const len1 = WASM_VECTOR_LEN;
767
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
768
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
769
- };
770
-
771
- export function __wbindgen_init_externref_table() {
772
- const table = wasm.__wbindgen_export_2;
773
- const offset = table.grow(4);
774
- table.set(0, undefined);
775
- table.set(offset + 0, undefined);
776
- table.set(offset + 1, null);
777
- table.set(offset + 2, true);
778
- table.set(offset + 3, false);
779
- ;
780
- };
781
-
782
- export function __wbindgen_is_null(arg0) {
783
- const ret = arg0 === null;
784
- return ret;
785
- };
786
-
787
- export function __wbindgen_is_undefined(arg0) {
788
- const ret = arg0 === undefined;
789
- return ret;
790
- };
791
-
792
- export function __wbindgen_number_new(arg0) {
793
- const ret = arg0;
794
- return ret;
795
- };
796
-
797
- export function __wbindgen_string_get(arg0, arg1) {
798
- const obj = arg1;
799
- const ret = typeof(obj) === 'string' ? obj : undefined;
800
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
801
- var len1 = WASM_VECTOR_LEN;
802
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
803
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
804
- };
805
-
806
- export function __wbindgen_string_new(arg0, arg1) {
807
- const ret = getStringFromWasm0(arg0, arg1);
808
- return ret;
809
- };
810
-
811
- export function __wbindgen_throw(arg0, arg1) {
812
- throw new Error(getStringFromWasm0(arg0, arg1));
813
- };
700
+ } else {
701
+ throw e;
702
+ }
703
+ }
704
+ }
705
+
706
+ const bytes = await module.arrayBuffer();
707
+ return await WebAssembly.instantiate(bytes, imports);
708
+
709
+ } else {
710
+ const instance = await WebAssembly.instantiate(module, imports);
711
+
712
+ if (instance instanceof WebAssembly.Instance) {
713
+ return { instance, module };
714
+
715
+ } else {
716
+ return instance;
717
+ }
718
+ }
719
+ }
720
+
721
+ function __wbg_get_imports() {
722
+ const imports = {};
723
+ imports.wbg = {};
724
+ imports.wbg.__wbg_get_67b2ba62fc30de12 = function() { return handleError(function (arg0, arg1) {
725
+ const ret = Reflect.get(arg0, arg1);
726
+ return ret;
727
+ }, arguments) };
728
+ imports.wbg.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
729
+ const ret = arg0[arg1 >>> 0];
730
+ return ret;
731
+ };
732
+ imports.wbg.__wbg_instanceof_Object_7f2dcef8f78644a4 = function(arg0) {
733
+ let result;
734
+ try {
735
+ result = arg0 instanceof Object;
736
+ } catch (_) {
737
+ result = false;
738
+ }
739
+ const ret = result;
740
+ return ret;
741
+ };
742
+ imports.wbg.__wbg_isArray_a1eab7e0d067391b = function(arg0) {
743
+ const ret = Array.isArray(arg0);
744
+ return ret;
745
+ };
746
+ imports.wbg.__wbg_keys_5c77a08ddc2fb8a6 = function(arg0) {
747
+ const ret = Object.keys(arg0);
748
+ return ret;
749
+ };
750
+ imports.wbg.__wbg_length_e2d2a49132c1b256 = function(arg0) {
751
+ const ret = arg0.length;
752
+ return ret;
753
+ };
754
+ imports.wbg.__wbg_log_c222819a41e063d3 = function(arg0) {
755
+ console.log(arg0);
756
+ };
757
+ imports.wbg.__wbg_new_405e22f390576ce2 = function() {
758
+ const ret = new Object();
759
+ return ret;
760
+ };
761
+ imports.wbg.__wbg_new_78feb108b6472713 = function() {
762
+ const ret = new Array();
763
+ return ret;
764
+ };
765
+ imports.wbg.__wbg_now_807e54c39636c349 = function() {
766
+ const ret = Date.now();
767
+ return ret;
768
+ };
769
+ imports.wbg.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
770
+ const ret = arg0.push(arg1);
771
+ return ret;
772
+ };
773
+ imports.wbg.__wbg_set_bb8cecf6a62b9f46 = function() { return handleError(function (arg0, arg1, arg2) {
774
+ const ret = Reflect.set(arg0, arg1, arg2);
775
+ return ret;
776
+ }, arguments) };
777
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
778
+ const ret = debugString(arg1);
779
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
780
+ const len1 = WASM_VECTOR_LEN;
781
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
782
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
783
+ };
784
+ imports.wbg.__wbindgen_init_externref_table = function() {
785
+ const table = wasm.__wbindgen_export_2;
786
+ const offset = table.grow(4);
787
+ table.set(0, undefined);
788
+ table.set(offset + 0, undefined);
789
+ table.set(offset + 1, null);
790
+ table.set(offset + 2, true);
791
+ table.set(offset + 3, false);
792
+ ;
793
+ };
794
+ imports.wbg.__wbindgen_is_null = function(arg0) {
795
+ const ret = arg0 === null;
796
+ return ret;
797
+ };
798
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
799
+ const ret = arg0 === undefined;
800
+ return ret;
801
+ };
802
+ imports.wbg.__wbindgen_number_new = function(arg0) {
803
+ const ret = arg0;
804
+ return ret;
805
+ };
806
+ imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
807
+ const obj = arg1;
808
+ const ret = typeof(obj) === 'string' ? obj : undefined;
809
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
810
+ var len1 = WASM_VECTOR_LEN;
811
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
812
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
813
+ };
814
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
815
+ const ret = getStringFromWasm0(arg0, arg1);
816
+ return ret;
817
+ };
818
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
819
+ throw new Error(getStringFromWasm0(arg0, arg1));
820
+ };
821
+
822
+ return imports;
823
+ }
824
+
825
+ function __wbg_init_memory(imports, memory) {
826
+
827
+ }
828
+
829
+ function __wbg_finalize_init(instance, module) {
830
+ wasm = instance.exports;
831
+ __wbg_init.__wbindgen_wasm_module = module;
832
+ cachedDataViewMemory0 = null;
833
+ cachedInt32ArrayMemory0 = null;
834
+ cachedUint8ArrayMemory0 = null;
835
+
836
+
837
+ wasm.__wbindgen_start();
838
+ return wasm;
839
+ }
840
+
841
+ function initSync(module) {
842
+ if (wasm !== undefined) return wasm;
843
+
844
+
845
+ if (typeof module !== 'undefined') {
846
+ if (Object.getPrototypeOf(module) === Object.prototype) {
847
+ ({module} = module)
848
+ } else {
849
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
850
+ }
851
+ }
852
+
853
+ const imports = __wbg_get_imports();
854
+
855
+ __wbg_init_memory(imports);
856
+
857
+ if (!(module instanceof WebAssembly.Module)) {
858
+ module = new WebAssembly.Module(module);
859
+ }
860
+
861
+ const instance = new WebAssembly.Instance(module, imports);
862
+
863
+ return __wbg_finalize_init(instance, module);
864
+ }
865
+
866
+ async function __wbg_init(module_or_path) {
867
+ if (wasm !== undefined) return wasm;
868
+
869
+
870
+ if (typeof module_or_path !== 'undefined') {
871
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
872
+ ({module_or_path} = module_or_path)
873
+ } else {
874
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
875
+ }
876
+ }
877
+
878
+ if (typeof module_or_path === 'undefined') {
879
+ module_or_path = new URL('nucleation_bg.wasm', import.meta.url);
880
+ }
881
+ const imports = __wbg_get_imports();
882
+
883
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
884
+ module_or_path = fetch(module_or_path);
885
+ }
886
+
887
+ __wbg_init_memory(imports);
888
+
889
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
890
+
891
+ return __wbg_finalize_init(instance, module);
892
+ }
814
893
 
894
+ export { initSync };
895
+ export default __wbg_init;
package/nucleation.d.ts CHANGED
@@ -1,4 +1,123 @@
1
- import * as wasm from './nucleation_bg';
2
- export * from './nucleation_bg';
3
- declare const wasmPromise: Promise<typeof wasm>;
4
- export default wasmPromise;
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export function start(): void;
4
+ export function debug_schematic(schematic: SchematicWrapper): string;
5
+ export function debug_json_schematic(schematic: SchematicWrapper): string;
6
+ export class BlockPosition {
7
+ free(): void;
8
+ constructor(x: number, y: number, z: number);
9
+ x: number;
10
+ y: number;
11
+ z: number;
12
+ }
13
+ export class BlockStateWrapper {
14
+ free(): void;
15
+ constructor(name: string);
16
+ with_property(key: string, value: string): void;
17
+ name(): string;
18
+ properties(): any;
19
+ }
20
+ export class SchematicWrapper {
21
+ free(): void;
22
+ constructor();
23
+ from_data(data: Uint8Array): void;
24
+ from_litematic(data: Uint8Array): void;
25
+ to_litematic(): Uint8Array;
26
+ from_schematic(data: Uint8Array): void;
27
+ to_schematic(): Uint8Array;
28
+ set_block(x: number, y: number, z: number, block_name: string): void;
29
+ set_block_from_string(x: number, y: number, z: number, block_string: string): void;
30
+ copy_region(from_schematic: SchematicWrapper, min_x: number, min_y: number, min_z: number, max_x: number, max_y: number, max_z: number, target_x: number, target_y: number, target_z: number, excluded_blocks: any): void;
31
+ set_block_with_properties(x: number, y: number, z: number, block_name: string, properties: any): void;
32
+ get_block(x: number, y: number, z: number): string | undefined;
33
+ get_block_with_properties(x: number, y: number, z: number): BlockStateWrapper | undefined;
34
+ get_block_entity(x: number, y: number, z: number): any;
35
+ get_all_block_entities(): any;
36
+ print_schematic(): string;
37
+ debug_info(): string;
38
+ get_dimensions(): Int32Array;
39
+ get_block_count(): number;
40
+ get_volume(): number;
41
+ get_region_names(): string[];
42
+ blocks(): Array<any>;
43
+ chunks(chunk_width: number, chunk_height: number, chunk_length: number): Array<any>;
44
+ chunks_with_strategy(chunk_width: number, chunk_height: number, chunk_length: number, strategy: string, camera_x: number, camera_y: number, camera_z: number): Array<any>;
45
+ get_chunk_blocks(offset_x: number, offset_y: number, offset_z: number, width: number, height: number, length: number): Array<any>;
46
+ }
47
+
48
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
49
+
50
+ export interface InitOutput {
51
+ readonly memory: WebAssembly.Memory;
52
+ readonly __wbg_schematicwrapper_free: (a: number, b: number) => void;
53
+ readonly __wbg_blockstatewrapper_free: (a: number, b: number) => void;
54
+ readonly schematicwrapper_new: () => number;
55
+ readonly schematicwrapper_from_data: (a: number, b: number, c: number) => [number, number];
56
+ readonly schematicwrapper_from_litematic: (a: number, b: number, c: number) => [number, number];
57
+ readonly schematicwrapper_to_litematic: (a: number) => [number, number, number, number];
58
+ readonly schematicwrapper_from_schematic: (a: number, b: number, c: number) => [number, number];
59
+ readonly schematicwrapper_to_schematic: (a: number) => [number, number, number, number];
60
+ readonly schematicwrapper_set_block: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
61
+ readonly schematicwrapper_set_block_from_string: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
62
+ readonly schematicwrapper_copy_region: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: any) => [number, number];
63
+ readonly schematicwrapper_set_block_with_properties: (a: number, b: number, c: number, d: number, e: number, f: number, g: any) => [number, number];
64
+ readonly schematicwrapper_get_block: (a: number, b: number, c: number, d: number) => [number, number];
65
+ readonly schematicwrapper_get_block_with_properties: (a: number, b: number, c: number, d: number) => number;
66
+ readonly schematicwrapper_get_block_entity: (a: number, b: number, c: number, d: number) => any;
67
+ readonly schematicwrapper_get_all_block_entities: (a: number) => any;
68
+ readonly schematicwrapper_print_schematic: (a: number) => [number, number];
69
+ readonly schematicwrapper_debug_info: (a: number) => [number, number];
70
+ readonly schematicwrapper_get_dimensions: (a: number) => [number, number];
71
+ readonly schematicwrapper_get_block_count: (a: number) => number;
72
+ readonly schematicwrapper_get_volume: (a: number) => number;
73
+ readonly schematicwrapper_get_region_names: (a: number) => [number, number];
74
+ readonly schematicwrapper_blocks: (a: number) => any;
75
+ readonly schematicwrapper_chunks: (a: number, b: number, c: number, d: number) => any;
76
+ readonly schematicwrapper_chunks_with_strategy: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => any;
77
+ readonly schematicwrapper_get_chunk_blocks: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => any;
78
+ readonly blockstatewrapper_new: (a: number, b: number) => number;
79
+ readonly blockstatewrapper_with_property: (a: number, b: number, c: number, d: number, e: number) => void;
80
+ readonly blockstatewrapper_name: (a: number) => [number, number];
81
+ readonly blockstatewrapper_properties: (a: number) => any;
82
+ readonly debug_schematic: (a: number) => [number, number];
83
+ readonly debug_json_schematic: (a: number) => [number, number];
84
+ readonly start: () => void;
85
+ readonly __wbg_blockposition_free: (a: number, b: number) => void;
86
+ readonly __wbg_get_blockposition_x: (a: number) => number;
87
+ readonly __wbg_set_blockposition_x: (a: number, b: number) => void;
88
+ readonly __wbg_get_blockposition_y: (a: number) => number;
89
+ readonly __wbg_set_blockposition_y: (a: number, b: number) => void;
90
+ readonly __wbg_get_blockposition_z: (a: number) => number;
91
+ readonly __wbg_set_blockposition_z: (a: number, b: number) => void;
92
+ readonly blockposition_new: (a: number, b: number, c: number) => number;
93
+ readonly __wbindgen_exn_store: (a: number) => void;
94
+ readonly __externref_table_alloc: () => number;
95
+ readonly __wbindgen_export_2: WebAssembly.Table;
96
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
97
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
98
+ readonly __externref_table_dealloc: (a: number) => void;
99
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
100
+ readonly __externref_drop_slice: (a: number, b: number) => void;
101
+ readonly __wbindgen_start: () => void;
102
+ }
103
+
104
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
105
+ /**
106
+ * Instantiates the given `module`, which can either be bytes or
107
+ * a precompiled `WebAssembly.Module`.
108
+ *
109
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
110
+ *
111
+ * @returns {InitOutput}
112
+ */
113
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
114
+
115
+ /**
116
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
117
+ * for everything else, calls `WebAssembly.instantiate` directly.
118
+ *
119
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
120
+ *
121
+ * @returns {Promise<InitOutput>}
122
+ */
123
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/nucleation.js CHANGED
@@ -1,6 +1,36 @@
1
- import init, * as wasm from './nucleation_bg.js';
1
+ // Universal WASM initializer that works in both Node.js and browsers
2
+ import init_wasm from './nucleation-original.js';
2
3
 
3
- // The default export is a promise that resolves with the initialized wasm exports.
4
- // Bundlers will automatically resolve the path to the wasm file.
5
- const wasmPromise = init().then(() => wasm);
6
- export default wasmPromise;
4
+ export default async function init(input) {
5
+ // If input is provided, use it directly (manual override)
6
+ if (input !== undefined) {
7
+ return await init_wasm(input);
8
+ }
9
+
10
+ // Auto-detect environment
11
+ const isNode = typeof process !== 'undefined' && process.versions?.node;
12
+
13
+ if (isNode) {
14
+ // Node.js: read the WASM file directly
15
+ try {
16
+ const fs = await import('fs');
17
+ const path = await import('path');
18
+ const url = await import('url');
19
+
20
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
21
+ const wasmPath = path.join(__dirname, 'nucleation_bg.wasm');
22
+ const wasmBytes = fs.readFileSync(wasmPath);
23
+
24
+ return await init_wasm(wasmBytes);
25
+ } catch (error) {
26
+ console.warn('Failed to load WASM in Node.js, trying default init:', error.message);
27
+ return await init_wasm();
28
+ }
29
+ } else {
30
+ // Browser: use default fetch behavior
31
+ return await init_wasm();
32
+ }
33
+ }
34
+
35
+ // Re-export everything from the original module
36
+ export * from './nucleation-original.js';
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Nano nano@schem.at"
6
6
  ],
7
7
  "description": "A high-performance Minecraft schematic parser and utility library",
8
- "version": "0.1.18",
8
+ "version": "0.1.20",
9
9
  "license": "MIT OR Apache-2.0",
10
10
  "repository": {
11
11
  "type": "git",
@@ -13,9 +13,9 @@
13
13
  },
14
14
  "files": [
15
15
  "nucleation.js",
16
- "nucleation_bg.wasm",
17
- "nucleation_bg.js",
16
+ "nucleation-original.js",
18
17
  "nucleation.d.ts",
18
+ "nucleation_bg.wasm",
19
19
  "nucleation_bg.d.ts",
20
20
  "nucleation-cdn-loader.js",
21
21
  "README.md"
@@ -23,7 +23,6 @@
23
23
  "main": "./nucleation.js",
24
24
  "types": "./nucleation.d.ts",
25
25
  "sideEffects": [
26
- "./nucleation.js",
27
26
  "./snippets/*"
28
27
  ],
29
28
  "keywords": [