@wasm-fmt/mago_fmt 0.3.1 → 0.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/mago_fmt_vite.js CHANGED
@@ -1,8 +1,38 @@
1
- import initAsync from "./mago_fmt.js";
2
- import wasm from "./mago_fmt_bg.wasm?url";
1
+ /* @ts-self-types="./mago_fmt_web.d.ts" */
2
+ import init from "./mago_fmt_bg.wasm?init";
3
+ import * as import_bg from "./mago_fmt_bg.js";
4
+ const { format, format_with_version, __wbg_set_wasm, ...wasmImport } = import_bg;
3
5
 
4
- export default function __wbg_init(input = { module_or_path: wasm }) {
5
- return initAsync(input);
6
+ let wasm, wasmModule;
7
+
8
+ function getImports() {
9
+ return {
10
+ __proto__: null,
11
+ "./mago_fmt_bg.js": wasmImport,
12
+ };
13
+ }
14
+
15
+ function finalize_init(instance, module) {
16
+ wasm = instance.exports;
17
+ wasmModule = module;
18
+ __wbg_set_wasm(wasm);
19
+ return wasm;
20
+ }
21
+
22
+ export default async function initAsync() {
23
+ if (wasm !== void 0) return wasm;
24
+ const instance = await init(getImports());
25
+ return finalize_init(instance);
26
+ }
27
+
28
+ export function initSync(module) {
29
+ if (wasm !== void 0) return wasm;
30
+
31
+ if (!(module instanceof WebAssembly.Module)) {
32
+ module = new WebAssembly.Module(module);
33
+ }
34
+ const instance = new WebAssembly.Instance(module, getImports());
35
+ return finalize_init(instance, module);
6
36
  }
7
37
 
8
- export * from "./mago_fmt.js";
38
+ export { format, format_with_version };
@@ -0,0 +1,18 @@
1
+ import type * as InitOutput from "./mago_fmt_bg.wasm.d.ts";
2
+ declare type InitOutput = typeof InitOutput;
3
+
4
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
5
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
6
+
7
+ /**
8
+ * Initializes the WASM module asynchronously.
9
+ * @param init_input - Optional URL/path to the WASM file, or any valid InitInput
10
+ */
11
+ export default function initAsync(init_input?: InitInput | Promise<InitInput>): Promise<InitOutput>;
12
+ /**
13
+ * Initializes the WASM module synchronously.
14
+ * @param module_or_buffer - The WASM module or buffer source
15
+ */
16
+ export declare function initSync(module_or_buffer: SyncInitInput): InitOutput;
17
+
18
+ export type * from "./mago_fmt.d.ts";
@@ -0,0 +1,76 @@
1
+ /* @ts-self-types="./mago_fmt_web.d.ts" */
2
+ import * as import_bg from "./mago_fmt_bg.js";
3
+ const { format, format_with_version, __wbg_set_wasm, ...wasmImport } = import_bg;
4
+
5
+ let wasm, wasmModule;
6
+
7
+ function getImports() {
8
+ return {
9
+ __proto__: null,
10
+ "./mago_fmt_bg.js": wasmImport,
11
+ };
12
+ }
13
+
14
+ function finalize_init(instance, module) {
15
+ wasm = instance.exports;
16
+ wasmModule = module;
17
+ __wbg_set_wasm(wasm);
18
+ return wasm;
19
+ }
20
+
21
+ export function initSync(module) {
22
+ if (wasm !== void 0) return wasm;
23
+
24
+ if (!(module instanceof WebAssembly.Module)) {
25
+ module = new WebAssembly.Module(module);
26
+ }
27
+ const instance = new WebAssembly.Instance(module, getImports());
28
+ return finalize_init(instance, module);
29
+ }
30
+
31
+ export default async function initAsync(module_or_path) {
32
+ if (wasm !== void 0) return wasm;
33
+
34
+ if (module_or_path === void 0) {
35
+ module_or_path = new URL("mago_fmt_bg.wasm", import.meta.url);
36
+ }
37
+
38
+ if (
39
+ typeof module_or_path === "string" ||
40
+ (typeof Request === "function" && module_or_path instanceof Request) ||
41
+ (typeof URL === "function" && module_or_path instanceof URL)
42
+ ) {
43
+ module_or_path = fetch(module_or_path);
44
+ }
45
+
46
+ if (typeof module_or_path.then === "function") {
47
+ module_or_path = await module_or_path;
48
+ }
49
+
50
+ if (
51
+ typeof Response === "function" &&
52
+ module_or_path instanceof Response &&
53
+ typeof WebAssembly.instantiateStreaming === "function"
54
+ ) {
55
+ try {
56
+ const { instance, module } = await WebAssembly.instantiateStreaming(module_or_path, getImports());
57
+ return finalize_init(instance, module);
58
+ } catch (e) {
59
+ if (module_or_path.ok && module_or_path.headers.get("Content-Type") !== "application/wasm") {
60
+ console.warn(
61
+ "`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",
62
+ e,
63
+ );
64
+ } else {
65
+ throw e;
66
+ }
67
+ }
68
+ }
69
+
70
+ const bytes = await module_or_path.arrayBuffer();
71
+ const { instance, module } = await WebAssembly.instantiate(bytes, getImports());
72
+
73
+ return finalize_init(instance, module);
74
+ }
75
+
76
+ export { format, format_with_version };
package/package.json CHANGED
@@ -1,41 +1,60 @@
1
1
  {
2
- "name": "@wasm-fmt/mago_fmt",
3
- "type": "module",
4
- "collaborators": [
5
- "magic-akari <akari.ccino@gmail.com>"
6
- ],
7
- "description": "A WASM based PHP Formatter",
8
- "version": "0.3.1",
9
- "license": "MIT",
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/wasm-fmt/mago_fmt"
13
- },
14
- "homepage": "https://github.com/wasm-fmt/mago_fmt",
15
- "types": "mago_fmt.d.ts",
16
- "sideEffects": [
17
- "./snippets/*"
18
- ],
19
- "keywords": [
20
- "wasm",
21
- "mago",
22
- "PHP",
23
- "formatter"
24
- ],
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
- "exports": {
29
- ".": {
30
- "types": "./mago_fmt.d.ts",
31
- "node": "./mago_fmt_node.js",
32
- "default": "./mago_fmt.js"
33
- },
34
- "./vite": {
35
- "types": "./mago_fmt.d.ts",
36
- "default": "./mago_fmt_vite.js"
37
- },
38
- "./package.json": "./package.json",
39
- "./*": "./*"
40
- }
2
+ "name": "@wasm-fmt/mago_fmt",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "magic-akari <akari.ccino@gmail.com>"
6
+ ],
7
+ "description": "A WASM based PHP Formatter",
8
+ "version": "0.4.1",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/wasm-fmt/mago_fmt"
13
+ },
14
+ "homepage": "https://github.com/wasm-fmt/mago_fmt",
15
+ "types": "mago_fmt.d.ts",
16
+ "sideEffects": [
17
+ "./mago_fmt.js",
18
+ "./snippets/*"
19
+ ],
20
+ "keywords": [
21
+ "wasm",
22
+ "mago",
23
+ "PHP",
24
+ "formatter"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "types": "./mago_fmt.d.ts",
32
+ "node": "./mago_fmt_node.js",
33
+ "webpack": "./mago_fmt.js",
34
+ "default": "./mago_fmt_esm.js"
35
+ },
36
+ "./esm": {
37
+ "types": "./mago_fmt.d.ts",
38
+ "default": "./mago_fmt_esm.js"
39
+ },
40
+ "./node": {
41
+ "types": "./mago_fmt.d.ts",
42
+ "default": "./mago_fmt_node.js"
43
+ },
44
+ "./bundler": {
45
+ "types": "./mago_fmt.d.ts",
46
+ "default": "./mago_fmt.js"
47
+ },
48
+ "./web": {
49
+ "types": "./mago_fmt_web.d.ts",
50
+ "default": "./mago_fmt_web.js"
51
+ },
52
+ "./vite": {
53
+ "types": "./mago_fmt_web.d.ts",
54
+ "default": "./mago_fmt_vite.js"
55
+ },
56
+ "./wasm": "./mago_fmt_bg.wasm",
57
+ "./package.json": "./package.json",
58
+ "./*": "./*"
59
+ }
41
60
  }