rdkit-esm 0.2.0 → 0.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
package/dist/index.js
CHANGED
|
@@ -638,7 +638,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
638
638
|
node.node_ops = MEMFS.ops_table.file.node;
|
|
639
639
|
node.stream_ops = MEMFS.ops_table.file.stream;
|
|
640
640
|
node.usedBytes = 0;
|
|
641
|
-
node.contents =
|
|
641
|
+
node.contents = MEMFS.emptyFileContents ??= new Uint8Array(0);
|
|
642
642
|
} else if (FS.isLink(node.mode)) {
|
|
643
643
|
node.node_ops = MEMFS.ops_table.link.node;
|
|
644
644
|
node.stream_ops = MEMFS.ops_table.link.stream;
|
|
@@ -654,30 +654,23 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
654
654
|
return node;
|
|
655
655
|
},
|
|
656
656
|
getFileDataAsTypedArray(node) {
|
|
657
|
-
|
|
658
|
-
if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes);
|
|
659
|
-
return new Uint8Array(node.contents);
|
|
657
|
+
return node.contents.subarray(0, node.usedBytes);
|
|
660
658
|
},
|
|
661
659
|
expandFileStorage(node, newCapacity) {
|
|
662
|
-
var prevCapacity = node.contents
|
|
660
|
+
var prevCapacity = node.contents.length;
|
|
663
661
|
if (prevCapacity >= newCapacity) return;
|
|
664
662
|
newCapacity = Math.max(newCapacity, prevCapacity * (prevCapacity < 1024 * 1024 ? 2 : 1.125) >>> 0);
|
|
665
|
-
if (prevCapacity
|
|
666
|
-
var oldContents = node
|
|
663
|
+
if (prevCapacity) newCapacity = Math.max(newCapacity, 256);
|
|
664
|
+
var oldContents = MEMFS.getFileDataAsTypedArray(node);
|
|
667
665
|
node.contents = new Uint8Array(newCapacity);
|
|
668
|
-
|
|
666
|
+
node.contents.set(oldContents);
|
|
669
667
|
},
|
|
670
668
|
resizeFileStorage(node, newSize) {
|
|
671
669
|
if (node.usedBytes == newSize) return;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
var oldContents = node.contents;
|
|
677
|
-
node.contents = new Uint8Array(newSize);
|
|
678
|
-
if (oldContents) node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
|
|
679
|
-
node.usedBytes = newSize;
|
|
680
|
-
}
|
|
670
|
+
var oldContents = node.contents;
|
|
671
|
+
node.contents = new Uint8Array(newSize);
|
|
672
|
+
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
|
|
673
|
+
node.usedBytes = newSize;
|
|
681
674
|
},
|
|
682
675
|
node_ops: {
|
|
683
676
|
getattr(node) {
|
|
@@ -764,8 +757,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
764
757
|
var contents = stream.node.contents;
|
|
765
758
|
if (position >= stream.node.usedBytes) return 0;
|
|
766
759
|
var size = Math.min(stream.node.usedBytes - position, length);
|
|
767
|
-
|
|
768
|
-
else for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
|
|
760
|
+
buffer.set(contents.subarray(position, position + size), offset);
|
|
769
761
|
return size;
|
|
770
762
|
},
|
|
771
763
|
write(stream, buffer, offset, length, position, canOwn) {
|
|
@@ -773,24 +765,17 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
773
765
|
if (!length) return 0;
|
|
774
766
|
var node = stream.node;
|
|
775
767
|
node.mtime = node.ctime = Date.now();
|
|
776
|
-
if (
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
787
|
-
return length;
|
|
788
|
-
}
|
|
768
|
+
if (canOwn) {
|
|
769
|
+
node.contents = buffer.subarray(offset, offset + length);
|
|
770
|
+
node.usedBytes = length;
|
|
771
|
+
} else if (node.usedBytes === 0 && position === 0) {
|
|
772
|
+
node.contents = buffer.slice(offset, offset + length);
|
|
773
|
+
node.usedBytes = length;
|
|
774
|
+
} else {
|
|
775
|
+
MEMFS.expandFileStorage(node, position + length);
|
|
776
|
+
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
777
|
+
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
789
778
|
}
|
|
790
|
-
MEMFS.expandFileStorage(node, position + length);
|
|
791
|
-
if (node.contents.subarray && buffer.subarray) node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
792
|
-
else for (var i = 0; i < length; i++) node.contents[position + i] = buffer[offset + i];
|
|
793
|
-
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
794
779
|
return length;
|
|
795
780
|
},
|
|
796
781
|
llseek(stream, offset, whence) {
|
|
@@ -807,7 +792,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
807
792
|
var ptr;
|
|
808
793
|
var allocated;
|
|
809
794
|
var contents = stream.node.contents;
|
|
810
|
-
if (!(flags & 2) && contents
|
|
795
|
+
if (!(flags & 2) && contents.buffer === HEAP8.buffer) {
|
|
811
796
|
allocated = false;
|
|
812
797
|
ptr = contents.byteOffset;
|
|
813
798
|
} else {
|
|
@@ -832,6 +817,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
832
817
|
}
|
|
833
818
|
};
|
|
834
819
|
var FS_modeStringToFlags = (str) => {
|
|
820
|
+
if (typeof str != "string") return str;
|
|
835
821
|
var flags = {
|
|
836
822
|
r: 0,
|
|
837
823
|
"r+": 2,
|
|
@@ -843,6 +829,11 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
843
829
|
if (typeof flags == "undefined") throw new Error(`Unknown file open mode: ${str}`);
|
|
844
830
|
return flags;
|
|
845
831
|
};
|
|
832
|
+
var FS_fileDataToTypedArray = (data) => {
|
|
833
|
+
if (typeof data == "string") data = intArrayFromString(data, true);
|
|
834
|
+
if (!data.subarray) data = new Uint8Array(data);
|
|
835
|
+
return data;
|
|
836
|
+
};
|
|
846
837
|
var FS_getMode = (canRead, canWrite) => {
|
|
847
838
|
var mode = 0;
|
|
848
839
|
if (canRead) mode |= 365;
|
|
@@ -1527,7 +1518,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1527
1518
|
},
|
|
1528
1519
|
open(path, flags, mode = 438) {
|
|
1529
1520
|
if (path === "") throw new FS.ErrnoError(44);
|
|
1530
|
-
flags =
|
|
1521
|
+
flags = FS_modeStringToFlags(flags);
|
|
1531
1522
|
if (flags & 64) mode = mode & 4095 | 32768;
|
|
1532
1523
|
else mode = 0;
|
|
1533
1524
|
var node;
|
|
@@ -1653,9 +1644,8 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1653
1644
|
writeFile(path, data, opts = {}) {
|
|
1654
1645
|
opts.flags = opts.flags || 577;
|
|
1655
1646
|
var stream = FS.open(path, opts.flags, opts.mode);
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
else abort("Unsupported data type");
|
|
1647
|
+
data = FS_fileDataToTypedArray(data);
|
|
1648
|
+
FS.write(stream, data, 0, data.byteLength, void 0, opts.canOwn);
|
|
1659
1649
|
FS.close(stream);
|
|
1660
1650
|
},
|
|
1661
1651
|
cwd: () => FS.currentPath,
|
|
@@ -1822,11 +1812,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
1822
1812
|
var mode = FS_getMode(canRead, canWrite);
|
|
1823
1813
|
var node = FS.create(path, mode);
|
|
1824
1814
|
if (data) {
|
|
1825
|
-
|
|
1826
|
-
var arr = new Array(data.length);
|
|
1827
|
-
for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
|
|
1828
|
-
data = arr;
|
|
1829
|
-
}
|
|
1815
|
+
data = FS_fileDataToTypedArray(data);
|
|
1830
1816
|
FS.chmod(node, mode | 146);
|
|
1831
1817
|
var stream = FS.open(node, 577);
|
|
1832
1818
|
FS.write(stream, data, 0, data.length, 0, canOwn);
|
|
@@ -3852,7 +3838,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
|
|
|
3852
3838
|
//#endregion
|
|
3853
3839
|
//#region MinimalLib/dist/RDKit_minimal.wasm?url
|
|
3854
3840
|
var import_RDKit_minimal = /* @__PURE__ */ __toESM(require_RDKit_minimal(), 1);
|
|
3855
|
-
var RDKit_minimal_default = "
|
|
3841
|
+
var RDKit_minimal_default = "4c709c835a45b633.wasm";
|
|
3856
3842
|
|
|
3857
3843
|
//#endregion
|
|
3858
3844
|
//#region src/mol-array.ts
|
|
@@ -4694,16 +4680,26 @@ var RDKit = class {
|
|
|
4694
4680
|
* Resolves the WASM URL for the current environment.
|
|
4695
4681
|
* In browsers, uses `import.meta.url` to resolve the WASM filename relative
|
|
4696
4682
|
* to the JS bundle's location — works regardless of where the page is served.
|
|
4697
|
-
* In Node.js (e.g. vitest), the `?url` import returns a root-relative path
|
|
4698
|
-
* like `/src/minimalib/RDKit_minimal.wasm` which needs to be joined with cwd.
|
|
4699
4683
|
*/
|
|
4700
4684
|
function resolveWasmUrl() {
|
|
4701
4685
|
const url = RDKit_minimal_default;
|
|
4702
|
-
if (typeof process !== "undefined" && process.versions != null && process.versions.node != null && url.startsWith("/") && !url.startsWith("//")) return process.cwd() + url;
|
|
4703
4686
|
return new URL(url, import.meta.url).href;
|
|
4704
4687
|
}
|
|
4705
4688
|
async function initRDKit(options, constructor = RDKit) {
|
|
4706
|
-
|
|
4689
|
+
const locateFile = options?.locateFile ?? (() => resolveWasmUrl());
|
|
4690
|
+
const moduleArgs = { locateFile };
|
|
4691
|
+
if (typeof process !== "undefined" && process.versions?.node) {
|
|
4692
|
+
const fs = await import("node:fs");
|
|
4693
|
+
const { fileURLToPath } = await import("node:url");
|
|
4694
|
+
const wasmFileUrl = locateFile();
|
|
4695
|
+
let wasmPath = wasmFileUrl.startsWith("file://") ? fileURLToPath(wasmFileUrl) : wasmFileUrl;
|
|
4696
|
+
if (!fs.existsSync(wasmPath)) {
|
|
4697
|
+
const { join } = await import("node:path");
|
|
4698
|
+
wasmPath = join(process.cwd(), wasmPath);
|
|
4699
|
+
}
|
|
4700
|
+
moduleArgs.wasmBinary = fs.readFileSync(wasmPath);
|
|
4701
|
+
}
|
|
4702
|
+
return new constructor(await (0, import_RDKit_minimal.default)(moduleArgs));
|
|
4707
4703
|
}
|
|
4708
4704
|
|
|
4709
4705
|
//#endregion
|