@thumbmarkjs/thumbmarkjs 0.20.5 → 1.0.0-rc.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 (32) hide show
  1. package/dist/thumbmark.cjs.js +1 -1
  2. package/dist/thumbmark.cjs.js.map +1 -1
  3. package/dist/thumbmark.esm.d.ts +110 -16
  4. package/dist/thumbmark.esm.js +1 -1
  5. package/dist/thumbmark.esm.js.map +1 -1
  6. package/dist/thumbmark.umd.js +1 -1
  7. package/dist/thumbmark.umd.js.map +1 -1
  8. package/package.json +8 -2
  9. package/src/components/audio/{audio.ts → index.ts} +11 -8
  10. package/src/components/canvas/{canvas.ts → index.ts} +12 -8
  11. package/src/components/fonts/{fonts.ts → index.ts} +10 -5
  12. package/src/components/hardware/{hardware.ts → index.ts} +3 -5
  13. package/src/components/locales/{locales.ts → index.ts} +2 -4
  14. package/src/components/math/index.ts +28 -0
  15. package/src/components/permissions/{permissions.ts → index.ts} +7 -4
  16. package/src/components/plugins/{plugins.ts → index.ts} +2 -4
  17. package/src/components/screen/{screen.ts → index.ts} +2 -4
  18. package/src/components/system/{system.ts → index.ts} +12 -10
  19. package/src/components/webgl/{webgl.ts → index.ts} +3 -5
  20. package/src/factory.ts +40 -29
  21. package/src/fingerprint/functions.test.ts +12 -7
  22. package/src/fingerprint/functions.ts +248 -118
  23. package/src/fingerprint/legacy_functions.ts +54 -0
  24. package/src/fingerprint/options.ts +19 -8
  25. package/src/index.ts +12 -3
  26. package/src/thumbmark.ts +41 -0
  27. package/src/{declarations.d.ts → types/global.d.ts} +1 -1
  28. package/src/utils/filterComponents.ts +42 -0
  29. package/src/utils/raceAll.ts +0 -2
  30. package/src/components/index.ts +0 -17
  31. package/src/components/math/math.ts +0 -39
  32. /package/src/components/canvas/{canvas.test.ts → index.test.ts} +0 -0
