oakscriptjs 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) 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/drawing/registry.d.ts +19 -0
  7. package/dist/drawing/registry.d.ts.map +1 -0
  8. package/dist/index.cjs +1661 -571
  9. package/dist/index.d.ts +8 -5
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.mjs +1661 -571
  12. package/dist/input.d.ts +7 -1
  13. package/dist/input.d.ts.map +1 -1
  14. package/dist/label/index.d.ts +12 -4
  15. package/dist/label/index.d.ts.map +1 -1
  16. package/dist/line/index.d.ts +11 -3
  17. package/dist/line/index.d.ts.map +1 -1
  18. package/dist/linefill/index.d.ts +3 -1
  19. package/dist/linefill/index.d.ts.map +1 -1
  20. package/dist/map/index.d.ts +14 -0
  21. package/dist/map/index.d.ts.map +1 -0
  22. package/dist/polyline/index.d.ts +1 -0
  23. package/dist/polyline/index.d.ts.map +1 -1
  24. package/dist/runtime/adapters/SimpleInputAdapter.d.ts.map +1 -1
  25. package/dist/runtime/index.cjs +40 -1
  26. package/dist/runtime/index.d.ts +1 -1
  27. package/dist/runtime/index.d.ts.map +1 -1
  28. package/dist/runtime/index.mjs +40 -1
  29. package/dist/runtime/inputs.d.ts +3 -0
  30. package/dist/runtime/inputs.d.ts.map +1 -1
  31. package/dist/runtime/types.d.ts +1 -1
  32. package/dist/runtime/types.d.ts.map +1 -1
  33. package/dist/script/index.cjs +3042 -622
  34. package/dist/script/index.d.ts +277 -12
  35. package/dist/script/index.d.ts.map +1 -1
  36. package/dist/script/index.mjs +3042 -622
  37. package/dist/security/resample.d.ts +13 -0
  38. package/dist/security/resample.d.ts.map +1 -0
  39. package/dist/session/bars.d.ts +34 -0
  40. package/dist/session/bars.d.ts.map +1 -0
  41. package/dist/session/calendar.d.ts +31 -0
  42. package/dist/session/calendar.d.ts.map +1 -0
  43. package/dist/str/dateformat.d.ts +2 -0
  44. package/dist/str/dateformat.d.ts.map +1 -0
  45. package/dist/str/index.d.ts +1 -1
  46. package/dist/str/index.d.ts.map +1 -1
  47. package/dist/str/messageformat.d.ts +2 -0
  48. package/dist/str/messageformat.d.ts.map +1 -0
  49. package/dist/str/numberformat.d.ts +3 -0
  50. package/dist/str/numberformat.d.ts.map +1 -0
  51. package/dist/ta/index.d.ts +14 -5
  52. package/dist/ta/index.d.ts.map +1 -1
  53. package/dist/ta-series.d.ts +23 -5
  54. package/dist/ta-series.d.ts.map +1 -1
  55. package/dist/text/index.d.ts +4 -0
  56. package/dist/text/index.d.ts.map +1 -0
  57. package/dist/time/datestring.d.ts +2 -0
  58. package/dist/time/datestring.d.ts.map +1 -0
  59. package/dist/time/index.d.ts +11 -0
  60. package/dist/time/index.d.ts.map +1 -1
  61. package/dist/time/session.d.ts +2 -0
  62. package/dist/time/session.d.ts.map +1 -0
  63. package/dist/time/timezone.d.ts +13 -0
  64. package/dist/time/timezone.d.ts.map +1 -0
  65. package/dist/timeframe/index.d.ts +17 -0
  66. package/dist/timeframe/index.d.ts.map +1 -0
  67. package/dist/types/index.d.ts +7 -0
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/metadata.d.ts +1 -1
  70. package/dist/types/metadata.d.ts.map +1 -1
  71. package/dist/utils/index.d.ts +1 -0
  72. package/dist/utils/index.d.ts.map +1 -1
  73. 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") {
