oakscriptjs 0.15.0 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/cjs/callsite/index.d.ts +3 -3
  2. package/dist/cjs/callsite/index.d.ts.map +1 -1
  3. package/dist/cjs/callsite/index.js +61 -7
  4. package/dist/cjs/callsite/index.js.map +2 -2
  5. package/dist/cjs/drawing/registry.d.ts +30 -5
  6. package/dist/cjs/drawing/registry.d.ts.map +1 -1
  7. package/dist/cjs/drawing/registry.js +118 -42
  8. package/dist/cjs/drawing/registry.js.map +2 -2
  9. package/dist/cjs/index.d.ts +1 -1
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/linefill/index.d.ts.map +1 -1
  13. package/dist/cjs/linefill/index.js +14 -5
  14. package/dist/cjs/linefill/index.js.map +2 -2
  15. package/dist/cjs/math/index.d.ts +2 -6
  16. package/dist/cjs/math/index.d.ts.map +1 -1
  17. package/dist/cjs/math/index.js.map +2 -2
  18. package/dist/cjs/script/index.d.ts.map +1 -1
  19. package/dist/cjs/str/floatingdecimal.d.ts +3 -0
  20. package/dist/cjs/str/floatingdecimal.d.ts.map +1 -1
  21. package/dist/cjs/str/floatingdecimal.js +25 -12
  22. package/dist/cjs/str/floatingdecimal.js.map +2 -2
  23. package/dist/cjs/str/messageformat.d.ts.map +1 -1
  24. package/dist/cjs/str/messageformat.js +27 -8
  25. package/dist/cjs/str/messageformat.js.map +2 -2
  26. package/dist/cjs/str/numberformat.d.ts.map +1 -1
  27. package/dist/cjs/str/numberformat.js +9 -16
  28. package/dist/cjs/str/numberformat.js.map +3 -3
  29. package/dist/cjs/ta/index.d.ts +9 -11
  30. package/dist/cjs/ta/index.d.ts.map +1 -1
  31. package/dist/cjs/ta/index.js +27 -0
  32. package/dist/cjs/ta/index.js.map +2 -2
  33. package/dist/cjs/ta/running-sum.d.ts +20 -19
  34. package/dist/cjs/ta/running-sum.d.ts.map +1 -1
  35. package/dist/cjs/ta/running-sum.js +74 -74
  36. package/dist/cjs/ta/running-sum.js.map +2 -2
  37. package/dist/cjs/time/timezone.d.ts.map +1 -1
  38. package/dist/cjs/time/timezone.js +14 -1
  39. package/dist/cjs/time/timezone.js.map +2 -2
  40. package/dist/esm/callsite/index.d.ts +3 -3
  41. package/dist/esm/callsite/index.d.ts.map +1 -1
  42. package/dist/esm/callsite/index.js +79 -10
  43. package/dist/esm/callsite/index.js.map +1 -1
  44. package/dist/esm/drawing/registry.d.ts +30 -5
  45. package/dist/esm/drawing/registry.d.ts.map +1 -1
  46. package/dist/esm/drawing/registry.js +163 -54
  47. package/dist/esm/drawing/registry.js.map +1 -1
  48. package/dist/esm/index.d.ts +1 -1
  49. package/dist/esm/index.js +1 -1
  50. package/dist/esm/linefill/index.d.ts.map +1 -1
  51. package/dist/esm/linefill/index.js +17 -7
  52. package/dist/esm/linefill/index.js.map +1 -1
  53. package/dist/esm/math/index.d.ts +2 -6
  54. package/dist/esm/math/index.d.ts.map +1 -1
  55. package/dist/esm/math/index.js +1 -1
  56. package/dist/esm/math/index.js.map +1 -1
  57. package/dist/esm/script/index.d.ts.map +1 -1
  58. package/dist/esm/str/floatingdecimal.d.ts +3 -0
  59. package/dist/esm/str/floatingdecimal.d.ts.map +1 -1
  60. package/dist/esm/str/floatingdecimal.js +27 -11
  61. package/dist/esm/str/floatingdecimal.js.map +1 -1
  62. package/dist/esm/str/messageformat.d.ts.map +1 -1
  63. package/dist/esm/str/messageformat.js +35 -9
  64. package/dist/esm/str/messageformat.js.map +1 -1
  65. package/dist/esm/str/numberformat.d.ts.map +1 -1
  66. package/dist/esm/str/numberformat.js +12 -18
  67. package/dist/esm/str/numberformat.js.map +1 -1
  68. package/dist/esm/ta/index.d.ts +9 -11
  69. package/dist/esm/ta/index.d.ts.map +1 -1
  70. package/dist/esm/ta/index.js +48 -15
  71. package/dist/esm/ta/index.js.map +1 -1
  72. package/dist/esm/ta/running-sum.d.ts +20 -19
  73. package/dist/esm/ta/running-sum.d.ts.map +1 -1
  74. package/dist/esm/ta/running-sum.js +103 -103
  75. package/dist/esm/ta/running-sum.js.map +1 -1
  76. package/dist/esm/time/timezone.d.ts.map +1 -1
  77. package/dist/esm/time/timezone.js +23 -3
  78. package/dist/esm/time/timezone.js.map +1 -1
  79. package/package.json +1 -1
  80. package/src/callsite/index.ts +68 -10
  81. package/src/drawing/registry.ts +167 -50
  82. package/src/index.ts +1 -1
  83. package/src/linefill/index.ts +16 -7
  84. package/src/math/index.ts +3 -7
  85. package/src/str/floatingdecimal.ts +27 -11
  86. package/src/str/messageformat.ts +40 -9
  87. package/src/str/numberformat.ts +13 -17
  88. package/src/ta/index.ts +54 -15
  89. package/src/ta/running-sum.ts +94 -99
  90. package/src/time/timezone.ts +26 -4
@@ -1,39 +1,40 @@
1
1
  /** A value PineScript treats as na in window functions (also +/-Infinity). */
2
2
  export declare function isNa(v: number | null | undefined): boolean;
3
3
  /**
4
- * Running sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without
4
+ * Window sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without
5
5
  * changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the
6
6
  * last one kept (a ta.* call in a loop).
7
7
  *
8
- * The length can change from one step to the next (a series length). PineScript then first moves the kept sum to the
9
- * new length with Kahan steps of the raw values (not the stored compensated values): a smaller length removes the
10
- * values that leave the window, oldest first; a larger length adds back the values from the one before the old window
11
- * down to the one `length` values back, newest first (one more than the window needs). Then the usual step runs with
12
- * the new length: it removes the stored value of the one `length` values back and adds the new value.
8
+ * The length can change from one step to the next (a series length): the window is then the last `length` values,
9
+ * the values that leave or come back are removed or added exactly.
13
10
  */
