@lotics/app-sdk 0.120.2 → 0.121.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.
@@ -185,28 +185,651 @@ function bandOf(tiers, figure) {
185
185
  return { min: tiers[at - 1] ?? null, max: tiers[at] ?? null };
186
186
  }
187
187
 
188
- // ../shared/src/utils.ts
189
- function decimalPlaces(value) {
190
- if (Number.isInteger(value)) return 0;
191
- const [mantissa = "", exponent = "0"] = String(value).split("e");
192
- const fraction = mantissa.split(".")[1]?.length ?? 0;
193
- return Math.max(0, fraction - Number(exponent));
188
+ // ../../node_modules/big.js/big.mjs
189
+ var DP = 20;
190
+ var RM = 1;
191
+ var MAX_DP = 1e6;
192
+ var MAX_POWER = 1e6;
193
+ var NE = -7;
194
+ var PE = 21;
195
+ var STRICT = false;
196
+ var NAME = "[big.js] ";
197
+ var INVALID = NAME + "Invalid ";
198
+ var INVALID_DP = INVALID + "decimal places";
199
+ var INVALID_RM = INVALID + "rounding mode";
200
+ var DIV_BY_ZERO = NAME + "Division by zero";
201
+ var P = {};
202
+ var UNDEFINED = void 0;
203
+ var NUMERIC = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
204
+ function _Big_() {
205
+ function Big2(n) {
206
+ var x = this;
207
+ if (!(x instanceof Big2)) {
208
+ return n === UNDEFINED && arguments.length === 0 ? _Big_() : new Big2(n);
209
+ }
210
+ if (n instanceof Big2) {
211
+ x.s = n.s;
212
+ x.e = n.e;
213
+ x.c = n.c.slice();
214
+ } else {
215
+ if (typeof n !== "string") {
216
+ if (Big2.strict === true && typeof n !== "bigint") {
217
+ throw TypeError(INVALID + "value");
218
+ }
219
+ n = n === 0 && 1 / n < 0 ? "-0" : String(n);
220
+ }
221
+ parse(x, n);
222
+ }
223
+ x.constructor = Big2;
224
+ }
225
+ Big2.prototype = P;
226
+ Big2.DP = DP;
227
+ Big2.RM = RM;
228
+ Big2.NE = NE;
229
+ Big2.PE = PE;
230
+ Big2.strict = STRICT;
231
+ Big2.roundDown = 0;
232
+ Big2.roundHalfUp = 1;
233
+ Big2.roundHalfEven = 2;
234
+ Big2.roundUp = 3;
235
+ return Big2;
236
+ }
237
+ function parse(x, n) {
238
+ var e, i, nl;
239
+ if (!NUMERIC.test(n)) {
240
+ throw Error(INVALID + "number");
241
+ }
242
+ x.s = n.charAt(0) == "-" ? (n = n.slice(1), -1) : 1;
243
+ if ((e = n.indexOf(".")) > -1) n = n.replace(".", "");
244
+ if ((i = n.search(/e/i)) > 0) {
245
+ if (e < 0) e = i;
246
+ e += +n.slice(i + 1);
247
+ n = n.substring(0, i);
248
+ } else if (e < 0) {
249
+ e = n.length;
250
+ }
251
+ nl = n.length;
252
+ for (i = 0; i < nl && n.charAt(i) == "0"; ) ++i;
253
+ if (i == nl) {
254
+ x.c = [x.e = 0];
255
+ } else {
256
+ for (; nl > 0 && n.charAt(--nl) == "0"; ) ;
257
+ x.e = e - i - 1;
258
+ x.c = [];
259
+ for (e = 0; i <= nl; ) x.c[e++] = +n.charAt(i++);
260
+ }
261
+ return x;
262
+ }
263
+ function round(x, sd, rm, more) {
264
+ var xc = x.c;
265
+ if (rm === UNDEFINED) rm = x.constructor.RM;
266
+ if (rm !== 0 && rm !== 1 && rm !== 2 && rm !== 3) {
267
+ throw Error(INVALID_RM);
268
+ }
269
+ if (sd < 1) {
270
+ more = rm === 3 && (more || !!xc[0]) || sd === 0 && (rm === 1 && xc[0] >= 5 || rm === 2 && (xc[0] > 5 || xc[0] === 5 && (more || xc[1] !== UNDEFINED)));
271
+ xc.length = 1;
272
+ if (more) {
273
+ x.e = x.e - sd + 1;
274
+ xc[0] = 1;
275
+ } else {
276
+ xc[0] = x.e = 0;
277
+ }
278
+ } else if (sd < xc.length) {
279
+ more = rm === 1 && xc[sd] >= 5 || rm === 2 && (xc[sd] > 5 || xc[sd] === 5 && (more || xc[sd + 1] !== UNDEFINED || xc[sd - 1] & 1)) || rm === 3 && (more || !!xc[0]);
280
+ xc.length = sd;
281
+ if (more) {
282
+ for (; ++xc[--sd] > 9; ) {
283
+ xc[sd] = 0;
284
+ if (sd === 0) {
285
+ ++x.e;
286
+ xc.unshift(1);
287
+ break;
288
+ }
289
+ }
290
+ }
291
+ for (sd = xc.length; !xc[--sd]; ) xc.pop();
292
+ }
293
+ return x;
294
+ }
295
+ function stringify(x, doExponential, isNonzero) {
296
+ var e = x.e, s = x.c.join(""), n = s.length;
297
+ if (doExponential) {
298
+ s = s.charAt(0) + (n > 1 ? "." + s.slice(1) : "") + (e < 0 ? "e" : "e+") + e;
299
+ } else if (e < 0) {
300
+ for (; ++e; ) s = "0" + s;
301
+ s = "0." + s;
302
+ } else if (e > 0) {
303
+ if (++e > n) {
304
+ for (e -= n; e--; ) s += "0";
305
+ } else if (e < n) {
306
+ s = s.slice(0, e) + "." + s.slice(e);
307
+ }
308
+ } else if (n > 1) {
309
+ s = s.charAt(0) + "." + s.slice(1);
310
+ }
311
+ return x.s < 0 && isNonzero ? "-" + s : s;
312
+ }
313
+ P.abs = function() {
314
+ var x = new this.constructor(this);
315
+ x.s = 1;
316
+ return x;
317
+ };
318
+ P.cmp = function(y) {
319
+ var isneg, x = this, xc = x.c, yc = (y = new x.constructor(y)).c, i = x.s, j = y.s, k = x.e, l = y.e;
320
+ if (!xc[0] || !yc[0]) return !xc[0] ? !yc[0] ? 0 : -j : i;
321
+ if (i != j) return i;
322
+ isneg = i < 0;
323
+ if (k != l) return k > l ^ isneg ? 1 : -1;
324
+ j = (k = xc.length) < (l = yc.length) ? k : l;
325
+ for (i = -1; ++i < j; ) {
326
+ if (xc[i] != yc[i]) return xc[i] > yc[i] ^ isneg ? 1 : -1;
327
+ }
328
+ return k == l ? 0 : k > l ^ isneg ? 1 : -1;
329
+ };
330
+ P.div = function(y) {
331
+ var x = this, Big2 = x.constructor, a = x.c, b = (y = new Big2(y)).c, k = x.s == y.s ? 1 : -1, dp = Big2.DP;
332
+ if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
333
+ throw Error(INVALID_DP);
334
+ }
335
+ if (!b[0]) {
336
+ throw Error(DIV_BY_ZERO);
337
+ }
338
+ if (!a[0]) {
339
+ y.s = k;
340
+ y.c = [y.e = 0];
341
+ return y;
342
+ }
343
+ var bl, bt, n, cmp, ri, bz = b.slice(), ai = bl = b.length, al = a.length, r = a.slice(0, bl), rl = r.length, q = y, qc = q.c = [], qi = 0, p = dp + (q.e = x.e - y.e) + 1;
344
+ q.s = k;
345
+ k = p < 0 ? 0 : p;
346
+ bz.unshift(0);
347
+ for (; rl++ < bl; ) r.push(0);
348
+ do {
349
+ for (n = 0; n < 10; n++) {
350
+ if (bl != (rl = r.length)) {
351
+ cmp = bl > rl ? 1 : -1;
352
+ } else {
353
+ for (ri = -1, cmp = 0; ++ri < bl; ) {
354
+ if (b[ri] != r[ri]) {
355
+ cmp = b[ri] > r[ri] ? 1 : -1;
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ if (cmp < 0) {
361
+ for (bt = rl == bl ? b : bz; rl; ) {
362
+ if (r[--rl] < bt[rl]) {
363
+ ri = rl;
364
+ for (; ri && !r[--ri]; ) r[ri] = 9;
365
+ --r[ri];
366
+ r[rl] += 10;
367
+ }
368
+ r[rl] -= bt[rl];
369
+ }
370
+ for (; !r[0]; ) r.shift();
371
+ } else {
372
+ break;
373
+ }
374
+ }
375
+ qc[qi++] = cmp ? n : ++n;
376
+ if (r[0] && cmp) r[rl] = a[ai] || 0;
377
+ else r = [a[ai]];
378
+ } while ((ai++ < al || r[0] !== UNDEFINED) && k--);
379
+ if (!qc[0] && qi != 1) {
380
+ qc.shift();
381
+ q.e--;
382
+ p--;
383
+ }
384
+ if (qi > p) round(q, p, Big2.RM, r[0] !== UNDEFINED);
385
+ return q;
386
+ };
387
+ P.eq = function(y) {
388
+ return this.cmp(y) === 0;
389
+ };
390
+ P.gt = function(y) {
391
+ return this.cmp(y) > 0;
392
+ };
393
+ P.gte = function(y) {
394
+ return this.cmp(y) > -1;
395
+ };
396
+ P.lt = function(y) {
397
+ return this.cmp(y) < 0;
398
+ };
399
+ P.lte = function(y) {
400
+ return this.cmp(y) < 1;
401
+ };
402
+ P.minus = P.sub = function(y) {
403
+ var i, j, t, xlty, x = this, Big2 = x.constructor, a = x.s, b = (y = new Big2(y)).s;
404
+ if (a != b) {
405
+ y.s = -b;
406
+ return x.plus(y);
407
+ }
408
+ var xc = x.c.slice(), xe = x.e, yc = y.c, ye = y.e;
409
+ if (!xc[0] || !yc[0]) {
410
+ if (yc[0]) {
411
+ y.s = -b;
412
+ } else if (xc[0]) {
413
+ y = new Big2(x);
414
+ } else {
415
+ y.s = 1;
416
+ }
417
+ return y;
418
+ }
419
+ if (a = xe - ye) {
420
+ if (xlty = a < 0) {
421
+ a = -a;
422
+ t = xc;
423
+ } else {
424
+ ye = xe;
425
+ t = yc;
426
+ }
427
+ t.reverse();
428
+ for (b = a; b--; ) t.push(0);
429
+ t.reverse();
430
+ } else {
431
+ j = ((xlty = xc.length < yc.length) ? xc : yc).length;
432
+ for (a = b = 0; b < j; b++) {
433
+ if (xc[b] != yc[b]) {
434
+ xlty = xc[b] < yc[b];
435
+ break;
436
+ }
437
+ }
438
+ }
439
+ if (xlty) {
440
+ t = xc;
441
+ xc = yc;
442
+ yc = t;
443
+ y.s = -y.s;
444
+ }
445
+ if ((b = (j = yc.length) - (i = xc.length)) > 0) for (; b--; ) xc[i++] = 0;
446
+ for (b = i; j > a; ) {
447
+ if (xc[--j] < yc[j]) {
448
+ for (i = j; i && !xc[--i]; ) xc[i] = 9;
449
+ --xc[i];
450
+ xc[j] += 10;
451
+ }
452
+ xc[j] -= yc[j];
453
+ }
454
+ for (; xc[--b] === 0; ) xc.pop();
455
+ for (; xc[0] === 0; ) {
456
+ xc.shift();
457
+ --ye;
458
+ }
459
+ if (!xc[0]) {
460
+ y.s = 1;
461
+ xc = [ye = 0];
462
+ }
463
+ y.c = xc;
464
+ y.e = ye;
465
+ return y;
466
+ };
467
+ P.mod = function(y) {
468
+ var ygtx, x = this, Big2 = x.constructor, a = x.s, b = (y = new Big2(y)).s;
469
+ if (!y.c[0]) {
470
+ throw Error(DIV_BY_ZERO);
471
+ }
472
+ x.s = y.s = 1;
473
+ ygtx = y.cmp(x) == 1;
474
+ x.s = a;
475
+ y.s = b;
476
+ if (ygtx) return new Big2(x);
477
+ a = Big2.DP;
478
+ b = Big2.RM;
479
+ Big2.DP = Big2.RM = 0;
480
+ x = x.div(y);
481
+ Big2.DP = a;
482
+ Big2.RM = b;
483
+ return this.minus(x.times(y));
484
+ };
485
+ P.neg = function() {
486
+ var x = new this.constructor(this);
487
+ x.s = -x.s;
488
+ return x;
489
+ };
490
+ P.plus = P.add = function(y) {
491
+ var e, k, t, x = this, Big2 = x.constructor;
492
+ y = new Big2(y);
493
+ if (x.s != y.s) {
494
+ y.s = -y.s;
495
+ return x.minus(y);
496
+ }
497
+ var xe = x.e, xc = x.c, ye = y.e, yc = y.c;
498
+ if (!xc[0] || !yc[0]) {
499
+ if (!yc[0]) {
500
+ if (xc[0]) {
501
+ y = new Big2(x);
502
+ } else {
503
+ y.s = x.s;
504
+ }
505
+ }
506
+ return y;
507
+ }
508
+ xc = xc.slice();
509
+ if (e = xe - ye) {
510
+ if (e > 0) {
511
+ ye = xe;
512
+ t = yc;
513
+ } else {
514
+ e = -e;
515
+ t = xc;
516
+ }
517
+ t.reverse();
518
+ for (; e--; ) t.push(0);
519
+ t.reverse();
520
+ }
521
+ if (xc.length - yc.length < 0) {
522
+ t = yc;
523
+ yc = xc;
524
+ xc = t;
525
+ }
526
+ e = yc.length;
527
+ for (k = 0; e; xc[e] %= 10) k = (xc[--e] = xc[e] + yc[e] + k) / 10 | 0;
528
+ if (k) {
529
+ xc.unshift(k);
530
+ ++ye;
531
+ }
532
+ for (e = xc.length; xc[--e] === 0; ) xc.pop();
533
+ y.c = xc;
534
+ y.e = ye;
535
+ return y;
536
+ };
537
+ P.pow = function(n) {
538
+ var x = this, one = new x.constructor("1"), y = one, isneg = n < 0;
539
+ if (n !== ~~n || n < -MAX_POWER || n > MAX_POWER) {
540
+ throw Error(INVALID + "exponent");
541
+ }
542
+ if (isneg) n = -n;
543
+ for (; ; ) {
544
+ if (n & 1) y = y.times(x);
545
+ n >>= 1;
546
+ if (!n) break;
547
+ x = x.times(x);
548
+ }
549
+ return isneg ? one.div(y) : y;
550
+ };
551
+ P.prec = function(sd, rm) {
552
+ if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
553
+ throw Error(INVALID + "precision");
554
+ }
555
+ return round(new this.constructor(this), sd, rm);
556
+ };
557
+ P.round = function(dp, rm) {
558
+ if (dp === UNDEFINED) dp = 0;
559
+ else if (dp !== ~~dp || dp < -MAX_DP || dp > MAX_DP) {
560
+ throw Error(INVALID_DP);
561
+ }
562
+ return round(new this.constructor(this), dp + this.e + 1, rm);
563
+ };
564
+ P.sqrt = function() {
565
+ var r, c, t, x = this, Big2 = x.constructor, s = x.s, e = x.e, half = new Big2("0.5");
566
+ if (!x.c[0]) return new Big2(x);
567
+ if (s < 0) {
568
+ throw Error(NAME + "No square root");
569
+ }
570
+ s = Math.sqrt(+stringify(x, true, true));
571
+ if (s === 0 || s === 1 / 0) {
572
+ c = x.c.join("");
573
+ if (!(c.length + e & 1)) c += "0";
574
+ s = Math.sqrt(c);
575
+ e = ((e + 1) / 2 | 0) - (e < 0 || e & 1);
576
+ r = new Big2((s == 1 / 0 ? "5e" : (s = s.toExponential()).slice(0, s.indexOf("e") + 1)) + e);
577
+ } else {
578
+ r = new Big2(s + "");
579
+ }
580
+ e = r.e + (Big2.DP += 4);
581
+ do {
582
+ t = r;
583
+ r = half.times(t.plus(x.div(t)));
584
+ } while (t.c.slice(0, e).join("") !== r.c.slice(0, e).join(""));
585
+ return round(r, (Big2.DP -= 4) + r.e + 1, Big2.RM);
586
+ };
587
+ P.times = P.mul = function(y) {
588
+ var c, x = this, Big2 = x.constructor, xc = x.c, yc = (y = new Big2(y)).c, a = xc.length, b = yc.length, i = x.e, j = y.e;
589
+ y.s = x.s == y.s ? 1 : -1;
590
+ if (!xc[0] || !yc[0]) {
591
+ y.c = [y.e = 0];
592
+ return y;
593
+ }
594
+ y.e = i + j;
595
+ if (a < b) {
596
+ c = xc;
597
+ xc = yc;
598
+ yc = c;
599
+ j = a;
600
+ a = b;
601
+ b = j;
602
+ }
603
+ for (c = new Array(j = a + b); j--; ) c[j] = 0;
604
+ for (i = b; i--; ) {
605
+ b = 0;
606
+ for (j = a + i; j > i; ) {
607
+ b = c[j] + yc[i] * xc[j - i - 1] + b;
608
+ c[j--] = b % 10;
609
+ b = b / 10 | 0;
610
+ }
611
+ c[j] = b;
612
+ }
613
+ if (b) ++y.e;
614
+ else c.shift();
615
+ for (i = c.length; !c[--i]; ) c.pop();
616
+ y.c = c;
617
+ return y;
618
+ };
619
+ P.toExponential = function(dp, rm) {
620
+ var x = this, n = x.c[0];
621
+ if (dp !== UNDEFINED) {
622
+ if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
623
+ throw Error(INVALID_DP);
624
+ }
625
+ x = round(new x.constructor(x), ++dp, rm);
626
+ for (; x.c.length < dp; ) x.c.push(0);
627
+ }
628
+ return stringify(x, true, !!n);
629
+ };
630
+ P.toFixed = function(dp, rm) {
631
+ var x = this, n = x.c[0];
632
+ if (dp !== UNDEFINED) {
633
+ if (dp !== ~~dp || dp < 0 || dp > MAX_DP) {
634
+ throw Error(INVALID_DP);
635
+ }
636
+ x = round(new x.constructor(x), dp + x.e + 1, rm);
637
+ for (dp = dp + x.e + 1; x.c.length < dp; ) x.c.push(0);
638
+ }
639
+ return stringify(x, false, !!n);
640
+ };
641
+ P.toJSON = P.toString = function() {
642
+ var x = this, Big2 = x.constructor;
643
+ return stringify(x, x.e <= Big2.NE || x.e >= Big2.PE, !!x.c[0]);
644
+ };
645
+ if (typeof Symbol !== "undefined") {
646
+ P[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")] = P.toJSON;
647
+ }
648
+ P.toNumber = function() {
649
+ var n = +stringify(this, true, true);
650
+ if (this.constructor.strict === true && !this.eq(n.toString())) {
651
+ throw Error(NAME + "Imprecise conversion");
652
+ }
653
+ return n;
654
+ };
655
+ P.toPrecision = function(sd, rm) {
656
+ var x = this, Big2 = x.constructor, n = x.c[0];
657
+ if (sd !== UNDEFINED) {
658
+ if (sd !== ~~sd || sd < 1 || sd > MAX_DP) {
659
+ throw Error(INVALID + "precision");
660
+ }
661
+ x = round(new Big2(x), sd, rm);
662
+ for (; x.c.length < sd; ) x.c.push(0);
663
+ }
664
+ return stringify(x, sd <= x.e || x.e <= Big2.NE || x.e >= Big2.PE, !!n);
665
+ };
666
+ P.valueOf = function() {
667
+ var x = this, Big2 = x.constructor;
668
+ if (Big2.strict === true) {
669
+ throw Error(NAME + "valueOf disallowed");
670
+ }
671
+ return stringify(x, x.e <= Big2.NE || x.e >= Big2.PE, true);
672
+ };
673
+ var Big = _Big_();
674
+ var big_default = Big;
675
+
676
+ // ../shared/src/decimal.ts
677
+ var DIVISION_DIGITS = 24;
678
+ var ROUNDING_PLACES = 1e6;
679
+ var POWER_DIGITS = 300;
680
+ var SIGNIFICANT_DIGITS = 15;
681
+ var SHORT_DIGITS = 12;
682
+ var WHOLE_DIGITS_LIMIT = 10 ** SIGNIFICANT_DIGITS;
683
+ var DIVISION_SCALES = [10, 100, 1e3, 1e4, 1e5, 1e6];
684
+ var Decimal = big_default();
685
+ Decimal.DP = DIVISION_DIGITS;
686
+ Decimal.RM = big_default.roundDown;
687
+ var QUOTIENT_STEP = new Decimal(`1e-${DIVISION_DIGITS}`);
688
+ function takesFloat(left, right) {
689
+ return !Number.isFinite(left) || !Number.isFinite(right) || left === 0 || right === 0;
690
+ }
691
+ function isExactInteger(left, right, result) {
692
+ return Number.isSafeInteger(left) && Number.isSafeInteger(right) && Number.isSafeInteger(result);
693
+ }
694
+ function isInexact(value, decimal) {
695
+ return decimal.c.length > SHORT_DIGITS && !Number.isSafeInteger(value);
696
+ }
697
+ function settled(result, inexact) {
698
+ if (!inexact) return result;
699
+ const reading = result.prec(SIGNIFICANT_DIGITS, big_default.roundHalfUp);
700
+ return reading.c.length <= SHORT_DIGITS ? reading : result;
701
+ }
702
+ function addDecimal(left, right) {
703
+ const float = left + right;
704
+ if (takesFloat(left, right) || isExactInteger(left, right, float)) return float;
705
+ const augend = new Decimal(left);
706
+ const addend = new Decimal(right);
707
+ return settled(augend.plus(addend), isInexact(left, augend) || isInexact(right, addend)).toNumber();
708
+ }
709
+ function subtractDecimal(left, right) {
710
+ const float = left - right;
711
+ if (takesFloat(left, right) || isExactInteger(left, right, float)) return float;
712
+ const minuend = new Decimal(left);
713
+ const subtrahend = new Decimal(right);
714
+ return settled(minuend.minus(subtrahend), isInexact(left, minuend) || isInexact(right, subtrahend)).toNumber();
715
+ }
716
+ function multiplyDecimal(left, right) {
717
+ return product(left, right, true);
718
+ }
719
+ function multiplyExactly(left, right) {
720
+ return product(left, right, false);
721
+ }
722
+ function product(left, right, settles) {
723
+ const float = left * right;
724
+ if (takesFloat(left, right) || isExactInteger(left, right, float)) return float;
725
+ const multiplicand = new Decimal(left);
726
+ const multiplier = new Decimal(right);
727
+ return settled(multiplicand.times(multiplier), settles && (isInexact(left, multiplicand) || isInexact(right, multiplier))).toNumber();
728
+ }
729
+ function divideDecimal(left, right) {
730
+ if (takesFloat(left, right) || Number.isSafeInteger(left) && Number.isSafeInteger(right)) return left / right;
731
+ const scaled = scaledQuotient(left, right);
732
+ if (scaled !== void 0) return scaled;
733
+ const dividend = new Decimal(left);
734
+ const divisor = new Decimal(right);
735
+ return quotient(dividend, divisor, isInexact(left, dividend) || isInexact(right, divisor));
736
+ }
737
+ function scaledQuotient(left, right) {
738
+ for (const scale2 of DIVISION_SCALES) {
739
+ const dividend = Math.round(left * scale2);
740
+ if (Math.abs(dividend) >= WHOLE_DIGITS_LIMIT || dividend / scale2 !== left) continue;
741
+ const divisor = Math.round(right * scale2);
742
+ if (Math.abs(divisor) < WHOLE_DIGITS_LIMIT && divisor / scale2 === right) return dividend / divisor;
743
+ }
744
+ return void 0;
745
+ }
746
+ function moduloDecimal(left, right) {
747
+ if (takesFloat(left, right)) return left % right;
748
+ const remainder = new Decimal(left).mod(right);
749
+ if (remainder.eq(0)) return left < 0 ? -0 : 0;
750
+ return remainder.toNumber();
751
+ }
752
+ function readAtSignificantDigits(value) {
753
+ if (Number.isInteger(value) || !Number.isFinite(value)) return value;
754
+ if (Math.abs(value) >= WHOLE_DIGITS_LIMIT) return Math.sign(value) * Math.round(Math.abs(value));
755
+ return Number(value.toPrecision(SIGNIFICANT_DIGITS));
756
+ }
757
+ function compareDecimal(left, right) {
758
+ if (left === right) return 0;
759
+ if (Number.isNaN(left) || Number.isNaN(right)) return NaN;
760
+ const leftRead = readAtSignificantDigits(left);
761
+ const rightRead = readAtSignificantDigits(right);
762
+ if (leftRead === rightRead) return 0;
763
+ return leftRead < rightRead ? -1 : 1;
194
764
  }
195
765
  function sumDecimal(values, divisor = 1) {
196
- const float = values.reduce((total2, value) => total2 + value, 0) / divisor;
197
- if (!values.every(Number.isFinite)) return float;
198
- const factor = 10 ** values.reduce((places, value) => Math.max(places, decimalPlaces(value)), 0);
199
- const scaled = values.map((value) => Math.round(value * factor));
200
- const total = scaled.reduce((sum, value) => sum + value, 0);
201
- const exact = Number.isSafeInteger(total) && scaled.every((one, index) => Number.isSafeInteger(one) && one / factor === values[index]);
202
- return exact ? total / (factor * divisor) : float;
766
+ if (!values.every(Number.isFinite) || !Number.isFinite(divisor) || divisor === 0) {
767
+ return values.reduce((total2, value) => total2 + value, 0) / divisor;
768
+ }
769
+ const { total, inexact } = isWithinSafeIntegers(values) ? { total: new Decimal(values.reduce((sum, value) => sum + value, 0)), inexact: false } : totalOf(values);
770
+ if (total.eq(0)) return 0;
771
+ if (divisor === 1) return total.toNumber();
772
+ const by = new Decimal(divisor);
773
+ return quotient(total, by, inexact || isInexact(divisor, by));
774
+ }
775
+ function totalOf(values) {
776
+ let total = new Decimal(0);
777
+ let inexact = false;
778
+ for (const value of values) {
779
+ const term = new Decimal(value);
780
+ inexact ||= isInexact(value, term);
781
+ total = total.plus(term);
782
+ }
783
+ return { total: settled(total, inexact), inexact };
784
+ }
785
+ function isWithinSafeIntegers(values) {
786
+ return values.every(Number.isSafeInteger) && values.reduce((magnitude, value) => magnitude + Math.abs(value), 0) <= Number.MAX_SAFE_INTEGER;
203
787
  }
204
- function sample(arr) {
205
- if (arr.length === 0) return void 0;
206
- return arr[Math.floor(Math.random() * arr.length)];
788
+ function roundDecimal(value, places) {
789
+ if (!Number.isFinite(value) || value === 0 || !Number.isInteger(places) || Math.abs(places) > ROUNDING_PLACES) {
790
+ const multiplier = Math.pow(10, places);
791
+ return Math.sign(value) * Math.round(Math.abs(value) * multiplier) / multiplier;
792
+ }
793
+ const rounded = new Decimal(value).round(places, big_default.roundHalfUp);
794
+ if (rounded.eq(0)) return value < 0 ? -0 : 0;
795
+ return rounded.toNumber();
796
+ }
797
+ function percentOf(part, total) {
798
+ return roundDecimal(divideDecimal(multiplyDecimal(part, 100), total), 0);
799
+ }
800
+ function fixedDecimal(value, places) {
801
+ if (!Number.isFinite(value) || Math.abs(value) >= 1e21) return value.toFixed(places);
802
+ return new Decimal(value).toFixed(places, big_default.roundHalfUp);
803
+ }
804
+ function powerDecimal(base, exponent) {
805
+ const float = Math.pow(base, exponent);
806
+ if (takesFloat(base, exponent) || !Number.isInteger(exponent)) return float;
807
+ const decimal = new Decimal(base);
808
+ if (decimal.c.length * Math.abs(exponent) > POWER_DIGITS) return float;
809
+ const inexact = isInexact(base, decimal);
810
+ const power = settled(decimal.pow(Math.abs(exponent)), inexact);
811
+ return exponent > 0 ? power.toNumber() : quotient(new Decimal(1), power, inexact);
812
+ }
813
+ function quotient(dividend, divisor, inexact) {
814
+ const sign = dividend.s === divisor.s ? 1 : -1;
815
+ const numerator = coefficientOf(dividend);
816
+ const denominator = coefficientOf(divisor);
817
+ for (let carried = 0; ; carried = carried * 2 + DIVISION_DIGITS) {
818
+ const scaled = new Decimal(`${numerator.digits}e${carried}`);
819
+ const low = scaled.div(denominator.digits);
820
+ const exponent = numerator.exponent - denominator.exponent - carried;
821
+ if (inexact) {
822
+ const short = settled(low, true);
823
+ if (short !== low) return sign * Number(`${short.toFixed()}e${exponent}`);
824
+ }
825
+ const lowNumber = Number(`${low.toFixed()}e${exponent}`);
826
+ const highNumber = Number(`${low.plus(QUOTIENT_STEP).toFixed()}e${exponent}`);
827
+ if (lowNumber === highNumber || low.times(denominator.digits).eq(scaled)) return sign * lowNumber;
828
+ }
207
829
  }
208
- function assertNever(value) {
209
- throw new Error(`Unhandled union member: ${JSON.stringify(value)}`);
830
+ function coefficientOf(decimal) {
831
+ const [digits = "", exponent = "0"] = decimal.abs().toExponential().split("e");
832
+ return { digits, exponent: Number(exponent) };
210
833
  }
211
834
 
212
835
  // ../shared/src/schemas/read_row.ts
@@ -1033,6 +1656,7 @@ function rpcStandalone(op, payload) {
1033
1656
  case "comments.counts":
1034
1657
  return rejectCommentsStandalone();
1035
1658
  case "activity.list":
1659
+ case "activity.undo":
1036
1660
  return Promise.reject(new Error("A record's activity is available only in embedded apps \u2014 a signed-in member is required."));
1037
1661
  case "recording.start":
1038
1662
  case "recording.stop":
@@ -1242,9 +1866,18 @@ export {
1242
1866
  tiersAscend,
1243
1867
  bandKey,
1244
1868
  bandOf,
1869
+ addDecimal,
1870
+ subtractDecimal,
1871
+ multiplyDecimal,
1872
+ multiplyExactly,
1873
+ divideDecimal,
1874
+ moduloDecimal,
1875
+ compareDecimal,
1245
1876
  sumDecimal,
1246
- sample,
1247
- assertNever,
1877
+ roundDecimal,
1878
+ percentOf,
1879
+ fixedDecimal,
1880
+ powerDecimal,
1248
1881
  AGGREGATE_COUNT_COLUMN,
1249
1882
  AGGREGATE_SUM_COLUMN,
1250
1883
  aggregateRows,
package/dist/index.d.ts CHANGED
@@ -11,9 +11,9 @@ export type { ExportedFile } from "./shared_types.js";
11
11
  export type { AttachedFile, AttachmentPiles, AttachmentPilesOptions, AttachmentsOptions, AttachmentsState } from "./attachments.js";
12
12
  export { useComments, useCommentCounts } from "./comments.js";
13
13
  export type { AppComment, AppCommentAuthor, AppCommentFile, CommentsState, UseCommentsArgs, CommentCountsState, UseCommentCountsArgs, } from "./comments.js";
14
- export { useRecordActivity } from "./activity.js";
14
+ export { undoRecordChange, useRecordActivity } from "./activity.js";
15
15
  export type { RecordActivityOptions, RecordActivityState } from "./activity.js";
16
- export type { ActivityActor, ActivityActorKind, ActivityChange, ActivityComment, ActivityEntry, ActivityValue, RecordActivityPage, } from "./shared_types.js";
16
+ export type { ActivityActor, ActivityActorKind, ActivityChange, ActivityComment, ActivityEntry, ActivityUndoResult, ActivityValue, RecordActivityPage, UndoKeptReason, } from "./shared_types.js";
17
17
  export { useAppContext, useViewer, useWorkspaceCurrency, useWorkspaceTimezone } from "./viewer.js";
18
18
  export type { AppAbsence } from "./shared_types.js";
19
19
  export { useRecording, useRecordings } from "./recording.js";