@xyo-network/wasm 2.74.5 → 2.75.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.
Files changed (46) 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.cts.map +1 -0
  4. package/dist/browser/WasmSupport.d.mts.map +1 -0
  5. package/dist/browser/WasmSupport.d.ts +92 -0
  6. package/dist/browser/WasmSupport.d.ts.map +1 -0
  7. package/dist/browser/WasmSupport.js +159 -0
  8. package/dist/browser/WasmSupport.js.map +1 -0
  9. package/dist/browser/index.cjs +166 -0
  10. package/dist/browser/index.cjs.map +1 -0
  11. package/dist/browser/index.d.cts.map +1 -0
  12. package/dist/{index.d.mts.map → browser/index.d.mts.map} +1 -1
  13. package/dist/browser/index.d.ts +2 -0
  14. package/dist/{index.d.ts.map → browser/index.d.ts.map} +1 -1
  15. package/dist/browser/index.js +2 -0
  16. package/dist/browser/index.js.map +1 -0
  17. package/dist/docs.json +52 -52
  18. package/dist/node/WasmSupport.d.cts +92 -0
  19. package/dist/node/WasmSupport.d.cts.map +1 -0
  20. package/dist/node/WasmSupport.d.mts +92 -0
  21. package/dist/node/WasmSupport.d.mts.map +1 -0
  22. package/dist/node/WasmSupport.d.ts +92 -0
  23. package/dist/node/WasmSupport.d.ts.map +1 -0
  24. package/dist/node/WasmSupport.js +169 -0
  25. package/dist/node/WasmSupport.js.map +1 -0
  26. package/dist/node/WasmSupport.mjs +160 -0
  27. package/dist/node/WasmSupport.mjs.map +1 -0
  28. package/dist/node/index.d.cts +2 -0
  29. package/dist/node/index.d.cts.map +1 -0
  30. package/dist/node/index.d.mts +2 -0
  31. package/dist/node/index.d.mts.map +1 -0
  32. package/dist/node/index.d.ts +2 -0
  33. package/dist/node/index.d.ts.map +1 -0
  34. package/dist/node/index.js.map +1 -0
  35. package/dist/node/index.mjs.map +1 -0
  36. package/package.json +24 -21
  37. package/dist/WasmSupport.d.mts.map +0 -1
  38. package/dist/WasmSupport.d.ts.map +0 -1
  39. package/dist/index.js.map +0 -1
  40. package/dist/index.mjs.map +0 -1
  41. /package/dist/{WasmSupport.d.mts → browser/WasmSupport.d.cts} +0 -0
  42. /package/dist/{WasmSupport.d.ts → browser/WasmSupport.d.mts} +0 -0
  43. /package/dist/{index.d.mts → browser/index.d.cts} +0 -0
  44. /package/dist/{index.d.ts → browser/index.d.mts} +0 -0
  45. /package/dist/{index.js → node/index.js} +0 -0
  46. /package/dist/{index.mjs → node/index.mjs} +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,iC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AAW,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/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,159 @@