@@ -1,118 +1,248 @@
1
- import {componentInterface, getComponentPromises, timeoutInstance} from '../factory'
2
- import {hash} from '../utils/hash'
3
- import {raceAll, raceAllPerformance} from '../utils/raceAll'
4
- import {options} from './options'
5
- import * as packageJson from '../../package.json'
6
-
7
- export function getVersion(): string {
8
- return packageJson.version
9
- }
10
-
11
- export async function getFingerprintData(): Promise<componentInterface> {
12
- try {
13
- const promiseMap: Record<string, Promise<componentInterface>> = getComponentPromises()
14
- const keys: string[] = Object.keys(promiseMap)
15
- const promises: Promise<componentInterface>[] = Object.values(promiseMap)
16
- const resolvedValues: (componentInterface | undefined)[] = await raceAll(promises, options?.timeout || 1000, timeoutInstance);
17
- const validValues: componentInterface[] = resolvedValues.filter((value): value is componentInterface => value !== undefined);
18
- const resolvedComponents: Record<string, componentInterface> = {};
19
- validValues.forEach((value, index) => {
20
- resolvedComponents[keys[index]] = value
21
- })
22
- return filterFingerprintData(resolvedComponents, options.exclude || [], options.include || [], "")
23
- }
24
- catch (error) {
25
- throw error
26
- }
27
- }
28
-
29
- /**
30
- * This function filters the fingerprint data based on the exclude and include list
31
- * @param {componentInterface} obj - components objects from main componentInterface
32
- * @param {string[]} excludeList - elements to exclude from components objects (e.g : 'canvas', 'system.browser')
33
- * @param {string[]} includeList - elements to only include from components objects (e.g : 'canvas', 'system.browser')
34
- * @param {string} path - auto-increment path iterating on key objects from components objects
35
- * @returns {componentInterface} result - returns the final object before hashing in order to get fingerprint
36
- */
37
- export function filterFingerprintData(obj: componentInterface, excludeList: string[], includeList: string[], path: string = ""): componentInterface {
38
- const result: componentInterface = {};
39
-
40
- for (const [key, value] of Object.entries(obj)) {
41
- const currentPath = path + key + ".";
42
-
43
- if (typeof value === "object" && !Array.isArray(value)) {
44
- const filtered = filterFingerprintData(value, excludeList, includeList, currentPath);
45
- if (Object.keys(filtered).length > 0) {
46
- result[key] = filtered;
47
- }
48
- } else {
49
- const isExcluded = excludeList.some(exclusion => currentPath.startsWith(exclusion));
50
- const isIncluded = includeList.some(inclusion => currentPath.startsWith(inclusion));
51
-
52
- if (!isExcluded || isIncluded) {
53
- result[key] = value;
54
- }
55
- }
56
- }
57
-
58
- return result;
59
- }
60
-
61
- export async function getFingerprint(includeData?: false): Promise<string>
62
- export async function getFingerprint(includeData: true): Promise<{ hash: string, data: componentInterface }>
63
- export async function getFingerprint(includeData?: boolean): Promise<string | { hash: string, data: componentInterface }> {
64
- try {
65
- const fingerprintData = await getFingerprintData()
66
- const thisHash = hash(JSON.stringify(fingerprintData))
67
- if (Math.random() < 0.00001 && options.logging) logFingerprintData(thisHash, fingerprintData)
68
- if (includeData) {
69
- return { hash: thisHash.toString(), data: fingerprintData}
70
- } else {
71
- return thisHash.toString()
72
- }
73
- } catch (error) {
74
- throw error
75
- }
76
- }
77
-
78
- export async function getFingerprintPerformance() {
79
- try {
80
- const promiseMap = getComponentPromises()
81
- const keys = Object.keys(promiseMap)
82
- const promises = Object.values(promiseMap)
83
- const resolvedValues = await raceAllPerformance(promises, options?.timeout || 1000, timeoutInstance )
84
- const resolvedComponents: { [key: string]: any } = {
85
- elapsed: {}
86
- }
87
- resolvedValues.forEach((value, index) => {
88
- resolvedComponents[keys[index]] = value.value
89
- resolvedComponents["elapsed"][keys[index]] = value.elapsed
90
- });
91
- return resolvedComponents
92
- }
93
- catch (error) {
94
- throw error
95
- }
96
- }
97
-
98
- // Function to log the fingerprint data
99
- async function logFingerprintData(thisHash: string, fingerprintData: componentInterface) {
100
- const url = 'https://logging.thumbmarkjs.com/v1/log'
101
- const payload = {
102
- thumbmark: thisHash,
103
- components: fingerprintData,
104
- version: getVersion()
105
- };
106
- if (!sessionStorage.getItem("_tmjs_l")) {
107
- sessionStorage.setItem("_tmjs_l", "1")
108
- try {
109
- await fetch(url, {
110
- method: 'POST',
111
- headers: {
112
- 'Content-Type': 'application/json'
113
- },
114
- body: JSON.stringify(payload)
115
- });
116
- } catch { } // do nothing
117
- }
118
- }
1
+ /**
2
+ * ThumbmarkJS: Main fingerprinting and API logic
3
+ *
4
+ * This module handles component collection, API calls, uniqueness scoring, and data filtering
5
+ * for the ThumbmarkJS browser fingerprinting library.
6
+ *
7
+ * Exports:
8
+ * - getThumbmark
9
+ * - getThumbmarkDataFromPromiseMap
10
+ * - resolveClientComponents
11
+ * - getVersion
12
+ * - filterThumbmarkData
13
+ *
14
+ * Internal helpers and types are also defined here.
15
+ */
16
+
17
+ // ===================== Imports =====================
18
+ import { defaultOptions, optionsInterface } from "./options";
19
+ import {
20
+ timeoutInstance,
21
+ componentInterface,
22
+ tm_component_promises,
23
+ customComponents,
24
+ includeComponent as globalIncludeComponent
25
+ } from "../factory";
26
+ import { hash } from "../utils/hash";
27
+ import { raceAllPerformance } from "../utils/raceAll";
28
+ import * as packageJson from '../../package.json';
29
+ import { filterThumbmarkData } from '../utils/filterComponents'
30
+
31
+ // ===================== Types & Interfaces =====================
32
+
33
+ /**
34
+ * Info returned from the API (IP, classification, uniqueness, etc)
35
+ */
36
+ interface infoInterface {
37
+ ip_address?: {
38
+ ip_address: string,
39
+ ip_identifier: string,
40
+ autonomous_system_number: number,
41
+ ip_version: 'v6' | 'v4',
42
+ },
43
+ classification?: {
44
+ tor: boolean,
45
+ proxy: boolean, // i.e. vpn and
46
+ datacenter: boolean,
47
+ danger_level: number, // 5 is highest and should be blocked. 0 is no danger.
48
+ },
49
+ uniqueness?: {
50
+ score: number | string
51
+ }
52
+ }
53
+
54
+ /**
55
+ * API response structure
56
+ */
57
+ interface apiResponse {
58
+ thumbmark?: string;
59
+ info?: infoInterface;
60
+ version?: string;
61
+ }
62
+
63
+ /**
64
+ * Final thumbmark response structure
65
+ */
66
+ interface thumbmarkResponse {
67
+ components: componentInterface,
68
+ info: { [key: string]: any },
69
+ version: string,
70
+ thumbmark: string,
71
+ /**
72
+ * Only present if options.performance is true.
73
+ */
74
+ elapsed?: any;
75
+ }
76
+
77
+ // ===================== Version =====================
78
+
79
+ /**
80
+ * Returns the current package version
81
+ */
82
+ export function getVersion(): string {
83
+ return packageJson.version;
84
+ }
85
+
86
+ // ===================== API Call Logic =====================
87
+
88
+ let currentApiPromise: Promise<apiResponse> | null = null;
89
+ let apiPromiseResult: apiResponse | null = null;
90
+
91
+ /**
92
+ * Calls the Thumbmark API with the given components, using caching and deduplication.
93
+ * Returns a promise for the API response or null on error.
94
+ */
95
+ export const getApiPromise = (
96
+ options: optionsInterface,
97
+ components: componentInterface
98
+ ): Promise<apiResponse | null> => {
99
+ // 1. If a result is already cached and caching is enabled, return it.
100
+ if (options.cache_api_call && apiPromiseResult) {
101
+ return Promise.resolve(apiPromiseResult);
102
+ }
103
+
104
+ // 2. If a request is already in flight, return that promise to prevent duplicate calls.
105
+ if (currentApiPromise) {
106
+ return currentApiPromise;
107
+ }
108
+
109
+ // 3. Otherwise, initiate a new API call.
110
+ const endpoint = 'https://api-dev.thumbmarkjs.com/thumbmark';
111
+ currentApiPromise = fetch(endpoint, {
112
+ method: 'POST',
113
+ headers: {
114
+ 'x-api-key': options.api_key!,
115
+ 'Authorization': 'custom-authorized',
116
+ },
117
+ body: JSON.stringify({ components: components, clientHash: hash(JSON.stringify(components)) }),
118
+ })
119
+ .then(response => {
120
+ // Handle HTTP errors that aren't network errors
121
+ if (!response.ok) {
122
+ throw new Error(`HTTP error! status: ${response.status}`);
123
+ }
124
+ return response.json();
125
+ })
126
+ .then(data => {
127
+ apiPromiseResult = data; // Cache the successful result
128
+ currentApiPromise = null; // Clear the in-flight promise
129
+ return data;
130
+ })
131
+ .catch(error => {
132
+ console.error('Error fetching pro data', error);
133
+ currentApiPromise = null; // Also clear the in-flight promise on error
134
+ // Return null instead of a string to prevent downstream crashes
135
+ return null;
136
+ });
137
+
138
+ return currentApiPromise;
139
+ };
140
+
141
+ // ===================== Main Thumbmark Logic =====================
142
+
143
+ /**
144
+ * Main entry point: collects all components, optionally calls API, and returns thumbmark data.
145
+ *
146
+ * @param options - Options for fingerprinting and API
147
+ * @returns thumbmarkResponse (elapsed is present only if options.performance is true)
148
+ */
149
+ export async function getThumbmark(options?: optionsInterface): Promise<thumbmarkResponse> {
150
+ const _options = { ...defaultOptions, ...options };
151
+ // Merge built-in and user-registered components
152
+ const allComponents = { ...tm_component_promises, ...customComponents };
153
+ const { elapsed, resolvedComponents: clientComponentsResult } = await resolveClientComponents(allComponents, _options);
154
+
155
+ const apiPromise = _options.api_key ? getApiPromise(_options, clientComponentsResult) : null;
156
+ const apiResult = apiPromise ? await apiPromise : null;
157
+
158
+ // Only add 'elapsed' if performance is true
159
+ const maybeElapsed = _options.performance ? { elapsed } : {};
160
+
161
+ if (apiResult) {
162
+ const info: infoInterface = apiResult.info || {};
163
+ return {
164
+ components: clientComponentsResult,
165
+ info,
166
+ version: getVersion(),
167
+ thumbmark: apiResult.thumbmark || 'undefined',
168
+ ...maybeElapsed,
169
+ };
170
+ }
171
+ return {
172
+ thumbmark: hash(JSON.stringify(clientComponentsResult)),
173
+ components: clientComponentsResult,
174
+ info: {
175
+ uniqueness: 'api only'
176
+ },
177
+ version: getVersion(),
178
+ ...maybeElapsed,
179
+ };
180
+ }
181
+
182
+ // ===================== Component Resolution & Performance =====================
183
+
184
+ /**
185
+ * Resolves and times all filtered component promises from a component function map.
186
+ *
187
+ * @param comps - Map of component functions
188
+ * @param options - Options for filtering and timing
189
+ * @returns Object with elapsed times and filtered resolved components
190
+ */
191
+ export async function resolveClientComponents(
192
+ comps: { [key: string]: (options?: optionsInterface) => Promise<componentInterface | null> },
193
+ options?: optionsInterface
194
+ ): Promise<{ elapsed: Record<string, number>, resolvedComponents: componentInterface }> {
195
+ const opts = { ...defaultOptions, ...options };
196
+ const filtered = Object.entries(comps)
197
+ .filter(([key]) => !opts?.exclude?.includes(key))
198
+ .filter(([key]) =>
199
+ opts?.include?.some(e => e.includes('.'))
200
+ ? opts?.include?.some(e => e.startsWith(key))
201
+ : opts?.include?.length === 0 || opts?.include?.includes(key)
202
+ );
203
+ const keys = filtered.map(([key]) => key);
204
+ const promises = filtered.map(([_, fn]) => fn());
205
+ const resolvedValues = await raceAllPerformance(promises, opts?.timeout || 1000, timeoutInstance);
206
+
207
+ const elapsed: Record<string, number> = {};
208
+ const resolvedComponentsRaw: Record<string, componentInterface> = {};
209
+
210
+ resolvedValues.forEach((value, index) => {
211
+ if (value.value != null) {
212
+ resolvedComponentsRaw[keys[index]] = value.value;
213
+ elapsed[keys[index]] = value.elapsed ?? 0;
214
+ }
215
+ });
216
+
217
+ const resolvedComponents = filterThumbmarkData(resolvedComponentsRaw, opts, "");
218
+ return { elapsed, resolvedComponents };
219
+ }
220
+
221
+ // ===================== Logging (Internal) =====================
222
+
223
+ /**
224
+ * Logs thumbmark data to remote logging endpoint (only once per session)
225
+ * @internal
226
+ */
227
+ async function logThumbmarkData(thisHash: string, thumbmarkData: componentInterface) {
228
+ const url = 'https://logging.thumbmarkjs.com/v1/log';
229
+ const payload = {
230
+ thumbmark: thisHash,
231
+ components: thumbmarkData,
232
+ version: getVersion()
233
+ };
234
+ if (!sessionStorage.getItem("_tmjs_l")) {
235
+ sessionStorage.setItem("_tmjs_l", "1");
236
+ try {
237
+ await fetch(url, {
238
+ method: 'POST',
239
+ headers: {
240
+ 'Content-Type': 'application/json'
241
+ },
242
+ body: JSON.stringify(payload)
243
+ });
244
+ } catch { /* do nothing */ }
245
+ }
246
+ }
247
+
248
+ export { globalIncludeComponent as includeComponent };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * This file is here to support legacy implementations.
3
+ * Eventually, these functions will be removed to keep the library small.
4
+ */
5
+
6
+ import { componentInterface } from '../factory'
7
+ import { options} from './options'
8
+ import { resolveClientComponents, getThumbmark } from './functions';
9
+ import { tm_component_promises } from "../factory";
10
+
11
+ /**
12
+ *
13
+ * @deprecated
14
+ */
15
+ export async function getFingerprintData() {
16
+ const thumbmarkData = await getThumbmark(options);
17
+ return thumbmarkData.components;
18
+ }
19
+
20
+ /**
21
+ *
22
+ * @param includeData boolean
23
+ * @deprecated this function is going to be removed. use getThumbmark or Thumbmark class instead.
24
+ */
25
+ export async function getFingerprint(includeData?: false): Promise<string>
26
+ export async function getFingerprint(includeData: true): Promise<{ hash: string, data: componentInterface }>
27
+ export async function getFingerprint(includeData?: boolean): Promise<string | { hash: string, data: componentInterface }> {
28
+ try {
29
+ const thumbmarkData = await getThumbmark(options);
30
+ if (includeData) {
31
+ return { hash: thumbmarkData.thumbmark.toString(), data: thumbmarkData.components}
32
+ } else {
33
+ return thumbmarkData.thumbmark.toString()
34
+ }
35
+ } catch (error) {
36
+ throw error
37
+ }
38
+ }
39
+ /**
40
+ *
41
+ * @deprecated use Thumbmark or getThumbmark instead with options
42
+ */
43
+ export async function getFingerprintPerformance() {
44
+ try {
45
+ const { elapsed, resolvedComponents } = await resolveClientComponents(tm_component_promises, options);
46
+ // Legacy format: merge resolvedComponents and elapsed into one object
47
+ return {
48
+ ...resolvedComponents,
49
+ elapsed
50
+ };
51
+ } catch (error) {
52
+ throw error;
53
+ }
54
+ }
@@ -1,23 +1,34 @@
1
1
  export interface optionsInterface {
2
- exclude: string[],
3
- include: string[],
2
+ exclude?: string[],
3
+ include?: string[],
4
4
  webgl_runs?: number,
5
5
  canvas_runs?: number,
6
6
  permissions_to_check?: PermissionName[], // new option
7
7
  retries?: number, // new option
8
- timeout: number, // new option
9
- logging: boolean
8
+ timeout?: number, // new option
9
+ logging?: boolean,
10
+ api_key?: string,
11
+ cache_api_call?: boolean,
12
+ performance?: boolean, // re-added
10
13
  }
