oakscriptjs 0.9.4 → 0.9.6
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.
- package/dist/cjs/array/index.d.ts +88 -27
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +257 -117
- package/dist/cjs/array/index.js.map +3 -3
- package/dist/cjs/callsite/index.d.ts +122 -4
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +102 -3
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts +7 -3
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +6 -1
- package/dist/cjs/color/index.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/label/index.d.ts.map +1 -1
- package/dist/cjs/label/index.js +2 -1
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +1 -0
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/math/index.d.ts +79 -22
- package/dist/cjs/math/index.d.ts.map +1 -1
- package/dist/cjs/math/index.js +157 -43
- package/dist/cjs/math/index.js.map +3 -3
- package/dist/cjs/matrix/index.d.ts.map +1 -1
- package/dist/cjs/matrix/index.js +42 -36
- package/dist/cjs/matrix/index.js.map +2 -2
- package/dist/cjs/runtime/series.d.ts +9 -0
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +16 -2
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/index.d.ts +15 -31
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +32 -0
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +15 -2
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/str/index.d.ts +50 -38
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +43 -15
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/str/messageformat.d.ts +2 -1
- package/dist/cjs/str/messageformat.d.ts.map +1 -1
- package/dist/cjs/str/messageformat.js +4 -1
- package/dist/cjs/str/messageformat.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts +4 -0
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +26 -4
- package/dist/cjs/str/numberformat.js.map +3 -3
- package/dist/cjs/ta/index.d.ts +95 -46
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +193 -318
- package/dist/cjs/ta/index.js.map +3 -3
- package/dist/cjs/ta/running-sum.d.ts +54 -1
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +132 -47
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta-series.d.ts +4 -4
- package/dist/cjs/ta-series.d.ts.map +1 -1
- package/dist/cjs/ta-series.js +4 -3
- package/dist/cjs/ta-series.js.map +2 -2
- package/dist/cjs/time/datestring.d.ts +1 -0
- package/dist/cjs/time/datestring.d.ts.map +1 -1
- package/dist/cjs/time/datestring.js +7 -0
- package/dist/cjs/time/datestring.js.map +2 -2
- package/dist/cjs/time/index.d.ts.map +1 -1
- package/dist/cjs/time/index.js +2 -1
- package/dist/cjs/time/index.js.map +2 -2
- package/dist/cjs/time/session.d.ts +28 -9
- package/dist/cjs/time/session.d.ts.map +1 -1
- package/dist/cjs/time/session.js +74 -28
- package/dist/cjs/time/session.js.map +2 -2
- package/dist/cjs/time/timezone.d.ts +5 -0
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +15 -1
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/esm/array/index.d.ts +88 -27
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +408 -157
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts +122 -4
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +228 -8
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/color/index.d.ts +7 -3
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +15 -3
- package/dist/esm/color/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/label/index.d.ts.map +1 -1
- package/dist/esm/label/index.js +2 -1
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +3 -0
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/math/index.d.ts +79 -22
- package/dist/esm/math/index.d.ts.map +1 -1
- package/dist/esm/math/index.js +229 -63
- package/dist/esm/math/index.js.map +1 -1
- package/dist/esm/matrix/index.d.ts.map +1 -1
- package/dist/esm/matrix/index.js +57 -43
- package/dist/esm/matrix/index.js.map +1 -1
- package/dist/esm/runtime/series.d.ts +9 -0
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +18 -1
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/index.d.ts +15 -31
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +44 -1
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +22 -2
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/str/index.d.ts +50 -38
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +103 -52
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/str/messageformat.d.ts +2 -1
- package/dist/esm/str/messageformat.d.ts.map +1 -1
- package/dist/esm/str/messageformat.js +7 -2
- package/dist/esm/str/messageformat.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts +4 -0
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +38 -4
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts +95 -46
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +341 -414
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/running-sum.d.ts +54 -1
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +166 -60
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta-series.d.ts +4 -4
- package/dist/esm/ta-series.d.ts.map +1 -1
- package/dist/esm/ta-series.js +5 -4
- package/dist/esm/ta-series.js.map +1 -1
- package/dist/esm/time/datestring.d.ts +1 -0
- package/dist/esm/time/datestring.d.ts.map +1 -1
- package/dist/esm/time/datestring.js +12 -0
- package/dist/esm/time/datestring.js.map +1 -1
- package/dist/esm/time/index.d.ts.map +1 -1
- package/dist/esm/time/index.js +3 -1
- package/dist/esm/time/index.js.map +1 -1
- package/dist/esm/time/session.d.ts +28 -9
- package/dist/esm/time/session.d.ts.map +1 -1
- package/dist/esm/time/session.js +113 -42
- package/dist/esm/time/session.js.map +1 -1
- package/dist/esm/time/timezone.d.ts +5 -0
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +21 -1
- package/dist/esm/time/timezone.js.map +1 -1
- package/package.json +2 -2
- package/src/array/index.ts +382 -174
- package/src/callsite/index.ts +232 -8
- package/src/color/index.ts +15 -5
- package/src/index.ts +1 -1
- package/src/label/index.ts +2 -1
- package/src/linefill/index.ts +2 -0
- package/src/math/index.ts +261 -77
- package/src/matrix/index.ts +52 -52
- package/src/runtime/series.ts +22 -1
- package/src/script/index.ts +53 -1
- package/src/session/calendar.ts +22 -2
- package/src/str/index.ts +95 -51
- package/src/str/messageformat.ts +7 -2
- package/src/str/numberformat.ts +39 -4
- package/src/ta/index.ts +356 -458
- package/src/ta/running-sum.ts +187 -62
- package/src/ta-series.ts +8 -7
- package/src/time/datestring.ts +10 -0
- package/src/time/index.ts +3 -1
- package/src/time/session.ts +97 -47
- package/src/time/timezone.ts +21 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/callsite/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Per-call history of ta.* functions called in a conditional block.\n *\n * In PineScript, every ta.* call keeps its own history of the values it receives. A call inside\n * an `if` block receives values only on the bars where the block runs, so its history skips the\n * other bars: `ta.crossover(a, b)` is false on the first bar the block runs, and `ta.sma(x, 3)`\n * averages the last 3 values it received, not the last 3 bars.\n *\n * - {@link whenCalled}: vectorized, when the bars of the calls are known in advance.\n * - {@link crossover} / {@link crossunder} / {@link cross} / {@link barssince}: one stateful call site for bar\n * loops, called only on the bars where the Pine call runs.\n * - {@link lowest} / {@link highest}: `ta.lowest` / `ta.highest` with a series length (a different length on each\n * call), which PineScript computes with a state kept between calls.\n * - {@link linreg}: `ta.linreg` in a conditional block, whose window is kept by bar (not by call).\n *\n * Since PineScript v6, `and` / `or` are lazy: the right operand runs only when the left operand does not decide\n * the result. A ta.* call in the right operand of `a or b` runs on the bars where `a` is false, in `a and b` on the\n * bars where `a` is true, so it needs a call site too:\n *\n * ```typescript\n * // Pine: longCond = longUp or (src > sig and ta.barssince(longUp) <= lookback)\n * const since = callsite.whenCalled(longUp.map((u, i) => !u && src[i] > sig[i]), (c) => taCore.barssince(c.map(Boolean)), longUp);\n * // ta.barssince(longUp) only runs where longUp is false: it never sees true and stays na\n * ```\n *\n * ```typescript\n * // Pine: if inRange\n * // buy = ta.crossover(cumRsi, 60)\n * const buy = callsite.whenCalled(inRange, (a) => taCore.crossover(a, a.map(() => 60)), cumRsi);\n *\n * // Same call in a bar loop\n * const buyCross = callsite.crossover();\n * for (let i = 0; i < n; i++) {\n * if (inRange[i]) {\n * const buy = buyCross(cumRsi[i], 60);\n * }\n * }\n * ```\n *\n * @module callsite\n */\n\nimport type { Source } from '../types/index.js';\nimport { linreg as linregSeries } from '../ta/index.js';\n\n/**\n * Runs `fn` on the bars where `called` is true only, like a ta.* call inside an `if` block.\n * `fn` receives the values of `sources` on those bars, in order; its results are placed back on\n * the same bars. The other bars get na (NaN).\n *\n * @param called - true (or non-zero) on the bars where the call runs\n * @param fn - the calculation, for example `(x) => taCore.sma(x, 3)`\n * @param sources - the arguments of the call, one value per chart bar\n */\nexport function whenCalled<T extends number | boolean>(\n called: ArrayLike<boolean | number>,\n fn: (...values: number[][]) => ArrayLike<T>,\n ...sources: Source[]\n): Array<T | number> {\n const bars: number[] = [];\n for (let i = 0; i < called.length; i++) if (called[i]) bars.push(i);\n const result = fn(...sources.map(s => bars.map(i => s[i] ?? NaN)));\n const out = new Array<T | number>(called.length).fill(NaN);\n bars.forEach((bar, k) => {\n out[bar] = result[k]!;\n });\n return out;\n}\n\n/** A call site that keeps the two previous arguments (na before the first call). */\nfunction twoSeriesSite(test: (a: number, b: number, prevA: number, prevB: number) => boolean) {\n let prevA = NaN;\n let prevB = NaN;\n return (a: number, b: number): boolean => {\n const result = test(a, b, prevA, prevB);\n prevA = a;\n prevB = b;\n return result;\n };\n}\n\n/** One `ta.crossover(a, b)` call site: false on its first call, as its history is na. */\nexport function crossover(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a > b && pa <= pb);\n}\n\n/** One `ta.crossunder(a, b)` call site: false on its first call, as its history is na. */\nexport function crossunder(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a < b && pa >= pb);\n}\n\n/**\n * One `ta.barssince(condition)` call site: the number of calls since the condition was true on a call (0 on that\n * call), na before the first true condition. An na condition counts as false.\n */\nexport function barssince(): (condition: boolean | number) => number {\n let count = NaN;\n return (condition) => {\n if (condition && !Number.isNaN(condition)) count = 0;\n else if (!Number.isNaN(count)) count++;\n return count;\n };\n}\n\n/** One `ta.cross(a, b)` call site: false on its first call, as its history is na. */\nexport function cross(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => (a > b && pa <= pb) || (a < b && pa >= pb));\n}\n\n/** One `ta.lowest` / `ta.highest` call site with a series length; rules in {@link lowest}. */\nfunction extremeSite(isLowest: boolean): (value: number, length: number) => number {\n const better = isLowest ? (a: number, b: number) => a < b : (a: number, b: number) => a > b;\n const values: number[] = [];\n let extreme = NaN;\n let extremeAt = -1;\n let prevLength = NaN;\n const keep = (v: number, at: number) => {\n extreme = v;\n extremeAt = at;\n };\n const rescan = (i: number, length: number) => {\n extreme = NaN;\n for (let b = i; b > i - length && b >= 0; b--) {\n const v = values[b]!;\n if (!Number.isNaN(v) && (Number.isNaN(extreme) || !better(extreme, v))) keep(v, b);\n }\n };\n return (value, length) => {\n const i = values.length;\n values.push(value);\n if (Number.isNaN(value)) {\n extreme = NaN;\n prevLength = length;\n return NaN;\n }\n if (length > prevLength) {\n const from = Math.max(0, i - length + 1);\n const to = Math.max(0, i - prevLength + 1);\n if (values.slice(from, to).some(Number.isNaN)) keep(value, i);\n else {\n for (let b = from; b < to; b++) if (Number.isNaN(extreme) || better(values[b]!, extreme)) keep(values[b]!, b);\n if (Number.isNaN(extreme) || better(value, extreme)) keep(value, i);\n }\n } else if (length < prevLength || Number.isNaN(extreme) || i - extremeAt >= length) rescan(i, length);\n else if (better(value, extreme)) keep(value, i);\n prevLength = length;\n return i < length - 1 ? NaN : extreme;\n };\n}\n\n/**\n * One `ta.lowest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`.\n *\n * PineScript rules (measured with a length that changes on each bar):\n * - the extreme is kept with its bar; a new value that passes it replaces it; when the kept extreme is `length`\n * calls old, the last `length` values are scanned again (na skipped, the oldest wins a tie)\n * - a length smaller than on the previous call: the last `length` values are scanned again\n * - a length larger than on the previous call: the values that enter the window at its old end are compared with the\n * extreme; when one of them is na, the extreme restarts from the current value (the values in between are not read)\n * - an na value gives na and resets the extreme; na before call `length - 1`\n *\n * @example\n * ```typescript\n * // Pine: lowPrice = ta.lowest(close[1], lookback) // lookback changes per bar\n * const lowPrice = callsite.lowest();\n * const out = closes.map((_, i) => lowPrice(i > 0 ? closes[i - 1]! : NaN, lookback[i]!));\n * ```\n */\nexport function lowest(): (value: number, length: number) => number {\n return extremeSite(true);\n}\n\n/**\n * One `ta.highest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`. Same rules as {@link lowest}.\n */\nexport function highest(): (value: number, length: number) => number {\n return extremeSite(false);\n}\n\n/**\n * One `ta.linreg(source, length, offset)` call site in a conditional block, called with\n * `(barIndex, value, length, offset)` on the bars where the Pine call runs.\n *\n * PineScript rules (measured): `ta.linreg` keeps the values it receives in a ring of `length + 1` slots indexed by the\n * bar index, filled with 0 at the start and written only on the bars where it is called. The window is read from the\n * ring for the last `length` bars: a bar before the first call counts as 0, and a bar without a call holds the value of\n * the call `length + 1` bars earlier (0 if there was none). The result is na before bar `length - 1`. Called on every\n * bar, it equals `ta.linreg`.\n *\n * @example\n * ```typescript\n * // Pine: if bar_index >= 20\n * // a := ta.linreg(close, 10, 0)\n * const site = callsite.linreg();\n * const a = closes.map((c, i) => (i >= 20 ? site(i, c, 10, 0) : NaN));\n * ```\n */\nexport function linreg(): (barIndex: number, value: number, length: number, offset?: number) => number {\n let ring: number[] = [];\n return (barIndex, value, length, offset = 0) => {\n const len = Math.floor(length);\n if (ring.length !== len + 1) ring = new Array<number>(len + 1).fill(0);\n ring[barIndex % (len + 1)] = value;\n if (barIndex < len - 1) return NaN;\n const window = Array.from({ length: len }, (_, k) => ring[(barIndex - len + 1 + k) % (len + 1)]!);\n return linregSeries(window, len, offset)[len - 1]!;\n };\n}\n\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Per-call history of ta.* functions called in a conditional block.\n *\n * In PineScript, every ta.* call keeps its own history of the values it receives. A call inside\n * an `if` block receives values only on the bars where the block runs, so its history skips the\n * other bars: `ta.crossover(a, b)` is false on the first bar the block runs, and `ta.sma(x, 3)`\n * averages the last 3 values it received, not the last 3 bars.\n *\n * - {@link whenCalled}: vectorized, when the bars of the calls are known in advance.\n * - {@link crossover} / {@link crossunder} / {@link cross} / {@link barssince}: one stateful call site for bar\n * loops, called only on the bars where the Pine call runs.\n * - {@link lowest} / {@link highest}: `ta.lowest` / `ta.highest` with a series length (a different length on each\n * call), which PineScript computes with a state kept between calls.\n * - {@link lowestByBar} / {@link highestByBar} / {@link linreg}: `ta.lowest` / `ta.highest` / `ta.linreg` in a\n * conditional block, whose history is kept by bar (not by call).\n * - {@link sum} / {@link sma}: `math.sum` / `ta.sma` in a `for` / `while` loop, called several times on one bar.\n *\n * Since PineScript v6, `and` / `or` are lazy: the right operand runs only when the left operand does not decide\n * the result. A ta.* call in the right operand of `a or b` runs on the bars where `a` is false, in `a and b` on the\n * bars where `a` is true, so it needs a call site too:\n *\n * ```typescript\n * // Pine: longCond = longUp or (src > sig and ta.barssince(longUp) <= lookback)\n * const since = callsite.whenCalled(longUp.map((u, i) => !u && src[i] > sig[i]), (c) => taCore.barssince(c.map(Boolean)), longUp);\n * // ta.barssince(longUp) only runs where longUp is false: it never sees true and stays na\n * ```\n *\n * ```typescript\n * // Pine: if inRange\n * // buy = ta.crossover(cumRsi, 60)\n * const buy = callsite.whenCalled(inRange, (a) => taCore.crossover(a, a.map(() => 60)), cumRsi);\n *\n * // Same call in a bar loop\n * const buyCross = callsite.crossover();\n * for (let i = 0; i < n; i++) {\n * if (inRange[i]) {\n * const buy = buyCross(cumRsi[i], 60);\n * }\n * }\n * ```\n *\n * @module callsite\n */\n\nimport type { Source } from '../types/index.js';\nimport { linreg as linregSeries } from '../ta/index.js';\nimport { RunningSum, isNa } from '../ta/running-sum.js';\nimport { seededRandom } from '../math/index.js';\n\n/**\n * Runs `fn` on the bars where `called` is true only, like a ta.* call inside an `if` block.\n * `fn` receives the values of `sources` on those bars, in order; its results are placed back on\n * the same bars. The other bars get na (NaN).\n *\n * @param called - true (or non-zero) on the bars where the call runs\n * @param fn - the calculation, for example `(x) => taCore.sma(x, 3)`\n * @param sources - the arguments of the call, one value per chart bar\n */\nexport function whenCalled<T extends number | boolean>(\n called: ArrayLike<boolean | number>,\n fn: (...values: number[][]) => ArrayLike<T>,\n ...sources: Source[]\n): Array<T | number> {\n const bars: number[] = [];\n for (let i = 0; i < called.length; i++) if (called[i]) bars.push(i);\n const result = fn(...sources.map(s => bars.map(i => s[i] ?? NaN)));\n const out = new Array<T | number>(called.length).fill(NaN);\n bars.forEach((bar, k) => {\n out[bar] = result[k]!;\n });\n return out;\n}\n\n/**\n * A call site that keeps the arguments of the last call where both were not na (na before such a call), as\n * ta.crossover / ta.crossunder / ta.cross.\n */\nfunction twoSeriesSite(test: (a: number, b: number, prevA: number, prevB: number) => boolean) {\n let prevA = NaN;\n let prevB = NaN;\n return (a: number, b: number): boolean => {\n const result = test(a, b, prevA, prevB);\n if (!Number.isNaN(a) && !Number.isNaN(b)) {\n prevA = a;\n prevB = b;\n }\n return result;\n };\n}\n\n/**\n * One `ta.crossover(a, b)` call site: compared with the last call where both arguments were not na; false before\n * such a call.\n */\nexport function crossover(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a > b && pa <= pb);\n}\n\n/**\n * One `ta.crossunder(a, b)` call site: compared with the last call where both arguments were not na; false before\n * such a call.\n */\nexport function crossunder(): (a: number, b: number) => boolean {\n return twoSeriesSite((a, b, pa, pb) => a < b && pa >= pb);\n}\n\n/**\n * One `ta.barssince(condition)` call site: the number of calls since the condition was true on a call (0 on that\n * call), na before the first true condition. An na condition counts as false.\n */\nexport function barssince(): (condition: boolean | number) => number {\n let count = NaN;\n return (condition) => {\n if (condition && !Number.isNaN(condition)) count = 0;\n else if (!Number.isNaN(count)) count++;\n return count;\n };\n}\n\n/**\n * One `ta.cross(a, b)` call site, rules of `ta.cross`: the site keeps the side of the last call where `a` was\n * strictly above or strictly below `b` (none before such a call; equal values and na arguments do not change it),\n * and is true when the arguments are strictly on the other side. False with an na argument.\n */\nexport function cross(): (a: number, b: number) => boolean {\n let side = 0; // -1: last strictly below, 1: last strictly above, 0: none yet\n return (a, b) => {\n if (Number.isNaN(a) || Number.isNaN(b)) return false;\n const result = (side < 0 && a > b) || (side > 0 && a < b);\n if (a < b) side = -1;\n else if (a > b) side = 1;\n return result;\n };\n}\n\n/** One `ta.lowest` / `ta.highest` call site with a series length; rules in {@link lowest}. */\nfunction extremeSite(isLowest: boolean): (value: number, length: number) => number {\n const better = isLowest ? (a: number, b: number) => a < b : (a: number, b: number) => a > b;\n const values: number[] = [];\n let extreme = NaN;\n let extremeAt = -1;\n let prevLength = NaN;\n const keep = (v: number, at: number) => {\n extreme = v;\n extremeAt = at;\n };\n const rescan = (i: number, length: number) => {\n extreme = NaN;\n for (let b = i; b > i - length && b >= 0; b--) {\n const v = values[b]!;\n if (!Number.isNaN(v) && (Number.isNaN(extreme) || !better(extreme, v))) keep(v, b);\n }\n };\n return (value, length) => {\n const i = values.length;\n values.push(value);\n if (Number.isNaN(value)) {\n extreme = NaN;\n prevLength = length;\n return NaN;\n }\n if (length > prevLength) {\n const from = Math.max(0, i - length + 1);\n const to = Math.max(0, i - prevLength + 1);\n if (values.slice(from, to).some(Number.isNaN)) keep(value, i);\n else {\n for (let b = from; b < to; b++) if (Number.isNaN(extreme) || better(values[b]!, extreme)) keep(values[b]!, b);\n if (Number.isNaN(extreme) || better(value, extreme)) keep(value, i);\n }\n } else if (length < prevLength || Number.isNaN(extreme) || i - extremeAt >= length) rescan(i, length);\n else if (better(value, extreme)) keep(value, i);\n prevLength = length;\n return i < length - 1 ? NaN : extreme;\n };\n}\n\n/**\n * One `ta.lowest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`.\n *\n * PineScript rules (measured with a length that changes on each bar):\n * - the extreme is kept with its bar; a new value that passes it replaces it; when the kept extreme is `length`\n * calls old, the last `length` values are scanned again (na skipped, the oldest wins a tie)\n * - a length smaller than on the previous call: the last `length` values are scanned again\n * - a length larger than on the previous call: the values that enter the window at its old end are compared with the\n * extreme; when one of them is na, the extreme restarts from the current value (the values in between are not read)\n * - an na value gives na and resets the extreme; na before call `length - 1`\n *\n * @example\n * ```typescript\n * // Pine: lowPrice = ta.lowest(close[1], lookback) // lookback changes per bar\n * const lowPrice = callsite.lowest();\n * const out = closes.map((_, i) => lowPrice(i > 0 ? closes[i - 1]! : NaN, lookback[i]!));\n * ```\n */\nexport function lowest(): (value: number, length: number) => number {\n return extremeSite(true);\n}\n\n/**\n * One `ta.highest(source, length)` call site with a series length (a different length on each call), called with\n * `(value, length)`. Same rules as {@link lowest}.\n */\nexport function highest(): (value: number, length: number) => number {\n return extremeSite(false);\n}\n\n/** One `ta.lowest` / `ta.highest` call site whose history is kept by bar; rules in {@link lowestByBar}. */\nfunction extremeByBarSite(isLowest: boolean): (barIndex: number, value: number, length: number) => number {\n const better = isLowest ? (a: number, b: number) => a < b : (a: number, b: number) => a > b;\n let ring: number[] = [];\n let extreme = NaN;\n let extremeAt = -1;\n return (barIndex, value, length) => {\n const len = Math.floor(length);\n if (ring.length !== len + 1) {\n ring = new Array<number>(len + 1).fill(0);\n extreme = NaN;\n }\n ring[barIndex % (len + 1)] = value;\n if (Number.isNaN(extreme) || better(value, extreme)) {\n extreme = value;\n extremeAt = barIndex;\n } else if (barIndex - extremeAt >= len) {\n extreme = NaN;\n for (let b = barIndex - len + 1; b <= barIndex; b++) {\n const v = ring[b % (len + 1)]!;\n if (!Number.isNaN(v) && (Number.isNaN(extreme) || better(v, extreme))) {\n extreme = v;\n extremeAt = b;\n }\n }\n }\n return barIndex < len - 1 ? NaN : extreme;\n };\n}\n\n/**\n * One `ta.lowest(source, length)` call site in a conditional block whose history is kept by bar (not by call), called\n * with `(barIndex, value, length)` on the bars where the Pine call runs.\n *\n * PineScript rules (measured on a call in a ternary branch, length 6):\n * - the values are kept in a ring of `length + 1` slots indexed by the bar index, filled with 0 at the start and\n * written only on the bars where the call runs: a bar before the first call counts as 0, and a bar without a call\n * holds the value of the call `length + 1` bars earlier (0 if there was none)\n * - on a call, the value replaces the kept extreme when there is none or when it is strictly lower; only otherwise,\n * when the kept extreme is `length` bars old, the last `length` bars are read again from the ring (the oldest bar\n * wins a tie)\n * - na before bar `length - 1` (by bar, not by call)\n *\n * {@link lowest} keeps the history by call instead; both rules were measured, on different scripts.\n *\n * @example\n * ```typescript\n * // Pine: lo = cond ? ta.lowest(low, 6) : na\n * const site = callsite.lowestByBar();\n * const lo = lows.map((v, i) => (cond[i] ? site(i, v, 6) : NaN));\n * ```\n */\nexport function lowestByBar(): (barIndex: number, value: number, length: number) => number {\n return extremeByBarSite(true);\n}\n\n/**\n * One `ta.highest(source, length)` call site in a conditional block whose history is kept by bar, called with\n * `(barIndex, value, length)`. Same rules as {@link lowestByBar} (a value replaces the kept extreme when it is\n * strictly higher).\n */\nexport function highestByBar(): (barIndex: number, value: number, length: number) => number {\n return extremeByBarSite(false);\n}\n\n/**\n * One `ta.linreg(source, length, offset)` call site in a conditional block, called with\n * `(barIndex, value, length, offset)` on the bars where the Pine call runs.\n *\n * PineScript rules (measured): `ta.linreg` keeps the values it receives in a ring of `length + 1` slots indexed by the\n * bar index, filled with 0 at the start and written only on the bars where it is called. The window is read from the\n * ring for the last `length` bars: a bar before the first call counts as 0, and a bar without a call holds the value of\n * the call `length + 1` bars earlier (0 if there was none). The result is na before bar `length - 1`. Called on every\n * bar, it equals `ta.linreg`.\n *\n * @example\n * ```typescript\n * // Pine: if bar_index >= 20\n * // a := ta.linreg(close, 10, 0)\n * const site = callsite.linreg();\n * const a = closes.map((c, i) => (i >= 20 ? site(i, c, 10, 0) : NaN));\n * ```\n */\nexport function linreg(): (barIndex: number, value: number, length: number, offset?: number) => number {\n let ring: number[] = [];\n return (barIndex, value, length, offset = 0) => {\n const len = Math.floor(length);\n if (ring.length !== len + 1) ring = new Array<number>(len + 1).fill(0);\n ring[barIndex % (len + 1)] = value;\n if (barIndex < len - 1) return NaN;\n const window = Array.from({ length: len }, (_, k) => ring[(barIndex - len + 1 + k) % (len + 1)]!);\n return linregSeries(window, len, offset)[len - 1]!;\n };\n}\n\n\n/**\n * One `math.sum` call site in a loop; rules in {@link sum}. With `squares`, it also keeps the running sum of the\n * squared values (for {@link stdev}). Returns `[sum, sumOfSquares]` (NaN when not kept).\n */\nfunction loopSumSite(\n name: string,\n squares: boolean\n): (barIndex: number, value: number, length: number) => [number, number] {\n const running = new RunningSum();\n const runningSq = new RunningSum();\n let lastBar = NaN;\n let pending = false;\n return (barIndex, value, length) => {\n const len = Math.floor(length);\n if (!(len >= 1)) throw new Error(`callsite.${name}: length must be at least 1 (got ${length})`);\n if (barIndex !== lastBar) {\n if (pending) {\n running.commit();\n if (squares) runningSq.commit();\n }\n pending = false;\n lastBar = barIndex;\n }\n if (isNa(value)) {\n pending = false;\n return [running.stepNa(len), squares ? runningSq.stepNa(len) : NaN];\n }\n const x = value;\n const out: [number, number] = [running.step(x, len), squares ? runningSq.step(x * x, len) : NaN];\n pending = true;\n return out;\n };\n}\n\n/**\n * One `math.sum(source, length)` call site inside a `for` / `while` loop, called with `(barIndex, value, length)` on\n * each call.\n *\n * PineScript rules (measured on calls in loops, 1 to 3 calls per bar, and bars without a call):\n * - the call site keeps one history value per bar: the value of its last call on that bar\n * - every call on a bar starts from the state of the earlier bars, so it gives the sum of its value and the last\n * `length - 1` kept values; the last call of the bar is the one kept for the later bars\n * - the length can change from one call to the next (also on the same bar): each call first moves the kept sum to\n * its own length as `math.sum` with a series length does (Kahan steps of the raw values)\n * - a bar without a call is not in the history (as a call in an `if` block)\n * - the sum is the same compensated running sum as `math.sum` (bit for bit)\n *\n * An na value is skipped as in `math.sum` (it returns the sum of the last `length` earlier values); when it is the\n * last call of a bar, the bar is not in the history (not measured).\n *\n * @example\n * ```typescript\n * // Pine: for i = 0 to 2\n * // s = math.sum(close * (1 + 0.01 * i), 7)\n * const site = callsite.sum();\n * for (let b = 0; b < closes.length; b++) {\n * for (let i = 0; i <= 2; i++) {\n * const s = site(b, closes[b]! * (1 + 0.01 * i), 7);\n * }\n * }\n * ```\n */\nexport function sum(): (barIndex: number, value: number, length: number) => number {\n const site = loopSumSite('sum', false);\n return (barIndex, value, length) => site(barIndex, value, length)[0];\n}\n\n/**\n * One `ta.sma(source, length)` call site inside a `for` / `while` loop, called with `(barIndex, value, length)` on\n * each call: {@link sum} divided by the length (same rules).\n *\n * @example\n * ```typescript\n * // Pine: evaluate(ratio) => ta.sma(gann(ratio), n) // called once per ratio in a while loop\n * const site = callsite.sma();\n * for (let b = 0; b < closes.length; b++) {\n * for (const ratio of ratios) {\n * const avg = site(b, gann(b, ratio), n);\n * }\n * }\n * ```\n */\nexport function sma(): (barIndex: number, value: number, length: number) => number {\n const site = loopSumSite('sma', false);\n return (barIndex, value, length) => site(barIndex, value, length)[0] / Math.floor(length);\n}\n\n/**\n * One `ta.stdev(source, length, biased)` call site inside a `for` / `while` loop, called with\n * `(barIndex, value, length, biased?)` on each call: the running sums of the values and of their squares follow the\n * rules of {@link sum}; the result is computed from them as `ta.stdev` (bit for bit).\n *\n * @example\n * ```typescript\n * // Pine: for len in lengths\n * // [mid, up, lo] = ta.bb(close, len, 2)\n * const avgSite = callsite.sma();\n * const devSite = callsite.stdev();\n * for (let b = 0; b < closes.length; b++) {\n * for (const len of lengths) {\n * const mid = avgSite(b, closes[b]!, len);\n * const dev = devSite(b, closes[b]!, len);\n * }\n * }\n * ```\n */\nexport function stdev(): (barIndex: number, value: number, length: number, biased?: boolean) => number {\n const site = loopSumSite('stdev', true);\n return (barIndex, value, length, biased = true) => {\n const len = Math.floor(length);\n const [s, sq] = site(barIndex, value, length);\n const mean = s / len;\n const variance = biased ? sq / len - mean * mean : sq / (len - 1) - (mean * s) / (len - 1);\n if (!biased && len <= 1) return NaN;\n return Number.isNaN(variance) ? NaN : variance > 0 ? Math.sqrt(variance) : 0;\n };\n}\n\n/**\n * One `math.random(min, max, seed)` call site: PineScript keeps one generator per call site, so two call sites\n * with the same seed give the same sequence. Called with `(min?, max?)` once per bar.\n *\n * @example\n * ```typescript\n * // Pine: a = math.random(0, 1, 42), b = math.random(0, 1, 42) // a == b on every bar\n * const a = callsite.random(42);\n * const b = callsite.random(42);\n * ```\n */\nexport function random(seed: number): (min?: number, max?: number) => number {\n return seededRandom(seed);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6CA,gBAAuC;AACvC,yBAAiC;AACjC,kBAA6B;AAWtB,SAAS,WACd,QACA,OACG,SACgB;AACnB,QAAM,OAAiB,CAAC;AACxB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,IAAK,KAAI,OAAO,CAAC,EAAG,MAAK,KAAK,CAAC;AAClE,QAAM,SAAS,GAAG,GAAG,QAAQ,IAAI,OAAK,KAAK,IAAI,OAAK,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC;AACjE,QAAM,MAAM,IAAI,MAAkB,OAAO,MAAM,EAAE,KAAK,GAAG;AACzD,OAAK,QAAQ,CAAC,KAAK,MAAM;AACvB,QAAI,GAAG,IAAI,OAAO,CAAC;AAAA,EACrB,CAAC;AACD,SAAO;AACT;AAMA,SAAS,cAAc,MAAuE;AAC5F,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,SAAO,CAAC,GAAW,MAAuB;AACxC,UAAM,SAAS,KAAK,GAAG,GAAG,OAAO,KAAK;AACtC,QAAI,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,GAAG;AACxC,cAAQ;AACR,cAAQ;AAAA,IACV;AACA,WAAO;AAAA,EACT;AACF;AAMO,SAAS,YAA+C;AA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AI,MAAM,WAAW,IAAI,KAAK,KAAK,QAAQ,IAAI;AAAA,EAC7E;AACF;AAaO,SAAS,OAAO,MAAsD;AAC3E,aAAO,0BAAa,IAAI;AAC1B;",
|
|
6
6
|
"names": ["linregSeries"]
|
|
7
7
|
}
|
|
@@ -72,7 +72,10 @@ export declare function from_hex(hex: string, transp?: simple_float): string;
|
|
|
72
72
|
* - Replaces the transparency with the new value
|
|
73
73
|
* - Useful for creating semi-transparent versions of existing colors
|
|
74
74
|
* - PineScript clamps the transparency to 0..100 (`color.new(c, 140)` is fully transparent, `color.new(c, -5)` is
|
|
75
|
-
* opaque); an `na` transparency is fully transparent
|
|
75
|
+
* opaque); an `na` transparency is fully transparent (measured: the colour is not na, its RGB is kept)
|
|
76
|
+
* - an `na` colour (null / undefined) gives black with the new transparency: `color.new(na, 30)` is
|
|
77
|
+
* `rgba(0, 0, 0, 0.7)`, as PineScript does for an na colour variable (measured, #150). In PineScript, the constant
|
|
78
|
+
* `color.new(color(na), 30)` is computed at compile time and stays na; a JS function cannot tell the two apart.
|
|
76
79
|
*
|
|
77
80
|
* @example
|
|
78
81
|
* ```typescript
|
|
@@ -82,7 +85,7 @@ export declare function from_hex(hex: string, transp?: simple_float): string;
|
|
|
82
85
|
* color.new_color(red, 100) // Returns: "rgba(255, 0, 0, 0)" - Fully transparent
|
|
83
86
|
* ```
|
|
84
87
|
*/
|
|
85
|
-
export declare function new_color(baseColor: color, transp: simple_float): string;
|
|
88
|
+
export declare function new_color(baseColor: color | null | undefined, transp: simple_float): string;
|
|
86
89
|
/**
|
|
87
90
|
* Extracts the red component from a color.
|
|
88
91
|
*
|
|
@@ -136,6 +139,7 @@ export declare function b(clr: color): int;
|
|
|
136
139
|
* - Converts alpha channel (0-1) to transparency (0-100)
|
|
137
140
|
* - PineScript stores the alpha as a byte (0-255) and returns an integer transparency:
|
|
138
141
|
* `color.t(color.new(c, 33.3))` is 33
|
|
142
|
+
* - an `na` colour (null / undefined) is fully transparent: 100
|
|
139
143
|
*
|
|
140
144
|
* @example
|
|
141
145
|
* ```typescript
|
|
@@ -144,7 +148,7 @@ export declare function b(clr: color): int;
|
|
|
144
148
|
* color.t(color.rgb(255, 0, 0, 100)) // Returns: 100 (fully transparent)
|
|
145
149
|
* ```
|
|
146
150
|
*/
|
|
147
|
-
export declare function t(clr: color): float;
|
|
151
|
+
export declare function t(clr: color | null | undefined): float;
|
|
148
152
|
/**
|
|
149
153
|
* Aqua/Cyan color constant
|
|
150
154
|
* @constant {string} #00BCD4 - RGB(0, 188, 212)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/color/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAcrF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAUvG;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CASnE;AAED
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/color/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAcrF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,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AAM,YAAY,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,MAAM,YAAY,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,GAAG,YAAY,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,MAAM,YAAY,CAAC;AAEhC;;;GAGG;AACH,eAAO,MAAM,IAAI,YAAY,CAAC;AAE9B;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAY,CAAC;AAE/B;;;GAGG;AACH,eAAO,MAAM,MAAM,YAAY,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,KAAK,EACnB,SAAS,EAAE,KAAK,EAChB,YAAY,EAAE,KAAK,EACnB,SAAS,EAAE,KAAK,GACf,MAAM,CA8BR;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,IAAI,GAAG,EAAE,CAAC"}
|
package/dist/cjs/color/index.js
CHANGED
|
@@ -67,6 +67,7 @@ function from_hex(hex, transp) {
|
|
|
67
67
|
return rgb(r2, g2, b2, transp);
|
|
68
68
|
}
|
|
69
69
|
function new_color(baseColor, transp) {
|
|
70
|
+
if (baseColor === null || baseColor === void 0) return rgb(0, 0, 0, transp);
|
|
70
71
|
const rgba = (0, import_parse.parseColor)(baseColor);
|
|
71
72
|
return rgb(rgba.r, rgba.g, rgba.b, transp);
|
|
72
73
|
}
|
|
@@ -80,6 +81,7 @@ function b(clr) {
|
|
|
80
81
|
return (0, import_parse.parseColor)(clr).b;
|
|
81
82
|
}
|
|
82
83
|
function t(clr) {
|
|
84
|
+
if (clr === null || clr === void 0) return 100;
|
|
83
85
|
return Math.round((1 - (0, import_parse.alphaByte)((0, import_parse.parseColor)(clr).a) / 255) * 100);
|
|
84
86
|
}
|
|
85
87
|
const aqua = "#00BCD4";
|
|
@@ -114,7 +116,10 @@ function from_gradient(value, bottom_value, top_value, bottom_color, top_color)
|
|
|
114
116
|
const c2 = rgba(top_color);
|
|
115
117
|
const a = c1.a * (1 - k) + c2.a * k;
|
|
116
118
|
if (a === 0) return transparent;
|
|
117
|
-
const
|
|
119
|
+
const scale = a / 255;
|
|
120
|
+
const w1 = c1.a / 255;
|
|
121
|
+
const w2 = c2.a / 255;
|
|
122
|
+
const mix = (x1, x2) => Math.floor((w1 * x1 * (1 - k) + w2 * x2 * k) / scale);
|
|
118
123
|
const [r2, g2, b2] = [mix(c1.r, c2.r), mix(c1.g, c2.g), mix(c1.b, c2.b)];
|
|
119
124
|
const alpha = Math.floor(a);
|
|
120
125
|
return alpha === 255 ? `rgb(${r2}, ${g2}, ${b2})` : `rgba(${r2}, ${g2}, ${b2}, ${alpha / 255})`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Color namespace\n * Mirrors PineScript's color.* functions for color creation and manipulation.\n *\n * @remarks\n * All color functions in this namespace follow PineScript v6 API specifications.\n * Colors are represented as RGB or RGBA strings.\n * Transparency values range from 0 (fully opaque) to 100 (fully transparent).\n *\n * @version 6\n */\n\nimport type { color, int, float, simple_int, simple_float } from '../types/index.js';\nimport { alphaByte, parseColor } from './parse.js';\n\n/** Channel of color.rgb: na is 0, a fraction is truncated. */\nconst channel = (v: number): int =>\n v === null || v === undefined || Number.isNaN(v) ? 0 : Math.max(0, Math.min(255, Math.trunc(v)));\n\n/**\n * Alpha (0-1) of a transparency given to color.rgb / color.new: na is fully transparent, clamped to 0..100.\n * `1 - t / 100` as in PineScript: `color.new(c, 90)` has the alpha byte 25 (0.09999999999999998 * 255 rounded).\n */\nconst alphaOf = (transp: number): float =>\n transp === null || Number.isNaN(transp) ? 0 : 1 - Math.max(0, Math.min(100, transp)) / 100;\n\n/**\n * Creates a color from RGB values with optional transparency.\n *\n * @param red - Red component (0-255, values are clamped)\n * @param green - Green component (0-255, values are clamped)\n * @param blue - Blue component (0-255, values are clamped)\n * @param transp - Optional transparency (0-100). 0 = opaque, 100 = fully transparent\n * @returns Color string in rgb() or rgba() format\n *\n * @remarks\n * - RGB values are automatically clamped to the 0-255 range\n * - Transparency of 0 or omitted results in rgb() format\n * - Transparency > 0 results in rgba() format\n * - Transparency is converted to alpha channel (0-1 range)\n *\n * PineScript rules:\n * - an `na` channel is 0; a fractional channel is truncated (127.6 is 127)\n * - the transparency is clamped to 0..100 (140 is fully transparent, -5 is opaque); an `na` transparency is fully\n * transparent\n *\n * @example\n * ```typescript\n * color.rgb(255, 0, 0) // Returns: \"rgb(255, 0, 0)\" - Red\n * color.rgb(0, 255, 0, 50) // Returns: \"rgba(0, 255, 0, 0.5)\" - Semi-transparent green\n * color.rgb(300, 0, 0) // Returns: \"rgb(255, 0, 0)\" - Clamped to 255\n * ```\n */\nexport function rgb(red: simple_int, green: simple_int, blue: simple_int, transp?: simple_float): string {\n const r = channel(red);\n const g = channel(green);\n const b = channel(blue);\n const a = transp !== undefined ? alphaOf(transp) : 1;\n\n if (a === 1) {\n return `rgb(${r}, ${g}, ${b})`;\n }\n return `rgba(${r}, ${g}, ${b}, ${a})`;\n}\n\n/**\n * Creates a color from a hexadecimal string with optional transparency.\n *\n * @param hex - Hex color string (with or without '#' prefix, e.g., \"#FF0000\" or \"FF0000\")\n * @param transp - Optional transparency (0-100). 0 = opaque, 100 = fully transparent\n * @returns Color string in rgb() or rgba() format\n *\n * @remarks\n * - Accepts hex strings with or without '#' prefix\n * - Case-insensitive (accepts both \"FF0000\" and \"ff0000\")\n * - Must be 6 characters (excluding '#')\n * - Format: RRGGBB where each component is 00-FF\n *\n * @example\n * ```typescript\n * color.from_hex(\"#FF0000\") // Returns: \"rgb(255, 0, 0)\" - Red\n * color.from_hex(\"00FF00\", 50) // Returns: \"rgba(0, 255, 0, 0.5)\" - Semi-transparent green\n * color.from_hex(\"#0000FF\") // Returns: \"rgb(0, 0, 255)\" - Blue\n * color.from_hex(\"FFA500\") // Returns: \"rgb(255, 165, 0)\" - Orange\n * ```\n */\nexport function from_hex(hex: string, transp?: simple_float): string {\n // Remove # if present\n hex = hex.replace('#', '');\n\n const r = parseInt(hex.substring(0, 2), 16);\n const g = parseInt(hex.substring(2, 4), 16);\n const b = parseInt(hex.substring(4, 6), 16);\n\n return rgb(r, g, b, transp);\n}\n\n/**\n * Creates a new color with modified transparency, preserving RGB components.\n *\n * @param baseColor - The base color to modify\n * @param transp - New transparency value (0-100). 0 = opaque, 100 = fully transparent\n * @returns New color with updated transparency\n *\n * @remarks\n * - Preserves the RGB values from the base color\n * - Replaces the transparency with the new value\n * - Useful for creating semi-transparent versions of existing colors\n * - PineScript clamps the transparency to 0..100 (`color.new(c, 140)` is fully transparent, `color.new(c, -5)` is\n * opaque); an `na` transparency is fully transparent\n *\n * @example\n * ```typescript\n * const red = color.rgb(255, 0, 0)\n * color.new_color(red, 50) // Returns: \"rgba(255, 0, 0, 0.5)\" - Semi-transparent red\n * color.new_color(red, 0) // Returns: \"rgb(255, 0, 0)\" - Fully opaque\n * color.new_color(red, 100) // Returns: \"rgba(255, 0, 0, 0)\" - Fully transparent\n * ```\n */\nexport function new_color(baseColor: color, transp: simple_float): string {\n // Parse the color and apply transparency\n const rgba = parseColor(baseColor);\n return rgb(rgba.r, rgba.g, rgba.b, transp);\n}\n\n/**\n * Extracts the red component from a color.\n *\n * @param clr - The color to extract from\n * @returns Red component value (0-255)\n *\n * @example\n * ```typescript\n * color.r(color.rgb(255, 128, 64)) // Returns: 255\n * color.r(color.from_hex(\"#FF0000\")) // Returns: 255\n * color.r(color.from_hex(\"#FFA500\")) // Returns: 255 (orange)\n * ```\n */\nexport function r(clr: color): int {\n return parseColor(clr).r;\n}\n\n/**\n * Extracts the green component from a color.\n *\n * @param clr - The color to extract from\n * @returns Green component value (0-255)\n *\n * @example\n * ```typescript\n * color.g(color.rgb(255, 128, 64)) // Returns: 128\n * color.g(color.from_hex(\"#00FF00\")) // Returns: 255\n * color.g(color.from_hex(\"#FFA500\")) // Returns: 165 (orange)\n * ```\n */\nexport function g(clr: color): int {\n return parseColor(clr).g;\n}\n\n/**\n * Extracts the blue component from a color.\n *\n * @param clr - The color to extract from\n * @returns Blue component value (0-255)\n *\n * @example\n * ```typescript\n * color.b(color.rgb(255, 128, 64)) // Returns: 64\n * color.b(color.from_hex(\"#0000FF\")) // Returns: 255\n * color.b(color.from_hex(\"#FFA500\")) // Returns: 0 (orange)\n * ```\n */\nexport function b(clr: color): int {\n return parseColor(clr).b;\n}\n\n/**\n * Extracts the transparency component from a color.\n *\n * @param clr - The color to extract from\n * @returns Transparency value (0-100). 0 = fully opaque, 100 = fully transparent\n *\n * @remarks\n * - Returns 0 for colors without transparency (rgb format)\n * - Converts alpha channel (0-1) to transparency (0-100)\n * - PineScript stores the alpha as a byte (0-255) and returns an integer transparency:\n * `color.t(color.new(c, 33.3))` is 33\n *\n * @example\n * ```typescript\n * color.t(color.rgb(255, 0, 0)) // Returns: 0 (opaque)\n * color.t(color.rgb(255, 0, 0, 50)) // Returns: 50\n * color.t(color.rgb(255, 0, 0, 100)) // Returns: 100 (fully transparent)\n * ```\n */\nexport function t(clr: color): float {\n return Math.round((1 - alphaByte(parseColor(clr).a) / 255) * 100);\n}\n\n// Predefined color constants of PineScript v6.\n// PineScript v5 differs for red (#FF5252), teal (#00897B) and yellow (#FFEB3B).\n/**\n * Aqua/Cyan color constant\n * @constant {string} #00BCD4 - RGB(0, 188, 212)\n */\nexport const aqua = '#00BCD4';\n\n/**\n * Black color constant\n * @constant {string} #363A45 - RGB(54, 58, 69)\n */\nexport const black = '#363A45';\n\n/**\n * Blue color constant\n * @constant {string} #2962FF - RGB(41, 98, 255)\n */\nexport const blue = '#2962FF';\n\n/**\n * Fuchsia/Magenta color constant\n * @constant {string} #E040FB - RGB(224, 64, 251)\n */\nexport const fuchsia = '#E040FB';\n\n/**\n * Gray color constant\n * @constant {string} #787B86 - RGB(120, 123, 134)\n */\nexport const gray = '#787B86';\n\n/**\n * Green color constant (same as lime)\n * @constant {string} #4CAF50 - RGB(76, 175, 80)\n */\nexport const green = '#4CAF50';\n\n/**\n * Lime color constant (same as green)\n * @constant {string} #00E676 - RGB(0, 230, 118)\n */\nexport const lime = '#00E676';\n\n/**\n * Maroon color constant\n * @constant {string} #880E4F - RGB(136, 14, 79)\n */\nexport const maroon = '#880E4F';\n\n/**\n * Navy color constant\n * @constant {string} #311B92 - RGB(49, 27, 146)\n */\nexport const navy = '#311B92';\n\n/**\n * Olive color constant\n * @constant {string} #808000 - RGB(128, 128, 0)\n */\nexport const olive = '#808000';\n\n/**\n * Orange color constant\n * @constant {string} #FF9800 - RGB(255, 152, 0)\n */\nexport const orange = '#FF9800';\n\n/**\n * Purple color constant\n * @constant {string} #9C27B0 - RGB(156, 39, 176)\n */\nexport const purple = '#9C27B0';\n\n/**\n * Red color constant\n * @constant {string} #F23645 - RGB(242, 54, 69)\n */\nexport const red = '#F23645';\n\n/**\n * Silver color constant\n * @constant {string} #B2B5BE - RGB(178, 181, 190)\n */\nexport const silver = '#B2B5BE';\n\n/**\n * Teal color constant\n * @constant {string} #089981 - RGB(8, 153, 129)\n */\nexport const teal = '#089981';\n\n/**\n * White color constant\n * @constant {string} #FFFFFF - RGB(255, 255, 255)\n */\nexport const white = '#FFFFFF';\n\n/**\n * Yellow color constant\n * @constant {string} #FDD835 - RGB(253, 216, 53)\n */\nexport const yellow = '#FDD835';\n\n/**\n * Creates a color from a gradient based on value position.\n *\n * @param value - Value to calculate position-dependent color\n * @param bottom_value - Bottom position value corresponding to bottom_color\n * @param top_value - Top position value corresponding to top_color\n * @param bottom_color - Bottom position color\n * @param top_color - Top position color\n * @returns Color calculated from linear gradient\n *\n * @remarks\n * PineScript rules:\n * - If value <= bottom_value, returns bottom_color; else if value >= top_value, returns top_color\n * - An inverted range (bottom_value > top_value) returns bottom_color, wherever the value is\n * - Otherwise the colours are mixed with their transparency (premultiplied alpha, alpha as a byte); the RGB channels\n * and the alpha are truncated. PineScript's float rounding order is not known: a channel can differ by 1 when the\n * exact result is an integer (same RGB at both ends)\n * - An na value or bottom_value / top_value, or bottom_value == top_value, gives a fully transparent colour\n * - An na colour counts as fully transparent\n * - Works with rgb(), rgba() and hex (#RRGGBB, #RRGGBBAA) colours\n *\n * @example\n * ```typescript\n * // Value at middle of range gets middle color\n * const midColor = color.from_gradient(50, 0, 100,\n * color.rgb(255, 0, 0), // Red at bottom\n * color.rgb(0, 255, 0) // Green at top\n * ); // Returns color between red and green\n *\n * // Value at extremes\n * const lowColor = color.from_gradient(-10, 0, 100, red, green); // Returns red\n * const highColor = color.from_gradient(150, 0, 100, red, green); // Returns green\n * ```\n */\nexport function from_gradient(\n value: float,\n bottom_value: float,\n top_value: float,\n bottom_color: color,\n top_color: color\n): string {\n const transparent = 'rgba(0, 0, 0, 0)';\n if ([value, bottom_value, top_value].some((v) => v === null || v === undefined || Number.isNaN(v)) || bottom_value === top_value) {\n return transparent;\n }\n const k =\n value <= bottom_value || bottom_value > top_value\n ? 0\n : value >= top_value\n ? 1\n : (value - bottom_value) / (top_value - bottom_value);\n // alpha as a byte (0-255), as PineScript stores it; an na colour (null / undefined) is fully transparent\n const rgba = (c: color) => {\n if (c === null || c === undefined) return { r: 0, g: 0, b: 0, a: 0 };\n const p = parseColor(c);\n return { r: p.r, g: p.g, b: p.b, a: alphaByte(p.a) };\n };\n const c1 = rgba(bottom_color);\n const c2 = rgba(top_color);\n const a = c1.a * (1 - k) + c2.a * k;\n if (a === 0) return transparent;\n // operation order with the fewest differences to PineScript (channels as 0-1, alpha as a byte)\n const mix = (x1: number, x2: number) => Math.floor((((x1 / 255) * c1.a) * (1 - k) + ((x2 / 255) * c2.a) * k) / (a / 255));\n const [r, g, b] = [mix(c1.r, c2.r), mix(c1.g, c2.g), mix(c1.b, c2.b)];\n const alpha = Math.floor(a);\n return alpha === 255 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${alpha / 255})`;\n}\n\n/**\n * Alias for new_color function.\n * Creates a new color with specified transparency from an existing color.\n *\n * @param baseColor - The base color\n * @param transp - Transparency value (0-100). 0 = fully opaque, 100 = fully transparent\n * @returns New color with applied transparency\n *\n * @remarks\n * This is an alias for `new_color()` to match PineScript's `color.new()` syntax.\n *\n * @example\n * ```typescript\n * const redColor = color.rgb(255, 0, 0);\n * const transparentRed = color.new(redColor, 50); // 50% transparent red\n * ```\n */\nexport { new_color as new };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAAsC;AAGtC,MAAM,UAAU,CAAC,MACf,MAAM,QAAQ,MAAM,UAAa,OAAO,MAAM,CAAC,IAAI,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC;AAMjG,MAAM,UAAU,CAAC,WACf,WAAW,QAAQ,OAAO,MAAM,MAAM,IAAI,IAAI,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC,IAAI;AA6BlF,SAAS,IAAIA,MAAiBC,QAAmBC,OAAkB,QAA+B;AACvG,QAAMC,KAAI,QAAQH,IAAG;AACrB,QAAMI,KAAI,QAAQH,MAAK;AACvB,QAAMI,KAAI,QAAQH,KAAI;AACtB,QAAM,IAAI,WAAW,SAAY,QAAQ,MAAM,IAAI;AAEnD,MAAI,MAAM,GAAG;AACX,WAAO,OAAOC,EAAC,KAAKC,EAAC,KAAKC,EAAC;AAAA,EAC7B;AACA,SAAO,QAAQF,EAAC,KAAKC,EAAC,KAAKC,EAAC,KAAK,CAAC;AACpC;AAuBO,SAAS,SAAS,KAAa,QAA+B;AAEnE,QAAM,IAAI,QAAQ,KAAK,EAAE;AAEzB,QAAMF,KAAI,SAAS,IAAI,UAAU,GAAG,CAAC,GAAG,EAAE;AAC1C,QAAMC,KAAI,SAAS,IAAI,UAAU,GAAG,CAAC,GAAG,EAAE;AAC1C,QAAMC,KAAI,SAAS,IAAI,UAAU,GAAG,CAAC,GAAG,EAAE;AAE1C,SAAO,IAAIF,IAAGC,IAAGC,IAAG,MAAM;AAC5B;
|
|
4
|
+
"sourcesContent": ["/**\n * Color namespace\n * Mirrors PineScript's color.* functions for color creation and manipulation.\n *\n * @remarks\n * All color functions in this namespace follow PineScript v6 API specifications.\n * Colors are represented as RGB or RGBA strings.\n * Transparency values range from 0 (fully opaque) to 100 (fully transparent).\n *\n * @version 6\n */\n\nimport type { color, int, float, simple_int, simple_float } from '../types/index.js';\nimport { alphaByte, parseColor } from './parse.js';\n\n/** Channel of color.rgb: na is 0, a fraction is truncated. */\nconst channel = (v: number): int =>\n v === null || v === undefined || Number.isNaN(v) ? 0 : Math.max(0, Math.min(255, Math.trunc(v)));\n\n/**\n * Alpha (0-1) of a transparency given to color.rgb / color.new: na is fully transparent, clamped to 0..100.\n * `1 - t / 100` as in PineScript: `color.new(c, 90)` has the alpha byte 25 (0.09999999999999998 * 255 rounded).\n */\nconst alphaOf = (transp: number): float =>\n transp === null || Number.isNaN(transp) ? 0 : 1 - Math.max(0, Math.min(100, transp)) / 100;\n\n/**\n * Creates a color from RGB values with optional transparency.\n *\n * @param red - Red component (0-255, values are clamped)\n * @param green - Green component (0-255, values are clamped)\n * @param blue - Blue component (0-255, values are clamped)\n * @param transp - Optional transparency (0-100). 0 = opaque, 100 = fully transparent\n * @returns Color string in rgb() or rgba() format\n *\n * @remarks\n * - RGB values are automatically clamped to the 0-255 range\n * - Transparency of 0 or omitted results in rgb() format\n * - Transparency > 0 results in rgba() format\n * - Transparency is converted to alpha channel (0-1 range)\n *\n * PineScript rules:\n * - an `na` channel is 0; a fractional channel is truncated (127.6 is 127)\n * - the transparency is clamped to 0..100 (140 is fully transparent, -5 is opaque); an `na` transparency is fully\n * transparent\n *\n * @example\n * ```typescript\n * color.rgb(255, 0, 0) // Returns: \"rgb(255, 0, 0)\" - Red\n * color.rgb(0, 255, 0, 50) // Returns: \"rgba(0, 255, 0, 0.5)\" - Semi-transparent green\n * color.rgb(300, 0, 0) // Returns: \"rgb(255, 0, 0)\" - Clamped to 255\n * ```\n */\nexport function rgb(red: simple_int, green: simple_int, blue: simple_int, transp?: simple_float): string {\n const r = channel(red);\n const g = channel(green);\n const b = channel(blue);\n const a = transp !== undefined ? alphaOf(transp) : 1;\n\n if (a === 1) {\n return `rgb(${r}, ${g}, ${b})`;\n }\n return `rgba(${r}, ${g}, ${b}, ${a})`;\n}\n\n/**\n * Creates a color from a hexadecimal string with optional transparency.\n *\n * @param hex - Hex color string (with or without '#' prefix, e.g., \"#FF0000\" or \"FF0000\")\n * @param transp - Optional transparency (0-100). 0 = opaque, 100 = fully transparent\n * @returns Color string in rgb() or rgba() format\n *\n * @remarks\n * - Accepts hex strings with or without '#' prefix\n * - Case-insensitive (accepts both \"FF0000\" and \"ff0000\")\n * - Must be 6 characters (excluding '#')\n * - Format: RRGGBB where each component is 00-FF\n *\n * @example\n * ```typescript\n * color.from_hex(\"#FF0000\") // Returns: \"rgb(255, 0, 0)\" - Red\n * color.from_hex(\"00FF00\", 50) // Returns: \"rgba(0, 255, 0, 0.5)\" - Semi-transparent green\n * color.from_hex(\"#0000FF\") // Returns: \"rgb(0, 0, 255)\" - Blue\n * color.from_hex(\"FFA500\") // Returns: \"rgb(255, 165, 0)\" - Orange\n * ```\n */\nexport function from_hex(hex: string, transp?: simple_float): string {\n // Remove # if present\n hex = hex.replace('#', '');\n\n const r = parseInt(hex.substring(0, 2), 16);\n const g = parseInt(hex.substring(2, 4), 16);\n const b = parseInt(hex.substring(4, 6), 16);\n\n return rgb(r, g, b, transp);\n}\n\n/**\n * Creates a new color with modified transparency, preserving RGB components.\n *\n * @param baseColor - The base color to modify\n * @param transp - New transparency value (0-100). 0 = opaque, 100 = fully transparent\n * @returns New color with updated transparency\n *\n * @remarks\n * - Preserves the RGB values from the base color\n * - Replaces the transparency with the new value\n * - Useful for creating semi-transparent versions of existing colors\n * - PineScript clamps the transparency to 0..100 (`color.new(c, 140)` is fully transparent, `color.new(c, -5)` is\n * opaque); an `na` transparency is fully transparent (measured: the colour is not na, its RGB is kept)\n * - an `na` colour (null / undefined) gives black with the new transparency: `color.new(na, 30)` is\n * `rgba(0, 0, 0, 0.7)`, as PineScript does for an na colour variable (measured, #150). In PineScript, the constant\n * `color.new(color(na), 30)` is computed at compile time and stays na; a JS function cannot tell the two apart.\n *\n * @example\n * ```typescript\n * const red = color.rgb(255, 0, 0)\n * color.new_color(red, 50) // Returns: \"rgba(255, 0, 0, 0.5)\" - Semi-transparent red\n * color.new_color(red, 0) // Returns: \"rgb(255, 0, 0)\" - Fully opaque\n * color.new_color(red, 100) // Returns: \"rgba(255, 0, 0, 0)\" - Fully transparent\n * ```\n */\nexport function new_color(baseColor: color | null | undefined, transp: simple_float): string {\n if (baseColor === null || baseColor === undefined) return rgb(0, 0, 0, transp); // na colour: black\n // Parse the color and apply transparency\n const rgba = parseColor(baseColor);\n return rgb(rgba.r, rgba.g, rgba.b, transp);\n}\n\n/**\n * Extracts the red component from a color.\n *\n * @param clr - The color to extract from\n * @returns Red component value (0-255)\n *\n * @example\n * ```typescript\n * color.r(color.rgb(255, 128, 64)) // Returns: 255\n * color.r(color.from_hex(\"#FF0000\")) // Returns: 255\n * color.r(color.from_hex(\"#FFA500\")) // Returns: 255 (orange)\n * ```\n */\nexport function r(clr: color): int {\n return parseColor(clr).r;\n}\n\n/**\n * Extracts the green component from a color.\n *\n * @param clr - The color to extract from\n * @returns Green component value (0-255)\n *\n * @example\n * ```typescript\n * color.g(color.rgb(255, 128, 64)) // Returns: 128\n * color.g(color.from_hex(\"#00FF00\")) // Returns: 255\n * color.g(color.from_hex(\"#FFA500\")) // Returns: 165 (orange)\n * ```\n */\nexport function g(clr: color): int {\n return parseColor(clr).g;\n}\n\n/**\n * Extracts the blue component from a color.\n *\n * @param clr - The color to extract from\n * @returns Blue component value (0-255)\n *\n * @example\n * ```typescript\n * color.b(color.rgb(255, 128, 64)) // Returns: 64\n * color.b(color.from_hex(\"#0000FF\")) // Returns: 255\n * color.b(color.from_hex(\"#FFA500\")) // Returns: 0 (orange)\n * ```\n */\nexport function b(clr: color): int {\n return parseColor(clr).b;\n}\n\n/**\n * Extracts the transparency component from a color.\n *\n * @param clr - The color to extract from\n * @returns Transparency value (0-100). 0 = fully opaque, 100 = fully transparent\n *\n * @remarks\n * - Returns 0 for colors without transparency (rgb format)\n * - Converts alpha channel (0-1) to transparency (0-100)\n * - PineScript stores the alpha as a byte (0-255) and returns an integer transparency:\n * `color.t(color.new(c, 33.3))` is 33\n * - an `na` colour (null / undefined) is fully transparent: 100\n *\n * @example\n * ```typescript\n * color.t(color.rgb(255, 0, 0)) // Returns: 0 (opaque)\n * color.t(color.rgb(255, 0, 0, 50)) // Returns: 50\n * color.t(color.rgb(255, 0, 0, 100)) // Returns: 100 (fully transparent)\n * ```\n */\nexport function t(clr: color | null | undefined): float {\n if (clr === null || clr === undefined) return 100;\n return Math.round((1 - alphaByte(parseColor(clr).a) / 255) * 100);\n}\n\n// Predefined color constants of PineScript v6.\n// PineScript v5 differs for red (#FF5252), teal (#00897B) and yellow (#FFEB3B).\n/**\n * Aqua/Cyan color constant\n * @constant {string} #00BCD4 - RGB(0, 188, 212)\n */\nexport const aqua = '#00BCD4';\n\n/**\n * Black color constant\n * @constant {string} #363A45 - RGB(54, 58, 69)\n */\nexport const black = '#363A45';\n\n/**\n * Blue color constant\n * @constant {string} #2962FF - RGB(41, 98, 255)\n */\nexport const blue = '#2962FF';\n\n/**\n * Fuchsia/Magenta color constant\n * @constant {string} #E040FB - RGB(224, 64, 251)\n */\nexport const fuchsia = '#E040FB';\n\n/**\n * Gray color constant\n * @constant {string} #787B86 - RGB(120, 123, 134)\n */\nexport const gray = '#787B86';\n\n/**\n * Green color constant (same as lime)\n * @constant {string} #4CAF50 - RGB(76, 175, 80)\n */\nexport const green = '#4CAF50';\n\n/**\n * Lime color constant (same as green)\n * @constant {string} #00E676 - RGB(0, 230, 118)\n */\nexport const lime = '#00E676';\n\n/**\n * Maroon color constant\n * @constant {string} #880E4F - RGB(136, 14, 79)\n */\nexport const maroon = '#880E4F';\n\n/**\n * Navy color constant\n * @constant {string} #311B92 - RGB(49, 27, 146)\n */\nexport const navy = '#311B92';\n\n/**\n * Olive color constant\n * @constant {string} #808000 - RGB(128, 128, 0)\n */\nexport const olive = '#808000';\n\n/**\n * Orange color constant\n * @constant {string} #FF9800 - RGB(255, 152, 0)\n */\nexport const orange = '#FF9800';\n\n/**\n * Purple color constant\n * @constant {string} #9C27B0 - RGB(156, 39, 176)\n */\nexport const purple = '#9C27B0';\n\n/**\n * Red color constant\n * @constant {string} #F23645 - RGB(242, 54, 69)\n */\nexport const red = '#F23645';\n\n/**\n * Silver color constant\n * @constant {string} #B2B5BE - RGB(178, 181, 190)\n */\nexport const silver = '#B2B5BE';\n\n/**\n * Teal color constant\n * @constant {string} #089981 - RGB(8, 153, 129)\n */\nexport const teal = '#089981';\n\n/**\n * White color constant\n * @constant {string} #FFFFFF - RGB(255, 255, 255)\n */\nexport const white = '#FFFFFF';\n\n/**\n * Yellow color constant\n * @constant {string} #FDD835 - RGB(253, 216, 53)\n */\nexport const yellow = '#FDD835';\n\n/**\n * Creates a color from a gradient based on value position.\n *\n * @param value - Value to calculate position-dependent color\n * @param bottom_value - Bottom position value corresponding to bottom_color\n * @param top_value - Top position value corresponding to top_color\n * @param bottom_color - Bottom position color\n * @param top_color - Top position color\n * @returns Color calculated from linear gradient\n *\n * @remarks\n * PineScript rules:\n * - If value <= bottom_value, returns bottom_color; else if value >= top_value, returns top_color\n * - An inverted range (bottom_value > top_value) returns bottom_color, wherever the value is\n * - Otherwise the colours are mixed with their transparency (premultiplied alpha, alpha as a byte); the RGB channels\n * and the alpha are truncated. PineScript's float rounding order is not known: a channel can differ by 1 when the\n * exact result is an integer (same RGB at both ends)\n * - An na value or bottom_value / top_value, or bottom_value == top_value, gives a fully transparent colour\n * - An na colour counts as fully transparent\n * - Works with rgb(), rgba() and hex (#RRGGBB, #RRGGBBAA) colours\n *\n * @example\n * ```typescript\n * // Value at middle of range gets middle color\n * const midColor = color.from_gradient(50, 0, 100,\n * color.rgb(255, 0, 0), // Red at bottom\n * color.rgb(0, 255, 0) // Green at top\n * ); // Returns color between red and green\n *\n * // Value at extremes\n * const lowColor = color.from_gradient(-10, 0, 100, red, green); // Returns red\n * const highColor = color.from_gradient(150, 0, 100, red, green); // Returns green\n * ```\n */\nexport function from_gradient(\n value: float,\n bottom_value: float,\n top_value: float,\n bottom_color: color,\n top_color: color\n): string {\n const transparent = 'rgba(0, 0, 0, 0)';\n if ([value, bottom_value, top_value].some((v) => v === null || v === undefined || Number.isNaN(v)) || bottom_value === top_value) {\n return transparent;\n }\n const k =\n value <= bottom_value || bottom_value > top_value\n ? 0\n : value >= top_value\n ? 1\n : (value - bottom_value) / (top_value - bottom_value);\n // alpha as a byte (0-255), as PineScript stores it; an na colour (null / undefined) is fully transparent\n const rgba = (c: color) => {\n if (c === null || c === undefined) return { r: 0, g: 0, b: 0, a: 0 };\n const p = parseColor(c);\n return { r: p.r, g: p.g, b: p.b, a: alphaByte(p.a) };\n };\n const c1 = rgba(bottom_color);\n const c2 = rgba(top_color);\n const a = c1.a * (1 - k) + c2.a * k;\n if (a === 0) return transparent;\n // PineScript order (bit for bit, #146): premultiplied channels ((alpha / 255) * channel) * weight, divided by the\n // byte-alpha mix / 255, truncated. At an end (k = 0 / 1) this is floor(x * a / a): the end colour or one unit less.\n const scale = a / 255;\n const w1 = c1.a / 255;\n const w2 = c2.a / 255;\n const mix = (x1: number, x2: number) => Math.floor(((w1 * x1) * (1 - k) + (w2 * x2) * k) / scale);\n const [r, g, b] = [mix(c1.r, c2.r), mix(c1.g, c2.g), mix(c1.b, c2.b)];\n const alpha = Math.floor(a);\n return alpha === 255 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${alpha / 255})`;\n}\n\n/**\n * Alias for new_color function.\n * Creates a new color with specified transparency from an existing color.\n *\n * @param baseColor - The base color\n * @param transp - Transparency value (0-100). 0 = fully opaque, 100 = fully transparent\n * @returns New color with applied transparency\n *\n * @remarks\n * This is an alias for `new_color()` to match PineScript's `color.new()` syntax.\n *\n * @example\n * ```typescript\n * const redColor = color.rgb(255, 0, 0);\n * const transparentRed = color.new(redColor, 50); // 50% transparent red\n * ```\n */\nexport { new_color as new };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAAsC;AAGtC,MAAM,UAAU,CAAC,MACf,MAAM,QAAQ,MAAM,UAAa,OAAO,MAAM,CAAC,IAAI,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC;AAMjG,MAAM,UAAU,CAAC,WACf,WAAW,QAAQ,OAAO,MAAM,MAAM,IAAI,IAAI,IAAI,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,MAAM,CAAC,IAAI;AA6BlF,SAAS,IAAIA,MAAiBC,QAAmBC,OAAkB,QAA+B;AACvG,QAAMC,KAAI,QAAQH,IAAG;AACrB,QAAMI,KAAI,QAAQH,MAAK;AACvB,QAAMI,KAAI,QAAQH,KAAI;AACtB,QAAM,IAAI,WAAW,SAAY,QAAQ,MAAM,IAAI;AAEnD,MAAI,MAAM,GAAG;AACX,WAAO,OAAOC,EAAC,KAAKC,EAAC,KAAKC,EAAC;AAAA,EAC7B;AACA,SAAO,QAAQF,EAAC,KAAKC,EAAC,KAAKC,EAAC,KAA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r", "g", "b"]
|
|
7
7
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export type * from './strategy/index.js';
|
|
|
54
54
|
export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
55
55
|
export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
56
56
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
57
|
-
export declare const VERSION = "0.9.
|
|
57
|
+
export declare const VERSION = "0.9.6";
|
|
58
58
|
/**
|
|
59
59
|
* Library information
|
|
60
60
|
*/
|
package/dist/cjs/index.js
CHANGED
|
@@ -160,7 +160,7 @@ var import_inputs = require("./runtime/inputs.js");
|
|
|
160
160
|
var import_strategy = require("./strategy/index.js");
|
|
161
161
|
var import_LightweightChartsAdapter = require("./runtime/adapters/LightweightChartsAdapter.js");
|
|
162
162
|
var import_SimpleInputAdapter = require("./runtime/adapters/SimpleInputAdapter.js");
|
|
163
|
-
const VERSION = "0.9.
|
|
163
|
+
const VERSION = "0.9.6";
|
|
164
164
|
const info = {
|
|
165
165
|
name: "OakScriptJS",
|
|
166
166
|
version: VERSION,
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * OakScriptJS - Simplified PineScript-like library for JavaScript\n *\n * This library provides Series-based lazy evaluation and technical analysis functions\n * for building trading indicators. The PineScript-style script API is in `oakscriptjs/script`.\n *\n * Key features:\n * - Series class for lazy evaluation and method chaining\n * - Core TA functions (array-based)\n * - TA-Series wrappers (Series-based)\n *\n * @packageDocumentation\n */\n\n// Export all types\nexport * from './types/index.js';\nexport * from './types/metadata.js';\n\n// Export core namespaces (array-based functions)\nimport * as taCore from './ta/index.js';\nimport * as math from './math/index.js';\nimport * as array from './array/index.js';\nimport * as map from './map/index.js';\nimport * as str from './str/index.js';\nimport * as color from './color/index.js';\nimport * as time from './time/index.js';\nimport * as timeframe from './timeframe/index.js';\nimport * as matrix from './matrix/index.js';\nimport * as line from './line/index.js';\nimport * as box from './box/index.js';\nimport * as label from './label/index.js';\nimport * as linefill from './linefill/index.js';\nimport * as chartPoint from './chartpoint/index.js';\nimport * as polyline from './polyline/index.js';\nimport * as text from './text/index.js';\nimport * as compare from './compare/index.js';\nimport * as callsite from './callsite/index.js';\n\nexport { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, text, compare, callsite };\n\n// Export Series class (self-contained, no context)\nexport { Series, BarData } from './runtime/series.js';\nexport type { SeriesExtractor } from './runtime/series.js';\n\n// Export TA-Series namespace (Series-based wrappers)\nimport * as ta from './ta-series.js';\nexport { ta };\n\n// Export metadata types for indicator return values\nexport type {\n PlotOptions,\n HLineOptions,\n FillOptions,\n InputMetadata,\n PlotMetadata,\n IndicatorMetadata,\n TimeValue,\n PlotData,\n HLineData,\n FillData,\n FillGradient,\n IndicatorResult,\n IndicatorFactory,\n PlotStyle,\n LineStyle,\n PlotDisplay,\n InputType\n} from './types/metadata.js';\n\n// Re-export commonly used functions for convenience\nexport { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series.js';\nexport { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';\nexport { rgb, from_hex as color_from_hex, new_color } from './color/index.js';\n\n// Export chart data utilities\nexport { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';\n\n// Export libraries (ZigZag, etc.)\nexport * from './lib/index.js';\n\n// Export helper functions for generated indicators (PineScript compatibility)\nexport {isNA as na, nz, fixnan} from './utils/index.js';\n\n// Export indicator infrastructure\nexport {\n indicator,\n type IndicatorMetadataConfig,\n type InputDefinition,\n type IndicatorContext,\n type IndicatorInstance,\n type IndicatorConstructor,\n} from './indicator.js';\n\nexport {\n input,\n type InputValue,\n type IntInputOptions,\n type FloatInputOptions,\n type SourceInputOptions,\n type BoolInputOptions,\n type StringInputOptions,\n type TimeInputOptions,\n type SourceType,\n} from './input.js';\n\nexport {\n plot as plotHelper,\n createPlot,\n type Time,\n type TimeValuePair,\n type PlotOptions as PlotHelperOptions,\n type PlotResult,\n} from './plot.js';\n\n// Runtime exports - global context runtime (setContext, plot, hline) drawing through a ChartAdapter\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n} from './runtime/runtime.js';\n\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_source,\n input_timeframe,\n input_session,\n input_time,\n} from './runtime/inputs.js';\n\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputOptions,\n OhlcvData,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ArrowConfig,\n} from './runtime/types.js';\n\n// Strategy types and constants (the script API forwards strategy.* calls to a host engine)\nexport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n} from './strategy/index.js';\nexport type * from './strategy/index.js';\n\nexport { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';\n\n// Version\nexport const VERSION = '0.9.
|
|
4
|
+
"sourcesContent": ["/**\n * OakScriptJS - Simplified PineScript-like library for JavaScript\n *\n * This library provides Series-based lazy evaluation and technical analysis functions\n * for building trading indicators. The PineScript-style script API is in `oakscriptjs/script`.\n *\n * Key features:\n * - Series class for lazy evaluation and method chaining\n * - Core TA functions (array-based)\n * - TA-Series wrappers (Series-based)\n *\n * @packageDocumentation\n */\n\n// Export all types\nexport * from './types/index.js';\nexport * from './types/metadata.js';\n\n// Export core namespaces (array-based functions)\nimport * as taCore from './ta/index.js';\nimport * as math from './math/index.js';\nimport * as array from './array/index.js';\nimport * as map from './map/index.js';\nimport * as str from './str/index.js';\nimport * as color from './color/index.js';\nimport * as time from './time/index.js';\nimport * as timeframe from './timeframe/index.js';\nimport * as matrix from './matrix/index.js';\nimport * as line from './line/index.js';\nimport * as box from './box/index.js';\nimport * as label from './label/index.js';\nimport * as linefill from './linefill/index.js';\nimport * as chartPoint from './chartpoint/index.js';\nimport * as polyline from './polyline/index.js';\nimport * as text from './text/index.js';\nimport * as compare from './compare/index.js';\nimport * as callsite from './callsite/index.js';\n\nexport { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, text, compare, callsite };\n\n// Export Series class (self-contained, no context)\nexport { Series, BarData } from './runtime/series.js';\nexport type { SeriesExtractor } from './runtime/series.js';\n\n// Export TA-Series namespace (Series-based wrappers)\nimport * as ta from './ta-series.js';\nexport { ta };\n\n// Export metadata types for indicator return values\nexport type {\n PlotOptions,\n HLineOptions,\n FillOptions,\n InputMetadata,\n PlotMetadata,\n IndicatorMetadata,\n TimeValue,\n PlotData,\n HLineData,\n FillData,\n FillGradient,\n IndicatorResult,\n IndicatorFactory,\n PlotStyle,\n LineStyle,\n PlotDisplay,\n InputType\n} from './types/metadata.js';\n\n// Re-export commonly used functions for convenience\nexport { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series.js';\nexport { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';\nexport { rgb, from_hex as color_from_hex, new_color } from './color/index.js';\n\n// Export chart data utilities\nexport { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';\n\n// Export libraries (ZigZag, etc.)\nexport * from './lib/index.js';\n\n// Export helper functions for generated indicators (PineScript compatibility)\nexport {isNA as na, nz, fixnan} from './utils/index.js';\n\n// Export indicator infrastructure\nexport {\n indicator,\n type IndicatorMetadataConfig,\n type InputDefinition,\n type IndicatorContext,\n type IndicatorInstance,\n type IndicatorConstructor,\n} from './indicator.js';\n\nexport {\n input,\n type InputValue,\n type IntInputOptions,\n type FloatInputOptions,\n type SourceInputOptions,\n type BoolInputOptions,\n type StringInputOptions,\n type TimeInputOptions,\n type SourceType,\n} from './input.js';\n\nexport {\n plot as plotHelper,\n createPlot,\n type Time,\n type TimeValuePair,\n type PlotOptions as PlotHelperOptions,\n type PlotResult,\n} from './plot.js';\n\n// Runtime exports - global context runtime (setContext, plot, hline) drawing through a ChartAdapter\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n} from './runtime/runtime.js';\n\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_source,\n input_timeframe,\n input_session,\n input_time,\n} from './runtime/inputs.js';\n\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputOptions,\n OhlcvData,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ArrowConfig,\n} from './runtime/types.js';\n\n// Strategy types and constants (the script API forwards strategy.* calls to a host engine)\nexport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n} from './strategy/index.js';\nexport type * from './strategy/index.js';\n\nexport { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';\n\n// Version\nexport const VERSION = '0.9.6';\n\n/**\n * Library information\n */\nexport const info = {\n name: 'OakScriptJS',\n version: VERSION,\n description: 'Simplified PineScript-like library - Series + TA functions',\n features: {\n series: 'Lazy evaluation with Series class',\n ta: 'Technical analysis functions (Series and array-based)',\n script: 'PineScript-style script API (oakscriptjs/script): indicator, strategy, inputs, plots, request.security',\n runtime: 'Global context runtime drawing through a ChartAdapter',\n indicator: 'Indicator function with automatic pane management'\n },\n namespaces: {\n core: ['ta', 'math', 'array', 'map', 'str', 'color', 'time', 'timeframe', 'matrix'],\n drawing: ['line', 'box', 'label', 'linefill', 'chartPoint', 'polyline', 'text'],\n runtime: ['setContext', 'plot', 'hline', 'input_*'],\n indicator: ['indicator', 'input', 'plotHelper', 'createPlot']\n }\n};\n\n// PineScript compatibility stubs - functions that have no runtime effect\n// These are no-ops so that PineScript-style code runs without modification\n\n/**\n * alertcondition() - Stub for PineScript alert configuration\n * In PineScript, this registers an alert condition. In oakscriptjs, it's a no-op\n * since alert configuration is handled by the host application.\n */\nexport function alertcondition(_condition: unknown, _title?: string, _message?: string): void {\n // No-op: Alert conditions are handled by the host application\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,0BAAc,6BAfd;AAgBA,0BAAc,gCAhBd;AAmBA,aAAwB;AACxB,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,wBAAgB,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,CAK7D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,CAIxE;AAGD,OAAO,EAAE,SAAS,IAAI,GAAG,EAAE,CAAC;AAC5B,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/cjs/label/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/label/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Label namespace\n * Functions for creating and manipulating label drawing objects.\n *\n * @remarks\n * Labels are primarily used for annotations and marking points on the chart.\n * They have limited computational value compared to lines and boxes, but getters\n * allow retrieving position and text for conditional logic.\n *\n * @version 6\n */\n\nimport { all as allDrawings, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Label, color } from '../types/index.js';\n\ntype LabelXloc = 'bar_index' | 'bar_time';\ntype LabelYloc = 'price' | 'abovebar' | 'belowbar';\ntype LabelStyle = NonNullable<Label['style']>;\n\n/**\n * Creates a new label (PineScript `label.new`), with a chart point or with coordinates:\n *\n * - `label.new(point, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,\n * text_font_family?, force_overlay?, text_formatting?)`\n * - `label.new(x, y, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,\n * text_font_family?, force_overlay?, text_formatting?)`\n *\n * With a chart point, x is `point.index` for `bar_index` labels and `point.time` for `bar_time` labels.\n *\n * @example\n * ```typescript\n * const signal = label.new(10, 105.5, 'BUY');\n * const atPoint = label.new(chartPoint.from_index(10, 105.5), 'BUY');\n * ```\n */\nexport function new_label(\n point: ChartPoint,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(\n x: number,\n y: number,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(...args: unknown[]): Label {\n let x: number, y: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const point = args[0] as ChartPoint;\n rest = args.slice(1);\n x = pointX(point, (rest[1] as LabelXloc | undefined) ?? 'bar_index');\n y = point.price;\n } else {\n [x, y] = args as [number, number];\n rest = args.slice(2);\n }\n const [text, xloc, yloc, labelColor, style, textcolor, size, textalign, tooltip, text_font_family,\n force_overlay, text_formatting] = rest as [\n string?, LabelXloc?, LabelYloc?, color?, LabelStyle?, color?, (string | number)?,\n ('left' | 'center' | 'right')?, string?, ('default' | 'monospace')?, boolean?, number?,\n ];\n return register('label', {\n x,\n y,\n xloc: xloc ?? 'bar_index',\n yloc: yloc ?? 'price',\n text,\n tooltip,\n color: labelColor,\n style,\n textcolor,\n size,\n textalign,\n text_font_family,\n force_overlay: force_overlay ?? false,\n text_formatting,\n });\n}\n\n/**\n * Returns the x coordinate.\n *\n * @param id - Label object\n * @returns X coordinate (bar index or timestamp)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * const x = label.get_x(label); // Returns 50\n * ```\n */\nexport function get_x(id: Label): number {\n return id.x;\n}\n\n/**\n * Returns the y coordinate (price level).\n *\n * @param id - Label object\n * @returns Y coordinate (price)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * const y = label.get_y(label); // Returns 155.5\n * ```\n */\nexport function get_y(id: Label): number {\n return id.y;\n}\n\n/**\n * Returns the label text content.\n *\n * @param id - Label object\n * @returns Text content (or undefined if no text)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot High');\n * const text = label.get_text(label); // Returns 'Pivot High'\n * ```\n */\nexport function get_text(id: Label): string | undefined {\n return id.text;\n}\n\n/**\n * Creates a copy of the label object.\n *\n * @param id - Label object to copy\n * @returns New label object with same properties\n *\n * @remarks\n * Creates a shallow copy of the label. Modifications to the copy won't affect the original.\n *\n * @example\n * ```typescript\n * const original = label.new(50, 155.5, 'Pivot');\n * const copied = label.copy(original);\n *\n * // Modify copy without affecting original\n * copied.text = 'New Text';\n * ```\n */\nexport function copy(id: Label): Label {\n return register('label', { ...id });\n}\n\n// =============================================================================\n// POSITION SETTERS\n// =============================================================================\n\n/**\n * Sets the x coordinate.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_x(label, 55); // Move to bar 55\n * ```\n */\nexport function set_x(id: Label, x: number): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n return id;\n}\n\n/**\n * Sets the y coordinate (price level).\n *\n * @param id - Label object to modify\n * @param y - New y coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_y(label, 160); // Move to price 160\n * ```\n */\nexport function set_y(id: Label, y: number): Label {\n if (isDeleted(id)) return id;\n id.y = y;\n return id;\n}\n\n/**\n * Sets both x and y coordinates.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_xy(label, 60, 160); // Move to (60, 160)\n * ```\n */\nexport function set_xy(id: Label, x: number, y: number): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n id.y = y;\n return id;\n}\n\n/**\n * Sets the x-axis coordinate system.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @param xloc - New coordinate system\n * @returns Modified label object\n *\n * @remarks\n * When changing xloc, you must provide an appropriate x coordinate for the new system.\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_xloc(label, 1609459200000, 'bar_time'); // Change to timestamp\n * ```\n */\nexport function set_xloc(id: Label, x: number, xloc: 'bar_index' | 'bar_time'): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets the y-location mode of the label (PineScript `label.set_yloc(id, yloc)`): `price` uses the\n * label's y, `abovebar` / `belowbar` place it above / below the bar.\n */\nexport function set_yloc(id: Label, yloc: 'price' | 'abovebar' | 'belowbar'): Label {\n if (isDeleted(id)) return id;\n id.yloc = yloc;\n return id;\n}\n\n// =============================================================================\n// CONTENT SETTERS\n// =============================================================================\n\n/**\n * Sets the text content.\n *\n * @param id - Label object to modify\n * @param text - New text content\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_text(label, 'Updated Text');\n * ```\n */\nexport function set_text(id: Label, text: string): Label {\n if (isDeleted(id)) return id;\n id.text = text;\n return id;\n}\n\n/**\n * Sets the tooltip text.\n *\n * @param id - Label object to modify\n * @param tooltip - New tooltip text\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_tooltip(label, 'Resistance level formed at 155.5');\n * ```\n */\nexport function set_tooltip(id: Label, tooltip: string): Label {\n if (isDeleted(id)) return id;\n id.tooltip = tooltip;\n return id;\n}\n\n// =============================================================================\n// STYLING SETTERS\n// =============================================================================\n\n/**\n * Sets the label color (border and arrow).\n *\n * @param id - Label object to modify\n * @param labelColor - New color\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_color(label, '#FF0000'); // Red label\n * ```\n */\nexport function set_color(id: Label, labelColor: color): Label {\n if (isDeleted(id)) return id;\n id.color = labelColor;\n return id;\n}\n\n/**\n * Sets the text color.\n *\n * @param id - Label object to modify\n * @param textColor - New text color\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_textcolor(label, '#FFFFFF'); // White text\n * ```\n */\nexport function set_textcolor(id: Label, textColor: color): Label {\n if (isDeleted(id)) return id;\n id.textcolor = textColor;\n return id;\n}\n\n/**\n * Sets the label style.\n *\n * @param id - Label object to modify\n * @param style - New label style\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_style(label, 'label_down'); // Arrow pointing down\n * ```\n */\nexport function set_style(\n id: Label,\n style: 'none' | 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' |\n 'arrowup' | 'arrowdown' | 'label_up' | 'label_down' | 'label_left' | 'label_right' |\n 'label_lower_left' | 'label_lower_right' | 'label_upper_left' | 'label_upper_right' |\n 'label_center' | 'square' | 'diamond' | 'text_outline'\n): Label {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the label size.\n *\n * @param id - Label object to modify\n * @param size - New size\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_size(label, 'large'); // Larger label\n * ```\n */\nexport function set_size(id: Label, size: string | number): Label {\n if (isDeleted(id)) return id;\n id.size = size;\n return id;\n}\n\n/**\n * Sets the text alignment.\n *\n * @param id - Label object to modify\n * @param align - New text alignment\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_textalign(label, 'center'); // Center-aligned text\n * ```\n */\nexport function set_textalign(id: Label, align: 'left' | 'center' | 'right'): Label {\n if (isDeleted(id)) return id;\n id.textalign = align;\n return id;\n}\n\n/**\n * Sets the text font family.\n *\n * @param id - Label object to modify\n * @param font - New font family\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_text_font_family(label, 'monospace');\n * ```\n */\nexport function set_text_font_family(id: Label, font: 'default' | 'monospace'): Label {\n if (isDeleted(id)) return id;\n id.text_font_family = font;\n return id;\n}\n\n/**\n * Deletes the label object.\n *\n * @param id - Label object to delete\n *\n * @remarks\n * Removes the label from `label.all()`. As in PineScript, the deleted label is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.delete(label);\n * // label.all() no longer contains it\n * ```\n */\nexport function delete_label(id: Label): void {\n remove('label', id);\n}\n\n/** x coordinate of a chart point for an object's xloc (`na` when the point has no such coordinate). */\nfunction pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time'): number {\n const x = xloc === 'bar_time' ? point.time : point.index;\n return x ?? NaN;\n}\n\n/**\n * All live labels, in creation order (PineScript `label.all`). A new array.\n */\nexport function all(): Label[] {\n return allDrawings('label');\n}\n\n/**\n * Sets the label position from a chart point: `point.index` for `bar_index` labels, `point.time`\n * for `bar_time` labels, and `point.price`.\n */\nexport function set_point(id: Label, point: ChartPoint): Label {\n if (isDeleted(id)) return id;\n id.x = pointX(point, id.xloc);\n id.y = point.price;\n return id;\n}\n\n/**\n * Sets the text formatting: `text.format_none`, `text.format_bold`, `text.format_italic`,\n * or `text.format_bold + text.format_italic`.\n */\nexport function set_text_formatting(id: Label, formatting: number): Label {\n if (isDeleted(id)) return id;\n id.text_formatting = formatting;\n return id;\n}\n\n// Alias to match PineScript API\nexport { new_label as new };\nexport { delete_label as delete };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAgE;AAsDzD,SAAS,aAAa,MAAwB;AACnD,MAAI,GAAW,GAAW;AAC1B,MAAI,OAAO,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,MAAM,MAAM;AACnD,UAAM,QAAQ,KAAK,CAAC;AACpB,WAAO,KAAK,MAAM,CAAC;AACnB,QAAI,OAAO,OAAQ,KAAK,CAAC,KAA+B,WAAW;AACnE,QAAI,MAAM;AAAA,EACZ,OAAO;AACL,KAAC,GAAG,CAAC,IAAI;AACT,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AACA,QAAM;AAAA,IAAC;AAAA,IAAM;AAAA,IAAM;AAAA,IAAM;AAAA,IAAY;AAAA,IAAO;AAAA,IAAW;AAAA,IAAM;AAAA,IAAW;AAAA,IAAS;AAAA,IAC/E;AAAA,IAAe;AAAA,EAAe,IAAI;AAIpC,aAAO,0BAAS,SAAS;AAAA,IACvB;AAAA,IACA;AAAA,IACA,MAAM,QAAQ;AAAA,IACd,MAAM,QAAQ;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * Label namespace\n * Functions for creating and manipulating label drawing objects.\n *\n * @remarks\n * Labels are primarily used for annotations and marking points on the chart.\n * They have limited computational value compared to lines and boxes, but getters\n * allow retrieving position and text for conditional logic.\n *\n * @version 6\n */\n\nimport { all as allDrawings, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Label, color } from '../types/index.js';\n\ntype LabelXloc = 'bar_index' | 'bar_time';\ntype LabelYloc = 'price' | 'abovebar' | 'belowbar';\ntype LabelStyle = NonNullable<Label['style']>;\n\n/**\n * Creates a new label (PineScript `label.new`), with a chart point or with coordinates:\n *\n * - `label.new(point, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,\n * text_font_family?, force_overlay?, text_formatting?)`\n * - `label.new(x, y, text?, xloc?, yloc?, color?, style?, textcolor?, size?, textalign?, tooltip?,\n * text_font_family?, force_overlay?, text_formatting?)`\n *\n * With a chart point, x is `point.index` for `bar_index` labels and `point.time` for `bar_time` labels.\n *\n * @example\n * ```typescript\n * const signal = label.new(10, 105.5, 'BUY');\n * const atPoint = label.new(chartPoint.from_index(10, 105.5), 'BUY');\n * ```\n */\nexport function new_label(\n point: ChartPoint,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(\n x: number,\n y: number,\n text?: string,\n xloc?: LabelXloc,\n yloc?: LabelYloc,\n labelColor?: color,\n style?: LabelStyle,\n textcolor?: color,\n size?: string | number,\n textalign?: 'left' | 'center' | 'right',\n tooltip?: string,\n text_font_family?: 'default' | 'monospace',\n force_overlay?: boolean,\n text_formatting?: number\n): Label;\nexport function new_label(...args: unknown[]): Label {\n let x: number, y: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const point = args[0] as ChartPoint;\n rest = args.slice(1);\n x = pointX(point, (rest[1] as LabelXloc | undefined) ?? 'bar_index');\n y = point.price;\n } else {\n [x, y] = args as [number, number];\n rest = args.slice(2);\n }\n const [text, xloc, yloc, labelColor, style, textcolor, size, textalign, tooltip, text_font_family,\n force_overlay, text_formatting] = rest as [\n string?, LabelXloc?, LabelYloc?, color?, LabelStyle?, color?, (string | number)?,\n ('left' | 'center' | 'right')?, string?, ('default' | 'monospace')?, boolean?, number?,\n ];\n return register('label', {\n x,\n y,\n xloc: xloc ?? 'bar_index',\n yloc: yloc ?? 'price',\n // PineScript: a label without text has the text \"\" (label.get_text gives \"\")\n text: text ?? '',\n tooltip,\n color: labelColor,\n style,\n textcolor,\n size,\n textalign,\n text_font_family,\n force_overlay: force_overlay ?? false,\n text_formatting,\n });\n}\n\n/**\n * Returns the x coordinate.\n *\n * @param id - Label object\n * @returns X coordinate (bar index or timestamp)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * const x = label.get_x(label); // Returns 50\n * ```\n */\nexport function get_x(id: Label): number {\n return id.x;\n}\n\n/**\n * Returns the y coordinate (price level).\n *\n * @param id - Label object\n * @returns Y coordinate (price)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * const y = label.get_y(label); // Returns 155.5\n * ```\n */\nexport function get_y(id: Label): number {\n return id.y;\n}\n\n/**\n * Returns the label text content.\n *\n * @param id - Label object\n * @returns Text content (or undefined if no text)\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot High');\n * const text = label.get_text(label); // Returns 'Pivot High'\n * ```\n */\nexport function get_text(id: Label): string | undefined {\n return id.text;\n}\n\n/**\n * Creates a copy of the label object.\n *\n * @param id - Label object to copy\n * @returns New label object with same properties\n *\n * @remarks\n * Creates a shallow copy of the label. Modifications to the copy won't affect the original.\n *\n * @example\n * ```typescript\n * const original = label.new(50, 155.5, 'Pivot');\n * const copied = label.copy(original);\n *\n * // Modify copy without affecting original\n * copied.text = 'New Text';\n * ```\n */\nexport function copy(id: Label): Label {\n return register('label', { ...id });\n}\n\n// =============================================================================\n// POSITION SETTERS\n// =============================================================================\n\n/**\n * Sets the x coordinate.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_x(label, 55); // Move to bar 55\n * ```\n */\nexport function set_x(id: Label, x: number): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n return id;\n}\n\n/**\n * Sets the y coordinate (price level).\n *\n * @param id - Label object to modify\n * @param y - New y coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_y(label, 160); // Move to price 160\n * ```\n */\nexport function set_y(id: Label, y: number): Label {\n if (isDeleted(id)) return id;\n id.y = y;\n return id;\n}\n\n/**\n * Sets both x and y coordinates.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_xy(label, 60, 160); // Move to (60, 160)\n * ```\n */\nexport function set_xy(id: Label, x: number, y: number): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n id.y = y;\n return id;\n}\n\n/**\n * Sets the x-axis coordinate system.\n *\n * @param id - Label object to modify\n * @param x - New x coordinate\n * @param xloc - New coordinate system\n * @returns Modified label object\n *\n * @remarks\n * When changing xloc, you must provide an appropriate x coordinate for the new system.\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_xloc(label, 1609459200000, 'bar_time'); // Change to timestamp\n * ```\n */\nexport function set_xloc(id: Label, x: number, xloc: 'bar_index' | 'bar_time'): Label {\n if (isDeleted(id)) return id;\n id.x = x;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets the y-location mode of the label (PineScript `label.set_yloc(id, yloc)`): `price` uses the\n * label's y, `abovebar` / `belowbar` place it above / below the bar.\n */\nexport function set_yloc(id: Label, yloc: 'price' | 'abovebar' | 'belowbar'): Label {\n if (isDeleted(id)) return id;\n id.yloc = yloc;\n return id;\n}\n\n// =============================================================================\n// CONTENT SETTERS\n// =============================================================================\n\n/**\n * Sets the text content.\n *\n * @param id - Label object to modify\n * @param text - New text content\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_text(label, 'Updated Text');\n * ```\n */\nexport function set_text(id: Label, text: string): Label {\n if (isDeleted(id)) return id;\n id.text = text;\n return id;\n}\n\n/**\n * Sets the tooltip text.\n *\n * @param id - Label object to modify\n * @param tooltip - New tooltip text\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_tooltip(label, 'Resistance level formed at 155.5');\n * ```\n */\nexport function set_tooltip(id: Label, tooltip: string): Label {\n if (isDeleted(id)) return id;\n id.tooltip = tooltip;\n return id;\n}\n\n// =============================================================================\n// STYLING SETTERS\n// =============================================================================\n\n/**\n * Sets the label color (border and arrow).\n *\n * @param id - Label object to modify\n * @param labelColor - New color\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_color(label, '#FF0000'); // Red label\n * ```\n */\nexport function set_color(id: Label, labelColor: color): Label {\n if (isDeleted(id)) return id;\n id.color = labelColor;\n return id;\n}\n\n/**\n * Sets the text color.\n *\n * @param id - Label object to modify\n * @param textColor - New text color\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_textcolor(label, '#FFFFFF'); // White text\n * ```\n */\nexport function set_textcolor(id: Label, textColor: color): Label {\n if (isDeleted(id)) return id;\n id.textcolor = textColor;\n return id;\n}\n\n/**\n * Sets the label style.\n *\n * @param id - Label object to modify\n * @param style - New label style\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_style(label, 'label_down'); // Arrow pointing down\n * ```\n */\nexport function set_style(\n id: Label,\n style: 'none' | 'xcross' | 'cross' | 'triangleup' | 'triangledown' | 'flag' | 'circle' |\n 'arrowup' | 'arrowdown' | 'label_up' | 'label_down' | 'label_left' | 'label_right' |\n 'label_lower_left' | 'label_lower_right' | 'label_upper_left' | 'label_upper_right' |\n 'label_center' | 'square' | 'diamond' | 'text_outline'\n): Label {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the label size.\n *\n * @param id - Label object to modify\n * @param size - New size\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_size(label, 'large'); // Larger label\n * ```\n */\nexport function set_size(id: Label, size: string | number): Label {\n if (isDeleted(id)) return id;\n id.size = size;\n return id;\n}\n\n/**\n * Sets the text alignment.\n *\n * @param id - Label object to modify\n * @param align - New text alignment\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_textalign(label, 'center'); // Center-aligned text\n * ```\n */\nexport function set_textalign(id: Label, align: 'left' | 'center' | 'right'): Label {\n if (isDeleted(id)) return id;\n id.textalign = align;\n return id;\n}\n\n/**\n * Sets the text font family.\n *\n * @param id - Label object to modify\n * @param font - New font family\n * @returns Modified label object\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.set_text_font_family(label, 'monospace');\n * ```\n */\nexport function set_text_font_family(id: Label, font: 'default' | 'monospace'): Label {\n if (isDeleted(id)) return id;\n id.text_font_family = font;\n return id;\n}\n\n/**\n * Deletes the label object.\n *\n * @param id - Label object to delete\n *\n * @remarks\n * Removes the label from `label.all()`. As in PineScript, the deleted label is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const label = label.new(50, 155.5, 'Pivot');\n * label.delete(label);\n * // label.all() no longer contains it\n * ```\n */\nexport function delete_label(id: Label): void {\n remove('label', id);\n}\n\n/** x coordinate of a chart point for an object's xloc (`na` when the point has no such coordinate). */\nfunction pointX(point: ChartPoint, xloc: 'bar_index' | 'bar_time'): number {\n const x = xloc === 'bar_time' ? point.time : point.index;\n return x ?? NaN;\n}\n\n/**\n * All live labels, in creation order (PineScript `label.all`). A new array.\n */\nexport function all(): Label[] {\n return allDrawings('label');\n}\n\n/**\n * Sets the label position from a chart point: `point.index` for `bar_index` labels, `point.time`\n * for `bar_time` labels, and `point.price`.\n */\nexport function set_point(id: Label, point: ChartPoint): Label {\n if (isDeleted(id)) return id;\n id.x = pointX(point, id.xloc);\n id.y = point.price;\n return id;\n}\n\n/**\n * Sets the text formatting: `text.format_none`, `text.format_bold`, `text.format_italic`,\n * or `text.format_bold + text.format_italic`.\n */\nexport function set_text_formatting(id: Label, formatting: number): Label {\n if (isDeleted(id)) return id;\n id.text_formatting = formatting;\n return id;\n}\n\n// Alias to match PineScript API\nexport { new_label as new };\nexport { delete_label as delete };\n"],
|
|
5
|
+
"mappings": ";;;;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QAAO;AAC1B,KAAG,YAAY;AACf,SAAO;AACT;AAeO,SAAS,qBAAqB,IAAW,MAAsC;AACpF,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,mBAAmB;AACtB,SAAO;AACT;AAkBO,SAAS,aAAa,IAAiB;AAC5C,8BAAO,SAAS,EAAE;AACpB;AAGA,SAAS,OAAO,OAAmB,MAAwC;AACzE,QAAM,IAAI,SAAS,aAAa,MAAM,OAAO,MAAM;AACnD,SAAO,KAAK;AACd;AAKO,SAAS,MAAe;AAC7B,aAAO,gBAAAA,KAAY,OAAO;AAC5B;AAMO,SAAS,UAAU,IAAW,OAA0B;AAC7D,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,IAAI,OAAO,OAAO,GAAG,IAAI;AAC5B,KAAG,IAAI,MAAM;AACb,SAAO;AACT;AAMO,SAAS,oBAAoB,IAAW,YAA2B;AACxE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,kBAAkB;AACrB,SAAO;AACT;",
|
|
6
6
|
"names": ["allDrawings"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAQlF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,GAAG,QAAQ,CAIlE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAGD;;GAEG;AACH,wBAAgB,GAAG,IAAI,QAAQ,EAAE,CAEhC;AAGD,OAAO,EAAE,YAAY,IAAI,GAAG,EAAE,CAAC;AAC/B,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -30,6 +30,7 @@ __export(linefill_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(linefill_exports);
|
|
31
31
|
var import_registry = require("../drawing/registry.js");
|
|
32
32
|
function new_linefill(line1, line2, fillColor) {
|
|
33
|
+
if (line1 === null || line1 === void 0 || line2 === null || line2 === void 0) return null;
|
|
33
34
|
return (0, import_registry.register)("linefill", {
|
|
34
35
|
line1,
|
|
35
36
|
line2,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/linefill/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Linefill namespace\n * Functions for creating and manipulating linefill drawing objects.\n *\n * @remarks\n * Linefill objects fill the area between two lines with a color.\n * They have minimal computational value but automatically follow line movements\n * and provide a way to retrieve the underlying line references.\n *\n * @version 6\n */\n\nimport { all as allDrawings, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { Linefill, Line, color } from '../types/index.js';\n\n/**\n * Creates a new linefill object that fills the area between two lines.\n *\n * @param line1 - First line object\n * @param line2 - Second line object\n * @param fillColor - Fill color (optional)\n * @returns New linefill object\n *\n * @remarks\n * - Automatically follows line movements (if lines are updated, fill updates too)\n * - Automatically deleted if either line is deleted\n * - If both lines extend in same direction, fill extends too\n * - Purely visual in PineScript, but getters allow retrieving line references\n *\n * @example\n * ```typescript\n * import { line, linefill } from 'oakscriptjs';\n *\n * // Create channel lines\n * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');\n * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');\n *\n * // Fill channel with color\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue\n * ```\n */\nexport function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {\n return register('linefill', {\n line1,\n line2,\n color: fillColor\n });\n}\n\n/**\n * Returns the first line reference.\n *\n * @param id - Linefill object\n * @returns First line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the first line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the first line\n * const line1 = linefill.get_line1(channelFill);\n * line.set_y2(line1, 175); // Update upper line's second point\n * ```\n */\nexport function get_line1(id: Linefill): Line {\n return id.line1;\n}\n\n/**\n * Returns the second line reference.\n *\n * @param id - Linefill object\n * @returns Second line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the second line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the second line\n * const line2 = linefill.get_line2(channelFill);\n * line.set_y2(line2, 145); // Update lower line's second point\n * ```\n */\nexport function get_line2(id: Linefill): Line {\n return id.line2;\n}\n\n/**\n * Sets the fill color.\n *\n * @param id - Linefill object to modify\n * @param fillColor - New fill color\n * @returns Modified linefill object\n *\n * @remarks\n * Useful for dynamically changing channel colors based on conditions.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');\n *\n * // Change color based on trend\n * if (bullish) {\n * linefill.set_color(channelFill, '#00FF0020'); // Green\n * } else {\n * linefill.set_color(channelFill, '#FF000020'); // Red\n * }\n * ```\n */\nexport function set_color(id: Linefill, fillColor: color): Linefill {\n if (isDeleted(id)) return id;\n id.color = fillColor;\n return id;\n}\n\n/**\n * Deletes the linefill object.\n *\n * @param id - Linefill object to delete\n *\n * @remarks\n * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n * linefill.delete(channelFill);\n * // linefill.all() no longer contains it\n * ```\n */\nexport function delete_linefill(id: Linefill): void {\n remove('linefill', id);\n}\n\n\n/**\n * All live linefills, in creation order (PineScript `linefill.all`). A new array.\n */\nexport function all(): Linefill[] {\n return allDrawings('linefill');\n}\n\n// Alias to match PineScript API\nexport { new_linefill as new };\nexport { delete_linefill as delete };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAgE;AA6BzD,SAAS,aAAa,OAAa,OAAa,WAA6B;
|
|
4
|
+
"sourcesContent": ["/**\n * Linefill namespace\n * Functions for creating and manipulating linefill drawing objects.\n *\n * @remarks\n * Linefill objects fill the area between two lines with a color.\n * They have minimal computational value but automatically follow line movements\n * and provide a way to retrieve the underlying line references.\n *\n * @version 6\n */\n\nimport { all as allDrawings, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { Linefill, Line, color } from '../types/index.js';\n\n/**\n * Creates a new linefill object that fills the area between two lines.\n *\n * @param line1 - First line object\n * @param line2 - Second line object\n * @param fillColor - Fill color (optional)\n * @returns New linefill object\n *\n * @remarks\n * - Automatically follows line movements (if lines are updated, fill updates too)\n * - Automatically deleted if either line is deleted\n * - If both lines extend in same direction, fill extends too\n * - Purely visual in PineScript, but getters allow retrieving line references\n *\n * @example\n * ```typescript\n * import { line, linefill } from 'oakscriptjs';\n *\n * // Create channel lines\n * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');\n * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');\n *\n * // Fill channel with color\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue\n * ```\n */\nexport function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {\n // PineScript: an na line gives an na linefill\n if (line1 === null || line1 === undefined || line2 === null || line2 === undefined) return null as unknown as Linefill;\n return register('linefill', {\n line1,\n line2,\n color: fillColor\n });\n}\n\n/**\n * Returns the first line reference.\n *\n * @param id - Linefill object\n * @returns First line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the first line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the first line\n * const line1 = linefill.get_line1(channelFill);\n * line.set_y2(line1, 175); // Update upper line's second point\n * ```\n */\nexport function get_line1(id: Linefill): Line {\n return id.line1;\n}\n\n/**\n * Returns the second line reference.\n *\n * @param id - Linefill object\n * @returns Second line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the second line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the second line\n * const line2 = linefill.get_line2(channelFill);\n * line.set_y2(line2, 145); // Update lower line's second point\n * ```\n */\nexport function get_line2(id: Linefill): Line {\n return id.line2;\n}\n\n/**\n * Sets the fill color.\n *\n * @param id - Linefill object to modify\n * @param fillColor - New fill color\n * @returns Modified linefill object\n *\n * @remarks\n * Useful for dynamically changing channel colors based on conditions.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');\n *\n * // Change color based on trend\n * if (bullish) {\n * linefill.set_color(channelFill, '#00FF0020'); // Green\n * } else {\n * linefill.set_color(channelFill, '#FF000020'); // Red\n * }\n * ```\n */\nexport function set_color(id: Linefill, fillColor: color): Linefill {\n if (isDeleted(id)) return id;\n id.color = fillColor;\n return id;\n}\n\n/**\n * Deletes the linefill object.\n *\n * @param id - Linefill object to delete\n *\n * @remarks\n * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n * linefill.delete(channelFill);\n * // linefill.all() no longer contains it\n * ```\n */\nexport function delete_linefill(id: Linefill): void {\n remove('linefill', id);\n}\n\n\n/**\n * All live linefills, in creation order (PineScript `linefill.all`). A new array.\n */\nexport function all(): Linefill[] {\n return allDrawings('linefill');\n}\n\n// Alias to match PineScript API\nexport { new_linefill as new };\nexport { delete_linefill as delete };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAgE;AA6BzD,SAAS,aAAa,OAAa,OAAa,WAA6B;AAElF,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,OAAW,QAAO;AAC3F,aAAO,0BAAS,YAAY;AAAA,IAC1B;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AACH;AAoBO,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAoBO,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAwBO,SAAS,UAAU,IAAc,WAA4B;AAClE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAkBO,SAAS,gBAAgB,IAAoB;AAClD,8BAAO,YAAY,EAAE;AACvB;AAMO,SAAS,MAAkB;AAChC,aAAO,gBAAAA,KAAY,UAAU;AAC/B;",
|
|
6
6
|
"names": ["allDrawings"]
|
|
7
7
|
}
|