@rel-packages/osu-beatmap-parser 1.1.2 → 1.4.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.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  ## osu-beatmap-parser
2
+
2
3
  native .osu beatmap parser used on [osu-stuff](https://github.com/mezleca/osu-stuff)
3
4
 
4
5
  ## installation
@@ -8,4 +9,5 @@ npm install @rel-packages/osu-beatmap-parser
8
9
  ```
9
10
 
10
11
  ## usage
12
+
11
13
  check [examples](https://github.com/mezleca/osu-beatmap-parser/tree/main/examples) for wasm / nodejs usage examples.
package/dist/index.d.ts CHANGED
@@ -3,5 +3,12 @@ export declare const get_property: (data: Uint8Array, key: OsuKey) => string;
3
3
  export declare const get_properties: (input: Uint8Array | OsuInput, keys: OsuKey[]) => Record<string, string>;
4
4
  export declare const get_section: (data: Uint8Array, section: string) => string[];
5
5
  export declare const parse: (input: Uint8Array | OsuInput) => OsuFileFormat;
6
+ declare const parser: {
7
+ get_property: (data: Uint8Array, key: OsuKey) => string;
8
+ get_properties: (input: Uint8Array | OsuInput, keys: OsuKey[]) => Record<string, string>;
9
+ get_section: (data: Uint8Array, section: string) => string[];
10
+ parse: (input: Uint8Array | OsuInput) => OsuFileFormat;
11
+ };
6
12
  export type { OsuKey, OsuInput, OsuFileFormat };
7
13
  export * from "./types/types";
14
+ export default parser;
package/dist/index.js CHANGED
@@ -38,4 +38,11 @@ const parse = (input) => {
38
38
  return bindings_1.native.parse(data);
39
39
  };
40
40
  exports.parse = parse;
41
+ const parser = {
42
+ get_property: exports.get_property,
43
+ get_properties: exports.get_properties,
44
+ get_section: exports.get_section,
45
+ parse: exports.parse
46
+ };
41
47
  __exportStar(require("./types/types"), exports);
48
+ exports.default = parser;
@@ -0,0 +1,2 @@
1
+ import { init_wasm, get_property, get_properties, get_section, parse, set_wasm_factory, is_wasm_ready, init_wasm_from_url } from "./wasm-wrapper";
2
+ export { init_wasm, get_property, get_properties, get_section, parse, set_wasm_factory, is_wasm_ready, init_wasm_from_url, };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init_wasm_from_url = exports.is_wasm_ready = exports.set_wasm_factory = exports.parse = exports.get_section = exports.get_properties = exports.get_property = exports.init_wasm = void 0;
4
+ const wasm_wrapper_1 = require("./wasm-wrapper");
5
+ Object.defineProperty(exports, "init_wasm", { enumerable: true, get: function () { return wasm_wrapper_1.init_wasm; } });
6
+ Object.defineProperty(exports, "get_property", { enumerable: true, get: function () { return wasm_wrapper_1.get_property; } });
7
+ Object.defineProperty(exports, "get_properties", { enumerable: true, get: function () { return wasm_wrapper_1.get_properties; } });
8
+ Object.defineProperty(exports, "get_section", { enumerable: true, get: function () { return wasm_wrapper_1.get_section; } });
9
+ Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return wasm_wrapper_1.parse; } });
10
+ Object.defineProperty(exports, "set_wasm_factory", { enumerable: true, get: function () { return wasm_wrapper_1.set_wasm_factory; } });
11
+ Object.defineProperty(exports, "is_wasm_ready", { enumerable: true, get: function () { return wasm_wrapper_1.is_wasm_ready; } });
12
+ Object.defineProperty(exports, "init_wasm_from_url", { enumerable: true, get: function () { return wasm_wrapper_1.init_wasm_from_url; } });
13
+ const api = {
14
+ init_wasm: wasm_wrapper_1.init_wasm,
15
+ get_property: wasm_wrapper_1.get_property,
16
+ get_properties: wasm_wrapper_1.get_properties,
17
+ get_section: wasm_wrapper_1.get_section,
18
+ parse: wasm_wrapper_1.parse,
19
+ set_wasm_factory: wasm_wrapper_1.set_wasm_factory,
20
+ is_wasm_ready: wasm_wrapper_1.is_wasm_ready,
21
+ init_wasm_from_url: wasm_wrapper_1.init_wasm_from_url,
22
+ };
23
+ globalThis.beatmap_parser = api;
@@ -1,6 +1,16 @@
1
1
  import type { OsuFileFormat } from "../types/types";
2
- export declare const init_wasm: () => Promise<void>;
2
+ type wasm_init_options = {
3
+ factory?: (module_config?: Record<string, unknown>) => any;
4
+ script_url?: string;
5
+ global_name?: string;
6
+ module_config?: Record<string, unknown>;
7
+ };
8
+ export declare const set_wasm_factory: (factory: (module_config?: Record<string, unknown>) => any, global_name?: string) => void;
9
+ export declare const is_wasm_ready: () => boolean;
10
+ export declare const init_wasm: (options?: wasm_init_options) => Promise<void>;
11
+ export declare const init_wasm_from_url: (script_url: string, module_config?: Record<string, unknown>, global_name?: string) => Promise<void>;
3
12
  export declare const get_property: (data: Uint8Array, key: string) => string;
4
13
  export declare const get_properties: (data: Uint8Array, keys: string[]) => Record<string, string>;
5
14
  export declare const get_section: (data: Uint8Array, section: string) => string[];
6
15
  export declare const parse: (data: Uint8Array) => OsuFileFormat;
16
+ export {};
@@ -1,33 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = exports.get_section = exports.get_properties = exports.get_property = exports.init_wasm = void 0;
4
- console.log("[parser] wrapper loaded");
3
+ exports.parse = exports.get_section = exports.get_properties = exports.get_property = exports.init_wasm_from_url = exports.init_wasm = exports.is_wasm_ready = exports.set_wasm_factory = void 0;
5
4
  let wasm_instance = null;
6
5
  let init_promise = null;
7
- const get_factory = () => {
8
- return globalThis.create_osu_parser;
6
+ let wasm_factory = null;
7
+ let wasm_global_name = "create_osu_parser";
8
+ const script_loaders = new Map();
9
+ const get_global_name = (options) => {
10
+ return options.global_name || wasm_global_name;
9
11
  };
10
- const init_wasm = async () => {
12
+ const load_script = (script_url) => {
13
+ const existing = script_loaders.get(script_url);
14
+ if (existing)
15
+ return existing;
16
+ const loader = new Promise((resolve, reject) => {
17
+ if (typeof document == "undefined") {
18
+ reject(new Error("script loading requires a browser environment"));
19
+ return;
20
+ }
21
+ const script = document.createElement("script");
22
+ script.src = script_url;
23
+ script.async = true;
24
+ script.onload = () => resolve();
25
+ script.onerror = () => reject(new Error(`failed to load wasm script: ${script_url}`));
26
+ document.head.appendChild(script);
27
+ });
28
+ script_loaders.set(script_url, loader);
29
+ return loader;
30
+ };
31
+ const resolve_factory = async (options) => {
32
+ if (options.factory)
33
+ return options.factory;
34
+ if (wasm_factory)
35
+ return wasm_factory;
36
+ if (options.script_url) {
37
+ await load_script(options.script_url);
38
+ }
39
+ const global_name = get_global_name(options);
40
+ return globalThis[global_name];
41
+ };
42
+ const set_wasm_factory = (factory, global_name) => {
43
+ wasm_factory = factory;
44
+ if (global_name) {
45
+ wasm_global_name = global_name;
46
+ }
47
+ };
48
+ exports.set_wasm_factory = set_wasm_factory;
49
+ const is_wasm_ready = () => {
50
+ return wasm_instance != null;
51
+ };
52
+ exports.is_wasm_ready = is_wasm_ready;
53
+ const init_wasm = async (options = {}) => {
11
54
  if (wasm_instance)
12
55
  return;
13
56
  if (init_promise)
14
57
  return init_promise;
15
58
  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;
59
+ const factory = await resolve_factory(options);
60
+ if (typeof factory != "function") {
61
+ const global_name = get_global_name(options);
62
+ throw new Error(`wasm factory not found: ${global_name}`);
26
63
  }
64
+ wasm_instance = await factory(options.module_config);
27
65
  })();
28
- return init_promise;
66
+ return init_promise.catch((err) => {
67
+ init_promise = null;
68
+ throw err;
69
+ });
29
70
  };
30
71
  exports.init_wasm = init_wasm;
72
+ const init_wasm_from_url = async (script_url, module_config = {}, global_name) => {
73
+ return (0, exports.init_wasm)({ script_url, module_config, global_name });
74
+ };
75
+ exports.init_wasm_from_url = init_wasm_from_url;
31
76
  const get_property = (data, key) => {
32
77
  if (wasm_instance == null)
33
78
  throw new Error("wasm not initialized");
@@ -80,14 +125,3 @@ const parse = (data) => {
80
125
  }
81
126
  };
82
127
  exports.parse = parse;
83
- if (typeof window != "undefined") {
84
- window.beatmap_parser = {
85
- init_wasm: exports.init_wasm,
86
- get_property: exports.get_property,
87
- get_properties: exports.get_properties,
88
- get_section: exports.get_section,
89
- parse: exports.parse,
90
- };
91
- console.log(window.beatmap_parser);
92
- console.log("[parser] attached to window");
93
- }
package/package.json CHANGED
@@ -1,49 +1,55 @@
1
1
  {
2
- "name": "@rel-packages/osu-beatmap-parser",
3
- "version": "1.1.2",
4
- "description": ".osu parser for nodejs",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "homepage": "https://github.com/mezleca/osu-beatmap-parser",
8
- "scripts": {
9
- "update:patch": "npm version patch && git push --follow-tags",
10
- "update:minor": "npm version minor && git push --follow-tags",
11
- "update:major": "npm version major && git push --follow-tags",
12
- "prepublishOnly": "npm run compile:tsc && mkdir -p lib",
13
- "compile:native": "tsx scripts/build.ts native",
14
- "compile:wasm": "tsx scripts/build.ts wasm",
15
- "compile:tsc": "tsc",
16
- "build": "tsx scripts/build.ts all && npm run compile:tsc",
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
- },
20
- "keywords": [
21
- "osu",
22
- "beatmap",
23
- "parser",
24
- "native"
25
- ],
26
- "author": "",
27
- "license": "ISC",
28
- "repository": {
29
- "url": "https://github.com/mezleca/osu-beatmap-parser.git"
30
- },
31
- "type": "commonjs",
32
- "files": [
33
- "dist/",
34
- "prebuilds/",
35
- "README.md"
36
- ],
37
- "devDependencies": {
38
- "@types/bindings": "^1.5.5",
39
- "@types/node": "^24.10.1",
40
- "cmake-js": "^7.4.0",
41
- "node-addon-api": "^8.5.0",
42
- "tsx": "^4.21.0",
43
- "typescript": "^5.9.3"
44
- },
45
- "dependencies": {
46
- "node-gyp-build": "^4.8.4"
47
- },
48
- "optionalDependencies": {}
2
+ "name": "@rel-packages/osu-beatmap-parser",
3
+ "version": "1.4.1",
4
+ "description": ".osu parser for nodejs",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "homepage": "https://github.com/mezleca/osu-beatmap-parser",
8
+ "scripts": {
9
+ "update:patch": "npm version patch && git push --follow-tags",
10
+ "update:minor": "npm version minor && git push --follow-tags",
11
+ "update:major": "npm version major && git push --follow-tags",
12
+ "prepublishOnly": "npm run compile:tsc && mkdir -p lib",
13
+ "compile:native": "bun scripts/build.ts native",
14
+ "compile:wasm": "bun scripts/build.ts wasm",
15
+ "compile:tsc": "tsc",
16
+ "format": "prettier --write . --ignore-unknown",
17
+ "pretest": "bun run format",
18
+ "test": "bun test",
19
+ "prebuild": "bun run format",
20
+ "build": "bun scripts/build.ts all && npm run compile:tsc",
21
+ "example:wasm": "bun run compile:wasm && bun x http-server . -p 8080 -c-1 -o /examples/wasm/",
22
+ "example:node": "bun run compile:native && bun run examples/node/index.ts"
23
+ },
24
+ "keywords": [
25
+ "osu",
26
+ "beatmap",
27
+ "parser",
28
+ "native"
29
+ ],
30
+ "author": "",
31
+ "license": "ISC",
32
+ "repository": {
33
+ "url": "https://github.com/mezleca/osu-beatmap-parser.git"
34
+ },
35
+ "type": "commonjs",
36
+ "files": [
37
+ "dist/",
38
+ "prebuilds/",
39
+ "README.md"
40
+ ],
41
+ "devDependencies": {
42
+ "@rel-packages/osu-beatmap-parser": "^1.1.2",
43
+ "@types/bindings": "^1.5.5",
44
+ "@types/node": "^24.10.4",
45
+ "cmake-js": "^7.4.0",
46
+ "node-addon-api": "^8.5.0",
47
+ "prettier": "^3.6.2",
48
+ "prettier-plugin-svelte": "^3.4.1",
49
+ "tsx": "^4.21.0",
50
+ "typescript": "^5.9.3"
51
+ },
52
+ "dependencies": {
53
+ "node-gyp-build": "^4.8.4"
54
+ }
49
55
  }