oakscriptjs 0.3.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 (75) 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 +1673 -571
  9. package/dist/index.d.ts +8 -5
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.mjs +1673 -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/series.d.ts +1 -0
  32. package/dist/runtime/series.d.ts.map +1 -1
  33. package/dist/runtime/types.d.ts +20 -1
  34. package/dist/runtime/types.d.ts.map +1 -1
  35. package/dist/script/index.cjs +6050 -0
  36. package/dist/script/index.d.ts +555 -0
  37. package/dist/script/index.d.ts.map +1 -0
  38. package/dist/script/index.mjs +6033 -0
  39. package/dist/security/resample.d.ts +13 -0
  40. package/dist/security/resample.d.ts.map +1 -0
  41. package/dist/session/bars.d.ts +34 -0
  42. package/dist/session/bars.d.ts.map +1 -0
  43. package/dist/session/calendar.d.ts +31 -0
  44. package/dist/session/calendar.d.ts.map +1 -0
  45. package/dist/str/dateformat.d.ts +2 -0
  46. package/dist/str/dateformat.d.ts.map +1 -0
  47. package/dist/str/index.d.ts +1 -1
  48. package/dist/str/index.d.ts.map +1 -1
  49. package/dist/str/messageformat.d.ts +2 -0
  50. package/dist/str/messageformat.d.ts.map +1 -0
  51. package/dist/str/numberformat.d.ts +3 -0
  52. package/dist/str/numberformat.d.ts.map +1 -0
  53. package/dist/ta/index.d.ts +14 -5
  54. package/dist/ta/index.d.ts.map +1 -1
  55. package/dist/ta-series.d.ts +23 -5
  56. package/dist/ta-series.d.ts.map +1 -1
  57. package/dist/text/index.d.ts +4 -0
  58. package/dist/text/index.d.ts.map +1 -0
  59. package/dist/time/datestring.d.ts +2 -0
  60. package/dist/time/datestring.d.ts.map +1 -0
  61. package/dist/time/index.d.ts +11 -0
  62. package/dist/time/index.d.ts.map +1 -1
  63. package/dist/time/session.d.ts +2 -0
  64. package/dist/time/session.d.ts.map +1 -0
  65. package/dist/time/timezone.d.ts +13 -0
  66. package/dist/time/timezone.d.ts.map +1 -0
  67. package/dist/timeframe/index.d.ts +17 -0
  68. package/dist/timeframe/index.d.ts.map +1 -0
  69. package/dist/types/index.d.ts +7 -0
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/metadata.d.ts +24 -1
  72. package/dist/types/metadata.d.ts.map +1 -1
  73. package/dist/utils/index.d.ts +1 -0
  74. package/dist/utils/index.d.ts.map +1 -1
  75. package/package.json +9 -2
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;
1024
+ return pivot(high, sourceOrLeftbars, leftbarsOrRightbars, true);
1000
1025
  }
1001
- const result = [];
1002
- for (let i = 0; i < source.length; i++) {
1003
- if (i < leftbars || i + right >= source.length) {
1004
- result.push(NaN);
1005
- continue;
1006
- }
1007
- const centerValue = source[i];
1008
- let isPivot = true;
1009
- for (let j = 1; j <= leftbars; j++) {
1010
- if (source[i - j] >= centerValue) {
1011
- isPivot = false;
1012
- break;
1013
- }
1014
- }
1015
- if (isPivot) {
1016
- for (let j = 1; j <= right; j++) {
1017
- if (source[i + j] >= centerValue) {
1018
- isPivot = false;
1019
- break;
1020
- }
1021
- }
1022
- }
1023
- result.push(isPivot ? centerValue : NaN);
1024
- }
1025
- return result;
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
@@ -2153,6 +2141,18 @@ var Series = class _Series {
2153
2141
  return a * b2;
2154
2142
  });
2155
2143
  }
2144
+ /**
2145
+ * Raise the series to a power (PineScript math.pow on a series)
2146
+ * @param exponent - Series or number exponent
2147
+ * @returns New Series representing base ** exponent
2148
+ */
2149
+ pow(exponent) {
2150
+ return new _Series(this.dataSource, (bar, i, data) => {
2151
+ const a = this.extractor(bar, i, data);
2152
+ const b2 = typeof exponent === "number" ? exponent : exponent.extractor(bar, i, data);
2153
+ return Math.pow(a, b2);
2154
+ });
2155
+ }
2156
2156
  /**
2157
2157
  * Divide two series or a series by a number
2158
2158
  * @param other - Series or number to divide by
@@ -2390,8 +2390,8 @@ var Series = class _Series {
2390
2390
  * @returns New Series with computed values and no closure dependencies
2391
2391
  */
2392
2392
  materialize() {
2393
- const values = this.toArray();
2394
- const valuesCopy = [...values];
2393
+ const values2 = this.toArray();
2394
+ const valuesCopy = [...values2];
2395
2395
  return _Series.fromArray(this.dataSource, valuesCopy);
2396
2396
  }
2397
2397
  /**
@@ -2421,16 +2421,16 @@ var Series = class _Series {
2421
2421
  * @returns Value at that index
2422
2422
  */
2423
2423
  get(index) {
2424
- const values = this.toArray();
2425
- return values[index] ?? NaN;
2424
+ const values2 = this.toArray();
2425
+ return values2[index] ?? NaN;
2426
2426
  }
2427
2427
  /**
2428
2428
  * Get the last value (most recent bar)
2429
2429
  * @returns Most recent value
2430
2430
  */
2431
2431
  last() {
2432
- const values = this.toArray();
2433
- return values[values.length - 1] ?? NaN;
2432
+ const values2 = this.toArray();
2433
+ return values2[values2.length - 1] ?? NaN;
2434
2434
  }
2435
2435
  /**
2436
2436
  * Get number of values
@@ -2444,11 +2444,11 @@ var Series = class _Series {
2444
2444
  * @returns Array of { time, value } objects
2445
2445
  */
2446
2446
  toTimeValuePairs() {
2447
- const values = this.toArray();
2447
+ const values2 = this.toArray();
2448
2448
  const bars = this.dataSource.bars;
2449
2449
  return bars.map((bar, i) => ({
2450
2450
  time: bar.time,
2451
- value: values[i]
2451
+ value: values2[i]
2452
2452
  })).filter((point) => !Number.isNaN(point.value));
2453
2453
  }
2454
2454
  };
@@ -2522,60 +2522,60 @@ function round(value, precision) {
2522
2522
  const multiplier = Math.pow(10, precision);
2523
2523
  return Math.round(value * multiplier) / multiplier;
2524
2524
  }