14
11
  export declare class RunningSum {
15
12
  private readonly values;
16
- private readonly stored;
13
+ /** Exact sum of the kept window (the last `keptLength` values). */
14
+ private partials;
17
15
  private keptLength;
18
- private s;
19
- private c;
20
16
  private stepLength;
21
17
  private stepX;
22
- private stepY;
23
- private stepS;
24
- private stepC;
25
- /** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */
26
- private resize;
18
+ private stepPartials;
27
19
  /**
28
- * The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is
20
+ * {@link resized} partials of the kept state by length, until the next {@link commit}: the calls of a loop (several
21
+ * steps on one bar) move the same kept sum to the same lengths. Kept from the second step on, so that one step per
22
+ * bar costs nothing more.
23
+ */
24
+ private readonly resizedByLength;
25
+ private resizedSinceCommit;
26
+ /** The partials of the last `len` values (kept state, nothing added); a new array. */
27
+ private resized;
28
+ /**
29
+ * The sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is
29
30
  * unchanged until {@link commit}.
30
31
  *
31
32
  * @returns The sum, or NaN while fewer than `length` values exist (with `x`)
32
33
  */
33
34
  step(x: number, length: number): number;
34
35
  /**
35
- * The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the
36
- * state is unchanged until {@link commit}. With an unchanged length, it is the previous result.
36
+ * The sum of the last `length` values on a bar with an na value (no value added), from the kept state; the state is
37
+ * unchanged until {@link commit}. With an unchanged length, it is the previous result.
37
38
  *
38
39
  * @returns The sum, or NaN while fewer than `length` values exist
39
40
  */
@@ -42,7 +43,7 @@ export declare class RunningSum {
42
43
  commit(): void;
43
44
  }
44
45
  /**
45
- * The sum of the last `length` non-na values on each bar, as PineScript computes it.
46
+ * The sum of the last `length` non-na values on each bar, correctly rounded, as PineScript.
46
47
  *
47
48
  * @param source - Values (na: NaN, null, undefined or +/-Infinity, skipped)
48
49
  * @param length - Number of non-na values in the window
@@ -58,7 +59,7 @@ export declare function runningSum(source: ArrayLike<number | null | undefined>,
58
59
  */
59
60
  export declare function runningSumSeries(source: ArrayLike<number | null | undefined>, lengths: ArrayLike<number>, name?: string): number[];
60
61
  /**
61
- * Window variance from the running sums of the values and of their squares, as PineScript computes it:
62
+ * Window variance from the window sums of the values and of their squares, as PineScript computes it (#188):
62
63
  * biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.
63
64
  */
64
65
  export declare function runningVariance(source: ArrayLike<number | null | undefined>, length: number, biased: boolean): number[];
@@ -1 +1 @@
1
- {"version":3,"file":"running-sum.d.ts","sourceRoot":"","sources":["../../../src/ta/running-sum.ts"],"names":[],"mappings":"AA6BA,8EAA8E;AAC9E,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE1D;AAED;;;;;;;;;;GAUG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,CAAC,CAAK;IACd,OAAO,CAAC,CAAC,CAAK;IACd,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,KAAK,CAAK;IAElB,0GAA0G;IAC1G,OAAO,CAAC,MAAM;IAqBd;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAkCvC;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAQ9B,kEAAkE;IAClE,MAAM,IAAI,IAAI;CASf;AAeD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAIjG;AAeD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B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AC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAIjG;AAeD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,IAAI,SAAa,GAChB,MAAM,EAAE,CAGV;AAuBD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,GACd,MAAM,EAAE,CAGV;AAED,4FAA4F;AAC5F,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAC5C,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,EAC1B,MAAM,EAAE,OAAO,EACf,IAAI,SAAgB,GACnB,MAAM,EAAE,CAGV"}
@@ -27,107 +27,107 @@ __export(running_sum_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(running_sum_exports);
29
29
  var import_limits = require("./limits.js");
30
- function compensationLost(x, c) {
31
- if (c === 0 || x === 0) return false;
32
- const size = Math.abs(c);
33
- return Math.abs(x + size - x) < size;
34
- }
35
30
  function isNa(v) {
36
31
  return v === void 0 || v === null || !Number.isFinite(v);
37
32
  }
33
+ function addExact(p, x) {
34
+ let i = 0;
35
+ for (let j = 0; j < p.length; j++) {
36
+ let y = p[j];
37
+ if (Math.abs(x) < Math.abs(y)) [x, y] = [y, x];
38
+ const hi = x + y;
39
+ const lo = y - (hi - x);
40
+ if (lo !== 0) p[i++] = lo;
41
+ x = hi;
42
+ }
43
+ p.length = i;
44
+ p.push(x);
45
+ }
46
+ function roundExact(p) {
47
+ let n = p.length;
48
+ if (n === 0) return 0;
49
+ let hi = p[--n];
50
+ while (n > 0) {
51
+ const x = hi;
52
+ const y = p[--n];
53
+ hi = x + y;
54
+ const lo = y - (hi - x);
55
+ if (lo !== 0) {
56
+ if (n > 0 && (lo < 0 && p[n - 1] < 0 || lo > 0 && p[n - 1] > 0)) {
57
+ const y2 = lo * 2;
58
+ const x2 = hi + y2;
59
+ if (y2 === x2 - hi) hi = x2;
60
+ }
61
+ break;
62
+ }
63
+ }
64
+ return hi;
65
+ }
38
66
  class RunningSum {
39
67
  values = [];
40
- stored = [];
41
- keptLength = NaN;
42
- s = 0;
43
- c = 0;
44
- stepLength = NaN;
68
+ /** Exact sum of the kept window (the last `keptLength` values). */
69
+ partials = [];
70
+ keptLength = 0;
71
+ stepLength = 0;
45
72
  stepX = NaN;
46
- stepY = NaN;
47
- stepS = 0;
48
- stepC = 0;
49
- /** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */
50
- resize(len) {
73
+ stepPartials = [];
74
+ /**
75
+ * {@link resized} partials of the kept state by length, until the next {@link commit}: the calls of a loop (several
76
+ * steps on one bar) move the same kept sum to the same lengths. Kept from the second step on, so that one step per
77
+ * bar costs nothing more.
78
+ */
79
+ resizedByLength = /* @__PURE__ */ new Map();
80
+ resizedSinceCommit = 0;
81
+ /** The partials of the last `len` values (kept state, nothing added); a new array. */
82
+ resized(len) {
83
+ const cached = this.resizedByLength.get(len);
84
+ if (cached) return cached.slice();
51
85
  const values = this.values;
52
86
  const n = values.length;
53
- const kept = this.keptLength;
54
- let s = this.s;
55
- let c = this.c;
56
- const add = (v) => {
57
- const y = v - c;
58
- const t = s + y;
59
- c = t - s - y;
60
- s = t;
61
- };
62
- if (len < kept) {
63
- for (let k = Math.max(0, n - kept); k <= n - len - 1; k++) add(-values[k]);
64
- } else if (len > kept) {
65
- for (let k = n - kept - 1; k >= Math.max(0, n - len); k--) add(values[k]);
66
- }
67
- this.stepS = s;
68
- this.stepC = c;
87
+ const p = this.partials.slice();
88
+ const kept = Math.min(this.keptLength, n);
89
+ const want = Math.min(len, n);
90
+ if (want < kept) for (let k = n - kept; k < n - want; k++) addExact(p, -values[k]);
91
+ else for (let k = n - kept - 1; k >= n - want; k--) addExact(p, values[k]);
92
+ if (this.resizedSinceCommit++ > 0) this.resizedByLength.set(len, p.slice());
93
+ return p;
69
94
  }
70
95
  /**
71
- * The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is
96
+ * The sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is
72
97
  * unchanged until {@link commit}.
73
98
  *
74
99
  * @returns The sum, or NaN while fewer than `length` values exist (with `x`)
75
100
  */
76
101
  step(x, length) {
77
- const len = length;
78
- const values = this.values;
79
- this.resize(len);
80
- let s = this.stepS;
81
- let c = this.stepC;
82
- const c0 = c;
83
- const n = values.length;
84
- if (n >= len) {
85
- const y = -this.stored[n - len] - c;
86
- const t = s + y;
87
- c = t - s - y;
88
- s = t;
89
- }
90
- if (compensationLost(x, c0)) {
91
- let fresh = x;
92
- for (let k = n - 1; k >= Math.max(0, n + 1 - len); k--) fresh += values[k];
93
- s = fresh;
94
- c = 0;
95
- this.stepY = x;
96
- } else {
97
- const y = x - c;
98
- const t = s + y;
99
- c = t - s - y;
100
- s = t;
101
- this.stepY = y;
102
- }
103
- this.stepLength = len;
102
+ const n = this.values.length;
103
+ const p = this.resized(length - 1);
104
+ addExact(p, x);
105
+ this.stepPartials = p;
106
+ this.stepLength = Math.min(length, n + 1);
104
107
  this.stepX = x;
105
- this.stepS = s;
106
- this.stepC = c;
107
- return n + 1 >= len ? s : NaN;
108
+ return n + 1 >= length ? roundExact(p) : NaN;
108
109
  }
109
110
  /**
110
- * The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the
111
- * state is unchanged until {@link commit}. With an unchanged length, it is the previous result.
111
+ * The sum of the last `length` values on a bar with an na value (no value added), from the kept state; the state is
112
+ * unchanged until {@link commit}. With an unchanged length, it is the previous result.
112
113
  *
113
114
  * @returns The sum, or NaN while fewer than `length` values exist
114
115
  */
115
116
  stepNa(length) {
116
- this.resize(length);
117
- this.stepLength = length;
118
- this.stepX = NaN;
119
117
  const n = this.values.length;
120
- return n > 0 && n >= length ? this.stepS : NaN;
118
+ const p = this.resized(length);
119
+ this.stepPartials = p;
120
+ this.stepLength = Math.min(length, n);
121
+ this.stepX = NaN;
122
+ return n > 0 && n >= length ? roundExact(p) : NaN;
121
123
  }
122
124
  /** Keeps the state of the last {@link step} or {@link stepNa}. */
123
125
  commit() {
124
- if (!Number.isNaN(this.stepX)) {
125
- this.values.push(this.stepX);
126
- this.stored.push(this.stepY);
127
- }
126
+ if (!Number.isNaN(this.stepX)) this.values.push(this.stepX);
128
127
  this.keptLength = this.stepLength;
129
- this.s = this.stepS;
130
- this.c = this.stepC;
128
+ this.partials = this.stepPartials;
129
+ this.resizedSinceCommit = 0;
130
+ if (this.resizedByLength.size > 0) this.resizedByLength.clear();
131
131
  }
132
132
  }
133
133
  function sumWindows(source, lengthAt) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/ta/running-sum.ts"],
4
- "sourcesContent": ["/**\n * Running window sum with the floating-point behaviour of PineScript `math.sum` / `ta.sma` / `ta.stdev` /\n * `ta.variance` (bit for bit).\n *\n * PineScript does not sum the window again on each bar. It keeps a compensated (Kahan) running sum:\n * - each bar first removes, with a Kahan step, the compensated value that was added for the value that leaves the\n * window, then adds the new value with a Kahan step and keeps its compensated value;\n * - when the compensation of the previous step would be lost when applied to the new value, the sum is computed\n * again from the window values (newest first) and the compensation is reset. The test moves the new value toward\n * +infinity by the size of the compensation, in floating point (#136, #142).\n *\n * So the result can differ from the exact window sum in the last bits (e.g. a small residue on a window of zeros),\n * as in PineScript.\n *\n * @internal\n */\nimport { checkSumLength } from './limits.js';\n\n/**\n * Whether the compensation `c` is (partly) lost when it is applied to `x`: `x + |c|` in floating point moves `x` by\n * less than `|c|`. Moving toward +infinity uses the grid above `x` (the coarser binade just below a power of two, the\n * finer binade for a negative power of two), as PineScript (measured bit for bit, #142).\n */\nfunction compensationLost(x: number, c: number): boolean {\n if (c === 0 || x === 0) return false;\n const size = Math.abs(c);\n return Math.abs(x + size - x) < size;\n}\n\n/** A value PineScript treats as na in window functions (also +/-Infinity). */\nexport function isNa(v: number | null | undefined): boolean {\n return v === undefined || v === null || !Number.isFinite(v);\n}\n\n/**\n * Running sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without\n * changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the\n * last one kept (a ta.* call in a loop).\n *\n * The length can change from one step to the next (a series length). PineScript then first moves the kept sum to the\n * new length with Kahan steps of the raw values (not the stored compensated values): a smaller length removes the\n * values that leave the window, oldest first; a larger length adds back the values from the one before the old window\n * down to the one `length` values back, newest first (one more than the window needs). Then the usual step runs with\n * the new length: it removes the stored value of the one `length` values back and adds the new value.\n */\nexport class RunningSum {\n private readonly values: number[] = [];\n private readonly stored: number[] = [];\n private keptLength = NaN;\n private s = 0;\n private c = 0;\n private stepLength = NaN;\n private stepX = NaN;\n private stepY = NaN;\n private stepS = 0;\n private stepC = 0;\n\n /** Kahan steps that move the kept sum from the kept length to `len`; the result goes to stepS / stepC. */\n private resize(len: number): void {\n const values = this.values;\n const n = values.length;\n const kept = this.keptLength;\n let s = this.s;\n let c = this.c;\n const add = (v: number) => {\n const y = v - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n };\n if (len < kept) {\n for (let k = Math.max(0, n - kept); k <= n - len - 1; k++) add(-values[k]!);\n } else if (len > kept) {\n for (let k = n - kept - 1; k >= Math.max(0, n - len); k--) add(values[k]!);\n }\n this.stepS = s;\n this.stepC = c;\n }\n\n /**\n * The running sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is\n * unchanged until {@link commit}.\n *\n * @returns The sum, or NaN while fewer than `length` values exist (with `x`)\n */\n step(x: number, length: number): number {\n const len = length;\n const values = this.values;\n this.resize(len);\n let s = this.stepS;\n let c = this.stepC;\n const c0 = c;\n const n = values.length;\n if (n >= len) {\n const y = -this.stored[n - len]! - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n }\n if (compensationLost(x, c0)) {\n let fresh = x;\n for (let k = n - 1; k >= Math.max(0, n + 1 - len); k--) fresh += values[k]!;\n s = fresh;\n c = 0;\n this.stepY = x;\n } else {\n const y = x - c;\n const t = s + y;\n c = (t - s) - y;\n s = t;\n this.stepY = y;\n }\n this.stepLength = len;\n this.stepX = x;\n this.stepS = s;\n this.stepC = c;\n return n + 1 >= len ? s : NaN;\n }\n\n /**\n * The running sum of the last `length` values on a bar with an na value (no value added), from the kept state; the\n * state is unchanged until {@link commit}. With an unchanged length, it is the previous result.\n *\n * @returns The sum, or NaN while fewer than `length` values exist\n */\n stepNa(length: number): number {\n this.resize(length);\n this.stepLength = length;\n this.stepX = NaN;\n const n = this.values.length;\n return n > 0 && n >= length ? this.stepS : NaN;\n }\n\n /** Keeps the state of the last {@link step} or {@link stepNa}. */\n commit(): void {\n if (!Number.isNaN(this.stepX)) {\n this.values.push(this.stepX);\n this.stored.push(this.stepY);\n }\n this.keptLength = this.stepLength;\n this.s = this.stepS;\n this.c = this.stepC;\n }\n}\n\n/** The running sums of `source` with the length `lengthAt(i)` on bar `i`. */\nfunction sumWindows(source: ArrayLike<number | null | undefined>, lengthAt: (i: number) => number): number[] {\n const out: number[] = new Array<number>(source.length);\n const sum = new RunningSum();\n for (let i = 0; i < source.length; i++) {\n const v = source[i];\n const len = lengthAt(i);\n out[i] = isNa(v) ? sum.stepNa(len) : sum.step(v as number, len);\n sum.commit();\n }\n return out;\n}\n\n/**\n * The sum of the last `length` non-na values on each bar, as PineScript computes it.\n *\n * @param source - Values (na: NaN, null, undefined or +/-Infinity, skipped)\n * @param length - Number of non-na values in the window\n * @returns The running sum per bar: NaN until `length` non-na values exist; a bar with an na value keeps the\n * previous result\n */\nexport function runningSum(source: ArrayLike<number | null | undefined>, length: number): number[] {\n const len = Math.floor(length);\n if (!(len >= 1)) return new Array<number>(source.length).fill(NaN);\n return sumWindows(source, () => len);\n}\n\n/** The values of a series length, floored, checked to be at least 1 on every bar. */\nfunction seriesLengths(lengths: ArrayLike<number>, count: number, name: string): number[] {\n if (lengths.length < count) {\n throw new Error(`${name}: the length series has ${lengths.length} values for ${count} bars`);\n }\n return Array.from({ length: count }, (_, i) => {\n const len = Math.floor(lengths[i]!);\n checkSumLength(name, len, i);\n if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);\n return len;\n });\n}\n\n/**\n * The sum of the last `lengths[i]` non-na values on each bar `i` (a series length), as PineScript computes it (see\n * {@link RunningSum}). A bar with an na value gives the sum of the last `lengths[i]` earlier values.\n *\n * @param name - Function name for the error messages\n */\nexport function runningSumSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n name = 'math.sum'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return sumWindows(source, (i) => lens[i]!);\n}\n\n/** Variance from the running sums of the values and of their squares; rules in {@link runningVariance}. */\nfunction varianceFromSums(\n source: ArrayLike<number | null | undefined>,\n sumOf: (src: ArrayLike<number | null | undefined>) => number[],\n lengthAt: (i: number) => number,\n biased: boolean\n): number[] {\n const squares = Array.from({ length: source.length }, (_, i) => {\n const v = source[i];\n return isNa(v) ? NaN : (v as number) * (v as number);\n });\n const sums = sumOf(source);\n const sumSquares = sumOf(squares);\n return sums.map((sum, i) => {\n const len = lengthAt(i);\n const mean = sum / len;\n const sq = sumSquares[i]!;\n return biased ? sq / len - mean * mean : sq / (len - 1) - (mean * sum) / (len - 1);\n });\n}\n\n/**\n * Window variance from the running sums of the values and of their squares, as PineScript computes it:\n * biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.\n */\nexport function runningVariance(\n source: ArrayLike<number | null | undefined>,\n length: number,\n biased: boolean\n): number[] {\n const len = Math.floor(length);\n return varianceFromSums(source, (src) => runningSum(src, len), () => len, biased);\n}\n\n/** {@link runningVariance} with a series length (the length of bar `i` is `lengths[i]`). */\nexport function runningVarianceSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n biased: boolean,\n name = 'ta.variance'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return varianceFromSums(source, (src) => sumWindows(src, (i) => lens[i]!), (i) => lens[i]!, biased);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAA+B;AAO/B,SAAS,iBAAiB,GAAW,GAAoB;AACvD,MAAI,MAAM,KAAK,MAAM,EAAG,QAAO;AAC/B,QAAM,OAAO,KAAK,IAAI,CAAC;AACvB,SAAO,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI;AAClC;AAGO,SAAS,KAAK,GAAuC;AAC1D,SAAO,MAAM,UAAa,MAAM,QAAQ,CAAC,OAAO,SAAS,CAAC;AAC5D;AAaO,MAAM,WAAW;AAAA,EACL,SAAmB,CAAC;AAAA,EACpB,SAAmB,CAAC;AAAA,EAC7B,aAAa;AAAA,EACb,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA;AAAA,EAGR,OAAO,KAAmB;AAChC,UAAM,SAAS,KAAK;AACpB,UAAM,IAAI,OAAO;AACjB,UAAM,OAAO,KAAK;AAClB,QAAI,IAAI,KAAK;AACb,QAAI,IAAI,KAAK;AACb,UAAM,MAAM,CAAC,MAAc;AACzB,YAAM,IAAI,IAAI;AACd,YAAM,IAAI,IAAI;AACd,UAAK,IAAI,IAAK;AACd,UAAI;AAAA,IACN;AACA,QAAI,MAAM,MAAM;AACd,eAAS,IAAI,KAAK,IAAI,GAAG,IAAI,IAAI,GAAG,KAAK,IAAI,MAAM,GAAG,IAAK,KAAI,CAAC,OAAO,CAAC,CAAE;AAAA,IAC5E,WAA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S,iBACd,QACA,SACA,OAAO,YACG;AACV,QAAM,OAAO,cAAc,SAAS,OAAO,QAAQ,IAAI;AACvD,SAAO,WAAW,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAE;AAC3C;AAGA,SAAS,iBACP,QACA,OACA,UACA,QACU;AACV,QAAM,UAAU,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,GAAG,CAAC,GAAG,MAAM;AAC9D,UAAM,IAAI,OAAO,CAAC;AAClB,WAAO,KAAK,CAAC,IAAI,MAAO,IAAgB;AAAA,EAC1C,CAAC;AACD,QAAM,OAAO,MAAM,MAAM;AACzB,QAAM,aAAa,MAAM,OAAO;AAChC,SAAO,KAAK,IAAI,CAAC,KAAK,MAAM;AAC1B,UAAM,MAAM,SAAS,CAAC;AACtB,UAAM,OAAO,MAAM;AACnB,UAAM,KAAK,WAAW,CAAC;AACvB,WAAO,SAAS,KAAK,MAAM,OAAO,OAAO,MAAM,MAAM,KAAM,OAAO,OAAQ,MAAM;AAAA,EAClF,CAAC;AACH;AAMO,SAAS,gBACd,QACA,QACA,QACU;AACV,QAAM,MAAM,KAAK,MAAM,MAAM;AAC7B,SAAO,iBAAiB,QAAQ,CAAC,QAAQ,WAAW,KAAK,GAAG,GAAG,MAAM,KAAK,MAAM;AAClF;AAGO,SAAS,sBACd,QACA,SACA,QACA,OAAO,eACG;AACV,QAAM,OAAO,cAAc,SAAS,OAAO,QAAQ,IAAI;AACvD,SAAO,iBAAiB,QAAQ,CAAC,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,CAAC,CAAE,GAAG,CAAC,MAAM,KAAK,CAAC,GAAI,MAAM;AACpG;",
4
+ "sourcesContent": ["/**\n * Window sums of PineScript `math.sum` / `ta.sma` / `ta.stdev` / `ta.variance` / `ta.mfi` (bit for bit).\n *\n * PineScript gives the correctly rounded sum of the window values (the exact sum of the doubles, rounded once), on\n * every bar: `ta.sma` is that sum divided by the length (measured on the reference 05/11/2026, #188: built-in and\n * expression sources, with or without a `ta.stdev` of the same source, constant and series lengths, na values; 0\n * differing bars of 16,550 on BTCUSD 1D and 34,665 on AAPL 1D). The running sum of earlier versions (Kahan steps,\n * #114) gave a small residue on a window of zeros; the reference no longer does.\n *\n * The exact sum is kept as non-overlapping partials (Shewchuk's algorithm, as Python `math.fsum`): adding a value and\n * removing the one that leaves the window (adding its negation) are exact, so a bar costs the values that enter and\n * leave, not the whole window.\n *\n * @internal\n */\nimport { checkSumLength } from './limits.js';\n\n/** A value PineScript treats as na in window functions (also +/-Infinity). */\nexport function isNa(v: number | null | undefined): boolean {\n return v === undefined || v === null || !Number.isFinite(v);\n}\n\n/** Adds `x` to the partials `p` (non-overlapping, increasing magnitude), exactly. */\nfunction addExact(p: number[], x: number): void {\n let i = 0;\n for (let j = 0; j < p.length; j++) {\n let y = p[j]!;\n if (Math.abs(x) < Math.abs(y)) [x, y] = [y, x];\n const hi = x + y;\n const lo = y - (hi - x);\n if (lo !== 0) p[i++] = lo;\n x = hi;\n }\n p.length = i;\n p.push(x);\n}\n\n/** The partials' exact sum rounded once to a double (round half to even), as Python `math.fsum`. */\nfunction roundExact(p: readonly number[]): number {\n let n = p.length;\n if (n === 0) return 0;\n let hi = p[--n]!;\n while (n > 0) {\n const x = hi;\n const y = p[--n]!;\n hi = x + y;\n const lo = y - (hi - x);\n if (lo !== 0) {\n // half-way case: the rest has the same sign, so round away from the tie\n if (n > 0 && ((lo < 0 && p[n - 1]! < 0) || (lo > 0 && p[n - 1]! > 0))) {\n const y2 = lo * 2;\n const x2 = hi + y2;\n if (y2 === x2 - hi) hi = x2;\n }\n break;\n }\n }\n return hi;\n}\n\n/**\n * Window sum state, one value at a time. {@link step} computes the sum with a new value from the kept state without\n * changing it; {@link commit} keeps the last step. So several candidate values can be tried on one bar and only the\n * last one kept (a ta.* call in a loop).\n *\n * The length can change from one step to the next (a series length): the window is then the last `length` values,\n * the values that leave or come back are removed or added exactly.\n */\nexport class RunningSum {\n private readonly values: number[] = [];\n /** Exact sum of the kept window (the last `keptLength` values). */\n private partials: number[] = [];\n private keptLength = 0;\n private stepLength = 0;\n private stepX = NaN;\n private stepPartials: number[] = [];\n /**\n * {@link resized} partials of the kept state by length, until the next {@link commit}: the calls of a loop (several\n * steps on one bar) move the same kept sum to the same lengths. Kept from the second step on, so that one step per\n * bar costs nothing more.\n */\n private readonly resizedByLength = new Map<number, readonly number[]>();\n private resizedSinceCommit = 0;\n\n /** The partials of the last `len` values (kept state, nothing added); a new array. */\n private resized(len: number): number[] {\n const cached = this.resizedByLength.get(len);\n if (cached) return cached.slice();\n const values = this.values;\n const n = values.length;\n const p = this.partials.slice();\n const kept = Math.min(this.keptLength, n);\n const want = Math.min(len, n);\n if (want < kept) for (let k = n - kept; k < n - want; k++) addExact(p, -values[k]!);\n else for (let k = n - kept - 1; k >= n - want; k--) addExact(p, values[k]!);\n if (this.resizedSinceCommit++ > 0) this.resizedByLength.set(len, p.slice());\n return p;\n }\n\n /**\n * The sum of the last `length` values with the (not na) value `x` added, from the kept state; the state is\n * unchanged until {@link commit}.\n *\n * @returns The sum, or NaN while fewer than `length` values exist (with `x`)\n */\n step(x: number, length: number): number {\n const n = this.values.length;\n const p = this.resized(length - 1);\n addExact(p, x);\n this.stepPartials = p;\n this.stepLength = Math.min(length, n + 1);\n this.stepX = x;\n return n + 1 >= length ? roundExact(p) : NaN;\n }\n\n /**\n * The sum of the last `length` values on a bar with an na value (no value added), from the kept state; the state is\n * unchanged until {@link commit}. With an unchanged length, it is the previous result.\n *\n * @returns The sum, or NaN while fewer than `length` values exist\n */\n stepNa(length: number): number {\n const n = this.values.length;\n const p = this.resized(length);\n this.stepPartials = p;\n this.stepLength = Math.min(length, n);\n this.stepX = NaN;\n return n > 0 && n >= length ? roundExact(p) : NaN;\n }\n\n /** Keeps the state of the last {@link step} or {@link stepNa}. */\n commit(): void {\n if (!Number.isNaN(this.stepX)) this.values.push(this.stepX);\n this.keptLength = this.stepLength;\n this.partials = this.stepPartials;\n this.resizedSinceCommit = 0;\n if (this.resizedByLength.size > 0) this.resizedByLength.clear();\n }\n}\n\n/** The running sums of `source` with the length `lengthAt(i)` on bar `i`. */\nfunction sumWindows(source: ArrayLike<number | null | undefined>, lengthAt: (i: number) => number): number[] {\n const out: number[] = new Array<number>(source.length);\n const sum = new RunningSum();\n for (let i = 0; i < source.length; i++) {\n const v = source[i];\n const len = lengthAt(i);\n out[i] = isNa(v) ? sum.stepNa(len) : sum.step(v as number, len);\n sum.commit();\n }\n return out;\n}\n\n/**\n * The sum of the last `length` non-na values on each bar, correctly rounded, as PineScript.\n *\n * @param source - Values (na: NaN, null, undefined or +/-Infinity, skipped)\n * @param length - Number of non-na values in the window\n * @returns The running sum per bar: NaN until `length` non-na values exist; a bar with an na value keeps the\n * previous result\n */\nexport function runningSum(source: ArrayLike<number | null | undefined>, length: number): number[] {\n const len = Math.floor(length);\n if (!(len >= 1)) return new Array<number>(source.length).fill(NaN);\n return sumWindows(source, () => len);\n}\n\n/** The values of a series length, floored, checked to be at least 1 on every bar. */\nfunction seriesLengths(lengths: ArrayLike<number>, count: number, name: string): number[] {\n if (lengths.length < count) {\n throw new Error(`${name}: the length series has ${lengths.length} values for ${count} bars`);\n }\n return Array.from({ length: count }, (_, i) => {\n const len = Math.floor(lengths[i]!);\n checkSumLength(name, len, i);\n if (!(len >= 1)) throw new Error(`${name}: length must be at least 1 (bar ${i}: ${lengths[i]})`);\n return len;\n });\n}\n\n/**\n * The sum of the last `lengths[i]` non-na values on each bar `i` (a series length), as PineScript computes it (see\n * {@link RunningSum}). A bar with an na value gives the sum of the last `lengths[i]` earlier values.\n *\n * @param name - Function name for the error messages\n */\nexport function runningSumSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n name = 'math.sum'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return sumWindows(source, (i) => lens[i]!);\n}\n\n/** Variance from the window sums of the values and of their squares; rules in {@link runningVariance}. */\nfunction varianceFromSums(\n source: ArrayLike<number | null | undefined>,\n sumOf: (src: ArrayLike<number | null | undefined>) => number[],\n lengthAt: (i: number) => number,\n biased: boolean\n): number[] {\n const squares = Array.from({ length: source.length }, (_, i) => {\n const v = source[i];\n return isNa(v) ? NaN : (v as number) * (v as number);\n });\n const sums = sumOf(source);\n const sumSquares = sumOf(squares);\n return sums.map((sum, i) => {\n const len = lengthAt(i);\n const mean = sum / len;\n const sq = sumSquares[i]!;\n return biased ? sq / len - mean * mean : sq / (len - 1) - (mean * sum) / (len - 1);\n });\n}\n\n/**\n * Window variance from the window sums of the values and of their squares, as PineScript computes it (#188):\n * biased `sumSq / n - mean * mean`, unbiased `sumSq / (n - 1) - mean * sum / (n - 1)`, with `mean = sum / n`.\n */\nexport function runningVariance(\n source: ArrayLike<number | null | undefined>,\n length: number,\n biased: boolean\n): number[] {\n const len = Math.floor(length);\n return varianceFromSums(source, (src) => runningSum(src, len), () => len, biased);\n}\n\n/** {@link runningVariance} with a series length (the length of bar `i` is `lengths[i]`). */\nexport function runningVarianceSeries(\n source: ArrayLike<number | null | undefined>,\n lengths: ArrayLike<number>,\n biased: boolean,\n name = 'ta.variance'\n): number[] {\n const lens = seriesLengths(lengths, source.length, name);\n return varianceFromSums(source, (src) => sumWindows(src, (i) => lens[i]!), (i) => lens[i]!, biased);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,oBAA+B;AAGxB,SAAS,KAAK,GAAuC;AAC1D,SAAO,MAAM,UAAa,MAAM,QAAQ,CAAC,OAAO,SAAS,CAAC;AAC5D;AAGA,SAAS,SAAS,GAAa,GAAiB;AAC9C,MAAI,IAAI;AACR,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,IAAI,EAAE,CAAC;AACX,QAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAG,EAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7C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,SAAI,EAAE,MAAM,SAAI,EAAE,MAAM,SAAI,GAAG,MAAM,CAc9G;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAU,EAChB,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAU,EAClB,OAAO,GAAE,OAAe,GACvB,MAAM,CAaR"}
@@ -38,6 +38,7 @@ function hasTimeZoneCase(name) {
38
38
  }
39
39
  const MS_PER_HOUR = 36e5;
40
40
  const MAX_CACHED_HOURS = 1e5;
41
+ const MAX_CACHED_DAYS = 1e5;
41
42
  const zones = /* @__PURE__ */ new Map();
42
43
  function resolveZone(timezone) {
43
44
  let zone = zones.get(timezone);
@@ -71,13 +72,25 @@ function resolveZone(timezone) {
71
72
  } catch {
72
73
  throw invalid();
73
74
  }
74
- zone = { kind: "iana", format, hours: /* @__PURE__ */ new Map() };
75
+ zone = { kind: "iana", format, dayStarts: /* @__PURE__ */ new Map(), hours: /* @__PURE__ */ new Map() };
75
76
  }
76
77
  zones.set(timezone, zone);
77
78
  return zone;
78
79
  }
80
+ function dayStartOffset(zone, day) {
81
+ let offset = zone.dayStarts.get(day);
82
+ if (offset === void 0) {
83
+ offset = formattedOffset(zone.format, day * MS_PER_DAY);
84
+ if (zone.dayStarts.size >= MAX_CACHED_DAYS) zone.dayStarts.clear();
85
+ zone.dayStarts.set(day, offset);
86
+ }
87
+ return offset;
88
+ }
79
89
  function offsetAt(zone, time) {
80
90
  if (zone.kind === "fixed") return zone.offsetMs;
91
+ const day = Math.floor(time / MS_PER_DAY);
92
+ const start = dayStartOffset(zone, day);
93
+ if (start === dayStartOffset(zone, day + 1)) return start;
81
94
  const hour = Math.floor(time / MS_PER_HOUR);
82
95
  let offset = zone.hours.get(hour);
83
96
  if (offset === void 0) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/time/timezone.ts"],
4
- "sourcesContent": ["/**\n * Time zone resolution for the calendar functions.\n *\n * PineScript accepts two time zone notations:\n * - UTC/GMT offset notation: \"UTC\", \"UTC-5\", \"UTC+05:30\", \"GMT+0530\", \"GMT+05:30:00\", up to \u00B118:00\n * - IANA time zone database names, case-sensitive: \"America/New_York\", \"Etc/UTC\", \"US/Eastern\", \"CET\"\n *\n * \"utc+2\", \"america/new_york\", \"UTC+5:3\", \"UTC+5:30:15\", \"GMT+18:01\", \"EST\", \"MST\" and \"HST\" are\n * errors in PineScript, and so here.\n *\n * Offsets of IANA zones (daylight saving time and historical changes included)\n * come from the host's `Intl.DateTimeFormat`, so no time zone data ships with the library.\n */\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_DAY = 86_400_000;\nconst MAX_OFFSET_SECONDS = 18 * 3600;\n\nconst OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\\d{1,2})(?::?(\\d{2})(?::?(\\d{2}))?)?)?$/;\n\n/** Time zone database names that PineScript rejects although `Intl` accepts them. */\nconst REJECTED_NAMES = new Set(['EST', 'MST', 'HST']);\n\nlet canonicalNames: Map<string, string> | undefined;\n\n/** False when `name` is a wrong-case spelling of a time zone name (`Intl` matches names case-insensitively). */\nfunction hasTimeZoneCase(name: string): boolean {\n if (name.split('/').some((segment) => !/^[A-Z]/.test(segment))) return false;\n canonicalNames ??= new Map(Intl.supportedValuesOf('timeZone').map((n) => [n.toLowerCase(), n]));\n const canonical = canonicalNames.get(name.toLowerCase());\n return canonical === undefined || canonical === name;\n}\n\ntype Zone =\n | { readonly kind: 'fixed'; readonly offsetMs: number }\n | {\n readonly kind: 'iana';\n readonly format: Intl.DateTimeFormat;\n /** Offset of each UTC hour (`floor(time / 1 h)`); null for an hour with an offset change inside */\n readonly hours: Map<number, number | null>;\n };\n\nconst MS_PER_HOUR = 3_600_000;\n/** Cached hours per zone before the cache restarts (about 11 years of hours) */\nconst MAX_CACHED_HOURS = 100_000;\n\nconst zones = new Map<string, Zone>();\n\nfunction resolveZone(timezone: string): Zone {\n let zone = zones.get(timezone);\n if (zone) return zone;\n\n const invalid = () =>\n new RangeError(\n `Invalid time zone \"${timezone}\": use UTC/GMT offset notation (\"UTC-5\", \"GMT+0530\") or an IANA name (\"America/New_York\")`\n );\n const m = OFFSET_NOTATION.exec(timezone);\n if (m) {\n const [, sign, h = '0', mi = '0', s] = m;\n const minutes = Number(mi);\n const seconds = s === undefined ? 0 : Number(s);\n if (minutes > 59 || seconds > 59 || (s !== undefined && h.length !== 2)) throw invalid();\n const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;\n if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();\n zone = { kind: 'fixed', offsetMs: (sign === '-' ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };\n } else {\n if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();\n let format: Intl.DateTimeFormat;\n try {\n format = new Intl.DateTimeFormat('en-US', {\n timeZone: timezone,\n hourCycle: 'h23',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n });\n } catch {\n throw invalid();\n }\n zone = { kind: 'iana', format, hours: new Map() };\n }\n zones.set(timezone, zone);\n return zone;\n}\n\n/**\n * Offset of the zone from UTC at instant `time`, in milliseconds (local = UTC + offset).\n * An offset change happens at most once in a UTC hour, so when the first and the last second of the hour have the\n * same offset, the whole hour has it: it is computed once and cached.\n */\nfunction offsetAt(zone: Zone, time: number): number {\n if (zone.kind === 'fixed') return zone.offsetMs;\n const hour = Math.floor(time / MS_PER_HOUR);\n let offset = zone.hours.get(hour);\n if (offset === undefined) {\n const first = formattedOffset(zone.format, hour * MS_PER_HOUR);\n const last = formattedOffset(zone.format, hour * MS_PER_HOUR + MS_PER_HOUR - MS_PER_SECOND);\n offset = first === last ? first : null;\n if (zone.hours.size >= MAX_CACHED_HOURS) zone.hours.clear();\n zone.hours.set(hour, offset);\n }\n return offset ?? formattedOffset(zone.format, time);\n}\n\n/** Offset of the zone at instant `time` (whole second), from the host's `Intl` time zone data. */\nfunction formattedOffset(format: Intl.DateTimeFormat, time: number): number {\n const wholeSecond = Math.floor(time / 1000) * 1000;\n const f: Record<string, number> = {};\n for (const part of format.formatToParts(wholeSecond)) {\n if (part.type !== 'literal') f[part.type] = Number(part.value);\n }\n const local = Date.UTC(f.year!, f.month! - 1, f.day!, f.hour!, f.minute!, f.second!);\n return local - wholeSecond;\n}\n\n/** Calendar fields of a UNIX time in a time zone. */\nexport interface ZonedFields {\n year: number;\n /** 1-12 */\n month: number;\n /** 1-31 */\n day: number;\n hour: number;\n minute: number;\n second: number;\n /** 1 = Sunday ... 7 = Saturday (PineScript dayofweek numbering) */\n dayOfWeek: number;\n}\n\n/** Offset of `timezone` from UTC at `time`, in milliseconds (local = UTC + offset). */\nexport function zoneOffset(time: number, timezone: string): number {\n return offsetAt(resolveZone(timezone), time);\n}\n\n/** Splits a UNIX time (ms) into calendar fields in `timezone`. */\nexport function zonedFields(time: number, timezone: string): ZonedFields {\n const local = new Date(time + offsetAt(resolveZone(timezone), time));\n return {\n year: local.getUTCFullYear(),\n month: local.getUTCMonth() + 1,\n day: local.getUTCDate(),\n hour: local.getUTCHours(),\n minute: local.getUTCMinutes(),\n second: local.getUTCSeconds(),\n dayOfWeek: local.getUTCDay() + 1,\n };\n}\n\n/**\n * Converts a wall-clock date and time in `timezone` to a UNIX time (ms).\n * Out-of-range fields roll over like `Date.UTC` (month 13 is January of the next year).\n *\n * As in PineScript: wall-clock times that occur twice (end of daylight saving time)\n * resolve to the later instant, and wall-clock times that do not exist (start of\n * daylight saving time) are shifted forward by the length of the gap.\n */\n/**\n * UNIX time (ms) of a UTC wall-clock date: Gregorian calendar from 1582-10-15, Julian calendar before it (as\n * PineScript: 1582-10-05 is 1582-10-15). Out-of-range fields roll over like `Date.UTC`.\n */\nexport function civilToUnix(year: number, month: number, day: number, hour = 0, minute = 0, second = 0): number {\n const gregorian = Date.UTC(year, month - 1, day, hour, minute, second);\n // normalized year / month / day of the Gregorian reading decides the calendar\n const d = new Date(Date.UTC(year, month - 1, 1));\n const y = d.getUTCFullYear();\n const m = d.getUTCMonth() + 1;\n if (y > 1582 || (y === 1582 && (m > 10 || (m === 10 && day >= 15)))) return gregorian;\n // Julian day number of y-m-1, then the day offset and the time of day\n const a = Math.floor((14 - m) / 12);\n const yy = y + 4800 - a;\n const mm = m + 12 * a - 3;\n const jdn = 1 + Math.floor((153 * mm + 2) / 5) + 365 * yy + Math.floor(yy / 4) - 32083;\n const days = jdn - 2440588 + (day - 1);\n return days * MS_PER_DAY + Date.UTC(1970, 0, 1, hour, minute, second);\n}\n\n/**\n * UNIX time (ms) of a wall-clock date in `timezone`. A wall time skipped by a clock change is read with the offset\n * before the change (02:30 on a 02:00 -> 03:00 night is 03:30 after it); a wall time that occurs twice gives the\n * later instant, or the earlier one with `earlier`.\n */\nexport function zonedToUnix(\n timezone: string,\n year: number,\n month: number,\n day: number,\n hour: number = 0,\n minute: number = 0,\n second: number = 0,\n earlier: boolean = false\n): number {\n const zone = resolveZone(timezone);\n const local = civilToUnix(year, month, day, hour, minute, second);\n if (zone.kind === 'fixed') return local - zone.offsetMs;\n\n // At most one offset transition happens within a day of `local`: the offsets\n // one day before and one day after are the two candidates.\n const before = offsetAt(zone, local - MS_PER_DAY);\n const after = offsetAt(zone, local + MS_PER_DAY);\n const candidates = [local - before, local - after].filter((t) => local - offsetAt(zone, t) === t);\n // a wall time that occurs twice: the later instant, or the earlier one with `earlier`\n if (candidates.length) return earlier ? Math.min(...candidates) : Math.max(...candidates);\n return local - before;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AACnB,MAAM,qBAAqB,KAAK;AAEhC,MAAM,kBAAkB;AAGxB,MAAM,iBAAiB,oBA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AQ,YAAY,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM;AAChE,MAAI,KAAK,SAAS,QAAS,QAAO,QAAQ,KAAK;AAI/C,QAAM,SAAS,SAAS,MAAM,QAAQ,UAAU;AAChD,QAAM,QAAQ,SAAS,MAAM,QAAQ,UAAU;AAC/C,QAAM,aAAa,CAAC,QAAQ,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,MAAM,QAAQ,SAAS,MAAM,CAAC,MAAM,CAAC;AAEhG,MAAI,WAAW,OAAQ,QAAO,UAAU,KAAK,IAAI,GAAG,UAAU,IAAI,KAAK,IAAI,GAAG,UAAU;AACxF,SAAO,QAAQ;AACjB;",
4
+ "sourcesContent": ["/**\n * Time zone resolution for the calendar functions.\n *\n * PineScript accepts two time zone notations:\n * - UTC/GMT offset notation: \"UTC\", \"UTC-5\", \"UTC+05:30\", \"GMT+0530\", \"GMT+05:30:00\", up to \u00B118:00\n * - IANA time zone database names, case-sensitive: \"America/New_York\", \"Etc/UTC\", \"US/Eastern\", \"CET\"\n *\n * \"utc+2\", \"america/new_york\", \"UTC+5:3\", \"UTC+5:30:15\", \"GMT+18:01\", \"EST\", \"MST\" and \"HST\" are\n * errors in PineScript, and so here.\n *\n * Offsets of IANA zones (daylight saving time and historical changes included)\n * come from the host's `Intl.DateTimeFormat`, so no time zone data ships with the library.\n */\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_DAY = 86_400_000;\nconst MAX_OFFSET_SECONDS = 18 * 3600;\n\nconst OFFSET_NOTATION = /^(?:UTC|GMT)(?:([+-])(\\d{1,2})(?::?(\\d{2})(?::?(\\d{2}))?)?)?$/;\n\n/** Time zone database names that PineScript rejects although `Intl` accepts them. */\nconst REJECTED_NAMES = new Set(['EST', 'MST', 'HST']);\n\nlet canonicalNames: Map<string, string> | undefined;\n\n/** False when `name` is a wrong-case spelling of a time zone name (`Intl` matches names case-insensitively). */\nfunction hasTimeZoneCase(name: string): boolean {\n if (name.split('/').some((segment) => !/^[A-Z]/.test(segment))) return false;\n canonicalNames ??= new Map(Intl.supportedValuesOf('timeZone').map((n) => [n.toLowerCase(), n]));\n const canonical = canonicalNames.get(name.toLowerCase());\n return canonical === undefined || canonical === name;\n}\n\ntype Zone =\n | { readonly kind: 'fixed'; readonly offsetMs: number }\n | {\n readonly kind: 'iana';\n readonly format: Intl.DateTimeFormat;\n /** Offset at the start of each UTC day (`floor(time / 1 day)`) */\n readonly dayStarts: Map<number, number>;\n /** Offset of each UTC hour (`floor(time / 1 h)`) of a day with an offset change; null for an hour with the\n * change inside */\n readonly hours: Map<number, number | null>;\n };\n\nconst MS_PER_HOUR = 3_600_000;\n/** Cached hours per zone before the cache restarts (about 11 years of hours) */\nconst MAX_CACHED_HOURS = 100_000;\n/** Cached days per zone before the cache restarts (about 270 years) */\nconst MAX_CACHED_DAYS = 100_000;\n\nconst zones = new Map<string, Zone>();\n\nfunction resolveZone(timezone: string): Zone {\n let zone = zones.get(timezone);\n if (zone) return zone;\n\n const invalid = () =>\n new RangeError(\n `Invalid time zone \"${timezone}\": use UTC/GMT offset notation (\"UTC-5\", \"GMT+0530\") or an IANA name (\"America/New_York\")`\n );\n const m = OFFSET_NOTATION.exec(timezone);\n if (m) {\n const [, sign, h = '0', mi = '0', s] = m;\n const minutes = Number(mi);\n const seconds = s === undefined ? 0 : Number(s);\n if (minutes > 59 || seconds > 59 || (s !== undefined && h.length !== 2)) throw invalid();\n const offsetSeconds = Number(h) * 3600 + minutes * 60 + seconds;\n if (offsetSeconds > MAX_OFFSET_SECONDS) throw invalid();\n zone = { kind: 'fixed', offsetMs: (sign === '-' ? -offsetSeconds : offsetSeconds) * MS_PER_SECOND };\n } else {\n if (REJECTED_NAMES.has(timezone) || !hasTimeZoneCase(timezone)) throw invalid();\n let format: Intl.DateTimeFormat;\n try {\n format = new Intl.DateTimeFormat('en-US', {\n timeZone: timezone,\n hourCycle: 'h23',\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n });\n } catch {\n throw invalid();\n }\n zone = { kind: 'iana', format, dayStarts: new Map(), hours: new Map() };\n }\n zones.set(timezone, zone);\n return zone;\n}\n\n/** Offset of the zone at the start of UTC day `day`, cached. */\nfunction dayStartOffset(zone: Zone & { kind: 'iana' }, day: number): number {\n let offset = zone.dayStarts.get(day);\n if (offset === undefined) {\n offset = formattedOffset(zone.format, day * MS_PER_DAY);\n if (zone.dayStarts.size >= MAX_CACHED_DAYS) zone.dayStarts.clear();\n zone.dayStarts.set(day, offset);\n }\n return offset;\n}\n\n/**\n * Offset of the zone from UTC at instant `time`, in milliseconds (local = UTC + offset).\n *\n * Two offset changes of a zone are always more than a day apart (the closest ones of the time zone database are 167\n * hours apart), so when a UTC day starts with the offset of the next day, the whole day has it: daily bars cost one\n * lookup per day. In a day with a change, an hour whose first and last second have the same offset has it (an offset\n * change happens at most once in an hour): it is computed once and cached.\n */\nfunction offsetAt(zone: Zone, time: number): number {\n if (zone.kind === 'fixed') return zone.offsetMs;\n const day = Math.floor(time / MS_PER_DAY);\n const start = dayStartOffset(zone, day);\n if (start === dayStartOffset(zone, day + 1)) return start;\n const hour = Math.floor(time / MS_PER_HOUR);\n let offset = zone.hours.get(hour);\n if (offset === undefined) {\n const first = formattedOffset(zone.format, hour * MS_PER_HOUR);\n const last = formattedOffset(zone.format, hour * MS_PER_HOUR + MS_PER_HOUR - MS_PER_SECOND);\n offset = first === last ? first : null;\n if (zone.hours.size >= MAX_CACHED_HOURS) zone.hours.clear();\n zone.hours.set(hour, offset);\n }\n return offset ?? formattedOffset(zone.format, time);\n}\n\n/** Offset of the zone at instant `time` (whole second), from the host's `Intl` time zone data. */\nfunction formattedOffset(format: Intl.DateTimeFormat, time: number): number {\n const wholeSecond = Math.floor(time / 1000) * 1000;\n const f: Record<string, number> = {};\n for (const part of format.formatToParts(wholeSecond)) {\n if (part.type !== 'literal') f[part.type] = Number(part.value);\n }\n const local = Date.UTC(f.year!, f.month! - 1, f.day!, f.hour!, f.minute!, f.second!);\n return local - wholeSecond;\n}\n\n/** Calendar fields of a UNIX time in a time zone. */\nexport interface ZonedFields {\n year: number;\n /** 1-12 */\n month: number;\n /** 1-31 */\n day: number;\n hour: number;\n minute: number;\n second: number;\n /** 1 = Sunday ... 7 = Saturday (PineScript dayofweek numbering) */\n dayOfWeek: number;\n}\n\n/** Offset of `timezone` from UTC at `time`, in milliseconds (local = UTC + offset). */\nexport function zoneOffset(time: number, timezone: string): number {\n return offsetAt(resolveZone(timezone), time);\n}\n\n/** Splits a UNIX time (ms) into calendar fields in `timezone`. */\nexport function zonedFields(time: number, timezone: string): ZonedFields {\n const local = new Date(time + offsetAt(resolveZone(timezone), time));\n return {\n year: local.getUTCFullYear(),\n month: local.getUTCMonth() + 1,\n day: local.getUTCDate(),\n hour: local.getUTCHours(),\n minute: local.getUTCMinutes(),\n second: local.getUTCSeconds(),\n dayOfWeek: local.getUTCDay() + 1,\n };\n}\n\n/**\n * Converts a wall-clock date and time in `timezone` to a UNIX time (ms).\n * Out-of-range fields roll over like `Date.UTC` (month 13 is January of the next year).\n *\n * As in PineScript: wall-clock times that occur twice (end of daylight saving time)\n * resolve to the later instant, and wall-clock times that do not exist (start of\n * daylight saving time) are shifted forward by the length of the gap.\n */\n/**\n * UNIX time (ms) of a UTC wall-clock date: Gregorian calendar from 1582-10-15, Julian calendar before it (as\n * PineScript: 1582-10-05 is 1582-10-15). Out-of-range fields roll over like `Date.UTC`.\n */\nexport function civilToUnix(year: number, month: number, day: number, hour = 0, minute = 0, second = 0): number {\n const gregorian = Date.UTC(year, month - 1, day, hour, minute, second);\n // normalized year / month / day of the Gregorian reading decides the calendar\n const d = new Date(Date.UTC(year, month - 1, 1));\n const y = d.getUTCFullYear();\n const m = d.getUTCMonth() + 1;\n if (y > 1582 || (y === 1582 && (m > 10 || (m === 10 && day >= 15)))) return gregorian;\n // Julian day number of y-m-1, then the day offset and the time of day\n const a = Math.floor((14 - m) / 12);\n const yy = y + 4800 - a;\n const mm = m + 12 * a - 3;\n const jdn = 1 + Math.floor((153 * mm + 2) / 5) + 365 * yy + Math.floor(yy / 4) - 32083;\n const days = jdn - 2440588 + (day - 1);\n return days * MS_PER_DAY + Date.UTC(1970, 0, 1, hour, minute, second);\n}\n\n/**\n * UNIX time (ms) of a wall-clock date in `timezone`. A wall time skipped by a clock change is read with the offset\n * before the change (02:30 on a 02:00 -> 03:00 night is 03:30 after it); a wall time that occurs twice gives the\n * later instant, or the earlier one with `earlier`.\n */\nexport function zonedToUnix(\n timezone: string,\n year: number,\n month: number,\n day: number,\n hour: number = 0,\n minute: number = 0,\n second: number = 0,\n earlier: boolean = false\n): number {\n const zone = resolveZone(timezone);\n const local = civilToUnix(year, month, day, hour, minute, second);\n if (zone.kind === 'fixed') return local - zone.offsetMs;\n\n // At most one offset transition happens within a day of `local`: the offsets\n // one day before and one day after are the two candidates.\n const before = offsetAt(zone, local - MS_PER_DAY);\n const after = offsetAt(zone, local + MS_PER_DAY);\n const candidates = [local - before, local - after].filter((t) => local - offsetAt(zone, t) === t);\n // a wall time that occurs twice: the later instant, or the earlier one with `earlier`\n if (candidates.length) return earlier ? Math.min(...candidates) : Math.max(...candidates);\n return local - before;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AACnB,MAAM,qBAAqB,KAAK;AAEhC,MAAM,kBAAkB;AAGxB,MAAM,iBAAiB,oBAAI,IAAI,CAAC,OAAO,OAAO,KAAK,CAAC;AAEpD,IAAI;AAGJ,SAAS,gBAAgB,MAAuB;AAC9C,MAAI,KAAK,MAAM,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,SAAS,KAAK,OAAO,CAAC,EAAG,QAAO;AACvE,qBAAmB,IAAI,IAAI,KAAK,kBAAkB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC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GAAG,MAAM,QAAQ,MAAM;AACtE;AAOO,SAAS,YACd,UACA,MACA,OACA,KACA,OAAe,GACf,SAAiB,GACjB,SAAiB,GACjB,UAAmB,OACX;AACR,QAAM,OAAO,YAAY,QAAQ;AACjC,QAAM,QAAQ,YAAY,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM;AAChE,MAAI,KAAK,SAAS,QAAS,QAAO,QAAQ,KAAK;AAI/C,QAAM,SAAS,SAAS,MAAM,QAAQ,UAAU;AAChD,QAAM,QAAQ,SAAS,MAAM,QAAQ,UAAU;AAC/C,QAAM,aAAa,CAAC,QAAQ,QAAQ,QAAQ,KAAK,EAAE,OAAO,CAAC,MAAM,QAAQ,SAAS,MAAM,CAAC,MAAM,CAAC;AAEhG,MAAI,WAAW,OAAQ,QAAO,UAAU,KAAK,IAAI,GAAG,UAAU,IAAI,KAAK,IAAI,GAAG,UAAU;AACxF,SAAO,QAAQ;AACjB;",
6
6
  "names": []
7
7
  }
@@ -215,9 +215,9 @@ export declare function linreg(): (barIndex: number, value: number, length: numb
215
215
  * - every call on a bar starts from the state of the earlier bars, so it gives the sum of its value and the last
216
216
  * `length - 1` kept values; the last call of the bar is the one kept for the later bars
217
217
  * - the length can change from one call to the next (also on the same bar): each call first moves the kept sum to
218
- * its own length as `math.sum` with a series length does (Kahan steps of the raw values)
218
+ * its own length, as `math.sum` with a series length
219
219
  * - a bar without a call is not in the history (as a call in an `if` block)
220
- * - the sum is the same compensated running sum as `math.sum` (bit for bit)
220
+ * - the sum is the correctly rounded window sum, as `math.sum` (bit for bit, #188)
221
221
  *
222
222
  * An na value is skipped as in `math.sum` (it returns the sum of the last `length` earlier values); when it is the
223
223
  * last call of a bar, the bar is not in the history (not measured).
@@ -253,7 +253,7 @@ export declare function sum(): (barIndex: number, value: number, length: number)
253
253
  export declare function sma(): (barIndex: number, value: number, length: number) => number;
254
254
  /**
255
255
  * One `ta.stdev(source, length, biased)` call site inside a `for` / `while` loop, called with
256
- * `(barIndex, value, length, biased?)` on each call: the running sums of the values and of their squares follow the
256
+ * `(barIndex, value, length, biased?)` on each call: the window sums of the values and of their squares follow the
257
257
  * rules of {@link sum}; the result is computed from them as `ta.stdev` (bit for bit).
258
258
  *
259
259
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/callsite/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAMhD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,EACnD,MAAM,EAAE,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC,EACnC,EAAE,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAC3C,GAAG,OAAO,EAAE,MAAM,EAAE,GACnB,KAAK,CAAC,CAAC,GAAG,MAAM,CAAC,CASnB;AAmBD;;;GAGG;AACH,wBAAgB,SAAS,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE7D;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAE9D;AAgCD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAEpF;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAErF;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,KAAK,MA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