@rel-packages/osu-beatmap-parser 1.0.5 → 1.0.7
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 +3 -2
- package/dist/lib/bindings.js +8 -117
- package/dist/lib/wasm-wrapper.d.ts +3 -0
- package/dist/lib/wasm-wrapper.js +65 -0
- package/package.json +6 -8
- package/prebuilds/linux-x64/osu-beatmap-parser.node +0 -0
- package/prebuilds/win32-x64/osu-beatmap-parser.node +0 -0
- package/build/osu-beatmap-parser.js +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 type { 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,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { INativeExporter } from "../types";
|
|
2
|
+
declare const native: INativeExporter;
|
|
3
|
+
export { native };
|
package/dist/lib/bindings.js
CHANGED
|
@@ -1,119 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.native = exports.init_wasm = void 0;
|
|
37
|
-
const IS_BROWSER = globalThis.window != undefined;
|
|
38
|
-
const wasm_proxy = {
|
|
39
|
-
instance: null,
|
|
40
|
-
init_promise: null,
|
|
41
|
-
get_property: (data, key) => {
|
|
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;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
86
4
|
};
|
|
87
|
-
exports
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const fs = require("fs");
|
|
94
|
-
const path = require("path");
|
|
95
|
-
const platform = process.platform;
|
|
96
|
-
const arch = process.arch;
|
|
97
|
-
const paths = [
|
|
98
|
-
// prebuilt binaries
|
|
99
|
-
path.join(__dirname, "..", "..", "prebuilds", `${platform}-${arch}`, "osu-beatmap-parser.node"),
|
|
100
|
-
path.join(__dirname, "..", "prebuilds", `${platform}-${arch}`, "osu-beatmap-parser.node"),
|
|
101
|
-
// local builds
|
|
102
|
-
path.join(__dirname, "..", "..", "build", "osu-beatmap-parser.node"),
|
|
103
|
-
path.join(__dirname, "..", "..", "build", "Release", "osu-beatmap-parser.node"),
|
|
104
|
-
path.join(__dirname, "..", "build", "osu-beatmap-parser.node"),
|
|
105
|
-
path.join(__dirname, "build", "osu-beatmap-parser.node"),
|
|
106
|
-
];
|
|
107
|
-
for (const p of paths) {
|
|
108
|
-
if (fs.existsSync(p)) {
|
|
109
|
-
return require(p);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (e) { }
|
|
114
|
-
return false;
|
|
115
|
-
};
|
|
116
|
-
exports.native = load_native_module();
|
|
117
|
-
if (exports.native == false && !IS_BROWSER) {
|
|
118
|
-
throw new Error("failed to load native module...");
|
|
119
|
-
}
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.native = void 0;
|
|
7
|
+
const node_gyp_build_1 = __importDefault(require("node-gyp-build"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const native = (0, node_gyp_build_1.default)(path_1.default.join(__dirname, "..", ".."));
|
|
10
|
+
exports.native = native;
|
|
@@ -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.7",
|
|
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:native &&
|
|
17
|
+
"example:wasm": "bun run compile:wasm && bun x http-server . -p 8080 -c-1 -o /examples/wasm/",
|
|
18
|
+
"example:node": "bun run compile:native && 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": {
|
|
@@ -46,6 +42,8 @@
|
|
|
46
42
|
"tsx": "^4.21.0",
|
|
47
43
|
"typescript": "^5.9.3"
|
|
48
44
|
},
|
|
49
|
-
"dependencies": {
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"node-gyp-build": "^4.8.4"
|
|
47
|
+
},
|
|
50
48
|
"optionalDependencies": {}
|
|
51
49
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|