@xyo-network/wasm 2.74.4 → 2.75.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.
Files changed (38) hide show
  1. package/dist/browser/WasmSupport.cjs +164 -0
  2. package/dist/browser/WasmSupport.cjs.map +1 -0
  3. package/dist/browser/WasmSupport.d.mts.map +1 -0
  4. package/dist/browser/WasmSupport.d.ts.map +1 -0
  5. package/dist/browser/WasmSupport.js +160 -0
  6. package/dist/browser/WasmSupport.js.map +1 -0
  7. package/dist/{index.js → browser/index.cjs} +1 -6
  8. package/dist/browser/index.cjs.map +1 -0
  9. package/dist/{index.d.mts.map → browser/index.d.mts.map} +1 -1
  10. package/dist/{index.d.ts.map → browser/index.d.ts.map} +1 -1
  11. package/dist/{index.mjs → browser/index.js} +1 -1
  12. package/dist/browser/index.js.map +1 -0
  13. package/dist/node/WasmSupport.d.mts +92 -0
  14. package/dist/node/WasmSupport.d.mts.map +1 -0
  15. package/dist/node/WasmSupport.d.ts +92 -0
  16. package/dist/node/WasmSupport.d.ts.map +1 -0
  17. package/dist/node/WasmSupport.js +167 -0
  18. package/dist/node/WasmSupport.js.map +1 -0
  19. package/dist/node/WasmSupport.mjs +159 -0
  20. package/dist/node/WasmSupport.mjs.map +1 -0
  21. package/dist/node/index.d.mts +2 -0
  22. package/dist/node/index.d.mts.map +1 -0
  23. package/dist/node/index.d.ts +2 -0
  24. package/dist/node/index.d.ts.map +1 -0
  25. package/dist/node/index.js +23 -0
  26. package/dist/node/index.js.map +1 -0
  27. package/dist/node/index.mjs +2 -0
  28. package/dist/node/index.mjs.map +1 -0
  29. package/package.json +24 -21
  30. package/dist/WasmSupport.d.mts.map +0 -1
  31. package/dist/WasmSupport.d.ts.map +0 -1
  32. package/dist/docs.json +0 -2888
  33. package/dist/index.js.map +0 -1
  34. package/dist/index.mjs.map +0 -1
  35. /package/dist/{WasmSupport.d.mts → browser/WasmSupport.d.mts} +0 -0
  36. /package/dist/{WasmSupport.d.ts → browser/WasmSupport.d.ts} +0 -0
  37. /package/dist/{index.d.mts → browser/index.d.mts} +0 -0
  38. /package/dist/{index.d.ts → browser/index.d.ts} +0 -0
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/WasmSupport.ts
21
+ var WasmSupport_exports = {};
22
+ __export(WasmSupport_exports, {
23
+ WasmFeatureDetectors: () => WasmFeatureDetectors,
24
+ WasmSupport: () => WasmSupport
25
+ });
26
+ module.exports = __toCommonJS(WasmSupport_exports);
27
+ var import_wasm_feature_detect = require("wasm-feature-detect");
28
+ var WasmFeatureDetectors = {
29
+ bigInt: import_wasm_feature_detect.bigInt,
30
+ bulkMemory: import_wasm_feature_detect.bulkMemory,
31
+ exceptions: import_wasm_feature_detect.exceptions,
32
+ extendedConst: import_wasm_feature_detect.extendedConst,
33
+ gc: import_wasm_feature_detect.gc,
34
+ memory64: import_wasm_feature_detect.memory64,
35
+ multiValue: import_wasm_feature_detect.multiValue,
36
+ mutableGlobals: import_wasm_feature_detect.mutableGlobals,
37
+ referenceTypes: import_wasm_feature_detect.referenceTypes,
38
+ relaxedSimd: import_wasm_feature_detect.relaxedSimd,
39
+ saturatedFloatToInt: import_wasm_feature_detect.saturatedFloatToInt,
40
+ signExtensions: import_wasm_feature_detect.signExtensions,
41
+ simd: import_wasm_feature_detect.simd,
42
+ streamingCompilation: import_wasm_feature_detect.streamingCompilation,
43
+ tailCall: import_wasm_feature_detect.tailCall,
44
+ threads: import_wasm_feature_detect.threads
45
+ };
46
+ var WasmSupport = class _WasmSupport {
47
+ /**
48
+ * Instance constructor for use where async instantiation
49
+ * is not possible. Where possible, prefer the static
50
+ * create method over use of this constructor directly
51
+ * as no initialization (feature detection) is able to
52
+ * be done here
53
+ * @param desiredFeatures The desired feature set
54
+ */
55
+ constructor(desiredFeatures) {
56
+ this.desiredFeatures = desiredFeatures;
57
+ }
58
+ _allowWasm = true;
59
+ _featureSupport = {};
60
+ _forceWasm = false;
61
+ _isInitialized = false;
62
+ _isWasmFeatureSetSupported = false;
63
+ /**
64
+ * Is Wasm allowed
65
+ */
66
+ get allowWasm() {
67
+ return this._allowWasm;
68
+ }
69
+ /**
70
+ * Whether or not to allow WASM usage
71
+ */
72
+ set allowWasm(v) {
73
+ this._allowWasm = v;
74
+ }
75
+ /**
76
+ * Whether or not Wasm should be used based on the desired
77
+ * feature set, initialization state, or force-use settings
78
+ */
79
+ get canUseWasm() {
80
+ return (
81
+ // Just force WASM
82
+ this._forceWasm || // Or if we haven't checked be optimistic
83
+ this._allowWasm && !this._isInitialized || // Or if we have checked and WASM is not supported, be realistic
84
+ this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported
85
+ );
86
+ }
87
+ /**
88
+ * Returns a object containing a property for each desired wasm feature
89
+ * with a boolean value indicating whether or not the feature is supported
90
+ */
91
+ get featureSupport() {
92
+ return { ...this._featureSupport };
93
+ }
94
+ /**
95
+ * Force use of Wasm
96
+ */
97
+ get forceWasm() {
98
+ return this._forceWasm;
99
+ }
100
+ /**
101
+ * Whether or not to force Wasm usage
102
+ */
103
+ set forceWasm(v) {
104
+ this._forceWasm = v;
105
+ }
106
+ /**
107
+ * Whether or not Wasm is supported based
108
+ * on the desired feature set
109
+ */
110
+ get isDesiredFeatureSetSupported() {
111
+ return this._isWasmFeatureSetSupported;
112
+ }
113
+ /**
114
+ * Whether or not Wasm detection has been run
115
+ * for the desired feature set
116
+ */
117
+ get isInitialized() {
118
+ return this._isInitialized;
119
+ }
120
+ /**
121
+ * Static creation & async initialization for use where
122
+ * async instantiation is possible
123
+ * @param desiredFeatures The desired feature set
124
+ * @returns An initialized instance of the class with detection
125
+ * for the desired feature set
126
+ */
127
+ static async create(desiredFeatures) {
128
+ const instance = new _WasmSupport(desiredFeatures);
129
+ await instance.initialize();
130
+ return Promise.resolve(instance);
131
+ }
132
+ /**
133
+ * Checks for specific wasm features
134
+ * @param features The list of features to check for
135
+ * @returns True if all the features are supported, false otherwise
136
+ */
137
+ async featureCheck(features) {
138
+ const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()));
139
+ return results.every((result) => result);
140
+ }
141
+ /**
142
+ * Does feature detection for the desired feature set
143
+ */
144
+ async initialize() {
145
+ if (this._isInitialized)
146
+ return;
147
+ await this.detectDesiredFeatures();
148
+ this._isInitialized = true;
149
+ return;
150
+ }
151
+ async detectDesiredFeatures() {
152
+ for (let feature = 0; feature < this.desiredFeatures.length; feature++) {
153
+ const desiredFeature = this.desiredFeatures[feature];
154
+ const detector = WasmFeatureDetectors[desiredFeature];
155
+ if (!await detector()) {
156
+ this._featureSupport[desiredFeature] = false;
157
+ } else {
158
+ this._featureSupport[desiredFeature] = true;
159
+ }
160
+ }
161
+ this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v);
162
+ }
163
+ };
164
+ //# sourceMappingURL=WasmSupport.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/WasmSupport.ts"],"sourcesContent":["import {\n bigInt,\n bulkMemory,\n exceptions,\n extendedConst,\n gc,\n memory64,\n multiValue,\n mutableGlobals,\n referenceTypes,\n relaxedSimd,\n saturatedFloatToInt,\n signExtensions,\n simd,\n streamingCompilation,\n tailCall,\n threads,\n} from 'wasm-feature-detect'\n\nexport const WasmFeatureDetectors = {\n bigInt: bigInt,\n bulkMemory: bulkMemory,\n exceptions: exceptions,\n extendedConst: extendedConst,\n gc: gc,\n memory64: memory64,\n multiValue: multiValue,\n mutableGlobals: mutableGlobals,\n referenceTypes: referenceTypes,\n relaxedSimd: relaxedSimd,\n saturatedFloatToInt: saturatedFloatToInt,\n signExtensions: signExtensions,\n simd: simd,\n streamingCompilation: streamingCompilation,\n tailCall: tailCall,\n threads: threads,\n} as const\n\nexport type WasmFeature = keyof typeof WasmFeatureDetectors\n\nexport class WasmSupport {\n private _allowWasm = true\n private _featureSupport: Partial<Record<WasmFeature, boolean>> = {}\n private _forceWasm = false\n private _isInitialized = false\n private _isWasmFeatureSetSupported = false\n\n /**\n * Instance constructor for use where async instantiation\n * is not possible. Where possible, prefer the static\n * create method over use of this constructor directly\n * as no initialization (feature detection) is able to\n * be done here\n * @param desiredFeatures The desired feature set\n */\n constructor(protected desiredFeatures: WasmFeature[]) {}\n\n /**\n * Is Wasm allowed\n */\n get allowWasm(): boolean {\n return this._allowWasm\n }\n /**\n * Whether or not to allow WASM usage\n */\n set allowWasm(v: boolean) {\n this._allowWasm = v\n }\n\n /**\n * Whether or not Wasm should be used based on the desired\n * feature set, initialization state, or force-use settings\n */\n get canUseWasm(): boolean {\n return (\n // Just force WASM\n this._forceWasm ||\n // Or if we haven't checked be optimistic\n (this._allowWasm && !this._isInitialized) ||\n // Or if we have checked and WASM is not supported, be realistic\n (this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported)\n )\n }\n\n /**\n * Returns a object containing a property for each desired wasm feature\n * with a boolean value indicating whether or not the feature is supported\n */\n get featureSupport(): Readonly<Partial<Record<WasmFeature, boolean>>> {\n return { ...this._featureSupport }\n }\n\n /**\n * Force use of Wasm\n */\n get forceWasm(): boolean {\n return this._forceWasm\n }\n /**\n * Whether or not to force Wasm usage\n */\n set forceWasm(v: boolean) {\n this._forceWasm = v\n }\n\n /**\n * Whether or not Wasm is supported based\n * on the desired feature set\n */\n get isDesiredFeatureSetSupported(): boolean {\n return this._isWasmFeatureSetSupported\n }\n\n /**\n * Whether or not Wasm detection has been run\n * for the desired feature set\n */\n get isInitialized(): boolean {\n return this._isInitialized\n }\n\n /**\n * Static creation & async initialization for use where\n * async instantiation is possible\n * @param desiredFeatures The desired feature set\n * @returns An initialized instance of the class with detection\n * for the desired feature set\n */\n static async create(desiredFeatures: WasmFeature[]): Promise<WasmSupport> {\n const instance = new WasmSupport(desiredFeatures)\n await instance.initialize()\n return Promise.resolve(instance)\n }\n\n /**\n * Checks for specific wasm features\n * @param features The list of features to check for\n * @returns True if all the features are supported, false otherwise\n */\n async featureCheck(features: WasmFeature[]): Promise<boolean> {\n const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()))\n return results.every((result) => result)\n }\n\n /**\n * Does feature detection for the desired feature set\n */\n async initialize(): Promise<void> {\n if (this._isInitialized) return\n await this.detectDesiredFeatures()\n this._isInitialized = true\n return\n }\n\n protected async detectDesiredFeatures(): Promise<void> {\n for (let feature = 0; feature < this.desiredFeatures.length; feature++) {\n const desiredFeature = this.desiredFeatures[feature]\n const detector = WasmFeatureDetectors[desiredFeature]\n if (!(await detector())) {\n this._featureSupport[desiredFeature] = false\n } else {\n this._featureSupport[desiredFeature] = true\n }\n }\n this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAiBO;AAEA,IAAM,uBAAuB;AAAA,EAClC,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,qBAAqB;AAAA,EACrB,gBAAgB;AA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B,CAAQ;IAE1C;;;;;;;OAOG;gBACmB,eAAe,EAAE,WAAW,EAAE;IAEpD;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD;;OAEG;IACH,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,EAEvB;IAED;;;OAGG;IACH,IAAI,UAAU,IAAI,OAAO,CASxB;IAED;;;OAGG;IACH,IAAI,cAAc,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAEpE;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD;;OAEG;IACH,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,EAEvB;IAED;;;OAGG;IACH,IAAI,4BAA4B,IAAI,OAAO,CAE1C;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED;;;;;;OAMG;WACU,MAAM,CAAC,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAMzE;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7D;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;cAOjB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;CAYvD"}
@@ -0,0 +1,160 @@
1
+ // src/WasmSupport.ts
2
+ import {
3
+ bigInt,
4
+ bulkMemory,
5
+ exceptions,
6
+ extendedConst,
7
+ gc,
8
+ memory64,
9
+ multiValue,
10
+ mutableGlobals,
11
+ referenceTypes,
12
+ relaxedSimd,
13
+ saturatedFloatToInt,
14
+ signExtensions,
15
+ simd,
16
+ streamingCompilation,
17
+ tailCall,
18
+ threads
19
+ } from "wasm-feature-detect";
20
+ var WasmFeatureDetectors = {
21
+ bigInt,
22
+ bulkMemory,
23
+ exceptions,
24
+ extendedConst,
25
+ gc,
26
+ memory64,
27
+ multiValue,
28
+ mutableGlobals,
29
+ referenceTypes,
30
+ relaxedSimd,
31
+ saturatedFloatToInt,
32
+ signExtensions,
33
+ simd,
34
+ streamingCompilation,
35
+ tailCall,
36
+ threads
37
+ };
38
+ var WasmSupport = class _WasmSupport {
39
+ /**
40
+ * Instance constructor for use where async instantiation
41
+ * is not possible. Where possible, prefer the static
42
+ * create method over use of this constructor directly
43
+ * as no initialization (feature detection) is able to
44
+ * be done here
45
+ * @param desiredFeatures The desired feature set
46
+ */
47
+ constructor(desiredFeatures) {
48
+ this.desiredFeatures = desiredFeatures;
49
+ }
50
+ _allowWasm = true;
51
+ _featureSupport = {};
52
+ _forceWasm = false;
53
+ _isInitialized = false;
54
+ _isWasmFeatureSetSupported = false;
55
+ /**
56
+ * Is Wasm allowed
57
+ */
58
+ get allowWasm() {
59
+ return this._allowWasm;
60
+ }
61
+ /**
62
+ * Whether or not to allow WASM usage
63
+ */
64
+ set allowWasm(v) {
65
+ this._allowWasm = v;
66
+ }
67
+ /**
68
+ * Whether or not Wasm should be used based on the desired
69
+ * feature set, initialization state, or force-use settings
70
+ */
71
+ get canUseWasm() {
72
+ return (
73
+ // Just force WASM
74
+ this._forceWasm || // Or if we haven't checked be optimistic
75
+ this._allowWasm && !this._isInitialized || // Or if we have checked and WASM is not supported, be realistic
76
+ this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported
77
+ );
78
+ }
79
+ /**
80
+ * Returns a object containing a property for each desired wasm feature
81
+ * with a boolean value indicating whether or not the feature is supported
82
+ */
83
+ get featureSupport() {
84
+ return { ...this._featureSupport };
85
+ }
86
+ /**
87
+ * Force use of Wasm
88
+ */
89
+ get forceWasm() {
90
+ return this._forceWasm;
91
+ }
92
+ /**
93
+ * Whether or not to force Wasm usage
94
+ */
95
+ set forceWasm(v) {
96
+ this._forceWasm = v;
97
+ }
98
+ /**
99
+ * Whether or not Wasm is supported based
100
+ * on the desired feature set
101
+ */
102
+ get isDesiredFeatureSetSupported() {
103
+ return this._isWasmFeatureSetSupported;
104
+ }
105
+ /**
106
+ * Whether or not Wasm detection has been run
107
+ * for the desired feature set
108
+ */
109
+ get isInitialized() {
110
+ return this._isInitialized;
111
+ }
112
+ /**
113
+ * Static creation & async initialization for use where
114
+ * async instantiation is possible
115
+ * @param desiredFeatures The desired feature set
116
+ * @returns An initialized instance of the class with detection
117
+ * for the desired feature set
118
+ */
119
+ static async create(desiredFeatures) {
120
+ const instance = new _WasmSupport(desiredFeatures);
121
+ await instance.initialize();
122
+ return Promise.resolve(instance);
123
+ }
124
+ /**
125
+ * Checks for specific wasm features
126
+ * @param features The list of features to check for
127
+ * @returns True if all the features are supported, false otherwise
128
+ */
129
+ async featureCheck(features) {
130
+ const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()));
131
+ return results.every((result) => result);
132
+ }
133
+ /**
134
+ * Does feature detection for the desired feature set
135
+ */
136
+ async initialize() {
137
+ if (this._isInitialized)
138
+ return;
139
+ await this.detectDesiredFeatures();
140
+ this._isInitialized = true;
141
+ return;
142
+ }
143
+ async detectDesiredFeatures() {
144
+ for (let feature = 0; feature < this.desiredFeatures.length; feature++) {
145
+ const desiredFeature = this.desiredFeatures[feature];
146
+ const detector = WasmFeatureDetectors[desiredFeature];
147
+ if (!await detector()) {
148
+ this._featureSupport[desiredFeature] = false;
149
+ } else {
150
+ this._featureSupport[desiredFeature] = true;
151
+ }
152
+ }
153
+ this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v);
154
+ }
155
+ };
156
+ export {
157
+ WasmFeatureDetectors,
158
+ WasmSupport
159
+ };
160
+ //# sourceMappingURL=WasmSupport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/WasmSupport.ts"],"sourcesContent":["import {\n bigInt,\n bulkMemory,\n exceptions,\n extendedConst,\n gc,\n memory64,\n multiValue,\n mutableGlobals,\n referenceTypes,\n relaxedSimd,\n saturatedFloatToInt,\n signExtensions,\n simd,\n streamingCompilation,\n tailCall,\n threads,\n} from 'wasm-feature-detect'\n\nexport const WasmFeatureDetectors = {\n bigInt: bigInt,\n bulkMemory: bulkMemory,\n exceptions: exceptions,\n extendedConst: extendedConst,\n gc: gc,\n memory64: memory64,\n multiValue: multiValue,\n mutableGlobals: mutableGlobals,\n referenceTypes: referenceTypes,\n relaxedSimd: relaxedSimd,\n saturatedFloatToInt: saturatedFloatToInt,\n signExtensions: signExtensions,\n simd: simd,\n streamingCompilation: streamingCompilation,\n tailCall: tailCall,\n threads: threads,\n} as const\n\nexport type WasmFeature = keyof typeof WasmFeatureDetectors\n\nexport class WasmSupport {\n private _allowWasm = true\n private _featureSupport: Partial<Record<WasmFeature, boolean>> = {}\n private _forceWasm = false\n private _isInitialized = false\n private _isWasmFeatureSetSupported = false\n\n /**\n * Instance constructor for use where async instantiation\n * is not possible. Where possible, prefer the static\n * create method over use of this constructor directly\n * as no initialization (feature detection) is able to\n * be done here\n * @param desiredFeatures The desired feature set\n */\n constructor(protected desiredFeatures: WasmFeature[]) {}\n\n /**\n * Is Wasm allowed\n */\n get allowWasm(): boolean {\n return this._allowWasm\n }\n /**\n * Whether or not to allow WASM usage\n */\n set allowWasm(v: boolean) {\n this._allowWasm = v\n }\n\n /**\n * Whether or not Wasm should be used based on the desired\n * feature set, initialization state, or force-use settings\n */\n get canUseWasm(): boolean {\n return (\n // Just force WASM\n this._forceWasm ||\n // Or if we haven't checked be optimistic\n (this._allowWasm && !this._isInitialized) ||\n // Or if we have checked and WASM is not supported, be realistic\n (this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported)\n )\n }\n\n /**\n * Returns a object containing a property for each desired wasm feature\n * with a boolean value indicating whether or not the feature is supported\n */\n get featureSupport(): Readonly<Partial<Record<WasmFeature, boolean>>> {\n return { ...this._featureSupport }\n }\n\n /**\n * Force use of Wasm\n */\n get forceWasm(): boolean {\n return this._forceWasm\n }\n /**\n * Whether or not to force Wasm usage\n */\n set forceWasm(v: boolean) {\n this._forceWasm = v\n }\n\n /**\n * Whether or not Wasm is supported based\n * on the desired feature set\n */\n get isDesiredFeatureSetSupported(): boolean {\n return this._isWasmFeatureSetSupported\n }\n\n /**\n * Whether or not Wasm detection has been run\n * for the desired feature set\n */\n get isInitialized(): boolean {\n return this._isInitialized\n }\n\n /**\n * Static creation & async initialization for use where\n * async instantiation is possible\n * @param desiredFeatures The desired feature set\n * @returns An initialized instance of the class with detection\n * for the desired feature set\n */\n static async create(desiredFeatures: WasmFeature[]): Promise<WasmSupport> {\n const instance = new WasmSupport(desiredFeatures)\n await instance.initialize()\n return Promise.resolve(instance)\n }\n\n /**\n * Checks for specific wasm features\n * @param features The list of features to check for\n * @returns True if all the features are supported, false otherwise\n */\n async featureCheck(features: WasmFeature[]): Promise<boolean> {\n const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()))\n return results.every((result) => result)\n }\n\n /**\n * Does feature detection for the desired feature set\n */\n async initialize(): Promise<void> {\n if (this._isInitialized) return\n await this.detectDesiredFeatures()\n this._isInitialized = true\n return\n }\n\n protected async detectDesiredFeatures(): Promise<void> {\n for (let feature = 0; feature < this.desiredFeatures.length; feature++) {\n const desiredFeature = this.desiredFeatures[feature]\n const detector = WasmFeatureDetectors[desiredFeature]\n if (!(await detector())) {\n this._featureSupport[desiredFeature] = false\n } else {\n this._featureSupport[desiredFeature] = true\n }\n }\n this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v)\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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AAAA,EAOA,MAAM,aAAa,UAA2C;AAC5D,UAAM,UAAU,MAAM,QAAQ,IAAI,SAAS,IAAI,CAAC,YAAY,qBAAqB,OAAO,CAAC,EAAE,IAAI,OAAO,aAAa,MAAM,SAAS,CAAC,CAAC;AACpI,WAAO,QAAQ,MAAM,CAAC,WAAW,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA4B;AAChC,QAAI,KAAK;AAAgB;AACzB,UAAM,KAAK,sBAAsB;AACjC,SAAK,iBAAiB;AACtB;AAAA,EACF;AAAA,EAEA,MAAgB,wBAAuC;AACrD,aAAS,UAAU,GAAG,UAAU,KAAK,gBAAgB,QAAQ,WAAW;AACtE,YAAM,iBAAiB,KAAK,gBAAgB,OAAO;AACnD,YAAM,WAAW,qBAAqB,cAAc;AACpD,UAAI,CAAE,MAAM,SAAS,GAAI;AACvB,aAAK,gBAAgB,cAAc,IAAI;AAAA,MACzC,OAAO;AACL,aAAK,gBAAgB,cAAc,IAAI;AAAA,MACzC;AAAA,IACF;AACA,SAAK,6BAA6B,OAAO,OAAO,KAAK,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;AAAA,EACtF;AACF;","names":[]}
@@ -163,9 +163,4 @@ var WasmSupport = class _WasmSupport {
163
163
  this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v);