@@ -48,6 +48,7 @@ __export(index_exports, {
48
48
  cum: () => cum2,
49
49
  ema: () => ema2,
50
50
  exp: () => exp,
51
+ fixnan: () => fixnan,
51
52
  floor: () => floor,
52
53
  getClose: () => getClose,
53
54
  getContext: () => getContext,
@@ -57,18 +58,22 @@ __export(index_exports, {
57
58
  getSourceSeries: () => getSourceSeries,
58
59
  hline: () => hline,
59
60
  indicator: () => indicator,
60
- info: () => info,
61
+ info: () => info2,
61
62
  input: () => input,
62
63
  input_bool: () => input_bool,
63
64
  input_float: () => input_float,
64
65
  input_int: () => input_int,
66
+ input_session: () => input_session,
65
67
  input_source: () => input_source,
66
68
  input_string: () => input_string,
69
+ input_time: () => input_time,
70
+ input_timeframe: () => input_timeframe,
67
71
  label: () => label_exports,
68
72
  line: () => line_exports,
69
73
  linefill: () => linefill_exports,
70
74
  log: () => log,
71
75
  macd: () => macd2,
76
+ map: () => map_exports,
72
77
  math: () => math_exports,
73
78
  matrix: () => matrix_exports,
74
79
  max: () => max2,
@@ -96,7 +101,9 @@ __export(index_exports, {
96
101
  ta: () => ta_series_exports,
97
102
  taCore: () => ta_exports,
98
103
  tan: () => tan,
104
+ text: () => text_exports,
99
105
  time: () => time_exports,
106
+ timeframe: () => timeframe_exports,
100
107
  tr: () => tr2,
101
108
  vwap: () => vwap2,
102
109
  xloc: () => xloc,
@@ -115,6 +122,7 @@ var xloc = {
115
122
  // src/ta/index.ts
116
123
  var ta_exports = {};
117
124
  __export(ta_exports, {
125
+ accdist: () => accdist,
118
126
  alma: () => alma,
119
127
  atr: () => atr,
120
128
  barssince: () => barssince,
@@ -137,6 +145,7 @@ __export(ta_exports, {
137
145
  highestbars: () => highestbars,
138
146
  hma: () => hma,
139
147
  ichimoku: () => ichimoku,
148
+ iii: () => iii,
140
149
  kc: () => kc,
141
150
  kcw: () => kcw,
142
151
  linreg: () => linreg,
@@ -149,12 +158,16 @@ __export(ta_exports, {
149
158
  min: () => min,
150
159
  mode: () => mode,
151
160
  mom: () => mom,
161
+ nvi: () => nvi,
162
+ obv: () => obv,
152
163
  percentile_linear_interpolation: () => percentile_linear_interpolation,
153
164
  percentile_nearest_rank: () => percentile_nearest_rank,
154
165
  percentrank: () => percentrank,
155
166
  pivot_point_levels: () => pivot_point_levels,
156
167
  pivothigh: () => pivothigh,
157
168
  pivotlow: () => pivotlow,
169
+ pvi: () => pvi,
170
+ pvt: () => pvt,
158
171
  range: () => range,
159
172
  rci: () => rci,
160
173
  rising: () => rising,
@@ -173,8 +186,10 @@ __export(ta_exports, {
173
186
  variance: () => variance,
174
187
  vwap: () => vwap,
175
188
  vwma: () => vwma,
189
+ wad: () => wad,
176
190
  wma: () => wma,
177
191
  wpr: () => wpr,
192
+ wvad: () => wvad,
178
193
  zigzag: () => zigzag
179
194
  });
180
195
  function sma(source, length2) {
@@ -274,23 +289,42 @@ function bb(series, length2, mult2) {
274
289
  }
275
290
  return [basis, upper2, lower2];
276
291
  }
277
- function stdev(source, length2) {
278
- const result = [];
292
+ function stdev(source, length2, biased = true) {
279
293
  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;
294
+ return source.map((_, i) => {
295
+ const values2 = lastValues(source, i, len);
296
+ if (!values2) return NaN;
297
+ const mean = values2.reduce((a, b2) => a + b2, 0) / len;
298
+ const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
299
+ return Math.sqrt(squares / (biased ? len : len - 1));
300
+ });
301
+ }
302
+ function lastValues(source, i, length2) {
303
+ const values2 = [];
304
+ for (let j = i; j >= 0 && values2.length < length2; j--) {
305
+ const x = source[j];
306
+ if (!Number.isNaN(x)) values2.push(x);
307
+ }
308
+ return values2.length === length2 ? values2 : null;
309
+ }
310
+ function windowUntilNa(source, i, length2) {
311
+ const values2 = [];
312
+ for (let j = 0; j < length2 && i - j >= 0; j++) {
313
+ const x = source[i - j];
314
+ if (Number.isNaN(x)) break;
315
+ values2.push([x, -j]);
316
+ }
317
+ return values2;
318
+ }
319
+ function extremeOffset(source, length2, isHigher) {
320
+ return source.map((_, i) => {
321
+ if (i < length2 - 1) return NaN;
322
+ const w = windowUntilNa(source, i, length2);
323
+ if (w.length === 0) return 0;
324
+ let best = w[0];
325
+ for (const item of w) if (isHigher(item[0], best[0])) best = item;
326
+ return best[1];
327
+ });
294
328
  }
295
329
  function crossover(series1, series2) {
296
330
  const result = [];
@@ -469,47 +503,26 @@ function wma(source, length2) {
469
503
  return result;
470
504
  }
471
505
  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;
506
+ return source.map((_, i) => {
507
+ if (i < length2 - 1) return NaN;
508
+ const w = windowUntilNa(source, i, length2);
509
+ return w.length ? Math.max(...w.map((x) => x[0])) : NaN;
510
+ });
487
511
  }
488
512
  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;
513
+ return source.map((_, i) => {
514
+ if (i < length2 - 1) return NaN;
515
+ const w = windowUntilNa(source, i, length2);
516
+ return w.length ? Math.min(...w.map((x) => x[0])) : NaN;
517
+ });
504
518
  }
505
519
  function cum(source) {
506
- const result = [];
507
520
  let sum4 = 0;
508
- for (let i = 0; i < source.length; i++) {
509
- sum4 += source[i];
510
- result.push(sum4);
511
- }
512
- return result;
521
+ return source.map((v) => {
522
+ if (Number.isNaN(v)) return NaN;
523
+ sum4 += v;
524
+ return sum4;
525
+ });
513
526
  }
514
527
  function cross(source1, source2) {
515
528
  const result = [];
@@ -638,21 +651,21 @@ function median(source, length2) {
638
651
  if (i < length2 - 1) {
639
652
  result.push(NaN);
640
653
  } else {
641
- const values = [];
654
+ const values2 = [];
642
655
  for (let j = 0; j < length2; j++) {
643
656
  if (!isNaN(source[i - j])) {
644
- values.push(source[i - j]);
657
+ values2.push(source[i - j]);
645
658
  }
646
659
  }
647
- if (values.length === 0) {
660
+ if (values2.length === 0) {
648
661
  result.push(NaN);
649
662
  } 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);
663
+ values2.sort((a, b2) => a - b2);
664
+ const mid = Math.floor(values2.length / 2);
665
+ if (values2.length % 2 === 0) {
666
+ result.push((values2[mid - 1] + values2[mid]) / 2);
654
667
  } else {
655
- result.push(values[mid]);
668
+ result.push(values2[mid]);
656
669
  }
657
670
  }
658
671
  }
@@ -982,89 +995,44 @@ function sar(start, inc, max6, high, low, close) {
982
995
  }
983
996
  return result;
984
997
  }
998
+ function pivot(source, leftbars, rightbars, isHigh) {
999
+ const beatsLeft = isHigh ? (x, v) => x > v : (x, v) => x < v;
1000
+ const beatsRight = isHigh ? (x, v) => x >= v : (x, v) => x <= v;
1001
+ return source.map((_, i) => {
1002
+ const center = i - rightbars;
1003
+ if (center - leftbars < 0) return NaN;
1004
+ const v = source[center];
1005
+ if (Number.isNaN(v)) return NaN;
1006
+ for (let j = 1; j <= leftbars; j++) {
1007
+ const x = source[center - j];
1008
+ if (Number.isNaN(x)) break;
1009
+ if (beatsLeft(x, v)) return NaN;
1010
+ }
1011
+ for (let j = 1; j <= rightbars; j++) {
1012
+ const x = source[center + j];
1013
+ if (Number.isNaN(x)) break;
1014
+ if (beatsRight(x, v)) return NaN;
1015
+ }
1016
+ return v;
1017
+ });
1018
+ }
985
1019
  function pivothigh(sourceOrLeftbars, leftbarsOrRightbars, rightbars, high) {
986
- let source;
987
- let leftbars;
988
- let right;
989
1020
  if (rightbars === void 0) {
990
1021
  if (!high) {
991
1022
  throw new Error("ta.pivothigh() requires high series when using two-parameter version.");
992
1023
  }
993
- source = high;
994
- leftbars = sourceOrLeftbars;
995
- right = leftbarsOrRightbars;
996
- } else {
997
- source = sourceOrLeftbars;
998
- leftbars = leftbarsOrRightbars;
999
- right = rightbars;
1000
- }
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
+ return pivot(high, sourceOrLeftbars, leftbarsOrRightbars, true);
1024
1025
  }
1025
- return result;
1026
+ return pivot(sourceOrLeftbars, leftbarsOrRightbars, rightbars, true);
1026
1027
  }
1027
1028
  function pivotlow(sourceOrLeftbars, leftbarsOrRightbars, rightbars, low) {
1028
- let source;
1029
- let leftbars;
1030
- let right;
1031
1029
  if (rightbars === void 0) {
1032
1030
  if (!low) {
1033
1031
  throw new Error("ta.pivotlow() requires low series when using two-parameter version.");
1034
1032
  }
1035
- source = low;
1036
- leftbars = sourceOrLeftbars;
1037
- right = leftbarsOrRightbars;
1038
- } else {
1039
- source = sourceOrLeftbars;
1040
- leftbars = leftbarsOrRightbars;
1041
- right = rightbars;
1033
+ return pivot(low, sourceOrLeftbars, leftbarsOrRightbars, false);
1042
1034
  }
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;
1035
+ return pivot(sourceOrLeftbars, leftbarsOrRightbars, rightbars, false);
1068
1036
  }
1069
1037
  function barssince(condition) {
1070
1038
  const result = [];
@@ -1258,27 +1226,38 @@ function wpr(high, low, close, length2 = 14) {
1258
1226
  }
1259
1227
  return result;
1260
1228
  }
1261
- function vwap(source, volume) {
1229
+ function vwap(source, volume, anchor, stdev_mult) {
1262
1230
  if (source.length !== volume.length) {
1263
1231
  throw new Error("ta.vwap: source and volume must have the same length");
1264
1232
  }
1265
- const result = [];
1266
- let cumulativePV = 0;
1267
- let cumulativeVolume = 0;
1233
+ const mid = [];
1234
+ const upper2 = [];
1235
+ const lower2 = [];
1236
+ let sumPV = 0;
1237
+ let sumV = 0;
1238
+ let sumPPV = 0;
1268
1239
  for (let i = 0; i < source.length; i++) {
1269
- if (isNaN(source[i]) || isNaN(volume[i])) {
1270
- result.push(NaN);
1271
- continue;
1240
+ if (anchor && anchor[i]) {
1241
+ sumPV = 0;
1242
+ sumV = 0;
1243
+ sumPPV = 0;
1272
1244
  }
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);
1245
+ const s = source[i];
1246
+ const v = volume[i];
1247
+ if (!Number.isNaN(s) && !Number.isNaN(v)) {
1248
+ sumPV += s * v;
1249
+ sumV += v;
1250
+ sumPPV += s * s * v;
1251
+ }
1252
+ const m = sumV === 0 ? NaN : sumPV / sumV;
1253
+ mid.push(m);
1254
+ if (stdev_mult !== void 0) {
1255
+ const sd = Math.sqrt(Math.max(0, sumPPV / sumV - m * m));
1256
+ upper2.push(m + stdev_mult * sd);
1257
+ lower2.push(m - stdev_mult * sd);
1279
1258
  }
1280
1259
  }
1281
- return result;
1260
+ return stdev_mult === void 0 ? mid : [mid, upper2, lower2];
1282
1261
  }
1283
1262
  function alma(source, length2 = 9, offset = 0.85, sigma = 6, floor2 = false) {
1284
1263
  const result = [];
@@ -1320,85 +1299,31 @@ function kcw(source, length2 = 20, mult2 = 2, useTrueRange = true, high, low, cl
1320
1299
  }
1321
1300
  return result;
1322
1301
  }
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;
1302
+ function range(source, length2) {
1303
+ return source.map((_, i) => {
1304
+ const values2 = lastValues(source, i, length2);
1305
+ return values2 ? Math.max(...values2) - Math.min(...values2) : NaN;
1306
+ });
1336
1307
  }
1337
1308
  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;
1309
+ return extremeOffset(source, length2, (a, b2) => a >= b2);
1355
1310
  }
1356
1311
  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;
1312
+ return extremeOffset(source, length2, (a, b2) => a <= b2);
1374
1313
  }
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;
1314
+ function max(source) {
1315
+ let best = NaN;
1316
+ return source.map((x) => {
1317
+ if (!Number.isNaN(x) && !(x <= best)) best = x;
1318
+ return best;
1319
+ });
1388
1320
  }
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;
1321
+ function min(source) {
1322
+ let best = NaN;
1323
+ return source.map((x) => {
1324
+ if (!Number.isNaN(x) && !(x >= best)) best = x;
1325
+ return best;
1326
+ });
1402
1327
  }
1403
1328
  function cog(source, length2 = 10) {
1404
1329
  const result = [];
@@ -1431,19 +1356,19 @@ function mode(source, length2) {
1431
1356
  result.push(NaN);
1432
1357
  continue;
1433
1358
  }
1434
- const values = [];
1359
+ const values2 = [];
1435
1360
  for (let j = 0; j < length2; j++) {
1436
1361
  const value = source[i - j];
1437
1362
  if (!isNaN(value)) {
1438
- values.push(value);
1363
+ values2.push(value);
1439
1364
  }
1440
1365
  }
1441
- if (values.length === 0) {
1366
+ if (values2.length === 0) {
1442
1367
  result.push(NaN);
1443
1368
  continue;
1444
1369
  }
1445
1370
  const frequencyMap = /* @__PURE__ */ new Map();
1446
- for (const value of values) {
1371
+ for (const value of values2) {
1447
1372
  frequencyMap.set(value, (frequencyMap.get(value) || 0) + 1);
1448
1373
  }
1449
1374
  let maxFrequency = 0;
@@ -1469,16 +1394,16 @@ function percentile_linear_interpolation(source, length2, percentage) {
1469
1394
  result.push(NaN);
1470
1395
  continue;
1471
1396
  }
1472
- const values = [];
1397
+ const values2 = [];
1473
1398
  for (let j = 0; j < length2; j++) {
1474
1399
  const value = source[i - j];
1475
- values.push(value);
1400
+ values2.push(value);
1476
1401
  }
1477
- if (values.some((v) => isNaN(v))) {
1402
+ if (values2.some((v) => isNaN(v))) {
1478
1403
  result.push(NaN);
1479
1404
  continue;
1480
1405
  }
1481
- const sorted = [...values].sort((a, b2) => a - b2);
1406
+ const sorted = [...values2].sort((a, b2) => a - b2);
1482
1407
  const position = percentage / 100 * (sorted.length - 1);
1483
1408
  const lowerIndex = Math.floor(position);
1484
1409
  const upperIndex = Math.ceil(position);
@@ -1499,18 +1424,18 @@ function percentile_nearest_rank(source, length2, percentage) {
1499
1424
  result.push(NaN);
1500
1425
  continue;
1501
1426
  }
1502
- const values = [];
1427
+ const values2 = [];
1503
1428
  for (let j = 0; j < length2; j++) {
1504
1429
  const value = source[i - j];
1505
1430
  if (!isNaN(value)) {
1506
- values.push(value);
1431
+ values2.push(value);
1507
1432
  }
1508
1433
  }
1509
- if (values.length === 0) {
1434
+ if (values2.length === 0) {
1510
1435
  result.push(NaN);
1511
1436
  continue;
1512
1437
  }
1513
- const sorted = [...values].sort((a, b2) => a - b2);
1438
+ const sorted = [...values2].sort((a, b2) => a - b2);
1514
1439
  if (percentage >= 100) {
1515
1440
  result.push(sorted[sorted.length - 1]);
1516
1441
  continue;
@@ -1528,15 +1453,15 @@ function rci(source, length2) {
1528
1453
  result.push(NaN);
1529
1454
  continue;
1530
1455
  }
1531
- const values = [];
1456
+ const values2 = [];
1532
1457
  for (let j = 0; j < length2; j++) {
1533
- values.push(source[i - length2 + 1 + j]);
1458
+ values2.push(source[i - length2 + 1 + j]);
1534
1459
  }
1535
- if (values.some((v) => isNaN(v))) {
1460
+ if (values2.some((v) => isNaN(v))) {
1536
1461
  result.push(NaN);
1537
1462
  continue;
1538
1463
  }
1539
- const indexed = values.map((value, index) => ({ value, index }));
1464
+ const indexed = values2.map((value, index) => ({ value, index }));
1540
1465
  const sorted = [...indexed].sort((a, b2) => a.value - b2.value);
1541
1466
  const ranks = new Array(length2).fill(0);
1542
1467
  let currentRank = 1;
@@ -1900,23 +1825,86 @@ function zigzag(deviation = 5, depth = 10, backstep = 3, source, high, low) {
1900
1825
  if (potentialPivot) {
1901
1826
  confirmedPivots.push(potentialPivot);
1902
1827
  }
1903
- for (const pivot of confirmedPivots) {
1904
- zigzagValues[pivot.index] = pivot.price;
1905
- isPivot[pivot.index] = true;
1828
+ for (const pivot2 of confirmedPivots) {
1829
+ zigzagValues[pivot2.index] = pivot2.price;
1830
+ isPivot[pivot2.index] = true;
1906
1831
  }
1907
1832
  let currentDir = 0;
1908
1833
  let pivotIdx = 0;
1909
1834
  const numConfirmed = lastPotentialWasAdded ? confirmedPivots.length - 1 : confirmedPivots.length;
1910
1835
  for (let i = 0; i < length2; i++) {
1911
1836
  while (pivotIdx < numConfirmed && confirmedPivots[pivotIdx].index <= i) {
1912
- const pivot = confirmedPivots[pivotIdx];
1913
- currentDir = pivot.type === "low" ? 1 : -1;
1837
+ const pivot2 = confirmedPivots[pivotIdx];
1838
+ currentDir = pivot2.type === "low" ? 1 : -1;
1914
1839
  pivotIdx++;
1915
1840
  }
1916
1841
  directions[i] = currentDir;
1917
1842
  }
1918
1843
  return [zigzagValues, directions, isPivot];
1919
1844
  }
1845
+ function obv(close, volume) {
1846
+ return cum(close.map((c, i) => i === 0 ? NaN : Math.sign(c - close[i - 1]) * volume[i]));
1847
+ }
1848
+ function pvt(close, volume) {
1849
+ return cum(
1850
+ close.map((c, i) => i === 0 ? NaN : (c - close[i - 1]) / close[i - 1] * volume[i])
1851
+ );
1852
+ }
1853
+ function accdist(high, low, close, volume) {
1854
+ return cum(
1855
+ close.map((c, i) => {
1856
+ const h = high[i];
1857
+ const l = low[i];
1858
+ return h === l ? 0 : (2 * c - l - h) / (h - l) * volume[i];
1859
+ })
1860
+ );
1861
+ }
1862
+ function iii(high, low, close, volume) {
1863
+ return close.map((c, i) => {
1864
+ const range4 = high[i] - low[i];
1865
+ return range4 === 0 ? NaN : (2 * c - high[i] - low[i]) / range4 * volume[i];
1866
+ });
1867
+ }
1868
+ function wvad(open, high, low, close, volume) {
1869
+ return close.map((c, i) => {
1870
+ const range4 = high[i] - low[i];
1871
+ return range4 === 0 ? NaN : (c - open[i]) / range4 * volume[i];
1872
+ });
1873
+ }
1874
+ function wad(high, low, close) {
1875
+ return cum(
1876
+ close.map((c, i) => {
1877
+ const prev = i === 0 ? NaN : close[i - 1];
1878
+ const mom3 = c - prev;
1879
+ if (mom3 > 0) return c - Math.min(low[i], prev);
1880
+ if (mom3 < 0) return c - Math.max(high[i], prev);
1881
+ return 0;
1882
+ })
1883
+ );
1884
+ }
1885
+ function volumeIndex(close, volume, use) {
1886
+ const result = [];
1887
+ let prevIndex = NaN;
1888
+ for (let i = 0; i < close.length; i++) {
1889
+ const prev = !prevIndex ? 1 : prevIndex;
1890
+ const c = close[i];
1891
+ const prevC = i === 0 ? NaN : close[i - 1];
1892
+ let value = prev;
1893
+ if (c && prevC) {
1894
+ const prevV = i === 0 || Number.isNaN(volume[i - 1]) ? 0 : volume[i - 1];
1895
+ if (use(volume[i], prevV)) value = prev + (c - prevC) / prevC * prev;
1896
+ }
1897
+ result.push(value);
1898
+ prevIndex = value;
1899
+ }
1900
+ return result;
1901
+ }
1902
+ function nvi(close, volume) {
1903
+ return volumeIndex(close, volume, (v, prevV) => v < prevV);
1904
+ }
1905
+ function pvi(close, volume) {
1906
+ return volumeIndex(close, volume, (v, prevV) => v > prevV);
1907
+ }
1920
1908
 
1921
1909
  // src/math/index.ts
1922
1910
  var math_exports = {};
@@ -2093,8 +2081,8 @@ var Series = class _Series {
2093
2081
  * @param field - Field to extract ('open', 'high', 'low', 'close', 'volume')
2094
2082
  * @returns Series with extracted field values
2095
2083
  */
2096
- static fromBars(bars, field) {
2097
- return new _Series(bars, (bar) => bar[field] ?? NaN);
2084
+ static fromBars(bars, field2) {
2085
+ return new _Series(bars, (bar) => bar[field2] ?? NaN);
2098
2086
  }
2099
2087
  /**
2100
2088
  * Create a constant series (same value for all bars)
@@ -2111,8 +2099,8 @@ var Series = class _Series {
2111
2099
  * @param values - Array of values
2112
2100
  * @returns Series
2113
2101
  */
2114
- static fromArray(bars, values) {
2115
- return new _Series(bars, (_bar, i) => values[i] ?? NaN);
2102
+ static fromArray(bars, values2) {
2103
+ return new _Series(bars, (_bar, i) => values2[i] ?? NaN);
2116
2104
  }
2117
2105
  // ============================================
2118
2106
  // Arithmetic Operations
@@ -2402,8 +2390,8 @@ var Series = class _Series {
2402
2390
  * @returns New Series with computed values and no closure dependencies
2403
2391
  */
2404
2392
  materialize() {
2405
- const values = this.toArray();
2406
- const valuesCopy = [...values];
2393
+ const values2 = this.toArray();
2394
+ const valuesCopy = [...values2];
2407
2395
  return _Series.fromArray(this.dataSource, valuesCopy);
2408
2396
  }
2409
2397
  /**
@@ -2433,16 +2421,16 @@ var Series = class _Series {
2433
2421
  * @returns Value at that index
2434
2422
  */
2435
2423
  get(index) {
2436
- const values = this.toArray();
2437
- return values[index] ?? NaN;
2424
+ const values2 = this.toArray();
2425
+ return values2[index] ?? NaN;
2438
2426
  }
2439
2427
  /**
2440
2428
  * Get the last value (most recent bar)
2441
2429
  * @returns Most recent value
2442
2430
  */
2443
2431
  last() {
2444
- const values = this.toArray();
2445
- return values[values.length - 1] ?? NaN;
2432
+ const values2 = this.toArray();
2433
+ return values2[values2.length - 1] ?? NaN;
2446
2434
  }
2447
2435
  /**
2448
2436
  * Get number of values
@@ -2456,11 +2444,11 @@ var Series = class _Series {
2456
2444
  * @returns Array of { time, value } objects
2457
2445
  */
2458
2446
  toTimeValuePairs() {
2459
- const values = this.toArray();
2447
+ const values2 = this.toArray();
2460
2448
  const bars = this.dataSource.bars;
2461
2449
  return bars.map((bar, i) => ({
2462
2450
  time: bar.time,
2463
- value: values[i]
2451
+ value: values2[i]
2464
2452
  })).filter((point) => !Number.isNaN(point.value));
2465
2453
  }
2466
2454
  };
@@ -2534,60 +2522,60 @@ function round(value, precision) {
2534
2522
  const multiplier = Math.pow(10, precision);
2535
2523
  return Math.round(value * multiplier) / multiplier;
2536
2524
  }
2537
- function max2(...values) {
2538
- const hasSeries = values.some((v) => v instanceof Series);
2525
+ function max2(...values2) {
2526
+ const hasSeries = values2.some((v) => v instanceof Series);
2539
2527
  if (!hasSeries) {
2540
- return Math.max(...values);
2528
+ return Math.max(...values2);
2541
2529
  }
2542
- const firstSeries = values.find((v) => v instanceof Series);
2530
+ const firstSeries = values2.find((v) => v instanceof Series);
2543
2531
  const bars = firstSeries.bars;
2544
2532
  const length2 = bars.length;
2545
- const valueArrays = values.map(
2533
+ const valueArrays = values2.map(
2546
2534
  (v) => v instanceof Series ? v.toArray() : null
2547
2535
  );
2548
2536
  const result = [];
2549
2537
  for (let i = 0; i < length2; i++) {
2550
- const nums = values.map(
2538
+ const nums = values2.map(
2551
2539
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2552
2540
  );
2553
2541
  result.push(Math.max(...nums));
2554
2542
  }
2555
2543
  return Series.fromArray(bars, result);
2556
2544
  }
2557
- function min2(...values) {
2558
- const hasSeries = values.some((v) => v instanceof Series);
2545
+ function min2(...values2) {
2546
+ const hasSeries = values2.some((v) => v instanceof Series);
2559
2547
  if (!hasSeries) {
2560
- return Math.min(...values);
2548
+ return Math.min(...values2);
2561
2549
  }
2562
- const firstSeries = values.find((v) => v instanceof Series);
2550
+ const firstSeries = values2.find((v) => v instanceof Series);
2563
2551
  const bars = firstSeries.bars;
2564
2552
  const length2 = bars.length;
2565
- const valueArrays = values.map(
2553
+ const valueArrays = values2.map(
2566
2554
  (v) => v instanceof Series ? v.toArray() : null
2567
2555
  );
2568
2556
  const result = [];
2569
2557
  for (let i = 0; i < length2; i++) {
2570
- const nums = values.map(
2558
+ const nums = values2.map(
2571
2559
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2572
2560
  );
2573
2561
  result.push(Math.min(...nums));
2574
2562
  }
2575
2563
  return Series.fromArray(bars, result);
2576
2564
  }
2577
- function avg(...values) {
2578
- const hasSeries = values.some((v) => v instanceof Series);
2565
+ function avg(...values2) {
2566
+ const hasSeries = values2.some((v) => v instanceof Series);
2579
2567
  if (!hasSeries) {
2580
- return values.reduce((a, b2) => a + b2, 0) / values.length;
2568
+ return values2.reduce((a, b2) => a + b2, 0) / values2.length;
2581
2569
  }
2582
- const firstSeries = values.find((v) => v instanceof Series);
2570
+ const firstSeries = values2.find((v) => v instanceof Series);
2583
2571
  const bars = firstSeries.bars;
2584
2572
  const length2 = bars.length;
2585
- const valueArrays = values.map(
2573
+ const valueArrays = values2.map(
2586
2574
  (v) => v instanceof Series ? v.toArray() : null
2587
2575
  );
2588
2576
  const result = [];
2589
2577
  for (let i = 0; i < length2; i++) {
2590
- const nums = values.map(
2578
+ const nums = values2.map(
2591
2579
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2592
2580
  );
2593
2581
  const sum4 = nums.reduce((a, b2) => a + b2, 0);
@@ -2821,10 +2809,10 @@ function sign(value) {
2821
2809
  }
2822
2810
  return value > 0 ? 1 : value < 0 ? -1 : 0;
2823
2811
  }
2824
- function round_to_mintick(number, mintick) {
2825
- if (number instanceof Series) {
2826
- const bars = number.bars;
2827
- const valueArray = number.toArray();
2812
+ function round_to_mintick(number2, mintick) {
2813
+ if (number2 instanceof Series) {
2814
+ const bars = number2.bars;
2815
+ const valueArray = number2.toArray();
2828
2816
  const length2 = bars.length;
2829
2817
  if (mintick === void 0) {
2830
2818
  throw new Error(
@@ -2848,7 +2836,7 @@ function round_to_mintick(number, mintick) {
2848
2836
  }
2849
2837
  return Series.fromArray(bars, result);
2850
2838
  }
2851
- if (isNaN(number)) {
2839
+ if (isNaN(number2)) {
2852
2840
  return NaN;
2853
2841
  }
2854
2842
  if (mintick === void 0) {
@@ -2857,9 +2845,9 @@ function round_to_mintick(number, mintick) {
2857
2845
  );
2858
2846
  }
2859
2847
  if (mintick === 0) {
2860
- return number;
2848
+ return number2;
2861
2849
  }
2862
- return Math.round(number / mintick) * mintick;
2850
+ return Math.round(number2 / mintick) * mintick;
2863
2851
  }
2864
2852
  var pi = Math.PI;
2865
2853
  var e = Math.E;
@@ -2925,9 +2913,9 @@ __export(array_exports, {
2925
2913
  unshift: () => unshift,
2926
2914
  variance: () => variance2
2927
2915
  });
2928
- function new_array(size2 = 0, initial_value) {
2916
+ function new_array(size3 = 0, initial_value) {
2929
2917
  const arr = [];
2930
- for (let i = 0; i < size2; i++) {
2918
+ for (let i = 0; i < size3; i++) {
2931
2919
  arr.push(initial_value);
2932
2920
  }
2933
2921
  return arr;
@@ -3001,11 +2989,13 @@ function sum2(id) {
3001
2989
  function avg2(id) {
3002
2990
  return sum2(id) / size(id);
3003
2991
  }
3004
- function min3(id) {
3005
- return Math.min(...id);
2992
+ function min3(id, nth = 0) {
2993
+ const values2 = id.filter((v) => !Number.isNaN(v)).sort((a, b2) => a - b2);
2994
+ return values2.length ? values2[Math.min(nth, values2.length - 1)] : NaN;
3006
2995
  }
3007
- function max3(id) {
3008
- return Math.max(...id);
2996
+ function max3(id, nth = 0) {
2997
+ const values2 = id.filter((v) => !Number.isNaN(v)).sort((a, b2) => b2 - a);
2998
+ return values2.length ? values2[Math.min(nth, values2.length - 1)] : NaN;
3009
2999
  }
3010
3000
  function median2(id) {
3011
3001
  const sorted = [...id].sort((a, b2) => a - b2);
@@ -3026,16 +3016,15 @@ function mode2(id) {
3026
3016
  }
3027
3017
  return mode5;
3028
3018
  }
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);
3019
+ function stdev2(id, biased = true) {
3020
+ return Math.sqrt(variance2(id, biased));
3034
3021
  }
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);
3022
+ function variance2(id, biased = true) {
3023
+ const values2 = id.filter((v) => !Number.isNaN(v));
3024
+ if (!values2.length) return NaN;
3025
+ const mean = values2.reduce((a, b2) => a + b2, 0) / values2.length;
3026
+ const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
3027
+ return squares / (biased ? values2.length : values2.length - 1);
3039
3028
  }
3040
3029
  function fill(id, value, index_from = 0, index_to) {
3041
3030
  const end = index_to ?? id.length;
@@ -3043,8 +3032,8 @@ function fill(id, value, index_from = 0, index_to) {
3043
3032
  id[i] = value;
3044
3033
  }
3045
3034
  }
3046
- function from(id) {
3047
- return copy(id);
3035
+ function from(...values2) {
3036
+ return [...values2];
3048
3037
  }
3049
3038
  function first(id) {
3050
3039
  return id[0];
@@ -3052,38 +3041,38 @@ function first(id) {
3052
3041
  function last(id) {
3053
3042
  return id[id.length - 1];
3054
3043
  }
3055
- function some(id, predicate) {
3056
- return id.some(predicate);
3044
+ function some(id) {
3045
+ return id.some((v) => v === true);
3057
3046
  }
3058
- function every(id, predicate) {
3059
- return id.every(predicate);
3047
+ function every(id) {
3048
+ return id.length > 0 && id.every((v) => v === true);
3060
3049
  }
3061
- function new_bool(size2 = 0, initial_value = false) {
3062
- return new_array(size2, initial_value);
3050
+ function new_bool(size3 = 0, initial_value = false) {
3051
+ return new_array(size3, initial_value);
3063
3052
  }
3064
- function new_float(size2 = 0, initial_value = NaN) {
3065
- return new_array(size2, initial_value);
3053
+ function new_float(size3 = 0, initial_value = NaN) {
3054
+ return new_array(size3, initial_value);
3066
3055
  }
3067
- function new_int(size2 = 0, initial_value = NaN) {
3068
- return new_array(size2, initial_value);
3056
+ function new_int(size3 = 0, initial_value = NaN) {
3057
+ return new_array(size3, initial_value);
3069
3058
  }
3070
- function new_string(size2 = 0, initial_value) {
3071
- return new_array(size2, initial_value);
3059
+ function new_string(size3 = 0, initial_value) {
3060
+ return new_array(size3, initial_value);
3072
3061
  }
3073
- function new_color(size2 = 0, initial_value) {
3074
- return new_array(size2, initial_value);
3062
+ function new_color(size3 = 0, initial_value) {
3063
+ return new_array(size3, initial_value);
3075
3064
  }
3076
- function new_line(size2 = 0, initial_value) {
3077
- return new_array(size2, initial_value);
3065
+ function new_line(size3 = 0, initial_value) {
3066
+ return new_array(size3, initial_value);
3078
3067
  }
3079
- function new_box(size2 = 0, initial_value) {
3080
- return new_array(size2, initial_value);
3068
+ function new_box(size3 = 0, initial_value) {
3069
+ return new_array(size3, initial_value);
3081
3070
  }
3082
- function new_label(size2 = 0, initial_value) {
3083
- return new_array(size2, initial_value);
3071
+ function new_label(size3 = 0, initial_value) {
3072
+ return new_array(size3, initial_value);
3084
3073
  }
3085
- function new_linefill(size2 = 0, initial_value) {
3086
- return new_array(size2, initial_value);
3074
+ function new_linefill(size3 = 0, initial_value) {
3075
+ return new_array(size3, initial_value);
3087
3076
  }
3088
3077
  function abs2(id) {
3089
3078
  return id.map((x) => Math.abs(x));
@@ -3223,8 +3212,70 @@ function standardize(id) {
3223
3212
  }
3224
3213
  return id.map((value) => (value - mean) / stdDev);
3225
3214
  }
3226
- function newtype(size2 = 0, initial_value) {
3227
- return new_array(size2, initial_value);
3215
+ function newtype(size3 = 0, initial_value) {
3216
+ return new_array(size3, initial_value);
3217
+ }
3218
+
3219
+ // src/map/index.ts
3220
+ var map_exports = {};
3221
+ __export(map_exports, {
3222
+ MAX_SIZE: () => MAX_SIZE,
3223
+ clear: () => clear2,
3224
+ contains: () => contains,
3225
+ copy: () => copy2,
3226
+ get: () => get2,
3227
+ keys: () => keys,
3228
+ new_map: () => new_map,
3229
+ put: () => put,
3230
+ put_all: () => put_all,
3231
+ remove: () => remove2,
3232
+ size: () => size2,
3233
+ values: () => values
3234
+ });
3235
+ var MAX_SIZE = 5e4;
3236
+ function tooLarge(size3) {
3237
+ return new RangeError(`A map cannot have more than ${MAX_SIZE} key-value pairs. The current size is ${size3}.`);
3238
+ }
3239
+ function new_map() {
3240
+ return /* @__PURE__ */ new Map();
3241
+ }
3242
+ function put(id, key, value) {
3243
+ const previous = id.get(key);
3244
+ if (!id.has(key) && id.size >= MAX_SIZE) throw tooLarge(id.size + 1);
3245
+ id.set(key, value);
3246
+ return previous;
3247
+ }
3248
+ function put_all(id, id2) {
3249
+ let size3 = id.size;
3250
+ for (const key of id2.keys()) if (!id.has(key)) size3++;
3251
+ if (size3 > MAX_SIZE) throw tooLarge(size3);
3252
+ for (const [key, value] of id2) id.set(key, value);
3253
+ }
3254
+ function get2(id, key) {
3255
+ return id.get(key);
3256
+ }
3257
+ function contains(id, key) {
3258
+ return id.has(key);
3259
+ }
3260
+ function remove2(id, key) {
3261
+ const value = id.get(key);
3262
+ id.delete(key);
3263
+ return value;
3264
+ }
3265
+ function size2(id) {
3266
+ return id.size;
3267
+ }
3268
+ function clear2(id) {
3269
+ id.clear();
3270
+ }
3271
+ function keys(id) {
3272
+ return [...id.keys()];
3273
+ }
3274
+ function values(id) {
3275
+ return [...id.values()];
3276
+ }
3277
+ function copy2(id) {
3278
+ return new Map(id);
3228
3279
  }
3229
3280
 
3230
3281
  // src/str/index.ts
@@ -3232,7 +3283,7 @@ var str_exports = {};
3232
3283
  __export(str_exports, {
3233
3284
  charAt: () => charAt,
3234
3285
  concat: () => concat2,
3235
- contains: () => contains,
3286
+ contains: () => contains2,
3236
3287
  endswith: () => endswith,
3237
3288
  format: () => format,
3238
3289
  format_time: () => format_time,
@@ -3253,15 +3304,486 @@ __export(str_exports, {
3253
3304
  trimRight: () => trimRight,
3254
3305
  upper: () => upper
3255
3306
  });
3307
+
3308
+ // src/str/numberformat.ts
3309
+ var patterns = /* @__PURE__ */ new Map();
3310
+ function parsePattern(pattern) {
3311
+ const cached = patterns.get(pattern);
3312
+ if (cached) return cached;
3313
+ let prefix = "";
3314
+ let suffix = "";
3315
+ let number2 = "";
3316
+ let percent = false;
3317
+ let phase = "prefix";
3318
+ for (let i = 0; i < pattern.length; i++) {
3319
+ const ch = pattern[i];
3320
+ let literal;
3321
+ if (ch === "'") {
3322
+ const end = pattern.indexOf("'", i + 1);
3323
+ if (end === i + 1) {
3324
+ literal = "'";
3325
+ i = end;
3326
+ } else {
3327
+ literal = pattern.slice(i + 1, end === -1 ? void 0 : end);
3328
+ i = end === -1 ? pattern.length : end;
3329
+ }
3330
+ } else if (phase !== "suffix" && ("#0,.".includes(ch) || phase === "number" && ch === "E")) {
3331
+ phase = "number";
3332
+ number2 += ch;
3333
+ continue;
3334
+ } else {
3335
+ if (ch === "%") percent = true;
3336
+ literal = ch;
3337
+ }
3338
+ if (phase === "number") phase = "suffix";
3339
+ if (phase === "prefix") prefix += literal;
3340
+ else suffix += literal;
3341
+ }
3342
+ const [mantissa = "", exp2] = number2.split("E");
3343
+ const [intPart = "", fracPart = ""] = mantissa.split(".");
3344
+ const lastComma = intPart.lastIndexOf(",");
3345
+ const parsed = {
3346
+ prefix,
3347
+ suffix,
3348
+ // as in Java, a pattern with a decimal point and no '0' at all ("#.##") shows one integer digit
3349
+ minInt: !mantissa.includes("0") && mantissa.includes(".") ? 1 : [...intPart].filter((c) => c === "0").length,
3350
+ minFrac: [...fracPart].filter((c) => c === "0").length,
3351
+ maxFrac: [...fracPart].filter((c) => c === "0" || c === "#").length,
3352
+ grouping: lastComma === -1 ? 0 : intPart.length - lastComma - 1,
3353
+ percent,
3354
+ exponent: exp2 === void 0 ? null : exp2.length,
3355
+ hasDigits: /[0#]/.test(mantissa)
3356
+ };
3357
+ patterns.set(pattern, parsed);
3358
+ return parsed;
3359
+ }
3360
+ function shortestDigits(x) {
3361
+ const m = /^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(Math.abs(x)));
3362
+ const all7 = m[1] + (m[2] ?? "");
3363
+ let intLen = m[1].length + Number(m[3] ?? 0);
3364
+ const lead = all7.length - all7.replace(/^0+/, "").length;
3365
+ intLen -= lead;
3366
+ const digits = all7.slice(lead).replace(/0+$/, "");
3367
+ return { digits, intLen: digits ? intLen : 0 };
3368
+ }
3369
+ function exactDigits(x) {
3370
+ const abs3 = Math.abs(x);
3371
+ if (abs3 === 0) return { digits: "", intLen: 0 };
3372
+ const view = new DataView(new ArrayBuffer(8));
3373
+ view.setFloat64(0, abs3);
3374
+ const bits = view.getBigUint64(0);
3375
+ const expBits = Number(bits >> 52n & 0x7ffn);
3376
+ let mant = bits & 0xfffffffffffffn;
3377
+ const e2 = expBits === 0 ? -1074 : expBits - 1075;
3378
+ if (expBits !== 0) mant |= 1n << 52n;
3379
+ let str;
3380
+ let fracDigits;
3381
+ if (e2 >= 0) {
3382
+ str = (mant << BigInt(e2)).toString();
3383
+ fracDigits = 0;
3384
+ } else {
3385
+ str = (mant * 5n ** BigInt(-e2)).toString();
3386
+ fracDigits = -e2;
3387
+ }
3388
+ const intLen = str.length - fracDigits;
3389
+ const lead = str.length - str.replace(/^0+/, "").length;
3390
+ const digits = str.slice(lead).replace(/0+$/, "");
3391
+ return { digits, intLen: intLen - lead };
3392
+ }
3393
+ function roundDigits(d, frac, mode5) {
3394
+ const keep = d.intLen + frac;
3395
+ if (keep >= d.digits.length) return d;
3396
+ if (keep < 0) return { digits: "", intLen: 0 };
3397
+ const first2 = d.digits.charCodeAt(keep) - 48;
3398
+ let up;
3399
+ if (mode5 === "halfUpShortest") up = first2 >= 5;
3400
+ else if (first2 !== 5) up = first2 > 5;
3401
+ else if (d.digits.length > keep + 1) up = true;
3402
+ else up = keep > 0 && (d.digits.charCodeAt(keep - 1) - 48) % 2 === 1;
3403
+ let kept = d.digits.slice(0, keep);
3404
+ let intLen = d.intLen;
3405
+ if (up) {
3406
+ const n = (BigInt(kept || "0") + 1n).toString();
3407
+ if (n.length > kept.length) intLen += 1;
3408
+ kept = n;
3409
+ }
3410
+ kept = kept.replace(/0+$/, "");
3411
+ return { digits: kept, intLen: kept ? intLen : 0 };
3412
+ }
3413
+ function group(int, size3) {
3414
+ if (!size3 || int.length <= size3) return int;
3415
+ const parts = [];
3416
+ for (let end = int.length; end > 0; end -= size3) parts.unshift(int.slice(Math.max(0, end - size3), end));
3417
+ return parts.join(",");
3418
+ }
3419
+ function layout(d, p) {
3420
+ let int = d.intLen > 0 ? d.digits.slice(0, d.intLen).padEnd(d.intLen, "0") : "";
3421
+ int = int.replace(/^0+/, "").padStart(p.minInt, "0");
3422
+ let frac = d.intLen < 0 ? "0".repeat(-d.intLen) + d.digits : d.digits.slice(Math.max(0, d.intLen));
3423
+ frac = frac.slice(0, p.maxFrac).replace(/0+$/, "").padEnd(p.minFrac, "0");
3424
+ if (!int && !frac) int = "0";
3425
+ return group(int, p.grouping) + (frac ? "." + frac : "");
3426
+ }
3427
+ function formatNumber(value, pattern, mode5) {
3428
+ if (Number.isNaN(value)) return "NaN";
3429
+ const p = parsePattern(pattern);
3430
+ if (!Number.isFinite(value)) return (value < 0 ? "-" : "") + p.prefix + "\u221E" + p.suffix;
3431
+ const x = p.percent ? value * 100 : value;
3432
+ const toDigits = mode5 === "halfUpShortest" ? shortestDigits : exactDigits;
3433
+ let body;
3434
+ let isZero;
3435
+ if (p.exponent !== null) {
3436
+ const rounded = roundDigits(toDigits(x), p.maxFrac, mode5);
3437
+ const intDigits = Math.max(p.minInt, 1);
3438
+ isZero = rounded.digits === "";
3439
+ let exponent = isZero ? 0 : rounded.intLen - intDigits;
3440
+ let mant = roundDigits({ digits: rounded.digits, intLen: isZero ? 0 : intDigits }, p.maxFrac, mode5);
3441
+ if (mant.intLen > intDigits) {
3442
+ exponent += 1;
3443
+ mant = { digits: mant.digits, intLen: intDigits };
3444
+ }
3445
+ const e2 = String(Math.abs(exponent)).padStart(p.exponent, "0");
3446
+ body = layout(mant, p) + "E" + (exponent < 0 ? "-" : "") + e2;
3447
+ } else {
3448
+ const rounded = roundDigits(toDigits(x), p.hasDigits ? p.maxFrac : 0, mode5);
3449
+ isZero = rounded.digits === "";
3450
+ body = p.hasDigits ? layout(rounded, p) : layout(rounded, { ...p, minInt: 0, maxFrac: 0, minFrac: 0 });
3451
+ }
3452
+ const negative = x < 0 && (!isZero || !p.hasDigits);
3453
+ return (negative ? "-" : "") + p.prefix + body + p.suffix;
3454
+ }
3455
+
3456
+ // src/time/timezone.ts
3457
+ var MS_PER_SECOND = 1e3;
3458
+ var MS_PER_DAY = 864e5;
3459
+ var MAX_OFFSET_SECONDS = 18 * 3600;
3460
+ var OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\d{1,2})(?::?(\d{2})(?::?(\d{2}))?)?)?$/;
3461
+ var REJECTED_NAMES = /* @__PURE__ */ new Set(["EST", "MST", "HST"]);
3462
+ var canonicalNames;
3463
+ function hasTimeZoneCase(name) {
3464
+ if (name.split("/").some((segment) => !/^[A-Z]/.test(segment))) return false;
3465
+ canonicalNames ??= new Map(Intl.supportedValuesOf("timeZone").map((n) => [n.toLowerCase(), n]));
3466
+ const canonical = canonicalNames.get(name.toLowerCase());
3467
+ return canonical === void 0 || canonical === name;
3468
+ }
3469
+ var zones = /* @__PURE__ */ new Map();
3470
+ function resolveZone(timezone) {
3471
+ let zone = zones.get(timezone);
3472
+ if (zone) return zone;
3473
+ const invalid = () => new RangeError(
3474
+ `Invalid time zone "${timezone}": use UTC/GMT offset notation ("UTC-5", "GMT+0530") or an IANA name ("America/New_York")`
3475
+ );
3476
+ const m = OFFSET_NOTATION.exec(timezone);
3477
+ if (m) {
3478
+ const [, sign2, h = "0", mi = "0", s] = m;
3479
+ const minutes = Number(mi);
3480
+ const seconds = s === void 0 ? 0 : Number(s);
3481
+ if (minutes > 59 || seconds > 59 || s !== void 0 && h.length !== 2) throw invalid();
3482
+ const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;
3483
+ if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();
3484
+ zone = { kind: "fixed", offsetMs: (sign2 === "-" ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };
3485
+ } else {
3486
+ if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();
3487
+ let format2;
3488
+ try {
3489
+ format2 = new Intl.DateTimeFormat("en-US", {
3490
+ timeZone: timezone,
3491
+ hourCycle: "h23",
3492
+ year: "numeric",
3493
+ month: "numeric",
3494
+ day: "numeric",
3495
+ hour: "numeric",
3496
+ minute: "numeric",
3497
+ second: "numeric"
3498
+ });
3499
+ } catch {
3500
+ throw invalid();
3501
+ }
3502
+ zone = { kind: "iana", format: format2 };
3503
+ }
3504
+ zones.set(timezone, zone);
3505
+ return zone;
3506
+ }
3507
+ function offsetAt(zone, time) {
3508
+ if (zone.kind === "fixed") return zone.offsetMs;
3509
+ const wholeSecond = Math.floor(time / 1e3) * 1e3;
3510
+ const f = {};
3511
+ for (const part of zone.format.formatToParts(wholeSecond)) {
3512
+ if (part.type !== "literal") f[part.type] = Number(part.value);
3513
+ }
3514
+ const local = Date.UTC(f.year, f.month - 1, f.day, f.hour, f.minute, f.second);
3515
+ return local - wholeSecond;
3516
+ }
3517
+ function zoneOffset(time, timezone) {
3518
+ return offsetAt(resolveZone(timezone), time);
3519
+ }
3520
+ function zonedFields(time, timezone) {
3521
+ const local = new Date(time + offsetAt(resolveZone(timezone), time));
3522
+ return {
3523
+ year: local.getUTCFullYear(),
3524
+ month: local.getUTCMonth() + 1,
3525
+ day: local.getUTCDate(),
3526
+ hour: local.getUTCHours(),
3527
+ minute: local.getUTCMinutes(),
3528
+ second: local.getUTCSeconds(),
3529
+ dayOfWeek: local.getUTCDay() + 1
3530
+ };
3531
+ }
3532
+ function zonedToUnix(timezone, year2, month2, day, hour2 = 0, minute2 = 0, second2 = 0) {
3533
+ const zone = resolveZone(timezone);
3534
+ const local = Date.UTC(year2, month2 - 1, day, hour2, minute2, second2);
3535
+ if (zone.kind === "fixed") return local - zone.offsetMs;
3536
+ const before = offsetAt(zone, local - MS_PER_DAY);
3537
+ const after = offsetAt(zone, local + MS_PER_DAY);
3538
+ const candidates = [local - before, local - after].filter((t2) => local - offsetAt(zone, t2) === t2);
3539
+ if (candidates.length) return Math.max(...candidates);
3540
+ return local - before;
3541
+ }
3542
+
3543
+ // src/str/dateformat.ts
3544
+ var MONTHS = [
3545
+ "January",
3546
+ "February",
3547
+ "March",
3548
+ "April",
3549
+ "May",
3550
+ "June",
3551
+ "July",
3552
+ "August",
3553
+ "September",
3554
+ "October",
3555
+ "November",
3556
+ "December"
3557
+ ];
3558
+ var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
3559
+ var pad = (n, width) => String(n).padStart(width, "0");
3560
+ function zoneName(time, timezone, offsetMs) {
3561
+ if (timezone === "Etc/UTC") return "UTC";
3562
+ if (/^(UTC|GMT)/.test(timezone)) {
3563
+ if (offsetMs === 0) return "GMT";
3564
+ const minutes = Math.abs(offsetMs) / 6e4;
3565
+ return `GMT${offsetMs < 0 ? "-" : "+"}${pad(Math.floor(minutes / 60), 2)}:${pad(minutes % 60, 2)}`;
3566
+ }
3567
+ const part = new Intl.DateTimeFormat("en-US", { timeZone: timezone, timeZoneName: "short" }).formatToParts(time).find((p) => p.type === "timeZoneName");
3568
+ return part?.value ?? timezone;
3569
+ }
3570
+ function weekOfYear(year2, month2, day) {
3571
+ const date = Date.UTC(year2, month2 - 1, day);
3572
+ const dow = new Date(date).getUTCDay();
3573
+ const weekStart = date - dow * 864e5;
3574
+ if (weekStart + 6 * 864e5 >= Date.UTC(year2 + 1, 0, 1)) return 1;
3575
+ const jan1 = Date.UTC(year2, 0, 1);
3576
+ const jan1Dow = new Date(jan1).getUTCDay();
3577
+ return Math.floor((date - jan1 + jan1Dow * 864e5) / (7 * 864e5)) + 1;
3578
+ }
3579
+ function formatDate(time, pattern, timezone) {
3580
+ if (Number.isNaN(time)) return "NaN";
3581
+ const f = zonedFields(time, timezone);
3582
+ const offset = zoneOffset(time, timezone);
3583
+ const ms = (time % 1e3 + 1e3) % 1e3;
3584
+ const dayOfYear = (Date.UTC(f.year, f.month - 1, f.day) - Date.UTC(f.year, 0, 1)) / 864e5 + 1;
3585
+ let out = "";
3586
+ for (let i = 0; i < pattern.length; ) {
3587
+ const ch = pattern[i];
3588
+ if (ch === "'") {
3589
+ const end = pattern.indexOf("'", i + 1);
3590
+ if (end === i + 1) {
3591
+ out += "'";
3592
+ i += 2;
3593
+ } else {
3594
+ out += pattern.slice(i + 1, end === -1 ? void 0 : end);
3595
+ i = end === -1 ? pattern.length : end + 1;
3596
+ }
3597
+ continue;
3598
+ }
3599
+ if (!/[A-Za-z]/.test(ch)) {
3600
+ out += ch;
3601
+ i++;
3602
+ continue;
3603
+ }
3604
+ let n = 1;
3605
+ while (pattern[i + n] === ch) n++;
3606
+ i += n;
3607
+ const hour12 = f.hour % 12;
3608
+ switch (ch) {
3609
+ case "y":
3610
+ out += n === 2 ? pad(f.year % 100, 2) : pad(f.year, n);
3611
+ break;
3612
+ case "M":
3613
+ out += n >= 4 ? MONTHS[f.month - 1] : n === 3 ? MONTHS[f.month - 1].slice(0, 3) : pad(f.month, n);
3614
+ break;
3615
+ case "d":
3616
+ out += pad(f.day, n);
3617
+ break;
3618
+ case "E":
3619
+ out += n >= 4 ? DAYS[f.dayOfWeek - 1] : DAYS[f.dayOfWeek - 1].slice(0, 3);
3620
+ break;
3621
+ case "u":
3622
+ out += pad(f.dayOfWeek === 1 ? 7 : f.dayOfWeek - 1, n);
3623
+ break;
3624
+ case "D":
3625
+ out += pad(dayOfYear, n);
3626
+ break;
3627
+ case "w":
3628
+ out += pad(weekOfYear(f.year, f.month, f.day), n);
3629
+ break;
3630
+ case "H":
3631
+ out += pad(f.hour, n);
3632
+ break;
3633
+ case "k":
3634
+ out += pad(f.hour === 0 ? 24 : f.hour, n);
3635
+ break;
3636
+ case "K":
3637
+ out += pad(hour12, n);
3638
+ break;
3639
+ case "h":
3640
+ out += pad(hour12 === 0 ? 12 : hour12, n);
3641
+ break;
3642
+ case "a":
3643
+ out += f.hour < 12 ? "AM" : "PM";
3644
+ break;
3645
+ case "m":
3646
+ out += pad(f.minute, n);
3647
+ break;
3648
+ case "s":
3649
+ out += pad(f.second, n);
3650
+ break;
3651
+ case "S":
3652
+ out += pad(ms, n);
3653
+ break;
3654
+ case "Z": {
3655
+ const minutes = Math.abs(offset) / 6e4;
3656
+ out += (offset < 0 ? "-" : "+") + pad(Math.floor(minutes / 60), 2) + pad(minutes % 60, 2);
3657
+ break;
3658
+ }
3659
+ case "z":
3660
+ out += zoneName(time, timezone, offset);
3661
+ break;
3662
+ default:
3663
+ throw new SyntaxError(`Unsupported date pattern letter "${ch}" in "${pattern}"`);
3664
+ }
3665
+ }
3666
+ return out;
3667
+ }
3668
+
3669
+ // src/str/messageformat.ts
3670
+ var DATE_STYLES = {
3671
+ short: "M/d/yy",
3672
+ medium: "MMM d, yyyy",
3673
+ long: "MMMM d, yyyy",
3674
+ full: "EEEE, MMMM d, yyyy"
3675
+ };
3676
+ var TIME_STYLES = {
3677
+ short: "h:mm\u202Fa",
3678
+ medium: "h:mm:ss\u202Fa",
3679
+ long: "h:mm:ss\u202Fa z",
3680
+ full: "h:mm:ss\u202Fa z"
3681
+ };
3682
+ function number(value, pattern) {
3683
+ return typeof value === "number" ? formatNumber(value, pattern, "halfEvenExact") : String(value);
3684
+ }
3685
+ function choice(value, spec) {
3686
+ const options = spec.split("|").map((part) => {
3687
+ const m = /^\s*(-?[\d.]+|-?∞)\s*([#<≤])(.*)$/.exec(part);
3688
+ if (!m) throw new SyntaxError(`Invalid choice format "${spec}"`);
3689
+ const limit = m[1].includes("\u221E") ? m[1].startsWith("-") ? -Infinity : Infinity : Number(m[1]);
3690
+ return { limit: m[2] === "<" ? limit + Number.EPSILON * Math.max(1, Math.abs(limit)) : limit, text: m[3] };
3691
+ });
3692
+ let chosen = options[0];
3693
+ for (const o of options) if (value >= o.limit) chosen = o;
3694
+ return chosen.text;
3695
+ }
3696
+ function formatArgument(value, type, style, timezone) {
3697
+ if (value === void 0) return "";
3698
+ if (!type) return typeof value === "number" ? number(value, "#,##0.###") : String(value);
3699
+ switch (type.trim()) {
3700
+ case "number": {
3701
+ const s = style?.trim();
3702
+ if (!s) return number(value, "#,##0.###");
3703
+ if (s === "integer") return number(value, "#,##0");
3704
+ if (s === "percent") return number(value, "#,##0%");
3705
+ if (s === "currency") return number(value, "'$'#,##0.00");
3706
+ return number(value, style);
3707
+ }
3708
+ case "date":
3709
+ case "time": {
3710
+ const styles = type.trim() === "date" ? DATE_STYLES : TIME_STYLES;
3711
+ const s = style?.trim() ?? "medium";
3712
+ return formatDate(Number(value), styles[s] ?? style, typeof timezone === "function" ? timezone() : timezone);
3713
+ }
3714
+ case "choice":
3715
+ return choice(Number(value), style ?? "");
3716
+ default:
3717
+ throw new SyntaxError(`Unknown format type "${type}"`);
3718
+ }
3719
+ }
3720
+ function formatMessage(pattern, args, timezone) {
3721
+ let out = "";
3722
+ for (let i = 0; i < pattern.length; ) {
3723
+ const ch = pattern[i];
3724
+ if (ch === "'") {
3725
+ if (pattern[i + 1] === "'") {
3726
+ out += "'";
3727
+ i += 2;
3728
+ continue;
3729
+ }
3730
+ const end = pattern.indexOf("'", i + 1);
3731
+ out += pattern.slice(i + 1, end === -1 ? void 0 : end);
3732
+ i = end === -1 ? pattern.length : end + 1;
3733
+ continue;
3734
+ }
3735
+ if (ch !== "{") {
3736
+ out += ch;
3737
+ i++;
3738
+ continue;
3739
+ }
3740
+ let depth = 1;
3741
+ let j = i + 1;
3742
+ let inQuote = false;
3743
+ for (; j < pattern.length && depth > 0; j++) {
3744
+ const c = pattern[j];
3745
+ if (c === "'") inQuote = !inQuote;
3746
+ else if (!inQuote && c === "{") depth++;
3747
+ else if (!inQuote && c === "}") depth--;
3748
+ }
3749
+ const inner = pattern.slice(i + 1, j - 1);
3750
+ const [index = "", type, ...rest] = inner.split(",");
3751
+ const style = rest.length ? rest.join(",") : void 0;
3752
+ const n = Number(index.trim());
3753
+ out += n < args.length ? formatArgument(args[n], type, style, timezone) : `{${inner}}`;
3754
+ i = j;
3755
+ }
3756
+ return out;
3757
+ }
3758
+
3759
+ // src/str/index.ts
3256
3760
  function length(str) {
3257
3761
  return str.length;
3258
3762
  }
3259
3763
  function tostring(value, format2) {
3260
- if (typeof value === "number" && format2) {
3261
- const decimals = format2.split(".")[1]?.length || 0;
3262
- return value.toFixed(decimals);
3764
+ if (typeof value !== "number") return String(value);
3765
+ if (!Number.isFinite(value)) return String(value);
3766
+ if (format2 === void 0 || format2 === "") {
3767
+ if (Math.abs(value) >= 1e21 && Number.isFinite(value)) {
3768
+ return String(value).replace("e+", "E").replace(/\.0+E/, "E");
3769
+ }
3770
+ return formatNumber(value, "#.##########", "halfUpShortest");
3771
+ }
3772
+ switch (format2) {
3773
+ case "percent":
3774
+ return formatNumber(value, "0.00", "halfUpShortest") + "%";
3775
+ case "volume": {
3776
+ const abs3 = Math.abs(value);
3777
+ for (const [size3, unit] of [[1e12, "T"], [1e9, "B"], [1e6, "M"], [1e3, "K"]]) {
3778
+ if (abs3 >= size3) return formatNumber(value / size3, "#.###", "halfUpShortest") + unit;
3779
+ }
3780
+ return formatNumber(value, "#", "halfUpShortest");
3781
+ }
3782
+ case "mintick":
3783
+ throw new Error("str.tostring(x, format.mintick) needs the symbol tick size (syminfo.mintick), which is not known here");
3784
+ default:
3785
+ return formatNumber(value, format2, "halfUpShortest");
3263
3786
  }
3264
- return String(value);
3265
3787
  }
3266
3788
  function tonumber(str) {
3267
3789
  const num = parseFloat(str);
@@ -3276,7 +3798,7 @@ function upper(str) {
3276
3798
  function lower(str) {
3277
3799
  return str.toLowerCase();
3278
3800
  }
3279
- function contains(source, str) {
3801
+ function contains2(source, str) {
3280
3802
  return source.includes(str);
3281
3803
  }
3282
3804
  function pos(source, str) {
@@ -3299,11 +3821,7 @@ function concat2(...strings) {
3299
3821
  return strings.join("");
3300
3822
  }
3301
3823
  function format(formatStr, ...args) {
3302
- let result = formatStr;
3303
- args.forEach((arg, index) => {
3304
- result = result.replaceAll(`{${index}}`, String(arg));
3305
- });
3306
- return result;
3824
+ return formatMessage(formatStr, args, "Etc/UTC");
3307
3825
  }
3308
3826
  function startswith(source, str) {
3309
3827
  return source.startsWith(str);
@@ -3331,84 +3849,8 @@ function repeat(source, count, separator = "") {
3331
3849
  if (count <= 0) return "";
3332
3850
  return Array(count).fill(source).join(separator);
3333
3851
  }
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;
3852
+ function format_time(time, format2 = "yyyy-MM-dd'T'HH:mm:ssZ", timezone = "Etc/UTC") {
3853
+ return formatDate(time, format2, timezone);
3412
3854
  }
3413
3855
 
3414
3856
  // src/color/index.ts
@@ -3506,16 +3948,16 @@ var teal = "#008080";
3506
3948
  var white = "#FFFFFF";
3507
3949
  var yellow = "#FFFF00";
3508
3950
  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);
3951
+ const parseColor2 = (col3) => {
3952
+ if (typeof col3 === "string") {
3953
+ if (col3.startsWith("#")) {
3954
+ const hex = col3.slice(1);
3513
3955
  const r4 = parseInt(hex.slice(0, 2), 16);
3514
3956
  const g4 = parseInt(hex.slice(2, 4), 16);
3515
3957
  const b4 = parseInt(hex.slice(4, 6), 16);
3516
3958
  return [r4, g4, b4, 1];
3517
3959
  }
3518
- const match2 = col2.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
3960
+ const match2 = col3.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
3519
3961
  if (match2) {
3520
3962
  return [
3521
3963
  parseInt(match2[1]),
@@ -3550,21 +3992,260 @@ function from_gradient(value, bottom_value, top_value, bottom_color, top_color)
3550
3992
  // src/time/index.ts
3551
3993
  var time_exports = {};
3552
3994
  __export(time_exports, {
3995
+ dayofmonth: () => dayofmonth,
3996
+ dayofweek: () => dayofweek,
3997
+ hour: () => hour,
3998
+ inSession: () => inSession2,
3999
+ minute: () => minute,
4000
+ month: () => month,
3553
4001
  now: () => now,
3554
- timestamp: () => timestamp
4002
+ second: () => second,
4003
+ timestamp: () => timestamp,
4004
+ weekofyear: () => weekofyear,
4005
+ year: () => year
3555
4006
  });
4007
+
4008
+ // src/time/datestring.ts
4009
+ var MONTHS2 = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
4010
+ var FULL_MONTHS = [
4011
+ "january",
4012
+ "february",
4013
+ "march",
4014
+ "april",
4015
+ "may",
4016
+ "june",
4017
+ "july",
4018
+ "august",
4019
+ "september",
4020
+ "october",
4021
+ "november",
4022
+ "december"
4023
+ ];
4024
+ var ZONE_NAMES = {
4025
+ ut: 0,
4026
+ utc: 0,
4027
+ gmt: 0,
4028
+ est: -5,
4029
+ edt: -4,
4030
+ cst: -6,
4031
+ cdt: -5,
4032
+ mst: -7,
4033
+ mdt: -6,
4034
+ pst: -8,
4035
+ pdt: -7
4036
+ };
4037
+ var TIME = String.raw`(\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3})\d*)?)?`;
4038
+ var ZONE = String.raw`(ut|utc|gmt|[ecmp][sd]t|(?:utc|gmt)?\s*[+-]\d{1,2}(?::?\d{2})?)`;
4039
+ var NUMERIC_ZONE = String.raw`([+-]\d{2}(?::?\d{2})?)`;
4040
+ var DATE = String.raw`(\d{4})([-/])(\d{1,2})\2(\d{1,2})`;
4041
+ var WEEKDAY = String.raw`(?:[a-z]{3,9},?\s+)?`;
4042
+ var ISO_T = new RegExp(String.raw`^${DATE}t${TIME}\s*${NUMERIC_ZONE}?$`, "i");
4043
+ var ISO = new RegExp(String.raw`^${DATE}(?:\s+${TIME})?\s*${ZONE}?$`, "i");
4044
+ var DAY_FIRST = new RegExp(String.raw`^${WEEKDAY}(\d{1,2})(?:\s+|-)([a-z]+)\.?,?(?:\s+|-)(\d{4})(?:,?\s+${TIME})?\s*${ZONE}?$`, "i");
4045
+ var MONTH_FIRST = new RegExp(String.raw`^${WEEKDAY}([a-z]+)\.?\s+(\d{1,2}),?\s+(\d{4})(?:,?\s+${TIME})?\s*${ZONE}?$`, "i");
4046
+ function monthNumber(name) {
4047
+ const lower2 = name.toLowerCase();
4048
+ const i = FULL_MONTHS.findIndex((full, k) => lower2.startsWith(MONTHS2[k]) && full.startsWith(lower2));
4049
+ return i + 1;
4050
+ }
4051
+ function zoneMinutes(zone) {
4052
+ if (!zone) return 0;
4053
+ const lower2 = zone.toLowerCase().replace(/\s+/g, "");
4054
+ const named = ZONE_NAMES[lower2];
4055
+ if (named !== void 0) return named * 60;
4056
+ const m = /^(?:utc|gmt)?([+-])(\d{1,2})(?::?(\d{2}))?$/.exec(lower2);
4057
+ if (!m) return NaN;
4058
+ const minutes = Number(m[2]) * 60 + (m[3] ? Number(m[3]) : 0);
4059
+ return m[1] === "-" ? -minutes : minutes;
4060
+ }
4061
+ function parseDateString(dateString) {
4062
+ const text = dateString.trim();
4063
+ let year2, month2, day;
4064
+ let rest;
4065
+ let m;
4066
+ if (m = ISO_T.exec(text) ?? ISO.exec(text)) {
4067
+ [year2, month2, day] = [m[1], Number(m[3]), m[4]];
4068
+ rest = m.slice(5);
4069
+ } else if (m = DAY_FIRST.exec(text)) {
4070
+ [day, month2, year2] = [m[1], monthNumber(m[2]), m[3]];
4071
+ rest = m.slice(4);
4072
+ } else if (m = MONTH_FIRST.exec(text)) {
4073
+ [month2, day, year2] = [monthNumber(m[1]), m[2], m[3]];
4074
+ rest = m.slice(4);
4075
+ } else {
4076
+ throw new SyntaxError(`Invalid date string "${dateString}": use RFC 2822 or ISO 8601 ("20 Feb 2020", "2020-02-20T14:48:00")`);
4077
+ }
4078
+ const [hour2 = "0", minute2 = "0", second2 = "0", millis = "0", zone] = rest;
4079
+ const d = Number(day);
4080
+ const h = Number(hour2);
4081
+ const mi = Number(minute2);
4082
+ const s = Number(second2);
4083
+ const offset = zoneMinutes(zone);
4084
+ const endOfDay = h === 24 && mi === 0 && s === 0 && Number(millis) === 0;
4085
+ if (month2 < 1 || month2 > 12 || d < 1 || d > 31 || h > 23 && !endOfDay || mi > 59 || s > 59 || Number.isNaN(offset)) {
4086
+ throw new SyntaxError(`Invalid date string "${dateString}": a field is out of range`);
4087
+ }
4088
+ const ms = Number(millis.padEnd(3, "0"));
4089
+ return Date.UTC(Number(year2), month2 - 1, d, h, mi, s, ms) - offset * 6e4;
4090
+ }
4091
+
4092
+ // src/time/session.ts
4093
+ var PERIOD = /^(\d{2})(\d{2})-(\d{2})(\d{2})$/;
4094
+ var sessions = /* @__PURE__ */ new Map();
4095
+ function parseSession(session) {
4096
+ let parsed = sessions.get(session);
4097
+ if (parsed) return parsed;
4098
+ const invalid = () => new SyntaxError(`Invalid session "${session}": expected "HHmm-HHmm[,HHmm-HHmm...][:days]"`);
4099
+ const text = session.trim() === "24x7" ? "0000-0000" : session.replace(/\s+/g, "");
4100
+ const [periodText = "", dayText, extra] = text.split(":");
4101
+ if (extra !== void 0 || periodText === "") throw invalid();
4102
+ const periods = periodText.split(",").map((p) => {
4103
+ const m = PERIOD.exec(p);
4104
+ if (!m) throw invalid();
4105
+ const [h1, m1, h2, m2] = [m[1], m[2], m[3], m[4]].map(Number);
4106
+ if (h1 > 23 || h2 > 23 || m1 > 59 || m2 > 59) throw invalid();
4107
+ return { start: h1 * 60 + m1, end: h2 * 60 + m2 };
4108
+ });
4109
+ const dayDigits = dayText ?? (periods.length > 1 ? "23456" : "1234567");
4110
+ if (!/^[1-7]+$/.test(dayDigits)) throw invalid();
4111
+ const days = new Array(8).fill(false);
4112
+ for (const d of dayDigits) days[Number(d)] = true;
4113
+ parsed = { periods, days };
4114
+ sessions.set(session, parsed);
4115
+ return parsed;
4116
+ }
4117
+ function inSession(time, session, timezone) {
4118
+ if (Number.isNaN(time)) return false;
4119
+ const { periods, days } = parseSession(session);
4120
+ const f = zonedFields(time, timezone);
4121
+ const minute2 = f.hour * 60 + f.minute;
4122
+ const nextDay = f.dayOfWeek % 7 + 1;
4123
+ for (const { start, end } of periods) {
4124
+ if (start < end || start === 0 && end === 0) {
4125
+ if (minute2 >= start && (minute2 < end || end === 0) && days[f.dayOfWeek]) return true;
4126
+ } else {
4127
+ if (minute2 >= start && days[nextDay]) return true;
4128
+ if (minute2 < end && days[f.dayOfWeek]) return true;
4129
+ }
4130
+ }
4131
+ return false;
4132
+ }
4133
+
4134
+ // src/time/index.ts
3556
4135
  function now() {
3557
4136
  return Date.now();
3558
4137
  }
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();
4138
+ function timestamp(first2, ...rest) {
4139
+ if (typeof first2 === "string") {
4140
+ if (rest.length === 0) return parseDateString(first2);
4141
+ const [year2, month3, day2, hour3, minute3, second3] = rest;
4142
+ return zonedToUnix(first2, year2, month3, day2, hour3 ?? 0, minute3 ?? 0, second3 ?? 0);
4143
+ }
4144
+ const [month2, day, hour2, minute2, second2] = rest;
4145
+ return new Date(first2, month2 - 1, day, hour2 || 0, minute2 || 0, second2 || 0).getTime();
4146
+ }
4147
+ function field(time, timezone, pick) {
4148
+ return Number.isNaN(time) ? NaN : pick(zonedFields(time, timezone));
4149
+ }
4150
+ function year(time, timezone) {
4151
+ return field(time, timezone, (f) => f.year);
4152
+ }
4153
+ function month(time, timezone) {
4154
+ return field(time, timezone, (f) => f.month);
4155
+ }
4156
+ function dayofmonth(time, timezone) {
4157
+ return field(time, timezone, (f) => f.day);
4158
+ }
4159
+ function dayofweek(time, timezone) {
4160
+ return field(time, timezone, (f) => f.dayOfWeek);
4161
+ }
4162
+ function weekofyear(time, timezone) {
4163
+ return field(time, timezone, (f) => {
4164
+ const date = Date.UTC(f.year, f.month - 1, f.day);
4165
+ const mondayBased = (f.dayOfWeek + 5) % 7;
4166
+ const thursday = new Date(date + (3 - mondayBased) * 864e5);
4167
+ const yearStart = Date.UTC(thursday.getUTCFullYear(), 0, 1);
4168
+ return 1 + Math.floor((thursday.getTime() - yearStart) / (7 * 864e5));
4169
+ });
4170
+ }
4171
+ function hour(time, timezone) {
4172
+ return field(time, timezone, (f) => f.hour);
4173
+ }
4174
+ function minute(time, timezone) {
4175
+ return field(time, timezone, (f) => f.minute);
4176
+ }
4177
+ function second(time, timezone) {
4178
+ return field(time, timezone, (f) => f.second);
4179
+ }
4180
+ function inSession2(time, session, timezone) {
4181
+ return inSession(time, session, timezone);
4182
+ }
4183
+
4184
+ // src/timeframe/index.ts
4185
+ var timeframe_exports = {};
4186
+ __export(timeframe_exports, {
4187
+ from_seconds: () => from_seconds,
4188
+ in_seconds: () => in_seconds,
4189
+ info: () => info
4190
+ });
4191
+ var SECONDS_PER_MINUTE = 60;
4192
+ var SECONDS_PER_DAY = 86400;
4193
+ var SECONDS_PER_WEEK = 604800;
4194
+ var SECONDS_PER_MONTH = 2628003;
4195
+ var SECONDS_365_DAYS = 365 * SECONDS_PER_DAY;
4196
+ var UNIT_SECONDS = {
4197
+ S: 1,
4198
+ "": SECONDS_PER_MINUTE,
4199
+ D: SECONDS_PER_DAY,
4200
+ W: SECONDS_PER_WEEK,
4201
+ M: SECONDS_PER_MONTH
4202
+ };
4203
+ var SECOND_TIMEFRAMES = [1, 5, 10, 15, 30];
4204
+ function in_seconds(timeframe) {
4205
+ const text = timeframe.trim();
4206
+ if (text === "") {
4207
+ throw new RangeError("timeframe.in_seconds() needs a timeframe: the chart timeframe is not known here");
4208
+ }
4209
+ const before = /^(\d*)([SDWMT]?)$/.exec(text);
4210
+ const after = before ? null : /^([SDWMT])(\d+)$/.exec(text);
4211
+ if (!before && !after) throw new RangeError(`Invalid timeframe "${timeframe}"`);
4212
+ const [digits, unit] = before ? [before[1], before[2]] : [after[2], after[1]];
4213
+ if (unit === "T") return NaN;
4214
+ const multiplier = digits === "" ? 1 : Number(digits);
4215
+ return multiplier * UNIT_SECONDS[unit];
4216
+ }
4217
+ function from_seconds(seconds) {
4218
+ if (Number.isNaN(seconds)) throw new RangeError("timeframe.from_seconds() needs a number of seconds");
4219
+ if (seconds >= SECONDS_365_DAYS) return "12M";
4220
+ if (seconds > 0) {
4221
+ if (seconds % SECONDS_PER_MONTH === 0) return `${seconds / SECONDS_PER_MONTH}M`;
4222
+ if (seconds % SECONDS_PER_WEEK === 0) return `${seconds / SECONDS_PER_WEEK}W`;
4223
+ if (seconds % SECONDS_PER_DAY === 0) return `${seconds / SECONDS_PER_DAY}D`;
4224
+ if (seconds % SECONDS_PER_MINUTE === 0 && seconds < SECONDS_PER_DAY) return `${seconds / SECONDS_PER_MINUTE}`;
4225
+ }
4226
+ const second2 = SECOND_TIMEFRAMES.find((m) => seconds <= m);
4227
+ if (second2 !== void 0) return `${second2}S`;
4228
+ if (seconds < SECONDS_PER_DAY) return `${Math.ceil(seconds / SECONDS_PER_MINUTE)}`;
4229
+ return `${Math.ceil(seconds / SECONDS_PER_DAY)}D`;
4230
+ }
4231
+ function info(timeframe) {
4232
+ const text = timeframe.trim();
4233
+ const m = /^(\d*)([SDWMT]?)$/.exec(text);
4234
+ if (!m || text === "") throw new RangeError(`Invalid timeframe "${timeframe}"`);
4235
+ const unit = m[2];
4236
+ const multiplier = m[1] === "" ? 1 : Number(m[1]);
4237
+ return {
4238
+ period: unit === "" ? String(multiplier) : `${multiplier}${unit}`,
4239
+ multiplier,
4240
+ isintraday: unit === "" || unit === "S" || unit === "T",
4241
+ isdaily: unit === "D",
4242
+ isweekly: unit === "W",
4243
+ ismonthly: unit === "M",
4244
+ isminutes: unit === "",
4245
+ isseconds: unit === "S",
4246
+ isticks: unit === "T",
4247
+ isdwm: unit === "D" || unit === "W" || unit === "M"
4248
+ };
3568
4249
  }
3569
4250
 
3570
4251
  // src/matrix/index.ts
@@ -3576,14 +4257,14 @@ __export(matrix_exports, {
3576
4257
  col: () => col,
3577
4258
  columns: () => columns,
3578
4259
  concat: () => concat3,
3579
- copy: () => copy2,
4260
+ copy: () => copy3,
3580
4261
  det: () => det,
3581
4262
  diff: () => diff,
3582
4263
  eigenvalues: () => eigenvalues,
3583
4264
  eigenvectors: () => eigenvectors,
3584
4265
  elements_count: () => elements_count,
3585
4266
  fill: () => fill2,
3586
- get: () => get2,
4267
+ get: () => get3,
3587
4268
  inv: () => inv,
3588
4269
  is_antidiagonal: () => is_antidiagonal,
3589
4270
  is_antisymmetric: () => is_antisymmetric,
@@ -3632,7 +4313,7 @@ function new_matrix(rows2, columns2, initial_value) {
3632
4313
  }
3633
4314
  return { rows: rows2, columns: columns2, data };
3634
4315
  }
3635
- function get2(id, row2, column) {
4316
+ function get3(id, row2, column) {
3636
4317
  if (row2 < 0 || row2 >= id.rows || column < 0 || column >= id.columns) {
3637
4318
  throw new Error(`Matrix index out of bounds: [${row2}, ${column}] for matrix of size [${id.rows}, ${id.columns}]`);
3638
4319
  }
@@ -3665,7 +4346,7 @@ function col(id, column_index) {
3665
4346
  }
3666
4347
  return id.data.map((r2) => r2[column_index]);
3667
4348
  }
3668
- function copy2(id) {
4349
+ function copy3(id) {
3669
4350
  const newData = id.data.map((r2) => [...r2]);
3670
4351
  return {
3671
4352
  rows: id.rows,
@@ -4017,24 +4698,24 @@ function median3(id) {
4017
4698
  if (id.rows === 0 || id.columns === 0) {
4018
4699
  return NaN;
4019
4700
  }
4020
- const values = [];
4701
+ const values2 = [];
4021
4702
  for (let i = 0; i < id.rows; i++) {
4022
4703
  for (let j = 0; j < id.columns; j++) {
4023
4704
  const val = id.data[i][j];
4024
4705
  if (val !== null && val !== void 0 && !isNaN(val)) {
4025
- values.push(val);
4706
+ values2.push(val);
4026
4707
  }
4027
4708
  }
4028
4709
  }
4029
- if (values.length === 0) {
4710
+ if (values2.length === 0) {
4030
4711
  return NaN;
4031
4712
  }
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;
4713
+ values2.sort((a, b2) => a - b2);
4714
+ const mid = Math.floor(values2.length / 2);
4715
+ if (values2.length % 2 === 0) {
4716
+ return (values2[mid - 1] + values2[mid]) / 2;
4036
4717
  } else {
4037
- return values[mid];
4718
+ return values2[mid];
4038
4719
  }
4039
4720
  }
4040
4721
  function mode3(id) {
@@ -4280,7 +4961,7 @@ function pow2(id, power) {
4280
4961
  base = inverse;
4281
4962
  p = -power;
4282
4963
  } else {
4283
- base = copy2(id);
4964
+ base = copy3(id);
4284
4965
  }
4285
4966
  let result = createIdentity(n);
4286
4967
  while (p > 0) {
@@ -4309,31 +4990,31 @@ function det(id) {
4309
4990
  const a = id.data.map((row2) => [...row2]);
4310
4991
  let determinant = 1;
4311
4992
  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]);
4993
+ for (let col3 = 0; col3 < n; col3++) {
4994
+ let maxRow = col3;
4995
+ let maxVal = Math.abs(a[col3][col3]);
4996
+ for (let row2 = col3 + 1; row2 < n; row2++) {
4997
+ const absVal = Math.abs(a[row2][col3]);
4317
4998
  if (absVal > maxVal) {
4318
4999
  maxVal = absVal;
4319
5000
  maxRow = row2;
4320
5001
  }
4321
5002
  }
4322
- if (maxRow !== col2) {
4323
- const temp = a[col2];
4324
- a[col2] = a[maxRow];
5003
+ if (maxRow !== col3) {
5004
+ const temp = a[col3];
5005
+ a[col3] = a[maxRow];
4325
5006
  a[maxRow] = temp;
4326
5007
  swapCount++;
4327
5008
  }
4328
- const pivot = a[col2][col2];
4329
- if (Math.abs(pivot) < EPSILON) {
5009
+ const pivot2 = a[col3][col3];
5010
+ if (Math.abs(pivot2) < EPSILON) {
4330
5011
  return 0;
4331
5012
  }
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];
5013
+ determinant *= pivot2;
5014
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5015
+ const factor = a[row2][col3] / pivot2;
5016
+ for (let j = col3; j < n; j++) {
5017
+ a[row2][j] = a[row2][j] - factor * a[col3][j];
4337
5018
  }
4338
5019
  }
4339
5020
  }
@@ -4361,33 +5042,33 @@ function inv(id) {
4361
5042
  }
4362
5043
  aug.push(row2);
4363
5044
  }
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]);
5045
+ for (let col3 = 0; col3 < n; col3++) {
5046
+ let maxRow = col3;
5047
+ let maxVal = Math.abs(aug[col3][col3]);
5048
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5049
+ const absVal = Math.abs(aug[row2][col3]);
4369
5050
  if (absVal > maxVal) {
4370
5051
  maxVal = absVal;
4371
5052
  maxRow = row2;
4372
5053
  }
4373
5054
  }
4374
- if (maxRow !== col2) {
4375
- const temp = aug[col2];
4376
- aug[col2] = aug[maxRow];
5055
+ if (maxRow !== col3) {
5056
+ const temp = aug[col3];
5057
+ aug[col3] = aug[maxRow];
4377
5058
  aug[maxRow] = temp;
4378
5059
  }
4379
- const pivot = aug[col2][col2];
4380
- if (Math.abs(pivot) < EPSILON) {
5060
+ const pivot2 = aug[col3][col3];
5061
+ if (Math.abs(pivot2) < EPSILON) {
4381
5062
  return null;
4382
5063
  }
4383
5064
  for (let j = 0; j < 2 * n; j++) {
4384
- aug[col2][j] = aug[col2][j] / pivot;
5065
+ aug[col3][j] = aug[col3][j] / pivot2;
4385
5066
  }
4386
5067
  for (let row2 = 0; row2 < n; row2++) {
4387
- if (row2 !== col2) {
4388
- const factor = aug[row2][col2];
5068
+ if (row2 !== col3) {
5069
+ const factor = aug[row2][col3];
4389
5070
  for (let j = 0; j < 2 * n; j++) {
4390
- aug[row2][j] = aug[row2][j] - factor * aug[col2][j];
5071
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4391
5072
  }
4392
5073
  }
4393
5074
  }
@@ -4450,11 +5131,11 @@ function rank(id) {
4450
5131
  const m = id.rows;
4451
5132
  const n = id.columns;
4452
5133
  let r2 = 0;
4453
- for (let col2 = 0; col2 < n && r2 < m; col2++) {
5134
+ for (let col3 = 0; col3 < n && r2 < m; col3++) {
4454
5135
  let maxRow = r2;
4455
- let maxVal = Math.abs(a[r2][col2]);
5136
+ let maxVal = Math.abs(a[r2][col3]);
4456
5137
  for (let row2 = r2 + 1; row2 < m; row2++) {
4457
- const absVal = Math.abs(a[row2][col2]);
5138
+ const absVal = Math.abs(a[row2][col3]);
4458
5139
  if (absVal > maxVal) {
4459
5140
  maxVal = absVal;
4460
5141
  maxRow = row2;
@@ -4468,10 +5149,10 @@ function rank(id) {
4468
5149
  a[r2] = a[maxRow];
4469
5150
  a[maxRow] = temp;
4470
5151
  }
4471
- const pivot = a[r2][col2];
5152
+ const pivot2 = a[r2][col3];
4472
5153
  for (let row2 = r2 + 1; row2 < m; row2++) {
4473
- const factor = a[row2][col2] / pivot;
4474
- for (let j = col2; j < n; j++) {
5154
+ const factor = a[row2][col3] / pivot2;
5155
+ for (let j = col3; j < n; j++) {
4475
5156
  a[row2][j] = a[row2][j] - factor * a[r2][j];
4476
5157
  }
4477
5158
  }
@@ -4679,29 +5360,29 @@ function inverseIteration(m, lambda) {
4679
5360
  function solveLinearSystem(a, b2) {
4680
5361
  const n = a.length;
4681
5362
  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]);
5363
+ for (let col3 = 0; col3 < n; col3++) {
5364
+ let maxRow = col3;
5365
+ let maxVal = Math.abs(aug[col3][col3]);
5366
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5367
+ const absVal = Math.abs(aug[row2][col3]);
4687
5368
  if (absVal > maxVal) {
4688
5369
  maxVal = absVal;
4689
5370
  maxRow = row2;
4690
5371
  }
4691
5372
  }
4692
- if (maxRow !== col2) {
4693
- const temp = aug[col2];
4694
- aug[col2] = aug[maxRow];
5373
+ if (maxRow !== col3) {
5374
+ const temp = aug[col3];
5375
+ aug[col3] = aug[maxRow];
4695
5376
  aug[maxRow] = temp;
4696
5377
  }
4697
- const pivot = aug[col2][col2];
4698
- if (Math.abs(pivot) < EPSILON) {
5378
+ const pivot2 = aug[col3][col3];
5379
+ if (Math.abs(pivot2) < EPSILON) {
4699
5380
  continue;
4700
5381
  }
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];
5382
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5383
+ const factor = aug[row2][col3] / pivot2;
5384
+ for (let j = col3; j <= n; j++) {
5385
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4705
5386
  }
4706
5387
  }
4707
5388
  }
@@ -4733,8 +5414,8 @@ function kron(id1, id2) {
4733
5414
  for (let i2 = 0; i2 < m2; i2++) {
4734
5415
  for (let j2 = 0; j2 < n2; j2++) {
4735
5416
  const row2 = i1 * m2 + i2;
4736
- const col2 = j1 * n2 + j2;
4737
- data[row2][col2] = a * id2.data[i2][j2];
5417
+ const col3 = j1 * n2 + j2;
5418
+ data[row2][col3] = a * id2.data[i2][j2];
4738
5419
  }
4739
5420
  }
4740
5421
  }
@@ -4752,7 +5433,9 @@ function newtype2(rows2 = 0, columns2 = 0, initial_value) {
4752
5433
  // src/line/index.ts
4753
5434
  var line_exports = {};
4754
5435
  __export(line_exports, {
4755
- copy: () => copy3,
5436
+ all: () => all2,
5437
+ copy: () => copy4,
5438
+ delete: () => delete_line,
4756
5439
  delete_line: () => delete_line,
4757
5440
  get_price: () => get_price,
4758
5441
  get_x1: () => get_x1,
@@ -4763,6 +5446,8 @@ __export(line_exports, {
4763
5446
  new_line: () => new_line2,
4764
5447
  set_color: () => set_color,
4765
5448
  set_extend: () => set_extend,
5449
+ set_first_point: () => set_first_point,
5450
+ set_second_point: () => set_second_point,
4766
5451
  set_style: () => set_style,
4767
5452
  set_width: () => set_width,
4768
5453
  set_x1: () => set_x1,
@@ -4773,18 +5458,78 @@ __export(line_exports, {
4773
5458
  set_y1: () => set_y1,
4774
5459
  set_y2: () => set_y2
4775
5460
  });
4776
- function new_line2(x1, y1, x2, y2, xloc2 = "bar_index", extend = "none", lineColor, style, width) {
4777
- return {
5461
+
5462
+ // src/drawing/registry.ts
5463
+ var DEFAULT_MAX_COUNT = 50;
5464
+ var SLACK = 5;
5465
+ var live = { line: [], label: [], box: [], polyline: [], linefill: [] };
5466
+ var limits = {
5467
+ line: DEFAULT_MAX_COUNT,
5468
+ label: DEFAULT_MAX_COUNT,
5469
+ box: DEFAULT_MAX_COUNT,
5470
+ polyline: DEFAULT_MAX_COUNT
5471
+ };
5472
+ var deleted = /* @__PURE__ */ new WeakSet();
5473
+ var COORDINATES = {
5474
+ line: ["x1", "y1", "x2", "y2"],
5475
+ label: ["x", "y"],
5476
+ box: ["left", "top", "right", "bottom"],
5477
+ polyline: [],
5478
+ linefill: []
5479
+ };
5480
+ function markDeleted(kind, obj, explicit) {
5481
+ deleted.add(obj);
5482
+ for (const field2 of COORDINATES[kind]) obj[field2] = NaN;
5483
+ if (kind === "line" && explicit) {
5484
+ for (const fill3 of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove3("linefill", fill3);
5485
+ }
5486
+ }
5487
+ function register(kind, obj) {
5488
+ const list = live[kind];
5489
+ list.push(obj);
5490
+ const max6 = limits[kind === "linefill" ? "line" : kind];
5491
+ if (list.length > max6 + SLACK) {
5492
+ for (const old of list.splice(0, list.length - max6)) markDeleted(kind, old, false);
5493
+ }
5494
+ return obj;
5495
+ }
5496
+ function remove3(kind, obj) {
5497
+ const list = live[kind];
5498
+ const index = list.indexOf(obj);
5499
+ if (index !== -1) list.splice(index, 1);
5500
+ if (!deleted.has(obj)) markDeleted(kind, obj, true);
5501
+ }
5502
+ function isDeleted(obj) {
5503
+ return typeof obj === "object" && obj !== null && deleted.has(obj);
5504
+ }
5505
+ function all(kind) {
5506
+ return [...live[kind]];
5507
+ }
5508
+
5509
+ // src/line/index.ts
5510
+ function new_line2(...args) {
5511
+ let x1, y1, x2, y2, rest;
5512
+ if (typeof args[0] === "object" && args[0] !== null) {
5513
+ const [p1, p2, ...others] = args;
5514
+ const xloc3 = others[0] ?? "bar_index";
5515
+ [x1, y1, x2, y2, rest] = [pointX(p1, xloc3), p1.price, pointX(p2, xloc3), p2.price, others];
5516
+ } else {
5517
+ [x1, y1, x2, y2] = args;
5518
+ rest = args.slice(4);
5519
+ }
5520
+ const [xloc2, extend, lineColor, style, width, force_overlay] = rest;
5521
+ return register("line", {
4778
5522
  x1,
4779
5523
  y1,
4780
5524
  x2,
4781
5525
  y2,
4782
- xloc: xloc2,
4783
- extend,
5526
+ xloc: xloc2 ?? "bar_index",
5527
+ extend: extend ?? "none",
4784
5528
  color: lineColor,
4785
5529
  style: style || "solid",
4786
- width: width || 1
4787
- };
5530
+ width: width || 1,
5531
+ force_overlay: force_overlay ?? false
5532
+ });
4788
5533
  }
4789
5534
  function get_price(id, x) {
4790
5535
  const { x1, y1, x2, y2, extend, xloc: xloc2 } = id;
@@ -4823,64 +5568,97 @@ function get_y1(id) {
4823
5568
  function get_y2(id) {
4824
5569
  return id.y2;
4825
5570
  }
4826
- function copy3(id) {
4827
- return { ...id };
5571
+ function copy4(id) {
5572
+ return register("line", { ...id });
4828
5573
  }
4829
5574
  function set_x1(id, x) {
5575
+ if (isDeleted(id)) return id;
4830
5576
  id.x1 = x;
4831
5577
  return id;
4832
5578
  }
4833
5579
  function set_x2(id, x) {
5580
+ if (isDeleted(id)) return id;
4834
5581
  id.x2 = x;
4835
5582
  return id;
4836
5583
  }
4837
5584
  function set_y1(id, y) {
5585
+ if (isDeleted(id)) return id;
4838
5586
  id.y1 = y;
4839
5587
  return id;
4840
5588
  }
4841
5589
  function set_y2(id, y) {
5590
+ if (isDeleted(id)) return id;
4842
5591
  id.y2 = y;
4843
5592
  return id;
4844
5593
  }
4845
5594
  function set_xy1(id, x, y) {
5595
+ if (isDeleted(id)) return id;
4846
5596
  id.x1 = x;
4847
5597
  id.y1 = y;
4848
5598
  return id;
4849
5599
  }
4850
5600
  function set_xy2(id, x, y) {
5601
+ if (isDeleted(id)) return id;
4851
5602
  id.x2 = x;
4852
5603
  id.y2 = y;
4853
5604
  return id;
4854
5605
  }
4855
5606
  function set_xloc(id, x1, x2, xloc2) {
5607
+ if (isDeleted(id)) return id;
4856
5608
  id.x1 = x1;
4857
5609
  id.x2 = x2;
4858
5610
  id.xloc = xloc2;
4859
5611
  return id;
4860
5612
  }
4861
5613
  function set_extend(id, extend) {
5614
+ if (isDeleted(id)) return id;
4862
5615
  id.extend = extend;
4863
5616
  return id;
4864
5617
  }
4865
5618
  function set_color(id, lineColor) {
5619
+ if (isDeleted(id)) return id;
4866
5620
  id.color = lineColor;
4867
5621
  return id;
4868
5622
  }
4869
5623
  function set_style(id, style) {
5624
+ if (isDeleted(id)) return id;
4870
5625
  id.style = style;
4871
5626
  return id;
4872
5627
  }
4873
5628
  function set_width(id, width) {
5629
+ if (isDeleted(id)) return id;
4874
5630
  id.width = width;
4875
5631
  return id;
4876
5632
  }
4877
- function delete_line(_id) {
5633
+ function delete_line(id) {
5634
+ remove3("line", id);
5635
+ }
5636
+ function pointX(point, xloc2) {
5637
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5638
+ return x ?? NaN;
5639
+ }
5640
+ function all2() {
5641
+ return all("line");
5642
+ }
5643
+ function set_first_point(id, point) {
5644
+ if (isDeleted(id)) return id;
5645
+ id.x1 = pointX(point, id.xloc);
5646
+ id.y1 = point.price;
5647
+ return id;
5648
+ }
5649
+ function set_second_point(id, point) {
5650
+ if (isDeleted(id)) return id;
5651
+ id.x2 = pointX(point, id.xloc);
5652
+ id.y2 = point.price;
5653
+ return id;
4878
5654
  }
4879
5655
 
4880
5656
  // src/box/index.ts
4881
5657
  var box_exports = {};
4882
5658
  __export(box_exports, {
4883
- copy: () => copy4,
5659
+ all: () => all3,
5660
+ copy: () => copy5,
5661
+ delete: () => delete_box,
4884
5662
  delete_box: () => delete_box,
4885
5663
  get_bottom: () => get_bottom,
4886
5664
  get_left: () => get_left,
@@ -4893,6 +5671,7 @@ __export(box_exports, {
4893
5671
  set_border_style: () => set_border_style,
4894
5672
  set_border_width: () => set_border_width,
4895
5673
  set_bottom: () => set_bottom,
5674
+ set_bottom_right_point: () => set_bottom_right_point,
4896
5675
  set_extend: () => set_extend2,
4897
5676
  set_left: () => set_left,
4898
5677
  set_lefttop: () => set_lefttop,
@@ -4901,21 +5680,49 @@ __export(box_exports, {
4901
5680
  set_text: () => set_text,
4902
5681
  set_text_color: () => set_text_color,
4903
5682
  set_text_font_family: () => set_text_font_family,
5683
+ set_text_formatting: () => set_text_formatting,
4904
5684
  set_text_halign: () => set_text_halign,
4905
5685
  set_text_size: () => set_text_size,
4906
5686
  set_text_valign: () => set_text_valign,
4907
5687
  set_text_wrap: () => set_text_wrap,
4908
5688
  set_top: () => set_top,
5689
+ set_top_left_point: () => set_top_left_point,
4909
5690
  set_xloc: () => set_xloc2
4910
5691
  });
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 {
5692
+ function new_box2(...args) {
5693
+ let left, top, right, bottom, rest;
5694
+ if (typeof args[0] === "object" && args[0] !== null) {
5695
+ const [tl, br, ...others] = args;
5696
+ const xloc3 = others[4] ?? "bar_index";
5697
+ [left, top, right, bottom, rest] = [pointX2(tl, xloc3), tl.price, pointX2(br, xloc3), br.price, others];
5698
+ } else {
5699
+ [left, top, right, bottom] = args;
5700
+ rest = args.slice(4);
5701
+ }
5702
+ const [
5703
+ border_color,
5704
+ border_width,
5705
+ border_style,
5706
+ extend,
5707
+ xloc2,
5708
+ bgcolor,
5709
+ text,
5710
+ text_size,
5711
+ text_color,
5712
+ text_halign,
5713
+ text_valign,
5714
+ text_wrap,
5715
+ text_font_family,
5716
+ force_overlay,
5717
+ text_formatting
5718
+ ] = rest;
5719
+ return register("box", {
4913
5720
  left,
4914
5721
  top,
4915
5722
  right,
4916
5723
  bottom,
4917
- xloc: xloc2,
4918
- extend,
5724
+ xloc: xloc2 ?? "bar_index",
5725
+ extend: extend ?? "none",
4919
5726
  border_color,
4920
5727
  border_width: border_width || 1,
4921
5728
  border_style: border_style || "solid",
@@ -4926,8 +5733,10 @@ function new_box2(left, top, right, bottom, xloc2 = "bar_index", extend = "none"
4926
5733
  text_halign,
4927
5734
  text_valign,
4928
5735
  text_wrap,
4929
- text_font_family
4930
- };
5736
+ text_font_family,
5737
+ force_overlay: force_overlay ?? false,
5738
+ text_formatting
5739
+ });
4931
5740
  }
4932
5741
  function get_left(id) {
4933
5742
  return id.left;
@@ -4941,96 +5750,142 @@ function get_top(id) {
4941
5750
  function get_bottom(id) {
4942
5751
  return id.bottom;
4943
5752
  }
4944
- function copy4(id) {
4945
- return { ...id };
5753
+ function copy5(id) {
5754
+ return register("box", { ...id });
4946
5755
  }
4947
5756
  function set_left(id, left) {
5757
+ if (isDeleted(id)) return id;
4948
5758
  id.left = left;
4949
5759
  return id;
4950
5760
  }
4951
5761
  function set_right(id, right) {
5762
+ if (isDeleted(id)) return id;
4952
5763
  id.right = right;
4953
5764
  return id;
4954
5765
  }
4955
5766
  function set_top(id, top) {
5767
+ if (isDeleted(id)) return id;
4956
5768
  id.top = top;
4957
5769
  return id;
4958
5770
  }
4959
5771
  function set_bottom(id, bottom) {
5772
+ if (isDeleted(id)) return id;
4960
5773
  id.bottom = bottom;
4961
5774
  return id;
4962
5775
  }
4963
5776
  function set_lefttop(id, left, top) {
5777
+ if (isDeleted(id)) return id;
4964
5778
  id.left = left;
4965
5779
  id.top = top;
4966
5780
  return id;
4967
5781
  }
4968
5782
  function set_rightbottom(id, right, bottom) {
5783
+ if (isDeleted(id)) return id;
4969
5784
  id.right = right;
4970
5785
  id.bottom = bottom;
4971
5786
  return id;
4972
5787
  }
4973
5788
  function set_xloc2(id, left, right, xloc2) {
5789
+ if (isDeleted(id)) return id;
4974
5790
  id.left = left;
4975
5791
  id.right = right;
4976
5792
  id.xloc = xloc2;
4977
5793
  return id;
4978
5794
  }
4979
5795
  function set_extend2(id, extend) {
5796
+ if (isDeleted(id)) return id;
4980
5797
  id.extend = extend;
4981
5798
  return id;
4982
5799
  }
4983
5800
  function set_border_color(id, borderColor) {
5801
+ if (isDeleted(id)) return id;
4984
5802
  id.border_color = borderColor;
4985
5803
  return id;
4986
5804
  }
4987
5805
  function set_border_width(id, width) {
5806
+ if (isDeleted(id)) return id;
4988
5807
  id.border_width = width;
4989
5808
  return id;
4990
5809
  }
4991
5810
  function set_border_style(id, style) {
5811
+ if (isDeleted(id)) return id;
4992
5812
  id.border_style = style;
4993
5813
  return id;
4994
5814
  }
4995
5815
  function set_bgcolor(id, bgColor) {
5816
+ if (isDeleted(id)) return id;
4996
5817
  id.bgcolor = bgColor;
4997
5818
  return id;
4998
5819
  }
4999
5820
  function set_text(id, text) {
5821
+ if (isDeleted(id)) return id;
5000
5822
  id.text = text;
5001
5823
  return id;
5002
5824
  }
5003
5825
  function set_text_color(id, textColor) {
5826
+ if (isDeleted(id)) return id;
5004
5827
  id.text_color = textColor;
5005
5828
  return id;
5006
5829
  }
5007
- function set_text_size(id, size2) {
5008
- id.text_size = size2;
5830
+ function set_text_size(id, size3) {
5831
+ if (isDeleted(id)) return id;
5832
+ id.text_size = size3;
5009
5833
  return id;
5010
5834
  }
5011
5835
  function set_text_halign(id, align) {
5836
+ if (isDeleted(id)) return id;
5012
5837
  id.text_halign = align;
5013
5838
  return id;
5014
5839
  }
5015
5840
  function set_text_valign(id, align) {
5841
+ if (isDeleted(id)) return id;
5016
5842
  id.text_valign = align;
5017
5843
  return id;
5018
5844
  }
5019
5845
  function set_text_wrap(id, wrap) {
5846
+ if (isDeleted(id)) return id;
5020
5847
  id.text_wrap = wrap;
5021
5848
  return id;
5022
5849
  }
5023
5850
  function set_text_font_family(id, font) {
5851
+ if (isDeleted(id)) return id;
5024
5852
  id.text_font_family = font;
5025
5853
  return id;
5026
5854
  }
5027
- function delete_box(_id) {
5855
+ function delete_box(id) {
5856
+ remove3("box", id);
5857
+ }
5858
+ function pointX2(point, xloc2) {
5859
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5860
+ return x ?? NaN;
5861
+ }
5862
+ function all3() {
5863
+ return all("box");
5864
+ }
5865
+ function set_top_left_point(id, point) {
5866
+ if (isDeleted(id)) return id;
5867
+ id.left = pointX2(point, id.xloc);
5868
+ id.top = point.price;
5869
+ return id;
5870
+ }
5871
+ function set_bottom_right_point(id, point) {
5872
+ if (isDeleted(id)) return id;
5873
+ id.right = pointX2(point, id.xloc);
5874
+ id.bottom = point.price;
5875
+ return id;
5876
+ }
5877
+ function set_text_formatting(id, formatting) {
5878
+ if (isDeleted(id)) return id;
5879
+ id.text_formatting = formatting;
5880
+ return id;
5028
5881
  }
5029
5882
 
5030
5883
  // src/label/index.ts
5031
5884
  var label_exports = {};
5032
5885
  __export(label_exports, {
5033
- copy: () => copy5,
5886
+ all: () => all4,
5887
+ copy: () => copy6,
5888
+ delete: () => delete_label,
5034
5889
  delete_label: () => delete_label,
5035
5890
  get_text: () => get_text,
5036
5891
  get_x: () => get_x,
@@ -5038,10 +5893,12 @@ __export(label_exports, {
5038
5893
  new: () => new_label2,
5039
5894
  new_label: () => new_label2,
5040
5895
  set_color: () => set_color2,
5896
+ set_point: () => set_point,
5041
5897
  set_size: () => set_size,
5042
5898
  set_style: () => set_style2,
5043
5899
  set_text: () => set_text2,
5044
5900
  set_text_font_family: () => set_text_font_family2,
5901
+ set_text_formatting: () => set_text_formatting2,
5045
5902
  set_textalign: () => set_textalign,
5046
5903
  set_textcolor: () => set_textcolor,
5047
5904
  set_tooltip: () => set_tooltip,
@@ -5051,21 +5908,47 @@ __export(label_exports, {
5051
5908
  set_y: () => set_y,
5052
5909
  set_yloc: () => set_yloc
5053
5910
  });
5054
- function new_label2(x, y, text, xloc2 = "bar_index", yloc = "price", labelColor, style, textcolor, size2, textalign, tooltip, text_font_family) {
5055
- return {
5911
+ function new_label2(...args) {
5912
+ let x, y, rest;
5913
+ if (typeof args[0] === "object" && args[0] !== null) {
5914
+ const point = args[0];
5915
+ rest = args.slice(1);
5916
+ x = pointX3(point, rest[1] ?? "bar_index");
5917
+ y = point.price;
5918
+ } else {
5919
+ [x, y] = args;
5920
+ rest = args.slice(2);
5921
+ }
5922
+ const [
5923
+ text,
5924
+ xloc2,
5925
+ yloc,
5926
+ labelColor,
5927
+ style,
5928
+ textcolor,
5929
+ size3,
5930
+ textalign,
5931
+ tooltip,
5932
+ text_font_family,
5933
+ force_overlay,
5934
+ text_formatting
5935
+ ] = rest;
5936
+ return register("label", {
5056
5937
  x,
5057
5938
  y,
5058
- xloc: xloc2,
5059
- yloc,
5939
+ xloc: xloc2 ?? "bar_index",
5940
+ yloc: yloc ?? "price",
5060
5941
  text,
5061
5942
  tooltip,
5062
5943
  color: labelColor,
5063
5944
  style,
5064
5945
  textcolor,
5065
- size: size2,
5946
+ size: size3,
5066
5947
  textalign,
5067
- text_font_family
5068
- };
5948
+ text_font_family,
5949
+ force_overlay: force_overlay ?? false,
5950
+ text_formatting
5951
+ });
5069
5952
  }
5070
5953
  function get_x(id) {
5071
5954
  return id.x;
@@ -5076,70 +5959,103 @@ function get_y(id) {
5076
5959
  function get_text(id) {
5077
5960
  return id.text;
5078
5961
  }
5079
- function copy5(id) {
5080
- return { ...id };
5962
+ function copy6(id) {
5963
+ return register("label", { ...id });
5081
5964
  }
5082
5965
  function set_x(id, x) {
5966
+ if (isDeleted(id)) return id;
5083
5967
  id.x = x;
5084
5968
  return id;
5085
5969
  }
5086
5970
  function set_y(id, y) {
5971
+ if (isDeleted(id)) return id;
5087
5972
  id.y = y;
5088
5973
  return id;
5089
5974
  }
5090
5975
  function set_xy(id, x, y) {
5976
+ if (isDeleted(id)) return id;
5091
5977
  id.x = x;
5092
5978
  id.y = y;
5093
5979
  return id;
5094
5980
  }
5095
5981
  function set_xloc3(id, x, xloc2) {
5982
+ if (isDeleted(id)) return id;
5096
5983
  id.x = x;
5097
5984
  id.xloc = xloc2;
5098
5985
  return id;
5099
5986
  }
5100
- function set_yloc(id, y, yloc) {
5101
- id.y = y;
5987
+ function set_yloc(id, yloc) {
5988
+ if (isDeleted(id)) return id;
5102
5989
  id.yloc = yloc;
5103
5990
  return id;
5104
5991
  }
5105
5992
  function set_text2(id, text) {
5993
+ if (isDeleted(id)) return id;
5106
5994
  id.text = text;
5107
5995
  return id;
5108
5996
  }
5109
5997
  function set_tooltip(id, tooltip) {
5998
+ if (isDeleted(id)) return id;
5110
5999
  id.tooltip = tooltip;
5111
6000
  return id;
5112
6001
  }
5113
6002
  function set_color2(id, labelColor) {
6003
+ if (isDeleted(id)) return id;
5114
6004
  id.color = labelColor;
5115
6005
  return id;
5116
6006
  }
5117
6007
  function set_textcolor(id, textColor) {
6008
+ if (isDeleted(id)) return id;
5118
6009
  id.textcolor = textColor;
5119
6010
  return id;
5120
6011
  }
5121
6012
  function set_style2(id, style) {
6013
+ if (isDeleted(id)) return id;
5122
6014
  id.style = style;
5123
6015
  return id;
5124
6016
  }
5125
- function set_size(id, size2) {
5126
- id.size = size2;
6017
+ function set_size(id, size3) {
6018
+ if (isDeleted(id)) return id;
6019
+ id.size = size3;
5127
6020
  return id;
5128
6021
  }
5129
6022
  function set_textalign(id, align) {
6023
+ if (isDeleted(id)) return id;
5130
6024
  id.textalign = align;
5131
6025
  return id;
5132
6026
  }
5133
6027
  function set_text_font_family2(id, font) {
6028
+ if (isDeleted(id)) return id;
5134
6029
  id.text_font_family = font;
5135
6030
  return id;
5136
6031
  }
5137
- function delete_label(_id) {
6032
+ function delete_label(id) {
6033
+ remove3("label", id);
6034
+ }
6035
+ function pointX3(point, xloc2) {
6036
+ const x = xloc2 === "bar_time" ? point.time : point.index;
6037
+ return x ?? NaN;
6038
+ }
6039
+ function all4() {
6040
+ return all("label");
6041
+ }
6042
+ function set_point(id, point) {
6043
+ if (isDeleted(id)) return id;
6044
+ id.x = pointX3(point, id.xloc);
6045
+ id.y = point.price;
6046
+ return id;
6047
+ }
6048
+ function set_text_formatting2(id, formatting) {
6049
+ if (isDeleted(id)) return id;
6050
+ id.text_formatting = formatting;
6051
+ return id;
5138
6052
  }
5139
6053
 
5140
6054
  // src/linefill/index.ts
5141
6055
  var linefill_exports = {};
5142
6056
  __export(linefill_exports, {
6057
+ all: () => all5,
6058
+ delete: () => delete_linefill,
5143
6059
  delete_linefill: () => delete_linefill,
5144
6060
  get_line1: () => get_line1,
5145
6061
  get_line2: () => get_line2,
@@ -5148,11 +6064,11 @@ __export(linefill_exports, {
5148
6064
  set_color: () => set_color3
5149
6065
  });
5150
6066
  function new_linefill2(line1, line2, fillColor) {
5151
- return {
6067
+ return register("linefill", {
5152
6068
  line1,
5153
6069
  line2,
5154
6070
  color: fillColor
5155
- };
6071
+ });
5156
6072
  }
5157
6073
  function get_line1(id) {
5158
6074
  return id.line1;
@@ -5161,16 +6077,21 @@ function get_line2(id) {
5161
6077
  return id.line2;
5162
6078
  }
5163
6079
  function set_color3(id, fillColor) {
6080
+ if (isDeleted(id)) return id;
5164
6081
  id.color = fillColor;
5165
6082
  return id;
5166
6083
  }
5167
- function delete_linefill(_id) {
6084
+ function delete_linefill(id) {
6085
+ remove3("linefill", id);
6086
+ }
6087
+ function all5() {
6088
+ return all("linefill");
5168
6089
  }
5169
6090
 
5170
6091
  // src/chartpoint/index.ts
5171
6092
  var chartpoint_exports = {};
5172
6093
  __export(chartpoint_exports, {
5173
- copy: () => copy6,
6094
+ copy: () => copy7,
5174
6095
  from_index: () => from_index,
5175
6096
  from_time: () => from_time,
5176
6097
  new: () => new_point,
@@ -5197,7 +6118,7 @@ function from_index(index, price) {
5197
6118
  price
5198
6119
  };
5199
6120
  }
5200
- function copy6(point) {
6121
+ function copy7(point) {
5201
6122
  return {
5202
6123
  time: point.time,
5203
6124
  index: point.index,
@@ -5208,6 +6129,7 @@ function copy6(point) {
5208
6129
  // src/polyline/index.ts
5209
6130
  var polyline_exports = {};
5210
6131
  __export(polyline_exports, {
6132
+ all: () => all6,
5211
6133
  clear_all: () => clear_all,
5212
6134
  delete: () => delete_polyline,
5213
6135
  delete_polyline: () => delete_polyline,
@@ -5217,7 +6139,6 @@ __export(polyline_exports, {
5217
6139
  reset_id_counter: () => reset_id_counter
5218
6140
  });
5219
6141
  var polylineIdCounter = 0;
5220
- var allPolylines = [];
5221
6142
  function generateId() {
5222
6143
  return `polyline_${++polylineIdCounter}`;
5223
6144
  }
@@ -5244,28 +6165,39 @@ function new_polyline(points, curved = false, closed = false, xloc2 = "bar_index
5244
6165
  line_width,
5245
6166
  force_overlay
5246
6167
  };
5247
- allPolylines.push(polyline);
5248
- return polyline;
6168
+ return register("polyline", polyline);
5249
6169
  }
5250
6170
  function delete_polyline(id) {
5251
- const index = allPolylines.findIndex((p) => p.id === id.id);
5252
- if (index !== -1) {
5253
- allPolylines.splice(index, 1);
5254
- }
6171
+ remove3("polyline", id);
5255
6172
  }
5256
6173
  function get_all() {
5257
- return [...allPolylines];
6174
+ return all("polyline");
6175
+ }
6176
+ function all6() {
6177
+ return all("polyline");
5258
6178
  }
5259
6179
  function clear_all() {
5260
- allPolylines.length = 0;
6180
+ for (const p of all("polyline")) remove3("polyline", p);
5261
6181
  }
5262
6182
  function reset_id_counter() {
5263
6183
  polylineIdCounter = 0;
5264
6184
  }
5265
6185
 
6186
+ // src/text/index.ts
6187
+ var text_exports = {};
6188
+ __export(text_exports, {
6189
+ format_bold: () => format_bold,
6190
+ format_italic: () => format_italic,
6191
+ format_none: () => format_none
6192
+ });
6193
+ var format_none = 0;
6194
+ var format_bold = 1;
6195
+ var format_italic = 2;
6196
+
5266
6197
  // src/ta-series.ts
5267
6198
  var ta_series_exports = {};
5268
6199
  __export(ta_series_exports, {
6200
+ accdist: () => accdist2,
5269
6201
  alma: () => alma2,
5270
6202
  atr: () => atr2,
5271
6203
  barssince: () => barssince2,
@@ -5288,6 +6220,7 @@ __export(ta_series_exports, {
5288
6220
  highestbars: () => highestbars2,
5289
6221
  hma: () => hma2,
5290
6222
  ichimoku: () => ichimoku2,
6223
+ iii: () => iii2,
5291
6224
  kc: () => kc2,
5292
6225
  kcw: () => kcw2,
5293
6226
  linreg: () => linreg2,
@@ -5300,11 +6233,15 @@ __export(ta_series_exports, {
5300
6233
  min: () => min5,
5301
6234
  mode: () => mode4,
5302
6235
  mom: () => mom2,
6236
+ nvi: () => nvi2,
6237
+ obv: () => obv2,
5303
6238
  percentile_linear_interpolation: () => percentile_linear_interpolation3,
5304
6239
  percentile_nearest_rank: () => percentile_nearest_rank3,
5305
6240
  percentrank: () => percentrank3,
5306
6241
  pivothigh: () => pivothigh2,
5307
6242
  pivotlow: () => pivotlow2,
6243
+ pvi: () => pvi2,
6244
+ pvt: () => pvt2,
5308
6245
  range: () => range3,
5309
6246
  rci: () => rci2,
5310
6247
  rising: () => rising2,
@@ -5323,9 +6260,12 @@ __export(ta_series_exports, {
5323
6260
  valuewhen: () => valuewhen2,
5324
6261
  variance: () => variance3,
5325
6262
  vwap: () => vwap2,
6263
+ vwapBands: () => vwapBands,
5326
6264
  vwma: () => vwma2,
6265
+ wad: () => wad2,
5327
6266
  wma: () => wma2,
5328
6267
  wpr: () => wpr2,
6268
+ wvad: () => wvad2,
5329
6269
  zigzag: () => zigzag2
5330
6270
  });
5331
6271
  function sma2(source, length2) {
@@ -5376,11 +6316,9 @@ function bb2(source, length2, mult2) {
5376
6316
  const lowerSeries = Series.fromArray(bars, lowerVals);
5377
6317
  return [upperSeries, basisSeries, lowerSeries];
5378
6318
  }
5379
- function stdev3(source, length2) {
6319
+ function stdev3(source, length2, biased = true) {
5380
6320
  const bars = source.bars;
5381
- const sourceValues = source.toArray();
5382
- const result = stdev(sourceValues, length2);
5383
- return Series.fromArray(bars, result);
6321
+ return Series.fromArray(bars, stdev(source.toArray(), length2, biased));
5384
6322
  }
5385
6323
  function atr2(bars, length2) {
5386
6324
  const high = bars.map((b2) => b2.high);
@@ -5396,6 +6334,40 @@ function tr2(bars, handle_na = false) {
5396
6334
  const result = tr(handle_na, high, low, close);
5397
6335
  return Series.fromArray(bars, result);
5398
6336
  }
6337
+ var col2 = (bars, f) => bars.map((b2) => b2[f] ?? NaN);
6338
+ function obv2(bars) {
6339
+ return Series.fromArray(bars, obv(col2(bars, "close"), col2(bars, "volume")));
6340
+ }
6341
+ function pvt2(bars) {
6342
+ return Series.fromArray(bars, pvt(col2(bars, "close"), col2(bars, "volume")));
6343
+ }
6344
+ function accdist2(bars) {
6345
+ return Series.fromArray(
6346
+ bars,
6347
+ accdist(col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6348
+ );
6349
+ }
6350
+ function nvi2(bars) {
6351
+ return Series.fromArray(bars, nvi(col2(bars, "close"), col2(bars, "volume")));
6352
+ }
6353
+ function pvi2(bars) {
6354
+ return Series.fromArray(bars, pvi(col2(bars, "close"), col2(bars, "volume")));
6355
+ }
6356
+ function iii2(bars) {
6357
+ return Series.fromArray(
6358
+ bars,
6359
+ iii(col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6360
+ );
6361
+ }
6362
+ function wad2(bars) {
6363
+ return Series.fromArray(bars, wad(col2(bars, "high"), col2(bars, "low"), col2(bars, "close")));
6364
+ }
6365
+ function wvad2(bars) {
6366
+ return Series.fromArray(
6367
+ bars,
6368
+ wvad(col2(bars, "open"), col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6369
+ );
6370
+ }
5399
6371
  function stoch2(source, high, low, length2) {
5400
6372
  const bars = source.bars;
5401
6373
  const sourceValues = source.toArray();
@@ -5487,12 +6459,14 @@ function supertrend2(bars, factor, atrLength) {
5487
6459
  const dirSeries = Series.fromArray(bars, dirVals);
5488
6460
  return [trendSeries, dirSeries];
5489
6461
  }
5490
- function vwap2(source, volume) {
6462
+ function vwap2(source, volume, anchor) {
5491
6463
  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);
6464
+ return Series.fromArray(bars, vwap(source.toArray(), volume.toArray(), anchor?.toArray()));
6465
+ }
6466
+ function vwapBands(source, volume, anchor, stdev_mult) {
6467
+ const bars = source.bars;
6468
+ const [m, u, l] = vwap(source.toArray(), volume.toArray(), anchor?.toArray(), stdev_mult);
6469
+ return [Series.fromArray(bars, m), Series.fromArray(bars, u), Series.fromArray(bars, l)];
5496
6470
  }
5497
6471
  function ichimoku2(bars, conversionPeriods, basePeriods, laggingSpan2Periods, displacement) {
5498
6472
  const high = bars.map((b2) => b2.high);
@@ -5677,10 +6651,9 @@ function kcw2(bars, source, length2 = 20, mult2 = 2, useTrueRange = true) {
5677
6651
  const result = kcw(source.toArray(), length2, mult2, useTrueRange, high, low, close);
5678
6652
  return Series.fromArray(bars, result);
5679
6653
  }
5680
- function range3(high, low) {
5681
- const bars = high.bars;
5682
- const result = range(high.toArray(), low.toArray());
5683
- return Series.fromArray(bars, result);
6654
+ function range3(source, length2) {
6655
+ const bars = source.bars;
6656
+ return Series.fromArray(bars, range(source.toArray(), length2));
5684
6657
  }
5685
6658
  function highestbars2(source, length2) {
5686
6659
  const bars = source.bars;
@@ -5692,15 +6665,13 @@ function lowestbars2(source, length2) {
5692
6665
  const result = lowestbars(source.toArray(), length2);
5693
6666
  return Series.fromArray(bars, result);
5694
6667
  }
5695
- function max5(source1, source2) {
5696
- const bars = source1.bars;
5697
- const result = max(source1.toArray(), source2.toArray());
5698
- return Series.fromArray(bars, result);
6668
+ function max5(source) {
6669
+ const bars = source.bars;
6670
+ return Series.fromArray(bars, max(source.toArray()));
5699
6671
  }
5700
- function min5(source1, source2) {
5701
- const bars = source1.bars;
5702
- const result = min(source1.toArray(), source2.toArray());
5703
- return Series.fromArray(bars, result);
6672
+ function min5(source) {
6673
+ const bars = source.bars;
6674
+ return Series.fromArray(bars, min(source.toArray()));
5704
6675
  }
5705
6676
  function cog2(source, length2 = 10) {
5706
6677
  const bars = source.bars;
@@ -5783,6 +6754,15 @@ var ta = {
5783
6754
  lowestbars: lowestbars2,
5784
6755
  max: max5,
5785
6756
  min: min5,
6757
+ vwapBands,
6758
+ obv: obv2,
6759
+ pvt: pvt2,
6760
+ accdist: accdist2,
6761
+ nvi: nvi2,
6762
+ pvi: pvi2,
6763
+ iii: iii2,
6764
+ wad: wad2,
6765
+ wvad: wvad2,
5786
6766
  cog: cog2,
5787
6767
  mode: mode4,
5788
6768
  percentile_linear_interpolation: percentile_linear_interpolation3,
@@ -5792,11 +6772,23 @@ var ta = {
5792
6772
 
5793
6773
  // src/utils/index.ts
5794
6774
  function isNA(value) {
5795
- return value === null || value === void 0 || Number.isNaN(value);
6775
+ return value === null || value === void 0 || Number.isNaN(value) || isDeleted(value);
5796
6776
  }
5797
6777
  function nz(value, defaultValue = 0) {
5798
6778
  return isNA(value) ? defaultValue : value;
5799
6779
  }
6780
+ function fixnan(source) {
6781
+ let last2;
6782
+ let seen = false;
6783
+ return source.map((v) => {
6784
+ if (!isNA(v)) {
6785
+ last2 = v;
6786
+ seen = true;
6787
+ return v;
6788
+ }
6789
+ return seen ? last2 : v;
6790
+ });
6791
+ }
5800
6792
  function ohlcFromBars(bars) {
5801
6793
  return {
5802
6794
  open: bars.map((b2) => b2.open),
@@ -6188,16 +7180,78 @@ var input = {
6188
7180
  title: options.title,
6189
7181
  options: options.options
6190
7182
  };
7183
+ },
7184
+ /**
7185
+ * Create a timeframe input parameter (PineScript `input.timeframe`)
7186
+ * @param defaultValue - Default timeframe string ("60", "1D", "W"); "" means the chart timeframe
7187
+ * @param options - Additional options (title, options for dropdown)
7188
+ * @returns Input value object
7189
+ *
7190
+ * @example
7191
+ * ```typescript
7192
+ * const htf = input.timeframe('1D', { title: 'Higher timeframe' });
7193
+ * console.log(htf.value); // '1D'
7194
+ * ```
7195
+ */
7196
+ timeframe(defaultValue, options = {}) {
7197
+ return {
7198
+ type: "timeframe",
7199
+ defaultValue,
7200
+ value: defaultValue,
7201
+ title: options.title,
7202
+ options: options.options
7203
+ };
7204
+ },
7205
+ /**
7206
+ * Create a session input parameter (PineScript `input.session`)
7207
+ * @param defaultValue - Default session string ("0930-1600", "0930-1600:23456")
7208
+ * @param options - Additional options (title, options for dropdown)
7209
+ * @returns Input value object
7210
+ *
7211
+ * @example
7212
+ * ```typescript
7213
+ * const rth = input.session('0930-1600', { title: 'Regular hours' });
7214
+ * console.log(rth.value); // '0930-1600'
7215
+ * ```
7216
+ */
7217
+ session(defaultValue, options = {}) {
7218
+ return {
7219
+ type: "session",
7220
+ defaultValue,
7221
+ value: defaultValue,
7222
+ title: options.title,
7223
+ options: options.options
7224
+ };
7225
+ },
7226
+ /**
7227
+ * Create a date/time input parameter (PineScript `input.time`)
7228
+ * @param defaultValue - Default UNIX time in milliseconds, e.g. `time.timestamp('2024-01-01')`
7229
+ * @param options - Additional options (title)
7230
+ * @returns Input value object
7231
+ *
7232
+ * @example
7233
+ * ```typescript
7234
+ * const start = input.time(time.timestamp('2024-01-01'), { title: 'Start' });
7235
+ * console.log(start.value); // 1704067200000
7236
+ * ```
7237
+ */
7238
+ time(defaultValue, options = {}) {
7239
+ return {
7240
+ type: "time",
7241
+ defaultValue,
7242
+ value: defaultValue,
7243
+ title: options.title
7244
+ };
6191
7245
  }
6192
7246
  };
6193
7247
  Object.freeze(input);
6194
7248
 
6195
7249
  // src/plot.ts
6196
- function plot(values, times, options = {}) {
7250
+ function plot(values2, times, options = {}) {
6197
7251
  const result = [];
6198
7252
  const offset = options.offset ?? 0;
6199
- for (let i = 0; i < values.length; i++) {
6200
- const value = values[i];
7253
+ for (let i = 0; i < values2.length; i++) {
7254
+ const value = values2[i];
6201
7255
  const timeIndex = i + offset;
6202
7256
  if (value === null || value === void 0 || Number.isNaN(value)) {
6203
7257
  continue;
@@ -6212,10 +7266,10 @@ function plot(values, times, options = {}) {
6212
7266
  }
6213
7267
  return result;
6214
7268
  }
6215
- function createPlot(id, values, times, options = {}) {
7269
+ function createPlot(id, values2, times, options = {}) {
6216
7270
  return {
6217
7271
  id,
6218
- data: plot(values, times, options),
7272
+ data: plot(values2, times, options),
6219
7273
  options
6220
7274
  };
6221
7275
  }
@@ -6456,6 +7510,42 @@ function input_string(defval, title, options) {
6456
7510
  const value = context2.inputs.getValue(id);
6457
7511
  return typeof value === "string" ? value : defval;
6458
7512
  }
7513
+ function registerOnce(config) {
7514
+ const context2 = getContext();
7515
+ if (!registeredInputs.has(config.id)) {
7516
+ context2.inputs.registerInput(config);
7517
+ registeredInputs.set(config.id, true);
7518
+ if (autoRecalculateEnabled) {
7519
+ context2.inputs.onInputChange((changedId) => {
7520
+ if (changedId === config.id) {
7521
+ recalculate();
7522
+ }
7523
+ });
7524
+ }
7525
+ }
7526
+ return context2.inputs.getValue(config.id);
7527
+ }
7528
+ function input_timeframe(defval, title, options) {
7529
+ if (!getContext()) {
7530
+ return defval;
7531
+ }
7532
+ const value = registerOnce({ id: generateInputId(title, defval, "timeframe"), type: "timeframe", defval, title, options });
7533
+ return typeof value === "string" ? value : defval;
7534
+ }
7535
+ function input_session(defval, title, options) {
7536
+ if (!getContext()) {
7537
+ return defval;
7538
+ }
7539
+ const value = registerOnce({ id: generateInputId(title, defval, "session"), type: "session", defval, title, options });
7540
+ return typeof value === "string" ? value : defval;
7541
+ }
7542
+ function input_time(defval, title) {
7543
+ if (!getContext()) {
7544
+ return defval;
7545
+ }
7546
+ const value = registerOnce({ id: generateInputId(title, defval, "time"), type: "time", defval, title });
7547
+ return typeof value === "number" ? value : defval;
7548
+ }
6459
7549
  function input_source(defval, title) {
6460
7550
  const context2 = getContext();
6461
7551
  if (!context2) {
@@ -6678,7 +7768,7 @@ var SimpleInputAdapter = class {
6678
7768
  validatedValue = Math.floor(validatedValue);
6679
7769
  }
6680
7770
  }
6681
- if (config.type === "string" && config.options && typeof value === "string") {
7771
+ if ((config.type === "string" || config.type === "timeframe" || config.type === "session") && config.options && typeof value === "string") {
6682
7772
  if (!config.options.includes(value)) {
6683
7773
  return;
6684
7774
  }
@@ -6726,8 +7816,8 @@ var SimpleInputAdapter = class {
6726
7816
  };
6727
7817
 
6728
7818
  // src/index.ts
6729
- var VERSION = "0.5.0";
6730
- var info = {
7819
+ var VERSION = "0.6.0";
7820
+ var info2 = {
6731
7821
  name: "OakScriptJS",
6732
7822
  version: VERSION,
6733
7823
  description: "Simplified PineScript-like library - Series + TA functions",
@@ -6740,8 +7830,8 @@ var info = {
6740
7830
  minimal: "No DSL layer - complexity in transpiler"
6741
7831
  },
6742
7832
  namespaces: {
6743
- core: ["ta", "math", "array", "str", "color", "time", "matrix"],
6744
- drawing: ["line", "box", "label", "linefill", "chartPoint", "polyline"],
7833
+ core: ["ta", "math", "array", "map", "str", "color", "time", "timeframe", "matrix"],
7834
+ drawing: ["line", "box", "label", "linefill", "chartPoint", "polyline", "text"],
6745
7835
  runtime: ["setContext", "plot", "hline", "input_*"],
6746
7836
  indicator: ["indicator", "input", "plotHelper", "createPlot"]
6747
7837
  }