@bitbybit-dev/base 0.19.0-alpha.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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/babel.config.cjs +14 -0
  4. package/babel.config.d.cts +5 -0
  5. package/index.d.ts +1 -0
  6. package/index.js +4 -0
  7. package/lib/api/index.d.ts +1 -0
  8. package/lib/api/index.js +1 -0
  9. package/lib/api/inputs/base-inputs.d.ts +35 -0
  10. package/lib/api/inputs/base-inputs.js +1 -0
  11. package/lib/api/inputs/color-inputs.d.ts +122 -0
  12. package/lib/api/inputs/color-inputs.js +164 -0
  13. package/lib/api/inputs/index.d.ts +8 -0
  14. package/lib/api/inputs/index.js +8 -0
  15. package/lib/api/inputs/inputs.d.ts +10 -0
  16. package/lib/api/inputs/inputs.js +10 -0
  17. package/lib/api/inputs/lists-inputs.d.ts +478 -0
  18. package/lib/api/inputs/lists-inputs.js +576 -0
  19. package/lib/api/inputs/logic-inputs.d.ts +163 -0
  20. package/lib/api/inputs/logic-inputs.js +111 -0
  21. package/lib/api/inputs/math-inputs.d.ts +311 -0
  22. package/lib/api/inputs/math-inputs.js +391 -0
  23. package/lib/api/inputs/point-inputs.d.ts +446 -0
  24. package/lib/api/inputs/point-inputs.js +521 -0
  25. package/lib/api/inputs/text-inputs.d.ts +83 -0
  26. package/lib/api/inputs/text-inputs.js +120 -0
  27. package/lib/api/inputs/transforms-inputs.d.ts +136 -0
  28. package/lib/api/inputs/transforms-inputs.js +200 -0
  29. package/lib/api/inputs/vector-inputs.d.ts +300 -0
  30. package/lib/api/inputs/vector-inputs.js +304 -0
  31. package/lib/api/services/color.d.ts +114 -0
  32. package/lib/api/services/color.js +170 -0
  33. package/lib/api/services/geometry-helper.d.ts +15 -0
  34. package/lib/api/services/geometry-helper.js +151 -0
  35. package/lib/api/services/index.d.ts +9 -0
  36. package/lib/api/services/index.js +9 -0
  37. package/lib/api/services/lists.d.ts +287 -0
  38. package/lib/api/services/lists.js +682 -0
  39. package/lib/api/services/logic.d.ts +99 -0
  40. package/lib/api/services/logic.js +203 -0
  41. package/lib/api/services/math.d.ts +349 -0
  42. package/lib/api/services/math.js +621 -0
  43. package/lib/api/services/point.d.ts +223 -0
  44. package/lib/api/services/point.js +351 -0
  45. package/lib/api/services/text.d.ts +69 -0
  46. package/lib/api/services/text.js +84 -0
  47. package/lib/api/services/transforms.d.ts +122 -0
  48. package/lib/api/services/transforms.js +256 -0
  49. package/lib/api/services/vector.d.ts +320 -0
  50. package/lib/api/services/vector.js +468 -0
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.js +1 -0
  53. package/package.json +93 -0
