oakscriptjs 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +42 -8
  2. package/dist/array/index.d.ts +7 -7
  3. package/dist/array/index.d.ts.map +1 -1
  4. package/dist/box/index.d.ts +11 -3
  5. package/dist/box/index.d.ts.map +1 -1
  6. package/dist/color/index.d.ts +15 -15
  7. package/dist/color/index.d.ts.map +1 -1
  8. package/dist/compare/index.d.ts +8 -0
  9. package/dist/compare/index.d.ts.map +1 -0
  10. package/dist/drawing/registry.d.ts +19 -0
  11. package/dist/drawing/registry.d.ts.map +1 -0
  12. package/dist/index.cjs +1740 -608
  13. package/dist/index.d.ts +9 -5
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.mjs +1740 -608
  16. package/dist/input.d.ts +7 -1
  17. package/dist/input.d.ts.map +1 -1
  18. package/dist/label/index.d.ts +12 -4
  19. package/dist/label/index.d.ts.map +1 -1
  20. package/dist/line/index.d.ts +11 -3
  21. package/dist/line/index.d.ts.map +1 -1
  22. package/dist/linefill/index.d.ts +3 -1
  23. package/dist/linefill/index.d.ts.map +1 -1
  24. package/dist/map/index.d.ts +14 -0
  25. package/dist/map/index.d.ts.map +1 -0
  26. package/dist/polyline/index.d.ts +1 -0
  27. package/dist/polyline/index.d.ts.map +1 -1
  28. package/dist/runtime/adapters/SimpleInputAdapter.d.ts.map +1 -1
  29. package/dist/runtime/index.cjs +40 -1
  30. package/dist/runtime/index.d.ts +1 -1
  31. package/dist/runtime/index.d.ts.map +1 -1
  32. package/dist/runtime/index.mjs +40 -1
  33. package/dist/runtime/inputs.d.ts +3 -0
  34. package/dist/runtime/inputs.d.ts.map +1 -1
  35. package/dist/runtime/series.d.ts.map +1 -1
  36. package/dist/runtime/types.d.ts +1 -1
  37. package/dist/runtime/types.d.ts.map +1 -1
  38. package/dist/script/index.cjs +3097 -635
  39. package/dist/script/index.d.ts +293 -27
  40. package/dist/script/index.d.ts.map +1 -1
  41. package/dist/script/index.mjs +3097 -635
  42. package/dist/security/resample.d.ts +13 -0
  43. package/dist/security/resample.d.ts.map +1 -0
  44. package/dist/session/bars.d.ts +34 -0
  45. package/dist/session/bars.d.ts.map +1 -0
  46. package/dist/session/calendar.d.ts +31 -0
  47. package/dist/session/calendar.d.ts.map +1 -0
  48. package/dist/str/dateformat.d.ts +2 -0
  49. package/dist/str/dateformat.d.ts.map +1 -0
  50. package/dist/str/index.d.ts +1 -1
  51. package/dist/str/index.d.ts.map +1 -1
  52. package/dist/str/messageformat.d.ts +2 -0
  53. package/dist/str/messageformat.d.ts.map +1 -0
  54. package/dist/str/numberformat.d.ts +3 -0
  55. package/dist/str/numberformat.d.ts.map +1 -0
  56. package/dist/ta/index.d.ts +14 -5
  57. package/dist/ta/index.d.ts.map +1 -1
  58. package/dist/ta-series.d.ts +23 -5
  59. package/dist/ta-series.d.ts.map +1 -1
  60. package/dist/text/index.d.ts +4 -0
  61. package/dist/text/index.d.ts.map +1 -0
  62. package/dist/time/datestring.d.ts +2 -0
  63. package/dist/time/datestring.d.ts.map +1 -0
  64. package/dist/time/index.d.ts +11 -0
  65. package/dist/time/index.d.ts.map +1 -1
  66. package/dist/time/session.d.ts +2 -0
  67. package/dist/time/session.d.ts.map +1 -0
  68. package/dist/time/timezone.d.ts +13 -0
  69. package/dist/time/timezone.d.ts.map +1 -0
  70. package/dist/timeframe/index.d.ts +17 -0
  71. package/dist/timeframe/index.d.ts.map +1 -0
  72. package/dist/types/index.d.ts +7 -0
  73. package/dist/types/index.d.ts.map +1 -1
  74. package/dist/types/metadata.d.ts +1 -1
  75. package/dist/types/metadata.d.ts.map +1 -1
  76. package/dist/utils/index.d.ts +1 -0
  77. package/dist/utils/index.d.ts.map +1 -1
  78. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -3,9 +3,9 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