11
14
 
12
- export let options: optionsInterface = {
15
+ export const defaultOptions: optionsInterface = {
13
16
  exclude: [],
14
17
  include: [],
15
18
  logging: true,
16
- timeout: 1000
17
- }
19
+ timeout: 5000,
20
+ cache_api_call: true,
21
+ performance: false // re-added
22
+ };
18
23
 
24
+ export let options = {...defaultOptions};
25
+ /**
26
+ *
27
+ * @param key @deprecated this function will be removed
28
+ * @param value
29
+ */
19
30
  export function setOption<K extends keyof optionsInterface>(key: K, value: optionsInterface[K]) {
20
- if (!['include', 'exclude', 'permissions_to_check', 'retries', 'timeout', 'logging'].includes(key))
31
+ if (!['include', 'exclude', 'permissions_to_check', 'retries', 'timeout', 'logging', 'api_key', 'cache_api_call'].includes(key))
21
32
  throw new Error('Unknown option ' + key)
22
33
  if (['include', 'exclude', 'permissions_to_check'].includes(key) && !(Array.isArray(value) && value.every(item => typeof item === 'string')) )
23
34
  throw new Error('The value of the include, exclude and permissions_to_check must be an array of strings');
package/src/index.ts CHANGED
@@ -1,6 +1,15 @@
1
- import { getFingerprint, getFingerprintData, getFingerprintPerformance, getVersion } from './fingerprint/functions'
1
+ import {
2
+ getFingerprint,
3
+ getFingerprintData,
4
+ getFingerprintPerformance
5
+ } from './fingerprint/legacy_functions'
6
+ import { getThumbmark, getVersion } from './fingerprint/functions'
2
7
  import { setOption } from './fingerprint/options'
3
8
  import { includeComponent } from './factory'
4
- import './components'
9
+ import { Thumbmark } from './thumbmark'
5
10
 
6
- export { setOption, getVersion, getFingerprint, getFingerprintData, getFingerprintPerformance, includeComponent }
11
+ export { Thumbmark, getThumbmark, getVersion,
12
+
13
+ // deprecated functions. Don't use anymore.
14
+ setOption, getFingerprint, getFingerprintData, getFingerprintPerformance, includeComponent
15
+ }
@@ -0,0 +1,41 @@
1
+ import { optionsInterface } from "./fingerprint/options";
2
+ import { getThumbmark, getVersion, includeComponent as globalIncludeComponent } from './fingerprint/functions';
3
+ import { defaultOptions } from "./fingerprint/options";
4
+ import { componentInterface } from "./factory";
5
+
6
+ /**
7
+ * A client for generating thumbmarks with a persistent configuration.
8
+ */
9
+
10
+ export class Thumbmark {
11
+ private options: optionsInterface;
12
+
13
+ /**
14
+ * Creates a new Thumbmarker client instance.
15
+ * @param options - Default configuration options for this instance.
16
+ */
17
+ constructor(options?: optionsInterface) {
18
+ this.options = { ...defaultOptions, ...options };
19
+ }
20
+
21
+ /**
22
+ * Generates a thumbmark using the instance's configuration.
23
+ * @param overrideOptions - Options to override for this specific call.
24
+ * @returns The thumbmark result.
25
+ */
26
+ public async get(overrideOptions?: optionsInterface): Promise<any> {
27
+ const finalOptions = { ...this.options, ...overrideOptions };
28
+ return getThumbmark(finalOptions);
29
+ }
30
+ public getVersion(): string {
31
+ return getVersion()
32
+ }
33
+ /**
34
+ * Register a custom component to be included in the fingerprint.
35
+ * @param key - The component name
36
+ * @param fn - The component function
37
+ */
38
+ public includeComponent(key: string, fn: (options?: optionsInterface) => Promise<componentInterface | null>) {
39
+ globalIncludeComponent(key, fn);
40
+ }
41
+ }
@@ -5,8 +5,8 @@ interface ApplePaySession {
5
5
  }
6
6
 
7
7
  interface Window {
8
- webkitAudioContext: typeof AudioContext
9
8
  webkitOfflineAudioContext: typeof OfflineAudioContext
9
+ webkitAudioContext: typeof AudioContext
10
10
  ApplePaySession: typeof ApplePaySession
11
11
  }
12
12
 
@@ -0,0 +1,42 @@
1
+ import { componentInterface } from "../factory";
2
+ import { optionsInterface } from "../fingerprint/options";
3
+
4
+ // ===================== Data Filtering =====================
5
+
6
+ /**
7
+ * Recursively filters a componentInterface object by include/exclude options.
8
+ *
9
+ * @param obj - The object to filter
10
+ * @param options - Filtering options
11
+ * @param path - Current path (for recursion)
12
+ * @returns Filtered object
13
+ */
14
+ export function filterThumbmarkData(
15
+ obj: componentInterface,
16
+ options?: optionsInterface,
17
+ path: string = ""
18
+ ): componentInterface {
19
+ const result: componentInterface = {};
20
+ const excludeList = options?.exclude || [];
21
+ const includeList = options?.include || [];
22
+
23
+ for (const [key, value] of Object.entries(obj)) {
24
+ const currentPath = path + key + ".";
25
+
26
+ if (typeof value === "object" && !Array.isArray(value)) {
27
+ const filtered = filterThumbmarkData(value, options, currentPath);
28
+ if (Object.keys(filtered).length > 0) {
29
+ result[key] = filtered;
30
+ }
31
+ } else {
32
+ const isExcluded = excludeList.some(exclusion => currentPath.startsWith(exclusion));
33
+ const isIncluded = includeList.some(inclusion => currentPath.startsWith(inclusion));
34
+
35
+ if (!isExcluded || isIncluded) {
36
+ result[key] = value;
37
+ }
38
+ }
39
+ }
40
+
41
+ return result;
42
+ }
@@ -1,5 +1,3 @@
1
- import { componentInterface } from '../factory'
2
-
3
1
  type DelayedPromise<T> = Promise<T>;
4
2
 
5
3
  export function delay<T>(t: number, val: T): DelayedPromise<T> {
@@ -1,17 +0,0 @@
1
- /**
2
- * Does anyone have a cleaner way of doing this?
3
- * I want to import all the components in this folder
4
- * Feels a little dumb I'm doing this manually.
5
- */
6
-
7
- import './audio/audio'
8
- import './canvas/canvas'
9
- import './fonts/fonts'
10
- import './hardware/hardware'
11
- import './locales/locales'
12
- import './permissions/permissions'
13
- import './plugins/plugins'
14
- import './screen/screen'
15
- import './system/system'
16
- import './webgl/webgl'
17
- import './math/math'
@@ -1,39 +0,0 @@
1
- import { componentInterface, includeComponent } from '../../factory'
2
-
3
- const getMathInfo = async (): Promise<componentInterface> => {
4
- return {
5
- acos: Math.acos(0.5),
6
- asin: integrate(Math.asin, -1, 1, 97),
7
- atan: integrate(Math.atan, -1, 1, 97),
8
- cos: integrate(Math.cos, 0, Math.PI, 97),
9
- cosh: Math.cosh(9/7),
10
- e: Math.E,
11
- largeCos: Math.cos(1e20),
12
- largeSin: Math.sin(1e20),
13
- largeTan: Math.tan(1e20),
14
- log: Math.log(1000),
15
- pi: Math.PI,
16
- sin: integrate(Math.sin, -Math.PI, Math.PI, 97),
17
- sinh: integrate(Math.sinh, -9/7, 7/9, 97),
18
- sqrt: Math.sqrt(2),
19
- tan: integrate(Math.tan, 0, 2 * Math.PI, 97),
20
- tanh: integrate(Math.tanh, -9/7, 7/9, 97),
21
- }
22
- }
23
-
24
- /** This might be a little excessive, but I wasn't sure what number to pick for some of the
25
- * trigonometric functions. Using an integral here, so a few numbers are calculated. However,
26
- * I do this mainly for those integrals that sum up to a small value, otherwise there's no point.
27
- */
28
-
29
- const integrate = (f: (x: number) => number, a: number, b: number, n: number): number => {
30
- const h = (b - a) / n;
31
- let sum = 0;
32
- for (let i = 0; i < n; i++) {
33
- const x = a + (i + 0.5) * h;
34
- sum += f(x);
35
- }
36
- return sum * h;
37
- };
38
-
39
- includeComponent('math', getMathInfo);