@@ -0,0 +1,621 @@
1
+ import * as Inputs from "../inputs/inputs";
2
+ /**
3
+ * Contains various math methods.
4
+ */
5
+ export class MathBitByBit {
6
+ /**
7
+ * Creates a number
8
+ * @param inputs a number to be created
9
+ * @returns number
10
+ * @group create
11
+ * @shortname number
12
+ * @drawable false
13
+ */
14
+ number(inputs) {
15
+ return inputs.number;
16
+ }
17
+ /**
18
+ * Does basic math operations
19
+ * @param inputs two numbers and operator
20
+ * @returns Result of math operation action
21
+ * @group operations
22
+ * @shortname two numbers
23
+ * @drawable false
24
+ */
25
+ twoNrOperation(inputs) {
26
+ let result;
27
+ switch (inputs.operation) {
28
+ case Inputs.Math.mathTwoNrOperatorEnum.add:
29
+ result = inputs.first + inputs.second;
30
+ break;
31
+ case Inputs.Math.mathTwoNrOperatorEnum.subtract:
32
+ result = inputs.first - inputs.second;
33
+ break;
34
+ case Inputs.Math.mathTwoNrOperatorEnum.multiply:
35
+ result = inputs.first * inputs.second;
36
+ break;
37
+ case Inputs.Math.mathTwoNrOperatorEnum.divide:
38
+ result = inputs.first / inputs.second;
39
+ break;
40
+ case Inputs.Math.mathTwoNrOperatorEnum.power:
41
+ result = Math.pow(inputs.first, inputs.second);
42
+ break;
43
+ case Inputs.Math.mathTwoNrOperatorEnum.modulus:
44
+ result = inputs.first % inputs.second;
45
+ break;
46
+ default:
47
+ break;
48
+ }
49
+ return result;
50
+ }
51
+ /**
52
+ * Does modulus operation
53
+ * @param inputs two numbers and operator
54
+ * @returns Result of modulus operation
55
+ * @group operations
56
+ * @shortname modulus
57
+ * @drawable false
58
+ */
59
+ modulus(inputs) {
60
+ return this.twoNrOperation({ first: inputs.number, second: inputs.modulus, operation: Inputs.Math.mathTwoNrOperatorEnum.modulus });
61
+ }
62
+ /**
63
+ * Does rounding to decimals
64
+ * @param inputs a number and decimal places
65
+ * @returns Result of rounding
66
+ * @group operations
67
+ * @shortname round to decimals
68
+ * @drawable false
69
+ */
70
+ roundToDecimals(inputs) {
71
+ return Math.round(inputs.number * Math.pow(10, inputs.decimalPlaces)) / Math.pow(10, inputs.decimalPlaces);
72
+ }
73
+ /**
74
+ * Does basic math operations on one number
75
+ * @param inputs one number and operator action
76
+ * @returns Result of math operation
77
+ * @group operations
78
+ * @shortname one number
79
+ * @drawable false
80
+ */
81
+ oneNrOperation(inputs) {
82
+ let result;
83
+ switch (inputs.operation) {
84
+ case Inputs.Math.mathOneNrOperatorEnum.absolute:
85
+ result = Math.abs(inputs.number);
86
+ break;
87
+ case Inputs.Math.mathOneNrOperatorEnum.negate:
88
+ result = -inputs.number;
89
+ break;
90
+ case Inputs.Math.mathOneNrOperatorEnum.ln:
91
+ result = Math.log(inputs.number);
92
+ break;
93
+ case Inputs.Math.mathOneNrOperatorEnum.log10:
94
+ result = Math.log10(inputs.number);
95
+ break;
96
+ case Inputs.Math.mathOneNrOperatorEnum.tenPow:
97
+ result = Math.pow(10, inputs.number);
98
+ break;
99
+ case Inputs.Math.mathOneNrOperatorEnum.round:
100
+ result = Math.round(inputs.number);
101
+ break;
102
+ case Inputs.Math.mathOneNrOperatorEnum.floor:
103
+ result = Math.floor(inputs.number);
104
+ break;
105
+ case Inputs.Math.mathOneNrOperatorEnum.ceil:
106
+ result = Math.ceil(inputs.number);
107
+ break;
108
+ case Inputs.Math.mathOneNrOperatorEnum.sqrt:
109
+ result = Math.sqrt(inputs.number);
110
+ break;
111
+ case Inputs.Math.mathOneNrOperatorEnum.sin:
112
+ result = Math.sin(inputs.number);
113
+ break;
114
+ case Inputs.Math.mathOneNrOperatorEnum.cos:
115
+ result = Math.cos(inputs.number);
116
+ break;
117
+ case Inputs.Math.mathOneNrOperatorEnum.tan:
118
+ result = Math.tan(inputs.number);
119
+ break;
120
+ case Inputs.Math.mathOneNrOperatorEnum.asin:
121
+ result = Math.asin(inputs.number);
122
+ break;
123
+ case Inputs.Math.mathOneNrOperatorEnum.acos:
124
+ result = Math.acos(inputs.number);
125
+ break;
126
+ case Inputs.Math.mathOneNrOperatorEnum.atan:
127
+ result = Math.atan(inputs.number);
128
+ break;
129
+ case Inputs.Math.mathOneNrOperatorEnum.log:
130
+ result = Math.log(inputs.number);
131
+ break;
132
+ case Inputs.Math.mathOneNrOperatorEnum.exp:
133
+ result = Math.exp(inputs.number);
134
+ break;
135
+ case Inputs.Math.mathOneNrOperatorEnum.degToRad:
136
+ result = inputs.number * Math.PI / 180;
137
+ break;
138
+ case Inputs.Math.mathOneNrOperatorEnum.radToDeg:
139
+ result = inputs.number * 180 / Math.PI;
140
+ break;
141
+ default:
142
+ break;
143
+ }
144
+ return result;
145
+ }
146
+ /**
147
+ * Remaps a number from one range to another
148
+ * @param inputs one number and operator action
149
+ * @returns Result of mapping
150
+ * @group operations
151
+ * @shortname remap
152
+ * @drawable false
153
+ */
154
+ remap(inputs) {
155
+ return (inputs.number - inputs.fromLow) * (inputs.toHigh - inputs.toLow) / (inputs.fromHigh - inputs.fromLow) + inputs.toLow;
156
+ }
157
+ /**
158
+ * Creates a random number between 0 and 1
159
+ * @returns A random number between 0 and 1
160
+ * @group generate
161
+ * @shortname random 0 - 1
162
+ * @drawable false
163
+ */
164
+ random() {
165
+ return Math.random();
166
+ }
167
+ /**
168
+ * Creates a random number between low and high value
169
+ * @param inputs low and high numbers
170
+ * @returns A random number
171
+ * @group generate
172
+ * @shortname random number
173
+ * @drawable false
174
+ */
175
+ randomNumber(inputs) {
176
+ return Math.random() * (inputs.high - inputs.low) + inputs.low;
177
+ }
178
+ /**
179
+ * Creates random numbers between low and high values
180
+ * @param inputs low and high numbers
181
+ * @returns A list of random numbers
182
+ * @group generate
183
+ * @shortname random numbers
184
+ * @drawable false
185
+ */
186
+ randomNumbers(inputs) {
187
+ const result = [];
188
+ for (let i = 0; i < inputs.count; i++) {
189
+ result.push(this.randomNumber(inputs));
190
+ }
191
+ return result;
192
+ }
193
+ /**
194
+ * Creates a PI number
195
+ * @returns A number PI
196
+ * @group generate
197
+ * @shortname π
198
+ * @drawable false
199
+ */
200
+ pi() {
201
+ return Math.PI;
202
+ }
203
+ /**
204
+ * Rounds the number to decimal places
205
+ * @param inputs a number to be rounded to decimal places
206
+ * @returns number
207
+ * @group operations
208
+ * @shortname to fixed
209
+ * @drawable false
210
+ */
211
+ toFixed(inputs) {
212
+ return inputs.number.toFixed(inputs.decimalPlaces);
213
+ }
214
+ /**
215
+ * Adds two numbers
216
+ * @param inputs two numbers
217
+ * @returns number
218
+ * @group basics
219
+ * @shortname add
220
+ * @drawable false
221
+ */
222
+ add(inputs) {
223
+ return inputs.first + inputs.second;
224
+ }
225
+ /**
226
+ * Subtracts two numbers
227
+ * @param inputs two numbers
228
+ * @returns number
229
+ * @group basics
230
+ * @shortname subtract
231
+ * @drawable false
232
+ */
233
+ subtract(inputs) {
234
+ return inputs.first - inputs.second;
235
+ }
236
+ /**
237
+ * Multiplies two numbers
238
+ * @param inputs two numbers
239
+ * @returns number
240
+ * @group basics
241
+ * @shortname multiply
242
+ * @drawable false
243
+ */
244
+ multiply(inputs) {
245
+ return inputs.first * inputs.second;
246
+ }
247
+ /**
248
+ * Divides two numbers
249
+ * @param inputs two numbers
250
+ * @returns number
251
+ * @group basics
252
+ * @shortname divide
253
+ * @drawable false
254
+ */
255
+ divide(inputs) {
256
+ return inputs.first / inputs.second;
257
+ }
258
+ /**
259
+ * Powers a number
260
+ * @param inputs two numbers
261
+ * @returns number
262
+ * @group basics
263
+ * @shortname power
264
+ * @drawable false
265
+ */
266
+ power(inputs) {
267
+ return Math.pow(inputs.first, inputs.second);
268
+ }
269
+ /**
270
+ * Gets the square root of a number
271
+ * @param inputs a number
272
+ * @returns number
273
+ * @group basics
274
+ * @shortname sqrt
275
+ * @drawable false
276
+ */
277
+ sqrt(inputs) {
278
+ return Math.sqrt(inputs.number);
279
+ }
280
+ /**
281
+ * Gets the absolute value of a number
282
+ * @param inputs a number
283
+ * @returns number
284
+ * @group basics
285
+ * @shortname abs
286
+ * @drawable false
287
+ */
288
+ abs(inputs) {
289
+ return Math.abs(inputs.number);
290
+ }
291
+ /**
292
+ * Rounds a number
293
+ * @param inputs a number
294
+ * @returns number
295
+ * @group basics
296
+ * @shortname round
297
+ * @drawable false
298
+ */
299
+ round(inputs) {
300
+ return Math.round(inputs.number);
301
+ }
302
+ /**
303
+ * Floors a number
304
+ * @param inputs a number
305
+ * @returns number
306
+ * @group basics
307
+ * @shortname floor
308
+ * @drawable false
309
+ */
310
+ floor(inputs) {
311
+ return Math.floor(inputs.number);
312
+ }
313
+ /**
314
+ * Ceils a number
315
+ * @param inputs a number
316
+ * @returns number
317
+ * @group basics
318
+ * @shortname ceil
319
+ * @drawable false
320
+ */
321
+ ceil(inputs) {
322
+ return Math.ceil(inputs.number);
323
+ }
324
+ /**
325
+ * Negates a number
326
+ * @param inputs a number
327
+ * @returns number
328
+ * @group basics
329
+ * @shortname negate
330
+ * @drawable false
331
+ */
332
+ negate(inputs) {
333
+ return -inputs.number;
334
+ }
335
+ /**
336
+ * Gets the natural logarithm of a number
337
+ * @param inputs a number
338
+ * @returns number
339
+ * @group basics
340
+ * @shortname ln
341
+ * @drawable false
342
+ */
343
+ ln(inputs) {
344
+ return Math.log(inputs.number);
345
+ }
346
+ /**
347
+ * Gets the base 10 logarithm of a number
348
+ * @param inputs a number
349
+ * @returns number
350
+ * @group basics
351
+ * @shortname log10
352
+ * @drawable false
353
+ */
354
+ log10(inputs) {
355
+ return Math.log10(inputs.number);
356
+ }
357
+ /**
358
+ * Raises 10 to the power of a number
359
+ * @param inputs a number
360
+ * @returns number
361
+ * @group basics
362
+ * @shortname ten pow
363
+ * @drawable false
364
+ */
365
+ tenPow(inputs) {
366
+ return Math.pow(10, inputs.number);
367
+ }
368
+ /**
369
+ * Gets the sine of a number
370
+ * @param inputs a number
371
+ * @returns number
372
+ * @group basics
373
+ * @shortname sin
374
+ * @drawable false
375
+ */
376
+ sin(inputs) {
377
+ return Math.sin(inputs.number);
378
+ }
379
+ /**
380
+ * Gets the cosine of a number
381
+ * @param inputs a number
382
+ * @returns number
383
+ * @group basics
384
+ * @shortname cos
385
+ * @drawable false
386
+ */
387
+ cos(inputs) {
388
+ return Math.cos(inputs.number);
389
+ }
390
+ /**
391
+ * Gets the tangent of a number
392
+ * @param inputs a number
393
+ * @returns number
394
+ * @group basics
395
+ * @shortname tan
396
+ * @drawable false
397
+ */
398
+ tan(inputs) {
399
+ return Math.tan(inputs.number);
400
+ }
401
+ /**
402
+ * Gets the arcsine of a number
403
+ * @param inputs a number
404
+ * @returns number
405
+ * @group basics
406
+ * @shortname asin
407
+ * @drawable false
408
+ */
409
+ asin(inputs) {
410
+ return Math.asin(inputs.number);
411
+ }
412
+ /**
413
+ * Gets the arccosine of a number
414
+ * @param inputs a number
415
+ * @returns number
416
+ * @group basics
417
+ * @shortname acos
418
+ * @drawable false
419
+ */
420
+ acos(inputs) {
421
+ return Math.acos(inputs.number);
422
+ }
423
+ /**
424
+ * Gets the arctangent of a number
425
+ * @param inputs a number
426
+ * @returns number
427
+ * @group basics
428
+ * @shortname atan
429
+ * @drawable false
430
+ */
431
+ atan(inputs) {
432
+ return Math.atan(inputs.number);
433
+ }
434
+ /**
435
+ * Gets the natural exponent of a number
436
+ * @param inputs a number
437
+ * @returns number
438
+ * @group basics
439
+ * @shortname exp
440
+ * @drawable false
441
+ */
442
+ exp(inputs) {
443
+ return Math.exp(inputs.number);
444
+ }
445
+ /**
446
+ * Converts degrees to radians
447
+ * @param inputs a number in degrees
448
+ * @returns number
449
+ * @group basics
450
+ * @shortname deg to rad
451
+ * @drawable false
452
+ */
453
+ degToRad(inputs) {
454
+ return inputs.number * Math.PI / 180;
455
+ }
456
+ /**
457
+ * Converts radians to degrees
458
+ * @param inputs a number in radians
459
+ * @returns number
460
+ * @group basics
461
+ * @shortname rad to deg
462
+ * @drawable false
463
+ */
464
+ radToDeg(inputs) {
465
+ return inputs.number * 180 / Math.PI;
466
+ }
467
+ /**
468
+ * Eases a number by providing x parameter 0-1 and a range of output values
469
+ * @param inputs a number, min and max values, and ease type
470
+ * @returns number
471
+ * @group operations
472
+ * @shortname ease
473
+ * @drawable false
474
+ */
475
+ ease(inputs) {
476
+ const x = inputs.x;
477
+ const min = inputs.min;
478
+ const max = inputs.max;
479
+ const y = this[inputs.ease](x);
480
+ const res = this.remap({ number: y, fromLow: 0, fromHigh: 1, toLow: min, toHigh: max });
481
+ return res;
482
+ }
483
+ easeInSine(x) {
484
+ return 1 - Math.cos((x * Math.PI) / 2);
485
+ }
486
+ easeOutSine(x) {
487
+ return Math.sin((x * Math.PI) / 2);
488
+ }
489
+ easeInOutSine(x) {
490
+ return -(Math.cos(Math.PI * x) - 1) / 2;
491
+ }
492
+ easeInQuad(x) {
493
+ return x * x;
494
+ }
495
+ easeOutQuad(x) {
496
+ return 1 - (1 - x) * (1 - x);
497
+ }
498
+ easeInOutQuad(x) {
499
+ return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
500
+ }
501
+ easeInCubic(x) {
502
+ return x * x * x;
503
+ }
504
+ easeOutCubic(x) {
505
+ return 1 - Math.pow(1 - x, 3);
506
+ }
507
+ easeInOutCubic(x) {
508
+ return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
509
+ }
510
+ easeInQuart(x) {
511
+ return x * x * x * x;
512
+ }
513
+ easeOutQuart(x) {
514
+ return 1 - Math.pow(1 - x, 4);
515
+ }
516
+ easeInOutQuart(x) {
517
+ return x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2;
518
+ }
519
+ easeInQuint(x) {
520
+ return x * x * x * x * x;
521
+ }
522
+ easeOutQuint(x) {
523
+ return 1 - Math.pow(1 - x, 5);
524
+ }
525
+ easeInOutQuint(x) {
526
+ return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
527
+ }
528
+ easeInExpo(x) {
529
+ return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
530
+ }
531
+ easeOutExpo(x) {
532
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
533
+ }
534
+ easeInOutExpo(x) {
535
+ return x === 0
536
+ ? 0
537
+ : x === 1
538
+ ? 1
539
+ : x < 0.5
540
+ ? Math.pow(2, 20 * x - 10) / 2
541
+ : (2 - Math.pow(2, -20 * x + 10)) / 2;
542
+ }
543
+ easeInCirc(x) {
544
+ return 1 - Math.sqrt(1 - x * x);
545
+ }
546
+ easeOutCirc(x) {
547
+ return Math.sqrt(1 - Math.pow(x - 1, 2));
548
+ }
549
+ easeInOutCirc(x) {
550
+ return x < 0.5
551
+ ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2
552
+ : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
553
+ }
554
+ easeInBack(x) {
555
+ const c1 = 1.70158;
556
+ const c3 = c1 + 1;
557
+ return c3 * x * x * x - c1 * x * x;
558
+ }
559
+ easeOutBack(x) {
560
+ const c1 = 1.70158;
561
+ const c3 = c1 + 1;
562
+ return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
563
+ }
564
+ easeInOutBack(x) {
565
+ const c1 = 1.70158;
566
+ const c2 = c1 * 1.525;
567
+ return x < 0.5
568
+ ? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
569
+ : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
570
+ }
571
+ easeInElastic(x) {
572
+ const c4 = (2 * Math.PI) / 3;
573
+ return x === 0
574
+ ? 0
575
+ : x === 1
576
+ ? 1
577
+ : -Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4);
578
+ }
579
+ easeOutElastic(x) {
580
+ const c4 = (2 * Math.PI) / 3;
581
+ return x === 0
582
+ ? 0
583
+ : x === 1
584
+ ? 1
585
+ : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1;
586
+ }
587
+ easeInOutElastic(x) {
588
+ const c5 = (2 * Math.PI) / 4.5;
589
+ return x === 0
590
+ ? 0
591
+ : x === 1
592
+ ? 1
593
+ : x < 0.5
594
+ ? -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2
595
+ : (Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5)) / 2 + 1;
596
+ }
597
+ easeInBounce(x) {
598
+ return 1 - this.easeOutBounce(1 - x);
599
+ }
600
+ easeOutBounce(x) {
601
+ const n1 = 7.5625;
602
+ const d1 = 2.75;
603
+ if (x < 1 / d1) {
604
+ return n1 * x * x;
605
+ }
606
+ else if (x < 2 / d1) {
607
+ return n1 * (x -= 1.5 / d1) * x + 0.75;
608
+ }
609
+ else if (x < 2.5 / d1) {
610
+ return n1 * (x -= 2.25 / d1) * x + 0.9375;
611
+ }
612
+ else {
613
+ return n1 * (x -= 2.625 / d1) * x + 0.984375;
614
+ }
615
+ }
616
+ easeInOutBounce(x) {
617
+ return x < 0.5
618
+ ? (1 - this.easeOutBounce(1 - 2 * x)) / 2
619
+ : (1 + this.easeOutBounce(2 * x - 1)) / 2;
620
+ }
621
+ }