oakscriptjs 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/array/index.d.ts +8 -2
- package/dist/cjs/array/index.d.ts.map +1 -1
- package/dist/cjs/array/index.js +2 -1
- package/dist/cjs/array/index.js.map +2 -2
- package/dist/cjs/box/index.js +6 -6
- package/dist/cjs/box/index.js.map +2 -2
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +6 -3
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +15 -6
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +16 -2
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/input.d.ts +9 -1
- package/dist/cjs/input.d.ts.map +1 -1
- package/dist/cjs/input.js +16 -0
- package/dist/cjs/input.js.map +2 -2
- package/dist/cjs/label/index.js +3 -3
- package/dist/cjs/label/index.js.map +2 -2
- package/dist/cjs/line/index.d.ts +10 -27
- package/dist/cjs/line/index.d.ts.map +1 -1
- package/dist/cjs/line/index.js +10 -27
- package/dist/cjs/line/index.js.map +2 -2
- package/dist/cjs/linefill/index.d.ts +3 -0
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +15 -1
- package/dist/cjs/linefill/index.js.map +3 -3
- package/dist/cjs/runtime/adapters/SimpleInputAdapter.js +1 -1
- package/dist/cjs/runtime/adapters/SimpleInputAdapter.js.map +2 -2
- package/dist/cjs/runtime/index.d.ts +1 -1
- package/dist/cjs/runtime/index.d.ts.map +1 -1
- package/dist/cjs/runtime/index.js +1 -0
- package/dist/cjs/runtime/index.js.map +2 -2
- package/dist/cjs/runtime/inputs.d.ts +9 -0
- package/dist/cjs/runtime/inputs.d.ts.map +1 -1
- package/dist/cjs/runtime/inputs.js +8 -0
- package/dist/cjs/runtime/inputs.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +1 -1
- package/dist/cjs/runtime/types.d.ts.map +1 -1
- package/dist/cjs/runtime/types.js.map +1 -1
- package/dist/cjs/script/index.d.ts +66 -13
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +139 -35
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/security/other.d.ts +92 -0
- package/dist/cjs/security/other.d.ts.map +1 -0
- package/dist/cjs/security/other.js +164 -0
- package/dist/cjs/security/other.js.map +7 -0
- package/dist/cjs/session/bars.d.ts +10 -1
- package/dist/cjs/session/bars.d.ts.map +1 -1
- package/dist/cjs/session/bars.js +16 -2
- package/dist/cjs/session/bars.js.map +2 -2
- package/dist/cjs/session/calendar.d.ts +4 -1
- package/dist/cjs/session/calendar.d.ts.map +1 -1
- package/dist/cjs/session/calendar.js +12 -7
- package/dist/cjs/session/calendar.js.map +2 -2
- package/dist/cjs/session/context.d.ts +22 -5
- package/dist/cjs/session/context.d.ts.map +1 -1
- package/dist/cjs/session/context.js +67 -6
- package/dist/cjs/session/context.js.map +2 -2
- package/dist/cjs/str/floatingdecimal.d.ts +31 -0
- package/dist/cjs/str/floatingdecimal.d.ts.map +1 -0
- package/dist/cjs/str/floatingdecimal.js +298 -0
- package/dist/cjs/str/floatingdecimal.js.map +7 -0
- package/dist/cjs/str/index.d.ts +4 -3
- package/dist/cjs/str/index.d.ts.map +1 -1
- package/dist/cjs/str/index.js +1 -1
- package/dist/cjs/str/index.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts +6 -4
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +3 -2
- package/dist/cjs/str/numberformat.js.map +2 -2
- package/dist/cjs/ta/index.d.ts +64 -45
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +140 -126
- package/dist/cjs/ta/index.js.map +3 -3
- package/dist/cjs/ta/limits.d.ts +11 -0
- package/dist/cjs/ta/limits.d.ts.map +1 -1
- package/dist/cjs/ta/limits.js +15 -1
- package/dist/cjs/ta/limits.js.map +2 -2
- package/dist/cjs/ta/running-sum.js +1 -1
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta-series.d.ts +1 -1
- package/dist/cjs/ta-series.d.ts.map +1 -1
- package/dist/cjs/ta-series.js +1 -1
- package/dist/cjs/ta-series.js.map +2 -2
- package/dist/cjs/table/index.d.ts +10 -3
- package/dist/cjs/table/index.d.ts.map +1 -1
- package/dist/cjs/table/index.js +11 -1
- package/dist/cjs/table/index.js.map +3 -3
- package/dist/cjs/time/session.d.ts +9 -0
- package/dist/cjs/time/session.d.ts.map +1 -1
- package/dist/cjs/time/session.js +42 -14
- package/dist/cjs/time/session.js.map +3 -3
- package/dist/cjs/time/timezone.d.ts +6 -1
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +2 -2
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +1 -1
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/esm/array/index.d.ts +8 -2
- package/dist/esm/array/index.d.ts.map +1 -1
- package/dist/esm/array/index.js +12 -3
- package/dist/esm/array/index.js.map +1 -1
- package/dist/esm/box/index.js +6 -6
- package/dist/esm/box/index.js.map +1 -1
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +6 -3
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +15 -6
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +30 -7
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +8 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/input.d.ts +9 -1
- package/dist/esm/input.d.ts.map +1 -1
- package/dist/esm/input.js +16 -0
- package/dist/esm/input.js.map +1 -1
- package/dist/esm/label/index.js +3 -3
- package/dist/esm/label/index.js.map +1 -1
- package/dist/esm/line/index.d.ts +10 -27
- package/dist/esm/line/index.d.ts.map +1 -1
- package/dist/esm/line/index.js +20 -64
- package/dist/esm/line/index.js.map +1 -1
- package/dist/esm/linefill/index.d.ts +3 -0
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +20 -1
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/runtime/adapters/SimpleInputAdapter.js +1 -1
- package/dist/esm/runtime/adapters/SimpleInputAdapter.js.map +1 -1
- package/dist/esm/runtime/index.d.ts +1 -1
- package/dist/esm/runtime/index.d.ts.map +1 -1
- package/dist/esm/runtime/index.js +1 -1
- package/dist/esm/runtime/index.js.map +1 -1
- package/dist/esm/runtime/inputs.d.ts +9 -0
- package/dist/esm/runtime/inputs.d.ts.map +1 -1
- package/dist/esm/runtime/inputs.js +15 -0
- package/dist/esm/runtime/inputs.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +1 -1
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +66 -13
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +187 -54
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/security/other.d.ts +92 -0
- package/dist/esm/security/other.d.ts.map +1 -0
- package/dist/esm/security/other.js +211 -0
- package/dist/esm/security/other.js.map +1 -0
- package/dist/esm/session/bars.d.ts +10 -1
- package/dist/esm/session/bars.d.ts.map +1 -1
- package/dist/esm/session/bars.js +26 -1
- package/dist/esm/session/bars.js.map +1 -1
- package/dist/esm/session/calendar.d.ts +4 -1
- package/dist/esm/session/calendar.d.ts.map +1 -1
- package/dist/esm/session/calendar.js +23 -7
- package/dist/esm/session/calendar.js.map +1 -1
- package/dist/esm/session/context.d.ts +22 -5
- package/dist/esm/session/context.d.ts.map +1 -1
- package/dist/esm/session/context.js +86 -10
- package/dist/esm/session/context.js.map +1 -1
- package/dist/esm/str/floatingdecimal.d.ts +31 -0
- package/dist/esm/str/floatingdecimal.d.ts.map +1 -0
- package/dist/esm/str/floatingdecimal.js +272 -0
- package/dist/esm/str/floatingdecimal.js.map +1 -0
- package/dist/esm/str/index.d.ts +4 -3
- package/dist/esm/str/index.d.ts.map +1 -1
- package/dist/esm/str/index.js +6 -5
- package/dist/esm/str/index.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts +6 -4
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +9 -5
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts +64 -45
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +198 -228
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/limits.d.ts +11 -0
- package/dist/esm/ta/limits.d.ts.map +1 -1
- package/dist/esm/ta/limits.js +27 -2
- package/dist/esm/ta/limits.js.map +1 -1
- package/dist/esm/ta/running-sum.js +1 -1
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta-series.d.ts +1 -1
- package/dist/esm/ta-series.d.ts.map +1 -1
- package/dist/esm/ta-series.js +2 -1
- package/dist/esm/ta-series.js.map +1 -1
- package/dist/esm/table/index.d.ts +10 -3
- package/dist/esm/table/index.d.ts.map +1 -1
- package/dist/esm/table/index.js +23 -3
- package/dist/esm/table/index.js.map +1 -1
- package/dist/esm/time/session.d.ts +9 -0
- package/dist/esm/time/session.d.ts.map +1 -1
- package/dist/esm/time/session.js +53 -15
- package/dist/esm/time/session.js.map +1 -1
- package/dist/esm/time/timezone.d.ts +6 -1
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +8 -2
- package/dist/esm/time/timezone.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +1 -1
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/array/index.ts +11 -3
- package/src/box/index.ts +6 -6
- package/src/callsite/index.ts +6 -3
- package/src/drawing/registry.ts +30 -7
- package/src/index.ts +16 -3
- package/src/input.ts +18 -1
- package/src/label/index.ts +3 -3
- package/src/line/index.ts +20 -68
- package/src/linefill/index.ts +20 -1
- package/src/runtime/adapters/SimpleInputAdapter.ts +1 -1
- package/src/runtime/index.ts +1 -0
- package/src/runtime/inputs.ts +16 -0
- package/src/runtime/types.ts +1 -1
- package/src/script/index.ts +262 -58
- package/src/security/other.ts +269 -0
- package/src/session/bars.ts +24 -1
- package/src/session/calendar.ts +26 -7
- package/src/session/context.ts +104 -10
- package/src/str/floatingdecimal.ts +268 -0
- package/src/str/index.ts +6 -5
- package/src/str/numberformat.ts +11 -6
- package/src/ta/index.ts +200 -225
- package/src/ta/limits.ts +28 -1
- package/src/ta/running-sum.ts +1 -1
- package/src/ta-series.ts +3 -2
- package/src/table/index.ts +22 -3
- package/src/time/session.ts +58 -16
- package/src/time/timezone.ts +9 -2
- package/src/types/metadata.ts +1 -1
package/dist/cjs/input.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/input.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Input helper functions for indicator parameters\n * These functions create input definitions that can be used with the indicator system.\n * @module input\n */\n\n/**\n * Input value with its configuration\n */\nexport interface InputValue<T> {\n /** Input type identifier */\n type: 'int' | 'float' | 'source' | 'bool' | 'string' | 'timeframe' | 'session' | 'time';\n /** Default value */\n defaultValue: T;\n /** Current value (initially equals defaultValue) */\n value: T;\n /** Display title */\n title?: string;\n /** Minimum value (for numeric inputs) */\n min?: number;\n /** Maximum value (for numeric inputs) */\n max?: number;\n /** Step size (for numeric inputs) */\n step?: number;\n /** Available options (for source/string/timeframe/session types) */\n options?: string[];\n}\n\n/**\n * Options for integer input\n */\nexport interface IntInputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for float input\n */\nexport interface FloatInputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for source input\n */\nexport interface SourceInputOptions {\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for boolean input\n */\nexport interface BoolInputOptions {\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for string input\n */\nexport interface StringInputOptions {\n /** Display title */\n title?: string;\n /** Available options for dropdown */\n options?: string[];\n}\n\n/**\n * Options for time input\n */\nexport interface TimeInputOptions {\n /** Display title */\n title?: string;\n}\n\n/**\n * Source type for price data\n */\nexport type SourceType = 'open' | 'high' | 'low' | 'close' | 'hl2' | 'hlc3' | 'ohlc4' | 'hlcc4';\n\n/**\n * Input helper functions for creating indicator parameters\n */\nexport const input = {\n /**\n * Create an integer input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (min, max, step, title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const length = input.int(14, { min: 1, max: 500, title: 'Length' });\n * console.log(length.value); // 14\n * ```\n */\n int(defaultValue: number, options: IntInputOptions = {}): InputValue<number> {\n return {\n type: 'int' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n min: options.min,\n max: options.max,\n step: options.step ?? 1,\n };\n },\n\n /**\n * Create a float input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (min, max, step, title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const multiplier = input.float(2.5, { min: 0.1, max: 10, step: 0.1, title: 'Multiplier' });\n * console.log(multiplier.value); // 2.5\n * ```\n */\n float(defaultValue: number, options: FloatInputOptions = {}): InputValue<number> {\n return {\n type: 'float' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n min: options.min,\n max: options.max,\n step: options.step ?? 0.1,\n };\n },\n\n /**\n * Create a source input parameter (for selecting price data type)\n * @param defaultValue - Default source type (default: 'close')\n * @param options - Additional options (title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const src = input.source('close', { title: 'Source' });\n * console.log(src.value); // 'close'\n * ```\n */\n source(defaultValue: SourceType = 'close', options: SourceInputOptions = {}): InputValue<SourceType> {\n return {\n type: 'source' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: ['open', 'high', 'low', 'close', 'hl2', 'hlc3', 'ohlc4', 'hlcc4'],\n };\n },\n\n /**\n * Create a boolean input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const showSignal = input.bool(true, { title: 'Show Signal' });\n * console.log(showSignal.value); // true\n * ```\n */\n bool(defaultValue: boolean, options: BoolInputOptions = {}): InputValue<boolean> {\n return {\n type: 'bool' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n };\n },\n\n /**\n * Create a string input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const maType = input.string('SMA', { title: 'MA Type', options: ['SMA', 'EMA', 'WMA'] });\n * console.log(maType.value); // 'SMA'\n * ```\n */\n string(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'string' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a timeframe input parameter (PineScript `input.timeframe`)\n * @param defaultValue - Default timeframe string (\"60\", \"1D\", \"W\"); \"\" means the chart timeframe\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n *\n * @example\n * ```typescript\n * const htf = input.timeframe('1D', { title: 'Higher timeframe' });\n * console.log(htf.value); // '1D'\n * ```\n */\n timeframe(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'timeframe' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a session input parameter (PineScript `input.session`)\n * @param defaultValue - Default session string (\"0930-1600\", \"0930-1600:23456\")\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n *\n * @example\n * ```typescript\n * const rth = input.session('0930-1600', { title: 'Regular hours' });\n * console.log(rth.value); // '0930-1600'\n * ```\n */\n session(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'session' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a date/time input parameter (PineScript `input.time`)\n * @param defaultValue - Default UNIX time in milliseconds, e.g. `time.timestamp('2024-01-01')`\n * @param options - Additional options (title)\n * @returns Input value object\n *\n * @example\n * ```typescript\n * const start = input.time(time.timestamp('2024-01-01'), { title: 'Start' });\n * console.log(start.value); // 1704067200000\n * ```\n */\n time(defaultValue: number, options: TimeInputOptions = {}): InputValue<number> {\n return {\n type: 'time' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n };\n },\n};\n\n// Freeze the input object to prevent accidental modifications\nObject.freeze(input);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkGO,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanB,IAAI,cAAsB,UAA2B,CAAC,GAAuB;AAC3E,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,MACf,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ;AAAA,MACb,MAAM,QAAQ,QAAQ;AAAA,IACxB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,cAAsB,UAA6B,CAAC,GAAuB;AAC/E,WAAO;AAAA,MACL,MAAM;AA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A;AAAA;AAAA,EAcA,QAAQ,cAAsB,UAA8B,CAAC,GAAuB;AAClF,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,MACf,SAAS,QAAQ;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,KAAK,cAAsB,UAA4B,CAAC,GAAuB;AAC7E,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;AAGA,OAAO,OAAO,KAAK;",
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Input helper functions for indicator parameters\n * These functions create input definitions that can be used with the indicator system.\n * @module input\n */\n\n/**\n * Input value with its configuration\n */\nexport interface InputValue<T> {\n /** Input type identifier */\n type: 'int' | 'float' | 'source' | 'bool' | 'string' | 'timeframe' | 'session' | 'time' | 'symbol';\n /** Default value */\n defaultValue: T;\n /** Current value (initially equals defaultValue) */\n value: T;\n /** Display title */\n title?: string;\n /** Minimum value (for numeric inputs) */\n min?: number;\n /** Maximum value (for numeric inputs) */\n max?: number;\n /** Step size (for numeric inputs) */\n step?: number;\n /** Available options (for source/string/timeframe/session types) */\n options?: string[];\n}\n\n/**\n * Options for integer input\n */\nexport interface IntInputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for float input\n */\nexport interface FloatInputOptions {\n /** Minimum value */\n min?: number;\n /** Maximum value */\n max?: number;\n /** Step size */\n step?: number;\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for source input\n */\nexport interface SourceInputOptions {\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for boolean input\n */\nexport interface BoolInputOptions {\n /** Display title */\n title?: string;\n}\n\n/**\n * Options for string input\n */\nexport interface StringInputOptions {\n /** Display title */\n title?: string;\n /** Available options for dropdown */\n options?: string[];\n}\n\n/**\n * Options for time input\n */\nexport interface TimeInputOptions {\n /** Display title */\n title?: string;\n}\n\n/**\n * Source type for price data\n */\nexport type SourceType = 'open' | 'high' | 'low' | 'close' | 'hl2' | 'hlc3' | 'ohlc4' | 'hlcc4';\n\n/**\n * Input helper functions for creating indicator parameters\n */\nexport const input = {\n /**\n * Create an integer input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (min, max, step, title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const length = input.int(14, { min: 1, max: 500, title: 'Length' });\n * console.log(length.value); // 14\n * ```\n */\n int(defaultValue: number, options: IntInputOptions = {}): InputValue<number> {\n return {\n type: 'int' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n min: options.min,\n max: options.max,\n step: options.step ?? 1,\n };\n },\n\n /**\n * Create a float input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (min, max, step, title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const multiplier = input.float(2.5, { min: 0.1, max: 10, step: 0.1, title: 'Multiplier' });\n * console.log(multiplier.value); // 2.5\n * ```\n */\n float(defaultValue: number, options: FloatInputOptions = {}): InputValue<number> {\n return {\n type: 'float' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n min: options.min,\n max: options.max,\n step: options.step ?? 0.1,\n };\n },\n\n /**\n * Create a source input parameter (for selecting price data type)\n * @param defaultValue - Default source type (default: 'close')\n * @param options - Additional options (title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const src = input.source('close', { title: 'Source' });\n * console.log(src.value); // 'close'\n * ```\n */\n source(defaultValue: SourceType = 'close', options: SourceInputOptions = {}): InputValue<SourceType> {\n return {\n type: 'source' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: ['open', 'high', 'low', 'close', 'hl2', 'hlc3', 'ohlc4', 'hlcc4'],\n };\n },\n\n /**\n * Create a boolean input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (title)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const showSignal = input.bool(true, { title: 'Show Signal' });\n * console.log(showSignal.value); // true\n * ```\n */\n bool(defaultValue: boolean, options: BoolInputOptions = {}): InputValue<boolean> {\n return {\n type: 'bool' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n };\n },\n\n /**\n * Create a string input parameter\n * @param defaultValue - Default value for the input\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n * \n * @example\n * ```typescript\n * const maType = input.string('SMA', { title: 'MA Type', options: ['SMA', 'EMA', 'WMA'] });\n * console.log(maType.value); // 'SMA'\n * ```\n */\n string(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'string' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a timeframe input parameter (PineScript `input.timeframe`)\n * @param defaultValue - Default timeframe string (\"60\", \"1D\", \"W\"); \"\" means the chart timeframe\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n *\n * @example\n * ```typescript\n * const htf = input.timeframe('1D', { title: 'Higher timeframe' });\n * console.log(htf.value); // '1D'\n * ```\n */\n timeframe(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'timeframe' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a session input parameter (PineScript `input.session`)\n * @param defaultValue - Default session string (\"0930-1600\", \"0930-1600:23456\")\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n *\n * @example\n * ```typescript\n * const rth = input.session('0930-1600', { title: 'Regular hours' });\n * console.log(rth.value); // '0930-1600'\n * ```\n */\n session(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'session' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a symbol input parameter (PineScript `input.symbol`): a ticker id (\"NASDAQ:MSFT\") that an application can\n * edit with a symbol picker (#180)\n * @param defaultValue - Default ticker id\n * @param options - Additional options (title, options for dropdown)\n * @returns Input value object\n */\n symbol(defaultValue: string, options: StringInputOptions = {}): InputValue<string> {\n return {\n type: 'symbol' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n options: options.options,\n };\n },\n\n /**\n * Create a date/time input parameter (PineScript `input.time`)\n * @param defaultValue - Default UNIX time in milliseconds, e.g. `time.timestamp('2024-01-01')`\n * @param options - Additional options (title)\n * @returns Input value object\n *\n * @example\n * ```typescript\n * const start = input.time(time.timestamp('2024-01-01'), { title: 'Start' });\n * console.log(start.value); // 1704067200000\n * ```\n */\n time(defaultValue: number, options: TimeInputOptions = {}): InputValue<number> {\n return {\n type: 'time' as const,\n defaultValue,\n value: defaultValue,\n title: options.title,\n };\n },\n};\n\n// Freeze the input object to prevent accidental modifications\nObject.freeze(input);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkGO,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAanB,IAAI,cAAsB,UAA2B,CAAC,GAAuB;AAC3E,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,MACf,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ;AAAA,MACb,MAAM,QAAQ,QAAQ;AAAA,IACxB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,cAAsB,UAA6B,CAAC,GAAuB;AAC/E,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,MACf,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ;AAAA,MACb,MAAM,QAAQ,QAAQ;AAAA,IACxB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A,MACf,SAAS,QAAQ;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,cAAsB,UAA8B,CAAC,GAAuB;AACjF,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,MACf,SAAS,QAAQ;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,KAAK,cAAsB,UAA4B,CAAC,GAAuB;AAC7E,WAAO;AAAA,MACL,MAAM;AAAA,MACN;AAAA,MACA,OAAO;AAAA,MACP,OAAO,QAAQ;AAAA,IACjB;AAAA,EACF;AACF;AAGA,OAAO,OAAO,KAAK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/label/index.js
CHANGED
|
@@ -70,7 +70,7 @@ function new_label(...args) {
|
|
|
70
70
|
force_overlay,
|
|
71
71
|
text_formatting
|
|
72
72
|
] = rest;
|
|
73
|
-
(0, import_registry.checkBarIndex)("label.new", "x", x, xloc);
|
|
73
|
+
x = (0, import_registry.checkBarIndex)("label.new", "x", x, xloc);
|
|
74
74
|
return (0, import_registry.register)("label", {
|
|
75
75
|
x,
|
|
76
76
|
y,
|
|
@@ -103,7 +103,7 @@ function copy(id) {
|
|
|
103
103
|
}
|
|
104
104
|
function set_x(id, x) {
|
|
105
105
|
if ((0, import_registry.isDeleted)(id)) return id;
|
|
106
|
-
(0, import_registry.checkBarIndex)("label.set_x", "x", x, id.xloc);
|
|
106
|
+
x = (0, import_registry.checkBarIndex)("label.set_x", "x", x, id.xloc);
|
|
107
107
|
id.x = x;
|
|
108
108
|
return id;
|
|
109
109
|
}
|
|
@@ -114,7 +114,7 @@ function set_y(id, y) {
|
|
|
114
114
|
}
|
|
115
115
|
function set_xy(id, x, y) {
|
|
116
116
|
if ((0, import_registry.isDeleted)(id)) return id;
|
|
117
|
-
(0, import_registry.checkBarIndex)("label.set_x", "x", x, id.xloc);
|
|
117
|
+
x = (0, import_registry.checkBarIndex)("label.set_x", "x", x, id.xloc);
|
|
118
118
|
id.x = x;
|
|
119
119
|
id.y = y;
|
|
120
120
|
return id;
|
|
@@ -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, checkBarIndex, 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 checkBarIndex('label.new', 'x', x, xloc);\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 checkBarIndex('label.set_x', 'x', x, id.xloc);\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 checkBarIndex('label.set_x', 'x', x, id.xloc);\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,sBAA+E;AAsDxE,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,
|
|
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, checkBarIndex, 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 x = checkBarIndex('label.new', 'x', x, xloc);\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 x = checkBarIndex('label.set_x', 'x', x, id.xloc);\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 x = checkBarIndex('label.set_x', 'x', x, id.xloc);\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"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ACT;AAeO,SAAS,SAAS,IAAW,MAA8B;AAChE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,OAAO;AACV,SAAO;AACT;AAeO,SAAS,cAAc,IAAW,OAA2C;AAClF,UAAI,2BAAU,EAAE,EAAG,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
|
}
|
package/dist/cjs/line/index.d.ts
CHANGED
|
@@ -34,43 +34,26 @@ type LineStyle = 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' |
|
|
|
34
34
|
export declare function new_line(first_point: ChartPoint, second_point: ChartPoint, xloc?: LineXloc, extend?: LineExtend, lineColor?: color, style?: LineStyle, width?: number, force_overlay?: boolean): Line;
|
|
35
35
|
export declare function new_line(x1: number, y1: number, x2: number, y2: number, xloc?: LineXloc, extend?: LineExtend, lineColor?: color, style?: LineStyle, width?: number, force_overlay?: boolean): Line;
|
|
36
36
|
/**
|
|
37
|
-
* Returns the price level of a line at a given bar index.
|
|
37
|
+
* Returns the price level of a line at a given bar index (PineScript `line.get_price`).
|
|
38
38
|
*
|
|
39
39
|
* @param id - Line object
|
|
40
40
|
* @param x - Bar index to calculate price at
|
|
41
|
-
* @returns Price level at the given bar index
|
|
41
|
+
* @returns Price level at the given bar index; NaN for a vertical line (x1 == x2) or a deleted line
|
|
42
42
|
*
|
|
43
43
|
* @remarks
|
|
44
|
-
*
|
|
45
|
-
* -
|
|
46
|
-
* -
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* - 'right': Extends infinitely to the right (x > x2)
|
|
50
|
-
* - 'both': Extends infinitely in both directions
|
|
51
|
-
* - Only works with xloc='bar_index' lines (not xloc='bar_time')
|
|
52
|
-
* - In PineScript, this function treats all lines as if extend='both' regardless of actual setting
|
|
53
|
-
* For compatibility, we follow the actual extend setting
|
|
44
|
+
* As in PineScript (#174):
|
|
45
|
+
* - the line is read as extended on both sides whatever its `extend`: a point before x1 or after x2 has a price
|
|
46
|
+
* - the price is `y1 + (y2 - y1) * (x - x1) / (x2 - x1)`, in that order (bit for bit)
|
|
47
|
+
* - a line placed with `xloc.bar_time` throws "'line.get_price' must be used with lines created using
|
|
48
|
+
* 'xloc=xloc.bar_index'." (runtime error RE10119)
|
|
54
49
|
*
|
|
55
50
|
* @example
|
|
56
51
|
* ```typescript
|
|
57
52
|
* const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');
|
|
58
53
|
*
|
|
59
|
-
* //
|
|
60
|
-
* line.get_price(trendLine,
|
|
61
|
-
*
|
|
62
|
-
* // Extended right
|
|
63
|
-
* line.get_price(trendLine, 100); // Returns 200
|
|
64
|
-
*
|
|
65
|
-
* // Not extended left (with extend='right')
|
|
66
|
-
* line.get_price(trendLine, -10); // Returns NaN
|
|
67
|
-
*
|
|
68
|
-
* // Use for breakout detection
|
|
69
|
-
* const currentPrice = close[close.length - 1];
|
|
70
|
-
* const linePrice = line.get_price(trendLine, close.length - 1);
|
|
71
|
-
* if (currentPrice > linePrice) {
|
|
72
|
-
* console.log('Breakout above trend line!');
|
|
73
|
-
* }
|
|
54
|
+
* line.get_price(trendLine, 25); // 125
|
|
55
|
+
* line.get_price(trendLine, 100); // 200
|
|
56
|
+
* line.get_price(trendLine, -10); // 90: extended to the left too
|
|
74
57
|
* ```
|
|
75
58
|
*/
|
|
76
59
|
export declare function get_price(id: Line, x: number): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/line/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEjE,KAAK,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;AACzC,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACrD,KAAK,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAC;AAE7F;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CACtB,WAAW,EAAE,UAAU,EACvB,YAAY,EAAE,UAAU,EACxB,IAAI,CAAC,EAAE,QAAQ,EACf,MAAM,CAAC,EAAE,UAAU,EACnB,SAAS,CAAC,EAAE,KAAK,EACjB,KAAK,CAAC,EAAE,SAAS,EACjB,KAAK,CAAC,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,OAAO,GACtB,IAAI,CAAC;AACR,wBAAgB,QAAQ,CACtB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE,QAAQ,EACf,MAAM,CAAC,EAAE,UAAU,EACnB,SAAS,CAAC,EAAE,KAAK,EACjB,KAAK,CAAC,EAAE,SAAS,EACjB,KAAK,CAAC,EAAE,MAAM,EACd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AAE,IAAI,EAAE,WAAW,GAAG,UAAU,GAAG,IAAI,CAM/F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAIrF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,GAAG,IAAI,CAI1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,GAAG,IAAI,CAI5H;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,IAAI,GAAG,IAAI,CAE1C;AAQD;;GAEG;AACH,wBAAgB,GAAG,IAAI,IAAI,EAAE,CAE5B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAKjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAKlE;AAGD,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,CAAC;AAC3B,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/cjs/line/index.js
CHANGED
|
@@ -56,8 +56,8 @@ function new_line(...args) {
|
|
|
56
56
|
rest = args.slice(4);
|
|
57
57
|
}
|
|
58
58
|
const [xloc, extend, lineColor, style, width, force_overlay] = rest;
|
|
59
|
-
(0, import_registry.checkBarIndex)("line.new", "x1", x1, xloc);
|
|
60
|
-
(0, import_registry.checkBarIndex)("line.new", "x2", x2, xloc);
|
|
59
|
+
x1 = (0, import_registry.checkBarIndex)("line.new", "x1", x1, xloc);
|
|
60
|
+
x2 = (0, import_registry.checkBarIndex)("line.new", "x2", x2, xloc);
|
|
61
61
|
return (0, import_registry.register)("line", {
|
|
62
62
|
x1,
|
|
63
63
|
y1,
|
|
@@ -72,29 +72,12 @@ function new_line(...args) {
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
function get_price(id, x) {
|
|
75
|
-
const { x1, y1, x2, y2,
|
|
75
|
+
const { x1, y1, x2, y2, xloc } = id;
|
|
76
76
|
if (xloc === "bar_time") {
|
|
77
|
-
throw new Error("line.get_price
|
|
77
|
+
throw new Error("'line.get_price' must be used with lines created using 'xloc=xloc.bar_index'.");
|
|
78
78
|
}
|
|
79
|
-
if (x2 === x1)
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
const slope = (y2 - y1) / (x2 - x1);
|
|
83
|
-
const price = y1 + slope * (x - x1);
|
|
84
|
-
if (extend === "none") {
|
|
85
|
-
if (x < Math.min(x1, x2) || x > Math.max(x1, x2)) {
|
|
86
|
-
return NaN;
|
|
87
|
-
}
|
|
88
|
-
} else if (extend === "left") {
|
|
89
|
-
if (x > Math.max(x1, x2)) {
|
|
90
|
-
return NaN;
|
|
91
|
-
}
|
|
92
|
-
} else if (extend === "right") {
|
|
93
|
-
if (x < Math.min(x1, x2)) {
|
|
94
|
-
return NaN;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return price;
|
|
79
|
+
if (x2 === x1) return NaN;
|
|
80
|
+
return y1 + (y2 - y1) * (x - x1) / (x2 - x1);
|
|
98
81
|
}
|
|
99
82
|
function get_x1(id) {
|
|
100
83
|
return id.x1;
|
|
@@ -113,13 +96,13 @@ function copy(id) {
|
|
|
113
96
|
}
|
|
114
97
|
function set_x1(id, x) {
|
|
115
98
|
if ((0, import_registry.isDeleted)(id)) return id;
|
|
116
|
-
(0, import_registry.checkBarIndex)("line.set_x***", "x1", x, id.xloc);
|
|
99
|
+
x = (0, import_registry.checkBarIndex)("line.set_x***", "x1", x, id.xloc);
|
|
117
100
|
id.x1 = x;
|
|
118
101
|
return id;
|
|
119
102
|
}
|
|
120
103
|
function set_x2(id, x) {
|
|
121
104
|
if ((0, import_registry.isDeleted)(id)) return id;
|
|
122
|
-
(0, import_registry.checkBarIndex)("line.set_x***", "x2", x, id.xloc);
|
|
105
|
+
x = (0, import_registry.checkBarIndex)("line.set_x***", "x2", x, id.xloc);
|
|
123
106
|
id.x2 = x;
|
|
124
107
|
return id;
|
|
125
108
|
}
|
|
@@ -135,14 +118,14 @@ function set_y2(id, y) {
|
|
|
135
118
|
}
|
|
136
119
|
function set_xy1(id, x, y) {
|
|
137
120
|
if ((0, import_registry.isDeleted)(id)) return id;
|
|
138
|
-
(0, import_registry.checkBarIndex)("line.set_x***", "x1", x, id.xloc);
|
|
121
|
+
x = (0, import_registry.checkBarIndex)("line.set_x***", "x1", x, id.xloc);
|
|
139
122
|
id.x1 = x;
|
|
140
123
|
id.y1 = y;
|
|
141
124
|
return id;
|
|
142
125
|
}
|
|
143
126
|
function set_xy2(id, x, y) {
|
|
144
127
|
if ((0, import_registry.isDeleted)(id)) return id;
|
|
145
|
-
(0, import_registry.checkBarIndex)("line.set_x***", "x2", x, id.xloc);
|
|
128
|
+
x = (0, import_registry.checkBarIndex)("line.set_x***", "x2", x, id.xloc);
|
|
146
129
|
id.x2 = x;
|
|
147
130
|
id.y2 = y;
|
|
148
131
|
return id;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/line/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Line namespace\n * Functions for creating and manipulating line drawing objects.\n *\n * @remarks\n * While lines are primarily visual in PineScript, the line.get_price() function provides\n * computational value for algorithmic trading - calculating trend line breakouts,\n * support/resistance levels, and pattern recognition.\n *\n * @version 6\n */\n\nimport { all as allDrawings, checkBarIndex, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Line, color } from '../types/index.js';\n\ntype LineXloc = 'bar_index' | 'bar_time';\ntype LineExtend = 'none' | 'left' | 'right' | 'both';\ntype LineStyle = 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both';\n\n/**\n * Creates a new line (PineScript `line.new`), with two chart points or with coordinates:\n *\n * - `line.new(first_point, second_point, xloc?, extend?, color?, style?, width?, force_overlay?)`\n * - `line.new(x1, y1, x2, y2, xloc?, extend?, color?, style?, width?, force_overlay?)`\n *\n * With chart points, x is `point.index` for `bar_index` lines and `point.time` for `bar_time` lines.\n *\n * @example\n * ```typescript\n * // Create a trend line from bar 0 (price 100) to bar 50 (price 150)\n * const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');\n * const fromPoints = line.new(chartPoint.from_index(0, 100), chartPoint.from_index(50, 150));\n *\n * // Calculate price at bar 75 (extrapolated)\n * const price = line.get_price(trendLine, 75); // Returns 175\n * ```\n */\nexport function new_line(\n first_point: ChartPoint,\n second_point: ChartPoint,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(...args: unknown[]): Line {\n let x1: number, y1: number, x2: number, y2: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const [p1, p2, ...others] = args as [ChartPoint, ChartPoint, ...unknown[]];\n const xloc = (others[0] as LineXloc | undefined) ?? 'bar_index';\n [x1, y1, x2, y2, rest] = [pointX(p1, xloc), p1.price, pointX(p2, xloc), p2.price, others];\n } else {\n [x1, y1, x2, y2] = args as [number, number, number, number];\n rest = args.slice(4);\n }\n const [xloc, extend, lineColor, style, width, force_overlay] = rest as [\n LineXloc?, LineExtend?, color?, LineStyle?, number?, boolean?,\n ];\n checkBarIndex('line.new', 'x1', x1, xloc);\n checkBarIndex('line.new', 'x2', x2, xloc);\n return register('line', {\n x1,\n y1,\n x2,\n y2,\n xloc: xloc ?? 'bar_index',\n extend: extend ?? 'none',\n color: lineColor,\n style: style || 'solid',\n width: width ?? 1,\n force_overlay: force_overlay ?? false,\n });\n}\n\n/**\n * Returns the price level of a line at a given bar index.\n *\n * @param id - Line object\n * @param x - Bar index to calculate price at\n * @returns Price level at the given bar index, or NaN if outside bounds and not extended\n *\n * @remarks\n * - **CRITICAL COMPUTATIONAL FUNCTION** - Enables trend line breakout detection\n * - Uses linear interpolation: y = y1 + (y2 - y1) * (x - x1) / (x2 - x1)\n * - Respects extend mode:\n * - 'none': Returns NaN if x is outside [x1, x2]\n * - 'left': Extends infinitely to the left (x < x1)\n * - 'right': Extends infinitely to the right (x > x2)\n * - 'both': Extends infinitely in both directions\n * - Only works with xloc='bar_index' lines (not xloc='bar_time')\n * - In PineScript, this function treats all lines as if extend='both' regardless of actual setting\n * For compatibility, we follow the actual extend setting\n *\n * @example\n * ```typescript\n * const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');\n *\n * // Within segment\n * line.get_price(trendLine, 25); // Returns 125\n *\n * // Extended right\n * line.get_price(trendLine, 100); // Returns 200\n *\n * // Not extended left (with extend='right')\n * line.get_price(trendLine, -10); // Returns NaN\n *\n * // Use for breakout detection\n * const currentPrice = close[close.length - 1];\n * const linePrice = line.get_price(trendLine, close.length - 1);\n * if (currentPrice > linePrice) {\n * console.log('Breakout above trend line!');\n * }\n * ```\n */\nexport function get_price(id: Line, x: number): number {\n const { x1, y1, x2, y2, extend, xloc } = id;\n\n // Only works with bar_index xloc\n if (xloc === 'bar_time') {\n throw new Error('line.get_price() only works with xloc.bar_index lines, not xloc.bar_time');\n }\n\n // Avoid division by zero\n if (x2 === x1) {\n // Vertical line - return NaN or could return y1/y2\n return NaN;\n }\n\n // Linear interpolation formula: y = y1 + (y2 - y1) * (x - x1) / (x2 - x1)\n const slope = (y2 - y1) / (x2 - x1);\n const price = y1 + slope * (x - x1);\n\n // Check bounds based on extend mode\n if (extend === 'none') {\n // Only valid within the segment\n if (x < Math.min(x1, x2) || x > Math.max(x1, x2)) {\n return NaN;\n }\n } else if (extend === 'left') {\n // Valid to the left and within, but not to the right\n if (x > Math.max(x1, x2)) {\n return NaN;\n }\n } else if (extend === 'right') {\n // Valid to the right and within, but not to the left\n if (x < Math.min(x1, x2)) {\n return NaN;\n }\n }\n // extend === 'both': always valid\n\n return price;\n}\n\n/**\n * Returns the first point's x coordinate.\n *\n * @param id - Line object\n * @returns X coordinate of the first point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const x1 = line.get_x1(line); // Returns 10\n * ```\n */\nexport function get_x1(id: Line): number {\n return id.x1;\n}\n\n/**\n * Returns the second point's x coordinate.\n *\n * @param id - Line object\n * @returns X coordinate of the second point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const x2 = line.get_x2(line); // Returns 50\n * ```\n */\nexport function get_x2(id: Line): number {\n return id.x2;\n}\n\n/**\n * Returns the first point's y coordinate (price level).\n *\n * @param id - Line object\n * @returns Y coordinate (price) of the first point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const y1 = line.get_y1(line); // Returns 100\n * ```\n */\nexport function get_y1(id: Line): number {\n return id.y1;\n}\n\n/**\n * Returns the second point's y coordinate (price level).\n *\n * @param id - Line object\n * @returns Y coordinate (price) of the second point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const y2 = line.get_y2(line); // Returns 150\n * ```\n */\nexport function get_y2(id: Line): number {\n return id.y2;\n}\n\n/**\n * Creates a copy of the line object.\n *\n * @param id - Line object to copy\n * @returns New line object with same properties\n *\n * @remarks\n * Creates a shallow copy of the line. Modifications to the copy won't affect the original.\n *\n * @example\n * ```typescript\n * const originalLine = line.new(0, 100, 50, 150);\n * const copiedLine = line.copy(originalLine);\n *\n * // Modify copy without affecting original\n * copiedLine.y2 = 200;\n * ```\n */\nexport function copy(id: Line): Line {\n return register('line', { ...id });\n}\n\n/**\n * Sets the first point's x coordinate.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate (bar index or timestamp)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_x1(line, 10); // Move first point to bar 10\n * ```\n */\nexport function set_x1(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n return id;\n}\n\n/**\n * Sets the second point's x coordinate.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate (bar index or timestamp)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_x2(line, 60); // Move second point to bar 60\n * ```\n */\nexport function set_x2(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n return id;\n}\n\n/**\n * Sets the first point's y coordinate (price level).\n *\n * @param id - Line object to modify\n * @param y - New y coordinate (price)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_y1(line, 110); // Move first point to price 110\n * ```\n */\nexport function set_y1(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y1 = y;\n return id;\n}\n\n/**\n * Sets the second point's y coordinate (price level).\n *\n * @param id - Line object to modify\n * @param y - New y coordinate (price)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_y2(line, 160); // Move second point to price 160\n * ```\n */\nexport function set_y2(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y2 = y;\n return id;\n}\n\n/**\n * Sets both coordinates of the first point.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_xy1(line, 5, 105); // Move first point to (5, 105)\n * ```\n */\nexport function set_xy1(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n id.y1 = y;\n return id;\n}\n\n/**\n * Sets both coordinates of the second point.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_xy2(line, 60, 160); // Move second point to (60, 160)\n * ```\n */\nexport function set_xy2(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n id.y2 = y;\n return id;\n}\n\n/**\n * Sets the coordinate system for the line.\n *\n * @param id - Line object to modify\n * @param x1 - New first point x coordinate\n * @param x2 - New second point x coordinate\n * @param xloc - New coordinate system ('bar_index' or 'bar_time')\n * @returns Modified line object\n *\n * @remarks\n * When changing xloc, you must provide appropriate x coordinates for the new system.\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * // Change to timestamp-based coordinates\n * line.set_xloc(line, 1609459200000, 1609545600000, 'bar_time');\n * ```\n */\nexport function set_xloc(id: Line, x1: number, x2: number, xloc: 'bar_index' | 'bar_time'): Line {\n if (isDeleted(id)) return id;\n id.x1 = x1;\n id.x2 = x2;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets the extension mode of the line.\n *\n * @param id - Line object to modify\n * @param extend - New extension mode\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_extend(line, 'right'); // Extend line to the right\n * ```\n */\nexport function set_extend(id: Line, extend: 'none' | 'left' | 'right' | 'both'): Line {\n if (isDeleted(id)) return id;\n id.extend = extend;\n return id;\n}\n\n/**\n * Sets the line color.\n *\n * @param id - Line object to modify\n * @param color - New line color\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_color(line, '#FF0000'); // Change to red\n * ```\n */\nexport function set_color(id: Line, lineColor: color): Line {\n if (isDeleted(id)) return id;\n id.color = lineColor;\n return id;\n}\n\n/**\n * Sets the line style.\n *\n * @param id - Line object to modify\n * @param style - New line style\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_style(line, 'dashed'); // Change to dashed line\n * ```\n */\nexport function set_style(id: Line, style: 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both'): Line {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the line width.\n *\n * @param id - Line object to modify\n * @param width - New line width in pixels\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_width(line, 3); // Make line thicker\n * ```\n */\nexport function set_width(id: Line, width: number): Line {\n if (isDeleted(id)) return id;\n id.width = width;\n return id;\n}\n\n/**\n * Deletes the line object.\n *\n * @param id - Line object to delete\n *\n * @remarks\n * Removes the line from `line.all()`. As in PineScript, the deleted line is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect. Deleting a line also deletes the linefills that use it.\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.delete(line);\n * // line.all() no longer contains it\n * ```\n */\nexport function delete_line(id: Line): void {\n remove('line', 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 lines, in creation order (PineScript `line.all`). A new array: later changes do not affect it.\n */\nexport function all(): Line[] {\n return allDrawings('line');\n}\n\n/**\n * Sets the first point of the line from a chart point: `point.index` for `bar_index` lines,\n * `point.time` for `bar_time` lines (`na` when the point does not have it), and `point.price`.\n */\nexport function set_first_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x1 = pointX(point, id.xloc);\n id.y1 = point.price;\n return id;\n}\n\n/**\n * Sets the second point of the line from a chart point (see {@link set_first_point}).\n */\nexport function set_second_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x2 = pointX(point, id.xloc);\n id.y2 = point.price;\n return id;\n}\n\n// Alias to match PineScript API\nexport { new_line as new };\nexport { delete_line 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,sBAA+E;AA+CxE,SAAS,YAAY,MAAuB;AACjD,MAAI,IAAY,IAAY,IAAY,IAAY;AACpD,MAAI,OAAO,KAAK,CAAC,MAAM,YAAY,KAAK,CAAC,MAAM,MAAM;AACnD,UAAM,CAAC,IAAI,IAAI,GAAG,MAAM,IAAI;AAC5B,UAAMA,QAAQ,OAAO,CAAC,KAA8B;AACpD,KAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,IAAIA,KAAI,GAAG,GAAG,OAAO,OAAO,IAAIA,KAAI,GAAG,GAAG,OAAO,MAAM;AAAA,EAC1F,OAAO;AACL,KAAC,IAAI,IAAI,IAAI,EAAE,IAAI;AACnB,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AACA,QAAM,CAAC,MAAM,QAAQ,WAAW,OAAO,OAAO,aAAa,IAAI;AAG/D,
|
|
4
|
+
"sourcesContent": ["/**\n * Line namespace\n * Functions for creating and manipulating line drawing objects.\n *\n * @remarks\n * While lines are primarily visual in PineScript, the line.get_price() function provides\n * computational value for algorithmic trading - calculating trend line breakouts,\n * support/resistance levels, and pattern recognition.\n *\n * @version 6\n */\n\nimport { all as allDrawings, checkBarIndex, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { ChartPoint, Line, color } from '../types/index.js';\n\ntype LineXloc = 'bar_index' | 'bar_time';\ntype LineExtend = 'none' | 'left' | 'right' | 'both';\ntype LineStyle = 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both';\n\n/**\n * Creates a new line (PineScript `line.new`), with two chart points or with coordinates:\n *\n * - `line.new(first_point, second_point, xloc?, extend?, color?, style?, width?, force_overlay?)`\n * - `line.new(x1, y1, x2, y2, xloc?, extend?, color?, style?, width?, force_overlay?)`\n *\n * With chart points, x is `point.index` for `bar_index` lines and `point.time` for `bar_time` lines.\n *\n * @example\n * ```typescript\n * // Create a trend line from bar 0 (price 100) to bar 50 (price 150)\n * const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');\n * const fromPoints = line.new(chartPoint.from_index(0, 100), chartPoint.from_index(50, 150));\n *\n * // Calculate price at bar 75 (extrapolated)\n * const price = line.get_price(trendLine, 75); // Returns 175\n * ```\n */\nexport function new_line(\n first_point: ChartPoint,\n second_point: ChartPoint,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(\n x1: number,\n y1: number,\n x2: number,\n y2: number,\n xloc?: LineXloc,\n extend?: LineExtend,\n lineColor?: color,\n style?: LineStyle,\n width?: number,\n force_overlay?: boolean\n): Line;\nexport function new_line(...args: unknown[]): Line {\n let x1: number, y1: number, x2: number, y2: number, rest: unknown[];\n if (typeof args[0] === 'object' && args[0] !== null) {\n const [p1, p2, ...others] = args as [ChartPoint, ChartPoint, ...unknown[]];\n const xloc = (others[0] as LineXloc | undefined) ?? 'bar_index';\n [x1, y1, x2, y2, rest] = [pointX(p1, xloc), p1.price, pointX(p2, xloc), p2.price, others];\n } else {\n [x1, y1, x2, y2] = args as [number, number, number, number];\n rest = args.slice(4);\n }\n const [xloc, extend, lineColor, style, width, force_overlay] = rest as [\n LineXloc?, LineExtend?, color?, LineStyle?, number?, boolean?,\n ];\n x1 = checkBarIndex('line.new', 'x1', x1, xloc);\n x2 = checkBarIndex('line.new', 'x2', x2, xloc);\n return register('line', {\n x1,\n y1,\n x2,\n y2,\n xloc: xloc ?? 'bar_index',\n extend: extend ?? 'none',\n color: lineColor,\n style: style || 'solid',\n width: width ?? 1,\n force_overlay: force_overlay ?? false,\n });\n}\n\n/**\n * Returns the price level of a line at a given bar index (PineScript `line.get_price`).\n *\n * @param id - Line object\n * @param x - Bar index to calculate price at\n * @returns Price level at the given bar index; NaN for a vertical line (x1 == x2) or a deleted line\n *\n * @remarks\n * As in PineScript (#174):\n * - the line is read as extended on both sides whatever its `extend`: a point before x1 or after x2 has a price\n * - the price is `y1 + (y2 - y1) * (x - x1) / (x2 - x1)`, in that order (bit for bit)\n * - a line placed with `xloc.bar_time` throws \"'line.get_price' must be used with lines created using\n * 'xloc=xloc.bar_index'.\" (runtime error RE10119)\n *\n * @example\n * ```typescript\n * const trendLine = line.new(0, 100, 50, 150, 'bar_index', 'right');\n *\n * line.get_price(trendLine, 25); // 125\n * line.get_price(trendLine, 100); // 200\n * line.get_price(trendLine, -10); // 90: extended to the left too\n * ```\n */\nexport function get_price(id: Line, x: number): number {\n const { x1, y1, x2, y2, xloc } = id;\n if (xloc === 'bar_time') {\n throw new Error(\"'line.get_price' must be used with lines created using 'xloc=xloc.bar_index'.\");\n }\n if (x2 === x1) return NaN;\n return y1 + ((y2 - y1) * (x - x1)) / (x2 - x1);\n}\n\n/**\n * Returns the first point's x coordinate.\n *\n * @param id - Line object\n * @returns X coordinate of the first point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const x1 = line.get_x1(line); // Returns 10\n * ```\n */\nexport function get_x1(id: Line): number {\n return id.x1;\n}\n\n/**\n * Returns the second point's x coordinate.\n *\n * @param id - Line object\n * @returns X coordinate of the second point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const x2 = line.get_x2(line); // Returns 50\n * ```\n */\nexport function get_x2(id: Line): number {\n return id.x2;\n}\n\n/**\n * Returns the first point's y coordinate (price level).\n *\n * @param id - Line object\n * @returns Y coordinate (price) of the first point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const y1 = line.get_y1(line); // Returns 100\n * ```\n */\nexport function get_y1(id: Line): number {\n return id.y1;\n}\n\n/**\n * Returns the second point's y coordinate (price level).\n *\n * @param id - Line object\n * @returns Y coordinate (price) of the second point\n *\n * @example\n * ```typescript\n * const line = line.new(10, 100, 50, 150);\n * const y2 = line.get_y2(line); // Returns 150\n * ```\n */\nexport function get_y2(id: Line): number {\n return id.y2;\n}\n\n/**\n * Creates a copy of the line object.\n *\n * @param id - Line object to copy\n * @returns New line object with same properties\n *\n * @remarks\n * Creates a shallow copy of the line. Modifications to the copy won't affect the original.\n *\n * @example\n * ```typescript\n * const originalLine = line.new(0, 100, 50, 150);\n * const copiedLine = line.copy(originalLine);\n *\n * // Modify copy without affecting original\n * copiedLine.y2 = 200;\n * ```\n */\nexport function copy(id: Line): Line {\n return register('line', { ...id });\n}\n\n/**\n * Sets the first point's x coordinate.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate (bar index or timestamp)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_x1(line, 10); // Move first point to bar 10\n * ```\n */\nexport function set_x1(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n return id;\n}\n\n/**\n * Sets the second point's x coordinate.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate (bar index or timestamp)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_x2(line, 60); // Move second point to bar 60\n * ```\n */\nexport function set_x2(id: Line, x: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n return id;\n}\n\n/**\n * Sets the first point's y coordinate (price level).\n *\n * @param id - Line object to modify\n * @param y - New y coordinate (price)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_y1(line, 110); // Move first point to price 110\n * ```\n */\nexport function set_y1(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y1 = y;\n return id;\n}\n\n/**\n * Sets the second point's y coordinate (price level).\n *\n * @param id - Line object to modify\n * @param y - New y coordinate (price)\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_y2(line, 160); // Move second point to price 160\n * ```\n */\nexport function set_y2(id: Line, y: number): Line {\n if (isDeleted(id)) return id;\n id.y2 = y;\n return id;\n}\n\n/**\n * Sets both coordinates of the first point.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_xy1(line, 5, 105); // Move first point to (5, 105)\n * ```\n */\nexport function set_xy1(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x1', x, id.xloc);\n id.x1 = x;\n id.y1 = y;\n return id;\n}\n\n/**\n * Sets both coordinates of the second point.\n *\n * @param id - Line object to modify\n * @param x - New x coordinate\n * @param y - New y coordinate\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_xy2(line, 60, 160); // Move second point to (60, 160)\n * ```\n */\nexport function set_xy2(id: Line, x: number, y: number): Line {\n if (isDeleted(id)) return id;\n x = checkBarIndex('line.set_x***', 'x2', x, id.xloc);\n id.x2 = x;\n id.y2 = y;\n return id;\n}\n\n/**\n * Sets the coordinate system for the line.\n *\n * @param id - Line object to modify\n * @param x1 - New first point x coordinate\n * @param x2 - New second point x coordinate\n * @param xloc - New coordinate system ('bar_index' or 'bar_time')\n * @returns Modified line object\n *\n * @remarks\n * When changing xloc, you must provide appropriate x coordinates for the new system.\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * // Change to timestamp-based coordinates\n * line.set_xloc(line, 1609459200000, 1609545600000, 'bar_time');\n * ```\n */\nexport function set_xloc(id: Line, x1: number, x2: number, xloc: 'bar_index' | 'bar_time'): Line {\n if (isDeleted(id)) return id;\n id.x1 = x1;\n id.x2 = x2;\n id.xloc = xloc;\n return id;\n}\n\n/**\n * Sets the extension mode of the line.\n *\n * @param id - Line object to modify\n * @param extend - New extension mode\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_extend(line, 'right'); // Extend line to the right\n * ```\n */\nexport function set_extend(id: Line, extend: 'none' | 'left' | 'right' | 'both'): Line {\n if (isDeleted(id)) return id;\n id.extend = extend;\n return id;\n}\n\n/**\n * Sets the line color.\n *\n * @param id - Line object to modify\n * @param color - New line color\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_color(line, '#FF0000'); // Change to red\n * ```\n */\nexport function set_color(id: Line, lineColor: color): Line {\n if (isDeleted(id)) return id;\n id.color = lineColor;\n return id;\n}\n\n/**\n * Sets the line style.\n *\n * @param id - Line object to modify\n * @param style - New line style\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_style(line, 'dashed'); // Change to dashed line\n * ```\n */\nexport function set_style(id: Line, style: 'solid' | 'dotted' | 'dashed' | 'arrow_left' | 'arrow_right' | 'arrow_both'): Line {\n if (isDeleted(id)) return id;\n id.style = style;\n return id;\n}\n\n/**\n * Sets the line width.\n *\n * @param id - Line object to modify\n * @param width - New line width in pixels\n * @returns Modified line object\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.set_width(line, 3); // Make line thicker\n * ```\n */\nexport function set_width(id: Line, width: number): Line {\n if (isDeleted(id)) return id;\n id.width = width;\n return id;\n}\n\n/**\n * Deletes the line object.\n *\n * @param id - Line object to delete\n *\n * @remarks\n * Removes the line from `line.all()`. As in PineScript, the deleted line is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect. Deleting a line also deletes the linefills that use it.\n *\n * @example\n * ```typescript\n * const line = line.new(0, 100, 50, 150);\n * line.delete(line);\n * // line.all() no longer contains it\n * ```\n */\nexport function delete_line(id: Line): void {\n remove('line', 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 lines, in creation order (PineScript `line.all`). A new array: later changes do not affect it.\n */\nexport function all(): Line[] {\n return allDrawings('line');\n}\n\n/**\n * Sets the first point of the line from a chart point: `point.index` for `bar_index` lines,\n * `point.time` for `bar_time` lines (`na` when the point does not have it), and `point.price`.\n */\nexport function set_first_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x1 = pointX(point, id.xloc);\n id.y1 = point.price;\n return id;\n}\n\n/**\n * Sets the second point of the line from a chart point (see {@link set_first_point}).\n */\nexport function set_second_point(id: Line, point: ChartPoint): Line {\n if (isDeleted(id)) return id;\n id.x2 = pointX(point, id.xloc);\n id.y2 = point.price;\n return id;\n}\n\n// Alias to match PineScript API\nexport { new_line as new };\nexport { delete_line 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,sBAA+E;AA+CxE,SAAS,YAAY,MAAuB;AACjD,MAAI,IAAY,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UAAU,IAAU,WAAwB;AAC1D,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAeO,SAAS,UAAU,IAAU,OAA0F;AAC5H,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAeO,SAAS,UAAU,IAAU,OAAqB;AACvD,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAkBO,SAAS,YAAY,IAAgB;AAC1C,8BAAO,QAAQ,EAAE;AACnB;AAGA,SAAS,OAAO,OAAmB,MAAwC;AACzE,QAAM,IAAI,SAAS,aAAa,MAAM,OAAO,MAAM;AACnD,SAAO,KAAK;AACd;AAKO,SAAS,MAAc;AAC5B,aAAO,gBAAAC,KAAY,MAAM;AAC3B;AAMO,SAAS,gBAAgB,IAAU,OAAyB;AACjE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,KAAK,OAAO,OAAO,GAAG,IAAI;AAC7B,KAAG,KAAK,MAAM;AACd,SAAO;AACT;AAKO,SAAS,iBAAiB,IAAU,OAAyB;AAClE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,KAAK,OAAO,OAAO,GAAG,IAAI;AAC7B,KAAG,KAAK,MAAM;AACd,SAAO;AACT;",
|
|
6
6
|
"names": ["xloc", "allDrawings"]
|
|
7
7
|
}
|
|
@@ -21,6 +21,9 @@ import type { Linefill, Line, color } from '../types/index.js';
|
|
|
21
21
|
* @remarks
|
|
22
22
|
* - Automatically follows line movements (if lines are updated, fill updates too)
|
|
23
23
|
* - Automatically deleted if either line is deleted
|
|
24
|
+
* - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill
|
|
25
|
+
* (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is
|
|
26
|
+
* returned with the new colour instead of a new one; with several, the one created or returned last
|
|
24
27
|
* - If both lines extend in same direction, fill extends too
|
|
25
28
|
* - Purely visual in PineScript, but getters allow retrieving line references
|
|
26
29
|
*
|
|
@@ -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
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAoBlF;AAMD;;;;;;;;;;;;;;;;;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"}
|
|
@@ -31,12 +31,26 @@ module.exports = __toCommonJS(linefill_exports);
|
|
|
31
31
|
var import_registry = require("../drawing/registry.js");
|
|
32
32
|
function new_linefill(line1, line2, fillColor) {
|
|
33
33
|
if (line1 === null || line1 === void 0 || line2 === null || line2 === void 0) return null;
|
|
34
|
-
|
|
34
|
+
let found;
|
|
35
|
+
for (const fill2 of (0, import_registry.all)("linefill")) {
|
|
36
|
+
const has = (l) => fill2.line1 === l || fill2.line2 === l;
|
|
37
|
+
if (has(line1) && has(line2) && (!found || (touched.get(fill2) ?? 0) > (touched.get(found) ?? 0))) found = fill2;
|
|
38
|
+
}
|
|
39
|
+
if (found) {
|
|
40
|
+
found.color = fillColor;
|
|
41
|
+
touched.set(found, ++touchCount);
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
const fill = (0, import_registry.register)("linefill", {
|
|
35
45
|
line1,
|
|
36
46
|
line2,
|
|
37
47
|
color: fillColor
|
|
38
48
|
});
|
|
49
|
+
touched.set(fill, ++touchCount);
|
|
50
|
+
return fill;
|
|
39
51
|
}
|
|
52
|
+
const touched = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
let touchCount = 0;
|
|
40
54
|
function get_line1(id) {
|
|
41
55
|
return id.line1;
|
|
42
56
|
}
|
|
@@ -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 // 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;
|
|
6
|
-
"names": ["allDrawings"]
|
|
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 * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill\n * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is\n * returned with the new colour instead of a new one; with several, the one created or returned last\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 let found: Linefill | undefined;\n for (const fill of allDrawings('linefill')) {\n const has = (l: Line): boolean => fill.line1 === l || fill.line2 === l;\n if (has(line1) && has(line2) && (!found || (touched.get(fill) ?? 0) > (touched.get(found) ?? 0))) found = fill;\n }\n if (found) {\n found.color = fillColor;\n touched.set(found, ++touchCount);\n return found;\n }\n const fill = register('linefill', {\n line1,\n line2,\n color: fillColor\n });\n touched.set(fill, ++touchCount);\n return fill;\n}\n\n/** Order in which the linefills were created or returned by `linefill.new` (the last one wins a lookup). */\nconst touched = new WeakMap<Linefill, number>();\nlet touchCount = 0;\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;AAgCzD,SAAS,aAAa,OAAa,OAAa,WAA6B;AAElF,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,OAAW,QAAO;AAC3F,MAAI;AACJ,aAAWA,aAAQ,gBAAAC,KAAY,UAAU,GAAG;AAC1C,UAAM,MAAM,CAAC,MAAqBD,MAAK,UAAU,KAAKA,MAAK,UAAU;AACrE,QAAI,IAAI,KAAK,KAAK,IAAI,KAAK,MAAM,CAAC,UAAU,QAAQ,IAAIA,KAAI,KAAK,MAAM,QAAQ,IAAI,KAAK,KAAK,IAAK,SAAQA;AAAA,EAC5G;AACA,MAAI,OAAO;AACT,UAAM,QAAQ;AACd,YAAQ,IAAI,OAAO,EAAE,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,WAAO,0BAAS,YAAY;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AACD,UAAQ,IAAI,MAAM,EAAE,UAAU;AAC9B,SAAO;AACT;AAGA,MAAM,UAAU,oBAAI,QAA0B;AAC9C,IAAI,aAAa;AAoBV,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,gBAAAC,KAAY,UAAU;AAC/B;",
|
|
6
|
+
"names": ["fill", "allDrawings"]
|
|
7
7
|
}
|
|
@@ -68,7 +68,7 @@ class SimpleInputAdapter {
|
|
|
68
68
|
validatedValue = Math.floor(validatedValue);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
if ((config.type === "string" || config.type === "timeframe" || config.type === "session") && config.options && typeof value === "string") {
|
|
71
|
+
if ((config.type === "string" || config.type === "timeframe" || config.type === "session" || config.type === "symbol") && config.options && typeof value === "string") {
|
|
72
72
|
if (!config.options.includes(value)) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/runtime/adapters/SimpleInputAdapter.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Simple in-memory input adapter for demos and testing\n * Stores input values in memory and provides change notification\n * @module runtime/adapters/SimpleInputAdapter\n */\n\nimport type { InputAdapter, InputConfig } from '../types.js';\n\n/**\n * Simple in-memory input adapter\n * Stores input configurations and values in memory\n * Useful for demos, testing, and simple applications\n */\nexport class SimpleInputAdapter implements InputAdapter {\n private inputs: Map<string, { config: InputConfig; value: unknown }> = new Map();\n private changeCallbacks: Array<(id: string, value: unknown) => void> = [];\n\n /**\n * Register an input configuration\n * If already registered, returns current value without modifying config\n * @param config - Input configuration\n * @returns Current value (defval on first registration)\n */\n registerInput(config: InputConfig): unknown {\n if (!this.inputs.has(config.id)) {\n this.inputs.set(config.id, { config, value: config.defval });\n }\n return this.inputs.get(config.id)!.value;\n }\n\n /**\n * Get current value of an input\n * @param id - Input identifier\n * @returns Current value or undefined if not registered\n */\n getValue(id: string): unknown {\n return this.inputs.get(id)?.value;\n }\n\n /**\n * Set value of an input with validation\n * Validates against config constraints (min/max/step for numerics, options for strings)\n * @param id - Input identifier\n * @param value - New value\n */\n setValue(id: string, value: unknown): void {\n const input = this.inputs.get(id);\n if (!input) {\n return;\n }\n\n const { config } = input;\n let validatedValue = value;\n\n // Validate numeric inputs\n if ((config.type === 'int' || config.type === 'float') && typeof value === 'number') {\n // Apply min constraint\n if (config.min !== undefined && value < config.min) {\n validatedValue = config.min;\n }\n // Apply max constraint\n if (config.max !== undefined && value > config.max) {\n validatedValue = config.max;\n }\n // Round to step for int type\n if (config.type === 'int') {\n validatedValue = Math.floor(validatedValue as number);\n }\n }\n\n // Validate string, timeframe and session inputs with options\n if (\n (config.type === 'string' || config.type === 'timeframe' || config.type === 'session') &&\n config.options &&\n typeof value === 'string'\n ) {\n if (!config.options.includes(value)) {\n // Keep current value if invalid option\n return;\n }\n }\n\n // Validate source inputs\n if (config.type === 'source' && config.options && typeof value === 'string') {\n if (!config.options.includes(value)) {\n return;\n }\n }\n\n // Update value\n input.value = validatedValue;\n\n // Notify callbacks\n this.changeCallbacks.forEach(cb => cb(id, validatedValue));\n }\n\n /**\n * Register a callback for input value changes\n * @param callback - Function to call when any input value changes\n */\n onInputChange(callback: (id: string, value: unknown) => void): void {\n this.changeCallbacks.push(callback);\n }\n\n /**\n * Get all registered inputs (for UI rendering)\n * @returns Map of input IDs to their configs and values\n */\n getAllInputs(): Map<string, { config: InputConfig; value: unknown }> {\n return new Map(this.inputs);\n }\n\n /**\n * Clear all registered inputs\n * Useful for testing or resetting state\n */\n clear(): void {\n this.inputs.clear();\n this.changeCallbacks = [];\n }\n\n /**\n * Remove a specific change callback\n * @param callback - The callback to remove\n */\n removeChangeCallback(callback: (id: string, value: unknown) => void): void {\n const index = this.changeCallbacks.indexOf(callback);\n if (index !== -1) {\n this.changeCallbacks.splice(index, 1);\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,MAAM,mBAA2C;AAAA,EAC9C,SAA+D,oBAAI,IAAI;AAAA,EACvE,kBAA+D,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxE,cAAc,QAA8B;AAC1C,QAAI,CAAC,KAAK,OAAO,IAAI,OAAO,EAAE,GAAG;AAC/B,WAAK,OAAO,IAAI,OAAO,IAAI,EAAE,QAAQ,OAAO,OAAO,OAAO,CAAC;AAAA,IAC7D;AACA,WAAO,KAAK,OAAO,IAAI,OAAO,EAAE,EAAG;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAS,IAAqB;AAC5B,WAAO,KAAK,OAAO,IAAI,EAAE,GAAG;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAS,IAAY,OAAsB;AACzC,UAAM,QAAQ,KAAK,OAAO,IAAI,EAAE;AAChC,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,EAAE,OAAO,IAAI;AACnB,QAAI,iBAAiB;AAGrB,SAAK,OAAO,SAAS,SAAS,OAAO,SAAS,YAAY,OAAO,UAAU,UAAU;AAEnF,UAAI,OAAO,QAAQ,UAAa,QAAQ,OAAO,KAAK;AAClD,yBAAiB,OAAO;AAAA,MAC1B;AAEA,UAAI,OAAO,QAAQ,UAAa,QAAQ,OAAO,KAAK;AAClD,yBAAiB,OAAO;AAAA,MAC1B;AAEA,UAAI,OAAO,SAAS,OAAO;AACzB,yBAAiB,KAAK,MAAM,cAAwB;AAAA,MACtD;AAAA,IACF;AAGA,SACG,OAAO,SAAS,YAAY,OAAO,SAAS,eAAe,OAAO,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Simple in-memory input adapter for demos and testing\n * Stores input values in memory and provides change notification\n * @module runtime/adapters/SimpleInputAdapter\n */\n\nimport type { InputAdapter, InputConfig } from '../types.js';\n\n/**\n * Simple in-memory input adapter\n * Stores input configurations and values in memory\n * Useful for demos, testing, and simple applications\n */\nexport class SimpleInputAdapter implements InputAdapter {\n private inputs: Map<string, { config: InputConfig; value: unknown }> = new Map();\n private changeCallbacks: Array<(id: string, value: unknown) => void> = [];\n\n /**\n * Register an input configuration\n * If already registered, returns current value without modifying config\n * @param config - Input configuration\n * @returns Current value (defval on first registration)\n */\n registerInput(config: InputConfig): unknown {\n if (!this.inputs.has(config.id)) {\n this.inputs.set(config.id, { config, value: config.defval });\n }\n return this.inputs.get(config.id)!.value;\n }\n\n /**\n * Get current value of an input\n * @param id - Input identifier\n * @returns Current value or undefined if not registered\n */\n getValue(id: string): unknown {\n return this.inputs.get(id)?.value;\n }\n\n /**\n * Set value of an input with validation\n * Validates against config constraints (min/max/step for numerics, options for strings)\n * @param id - Input identifier\n * @param value - New value\n */\n setValue(id: string, value: unknown): void {\n const input = this.inputs.get(id);\n if (!input) {\n return;\n }\n\n const { config } = input;\n let validatedValue = value;\n\n // Validate numeric inputs\n if ((config.type === 'int' || config.type === 'float') && typeof value === 'number') {\n // Apply min constraint\n if (config.min !== undefined && value < config.min) {\n validatedValue = config.min;\n }\n // Apply max constraint\n if (config.max !== undefined && value > config.max) {\n validatedValue = config.max;\n }\n // Round to step for int type\n if (config.type === 'int') {\n validatedValue = Math.floor(validatedValue as number);\n }\n }\n\n // Validate string, timeframe and session inputs with options\n if (\n (config.type === 'string' || config.type === 'timeframe' || config.type === 'session' || config.type === 'symbol') &&\n config.options &&\n typeof value === 'string'\n ) {\n if (!config.options.includes(value)) {\n // Keep current value if invalid option\n return;\n }\n }\n\n // Validate source inputs\n if (config.type === 'source' && config.options && typeof value === 'string') {\n if (!config.options.includes(value)) {\n return;\n }\n }\n\n // Update value\n input.value = validatedValue;\n\n // Notify callbacks\n this.changeCallbacks.forEach(cb => cb(id, validatedValue));\n }\n\n /**\n * Register a callback for input value changes\n * @param callback - Function to call when any input value changes\n */\n onInputChange(callback: (id: string, value: unknown) => void): void {\n this.changeCallbacks.push(callback);\n }\n\n /**\n * Get all registered inputs (for UI rendering)\n * @returns Map of input IDs to their configs and values\n */\n getAllInputs(): Map<string, { config: InputConfig; value: unknown }> {\n return new Map(this.inputs);\n }\n\n /**\n * Clear all registered inputs\n * Useful for testing or resetting state\n */\n clear(): void {\n this.inputs.clear();\n this.changeCallbacks = [];\n }\n\n /**\n * Remove a specific change callback\n * @param callback - The callback to remove\n */\n removeChangeCallback(callback: (id: string, value: unknown) => void): void {\n const index = this.changeCallbacks.indexOf(callback);\n if (index !== -1) {\n this.changeCallbacks.splice(index, 1);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,MAAM,mBAA2C;AAAA,EAC9C,SAA+D,oBAAI,IAAI;AAAA,EACvE,kBAA+D,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQxE,cAAc,QAA8B;AAC1C,QAAI,CAAC,KAAK,OAAO,IAAI,OAAO,EAAE,GAAG;A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MA,cAAc,UAAsD;AAClE,SAAK,gBAAgB,KAAK,QAAQ;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAqE;AACnE,WAAO,IAAI,IAAI,KAAK,MAAM;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,QAAc;AACZ,SAAK,OAAO,MAAM;AAClB,SAAK,kBAAkB,CAAC;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAqB,UAAsD;AACzE,UAAM,QAAQ,KAAK,gBAAgB,QAAQ,QAAQ;AACnD,QAAI,UAAU,IAAI;AAChB,WAAK,gBAAgB,OAAO,OAAO,CAAC;AAAA,IACtC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @module runtime
|
|
6
6
|
*/
|
|
7
7
|
export { setContext, clearContext, getContext, registerCalculate, recalculate, plot, hline, clearPlots, getActivePlots, } from './runtime.js';
|
|
8
|
-
export { input_int, input_float, input_bool, input_string, input_source, input_timeframe, input_session, input_time, enableAutoRecalculate, disableAutoRecalculate, resetInputs, } from './inputs.js';
|
|
8
|
+
export { input_int, input_float, input_bool, input_string, input_source, input_timeframe, input_session, input_symbol, input_time, enableAutoRecalculate, disableAutoRecalculate, resetInputs, } from './inputs.js';
|
|
9
9
|
export type { OakScriptContext, ChartAdapter, InputAdapter, SeriesHandle, SeriesOptions, InputConfig, InputCondition, InputOptions, OhlcvData, PlotConfig, } from './types.js';
|
|
10
10
|
export { isInputActive } from './input-active.js';
|
|
11
11
|
export { LightweightChartsAdapter } from './adapters/LightweightChartsAdapter.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,IAAI,EACJ,KAAK,EACL,UAAU,EACV,cAAc,GACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,SAAS,EACP,UAAU,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,YAAY,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,IAAI,EACJ,KAAK,EACL,UAAU,EACV,cAAc,GACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EACZ,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACtB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,SAAS,EACP,UAAU,GACb,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,YAAY,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -33,6 +33,7 @@ __export(runtime_exports, {
|
|
|
33
33
|
input_session: () => import_inputs.input_session,
|
|
34
34
|
input_source: () => import_inputs.input_source,
|
|
35
35
|
input_string: () => import_inputs.input_string,
|
|
36
|
+
input_symbol: () => import_inputs.input_symbol,
|
|
36
37
|
input_time: () => import_inputs.input_time,
|
|
37
38
|
input_timeframe: () => import_inputs.input_timeframe,
|
|
38
39
|
isInputActive: () => import_input_active.isInputActive,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview OakScriptJS Runtime Module\n * Provides global context management, plot functions, and input handling\n * for indicators that draw through a ChartAdapter\n * @module runtime\n */\n\n// Core runtime exports\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n getActivePlots,\n} from './runtime.js';\n\n// Input function exports\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 enableAutoRecalculate,\n disableAutoRecalculate,\n resetInputs,\n} from './inputs.js';\n\n// Type exports\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputCondition,\n InputOptions,\n OhlcvData,\n PlotConfig,\n} from './types.js';\n\nexport { isInputActive } from './input-active.js';\n\n// Adapter exports\nexport { LightweightChartsAdapter } from './adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './adapters/SimpleInputAdapter.js';\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;AAQA,qBAUO;AAGP,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview OakScriptJS Runtime Module\n * Provides global context management, plot functions, and input handling\n * for indicators that draw through a ChartAdapter\n * @module runtime\n */\n\n// Core runtime exports\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n getActivePlots,\n} from './runtime.js';\n\n// Input function exports\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_source,\n input_timeframe,\n input_session,\n input_symbol,\n input_time,\n enableAutoRecalculate,\n disableAutoRecalculate,\n resetInputs,\n} from './inputs.js';\n\n// Type exports\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputCondition,\n InputOptions,\n OhlcvData,\n PlotConfig,\n} from './types.js';\n\nexport { isInputActive } from './input-active.js';\n\n// Adapter exports\nexport { LightweightChartsAdapter } from './adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './adapters/SimpleInputAdapter.js';\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;AAQA,qBAUO;AAGP,oBAaO;AAgBP,0BAA8B;AAG9B,sCAAyC;AAEzC,gCAAmC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|