2525
- function max2(...values) {
2526
- const hasSeries = values.some((v) => v instanceof Series);
2525
+ function max2(...values2) {
2526
+ const hasSeries = values2.some((v) => v instanceof Series);
2527
2527
  if (!hasSeries) {
2528
- return Math.max(...values);
2528
+ return Math.max(...values2);
2529
2529
  }
2530
- const firstSeries = values.find((v) => v instanceof Series);
2530
+ const firstSeries = values2.find((v) => v instanceof Series);
2531
2531
  const bars = firstSeries.bars;
2532
2532
  const length2 = bars.length;
2533
- const valueArrays = values.map(
2533
+ const valueArrays = values2.map(
2534
2534
  (v) => v instanceof Series ? v.toArray() : null
2535
2535
  );
2536
2536
  const result = [];
2537
2537
  for (let i = 0; i < length2; i++) {
2538
- const nums = values.map(
2538
+ const nums = values2.map(
2539
2539
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2540
2540
  );
2541
2541
  result.push(Math.max(...nums));
2542
2542
  }
2543
2543
  return Series.fromArray(bars, result);
2544
2544
  }
2545
- function min2(...values) {
2546
- const hasSeries = values.some((v) => v instanceof Series);
2545
+ function min2(...values2) {
2546
+ const hasSeries = values2.some((v) => v instanceof Series);
2547
2547
  if (!hasSeries) {
2548
- return Math.min(...values);
2548
+ return Math.min(...values2);
2549
2549
  }
2550
- const firstSeries = values.find((v) => v instanceof Series);
2550
+ const firstSeries = values2.find((v) => v instanceof Series);
2551
2551
  const bars = firstSeries.bars;
2552
2552
  const length2 = bars.length;
2553
- const valueArrays = values.map(
2553
+ const valueArrays = values2.map(
2554
2554
  (v) => v instanceof Series ? v.toArray() : null
2555
2555
  );
2556
2556
  const result = [];
2557
2557
  for (let i = 0; i < length2; i++) {
2558
- const nums = values.map(
2558
+ const nums = values2.map(
2559
2559
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2560
2560
  );
2561
2561
  result.push(Math.min(...nums));
2562
2562
  }
2563
2563
  return Series.fromArray(bars, result);
2564
2564
  }
2565
- function avg(...values) {
2566
- const hasSeries = values.some((v) => v instanceof Series);
2565
+ function avg(...values2) {
2566
+ const hasSeries = values2.some((v) => v instanceof Series);
2567
2567
  if (!hasSeries) {
2568
- return values.reduce((a, b2) => a + b2, 0) / values.length;
2568
+ return values2.reduce((a, b2) => a + b2, 0) / values2.length;
2569
2569
  }
2570
- const firstSeries = values.find((v) => v instanceof Series);
2570
+ const firstSeries = values2.find((v) => v instanceof Series);
2571
2571
  const bars = firstSeries.bars;
2572
2572
  const length2 = bars.length;
2573
- const valueArrays = values.map(
2573
+ const valueArrays = values2.map(
2574
2574
  (v) => v instanceof Series ? v.toArray() : null
2575
2575
  );
2576
2576
  const result = [];
2577
2577
  for (let i = 0; i < length2; i++) {
2578
- const nums = values.map(
2578
+ const nums = values2.map(
2579
2579
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2580
2580
  );
2581
2581
  const sum4 = nums.reduce((a, b2) => a + b2, 0);
@@ -2809,10 +2809,10 @@ function sign(value) {
2809
2809
  }
2810
2810
  return value > 0 ? 1 : value < 0 ? -1 : 0;
2811
2811
  }
2812
- function round_to_mintick(number, mintick) {
2813
- if (number instanceof Series) {
2814
- const bars = number.bars;
2815
- 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();
2816
2816
  const length2 = bars.length;
2817
2817
  if (mintick === void 0) {
2818
2818
  throw new Error(
@@ -2836,7 +2836,7 @@ function round_to_mintick(number, mintick) {
2836
2836
  }
2837
2837
  return Series.fromArray(bars, result);
2838
2838
  }
2839
- if (isNaN(number)) {
2839
+ if (isNaN(number2)) {
2840
2840
  return NaN;
2841
2841
  }
2842
2842
  if (mintick === void 0) {
@@ -2845,9 +2845,9 @@ function round_to_mintick(number, mintick) {
2845
2845
  );
2846
2846
  }
2847
2847
  if (mintick === 0) {
2848
- return number;
2848
+ return number2;
2849
2849
  }
2850
- return Math.round(number / mintick) * mintick;
2850
+ return Math.round(number2 / mintick) * mintick;
2851
2851
  }
2852
2852
  var pi = Math.PI;
2853
2853
  var e = Math.E;
@@ -2913,9 +2913,9 @@ __export(array_exports, {
2913
2913
  unshift: () => unshift,
2914
2914
  variance: () => variance2
2915
2915
  });
2916
- function new_array(size2 = 0, initial_value) {
2916
+ function new_array(size3 = 0, initial_value) {
2917
2917
  const arr = [];
2918
- for (let i = 0; i < size2; i++) {
2918
+ for (let i = 0; i < size3; i++) {
2919
2919
  arr.push(initial_value);
2920
2920
  }
2921
2921
  return arr;
@@ -2989,11 +2989,13 @@ function sum2(id) {
2989
2989
  function avg2(id) {
2990
2990
  return sum2(id) / size(id);
2991
2991
  }
2992
- function min3(id) {
2993
- 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;
2994
2995
  }
2995
- function max3(id) {
2996
- 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;
2997
2999
  }
2998
3000
  function median2(id) {
2999
3001
  const sorted = [...id].sort((a, b2) => a - b2);
@@ -3014,16 +3016,15 @@ function mode2(id) {
3014
3016
  }
3015
3017
  return mode5;
3016
3018
  }
3017
- function stdev2(id) {
3018
- const mean = avg2(id);
3019
- const squareDiffs = id.map((value) => Math.pow(value - mean, 2));
3020
- const avgSquareDiff = sum2(squareDiffs) / size(id);
3021
- return Math.sqrt(avgSquareDiff);
3019
+ function stdev2(id, biased = true) {
3020
+ return Math.sqrt(variance2(id, biased));
3022
3021
  }
3023
- function variance2(id) {
3024
- const mean = avg2(id);
3025
- const squareDiffs = id.map((value) => Math.pow(value - mean, 2));
3026
- 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);
3027
3028
  }
3028
3029
  function fill(id, value, index_from = 0, index_to) {
3029
3030
  const end = index_to ?? id.length;
@@ -3031,8 +3032,8 @@ function fill(id, value, index_from = 0, index_to) {
3031
3032
  id[i] = value;
3032
3033
  }
3033
3034
  }
3034
- function from(id) {
3035
- return copy(id);
3035
+ function from(...values2) {
3036
+ return [...values2];
3036
3037
  }
3037
3038
  function first(id) {
3038
3039
  return id[0];
@@ -3040,38 +3041,38 @@ function first(id) {
3040
3041
  function last(id) {
3041
3042
  return id[id.length - 1];
3042
3043
  }
3043
- function some(id, predicate) {
3044
- return id.some(predicate);
3044
+ function some(id) {
3045
+ return id.some((v) => v === true);
3045
3046
  }
3046
- function every(id, predicate) {
3047
- return id.every(predicate);
3047
+ function every(id) {
3048
+ return id.length > 0 && id.every((v) => v === true);
3048
3049
  }
3049
- function new_bool(size2 = 0, initial_value = false) {
3050
- return new_array(size2, initial_value);
3050
+ function new_bool(size3 = 0, initial_value = false) {
3051
+ return new_array(size3, initial_value);
3051
3052
  }
3052
- function new_float(size2 = 0, initial_value = NaN) {
3053
- return new_array(size2, initial_value);
3053
+ function new_float(size3 = 0, initial_value = NaN) {
3054
+ return new_array(size3, initial_value);
3054
3055
  }
3055
- function new_int(size2 = 0, initial_value = NaN) {
3056
- return new_array(size2, initial_value);
3056
+ function new_int(size3 = 0, initial_value = NaN) {
3057
+ return new_array(size3, initial_value);
3057
3058
  }
3058
- function new_string(size2 = 0, initial_value) {
3059
- return new_array(size2, initial_value);
3059
+ function new_string(size3 = 0, initial_value) {
3060
+ return new_array(size3, initial_value);
3060
3061
  }
3061
- function new_color(size2 = 0, initial_value) {
3062
- return new_array(size2, initial_value);
3062
+ function new_color(size3 = 0, initial_value) {
3063
+ return new_array(size3, initial_value);
3063
3064
  }
3064
- function new_line(size2 = 0, initial_value) {
3065
- return new_array(size2, initial_value);
3065
+ function new_line(size3 = 0, initial_value) {
3066
+ return new_array(size3, initial_value);
3066
3067
  }
3067
- function new_box(size2 = 0, initial_value) {
3068
- return new_array(size2, initial_value);
3068
+ function new_box(size3 = 0, initial_value) {
3069
+ return new_array(size3, initial_value);
3069
3070
  }
3070
- function new_label(size2 = 0, initial_value) {
3071
- return new_array(size2, initial_value);
3071
+ function new_label(size3 = 0, initial_value) {
3072
+ return new_array(size3, initial_value);
3072
3073
  }
3073
- function new_linefill(size2 = 0, initial_value) {
3074
- return new_array(size2, initial_value);
3074
+ function new_linefill(size3 = 0, initial_value) {
3075
+ return new_array(size3, initial_value);
3075
3076
  }
3076
3077
  function abs2(id) {
3077
3078
  return id.map((x) => Math.abs(x));
@@ -3211,8 +3212,70 @@ function standardize(id) {
3211
3212
  }
3212
3213
  return id.map((value) => (value - mean) / stdDev);
3213
3214
  }
3214
- function newtype(size2 = 0, initial_value) {
3215
- 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);
3216
3279
  }
3217
3280
 
3218
3281
  // src/str/index.ts
@@ -3220,7 +3283,7 @@ var str_exports = {};
3220
3283
  __export(str_exports, {
3221
3284
  charAt: () => charAt,
3222
3285
  concat: () => concat2,
3223
- contains: () => contains,
3286
+ contains: () => contains2,
3224
3287
  endswith: () => endswith,
3225
3288
  format: () => format,
3226
3289
  format_time: () => format_time,
@@ -3241,15 +3304,486 @@ __export(str_exports, {
3241
3304
  trimRight: () => trimRight,
3242
3305
  upper: () => upper
3243
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
3244
3760
  function length(str) {
3245
3761
  return str.length;
3246
3762
  }
3247
3763
  function tostring(value, format2) {
3248
- if (typeof value === "number" && format2) {
3249
- const decimals = format2.split(".")[1]?.length || 0;
3250
- 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");
3251
3786
  }
3252
- return String(value);
3253
3787
  }
3254
3788
  function tonumber(str) {
3255
3789
  const num = parseFloat(str);
@@ -3264,7 +3798,7 @@ function upper(str) {
3264
3798
  function lower(str) {
3265
3799
  return str.toLowerCase();
3266
3800
  }
3267
- function contains(source, str) {
3801
+ function contains2(source, str) {
3268
3802
  return source.includes(str);
3269
3803
  }
3270
3804
  function pos(source, str) {
@@ -3287,11 +3821,7 @@ function concat2(...strings) {
3287
3821
  return strings.join("");
3288
3822
  }
3289
3823
  function format(formatStr, ...args) {
3290
- let result = formatStr;
3291
- args.forEach((arg, index) => {
3292
- result = result.replaceAll(`{${index}}`, String(arg));
3293
- });
3294
- return result;
3824
+ return formatMessage(formatStr, args, "Etc/UTC");
3295
3825
  }
3296
3826
  function startswith(source, str) {
3297
3827
  return source.startsWith(str);
@@ -3319,84 +3849,8 @@ function repeat(source, count, separator = "") {
3319
3849
  if (count <= 0) return "";
3320
3850
  return Array(count).fill(source).join(separator);
3321
3851
  }
3322
- function format_time(time, format2) {
3323
- const date = new Date(time);
3324
- const monthNames = [
3325
- "January",
3326
- "February",
3327
- "March",
3328
- "April",
3329
- "May",
3330
- "June",
3331
- "July",
3332
- "August",
3333
- "September",
3334
- "October",
3335
- "November",
3336
- "December"
3337
- ];
3338
- const monthNamesShort = [
3339
- "Jan",
3340
- "Feb",
3341
- "Mar",
3342
- "Apr",
3343
- "May",
3344
- "Jun",
3345
- "Jul",
3346
- "Aug",
3347
- "Sep",
3348
- "Oct",
3349
- "Nov",
3350
- "Dec"
3351
- ];
3352
- const year = date.getUTCFullYear();
3353
- const month = date.getUTCMonth();
3354
- const day = date.getUTCDate();
3355
- const hours = date.getUTCHours();
3356
- const minutes = date.getUTCMinutes();
3357
- const seconds = date.getUTCSeconds();
3358
- const pad = (num, len = 2) => num.toString().padStart(len, "0");
3359
- const hours12 = hours % 12 || 12;
3360
- const ampm = hours < 12 ? "AM" : "PM";
3361
- const replacements = [
3362
- // Year (process yyyy before yy)
3363
- [/yyyy/g, year.toString()],
3364
- [/yy/g, year.toString().slice(-2)],
3365
- // Month (process MMMM before MMM before MM before M)
3366
- [/MMMM/g, monthNames[month]],
3367
- [/MMM/g, monthNamesShort[month]],
3368
- [/MM/g, pad(month + 1)],
3369
- [/M/g, (month + 1).toString()],
3370
- // Day (process dd before d)
3371
- [/dd/g, pad(day)],
3372
- [/d/g, day.toString()],
3373
- // Hours 24-hour (process HH before H)
3374
- [/HH/g, pad(hours)],
3375
- [/H/g, hours.toString()],
3376
- // Hours 12-hour (process hh before h)
3377
- [/hh/g, pad(hours12)],
3378
- [/h/g, hours12.toString()],
3379
- // Minutes (process mm before m)
3380
- [/mm/g, pad(minutes)],
3381
- [/m/g, minutes.toString()],
3382
- // Seconds (process ss before s)
3383
- [/ss/g, pad(seconds)],
3384
- [/s/g, seconds.toString()],
3385
- // AM/PM
3386
- [/a/g, ampm]
3387
- ];
3388
- let result = format2;
3389
- const tokens = [];
3390
- replacements.forEach(([pattern, value], index) => {
3391
- const token = `\uFFF0${index}\uFFF1`;
3392
- result = result.replace(pattern, token);
3393
- tokens[index] = value;
3394
- });
3395
- tokens.forEach((value, index) => {
3396
- const token = `\uFFF0${index}\uFFF1`;
3397
- result = result.replaceAll(token, value);
3398
- });
3399
- return result;
3852
+ function format_time(time, format2 = "yyyy-MM-dd'T'HH:mm:ssZ", timezone = "Etc/UTC") {
3853
+ return formatDate(time, format2, timezone);
3400
3854
  }
3401
3855
 
3402
3856
  // src/color/index.ts
@@ -3494,16 +3948,16 @@ var teal = "#008080";
3494
3948
  var white = "#FFFFFF";
3495
3949
  var yellow = "#FFFF00";
3496
3950
  function from_gradient(value, bottom_value, top_value, bottom_color, top_color) {
3497
- const parseColor2 = (col2) => {
3498
- if (typeof col2 === "string") {
3499
- if (col2.startsWith("#")) {
3500
- const hex = col2.slice(1);
3951
+ const parseColor2 = (col3) => {
3952
+ if (typeof col3 === "string") {
3953
+ if (col3.startsWith("#")) {
3954
+ const hex = col3.slice(1);
3501
3955
  const r4 = parseInt(hex.slice(0, 2), 16);
3502
3956
  const g4 = parseInt(hex.slice(2, 4), 16);
3503
3957
  const b4 = parseInt(hex.slice(4, 6), 16);
3504
3958
  return [r4, g4, b4, 1];
3505
3959
  }
3506
- 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.]+))?\)/);
3507
3961
  if (match2) {
3508
3962
  return [
3509
3963
  parseInt(match2[1]),
@@ -3538,21 +3992,260 @@ function from_gradient(value, bottom_value, top_value, bottom_color, top_color)
3538
3992
  // src/time/index.ts
3539
3993
  var time_exports = {};
3540
3994
  __export(time_exports, {
3995
+ dayofmonth: () => dayofmonth,
3996
+ dayofweek: () => dayofweek,
3997
+ hour: () => hour,
3998
+ inSession: () => inSession2,
3999
+ minute: () => minute,
4000
+ month: () => month,
3541
4001
  now: () => now,
3542
- timestamp: () => timestamp
4002
+ second: () => second,
4003
+ timestamp: () => timestamp,
4004
+ weekofyear: () => weekofyear,
4005
+ year: () => year
3543
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
3544
4135
  function now() {
3545
4136
  return Date.now();
3546
4137
  }
3547
- function timestamp(year, month, day, hour, minute, second) {
3548
- return new Date(
3549
- year,
3550
- month - 1,
3551
- day,
3552
- hour || 0,
3553
- minute || 0,
3554
- second || 0
3555
- ).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
+ };
3556
4249
  }
3557
4250
 
3558
4251
  // src/matrix/index.ts
@@ -3564,14 +4257,14 @@ __export(matrix_exports, {
3564
4257
  col: () => col,
3565
4258
  columns: () => columns,
3566
4259
  concat: () => concat3,
3567
- copy: () => copy2,
4260
+ copy: () => copy3,
3568
4261
  det: () => det,
3569
4262
  diff: () => diff,
3570
4263
  eigenvalues: () => eigenvalues,
3571
4264
  eigenvectors: () => eigenvectors,
3572
4265
  elements_count: () => elements_count,
3573
4266
  fill: () => fill2,
3574
- get: () => get2,
4267
+ get: () => get3,
3575
4268
  inv: () => inv,
3576
4269
  is_antidiagonal: () => is_antidiagonal,
3577
4270
  is_antisymmetric: () => is_antisymmetric,
@@ -3620,7 +4313,7 @@ function new_matrix(rows2, columns2, initial_value) {
3620
4313
  }
3621
4314
  return { rows: rows2, columns: columns2, data };
3622
4315
  }
3623
- function get2(id, row2, column) {
4316
+ function get3(id, row2, column) {
3624
4317
  if (row2 < 0 || row2 >= id.rows || column < 0 || column >= id.columns) {
3625
4318
  throw new Error(`Matrix index out of bounds: [${row2}, ${column}] for matrix of size [${id.rows}, ${id.columns}]`);
3626
4319
  }
@@ -3653,7 +4346,7 @@ function col(id, column_index) {
3653
4346
  }
3654
4347
  return id.data.map((r2) => r2[column_index]);
3655
4348
  }
3656
- function copy2(id) {
4349
+ function copy3(id) {
3657
4350
  const newData = id.data.map((r2) => [...r2]);
3658
4351
  return {
3659
4352
  rows: id.rows,
@@ -4005,24 +4698,24 @@ function median3(id) {
4005
4698
  if (id.rows === 0 || id.columns === 0) {
4006
4699
  return NaN;
4007
4700
  }
4008
- const values = [];
4701
+ const values2 = [];
4009
4702
  for (let i = 0; i < id.rows; i++) {
4010
4703
  for (let j = 0; j < id.columns; j++) {
4011
4704
  const val = id.data[i][j];
4012
4705
  if (val !== null && val !== void 0 && !isNaN(val)) {
4013
- values.push(val);
4706
+ values2.push(val);
4014
4707
  }
4015
4708
  }
4016
4709
  }
4017
- if (values.length === 0) {
4710
+ if (values2.length === 0) {
4018
4711
  return NaN;
4019
4712
  }
4020
- values.sort((a, b2) => a - b2);
4021
- const mid = Math.floor(values.length / 2);
4022
- if (values.length % 2 === 0) {
4023
- 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;
4024
4717
  } else {
4025
- return values[mid];
4718
+ return values2[mid];
4026
4719
  }
4027
4720
  }
4028
4721
  function mode3(id) {
@@ -4268,7 +4961,7 @@ function pow2(id, power) {
4268
4961
  base = inverse;
4269
4962
  p = -power;
4270
4963
  } else {
4271
- base = copy2(id);
4964
+ base = copy3(id);
4272
4965
  }
4273
4966
  let result = createIdentity(n);
4274
4967
  while (p > 0) {
@@ -4297,31 +4990,31 @@ function det(id) {
4297
4990
  const a = id.data.map((row2) => [...row2]);
4298
4991
  let determinant = 1;
4299
4992
  let swapCount = 0;
4300
- for (let col2 = 0; col2 < n; col2++) {
4301
- let maxRow = col2;
4302
- let maxVal = Math.abs(a[col2][col2]);
4303
- for (let row2 = col2 + 1; row2 < n; row2++) {
4304
- 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]);
4305
4998
  if (absVal > maxVal) {
4306
4999
  maxVal = absVal;
4307
5000
  maxRow = row2;
4308
5001
  }
4309
5002
  }
4310
- if (maxRow !== col2) {
4311
- const temp = a[col2];
4312
- a[col2] = a[maxRow];
5003
+ if (maxRow !== col3) {
5004
+ const temp = a[col3];
5005
+ a[col3] = a[maxRow];
4313
5006
  a[maxRow] = temp;
4314
5007
  swapCount++;
4315
5008
  }
4316
- const pivot = a[col2][col2];
4317
- if (Math.abs(pivot) < EPSILON) {
5009
+ const pivot2 = a[col3][col3];
5010
+ if (Math.abs(pivot2) < EPSILON) {
4318
5011
  return 0;
4319
5012
  }
4320
- determinant *= pivot;
4321
- for (let row2 = col2 + 1; row2 < n; row2++) {
4322
- const factor = a[row2][col2] / pivot;
4323
- for (let j = col2; j < n; j++) {
4324
- 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];
4325
5018
  }
4326
5019
  }
4327
5020
  }
@@ -4349,33 +5042,33 @@ function inv(id) {
4349
5042
  }
4350
5043
  aug.push(row2);
4351
5044
  }
4352
- for (let col2 = 0; col2 < n; col2++) {
4353
- let maxRow = col2;
4354
- let maxVal = Math.abs(aug[col2][col2]);
4355
- for (let row2 = col2 + 1; row2 < n; row2++) {
4356
- 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]);
4357
5050
  if (absVal > maxVal) {
4358
5051
  maxVal = absVal;
4359
5052
  maxRow = row2;
4360
5053
  }
4361
5054
  }
4362
- if (maxRow !== col2) {
4363
- const temp = aug[col2];
4364
- aug[col2] = aug[maxRow];
5055
+ if (maxRow !== col3) {
5056
+ const temp = aug[col3];
5057
+ aug[col3] = aug[maxRow];
4365
5058
  aug[maxRow] = temp;
4366
5059
  }
4367
- const pivot = aug[col2][col2];
4368
- if (Math.abs(pivot) < EPSILON) {
5060
+ const pivot2 = aug[col3][col3];
5061
+ if (Math.abs(pivot2) < EPSILON) {
4369
5062
  return null;
4370
5063
  }
4371
5064
  for (let j = 0; j < 2 * n; j++) {
4372
- aug[col2][j] = aug[col2][j] / pivot;
5065
+ aug[col3][j] = aug[col3][j] / pivot2;
4373
5066
  }
4374
5067
  for (let row2 = 0; row2 < n; row2++) {
4375
- if (row2 !== col2) {
4376
- const factor = aug[row2][col2];
5068
+ if (row2 !== col3) {
5069
+ const factor = aug[row2][col3];
4377
5070
  for (let j = 0; j < 2 * n; j++) {
4378
- aug[row2][j] = aug[row2][j] - factor * aug[col2][j];
5071
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4379
5072
  }
4380
5073
  }
4381
5074
  }
@@ -4438,11 +5131,11 @@ function rank(id) {
4438
5131
  const m = id.rows;
4439
5132
  const n = id.columns;
4440
5133
  let r2 = 0;
4441
- for (let col2 = 0; col2 < n && r2 < m; col2++) {
5134
+ for (let col3 = 0; col3 < n && r2 < m; col3++) {
4442
5135
  let maxRow = r2;
4443
- let maxVal = Math.abs(a[r2][col2]);
5136
+ let maxVal = Math.abs(a[r2][col3]);
4444
5137
  for (let row2 = r2 + 1; row2 < m; row2++) {
4445
- const absVal = Math.abs(a[row2][col2]);
5138
+ const absVal = Math.abs(a[row2][col3]);
4446
5139
  if (absVal > maxVal) {
4447
5140
  maxVal = absVal;
4448
5141
  maxRow = row2;
@@ -4456,10 +5149,10 @@ function rank(id) {
4456
5149
  a[r2] = a[maxRow];
4457
5150
  a[maxRow] = temp;
4458
5151
  }
4459
- const pivot = a[r2][col2];
5152
+ const pivot2 = a[r2][col3];
4460
5153
  for (let row2 = r2 + 1; row2 < m; row2++) {
4461
- const factor = a[row2][col2] / pivot;
4462
- for (let j = col2; j < n; j++) {
5154
+ const factor = a[row2][col3] / pivot2;
5155
+ for (let j = col3; j < n; j++) {
4463
5156
  a[row2][j] = a[row2][j] - factor * a[r2][j];
4464
5157
  }
4465
5158
  }
@@ -4667,29 +5360,29 @@ function inverseIteration(m, lambda) {
4667
5360
  function solveLinearSystem(a, b2) {
4668
5361
  const n = a.length;
4669
5362
  const aug = a.map((row2, i) => [...row2, b2[i]]);
4670
- for (let col2 = 0; col2 < n; col2++) {
4671
- let maxRow = col2;
4672
- let maxVal = Math.abs(aug[col2][col2]);
4673
- for (let row2 = col2 + 1; row2 < n; row2++) {
4674
- 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]);
4675
5368
  if (absVal > maxVal) {
4676
5369
  maxVal = absVal;
4677
5370
  maxRow = row2;
4678
5371
  }
4679
5372
  }
4680
- if (maxRow !== col2) {
4681
- const temp = aug[col2];
4682
- aug[col2] = aug[maxRow];
5373
+ if (maxRow !== col3) {
5374
+ const temp = aug[col3];
5375
+ aug[col3] = aug[maxRow];
4683
5376
  aug[maxRow] = temp;
4684
5377
  }
4685
- const pivot = aug[col2][col2];
4686
- if (Math.abs(pivot) < EPSILON) {
5378
+ const pivot2 = aug[col3][col3];
5379
+ if (Math.abs(pivot2) < EPSILON) {
4687
5380
  continue;
4688
5381
  }
4689
- for (let row2 = col2 + 1; row2 < n; row2++) {
4690
- const factor = aug[row2][col2] / pivot;
4691
- for (let j = col2; j <= n; j++) {
4692
- 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];
4693
5386
  }
4694
5387
  }
4695
5388
  }
@@ -4721,8 +5414,8 @@ function kron(id1, id2) {
4721
5414
  for (let i2 = 0; i2 < m2; i2++) {
4722
5415
  for (let j2 = 0; j2 < n2; j2++) {
4723
5416
  const row2 = i1 * m2 + i2;
4724
- const col2 = j1 * n2 + j2;
4725
- data[row2][col2] = a * id2.data[i2][j2];
5417
+ const col3 = j1 * n2 + j2;
5418
+ data[row2][col3] = a * id2.data[i2][j2];
4726
5419
  }
4727
5420
  }
4728
5421
  }
@@ -4740,7 +5433,9 @@ function newtype2(rows2 = 0, columns2 = 0, initial_value) {
4740
5433
  // src/line/index.ts
4741
5434
  var line_exports = {};
4742
5435
  __export(line_exports, {
4743
- copy: () => copy3,
5436
+ all: () => all2,
5437
+ copy: () => copy4,
5438
+ delete: () => delete_line,
4744
5439
  delete_line: () => delete_line,
4745
5440
  get_price: () => get_price,
4746
5441
  get_x1: () => get_x1,
@@ -4751,6 +5446,8 @@ __export(line_exports, {
4751
5446
  new_line: () => new_line2,
4752
5447
  set_color: () => set_color,
4753
5448
  set_extend: () => set_extend,
5449
+ set_first_point: () => set_first_point,
5450
+ set_second_point: () => set_second_point,
4754
5451
  set_style: () => set_style,
4755
5452
  set_width: () => set_width,
4756
5453
  set_x1: () => set_x1,
@@ -4761,18 +5458,78 @@ __export(line_exports, {
4761
5458
  set_y1: () => set_y1,
4762
5459
  set_y2: () => set_y2
4763
5460
  });
4764
- function new_line2(x1, y1, x2, y2, xloc2 = "bar_index", extend = "none", lineColor, style, width) {
4765
- 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", {
4766
5522
  x1,
4767
5523
  y1,
4768
5524
  x2,
4769
5525
  y2,
4770
- xloc: xloc2,
4771
- extend,
5526
+ xloc: xloc2 ?? "bar_index",
5527
+ extend: extend ?? "none",
4772
5528
  color: lineColor,
4773
5529
  style: style || "solid",
4774
- width: width || 1
4775
- };
5530
+ width: width || 1,
5531
+ force_overlay: force_overlay ?? false
5532
+ });
4776
5533
  }
4777
5534
  function get_price(id, x) {
4778
5535
  const { x1, y1, x2, y2, extend, xloc: xloc2 } = id;
@@ -4811,64 +5568,97 @@ function get_y1(id) {
4811
5568
  function get_y2(id) {
4812
5569
  return id.y2;
4813
5570
  }
4814
- function copy3(id) {
4815
- return { ...id };
5571
+ function copy4(id) {
5572
+ return register("line", { ...id });
4816
5573
  }
4817
5574
  function set_x1(id, x) {
5575
+ if (isDeleted(id)) return id;
4818
5576
  id.x1 = x;
4819
5577
  return id;
4820
5578
  }
4821
5579
  function set_x2(id, x) {
5580
+ if (isDeleted(id)) return id;
4822
5581
  id.x2 = x;
4823
5582
  return id;
4824
5583
  }
4825
5584
  function set_y1(id, y) {
5585
+ if (isDeleted(id)) return id;
4826
5586
  id.y1 = y;
4827
5587
  return id;
4828
5588
  }
4829
5589
  function set_y2(id, y) {
5590
+ if (isDeleted(id)) return id;
4830
5591
  id.y2 = y;
4831
5592
  return id;
4832
5593
  }
4833
5594
  function set_xy1(id, x, y) {
5595
+ if (isDeleted(id)) return id;
4834
5596
  id.x1 = x;
4835
5597
  id.y1 = y;
4836
5598
  return id;
4837
5599
  }
4838
5600
  function set_xy2(id, x, y) {
5601
+ if (isDeleted(id)) return id;
4839
5602
  id.x2 = x;
4840
5603
  id.y2 = y;
4841
5604
  return id;
4842
5605
  }
4843
5606
  function set_xloc(id, x1, x2, xloc2) {
5607
+ if (isDeleted(id)) return id;
4844
5608
  id.x1 = x1;
4845
5609
  id.x2 = x2;
4846
5610
  id.xloc = xloc2;
4847
5611
  return id;
4848
5612
  }
4849
5613
  function set_extend(id, extend) {
5614
+ if (isDeleted(id)) return id;
4850
5615
  id.extend = extend;
4851
5616
  return id;
4852
5617
  }
4853
5618
  function set_color(id, lineColor) {
5619
+ if (isDeleted(id)) return id;
4854
5620
  id.color = lineColor;
4855
5621
  return id;
4856
5622
  }
4857
5623
  function set_style(id, style) {
5624
+ if (isDeleted(id)) return id;
4858
5625
  id.style = style;
4859
5626
  return id;
4860
5627
  }
4861
5628
  function set_width(id, width) {
5629
+ if (isDeleted(id)) return id;
4862
5630
  id.width = width;
4863
5631
  return id;
4864
5632
  }
4865
- 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;
4866
5654
  }
4867
5655
 
4868
5656
  // src/box/index.ts
4869
5657
  var box_exports = {};
4870
5658
  __export(box_exports, {
4871
- copy: () => copy4,
5659
+ all: () => all3,
5660
+ copy: () => copy5,
5661
+ delete: () => delete_box,
4872
5662
  delete_box: () => delete_box,
4873
5663
  get_bottom: () => get_bottom,
4874
5664
  get_left: () => get_left,
@@ -4881,6 +5671,7 @@ __export(box_exports, {
4881
5671
  set_border_style: () => set_border_style,
4882
5672
  set_border_width: () => set_border_width,
4883
5673
  set_bottom: () => set_bottom,
5674
+ set_bottom_right_point: () => set_bottom_right_point,
4884
5675
  set_extend: () => set_extend2,
4885
5676
  set_left: () => set_left,
4886
5677
  set_lefttop: () => set_lefttop,
@@ -4889,21 +5680,49 @@ __export(box_exports, {
4889
5680
  set_text: () => set_text,
4890
5681
  set_text_color: () => set_text_color,
4891
5682
  set_text_font_family: () => set_text_font_family,
5683
+ set_text_formatting: () => set_text_formatting,
4892
5684
  set_text_halign: () => set_text_halign,
4893
5685
  set_text_size: () => set_text_size,
4894
5686
  set_text_valign: () => set_text_valign,
4895
5687
  set_text_wrap: () => set_text_wrap,
4896
5688
  set_top: () => set_top,
5689
+ set_top_left_point: () => set_top_left_point,
4897
5690
  set_xloc: () => set_xloc2
4898
5691
  });
4899
- 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) {
4900
- 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", {
4901
5720
  left,
4902
5721
  top,
4903
5722
  right,
4904
5723
  bottom,
4905
- xloc: xloc2,
4906
- extend,
5724
+ xloc: xloc2 ?? "bar_index",
5725
+ extend: extend ?? "none",
4907
5726
  border_color,
4908
5727
  border_width: border_width || 1,
4909
5728
  border_style: border_style || "solid",
@@ -4914,8 +5733,10 @@ function new_box2(left, top, right, bottom, xloc2 = "bar_index", extend = "none"
4914
5733
  text_halign,
4915
5734
  text_valign,
4916
5735
  text_wrap,
4917
- text_font_family
4918
- };
5736
+ text_font_family,
5737
+ force_overlay: force_overlay ?? false,
5738
+ text_formatting
5739
+ });
4919
5740
  }
4920
5741
  function get_left(id) {
4921
5742
  return id.left;
@@ -4929,96 +5750,142 @@ function get_top(id) {
4929
5750
  function get_bottom(id) {
4930
5751
  return id.bottom;
4931
5752
  }
4932
- function copy4(id) {
4933
- return { ...id };
5753
+ function copy5(id) {
5754
+ return register("box", { ...id });
4934
5755
  }
4935
5756
  function set_left(id, left) {
5757
+ if (isDeleted(id)) return id;
4936
5758
  id.left = left;
4937
5759
  return id;
4938
5760
  }
4939
5761
  function set_right(id, right) {
5762
+ if (isDeleted(id)) return id;
4940
5763
  id.right = right;
4941
5764
  return id;
4942
5765
  }
4943
5766
  function set_top(id, top) {
5767
+ if (isDeleted(id)) return id;
4944
5768
  id.top = top;
4945
5769
  return id;
4946
5770
  }
4947
5771
  function set_bottom(id, bottom) {
5772
+ if (isDeleted(id)) return id;
4948
5773
  id.bottom = bottom;
4949
5774
  return id;
4950
5775
  }
4951
5776
  function set_lefttop(id, left, top) {
5777
+ if (isDeleted(id)) return id;
4952
5778
  id.left = left;
4953
5779
  id.top = top;
4954
5780
  return id;
4955
5781
  }
4956
5782
  function set_rightbottom(id, right, bottom) {
5783
+ if (isDeleted(id)) return id;
4957
5784
  id.right = right;
4958
5785
  id.bottom = bottom;
4959
5786
  return id;
4960
5787
  }
4961
5788
  function set_xloc2(id, left, right, xloc2) {
5789
+ if (isDeleted(id)) return id;
4962
5790
  id.left = left;
4963
5791
  id.right = right;
4964
5792
  id.xloc = xloc2;
4965
5793
  return id;
4966
5794
  }
4967
5795
  function set_extend2(id, extend) {
5796
+ if (isDeleted(id)) return id;
4968
5797
  id.extend = extend;
4969
5798
  return id;
4970
5799
  }
4971
5800
  function set_border_color(id, borderColor) {
5801
+ if (isDeleted(id)) return id;
4972
5802
  id.border_color = borderColor;
4973
5803
  return id;
4974
5804
  }
4975
5805
  function set_border_width(id, width) {
5806
+ if (isDeleted(id)) return id;
4976
5807
  id.border_width = width;
4977
5808
  return id;
4978
5809
  }
4979
5810
  function set_border_style(id, style) {
5811
+ if (isDeleted(id)) return id;
4980
5812
  id.border_style = style;
4981
5813
  return id;
4982
5814
  }
4983
5815
  function set_bgcolor(id, bgColor) {
5816
+ if (isDeleted(id)) return id;
4984
5817
  id.bgcolor = bgColor;
4985
5818
  return id;
4986
5819
  }
4987
5820
  function set_text(id, text) {
5821
+ if (isDeleted(id)) return id;
4988
5822
  id.text = text;
4989
5823
  return id;
4990
5824
  }
4991
5825
  function set_text_color(id, textColor) {
5826
+ if (isDeleted(id)) return id;
4992
5827
  id.text_color = textColor;
4993
5828
  return id;
4994
5829
  }
4995
- function set_text_size(id, size2) {
4996
- id.text_size = size2;
5830
+ function set_text_size(id, size3) {
5831
+ if (isDeleted(id)) return id;
5832
+ id.text_size = size3;
4997
5833
  return id;
4998
5834
  }
4999
5835
  function set_text_halign(id, align) {
5836
+ if (isDeleted(id)) return id;
5000
5837
  id.text_halign = align;
5001
5838
  return id;
5002
5839
  }
5003
5840
  function set_text_valign(id, align) {
5841
+ if (isDeleted(id)) return id;
5004
5842
  id.text_valign = align;
5005
5843
  return id;
5006
5844
  }
5007
5845
  function set_text_wrap(id, wrap) {
5846
+ if (isDeleted(id)) return id;
5008
5847
  id.text_wrap = wrap;
5009
5848
  return id;
5010
5849
  }
5011
5850
  function set_text_font_family(id, font) {
5851
+ if (isDeleted(id)) return id;
5012
5852
  id.text_font_family = font;
5013
5853
  return id;
5014
5854
  }
5015
- 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;
5016
5881
  }
5017
5882
 
5018
5883
  // src/label/index.ts
5019
5884
  var label_exports = {};
5020
5885
  __export(label_exports, {
5021
- copy: () => copy5,
5886
+ all: () => all4,
5887
+ copy: () => copy6,
5888
+ delete: () => delete_label,
5022
5889
  delete_label: () => delete_label,
5023
5890
  get_text: () => get_text,
5024
5891
  get_x: () => get_x,
@@ -5026,10 +5893,12 @@ __export(label_exports, {
5026
5893
  new: () => new_label2,
5027
5894
  new_label: () => new_label2,
5028
5895
  set_color: () => set_color2,
5896
+ set_point: () => set_point,
5029
5897
  set_size: () => set_size,
5030
5898
  set_style: () => set_style2,
5031
5899
  set_text: () => set_text2,
5032
5900
  set_text_font_family: () => set_text_font_family2,
5901
+ set_text_formatting: () => set_text_formatting2,
5033
5902
  set_textalign: () => set_textalign,
5034
5903
  set_textcolor: () => set_textcolor,
5035
5904
  set_tooltip: () => set_tooltip,
@@ -5039,21 +5908,47 @@ __export(label_exports, {
5039
5908
  set_y: () => set_y,
5040
5909
  set_yloc: () => set_yloc
5041
5910
  });
5042
- function new_label2(x, y, text, xloc2 = "bar_index", yloc = "price", labelColor, style, textcolor, size2, textalign, tooltip, text_font_family) {
5043
- 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", {
5044
5937
  x,
5045
5938
  y,
5046
- xloc: xloc2,
5047
- yloc,
5939
+ xloc: xloc2 ?? "bar_index",
5940
+ yloc: yloc ?? "price",
5048
5941
  text,
5049
5942
  tooltip,
5050
5943
  color: labelColor,
5051
5944
  style,
5052
5945
  textcolor,
5053
- size: size2,
5946
+ size: size3,
5054
5947
  textalign,
5055
- text_font_family
5056
- };
5948
+ text_font_family,
5949
+ force_overlay: force_overlay ?? false,
5950
+ text_formatting
5951
+ });
5057
5952
  }
5058
5953
  function get_x(id) {
5059
5954
  return id.x;
@@ -5064,70 +5959,103 @@ function get_y(id) {
5064
5959
  function get_text(id) {
5065
5960
  return id.text;
5066
5961
  }
5067
- function copy5(id) {
5068
- return { ...id };
5962
+ function copy6(id) {
5963
+ return register("label", { ...id });
5069
5964
  }
5070
5965
  function set_x(id, x) {
5966
+ if (isDeleted(id)) return id;
5071
5967
  id.x = x;
5072
5968
  return id;
5073
5969
  }
5074
5970
  function set_y(id, y) {
5971
+ if (isDeleted(id)) return id;
5075
5972
  id.y = y;
5076
5973
  return id;
5077
5974
  }
5078
5975
  function set_xy(id, x, y) {
5976
+ if (isDeleted(id)) return id;
5079
5977
  id.x = x;
5080
5978
  id.y = y;
5081
5979
  return id;
5082
5980
  }
5083
5981
  function set_xloc3(id, x, xloc2) {
5982
+ if (isDeleted(id)) return id;
5084
5983
  id.x = x;
5085
5984
  id.xloc = xloc2;
5086
5985
  return id;
5087
5986
  }
5088
- function set_yloc(id, y, yloc) {
5089
- id.y = y;
5987
+ function set_yloc(id, yloc) {
5988
+ if (isDeleted(id)) return id;
5090
5989
  id.yloc = yloc;
5091
5990
  return id;
5092
5991
  }
5093
5992
  function set_text2(id, text) {
5993
+ if (isDeleted(id)) return id;
5094
5994
  id.text = text;
5095
5995
  return id;
5096
5996
  }
5097
5997
  function set_tooltip(id, tooltip) {
5998
+ if (isDeleted(id)) return id;
5098
5999
  id.tooltip = tooltip;
5099
6000
  return id;
5100
6001
  }
5101
6002
  function set_color2(id, labelColor) {
6003
+ if (isDeleted(id)) return id;
5102
6004
  id.color = labelColor;
5103
6005
  return id;
5104
6006
  }
5105
6007
  function set_textcolor(id, textColor) {
6008
+ if (isDeleted(id)) return id;
5106
6009
  id.textcolor = textColor;
5107
6010
  return id;
5108
6011
  }
5109
6012
  function set_style2(id, style) {
6013
+ if (isDeleted(id)) return id;
5110
6014
  id.style = style;
5111
6015
  return id;
5112
6016
  }
5113
- function set_size(id, size2) {
5114
- id.size = size2;
6017
+ function set_size(id, size3) {
6018
+ if (isDeleted(id)) return id;
6019
+ id.size = size3;
5115
6020
  return id;
5116
6021
  }
5117
6022
  function set_textalign(id, align) {
6023
+ if (isDeleted(id)) return id;
5118
6024
  id.textalign = align;
5119
6025
  return id;
5120
6026
  }
5121
6027
  function set_text_font_family2(id, font) {
6028
+ if (isDeleted(id)) return id;
5122
6029
  id.text_font_family = font;
5123
6030
  return id;
5124
6031
  }
5125
- 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;
5126
6052
  }
5127
6053
 
5128
6054
  // src/linefill/index.ts
5129
6055
  var linefill_exports = {};
5130
6056
  __export(linefill_exports, {
6057
+ all: () => all5,
6058
+ delete: () => delete_linefill,
5131
6059
  delete_linefill: () => delete_linefill,
5132
6060
  get_line1: () => get_line1,
5133
6061
  get_line2: () => get_line2,
@@ -5136,11 +6064,11 @@ __export(linefill_exports, {
5136
6064
  set_color: () => set_color3
5137
6065
  });
5138
6066
  function new_linefill2(line1, line2, fillColor) {
5139
- return {
6067
+ return register("linefill", {
5140
6068
  line1,
5141
6069
  line2,
5142
6070
  color: fillColor
5143
- };
6071
+ });
5144
6072
  }
5145
6073
  function get_line1(id) {
5146
6074
  return id.line1;
@@ -5149,16 +6077,21 @@ function get_line2(id) {
5149
6077
  return id.line2;
5150
6078
  }
5151
6079
  function set_color3(id, fillColor) {
6080
+ if (isDeleted(id)) return id;
5152
6081
  id.color = fillColor;
5153
6082
  return id;
5154
6083
  }
5155
- function delete_linefill(_id) {
6084
+ function delete_linefill(id) {
6085
+ remove3("linefill", id);
6086
+ }
6087
+ function all5() {
6088
+ return all("linefill");
5156
6089
  }
5157
6090
 
5158
6091
  // src/chartpoint/index.ts
5159
6092
  var chartpoint_exports = {};
5160
6093
  __export(chartpoint_exports, {
5161
- copy: () => copy6,
6094
+ copy: () => copy7,
5162
6095
  from_index: () => from_index,
5163
6096
  from_time: () => from_time,
5164
6097
  new: () => new_point,
@@ -5185,7 +6118,7 @@ function from_index(index, price) {
5185
6118
  price
5186
6119
  };
5187
6120
  }
5188
- function copy6(point) {
6121
+ function copy7(point) {
5189
6122
  return {
5190
6123
  time: point.time,
5191
6124
  index: point.index,
@@ -5196,6 +6129,7 @@ function copy6(point) {
5196
6129
  // src/polyline/index.ts
5197
6130
  var polyline_exports = {};
5198
6131
  __export(polyline_exports, {
6132
+ all: () => all6,
5199
6133
  clear_all: () => clear_all,
5200
6134
  delete: () => delete_polyline,
5201
6135
  delete_polyline: () => delete_polyline,
@@ -5205,7 +6139,6 @@ __export(polyline_exports, {
5205
6139
  reset_id_counter: () => reset_id_counter
5206
6140
  });
5207
6141
  var polylineIdCounter = 0;
5208
- var allPolylines = [];
5209
6142
  function generateId() {
5210
6143
  return `polyline_${++polylineIdCounter}`;
5211
6144
  }
@@ -5232,28 +6165,39 @@ function new_polyline(points, curved = false, closed = false, xloc2 = "bar_index
5232
6165
  line_width,
5233
6166
  force_overlay
5234
6167
  };
5235
- allPolylines.push(polyline);
5236
- return polyline;
6168
+ return register("polyline", polyline);
5237
6169
  }
5238
6170
  function delete_polyline(id) {
5239
- const index = allPolylines.findIndex((p) => p.id === id.id);
5240
- if (index !== -1) {
5241
- allPolylines.splice(index, 1);
5242
- }
6171
+ remove3("polyline", id);
5243
6172
  }
5244
6173
  function get_all() {
5245
- return [...allPolylines];
6174
+ return all("polyline");
6175
+ }
6176
+ function all6() {
6177
+ return all("polyline");
5246
6178
  }
5247
6179
  function clear_all() {
5248
- allPolylines.length = 0;
6180
+ for (const p of all("polyline")) remove3("polyline", p);
5249
6181
  }
5250
6182
  function reset_id_counter() {
5251
6183
  polylineIdCounter = 0;
5252
6184
  }
5253
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
+
5254
6197
  // src/ta-series.ts
5255
6198
  var ta_series_exports = {};
5256
6199
  __export(ta_series_exports, {
6200
+ accdist: () => accdist2,
5257
6201
  alma: () => alma2,
5258
6202
  atr: () => atr2,
5259
6203
  barssince: () => barssince2,
@@ -5276,6 +6220,7 @@ __export(ta_series_exports, {
5276
6220
  highestbars: () => highestbars2,
5277
6221
  hma: () => hma2,
5278
6222
  ichimoku: () => ichimoku2,
6223
+ iii: () => iii2,
5279
6224
  kc: () => kc2,
5280
6225
  kcw: () => kcw2,
5281
6226
  linreg: () => linreg2,
@@ -5288,11 +6233,15 @@ __export(ta_series_exports, {
5288
6233
  min: () => min5,
5289
6234
  mode: () => mode4,
5290
6235
  mom: () => mom2,
6236
+ nvi: () => nvi2,
6237
+ obv: () => obv2,
5291
6238
  percentile_linear_interpolation: () => percentile_linear_interpolation3,
5292
6239
  percentile_nearest_rank: () => percentile_nearest_rank3,
5293
6240
  percentrank: () => percentrank3,
5294
6241
  pivothigh: () => pivothigh2,
5295
6242
  pivotlow: () => pivotlow2,
6243
+ pvi: () => pvi2,
6244
+ pvt: () => pvt2,
5296
6245
  range: () => range3,
5297
6246
  rci: () => rci2,
5298
6247
  rising: () => rising2,
@@ -5311,9 +6260,12 @@ __export(ta_series_exports, {
5311
6260
  valuewhen: () => valuewhen2,
5312
6261
  variance: () => variance3,
5313
6262
  vwap: () => vwap2,
6263
+ vwapBands: () => vwapBands,
5314
6264
  vwma: () => vwma2,
6265
+ wad: () => wad2,
5315
6266
  wma: () => wma2,
5316
6267
  wpr: () => wpr2,
6268
+ wvad: () => wvad2,
5317
6269
  zigzag: () => zigzag2
5318
6270
  });
5319
6271
  function sma2(source, length2) {
@@ -5364,11 +6316,9 @@ function bb2(source, length2, mult2) {
5364
6316
  const lowerSeries = Series.fromArray(bars, lowerVals);
5365
6317
  return [upperSeries, basisSeries, lowerSeries];
5366
6318
  }
5367
- function stdev3(source, length2) {
6319
+ function stdev3(source, length2, biased = true) {
5368
6320
  const bars = source.bars;
5369
- const sourceValues = source.toArray();
5370
- const result = stdev(sourceValues, length2);
5371
- return Series.fromArray(bars, result);
6321
+ return Series.fromArray(bars, stdev(source.toArray(), length2, biased));
5372
6322
  }
5373
6323
  function atr2(bars, length2) {
5374
6324
  const high = bars.map((b2) => b2.high);
@@ -5384,6 +6334,40 @@ function tr2(bars, handle_na = false) {
5384
6334
  const result = tr(handle_na, high, low, close);
5385
6335
  return Series.fromArray(bars, result);
5386
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
+ }
5387
6371
  function stoch2(source, high, low, length2) {
5388
6372
  const bars = source.bars;
5389
6373
  const sourceValues = source.toArray();
@@ -5475,12 +6459,14 @@ function supertrend2(bars, factor, atrLength) {
5475
6459
  const dirSeries = Series.fromArray(bars, dirVals);
5476
6460
  return [trendSeries, dirSeries];
5477
6461
  }
5478
- function vwap2(source, volume) {
6462
+ function vwap2(source, volume, anchor) {
5479
6463
  const bars = source.bars;
5480
- const sourceValues = source.toArray();
5481
- const volumeValues = volume.toArray();
5482
- const result = vwap(sourceValues, volumeValues);
5483
- 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)];
5484
6470
  }
5485
6471
  function ichimoku2(bars, conversionPeriods, basePeriods, laggingSpan2Periods, displacement) {
5486
6472
  const high = bars.map((b2) => b2.high);
@@ -5665,10 +6651,9 @@ function kcw2(bars, source, length2 = 20, mult2 = 2, useTrueRange = true) {
5665
6651
  const result = kcw(source.toArray(), length2, mult2, useTrueRange, high, low, close);
5666
6652
  return Series.fromArray(bars, result);
5667
6653
  }
5668
- function range3(high, low) {
5669
- const bars = high.bars;
5670
- const result = range(high.toArray(), low.toArray());
5671
- return Series.fromArray(bars, result);
6654
+ function range3(source, length2) {
6655
+ const bars = source.bars;
6656
+ return Series.fromArray(bars, range(source.toArray(), length2));
5672
6657
  }
5673
6658
  function highestbars2(source, length2) {
5674
6659
  const bars = source.bars;
@@ -5680,15 +6665,13 @@ function lowestbars2(source, length2) {
5680
6665
  const result = lowestbars(source.toArray(), length2);
5681
6666
  return Series.fromArray(bars, result);
5682
6667
  }
5683
- function max5(source1, source2) {
5684
- const bars = source1.bars;
5685
- const result = max(source1.toArray(), source2.toArray());
5686
- return Series.fromArray(bars, result);
6668
+ function max5(source) {
6669
+ const bars = source.bars;
6670
+ return Series.fromArray(bars, max(source.toArray()));
5687
6671
  }
5688
- function min5(source1, source2) {
5689
- const bars = source1.bars;
5690
- const result = min(source1.toArray(), source2.toArray());
5691
- return Series.fromArray(bars, result);
6672
+ function min5(source) {
6673
+ const bars = source.bars;
6674
+ return Series.fromArray(bars, min(source.toArray()));
5692
6675
  }
5693
6676
  function cog2(source, length2 = 10) {
5694
6677
  const bars = source.bars;
@@ -5771,6 +6754,15 @@ var ta = {
5771
6754
  lowestbars: lowestbars2,
5772
6755
  max: max5,
5773
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,
5774
6766
  cog: cog2,
5775
6767
  mode: mode4,
5776
6768
  percentile_linear_interpolation: percentile_linear_interpolation3,
@@ -5780,11 +6772,23 @@ var ta = {
5780
6772
 
5781
6773
  // src/utils/index.ts
5782
6774
  function isNA(value) {
5783
- return value === null || value === void 0 || Number.isNaN(value);
6775
+ return value === null || value === void 0 || Number.isNaN(value) || isDeleted(value);
5784
6776
  }
5785
6777
  function nz(value, defaultValue = 0) {
5786
6778
  return isNA(value) ? defaultValue : value;
5787
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
+ }
5788
6792
  function ohlcFromBars(bars) {
5789
6793
  return {
5790
6794
  open: bars.map((b2) => b2.open),
@@ -6176,16 +7180,78 @@ var input = {
6176
7180
  title: options.title,
6177
7181
  options: options.options
6178
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
+ };
6179
7245
  }
6180
7246
  };
6181
7247
  Object.freeze(input);
6182
7248
 
6183
7249
  // src/plot.ts
6184
- function plot(values, times, options = {}) {
7250
+ function plot(values2, times, options = {}) {
6185
7251
  const result = [];
6186
7252
  const offset = options.offset ?? 0;
6187
- for (let i = 0; i < values.length; i++) {
6188
- const value = values[i];
7253
+ for (let i = 0; i < values2.length; i++) {
7254
+ const value = values2[i];
6189
7255
  const timeIndex = i + offset;
6190
7256
  if (value === null || value === void 0 || Number.isNaN(value)) {
6191
7257
  continue;
@@ -6200,10 +7266,10 @@ function plot(values, times, options = {}) {
6200
7266
  }
6201
7267
  return result;
6202
7268
  }
6203
- function createPlot(id, values, times, options = {}) {
7269
+ function createPlot(id, values2, times, options = {}) {
6204
7270
  return {
6205
7271
  id,
6206
- data: plot(values, times, options),
7272
+ data: plot(values2, times, options),
6207
7273
  options
6208
7274
  };
6209
7275
  }
@@ -6444,6 +7510,42 @@ function input_string(defval, title, options) {
6444
7510
  const value = context2.inputs.getValue(id);
6445
7511
  return typeof value === "string" ? value : defval;
6446
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
+ }
6447
7549
  function input_source(defval, title) {
6448
7550
  const context2 = getContext();
6449
7551
  if (!context2) {
@@ -6666,7 +7768,7 @@ var SimpleInputAdapter = class {
6666
7768
  validatedValue = Math.floor(validatedValue);
6667
7769
  }
6668
7770
  }
6669
- 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") {
6670
7772
  if (!config.options.includes(value)) {
6671
7773
  return;
6672
7774
  }
@@ -6714,8 +7816,8 @@ var SimpleInputAdapter = class {
6714
7816
  };
6715
7817
 
6716
7818
  // src/index.ts
6717
- var VERSION = "0.3.0";
6718
- var info = {
7819
+ var VERSION = "0.6.0";
7820
+ var info2 = {
6719
7821
  name: "OakScriptJS",
6720
7822
  version: VERSION,
6721
7823
  description: "Simplified PineScript-like library - Series + TA functions",
@@ -6728,8 +7830,8 @@ var info = {
6728
7830
  minimal: "No DSL layer - complexity in transpiler"
6729
7831
  },
6730
7832
  namespaces: {
6731
- core: ["ta", "math", "array", "str", "color", "time", "matrix"],
6732
- 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"],
6733
7835
  runtime: ["setContext", "plot", "hline", "input_*"],
6734
7836
  indicator: ["indicator", "input", "plotHelper", "createPlot"]
6735
7837
  }