1
+ import {
2
+ bigInt,
3
+ bulkMemory,
4
+ exceptions,
5
+ extendedConst,
6
+ gc,
7
+ memory64,
8
+ multiValue,
9
+ mutableGlobals,
10
+ referenceTypes,
11
+ relaxedSimd,
12
+ saturatedFloatToInt,
13
+ signExtensions,
14
+ simd,
15
+ streamingCompilation,
16
+ tailCall,
17
+ threads
18
+ } from "wasm-feature-detect";
19
+ const WasmFeatureDetectors = {
20
+ bigInt,
21
+ bulkMemory,
22
+ exceptions,
23
+ extendedConst,
24
+ gc,
25
+ memory64,
26
+ multiValue,
27
+ mutableGlobals,
28
+ referenceTypes,
29
+ relaxedSimd,
30
+ saturatedFloatToInt,
31
+ signExtensions,
32
+ simd,
33
+ streamingCompilation,
34
+ tailCall,
35
+ threads
36
+ };
37
+ class WasmSupport {
38
+ /**
39
+ * Instance constructor for use where async instantiation
40
+ * is not possible. Where possible, prefer the static
41
+ * create method over use of this constructor directly
42
+ * as no initialization (feature detection) is able to
43
+ * be done here
44
+ * @param desiredFeatures The desired feature set
45
+ */
46
+ constructor(desiredFeatures) {
47
+ this.desiredFeatures = desiredFeatures;
48
+ }
49
+ _allowWasm = true;
50
+ _featureSupport = {};
51
+ _forceWasm = false;
52
+ _isInitialized = false;
53
+ _isWasmFeatureSetSupported = false;
54
+ /**
55
+ * Is Wasm allowed
56
+ */
57
+ get allowWasm() {
58
+ return this._allowWasm;
59
+ }
60
+ /**
61
+ * Whether or not to allow WASM usage
62
+ */
63
+ set allowWasm(v) {
64
+ this._allowWasm = v;
65
+ }
66
+ /**
67
+ * Whether or not Wasm should be used based on the desired
68
+ * feature set, initialization state, or force-use settings
69
+ */
70
+ get canUseWasm() {
71
+ return (
72
+ // Just force WASM
73
+ this._forceWasm || // Or if we haven't checked be optimistic
74
+ this._allowWasm && !this._isInitialized || // Or if we have checked and WASM is not supported, be realistic
75
+ this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported
76
+ );
77
+ }
78
+ /**
79
+ * Returns a object containing a property for each desired wasm feature
80
+ * with a boolean value indicating whether or not the feature is supported
81
+ */
82
+ get featureSupport() {
83
+ return { ...this._featureSupport };
84
+ }
85
+ /**
86
+ * Force use of Wasm
87
+ */
88
+ get forceWasm() {
89
+ return this._forceWasm;
90
+ }
91
+ /**
92
+ * Whether or not to force Wasm usage
93
+ */
94
+ set forceWasm(v) {
95
+ this._forceWasm = v;
96
+ }
97
+ /**
98
+ * Whether or not Wasm is supported based
99
+ * on the desired feature set
100
+ */
101
+ get isDesiredFeatureSetSupported() {
102
+ return this._isWasmFeatureSetSupported;
103
+ }
104
+ /**
105
+ * Whether or not Wasm detection has been run
106
+ * for the desired feature set
107
+ */
108
+ get isInitialized() {
109
+ return this._isInitialized;
110
+ }
111
+ /**
112
+ * Static creation & async initialization for use where
113
+ * async instantiation is possible
114
+ * @param desiredFeatures The desired feature set
115
+ * @returns An initialized instance of the class with detection
116
+ * for the desired feature set
117
+ */
118
+ static async create(desiredFeatures) {
119
+ const instance = new WasmSupport(desiredFeatures);
120
+ await instance.initialize();
121
+ return Promise.resolve(instance);
122
+ }
123
+ /**
124
+ * Checks for specific wasm features
125
+ * @param features The list of features to check for
126
+ * @returns True if all the features are supported, false otherwise
127
+ */
128
+ async featureCheck(features) {
129
+ const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()));
130
+ return results.every((result) => result);
131
+ }
132
+ /**
133
+ * Does feature detection for the desired feature set
134
+ */
135
+ async initialize() {
136
+ if (this._isInitialized)
137
+ return;
138
+ await this.detectDesiredFeatures();
139
+ this._isInitialized = true;
140
+ return;
141
+ }
142
+ async detectDesiredFeatures() {
143
+ for (let feature = 0; feature < this.desiredFeatures.length; feature++) {
144
+ const desiredFeature = this.desiredFeatures[feature];
145
+ const detector = WasmFeatureDetectors[desiredFeature];
146
+ if (!await detector()) {
147
+ this._featureSupport[desiredFeature] = false;
148
+ } else {
149
+ this._featureSupport[desiredFeature] = true;
150
+ }
151
+ }
152
+ this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v);
153
+ }
154
+ }
155
+ export {
156
+ WasmFeatureDetectors,
157
+ WasmSupport
158
+ };
159
+ //# 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,MAAM,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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIO,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAevB,YAAsB,iBAAgC;AAAhC;AAAA,EAAiC;AAAA,EAd/C,aAAa;AAAA,EACb,kBAAyD,CAAC;AAAA,EAC1D,aAAa;AAAA,EACb,iBAAiB;AAAA,EACjB,6BAA6B;AAAA;AAAA;AAAA;AAAA,EAerC,IAAI,YAAqB;AACvB,WAA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iB;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,166 @@
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/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ WasmFeatureDetectors: () => WasmFeatureDetectors,
24
+ WasmSupport: () => WasmSupport
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/WasmSupport.ts
29
+ var import_wasm_feature_detect = require("wasm-feature-detect");
30
+ var WasmFeatureDetectors = {
31
+ bigInt: import_wasm_feature_detect.bigInt,
32
+ bulkMemory: import_wasm_feature_detect.bulkMemory,
33
+ exceptions: import_wasm_feature_detect.exceptions,
34
+ extendedConst: import_wasm_feature_detect.extendedConst,
35
+ gc: import_wasm_feature_detect.gc,
36
+ memory64: import_wasm_feature_detect.memory64,
37
+ multiValue: import_wasm_feature_detect.multiValue,
38
+ mutableGlobals: import_wasm_feature_detect.mutableGlobals,
39
+ referenceTypes: import_wasm_feature_detect.referenceTypes,
40
+ relaxedSimd: import_wasm_feature_detect.relaxedSimd,
41
+ saturatedFloatToInt: import_wasm_feature_detect.saturatedFloatToInt,
42
+ signExtensions: import_wasm_feature_detect.signExtensions,
43
+ simd: import_wasm_feature_detect.simd,
44
+ streamingCompilation: import_wasm_feature_detect.streamingCompilation,
45
+ tailCall: import_wasm_feature_detect.tailCall,
46
+ threads: import_wasm_feature_detect.threads
47
+ };
48
+ var WasmSupport = class _WasmSupport {
49
+ /**
50
+ * Instance constructor for use where async instantiation
51
+ * is not possible. Where possible, prefer the static
52
+ * create method over use of this constructor directly
53
+ * as no initialization (feature detection) is able to
54
+ * be done here
55
+ * @param desiredFeatures The desired feature set
56
+ */
57
+ constructor(desiredFeatures) {
58
+ this.desiredFeatures = desiredFeatures;
59
+ }
60
+ _allowWasm = true;
61
+ _featureSupport = {};
62
+ _forceWasm = false;
63
+ _isInitialized = false;
64
+ _isWasmFeatureSetSupported = false;
65
+ /**
66
+ * Is Wasm allowed
67
+ */
68
+ get allowWasm() {
69
+ return this._allowWasm;
70
+ }
71
+ /**
72
+ * Whether or not to allow WASM usage
73
+ */
74
+ set allowWasm(v) {
75
+ this._allowWasm = v;
76
+ }
77
+ /**
78
+ * Whether or not Wasm should be used based on the desired
79
+ * feature set, initialization state, or force-use settings
80
+ */
81
+ get canUseWasm() {
82
+ return (
83
+ // Just force WASM
84
+ this._forceWasm || // Or if we haven't checked be optimistic
85
+ this._allowWasm && !this._isInitialized || // Or if we have checked and WASM is not supported, be realistic
86
+ this._allowWasm && this._isInitialized && this._isWasmFeatureSetSupported
87
+ );
88
+ }
89
+ /**
90
+ * Returns a object containing a property for each desired wasm feature
91
+ * with a boolean value indicating whether or not the feature is supported
92
+ */
93
+ get featureSupport() {
94
+ return { ...this._featureSupport };
95
+ }
96
+ /**
97
+ * Force use of Wasm
98
+ */
99
+ get forceWasm() {
100
+ return this._forceWasm;
101
+ }
102
+ /**
103
+ * Whether or not to force Wasm usage
104
+ */
105
+ set forceWasm(v) {
106
+ this._forceWasm = v;
107
+ }
108
+ /**
109
+ * Whether or not Wasm is supported based
110
+ * on the desired feature set
111
+ */
112
+ get isDesiredFeatureSetSupported() {
113
+ return this._isWasmFeatureSetSupported;
114
+ }
115
+ /**
116
+ * Whether or not Wasm detection has been run
117
+ * for the desired feature set
118
+ */
119
+ get isInitialized() {
120
+ return this._isInitialized;
121
+ }
122
+ /**
123
+ * Static creation & async initialization for use where
124
+ * async instantiation is possible
125
+ * @param desiredFeatures The desired feature set
126
+ * @returns An initialized instance of the class with detection
127
+ * for the desired feature set
128
+ */
129
+ static async create(desiredFeatures) {
130
+ const instance = new _WasmSupport(desiredFeatures);
131
+ await instance.initialize();
132
+ return Promise.resolve(instance);
133
+ }
134
+ /**
135
+ * Checks for specific wasm features
136
+ * @param features The list of features to check for
137
+ * @returns True if all the features are supported, false otherwise
138
+ */
139
+ async featureCheck(features) {
140
+ const results = await Promise.all(features.map((feature) => WasmFeatureDetectors[feature]).map(async (detector) => await detector()));
141
+ return results.every((result) => result);
142
+ }
143
+ /**
144
+ * Does feature detection for the desired feature set
145
+ */
146
+ async initialize() {
147
+ if (this._isInitialized)
148
+ return;
149
+ await this.detectDesiredFeatures();
150
+ this._isInitialized = true;
151
+ return;
152
+ }
153
+ async detectDesiredFeatures() {
154
+ for (let feature = 0; feature < this.desiredFeatures.length; feature++) {
155
+ const desiredFeature = this.desiredFeatures[feature];
156
+ const detector = WasmFeatureDetectors[desiredFeature];
157
+ if (!await detector()) {
158
+ this._featureSupport[desiredFeature] = false;
159
+ } else {
160
+ this._featureSupport[desiredFeature] = true;
161
+ }
162
+ }
163
+ this._isWasmFeatureSetSupported = Object.values(this._featureSupport).every((v) => v);
164
+ }
165
+ };
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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
- {"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"}
@@ -0,0 +1,2 @@
1
+ export * from './WasmSupport';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ export * from "./WasmSupport";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './WasmSupport'\n"],"mappings":"AAAA,cAAc;","names":[]}