6
+ var __export = (target, all7) => {
7
+ for (var name in all7)
8
+ __defProp(target, name, { get: all7[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from2, except, desc) => {
11
11
  if (from2 && typeof from2 === "object" || typeof from2 === "function") {
@@ -41,6 +41,7 @@ __export(index_exports, {
41
41
  clearPlots: () => clearPlots,
42
42
  color: () => color_exports,
43
43
  color_from_hex: () => from_hex,
44
+ compare: () => compare_exports,
44
45
  cos: () => cos,
45
46
  createPlot: () => createPlot,
46
47
  crossover: () => crossover2,
@@ -48,6 +49,7 @@ __export(index_exports, {
48
49
  cum: () => cum2,
49
50
  ema: () => ema2,
50
51
  exp: () => exp,
52
+ fixnan: () => fixnan,
51
53
  floor: () => floor,
52
54
  getClose: () => getClose,
53
55
  getContext: () => getContext,
@@ -57,18 +59,22 @@ __export(index_exports, {
57
59
  getSourceSeries: () => getSourceSeries,
58
60
  hline: () => hline,
59
61
  indicator: () => indicator,
60
- info: () => info,
62
+ info: () => info2,
61
63
  input: () => input,
62
64
  input_bool: () => input_bool,
63
65
  input_float: () => input_float,
64
66
  input_int: () => input_int,
67
+ input_session: () => input_session,
65
68
  input_source: () => input_source,
66
69
  input_string: () => input_string,
70
+ input_time: () => input_time,
71
+ input_timeframe: () => input_timeframe,
67
72
  label: () => label_exports,
68
73
  line: () => line_exports,
69
74
  linefill: () => linefill_exports,
70
75
  log: () => log,
71
76
  macd: () => macd2,
77
+ map: () => map_exports,
72
78
  math: () => math_exports,
73
79
  matrix: () => matrix_exports,
74
80
  max: () => max2,
@@ -96,7 +102,9 @@ __export(index_exports, {
96
102
  ta: () => ta_series_exports,
97
103
  taCore: () => ta_exports,
98
104
  tan: () => tan,
105
+ text: () => text_exports,
99
106
  time: () => time_exports,
107
+ timeframe: () => timeframe_exports,
100
108
  tr: () => tr2,
101
109
  vwap: () => vwap2,
102
110
  xloc: () => xloc,
@@ -115,6 +123,7 @@ var xloc = {
115
123
  // src/ta/index.ts
116
124
  var ta_exports = {};
117
125
  __export(ta_exports, {
126
+ accdist: () => accdist,
118
127
  alma: () => alma,
119
128
  atr: () => atr,
120
129
  barssince: () => barssince,
@@ -137,6 +146,7 @@ __export(ta_exports, {
137
146
  highestbars: () => highestbars,
138
147
  hma: () => hma,
139
148
  ichimoku: () => ichimoku,
149
+ iii: () => iii,
140
150
  kc: () => kc,
141
151
  kcw: () => kcw,
142
152
  linreg: () => linreg,
@@ -149,12 +159,16 @@ __export(ta_exports, {
149
159
  min: () => min,
150
160
  mode: () => mode,
151
161
  mom: () => mom,
162
+ nvi: () => nvi,
163
+ obv: () => obv,
152
164
  percentile_linear_interpolation: () => percentile_linear_interpolation,
153
165
  percentile_nearest_rank: () => percentile_nearest_rank,
154
166
  percentrank: () => percentrank,
155
167
  pivot_point_levels: () => pivot_point_levels,
156
168
  pivothigh: () => pivothigh,
157
169
  pivotlow: () => pivotlow,
170
+ pvi: () => pvi,
171
+ pvt: () => pvt,
158
172
  range: () => range,
159
173
  rci: () => rci,
160
174
  rising: () => rising,
@@ -173,8 +187,10 @@ __export(ta_exports, {
173
187
  variance: () => variance,
174
188
  vwap: () => vwap,
175
189
  vwma: () => vwma,
190
+ wad: () => wad,
176
191
  wma: () => wma,
177
192
  wpr: () => wpr,
193
+ wvad: () => wvad,
178
194
  zigzag: () => zigzag
179
195
  });
180
196
  function sma(source, length2) {
@@ -234,8 +250,8 @@ function rsi(source, length2) {
234
250
  for (let i = 1; i < source.length; i++) {
235
251
  changes.push(source[i] - source[i - 1]);
236
252
  }
237
- const gains = changes.map((c) => c > 0 ? c : 0);
238
- const losses = changes.map((c) => c < 0 ? -c : 0);
253
+ const gains = changes.map((c) => Number.isNaN(c) ? NaN : c > 0 ? c : 0);
254
+ const losses = changes.map((c) => Number.isNaN(c) ? NaN : c < 0 ? -c : 0);
239
255
  const avgGains = rma(gains, length2);
240
256
  const avgLosses = rma(losses, length2);
241
257
  result.push(NaN);
@@ -274,23 +290,42 @@ function bb(series, length2, mult2) {
274
290
  }
275
291
  return [basis, upper2, lower2];
276
292
  }
277
- function stdev(source, length2) {
278
- const result = [];
293
+ function stdev(source, length2, biased = true) {
279
294
  const len = Math.floor(length2);
280
- const avg4 = sma(source, len);
281
- for (let i = 0; i < source.length; i++) {
282
- if (i < len - 1) {
283
- result.push(NaN);
284
- } else {
285
- let sumSquares = 0;
286
- for (let j = 0; j < len; j++) {
287
- const diff2 = source[i - j] - avg4[i];
288
- sumSquares += diff2 * diff2;
289
- }
290
- result.push(Math.sqrt(sumSquares / len));
291
- }
292
- }
293
- return result;
295
+ return source.map((_, i) => {
296
+ const values2 = lastValues(source, i, len);
297
+ if (!values2) return NaN;
298
+ const mean = values2.reduce((a, b2) => a + b2, 0) / len;
299
+ const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
300
+ return Math.sqrt(squares / (biased ? len : len - 1));
301
+ });
302
+ }
303
+ function lastValues(source, i, length2) {
304
+ const values2 = [];
305
+ for (let j = i; j >= 0 && values2.length < length2; j--) {
306
+ const x = source[j];
307
+ if (!Number.isNaN(x)) values2.push(x);
308
+ }
309
+ return values2.length === length2 ? values2 : null;
310
+ }
311
+ function windowUntilNa(source, i, length2) {
312
+ const values2 = [];
313
+ for (let j = 0; j < length2 && i - j >= 0; j++) {
314
+ const x = source[i - j];
315
+ if (Number.isNaN(x)) break;
316
+ values2.push([x, -j]);
317
+ }
318
+ return values2;
319
+ }
320
+ function extremeOffset(source, length2, isHigher) {
321
+ return source.map((_, i) => {
322
+ if (i < length2 - 1) return NaN;
323
+ const w = windowUntilNa(source, i, length2);
324
+ if (w.length === 0) return 0;
325
+ let best = w[0];
326
+ for (const item of w) if (isHigher(item[0], best[0])) best = item;
327
+ return best[1];
328
+ });
294
329
  }
295
330
  function crossover(series1, series2) {
296
331
  const result = [];
@@ -443,8 +478,10 @@ function rma(source, length2) {
443
478
  const val = source[i];
444
479
  if (val !== void 0 && !isNaN(val)) {
445
480
  rmaValue = alpha * val + (1 - alpha) * rmaValue;
481
+ result.push(rmaValue);
482
+ } else {
483
+ result.push(NaN);
446
484
  }
447
- result.push(rmaValue);
448
485
  }
449
486
  }
450
487
  return result;
@@ -469,47 +506,26 @@ function wma(source, length2) {
469
506
  return result;
470
507
  }
471
508
  function highest(source, length2) {
472
- const result = [];
473
- for (let i = 0; i < source.length; i++) {
474
- if (i < length2 - 1) {
475
- result.push(NaN);
476
- } else {
477
- let max6 = -Infinity;
478
- for (let j = 0; j < length2; j++) {
479
- if (!isNaN(source[i - j])) {
480
- max6 = Math.max(max6, source[i - j]);
481
- }
482
- }
483
- result.push(max6 === -Infinity ? NaN : max6);
484
- }
485
- }
486
- return result;
509
+ return source.map((_, i) => {
510
+ if (i < length2 - 1) return NaN;
511
+ const w = windowUntilNa(source, i, length2);
512
+ return w.length ? Math.max(...w.map((x) => x[0])) : NaN;
513
+ });
487
514
  }
488
515
  function lowest(source, length2) {
489
- const result = [];
490
- for (let i = 0; i < source.length; i++) {
491
- if (i < length2 - 1) {
492
- result.push(NaN);
493
- } else {
494
- let min6 = Infinity;
495
- for (let j = 0; j < length2; j++) {
496
- if (!isNaN(source[i - j])) {
497
- min6 = Math.min(min6, source[i - j]);
498
- }
499
- }
500
- result.push(min6 === Infinity ? NaN : min6);
501
- }
502
- }
503
- return result;
516
+ return source.map((_, i) => {
517
+ if (i < length2 - 1) return NaN;
518
+ const w = windowUntilNa(source, i, length2);
519
+ return w.length ? Math.min(...w.map((x) => x[0])) : NaN;
520
+ });
504
521
  }
505
522
  function cum(source) {
506
- const result = [];
507
523
  let sum4 = 0;
508
- for (let i = 0; i < source.length; i++) {
509
- sum4 += source[i];
510
- result.push(sum4);
511
- }
512
- return result;
524
+ return source.map((v) => {
525
+ if (Number.isNaN(v)) return NaN;
526
+ sum4 += v;
527
+ return sum4;
528
+ });
513
529
  }
514
530
  function cross(source1, source2) {
515
531
  const result = [];
@@ -638,21 +654,21 @@ function median(source, length2) {
638
654
  if (i < length2 - 1) {
639
655
  result.push(NaN);
640
656
  } else {
641
- const values = [];
657
+ const values2 = [];
642
658
  for (let j = 0; j < length2; j++) {
643
659
  if (!isNaN(source[i - j])) {
644
- values.push(source[i - j]);
660
+ values2.push(source[i - j]);
645
661
  }
646
662
  }
647
- if (values.length === 0) {
663
+ if (values2.length === 0) {
648
664
  result.push(NaN);
649
665
  } else {
650
- values.sort((a, b2) => a - b2);
651
- const mid = Math.floor(values.length / 2);
652
- if (values.length % 2 === 0) {
653
- result.push((values[mid - 1] + values[mid]) / 2);
666
+ values2.sort((a, b2) => a - b2);
667
+ const mid = Math.floor(values2.length / 2);
668
+ if (values2.length % 2 === 0) {
669
+ result.push((values2[mid - 1] + values2[mid]) / 2);
654
670
  } else {
655
- result.push(values[mid]);
671
+ result.push(values2[mid]);
656
672
  }
657
673
  }
658
674
  }
@@ -982,89 +998,44 @@ function sar(start, inc, max6, high, low, close) {
982
998
  }
983
999
  return result;
984
1000
  }
1001
+ function pivot(source, leftbars, rightbars, isHigh) {
1002
+ const beatsLeft = isHigh ? (x, v) => x > v : (x, v) => x < v;
1003
+ const beatsRight = isHigh ? (x, v) => x >= v : (x, v) => x <= v;
1004
+ return source.map((_, i) => {
1005
+ const center = i - rightbars;
1006
+ if (center - leftbars < 0) return NaN;
1007
+ const v = source[center];
1008
+ if (Number.isNaN(v)) return NaN;
1009
+ for (let j = 1; j <= leftbars; j++) {
1010
+ const x = source[center - j];
1011
+ if (Number.isNaN(x)) break;
1012
+ if (beatsLeft(x, v)) return NaN;
1013
+ }
1014
+ for (let j = 1; j <= rightbars; j++) {
1015
+ const x = source[center + j];
1016
+ if (Number.isNaN(x)) break;
1017
+ if (beatsRight(x, v)) return NaN;
1018
+ }
1019
+ return v;
1020
+ });
1021
+ }
985
1022
  function pivothigh(sourceOrLeftbars, leftbarsOrRightbars, rightbars, high) {
986
- let source;
987
- let leftbars;
988
- let right;
989
1023
  if (rightbars === void 0) {
990
1024
  if (!high) {
991
1025
  throw new Error("ta.pivothigh() requires high series when using two-parameter version.");
992
1026
  }
993
- source = high;
994
- leftbars = sourceOrLeftbars;
995
- right = leftbarsOrRightbars;
996
- } else {
997
- source = sourceOrLeftbars;
998
- leftbars = leftbarsOrRightbars;
999
- right = rightbars;
1027
+ return pivot(high, sourceOrLeftbars, leftbarsOrRightbars, true);
1000
1028
  }
1001
- const result = [];
1002
- for (let i = 0; i < source.length; i++) {
1003
- if (i < leftbars || i + right >= source.length) {
1004
- result.push(NaN);
1005
- continue;
1006
- }
1007
- const centerValue = source[i];
1008
- let isPivot = true;
1009
- for (let j = 1; j <= leftbars; j++) {
1010
- if (source[i - j] >= centerValue) {
1011
- isPivot = false;
1012
- break;
1013
- }
1014
- }
1015
- if (isPivot) {
1016
- for (let j = 1; j <= right; j++) {
1017
- if (source[i + j] >= centerValue) {
1018
- isPivot = false;
1019
- break;
1020
- }
1021
- }
1022
- }
1023
- result.push(isPivot ? centerValue : NaN);
1024
- }
1025
- return result;
1029
+ return pivot(sourceOrLeftbars, leftbarsOrRightbars, rightbars, true);
1026
1030
  }
1027
1031
  function pivotlow(sourceOrLeftbars, leftbarsOrRightbars, rightbars, low) {
1028
- let source;
1029
- let leftbars;
1030
- let right;
1031
1032
  if (rightbars === void 0) {
1032
1033
  if (!low) {
1033
1034
  throw new Error("ta.pivotlow() requires low series when using two-parameter version.");
1034
1035
  }
1035
- source = low;
1036
- leftbars = sourceOrLeftbars;
1037
- right = leftbarsOrRightbars;
1038
- } else {
1039
- source = sourceOrLeftbars;
1040
- leftbars = leftbarsOrRightbars;
1041
- right = rightbars;
1036
+ return pivot(low, sourceOrLeftbars, leftbarsOrRightbars, false);
1042
1037
  }
1043
- const result = [];
1044
- for (let i = 0; i < source.length; i++) {
1045
- if (i < leftbars || i + right >= source.length) {
1046
- result.push(NaN);
1047
- continue;
1048
- }
1049
- const centerValue = source[i];
1050
- let isPivot = true;
1051
- for (let j = 1; j <= leftbars; j++) {
1052
- if (source[i - j] <= centerValue) {
1053
- isPivot = false;
1054
- break;
1055
- }
1056
- }
1057
- if (isPivot) {
1058
- for (let j = 1; j <= right; j++) {
1059
- if (source[i + j] <= centerValue) {
1060
- isPivot = false;
1061
- break;
1062
- }
1063
- }
1064
- }
1065
- result.push(isPivot ? centerValue : NaN);
1066
- }
1067
- return result;
1038
+ return pivot(sourceOrLeftbars, leftbarsOrRightbars, rightbars, false);
1068
1039
  }
1069
1040
  function barssince(condition) {
1070
1041
  const result = [];
@@ -1258,27 +1229,38 @@ function wpr(high, low, close, length2 = 14) {
1258
1229
  }
1259
1230
  return result;
1260
1231
  }
1261
- function vwap(source, volume) {
1232
+ function vwap(source, volume, anchor, stdev_mult) {
1262
1233
  if (source.length !== volume.length) {
1263
1234
  throw new Error("ta.vwap: source and volume must have the same length");
1264
1235
  }
1265
- const result = [];
1266
- let cumulativePV = 0;
1267
- let cumulativeVolume = 0;
1236
+ const mid = [];
1237
+ const upper2 = [];
1238
+ const lower2 = [];
1239
+ let sumPV = 0;
1240
+ let sumV = 0;
1241
+ let sumPPV = 0;
1268
1242
  for (let i = 0; i < source.length; i++) {
1269
- if (isNaN(source[i]) || isNaN(volume[i])) {
1270
- result.push(NaN);
1271
- continue;
1243
+ if (anchor && anchor[i]) {
1244
+ sumPV = 0;
1245
+ sumV = 0;
1246
+ sumPPV = 0;
1272
1247
  }
1273
- cumulativePV += source[i] * volume[i];
1274
- cumulativeVolume += volume[i];
1275
- if (cumulativeVolume === 0) {
1276
- result.push(NaN);
1277
- } else {
1278
- result.push(cumulativePV / cumulativeVolume);
1248
+ const s = source[i];
1249
+ const v = volume[i];
1250
+ if (!Number.isNaN(s) && !Number.isNaN(v)) {
1251
+ sumPV += s * v;
1252
+ sumV += v;
1253
+ sumPPV += s * s * v;
1254
+ }
1255
+ const m = sumV === 0 ? NaN : sumPV / sumV;
1256
+ mid.push(m);
1257
+ if (stdev_mult !== void 0) {
1258
+ const sd = Math.sqrt(Math.max(0, sumPPV / sumV - m * m));
1259
+ upper2.push(m + stdev_mult * sd);
1260
+ lower2.push(m - stdev_mult * sd);
1279
1261
  }
1280
1262
  }
1281
- return result;
1263
+ return stdev_mult === void 0 ? mid : [mid, upper2, lower2];
1282
1264
  }
1283
1265
  function alma(source, length2 = 9, offset = 0.85, sigma = 6, floor2 = false) {
1284
1266
  const result = [];
@@ -1320,85 +1302,31 @@ function kcw(source, length2 = 20, mult2 = 2, useTrueRange = true, high, low, cl
1320
1302
  }
1321
1303
  return result;
1322
1304
  }
1323
- function range(high, low) {
1324
- if (high.length !== low.length) {
1325
- throw new Error("ta.range: high and low must have the same length");
1326
- }
1327
- const result = [];
1328
- for (let i = 0; i < high.length; i++) {
1329
- if (isNaN(high[i]) || isNaN(low[i])) {
1330
- result.push(NaN);
1331
- } else {
1332
- result.push(high[i] - low[i]);
1333
- }
1334
- }
1335
- return result;
1305
+ function range(source, length2) {
1306
+ return source.map((_, i) => {
1307
+ const values2 = lastValues(source, i, length2);
1308
+ return values2 ? Math.max(...values2) - Math.min(...values2) : NaN;
1309
+ });
1336
1310
  }
1337
1311
  function highestbars(source, length2) {
1338
- const result = [];
1339
- for (let i = 0; i < source.length; i++) {
1340
- if (i < length2 - 1) {
1341
- result.push(NaN);
1342
- continue;
1343
- }
1344
- let highestValue = source[i - length2 + 1];
1345
- let highestOffset = length2 - 1;
1346
- for (let j = i - length2 + 2; j <= i; j++) {
1347
- if (source[j] > highestValue) {
1348
- highestValue = source[j];
1349
- highestOffset = i - j;
1350
- }
1351
- }
1352
- result.push(highestOffset);
1353
- }
1354
- return result;
1312
+ return extremeOffset(source, length2, (a, b2) => a >= b2);
1355
1313
  }
1356
1314
  function lowestbars(source, length2) {
1357
- const result = [];
1358
- for (let i = 0; i < source.length; i++) {
1359
- if (i < length2 - 1) {
1360
- result.push(NaN);
1361
- continue;
1362
- }
1363
- let lowestValue = source[i - length2 + 1];
1364
- let lowestOffset = length2 - 1;
1365
- for (let j = i - length2 + 2; j <= i; j++) {
1366
- if (source[j] < lowestValue) {
1367
- lowestValue = source[j];
1368
- lowestOffset = i - j;
1369
- }
1370
- }
1371
- result.push(lowestOffset);
1372
- }
1373
- return result;
1315
+ return extremeOffset(source, length2, (a, b2) => a <= b2);
1374
1316
  }
1375
- function max(source1, source2) {
1376
- if (source1.length !== source2.length) {
1377
- throw new Error("ta.max: source1 and source2 must have the same length");
1378
- }
1379
- const result = [];
1380
- for (let i = 0; i < source1.length; i++) {
1381
- if (isNaN(source1[i]) || isNaN(source2[i])) {
1382
- result.push(NaN);
1383
- } else {
1384
- result.push(Math.max(source1[i], source2[i]));
1385
- }
1386
- }
1387
- return result;
1317
+ function max(source) {
1318
+ let best = NaN;
1319
+ return source.map((x) => {
1320
+ if (!Number.isNaN(x) && !(x <= best)) best = x;
1321
+ return best;
1322
+ });
1388
1323
  }
1389
- function min(source1, source2) {
1390
- if (source1.length !== source2.length) {
1391
- throw new Error("ta.min: source1 and source2 must have the same length");
1392
- }
1393
- const result = [];
1394
- for (let i = 0; i < source1.length; i++) {
1395
- if (isNaN(source1[i]) || isNaN(source2[i])) {
1396
- result.push(NaN);
1397
- } else {
1398
- result.push(Math.min(source1[i], source2[i]));
1399
- }
1400
- }
1401
- return result;
1324
+ function min(source) {
1325
+ let best = NaN;
1326
+ return source.map((x) => {
1327
+ if (!Number.isNaN(x) && !(x >= best)) best = x;
1328
+ return best;
1329
+ });
1402
1330
  }
1403
1331
  function cog(source, length2 = 10) {
1404
1332
  const result = [];
@@ -1431,19 +1359,19 @@ function mode(source, length2) {
1431
1359
  result.push(NaN);
1432
1360
  continue;
1433
1361
  }
1434
- const values = [];
1362
+ const values2 = [];
1435
1363
  for (let j = 0; j < length2; j++) {
1436
1364
  const value = source[i - j];
1437
1365
  if (!isNaN(value)) {
1438
- values.push(value);
1366
+ values2.push(value);
1439
1367
  }
1440
1368
  }
1441
- if (values.length === 0) {
1369
+ if (values2.length === 0) {
1442
1370
  result.push(NaN);
1443
1371
  continue;
1444
1372
  }
1445
1373
  const frequencyMap = /* @__PURE__ */ new Map();
1446
- for (const value of values) {
1374
+ for (const value of values2) {
1447
1375
  frequencyMap.set(value, (frequencyMap.get(value) || 0) + 1);
1448
1376
  }
1449
1377
  let maxFrequency = 0;
@@ -1469,16 +1397,16 @@ function percentile_linear_interpolation(source, length2, percentage) {
1469
1397
  result.push(NaN);
1470
1398
  continue;
1471
1399
  }
1472
- const values = [];
1400
+ const values2 = [];
1473
1401
  for (let j = 0; j < length2; j++) {
1474
1402
  const value = source[i - j];
1475
- values.push(value);
1403
+ values2.push(value);
1476
1404
  }
1477
- if (values.some((v) => isNaN(v))) {
1405
+ if (values2.some((v) => isNaN(v))) {
1478
1406
  result.push(NaN);
1479
1407
  continue;
1480
1408
  }
1481
- const sorted = [...values].sort((a, b2) => a - b2);
1409
+ const sorted = [...values2].sort((a, b2) => a - b2);
1482
1410
  const position = percentage / 100 * (sorted.length - 1);
1483
1411
  const lowerIndex = Math.floor(position);
1484
1412
  const upperIndex = Math.ceil(position);
@@ -1499,18 +1427,18 @@ function percentile_nearest_rank(source, length2, percentage) {
1499
1427
  result.push(NaN);
1500
1428
  continue;
1501
1429
  }
1502
- const values = [];
1430
+ const values2 = [];
1503
1431
  for (let j = 0; j < length2; j++) {
1504
1432
  const value = source[i - j];
1505
1433
  if (!isNaN(value)) {
1506
- values.push(value);
1434
+ values2.push(value);
1507
1435
  }
1508
1436
  }
1509
- if (values.length === 0) {
1437
+ if (values2.length === 0) {
1510
1438
  result.push(NaN);
1511
1439
  continue;
1512
1440
  }
1513
- const sorted = [...values].sort((a, b2) => a - b2);
1441
+ const sorted = [...values2].sort((a, b2) => a - b2);
1514
1442
  if (percentage >= 100) {
1515
1443
  result.push(sorted[sorted.length - 1]);
1516
1444
  continue;
@@ -1528,15 +1456,15 @@ function rci(source, length2) {
1528
1456
  result.push(NaN);
1529
1457
  continue;
1530
1458
  }
1531
- const values = [];
1459
+ const values2 = [];
1532
1460
  for (let j = 0; j < length2; j++) {
1533
- values.push(source[i - length2 + 1 + j]);
1461
+ values2.push(source[i - length2 + 1 + j]);
1534
1462
  }
1535
- if (values.some((v) => isNaN(v))) {
1463
+ if (values2.some((v) => isNaN(v))) {
1536
1464
  result.push(NaN);
1537
1465
  continue;
1538
1466
  }
1539
- const indexed = values.map((value, index) => ({ value, index }));
1467
+ const indexed = values2.map((value, index) => ({ value, index }));
1540
1468
  const sorted = [...indexed].sort((a, b2) => a.value - b2.value);
1541
1469
  const ranks = new Array(length2).fill(0);
1542
1470
  let currentRank = 1;
@@ -1900,23 +1828,86 @@ function zigzag(deviation = 5, depth = 10, backstep = 3, source, high, low) {
1900
1828
  if (potentialPivot) {
1901
1829
  confirmedPivots.push(potentialPivot);
1902
1830
  }
1903
- for (const pivot of confirmedPivots) {
1904
- zigzagValues[pivot.index] = pivot.price;
1905
- isPivot[pivot.index] = true;
1831
+ for (const pivot2 of confirmedPivots) {
1832
+ zigzagValues[pivot2.index] = pivot2.price;
1833
+ isPivot[pivot2.index] = true;
1906
1834
  }
1907
1835
  let currentDir = 0;
1908
1836
  let pivotIdx = 0;
1909
1837
  const numConfirmed = lastPotentialWasAdded ? confirmedPivots.length - 1 : confirmedPivots.length;
1910
1838
  for (let i = 0; i < length2; i++) {
1911
1839
  while (pivotIdx < numConfirmed && confirmedPivots[pivotIdx].index <= i) {
1912
- const pivot = confirmedPivots[pivotIdx];
1913
- currentDir = pivot.type === "low" ? 1 : -1;
1840
+ const pivot2 = confirmedPivots[pivotIdx];
1841
+ currentDir = pivot2.type === "low" ? 1 : -1;
1914
1842
  pivotIdx++;
1915
1843
  }
1916
1844
  directions[i] = currentDir;
1917
1845
  }
1918
1846
  return [zigzagValues, directions, isPivot];
1919
1847
  }
1848
+ function obv(close, volume) {
1849
+ return cum(close.map((c, i) => i === 0 ? NaN : Math.sign(c - close[i - 1]) * volume[i]));
1850
+ }
1851
+ function pvt(close, volume) {
1852
+ return cum(
1853
+ close.map((c, i) => i === 0 ? NaN : (c - close[i - 1]) / close[i - 1] * volume[i])
1854
+ );
1855
+ }
1856
+ function accdist(high, low, close, volume) {
1857
+ return cum(
1858
+ close.map((c, i) => {
1859
+ const h = high[i];
1860
+ const l = low[i];
1861
+ return h === l ? 0 : (2 * c - l - h) / (h - l) * volume[i];
1862
+ })
1863
+ );
1864
+ }
1865
+ function iii(high, low, close, volume) {
1866
+ return close.map((c, i) => {
1867
+ const range4 = high[i] - low[i];
1868
+ return range4 === 0 ? NaN : (2 * c - high[i] - low[i]) / range4 * volume[i];
1869
+ });
1870
+ }
1871
+ function wvad(open, high, low, close, volume) {
1872
+ return close.map((c, i) => {
1873
+ const range4 = high[i] - low[i];
1874
+ return range4 === 0 ? NaN : (c - open[i]) / range4 * volume[i];
1875
+ });
1876
+ }
1877
+ function wad(high, low, close) {
1878
+ return cum(
1879
+ close.map((c, i) => {
1880
+ const prev = i === 0 ? NaN : close[i - 1];
1881
+ const mom3 = c - prev;
1882
+ if (mom3 > 0) return c - Math.min(low[i], prev);
1883
+ if (mom3 < 0) return c - Math.max(high[i], prev);
1884
+ return 0;
1885
+ })
1886
+ );
1887
+ }
1888
+ function volumeIndex(close, volume, use) {
1889
+ const result = [];
1890
+ let prevIndex = NaN;
1891
+ for (let i = 0; i < close.length; i++) {
1892
+ const prev = !prevIndex ? 1 : prevIndex;
1893
+ const c = close[i];
1894
+ const prevC = i === 0 ? NaN : close[i - 1];
1895
+ let value = prev;
1896
+ if (c && prevC) {
1897
+ const prevV = i === 0 || Number.isNaN(volume[i - 1]) ? 0 : volume[i - 1];
1898
+ if (use(volume[i], prevV)) value = prev + (c - prevC) / prevC * prev;
1899
+ }
1900
+ result.push(value);
1901
+ prevIndex = value;
1902
+ }
1903
+ return result;
1904
+ }
1905
+ function nvi(close, volume) {
1906
+ return volumeIndex(close, volume, (v, prevV) => v < prevV);
1907
+ }
1908
+ function pvi(close, volume) {
1909
+ return volumeIndex(close, volume, (v, prevV) => v > prevV);
1910
+ }
1920
1911
 
1921
1912
  // src/math/index.ts
1922
1913
  var math_exports = {};
@@ -1951,6 +1942,38 @@ __export(math_exports, {
1951
1942
  toradians: () => toradians
1952
1943
  });
1953
1944
 
1945
+ // src/compare/index.ts
1946
+ var compare_exports = {};
1947
+ __export(compare_exports, {
1948
+ EPSILON: () => EPSILON,
1949
+ eq: () => eq,
1950
+ ge: () => ge,
1951
+ gt: () => gt,
1952
+ le: () => le,
1953
+ lt: () => lt,
1954
+ ne: () => ne
1955
+ });
1956
+ var EPSILON = 1e-10;
1957
+ var valid = (a, b2) => !Number.isNaN(a) && !Number.isNaN(b2);
1958
+ function eq(a, b2) {
1959
+ return valid(a, b2) && Math.abs(a - b2) <= EPSILON;
1960
+ }
1961
+ function ne(a, b2) {
1962
+ return valid(a, b2) && Math.abs(a - b2) > EPSILON;
1963
+ }
1964
+ function lt(a, b2) {
1965
+ return valid(a, b2) && b2 - a > EPSILON;
1966
+ }
1967
+ function le(a, b2) {
1968
+ return valid(a, b2) && a - b2 <= EPSILON;
1969
+ }
1970
+ function gt(a, b2) {
1971
+ return valid(a, b2) && a - b2 > EPSILON;
1972
+ }
1973
+ function ge(a, b2) {
1974
+ return valid(a, b2) && b2 - a <= EPSILON;
1975
+ }
1976
+
1954
1977
  // src/runtime/series.ts
1955
1978
  var BarData = class _BarData {
1956
1979
  _bars;
@@ -2093,8 +2116,8 @@ var Series = class _Series {
2093
2116
  * @param field - Field to extract ('open', 'high', 'low', 'close', 'volume')
2094
2117
  * @returns Series with extracted field values
2095
2118
  */
2096
- static fromBars(bars, field) {
2097
- return new _Series(bars, (bar) => bar[field] ?? NaN);
2119
+ static fromBars(bars, field2) {
2120
+ return new _Series(bars, (bar) => bar[field2] ?? NaN);
2098
2121
  }
2099
2122
  /**
2100
2123
  * Create a constant series (same value for all bars)
@@ -2111,8 +2134,8 @@ var Series = class _Series {
2111
2134
  * @param values - Array of values
2112
2135
  * @returns Series
2113
2136
  */
2114
- static fromArray(bars, values) {
2115
- return new _Series(bars, (_bar, i) => values[i] ?? NaN);
2137
+ static fromArray(bars, values2) {
2138
+ return new _Series(bars, (_bar, i) => values2[i] ?? NaN);
2116
2139
  }
2117
2140
  // ============================================
2118
2141
  // Arithmetic Operations
@@ -2199,7 +2222,7 @@ var Series = class _Series {
2199
2222
  });
2200
2223
  }
2201
2224
  // ============================================
2202
- // Comparison Operations
2225
+ // Comparison Operations (PineScript operators: tolerance 1e-10, false with na; see src/compare)
2203
2226
  // ============================================
2204
2227
  /**
2205
2228
  * Greater than comparison
@@ -2210,7 +2233,7 @@ var Series = class _Series {
2210
2233
  return new _Series(this.dataSource, (bar, i, data) => {
2211
2234
  const a = this.extractor(bar, i, data);
2212
2235
  const b2 = typeof other === "number" ? other : other.extractor(bar, i, data);
2213
- return a > b2 ? 1 : 0;
2236
+ return gt(a, b2) ? 1 : 0;
2214
2237
  });
2215
2238
  }
2216
2239
  /**
@@ -2222,7 +2245,7 @@ var Series = class _Series {
2222
2245
  return new _Series(this.dataSource, (bar, i, data) => {
2223
2246
  const a = this.extractor(bar, i, data);
2224
2247
  const b2 = typeof other === "number" ? other : other.extractor(bar, i, data);
2225
- return a >= b2 ? 1 : 0;
2248
+ return ge(a, b2) ? 1 : 0;
2226
2249
  });
2227
2250
  }
2228
2251
  /**
@@ -2234,7 +2257,7 @@ var Series = class _Series {
2234
2257
  return new _Series(this.dataSource, (bar, i, data) => {
2235
2258
  const a = this.extractor(bar, i, data);
2236
2259
  const b2 = typeof other === "number" ? other : other.extractor(bar, i, data);
2237
- return a < b2 ? 1 : 0;
2260
+ return lt(a, b2) ? 1 : 0;
2238
2261
  });
2239
2262
  }
2240
2263
  /**
@@ -2246,7 +2269,7 @@ var Series = class _Series {
2246
2269
  return new _Series(this.dataSource, (bar, i, data) => {
2247
2270
  const a = this.extractor(bar, i, data);
2248
2271
  const b2 = typeof other === "number" ? other : other.extractor(bar, i, data);
2249
- return a <= b2 ? 1 : 0;
2272
+ return le(a, b2) ? 1 : 0;
2250
2273
  });
2251
2274
  }
2252
2275
  /**
@@ -2258,7 +2281,7 @@ var Series = class _Series {
2258
2281
  return new _Series(this.dataSource, (bar, i, data) => {
2259
2282
  const a = this.extractor(bar, i, data);
2260
2283
  const b2 = typeof other === "number" ? other : other.extractor(bar, i, data);
2261
- return a === b2 ? 1 : 0;
2284
+ return eq(a, b2) ? 1 : 0;
2262
2285
  });
2263
2286
  }
2264
2287
  /**
@@ -2270,7 +2293,7 @@ var Series = class _Series {
2270
2293
  return new _Series(this.dataSource, (bar, i, data) => {
2271
2294
  const a = this.extractor(bar, i, data);
2272
2295
  const b2 = typeof other === "number" ? other : other.extractor(bar, i, data);
2273
- return a !== b2 ? 1 : 0;
2296
+ return ne(a, b2) ? 1 : 0;
2274
2297
  });
2275
2298
  }
2276
2299
  // ============================================
@@ -2402,8 +2425,8 @@ var Series = class _Series {
2402
2425
  * @returns New Series with computed values and no closure dependencies
2403
2426
  */
2404
2427
  materialize() {
2405
- const values = this.toArray();
2406
- const valuesCopy = [...values];
2428
+ const values2 = this.toArray();
2429
+ const valuesCopy = [...values2];
2407
2430
  return _Series.fromArray(this.dataSource, valuesCopy);
2408
2431
  }
2409
2432
  /**
@@ -2433,16 +2456,16 @@ var Series = class _Series {
2433
2456
  * @returns Value at that index
2434
2457
  */
2435
2458
  get(index) {
2436
- const values = this.toArray();
2437
- return values[index] ?? NaN;
2459
+ const values2 = this.toArray();
2460
+ return values2[index] ?? NaN;
2438
2461
  }
2439
2462
  /**
2440
2463
  * Get the last value (most recent bar)
2441
2464
  * @returns Most recent value
2442
2465
  */
2443
2466
  last() {
2444
- const values = this.toArray();
2445
- return values[values.length - 1] ?? NaN;
2467
+ const values2 = this.toArray();
2468
+ return values2[values2.length - 1] ?? NaN;
2446
2469
  }
2447
2470
  /**
2448
2471
  * Get number of values
@@ -2456,11 +2479,11 @@ var Series = class _Series {
2456
2479
  * @returns Array of { time, value } objects
2457
2480
  */
2458
2481
  toTimeValuePairs() {
2459
- const values = this.toArray();
2482
+ const values2 = this.toArray();
2460
2483
  const bars = this.dataSource.bars;
2461
2484
  return bars.map((bar, i) => ({
2462
2485
  time: bar.time,
2463
- value: values[i]
2486
+ value: values2[i]
2464
2487
  })).filter((point) => !Number.isNaN(point.value));
2465
2488
  }
2466
2489
  };
@@ -2534,60 +2557,60 @@ function round(value, precision) {
2534
2557
  const multiplier = Math.pow(10, precision);
2535
2558
  return Math.round(value * multiplier) / multiplier;
2536
2559
  }
2537
- function max2(...values) {
2538
- const hasSeries = values.some((v) => v instanceof Series);
2560
+ function max2(...values2) {
2561
+ const hasSeries = values2.some((v) => v instanceof Series);
2539
2562
  if (!hasSeries) {
2540
- return Math.max(...values);
2563
+ return Math.max(...values2);
2541
2564
  }
2542
- const firstSeries = values.find((v) => v instanceof Series);
2565
+ const firstSeries = values2.find((v) => v instanceof Series);
2543
2566
  const bars = firstSeries.bars;
2544
2567
  const length2 = bars.length;
2545
- const valueArrays = values.map(
2568
+ const valueArrays = values2.map(
2546
2569
  (v) => v instanceof Series ? v.toArray() : null
2547
2570
  );
2548
2571
  const result = [];
2549
2572
  for (let i = 0; i < length2; i++) {
2550
- const nums = values.map(
2573
+ const nums = values2.map(
2551
2574
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2552
2575
  );
2553
2576
  result.push(Math.max(...nums));
2554
2577
  }
2555
2578
  return Series.fromArray(bars, result);
2556
2579
  }
2557
- function min2(...values) {
2558
- const hasSeries = values.some((v) => v instanceof Series);
2580
+ function min2(...values2) {
2581
+ const hasSeries = values2.some((v) => v instanceof Series);
2559
2582
  if (!hasSeries) {
2560
- return Math.min(...values);
2583
+ return Math.min(...values2);
2561
2584
  }
2562
- const firstSeries = values.find((v) => v instanceof Series);
2585
+ const firstSeries = values2.find((v) => v instanceof Series);
2563
2586
  const bars = firstSeries.bars;
2564
2587
  const length2 = bars.length;
2565
- const valueArrays = values.map(
2588
+ const valueArrays = values2.map(
2566
2589
  (v) => v instanceof Series ? v.toArray() : null
2567
2590
  );
2568
2591
  const result = [];
2569
2592
  for (let i = 0; i < length2; i++) {
2570
- const nums = values.map(
2593
+ const nums = values2.map(
2571
2594
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2572
2595
  );
2573
2596
  result.push(Math.min(...nums));
2574
2597
  }
2575
2598
  return Series.fromArray(bars, result);
2576
2599
  }
2577
- function avg(...values) {
2578
- const hasSeries = values.some((v) => v instanceof Series);
2600
+ function avg(...values2) {
2601
+ const hasSeries = values2.some((v) => v instanceof Series);
2579
2602
  if (!hasSeries) {
2580
- return values.reduce((a, b2) => a + b2, 0) / values.length;
2603
+ return values2.reduce((a, b2) => a + b2, 0) / values2.length;
2581
2604
  }
2582
- const firstSeries = values.find((v) => v instanceof Series);
2605
+ const firstSeries = values2.find((v) => v instanceof Series);
2583
2606
  const bars = firstSeries.bars;
2584
2607
  const length2 = bars.length;
2585
- const valueArrays = values.map(
2608
+ const valueArrays = values2.map(
2586
2609
  (v) => v instanceof Series ? v.toArray() : null
2587
2610
  );
2588
2611
  const result = [];
2589
2612
  for (let i = 0; i < length2; i++) {
2590
- const nums = values.map(
2613
+ const nums = values2.map(
2591
2614
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2592
2615
  );
2593
2616
  const sum4 = nums.reduce((a, b2) => a + b2, 0);
@@ -2821,10 +2844,10 @@ function sign(value) {
2821
2844
  }
2822
2845
  return value > 0 ? 1 : value < 0 ? -1 : 0;
2823
2846
  }
2824
- function round_to_mintick(number, mintick) {
2825
- if (number instanceof Series) {
2826
- const bars = number.bars;
2827
- const valueArray = number.toArray();
2847
+ function round_to_mintick(number2, mintick) {
2848
+ if (number2 instanceof Series) {
2849
+ const bars = number2.bars;
2850
+ const valueArray = number2.toArray();
2828
2851
  const length2 = bars.length;
2829
2852
  if (mintick === void 0) {
2830
2853
  throw new Error(
@@ -2848,7 +2871,7 @@ function round_to_mintick(number, mintick) {
2848
2871
  }
2849
2872
  return Series.fromArray(bars, result);
2850
2873
  }
2851
- if (isNaN(number)) {
2874
+ if (isNaN(number2)) {
2852
2875
  return NaN;
2853
2876
  }
2854
2877
  if (mintick === void 0) {
@@ -2857,9 +2880,9 @@ function round_to_mintick(number, mintick) {
2857
2880
  );
2858
2881
  }
2859
2882
  if (mintick === 0) {
2860
- return number;
2883
+ return number2;
2861
2884
  }
2862
- return Math.round(number / mintick) * mintick;
2885
+ return Math.round(number2 / mintick) * mintick;
2863
2886
  }
2864
2887
  var pi = Math.PI;
2865
2888
  var e = Math.E;
@@ -2925,9 +2948,9 @@ __export(array_exports, {
2925
2948
  unshift: () => unshift,
2926
2949
  variance: () => variance2
2927
2950
  });
2928
- function new_array(size2 = 0, initial_value) {
2951
+ function new_array(size3 = 0, initial_value) {
2929
2952
  const arr = [];
2930
- for (let i = 0; i < size2; i++) {
2953
+ for (let i = 0; i < size3; i++) {
2931
2954
  arr.push(initial_value);
2932
2955
  }
2933
2956
  return arr;
@@ -3001,11 +3024,13 @@ function sum2(id) {
3001
3024
  function avg2(id) {
3002
3025
  return sum2(id) / size(id);
3003
3026
  }
3004
- function min3(id) {
3005
- return Math.min(...id);
3027
+ function min3(id, nth = 0) {
3028
+ const values2 = id.filter((v) => !Number.isNaN(v)).sort((a, b2) => a - b2);
3029
+ return values2.length ? values2[Math.min(nth, values2.length - 1)] : NaN;
3006
3030
  }
3007
- function max3(id) {
3008
- return Math.max(...id);
3031
+ function max3(id, nth = 0) {
3032
+ const values2 = id.filter((v) => !Number.isNaN(v)).sort((a, b2) => b2 - a);
3033
+ return values2.length ? values2[Math.min(nth, values2.length - 1)] : NaN;
3009
3034
  }
3010
3035
  function median2(id) {
3011
3036
  const sorted = [...id].sort((a, b2) => a - b2);
@@ -3026,16 +3051,15 @@ function mode2(id) {
3026
3051
  }
3027
3052
  return mode5;
3028
3053
  }
3029
- function stdev2(id) {
3030
- const mean = avg2(id);
3031
- const squareDiffs = id.map((value) => Math.pow(value - mean, 2));
3032
- const avgSquareDiff = sum2(squareDiffs) / size(id);
3033
- return Math.sqrt(avgSquareDiff);
3054
+ function stdev2(id, biased = true) {
3055
+ return Math.sqrt(variance2(id, biased));
3034
3056
  }
3035
- function variance2(id) {
3036
- const mean = avg2(id);
3037
- const squareDiffs = id.map((value) => Math.pow(value - mean, 2));
3038
- return sum2(squareDiffs) / size(id);
3057
+ function variance2(id, biased = true) {
3058
+ const values2 = id.filter((v) => !Number.isNaN(v));
3059
+ if (!values2.length) return NaN;
3060
+ const mean = values2.reduce((a, b2) => a + b2, 0) / values2.length;
3061
+ const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
3062
+ return squares / (biased ? values2.length : values2.length - 1);
3039
3063
  }
3040
3064
  function fill(id, value, index_from = 0, index_to) {
3041
3065
  const end = index_to ?? id.length;
@@ -3043,8 +3067,8 @@ function fill(id, value, index_from = 0, index_to) {
3043
3067
  id[i] = value;
3044
3068
  }
3045
3069
  }
3046
- function from(id) {
3047
- return copy(id);
3070
+ function from(...values2) {
3071
+ return [...values2];
3048
3072
  }
3049
3073
  function first(id) {
3050
3074
  return id[0];
@@ -3052,38 +3076,38 @@ function first(id) {
3052
3076
  function last(id) {
3053
3077
  return id[id.length - 1];
3054
3078
  }
3055
- function some(id, predicate) {
3056
- return id.some(predicate);
3079
+ function some(id) {
3080
+ return id.some((v) => v === true);
3057
3081
  }
3058
- function every(id, predicate) {
3059
- return id.every(predicate);
3082
+ function every(id) {
3083
+ return id.length > 0 && id.every((v) => v === true);
3060
3084
  }
3061
- function new_bool(size2 = 0, initial_value = false) {
3062
- return new_array(size2, initial_value);
3085
+ function new_bool(size3 = 0, initial_value = false) {
3086
+ return new_array(size3, initial_value);
3063
3087
  }
3064
- function new_float(size2 = 0, initial_value = NaN) {
3065
- return new_array(size2, initial_value);
3088
+ function new_float(size3 = 0, initial_value = NaN) {
3089
+ return new_array(size3, initial_value);
3066
3090
  }
3067
- function new_int(size2 = 0, initial_value = NaN) {
3068
- return new_array(size2, initial_value);
3091
+ function new_int(size3 = 0, initial_value = NaN) {
3092
+ return new_array(size3, initial_value);
3069
3093
  }
3070
- function new_string(size2 = 0, initial_value) {
3071
- return new_array(size2, initial_value);
3094
+ function new_string(size3 = 0, initial_value) {
3095
+ return new_array(size3, initial_value);
3072
3096
  }
3073
- function new_color(size2 = 0, initial_value) {
3074
- return new_array(size2, initial_value);
3097
+ function new_color(size3 = 0, initial_value) {
3098
+ return new_array(size3, initial_value);
3075
3099
  }
3076
- function new_line(size2 = 0, initial_value) {
3077
- return new_array(size2, initial_value);
3100
+ function new_line(size3 = 0, initial_value) {
3101
+ return new_array(size3, initial_value);
3078
3102
  }
3079
- function new_box(size2 = 0, initial_value) {
3080
- return new_array(size2, initial_value);
3103
+ function new_box(size3 = 0, initial_value) {
3104
+ return new_array(size3, initial_value);
3081
3105
  }
3082
- function new_label(size2 = 0, initial_value) {
3083
- return new_array(size2, initial_value);
3106
+ function new_label(size3 = 0, initial_value) {
3107
+ return new_array(size3, initial_value);
3084
3108
  }
3085
- function new_linefill(size2 = 0, initial_value) {
3086
- return new_array(size2, initial_value);
3109
+ function new_linefill(size3 = 0, initial_value) {
3110
+ return new_array(size3, initial_value);
3087
3111
  }
3088
3112
  function abs2(id) {
3089
3113
  return id.map((x) => Math.abs(x));
@@ -3223,8 +3247,70 @@ function standardize(id) {
3223
3247
  }
3224
3248
  return id.map((value) => (value - mean) / stdDev);
3225
3249
  }
3226
- function newtype(size2 = 0, initial_value) {
3227
- return new_array(size2, initial_value);
3250
+ function newtype(size3 = 0, initial_value) {
3251
+ return new_array(size3, initial_value);
3252
+ }
3253
+
3254
+ // src/map/index.ts
3255
+ var map_exports = {};
3256
+ __export(map_exports, {
3257
+ MAX_SIZE: () => MAX_SIZE,
3258
+ clear: () => clear2,
3259
+ contains: () => contains,
3260
+ copy: () => copy2,
3261
+ get: () => get2,
3262
+ keys: () => keys,
3263
+ new_map: () => new_map,
3264
+ put: () => put,
3265
+ put_all: () => put_all,
3266
+ remove: () => remove2,
3267
+ size: () => size2,
3268
+ values: () => values
3269
+ });
3270
+ var MAX_SIZE = 5e4;
3271
+ function tooLarge(size3) {
3272
+ return new RangeError(`A map cannot have more than ${MAX_SIZE} key-value pairs. The current size is ${size3}.`);
3273
+ }
3274
+ function new_map() {
3275
+ return /* @__PURE__ */ new Map();
3276
+ }
3277
+ function put(id, key, value) {
3278
+ const previous = id.get(key);
3279
+ if (!id.has(key) && id.size >= MAX_SIZE) throw tooLarge(id.size + 1);
3280
+ id.set(key, value);
3281
+ return previous;
3282
+ }
3283
+ function put_all(id, id2) {
3284
+ let size3 = id.size;
3285
+ for (const key of id2.keys()) if (!id.has(key)) size3++;
3286
+ if (size3 > MAX_SIZE) throw tooLarge(size3);
3287
+ for (const [key, value] of id2) id.set(key, value);
3288
+ }
3289
+ function get2(id, key) {
3290
+ return id.get(key);
3291
+ }
3292
+ function contains(id, key) {
3293
+ return id.has(key);
3294
+ }
3295
+ function remove2(id, key) {
3296
+ const value = id.get(key);
3297
+ id.delete(key);
3298
+ return value;
3299
+ }
3300
+ function size2(id) {
3301
+ return id.size;
3302
+ }
3303
+ function clear2(id) {
3304
+ id.clear();
3305
+ }
3306
+ function keys(id) {
3307
+ return [...id.keys()];
3308
+ }
3309
+ function values(id) {
3310
+ return [...id.values()];
3311
+ }
3312
+ function copy2(id) {
3313
+ return new Map(id);
3228
3314
  }
3229
3315
 
3230
3316
  // src/str/index.ts
@@ -3232,7 +3318,7 @@ var str_exports = {};
3232
3318
  __export(str_exports, {
3233
3319
  charAt: () => charAt,
3234
3320
  concat: () => concat2,
3235
- contains: () => contains,
3321
+ contains: () => contains2,
3236
3322
  endswith: () => endswith,
3237
3323
  format: () => format,
3238
3324
  format_time: () => format_time,
@@ -3253,15 +3339,486 @@ __export(str_exports, {
3253
3339
  trimRight: () => trimRight,
3254
3340
  upper: () => upper
3255
3341
  });
3342
+
3343
+ // src/str/numberformat.ts
3344
+ var patterns = /* @__PURE__ */ new Map();
3345
+ function parsePattern(pattern) {
3346
+ const cached = patterns.get(pattern);
3347
+ if (cached) return cached;
3348
+ let prefix = "";
3349
+ let suffix = "";
3350
+ let number2 = "";
3351
+ let percent = false;
3352
+ let phase = "prefix";
3353
+ for (let i = 0; i < pattern.length; i++) {
3354
+ const ch = pattern[i];
3355
+ let literal;
3356
+ if (ch === "'") {
3357
+ const end = pattern.indexOf("'", i + 1);
3358
+ if (end === i + 1) {
3359
+ literal = "'";
3360
+ i = end;
3361
+ } else {
3362
+ literal = pattern.slice(i + 1, end === -1 ? void 0 : end);
3363
+ i = end === -1 ? pattern.length : end;
3364
+ }
3365
+ } else if (phase !== "suffix" && ("#0,.".includes(ch) || phase === "number" && ch === "E")) {
3366
+ phase = "number";
3367
+ number2 += ch;
3368
+ continue;
3369
+ } else {
3370
+ if (ch === "%") percent = true;
3371
+ literal = ch;
3372
+ }
3373
+ if (phase === "number") phase = "suffix";
3374
+ if (phase === "prefix") prefix += literal;
3375
+ else suffix += literal;
3376
+ }
3377
+ const [mantissa = "", exp2] = number2.split("E");
3378
+ const [intPart = "", fracPart = ""] = mantissa.split(".");
3379
+ const lastComma = intPart.lastIndexOf(",");
3380
+ const parsed = {
3381
+ prefix,
3382
+ suffix,
3383
+ // as in Java, a pattern with a decimal point and no '0' at all ("#.##") shows one integer digit
3384
+ minInt: !mantissa.includes("0") && mantissa.includes(".") ? 1 : [...intPart].filter((c) => c === "0").length,
3385
+ minFrac: [...fracPart].filter((c) => c === "0").length,
3386
+ maxFrac: [...fracPart].filter((c) => c === "0" || c === "#").length,
3387
+ grouping: lastComma === -1 ? 0 : intPart.length - lastComma - 1,
3388
+ percent,
3389
+ exponent: exp2 === void 0 ? null : exp2.length,
3390
+ hasDigits: /[0#]/.test(mantissa)
3391
+ };
3392
+ patterns.set(pattern, parsed);
3393
+ return parsed;
3394
+ }
3395
+ function shortestDigits(x) {
3396
+ const m = /^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(Math.abs(x)));
3397
+ const all7 = m[1] + (m[2] ?? "");
3398
+ let intLen = m[1].length + Number(m[3] ?? 0);
3399
+ const lead = all7.length - all7.replace(/^0+/, "").length;
3400
+ intLen -= lead;
3401
+ const digits = all7.slice(lead).replace(/0+$/, "");
3402
+ return { digits, intLen: digits ? intLen : 0 };
3403
+ }
3404
+ function exactDigits(x) {
3405
+ const abs3 = Math.abs(x);
3406
+ if (abs3 === 0) return { digits: "", intLen: 0 };
3407
+ const view = new DataView(new ArrayBuffer(8));
3408
+ view.setFloat64(0, abs3);
3409
+ const bits = view.getBigUint64(0);
3410
+ const expBits = Number(bits >> 52n & 0x7ffn);
3411
+ let mant = bits & 0xfffffffffffffn;
3412
+ const e2 = expBits === 0 ? -1074 : expBits - 1075;
3413
+ if (expBits !== 0) mant |= 1n << 52n;
3414
+ let str;
3415
+ let fracDigits;
3416
+ if (e2 >= 0) {
3417
+ str = (mant << BigInt(e2)).toString();
3418
+ fracDigits = 0;
3419
+ } else {
3420
+ str = (mant * 5n ** BigInt(-e2)).toString();
3421
+ fracDigits = -e2;
3422
+ }
3423
+ const intLen = str.length - fracDigits;
3424
+ const lead = str.length - str.replace(/^0+/, "").length;
3425
+ const digits = str.slice(lead).replace(/0+$/, "");
3426
+ return { digits, intLen: intLen - lead };
3427
+ }
3428
+ function roundDigits(d, frac, mode5) {
3429
+ const keep = d.intLen + frac;
3430
+ if (keep >= d.digits.length) return d;
3431
+ if (keep < 0) return { digits: "", intLen: 0 };
3432
+ const first2 = d.digits.charCodeAt(keep) - 48;
3433
+ let up;
3434
+ if (mode5 === "halfUpShortest") up = first2 >= 5;
3435
+ else if (first2 !== 5) up = first2 > 5;
3436
+ else if (d.digits.length > keep + 1) up = true;
3437
+ else up = keep > 0 && (d.digits.charCodeAt(keep - 1) - 48) % 2 === 1;
3438
+ let kept = d.digits.slice(0, keep);
3439
+ let intLen = d.intLen;
3440
+ if (up) {
3441
+ const n = (BigInt(kept || "0") + 1n).toString();
3442
+ if (n.length > kept.length) intLen += 1;
3443
+ kept = n;
3444
+ }
3445
+ kept = kept.replace(/0+$/, "");
3446
+ return { digits: kept, intLen: kept ? intLen : 0 };
3447
+ }
3448
+ function group(int, size3) {
3449
+ if (!size3 || int.length <= size3) return int;
3450
+ const parts = [];
3451
+ for (let end = int.length; end > 0; end -= size3) parts.unshift(int.slice(Math.max(0, end - size3), end));
3452
+ return parts.join(",");
3453
+ }
3454
+ function layout(d, p) {
3455
+ let int = d.intLen > 0 ? d.digits.slice(0, d.intLen).padEnd(d.intLen, "0") : "";
3456
+ int = int.replace(/^0+/, "").padStart(p.minInt, "0");
3457
+ let frac = d.intLen < 0 ? "0".repeat(-d.intLen) + d.digits : d.digits.slice(Math.max(0, d.intLen));
3458
+ frac = frac.slice(0, p.maxFrac).replace(/0+$/, "").padEnd(p.minFrac, "0");
3459
+ if (!int && !frac) int = "0";
3460
+ return group(int, p.grouping) + (frac ? "." + frac : "");
3461
+ }
3462
+ function formatNumber(value, pattern, mode5) {
3463
+ if (Number.isNaN(value)) return "NaN";
3464
+ const p = parsePattern(pattern);
3465
+ if (!Number.isFinite(value)) return (value < 0 ? "-" : "") + p.prefix + "\u221E" + p.suffix;
3466
+ const x = p.percent ? value * 100 : value;
3467
+ const toDigits = mode5 === "halfUpShortest" ? shortestDigits : exactDigits;
3468
+ let body;
3469
+ let isZero;
3470
+ if (p.exponent !== null) {
3471
+ const rounded = roundDigits(toDigits(x), p.maxFrac, mode5);
3472
+ const intDigits = Math.max(p.minInt, 1);
3473
+ isZero = rounded.digits === "";
3474
+ let exponent = isZero ? 0 : rounded.intLen - intDigits;
3475
+ let mant = roundDigits({ digits: rounded.digits, intLen: isZero ? 0 : intDigits }, p.maxFrac, mode5);
3476
+ if (mant.intLen > intDigits) {
3477
+ exponent += 1;
3478
+ mant = { digits: mant.digits, intLen: intDigits };
3479
+ }
3480
+ const e2 = String(Math.abs(exponent)).padStart(p.exponent, "0");
3481
+ body = layout(mant, p) + "E" + (exponent < 0 ? "-" : "") + e2;
3482
+ } else {
3483
+ const rounded = roundDigits(toDigits(x), p.hasDigits ? p.maxFrac : 0, mode5);
3484
+ isZero = rounded.digits === "";
3485
+ body = p.hasDigits ? layout(rounded, p) : layout(rounded, { ...p, minInt: 0, maxFrac: 0, minFrac: 0 });
3486
+ }
3487
+ const negative = x < 0 && (!isZero || !p.hasDigits);
3488
+ return (negative ? "-" : "") + p.prefix + body + p.suffix;
3489
+ }
3490
+
3491
+ // src/time/timezone.ts
3492
+ var MS_PER_SECOND = 1e3;
3493
+ var MS_PER_DAY = 864e5;
3494
+ var MAX_OFFSET_SECONDS = 18 * 3600;
3495
+ var OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\d{1,2})(?::?(\d{2})(?::?(\d{2}))?)?)?$/;
3496
+ var REJECTED_NAMES = /* @__PURE__ */ new Set(["EST", "MST", "HST"]);
3497
+ var canonicalNames;
3498
+ function hasTimeZoneCase(name) {
3499
+ if (name.split("/").some((segment) => !/^[A-Z]/.test(segment))) return false;
3500
+ canonicalNames ??= new Map(Intl.supportedValuesOf("timeZone").map((n) => [n.toLowerCase(), n]));
3501
+ const canonical = canonicalNames.get(name.toLowerCase());
3502
+ return canonical === void 0 || canonical === name;
3503
+ }
3504
+ var zones = /* @__PURE__ */ new Map();
3505
+ function resolveZone(timezone) {
3506
+ let zone = zones.get(timezone);
3507
+ if (zone) return zone;
3508
+ const invalid = () => new RangeError(
3509
+ `Invalid time zone "${timezone}": use UTC/GMT offset notation ("UTC-5", "GMT+0530") or an IANA name ("America/New_York")`
3510
+ );
3511
+ const m = OFFSET_NOTATION.exec(timezone);
3512
+ if (m) {
3513
+ const [, sign2, h = "0", mi = "0", s] = m;
3514
+ const minutes = Number(mi);
3515
+ const seconds = s === void 0 ? 0 : Number(s);
3516
+ if (minutes > 59 || seconds > 59 || s !== void 0 && h.length !== 2) throw invalid();
3517
+ const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;
3518
+ if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();
3519
+ zone = { kind: "fixed", offsetMs: (sign2 === "-" ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };
3520
+ } else {
3521
+ if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();
3522
+ let format2;
3523
+ try {
3524
+ format2 = new Intl.DateTimeFormat("en-US", {
3525
+ timeZone: timezone,
3526
+ hourCycle: "h23",
3527
+ year: "numeric",
3528
+ month: "numeric",
3529
+ day: "numeric",
3530
+ hour: "numeric",
3531
+ minute: "numeric",
3532
+ second: "numeric"
3533
+ });
3534
+ } catch {
3535
+ throw invalid();
3536
+ }
3537
+ zone = { kind: "iana", format: format2 };
3538
+ }
3539
+ zones.set(timezone, zone);
3540
+ return zone;
3541
+ }
3542
+ function offsetAt(zone, time) {
3543
+ if (zone.kind === "fixed") return zone.offsetMs;
3544
+ const wholeSecond = Math.floor(time / 1e3) * 1e3;
3545
+ const f = {};
3546
+ for (const part of zone.format.formatToParts(wholeSecond)) {
3547
+ if (part.type !== "literal") f[part.type] = Number(part.value);
3548
+ }
3549
+ const local = Date.UTC(f.year, f.month - 1, f.day, f.hour, f.minute, f.second);
3550
+ return local - wholeSecond;
3551
+ }
3552
+ function zoneOffset(time, timezone) {
3553
+ return offsetAt(resolveZone(timezone), time);
3554
+ }
3555
+ function zonedFields(time, timezone) {
3556
+ const local = new Date(time + offsetAt(resolveZone(timezone), time));
3557
+ return {
3558
+ year: local.getUTCFullYear(),
3559
+ month: local.getUTCMonth() + 1,
3560
+ day: local.getUTCDate(),
3561
+ hour: local.getUTCHours(),
3562
+ minute: local.getUTCMinutes(),
3563
+ second: local.getUTCSeconds(),
3564
+ dayOfWeek: local.getUTCDay() + 1
3565
+ };
3566
+ }
3567
+ function zonedToUnix(timezone, year2, month2, day, hour2 = 0, minute2 = 0, second2 = 0) {
3568
+ const zone = resolveZone(timezone);
3569
+ const local = Date.UTC(year2, month2 - 1, day, hour2, minute2, second2);
3570
+ if (zone.kind === "fixed") return local - zone.offsetMs;
3571
+ const before = offsetAt(zone, local - MS_PER_DAY);
3572
+ const after = offsetAt(zone, local + MS_PER_DAY);
3573
+ const candidates = [local - before, local - after].filter((t2) => local - offsetAt(zone, t2) === t2);
3574
+ if (candidates.length) return Math.max(...candidates);
3575
+ return local - before;
3576
+ }
3577
+
3578
+ // src/str/dateformat.ts
3579
+ var MONTHS = [
3580
+ "January",
3581
+ "February",
3582
+ "March",
3583
+ "April",
3584
+ "May",
3585
+ "June",
3586
+ "July",
3587
+ "August",
3588
+ "September",
3589
+ "October",
3590
+ "November",
3591
+ "December"
3592
+ ];
3593
+ var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
3594
+ var pad = (n, width) => String(n).padStart(width, "0");
3595
+ function zoneName(time, timezone, offsetMs) {
3596
+ if (timezone === "Etc/UTC") return "UTC";
3597
+ if (/^(UTC|GMT)/.test(timezone)) {
3598
+ if (offsetMs === 0) return "GMT";
3599
+ const minutes = Math.abs(offsetMs) / 6e4;
3600
+ return `GMT${offsetMs < 0 ? "-" : "+"}${pad(Math.floor(minutes / 60), 2)}:${pad(minutes % 60, 2)}`;
3601
+ }
3602
+ const part = new Intl.DateTimeFormat("en-US", { timeZone: timezone, timeZoneName: "short" }).formatToParts(time).find((p) => p.type === "timeZoneName");
3603
+ return part?.value ?? timezone;
3604
+ }
3605
+ function weekOfYear(year2, month2, day) {
3606
+ const date = Date.UTC(year2, month2 - 1, day);
3607
+ const dow = new Date(date).getUTCDay();
3608
+ const weekStart = date - dow * 864e5;
3609
+ if (weekStart + 6 * 864e5 >= Date.UTC(year2 + 1, 0, 1)) return 1;
3610
+ const jan1 = Date.UTC(year2, 0, 1);
3611
+ const jan1Dow = new Date(jan1).getUTCDay();
3612
+ return Math.floor((date - jan1 + jan1Dow * 864e5) / (7 * 864e5)) + 1;
3613
+ }
3614
+ function formatDate(time, pattern, timezone) {
3615
+ if (Number.isNaN(time)) return "NaN";
3616
+ const f = zonedFields(time, timezone);
3617
+ const offset = zoneOffset(time, timezone);
3618
+ const ms = (time % 1e3 + 1e3) % 1e3;
3619
+ const dayOfYear = (Date.UTC(f.year, f.month - 1, f.day) - Date.UTC(f.year, 0, 1)) / 864e5 + 1;
3620
+ let out = "";
3621
+ for (let i = 0; i < pattern.length; ) {
3622
+ const ch = pattern[i];
3623
+ if (ch === "'") {
3624
+ const end = pattern.indexOf("'", i + 1);
3625
+ if (end === i + 1) {
3626
+ out += "'";
3627
+ i += 2;
3628
+ } else {
3629
+ out += pattern.slice(i + 1, end === -1 ? void 0 : end);
3630
+ i = end === -1 ? pattern.length : end + 1;
3631
+ }
3632
+ continue;
3633
+ }
3634
+ if (!/[A-Za-z]/.test(ch)) {
3635
+ out += ch;
3636
+ i++;
3637
+ continue;
3638
+ }
3639
+ let n = 1;
3640
+ while (pattern[i + n] === ch) n++;
3641
+ i += n;
3642
+ const hour12 = f.hour % 12;
3643
+ switch (ch) {
3644
+ case "y":
3645
+ out += n === 2 ? pad(f.year % 100, 2) : pad(f.year, n);
3646
+ break;
3647
+ case "M":
3648
+ out += n >= 4 ? MONTHS[f.month - 1] : n === 3 ? MONTHS[f.month - 1].slice(0, 3) : pad(f.month, n);
3649
+ break;
3650
+ case "d":
3651
+ out += pad(f.day, n);
3652
+ break;
3653
+ case "E":
3654
+ out += n >= 4 ? DAYS[f.dayOfWeek - 1] : DAYS[f.dayOfWeek - 1].slice(0, 3);
3655
+ break;
3656
+ case "u":
3657
+ out += pad(f.dayOfWeek === 1 ? 7 : f.dayOfWeek - 1, n);
3658
+ break;
3659
+ case "D":
3660
+ out += pad(dayOfYear, n);
3661
+ break;
3662
+ case "w":
3663
+ out += pad(weekOfYear(f.year, f.month, f.day), n);
3664
+ break;
3665
+ case "H":
3666
+ out += pad(f.hour, n);
3667
+ break;
3668
+ case "k":
3669
+ out += pad(f.hour === 0 ? 24 : f.hour, n);
3670
+ break;
3671
+ case "K":
3672
+ out += pad(hour12, n);
3673
+ break;
3674
+ case "h":
3675
+ out += pad(hour12 === 0 ? 12 : hour12, n);
3676
+ break;
3677
+ case "a":
3678
+ out += f.hour < 12 ? "AM" : "PM";
3679
+ break;
3680
+ case "m":
3681
+ out += pad(f.minute, n);
3682
+ break;
3683
+ case "s":
3684
+ out += pad(f.second, n);
3685
+ break;
3686
+ case "S":
3687
+ out += pad(ms, n);
3688
+ break;
3689
+ case "Z": {
3690
+ const minutes = Math.abs(offset) / 6e4;
3691
+ out += (offset < 0 ? "-" : "+") + pad(Math.floor(minutes / 60), 2) + pad(minutes % 60, 2);
3692
+ break;
3693
+ }
3694
+ case "z":
3695
+ out += zoneName(time, timezone, offset);
3696
+ break;
3697
+ default:
3698
+ throw new SyntaxError(`Unsupported date pattern letter "${ch}" in "${pattern}"`);
3699
+ }
3700
+ }
3701
+ return out;
3702
+ }
3703
+
3704
+ // src/str/messageformat.ts
3705
+ var DATE_STYLES = {
3706
+ short: "M/d/yy",
3707
+ medium: "MMM d, yyyy",
3708
+ long: "MMMM d, yyyy",
3709
+ full: "EEEE, MMMM d, yyyy"
3710
+ };
3711
+ var TIME_STYLES = {
3712
+ short: "h:mm\u202Fa",
3713
+ medium: "h:mm:ss\u202Fa",
3714
+ long: "h:mm:ss\u202Fa z",
3715
+ full: "h:mm:ss\u202Fa z"
3716
+ };
3717
+ function number(value, pattern) {
3718
+ return typeof value === "number" ? formatNumber(value, pattern, "halfEvenExact") : String(value);
3719
+ }
3720
+ function choice(value, spec) {
3721
+ const options = spec.split("|").map((part) => {
3722
+ const m = /^\s*(-?[\d.]+|-?∞)\s*([#<≤])(.*)$/.exec(part);
3723
+ if (!m) throw new SyntaxError(`Invalid choice format "${spec}"`);
3724
+ const limit = m[1].includes("\u221E") ? m[1].startsWith("-") ? -Infinity : Infinity : Number(m[1]);
3725
+ return { limit: m[2] === "<" ? limit + Number.EPSILON * Math.max(1, Math.abs(limit)) : limit, text: m[3] };
3726
+ });
3727
+ let chosen = options[0];
3728
+ for (const o of options) if (value >= o.limit) chosen = o;
3729
+ return chosen.text;
3730
+ }
3731
+ function formatArgument(value, type, style, timezone) {
3732
+ if (value === void 0) return "";
3733
+ if (!type) return typeof value === "number" ? number(value, "#,##0.###") : String(value);
3734
+ switch (type.trim()) {
3735
+ case "number": {
3736
+ const s = style?.trim();
3737
+ if (!s) return number(value, "#,##0.###");
3738
+ if (s === "integer") return number(value, "#,##0");
3739
+ if (s === "percent") return number(value, "#,##0%");
3740
+ if (s === "currency") return number(value, "'$'#,##0.00");
3741
+ return number(value, style);
3742
+ }
3743
+ case "date":
3744
+ case "time": {
3745
+ const styles = type.trim() === "date" ? DATE_STYLES : TIME_STYLES;
3746
+ const s = style?.trim() ?? "medium";
3747
+ return formatDate(Number(value), styles[s] ?? style, typeof timezone === "function" ? timezone() : timezone);
3748
+ }
3749
+ case "choice":
3750
+ return choice(Number(value), style ?? "");
3751
+ default:
3752
+ throw new SyntaxError(`Unknown format type "${type}"`);
3753
+ }
3754
+ }
3755
+ function formatMessage(pattern, args, timezone) {
3756
+ let out = "";
3757
+ for (let i = 0; i < pattern.length; ) {
3758
+ const ch = pattern[i];
3759
+ if (ch === "'") {
3760
+ if (pattern[i + 1] === "'") {
3761
+ out += "'";
3762
+ i += 2;
3763
+ continue;
3764
+ }
3765
+ const end = pattern.indexOf("'", i + 1);
3766
+ out += pattern.slice(i + 1, end === -1 ? void 0 : end);
3767
+ i = end === -1 ? pattern.length : end + 1;
3768
+ continue;
3769
+ }
3770
+ if (ch !== "{") {
3771
+ out += ch;
3772
+ i++;
3773
+ continue;
3774
+ }
3775
+ let depth = 1;
3776
+ let j = i + 1;
3777
+ let inQuote = false;
3778
+ for (; j < pattern.length && depth > 0; j++) {
3779
+ const c = pattern[j];
3780
+ if (c === "'") inQuote = !inQuote;
3781
+ else if (!inQuote && c === "{") depth++;
3782
+ else if (!inQuote && c === "}") depth--;
3783
+ }
3784
+ const inner = pattern.slice(i + 1, j - 1);
3785
+ const [index = "", type, ...rest] = inner.split(",");
3786
+ const style = rest.length ? rest.join(",") : void 0;
3787
+ const n = Number(index.trim());
3788
+ out += n < args.length ? formatArgument(args[n], type, style, timezone) : `{${inner}}`;
3789
+ i = j;
3790
+ }
3791
+ return out;
3792
+ }
3793
+
3794
+ // src/str/index.ts
3256
3795
  function length(str) {
3257
3796
  return str.length;
3258
3797
  }
3259
3798
  function tostring(value, format2) {
3260
- if (typeof value === "number" && format2) {
3261
- const decimals = format2.split(".")[1]?.length || 0;
3262
- return value.toFixed(decimals);
3799
+ if (typeof value !== "number") return String(value);
3800
+ if (!Number.isFinite(value)) return String(value);
3801
+ if (format2 === void 0 || format2 === "") {
3802
+ if (Math.abs(value) >= 1e21 && Number.isFinite(value)) {
3803
+ return String(value).replace("e+", "E").replace(/\.0+E/, "E");
3804
+ }
3805
+ return formatNumber(value, "#.##########", "halfUpShortest");
3806
+ }
3807
+ switch (format2) {
3808
+ case "percent":
3809
+ return formatNumber(value, "0.00", "halfUpShortest") + "%";
3810
+ case "volume": {
3811
+ const abs3 = Math.abs(value);
3812
+ for (const [size3, unit] of [[1e12, "T"], [1e9, "B"], [1e6, "M"], [1e3, "K"]]) {
3813
+ if (abs3 >= size3) return formatNumber(value / size3, "#.###", "halfUpShortest") + unit;
3814
+ }
3815
+ return formatNumber(value, "#", "halfUpShortest");
3816
+ }
3817
+ case "mintick":
3818
+ throw new Error("str.tostring(x, format.mintick) needs the symbol tick size (syminfo.mintick), which is not known here");
3819
+ default:
3820
+ return formatNumber(value, format2, "halfUpShortest");
3263
3821
  }
3264
- return String(value);
3265
3822
  }
3266
3823
  function tonumber(str) {
3267
3824
  const num = parseFloat(str);
@@ -3276,7 +3833,7 @@ function upper(str) {
3276
3833
  function lower(str) {
3277
3834
  return str.toLowerCase();
3278
3835
  }
3279
- function contains(source, str) {
3836
+ function contains2(source, str) {
3280
3837
  return source.includes(str);
3281
3838
  }
3282
3839
  function pos(source, str) {
@@ -3299,11 +3856,7 @@ function concat2(...strings) {
3299
3856
  return strings.join("");
3300
3857
  }
3301
3858
  function format(formatStr, ...args) {
3302
- let result = formatStr;
3303
- args.forEach((arg, index) => {
3304
- result = result.replaceAll(`{${index}}`, String(arg));
3305
- });
3306
- return result;
3859
+ return formatMessage(formatStr, args, "Etc/UTC");
3307
3860
  }
3308
3861
  function startswith(source, str) {
3309
3862
  return source.startsWith(str);
@@ -3331,84 +3884,8 @@ function repeat(source, count, separator = "") {
3331
3884
  if (count <= 0) return "";
3332
3885
  return Array(count).fill(source).join(separator);
3333
3886
  }
3334
- function format_time(time, format2) {
3335
- const date = new Date(time);
3336
- const monthNames = [
3337
- "January",
3338
- "February",
3339
- "March",
3340
- "April",
3341
- "May",
3342
- "June",
3343
- "July",
3344
- "August",
3345
- "September",
3346
- "October",
3347
- "November",
3348
- "December"
3349
- ];
3350
- const monthNamesShort = [
3351
- "Jan",
3352
- "Feb",
3353
- "Mar",
3354
- "Apr",
3355
- "May",
3356
- "Jun",
3357
- "Jul",
3358
- "Aug",
3359
- "Sep",
3360
- "Oct",
3361
- "Nov",
3362
- "Dec"
3363
- ];
3364
- const year = date.getUTCFullYear();
3365
- const month = date.getUTCMonth();
3366
- const day = date.getUTCDate();
3367
- const hours = date.getUTCHours();
3368
- const minutes = date.getUTCMinutes();
3369
- const seconds = date.getUTCSeconds();
3370
- const pad = (num, len = 2) => num.toString().padStart(len, "0");
3371
- const hours12 = hours % 12 || 12;
3372
- const ampm = hours < 12 ? "AM" : "PM";
3373
- const replacements = [
3374
- // Year (process yyyy before yy)
3375
- [/yyyy/g, year.toString()],
3376
- [/yy/g, year.toString().slice(-2)],
3377
- // Month (process MMMM before MMM before MM before M)
3378
- [/MMMM/g, monthNames[month]],
3379
- [/MMM/g, monthNamesShort[month]],
3380
- [/MM/g, pad(month + 1)],
3381
- [/M/g, (month + 1).toString()],
3382
- // Day (process dd before d)
3383
- [/dd/g, pad(day)],
3384
- [/d/g, day.toString()],
3385
- // Hours 24-hour (process HH before H)
3386
- [/HH/g, pad(hours)],
3387
- [/H/g, hours.toString()],
3388
- // Hours 12-hour (process hh before h)
3389
- [/hh/g, pad(hours12)],
3390
- [/h/g, hours12.toString()],
3391
- // Minutes (process mm before m)
3392
- [/mm/g, pad(minutes)],
3393
- [/m/g, minutes.toString()],
3394
- // Seconds (process ss before s)
3395
- [/ss/g, pad(seconds)],
3396
- [/s/g, seconds.toString()],
3397
- // AM/PM
3398
- [/a/g, ampm]
3399
- ];
3400
- let result = format2;
3401
- const tokens = [];
3402
- replacements.forEach(([pattern, value], index) => {
3403
- const token = `\uFFF0${index}\uFFF1`;
3404
- result = result.replace(pattern, token);
3405
- tokens[index] = value;
3406
- });
3407
- tokens.forEach((value, index) => {
3408
- const token = `\uFFF0${index}\uFFF1`;
3409
- result = result.replaceAll(token, value);
3410
- });
3411
- return result;
3887
+ function format_time(time, format2 = "yyyy-MM-dd'T'HH:mm:ssZ", timezone = "Etc/UTC") {
3888
+ return formatDate(time, format2, timezone);
3412
3889
  }
3413
3890
 
3414
3891
  // src/color/index.ts
@@ -3476,6 +3953,13 @@ function t(clr) {
3476
3953
  }
3477
3954
  function parseColor(clr) {
3478
3955
  if (typeof clr === "string") {
3956
+ const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(clr.trim());
3957
+ if (hex) {
3958
+ let digits = hex[1];
3959
+ if (digits.length <= 4) digits = [...digits].map((c) => c + c).join("");
3960
+ const byte = (k) => parseInt(digits.slice(k, k + 2), 16);
3961
+ return { r: byte(0), g: byte(2), b: byte(4), t: digits.length === 8 ? (1 - byte(6) / 255) * 100 : 0 };
3962
+ }
3479
3963
  const match2 = clr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
3480
3964
  if (match2) {
3481
3965
  return {
@@ -3488,34 +3972,34 @@ function parseColor(clr) {
3488
3972
  }
3489
3973
  return { r: 0, g: 0, b: 0, t: 0 };
3490
3974
  }
3491
- var aqua = "#00FFFF";
3492
- var black = "#000000";
3493
- var blue = "#0000FF";
3494
- var fuchsia = "#FF00FF";
3495
- var gray = "#808080";
3496
- var green = "#00FF00";
3497
- var lime = "#00FF00";
3498
- var maroon = "#800000";
3499
- var navy = "#000080";
3975
+ var aqua = "#00BCD4";
3976
+ var black = "#363A45";
3977
+ var blue = "#2962FF";
3978
+ var fuchsia = "#E040FB";
3979
+ var gray = "#787B86";
3980
+ var green = "#4CAF50";
3981
+ var lime = "#00E676";
3982
+ var maroon = "#880E4F";
3983
+ var navy = "#311B92";
3500
3984
  var olive = "#808000";
3501
- var orange = "#FFA500";
3502
- var purple = "#800080";
3503
- var red = "#FF0000";
3504
- var silver = "#C0C0C0";
3505
- var teal = "#008080";
3985
+ var orange = "#FF9800";
3986
+ var purple = "#9C27B0";
3987
+ var red = "#F23645";
3988
+ var silver = "#B2B5BE";
3989
+ var teal = "#089981";
3506
3990
  var white = "#FFFFFF";
3507
- var yellow = "#FFFF00";
3991
+ var yellow = "#FDD835";
3508
3992
  function from_gradient(value, bottom_value, top_value, bottom_color, top_color) {
3509
- const parseColor2 = (col2) => {
3510
- if (typeof col2 === "string") {
3511
- if (col2.startsWith("#")) {
3512
- const hex = col2.slice(1);
3993
+ const parseColor2 = (col3) => {
3994
+ if (typeof col3 === "string") {
3995
+ if (col3.startsWith("#")) {
3996
+ const hex = col3.slice(1);
3513
3997
  const r4 = parseInt(hex.slice(0, 2), 16);
3514
3998
  const g4 = parseInt(hex.slice(2, 4), 16);
3515
3999
  const b4 = parseInt(hex.slice(4, 6), 16);
3516
4000
  return [r4, g4, b4, 1];
3517
4001
  }
3518
- const match2 = col2.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
4002
+ const match2 = col3.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
3519
4003
  if (match2) {
3520
4004
  return [
3521
4005
  parseInt(match2[1]),
@@ -3550,21 +4034,260 @@ function from_gradient(value, bottom_value, top_value, bottom_color, top_color)
3550
4034
  // src/time/index.ts
3551
4035
  var time_exports = {};
3552
4036
  __export(time_exports, {
4037
+ dayofmonth: () => dayofmonth,
4038
+ dayofweek: () => dayofweek,
4039
+ hour: () => hour,
4040
+ inSession: () => inSession2,
4041
+ minute: () => minute,
4042
+ month: () => month,
3553
4043
  now: () => now,
3554
- timestamp: () => timestamp
4044
+ second: () => second,
4045
+ timestamp: () => timestamp,
4046
+ weekofyear: () => weekofyear,
4047
+ year: () => year
3555
4048
  });
4049
+
4050
+ // src/time/datestring.ts
4051
+ var MONTHS2 = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
4052
+ var FULL_MONTHS = [
4053
+ "january",
4054
+ "february",
4055
+ "march",
4056
+ "april",
4057
+ "may",
4058
+ "june",
4059
+ "july",
4060
+ "august",
4061
+ "september",
4062
+ "october",
4063
+ "november",
4064
+ "december"
4065
+ ];
4066
+ var ZONE_NAMES = {
4067
+ ut: 0,
4068
+ utc: 0,
4069
+ gmt: 0,
4070
+ est: -5,
4071
+ edt: -4,
4072
+ cst: -6,
4073
+ cdt: -5,
4074
+ mst: -7,
4075
+ mdt: -6,
4076
+ pst: -8,
4077
+ pdt: -7
4078
+ };
4079
+ var TIME = String.raw`(\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3})\d*)?)?`;
4080
+ var ZONE = String.raw`(ut|utc|gmt|[ecmp][sd]t|(?:utc|gmt)?\s*[+-]\d{1,2}(?::?\d{2})?)`;
4081
+ var NUMERIC_ZONE = String.raw`([+-]\d{2}(?::?\d{2})?)`;
4082
+ var DATE = String.raw`(\d{4})([-/])(\d{1,2})\2(\d{1,2})`;
4083
+ var WEEKDAY = String.raw`(?:[a-z]{3,9},?\s+)?`;
4084
+ var ISO_T = new RegExp(String.raw`^${DATE}t${TIME}\s*${NUMERIC_ZONE}?$`, "i");
4085
+ var ISO = new RegExp(String.raw`^${DATE}(?:\s+${TIME})?\s*${ZONE}?$`, "i");
4086
+ var DAY_FIRST = new RegExp(String.raw`^${WEEKDAY}(\d{1,2})(?:\s+|-)([a-z]+)\.?,?(?:\s+|-)(\d{4})(?:,?\s+${TIME})?\s*${ZONE}?$`, "i");
4087
+ var MONTH_FIRST = new RegExp(String.raw`^${WEEKDAY}([a-z]+)\.?\s+(\d{1,2}),?\s+(\d{4})(?:,?\s+${TIME})?\s*${ZONE}?$`, "i");
4088
+ function monthNumber(name) {
4089
+ const lower2 = name.toLowerCase();
4090
+ const i = FULL_MONTHS.findIndex((full, k) => lower2.startsWith(MONTHS2[k]) && full.startsWith(lower2));
4091
+ return i + 1;
4092
+ }
4093
+ function zoneMinutes(zone) {
4094
+ if (!zone) return 0;
4095
+ const lower2 = zone.toLowerCase().replace(/\s+/g, "");
4096
+ const named = ZONE_NAMES[lower2];
4097
+ if (named !== void 0) return named * 60;
4098
+ const m = /^(?:utc|gmt)?([+-])(\d{1,2})(?::?(\d{2}))?$/.exec(lower2);
4099
+ if (!m) return NaN;
4100
+ const minutes = Number(m[2]) * 60 + (m[3] ? Number(m[3]) : 0);
4101
+ return m[1] === "-" ? -minutes : minutes;
4102
+ }
4103
+ function parseDateString(dateString) {
4104
+ const text = dateString.trim();
4105
+ let year2, month2, day;
4106
+ let rest;
4107
+ let m;
4108
+ if (m = ISO_T.exec(text) ?? ISO.exec(text)) {
4109
+ [year2, month2, day] = [m[1], Number(m[3]), m[4]];
4110
+ rest = m.slice(5);
4111
+ } else if (m = DAY_FIRST.exec(text)) {
4112
+ [day, month2, year2] = [m[1], monthNumber(m[2]), m[3]];
4113
+ rest = m.slice(4);
4114
+ } else if (m = MONTH_FIRST.exec(text)) {
4115
+ [month2, day, year2] = [monthNumber(m[1]), m[2], m[3]];
4116
+ rest = m.slice(4);
4117
+ } else {
4118
+ throw new SyntaxError(`Invalid date string "${dateString}": use RFC 2822 or ISO 8601 ("20 Feb 2020", "2020-02-20T14:48:00")`);
4119
+ }
4120
+ const [hour2 = "0", minute2 = "0", second2 = "0", millis = "0", zone] = rest;
4121
+ const d = Number(day);
4122
+ const h = Number(hour2);
4123
+ const mi = Number(minute2);
4124
+ const s = Number(second2);
4125
+ const offset = zoneMinutes(zone);
4126
+ const endOfDay = h === 24 && mi === 0 && s === 0 && Number(millis) === 0;
4127
+ if (month2 < 1 || month2 > 12 || d < 1 || d > 31 || h > 23 && !endOfDay || mi > 59 || s > 59 || Number.isNaN(offset)) {
4128
+ throw new SyntaxError(`Invalid date string "${dateString}": a field is out of range`);
4129
+ }
4130
+ const ms = Number(millis.padEnd(3, "0"));
4131
+ return Date.UTC(Number(year2), month2 - 1, d, h, mi, s, ms) - offset * 6e4;
4132
+ }
4133
+
4134
+ // src/time/session.ts
4135
+ var PERIOD = /^(\d{2})(\d{2})-(\d{2})(\d{2})$/;
4136
+ var sessions = /* @__PURE__ */ new Map();
4137
+ function parseSession(session) {
4138
+ let parsed = sessions.get(session);
4139
+ if (parsed) return parsed;
4140
+ const invalid = () => new SyntaxError(`Invalid session "${session}": expected "HHmm-HHmm[,HHmm-HHmm...][:days]"`);
4141
+ const text = session.trim() === "24x7" ? "0000-0000" : session.replace(/\s+/g, "");
4142
+ const [periodText = "", dayText, extra] = text.split(":");
4143
+ if (extra !== void 0 || periodText === "") throw invalid();
4144
+ const periods = periodText.split(",").map((p) => {
4145
+ const m = PERIOD.exec(p);
4146
+ if (!m) throw invalid();
4147
+ const [h1, m1, h2, m2] = [m[1], m[2], m[3], m[4]].map(Number);
4148
+ if (h1 > 23 || h2 > 23 || m1 > 59 || m2 > 59) throw invalid();
4149
+ return { start: h1 * 60 + m1, end: h2 * 60 + m2 };
4150
+ });
4151
+ const dayDigits = dayText ?? (periods.length > 1 ? "23456" : "1234567");
4152
+ if (!/^[1-7]+$/.test(dayDigits)) throw invalid();
4153
+ const days = new Array(8).fill(false);
4154
+ for (const d of dayDigits) days[Number(d)] = true;
4155
+ parsed = { periods, days };
4156
+ sessions.set(session, parsed);
4157
+ return parsed;
4158
+ }
4159
+ function inSession(time, session, timezone) {
4160
+ if (Number.isNaN(time)) return false;
4161
+ const { periods, days } = parseSession(session);
4162
+ const f = zonedFields(time, timezone);
4163
+ const minute2 = f.hour * 60 + f.minute;
4164
+ const nextDay = f.dayOfWeek % 7 + 1;
4165
+ for (const { start, end } of periods) {
4166
+ if (start < end || start === 0 && end === 0) {
4167
+ if (minute2 >= start && (minute2 < end || end === 0) && days[f.dayOfWeek]) return true;
4168
+ } else {
4169
+ if (minute2 >= start && days[nextDay]) return true;
4170
+ if (minute2 < end && days[f.dayOfWeek]) return true;
4171
+ }
4172
+ }
4173
+ return false;
4174
+ }
4175
+
4176
+ // src/time/index.ts
3556
4177
  function now() {
3557
4178
  return Date.now();
3558
4179
  }
3559
- function timestamp(year, month, day, hour, minute, second) {
3560
- return new Date(
3561
- year,
3562
- month - 1,
3563
- day,
3564
- hour || 0,
3565
- minute || 0,
3566
- second || 0
3567
- ).getTime();
4180
+ function timestamp(first2, ...rest) {
4181
+ if (typeof first2 === "string") {
4182
+ if (rest.length === 0) return parseDateString(first2);
4183
+ const [year2, month3, day2, hour3, minute3, second3] = rest;
4184
+ return zonedToUnix(first2, year2, month3, day2, hour3 ?? 0, minute3 ?? 0, second3 ?? 0);
4185
+ }
4186
+ const [month2, day, hour2, minute2, second2] = rest;
4187
+ return new Date(first2, month2 - 1, day, hour2 || 0, minute2 || 0, second2 || 0).getTime();
4188
+ }
4189
+ function field(time, timezone, pick) {
4190
+ return Number.isNaN(time) ? NaN : pick(zonedFields(time, timezone));
4191
+ }
4192
+ function year(time, timezone) {
4193
+ return field(time, timezone, (f) => f.year);
4194
+ }
4195
+ function month(time, timezone) {
4196
+ return field(time, timezone, (f) => f.month);
4197
+ }
4198
+ function dayofmonth(time, timezone) {
4199
+ return field(time, timezone, (f) => f.day);
4200
+ }
4201
+ function dayofweek(time, timezone) {
4202
+ return field(time, timezone, (f) => f.dayOfWeek);
4203
+ }
4204
+ function weekofyear(time, timezone) {
4205
+ return field(time, timezone, (f) => {
4206
+ const date = Date.UTC(f.year, f.month - 1, f.day);
4207
+ const mondayBased = (f.dayOfWeek + 5) % 7;
4208
+ const thursday = new Date(date + (3 - mondayBased) * 864e5);
4209
+ const yearStart = Date.UTC(thursday.getUTCFullYear(), 0, 1);
4210
+ return 1 + Math.floor((thursday.getTime() - yearStart) / (7 * 864e5));
4211
+ });
4212
+ }
4213
+ function hour(time, timezone) {
4214
+ return field(time, timezone, (f) => f.hour);
4215
+ }
4216
+ function minute(time, timezone) {
4217
+ return field(time, timezone, (f) => f.minute);
4218
+ }
4219
+ function second(time, timezone) {
4220
+ return field(time, timezone, (f) => f.second);
4221
+ }
4222
+ function inSession2(time, session, timezone) {
4223
+ return inSession(time, session, timezone);
4224
+ }
4225
+
4226
+ // src/timeframe/index.ts
4227
+ var timeframe_exports = {};
4228
+ __export(timeframe_exports, {
4229
+ from_seconds: () => from_seconds,
4230
+ in_seconds: () => in_seconds,
4231
+ info: () => info
4232
+ });
4233
+ var SECONDS_PER_MINUTE = 60;
4234
+ var SECONDS_PER_DAY = 86400;
4235
+ var SECONDS_PER_WEEK = 604800;
4236
+ var SECONDS_PER_MONTH = 2628003;
4237
+ var SECONDS_365_DAYS = 365 * SECONDS_PER_DAY;
4238
+ var UNIT_SECONDS = {
4239
+ S: 1,
4240
+ "": SECONDS_PER_MINUTE,
4241
+ D: SECONDS_PER_DAY,
4242
+ W: SECONDS_PER_WEEK,
4243
+ M: SECONDS_PER_MONTH
4244
+ };
4245
+ var SECOND_TIMEFRAMES = [1, 5, 10, 15, 30];
4246
+ function in_seconds(timeframe) {
4247
+ const text = timeframe.trim();
4248
+ if (text === "") {
4249
+ throw new RangeError("timeframe.in_seconds() needs a timeframe: the chart timeframe is not known here");
4250
+ }
4251
+ const before = /^(\d*)([SDWMT]?)$/.exec(text);
4252
+ const after = before ? null : /^([SDWMT])(\d+)$/.exec(text);
4253
+ if (!before && !after) throw new RangeError(`Invalid timeframe "${timeframe}"`);
4254
+ const [digits, unit] = before ? [before[1], before[2]] : [after[2], after[1]];
4255
+ if (unit === "T") return NaN;
4256
+ const multiplier = digits === "" ? 1 : Number(digits);
4257
+ return multiplier * UNIT_SECONDS[unit];
4258
+ }
4259
+ function from_seconds(seconds) {
4260
+ if (Number.isNaN(seconds)) throw new RangeError("timeframe.from_seconds() needs a number of seconds");
4261
+ if (seconds >= SECONDS_365_DAYS) return "12M";
4262
+ if (seconds > 0) {
4263
+ if (seconds % SECONDS_PER_MONTH === 0) return `${seconds / SECONDS_PER_MONTH}M`;
4264
+ if (seconds % SECONDS_PER_WEEK === 0) return `${seconds / SECONDS_PER_WEEK}W`;
4265
+ if (seconds % SECONDS_PER_DAY === 0) return `${seconds / SECONDS_PER_DAY}D`;
4266
+ if (seconds % SECONDS_PER_MINUTE === 0 && seconds < SECONDS_PER_DAY) return `${seconds / SECONDS_PER_MINUTE}`;
4267
+ }
4268
+ const second2 = SECOND_TIMEFRAMES.find((m) => seconds <= m);
4269
+ if (second2 !== void 0) return `${second2}S`;
4270
+ if (seconds < SECONDS_PER_DAY) return `${Math.ceil(seconds / SECONDS_PER_MINUTE)}`;
4271
+ return `${Math.ceil(seconds / SECONDS_PER_DAY)}D`;
4272
+ }
4273
+ function info(timeframe) {
4274
+ const text = timeframe.trim();
4275
+ const m = /^(\d*)([SDWMT]?)$/.exec(text);
4276
+ if (!m || text === "") throw new RangeError(`Invalid timeframe "${timeframe}"`);
4277
+ const unit = m[2];
4278
+ const multiplier = m[1] === "" ? 1 : Number(m[1]);
4279
+ return {
4280
+ period: unit === "" ? String(multiplier) : `${multiplier}${unit}`,
4281
+ multiplier,
4282
+ isintraday: unit === "" || unit === "S" || unit === "T",
4283
+ isdaily: unit === "D",
4284
+ isweekly: unit === "W",
4285
+ ismonthly: unit === "M",
4286
+ isminutes: unit === "",
4287
+ isseconds: unit === "S",
4288
+ isticks: unit === "T",
4289
+ isdwm: unit === "D" || unit === "W" || unit === "M"
4290
+ };
3568
4291
  }
3569
4292
 
3570
4293
  // src/matrix/index.ts
@@ -3576,14 +4299,14 @@ __export(matrix_exports, {
3576
4299
  col: () => col,
3577
4300
  columns: () => columns,
3578
4301
  concat: () => concat3,
3579
- copy: () => copy2,
4302
+ copy: () => copy3,
3580
4303
  det: () => det,
3581
4304
  diff: () => diff,
3582
4305
  eigenvalues: () => eigenvalues,
3583
4306
  eigenvectors: () => eigenvectors,
3584
4307
  elements_count: () => elements_count,
3585
4308
  fill: () => fill2,
3586
- get: () => get2,
4309
+ get: () => get3,
3587
4310
  inv: () => inv,
3588
4311
  is_antidiagonal: () => is_antidiagonal,
3589
4312
  is_antisymmetric: () => is_antisymmetric,
@@ -3632,7 +4355,7 @@ function new_matrix(rows2, columns2, initial_value) {
3632
4355
  }
3633
4356
  return { rows: rows2, columns: columns2, data };
3634
4357
  }
3635
- function get2(id, row2, column) {
4358
+ function get3(id, row2, column) {
3636
4359
  if (row2 < 0 || row2 >= id.rows || column < 0 || column >= id.columns) {
3637
4360
  throw new Error(`Matrix index out of bounds: [${row2}, ${column}] for matrix of size [${id.rows}, ${id.columns}]`);
3638
4361
  }
@@ -3665,7 +4388,7 @@ function col(id, column_index) {
3665
4388
  }
3666
4389
  return id.data.map((r2) => r2[column_index]);
3667
4390
  }
3668
- function copy2(id) {
4391
+ function copy3(id) {
3669
4392
  const newData = id.data.map((r2) => [...r2]);
3670
4393
  return {
3671
4394
  rows: id.rows,
@@ -4017,24 +4740,24 @@ function median3(id) {
4017
4740
  if (id.rows === 0 || id.columns === 0) {
4018
4741
  return NaN;
4019
4742
  }
4020
- const values = [];
4743
+ const values2 = [];
4021
4744
  for (let i = 0; i < id.rows; i++) {
4022
4745
  for (let j = 0; j < id.columns; j++) {
4023
4746
  const val = id.data[i][j];
4024
4747
  if (val !== null && val !== void 0 && !isNaN(val)) {
4025
- values.push(val);
4748
+ values2.push(val);
4026
4749
  }
4027
4750
  }
4028
4751
  }
4029
- if (values.length === 0) {
4752
+ if (values2.length === 0) {
4030
4753
  return NaN;
4031
4754
  }
4032
- values.sort((a, b2) => a - b2);
4033
- const mid = Math.floor(values.length / 2);
4034
- if (values.length % 2 === 0) {
4035
- return (values[mid - 1] + values[mid]) / 2;
4755
+ values2.sort((a, b2) => a - b2);
4756
+ const mid = Math.floor(values2.length / 2);
4757
+ if (values2.length % 2 === 0) {
4758
+ return (values2[mid - 1] + values2[mid]) / 2;
4036
4759
  } else {
4037
- return values[mid];
4760
+ return values2[mid];
4038
4761
  }
4039
4762
  }
4040
4763
  function mode3(id) {
@@ -4199,7 +4922,7 @@ function is_stochastic(id) {
4199
4922
  }
4200
4923
  return true;
4201
4924
  }
4202
- var EPSILON = 1e-10;
4925
+ var EPSILON2 = 1e-10;
4203
4926
  function createIdentity(n) {
4204
4927
  const m = new_matrix(n, n, 0);
4205
4928
  for (let i = 0; i < n; i++) {
@@ -4280,7 +5003,7 @@ function pow2(id, power) {
4280
5003
  base = inverse;
4281
5004
  p = -power;
4282
5005
  } else {
4283
- base = copy2(id);
5006
+ base = copy3(id);
4284
5007
  }
4285
5008
  let result = createIdentity(n);
4286
5009
  while (p > 0) {
@@ -4309,31 +5032,31 @@ function det(id) {
4309
5032
  const a = id.data.map((row2) => [...row2]);
4310
5033
  let determinant = 1;
4311
5034
  let swapCount = 0;
4312
- for (let col2 = 0; col2 < n; col2++) {
4313
- let maxRow = col2;
4314
- let maxVal = Math.abs(a[col2][col2]);
4315
- for (let row2 = col2 + 1; row2 < n; row2++) {
4316
- const absVal = Math.abs(a[row2][col2]);
5035
+ for (let col3 = 0; col3 < n; col3++) {
5036
+ let maxRow = col3;
5037
+ let maxVal = Math.abs(a[col3][col3]);
5038
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5039
+ const absVal = Math.abs(a[row2][col3]);
4317
5040
  if (absVal > maxVal) {
4318
5041
  maxVal = absVal;
4319
5042
  maxRow = row2;
4320
5043
  }
4321
5044
  }
4322
- if (maxRow !== col2) {
4323
- const temp = a[col2];
4324
- a[col2] = a[maxRow];
5045
+ if (maxRow !== col3) {
5046
+ const temp = a[col3];
5047
+ a[col3] = a[maxRow];
4325
5048
  a[maxRow] = temp;
4326
5049
  swapCount++;
4327
5050
  }
4328
- const pivot = a[col2][col2];
4329
- if (Math.abs(pivot) < EPSILON) {
5051
+ const pivot2 = a[col3][col3];
5052
+ if (Math.abs(pivot2) < EPSILON2) {
4330
5053
  return 0;
4331
5054
  }
4332
- determinant *= pivot;
4333
- for (let row2 = col2 + 1; row2 < n; row2++) {
4334
- const factor = a[row2][col2] / pivot;
4335
- for (let j = col2; j < n; j++) {
4336
- a[row2][j] = a[row2][j] - factor * a[col2][j];
5055
+ determinant *= pivot2;
5056
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5057
+ const factor = a[row2][col3] / pivot2;
5058
+ for (let j = col3; j < n; j++) {
5059
+ a[row2][j] = a[row2][j] - factor * a[col3][j];
4337
5060
  }
4338
5061
  }
4339
5062
  }
@@ -4361,33 +5084,33 @@ function inv(id) {
4361
5084
  }
4362
5085
  aug.push(row2);
4363
5086
  }
4364
- for (let col2 = 0; col2 < n; col2++) {
4365
- let maxRow = col2;
4366
- let maxVal = Math.abs(aug[col2][col2]);
4367
- for (let row2 = col2 + 1; row2 < n; row2++) {
4368
- const absVal = Math.abs(aug[row2][col2]);
5087
+ for (let col3 = 0; col3 < n; col3++) {
5088
+ let maxRow = col3;
5089
+ let maxVal = Math.abs(aug[col3][col3]);
5090
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5091
+ const absVal = Math.abs(aug[row2][col3]);
4369
5092
  if (absVal > maxVal) {
4370
5093
  maxVal = absVal;
4371
5094
  maxRow = row2;
4372
5095
  }
4373
5096
  }
4374
- if (maxRow !== col2) {
4375
- const temp = aug[col2];
4376
- aug[col2] = aug[maxRow];
5097
+ if (maxRow !== col3) {
5098
+ const temp = aug[col3];
5099
+ aug[col3] = aug[maxRow];
4377
5100
  aug[maxRow] = temp;
4378
5101
  }
4379
- const pivot = aug[col2][col2];
4380
- if (Math.abs(pivot) < EPSILON) {
5102
+ const pivot2 = aug[col3][col3];
5103
+ if (Math.abs(pivot2) < EPSILON2) {
4381
5104
  return null;
4382
5105
  }
4383
5106
  for (let j = 0; j < 2 * n; j++) {
4384
- aug[col2][j] = aug[col2][j] / pivot;
5107
+ aug[col3][j] = aug[col3][j] / pivot2;
4385
5108
  }
4386
5109
  for (let row2 = 0; row2 < n; row2++) {
4387
- if (row2 !== col2) {
4388
- const factor = aug[row2][col2];
5110
+ if (row2 !== col3) {
5111
+ const factor = aug[row2][col3];
4389
5112
  for (let j = 0; j < 2 * n; j++) {
4390
- aug[row2][j] = aug[row2][j] - factor * aug[col2][j];
5113
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4391
5114
  }
4392
5115
  }
4393
5116
  }
@@ -4450,17 +5173,17 @@ function rank(id) {
4450
5173
  const m = id.rows;
4451
5174
  const n = id.columns;
4452
5175
  let r2 = 0;
4453
- for (let col2 = 0; col2 < n && r2 < m; col2++) {
5176
+ for (let col3 = 0; col3 < n && r2 < m; col3++) {
4454
5177
  let maxRow = r2;
4455
- let maxVal = Math.abs(a[r2][col2]);
5178
+ let maxVal = Math.abs(a[r2][col3]);
4456
5179
  for (let row2 = r2 + 1; row2 < m; row2++) {
4457
- const absVal = Math.abs(a[row2][col2]);
5180
+ const absVal = Math.abs(a[row2][col3]);
4458
5181
  if (absVal > maxVal) {
4459
5182
  maxVal = absVal;
4460
5183
  maxRow = row2;
4461
5184
  }
4462
5185
  }
4463
- if (maxVal < EPSILON) {
5186
+ if (maxVal < EPSILON2) {
4464
5187
  continue;
4465
5188
  }
4466
5189
  if (maxRow !== r2) {
@@ -4468,10 +5191,10 @@ function rank(id) {
4468
5191
  a[r2] = a[maxRow];
4469
5192
  a[maxRow] = temp;
4470
5193
  }
4471
- const pivot = a[r2][col2];
5194
+ const pivot2 = a[r2][col3];
4472
5195
  for (let row2 = r2 + 1; row2 < m; row2++) {
4473
- const factor = a[row2][col2] / pivot;
4474
- for (let j = col2; j < n; j++) {
5196
+ const factor = a[row2][col3] / pivot2;
5197
+ for (let j = col3; j < n; j++) {
4475
5198
  a[row2][j] = a[row2][j] - factor * a[r2][j];
4476
5199
  }
4477
5200
  }
@@ -4517,7 +5240,7 @@ function toHessenberg(m) {
4517
5240
  for (let i = k + 1; i < n; i++) {
4518
5241
  maxVal = Math.max(maxVal, Math.abs(h[i][k]));
4519
5242
  }
4520
- if (maxVal < EPSILON) continue;
5243
+ if (maxVal < EPSILON2) continue;
4521
5244
  let sigma = 0;
4522
5245
  for (let i = k + 1; i < n; i++) {
4523
5246
  sigma += h[i][k] * h[i][k];
@@ -4533,7 +5256,7 @@ function toHessenberg(m) {
4533
5256
  for (let i = k + 1; i < n; i++) {
4534
5257
  uTu += u[i] * u[i];
4535
5258
  }
4536
- if (uTu < EPSILON) continue;
5259
+ if (uTu < EPSILON2) continue;
4537
5260
  for (let j = k; j < n; j++) {
4538
5261
  let dot = 0;
4539
5262
  for (let i = k + 1; i < n; i++) {
@@ -4565,7 +5288,7 @@ function qrAlgorithm(h, maxIter) {
4565
5288
  for (let iter = 0; iter < maxIter && remaining > 1; iter++) {
4566
5289
  let converged = false;
4567
5290
  for (let i = remaining - 1; i >= 1; i--) {
4568
- if (Math.abs(a[i][i - 1]) < EPSILON * (Math.abs(a[i - 1][i - 1]) + Math.abs(a[i][i]))) {
5291
+ if (Math.abs(a[i][i - 1]) < EPSILON2 * (Math.abs(a[i - 1][i - 1]) + Math.abs(a[i][i]))) {
4569
5292
  a[i][i - 1] = 0;
4570
5293
  if (i === remaining - 1) {
4571
5294
  eigenvals.push(a[remaining - 1][remaining - 1]);
@@ -4584,8 +5307,8 @@ function qrAlgorithm(h, maxIter) {
4584
5307
  let z = a[1][0];
4585
5308
  for (let k = 0; k < remaining - 1; k++) {
4586
5309
  let r2 = Math.sqrt(x * x + z * z);
4587
- if (r2 < EPSILON) {
4588
- r2 = EPSILON;
5310
+ if (r2 < EPSILON2) {
5311
+ r2 = EPSILON2;
4589
5312
  }
4590
5313
  const c = x / r2;
4591
5314
  const s = z / r2;
@@ -4646,8 +5369,8 @@ function inverseIteration(m, lambda) {
4646
5369
  (row2, i) => row2.map((val, j) => i === j ? val - lambda : val)
4647
5370
  );
4648
5371
  for (let i = 0; i < n; i++) {
4649
- if (Math.abs(shifted[i][i]) < EPSILON) {
4650
- shifted[i][i] = EPSILON;
5372
+ if (Math.abs(shifted[i][i]) < EPSILON2) {
5373
+ shifted[i][i] = EPSILON2;
4651
5374
  }
4652
5375
  }
4653
5376
  let v = new Array(n).fill(1);
@@ -4658,7 +5381,7 @@ function inverseIteration(m, lambda) {
4658
5381
  norm += w[i] * w[i];
4659
5382
  }
4660
5383
  norm = Math.sqrt(norm);
4661
- if (norm < EPSILON) {
5384
+ if (norm < EPSILON2) {
4662
5385
  return v;
4663
5386
  }
4664
5387
  const newV = [];
@@ -4670,7 +5393,7 @@ function inverseIteration(m, lambda) {
4670
5393
  diff2 += Math.abs(Math.abs(newV[i]) - Math.abs(v[i]));
4671
5394
  }
4672
5395
  v = newV;
4673
- if (diff2 < EPSILON) {
5396
+ if (diff2 < EPSILON2) {
4674
5397
  break;
4675
5398
  }
4676
5399
  }
@@ -4679,29 +5402,29 @@ function inverseIteration(m, lambda) {
4679
5402
  function solveLinearSystem(a, b2) {
4680
5403
  const n = a.length;
4681
5404
  const aug = a.map((row2, i) => [...row2, b2[i]]);
4682
- for (let col2 = 0; col2 < n; col2++) {
4683
- let maxRow = col2;
4684
- let maxVal = Math.abs(aug[col2][col2]);
4685
- for (let row2 = col2 + 1; row2 < n; row2++) {
4686
- const absVal = Math.abs(aug[row2][col2]);
5405
+ for (let col3 = 0; col3 < n; col3++) {
5406
+ let maxRow = col3;
5407
+ let maxVal = Math.abs(aug[col3][col3]);
5408
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5409
+ const absVal = Math.abs(aug[row2][col3]);
4687
5410
  if (absVal > maxVal) {
4688
5411
  maxVal = absVal;
4689
5412
  maxRow = row2;
4690
5413
  }
4691
5414
  }
4692
- if (maxRow !== col2) {
4693
- const temp = aug[col2];
4694
- aug[col2] = aug[maxRow];
5415
+ if (maxRow !== col3) {
5416
+ const temp = aug[col3];
5417
+ aug[col3] = aug[maxRow];
4695
5418
  aug[maxRow] = temp;
4696
5419
  }
4697
- const pivot = aug[col2][col2];
4698
- if (Math.abs(pivot) < EPSILON) {
5420
+ const pivot2 = aug[col3][col3];
5421
+ if (Math.abs(pivot2) < EPSILON2) {
4699
5422
  continue;
4700
5423
  }
4701
- for (let row2 = col2 + 1; row2 < n; row2++) {
4702
- const factor = aug[row2][col2] / pivot;
4703
- for (let j = col2; j <= n; j++) {
4704
- aug[row2][j] = aug[row2][j] - factor * aug[col2][j];
5424
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5425
+ const factor = aug[row2][col3] / pivot2;
5426
+ for (let j = col3; j <= n; j++) {
5427
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4705
5428
  }
4706
5429
  }
4707
5430
  }
@@ -4712,7 +5435,7 @@ function solveLinearSystem(a, b2) {
4712
5435
  sum4 -= aug[i][j] * x[j];
4713
5436
  }
4714
5437
  const diag = aug[i][i];
4715
- x[i] = Math.abs(diag) < EPSILON ? 0 : sum4 / diag;
5438
+ x[i] = Math.abs(diag) < EPSILON2 ? 0 : sum4 / diag;
4716
5439
  }
4717
5440
  return x;
4718
5441
  }
@@ -4733,8 +5456,8 @@ function kron(id1, id2) {
4733
5456
  for (let i2 = 0; i2 < m2; i2++) {
4734
5457
  for (let j2 = 0; j2 < n2; j2++) {
4735
5458
  const row2 = i1 * m2 + i2;
4736
- const col2 = j1 * n2 + j2;
4737
- data[row2][col2] = a * id2.data[i2][j2];
5459
+ const col3 = j1 * n2 + j2;
5460
+ data[row2][col3] = a * id2.data[i2][j2];
4738
5461
  }
4739
5462
  }
4740
5463
  }
@@ -4752,7 +5475,9 @@ function newtype2(rows2 = 0, columns2 = 0, initial_value) {
4752
5475
  // src/line/index.ts
4753
5476
  var line_exports = {};
4754
5477
  __export(line_exports, {
4755
- copy: () => copy3,
5478
+ all: () => all2,
5479
+ copy: () => copy4,
5480
+ delete: () => delete_line,
4756
5481
  delete_line: () => delete_line,
4757
5482
  get_price: () => get_price,
4758
5483
  get_x1: () => get_x1,
@@ -4763,6 +5488,8 @@ __export(line_exports, {
4763
5488
  new_line: () => new_line2,
4764
5489
  set_color: () => set_color,
4765
5490
  set_extend: () => set_extend,
5491
+ set_first_point: () => set_first_point,
5492
+ set_second_point: () => set_second_point,
4766
5493
  set_style: () => set_style,
4767
5494
  set_width: () => set_width,
4768
5495
  set_x1: () => set_x1,
@@ -4773,18 +5500,78 @@ __export(line_exports, {
4773
5500
  set_y1: () => set_y1,
4774
5501
  set_y2: () => set_y2
4775
5502
  });
4776
- function new_line2(x1, y1, x2, y2, xloc2 = "bar_index", extend = "none", lineColor, style, width) {
4777
- return {
5503
+
5504
+ // src/drawing/registry.ts
5505
+ var DEFAULT_MAX_COUNT = 50;
5506
+ var SLACK = 5;
5507
+ var live = { line: [], label: [], box: [], polyline: [], linefill: [] };
5508
+ var limits = {
5509
+ line: DEFAULT_MAX_COUNT,
5510
+ label: DEFAULT_MAX_COUNT,
5511
+ box: DEFAULT_MAX_COUNT,
5512
+ polyline: DEFAULT_MAX_COUNT
5513
+ };
5514
+ var deleted = /* @__PURE__ */ new WeakSet();
5515
+ var COORDINATES = {
5516
+ line: ["x1", "y1", "x2", "y2"],
5517
+ label: ["x", "y"],
5518
+ box: ["left", "top", "right", "bottom"],
5519
+ polyline: [],
5520
+ linefill: []
5521
+ };
5522
+ function markDeleted(kind, obj, explicit) {
5523
+ deleted.add(obj);
5524
+ for (const field2 of COORDINATES[kind]) obj[field2] = NaN;
5525
+ if (kind === "line" && explicit) {
5526
+ for (const fill3 of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove3("linefill", fill3);
5527
+ }
5528
+ }
5529
+ function register(kind, obj) {
5530
+ const list = live[kind];
5531
+ list.push(obj);
5532
+ const max6 = limits[kind === "linefill" ? "line" : kind];
5533
+ if (list.length > max6 + SLACK) {
5534
+ for (const old of list.splice(0, list.length - max6)) markDeleted(kind, old, false);
5535
+ }
5536
+ return obj;
5537
+ }
5538
+ function remove3(kind, obj) {
5539
+ const list = live[kind];
5540
+ const index = list.indexOf(obj);
5541
+ if (index !== -1) list.splice(index, 1);
5542
+ if (!deleted.has(obj)) markDeleted(kind, obj, true);
5543
+ }
5544
+ function isDeleted(obj) {
5545
+ return typeof obj === "object" && obj !== null && deleted.has(obj);
5546
+ }
5547
+ function all(kind) {
5548
+ return [...live[kind]];
5549
+ }
5550
+
5551
+ // src/line/index.ts
5552
+ function new_line2(...args) {
5553
+ let x1, y1, x2, y2, rest;
5554
+ if (typeof args[0] === "object" && args[0] !== null) {
5555
+ const [p1, p2, ...others] = args;
5556
+ const xloc3 = others[0] ?? "bar_index";
5557
+ [x1, y1, x2, y2, rest] = [pointX(p1, xloc3), p1.price, pointX(p2, xloc3), p2.price, others];
5558
+ } else {
5559
+ [x1, y1, x2, y2] = args;
5560
+ rest = args.slice(4);
5561
+ }
5562
+ const [xloc2, extend, lineColor, style, width, force_overlay] = rest;
5563
+ return register("line", {
4778
5564
  x1,
4779
5565
  y1,
4780
5566
  x2,
4781
5567
  y2,
4782
- xloc: xloc2,
4783
- extend,
5568
+ xloc: xloc2 ?? "bar_index",
5569
+ extend: extend ?? "none",
4784
5570
  color: lineColor,
4785
5571
  style: style || "solid",
4786
- width: width || 1
4787
- };
5572
+ width: width || 1,
5573
+ force_overlay: force_overlay ?? false
5574
+ });
4788
5575
  }
4789
5576
  function get_price(id, x) {
4790
5577
  const { x1, y1, x2, y2, extend, xloc: xloc2 } = id;
@@ -4823,64 +5610,97 @@ function get_y1(id) {
4823
5610
  function get_y2(id) {
4824
5611
  return id.y2;
4825
5612
  }
4826
- function copy3(id) {
4827
- return { ...id };
5613
+ function copy4(id) {
5614
+ return register("line", { ...id });
4828
5615
  }
4829
5616
  function set_x1(id, x) {
5617
+ if (isDeleted(id)) return id;
4830
5618
  id.x1 = x;
4831
5619
  return id;
4832
5620
  }
4833
5621
  function set_x2(id, x) {
5622
+ if (isDeleted(id)) return id;
4834
5623
  id.x2 = x;
4835
5624
  return id;
4836
5625
  }
4837
5626
  function set_y1(id, y) {
5627
+ if (isDeleted(id)) return id;
4838
5628
  id.y1 = y;
4839
5629
  return id;
4840
5630
  }
4841
5631
  function set_y2(id, y) {
5632
+ if (isDeleted(id)) return id;
4842
5633
  id.y2 = y;
4843
5634
  return id;
4844
5635
  }
4845
5636
  function set_xy1(id, x, y) {
5637
+ if (isDeleted(id)) return id;
4846
5638
  id.x1 = x;
4847
5639
  id.y1 = y;
4848
5640
  return id;
4849
5641
  }
4850
5642
  function set_xy2(id, x, y) {
5643
+ if (isDeleted(id)) return id;
4851
5644
  id.x2 = x;
4852
5645
  id.y2 = y;
4853
5646
  return id;
4854
5647
  }
4855
5648
  function set_xloc(id, x1, x2, xloc2) {
5649
+ if (isDeleted(id)) return id;
4856
5650
  id.x1 = x1;
4857
5651
  id.x2 = x2;
4858
5652
  id.xloc = xloc2;
4859
5653
  return id;
4860
5654
  }
4861
5655
  function set_extend(id, extend) {
5656
+ if (isDeleted(id)) return id;
4862
5657
  id.extend = extend;
4863
5658
  return id;
4864
5659
  }
4865
5660
  function set_color(id, lineColor) {
5661
+ if (isDeleted(id)) return id;
4866
5662
  id.color = lineColor;
4867
5663
  return id;
4868
5664
  }
4869
5665
  function set_style(id, style) {
5666
+ if (isDeleted(id)) return id;
4870
5667
  id.style = style;
4871
5668
  return id;
4872
5669
  }
4873
5670
  function set_width(id, width) {
5671
+ if (isDeleted(id)) return id;
4874
5672
  id.width = width;
4875
5673
  return id;
4876
5674
  }
4877
- function delete_line(_id) {
5675
+ function delete_line(id) {
5676
+ remove3("line", id);
5677
+ }
5678
+ function pointX(point, xloc2) {
5679
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5680
+ return x ?? NaN;
5681
+ }
5682
+ function all2() {
5683
+ return all("line");
5684
+ }
5685
+ function set_first_point(id, point) {
5686
+ if (isDeleted(id)) return id;
5687
+ id.x1 = pointX(point, id.xloc);
5688
+ id.y1 = point.price;
5689
+ return id;
5690
+ }
5691
+ function set_second_point(id, point) {
5692
+ if (isDeleted(id)) return id;
5693
+ id.x2 = pointX(point, id.xloc);
5694
+ id.y2 = point.price;
5695
+ return id;
4878
5696
  }
4879
5697
 
4880
5698
  // src/box/index.ts
4881
5699
  var box_exports = {};
4882
5700
  __export(box_exports, {
4883
- copy: () => copy4,
5701
+ all: () => all3,
5702
+ copy: () => copy5,
5703
+ delete: () => delete_box,
4884
5704
  delete_box: () => delete_box,
4885
5705
  get_bottom: () => get_bottom,
4886
5706
  get_left: () => get_left,
@@ -4893,6 +5713,7 @@ __export(box_exports, {
4893
5713
  set_border_style: () => set_border_style,
4894
5714
  set_border_width: () => set_border_width,
4895
5715
  set_bottom: () => set_bottom,
5716
+ set_bottom_right_point: () => set_bottom_right_point,
4896
5717
  set_extend: () => set_extend2,
4897
5718
  set_left: () => set_left,
4898
5719
  set_lefttop: () => set_lefttop,
@@ -4901,21 +5722,49 @@ __export(box_exports, {
4901
5722
  set_text: () => set_text,
4902
5723
  set_text_color: () => set_text_color,
4903
5724
  set_text_font_family: () => set_text_font_family,
5725
+ set_text_formatting: () => set_text_formatting,
4904
5726
  set_text_halign: () => set_text_halign,
4905
5727
  set_text_size: () => set_text_size,
4906
5728
  set_text_valign: () => set_text_valign,
4907
5729
  set_text_wrap: () => set_text_wrap,
4908
5730
  set_top: () => set_top,
5731
+ set_top_left_point: () => set_top_left_point,
4909
5732
  set_xloc: () => set_xloc2
4910
5733
  });
4911
- function new_box2(left, top, right, bottom, xloc2 = "bar_index", extend = "none", border_color, border_width, border_style, bgcolor, text, text_size, text_color, text_halign, text_valign, text_wrap, text_font_family) {
4912
- return {
5734
+ function new_box2(...args) {
5735
+ let left, top, right, bottom, rest;
5736
+ if (typeof args[0] === "object" && args[0] !== null) {
5737
+ const [tl, br, ...others] = args;
5738
+ const xloc3 = others[4] ?? "bar_index";
5739
+ [left, top, right, bottom, rest] = [pointX2(tl, xloc3), tl.price, pointX2(br, xloc3), br.price, others];
5740
+ } else {
5741
+ [left, top, right, bottom] = args;
5742
+ rest = args.slice(4);
5743
+ }
5744
+ const [
5745
+ border_color,
5746
+ border_width,
5747
+ border_style,
5748
+ extend,
5749
+ xloc2,
5750
+ bgcolor,
5751
+ text,
5752
+ text_size,
5753
+ text_color,
5754
+ text_halign,
5755
+ text_valign,
5756
+ text_wrap,
5757
+ text_font_family,
5758
+ force_overlay,
5759
+ text_formatting
5760
+ ] = rest;
5761
+ return register("box", {
4913
5762
  left,
4914
5763
  top,
4915
5764
  right,
4916
5765
  bottom,
4917
- xloc: xloc2,
4918
- extend,
5766
+ xloc: xloc2 ?? "bar_index",
5767
+ extend: extend ?? "none",
4919
5768
  border_color,
4920
5769
  border_width: border_width || 1,
4921
5770
  border_style: border_style || "solid",
@@ -4926,8 +5775,10 @@ function new_box2(left, top, right, bottom, xloc2 = "bar_index", extend = "none"
4926
5775
  text_halign,
4927
5776
  text_valign,
4928
5777
  text_wrap,
4929
- text_font_family
4930
- };
5778
+ text_font_family,
5779
+ force_overlay: force_overlay ?? false,
5780
+ text_formatting
5781
+ });
4931
5782
  }
4932
5783
  function get_left(id) {
4933
5784
  return id.left;
@@ -4941,96 +5792,142 @@ function get_top(id) {
4941
5792
  function get_bottom(id) {
4942
5793
  return id.bottom;
4943
5794
  }
4944
- function copy4(id) {
4945
- return { ...id };
5795
+ function copy5(id) {
5796
+ return register("box", { ...id });
4946
5797
  }
4947
5798
  function set_left(id, left) {
5799
+ if (isDeleted(id)) return id;
4948
5800
  id.left = left;
4949
5801
  return id;
4950
5802
  }
4951
5803
  function set_right(id, right) {
5804
+ if (isDeleted(id)) return id;
4952
5805
  id.right = right;
4953
5806
  return id;
4954
5807
  }
4955
5808
  function set_top(id, top) {
5809
+ if (isDeleted(id)) return id;
4956
5810
  id.top = top;
4957
5811
  return id;
4958
5812
  }
4959
5813
  function set_bottom(id, bottom) {
5814
+ if (isDeleted(id)) return id;
4960
5815
  id.bottom = bottom;
4961
5816
  return id;
4962
5817
  }
4963
5818
  function set_lefttop(id, left, top) {
5819
+ if (isDeleted(id)) return id;
4964
5820
  id.left = left;
4965
5821
  id.top = top;
4966
5822
  return id;
4967
5823
  }
4968
5824
  function set_rightbottom(id, right, bottom) {
5825
+ if (isDeleted(id)) return id;
4969
5826
  id.right = right;
4970
5827
  id.bottom = bottom;
4971
5828
  return id;
4972
5829
  }
4973
5830
  function set_xloc2(id, left, right, xloc2) {
5831
+ if (isDeleted(id)) return id;
4974
5832
  id.left = left;
4975
5833
  id.right = right;
4976
5834
  id.xloc = xloc2;
4977
5835
  return id;
4978
5836
  }
4979
5837
  function set_extend2(id, extend) {
5838
+ if (isDeleted(id)) return id;
4980
5839
  id.extend = extend;
4981
5840
  return id;
4982
5841
  }
4983
5842
  function set_border_color(id, borderColor) {
5843
+ if (isDeleted(id)) return id;
4984
5844
  id.border_color = borderColor;
4985
5845
  return id;
4986
5846
  }
4987
5847
  function set_border_width(id, width) {
5848
+ if (isDeleted(id)) return id;
4988
5849
  id.border_width = width;
4989
5850
  return id;
4990
5851
  }
4991
5852
  function set_border_style(id, style) {
5853
+ if (isDeleted(id)) return id;
4992
5854
  id.border_style = style;
4993
5855
  return id;
4994
5856
  }
4995
5857
  function set_bgcolor(id, bgColor) {
5858
+ if (isDeleted(id)) return id;
4996
5859
  id.bgcolor = bgColor;
4997
5860
  return id;
4998
5861
  }
4999
5862
  function set_text(id, text) {
5863
+ if (isDeleted(id)) return id;
5000
5864
  id.text = text;
5001
5865
  return id;
5002
5866
  }
5003
5867
  function set_text_color(id, textColor) {
5868
+ if (isDeleted(id)) return id;
5004
5869
  id.text_color = textColor;
5005
5870
  return id;
5006
5871
  }
5007
- function set_text_size(id, size2) {
5008
- id.text_size = size2;
5872
+ function set_text_size(id, size3) {
5873
+ if (isDeleted(id)) return id;
5874
+ id.text_size = size3;
5009
5875
  return id;
5010
5876
  }
5011
5877
  function set_text_halign(id, align) {
5878
+ if (isDeleted(id)) return id;
5012
5879
  id.text_halign = align;
5013
5880
  return id;
5014
5881
  }
5015
5882
  function set_text_valign(id, align) {
5883
+ if (isDeleted(id)) return id;
5016
5884
  id.text_valign = align;
5017
5885
  return id;
5018
5886
  }
5019
5887
  function set_text_wrap(id, wrap) {
5888
+ if (isDeleted(id)) return id;
5020
5889
  id.text_wrap = wrap;
5021
5890
  return id;
5022
5891
  }
5023
5892
  function set_text_font_family(id, font) {
5893
+ if (isDeleted(id)) return id;
5024
5894
  id.text_font_family = font;
5025
5895
  return id;
5026
5896
  }
5027
- function delete_box(_id) {
5897
+ function delete_box(id) {
5898
+ remove3("box", id);
5899
+ }
5900
+ function pointX2(point, xloc2) {
5901
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5902
+ return x ?? NaN;
5903
+ }
5904
+ function all3() {
5905
+ return all("box");
5906
+ }
5907
+ function set_top_left_point(id, point) {
5908
+ if (isDeleted(id)) return id;
5909
+ id.left = pointX2(point, id.xloc);
5910
+ id.top = point.price;
5911
+ return id;
5912
+ }
5913
+ function set_bottom_right_point(id, point) {
5914
+ if (isDeleted(id)) return id;
5915
+ id.right = pointX2(point, id.xloc);
5916
+ id.bottom = point.price;
5917
+ return id;
5918
+ }
5919
+ function set_text_formatting(id, formatting) {
5920
+ if (isDeleted(id)) return id;
5921
+ id.text_formatting = formatting;
5922
+ return id;
5028
5923
  }
5029
5924
 
5030
5925
  // src/label/index.ts
5031
5926
  var label_exports = {};
5032
5927
  __export(label_exports, {
5033
- copy: () => copy5,
5928
+ all: () => all4,
5929
+ copy: () => copy6,
5930
+ delete: () => delete_label,
5034
5931
  delete_label: () => delete_label,
5035
5932
  get_text: () => get_text,
5036
5933
  get_x: () => get_x,
@@ -5038,10 +5935,12 @@ __export(label_exports, {
5038
5935
  new: () => new_label2,
5039
5936
  new_label: () => new_label2,
5040
5937
  set_color: () => set_color2,
5938
+ set_point: () => set_point,
5041
5939
  set_size: () => set_size,
5042
5940
  set_style: () => set_style2,
5043
5941
  set_text: () => set_text2,
5044
5942
  set_text_font_family: () => set_text_font_family2,
5943
+ set_text_formatting: () => set_text_formatting2,
5045
5944
  set_textalign: () => set_textalign,
5046
5945
  set_textcolor: () => set_textcolor,
5047
5946
  set_tooltip: () => set_tooltip,
@@ -5051,21 +5950,47 @@ __export(label_exports, {
5051
5950
  set_y: () => set_y,
5052
5951
  set_yloc: () => set_yloc
5053
5952
  });
5054
- function new_label2(x, y, text, xloc2 = "bar_index", yloc = "price", labelColor, style, textcolor, size2, textalign, tooltip, text_font_family) {
5055
- return {
5953
+ function new_label2(...args) {
5954
+ let x, y, rest;
5955
+ if (typeof args[0] === "object" && args[0] !== null) {
5956
+ const point = args[0];
5957
+ rest = args.slice(1);
5958
+ x = pointX3(point, rest[1] ?? "bar_index");
5959
+ y = point.price;
5960
+ } else {
5961
+ [x, y] = args;
5962
+ rest = args.slice(2);
5963
+ }
5964
+ const [
5965
+ text,
5966
+ xloc2,
5967
+ yloc,
5968
+ labelColor,
5969
+ style,
5970
+ textcolor,
5971
+ size3,
5972
+ textalign,
5973
+ tooltip,
5974
+ text_font_family,
5975
+ force_overlay,
5976
+ text_formatting
5977
+ ] = rest;
5978
+ return register("label", {
5056
5979
  x,
5057
5980
  y,
5058
- xloc: xloc2,
5059
- yloc,
5981
+ xloc: xloc2 ?? "bar_index",
5982
+ yloc: yloc ?? "price",
5060
5983
  text,
5061
5984
  tooltip,
5062
5985
  color: labelColor,
5063
5986
  style,
5064
5987
  textcolor,
5065
- size: size2,
5988
+ size: size3,
5066
5989
  textalign,
5067
- text_font_family
5068
- };
5990
+ text_font_family,
5991
+ force_overlay: force_overlay ?? false,
5992
+ text_formatting
5993
+ });
5069
5994
  }
5070
5995
  function get_x(id) {
5071
5996
  return id.x;
@@ -5076,70 +6001,103 @@ function get_y(id) {
5076
6001
  function get_text(id) {
5077
6002
  return id.text;
5078
6003
  }
5079
- function copy5(id) {
5080
- return { ...id };
6004
+ function copy6(id) {
6005
+ return register("label", { ...id });
5081
6006
  }
5082
6007
  function set_x(id, x) {
6008
+ if (isDeleted(id)) return id;
5083
6009
  id.x = x;
5084
6010
  return id;
5085
6011
  }
5086
6012
  function set_y(id, y) {
6013
+ if (isDeleted(id)) return id;
5087
6014
  id.y = y;
5088
6015
  return id;
5089
6016
  }
5090
6017
  function set_xy(id, x, y) {
6018
+ if (isDeleted(id)) return id;
5091
6019
  id.x = x;
5092
6020
  id.y = y;
5093
6021
  return id;
5094
6022
  }
5095
6023
  function set_xloc3(id, x, xloc2) {
6024
+ if (isDeleted(id)) return id;
5096
6025
  id.x = x;
5097
6026
  id.xloc = xloc2;
5098
6027
  return id;
5099
6028
  }
5100
- function set_yloc(id, y, yloc) {
5101
- id.y = y;
6029
+ function set_yloc(id, yloc) {
6030
+ if (isDeleted(id)) return id;
5102
6031
  id.yloc = yloc;
5103
6032
  return id;
5104
6033
  }
5105
6034
  function set_text2(id, text) {
6035
+ if (isDeleted(id)) return id;
5106
6036
  id.text = text;
5107
6037
  return id;
5108
6038
  }
5109
6039
  function set_tooltip(id, tooltip) {
6040
+ if (isDeleted(id)) return id;
5110
6041
  id.tooltip = tooltip;
5111
6042
  return id;
5112
6043
  }
5113
6044
  function set_color2(id, labelColor) {
6045
+ if (isDeleted(id)) return id;
5114
6046
  id.color = labelColor;
5115
6047
  return id;
5116
6048
  }
5117
6049
  function set_textcolor(id, textColor) {
6050
+ if (isDeleted(id)) return id;
5118
6051
  id.textcolor = textColor;
5119
6052
  return id;
5120
6053
  }
5121
6054
  function set_style2(id, style) {
6055
+ if (isDeleted(id)) return id;
5122
6056
  id.style = style;
5123
6057
  return id;
5124
6058
  }
5125
- function set_size(id, size2) {
5126
- id.size = size2;
6059
+ function set_size(id, size3) {
6060
+ if (isDeleted(id)) return id;
6061
+ id.size = size3;
5127
6062
  return id;
5128
6063
  }
5129
6064
  function set_textalign(id, align) {
6065
+ if (isDeleted(id)) return id;
5130
6066
  id.textalign = align;
5131
6067
  return id;
5132
6068
  }
5133
6069
  function set_text_font_family2(id, font) {
6070
+ if (isDeleted(id)) return id;
5134
6071
  id.text_font_family = font;
5135
6072
  return id;
5136
6073
  }
5137
- function delete_label(_id) {
6074
+ function delete_label(id) {
6075
+ remove3("label", id);
6076
+ }
6077
+ function pointX3(point, xloc2) {
6078
+ const x = xloc2 === "bar_time" ? point.time : point.index;
6079
+ return x ?? NaN;
6080
+ }
6081
+ function all4() {
6082
+ return all("label");
6083
+ }
6084
+ function set_point(id, point) {
6085
+ if (isDeleted(id)) return id;
6086
+ id.x = pointX3(point, id.xloc);
6087
+ id.y = point.price;
6088
+ return id;
6089
+ }
6090
+ function set_text_formatting2(id, formatting) {
6091
+ if (isDeleted(id)) return id;
6092
+ id.text_formatting = formatting;
6093
+ return id;
5138
6094
  }
5139
6095
 
5140
6096
  // src/linefill/index.ts
5141
6097
  var linefill_exports = {};
5142
6098
  __export(linefill_exports, {
6099
+ all: () => all5,
6100
+ delete: () => delete_linefill,
5143
6101
  delete_linefill: () => delete_linefill,
5144
6102
  get_line1: () => get_line1,
5145
6103
  get_line2: () => get_line2,
@@ -5148,11 +6106,11 @@ __export(linefill_exports, {
5148
6106
  set_color: () => set_color3
5149
6107
  });
5150
6108
  function new_linefill2(line1, line2, fillColor) {
5151
- return {
6109
+ return register("linefill", {
5152
6110
  line1,
5153
6111
  line2,
5154
6112
  color: fillColor
5155
- };
6113
+ });
5156
6114
  }
5157
6115
  function get_line1(id) {
5158
6116
  return id.line1;
@@ -5161,16 +6119,21 @@ function get_line2(id) {
5161
6119
  return id.line2;
5162
6120
  }
5163
6121
  function set_color3(id, fillColor) {
6122
+ if (isDeleted(id)) return id;
5164
6123
  id.color = fillColor;
5165
6124
  return id;
5166
6125
  }
5167
- function delete_linefill(_id) {
6126
+ function delete_linefill(id) {
6127
+ remove3("linefill", id);
6128
+ }
6129
+ function all5() {
6130
+ return all("linefill");
5168
6131
  }
5169
6132
 
5170
6133
  // src/chartpoint/index.ts
5171
6134
  var chartpoint_exports = {};
5172
6135
  __export(chartpoint_exports, {
5173
- copy: () => copy6,
6136
+ copy: () => copy7,
5174
6137
  from_index: () => from_index,
5175
6138
  from_time: () => from_time,
5176
6139
  new: () => new_point,
@@ -5197,7 +6160,7 @@ function from_index(index, price) {
5197
6160
  price
5198
6161
  };
5199
6162
  }
5200
- function copy6(point) {
6163
+ function copy7(point) {
5201
6164
  return {
5202
6165
  time: point.time,
5203
6166
  index: point.index,
@@ -5208,6 +6171,7 @@ function copy6(point) {
5208
6171
  // src/polyline/index.ts
5209
6172
  var polyline_exports = {};
5210
6173
  __export(polyline_exports, {
6174
+ all: () => all6,
5211
6175
  clear_all: () => clear_all,
5212
6176
  delete: () => delete_polyline,
5213
6177
  delete_polyline: () => delete_polyline,
@@ -5217,7 +6181,6 @@ __export(polyline_exports, {
5217
6181
  reset_id_counter: () => reset_id_counter
5218
6182
  });
5219
6183
  var polylineIdCounter = 0;
5220
- var allPolylines = [];
5221
6184
  function generateId() {
5222
6185
  return `polyline_${++polylineIdCounter}`;
5223
6186
  }
@@ -5244,28 +6207,39 @@ function new_polyline(points, curved = false, closed = false, xloc2 = "bar_index
5244
6207
  line_width,
5245
6208
  force_overlay
5246
6209
  };
5247
- allPolylines.push(polyline);
5248
- return polyline;
6210
+ return register("polyline", polyline);
5249
6211
  }
5250
6212
  function delete_polyline(id) {
5251
- const index = allPolylines.findIndex((p) => p.id === id.id);
5252
- if (index !== -1) {
5253
- allPolylines.splice(index, 1);
5254
- }
6213
+ remove3("polyline", id);
5255
6214
  }
5256
6215
  function get_all() {
5257
- return [...allPolylines];
6216
+ return all("polyline");
6217
+ }
6218
+ function all6() {
6219
+ return all("polyline");
5258
6220
  }
5259
6221
  function clear_all() {
5260
- allPolylines.length = 0;
6222
+ for (const p of all("polyline")) remove3("polyline", p);
5261
6223
  }
5262
6224
  function reset_id_counter() {
5263
6225
  polylineIdCounter = 0;
5264
6226
  }
5265
6227
 
6228
+ // src/text/index.ts
6229
+ var text_exports = {};
6230
+ __export(text_exports, {
6231
+ format_bold: () => format_bold,
6232
+ format_italic: () => format_italic,
6233
+ format_none: () => format_none
6234
+ });
6235
+ var format_none = 0;
6236
+ var format_bold = 1;
6237
+ var format_italic = 2;
6238
+
5266
6239
  // src/ta-series.ts
5267
6240
  var ta_series_exports = {};
5268
6241
  __export(ta_series_exports, {
6242
+ accdist: () => accdist2,
5269
6243
  alma: () => alma2,
5270
6244
  atr: () => atr2,
5271
6245
  barssince: () => barssince2,
@@ -5288,6 +6262,7 @@ __export(ta_series_exports, {
5288
6262
  highestbars: () => highestbars2,
5289
6263
  hma: () => hma2,
5290
6264
  ichimoku: () => ichimoku2,
6265
+ iii: () => iii2,
5291
6266
  kc: () => kc2,
5292
6267
  kcw: () => kcw2,
5293
6268
  linreg: () => linreg2,
@@ -5300,11 +6275,15 @@ __export(ta_series_exports, {
5300
6275
  min: () => min5,
5301
6276
  mode: () => mode4,
5302
6277
  mom: () => mom2,
6278
+ nvi: () => nvi2,
6279
+ obv: () => obv2,
5303
6280
  percentile_linear_interpolation: () => percentile_linear_interpolation3,
5304
6281
  percentile_nearest_rank: () => percentile_nearest_rank3,
5305
6282
  percentrank: () => percentrank3,
5306
6283
  pivothigh: () => pivothigh2,
5307
6284
  pivotlow: () => pivotlow2,
6285
+ pvi: () => pvi2,
6286
+ pvt: () => pvt2,
5308
6287
  range: () => range3,
5309
6288
  rci: () => rci2,
5310
6289
  rising: () => rising2,
@@ -5323,9 +6302,12 @@ __export(ta_series_exports, {
5323
6302
  valuewhen: () => valuewhen2,
5324
6303
  variance: () => variance3,
5325
6304
  vwap: () => vwap2,
6305
+ vwapBands: () => vwapBands,
5326
6306
  vwma: () => vwma2,
6307
+ wad: () => wad2,
5327
6308
  wma: () => wma2,
5328
6309
  wpr: () => wpr2,
6310
+ wvad: () => wvad2,
5329
6311
  zigzag: () => zigzag2
5330
6312
  });
5331
6313
  function sma2(source, length2) {
@@ -5376,11 +6358,9 @@ function bb2(source, length2, mult2) {
5376
6358
  const lowerSeries = Series.fromArray(bars, lowerVals);
5377
6359
  return [upperSeries, basisSeries, lowerSeries];
5378
6360
  }
5379
- function stdev3(source, length2) {
6361
+ function stdev3(source, length2, biased = true) {
5380
6362
  const bars = source.bars;
5381
- const sourceValues = source.toArray();
5382
- const result = stdev(sourceValues, length2);
5383
- return Series.fromArray(bars, result);
6363
+ return Series.fromArray(bars, stdev(source.toArray(), length2, biased));
5384
6364
  }
5385
6365
  function atr2(bars, length2) {
5386
6366
  const high = bars.map((b2) => b2.high);
@@ -5396,6 +6376,40 @@ function tr2(bars, handle_na = false) {
5396
6376
  const result = tr(handle_na, high, low, close);
5397
6377
  return Series.fromArray(bars, result);
5398
6378
  }
6379
+ var col2 = (bars, f) => bars.map((b2) => b2[f] ?? NaN);
6380
+ function obv2(bars) {
6381
+ return Series.fromArray(bars, obv(col2(bars, "close"), col2(bars, "volume")));
6382
+ }
6383
+ function pvt2(bars) {
6384
+ return Series.fromArray(bars, pvt(col2(bars, "close"), col2(bars, "volume")));
6385
+ }
6386
+ function accdist2(bars) {
6387
+ return Series.fromArray(
6388
+ bars,
6389
+ accdist(col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6390
+ );
6391
+ }
6392
+ function nvi2(bars) {
6393
+ return Series.fromArray(bars, nvi(col2(bars, "close"), col2(bars, "volume")));
6394
+ }
6395
+ function pvi2(bars) {
6396
+ return Series.fromArray(bars, pvi(col2(bars, "close"), col2(bars, "volume")));
6397
+ }
6398
+ function iii2(bars) {
6399
+ return Series.fromArray(
6400
+ bars,
6401
+ iii(col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6402
+ );
6403
+ }
6404
+ function wad2(bars) {
6405
+ return Series.fromArray(bars, wad(col2(bars, "high"), col2(bars, "low"), col2(bars, "close")));
6406
+ }
6407
+ function wvad2(bars) {
6408
+ return Series.fromArray(
6409
+ bars,
6410
+ wvad(col2(bars, "open"), col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6411
+ );
6412
+ }
5399
6413
  function stoch2(source, high, low, length2) {
5400
6414
  const bars = source.bars;
5401
6415
  const sourceValues = source.toArray();
@@ -5487,12 +6501,14 @@ function supertrend2(bars, factor, atrLength) {
5487
6501
  const dirSeries = Series.fromArray(bars, dirVals);
5488
6502
  return [trendSeries, dirSeries];
5489
6503
  }
5490
- function vwap2(source, volume) {
6504
+ function vwap2(source, volume, anchor) {
5491
6505
  const bars = source.bars;
5492
- const sourceValues = source.toArray();
5493
- const volumeValues = volume.toArray();
5494
- const result = vwap(sourceValues, volumeValues);
5495
- return Series.fromArray(bars, result);
6506
+ return Series.fromArray(bars, vwap(source.toArray(), volume.toArray(), anchor?.toArray()));
6507
+ }
6508
+ function vwapBands(source, volume, anchor, stdev_mult) {
6509
+ const bars = source.bars;
6510
+ const [m, u, l] = vwap(source.toArray(), volume.toArray(), anchor?.toArray(), stdev_mult);
6511
+ return [Series.fromArray(bars, m), Series.fromArray(bars, u), Series.fromArray(bars, l)];
5496
6512
  }
5497
6513
  function ichimoku2(bars, conversionPeriods, basePeriods, laggingSpan2Periods, displacement) {
5498
6514
  const high = bars.map((b2) => b2.high);
@@ -5677,10 +6693,9 @@ function kcw2(bars, source, length2 = 20, mult2 = 2, useTrueRange = true) {
5677
6693
  const result = kcw(source.toArray(), length2, mult2, useTrueRange, high, low, close);
5678
6694
  return Series.fromArray(bars, result);
5679
6695
  }
5680
- function range3(high, low) {
5681
- const bars = high.bars;
5682
- const result = range(high.toArray(), low.toArray());
5683
- return Series.fromArray(bars, result);
6696
+ function range3(source, length2) {
6697
+ const bars = source.bars;
6698
+ return Series.fromArray(bars, range(source.toArray(), length2));
5684
6699
  }
5685
6700
  function highestbars2(source, length2) {
5686
6701
  const bars = source.bars;
@@ -5692,15 +6707,13 @@ function lowestbars2(source, length2) {
5692
6707
  const result = lowestbars(source.toArray(), length2);
5693
6708
  return Series.fromArray(bars, result);
5694
6709
  }
5695
- function max5(source1, source2) {
5696
- const bars = source1.bars;
5697
- const result = max(source1.toArray(), source2.toArray());
5698
- return Series.fromArray(bars, result);
6710
+ function max5(source) {
6711
+ const bars = source.bars;
6712
+ return Series.fromArray(bars, max(source.toArray()));
5699
6713
  }
5700
- function min5(source1, source2) {
5701
- const bars = source1.bars;
5702
- const result = min(source1.toArray(), source2.toArray());
5703
- return Series.fromArray(bars, result);
6714
+ function min5(source) {
6715
+ const bars = source.bars;
6716
+ return Series.fromArray(bars, min(source.toArray()));
5704
6717
  }
5705
6718
  function cog2(source, length2 = 10) {
5706
6719
  const bars = source.bars;
@@ -5783,6 +6796,15 @@ var ta = {
5783
6796
  lowestbars: lowestbars2,
5784
6797
  max: max5,
5785
6798
  min: min5,
6799
+ vwapBands,
6800
+ obv: obv2,
6801
+ pvt: pvt2,
6802
+ accdist: accdist2,
6803
+ nvi: nvi2,
6804
+ pvi: pvi2,
6805
+ iii: iii2,
6806
+ wad: wad2,
6807
+ wvad: wvad2,
5786
6808
  cog: cog2,
5787
6809
  mode: mode4,
5788
6810
  percentile_linear_interpolation: percentile_linear_interpolation3,
@@ -5792,11 +6814,23 @@ var ta = {
5792
6814
 
5793
6815
  // src/utils/index.ts
5794
6816
  function isNA(value) {
5795
- return value === null || value === void 0 || Number.isNaN(value);
6817
+ return value === null || value === void 0 || Number.isNaN(value) || isDeleted(value);
5796
6818
  }
5797
6819
  function nz(value, defaultValue = 0) {
5798
6820
  return isNA(value) ? defaultValue : value;
5799
6821
  }
6822
+ function fixnan(source) {
6823
+ let last2;
6824
+ let seen = false;
6825
+ return source.map((v) => {
6826
+ if (!isNA(v)) {
6827
+ last2 = v;
6828
+ seen = true;
6829
+ return v;
6830
+ }
6831
+ return seen ? last2 : v;
6832
+ });
6833
+ }
5800
6834
  function ohlcFromBars(bars) {
5801
6835
  return {
5802
6836
  open: bars.map((b2) => b2.open),
@@ -6188,16 +7222,78 @@ var input = {
6188
7222
  title: options.title,
6189
7223
  options: options.options
6190
7224
  };
7225
+ },
7226
+ /**
7227
+ * Create a timeframe input parameter (PineScript `input.timeframe`)
7228
+ * @param defaultValue - Default timeframe string ("60", "1D", "W"); "" means the chart timeframe
7229
+ * @param options - Additional options (title, options for dropdown)
7230
+ * @returns Input value object
7231
+ *
7232
+ * @example
7233
+ * ```typescript
7234
+ * const htf = input.timeframe('1D', { title: 'Higher timeframe' });
7235
+ * console.log(htf.value); // '1D'
7236
+ * ```
7237
+ */
7238
+ timeframe(defaultValue, options = {}) {
7239
+ return {
7240
+ type: "timeframe",
7241
+ defaultValue,
7242
+ value: defaultValue,
7243
+ title: options.title,
7244
+ options: options.options
7245
+ };
7246
+ },
7247
+ /**
7248
+ * Create a session input parameter (PineScript `input.session`)
7249
+ * @param defaultValue - Default session string ("0930-1600", "0930-1600:23456")
7250
+ * @param options - Additional options (title, options for dropdown)
7251
+ * @returns Input value object
7252
+ *
7253
+ * @example
7254
+ * ```typescript
7255
+ * const rth = input.session('0930-1600', { title: 'Regular hours' });
7256
+ * console.log(rth.value); // '0930-1600'
7257
+ * ```
7258
+ */
7259
+ session(defaultValue, options = {}) {
7260
+ return {
7261
+ type: "session",
7262
+ defaultValue,
7263
+ value: defaultValue,
7264
+ title: options.title,
7265
+ options: options.options
7266
+ };
7267
+ },
7268
+ /**
7269
+ * Create a date/time input parameter (PineScript `input.time`)
7270
+ * @param defaultValue - Default UNIX time in milliseconds, e.g. `time.timestamp('2024-01-01')`
7271
+ * @param options - Additional options (title)
7272
+ * @returns Input value object
7273
+ *
7274
+ * @example
7275
+ * ```typescript
7276
+ * const start = input.time(time.timestamp('2024-01-01'), { title: 'Start' });
7277
+ * console.log(start.value); // 1704067200000
7278
+ * ```
7279
+ */
7280
+ time(defaultValue, options = {}) {
7281
+ return {
7282
+ type: "time",
7283
+ defaultValue,
7284
+ value: defaultValue,
7285
+ title: options.title
7286
+ };
6191
7287
  }
6192
7288
  };
6193
7289
  Object.freeze(input);
6194
7290
 
6195
7291
  // src/plot.ts
6196
- function plot(values, times, options = {}) {
7292
+ function plot(values2, times, options = {}) {
6197
7293
  const result = [];
6198
7294
  const offset = options.offset ?? 0;
6199
- for (let i = 0; i < values.length; i++) {
6200
- const value = values[i];
7295
+ for (let i = 0; i < values2.length; i++) {
7296
+ const value = values2[i];
6201
7297
  const timeIndex = i + offset;
6202
7298
  if (value === null || value === void 0 || Number.isNaN(value)) {
6203
7299
  continue;
@@ -6212,10 +7308,10 @@ function plot(values, times, options = {}) {
6212
7308
  }
6213
7309
  return result;
6214
7310
  }
6215
- function createPlot(id, values, times, options = {}) {
7311
+ function createPlot(id, values2, times, options = {}) {
6216
7312
  return {
6217
7313
  id,
6218
- data: plot(values, times, options),
7314
+ data: plot(values2, times, options),
6219
7315
  options
6220
7316
  };
6221
7317
  }
@@ -6456,6 +7552,42 @@ function input_string(defval, title, options) {
6456
7552
  const value = context2.inputs.getValue(id);
6457
7553
  return typeof value === "string" ? value : defval;
6458
7554
  }
7555
+ function registerOnce(config) {
7556
+ const context2 = getContext();
7557
+ if (!registeredInputs.has(config.id)) {
7558
+ context2.inputs.registerInput(config);
7559
+ registeredInputs.set(config.id, true);
7560
+ if (autoRecalculateEnabled) {
7561
+ context2.inputs.onInputChange((changedId) => {
7562
+ if (changedId === config.id) {
7563
+ recalculate();
7564
+ }
7565
+ });
7566
+ }
7567
+ }
7568
+ return context2.inputs.getValue(config.id);
7569
+ }
7570
+ function input_timeframe(defval, title, options) {
7571
+ if (!getContext()) {
7572
+ return defval;
7573
+ }
7574
+ const value = registerOnce({ id: generateInputId(title, defval, "timeframe"), type: "timeframe", defval, title, options });
7575
+ return typeof value === "string" ? value : defval;
7576
+ }
7577
+ function input_session(defval, title, options) {
7578
+ if (!getContext()) {
7579
+ return defval;
7580
+ }
7581
+ const value = registerOnce({ id: generateInputId(title, defval, "session"), type: "session", defval, title, options });
7582
+ return typeof value === "string" ? value : defval;
7583
+ }
7584
+ function input_time(defval, title) {
7585
+ if (!getContext()) {
7586
+ return defval;
7587
+ }
7588
+ const value = registerOnce({ id: generateInputId(title, defval, "time"), type: "time", defval, title });
7589
+ return typeof value === "number" ? value : defval;
7590
+ }
6459
7591
  function input_source(defval, title) {
6460
7592
  const context2 = getContext();
6461
7593
  if (!context2) {
@@ -6678,7 +7810,7 @@ var SimpleInputAdapter = class {
6678
7810
  validatedValue = Math.floor(validatedValue);
6679
7811
  }
6680
7812
  }
6681
- if (config.type === "string" && config.options && typeof value === "string") {
7813
+ if ((config.type === "string" || config.type === "timeframe" || config.type === "session") && config.options && typeof value === "string") {
6682
7814
  if (!config.options.includes(value)) {
6683
7815
  return;
6684
7816
  }
@@ -6726,8 +7858,8 @@ var SimpleInputAdapter = class {
6726
7858
  };
6727
7859
 
6728
7860
  // src/index.ts
6729
- var VERSION = "0.5.0";
6730
- var info = {
7861
+ var VERSION = "0.6.1";
7862
+ var info2 = {
6731
7863
  name: "OakScriptJS",
6732
7864
  version: VERSION,
6733
7865
  description: "Simplified PineScript-like library - Series + TA functions",
@@ -6740,8 +7872,8 @@ var info = {
6740
7872
  minimal: "No DSL layer - complexity in transpiler"
6741
7873
  },
6742
7874
  namespaces: {
6743
- core: ["ta", "math", "array", "str", "color", "time", "matrix"],
6744
- drawing: ["line", "box", "label", "linefill", "chartPoint", "polyline"],
7875
+ core: ["ta", "math", "array", "map", "str", "color", "time", "timeframe", "matrix"],
7876
+ drawing: ["line", "box", "label", "linefill", "chartPoint", "polyline", "text"],
6745
7877
  runtime: ["setContext", "plot", "hline", "input_*"],
6746
7878
  indicator: ["indicator", "input", "plotHelper", "createPlot"]
6747
7879
  }