oakscriptjs 0.8.1 → 0.8.2

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.
package/dist/index.cjs CHANGED
@@ -234,26 +234,86 @@ function ge(a, b2) {
234
234
  return valid(a, b2) && b2 - a <= EPSILON;
235
235
  }
236
236
 
237
- // src/ta/index.ts
238
- function sma(source, length2) {
239
- const result = [];
237
+ // src/ta/running-sum.ts
238
+ var view = new DataView(new ArrayBuffer(8));
239
+ function exponentOf(x) {
240
+ view.setFloat64(0, x);
241
+ const e2 = view.getUint16(0) >> 4 & 2047;
242
+ return e2 === 0 ? -1074 : e2 - 1023;
243
+ }
244
+ function compensationLost(x, c) {
245
+ if (c === 0 || x === 0) return false;
246
+ const ulp = 2 ** (exponentOf(x) - 52);
247
+ const q = c / ulp;
248
+ const mantissa = x / ulp;
249
+ const f = Math.floor(q);
250
+ const d = q - f;
251
+ const applied = d > 0.5 ? f + 1 : d < 0.5 ? f : (mantissa - f) % 2 === 0 ? f : f + 1;
252
+ return Math.abs(applied) < Math.abs(q);
253
+ }
254
+ function isNa(v) {
255
+ return v === void 0 || v === null || !Number.isFinite(v);
256
+ }
257
+ function runningSum(source, length2) {
240
258
  const len = Math.floor(length2);
241
- const window = [];
259
+ const out = new Array(source.length).fill(NaN);
260
+ if (!(len >= 1)) return out;
261
+ const values2 = [];
262
+ const stored = [];
263
+ let s = 0;
264
+ let c = 0;
265
+ let previous = NaN;
266
+ const kahanAdd = (v) => {
267
+ const y = v - c;
268
+ const t2 = s + y;
269
+ c = t2 - s - y;
270
+ s = t2;
271
+ return y;
272
+ };
242
273
  for (let i = 0; i < source.length; i++) {
243
274
  const v = source[i];
244
- if (v !== void 0 && v !== null && Number.isFinite(v)) {
245
- window.push(v);
246
- if (window.length > len) window.shift();
275
+ if (isNa(v)) {
276
+ out[i] = previous;
277
+ continue;
247
278
  }
248
- if (window.length < len) {
249
- result.push(NaN);
279
+ const x = v;
280
+ const c0 = c;
281
+ const n = values2.length;
282
+ if (n >= len) kahanAdd(-stored[n - len]);
283
+ values2.push(x);
284
+ if (compensationLost(x, c0)) {
285
+ let fresh = 0;
286
+ for (let k = values2.length - 1; k >= Math.max(0, values2.length - len); k--) fresh += values2[k];
287
+ s = fresh;
288
+ c = 0;
289
+ stored.push(x);
250
290
  } else {
251
- let sum4 = 0;
252
- for (const x of window) sum4 += x;
253
- result.push(sum4 / len);
291
+ stored.push(kahanAdd(x));
254
292
  }
293
+ previous = values2.length >= len ? s : NaN;
294
+ out[i] = previous;
255
295
  }
256
- return result;
296
+ return out;
297
+ }
298
+ function runningVariance(source, length2, biased) {
299
+ const len = Math.floor(length2);
300
+ const squares = Array.from({ length: source.length }, (_, i) => {
301
+ const v = source[i];
302
+ return isNa(v) ? NaN : v * v;
303
+ });
304
+ const sums = runningSum(source, len);
305
+ const sumSquares = runningSum(squares, len);
306
+ return sums.map((sum4, i) => {
307
+ const mean = sum4 / len;
308
+ const sq = sumSquares[i];
309
+ return biased ? sq / len - mean * mean : sq / (len - 1) - mean * sum4 / (len - 1);
310
+ });
311
+ }
312
+
313
+ // src/ta/index.ts
314
+ function sma(source, length2) {
315
+ const len = Math.floor(length2);
316
+ return runningSum(source, len).map((sum4) => sum4 / len);
257
317
  }
258
318
  function strictWindowMean(source, length2) {
259
319
  const len = Math.floor(length2);
@@ -273,7 +333,7 @@ function ema(source, length2) {
273
333
  let initSum = 0;
274
334
  for (let i = 0; i < source.length; i++) {
275
335
  const val = source[i];
276
- if (val !== void 0 && !isNaN(val)) {
336
+ if (val !== void 0 && Number.isFinite(val)) {
277
337
  initSum += val;
278
338
  validCount++;
279
339
  if (validCount === len) {
@@ -291,7 +351,7 @@ function ema(source, length2) {
291
351
  result.push(emaValue);
292
352
  } else {
293
353
  const val = source[i];
294
- if (val !== void 0 && !isNaN(val)) {
354
+ if (val !== void 0 && Number.isFinite(val)) {
295
355
  emaValue = (val - emaValue) * multiplier + emaValue;
296
356
  result.push(emaValue);
297
357
  } else {
@@ -348,14 +408,7 @@ function bb(series, length2, mult2) {
348
408
  return [basis, upper2, lower2];
349
409
  }
350
410
  function stdev(source, length2, biased = true) {
351
- const len = Math.floor(length2);
352
- return source.map((_, i) => {
353
- const values2 = lastValues(source, i, len);
354
- if (!values2) return NaN;
355
- const mean = values2.reduce((a, b2) => a + b2, 0) / len;
356
- const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
357
- return Math.sqrt(squares / (biased ? len : len - 1));
358
- });
411
+ return variance(source, length2, biased).map((v) => Number.isNaN(v) ? NaN : v > 0 ? Math.sqrt(v) : 0);
359
412
  }
360
413
  function lastValues(source, i, length2) {
361
414
  const values2 = [];
@@ -509,13 +562,12 @@ function supertrend(factor, atrPeriod, high, low, close, wicks = false) {
509
562
  function rma(source, length2) {
510
563
  const result = [];
511
564
  const len = Math.floor(length2);
512
- const alpha = 1 / len;
513
565
  let firstValidIndex = -1;
514
566
  let validCount = 0;
515
567
  let initSum = 0;
516
568
  for (let i = 0; i < source.length; i++) {
517
569
  const val = source[i];
518
- if (val !== void 0 && !isNaN(val)) {
570
+ if (val !== void 0 && Number.isFinite(val)) {
519
571
  initSum += val;
520
572
  validCount++;
521
573
  if (validCount === len) {
@@ -533,8 +585,8 @@ function rma(source, length2) {
533
585
  result.push(rmaValue);
534
586
  } else {
535
587
  const val = source[i];
536
- if (val !== void 0 && !isNaN(val)) {
537
- rmaValue = alpha * val + (1 - alpha) * rmaValue;
588
+ if (val !== void 0 && Number.isFinite(val)) {
589
+ rmaValue = (val + (len - 1) * rmaValue) / len;
538
590
  result.push(rmaValue);
539
591
  } else {
540
592
  result.push(NaN);
@@ -548,18 +600,22 @@ function wma(source, length2) {
548
600
  const len = Math.floor(length2);
549
601
  const filled = [];
550
602
  let last2 = NaN;
603
+ let count = 0;
551
604
  for (let i = 0; i < source.length; i++) {
552
605
  const v = source[i];
553
- const isNa = v === void 0 || v === null || Number.isNaN(v);
554
- if (!isNa) last2 = v;
606
+ const isNa2 = v === void 0 || v === null || !Number.isFinite(v);
607
+ if (!isNa2) {
608
+ last2 = v;
609
+ count++;
610
+ }
555
611
  filled.push(last2);
556
- if (isNa || i < len - 1) {
612
+ if (isNa2 || count < len) {
557
613
  result.push(NaN);
558
614
  continue;
559
615
  }
560
616
  let sum4 = 0;
561
617
  let weightSum = 0;
562
- for (let j = 0; j < len; j++) {
618
+ for (let j = len - 1; j >= 0; j--) {
563
619
  const weight = len - j;
564
620
  sum4 += filled[i - j] * weight;
565
621
  weightSum += weight;
@@ -673,53 +729,19 @@ function dev(source, length2) {
673
729
  return result;
674
730
  }
675
731
  function variance(source, length2, biased = true) {
676
- const result = [];
677
732
  const len = Math.floor(length2);
678
- const window = [];
679
- for (let i = 0; i < source.length; i++) {
680
- const v = source[i];
681
- if (v !== void 0 && v !== null && !Number.isNaN(v)) {
682
- window.push(v);
683
- if (window.length > len) window.shift();
684
- }
685
- const divisor = biased ? len : len - 1;
686
- if (window.length < len || divisor <= 0) {
687
- result.push(NaN);
688
- continue;
689
- }
690
- const mean = window.reduce((a, x) => a + x, 0) / len;
691
- let sumSquares = 0;
692
- for (const x of window) sumSquares += (x - mean) * (x - mean);
693
- result.push(sumSquares / divisor);
694
- }
695
- return result;
733
+ if ((biased ? len : len - 1) <= 0) return source.map(() => NaN);
734
+ return runningVariance(source, len, biased);
696
735
  }
697
736
  function median(source, length2) {
698
- const result = [];
699
- for (let i = 0; i < source.length; i++) {
700
- if (i < length2 - 1) {
701
- result.push(NaN);
702
- } else {
703
- const values2 = [];
704
- for (let j = 0; j < length2; j++) {
705
- if (!isNaN(source[i - j])) {
706
- values2.push(source[i - j]);
707
- }
708
- }
709
- if (values2.length === 0) {
710
- result.push(NaN);
711
- } else {
712
- values2.sort((a, b2) => a - b2);
713
- const mid = Math.floor(values2.length / 2);
714
- if (values2.length % 2 === 0) {
715
- result.push((values2[mid - 1] + values2[mid]) / 2);
716
- } else {
717
- result.push(values2[mid]);
718
- }
719
- }
720
- }
721
- }
722
- return result;
737
+ const len = Math.floor(length2);
738
+ return source.map((_, i) => {
739
+ const values2 = lastValues(source, i, len);
740
+ if (!values2) return NaN;
741
+ values2.sort((a, b2) => a - b2);
742
+ const mid = Math.floor(len / 2);
743
+ return len % 2 === 0 ? (values2[mid - 1] + values2[mid]) / 2 : values2[mid];
744
+ });
723
745
  }
724
746
  function swma(source) {
725
747
  const result = [];
@@ -904,12 +926,8 @@ function mfi(source, length2, volume) {
904
926
  upperFlow.push(le(change3, 0) ? 0 : flow);
905
927
  lowerFlow.push(ge(change3, 0) ? 0 : flow);
906
928
  }
907
- const sumAt = (flow, i) => {
908
- const values2 = lastValues(flow, i, Math.floor(length2));
909
- return values2 ? values2.reduce((a, b2) => a + b2, 0) : NaN;
910
- };
911
- const upper2 = upperFlow.map((_, i) => sumAt(upperFlow, i));
912
- const lower2 = lowerFlow.map((_, i) => sumAt(lowerFlow, i));
929
+ const upper2 = runningSum(upperFlow, length2);
930
+ const lower2 = runningSum(lowerFlow, length2);
913
931
  return upper2.map((u, i) => {
914
932
  const l = lower2[i];
915
933
  if (Number.isNaN(u) || Number.isNaN(l)) return NaN;
@@ -2550,23 +2568,7 @@ function avg(...values2) {
2550
2568
  }
2551
2569
  function sum(source, length2) {
2552
2570
  const sourceArray = source instanceof Series ? source.toArray() : source;
2553
- const result = [];
2554
- const len = Math.floor(length2);
2555
- const window = [];
2556
- for (let i = 0; i < sourceArray.length; i++) {
2557
- const v = sourceArray[i];
2558
- if (v !== void 0 && v !== null && !Number.isNaN(v)) {
2559
- window.push(v);
2560
- if (window.length > len) window.shift();
2561
- }
2562
- if (window.length < len) {
2563
- result.push(NaN);
2564
- } else {
2565
- let total = 0;
2566
- for (const x of window) total += x;
2567
- result.push(total);
2568
- }
2569
- }
2571
+ const result = runningSum(sourceArray, length2);
2570
2572
  if (source instanceof Series) {
2571
2573
  return Series.fromArray(source.bars, result);
2572
2574
  }
@@ -3351,9 +3353,9 @@ function shortestDigits(x) {
3351
3353
  function exactDigits(x) {
3352
3354
  const abs3 = Math.abs(x);
3353
3355
  if (abs3 === 0) return { digits: "", intLen: 0 };
3354
- const view = new DataView(new ArrayBuffer(8));
3355
- view.setFloat64(0, abs3);
3356
- const bits = view.getBigUint64(0);
3356
+ const view2 = new DataView(new ArrayBuffer(8));
3357
+ view2.setFloat64(0, abs3);
3358
+ const bits = view2.getBigUint64(0);
3357
3359
  const expBits = Number(bits >> 52n & 0x7ffn);
3358
3360
  let mant = bits & 0xfffffffffffffn;
3359
3361
  const e2 = expBits === 0 ? -1074 : expBits - 1075;
@@ -7955,7 +7957,7 @@ var SimpleInputAdapter = class {
7955
7957
  };
7956
7958
 
7957
7959
  // src/index.ts
7958
- var VERSION = "0.8.1";
7960
+ var VERSION = "0.8.2";
7959
7961
  var info2 = {
7960
7962
  name: "OakScriptJS",
7961
7963
  version: VERSION,
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export { STRATEGY_CONSTANTS, STRATEGY_DEFAULTS, STRATEGY_NUMBER_VARIABLES, STRAT
40
40
  export type * from './strategy';
41
41
  export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter';
42
42
  export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter';
43
- export declare const VERSION = "0.8.1";
43
+ export declare const VERSION = "0.8.2";
44
44
  export declare const info: {
45
45
  name: string;
46
46
  version: string;
package/dist/index.mjs CHANGED
@@ -118,26 +118,86 @@ function ge(a, b2) {
118
118
  return valid(a, b2) && b2 - a <= EPSILON;
119
119
  }
120
120
 
121
- // src/ta/index.ts
122
- function sma(source, length2) {
123
- const result = [];
121
+ // src/ta/running-sum.ts
122
+ var view = new DataView(new ArrayBuffer(8));
123
+ function exponentOf(x) {
124
+ view.setFloat64(0, x);
125
+ const e2 = view.getUint16(0) >> 4 & 2047;
126
+ return e2 === 0 ? -1074 : e2 - 1023;
127
+ }
128
+ function compensationLost(x, c) {
129
+ if (c === 0 || x === 0) return false;
130
+ const ulp = 2 ** (exponentOf(x) - 52);
131
+ const q = c / ulp;
132
+ const mantissa = x / ulp;
133
+ const f = Math.floor(q);
134
+ const d = q - f;
135
+ const applied = d > 0.5 ? f + 1 : d < 0.5 ? f : (mantissa - f) % 2 === 0 ? f : f + 1;
136
+ return Math.abs(applied) < Math.abs(q);
137
+ }
138
+ function isNa(v) {
139
+ return v === void 0 || v === null || !Number.isFinite(v);
140
+ }
141
+ function runningSum(source, length2) {
124
142
  const len = Math.floor(length2);
125
- const window = [];
143
+ const out = new Array(source.length).fill(NaN);
144
+ if (!(len >= 1)) return out;
145
+ const values2 = [];
146
+ const stored = [];
147
+ let s = 0;
148
+ let c = 0;
149
+ let previous = NaN;
150
+ const kahanAdd = (v) => {
151
+ const y = v - c;
152
+ const t2 = s + y;
153
+ c = t2 - s - y;
154
+ s = t2;
155
+ return y;
156
+ };
126
157
  for (let i = 0; i < source.length; i++) {
127
158
  const v = source[i];
128
- if (v !== void 0 && v !== null && Number.isFinite(v)) {
129
- window.push(v);
130
- if (window.length > len) window.shift();
159
+ if (isNa(v)) {
160
+ out[i] = previous;
161
+ continue;
131
162
  }
132
- if (window.length < len) {
133
- result.push(NaN);
163
+ const x = v;
164
+ const c0 = c;
165
+ const n = values2.length;
166
+ if (n >= len) kahanAdd(-stored[n - len]);
167
+ values2.push(x);
168
+ if (compensationLost(x, c0)) {
169
+ let fresh = 0;
170
+ for (let k = values2.length - 1; k >= Math.max(0, values2.length - len); k--) fresh += values2[k];
171
+ s = fresh;
172
+ c = 0;
173
+ stored.push(x);
134
174
  } else {
135
- let sum4 = 0;
136
- for (const x of window) sum4 += x;
137
- result.push(sum4 / len);
175
+ stored.push(kahanAdd(x));
138
176
  }
177
+ previous = values2.length >= len ? s : NaN;
178
+ out[i] = previous;
139
179
  }
140
- return result;
180
+ return out;
181
+ }
182
+ function runningVariance(source, length2, biased) {
183
+ const len = Math.floor(length2);
184
+ const squares = Array.from({ length: source.length }, (_, i) => {
185
+ const v = source[i];
186
+ return isNa(v) ? NaN : v * v;
187
+ });
188
+ const sums = runningSum(source, len);
189
+ const sumSquares = runningSum(squares, len);
190
+ return sums.map((sum4, i) => {
191
+ const mean = sum4 / len;
192
+ const sq = sumSquares[i];
193
+ return biased ? sq / len - mean * mean : sq / (len - 1) - mean * sum4 / (len - 1);
194
+ });
195
+ }
196
+
197
+ // src/ta/index.ts
198
+ function sma(source, length2) {
199
+ const len = Math.floor(length2);
200
+ return runningSum(source, len).map((sum4) => sum4 / len);
141
201
  }
142
202
  function strictWindowMean(source, length2) {
143
203
  const len = Math.floor(length2);
@@ -157,7 +217,7 @@ function ema(source, length2) {
157
217
  let initSum = 0;
158
218
  for (let i = 0; i < source.length; i++) {
159
219
  const val = source[i];
160
- if (val !== void 0 && !isNaN(val)) {
220
+ if (val !== void 0 && Number.isFinite(val)) {
161
221
  initSum += val;
162
222
  validCount++;
163
223
  if (validCount === len) {
@@ -175,7 +235,7 @@ function ema(source, length2) {
175
235
  result.push(emaValue);
176
236
  } else {
177
237
  const val = source[i];
178
- if (val !== void 0 && !isNaN(val)) {
238
+ if (val !== void 0 && Number.isFinite(val)) {
179
239
  emaValue = (val - emaValue) * multiplier + emaValue;
180
240
  result.push(emaValue);
181
241
  } else {
@@ -232,14 +292,7 @@ function bb(series, length2, mult2) {
232
292
  return [basis, upper2, lower2];
233
293
  }
234
294
  function stdev(source, length2, biased = true) {
235
- const len = Math.floor(length2);
236
- return source.map((_, i) => {
237
- const values2 = lastValues(source, i, len);
238
- if (!values2) return NaN;
239
- const mean = values2.reduce((a, b2) => a + b2, 0) / len;
240
- const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
241
- return Math.sqrt(squares / (biased ? len : len - 1));
242
- });
295
+ return variance(source, length2, biased).map((v) => Number.isNaN(v) ? NaN : v > 0 ? Math.sqrt(v) : 0);
243
296
  }
244
297
  function lastValues(source, i, length2) {
245
298
  const values2 = [];
@@ -393,13 +446,12 @@ function supertrend(factor, atrPeriod, high, low, close, wicks = false) {
393
446
  function rma(source, length2) {
394
447
  const result = [];
395
448
  const len = Math.floor(length2);
396
- const alpha = 1 / len;
397
449
  let firstValidIndex = -1;
398
450
  let validCount = 0;
399
451
  let initSum = 0;
400
452
  for (let i = 0; i < source.length; i++) {
401
453
  const val = source[i];
402
- if (val !== void 0 && !isNaN(val)) {
454
+ if (val !== void 0 && Number.isFinite(val)) {
403
455
  initSum += val;
404
456
  validCount++;
405
457
  if (validCount === len) {
@@ -417,8 +469,8 @@ function rma(source, length2) {
417
469
  result.push(rmaValue);
418
470
  } else {
419
471
  const val = source[i];
420
- if (val !== void 0 && !isNaN(val)) {
421
- rmaValue = alpha * val + (1 - alpha) * rmaValue;
472
+ if (val !== void 0 && Number.isFinite(val)) {
473
+ rmaValue = (val + (len - 1) * rmaValue) / len;
422
474
  result.push(rmaValue);
423
475
  } else {
424
476
  result.push(NaN);
@@ -432,18 +484,22 @@ function wma(source, length2) {
432
484
  const len = Math.floor(length2);
433
485
  const filled = [];
434
486
  let last2 = NaN;
487
+ let count = 0;
435
488
  for (let i = 0; i < source.length; i++) {
436
489
  const v = source[i];
437
- const isNa = v === void 0 || v === null || Number.isNaN(v);
438
- if (!isNa) last2 = v;
490
+ const isNa2 = v === void 0 || v === null || !Number.isFinite(v);
491
+ if (!isNa2) {
492
+ last2 = v;
493
+ count++;
494
+ }
439
495
  filled.push(last2);
440
- if (isNa || i < len - 1) {
496
+ if (isNa2 || count < len) {
441
497
  result.push(NaN);
442
498
  continue;
443
499
  }
444
500
  let sum4 = 0;
445
501
  let weightSum = 0;
446
- for (let j = 0; j < len; j++) {
502
+ for (let j = len - 1; j >= 0; j--) {
447
503
  const weight = len - j;
448
504
  sum4 += filled[i - j] * weight;
449
505
  weightSum += weight;
@@ -557,53 +613,19 @@ function dev(source, length2) {
557
613
  return result;
558
614
  }
559
615
  function variance(source, length2, biased = true) {
560
- const result = [];
561
616
  const len = Math.floor(length2);
562
- const window = [];
563
- for (let i = 0; i < source.length; i++) {
564
- const v = source[i];
565
- if (v !== void 0 && v !== null && !Number.isNaN(v)) {
566
- window.push(v);
567
- if (window.length > len) window.shift();
568
- }
569
- const divisor = biased ? len : len - 1;
570
- if (window.length < len || divisor <= 0) {
571
- result.push(NaN);
572
- continue;
573
- }
574
- const mean = window.reduce((a, x) => a + x, 0) / len;
575
- let sumSquares = 0;
576
- for (const x of window) sumSquares += (x - mean) * (x - mean);
577
- result.push(sumSquares / divisor);
578
- }
579
- return result;
617
+ if ((biased ? len : len - 1) <= 0) return source.map(() => NaN);
618
+ return runningVariance(source, len, biased);
580
619
  }
581
620
  function median(source, length2) {
582
- const result = [];
583
- for (let i = 0; i < source.length; i++) {
584
- if (i < length2 - 1) {
585
- result.push(NaN);
586
- } else {
587
- const values2 = [];
588
- for (let j = 0; j < length2; j++) {
589
- if (!isNaN(source[i - j])) {
590
- values2.push(source[i - j]);
591
- }
592
- }
593
- if (values2.length === 0) {
594
- result.push(NaN);
595
- } else {
596
- values2.sort((a, b2) => a - b2);
597
- const mid = Math.floor(values2.length / 2);
598
- if (values2.length % 2 === 0) {
599
- result.push((values2[mid - 1] + values2[mid]) / 2);
600
- } else {
601
- result.push(values2[mid]);
602
- }
603
- }
604
- }
605
- }
606
- return result;
621
+ const len = Math.floor(length2);
622
+ return source.map((_, i) => {
623
+ const values2 = lastValues(source, i, len);
624
+ if (!values2) return NaN;
625
+ values2.sort((a, b2) => a - b2);
626
+ const mid = Math.floor(len / 2);
627
+ return len % 2 === 0 ? (values2[mid - 1] + values2[mid]) / 2 : values2[mid];
628
+ });
607
629
  }
608
630
  function swma(source) {
609
631
  const result = [];
@@ -788,12 +810,8 @@ function mfi(source, length2, volume) {
788
810
  upperFlow.push(le(change3, 0) ? 0 : flow);
789
811
  lowerFlow.push(ge(change3, 0) ? 0 : flow);
790
812
  }
791
- const sumAt = (flow, i) => {
792
- const values2 = lastValues(flow, i, Math.floor(length2));
793
- return values2 ? values2.reduce((a, b2) => a + b2, 0) : NaN;
794
- };
795
- const upper2 = upperFlow.map((_, i) => sumAt(upperFlow, i));
796
- const lower2 = lowerFlow.map((_, i) => sumAt(lowerFlow, i));
813
+ const upper2 = runningSum(upperFlow, length2);
814
+ const lower2 = runningSum(lowerFlow, length2);
797
815
  return upper2.map((u, i) => {
798
816
  const l = lower2[i];
799
817
  if (Number.isNaN(u) || Number.isNaN(l)) return NaN;
@@ -2434,23 +2452,7 @@ function avg(...values2) {
2434
2452
  }
2435
2453
  function sum(source, length2) {
2436
2454
  const sourceArray = source instanceof Series ? source.toArray() : source;
2437
- const result = [];
2438
- const len = Math.floor(length2);
2439
- const window = [];
2440
- for (let i = 0; i < sourceArray.length; i++) {
2441
- const v = sourceArray[i];
2442
- if (v !== void 0 && v !== null && !Number.isNaN(v)) {
2443
- window.push(v);
2444
- if (window.length > len) window.shift();
2445
- }
2446
- if (window.length < len) {
2447
- result.push(NaN);
2448
- } else {
2449
- let total = 0;
2450
- for (const x of window) total += x;
2451
- result.push(total);
2452
- }
2453
- }
2455
+ const result = runningSum(sourceArray, length2);
2454
2456
  if (source instanceof Series) {
2455
2457
  return Series.fromArray(source.bars, result);
2456
2458
  }
@@ -3235,9 +3237,9 @@ function shortestDigits(x) {
3235
3237
  function exactDigits(x) {
3236
3238
  const abs3 = Math.abs(x);
3237
3239
  if (abs3 === 0) return { digits: "", intLen: 0 };
3238
- const view = new DataView(new ArrayBuffer(8));
3239
- view.setFloat64(0, abs3);
3240
- const bits = view.getBigUint64(0);
3240
+ const view2 = new DataView(new ArrayBuffer(8));
3241
+ view2.setFloat64(0, abs3);
3242
+ const bits = view2.getBigUint64(0);
3241
3243
  const expBits = Number(bits >> 52n & 0x7ffn);
3242
3244
  let mant = bits & 0xfffffffffffffn;
3243
3245
  const e2 = expBits === 0 ? -1074 : expBits - 1075;
@@ -7839,7 +7841,7 @@ var SimpleInputAdapter = class {
7839
7841
  };
7840
7842
 
7841
7843
  // src/index.ts
7842
- var VERSION = "0.8.1";
7844
+ var VERSION = "0.8.2";
7843
7845
  var info2 = {
7844
7846
  name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KAAK,GAAG,MAAM,CAAC;AAC1E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;AAuDxE,eAAO,MAAM,EAAE,QAAU,CAAC;AAC1B,eAAO,MAAM,CAAC,QAAS,CAAC;AACxB,eAAO,MAAM,GAAG,oBAAoB,CAAC;AACrC,eAAO,MAAM,IAAI,oBAAoB,CAAC"}
@@ -45,6 +45,7 @@ export interface PlotConfig {
45
45
  offset?: number;
46
46
  histbase?: number;
47
47
  linestyle?: 'solid' | 'dashed' | 'dotted';
48
+ forceOverlay?: boolean;
48
49
  }
49
50
  export interface ArrowConfig {
50
51
  id: string;
@@ -55,6 +56,7 @@ export interface ArrowConfig {
55
56
  maxheight: number;
56
57
  offset?: number;
57
58
  display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
59
+ forceOverlay?: boolean;
58
60
  }
59
61
  export interface HLineConfig {
60
62
  id: string;
@@ -87,12 +89,14 @@ export interface ShapeConfig {
87
89
  textcolor?: string;
88
90
  size?: 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';
89
91
  offset?: number;
92
+ forceOverlay?: boolean;
90
93
  }
91
94
  export interface BarColorConfig {
92
95
  id: string;
93
96
  kind: 'bgcolor' | 'barcolor';
94
97
  title?: string;
95
98
  offset?: number;
99
+ forceOverlay?: boolean;
96
100
  }
97
101
  export interface InputOptions {
98
102
  min?: number;