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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
2
+ var __export = (target, all7) => {
3
+ for (var name in all7)
4
+ __defProp(target, name, { get: all7[name], enumerable: true });
5
5
  };
6
6
 
7
7
  // src/types/index.ts
@@ -15,6 +15,7 @@ var xloc = {
15
15
  // src/ta/index.ts
16
16
  var ta_exports = {};
17
17
  __export(ta_exports, {
18
+ accdist: () => accdist,
18
19
  alma: () => alma,
19
20
  atr: () => atr,
20
21
  barssince: () => barssince,
@@ -37,6 +38,7 @@ __export(ta_exports, {
37
38
  highestbars: () => highestbars,
38
39
  hma: () => hma,
39
40
  ichimoku: () => ichimoku,
41
+ iii: () => iii,
40
42
  kc: () => kc,
41
43
  kcw: () => kcw,
42
44
  linreg: () => linreg,
@@ -49,12 +51,16 @@ __export(ta_exports, {
49
51
  min: () => min,
50
52
  mode: () => mode,
51
53
  mom: () => mom,
54
+ nvi: () => nvi,
55
+ obv: () => obv,
52
56
  percentile_linear_interpolation: () => percentile_linear_interpolation,
53
57
  percentile_nearest_rank: () => percentile_nearest_rank,
54
58
  percentrank: () => percentrank,
55
59
  pivot_point_levels: () => pivot_point_levels,
56
60
  pivothigh: () => pivothigh,
57
61
  pivotlow: () => pivotlow,
62
+ pvi: () => pvi,
63
+ pvt: () => pvt,
58
64
  range: () => range,
59
65
  rci: () => rci,
60
66
  rising: () => rising,
@@ -73,8 +79,10 @@ __export(ta_exports, {
73
79
  variance: () => variance,
74
80
  vwap: () => vwap,
75
81
  vwma: () => vwma,
82
+ wad: () => wad,
76
83
  wma: () => wma,
77
84
  wpr: () => wpr,
85
+ wvad: () => wvad,
78
86
  zigzag: () => zigzag
79
87
  });
80
88
  function sma(source, length2) {
@@ -174,23 +182,42 @@ function bb(series, length2, mult2) {
174
182
  }
175
183
  return [basis, upper2, lower2];
176
184
  }
177
- function stdev(source, length2) {
178
- const result = [];
185
+ function stdev(source, length2, biased = true) {
179
186
  const len = Math.floor(length2);
180
- const avg4 = sma(source, len);
181
- for (let i = 0; i < source.length; i++) {
182
- if (i < len - 1) {
183
- result.push(NaN);
184
- } else {
185
- let sumSquares = 0;
186
- for (let j = 0; j < len; j++) {
187
- const diff2 = source[i - j] - avg4[i];
188
- sumSquares += diff2 * diff2;
189
- }
190
- result.push(Math.sqrt(sumSquares / len));
191
- }
192
- }
193
- return result;
187
+ return source.map((_, i) => {
188
+ const values2 = lastValues(source, i, len);
189
+ if (!values2) return NaN;
190
+ const mean = values2.reduce((a, b2) => a + b2, 0) / len;
191
+ const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
192
+ return Math.sqrt(squares / (biased ? len : len - 1));
193
+ });
194
+ }
195
+ function lastValues(source, i, length2) {
196
+ const values2 = [];
197
+ for (let j = i; j >= 0 && values2.length < length2; j--) {
198
+ const x = source[j];
199
+ if (!Number.isNaN(x)) values2.push(x);
200
+ }
201
+ return values2.length === length2 ? values2 : null;
202
+ }
203
+ function windowUntilNa(source, i, length2) {
204
+ const values2 = [];
205
+ for (let j = 0; j < length2 && i - j >= 0; j++) {
206
+ const x = source[i - j];
207
+ if (Number.isNaN(x)) break;
208
+ values2.push([x, -j]);
209
+ }
210
+ return values2;
211
+ }
212
+ function extremeOffset(source, length2, isHigher) {
213
+ return source.map((_, i) => {
214
+ if (i < length2 - 1) return NaN;
215
+ const w = windowUntilNa(source, i, length2);
216
+ if (w.length === 0) return 0;
217
+ let best = w[0];
218
+ for (const item of w) if (isHigher(item[0], best[0])) best = item;
219
+ return best[1];
220
+ });
194
221
  }
195
222
  function crossover(series1, series2) {
196
223
  const result = [];
@@ -369,47 +396,26 @@ function wma(source, length2) {
369
396
  return result;
370
397
  }
371
398
  function highest(source, length2) {
372
- const result = [];
373
- for (let i = 0; i < source.length; i++) {
374
- if (i < length2 - 1) {
375
- result.push(NaN);
376
- } else {
377
- let max6 = -Infinity;
378
- for (let j = 0; j < length2; j++) {
379
- if (!isNaN(source[i - j])) {
380
- max6 = Math.max(max6, source[i - j]);
381
- }
382
- }
383
- result.push(max6 === -Infinity ? NaN : max6);
384
- }
385
- }
386
- return result;
399
+ return source.map((_, i) => {
400
+ if (i < length2 - 1) return NaN;
401
+ const w = windowUntilNa(source, i, length2);
402
+ return w.length ? Math.max(...w.map((x) => x[0])) : NaN;
403
+ });
387
404
  }
388
405
  function lowest(source, length2) {
389
- const result = [];
390
- for (let i = 0; i < source.length; i++) {
391
- if (i < length2 - 1) {
392
- result.push(NaN);
393
- } else {
394
- let min6 = Infinity;
395
- for (let j = 0; j < length2; j++) {
396
- if (!isNaN(source[i - j])) {
397
- min6 = Math.min(min6, source[i - j]);
398
- }
399
- }
400
- result.push(min6 === Infinity ? NaN : min6);
401
- }
402
- }
403
- return result;
406
+ return source.map((_, i) => {
407
+ if (i < length2 - 1) return NaN;
408
+ const w = windowUntilNa(source, i, length2);
409
+ return w.length ? Math.min(...w.map((x) => x[0])) : NaN;
410
+ });
404
411
  }
405
412
  function cum(source) {
406
- const result = [];
407
413
  let sum4 = 0;
408
- for (let i = 0; i < source.length; i++) {
409
- sum4 += source[i];
410
- result.push(sum4);
411
- }
412
- return result;
414
+ return source.map((v) => {
415
+ if (Number.isNaN(v)) return NaN;
416
+ sum4 += v;
417
+ return sum4;
418
+ });
413
419
  }
414
420
  function cross(source1, source2) {
415
421
  const result = [];
@@ -538,21 +544,21 @@ function median(source, length2) {
538
544
  if (i < length2 - 1) {
539
545
  result.push(NaN);
540
546
  } else {
541
- const values = [];
547
+ const values2 = [];
542
548
  for (let j = 0; j < length2; j++) {
543
549
  if (!isNaN(source[i - j])) {
544
- values.push(source[i - j]);
550
+ values2.push(source[i - j]);
545
551
  }
546
552
  }
547
- if (values.length === 0) {
553
+ if (values2.length === 0) {
548
554
  result.push(NaN);
549
555
  } else {
550
- values.sort((a, b2) => a - b2);
551
- const mid = Math.floor(values.length / 2);
552
- if (values.length % 2 === 0) {
553
- result.push((values[mid - 1] + values[mid]) / 2);
556
+ values2.sort((a, b2) => a - b2);
557
+ const mid = Math.floor(values2.length / 2);
558
+ if (values2.length % 2 === 0) {
559
+ result.push((values2[mid - 1] + values2[mid]) / 2);
554
560
  } else {
555
- result.push(values[mid]);
561
+ result.push(values2[mid]);
556
562
  }
557
563
  }
558
564
  }
@@ -882,89 +888,44 @@ function sar(start, inc, max6, high, low, close) {
882
888
  }
883
889
  return result;
884
890
  }
891
+ function pivot(source, leftbars, rightbars, isHigh) {
892
+ const beatsLeft = isHigh ? (x, v) => x > v : (x, v) => x < v;
893
+ const beatsRight = isHigh ? (x, v) => x >= v : (x, v) => x <= v;
894
+ return source.map((_, i) => {
895
+ const center = i - rightbars;
896
+ if (center - leftbars < 0) return NaN;
897
+ const v = source[center];
898
+ if (Number.isNaN(v)) return NaN;
899
+ for (let j = 1; j <= leftbars; j++) {
900
+ const x = source[center - j];
901
+ if (Number.isNaN(x)) break;
902
+ if (beatsLeft(x, v)) return NaN;
903
+ }
904
+ for (let j = 1; j <= rightbars; j++) {
905
+ const x = source[center + j];
906
+ if (Number.isNaN(x)) break;
907
+ if (beatsRight(x, v)) return NaN;
908
+ }
909
+ return v;
910
+ });
911
+ }
885
912
  function pivothigh(sourceOrLeftbars, leftbarsOrRightbars, rightbars, high) {
886
- let source;
887
- let leftbars;
888
- let right;
889
913
  if (rightbars === void 0) {
890
914
  if (!high) {
891
915
  throw new Error("ta.pivothigh() requires high series when using two-parameter version.");
892
916
  }
893
- source = high;
894
- leftbars = sourceOrLeftbars;
895
- right = leftbarsOrRightbars;
896
- } else {
897
- source = sourceOrLeftbars;
898
- leftbars = leftbarsOrRightbars;
899
- right = rightbars;
917
+ return pivot(high, sourceOrLeftbars, leftbarsOrRightbars, true);
900
918
  }
901
- const result = [];
902
- for (let i = 0; i < source.length; i++) {
903
- if (i < leftbars || i + right >= source.length) {
904
- result.push(NaN);
905
- continue;
906
- }
907
- const centerValue = source[i];
908
- let isPivot = true;
909
- for (let j = 1; j <= leftbars; j++) {
910
- if (source[i - j] >= centerValue) {
911
- isPivot = false;
912
- break;
913
- }
914
- }
915
- if (isPivot) {
916
- for (let j = 1; j <= right; j++) {
917
- if (source[i + j] >= centerValue) {
918
- isPivot = false;
919
- break;
920
- }
921
- }
922
- }
923
- result.push(isPivot ? centerValue : NaN);
924
- }
925
- return result;
919
+ return pivot(sourceOrLeftbars, leftbarsOrRightbars, rightbars, true);
926
920
  }
927
921
  function pivotlow(sourceOrLeftbars, leftbarsOrRightbars, rightbars, low) {
928
- let source;
929
- let leftbars;
930
- let right;
931
922
  if (rightbars === void 0) {
932
923
  if (!low) {
933
924
  throw new Error("ta.pivotlow() requires low series when using two-parameter version.");
934
925
  }
935
- source = low;
936
- leftbars = sourceOrLeftbars;
937
- right = leftbarsOrRightbars;
938
- } else {
939
- source = sourceOrLeftbars;
940
- leftbars = leftbarsOrRightbars;
941
- right = rightbars;
926
+ return pivot(low, sourceOrLeftbars, leftbarsOrRightbars, false);
942
927
  }
943
- const result = [];
944
- for (let i = 0; i < source.length; i++) {
945
- if (i < leftbars || i + right >= source.length) {
946
- result.push(NaN);
947
- continue;
948
- }
949
- const centerValue = source[i];
950
- let isPivot = true;
951
- for (let j = 1; j <= leftbars; j++) {
952
- if (source[i - j] <= centerValue) {
953
- isPivot = false;
954
- break;
955
- }
956
- }
957
- if (isPivot) {
958
- for (let j = 1; j <= right; j++) {
959
- if (source[i + j] <= centerValue) {
960
- isPivot = false;
961
- break;
962
- }
963
- }
964
- }
965
- result.push(isPivot ? centerValue : NaN);
966
- }
967
- return result;
928
+ return pivot(sourceOrLeftbars, leftbarsOrRightbars, rightbars, false);
968
929
  }
969
930
  function barssince(condition) {
970
931
  const result = [];
@@ -1158,27 +1119,38 @@ function wpr(high, low, close, length2 = 14) {
1158
1119
  }
1159
1120
  return result;
1160
1121
  }
1161
- function vwap(source, volume) {
1122
+ function vwap(source, volume, anchor, stdev_mult) {
1162
1123
  if (source.length !== volume.length) {
1163
1124
  throw new Error("ta.vwap: source and volume must have the same length");
1164
1125
  }
1165
- const result = [];
1166
- let cumulativePV = 0;
1167
- let cumulativeVolume = 0;
1126
+ const mid = [];
1127
+ const upper2 = [];
1128
+ const lower2 = [];
1129
+ let sumPV = 0;
1130
+ let sumV = 0;
1131
+ let sumPPV = 0;
1168
1132
  for (let i = 0; i < source.length; i++) {
1169
- if (isNaN(source[i]) || isNaN(volume[i])) {
1170
- result.push(NaN);
1171
- continue;
1133
+ if (anchor && anchor[i]) {
1134
+ sumPV = 0;
1135
+ sumV = 0;
1136
+ sumPPV = 0;
1172
1137
  }
1173
- cumulativePV += source[i] * volume[i];
1174
- cumulativeVolume += volume[i];
1175
- if (cumulativeVolume === 0) {
1176
- result.push(NaN);
1177
- } else {
1178
- result.push(cumulativePV / cumulativeVolume);
1138
+ const s = source[i];
1139
+ const v = volume[i];
1140
+ if (!Number.isNaN(s) && !Number.isNaN(v)) {
1141
+ sumPV += s * v;
1142
+ sumV += v;
1143
+ sumPPV += s * s * v;
1144
+ }
1145
+ const m = sumV === 0 ? NaN : sumPV / sumV;
1146
+ mid.push(m);
1147
+ if (stdev_mult !== void 0) {
1148
+ const sd = Math.sqrt(Math.max(0, sumPPV / sumV - m * m));
1149
+ upper2.push(m + stdev_mult * sd);
1150
+ lower2.push(m - stdev_mult * sd);
1179
1151
  }
1180
1152
  }
1181
- return result;
1153
+ return stdev_mult === void 0 ? mid : [mid, upper2, lower2];
1182
1154
  }
1183
1155
  function alma(source, length2 = 9, offset = 0.85, sigma = 6, floor2 = false) {
1184
1156
  const result = [];
@@ -1220,85 +1192,31 @@ function kcw(source, length2 = 20, mult2 = 2, useTrueRange = true, high, low, cl
1220
1192
  }
1221
1193
  return result;
1222
1194
  }
1223
- function range(high, low) {
1224
- if (high.length !== low.length) {
1225
- throw new Error("ta.range: high and low must have the same length");
1226
- }
1227
- const result = [];
1228
- for (let i = 0; i < high.length; i++) {
1229
- if (isNaN(high[i]) || isNaN(low[i])) {
1230
- result.push(NaN);
1231
- } else {
1232
- result.push(high[i] - low[i]);
1233
- }
1234
- }
1235
- return result;
1195
+ function range(source, length2) {
1196
+ return source.map((_, i) => {
1197
+ const values2 = lastValues(source, i, length2);
1198
+ return values2 ? Math.max(...values2) - Math.min(...values2) : NaN;
1199
+ });
1236
1200
  }
1237
1201
  function highestbars(source, length2) {
1238
- const result = [];
1239
- for (let i = 0; i < source.length; i++) {
1240
- if (i < length2 - 1) {
1241
- result.push(NaN);
1242
- continue;
1243
- }
1244
- let highestValue = source[i - length2 + 1];
1245
- let highestOffset = length2 - 1;
1246
- for (let j = i - length2 + 2; j <= i; j++) {
1247
- if (source[j] > highestValue) {
1248
- highestValue = source[j];
1249
- highestOffset = i - j;
1250
- }
1251
- }
1252
- result.push(highestOffset);
1253
- }
1254
- return result;
1202
+ return extremeOffset(source, length2, (a, b2) => a >= b2);
1255
1203
  }
1256
1204
  function lowestbars(source, length2) {
1257
- const result = [];
1258
- for (let i = 0; i < source.length; i++) {
1259
- if (i < length2 - 1) {
1260
- result.push(NaN);
1261
- continue;
1262
- }
1263
- let lowestValue = source[i - length2 + 1];
1264
- let lowestOffset = length2 - 1;
1265
- for (let j = i - length2 + 2; j <= i; j++) {
1266
- if (source[j] < lowestValue) {
1267
- lowestValue = source[j];
1268
- lowestOffset = i - j;
1269
- }
1270
- }
1271
- result.push(lowestOffset);
1272
- }
1273
- return result;
1205
+ return extremeOffset(source, length2, (a, b2) => a <= b2);
1274
1206
  }
1275
- function max(source1, source2) {
1276
- if (source1.length !== source2.length) {
1277
- throw new Error("ta.max: source1 and source2 must have the same length");
1278
- }
1279
- const result = [];
1280
- for (let i = 0; i < source1.length; i++) {
1281
- if (isNaN(source1[i]) || isNaN(source2[i])) {
1282
- result.push(NaN);
1283
- } else {
1284
- result.push(Math.max(source1[i], source2[i]));
1285
- }
1286
- }
1287
- return result;
1207
+ function max(source) {
1208
+ let best = NaN;
1209
+ return source.map((x) => {
1210
+ if (!Number.isNaN(x) && !(x <= best)) best = x;
1211
+ return best;
1212
+ });
1288
1213
  }
1289
- function min(source1, source2) {
1290
- if (source1.length !== source2.length) {
1291
- throw new Error("ta.min: source1 and source2 must have the same length");
1292
- }
1293
- const result = [];
1294
- for (let i = 0; i < source1.length; i++) {
1295
- if (isNaN(source1[i]) || isNaN(source2[i])) {
1296
- result.push(NaN);
1297
- } else {
1298
- result.push(Math.min(source1[i], source2[i]));
1299
- }
1300
- }
1301
- return result;
1214
+ function min(source) {
1215
+ let best = NaN;
1216
+ return source.map((x) => {
1217
+ if (!Number.isNaN(x) && !(x >= best)) best = x;
1218
+ return best;
1219
+ });
1302
1220
  }
1303
1221
  function cog(source, length2 = 10) {
1304
1222
  const result = [];
@@ -1331,19 +1249,19 @@ function mode(source, length2) {
1331
1249
  result.push(NaN);
1332
1250
  continue;
1333
1251
  }
1334
- const values = [];
1252
+ const values2 = [];
1335
1253
  for (let j = 0; j < length2; j++) {
1336
1254
  const value = source[i - j];
1337
1255
  if (!isNaN(value)) {
1338
- values.push(value);
1256
+ values2.push(value);
1339
1257
  }
1340
1258
  }
1341
- if (values.length === 0) {
1259
+ if (values2.length === 0) {
1342
1260
  result.push(NaN);
1343
1261
  continue;
1344
1262
  }
1345
1263
  const frequencyMap = /* @__PURE__ */ new Map();
1346
- for (const value of values) {
1264
+ for (const value of values2) {
1347
1265
  frequencyMap.set(value, (frequencyMap.get(value) || 0) + 1);
1348
1266
  }
1349
1267
  let maxFrequency = 0;
@@ -1369,16 +1287,16 @@ function percentile_linear_interpolation(source, length2, percentage) {
1369
1287
  result.push(NaN);
1370
1288
  continue;
1371
1289
  }
1372
- const values = [];
1290
+ const values2 = [];
1373
1291
  for (let j = 0; j < length2; j++) {
1374
1292
  const value = source[i - j];
1375
- values.push(value);
1293
+ values2.push(value);
1376
1294
  }
1377
- if (values.some((v) => isNaN(v))) {
1295
+ if (values2.some((v) => isNaN(v))) {
1378
1296
  result.push(NaN);
1379
1297
  continue;
1380
1298
  }
1381
- const sorted = [...values].sort((a, b2) => a - b2);
1299
+ const sorted = [...values2].sort((a, b2) => a - b2);
1382
1300
  const position = percentage / 100 * (sorted.length - 1);
1383
1301
  const lowerIndex = Math.floor(position);
1384
1302
  const upperIndex = Math.ceil(position);
@@ -1399,18 +1317,18 @@ function percentile_nearest_rank(source, length2, percentage) {
1399
1317
  result.push(NaN);
1400
1318
  continue;
1401
1319
  }
1402
- const values = [];
1320
+ const values2 = [];
1403
1321
  for (let j = 0; j < length2; j++) {
1404
1322
  const value = source[i - j];
1405
1323
  if (!isNaN(value)) {
1406
- values.push(value);
1324
+ values2.push(value);
1407
1325
  }
1408
1326
  }
1409
- if (values.length === 0) {
1327
+ if (values2.length === 0) {
1410
1328
  result.push(NaN);
1411
1329
  continue;
1412
1330
  }
1413
- const sorted = [...values].sort((a, b2) => a - b2);
1331
+ const sorted = [...values2].sort((a, b2) => a - b2);
1414
1332
  if (percentage >= 100) {
1415
1333
  result.push(sorted[sorted.length - 1]);
1416
1334
  continue;
@@ -1428,15 +1346,15 @@ function rci(source, length2) {
1428
1346
  result.push(NaN);
1429
1347
  continue;
1430
1348
  }
1431
- const values = [];
1349
+ const values2 = [];
1432
1350
  for (let j = 0; j < length2; j++) {
1433
- values.push(source[i - length2 + 1 + j]);
1351
+ values2.push(source[i - length2 + 1 + j]);
1434
1352
  }
1435
- if (values.some((v) => isNaN(v))) {
1353
+ if (values2.some((v) => isNaN(v))) {
1436
1354
  result.push(NaN);
1437
1355
  continue;
1438
1356
  }
1439
- const indexed = values.map((value, index) => ({ value, index }));
1357
+ const indexed = values2.map((value, index) => ({ value, index }));
1440
1358
  const sorted = [...indexed].sort((a, b2) => a.value - b2.value);
1441
1359
  const ranks = new Array(length2).fill(0);
1442
1360
  let currentRank = 1;
@@ -1800,23 +1718,86 @@ function zigzag(deviation = 5, depth = 10, backstep = 3, source, high, low) {
1800
1718
  if (potentialPivot) {
1801
1719
  confirmedPivots.push(potentialPivot);
1802
1720
  }
1803
- for (const pivot of confirmedPivots) {
1804
- zigzagValues[pivot.index] = pivot.price;
1805
- isPivot[pivot.index] = true;
1721
+ for (const pivot2 of confirmedPivots) {
1722
+ zigzagValues[pivot2.index] = pivot2.price;
1723
+ isPivot[pivot2.index] = true;
1806
1724
  }
1807
1725
  let currentDir = 0;
1808
1726
  let pivotIdx = 0;
1809
1727
  const numConfirmed = lastPotentialWasAdded ? confirmedPivots.length - 1 : confirmedPivots.length;
1810
1728
  for (let i = 0; i < length2; i++) {
1811
1729
  while (pivotIdx < numConfirmed && confirmedPivots[pivotIdx].index <= i) {
1812
- const pivot = confirmedPivots[pivotIdx];
1813
- currentDir = pivot.type === "low" ? 1 : -1;
1730
+ const pivot2 = confirmedPivots[pivotIdx];
1731
+ currentDir = pivot2.type === "low" ? 1 : -1;
1814
1732
  pivotIdx++;
1815
1733
  }
1816
1734
  directions[i] = currentDir;
1817
1735
  }
1818
1736
  return [zigzagValues, directions, isPivot];
1819
1737
  }
1738
+ function obv(close, volume) {
1739
+ return cum(close.map((c, i) => i === 0 ? NaN : Math.sign(c - close[i - 1]) * volume[i]));
1740
+ }
1741
+ function pvt(close, volume) {
1742
+ return cum(
1743
+ close.map((c, i) => i === 0 ? NaN : (c - close[i - 1]) / close[i - 1] * volume[i])
1744
+ );
1745
+ }
1746
+ function accdist(high, low, close, volume) {
1747
+ return cum(
1748
+ close.map((c, i) => {
1749
+ const h = high[i];
1750
+ const l = low[i];
1751
+ return h === l ? 0 : (2 * c - l - h) / (h - l) * volume[i];
1752
+ })
1753
+ );
1754
+ }
1755
+ function iii(high, low, close, volume) {
1756
+ return close.map((c, i) => {
1757
+ const range4 = high[i] - low[i];
1758
+ return range4 === 0 ? NaN : (2 * c - high[i] - low[i]) / range4 * volume[i];
1759
+ });
1760
+ }
1761
+ function wvad(open, high, low, close, volume) {
1762
+ return close.map((c, i) => {
1763
+ const range4 = high[i] - low[i];
1764
+ return range4 === 0 ? NaN : (c - open[i]) / range4 * volume[i];
1765
+ });
1766
+ }
1767
+ function wad(high, low, close) {
1768
+ return cum(
1769
+ close.map((c, i) => {
1770
+ const prev = i === 0 ? NaN : close[i - 1];
1771
+ const mom3 = c - prev;
1772
+ if (mom3 > 0) return c - Math.min(low[i], prev);
1773
+ if (mom3 < 0) return c - Math.max(high[i], prev);
1774
+ return 0;
1775
+ })
1776
+ );
1777
+ }
1778
+ function volumeIndex(close, volume, use) {
1779
+ const result = [];
1780
+ let prevIndex = NaN;
1781
+ for (let i = 0; i < close.length; i++) {
1782
+ const prev = !prevIndex ? 1 : prevIndex;
1783
+ const c = close[i];
1784
+ const prevC = i === 0 ? NaN : close[i - 1];
1785
+ let value = prev;
1786
+ if (c && prevC) {
1787
+ const prevV = i === 0 || Number.isNaN(volume[i - 1]) ? 0 : volume[i - 1];
1788
+ if (use(volume[i], prevV)) value = prev + (c - prevC) / prevC * prev;
1789
+ }
1790
+ result.push(value);
1791
+ prevIndex = value;
1792
+ }
1793
+ return result;
1794
+ }
1795
+ function nvi(close, volume) {
1796
+ return volumeIndex(close, volume, (v, prevV) => v < prevV);
1797
+ }
1798
+ function pvi(close, volume) {
1799
+ return volumeIndex(close, volume, (v, prevV) => v > prevV);
1800
+ }
1820
1801
 
1821
1802
  // src/math/index.ts
1822
1803
  var math_exports = {};
@@ -1993,8 +1974,8 @@ var Series = class _Series {
1993
1974
  * @param field - Field to extract ('open', 'high', 'low', 'close', 'volume')
1994
1975
  * @returns Series with extracted field values
1995
1976
  */
1996
- static fromBars(bars, field) {
1997
- return new _Series(bars, (bar) => bar[field] ?? NaN);
1977
+ static fromBars(bars, field2) {
1978
+ return new _Series(bars, (bar) => bar[field2] ?? NaN);
1998
1979
  }
1999
1980
  /**
2000
1981
  * Create a constant series (same value for all bars)
@@ -2011,8 +1992,8 @@ var Series = class _Series {
2011
1992
  * @param values - Array of values
2012
1993
  * @returns Series
2013
1994
  */
2014
- static fromArray(bars, values) {
2015
- return new _Series(bars, (_bar, i) => values[i] ?? NaN);
1995
+ static fromArray(bars, values2) {
1996
+ return new _Series(bars, (_bar, i) => values2[i] ?? NaN);
2016
1997
  }
2017
1998
  // ============================================
2018
1999
  // Arithmetic Operations
@@ -2053,6 +2034,18 @@ var Series = class _Series {
2053
2034
  return a * b2;
2054
2035
  });
2055
2036
  }
2037
+ /**
2038
+ * Raise the series to a power (PineScript math.pow on a series)
2039
+ * @param exponent - Series or number exponent
2040
+ * @returns New Series representing base ** exponent
2041
+ */
2042
+ pow(exponent) {
2043
+ return new _Series(this.dataSource, (bar, i, data) => {
2044
+ const a = this.extractor(bar, i, data);
2045
+ const b2 = typeof exponent === "number" ? exponent : exponent.extractor(bar, i, data);
2046
+ return Math.pow(a, b2);
2047
+ });
2048
+ }
2056
2049
  /**
2057
2050
  * Divide two series or a series by a number
2058
2051
  * @param other - Series or number to divide by
@@ -2290,8 +2283,8 @@ var Series = class _Series {
2290
2283
  * @returns New Series with computed values and no closure dependencies
2291
2284
  */
2292
2285
  materialize() {
2293
- const values = this.toArray();
2294
- const valuesCopy = [...values];
2286
+ const values2 = this.toArray();
2287
+ const valuesCopy = [...values2];
2295
2288
  return _Series.fromArray(this.dataSource, valuesCopy);
2296
2289
  }
2297
2290
  /**
@@ -2321,16 +2314,16 @@ var Series = class _Series {
2321
2314
  * @returns Value at that index
2322
2315
  */
2323
2316
  get(index) {
2324
- const values = this.toArray();
2325
- return values[index] ?? NaN;
2317
+ const values2 = this.toArray();
2318
+ return values2[index] ?? NaN;
2326
2319
  }
2327
2320
  /**
2328
2321
  * Get the last value (most recent bar)
2329
2322
  * @returns Most recent value
2330
2323
  */
2331
2324
  last() {
2332
- const values = this.toArray();
2333
- return values[values.length - 1] ?? NaN;
2325
+ const values2 = this.toArray();
2326
+ return values2[values2.length - 1] ?? NaN;
2334
2327
  }
2335
2328
  /**
2336
2329
  * Get number of values
@@ -2344,11 +2337,11 @@ var Series = class _Series {
2344
2337
  * @returns Array of { time, value } objects
2345
2338
  */
2346
2339
  toTimeValuePairs() {
2347
- const values = this.toArray();
2340
+ const values2 = this.toArray();
2348
2341
  const bars = this.dataSource.bars;
2349
2342
  return bars.map((bar, i) => ({
2350
2343
  time: bar.time,
2351
- value: values[i]
2344
+ value: values2[i]
2352
2345
  })).filter((point) => !Number.isNaN(point.value));
2353
2346
  }
2354
2347
  };
@@ -2422,60 +2415,60 @@ function round(value, precision) {
2422
2415
  const multiplier = Math.pow(10, precision);
2423
2416
  return Math.round(value * multiplier) / multiplier;
2424
2417
  }
2425
- function max2(...values) {
2426
- const hasSeries = values.some((v) => v instanceof Series);
2418
+ function max2(...values2) {
2419
+ const hasSeries = values2.some((v) => v instanceof Series);
2427
2420
  if (!hasSeries) {
2428
- return Math.max(...values);
2421
+ return Math.max(...values2);
2429
2422
  }
2430
- const firstSeries = values.find((v) => v instanceof Series);
2423
+ const firstSeries = values2.find((v) => v instanceof Series);
2431
2424
  const bars = firstSeries.bars;
2432
2425
  const length2 = bars.length;
2433
- const valueArrays = values.map(
2426
+ const valueArrays = values2.map(
2434
2427
  (v) => v instanceof Series ? v.toArray() : null
2435
2428
  );
2436
2429
  const result = [];
2437
2430
  for (let i = 0; i < length2; i++) {
2438
- const nums = values.map(
2431
+ const nums = values2.map(
2439
2432
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2440
2433
  );
2441
2434
  result.push(Math.max(...nums));
2442
2435
  }
2443
2436
  return Series.fromArray(bars, result);
2444
2437
  }
2445
- function min2(...values) {
2446
- const hasSeries = values.some((v) => v instanceof Series);
2438
+ function min2(...values2) {
2439
+ const hasSeries = values2.some((v) => v instanceof Series);
2447
2440
  if (!hasSeries) {
2448
- return Math.min(...values);
2441
+ return Math.min(...values2);
2449
2442
  }
2450
- const firstSeries = values.find((v) => v instanceof Series);
2443
+ const firstSeries = values2.find((v) => v instanceof Series);
2451
2444
  const bars = firstSeries.bars;
2452
2445
  const length2 = bars.length;
2453
- const valueArrays = values.map(
2446
+ const valueArrays = values2.map(
2454
2447
  (v) => v instanceof Series ? v.toArray() : null
2455
2448
  );
2456
2449
  const result = [];
2457
2450
  for (let i = 0; i < length2; i++) {
2458
- const nums = values.map(
2451
+ const nums = values2.map(
2459
2452
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2460
2453
  );
2461
2454
  result.push(Math.min(...nums));
2462
2455
  }
2463
2456
  return Series.fromArray(bars, result);
2464
2457
  }
2465
- function avg(...values) {
2466
- const hasSeries = values.some((v) => v instanceof Series);
2458
+ function avg(...values2) {
2459
+ const hasSeries = values2.some((v) => v instanceof Series);
2467
2460
  if (!hasSeries) {
2468
- return values.reduce((a, b2) => a + b2, 0) / values.length;
2461
+ return values2.reduce((a, b2) => a + b2, 0) / values2.length;
2469
2462
  }
2470
- const firstSeries = values.find((v) => v instanceof Series);
2463
+ const firstSeries = values2.find((v) => v instanceof Series);
2471
2464
  const bars = firstSeries.bars;
2472
2465
  const length2 = bars.length;
2473
- const valueArrays = values.map(
2466
+ const valueArrays = values2.map(
2474
2467
  (v) => v instanceof Series ? v.toArray() : null
2475
2468
  );
2476
2469
  const result = [];
2477
2470
  for (let i = 0; i < length2; i++) {
2478
- const nums = values.map(
2471
+ const nums = values2.map(
2479
2472
  (v, idx) => valueArrays[idx] ? valueArrays[idx][i] ?? NaN : v
2480
2473
  );
2481
2474
  const sum4 = nums.reduce((a, b2) => a + b2, 0);
@@ -2709,10 +2702,10 @@ function sign(value) {
2709
2702
  }
2710
2703
  return value > 0 ? 1 : value < 0 ? -1 : 0;
2711
2704
  }
2712
- function round_to_mintick(number, mintick) {
2713
- if (number instanceof Series) {
2714
- const bars = number.bars;
2715
- const valueArray = number.toArray();
2705
+ function round_to_mintick(number2, mintick) {
2706
+ if (number2 instanceof Series) {
2707
+ const bars = number2.bars;
2708
+ const valueArray = number2.toArray();
2716
2709
  const length2 = bars.length;
2717
2710
  if (mintick === void 0) {
2718
2711
  throw new Error(
@@ -2736,7 +2729,7 @@ function round_to_mintick(number, mintick) {
2736
2729
  }
2737
2730
  return Series.fromArray(bars, result);
2738
2731
  }
2739
- if (isNaN(number)) {
2732
+ if (isNaN(number2)) {
2740
2733
  return NaN;
2741
2734
  }
2742
2735
  if (mintick === void 0) {
@@ -2745,9 +2738,9 @@ function round_to_mintick(number, mintick) {
2745
2738
  );
2746
2739
  }
2747
2740
  if (mintick === 0) {
2748
- return number;
2741
+ return number2;
2749
2742
  }
2750
- return Math.round(number / mintick) * mintick;
2743
+ return Math.round(number2 / mintick) * mintick;
2751
2744
  }
2752
2745
  var pi = Math.PI;
2753
2746
  var e = Math.E;
@@ -2813,9 +2806,9 @@ __export(array_exports, {
2813
2806
  unshift: () => unshift,
2814
2807
  variance: () => variance2
2815
2808
  });
2816
- function new_array(size2 = 0, initial_value) {
2809
+ function new_array(size3 = 0, initial_value) {
2817
2810
  const arr = [];
2818
- for (let i = 0; i < size2; i++) {
2811
+ for (let i = 0; i < size3; i++) {
2819
2812
  arr.push(initial_value);
2820
2813
  }
2821
2814
  return arr;
@@ -2889,11 +2882,13 @@ function sum2(id) {
2889
2882
  function avg2(id) {
2890
2883
  return sum2(id) / size(id);
2891
2884
  }
2892
- function min3(id) {
2893
- return Math.min(...id);
2885
+ function min3(id, nth = 0) {
2886
+ const values2 = id.filter((v) => !Number.isNaN(v)).sort((a, b2) => a - b2);
2887
+ return values2.length ? values2[Math.min(nth, values2.length - 1)] : NaN;
2894
2888
  }
2895
- function max3(id) {
2896
- return Math.max(...id);
2889
+ function max3(id, nth = 0) {
2890
+ const values2 = id.filter((v) => !Number.isNaN(v)).sort((a, b2) => b2 - a);
2891
+ return values2.length ? values2[Math.min(nth, values2.length - 1)] : NaN;
2897
2892
  }
2898
2893
  function median2(id) {
2899
2894
  const sorted = [...id].sort((a, b2) => a - b2);
@@ -2914,16 +2909,15 @@ function mode2(id) {
2914
2909
  }
2915
2910
  return mode5;
2916
2911
  }
2917
- function stdev2(id) {
2918
- const mean = avg2(id);
2919
- const squareDiffs = id.map((value) => Math.pow(value - mean, 2));
2920
- const avgSquareDiff = sum2(squareDiffs) / size(id);
2921
- return Math.sqrt(avgSquareDiff);
2912
+ function stdev2(id, biased = true) {
2913
+ return Math.sqrt(variance2(id, biased));
2922
2914
  }
2923
- function variance2(id) {
2924
- const mean = avg2(id);
2925
- const squareDiffs = id.map((value) => Math.pow(value - mean, 2));
2926
- return sum2(squareDiffs) / size(id);
2915
+ function variance2(id, biased = true) {
2916
+ const values2 = id.filter((v) => !Number.isNaN(v));
2917
+ if (!values2.length) return NaN;
2918
+ const mean = values2.reduce((a, b2) => a + b2, 0) / values2.length;
2919
+ const squares = values2.reduce((a, b2) => a + (b2 - mean) * (b2 - mean), 0);
2920
+ return squares / (biased ? values2.length : values2.length - 1);
2927
2921
  }
2928
2922
  function fill(id, value, index_from = 0, index_to) {
2929
2923
  const end = index_to ?? id.length;
@@ -2931,8 +2925,8 @@ function fill(id, value, index_from = 0, index_to) {
2931
2925
  id[i] = value;
2932
2926
  }
2933
2927
  }
2934
- function from(id) {
2935
- return copy(id);
2928
+ function from(...values2) {
2929
+ return [...values2];
2936
2930
  }
2937
2931
  function first(id) {
2938
2932
  return id[0];
@@ -2940,38 +2934,38 @@ function first(id) {
2940
2934
  function last(id) {
2941
2935
  return id[id.length - 1];
2942
2936
  }
2943
- function some(id, predicate) {
2944
- return id.some(predicate);
2937
+ function some(id) {
2938
+ return id.some((v) => v === true);
2945
2939
  }
2946
- function every(id, predicate) {
2947
- return id.every(predicate);
2940
+ function every(id) {
2941
+ return id.length > 0 && id.every((v) => v === true);
2948
2942
  }
2949
- function new_bool(size2 = 0, initial_value = false) {
2950
- return new_array(size2, initial_value);
2943
+ function new_bool(size3 = 0, initial_value = false) {
2944
+ return new_array(size3, initial_value);
2951
2945
  }
2952
- function new_float(size2 = 0, initial_value = NaN) {
2953
- return new_array(size2, initial_value);
2946
+ function new_float(size3 = 0, initial_value = NaN) {
2947
+ return new_array(size3, initial_value);
2954
2948
  }
2955
- function new_int(size2 = 0, initial_value = NaN) {
2956
- return new_array(size2, initial_value);
2949
+ function new_int(size3 = 0, initial_value = NaN) {
2950
+ return new_array(size3, initial_value);
2957
2951
  }
2958
- function new_string(size2 = 0, initial_value) {
2959
- return new_array(size2, initial_value);
2952
+ function new_string(size3 = 0, initial_value) {
2953
+ return new_array(size3, initial_value);
2960
2954
  }
2961
- function new_color(size2 = 0, initial_value) {
2962
- return new_array(size2, initial_value);
2955
+ function new_color(size3 = 0, initial_value) {
2956
+ return new_array(size3, initial_value);
2963
2957
  }
2964
- function new_line(size2 = 0, initial_value) {
2965
- return new_array(size2, initial_value);
2958
+ function new_line(size3 = 0, initial_value) {
2959
+ return new_array(size3, initial_value);
2966
2960
  }
2967
- function new_box(size2 = 0, initial_value) {
2968
- return new_array(size2, initial_value);
2961
+ function new_box(size3 = 0, initial_value) {
2962
+ return new_array(size3, initial_value);
2969
2963
  }
2970
- function new_label(size2 = 0, initial_value) {
2971
- return new_array(size2, initial_value);
2964
+ function new_label(size3 = 0, initial_value) {
2965
+ return new_array(size3, initial_value);
2972
2966
  }
2973
- function new_linefill(size2 = 0, initial_value) {
2974
- return new_array(size2, initial_value);
2967
+ function new_linefill(size3 = 0, initial_value) {
2968
+ return new_array(size3, initial_value);
2975
2969
  }
2976
2970
  function abs2(id) {
2977
2971
  return id.map((x) => Math.abs(x));
@@ -3111,8 +3105,70 @@ function standardize(id) {
3111
3105
  }
3112
3106
  return id.map((value) => (value - mean) / stdDev);
3113
3107
  }
3114
- function newtype(size2 = 0, initial_value) {
3115
- return new_array(size2, initial_value);
3108
+ function newtype(size3 = 0, initial_value) {
3109
+ return new_array(size3, initial_value);
3110
+ }
3111
+
3112
+ // src/map/index.ts
3113
+ var map_exports = {};
3114
+ __export(map_exports, {
3115
+ MAX_SIZE: () => MAX_SIZE,
3116
+ clear: () => clear2,
3117
+ contains: () => contains,
3118
+ copy: () => copy2,
3119
+ get: () => get2,
3120
+ keys: () => keys,
3121
+ new_map: () => new_map,
3122
+ put: () => put,
3123
+ put_all: () => put_all,
3124
+ remove: () => remove2,
3125
+ size: () => size2,
3126
+ values: () => values
3127
+ });
3128
+ var MAX_SIZE = 5e4;
3129
+ function tooLarge(size3) {
3130
+ return new RangeError(`A map cannot have more than ${MAX_SIZE} key-value pairs. The current size is ${size3}.`);
3131
+ }
3132
+ function new_map() {
3133
+ return /* @__PURE__ */ new Map();
3134
+ }
3135
+ function put(id, key, value) {
3136
+ const previous = id.get(key);
3137
+ if (!id.has(key) && id.size >= MAX_SIZE) throw tooLarge(id.size + 1);
3138
+ id.set(key, value);
3139
+ return previous;
3140
+ }
3141
+ function put_all(id, id2) {
3142
+ let size3 = id.size;
3143
+ for (const key of id2.keys()) if (!id.has(key)) size3++;
3144
+ if (size3 > MAX_SIZE) throw tooLarge(size3);
3145
+ for (const [key, value] of id2) id.set(key, value);
3146
+ }
3147
+ function get2(id, key) {
3148
+ return id.get(key);
3149
+ }
3150
+ function contains(id, key) {
3151
+ return id.has(key);
3152
+ }
3153
+ function remove2(id, key) {
3154
+ const value = id.get(key);
3155
+ id.delete(key);
3156
+ return value;
3157
+ }
3158
+ function size2(id) {
3159
+ return id.size;
3160
+ }
3161
+ function clear2(id) {
3162
+ id.clear();
3163
+ }
3164
+ function keys(id) {
3165
+ return [...id.keys()];
3166
+ }
3167
+ function values(id) {
3168
+ return [...id.values()];
3169
+ }
3170
+ function copy2(id) {
3171
+ return new Map(id);
3116
3172
  }
3117
3173
 
3118
3174
  // src/str/index.ts
@@ -3120,7 +3176,7 @@ var str_exports = {};
3120
3176
  __export(str_exports, {
3121
3177
  charAt: () => charAt,
3122
3178
  concat: () => concat2,
3123
- contains: () => contains,
3179
+ contains: () => contains2,
3124
3180
  endswith: () => endswith,
3125
3181
  format: () => format,
3126
3182
  format_time: () => format_time,
@@ -3141,15 +3197,486 @@ __export(str_exports, {
3141
3197
  trimRight: () => trimRight,
3142
3198
  upper: () => upper
3143
3199
  });
3200
+
3201
+ // src/str/numberformat.ts
3202
+ var patterns = /* @__PURE__ */ new Map();
3203
+ function parsePattern(pattern) {
3204
+ const cached = patterns.get(pattern);
3205
+ if (cached) return cached;
3206
+ let prefix = "";
3207
+ let suffix = "";
3208
+ let number2 = "";
3209
+ let percent = false;
3210
+ let phase = "prefix";
3211
+ for (let i = 0; i < pattern.length; i++) {
3212
+ const ch = pattern[i];
3213
+ let literal;
3214
+ if (ch === "'") {
3215
+ const end = pattern.indexOf("'", i + 1);
3216
+ if (end === i + 1) {
3217
+ literal = "'";
3218
+ i = end;
3219
+ } else {
3220
+ literal = pattern.slice(i + 1, end === -1 ? void 0 : end);
3221
+ i = end === -1 ? pattern.length : end;
3222
+ }
3223
+ } else if (phase !== "suffix" && ("#0,.".includes(ch) || phase === "number" && ch === "E")) {
3224
+ phase = "number";
3225
+ number2 += ch;
3226
+ continue;
3227
+ } else {
3228
+ if (ch === "%") percent = true;
3229
+ literal = ch;
3230
+ }
3231
+ if (phase === "number") phase = "suffix";
3232
+ if (phase === "prefix") prefix += literal;
3233
+ else suffix += literal;
3234
+ }
3235
+ const [mantissa = "", exp2] = number2.split("E");
3236
+ const [intPart = "", fracPart = ""] = mantissa.split(".");
3237
+ const lastComma = intPart.lastIndexOf(",");
3238
+ const parsed = {
3239
+ prefix,
3240
+ suffix,
3241
+ // as in Java, a pattern with a decimal point and no '0' at all ("#.##") shows one integer digit
3242
+ minInt: !mantissa.includes("0") && mantissa.includes(".") ? 1 : [...intPart].filter((c) => c === "0").length,
3243
+ minFrac: [...fracPart].filter((c) => c === "0").length,
3244
+ maxFrac: [...fracPart].filter((c) => c === "0" || c === "#").length,
3245
+ grouping: lastComma === -1 ? 0 : intPart.length - lastComma - 1,
3246
+ percent,
3247
+ exponent: exp2 === void 0 ? null : exp2.length,
3248
+ hasDigits: /[0#]/.test(mantissa)
3249
+ };
3250
+ patterns.set(pattern, parsed);
3251
+ return parsed;
3252
+ }
3253
+ function shortestDigits(x) {
3254
+ const m = /^(\d+)(?:\.(\d+))?(?:e([+-]\d+))?$/.exec(String(Math.abs(x)));
3255
+ const all7 = m[1] + (m[2] ?? "");
3256
+ let intLen = m[1].length + Number(m[3] ?? 0);
3257
+ const lead = all7.length - all7.replace(/^0+/, "").length;
3258
+ intLen -= lead;
3259
+ const digits = all7.slice(lead).replace(/0+$/, "");
3260
+ return { digits, intLen: digits ? intLen : 0 };
3261
+ }
3262
+ function exactDigits(x) {
3263
+ const abs3 = Math.abs(x);
3264
+ if (abs3 === 0) return { digits: "", intLen: 0 };
3265
+ const view = new DataView(new ArrayBuffer(8));
3266
+ view.setFloat64(0, abs3);
3267
+ const bits = view.getBigUint64(0);
3268
+ const expBits = Number(bits >> 52n & 0x7ffn);
3269
+ let mant = bits & 0xfffffffffffffn;
3270
+ const e2 = expBits === 0 ? -1074 : expBits - 1075;
3271
+ if (expBits !== 0) mant |= 1n << 52n;
3272
+ let str;
3273
+ let fracDigits;
3274
+ if (e2 >= 0) {
3275
+ str = (mant << BigInt(e2)).toString();
3276
+ fracDigits = 0;
3277
+ } else {
3278
+ str = (mant * 5n ** BigInt(-e2)).toString();
3279
+ fracDigits = -e2;
3280
+ }
3281
+ const intLen = str.length - fracDigits;
3282
+ const lead = str.length - str.replace(/^0+/, "").length;
3283
+ const digits = str.slice(lead).replace(/0+$/, "");
3284
+ return { digits, intLen: intLen - lead };
3285
+ }
3286
+ function roundDigits(d, frac, mode5) {
3287
+ const keep = d.intLen + frac;
3288
+ if (keep >= d.digits.length) return d;
3289
+ if (keep < 0) return { digits: "", intLen: 0 };
3290
+ const first2 = d.digits.charCodeAt(keep) - 48;
3291
+ let up;
3292
+ if (mode5 === "halfUpShortest") up = first2 >= 5;
3293
+ else if (first2 !== 5) up = first2 > 5;
3294
+ else if (d.digits.length > keep + 1) up = true;
3295
+ else up = keep > 0 && (d.digits.charCodeAt(keep - 1) - 48) % 2 === 1;
3296
+ let kept = d.digits.slice(0, keep);
3297
+ let intLen = d.intLen;
3298
+ if (up) {
3299
+ const n = (BigInt(kept || "0") + 1n).toString();
3300
+ if (n.length > kept.length) intLen += 1;
3301
+ kept = n;
3302
+ }
3303
+ kept = kept.replace(/0+$/, "");
3304
+ return { digits: kept, intLen: kept ? intLen : 0 };
3305
+ }
3306
+ function group(int, size3) {
3307
+ if (!size3 || int.length <= size3) return int;
3308
+ const parts = [];
3309
+ for (let end = int.length; end > 0; end -= size3) parts.unshift(int.slice(Math.max(0, end - size3), end));
3310
+ return parts.join(",");
3311
+ }
3312
+ function layout(d, p) {
3313
+ let int = d.intLen > 0 ? d.digits.slice(0, d.intLen).padEnd(d.intLen, "0") : "";
3314
+ int = int.replace(/^0+/, "").padStart(p.minInt, "0");
3315
+ let frac = d.intLen < 0 ? "0".repeat(-d.intLen) + d.digits : d.digits.slice(Math.max(0, d.intLen));
3316
+ frac = frac.slice(0, p.maxFrac).replace(/0+$/, "").padEnd(p.minFrac, "0");
3317
+ if (!int && !frac) int = "0";
3318
+ return group(int, p.grouping) + (frac ? "." + frac : "");
3319
+ }
3320
+ function formatNumber(value, pattern, mode5) {
3321
+ if (Number.isNaN(value)) return "NaN";
3322
+ const p = parsePattern(pattern);
3323
+ if (!Number.isFinite(value)) return (value < 0 ? "-" : "") + p.prefix + "\u221E" + p.suffix;
3324
+ const x = p.percent ? value * 100 : value;
3325
+ const toDigits = mode5 === "halfUpShortest" ? shortestDigits : exactDigits;
3326
+ let body;
3327
+ let isZero;
3328
+ if (p.exponent !== null) {
3329
+ const rounded = roundDigits(toDigits(x), p.maxFrac, mode5);
3330
+ const intDigits = Math.max(p.minInt, 1);
3331
+ isZero = rounded.digits === "";
3332
+ let exponent = isZero ? 0 : rounded.intLen - intDigits;
3333
+ let mant = roundDigits({ digits: rounded.digits, intLen: isZero ? 0 : intDigits }, p.maxFrac, mode5);
3334
+ if (mant.intLen > intDigits) {
3335
+ exponent += 1;
3336
+ mant = { digits: mant.digits, intLen: intDigits };
3337
+ }
3338
+ const e2 = String(Math.abs(exponent)).padStart(p.exponent, "0");
3339
+ body = layout(mant, p) + "E" + (exponent < 0 ? "-" : "") + e2;
3340
+ } else {
3341
+ const rounded = roundDigits(toDigits(x), p.hasDigits ? p.maxFrac : 0, mode5);
3342
+ isZero = rounded.digits === "";
3343
+ body = p.hasDigits ? layout(rounded, p) : layout(rounded, { ...p, minInt: 0, maxFrac: 0, minFrac: 0 });
3344
+ }
3345
+ const negative = x < 0 && (!isZero || !p.hasDigits);
3346
+ return (negative ? "-" : "") + p.prefix + body + p.suffix;
3347
+ }
3348
+
3349
+ // src/time/timezone.ts
3350
+ var MS_PER_SECOND = 1e3;
3351
+ var MS_PER_DAY = 864e5;
3352
+ var MAX_OFFSET_SECONDS = 18 * 3600;
3353
+ var OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\d{1,2})(?::?(\d{2})(?::?(\d{2}))?)?)?$/;
3354
+ var REJECTED_NAMES = /* @__PURE__ */ new Set(["EST", "MST", "HST"]);
3355
+ var canonicalNames;
3356
+ function hasTimeZoneCase(name) {
3357
+ if (name.split("/").some((segment) => !/^[A-Z]/.test(segment))) return false;
3358
+ canonicalNames ??= new Map(Intl.supportedValuesOf("timeZone").map((n) => [n.toLowerCase(), n]));
3359
+ const canonical = canonicalNames.get(name.toLowerCase());
3360
+ return canonical === void 0 || canonical === name;
3361
+ }
3362
+ var zones = /* @__PURE__ */ new Map();
3363
+ function resolveZone(timezone) {
3364
+ let zone = zones.get(timezone);
3365
+ if (zone) return zone;
3366
+ const invalid = () => new RangeError(
3367
+ `Invalid time zone "${timezone}": use UTC/GMT offset notation ("UTC-5", "GMT+0530") or an IANA name ("America/New_York")`
3368
+ );
3369
+ const m = OFFSET_NOTATION.exec(timezone);
3370
+ if (m) {
3371
+ const [, sign2, h = "0", mi = "0", s] = m;
3372
+ const minutes = Number(mi);
3373
+ const seconds = s === void 0 ? 0 : Number(s);
3374
+ if (minutes > 59 || seconds > 59 || s !== void 0 && h.length !== 2) throw invalid();
3375
+ const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;
3376
+ if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();
3377
+ zone = { kind: "fixed", offsetMs: (sign2 === "-" ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };
3378
+ } else {
3379
+ if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();
3380
+ let format2;
3381
+ try {
3382
+ format2 = new Intl.DateTimeFormat("en-US", {
3383
+ timeZone: timezone,
3384
+ hourCycle: "h23",
3385
+ year: "numeric",
3386
+ month: "numeric",
3387
+ day: "numeric",
3388
+ hour: "numeric",
3389
+ minute: "numeric",
3390
+ second: "numeric"
3391
+ });
3392
+ } catch {
3393
+ throw invalid();
3394
+ }
3395
+ zone = { kind: "iana", format: format2 };
3396
+ }
3397
+ zones.set(timezone, zone);
3398
+ return zone;
3399
+ }
3400
+ function offsetAt(zone, time) {
3401
+ if (zone.kind === "fixed") return zone.offsetMs;
3402
+ const wholeSecond = Math.floor(time / 1e3) * 1e3;
3403
+ const f = {};
3404
+ for (const part of zone.format.formatToParts(wholeSecond)) {
3405
+ if (part.type !== "literal") f[part.type] = Number(part.value);
3406
+ }
3407
+ const local = Date.UTC(f.year, f.month - 1, f.day, f.hour, f.minute, f.second);
3408
+ return local - wholeSecond;
3409
+ }
3410
+ function zoneOffset(time, timezone) {
3411
+ return offsetAt(resolveZone(timezone), time);
3412
+ }
3413
+ function zonedFields(time, timezone) {
3414
+ const local = new Date(time + offsetAt(resolveZone(timezone), time));
3415
+ return {
3416
+ year: local.getUTCFullYear(),
3417
+ month: local.getUTCMonth() + 1,
3418
+ day: local.getUTCDate(),
3419
+ hour: local.getUTCHours(),
3420
+ minute: local.getUTCMinutes(),
3421
+ second: local.getUTCSeconds(),
3422
+ dayOfWeek: local.getUTCDay() + 1
3423
+ };
3424
+ }
3425
+ function zonedToUnix(timezone, year2, month2, day, hour2 = 0, minute2 = 0, second2 = 0) {
3426
+ const zone = resolveZone(timezone);
3427
+ const local = Date.UTC(year2, month2 - 1, day, hour2, minute2, second2);
3428
+ if (zone.kind === "fixed") return local - zone.offsetMs;
3429
+ const before = offsetAt(zone, local - MS_PER_DAY);
3430
+ const after = offsetAt(zone, local + MS_PER_DAY);
3431
+ const candidates = [local - before, local - after].filter((t2) => local - offsetAt(zone, t2) === t2);
3432
+ if (candidates.length) return Math.max(...candidates);
3433
+ return local - before;
3434
+ }
3435
+
3436
+ // src/str/dateformat.ts
3437
+ var MONTHS = [
3438
+ "January",
3439
+ "February",
3440
+ "March",
3441
+ "April",
3442
+ "May",
3443
+ "June",
3444
+ "July",
3445
+ "August",
3446
+ "September",
3447
+ "October",
3448
+ "November",
3449
+ "December"
3450
+ ];
3451
+ var DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
3452
+ var pad = (n, width) => String(n).padStart(width, "0");
3453
+ function zoneName(time, timezone, offsetMs) {
3454
+ if (timezone === "Etc/UTC") return "UTC";
3455
+ if (/^(UTC|GMT)/.test(timezone)) {
3456
+ if (offsetMs === 0) return "GMT";
3457
+ const minutes = Math.abs(offsetMs) / 6e4;
3458
+ return `GMT${offsetMs < 0 ? "-" : "+"}${pad(Math.floor(minutes / 60), 2)}:${pad(minutes % 60, 2)}`;
3459
+ }
3460
+ const part = new Intl.DateTimeFormat("en-US", { timeZone: timezone, timeZoneName: "short" }).formatToParts(time).find((p) => p.type === "timeZoneName");
3461
+ return part?.value ?? timezone;
3462
+ }
3463
+ function weekOfYear(year2, month2, day) {
3464
+ const date = Date.UTC(year2, month2 - 1, day);
3465
+ const dow = new Date(date).getUTCDay();
3466
+ const weekStart = date - dow * 864e5;
3467
+ if (weekStart + 6 * 864e5 >= Date.UTC(year2 + 1, 0, 1)) return 1;
3468
+ const jan1 = Date.UTC(year2, 0, 1);
3469
+ const jan1Dow = new Date(jan1).getUTCDay();
3470
+ return Math.floor((date - jan1 + jan1Dow * 864e5) / (7 * 864e5)) + 1;
3471
+ }
3472
+ function formatDate(time, pattern, timezone) {
3473
+ if (Number.isNaN(time)) return "NaN";
3474
+ const f = zonedFields(time, timezone);
3475
+ const offset = zoneOffset(time, timezone);
3476
+ const ms = (time % 1e3 + 1e3) % 1e3;
3477
+ const dayOfYear = (Date.UTC(f.year, f.month - 1, f.day) - Date.UTC(f.year, 0, 1)) / 864e5 + 1;
3478
+ let out = "";
3479
+ for (let i = 0; i < pattern.length; ) {
3480
+ const ch = pattern[i];
3481
+ if (ch === "'") {
3482
+ const end = pattern.indexOf("'", i + 1);
3483
+ if (end === i + 1) {
3484
+ out += "'";
3485
+ i += 2;
3486
+ } else {
3487
+ out += pattern.slice(i + 1, end === -1 ? void 0 : end);
3488
+ i = end === -1 ? pattern.length : end + 1;
3489
+ }
3490
+ continue;
3491
+ }
3492
+ if (!/[A-Za-z]/.test(ch)) {
3493
+ out += ch;
3494
+ i++;
3495
+ continue;
3496
+ }
3497
+ let n = 1;
3498
+ while (pattern[i + n] === ch) n++;
3499
+ i += n;
3500
+ const hour12 = f.hour % 12;
3501
+ switch (ch) {
3502
+ case "y":
3503
+ out += n === 2 ? pad(f.year % 100, 2) : pad(f.year, n);
3504
+ break;
3505
+ case "M":
3506
+ out += n >= 4 ? MONTHS[f.month - 1] : n === 3 ? MONTHS[f.month - 1].slice(0, 3) : pad(f.month, n);
3507
+ break;
3508
+ case "d":
3509
+ out += pad(f.day, n);
3510
+ break;
3511
+ case "E":
3512
+ out += n >= 4 ? DAYS[f.dayOfWeek - 1] : DAYS[f.dayOfWeek - 1].slice(0, 3);
3513
+ break;
3514
+ case "u":
3515
+ out += pad(f.dayOfWeek === 1 ? 7 : f.dayOfWeek - 1, n);
3516
+ break;
3517
+ case "D":
3518
+ out += pad(dayOfYear, n);
3519
+ break;
3520
+ case "w":
3521
+ out += pad(weekOfYear(f.year, f.month, f.day), n);
3522
+ break;
3523
+ case "H":
3524
+ out += pad(f.hour, n);
3525
+ break;
3526
+ case "k":
3527
+ out += pad(f.hour === 0 ? 24 : f.hour, n);
3528
+ break;
3529
+ case "K":
3530
+ out += pad(hour12, n);
3531
+ break;
3532
+ case "h":
3533
+ out += pad(hour12 === 0 ? 12 : hour12, n);
3534
+ break;
3535
+ case "a":
3536
+ out += f.hour < 12 ? "AM" : "PM";
3537
+ break;
3538
+ case "m":
3539
+ out += pad(f.minute, n);
3540
+ break;
3541
+ case "s":
3542
+ out += pad(f.second, n);
3543
+ break;
3544
+ case "S":
3545
+ out += pad(ms, n);
3546
+ break;
3547
+ case "Z": {
3548
+ const minutes = Math.abs(offset) / 6e4;
3549
+ out += (offset < 0 ? "-" : "+") + pad(Math.floor(minutes / 60), 2) + pad(minutes % 60, 2);
3550
+ break;
3551
+ }
3552
+ case "z":
3553
+ out += zoneName(time, timezone, offset);
3554
+ break;
3555
+ default:
3556
+ throw new SyntaxError(`Unsupported date pattern letter "${ch}" in "${pattern}"`);
3557
+ }
3558
+ }
3559
+ return out;
3560
+ }
3561
+
3562
+ // src/str/messageformat.ts
3563
+ var DATE_STYLES = {
3564
+ short: "M/d/yy",
3565
+ medium: "MMM d, yyyy",
3566
+ long: "MMMM d, yyyy",
3567
+ full: "EEEE, MMMM d, yyyy"
3568
+ };
3569
+ var TIME_STYLES = {
3570
+ short: "h:mm\u202Fa",
3571
+ medium: "h:mm:ss\u202Fa",
3572
+ long: "h:mm:ss\u202Fa z",
3573
+ full: "h:mm:ss\u202Fa z"
3574
+ };
3575
+ function number(value, pattern) {
3576
+ return typeof value === "number" ? formatNumber(value, pattern, "halfEvenExact") : String(value);
3577
+ }
3578
+ function choice(value, spec) {
3579
+ const options = spec.split("|").map((part) => {
3580
+ const m = /^\s*(-?[\d.]+|-?∞)\s*([#<≤])(.*)$/.exec(part);
3581
+ if (!m) throw new SyntaxError(`Invalid choice format "${spec}"`);
3582
+ const limit = m[1].includes("\u221E") ? m[1].startsWith("-") ? -Infinity : Infinity : Number(m[1]);
3583
+ return { limit: m[2] === "<" ? limit + Number.EPSILON * Math.max(1, Math.abs(limit)) : limit, text: m[3] };
3584
+ });
3585
+ let chosen = options[0];
3586
+ for (const o of options) if (value >= o.limit) chosen = o;
3587
+ return chosen.text;
3588
+ }
3589
+ function formatArgument(value, type, style, timezone) {
3590
+ if (value === void 0) return "";
3591
+ if (!type) return typeof value === "number" ? number(value, "#,##0.###") : String(value);
3592
+ switch (type.trim()) {
3593
+ case "number": {
3594
+ const s = style?.trim();
3595
+ if (!s) return number(value, "#,##0.###");
3596
+ if (s === "integer") return number(value, "#,##0");
3597
+ if (s === "percent") return number(value, "#,##0%");
3598
+ if (s === "currency") return number(value, "'$'#,##0.00");
3599
+ return number(value, style);
3600
+ }
3601
+ case "date":
3602
+ case "time": {
3603
+ const styles = type.trim() === "date" ? DATE_STYLES : TIME_STYLES;
3604
+ const s = style?.trim() ?? "medium";
3605
+ return formatDate(Number(value), styles[s] ?? style, typeof timezone === "function" ? timezone() : timezone);
3606
+ }
3607
+ case "choice":
3608
+ return choice(Number(value), style ?? "");
3609
+ default:
3610
+ throw new SyntaxError(`Unknown format type "${type}"`);
3611
+ }
3612
+ }
3613
+ function formatMessage(pattern, args, timezone) {
3614
+ let out = "";
3615
+ for (let i = 0; i < pattern.length; ) {
3616
+ const ch = pattern[i];
3617
+ if (ch === "'") {
3618
+ if (pattern[i + 1] === "'") {
3619
+ out += "'";
3620
+ i += 2;
3621
+ continue;
3622
+ }
3623
+ const end = pattern.indexOf("'", i + 1);
3624
+ out += pattern.slice(i + 1, end === -1 ? void 0 : end);
3625
+ i = end === -1 ? pattern.length : end + 1;
3626
+ continue;
3627
+ }
3628
+ if (ch !== "{") {
3629
+ out += ch;
3630
+ i++;
3631
+ continue;
3632
+ }
3633
+ let depth = 1;
3634
+ let j = i + 1;
3635
+ let inQuote = false;
3636
+ for (; j < pattern.length && depth > 0; j++) {
3637
+ const c = pattern[j];
3638
+ if (c === "'") inQuote = !inQuote;
3639
+ else if (!inQuote && c === "{") depth++;
3640
+ else if (!inQuote && c === "}") depth--;
3641
+ }
3642
+ const inner = pattern.slice(i + 1, j - 1);
3643
+ const [index = "", type, ...rest] = inner.split(",");
3644
+ const style = rest.length ? rest.join(",") : void 0;
3645
+ const n = Number(index.trim());
3646
+ out += n < args.length ? formatArgument(args[n], type, style, timezone) : `{${inner}}`;
3647
+ i = j;
3648
+ }
3649
+ return out;
3650
+ }
3651
+
3652
+ // src/str/index.ts
3144
3653
  function length(str) {
3145
3654
  return str.length;
3146
3655
  }
3147
3656
  function tostring(value, format2) {
3148
- if (typeof value === "number" && format2) {
3149
- const decimals = format2.split(".")[1]?.length || 0;
3150
- return value.toFixed(decimals);
3657
+ if (typeof value !== "number") return String(value);
3658
+ if (!Number.isFinite(value)) return String(value);
3659
+ if (format2 === void 0 || format2 === "") {
3660
+ if (Math.abs(value) >= 1e21 && Number.isFinite(value)) {
3661
+ return String(value).replace("e+", "E").replace(/\.0+E/, "E");
3662
+ }
3663
+ return formatNumber(value, "#.##########", "halfUpShortest");
3664
+ }
3665
+ switch (format2) {
3666
+ case "percent":
3667
+ return formatNumber(value, "0.00", "halfUpShortest") + "%";
3668
+ case "volume": {
3669
+ const abs3 = Math.abs(value);
3670
+ for (const [size3, unit] of [[1e12, "T"], [1e9, "B"], [1e6, "M"], [1e3, "K"]]) {
3671
+ if (abs3 >= size3) return formatNumber(value / size3, "#.###", "halfUpShortest") + unit;
3672
+ }
3673
+ return formatNumber(value, "#", "halfUpShortest");
3674
+ }
3675
+ case "mintick":
3676
+ throw new Error("str.tostring(x, format.mintick) needs the symbol tick size (syminfo.mintick), which is not known here");
3677
+ default:
3678
+ return formatNumber(value, format2, "halfUpShortest");
3151
3679
  }
3152
- return String(value);
3153
3680
  }
3154
3681
  function tonumber(str) {
3155
3682
  const num = parseFloat(str);
@@ -3164,7 +3691,7 @@ function upper(str) {
3164
3691
  function lower(str) {
3165
3692
  return str.toLowerCase();
3166
3693
  }
3167
- function contains(source, str) {
3694
+ function contains2(source, str) {
3168
3695
  return source.includes(str);
3169
3696
  }
3170
3697
  function pos(source, str) {
@@ -3187,11 +3714,7 @@ function concat2(...strings) {
3187
3714
  return strings.join("");
3188
3715
  }
3189
3716
  function format(formatStr, ...args) {
3190
- let result = formatStr;
3191
- args.forEach((arg, index) => {
3192
- result = result.replaceAll(`{${index}}`, String(arg));
3193
- });
3194
- return result;
3717
+ return formatMessage(formatStr, args, "Etc/UTC");
3195
3718
  }
3196
3719
  function startswith(source, str) {
3197
3720
  return source.startsWith(str);
@@ -3219,84 +3742,8 @@ function repeat(source, count, separator = "") {
3219
3742
  if (count <= 0) return "";
3220
3743
  return Array(count).fill(source).join(separator);
3221
3744
  }
3222
- function format_time(time, format2) {
3223
- const date = new Date(time);
3224
- const monthNames = [
3225
- "January",
3226
- "February",
3227
- "March",
3228
- "April",
3229
- "May",
3230
- "June",
3231
- "July",
3232
- "August",
3233
- "September",
3234
- "October",
3235
- "November",
3236
- "December"
3237
- ];
3238
- const monthNamesShort = [
3239
- "Jan",
3240
- "Feb",
3241
- "Mar",
3242
- "Apr",
3243
- "May",
3244
- "Jun",
3245
- "Jul",
3246
- "Aug",
3247
- "Sep",
3248
- "Oct",
3249
- "Nov",
3250
- "Dec"
3251
- ];
3252
- const year = date.getUTCFullYear();
3253
- const month = date.getUTCMonth();
3254
- const day = date.getUTCDate();
3255
- const hours = date.getUTCHours();
3256
- const minutes = date.getUTCMinutes();
3257
- const seconds = date.getUTCSeconds();
3258
- const pad = (num, len = 2) => num.toString().padStart(len, "0");
3259
- const hours12 = hours % 12 || 12;
3260
- const ampm = hours < 12 ? "AM" : "PM";
3261
- const replacements = [
3262
- // Year (process yyyy before yy)
3263
- [/yyyy/g, year.toString()],
3264
- [/yy/g, year.toString().slice(-2)],
3265
- // Month (process MMMM before MMM before MM before M)
3266
- [/MMMM/g, monthNames[month]],
3267
- [/MMM/g, monthNamesShort[month]],
3268
- [/MM/g, pad(month + 1)],
3269
- [/M/g, (month + 1).toString()],
3270
- // Day (process dd before d)
3271
- [/dd/g, pad(day)],
3272
- [/d/g, day.toString()],
3273
- // Hours 24-hour (process HH before H)
3274
- [/HH/g, pad(hours)],
3275
- [/H/g, hours.toString()],
3276
- // Hours 12-hour (process hh before h)
3277
- [/hh/g, pad(hours12)],
3278
- [/h/g, hours12.toString()],
3279
- // Minutes (process mm before m)
3280
- [/mm/g, pad(minutes)],
3281
- [/m/g, minutes.toString()],
3282
- // Seconds (process ss before s)
3283
- [/ss/g, pad(seconds)],
3284
- [/s/g, seconds.toString()],
3285
- // AM/PM
3286
- [/a/g, ampm]
3287
- ];
3288
- let result = format2;
3289
- const tokens = [];
3290
- replacements.forEach(([pattern, value], index) => {
3291
- const token = `\uFFF0${index}\uFFF1`;
3292
- result = result.replace(pattern, token);
3293
- tokens[index] = value;
3294
- });
3295
- tokens.forEach((value, index) => {
3296
- const token = `\uFFF0${index}\uFFF1`;
3297
- result = result.replaceAll(token, value);
3298
- });
3299
- return result;
3745
+ function format_time(time, format2 = "yyyy-MM-dd'T'HH:mm:ssZ", timezone = "Etc/UTC") {
3746
+ return formatDate(time, format2, timezone);
3300
3747
  }
3301
3748
 
3302
3749
  // src/color/index.ts
@@ -3394,16 +3841,16 @@ var teal = "#008080";
3394
3841
  var white = "#FFFFFF";
3395
3842
  var yellow = "#FFFF00";
3396
3843
  function from_gradient(value, bottom_value, top_value, bottom_color, top_color) {
3397
- const parseColor2 = (col2) => {
3398
- if (typeof col2 === "string") {
3399
- if (col2.startsWith("#")) {
3400
- const hex = col2.slice(1);
3844
+ const parseColor2 = (col3) => {
3845
+ if (typeof col3 === "string") {
3846
+ if (col3.startsWith("#")) {
3847
+ const hex = col3.slice(1);
3401
3848
  const r4 = parseInt(hex.slice(0, 2), 16);
3402
3849
  const g4 = parseInt(hex.slice(2, 4), 16);
3403
3850
  const b4 = parseInt(hex.slice(4, 6), 16);
3404
3851
  return [r4, g4, b4, 1];
3405
3852
  }
3406
- const match2 = col2.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
3853
+ const match2 = col3.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
3407
3854
  if (match2) {
3408
3855
  return [
3409
3856
  parseInt(match2[1]),
@@ -3438,21 +3885,260 @@ function from_gradient(value, bottom_value, top_value, bottom_color, top_color)
3438
3885
  // src/time/index.ts
3439
3886
  var time_exports = {};
3440
3887
  __export(time_exports, {
3888
+ dayofmonth: () => dayofmonth,
3889
+ dayofweek: () => dayofweek,
3890
+ hour: () => hour,
3891
+ inSession: () => inSession2,
3892
+ minute: () => minute,
3893
+ month: () => month,
3441
3894
  now: () => now,
3442
- timestamp: () => timestamp
3895
+ second: () => second,
3896
+ timestamp: () => timestamp,
3897
+ weekofyear: () => weekofyear,
3898
+ year: () => year
3443
3899
  });
3900
+
3901
+ // src/time/datestring.ts
3902
+ var MONTHS2 = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
3903
+ var FULL_MONTHS = [
3904
+ "january",
3905
+ "february",
3906
+ "march",
3907
+ "april",
3908
+ "may",
3909
+ "june",
3910
+ "july",
3911
+ "august",
3912
+ "september",
3913
+ "october",
3914
+ "november",
3915
+ "december"
3916
+ ];
3917
+ var ZONE_NAMES = {
3918
+ ut: 0,
3919
+ utc: 0,
3920
+ gmt: 0,
3921
+ est: -5,
3922
+ edt: -4,
3923
+ cst: -6,
3924
+ cdt: -5,
3925
+ mst: -7,
3926
+ mdt: -6,
3927
+ pst: -8,
3928
+ pdt: -7
3929
+ };
3930
+ var TIME = String.raw`(\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3})\d*)?)?`;
3931
+ var ZONE = String.raw`(ut|utc|gmt|[ecmp][sd]t|(?:utc|gmt)?\s*[+-]\d{1,2}(?::?\d{2})?)`;
3932
+ var NUMERIC_ZONE = String.raw`([+-]\d{2}(?::?\d{2})?)`;
3933
+ var DATE = String.raw`(\d{4})([-/])(\d{1,2})\2(\d{1,2})`;
3934
+ var WEEKDAY = String.raw`(?:[a-z]{3,9},?\s+)?`;
3935
+ var ISO_T = new RegExp(String.raw`^${DATE}t${TIME}\s*${NUMERIC_ZONE}?$`, "i");
3936
+ var ISO = new RegExp(String.raw`^${DATE}(?:\s+${TIME})?\s*${ZONE}?$`, "i");
3937
+ var DAY_FIRST = new RegExp(String.raw`^${WEEKDAY}(\d{1,2})(?:\s+|-)([a-z]+)\.?,?(?:\s+|-)(\d{4})(?:,?\s+${TIME})?\s*${ZONE}?$`, "i");
3938
+ var MONTH_FIRST = new RegExp(String.raw`^${WEEKDAY}([a-z]+)\.?\s+(\d{1,2}),?\s+(\d{4})(?:,?\s+${TIME})?\s*${ZONE}?$`, "i");
3939
+ function monthNumber(name) {
3940
+ const lower2 = name.toLowerCase();
3941
+ const i = FULL_MONTHS.findIndex((full, k) => lower2.startsWith(MONTHS2[k]) && full.startsWith(lower2));
3942
+ return i + 1;
3943
+ }
3944
+ function zoneMinutes(zone) {
3945
+ if (!zone) return 0;
3946
+ const lower2 = zone.toLowerCase().replace(/\s+/g, "");
3947
+ const named = ZONE_NAMES[lower2];
3948
+ if (named !== void 0) return named * 60;
3949
+ const m = /^(?:utc|gmt)?([+-])(\d{1,2})(?::?(\d{2}))?$/.exec(lower2);
3950
+ if (!m) return NaN;
3951
+ const minutes = Number(m[2]) * 60 + (m[3] ? Number(m[3]) : 0);
3952
+ return m[1] === "-" ? -minutes : minutes;
3953
+ }
3954
+ function parseDateString(dateString) {
3955
+ const text = dateString.trim();
3956
+ let year2, month2, day;
3957
+ let rest;
3958
+ let m;
3959
+ if (m = ISO_T.exec(text) ?? ISO.exec(text)) {
3960
+ [year2, month2, day] = [m[1], Number(m[3]), m[4]];
3961
+ rest = m.slice(5);
3962
+ } else if (m = DAY_FIRST.exec(text)) {
3963
+ [day, month2, year2] = [m[1], monthNumber(m[2]), m[3]];
3964
+ rest = m.slice(4);
3965
+ } else if (m = MONTH_FIRST.exec(text)) {
3966
+ [month2, day, year2] = [monthNumber(m[1]), m[2], m[3]];
3967
+ rest = m.slice(4);
3968
+ } else {
3969
+ throw new SyntaxError(`Invalid date string "${dateString}": use RFC 2822 or ISO 8601 ("20 Feb 2020", "2020-02-20T14:48:00")`);
3970
+ }
3971
+ const [hour2 = "0", minute2 = "0", second2 = "0", millis = "0", zone] = rest;
3972
+ const d = Number(day);
3973
+ const h = Number(hour2);
3974
+ const mi = Number(minute2);
3975
+ const s = Number(second2);
3976
+ const offset = zoneMinutes(zone);
3977
+ const endOfDay = h === 24 && mi === 0 && s === 0 && Number(millis) === 0;
3978
+ if (month2 < 1 || month2 > 12 || d < 1 || d > 31 || h > 23 && !endOfDay || mi > 59 || s > 59 || Number.isNaN(offset)) {
3979
+ throw new SyntaxError(`Invalid date string "${dateString}": a field is out of range`);
3980
+ }
3981
+ const ms = Number(millis.padEnd(3, "0"));
3982
+ return Date.UTC(Number(year2), month2 - 1, d, h, mi, s, ms) - offset * 6e4;
3983
+ }
3984
+
3985
+ // src/time/session.ts
3986
+ var PERIOD = /^(\d{2})(\d{2})-(\d{2})(\d{2})$/;
3987
+ var sessions = /* @__PURE__ */ new Map();
3988
+ function parseSession(session) {
3989
+ let parsed = sessions.get(session);
3990
+ if (parsed) return parsed;
3991
+ const invalid = () => new SyntaxError(`Invalid session "${session}": expected "HHmm-HHmm[,HHmm-HHmm...][:days]"`);
3992
+ const text = session.trim() === "24x7" ? "0000-0000" : session.replace(/\s+/g, "");
3993
+ const [periodText = "", dayText, extra] = text.split(":");
3994
+ if (extra !== void 0 || periodText === "") throw invalid();
3995
+ const periods = periodText.split(",").map((p) => {
3996
+ const m = PERIOD.exec(p);
3997
+ if (!m) throw invalid();
3998
+ const [h1, m1, h2, m2] = [m[1], m[2], m[3], m[4]].map(Number);
3999
+ if (h1 > 23 || h2 > 23 || m1 > 59 || m2 > 59) throw invalid();
4000
+ return { start: h1 * 60 + m1, end: h2 * 60 + m2 };
4001
+ });
4002
+ const dayDigits = dayText ?? (periods.length > 1 ? "23456" : "1234567");
4003
+ if (!/^[1-7]+$/.test(dayDigits)) throw invalid();
4004
+ const days = new Array(8).fill(false);
4005
+ for (const d of dayDigits) days[Number(d)] = true;
4006
+ parsed = { periods, days };
4007
+ sessions.set(session, parsed);
4008
+ return parsed;
4009
+ }
4010
+ function inSession(time, session, timezone) {
4011
+ if (Number.isNaN(time)) return false;
4012
+ const { periods, days } = parseSession(session);
4013
+ const f = zonedFields(time, timezone);
4014
+ const minute2 = f.hour * 60 + f.minute;
4015
+ const nextDay = f.dayOfWeek % 7 + 1;
4016
+ for (const { start, end } of periods) {
4017
+ if (start < end || start === 0 && end === 0) {
4018
+ if (minute2 >= start && (minute2 < end || end === 0) && days[f.dayOfWeek]) return true;
4019
+ } else {
4020
+ if (minute2 >= start && days[nextDay]) return true;
4021
+ if (minute2 < end && days[f.dayOfWeek]) return true;
4022
+ }
4023
+ }
4024
+ return false;
4025
+ }
4026
+
4027
+ // src/time/index.ts
3444
4028
  function now() {
3445
4029
  return Date.now();
3446
4030
  }
3447
- function timestamp(year, month, day, hour, minute, second) {
3448
- return new Date(
3449
- year,
3450
- month - 1,
3451
- day,
3452
- hour || 0,
3453
- minute || 0,
3454
- second || 0
3455
- ).getTime();
4031
+ function timestamp(first2, ...rest) {
4032
+ if (typeof first2 === "string") {
4033
+ if (rest.length === 0) return parseDateString(first2);
4034
+ const [year2, month3, day2, hour3, minute3, second3] = rest;
4035
+ return zonedToUnix(first2, year2, month3, day2, hour3 ?? 0, minute3 ?? 0, second3 ?? 0);
4036
+ }
4037
+ const [month2, day, hour2, minute2, second2] = rest;
4038
+ return new Date(first2, month2 - 1, day, hour2 || 0, minute2 || 0, second2 || 0).getTime();
4039
+ }
4040
+ function field(time, timezone, pick) {
4041
+ return Number.isNaN(time) ? NaN : pick(zonedFields(time, timezone));
4042
+ }
4043
+ function year(time, timezone) {
4044
+ return field(time, timezone, (f) => f.year);
4045
+ }
4046
+ function month(time, timezone) {
4047
+ return field(time, timezone, (f) => f.month);
4048
+ }
4049
+ function dayofmonth(time, timezone) {
4050
+ return field(time, timezone, (f) => f.day);
4051
+ }
4052
+ function dayofweek(time, timezone) {
4053
+ return field(time, timezone, (f) => f.dayOfWeek);
4054
+ }
4055
+ function weekofyear(time, timezone) {
4056
+ return field(time, timezone, (f) => {
4057
+ const date = Date.UTC(f.year, f.month - 1, f.day);
4058
+ const mondayBased = (f.dayOfWeek + 5) % 7;
4059
+ const thursday = new Date(date + (3 - mondayBased) * 864e5);
4060
+ const yearStart = Date.UTC(thursday.getUTCFullYear(), 0, 1);
4061
+ return 1 + Math.floor((thursday.getTime() - yearStart) / (7 * 864e5));
4062
+ });
4063
+ }
4064
+ function hour(time, timezone) {
4065
+ return field(time, timezone, (f) => f.hour);
4066
+ }
4067
+ function minute(time, timezone) {
4068
+ return field(time, timezone, (f) => f.minute);
4069
+ }
4070
+ function second(time, timezone) {
4071
+ return field(time, timezone, (f) => f.second);
4072
+ }
4073
+ function inSession2(time, session, timezone) {
4074
+ return inSession(time, session, timezone);
4075
+ }
4076
+
4077
+ // src/timeframe/index.ts
4078
+ var timeframe_exports = {};
4079
+ __export(timeframe_exports, {
4080
+ from_seconds: () => from_seconds,
4081
+ in_seconds: () => in_seconds,
4082
+ info: () => info
4083
+ });
4084
+ var SECONDS_PER_MINUTE = 60;
4085
+ var SECONDS_PER_DAY = 86400;
4086
+ var SECONDS_PER_WEEK = 604800;
4087
+ var SECONDS_PER_MONTH = 2628003;
4088
+ var SECONDS_365_DAYS = 365 * SECONDS_PER_DAY;
4089
+ var UNIT_SECONDS = {
4090
+ S: 1,
4091
+ "": SECONDS_PER_MINUTE,
4092
+ D: SECONDS_PER_DAY,
4093
+ W: SECONDS_PER_WEEK,
4094
+ M: SECONDS_PER_MONTH
4095
+ };
4096
+ var SECOND_TIMEFRAMES = [1, 5, 10, 15, 30];
4097
+ function in_seconds(timeframe) {
4098
+ const text = timeframe.trim();
4099
+ if (text === "") {
4100
+ throw new RangeError("timeframe.in_seconds() needs a timeframe: the chart timeframe is not known here");
4101
+ }
4102
+ const before = /^(\d*)([SDWMT]?)$/.exec(text);
4103
+ const after = before ? null : /^([SDWMT])(\d+)$/.exec(text);
4104
+ if (!before && !after) throw new RangeError(`Invalid timeframe "${timeframe}"`);
4105
+ const [digits, unit] = before ? [before[1], before[2]] : [after[2], after[1]];
4106
+ if (unit === "T") return NaN;
4107
+ const multiplier = digits === "" ? 1 : Number(digits);
4108
+ return multiplier * UNIT_SECONDS[unit];
4109
+ }
4110
+ function from_seconds(seconds) {
4111
+ if (Number.isNaN(seconds)) throw new RangeError("timeframe.from_seconds() needs a number of seconds");
4112
+ if (seconds >= SECONDS_365_DAYS) return "12M";
4113
+ if (seconds > 0) {
4114
+ if (seconds % SECONDS_PER_MONTH === 0) return `${seconds / SECONDS_PER_MONTH}M`;
4115
+ if (seconds % SECONDS_PER_WEEK === 0) return `${seconds / SECONDS_PER_WEEK}W`;
4116
+ if (seconds % SECONDS_PER_DAY === 0) return `${seconds / SECONDS_PER_DAY}D`;
4117
+ if (seconds % SECONDS_PER_MINUTE === 0 && seconds < SECONDS_PER_DAY) return `${seconds / SECONDS_PER_MINUTE}`;
4118
+ }
4119
+ const second2 = SECOND_TIMEFRAMES.find((m) => seconds <= m);
4120
+ if (second2 !== void 0) return `${second2}S`;
4121
+ if (seconds < SECONDS_PER_DAY) return `${Math.ceil(seconds / SECONDS_PER_MINUTE)}`;
4122
+ return `${Math.ceil(seconds / SECONDS_PER_DAY)}D`;
4123
+ }
4124
+ function info(timeframe) {
4125
+ const text = timeframe.trim();
4126
+ const m = /^(\d*)([SDWMT]?)$/.exec(text);
4127
+ if (!m || text === "") throw new RangeError(`Invalid timeframe "${timeframe}"`);
4128
+ const unit = m[2];
4129
+ const multiplier = m[1] === "" ? 1 : Number(m[1]);
4130
+ return {
4131
+ period: unit === "" ? String(multiplier) : `${multiplier}${unit}`,
4132
+ multiplier,
4133
+ isintraday: unit === "" || unit === "S" || unit === "T",
4134
+ isdaily: unit === "D",
4135
+ isweekly: unit === "W",
4136
+ ismonthly: unit === "M",
4137
+ isminutes: unit === "",
4138
+ isseconds: unit === "S",
4139
+ isticks: unit === "T",
4140
+ isdwm: unit === "D" || unit === "W" || unit === "M"
4141
+ };
3456
4142
  }
3457
4143
 
3458
4144
  // src/matrix/index.ts
@@ -3464,14 +4150,14 @@ __export(matrix_exports, {
3464
4150
  col: () => col,
3465
4151
  columns: () => columns,
3466
4152
  concat: () => concat3,
3467
- copy: () => copy2,
4153
+ copy: () => copy3,
3468
4154
  det: () => det,
3469
4155
  diff: () => diff,
3470
4156
  eigenvalues: () => eigenvalues,
3471
4157
  eigenvectors: () => eigenvectors,
3472
4158
  elements_count: () => elements_count,
3473
4159
  fill: () => fill2,
3474
- get: () => get2,
4160
+ get: () => get3,
3475
4161
  inv: () => inv,
3476
4162
  is_antidiagonal: () => is_antidiagonal,
3477
4163
  is_antisymmetric: () => is_antisymmetric,
@@ -3520,7 +4206,7 @@ function new_matrix(rows2, columns2, initial_value) {
3520
4206
  }
3521
4207
  return { rows: rows2, columns: columns2, data };
3522
4208
  }
3523
- function get2(id, row2, column) {
4209
+ function get3(id, row2, column) {
3524
4210
  if (row2 < 0 || row2 >= id.rows || column < 0 || column >= id.columns) {
3525
4211
  throw new Error(`Matrix index out of bounds: [${row2}, ${column}] for matrix of size [${id.rows}, ${id.columns}]`);
3526
4212
  }
@@ -3553,7 +4239,7 @@ function col(id, column_index) {
3553
4239
  }
3554
4240
  return id.data.map((r2) => r2[column_index]);
3555
4241
  }
3556
- function copy2(id) {
4242
+ function copy3(id) {
3557
4243
  const newData = id.data.map((r2) => [...r2]);
3558
4244
  return {
3559
4245
  rows: id.rows,
@@ -3905,24 +4591,24 @@ function median3(id) {
3905
4591
  if (id.rows === 0 || id.columns === 0) {
3906
4592
  return NaN;
3907
4593
  }
3908
- const values = [];
4594
+ const values2 = [];
3909
4595
  for (let i = 0; i < id.rows; i++) {
3910
4596
  for (let j = 0; j < id.columns; j++) {
3911
4597
  const val = id.data[i][j];
3912
4598
  if (val !== null && val !== void 0 && !isNaN(val)) {
3913
- values.push(val);
4599
+ values2.push(val);
3914
4600
  }
3915
4601
  }
3916
4602
  }
3917
- if (values.length === 0) {
4603
+ if (values2.length === 0) {
3918
4604
  return NaN;
3919
4605
  }
3920
- values.sort((a, b2) => a - b2);
3921
- const mid = Math.floor(values.length / 2);
3922
- if (values.length % 2 === 0) {
3923
- return (values[mid - 1] + values[mid]) / 2;
4606
+ values2.sort((a, b2) => a - b2);
4607
+ const mid = Math.floor(values2.length / 2);
4608
+ if (values2.length % 2 === 0) {
4609
+ return (values2[mid - 1] + values2[mid]) / 2;
3924
4610
  } else {
3925
- return values[mid];
4611
+ return values2[mid];
3926
4612
  }
3927
4613
  }
3928
4614
  function mode3(id) {
@@ -4168,7 +4854,7 @@ function pow2(id, power) {
4168
4854
  base = inverse;
4169
4855
  p = -power;
4170
4856
  } else {
4171
- base = copy2(id);
4857
+ base = copy3(id);
4172
4858
  }
4173
4859
  let result = createIdentity(n);
4174
4860
  while (p > 0) {
@@ -4197,31 +4883,31 @@ function det(id) {
4197
4883
  const a = id.data.map((row2) => [...row2]);
4198
4884
  let determinant = 1;
4199
4885
  let swapCount = 0;
4200
- for (let col2 = 0; col2 < n; col2++) {
4201
- let maxRow = col2;
4202
- let maxVal = Math.abs(a[col2][col2]);
4203
- for (let row2 = col2 + 1; row2 < n; row2++) {
4204
- const absVal = Math.abs(a[row2][col2]);
4886
+ for (let col3 = 0; col3 < n; col3++) {
4887
+ let maxRow = col3;
4888
+ let maxVal = Math.abs(a[col3][col3]);
4889
+ for (let row2 = col3 + 1; row2 < n; row2++) {
4890
+ const absVal = Math.abs(a[row2][col3]);
4205
4891
  if (absVal > maxVal) {
4206
4892
  maxVal = absVal;
4207
4893
  maxRow = row2;
4208
4894
  }
4209
4895
  }
4210
- if (maxRow !== col2) {
4211
- const temp = a[col2];
4212
- a[col2] = a[maxRow];
4896
+ if (maxRow !== col3) {
4897
+ const temp = a[col3];
4898
+ a[col3] = a[maxRow];
4213
4899
  a[maxRow] = temp;
4214
4900
  swapCount++;
4215
4901
  }
4216
- const pivot = a[col2][col2];
4217
- if (Math.abs(pivot) < EPSILON) {
4902
+ const pivot2 = a[col3][col3];
4903
+ if (Math.abs(pivot2) < EPSILON) {
4218
4904
  return 0;
4219
4905
  }
4220
- determinant *= pivot;
4221
- for (let row2 = col2 + 1; row2 < n; row2++) {
4222
- const factor = a[row2][col2] / pivot;
4223
- for (let j = col2; j < n; j++) {
4224
- a[row2][j] = a[row2][j] - factor * a[col2][j];
4906
+ determinant *= pivot2;
4907
+ for (let row2 = col3 + 1; row2 < n; row2++) {
4908
+ const factor = a[row2][col3] / pivot2;
4909
+ for (let j = col3; j < n; j++) {
4910
+ a[row2][j] = a[row2][j] - factor * a[col3][j];
4225
4911
  }
4226
4912
  }
4227
4913
  }
@@ -4249,33 +4935,33 @@ function inv(id) {
4249
4935
  }
4250
4936
  aug.push(row2);
4251
4937
  }
4252
- for (let col2 = 0; col2 < n; col2++) {
4253
- let maxRow = col2;
4254
- let maxVal = Math.abs(aug[col2][col2]);
4255
- for (let row2 = col2 + 1; row2 < n; row2++) {
4256
- const absVal = Math.abs(aug[row2][col2]);
4938
+ for (let col3 = 0; col3 < n; col3++) {
4939
+ let maxRow = col3;
4940
+ let maxVal = Math.abs(aug[col3][col3]);
4941
+ for (let row2 = col3 + 1; row2 < n; row2++) {
4942
+ const absVal = Math.abs(aug[row2][col3]);
4257
4943
  if (absVal > maxVal) {
4258
4944
  maxVal = absVal;
4259
4945
  maxRow = row2;
4260
4946
  }
4261
4947
  }
4262
- if (maxRow !== col2) {
4263
- const temp = aug[col2];
4264
- aug[col2] = aug[maxRow];
4948
+ if (maxRow !== col3) {
4949
+ const temp = aug[col3];
4950
+ aug[col3] = aug[maxRow];
4265
4951
  aug[maxRow] = temp;
4266
4952
  }
4267
- const pivot = aug[col2][col2];
4268
- if (Math.abs(pivot) < EPSILON) {
4953
+ const pivot2 = aug[col3][col3];
4954
+ if (Math.abs(pivot2) < EPSILON) {
4269
4955
  return null;
4270
4956
  }
4271
4957
  for (let j = 0; j < 2 * n; j++) {
4272
- aug[col2][j] = aug[col2][j] / pivot;
4958
+ aug[col3][j] = aug[col3][j] / pivot2;
4273
4959
  }
4274
4960
  for (let row2 = 0; row2 < n; row2++) {
4275
- if (row2 !== col2) {
4276
- const factor = aug[row2][col2];
4961
+ if (row2 !== col3) {
4962
+ const factor = aug[row2][col3];
4277
4963
  for (let j = 0; j < 2 * n; j++) {
4278
- aug[row2][j] = aug[row2][j] - factor * aug[col2][j];
4964
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4279
4965
  }
4280
4966
  }
4281
4967
  }
@@ -4338,11 +5024,11 @@ function rank(id) {
4338
5024
  const m = id.rows;
4339
5025
  const n = id.columns;
4340
5026
  let r2 = 0;
4341
- for (let col2 = 0; col2 < n && r2 < m; col2++) {
5027
+ for (let col3 = 0; col3 < n && r2 < m; col3++) {
4342
5028
  let maxRow = r2;
4343
- let maxVal = Math.abs(a[r2][col2]);
5029
+ let maxVal = Math.abs(a[r2][col3]);
4344
5030
  for (let row2 = r2 + 1; row2 < m; row2++) {
4345
- const absVal = Math.abs(a[row2][col2]);
5031
+ const absVal = Math.abs(a[row2][col3]);
4346
5032
  if (absVal > maxVal) {
4347
5033
  maxVal = absVal;
4348
5034
  maxRow = row2;
@@ -4356,10 +5042,10 @@ function rank(id) {
4356
5042
  a[r2] = a[maxRow];
4357
5043
  a[maxRow] = temp;
4358
5044
  }
4359
- const pivot = a[r2][col2];
5045
+ const pivot2 = a[r2][col3];
4360
5046
  for (let row2 = r2 + 1; row2 < m; row2++) {
4361
- const factor = a[row2][col2] / pivot;
4362
- for (let j = col2; j < n; j++) {
5047
+ const factor = a[row2][col3] / pivot2;
5048
+ for (let j = col3; j < n; j++) {
4363
5049
  a[row2][j] = a[row2][j] - factor * a[r2][j];
4364
5050
  }
4365
5051
  }
@@ -4567,29 +5253,29 @@ function inverseIteration(m, lambda) {
4567
5253
  function solveLinearSystem(a, b2) {
4568
5254
  const n = a.length;
4569
5255
  const aug = a.map((row2, i) => [...row2, b2[i]]);
4570
- for (let col2 = 0; col2 < n; col2++) {
4571
- let maxRow = col2;
4572
- let maxVal = Math.abs(aug[col2][col2]);
4573
- for (let row2 = col2 + 1; row2 < n; row2++) {
4574
- const absVal = Math.abs(aug[row2][col2]);
5256
+ for (let col3 = 0; col3 < n; col3++) {
5257
+ let maxRow = col3;
5258
+ let maxVal = Math.abs(aug[col3][col3]);
5259
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5260
+ const absVal = Math.abs(aug[row2][col3]);
4575
5261
  if (absVal > maxVal) {
4576
5262
  maxVal = absVal;
4577
5263
  maxRow = row2;
4578
5264
  }
4579
5265
  }
4580
- if (maxRow !== col2) {
4581
- const temp = aug[col2];
4582
- aug[col2] = aug[maxRow];
5266
+ if (maxRow !== col3) {
5267
+ const temp = aug[col3];
5268
+ aug[col3] = aug[maxRow];
4583
5269
  aug[maxRow] = temp;
4584
5270
  }
4585
- const pivot = aug[col2][col2];
4586
- if (Math.abs(pivot) < EPSILON) {
5271
+ const pivot2 = aug[col3][col3];
5272
+ if (Math.abs(pivot2) < EPSILON) {
4587
5273
  continue;
4588
5274
  }
4589
- for (let row2 = col2 + 1; row2 < n; row2++) {
4590
- const factor = aug[row2][col2] / pivot;
4591
- for (let j = col2; j <= n; j++) {
4592
- aug[row2][j] = aug[row2][j] - factor * aug[col2][j];
5275
+ for (let row2 = col3 + 1; row2 < n; row2++) {
5276
+ const factor = aug[row2][col3] / pivot2;
5277
+ for (let j = col3; j <= n; j++) {
5278
+ aug[row2][j] = aug[row2][j] - factor * aug[col3][j];
4593
5279
  }
4594
5280
  }
4595
5281
  }
@@ -4621,8 +5307,8 @@ function kron(id1, id2) {
4621
5307
  for (let i2 = 0; i2 < m2; i2++) {
4622
5308
  for (let j2 = 0; j2 < n2; j2++) {
4623
5309
  const row2 = i1 * m2 + i2;
4624
- const col2 = j1 * n2 + j2;
4625
- data[row2][col2] = a * id2.data[i2][j2];
5310
+ const col3 = j1 * n2 + j2;
5311
+ data[row2][col3] = a * id2.data[i2][j2];
4626
5312
  }
4627
5313
  }
4628
5314
  }
@@ -4640,7 +5326,9 @@ function newtype2(rows2 = 0, columns2 = 0, initial_value) {
4640
5326
  // src/line/index.ts
4641
5327
  var line_exports = {};
4642
5328
  __export(line_exports, {
4643
- copy: () => copy3,
5329
+ all: () => all2,
5330
+ copy: () => copy4,
5331
+ delete: () => delete_line,
4644
5332
  delete_line: () => delete_line,
4645
5333
  get_price: () => get_price,
4646
5334
  get_x1: () => get_x1,
@@ -4651,6 +5339,8 @@ __export(line_exports, {
4651
5339
  new_line: () => new_line2,
4652
5340
  set_color: () => set_color,
4653
5341
  set_extend: () => set_extend,
5342
+ set_first_point: () => set_first_point,
5343
+ set_second_point: () => set_second_point,
4654
5344
  set_style: () => set_style,
4655
5345
  set_width: () => set_width,
4656
5346
  set_x1: () => set_x1,
@@ -4661,18 +5351,78 @@ __export(line_exports, {
4661
5351
  set_y1: () => set_y1,
4662
5352
  set_y2: () => set_y2
4663
5353
  });
4664
- function new_line2(x1, y1, x2, y2, xloc2 = "bar_index", extend = "none", lineColor, style, width) {
4665
- return {
5354
+
5355
+ // src/drawing/registry.ts
5356
+ var DEFAULT_MAX_COUNT = 50;
5357
+ var SLACK = 5;
5358
+ var live = { line: [], label: [], box: [], polyline: [], linefill: [] };
5359
+ var limits = {
5360
+ line: DEFAULT_MAX_COUNT,
5361
+ label: DEFAULT_MAX_COUNT,
5362
+ box: DEFAULT_MAX_COUNT,
5363
+ polyline: DEFAULT_MAX_COUNT
5364
+ };
5365
+ var deleted = /* @__PURE__ */ new WeakSet();
5366
+ var COORDINATES = {
5367
+ line: ["x1", "y1", "x2", "y2"],
5368
+ label: ["x", "y"],
5369
+ box: ["left", "top", "right", "bottom"],
5370
+ polyline: [],
5371
+ linefill: []
5372
+ };
5373
+ function markDeleted(kind, obj, explicit) {
5374
+ deleted.add(obj);
5375
+ for (const field2 of COORDINATES[kind]) obj[field2] = NaN;
5376
+ if (kind === "line" && explicit) {
5377
+ for (const fill3 of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove3("linefill", fill3);
5378
+ }
5379
+ }
5380
+ function register(kind, obj) {
5381
+ const list = live[kind];
5382
+ list.push(obj);
5383
+ const max6 = limits[kind === "linefill" ? "line" : kind];
5384
+ if (list.length > max6 + SLACK) {
5385
+ for (const old of list.splice(0, list.length - max6)) markDeleted(kind, old, false);
5386
+ }
5387
+ return obj;
5388
+ }
5389
+ function remove3(kind, obj) {
5390
+ const list = live[kind];
5391
+ const index = list.indexOf(obj);
5392
+ if (index !== -1) list.splice(index, 1);
5393
+ if (!deleted.has(obj)) markDeleted(kind, obj, true);
5394
+ }
5395
+ function isDeleted(obj) {
5396
+ return typeof obj === "object" && obj !== null && deleted.has(obj);
5397
+ }
5398
+ function all(kind) {
5399
+ return [...live[kind]];
5400
+ }
5401
+
5402
+ // src/line/index.ts
5403
+ function new_line2(...args) {
5404
+ let x1, y1, x2, y2, rest;
5405
+ if (typeof args[0] === "object" && args[0] !== null) {
5406
+ const [p1, p2, ...others] = args;
5407
+ const xloc3 = others[0] ?? "bar_index";
5408
+ [x1, y1, x2, y2, rest] = [pointX(p1, xloc3), p1.price, pointX(p2, xloc3), p2.price, others];
5409
+ } else {
5410
+ [x1, y1, x2, y2] = args;
5411
+ rest = args.slice(4);
5412
+ }
5413
+ const [xloc2, extend, lineColor, style, width, force_overlay] = rest;
5414
+ return register("line", {
4666
5415
  x1,
4667
5416
  y1,
4668
5417
  x2,
4669
5418
  y2,
4670
- xloc: xloc2,
4671
- extend,
5419
+ xloc: xloc2 ?? "bar_index",
5420
+ extend: extend ?? "none",
4672
5421
  color: lineColor,
4673
5422
  style: style || "solid",
4674
- width: width || 1
4675
- };
5423
+ width: width || 1,
5424
+ force_overlay: force_overlay ?? false
5425
+ });
4676
5426
  }
4677
5427
  function get_price(id, x) {
4678
5428
  const { x1, y1, x2, y2, extend, xloc: xloc2 } = id;
@@ -4711,64 +5461,97 @@ function get_y1(id) {
4711
5461
  function get_y2(id) {
4712
5462
  return id.y2;
4713
5463
  }
4714
- function copy3(id) {
4715
- return { ...id };
5464
+ function copy4(id) {
5465
+ return register("line", { ...id });
4716
5466
  }
4717
5467
  function set_x1(id, x) {
5468
+ if (isDeleted(id)) return id;
4718
5469
  id.x1 = x;
4719
5470
  return id;
4720
5471
  }
4721
5472
  function set_x2(id, x) {
5473
+ if (isDeleted(id)) return id;
4722
5474
  id.x2 = x;
4723
5475
  return id;
4724
5476
  }
4725
5477
  function set_y1(id, y) {
5478
+ if (isDeleted(id)) return id;
4726
5479
  id.y1 = y;
4727
5480
  return id;
4728
5481
  }
4729
5482
  function set_y2(id, y) {
5483
+ if (isDeleted(id)) return id;
4730
5484
  id.y2 = y;
4731
5485
  return id;
4732
5486
  }
4733
5487
  function set_xy1(id, x, y) {
5488
+ if (isDeleted(id)) return id;
4734
5489
  id.x1 = x;
4735
5490
  id.y1 = y;
4736
5491
  return id;
4737
5492
  }
4738
5493
  function set_xy2(id, x, y) {
5494
+ if (isDeleted(id)) return id;
4739
5495
  id.x2 = x;
4740
5496
  id.y2 = y;
4741
5497
  return id;
4742
5498
  }
4743
5499
  function set_xloc(id, x1, x2, xloc2) {
5500
+ if (isDeleted(id)) return id;
4744
5501
  id.x1 = x1;
4745
5502
  id.x2 = x2;
4746
5503
  id.xloc = xloc2;
4747
5504
  return id;
4748
5505
  }
4749
5506
  function set_extend(id, extend) {
5507
+ if (isDeleted(id)) return id;
4750
5508
  id.extend = extend;
4751
5509
  return id;
4752
5510
  }
4753
5511
  function set_color(id, lineColor) {
5512
+ if (isDeleted(id)) return id;
4754
5513
  id.color = lineColor;
4755
5514
  return id;
4756
5515
  }
4757
5516
  function set_style(id, style) {
5517
+ if (isDeleted(id)) return id;
4758
5518
  id.style = style;
4759
5519
  return id;
4760
5520
  }
4761
5521
  function set_width(id, width) {
5522
+ if (isDeleted(id)) return id;
4762
5523
  id.width = width;
4763
5524
  return id;
4764
5525
  }
4765
- function delete_line(_id) {
5526
+ function delete_line(id) {
5527
+ remove3("line", id);
5528
+ }
5529
+ function pointX(point, xloc2) {
5530
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5531
+ return x ?? NaN;
5532
+ }
5533
+ function all2() {
5534
+ return all("line");
5535
+ }
5536
+ function set_first_point(id, point) {
5537
+ if (isDeleted(id)) return id;
5538
+ id.x1 = pointX(point, id.xloc);
5539
+ id.y1 = point.price;
5540
+ return id;
5541
+ }
5542
+ function set_second_point(id, point) {
5543
+ if (isDeleted(id)) return id;
5544
+ id.x2 = pointX(point, id.xloc);
5545
+ id.y2 = point.price;
5546
+ return id;
4766
5547
  }
4767
5548
 
4768
5549
  // src/box/index.ts
4769
5550
  var box_exports = {};
4770
5551
  __export(box_exports, {
4771
- copy: () => copy4,
5552
+ all: () => all3,
5553
+ copy: () => copy5,
5554
+ delete: () => delete_box,
4772
5555
  delete_box: () => delete_box,
4773
5556
  get_bottom: () => get_bottom,
4774
5557
  get_left: () => get_left,
@@ -4781,6 +5564,7 @@ __export(box_exports, {
4781
5564
  set_border_style: () => set_border_style,
4782
5565
  set_border_width: () => set_border_width,
4783
5566
  set_bottom: () => set_bottom,
5567
+ set_bottom_right_point: () => set_bottom_right_point,
4784
5568
  set_extend: () => set_extend2,
4785
5569
  set_left: () => set_left,
4786
5570
  set_lefttop: () => set_lefttop,
@@ -4789,21 +5573,49 @@ __export(box_exports, {
4789
5573
  set_text: () => set_text,
4790
5574
  set_text_color: () => set_text_color,
4791
5575
  set_text_font_family: () => set_text_font_family,
5576
+ set_text_formatting: () => set_text_formatting,
4792
5577
  set_text_halign: () => set_text_halign,
4793
5578
  set_text_size: () => set_text_size,
4794
5579
  set_text_valign: () => set_text_valign,
4795
5580
  set_text_wrap: () => set_text_wrap,
4796
5581
  set_top: () => set_top,
5582
+ set_top_left_point: () => set_top_left_point,
4797
5583
  set_xloc: () => set_xloc2
4798
5584
  });
4799
- 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) {
4800
- return {
5585
+ function new_box2(...args) {
5586
+ let left, top, right, bottom, rest;
5587
+ if (typeof args[0] === "object" && args[0] !== null) {
5588
+ const [tl, br, ...others] = args;
5589
+ const xloc3 = others[4] ?? "bar_index";
5590
+ [left, top, right, bottom, rest] = [pointX2(tl, xloc3), tl.price, pointX2(br, xloc3), br.price, others];
5591
+ } else {
5592
+ [left, top, right, bottom] = args;
5593
+ rest = args.slice(4);
5594
+ }
5595
+ const [
5596
+ border_color,
5597
+ border_width,
5598
+ border_style,
5599
+ extend,
5600
+ xloc2,
5601
+ bgcolor,
5602
+ text,
5603
+ text_size,
5604
+ text_color,
5605
+ text_halign,
5606
+ text_valign,
5607
+ text_wrap,
5608
+ text_font_family,
5609
+ force_overlay,
5610
+ text_formatting
5611
+ ] = rest;
5612
+ return register("box", {
4801
5613
  left,
4802
5614
  top,
4803
5615
  right,
4804
5616
  bottom,
4805
- xloc: xloc2,
4806
- extend,
5617
+ xloc: xloc2 ?? "bar_index",
5618
+ extend: extend ?? "none",
4807
5619
  border_color,
4808
5620
  border_width: border_width || 1,
4809
5621
  border_style: border_style || "solid",
@@ -4814,8 +5626,10 @@ function new_box2(left, top, right, bottom, xloc2 = "bar_index", extend = "none"
4814
5626
  text_halign,
4815
5627
  text_valign,
4816
5628
  text_wrap,
4817
- text_font_family
4818
- };
5629
+ text_font_family,
5630
+ force_overlay: force_overlay ?? false,
5631
+ text_formatting
5632
+ });
4819
5633
  }
4820
5634
  function get_left(id) {
4821
5635
  return id.left;
@@ -4829,96 +5643,142 @@ function get_top(id) {
4829
5643
  function get_bottom(id) {
4830
5644
  return id.bottom;
4831
5645
  }
4832
- function copy4(id) {
4833
- return { ...id };
5646
+ function copy5(id) {
5647
+ return register("box", { ...id });
4834
5648
  }
4835
5649
  function set_left(id, left) {
5650
+ if (isDeleted(id)) return id;
4836
5651
  id.left = left;
4837
5652
  return id;
4838
5653
  }
4839
5654
  function set_right(id, right) {
5655
+ if (isDeleted(id)) return id;
4840
5656
  id.right = right;
4841
5657
  return id;
4842
5658
  }
4843
5659
  function set_top(id, top) {
5660
+ if (isDeleted(id)) return id;
4844
5661
  id.top = top;
4845
5662
  return id;
4846
5663
  }
4847
5664
  function set_bottom(id, bottom) {
5665
+ if (isDeleted(id)) return id;
4848
5666
  id.bottom = bottom;
4849
5667
  return id;
4850
5668
  }
4851
5669
  function set_lefttop(id, left, top) {
5670
+ if (isDeleted(id)) return id;
4852
5671
  id.left = left;
4853
5672
  id.top = top;
4854
5673
  return id;
4855
5674
  }
4856
5675
  function set_rightbottom(id, right, bottom) {
5676
+ if (isDeleted(id)) return id;
4857
5677
  id.right = right;
4858
5678
  id.bottom = bottom;
4859
5679
  return id;
4860
5680
  }
4861
5681
  function set_xloc2(id, left, right, xloc2) {
5682
+ if (isDeleted(id)) return id;
4862
5683
  id.left = left;
4863
5684
  id.right = right;
4864
5685
  id.xloc = xloc2;
4865
5686
  return id;
4866
5687
  }
4867
5688
  function set_extend2(id, extend) {
5689
+ if (isDeleted(id)) return id;
4868
5690
  id.extend = extend;
4869
5691
  return id;
4870
5692
  }
4871
5693
  function set_border_color(id, borderColor) {
5694
+ if (isDeleted(id)) return id;
4872
5695
  id.border_color = borderColor;
4873
5696
  return id;
4874
5697
  }
4875
5698
  function set_border_width(id, width) {
5699
+ if (isDeleted(id)) return id;
4876
5700
  id.border_width = width;
4877
5701
  return id;
4878
5702
  }
4879
5703
  function set_border_style(id, style) {
5704
+ if (isDeleted(id)) return id;
4880
5705
  id.border_style = style;
4881
5706
  return id;
4882
5707
  }
4883
5708
  function set_bgcolor(id, bgColor) {
5709
+ if (isDeleted(id)) return id;
4884
5710
  id.bgcolor = bgColor;
4885
5711
  return id;
4886
5712
  }
4887
5713
  function set_text(id, text) {
5714
+ if (isDeleted(id)) return id;
4888
5715
  id.text = text;
4889
5716
  return id;
4890
5717
  }
4891
5718
  function set_text_color(id, textColor) {
5719
+ if (isDeleted(id)) return id;
4892
5720
  id.text_color = textColor;
4893
5721
  return id;
4894
5722
  }
4895
- function set_text_size(id, size2) {
4896
- id.text_size = size2;
5723
+ function set_text_size(id, size3) {
5724
+ if (isDeleted(id)) return id;
5725
+ id.text_size = size3;
4897
5726
  return id;
4898
5727
  }
4899
5728
  function set_text_halign(id, align) {
5729
+ if (isDeleted(id)) return id;
4900
5730
  id.text_halign = align;
4901
5731
  return id;
4902
5732
  }
4903
5733
  function set_text_valign(id, align) {
5734
+ if (isDeleted(id)) return id;
4904
5735
  id.text_valign = align;
4905
5736
  return id;
4906
5737
  }
4907
5738
  function set_text_wrap(id, wrap) {
5739
+ if (isDeleted(id)) return id;
4908
5740
  id.text_wrap = wrap;
4909
5741
  return id;
4910
5742
  }
4911
5743
  function set_text_font_family(id, font) {
5744
+ if (isDeleted(id)) return id;
4912
5745
  id.text_font_family = font;
4913
5746
  return id;
4914
5747
  }
4915
- function delete_box(_id) {
5748
+ function delete_box(id) {
5749
+ remove3("box", id);
5750
+ }
5751
+ function pointX2(point, xloc2) {
5752
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5753
+ return x ?? NaN;
5754
+ }
5755
+ function all3() {
5756
+ return all("box");
5757
+ }
5758
+ function set_top_left_point(id, point) {
5759
+ if (isDeleted(id)) return id;
5760
+ id.left = pointX2(point, id.xloc);
5761
+ id.top = point.price;
5762
+ return id;
5763
+ }
5764
+ function set_bottom_right_point(id, point) {
5765
+ if (isDeleted(id)) return id;
5766
+ id.right = pointX2(point, id.xloc);
5767
+ id.bottom = point.price;
5768
+ return id;
5769
+ }
5770
+ function set_text_formatting(id, formatting) {
5771
+ if (isDeleted(id)) return id;
5772
+ id.text_formatting = formatting;
5773
+ return id;
4916
5774
  }
4917
5775
 
4918
5776
  // src/label/index.ts
4919
5777
  var label_exports = {};
4920
5778
  __export(label_exports, {
4921
- copy: () => copy5,
5779
+ all: () => all4,
5780
+ copy: () => copy6,
5781
+ delete: () => delete_label,
4922
5782
  delete_label: () => delete_label,
4923
5783
  get_text: () => get_text,
4924
5784
  get_x: () => get_x,
@@ -4926,10 +5786,12 @@ __export(label_exports, {
4926
5786
  new: () => new_label2,
4927
5787
  new_label: () => new_label2,
4928
5788
  set_color: () => set_color2,
5789
+ set_point: () => set_point,
4929
5790
  set_size: () => set_size,
4930
5791
  set_style: () => set_style2,
4931
5792
  set_text: () => set_text2,
4932
5793
  set_text_font_family: () => set_text_font_family2,
5794
+ set_text_formatting: () => set_text_formatting2,
4933
5795
  set_textalign: () => set_textalign,
4934
5796
  set_textcolor: () => set_textcolor,
4935
5797
  set_tooltip: () => set_tooltip,
@@ -4939,21 +5801,47 @@ __export(label_exports, {
4939
5801
  set_y: () => set_y,
4940
5802
  set_yloc: () => set_yloc
4941
5803
  });
4942
- function new_label2(x, y, text, xloc2 = "bar_index", yloc = "price", labelColor, style, textcolor, size2, textalign, tooltip, text_font_family) {
4943
- return {
5804
+ function new_label2(...args) {
5805
+ let x, y, rest;
5806
+ if (typeof args[0] === "object" && args[0] !== null) {
5807
+ const point = args[0];
5808
+ rest = args.slice(1);
5809
+ x = pointX3(point, rest[1] ?? "bar_index");
5810
+ y = point.price;
5811
+ } else {
5812
+ [x, y] = args;
5813
+ rest = args.slice(2);
5814
+ }
5815
+ const [
5816
+ text,
5817
+ xloc2,
5818
+ yloc,
5819
+ labelColor,
5820
+ style,
5821
+ textcolor,
5822
+ size3,
5823
+ textalign,
5824
+ tooltip,
5825
+ text_font_family,
5826
+ force_overlay,
5827
+ text_formatting
5828
+ ] = rest;
5829
+ return register("label", {
4944
5830
  x,
4945
5831
  y,
4946
- xloc: xloc2,
4947
- yloc,
5832
+ xloc: xloc2 ?? "bar_index",
5833
+ yloc: yloc ?? "price",
4948
5834
  text,
4949
5835
  tooltip,
4950
5836
  color: labelColor,
4951
5837
  style,
4952
5838
  textcolor,
4953
- size: size2,
5839
+ size: size3,
4954
5840
  textalign,
4955
- text_font_family
4956
- };
5841
+ text_font_family,
5842
+ force_overlay: force_overlay ?? false,
5843
+ text_formatting
5844
+ });
4957
5845
  }
4958
5846
  function get_x(id) {
4959
5847
  return id.x;
@@ -4964,70 +5852,103 @@ function get_y(id) {
4964
5852
  function get_text(id) {
4965
5853
  return id.text;
4966
5854
  }
4967
- function copy5(id) {
4968
- return { ...id };
5855
+ function copy6(id) {
5856
+ return register("label", { ...id });
4969
5857
  }
4970
5858
  function set_x(id, x) {
5859
+ if (isDeleted(id)) return id;
4971
5860
  id.x = x;
4972
5861
  return id;
4973
5862
  }
4974
5863
  function set_y(id, y) {
5864
+ if (isDeleted(id)) return id;
4975
5865
  id.y = y;
4976
5866
  return id;
4977
5867
  }
4978
5868
  function set_xy(id, x, y) {
5869
+ if (isDeleted(id)) return id;
4979
5870
  id.x = x;
4980
5871
  id.y = y;
4981
5872
  return id;
4982
5873
  }
4983
5874
  function set_xloc3(id, x, xloc2) {
5875
+ if (isDeleted(id)) return id;
4984
5876
  id.x = x;
4985
5877
  id.xloc = xloc2;
4986
5878
  return id;
4987
5879
  }
4988
- function set_yloc(id, y, yloc) {
4989
- id.y = y;
5880
+ function set_yloc(id, yloc) {
5881
+ if (isDeleted(id)) return id;
4990
5882
  id.yloc = yloc;
4991
5883
  return id;
4992
5884
  }
4993
5885
  function set_text2(id, text) {
5886
+ if (isDeleted(id)) return id;
4994
5887
  id.text = text;
4995
5888
  return id;
4996
5889
  }
4997
5890
  function set_tooltip(id, tooltip) {
5891
+ if (isDeleted(id)) return id;
4998
5892
  id.tooltip = tooltip;
4999
5893
  return id;
5000
5894
  }
5001
5895
  function set_color2(id, labelColor) {
5896
+ if (isDeleted(id)) return id;
5002
5897
  id.color = labelColor;
5003
5898
  return id;
5004
5899
  }
5005
5900
  function set_textcolor(id, textColor) {
5901
+ if (isDeleted(id)) return id;
5006
5902
  id.textcolor = textColor;
5007
5903
  return id;
5008
5904
  }
5009
5905
  function set_style2(id, style) {
5906
+ if (isDeleted(id)) return id;
5010
5907
  id.style = style;
5011
5908
  return id;
5012
5909
  }
5013
- function set_size(id, size2) {
5014
- id.size = size2;
5910
+ function set_size(id, size3) {
5911
+ if (isDeleted(id)) return id;
5912
+ id.size = size3;
5015
5913
  return id;
5016
5914
  }
5017
5915
  function set_textalign(id, align) {
5916
+ if (isDeleted(id)) return id;
5018
5917
  id.textalign = align;
5019
5918
  return id;
5020
5919
  }
5021
5920
  function set_text_font_family2(id, font) {
5921
+ if (isDeleted(id)) return id;
5022
5922
  id.text_font_family = font;
5023
5923
  return id;
5024
5924
  }
5025
- function delete_label(_id) {
5925
+ function delete_label(id) {
5926
+ remove3("label", id);
5927
+ }
5928
+ function pointX3(point, xloc2) {
5929
+ const x = xloc2 === "bar_time" ? point.time : point.index;
5930
+ return x ?? NaN;
5931
+ }
5932
+ function all4() {
5933
+ return all("label");
5934
+ }
5935
+ function set_point(id, point) {
5936
+ if (isDeleted(id)) return id;
5937
+ id.x = pointX3(point, id.xloc);
5938
+ id.y = point.price;
5939
+ return id;
5940
+ }
5941
+ function set_text_formatting2(id, formatting) {
5942
+ if (isDeleted(id)) return id;
5943
+ id.text_formatting = formatting;
5944
+ return id;
5026
5945
  }
5027
5946
 
5028
5947
  // src/linefill/index.ts
5029
5948
  var linefill_exports = {};
5030
5949
  __export(linefill_exports, {
5950
+ all: () => all5,
5951
+ delete: () => delete_linefill,
5031
5952
  delete_linefill: () => delete_linefill,
5032
5953
  get_line1: () => get_line1,
5033
5954
  get_line2: () => get_line2,
@@ -5036,11 +5957,11 @@ __export(linefill_exports, {
5036
5957
  set_color: () => set_color3
5037
5958
  });
5038
5959
  function new_linefill2(line1, line2, fillColor) {
5039
- return {
5960
+ return register("linefill", {
5040
5961
  line1,
5041
5962
  line2,
5042
5963
  color: fillColor
5043
- };
5964
+ });
5044
5965
  }
5045
5966
  function get_line1(id) {
5046
5967
  return id.line1;
@@ -5049,16 +5970,21 @@ function get_line2(id) {
5049
5970
  return id.line2;
5050
5971
  }
5051
5972
  function set_color3(id, fillColor) {
5973
+ if (isDeleted(id)) return id;
5052
5974
  id.color = fillColor;
5053
5975
  return id;
5054
5976
  }
5055
- function delete_linefill(_id) {
5977
+ function delete_linefill(id) {
5978
+ remove3("linefill", id);
5979
+ }
5980
+ function all5() {
5981
+ return all("linefill");
5056
5982
  }
5057
5983
 
5058
5984
  // src/chartpoint/index.ts
5059
5985
  var chartpoint_exports = {};
5060
5986
  __export(chartpoint_exports, {
5061
- copy: () => copy6,
5987
+ copy: () => copy7,
5062
5988
  from_index: () => from_index,
5063
5989
  from_time: () => from_time,
5064
5990
  new: () => new_point,
@@ -5085,7 +6011,7 @@ function from_index(index, price) {
5085
6011
  price
5086
6012
  };
5087
6013
  }
5088
- function copy6(point) {
6014
+ function copy7(point) {
5089
6015
  return {
5090
6016
  time: point.time,
5091
6017
  index: point.index,
@@ -5096,6 +6022,7 @@ function copy6(point) {
5096
6022
  // src/polyline/index.ts
5097
6023
  var polyline_exports = {};
5098
6024
  __export(polyline_exports, {
6025
+ all: () => all6,
5099
6026
  clear_all: () => clear_all,
5100
6027
  delete: () => delete_polyline,
5101
6028
  delete_polyline: () => delete_polyline,
@@ -5105,7 +6032,6 @@ __export(polyline_exports, {
5105
6032
  reset_id_counter: () => reset_id_counter
5106
6033
  });
5107
6034
  var polylineIdCounter = 0;
5108
- var allPolylines = [];
5109
6035
  function generateId() {
5110
6036
  return `polyline_${++polylineIdCounter}`;
5111
6037
  }
@@ -5132,28 +6058,39 @@ function new_polyline(points, curved = false, closed = false, xloc2 = "bar_index
5132
6058
  line_width,
5133
6059
  force_overlay
5134
6060
  };
5135
- allPolylines.push(polyline);
5136
- return polyline;
6061
+ return register("polyline", polyline);
5137
6062
  }
5138
6063
  function delete_polyline(id) {
5139
- const index = allPolylines.findIndex((p) => p.id === id.id);
5140
- if (index !== -1) {
5141
- allPolylines.splice(index, 1);
5142
- }
6064
+ remove3("polyline", id);
5143
6065
  }
5144
6066
  function get_all() {
5145
- return [...allPolylines];
6067
+ return all("polyline");
6068
+ }
6069
+ function all6() {
6070
+ return all("polyline");
5146
6071
  }
5147
6072
  function clear_all() {
5148
- allPolylines.length = 0;
6073
+ for (const p of all("polyline")) remove3("polyline", p);
5149
6074
  }
5150
6075
  function reset_id_counter() {
5151
6076
  polylineIdCounter = 0;
5152
6077
  }
5153
6078
 
6079
+ // src/text/index.ts
6080
+ var text_exports = {};
6081
+ __export(text_exports, {
6082
+ format_bold: () => format_bold,
6083
+ format_italic: () => format_italic,
6084
+ format_none: () => format_none
6085
+ });
6086
+ var format_none = 0;
6087
+ var format_bold = 1;
6088
+ var format_italic = 2;
6089
+
5154
6090
  // src/ta-series.ts
5155
6091
  var ta_series_exports = {};
5156
6092
  __export(ta_series_exports, {
6093
+ accdist: () => accdist2,
5157
6094
  alma: () => alma2,
5158
6095
  atr: () => atr2,
5159
6096
  barssince: () => barssince2,
@@ -5176,6 +6113,7 @@ __export(ta_series_exports, {
5176
6113
  highestbars: () => highestbars2,
5177
6114
  hma: () => hma2,
5178
6115
  ichimoku: () => ichimoku2,
6116
+ iii: () => iii2,
5179
6117
  kc: () => kc2,
5180
6118
  kcw: () => kcw2,
5181
6119
  linreg: () => linreg2,
@@ -5188,11 +6126,15 @@ __export(ta_series_exports, {
5188
6126
  min: () => min5,
5189
6127
  mode: () => mode4,
5190
6128
  mom: () => mom2,
6129
+ nvi: () => nvi2,
6130
+ obv: () => obv2,
5191
6131
  percentile_linear_interpolation: () => percentile_linear_interpolation3,
5192
6132
  percentile_nearest_rank: () => percentile_nearest_rank3,
5193
6133
  percentrank: () => percentrank3,
5194
6134
  pivothigh: () => pivothigh2,
5195
6135
  pivotlow: () => pivotlow2,
6136
+ pvi: () => pvi2,
6137
+ pvt: () => pvt2,
5196
6138
  range: () => range3,
5197
6139
  rci: () => rci2,
5198
6140
  rising: () => rising2,
@@ -5211,9 +6153,12 @@ __export(ta_series_exports, {
5211
6153
  valuewhen: () => valuewhen2,
5212
6154
  variance: () => variance3,
5213
6155
  vwap: () => vwap2,
6156
+ vwapBands: () => vwapBands,
5214
6157
  vwma: () => vwma2,
6158
+ wad: () => wad2,
5215
6159
  wma: () => wma2,
5216
6160
  wpr: () => wpr2,
6161
+ wvad: () => wvad2,
5217
6162
  zigzag: () => zigzag2
5218
6163
  });
5219
6164
  function sma2(source, length2) {
@@ -5264,11 +6209,9 @@ function bb2(source, length2, mult2) {
5264
6209
  const lowerSeries = Series.fromArray(bars, lowerVals);
5265
6210
  return [upperSeries, basisSeries, lowerSeries];
5266
6211
  }
5267
- function stdev3(source, length2) {
6212
+ function stdev3(source, length2, biased = true) {
5268
6213
  const bars = source.bars;
5269
- const sourceValues = source.toArray();
5270
- const result = stdev(sourceValues, length2);
5271
- return Series.fromArray(bars, result);
6214
+ return Series.fromArray(bars, stdev(source.toArray(), length2, biased));
5272
6215
  }
5273
6216
  function atr2(bars, length2) {
5274
6217
  const high = bars.map((b2) => b2.high);
@@ -5284,6 +6227,40 @@ function tr2(bars, handle_na = false) {
5284
6227
  const result = tr(handle_na, high, low, close);
5285
6228
  return Series.fromArray(bars, result);
5286
6229
  }
6230
+ var col2 = (bars, f) => bars.map((b2) => b2[f] ?? NaN);
6231
+ function obv2(bars) {
6232
+ return Series.fromArray(bars, obv(col2(bars, "close"), col2(bars, "volume")));
6233
+ }
6234
+ function pvt2(bars) {
6235
+ return Series.fromArray(bars, pvt(col2(bars, "close"), col2(bars, "volume")));
6236
+ }
6237
+ function accdist2(bars) {
6238
+ return Series.fromArray(
6239
+ bars,
6240
+ accdist(col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6241
+ );
6242
+ }
6243
+ function nvi2(bars) {
6244
+ return Series.fromArray(bars, nvi(col2(bars, "close"), col2(bars, "volume")));
6245
+ }
6246
+ function pvi2(bars) {
6247
+ return Series.fromArray(bars, pvi(col2(bars, "close"), col2(bars, "volume")));
6248
+ }
6249
+ function iii2(bars) {
6250
+ return Series.fromArray(
6251
+ bars,
6252
+ iii(col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6253
+ );
6254
+ }
6255
+ function wad2(bars) {
6256
+ return Series.fromArray(bars, wad(col2(bars, "high"), col2(bars, "low"), col2(bars, "close")));
6257
+ }
6258
+ function wvad2(bars) {
6259
+ return Series.fromArray(
6260
+ bars,
6261
+ wvad(col2(bars, "open"), col2(bars, "high"), col2(bars, "low"), col2(bars, "close"), col2(bars, "volume"))
6262
+ );
6263
+ }
5287
6264
  function stoch2(source, high, low, length2) {
5288
6265
  const bars = source.bars;
5289
6266
  const sourceValues = source.toArray();
@@ -5375,12 +6352,14 @@ function supertrend2(bars, factor, atrLength) {
5375
6352
  const dirSeries = Series.fromArray(bars, dirVals);
5376
6353
  return [trendSeries, dirSeries];
5377
6354
  }
5378
- function vwap2(source, volume) {
6355
+ function vwap2(source, volume, anchor) {
5379
6356
  const bars = source.bars;
5380
- const sourceValues = source.toArray();
5381
- const volumeValues = volume.toArray();
5382
- const result = vwap(sourceValues, volumeValues);
5383
- return Series.fromArray(bars, result);
6357
+ return Series.fromArray(bars, vwap(source.toArray(), volume.toArray(), anchor?.toArray()));
6358
+ }
6359
+ function vwapBands(source, volume, anchor, stdev_mult) {
6360
+ const bars = source.bars;
6361
+ const [m, u, l] = vwap(source.toArray(), volume.toArray(), anchor?.toArray(), stdev_mult);
6362
+ return [Series.fromArray(bars, m), Series.fromArray(bars, u), Series.fromArray(bars, l)];
5384
6363
  }
5385
6364
  function ichimoku2(bars, conversionPeriods, basePeriods, laggingSpan2Periods, displacement) {
5386
6365
  const high = bars.map((b2) => b2.high);
@@ -5565,10 +6544,9 @@ function kcw2(bars, source, length2 = 20, mult2 = 2, useTrueRange = true) {
5565
6544
  const result = kcw(source.toArray(), length2, mult2, useTrueRange, high, low, close);
5566
6545
  return Series.fromArray(bars, result);
5567
6546
  }
5568
- function range3(high, low) {
5569
- const bars = high.bars;
5570
- const result = range(high.toArray(), low.toArray());
5571
- return Series.fromArray(bars, result);
6547
+ function range3(source, length2) {
6548
+ const bars = source.bars;
6549
+ return Series.fromArray(bars, range(source.toArray(), length2));
5572
6550
  }
5573
6551
  function highestbars2(source, length2) {
5574
6552
  const bars = source.bars;
@@ -5580,15 +6558,13 @@ function lowestbars2(source, length2) {
5580
6558
  const result = lowestbars(source.toArray(), length2);
5581
6559
  return Series.fromArray(bars, result);
5582
6560
  }
5583
- function max5(source1, source2) {
5584
- const bars = source1.bars;
5585
- const result = max(source1.toArray(), source2.toArray());
5586
- return Series.fromArray(bars, result);
6561
+ function max5(source) {
6562
+ const bars = source.bars;
6563
+ return Series.fromArray(bars, max(source.toArray()));
5587
6564
  }
5588
- function min5(source1, source2) {
5589
- const bars = source1.bars;
5590
- const result = min(source1.toArray(), source2.toArray());
5591
- return Series.fromArray(bars, result);
6565
+ function min5(source) {
6566
+ const bars = source.bars;
6567
+ return Series.fromArray(bars, min(source.toArray()));
5592
6568
  }
5593
6569
  function cog2(source, length2 = 10) {
5594
6570
  const bars = source.bars;
@@ -5671,6 +6647,15 @@ var ta = {
5671
6647
  lowestbars: lowestbars2,
5672
6648
  max: max5,
5673
6649
  min: min5,
6650
+ vwapBands,
6651
+ obv: obv2,
6652
+ pvt: pvt2,
6653
+ accdist: accdist2,
6654
+ nvi: nvi2,
6655
+ pvi: pvi2,
6656
+ iii: iii2,
6657
+ wad: wad2,
6658
+ wvad: wvad2,
5674
6659
  cog: cog2,
5675
6660
  mode: mode4,
5676
6661
  percentile_linear_interpolation: percentile_linear_interpolation3,
@@ -5680,11 +6665,23 @@ var ta = {
5680
6665
 
5681
6666
  // src/utils/index.ts
5682
6667
  function isNA(value) {
5683
- return value === null || value === void 0 || Number.isNaN(value);
6668
+ return value === null || value === void 0 || Number.isNaN(value) || isDeleted(value);
5684
6669
  }
5685
6670
  function nz(value, defaultValue = 0) {
5686
6671
  return isNA(value) ? defaultValue : value;
5687
6672
  }
6673
+ function fixnan(source) {
6674
+ let last2;
6675
+ let seen = false;
6676
+ return source.map((v) => {
6677
+ if (!isNA(v)) {
6678
+ last2 = v;
6679
+ seen = true;
6680
+ return v;
6681
+ }
6682
+ return seen ? last2 : v;
6683
+ });
6684
+ }
5688
6685
  function ohlcFromBars(bars) {
5689
6686
  return {
5690
6687
  open: bars.map((b2) => b2.open),
@@ -6076,16 +7073,78 @@ var input = {
6076
7073
  title: options.title,
6077
7074
  options: options.options
6078
7075
  };
7076
+ },
7077
+ /**
7078
+ * Create a timeframe input parameter (PineScript `input.timeframe`)
7079
+ * @param defaultValue - Default timeframe string ("60", "1D", "W"); "" means the chart timeframe
7080
+ * @param options - Additional options (title, options for dropdown)
7081
+ * @returns Input value object
7082
+ *
7083
+ * @example
7084
+ * ```typescript
7085
+ * const htf = input.timeframe('1D', { title: 'Higher timeframe' });
7086
+ * console.log(htf.value); // '1D'
7087
+ * ```
7088
+ */
7089
+ timeframe(defaultValue, options = {}) {
7090
+ return {
7091
+ type: "timeframe",
7092
+ defaultValue,
7093
+ value: defaultValue,
7094
+ title: options.title,
7095
+ options: options.options
7096
+ };
7097
+ },
7098
+ /**
7099
+ * Create a session input parameter (PineScript `input.session`)
7100
+ * @param defaultValue - Default session string ("0930-1600", "0930-1600:23456")
7101
+ * @param options - Additional options (title, options for dropdown)
7102
+ * @returns Input value object
7103
+ *
7104
+ * @example
7105
+ * ```typescript
7106
+ * const rth = input.session('0930-1600', { title: 'Regular hours' });
7107
+ * console.log(rth.value); // '0930-1600'
7108
+ * ```
7109
+ */
7110
+ session(defaultValue, options = {}) {
7111
+ return {
7112
+ type: "session",
7113
+ defaultValue,
7114
+ value: defaultValue,
7115
+ title: options.title,
7116
+ options: options.options
7117
+ };
7118
+ },
7119
+ /**
7120
+ * Create a date/time input parameter (PineScript `input.time`)
7121
+ * @param defaultValue - Default UNIX time in milliseconds, e.g. `time.timestamp('2024-01-01')`
7122
+ * @param options - Additional options (title)
7123
+ * @returns Input value object
7124
+ *
7125
+ * @example
7126
+ * ```typescript
7127
+ * const start = input.time(time.timestamp('2024-01-01'), { title: 'Start' });
7128
+ * console.log(start.value); // 1704067200000
7129
+ * ```
7130
+ */
7131
+ time(defaultValue, options = {}) {
7132
+ return {
7133
+ type: "time",
7134
+ defaultValue,
7135
+ value: defaultValue,
7136
+ title: options.title
7137
+ };
6079
7138
  }
6080
7139
  };
6081
7140
  Object.freeze(input);
6082
7141
 
6083
7142
  // src/plot.ts
6084
- function plot(values, times, options = {}) {
7143
+ function plot(values2, times, options = {}) {
6085
7144
  const result = [];
6086
7145
  const offset = options.offset ?? 0;
6087
- for (let i = 0; i < values.length; i++) {
6088
- const value = values[i];
7146
+ for (let i = 0; i < values2.length; i++) {
7147
+ const value = values2[i];
6089
7148
  const timeIndex = i + offset;
6090
7149
  if (value === null || value === void 0 || Number.isNaN(value)) {
6091
7150
  continue;
@@ -6100,10 +7159,10 @@ function plot(values, times, options = {}) {
6100
7159
  }
6101
7160
  return result;
6102
7161
  }
6103
- function createPlot(id, values, times, options = {}) {
7162
+ function createPlot(id, values2, times, options = {}) {
6104
7163
  return {
6105
7164
  id,
6106
- data: plot(values, times, options),
7165
+ data: plot(values2, times, options),
6107
7166
  options
6108
7167
  };
6109
7168
  }
@@ -6344,6 +7403,42 @@ function input_string(defval, title, options) {
6344
7403
  const value = context2.inputs.getValue(id);
6345
7404
  return typeof value === "string" ? value : defval;
6346
7405
  }
7406
+ function registerOnce(config) {
7407
+ const context2 = getContext();
7408
+ if (!registeredInputs.has(config.id)) {
7409
+ context2.inputs.registerInput(config);
7410
+ registeredInputs.set(config.id, true);
7411
+ if (autoRecalculateEnabled) {
7412
+ context2.inputs.onInputChange((changedId) => {
7413
+ if (changedId === config.id) {
7414
+ recalculate();
7415
+ }
7416
+ });
7417
+ }
7418
+ }
7419
+ return context2.inputs.getValue(config.id);
7420
+ }
7421
+ function input_timeframe(defval, title, options) {
7422
+ if (!getContext()) {
7423
+ return defval;
7424
+ }
7425
+ const value = registerOnce({ id: generateInputId(title, defval, "timeframe"), type: "timeframe", defval, title, options });
7426
+ return typeof value === "string" ? value : defval;
7427
+ }
7428
+ function input_session(defval, title, options) {
7429
+ if (!getContext()) {
7430
+ return defval;
7431
+ }
7432
+ const value = registerOnce({ id: generateInputId(title, defval, "session"), type: "session", defval, title, options });
7433
+ return typeof value === "string" ? value : defval;
7434
+ }
7435
+ function input_time(defval, title) {
7436
+ if (!getContext()) {
7437
+ return defval;
7438
+ }
7439
+ const value = registerOnce({ id: generateInputId(title, defval, "time"), type: "time", defval, title });
7440
+ return typeof value === "number" ? value : defval;
7441
+ }
6347
7442
  function input_source(defval, title) {
6348
7443
  const context2 = getContext();
6349
7444
  if (!context2) {
@@ -6566,7 +7661,7 @@ var SimpleInputAdapter = class {
6566
7661
  validatedValue = Math.floor(validatedValue);
6567
7662
  }
6568
7663
  }
6569
- if (config.type === "string" && config.options && typeof value === "string") {
7664
+ if ((config.type === "string" || config.type === "timeframe" || config.type === "session") && config.options && typeof value === "string") {
6570
7665
  if (!config.options.includes(value)) {
6571
7666
  return;
6572
7667
  }
@@ -6614,8 +7709,8 @@ var SimpleInputAdapter = class {
6614
7709
  };
6615
7710
 
6616
7711
  // src/index.ts
6617
- var VERSION = "0.3.0";
6618
- var info = {
7712
+ var VERSION = "0.6.0";
7713
+ var info2 = {
6619
7714
  name: "OakScriptJS",
6620
7715
  version: VERSION,
6621
7716
  description: "Simplified PineScript-like library - Series + TA functions",
@@ -6628,8 +7723,8 @@ var info = {
6628
7723
  minimal: "No DSL layer - complexity in transpiler"
6629
7724
  },
6630
7725
  namespaces: {
6631
- core: ["ta", "math", "array", "str", "color", "time", "matrix"],
6632
- drawing: ["line", "box", "label", "linefill", "chartPoint", "polyline"],
7726
+ core: ["ta", "math", "array", "map", "str", "color", "time", "timeframe", "matrix"],
7727
+ drawing: ["line", "box", "label", "linefill", "chartPoint", "polyline", "text"],
6633
7728
  runtime: ["setContext", "plot", "hline", "input_*"],
6634
7729
  indicator: ["indicator", "input", "plotHelper", "createPlot"]
6635
7730
  }
@@ -6665,6 +7760,7 @@ export {
6665
7760
  cum2 as cum,
6666
7761
  ema2 as ema,
6667
7762
  exp,
7763
+ fixnan,
6668
7764
  floor,
6669
7765
  getClose,
6670
7766
  getContext,
@@ -6674,18 +7770,22 @@ export {
6674
7770
  getSourceSeries,
6675
7771
  hline,
6676
7772
  indicator,
6677
- info,
7773
+ info2 as info,
6678
7774
  input,
6679
7775
  input_bool,
6680
7776
  input_float,
6681
7777
  input_int,
7778
+ input_session,
6682
7779
  input_source,
6683
7780
  input_string,
7781
+ input_time,
7782
+ input_timeframe,
6684
7783
  label_exports as label,
6685
7784
  line_exports as line,
6686
7785
  linefill_exports as linefill,
6687
7786
  log,
6688
7787
  macd2 as macd,
7788
+ map_exports as map,
6689
7789
  math_exports as math,
6690
7790
  matrix_exports as matrix,
6691
7791
  max2 as max,
@@ -6713,7 +7813,9 @@ export {
6713
7813
  ta_series_exports as ta,
6714
7814
  ta_exports as taCore,
6715
7815
  tan,
7816
+ text_exports as text,
6716
7817
  time_exports as time,
7818
+ timeframe_exports as timeframe,
6717
7819
  tr2 as tr,
6718
7820
  vwap2 as vwap,
6719
7821
  xloc,