@rel-packages/osu-beatmap-parser 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -2
- package/dist/lib/bindings.d.ts +1 -2
- package/dist/lib/bindings.js +36 -110
- package/dist/lib/wasm-wrapper.d.ts +3 -0
- package/dist/lib/wasm-wrapper.js +65 -0
- package/package.json +3 -7
- package/prebuilds/{prebuilds-win32-x64/win32-x64 → win32-x64}/osu-beatmap-parser.node +0 -0
- package/build/osu-beatmap-parser.js +0 -0
- /package/prebuilds/{prebuilds-linux-x64/linux-x64 → linux-x64}/osu-beatmap-parser.node +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OsuKey, OsuInput } from "./types";
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export
|
|
5
|
-
export { OsuKey, OsuInput, init_wasm };
|
|
2
|
+
export declare const get_property: (data: Uint8Array, key: OsuKey) => string;
|
|
3
|
+
export declare const get_properties: (input: Uint8Array | OsuInput, keys: OsuKey[]) => Record<string, string>;
|
|
4
|
+
export { OsuKey, OsuInput };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.get_properties = exports.get_property = void 0;
|
|
4
4
|
const bindings_1 = require("./lib/bindings");
|
|
5
|
-
Object.defineProperty(exports, "init_wasm", { enumerable: true, get: function () { return bindings_1.init_wasm; } });
|
|
6
5
|
const get_property = (data, key) => {
|
|
7
6
|
return bindings_1.native.get_property(data, key);
|
|
8
7
|
};
|
package/dist/lib/bindings.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare let native: any;
|
|
1
|
+
export declare const native: any;
|
package/dist/lib/bindings.js
CHANGED
|
@@ -1,119 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.native =
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (wasm_proxy.instance == null)
|
|
43
|
-
throw Error("WASM not loaded yet...");
|
|
44
|
-
const wasm_inst = wasm_proxy.instance;
|
|
45
|
-
const buffer_ptr = wasm_inst._malloc(data.length);
|
|
46
|
-
wasm_inst.HEAPU8.set(data, buffer_ptr);
|
|
47
|
-
const result = wasm_inst.get_property(buffer_ptr, data.length, key);
|
|
48
|
-
wasm_inst._free(buffer_ptr);
|
|
49
|
-
return result;
|
|
50
|
-
},
|
|
51
|
-
get_properties: (data, keys) => {
|
|
52
|
-
if (wasm_proxy.instance == null)
|
|
53
|
-
throw Error("WASM not loaded yet...");
|
|
54
|
-
const wasm_inst = wasm_proxy.instance;
|
|
55
|
-
const buffer_ptr = wasm_inst._malloc(data.length);
|
|
56
|
-
wasm_inst.HEAPU8.set(data, buffer_ptr);
|
|
57
|
-
const result = wasm_inst.get_properties(buffer_ptr, data.length, keys);
|
|
58
|
-
wasm_inst._free(buffer_ptr);
|
|
59
|
-
return result;
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const init_wasm = async () => {
|
|
63
|
-
if (!IS_BROWSER)
|
|
64
|
-
return;
|
|
65
|
-
if (wasm_proxy.instance)
|
|
66
|
-
return;
|
|
67
|
-
if (wasm_proxy.init_promise)
|
|
68
|
-
return wasm_proxy.init_promise;
|
|
69
|
-
wasm_proxy.init_promise = (async () => {
|
|
70
|
-
// try dynamic import first, fallback to globalThis
|
|
71
|
-
let create_func;
|
|
72
|
-
try {
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
const mod = await Promise.resolve().then(() => __importStar(require("../../build/osu-beatmap-parser.js")));
|
|
75
|
-
create_func = mod.default || mod.create_osu_parser;
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
create_func = globalThis.create_osu_parser;
|
|
79
|
-
}
|
|
80
|
-
if (!create_func) {
|
|
81
|
-
throw Error("create_osu_parser not found");
|
|
82
|
-
}
|
|
83
|
-
wasm_proxy.instance = await create_func();
|
|
84
|
-
})();
|
|
85
|
-
return wasm_proxy.init_promise;
|
|
3
|
+
exports.native = void 0;
|
|
4
|
+
const DEBUG = typeof process != "undefined" && process.env?.OSU_PARSER_DEBUG == "1";
|
|
5
|
+
const log_debug = (...args) => {
|
|
6
|
+
if (DEBUG) {
|
|
7
|
+
console.log("[osu-beatmap-parser]", ...args);
|
|
8
|
+
}
|
|
86
9
|
};
|
|
87
|
-
exports.init_wasm = init_wasm;
|
|
88
10
|
const load_native_module = () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const path = require("path");
|
|
13
|
+
const platform = process.platform;
|
|
14
|
+
const arch = process.arch;
|
|
15
|
+
log_debug(`loading native module for ${platform}-${arch}`);
|
|
16
|
+
log_debug(`__dirname: ${__dirname}`);
|
|
17
|
+
const paths = [
|
|
18
|
+
// prebuilt binaries
|
|
19
|
+
path.join(__dirname, "..", "..", "prebuilds", `${platform}-${arch}`, "osu-beatmap-parser.node"),
|
|
20
|
+
path.join(__dirname, "..", "prebuilds", `${platform}-${arch}`, "osu-beatmap-parser.node"),
|
|
21
|
+
// local dev builds
|
|
22
|
+
path.join(__dirname, "..", "..", "build", "osu-beatmap-parser.node"),
|
|
23
|
+
path.join(__dirname, "..", "..", "build", "Release", "osu-beatmap-parser.node"),
|
|
24
|
+
path.join(__dirname, "..", "build", "osu-beatmap-parser.node"),
|
|
25
|
+
path.join(__dirname, "build", "osu-beatmap-parser.node"),
|
|
26
|
+
];
|
|
27
|
+
for (const p of paths) {
|
|
28
|
+
const resolved = path.resolve(p);
|
|
29
|
+
const exists = fs.existsSync(resolved);
|
|
30
|
+
log_debug(`checking: ${resolved} -> ${exists ? "found" : "not found"}`);
|
|
31
|
+
if (exists) {
|
|
32
|
+
log_debug(`loading native module from: ${resolved}`);
|
|
33
|
+
return require(resolved);
|
|
111
34
|
}
|
|
112
35
|
}
|
|
113
|
-
|
|
114
|
-
return
|
|
36
|
+
log_debug("no native module found in any path");
|
|
37
|
+
return null;
|
|
115
38
|
};
|
|
116
39
|
exports.native = load_native_module();
|
|
117
|
-
if (exports.native ==
|
|
118
|
-
|
|
40
|
+
if (exports.native == null) {
|
|
41
|
+
const platform = process.platform;
|
|
42
|
+
const arch = process.arch;
|
|
43
|
+
throw new Error(`failed to load native module for ${platform}-${arch}. ` +
|
|
44
|
+
`Set OSU_PARSER_DEBUG=1 for more info.`);
|
|
119
45
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_properties = exports.get_property = exports.init_wasm = void 0;
|
|
4
|
+
console.log("[parser] wrapper loaded");
|
|
5
|
+
let wasm_instance = null;
|
|
6
|
+
let init_promise = null;
|
|
7
|
+
const get_factory = () => {
|
|
8
|
+
return globalThis.create_osu_parser;
|
|
9
|
+
};
|
|
10
|
+
const init_wasm = async () => {
|
|
11
|
+
if (wasm_instance)
|
|
12
|
+
return;
|
|
13
|
+
if (init_promise)
|
|
14
|
+
return init_promise;
|
|
15
|
+
init_promise = (async () => {
|
|
16
|
+
const factory = get_factory();
|
|
17
|
+
if (typeof factory !== "function") {
|
|
18
|
+
throw new Error("create_osu_parser not found in global scope");
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
wasm_instance = await factory();
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
return init_promise;
|
|
29
|
+
};
|
|
30
|
+
exports.init_wasm = init_wasm;
|
|
31
|
+
const get_property = (data, key) => {
|
|
32
|
+
if (wasm_instance == null)
|
|
33
|
+
throw new Error("wasm not initialized");
|
|
34
|
+
const buffer_ptr = wasm_instance._malloc(data.length);
|
|
35
|
+
wasm_instance.HEAPU8.set(data, buffer_ptr);
|
|
36
|
+
try {
|
|
37
|
+
return wasm_instance.get_property(buffer_ptr, data.length, key);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
wasm_instance._free(buffer_ptr);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.get_property = get_property;
|
|
44
|
+
const get_properties = (data, keys) => {
|
|
45
|
+
if (wasm_instance == null)
|
|
46
|
+
throw new Error("wasm not initialized");
|
|
47
|
+
const buffer_ptr = wasm_instance._malloc(data.length);
|
|
48
|
+
wasm_instance.HEAPU8.set(data, buffer_ptr);
|
|
49
|
+
try {
|
|
50
|
+
return wasm_instance.get_properties(buffer_ptr, data.length, keys);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
wasm_instance._free(buffer_ptr);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.get_properties = get_properties;
|
|
57
|
+
if (typeof window != "undefined") {
|
|
58
|
+
window.beatmap_parser = {
|
|
59
|
+
init_wasm: exports.init_wasm,
|
|
60
|
+
get_property: exports.get_property,
|
|
61
|
+
get_properties: exports.get_properties,
|
|
62
|
+
};
|
|
63
|
+
console.log(window.beatmap_parser);
|
|
64
|
+
console.log("[parser] attached to window");
|
|
65
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rel-packages/osu-beatmap-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": ".osu parser for nodejs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"compile:wasm": "tsx scripts/build.ts wasm",
|
|
15
15
|
"compile:tsc": "tsc",
|
|
16
16
|
"build": "tsx scripts/build.ts all && npm run compile:tsc",
|
|
17
|
-
"example:wasm": "bun run compile:wasm && bun
|
|
18
|
-
"example:node": "bun run compile:
|
|
17
|
+
"example:wasm": "bun run compile:wasm && bun x http-server . -p 8080 -c-1 -o /examples/wasm/",
|
|
18
|
+
"example:node": "bun run compile:node && bun run examples/node/index.ts"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"osu",
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"dist/",
|
|
34
34
|
"prebuilds/",
|
|
35
|
-
"build/*.node",
|
|
36
|
-
"build/*.wasm",
|
|
37
|
-
"build/*.js",
|
|
38
|
-
"lib/bindings.ts",
|
|
39
35
|
"README.md"
|
|
40
36
|
],
|
|
41
37
|
"devDependencies": {
|
|
index d90453c..81b131f 100644
|
|
|
Binary file
|
|
Binary file
|
|
File without changes
|