164
164
  }
165
165
  };
166
- // Annotate the CommonJS export names for ESM import in node:
167
- 0 && (module.exports = {
168
- WasmFeatureDetectors,
169
- WasmSupport
170
- });
171
- //# sourceMappingURL=index.js.map
166
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/WasmSupport.ts"],"sourcesContent":["export * from './WasmSupport'\n","import {\n bigInt,\n bulkMemory,\n exceptions,\n extendedConst,\n gc,\n memory64,\n multiValue,\n mutableGlobals,\n referenceTypes,\n relaxedSimd,\n saturatedFloatToInt,\n signExtensions,\n simd,\n streamingCompilation,\n tailCall,\n threads,\n} from 'wasm-feature-detect'\n\nexport const WasmFeatureDetectors = {\n bigInt: bigInt,\n bulkMemory: bulkMemory,\n exceptions: exceptions,\n extendedConst: extendedConst,\n gc: gc,\n memory64: memory64,\n multiValue: multiValue,\n mutableGlobals: mutableGlobals,\n referenceTypes: referenceTypes,\n relaxedSimd: relaxedSimd,\n saturatedFloatToInt: saturatedFloatToInt,\n signExtensions: signExtensions,\n simd: simd,\n streamingCompilation: streamingCompilation,\n tailCall: tailCall,\n threads: threads,\n} as const\n\nexport type WasmFeature = keyof typeof WasmFeatureDetectors\n\nexport class WasmSupport {\n private _allowWasm = true\n private _featureSupport: Partial<Record<WasmFeature, boolean>> = {}\n private _forceWasm = false\n private _isInitialized = false\n private _isWasmFeatureSetSupported = false\n\n /**\n * Instance constructor for use where async instantiation\n * is not possible. Where possible, prefer the static\n * create method over use of this constructor directly\n * as no initialization (feature detection) is able to\n * be done here\n * @param desiredFeatures The desired feature set\n */\n constructor(protected desiredFeatures: WasmFeature[]) {}\n\n /**\n * Is Wasm allowed\n */\n get allowWasm(): boolean {\n return this._allowWasm\n }\n /**\n * Whether or not to allow WASM usage\n */\n set allowWasm(v: boolean) {\n this._allowWasm = v\n }\n\n /**\n * Whether or not Wasm should be used based on the desired\n * feature set, initialization state, or force-use settings\n */\n get canUseWasm(): boolean {\n return (\n // Just force WASM\n this._forceWasm ||\n // Or if we haven't checked be optimistic\n (this._allowWasm && !this._isInitialized) ||\n // Or if we have checked and WASM is not supported, be realistic\n (this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported)\n )\n }\n\n /**\n * Returns a object containing a property for each desired wasm feature\n * with a boolean value indicating whether or not the feature is supported\n */\n get featureSupport(): Readonly<Partial<Record<WasmFeature, boolean>>> {\n return { ...this._featureSupport }\n }\n\n /**\n * Force use of Wasm\n */\n get forceWasm(): boolean {\n return this._forceWasm\n }\n /**\n * Whether or not to force Wasm usage\n */\n set forceWasm(v: boolean) {\n this._forceWasm = v\n }\n\n /**\n * Whether or not Wasm is supported based\n * on the desired feature set\n */\n get isDesiredFeatureSetSupported(): boolean {\n return this._isWasmFeatureSetSupported\n }\n\n /**\n * Whether or not Wasm detection has been run\n * for the desired feature set\n */\n get isInitialized(): boolean {\n return this._isInitialized\n }\n\n /**\n * Static creation & async initialization for use where\n * async instantiation is possible\n * @param desiredFeatures The desired feature set\n * @returns An initialized instance of the class with detection\n * for the desired feature set\n */\n static async create(desiredFeatures: WasmFeature[]): Promise<WasmSupport> {\n const instance = new WasmSupport(desiredFeatures)\n await instance.initialize()\n return Promise.resolve(instance)\n }\n\n /**\n * Checks for specific wasm features\n * @param features The list of features to check for\n * @returns True if all the features are supported, false otherwise\n */\n async featureCheck(features: WasmFeature[]): Promise<boolean> {\n const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()))\n return results.every((result) => result)\n }\n\n /**\n * Does feature detection for the desired feature set\n */\n async initialize(): Promise<void> {\n if (this._isInitialized) return\n await this.detectDesiredFeatures()\n this._isInitialized = true\n return\n }\n\n protected async detectDesiredFeatures(): Promise<void> {\n for (let feature = 0; feature < this.desiredFeatures.length; feature++) {\n const desiredFeature = this.desiredFeatures[feature]\n const detector = WasmFeatureDetectors[desiredFeature]\n if (!(await detector())) {\n this._featureSupport[desiredFeature] = false\n } else {\n this._featureSupport[desiredFeature] = true\n }\n }\n this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iCAiBO;AAEA,IAAM,uBAAuB;AAAA,EAClC,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,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AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,UAA2C;AAC5D,UAAM,UAAU,MAAM,QAAQ,IAAI,SAAS,IAAI,CAAC,YAAY,qBAAqB,OAAO,CAAC,EAAE,IAAI,OAAO,aAAa,MAAM,SAAS,CAAC,CAAC;AACpI,WAAO,QAAQ,MAAM,CAAC,WAAW,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA4B;AAChC,QAAI,KAAK;AAAgB;AACzB,UAAM,KAAK,sBAAsB;AACjC,SAAK,iBAAiB;AACtB;AAAA,EACF;AAAA,EAEA,MAAgB,wBAAuC;AACrD,aAAS,UAAU,GAAG,UAAU,KAAK,gBAAgB,QAAQ,WAAW;AACtE,YAAM,iBAAiB,KAAK,gBAAgB,OAAO;AACnD,YAAM,WAAW,qBAAqB,cAAc;AACpD,UAAI,CAAE,MAAM,SAAS,GAAI;AACvB,aAAK,gBAAgB,cAAc,IAAI;AAAA,MACzC,OAAO;AACL,aAAK,gBAAgB,cAAc,IAAI;AAAA,MACzC;AAAA,IACF;AACA,SAAK,6BAA6B,OAAO,OAAO,KAAK,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;AAAA,EACtF;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA"}
@@ -157,4 +157,4 @@ export {
157
157
  WasmFeatureDetectors,
158
158
  WasmSupport
159
159
  };
160
- //# sourceMappingURL=index.mjs.map
160
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/WasmSupport.ts"],"sourcesContent":["import {\n bigInt,\n bulkMemory,\n exceptions,\n extendedConst,\n gc,\n memory64,\n multiValue,\n mutableGlobals,\n referenceTypes,\n relaxedSimd,\n saturatedFloatToInt,\n signExtensions,\n simd,\n streamingCompilation,\n tailCall,\n threads,\n} from 'wasm-feature-detect'\n\nexport const WasmFeatureDetectors = {\n bigInt: bigInt,\n bulkMemory: bulkMemory,\n exceptions: exceptions,\n extendedConst: extendedConst,\n gc: gc,\n memory64: memory64,\n multiValue: multiValue,\n mutableGlobals: mutableGlobals,\n referenceTypes: referenceTypes,\n relaxedSimd: relaxedSimd,\n saturatedFloatToInt: saturatedFloatToInt,\n signExtensions: signExtensions,\n simd: simd,\n streamingCompilation: streamingCompilation,\n tailCall: tailCall,\n threads: threads,\n} as const\n\nexport type WasmFeature = keyof typeof WasmFeatureDetectors\n\nexport class WasmSupport {\n private _allowWasm = true\n private _featureSupport: Partial<Record<WasmFeature, boolean>> = {}\n private _forceWasm = false\n private _isInitialized = false\n private _isWasmFeatureSetSupported = false\n\n /**\n * Instance constructor for use where async instantiation\n * is not possible. Where possible, prefer the static\n * create method over use of this constructor directly\n * as no initialization (feature detection) is able to\n * be done here\n * @param desiredFeatures The desired feature set\n */\n constructor(protected desiredFeatures: WasmFeature[]) {}\n\n /**\n * Is Wasm allowed\n */\n get allowWasm(): boolean {\n return this._allowWasm\n }\n /**\n * Whether or not to allow WASM usage\n */\n set allowWasm(v: boolean) {\n this._allowWasm = v\n }\n\n /**\n * Whether or not Wasm should be used based on the desired\n * feature set, initialization state, or force-use settings\n */\n get canUseWasm(): boolean {\n return (\n // Just force WASM\n this._forceWasm ||\n // Or if we haven't checked be optimistic\n (this._allowWasm && !this._isInitialized) ||\n // Or if we have checked and WASM is not supported, be realistic\n (this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported)\n )\n }\n\n /**\n * Returns a object containing a property for each desired wasm feature\n * with a boolean value indicating whether or not the feature is supported\n */\n get featureSupport(): Readonly<Partial<Record<WasmFeature, boolean>>> {\n return { ...this._featureSupport }\n }\n\n /**\n * Force use of Wasm\n */\n get forceWasm(): boolean {\n return this._forceWasm\n }\n /**\n * Whether or not to force Wasm usage\n */\n set forceWasm(v: boolean) {\n this._forceWasm = v\n }\n\n /**\n * Whether or not Wasm is supported based\n * on the desired feature set\n */\n get isDesiredFeatureSetSupported(): boolean {\n return this._isWasmFeatureSetSupported\n }\n\n /**\n * Whether or not Wasm detection has been run\n * for the desired feature set\n */\n get isInitialized(): boolean {\n return this._isInitialized\n }\n\n /**\n * Static creation & async initialization for use where\n * async instantiation is possible\n * @param desiredFeatures The desired feature set\n * @returns An initialized instance of the class with detection\n * for the desired feature set\n */\n static async create(desiredFeatures: WasmFeature[]): Promise<WasmSupport> {\n const instance = new WasmSupport(desiredFeatures)\n await instance.initialize()\n return Promise.resolve(instance)\n }\n\n /**\n * Checks for specific wasm features\n * @param features The list of features to check for\n * @returns True if all the features are supported, false otherwise\n */\n async featureCheck(features: WasmFeature[]): Promise<boolean> {\n const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()))\n return results.every((result) => result)\n }\n\n /**\n * Does feature detection for the desired feature set\n */\n async initialize(): Promise<void> {\n if (this._isInitialized) return\n await this.detectDesiredFeatures()\n this._isInitialized = true\n return\n }\n\n protected async detectDesiredFeatures(): Promise<void> {\n for (let feature = 0; feature < this.desiredFeatures.length; feature++) {\n const desiredFeature = this.desiredFeatures[feature]\n const detector = WasmFeatureDetectors[desiredFeature]\n if (!(await detector())) {\n this._featureSupport[desiredFeature] = false\n } else {\n this._featureSupport[desiredFeature] = true\n }\n }\n this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v)\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;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AA;AAAA;AAAA;AAAA,EAMA,IAAI,gBAAyB;AAC3B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,aAAa,OAAO,iBAAsD;AACxE,UAAM,WAAW,IAAI,aAAY,eAAe;AAChD,UAAM,SAAS,WAAW;AAC1B,WAAO,QAAQ,QAAQ,QAAQ;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAAa,UAA2C;AAC5D,UAAM,UAAU,MAAM,QAAQ,IAAI,SAAS,IAAI,CAAC,YAAY,qBAAqB,OAAO,CAAC,EAAE,IAAI,OAAO,aAAa,MAAM,SAAS,CAAC,CAAC;AACpI,WAAO,QAAQ,MAAM,CAAC,WAAW,MAAM;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA4B;AAChC,QAAI,KAAK;AAAgB;AACzB,UAAM,KAAK,sBAAsB;AACjC,SAAK,iBAAiB;AACtB;AAAA,EACF;AAAA,EAEA,MAAgB,wBAAuC;AACrD,aAAS,UAAU,GAAG,UAAU,KAAK,gBAAgB,QAAQ,WAAW;AACtE,YAAM,iBAAiB,KAAK,gBAAgB,OAAO;AACnD,YAAM,WAAW,qBAAqB,cAAc;AACpD,UAAI,CAAE,MAAM,SAAS,GAAI;AACvB,aAAK,gBAAgB,cAAc,IAAI;AAAA,MACzC,OAAO;AACL,aAAK,gBAAgB,cAAc,IAAI;AAAA,MACzC;AAAA,IACF;AACA,SAAK,6BAA6B,OAAO,OAAO,KAAK,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;AAAA,EACtF;AACF;","names":[]}
@@ -0,0 +1,92 @@
1
+ export declare const WasmFeatureDetectors: {
2
+ readonly bigInt: () => Promise<boolean>;
3
+ readonly bulkMemory: () => Promise<boolean>;
4
+ readonly exceptions: () => Promise<boolean>;
5
+ readonly extendedConst: () => Promise<boolean>;
6
+ readonly gc: () => Promise<boolean>;
7
+ readonly memory64: () => Promise<boolean>;
8
+ readonly multiValue: () => Promise<boolean>;
9
+ readonly mutableGlobals: () => Promise<boolean>;
10
+ readonly referenceTypes: () => Promise<boolean>;
11
+ readonly relaxedSimd: () => Promise<boolean>;
12
+ readonly saturatedFloatToInt: () => Promise<boolean>;
13
+ readonly signExtensions: () => Promise<boolean>;
14
+ readonly simd: () => Promise<boolean>;
15
+ readonly streamingCompilation: () => Promise<boolean>;
16
+ readonly tailCall: () => Promise<boolean>;
17
+ readonly threads: () => Promise<boolean>;
18
+ };
19
+ export type WasmFeature = keyof typeof WasmFeatureDetectors;
20
+ export declare class WasmSupport {
21
+ protected desiredFeatures: WasmFeature[];
22
+ private _allowWasm;
23
+ private _featureSupport;
24
+ private _forceWasm;
25
+ private _isInitialized;
26
+ private _isWasmFeatureSetSupported;
27
+ /**
28
+ * Instance constructor for use where async instantiation
29
+ * is not possible. Where possible, prefer the static
30
+ * create method over use of this constructor directly
31
+ * as no initialization (feature detection) is able to
32
+ * be done here
33
+ * @param desiredFeatures The desired feature set
34
+ */
35
+ constructor(desiredFeatures: WasmFeature[]);
36
+ /**
37
+ * Is Wasm allowed
38
+ */
39
+ get allowWasm(): boolean;
40
+ /**
41
+ * Whether or not to allow WASM usage
42
+ */
43
+ set allowWasm(v: boolean);
44
+ /**
45
+ * Whether or not Wasm should be used based on the desired
46
+ * feature set, initialization state, or force-use settings
47
+ */
48
+ get canUseWasm(): boolean;
49
+ /**
50
+ * Returns a object containing a property for each desired wasm feature
51
+ * with a boolean value indicating whether or not the feature is supported
52
+ */
53
+ get featureSupport(): Readonly<Partial<Record<WasmFeature, boolean>>>;
54
+ /**
55
+ * Force use of Wasm
56
+ */
57
+ get forceWasm(): boolean;
58
+ /**
59
+ * Whether or not to force Wasm usage
60
+ */
61
+ set forceWasm(v: boolean);
62
+ /**
63
+ * Whether or not Wasm is supported based
64
+ * on the desired feature set
65
+ */
66
+ get isDesiredFeatureSetSupported(): boolean;
67
+ /**
68
+ * Whether or not Wasm detection has been run
69
+ * for the desired feature set
70
+ */
71
+ get isInitialized(): boolean;
72
+ /**
73
+ * Static creation & async initialization for use where
74
+ * async instantiation is possible
75
+ * @param desiredFeatures The desired feature set
76
+ * @returns An initialized instance of the class with detection
77
+ * for the desired feature set
78
+ */
79
+ static create(desiredFeatures: WasmFeature[]): Promise<WasmSupport>;
80
+ /**
81
+ * Checks for specific wasm features
82
+ * @param features The list of features to check for
83
+ * @returns True if all the features are supported, false otherwise
84
+ */
85
+ featureCheck(features: WasmFeature[]): Promise<boolean>;
86
+ /**
87
+ * Does feature detection for the desired feature set
88
+ */
89
+ initialize(): Promise<void>;
90
+ protected detectDesiredFeatures(): Promise<void>;
91
+ }
92
+ //# sourceMappingURL=WasmSupport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WasmSupport.d.ts","sourceRoot":"","sources":["../../src/WasmSupport.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;CAiBvB,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,oBAAoB,CAAA;AAE3D,qBAAa,WAAW;IAeV,SAAS,CAAC,eAAe,EAAE,WAAW,EAAE;IAdpD,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,eAAe,CAA4C;IACnE,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,0BAA0B,CAAQ;IAE1C;;;;;;;OAOG;gBACmB,eAAe,EAAE,WAAW,EAAE;IAEpD;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD;;OAEG;IACH,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,EAEvB;IAED;;;OAGG;IACH,IAAI,UAAU,IAAI,OAAO,CASxB;IAED;;;OAGG;IACH,IAAI,cAAc,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAEpE;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD;;OAEG;IACH,IAAI,SAAS,CAAC,CAAC,EAAE,OAAO,EAEvB;IAED;;;OAGG;IACH,IAAI,4BAA4B,IAAI,OAAO,CAE1C;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED;;;;;;OAMG;WACU,MAAM,CAAC,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAMzE;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7D;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;cAOjB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;CAYvD"}
@@ -0,0 +1,92 @@
1
+ export declare const WasmFeatureDetectors: {
2
+ readonly bigInt: () => Promise<boolean>;
3
+ readonly bulkMemory: () => Promise<boolean>;
4
+ readonly exceptions: () => Promise<boolean>;
5
+ readonly extendedConst: () => Promise<boolean>;
6
+ readonly gc: () => Promise<boolean>;
7
+ readonly memory64: () => Promise<boolean>;
8
+ readonly multiValue: () => Promise<boolean>;
9
+ readonly mutableGlobals: () => Promise<boolean>;
10
+ readonly referenceTypes: () => Promise<boolean>;
11
+ readonly relaxedSimd: () => Promise<boolean>;
12
+ readonly saturatedFloatToInt: () => Promise<boolean>;
13
+ readonly signExtensions: () => Promise<boolean>;
14
+ readonly simd: () => Promise<boolean>;
15
+ readonly streamingCompilation: () => Promise<boolean>;
16
+ readonly tailCall: () => Promise<boolean>;
17
+ readonly threads: () => Promise<boolean>;
18
+ };
19
+ export type WasmFeature = keyof typeof WasmFeatureDetectors;
20
+ export declare class WasmSupport {
21
+ protected desiredFeatures: WasmFeature[];
22
+ private _allowWasm;
23
+ private _featureSupport;
24
+ private _forceWasm;
25
+ private _isInitialized;
26
+ private _isWasmFeatureSetSupported;
27
+ /**
28
+ * Instance constructor for use where async instantiation
29
+ * is not possible. Where possible, prefer the static
30
+ * create method over use of this constructor directly
31
+ * as no initialization (feature detection) is able to
32
+ * be done here
33
+ * @param desiredFeatures The desired feature set
34
+ */
35
+ constructor(desiredFeatures: WasmFeature[]);
36
+ /**
37
+ * Is Wasm allowed
38
+ */
39
+ get allowWasm(): boolean;
40
+ /**
41
+ * Whether or not to allow WASM usage
42
+ */
43
+ set allowWasm(v: boolean);
44
+ /**
45
+ * Whether or not Wasm should be used based on the desired
46
+ * feature set, initialization state, or force-use settings
47
+ */
48
+ get canUseWasm(): boolean;
49
+ /**
50
+ * Returns a object containing a property for each desired wasm feature
51
+ * with a boolean value indicating whether or not the feature is supported
52
+ */
53
+ get featureSupport(): Readonly<Partial<Record<WasmFeature, boolean>>>;
54
+ /**
55
+ * Force use of Wasm
56
+ */
57
+ get forceWasm(): boolean;
58
+ /**
59
+ * Whether or not to force Wasm usage
60
+ */
61
+ set forceWasm(v: boolean);
62
+ /**
63
+ * Whether or not Wasm is supported based
64
+ * on the desired feature set
65
+ */
66
+ get isDesiredFeatureSetSupported(): boolean;
67
+ /**
68
+ * Whether or not Wasm detection has been run
69
+ * for the desired feature set
70
+ */
71
+ get isInitialized(): boolean;
72
+ /**
73
+ * Static creation & async initialization for use where
74
+ * async instantiation is possible
75
+ * @param desiredFeatures The desired feature set
76
+ * @returns An initialized instance of the class with detection
77
+ * for the desired feature set
78
+ */
79
+ static create(desiredFeatures: WasmFeature[]): Promise<WasmSupport>;
80
+ /**
81
+ * Checks for specific wasm features
82
+ * @param features The list of features to check for
83
+ * @returns True if all the features are supported, false otherwise
84
+ */
85
+ featureCheck(features: WasmFeature[]): Promise<boolean>;
86
+ /**
87
+ * Does feature detection for the desired feature set
88
+ */
89
+ initialize(): Promise<void>;
90
+ protected detectDesiredFeatures(): Promise<void>;
91
+ }
92
+ //# sourceMappingURL=WasmSupport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WasmSupport.d.ts","sourceRoot":"","sources":["../../src/Was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