oakscriptjs 0.11.6 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/drawing/registry.d.ts +2 -0
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +7 -0
- 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 +6 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/runtime/inputs.d.ts.map +1 -1
- package/dist/cjs/runtime/inputs.js +6 -2
- package/dist/cjs/runtime/inputs.js.map +2 -2
- package/dist/cjs/runtime/types.d.ts +69 -0
- 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 +24 -2
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +58 -21
- package/dist/cjs/script/index.js.map +2 -2
- package/dist/cjs/types/metadata.d.ts +8 -0
- package/dist/cjs/types/metadata.d.ts.map +1 -1
- package/dist/cjs/types/metadata.js.map +1 -1
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +13 -2
- package/dist/cjs/utils/index.js.map +2 -2
- package/dist/cjs/utils/source-resolver.d.ts +17 -0
- package/dist/cjs/utils/source-resolver.d.ts.map +1 -0
- package/dist/cjs/utils/source-resolver.js +45 -0
- package/dist/cjs/utils/source-resolver.js.map +7 -0
- package/dist/esm/drawing/registry.d.ts +2 -0
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +8 -0
- 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 +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/runtime/inputs.d.ts.map +1 -1
- package/dist/esm/runtime/inputs.js +8 -2
- package/dist/esm/runtime/inputs.js.map +1 -1
- package/dist/esm/runtime/types.d.ts +69 -0
- package/dist/esm/runtime/types.d.ts.map +1 -1
- package/dist/esm/script/index.d.ts +24 -2
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +57 -15
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/types/metadata.d.ts +8 -0
- package/dist/esm/types/metadata.d.ts.map +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +18 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/source-resolver.d.ts +17 -0
- package/dist/esm/utils/source-resolver.d.ts.map +1 -0
- package/dist/esm/utils/source-resolver.js +24 -0
- package/dist/esm/utils/source-resolver.js.map +1 -0
- package/package.json +1 -1
- package/src/drawing/registry.ts +10 -0
- package/src/index.ts +6 -1
- package/src/runtime/inputs.ts +7 -2
- package/src/runtime/types.ts +65 -0
- package/src/script/index.ts +80 -21
- package/src/types/metadata.ts +8 -0
- package/src/utils/index.ts +15 -1
- package/src/utils/source-resolver.ts +29 -0
|
@@ -111,6 +111,8 @@ export declare function setDrawingBar(barIndex: number | null, last?: boolean, l
|
|
|
111
111
|
* #176).
|
|
112
112
|
*/
|
|
113
113
|
export declare function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number;
|
|
114
|
+
/** The kinds of drawing objects created since the last {@link resetDrawings}, even when none is alive any more. */
|
|
115
|
+
export declare function createdDrawingKinds(): DrawingKind[];
|
|
114
116
|
/** Records a new object and deletes the oldest objects of its kind when the count is too high. */
|
|
115
117
|
export declare function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K];
|
|
116
118
|
/** Deletes an object (no effect when it is already deleted). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/drawing/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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AG,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAE1E;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,SAAS,GAAE,aAAkB,GAAG,IAAI,CAgBjE;AAED,uGAAuG;AACvG,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI,CAE/D"}
|
|
@@ -23,6 +23,7 @@ __export(registry_exports, {
|
|
|
23
23
|
MAX_DRAWING_BARS_FORWARD: () => MAX_DRAWING_BARS_FORWARD,
|
|
24
24
|
all: () => all,
|
|
25
25
|
checkBarIndex: () => checkBarIndex,
|
|
26
|
+
createdDrawingKinds: () => createdDrawingKinds,
|
|
26
27
|
holdDrawing: () => holdDrawing,
|
|
27
28
|
isDeleted: () => isDeleted,
|
|
28
29
|
register: () => register,
|
|
@@ -171,8 +172,13 @@ function cutOldest(kind, list, obj, only) {
|
|
|
171
172
|
list.push(...kept);
|
|
172
173
|
return cut;
|
|
173
174
|
}
|
|
175
|
+
const created = /* @__PURE__ */ new Set();
|
|
176
|
+
function createdDrawingKinds() {
|
|
177
|
+
return [...created];
|
|
178
|
+
}
|
|
174
179
|
function register(kind, obj) {
|
|
175
180
|
const list = live[kind];
|
|
181
|
+
created.add(kind);
|
|
176
182
|
if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);
|
|
177
183
|
if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;
|
|
178
184
|
list.push(obj);
|
|
@@ -223,6 +229,7 @@ function all(kind) {
|
|
|
223
229
|
}
|
|
224
230
|
function resetDrawings(newLimits = {}) {
|
|
225
231
|
for (const kind of Object.keys(live)) live[kind].length = 0;
|
|
232
|
+
created.clear();
|
|
226
233
|
held = /* @__PURE__ */ new WeakMap();
|
|
227
234
|
releasedAt = /* @__PURE__ */ new WeakMap();
|
|
228
235
|
heldAt = /* @__PURE__ */ new WeakMap();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/drawing/registry.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Registry of the live drawing objects (lines, labels, boxes, polylines, linefills, tables), as PineScript\n * keeps them. PineScript rules:\n *\n * - `line.all`, `label.all`, ... list the live objects in creation order (a copy of the list)\n * - `delete` removes an object; the object becomes `na`: its getters return NaN and its setters\n * do nothing. Deleting a line with `line.delete` also deletes the linefills that use it\n * - when a creation brings the count above `max_*_count + 5`, the oldest objects are deleted until\n * `max_*_count` remain (default 50). Copies count as creations. Linefills follow the same rule with\n * `max_lines_count`; lines deleted by this rule do not delete their linefills\n * - the object that was just created is never deleted by this rule\n * - an object that a `var` variable of the drawing type refers to is never deleted by this rule, and it still counts\n * (measured for lines, labels and boxes: with 9 held boxes and a maximum of 50, 9 held + 46 others stay; with 8\n * held lines and a maximum of 5, the 8 and the newest line stay). The protection starts on the bar after the\n * assignment: 12 `var` lines created on the first bar with a maximum of 5 lose the first 6. Only\n * the variable itself protects: an object in a `var` array, in a field of a user type or in a variable that got\n * another object or `na` later is deleted like any other. JavaScript has no `var` declaration to observe, so the\n * script says it: {@link varDrawing} (a variable), or {@link holdDrawing} / {@link releaseDrawing}\n * - linefills have the limit of `max_lines_count` with another rule for the held ones (measured on one script, two\n * long runs): a fill is skipped when a `var` variable holds it or released it less than 5,000 bars ago (the bar\n * of {@link setDrawingBar}); when the count is still above the maximum + 5 after that, the oldest fills are\n * deleted until the maximum remain, the held ones too\n * - the script deletes count (`line.delete`, `label.delete`, ...): each kind has a number `P` of deleted objects. A\n * delete adds 1; a creation first sets `P` to 0 when it is 5 or more (3 or more for polylines)\n * - polylines use `P` on every bar: a creation cuts when the count is above `max_polylines_count + 5 + P`, down to\n * the maximum + `P`, and the polylines of the cut are added to `P`. A script that deletes and creates one polyline\n * per bar therefore sees the cut 0, 1 or 2 bars late\n * - lines, labels and boxes use `P` on the last bar only, with its value at the start of that bar: there the cut is\n * above the maximum + 5 + `P`, down to the maximum + `P` (up to 4 more objects)\n * - the last bar has rules of its own (measured from the count after each creation, on a closed and on an open last\n * bar): a cut deletes the objects of the bars before first, at most those (a line takes its linefills with it);\n * once none is left, a cut deletes objects of the last bar as on any bar. With 10 lines and a maximum of 10, 13\n * lines on the last bar leave these 13: the cut at the 16th line deletes the 10 old ones only. Lines, labels and\n * boxes: equal to PineScript, count after every operation and objects alive at the end, on 72 of 72 runs checked\n * after the rule was written (and 218 of 218 end states before)\n * - polylines on the last bar: the `P` carried from the bar before is counted twice (the first creation adds it once\n * more, unless it sets `P` to 0), later creations do not set `P` to 0, and the polylines of the bars before that a\n * cut deletes are added to `P`. Once none is\n * left, `P` is at least the number of polylines of the bars before deleted on the last bar (by the count or by\n * the script) and a cut deletes polylines of the last bar: a script that deletes its 100 polylines and creates 200\n * on the last bar keeps them all (#176). Equal to PineScript for the polylines alive at the end on 271 of\n * 281 probe runs; the count inside the bar can differ when the script deletes polylines of the last bar\n *\n * - a bar index (`xloc.bar_index`) more than 10,000 bars before the current bar stops the script (runtime error\n * RE10026) in `line.new`, `box.new`, `label.new`, `polyline.new` and the setters of x. The current bar is the one\n * of `eachBar` in a script run; a port with its own bar loop gives it with {@link setDrawingBar}\n *\n * The script API (`executeScript`) resets the registry at the start of every run and applies the\n * `max_*_count` values of `indicator()`. Outside a script run the registry is global to the module.\n *\n * @module drawing/registry\n */\n\nimport type { Box, Label, Line, Linefill, Polyline, Table } from '../types/index.js';\n\nexport type DrawingKind = 'line' | 'label' | 'box' | 'polyline' | 'linefill' | 'table';\n\ninterface DrawingTypes {\n line: Line;\n label: Label;\n box: Box;\n polyline: Polyline;\n linefill: Linefill;\n table: Table;\n}\n\n/** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */\nexport const DEFAULT_MAX_COUNT = 50;\n/** Objects above the maximum that PineScript keeps before it deletes the oldest ones. */\nconst SLACK = 5;\n\nexport type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;\n\nconst live: { [K in DrawingKind]: Array<DrawingTypes[K]> } = {\n line: [],\n label: [],\n box: [],\n polyline: [],\n linefill: [],\n table: [],\n};\nlet limits: Required<DrawingLimits> = {\n line: DEFAULT_MAX_COUNT,\n label: DEFAULT_MAX_COUNT,\n box: DEFAULT_MAX_COUNT,\n polyline: DEFAULT_MAX_COUNT,\n};\nconst deleted = new WeakSet<object>();\n/** Objects held by a `var` variable, with the number of variables that hold them. */\nlet held = new WeakMap<object, number>();\n/** Bar on which the last `var` variable released an object (linefill rule). */\nlet releasedAt = new WeakMap<object, number>();\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\n/** Bar on which a `var` variable got an object: the maximum count skips it from the next bar on. */\nlet heldAt = new WeakMap<object, number>();\n/** Kinds with a maximum count of their own. */\ntype CountedKind = 'line' | 'label' | 'box' | 'polyline';\nconst COUNTED_KINDS: readonly CountedKind[] = ['line', 'label', 'box', 'polyline'];\nconst isCounted = (kind: DrawingKind): kind is CountedKind => (COUNTED_KINDS as readonly DrawingKind[]).includes(kind);\n/** `P` of the module notes: objects deleted by the script (for polylines also by the maximum count). */\nlet pending: Record<CountedKind, number> = { line: 0, label: 0, box: 0, polyline: 0 };\n/** A creation sets `P` to 0 from this value on. */\nconst PENDING_RESET: Record<CountedKind, number> = { line: 5, label: 5, box: 5, polyline: 3 };\n\n/**\n * Marks an object as held by a `var` variable (PineScript `var line l = ...` or `l := line.new(...)` on a `var`\n * variable): the maximum count never deletes it, and it still counts. Returns the object.\n */\nexport function holdDrawing<T extends object>(obj: T): T {\n if (!held.has(obj)) {\n if (currentBar === null) heldAt.delete(obj);\n else heldAt.set(obj, currentBar);\n }\n held.set(obj, (held.get(obj) ?? 0) + 1);\n return obj;\n}\n\n/** The `var` variable no longer refers to the object (it got another object or `na`). */\nexport function releaseDrawing(obj: object | null | undefined): void {\n if (!obj) return;\n const count = held.get(obj) ?? 0;\n if (count > 1) held.set(obj, count - 1);\n else if (held.delete(obj) && currentBar !== null) releasedAt.set(obj, currentBar);\n}\n\n/** Held by a `var` variable since a bar before the current one (or outside a bar loop). */\nfunction heldBefore(obj: object): boolean {\n if (!held.has(obj)) return false;\n const bar = heldAt.get(obj);\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n if (held.has(obj)) return true;\n const bar = releasedAt.get(obj);\n return bar !== undefined && currentBar !== null && currentBar - bar < LINEFILL_RELEASE_BARS;\n}\n\n/** A `var` variable of a drawing type: see {@link varDrawing}. */\nexport interface DrawingVariable<T extends object> {\n /** The object of the variable; setting it holds the new object and releases the one before */\n value: T | undefined;\n}\n\n/**\n * A PineScript `var` variable of a drawing type (`var line l = na`). The object it refers to is not deleted by the\n * maximum count; assigning another object (or `undefined` for `na`) releases the one before.\n *\n * @example\n * ```typescript\n * // Pine: var line level = na\n * // level := line.new(bar_index, close, bar_index + 1, close)\n * const level = varDrawing<Line>();\n * level.value = line.new(i, close, i + 1, close);\n * ```\n */\nexport function varDrawing<T extends object>(initial?: T): DrawingVariable<T> {\n let current: T | undefined = initial ? holdDrawing(initial) : undefined;\n return {\n get value() {\n return current;\n },\n set value(next: T | undefined) {\n if (next === current) return;\n releaseDrawing(current);\n current = next ? holdDrawing(next) : undefined;\n },\n };\n}\n\n/** Largest distance, in bars, of a bar index before the current bar (PineScript runtime error RE10026 above it). */\nexport const MAX_DRAWING_BARS_BACK = 10000;\n/** Largest distance, in bars, of a bar index after the last bar of the data (PineScript runtime error RE10020 above it). */\nexport const MAX_DRAWING_BARS_FORWARD = 500;\nlet currentBar: number | null = null;\nlet lastBarIndex: number | null = null;\n\n/** Kinds whose allowance on the last bar is the `P` they had when the bar started. */\ntype AllowanceKind = 'line' | 'label' | 'box';\nconst isAllowanceKind = (kind: DrawingKind): kind is AllowanceKind => kind === 'line' || kind === 'label' || kind === 'box';\n\n/** State of the last bar (see the module notes). */\ninterface LastBar {\n bar: number;\n /** The objects alive when the bar started (the objects of the bars before) */\n old: Set<object>;\n /** `P` of lines, labels and boxes when the bar started: their allowance for the whole bar */\n allowance: Record<AllowanceKind, number>;\n /** `P` of polylines when the bar started */\n carried: number;\n /** A polyline was created on this bar */\n polyline: boolean;\n /** Polylines of the bars before deleted on this bar (by the count or by the script) */\n oldPolylinesGone: number;\n}\nlet lastBar: LastBar | null = null;\n\n/**\n * Tells the drawing functions which bar is being calculated (`bar_index`), so that a bar index more than 10,000\n * bars back throws as in PineScript; `null` turns the check off. `eachBar` of the script API calls it.\n *\n * The bar also dates the objects held by a `var` variable (protected from the next bar on). `last` says that it is\n * the last bar of the data, which has rules of its own for the maximum count. `lastIndex` is the bar index of the\n * last bar of the data (PineScript `last_bar_index`): with it, a bar index more than 500 bars after it throws, also\n * on the bars before the last one (RE10020).\n */\nexport function setDrawingBar(barIndex: number | null, last: boolean = false, lastIndex?: number): void {\n if (lastBar && !(last && barIndex === lastBar.bar)) lastBar = null;\n currentBar = barIndex;\n lastBarIndex = barIndex === null ? null : (lastIndex ?? (last ? barIndex : null));\n if (barIndex !== null && last && !lastBar) {\n const start = (kind: AllowanceKind): number => (pending[kind] >= PENDING_RESET[kind] ? 0 : pending[kind]);\n lastBar = {\n bar: barIndex,\n old: new Set<object>([...live.line, ...live.label, ...live.box, ...live.polyline]),\n allowance: { line: start('line'), label: start('label'), box: start('box') },\n carried: pending.polyline,\n polyline: false,\n oldPolylinesGone: 0,\n };\n }\n}\n\n/**\n * Throws the PineScript runtime error RE10026 when `x` is a bar index more than 10,000 bars before the current bar,\n * and RE10020 when it is more than 500 bars after the last bar of the data (when {@link setDrawingBar} knows it).\n * `method` and `variable` are the names of the PineScript message (\"line.new\", \"x1\").\n *\n * Returns `x`, truncated when it is a bar index: PineScript's x is an int (a box from 5537.94 starts on bar 5537,\n * #176).\n */\nexport function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number {\n if ((xloc ?? 'bar_index') !== 'bar_index') return x;\n x = Math.trunc(x);\n if (currentBar === null) return x;\n if (lastBarIndex !== null && x - lastBarIndex > MAX_DRAWING_BARS_FORWARD) {\n throw new Error(\n `Error on bar ${currentBar}: Objects positioned using xloc.bar_index cannot be drawn further than ` +\n `${MAX_DRAWING_BARS_FORWARD} bars into the future.`\n );\n }\n if (currentBar - x > MAX_DRAWING_BARS_BACK) {\n throw new Error(\n `Error on bar ${currentBar}: Bar index value of the \\`${variable}\\` argument (${x}) in \\`${method}()\\` is too far ` +\n 'from the current bar index. Try using `time` instead.'\n );\n }\n return x;\n}\n\n/** Numeric fields that become NaN when an object is deleted, so that its getters return `na`. */\nconst COORDINATES: { [K in DrawingKind]: Array<keyof DrawingTypes[K]> } = {\n line: ['x1', 'y1', 'x2', 'y2'],\n label: ['x', 'y'],\n box: ['left', 'top', 'right', 'bottom'],\n polyline: [],\n linefill: [],\n table: [],\n};\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n deleted.add(obj);\n for (const field of COORDINATES[kind]) (obj as unknown as Record<string, unknown>)[field as string] = NaN;\n if (kind === 'line' && explicit) {\n for (const fill of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove('linefill', fill);\n }\n}\n\n/** Objects above the maximum that the rule allows for, besides the 5: `P` of the module notes. */\nfunction allowance(kind: DrawingKind): number {\n if (kind === 'polyline') return pending.polyline;\n return lastBar && isAllowanceKind(kind) ? lastBar.allowance[kind] : 0;\n}\n\n/**\n * The maximum count after the creation of `obj`: removes the objects to delete from `list` (the oldest first; the new\n * object and an object held by a `var` variable are skipped and still count) and returns them.\n */\nfunction cutOldest<K extends DrawingKind>(\n kind: K,\n list: Array<DrawingTypes[K]>,\n obj: DrawingTypes[K],\n only?: (old: object) => boolean\n): Array<DrawingTypes[K]> {\n if (kind === 'table') return []; // tables have no maximum count\n const max = limits[kind === 'linefill' ? 'line' : (kind as keyof DrawingLimits)] + allowance(kind);\n if (list.length <= max + SLACK) return [];\n const kept: Array<DrawingTypes[K]> = [];\n const cut: Array<DrawingTypes[K]> = [];\n let excess = list.length - max;\n for (const old of list) {\n if (excess > 0 && old !== obj && (!only || only(old)) && !(kind === 'linefill' ? fillProtected(old) : heldBefore(old))) {\n excess--;\n cut.push(old);\n } else kept.push(old);\n }\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (kind === 'linefill' && kept.length > max + SLACK) cut.push(...kept.splice(0, kept.length - max));\n list.length = 0;\n list.push(...kept);\n return cut;\n}\n\n/** Records a new object and deletes the oldest objects of its kind when the count is too high. */\nexport function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n const list = live[kind];\n if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);\n if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;\n list.push(obj);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) markDeleted(kind, old, false);\n return obj;\n}\n\n/** An object created on the last bar (see the module notes). */\nfunction registerLast<K extends DrawingKind>(bar: LastBar, kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n if (kind === 'polyline' && !bar.polyline) {\n bar.polyline = true;\n if (pending.polyline >= PENDING_RESET.polyline) pending.polyline = 0;\n else pending.polyline += bar.carried; // counted twice\n }\n const list = live[kind];\n list.push(obj);\n const isOld = (old: object): boolean => bar.old.has(old);\n if (list.some((old) => old !== obj && isOld(old) && !heldBefore(old))) {\n // the objects of the bars before only; a line takes its linefills with it\n const cut = cutOldest(kind, list, obj, isOld);\n if (kind === 'polyline') {\n pending.polyline += cut.length;\n bar.oldPolylinesGone += cut.length;\n }\n for (const old of cut) markDeleted(kind, old, true);\n } else {\n // the polylines of the bars before deleted on this bar count before the cut (#176)\n if (kind === 'polyline' && pending.polyline < bar.oldPolylinesGone) pending.polyline = bar.oldPolylinesGone;\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline' && cut.length > 0) pending.polyline = bar.oldPolylinesGone;\n for (const old of cut) markDeleted(kind, old, false);\n }\n return obj;\n}\n\n/** Deletes an object (no effect when it is already deleted). */\nexport function remove<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): void {\n const list = live[kind];\n const index = list.indexOf(obj);\n if (index !== -1) {\n list.splice(index, 1);\n if (isCounted(kind)) pending[kind]++;\n if (kind === 'polyline' && lastBar?.old.has(obj)) lastBar.oldPolylinesGone++;\n }\n if (!deleted.has(obj)) markDeleted(kind, obj, true);\n}\n\n/** True when the object was deleted (by `delete` or by the maximum count). */\nexport function isDeleted(obj: unknown): boolean {\n return typeof obj === 'object' && obj !== null && deleted.has(obj);\n}\n\n/** The live objects of a kind, in creation order (a new array). */\nexport function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[K]> {\n return [...live[kind]] as Array<DrawingTypes[K]>;\n}\n\n/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */\nexport function resetDrawings(newLimits: DrawingLimits = {}): void {\n for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;\n held = new WeakMap();\n releasedAt = new WeakMap();\n heldAt = new WeakMap();\n pending = { line: 0, label: 0, box: 0, polyline: 0 };\n currentBar = null;\n lastBarIndex = null;\n lastBar = null;\n limits = {\n line: newLimits.line ?? DEFAULT_MAX_COUNT,\n label: newLimits.label ?? DEFAULT_MAX_COUNT,\n box: newLimits.box ?? DEFAULT_MAX_COUNT,\n polyline: newLimits.polyline ?? DEFAULT_MAX_COUNT,\n };\n}\n\n/** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */\nexport function setDrawingLimits(newLimits: DrawingLimits): void {\n limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== undefined)) };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AQ,OAAO,KAAK,IAAI,EAAoB,MAAK,IAAI,EAAE,SAAS;AAC3E,SAAO,oBAAI,QAAQ;AACnB,eAAa,oBAAI,QAAQ;AACzB,WAAS,oBAAI,QAAQ;AACrB,YAAU,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,EAAE;AACnD,eAAa;AACb,iBAAe;AACf,YAAU;AACV,WAAS;AAAA,IACP,MAAM,UAAU,QAAQ;AAAA,IACxB,OAAO,UAAU,SAAS;AAAA,IAC1B,KAAK,UAAU,OAAO;AAAA,IACtB,UAAU,UAAU,YAAY;AAAA,EAClC;AACF;AAGO,SAAS,iBAAiB,WAAgC;AAC/D,WAAS,EAAE,GAAG,QAAQ,GAAG,OAAO,YAAY,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,CAAC,EAAE;AAC5G;",
|
|
4
|
+
"sourcesContent": ["/**\n * Registry of the live drawing objects (lines, labels, boxes, polylines, linefills, tables), as PineScript\n * keeps them. PineScript rules:\n *\n * - `line.all`, `label.all`, ... list the live objects in creation order (a copy of the list)\n * - `delete` removes an object; the object becomes `na`: its getters return NaN and its setters\n * do nothing. Deleting a line with `line.delete` also deletes the linefills that use it\n * - when a creation brings the count above `max_*_count + 5`, the oldest objects are deleted until\n * `max_*_count` remain (default 50). Copies count as creations. Linefills follow the same rule with\n * `max_lines_count`; lines deleted by this rule do not delete their linefills\n * - the object that was just created is never deleted by this rule\n * - an object that a `var` variable of the drawing type refers to is never deleted by this rule, and it still counts\n * (measured for lines, labels and boxes: with 9 held boxes and a maximum of 50, 9 held + 46 others stay; with 8\n * held lines and a maximum of 5, the 8 and the newest line stay). The protection starts on the bar after the\n * assignment: 12 `var` lines created on the first bar with a maximum of 5 lose the first 6. Only\n * the variable itself protects: an object in a `var` array, in a field of a user type or in a variable that got\n * another object or `na` later is deleted like any other. JavaScript has no `var` declaration to observe, so the\n * script says it: {@link varDrawing} (a variable), or {@link holdDrawing} / {@link releaseDrawing}\n * - linefills have the limit of `max_lines_count` with another rule for the held ones (measured on one script, two\n * long runs): a fill is skipped when a `var` variable holds it or released it less than 5,000 bars ago (the bar\n * of {@link setDrawingBar}); when the count is still above the maximum + 5 after that, the oldest fills are\n * deleted until the maximum remain, the held ones too\n * - the script deletes count (`line.delete`, `label.delete`, ...): each kind has a number `P` of deleted objects. A\n * delete adds 1; a creation first sets `P` to 0 when it is 5 or more (3 or more for polylines)\n * - polylines use `P` on every bar: a creation cuts when the count is above `max_polylines_count + 5 + P`, down to\n * the maximum + `P`, and the polylines of the cut are added to `P`. A script that deletes and creates one polyline\n * per bar therefore sees the cut 0, 1 or 2 bars late\n * - lines, labels and boxes use `P` on the last bar only, with its value at the start of that bar: there the cut is\n * above the maximum + 5 + `P`, down to the maximum + `P` (up to 4 more objects)\n * - the last bar has rules of its own (measured from the count after each creation, on a closed and on an open last\n * bar): a cut deletes the objects of the bars before first, at most those (a line takes its linefills with it);\n * once none is left, a cut deletes objects of the last bar as on any bar. With 10 lines and a maximum of 10, 13\n * lines on the last bar leave these 13: the cut at the 16th line deletes the 10 old ones only. Lines, labels and\n * boxes: equal to PineScript, count after every operation and objects alive at the end, on 72 of 72 runs checked\n * after the rule was written (and 218 of 218 end states before)\n * - polylines on the last bar: the `P` carried from the bar before is counted twice (the first creation adds it once\n * more, unless it sets `P` to 0), later creations do not set `P` to 0, and the polylines of the bars before that a\n * cut deletes are added to `P`. Once none is\n * left, `P` is at least the number of polylines of the bars before deleted on the last bar (by the count or by\n * the script) and a cut deletes polylines of the last bar: a script that deletes its 100 polylines and creates 200\n * on the last bar keeps them all (#176). Equal to PineScript for the polylines alive at the end on 271 of\n * 281 probe runs; the count inside the bar can differ when the script deletes polylines of the last bar\n *\n * - a bar index (`xloc.bar_index`) more than 10,000 bars before the current bar stops the script (runtime error\n * RE10026) in `line.new`, `box.new`, `label.new`, `polyline.new` and the setters of x. The current bar is the one\n * of `eachBar` in a script run; a port with its own bar loop gives it with {@link setDrawingBar}\n *\n * The script API (`executeScript`) resets the registry at the start of every run and applies the\n * `max_*_count` values of `indicator()`. Outside a script run the registry is global to the module.\n *\n * @module drawing/registry\n */\n\nimport type { Box, Label, Line, Linefill, Polyline, Table } from '../types/index.js';\n\nexport type DrawingKind = 'line' | 'label' | 'box' | 'polyline' | 'linefill' | 'table';\n\ninterface DrawingTypes {\n line: Line;\n label: Label;\n box: Box;\n polyline: Polyline;\n linefill: Linefill;\n table: Table;\n}\n\n/** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */\nexport const DEFAULT_MAX_COUNT = 50;\n/** Objects above the maximum that PineScript keeps before it deletes the oldest ones. */\nconst SLACK = 5;\n\nexport type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;\n\nconst live: { [K in DrawingKind]: Array<DrawingTypes[K]> } = {\n line: [],\n label: [],\n box: [],\n polyline: [],\n linefill: [],\n table: [],\n};\nlet limits: Required<DrawingLimits> = {\n line: DEFAULT_MAX_COUNT,\n label: DEFAULT_MAX_COUNT,\n box: DEFAULT_MAX_COUNT,\n polyline: DEFAULT_MAX_COUNT,\n};\nconst deleted = new WeakSet<object>();\n/** Objects held by a `var` variable, with the number of variables that hold them. */\nlet held = new WeakMap<object, number>();\n/** Bar on which the last `var` variable released an object (linefill rule). */\nlet releasedAt = new WeakMap<object, number>();\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\n/** Bar on which a `var` variable got an object: the maximum count skips it from the next bar on. */\nlet heldAt = new WeakMap<object, number>();\n/** Kinds with a maximum count of their own. */\ntype CountedKind = 'line' | 'label' | 'box' | 'polyline';\nconst COUNTED_KINDS: readonly CountedKind[] = ['line', 'label', 'box', 'polyline'];\nconst isCounted = (kind: DrawingKind): kind is CountedKind => (COUNTED_KINDS as readonly DrawingKind[]).includes(kind);\n/** `P` of the module notes: objects deleted by the script (for polylines also by the maximum count). */\nlet pending: Record<CountedKind, number> = { line: 0, label: 0, box: 0, polyline: 0 };\n/** A creation sets `P` to 0 from this value on. */\nconst PENDING_RESET: Record<CountedKind, number> = { line: 5, label: 5, box: 5, polyline: 3 };\n\n/**\n * Marks an object as held by a `var` variable (PineScript `var line l = ...` or `l := line.new(...)` on a `var`\n * variable): the maximum count never deletes it, and it still counts. Returns the object.\n */\nexport function holdDrawing<T extends object>(obj: T): T {\n if (!held.has(obj)) {\n if (currentBar === null) heldAt.delete(obj);\n else heldAt.set(obj, currentBar);\n }\n held.set(obj, (held.get(obj) ?? 0) + 1);\n return obj;\n}\n\n/** The `var` variable no longer refers to the object (it got another object or `na`). */\nexport function releaseDrawing(obj: object | null | undefined): void {\n if (!obj) return;\n const count = held.get(obj) ?? 0;\n if (count > 1) held.set(obj, count - 1);\n else if (held.delete(obj) && currentBar !== null) releasedAt.set(obj, currentBar);\n}\n\n/** Held by a `var` variable since a bar before the current one (or outside a bar loop). */\nfunction heldBefore(obj: object): boolean {\n if (!held.has(obj)) return false;\n const bar = heldAt.get(obj);\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n if (held.has(obj)) return true;\n const bar = releasedAt.get(obj);\n return bar !== undefined && currentBar !== null && currentBar - bar < LINEFILL_RELEASE_BARS;\n}\n\n/** A `var` variable of a drawing type: see {@link varDrawing}. */\nexport interface DrawingVariable<T extends object> {\n /** The object of the variable; setting it holds the new object and releases the one before */\n value: T | undefined;\n}\n\n/**\n * A PineScript `var` variable of a drawing type (`var line l = na`). The object it refers to is not deleted by the\n * maximum count; assigning another object (or `undefined` for `na`) releases the one before.\n *\n * @example\n * ```typescript\n * // Pine: var line level = na\n * // level := line.new(bar_index, close, bar_index + 1, close)\n * const level = varDrawing<Line>();\n * level.value = line.new(i, close, i + 1, close);\n * ```\n */\nexport function varDrawing<T extends object>(initial?: T): DrawingVariable<T> {\n let current: T | undefined = initial ? holdDrawing(initial) : undefined;\n return {\n get value() {\n return current;\n },\n set value(next: T | undefined) {\n if (next === current) return;\n releaseDrawing(current);\n current = next ? holdDrawing(next) : undefined;\n },\n };\n}\n\n/** Largest distance, in bars, of a bar index before the current bar (PineScript runtime error RE10026 above it). */\nexport const MAX_DRAWING_BARS_BACK = 10000;\n/** Largest distance, in bars, of a bar index after the last bar of the data (PineScript runtime error RE10020 above it). */\nexport const MAX_DRAWING_BARS_FORWARD = 500;\nlet currentBar: number | null = null;\nlet lastBarIndex: number | null = null;\n\n/** Kinds whose allowance on the last bar is the `P` they had when the bar started. */\ntype AllowanceKind = 'line' | 'label' | 'box';\nconst isAllowanceKind = (kind: DrawingKind): kind is AllowanceKind => kind === 'line' || kind === 'label' || kind === 'box';\n\n/** State of the last bar (see the module notes). */\ninterface LastBar {\n bar: number;\n /** The objects alive when the bar started (the objects of the bars before) */\n old: Set<object>;\n /** `P` of lines, labels and boxes when the bar started: their allowance for the whole bar */\n allowance: Record<AllowanceKind, number>;\n /** `P` of polylines when the bar started */\n carried: number;\n /** A polyline was created on this bar */\n polyline: boolean;\n /** Polylines of the bars before deleted on this bar (by the count or by the script) */\n oldPolylinesGone: number;\n}\nlet lastBar: LastBar | null = null;\n\n/**\n * Tells the drawing functions which bar is being calculated (`bar_index`), so that a bar index more than 10,000\n * bars back throws as in PineScript; `null` turns the check off. `eachBar` of the script API calls it.\n *\n * The bar also dates the objects held by a `var` variable (protected from the next bar on). `last` says that it is\n * the last bar of the data, which has rules of its own for the maximum count. `lastIndex` is the bar index of the\n * last bar of the data (PineScript `last_bar_index`): with it, a bar index more than 500 bars after it throws, also\n * on the bars before the last one (RE10020).\n */\nexport function setDrawingBar(barIndex: number | null, last: boolean = false, lastIndex?: number): void {\n if (lastBar && !(last && barIndex === lastBar.bar)) lastBar = null;\n currentBar = barIndex;\n lastBarIndex = barIndex === null ? null : (lastIndex ?? (last ? barIndex : null));\n if (barIndex !== null && last && !lastBar) {\n const start = (kind: AllowanceKind): number => (pending[kind] >= PENDING_RESET[kind] ? 0 : pending[kind]);\n lastBar = {\n bar: barIndex,\n old: new Set<object>([...live.line, ...live.label, ...live.box, ...live.polyline]),\n allowance: { line: start('line'), label: start('label'), box: start('box') },\n carried: pending.polyline,\n polyline: false,\n oldPolylinesGone: 0,\n };\n }\n}\n\n/**\n * Throws the PineScript runtime error RE10026 when `x` is a bar index more than 10,000 bars before the current bar,\n * and RE10020 when it is more than 500 bars after the last bar of the data (when {@link setDrawingBar} knows it).\n * `method` and `variable` are the names of the PineScript message (\"line.new\", \"x1\").\n *\n * Returns `x`, truncated when it is a bar index: PineScript's x is an int (a box from 5537.94 starts on bar 5537,\n * #176).\n */\nexport function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number {\n if ((xloc ?? 'bar_index') !== 'bar_index') return x;\n x = Math.trunc(x);\n if (currentBar === null) return x;\n if (lastBarIndex !== null && x - lastBarIndex > MAX_DRAWING_BARS_FORWARD) {\n throw new Error(\n `Error on bar ${currentBar}: Objects positioned using xloc.bar_index cannot be drawn further than ` +\n `${MAX_DRAWING_BARS_FORWARD} bars into the future.`\n );\n }\n if (currentBar - x > MAX_DRAWING_BARS_BACK) {\n throw new Error(\n `Error on bar ${currentBar}: Bar index value of the \\`${variable}\\` argument (${x}) in \\`${method}()\\` is too far ` +\n 'from the current bar index. Try using `time` instead.'\n );\n }\n return x;\n}\n\n/** Numeric fields that become NaN when an object is deleted, so that its getters return `na`. */\nconst COORDINATES: { [K in DrawingKind]: Array<keyof DrawingTypes[K]> } = {\n line: ['x1', 'y1', 'x2', 'y2'],\n label: ['x', 'y'],\n box: ['left', 'top', 'right', 'bottom'],\n polyline: [],\n linefill: [],\n table: [],\n};\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n deleted.add(obj);\n for (const field of COORDINATES[kind]) (obj as unknown as Record<string, unknown>)[field as string] = NaN;\n if (kind === 'line' && explicit) {\n for (const fill of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove('linefill', fill);\n }\n}\n\n/** Objects above the maximum that the rule allows for, besides the 5: `P` of the module notes. */\nfunction allowance(kind: DrawingKind): number {\n if (kind === 'polyline') return pending.polyline;\n return lastBar && isAllowanceKind(kind) ? lastBar.allowance[kind] : 0;\n}\n\n/**\n * The maximum count after the creation of `obj`: removes the objects to delete from `list` (the oldest first; the new\n * object and an object held by a `var` variable are skipped and still count) and returns them.\n */\nfunction cutOldest<K extends DrawingKind>(\n kind: K,\n list: Array<DrawingTypes[K]>,\n obj: DrawingTypes[K],\n only?: (old: object) => boolean\n): Array<DrawingTypes[K]> {\n if (kind === 'table') return []; // tables have no maximum count\n const max = limits[kind === 'linefill' ? 'line' : (kind as keyof DrawingLimits)] + allowance(kind);\n if (list.length <= max + SLACK) return [];\n const kept: Array<DrawingTypes[K]> = [];\n const cut: Array<DrawingTypes[K]> = [];\n let excess = list.length - max;\n for (const old of list) {\n if (excess > 0 && old !== obj && (!only || only(old)) && !(kind === 'linefill' ? fillProtected(old) : heldBefore(old))) {\n excess--;\n cut.push(old);\n } else kept.push(old);\n }\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (kind === 'linefill' && kept.length > max + SLACK) cut.push(...kept.splice(0, kept.length - max));\n list.length = 0;\n list.push(...kept);\n return cut;\n}\n\n/** Kinds of the objects created since the last reset (a table counts too), in no order. */\nconst created = new Set<DrawingKind>();\n\n/** The kinds of drawing objects created since the last {@link resetDrawings}, even when none is alive any more. */\nexport function createdDrawingKinds(): DrawingKind[] {\n return [...created];\n}\n\n/** Records a new object and deletes the oldest objects of its kind when the count is too high. */\nexport function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n const list = live[kind];\n created.add(kind);\n if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);\n if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;\n list.push(obj);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) markDeleted(kind, old, false);\n return obj;\n}\n\n/** An object created on the last bar (see the module notes). */\nfunction registerLast<K extends DrawingKind>(bar: LastBar, kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n if (kind === 'polyline' && !bar.polyline) {\n bar.polyline = true;\n if (pending.polyline >= PENDING_RESET.polyline) pending.polyline = 0;\n else pending.polyline += bar.carried; // counted twice\n }\n const list = live[kind];\n list.push(obj);\n const isOld = (old: object): boolean => bar.old.has(old);\n if (list.some((old) => old !== obj && isOld(old) && !heldBefore(old))) {\n // the objects of the bars before only; a line takes its linefills with it\n const cut = cutOldest(kind, list, obj, isOld);\n if (kind === 'polyline') {\n pending.polyline += cut.length;\n bar.oldPolylinesGone += cut.length;\n }\n for (const old of cut) markDeleted(kind, old, true);\n } else {\n // the polylines of the bars before deleted on this bar count before the cut (#176)\n if (kind === 'polyline' && pending.polyline < bar.oldPolylinesGone) pending.polyline = bar.oldPolylinesGone;\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline' && cut.length > 0) pending.polyline = bar.oldPolylinesGone;\n for (const old of cut) markDeleted(kind, old, false);\n }\n return obj;\n}\n\n/** Deletes an object (no effect when it is already deleted). */\nexport function remove<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): void {\n const list = live[kind];\n const index = list.indexOf(obj);\n if (index !== -1) {\n list.splice(index, 1);\n if (isCounted(kind)) pending[kind]++;\n if (kind === 'polyline' && lastBar?.old.has(obj)) lastBar.oldPolylinesGone++;\n }\n if (!deleted.has(obj)) markDeleted(kind, obj, true);\n}\n\n/** True when the object was deleted (by `delete` or by the maximum count). */\nexport function isDeleted(obj: unknown): boolean {\n return typeof obj === 'object' && obj !== null && deleted.has(obj);\n}\n\n/** The live objects of a kind, in creation order (a new array). */\nexport function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[K]> {\n return [...live[kind]] as Array<DrawingTypes[K]>;\n}\n\n/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */\nexport function resetDrawings(newLimits: DrawingLimits = {}): void {\n for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;\n created.clear();\n held = new WeakMap();\n releasedAt = new WeakMap();\n heldAt = new WeakMap();\n pending = { line: 0, label: 0, box: 0, polyline: 0 };\n currentBar = null;\n lastBarIndex = null;\n lastBar = null;\n limits = {\n line: newLimits.line ?? DEFAULT_MAX_COUNT,\n label: newLimits.label ?? DEFAULT_MAX_COUNT,\n box: newLimits.box ?? DEFAULT_MAX_COUNT,\n polyline: newLimits.polyline ?? DEFAULT_MAX_COUNT,\n };\n}\n\n/** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */\nexport function setDrawingLimits(newLimits: DrawingLimits): void {\n limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== undefined)) };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmEO,MAAM,oBAAoB;AAEjC,MAAM,QAAQ;AAId,MAAM,OAAuD;AAAA,EAC3D,MAAM,CAAC;AAAA,EACP,OAAO,CAAC;AAAA,EACR,KAAK,CAAC;AAAA,EACN,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,OAAO,CAAC;AACV;AACA,IAAI,SAAkC;AAAA,EACpC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AACZ;AACA,MAAM,UAAU,oBAAI,QAAgB;AAEpC,IAAI,OAAO,oBAAI,QAAwB;AAEvC,IAAI,aAAa,oBAAI,QAAwB;AAE7C,MAAM,wBAAwB;AAE9B,IAAI,SAAS,oBAAI,QAAwB;AAGzC,MAAM,gBAAwC,CAAC,QAAQ,SAAS,OAAO,UAAU;AACjF,MAAM,YAAY,CAAC,SAA4C,cAAyC,SAAS,IAAI;AAErH,IAAI,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AY,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,MAAM,MAAS,CAAC,EAAE;AAC5G;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ import * as callsite from './callsite/index.js';
|
|
|
35
35
|
export { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, table, text, compare, callsite };
|
|
36
36
|
export { drawingOutputs, type DrawingOutputs } from './drawing/output.js';
|
|
37
37
|
export { barInterval, barTime } from './drawing/bar-time.js';
|
|
38
|
-
export { resetDrawings, setDrawingLimits, setDrawingBar, holdDrawing, releaseDrawing, varDrawing, type DrawingLimits, type DrawingVariable, } from './drawing/registry.js';
|
|
38
|
+
export { resetDrawings, setDrawingLimits, setDrawingBar, holdDrawing, releaseDrawing, varDrawing, createdDrawingKinds, type DrawingKind, type DrawingLimits, type DrawingVariable, } from './drawing/registry.js';
|
|
39
39
|
export { chartSessions, sessionPeriods, periodTime, periodClose, tradingDayTime, chartSessionFlags, resampleSession, barTimeAfter, barsUntil, type SessionContext, type ChartSessions, type SessionPeriods, type SessionResample, } from './session/context.js';
|
|
40
40
|
export { TradingCalendar, type SessionSpec } from './session/calendar.js';
|
|
41
41
|
export { SessionBars, sessionFlags, type SessionFlags } from './session/bars.js';
|
|
@@ -50,6 +50,7 @@ export { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr,
|
|
|
50
50
|
export { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';
|
|
51
51
|
export { rgb, from_hex as color_from_hex, new_color } from './color/index.js';
|
|
52
52
|
export { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';
|
|
53
|
+
export { setSourceResolver, externalSource, BUILTIN_SOURCES, type SourceResolver } from './utils/source-resolver.js';
|
|
53
54
|
export * from './lib/index.js';
|
|
54
55
|
export { isNA as na, nz, fixnan } from './utils/index.js';
|
|
55
56
|
export { indicator, type IndicatorMetadataConfig, type InputDefinition, type IndicatorContext, type IndicatorInstance, type IndicatorConstructor, } from './indicator.js';
|
|
@@ -58,13 +59,13 @@ export { plot as plotHelper, createPlot, type Time, type TimeValuePair, type Plo
|
|
|
58
59
|
export { setContext, clearContext, getContext, registerCalculate, recalculate, plot, hline, clearPlots, } from './runtime/runtime.js';
|
|
59
60
|
export { input_int, input_float, input_bool, input_string, input_text_area, input_source, input_timeframe, input_session, input_symbol, input_time, } from './runtime/inputs.js';
|
|
60
61
|
export { isInputActive } from './runtime/input-active.js';
|
|
61
|
-
export type { OakScriptContext, ChartAdapter, InputAdapter, SeriesHandle, SeriesOptions, InputConfig, InputCondition, InputOptions, OhlcvData, PlotConfig, HLineConfig, FillConfig, ArrowConfig, CandleConfig, } from './runtime/types.js';
|
|
62
|
+
export type { OakScriptContext, ChartAdapter, InputAdapter, SeriesHandle, SeriesOptions, InputConfig, InputCondition, InputOptions, OhlcvData, PlotConfig, HLineConfig, FillConfig, ArrowConfig, CandleConfig, ShapeConfig, BarColorConfig, } from './runtime/types.js';
|
|
62
63
|
export { STRATEGY_CONSTANTS, STRATEGY_DEFAULTS, STRATEGY_NUMBER_VARIABLES, STRATEGY_TEXT_VARIABLES, } from './strategy/index.js';
|
|
63
64
|
export type * from './strategy/index.js';
|
|
64
65
|
export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
65
66
|
export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
66
67
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
67
|
-
export declare const VERSION = "0.
|
|
68
|
+
export declare const VERSION = "0.12.0";
|
|
68
69
|
/**
|
|
69
70
|
* Library information
|
|
70
71
|
*/
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","s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Z,eAAe,EACf,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EACZ,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,mBAAmB,qBAAqB,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,YAAY,EAAE,4BAA4B,EAAE,MAAM,gDAAgD,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAG9E,eAAO,MAAM,OAAO,WAAW,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;CAiBhB,CAAC;AAKF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAE5F"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
|
+
BUILTIN_SOURCES: () => import_source_resolver.BUILTIN_SOURCES,
|
|
32
33
|
BarData: () => import_series.BarData,
|
|
33
34
|
LightweightChartsAdapter: () => import_LightweightChartsAdapter.LightweightChartsAdapter,
|
|
34
35
|
STRATEGY_CONSTANTS: () => import_strategy.STRATEGY_CONSTANTS,
|
|
@@ -66,6 +67,7 @@ __export(index_exports, {
|
|
|
66
67
|
compare: () => compare,
|
|
67
68
|
cos: () => import_math.cos,
|
|
68
69
|
createPlot: () => import_plot.createPlot,
|
|
70
|
+
createdDrawingKinds: () => import_registry.createdDrawingKinds,
|
|
69
71
|
crossover: () => import_ta_series.crossover,
|
|
70
72
|
crossunder: () => import_ta_series.crossunder,
|
|
71
73
|
cum: () => import_ta_series.cum,
|
|
@@ -73,6 +75,7 @@ __export(index_exports, {
|
|
|
73
75
|
drawingOutputs: () => import_output.drawingOutputs,
|
|
74
76
|
ema: () => import_ta_series.ema,
|
|
75
77
|
exp: () => import_math.exp,
|
|
78
|
+
externalSource: () => import_source_resolver.externalSource,
|
|
76
79
|
fixnan: () => import_utils2.fixnan,
|
|
77
80
|
floor: () => import_math.floor,
|
|
78
81
|
getClose: () => import_utils.getClose,
|
|
@@ -138,6 +141,7 @@ __export(index_exports, {
|
|
|
138
141
|
setContext: () => import_runtime.setContext,
|
|
139
142
|
setDrawingBar: () => import_registry.setDrawingBar,
|
|
140
143
|
setDrawingLimits: () => import_registry.setDrawingLimits,
|
|
144
|
+
setSourceResolver: () => import_source_resolver.setSourceResolver,
|
|
141
145
|
sin: () => import_math.sin,
|
|
142
146
|
sma: () => import_ta_series.sma,
|
|
143
147
|
sqrt: () => import_math.sqrt,
|
|
@@ -192,6 +196,7 @@ var import_ta_series = require("./ta-series.js");
|
|
|
192
196
|
var import_math = require("./math/index.js");
|
|
193
197
|
var import_color = require("./color/index.js");
|
|
194
198
|
var import_utils = require("./utils/index.js");
|
|
199
|
+
var import_source_resolver = require("./utils/source-resolver.js");
|
|
195
200
|
__reExport(index_exports, require("./lib/index.js"), module.exports);
|
|
196
201
|
var import_utils2 = require("./utils/index.js");
|
|
197
202
|
var import_indicator = require("./indicator.js");
|
|
@@ -203,7 +208,7 @@ var import_input_active = require("./runtime/input-active.js");
|
|
|
203
208
|
var import_strategy = require("./strategy/index.js");
|
|
204
209
|
var import_LightweightChartsAdapter = require("./runtime/adapters/LightweightChartsAdapter.js");
|
|
205
210
|
var import_SimpleInputAdapter = require("./runtime/adapters/SimpleInputAdapter.js");
|
|
206
|
-
const VERSION = "0.
|
|
211
|
+
const VERSION = "0.12.0";
|
|
207
212
|
const info = {
|
|
208
213
|
name: "OakScriptJS",
|
|
209
214
|
version: VERSION,
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * OakScriptJS - Simplified PineScript-like library for JavaScript\n *\n * This library provides Series-based lazy evaluation and technical analysis functions\n * for building trading indicators. The PineScript-style script API is in `oakscriptjs/script`.\n *\n * Key features:\n * - Series class for lazy evaluation and method chaining\n * - Core TA functions (array-based)\n * - TA-Series wrappers (Series-based)\n *\n * @packageDocumentation\n */\n\n// Export all types\nexport * from './types/index.js';\nexport * from './types/metadata.js';\n\n// Export core namespaces (array-based functions)\nimport * as taCore from './ta/index.js';\nimport * as math from './math/index.js';\nimport * as array from './array/index.js';\nimport * as map from './map/index.js';\nimport * as str from './str/index.js';\nimport * as color from './color/index.js';\nimport * as time from './time/index.js';\nimport * as timeframe from './timeframe/index.js';\nimport * as matrix from './matrix/index.js';\nimport * as line from './line/index.js';\nimport * as box from './box/index.js';\nimport * as label from './label/index.js';\nimport * as linefill from './linefill/index.js';\nimport * as chartPoint from './chartpoint/index.js';\nimport * as polyline from './polyline/index.js';\nimport * as table from './table/index.js';\nimport * as text from './text/index.js';\nimport * as compare from './compare/index.js';\nimport * as callsite from './callsite/index.js';\n\nexport { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, table, text, compare, callsite };\n\n// Renderable drawings (IndicatorResult labels, lines, boxes, linefills, polylines, tables) and future bar times\nexport { drawingOutputs, type DrawingOutputs } from './drawing/output.js';\nexport { barInterval, barTime } from './drawing/bar-time.js';\n\n// Drawing registry limits (PineScript indicator(max_lines_count / max_labels_count / max_boxes_count / max_polylines_count))\nexport {\n resetDrawings,\n setDrawingLimits,\n setDrawingBar,\n holdDrawing,\n releaseDrawing,\n varDrawing,\n type DrawingLimits,\n type DrawingVariable,\n} from './drawing/registry.js';\n\n// The session of a chart context without a script run: time(tf, session, timezone), time_close(...), time_tradingday,\n// session.* flags, request.security periods with the session and holidays, and bars after the last bar on the trading\n// calendar\nexport {\n chartSessions,\n sessionPeriods,\n periodTime,\n periodClose,\n tradingDayTime,\n chartSessionFlags,\n resampleSession,\n barTimeAfter,\n barsUntil,\n type SessionContext,\n type ChartSessions,\n type SessionPeriods,\n type SessionResample,\n} from './session/context.js';\nexport { TradingCalendar, type SessionSpec } from './session/calendar.js';\nexport { SessionBars, sessionFlags, type SessionFlags } from './session/bars.js';\n\n// Same-symbol request.security on a higher timeframe (completion and lookahead rules) and ticker.heikinashi\nexport { resample, periodsOf, afterCompletion, mapToChart, heikinAshi, type Resampled } from './security/resample.js';\n// request.security of another symbol: which bar of the other symbol each chart bar shows (#179)\nexport {\n securityOther,\n securityOtherValues,\n securityLowerTf,\n type OtherSymbolChart,\n type OtherSymbolOptions,\n type SymbolCalendar,\n} from './security/other.js';\n\n// Export Series class (self-contained, no context)\nexport { Series, BarData } from './runtime/series.js';\nexport type { SeriesExtractor } from './runtime/series.js';\n\n// Export TA-Series namespace (Series-based wrappers)\nimport * as ta from './ta-series.js';\nexport { ta };\n\n// Export metadata types for indicator return values\nexport type {\n PlotOptions,\n HLineOptions,\n FillOptions,\n InputMetadata,\n PlotMetadata,\n IndicatorMetadata,\n TimeValue,\n PlotData,\n HLineData,\n FillData,\n FillGradient,\n IndicatorResult,\n IndicatorFactory,\n PlotStyle,\n LineStyle,\n PlotDisplay,\n InputType\n} from './types/metadata.js';\n\n// Re-export commonly used functions for convenience\nexport { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series.js';\nexport { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';\nexport { rgb, from_hex as color_from_hex, new_color } from './color/index.js';\n\n// Export chart data utilities\nexport { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';\n\n// Export libraries (ZigZag, etc.)\nexport * from './lib/index.js';\n\n// Export helper functions for generated indicators (PineScript compatibility)\nexport {isNA as na, nz, fixnan} from './utils/index.js';\n\n// Export indicator infrastructure\nexport {\n indicator,\n type IndicatorMetadataConfig,\n type InputDefinition,\n type IndicatorContext,\n type IndicatorInstance,\n type IndicatorConstructor,\n} from './indicator.js';\n\nexport {\n input,\n type InputValue,\n type IntInputOptions,\n type FloatInputOptions,\n type SourceInputOptions,\n type BoolInputOptions,\n type StringInputOptions,\n type TimeInputOptions,\n type SourceType,\n} from './input.js';\n\nexport {\n plot as plotHelper,\n createPlot,\n type Time,\n type TimeValuePair,\n type PlotOptions as PlotHelperOptions,\n type PlotResult,\n} from './plot.js';\n\n// Runtime exports - global context runtime (setContext, plot, hline) drawing through a ChartAdapter\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n} from './runtime/runtime.js';\n\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_text_area,\n input_source,\n input_timeframe,\n input_session,\n input_symbol,\n input_time,\n} from './runtime/inputs.js';\nexport { isInputActive } from './runtime/input-active.js';\n\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputCondition,\n InputOptions,\n OhlcvData,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ArrowConfig,\n CandleConfig,\n} from './runtime/types.js';\n\n// Strategy types and constants (the script API forwards strategy.* calls to a host engine)\nexport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n} from './strategy/index.js';\nexport type * from './strategy/index.js';\n\nexport { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';\n\n// Version\nexport const VERSION = '0.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,0BAAc,6BAfd;AAgBA,0BAAc,gCAhBd;AAmBA,aAAwB;AACxB,WAAsB;AACtB,YAAuB;AACvB,UAAqB;AACrB,UAAqB;AACrB,YAAuB;AACvB,WAAsB;AACtB,gBAA2B;AAC3B,aAAwB;AACxB,WAAsB;AACtB,UAAqB;AACrB,YAAuB;AACvB,eAA0B;AAC1B,iBAA4B;AAC5B,eAA0B;AAC1B,YAAuB;AACvB,WAAsB;AACtB,cAAyB;AACzB,eAA0B;AAK1B,oBAAoD;AACpD,sBAAqC;AAGrC,
|
|
4
|
+
"sourcesContent": ["/**\n * OakScriptJS - Simplified PineScript-like library for JavaScript\n *\n * This library provides Series-based lazy evaluation and technical analysis functions\n * for building trading indicators. The PineScript-style script API is in `oakscriptjs/script`.\n *\n * Key features:\n * - Series class for lazy evaluation and method chaining\n * - Core TA functions (array-based)\n * - TA-Series wrappers (Series-based)\n *\n * @packageDocumentation\n */\n\n// Export all types\nexport * from './types/index.js';\nexport * from './types/metadata.js';\n\n// Export core namespaces (array-based functions)\nimport * as taCore from './ta/index.js';\nimport * as math from './math/index.js';\nimport * as array from './array/index.js';\nimport * as map from './map/index.js';\nimport * as str from './str/index.js';\nimport * as color from './color/index.js';\nimport * as time from './time/index.js';\nimport * as timeframe from './timeframe/index.js';\nimport * as matrix from './matrix/index.js';\nimport * as line from './line/index.js';\nimport * as box from './box/index.js';\nimport * as label from './label/index.js';\nimport * as linefill from './linefill/index.js';\nimport * as chartPoint from './chartpoint/index.js';\nimport * as polyline from './polyline/index.js';\nimport * as table from './table/index.js';\nimport * as text from './text/index.js';\nimport * as compare from './compare/index.js';\nimport * as callsite from './callsite/index.js';\n\nexport { taCore, math, array, map, str, color, time, timeframe, matrix, line, box, label, linefill, chartPoint, polyline, table, text, compare, callsite };\n\n// Renderable drawings (IndicatorResult labels, lines, boxes, linefills, polylines, tables) and future bar times\nexport { drawingOutputs, type DrawingOutputs } from './drawing/output.js';\nexport { barInterval, barTime } from './drawing/bar-time.js';\n\n// Drawing registry limits (PineScript indicator(max_lines_count / max_labels_count / max_boxes_count / max_polylines_count))\nexport {\n resetDrawings,\n setDrawingLimits,\n setDrawingBar,\n holdDrawing,\n releaseDrawing,\n varDrawing,\n createdDrawingKinds,\n type DrawingKind,\n type DrawingLimits,\n type DrawingVariable,\n} from './drawing/registry.js';\n\n// The session of a chart context without a script run: time(tf, session, timezone), time_close(...), time_tradingday,\n// session.* flags, request.security periods with the session and holidays, and bars after the last bar on the trading\n// calendar\nexport {\n chartSessions,\n sessionPeriods,\n periodTime,\n periodClose,\n tradingDayTime,\n chartSessionFlags,\n resampleSession,\n barTimeAfter,\n barsUntil,\n type SessionContext,\n type ChartSessions,\n type SessionPeriods,\n type SessionResample,\n} from './session/context.js';\nexport { TradingCalendar, type SessionSpec } from './session/calendar.js';\nexport { SessionBars, sessionFlags, type SessionFlags } from './session/bars.js';\n\n// Same-symbol request.security on a higher timeframe (completion and lookahead rules) and ticker.heikinashi\nexport { resample, periodsOf, afterCompletion, mapToChart, heikinAshi, type Resampled } from './security/resample.js';\n// request.security of another symbol: which bar of the other symbol each chart bar shows (#179)\nexport {\n securityOther,\n securityOtherValues,\n securityLowerTf,\n type OtherSymbolChart,\n type OtherSymbolOptions,\n type SymbolCalendar,\n} from './security/other.js';\n\n// Export Series class (self-contained, no context)\nexport { Series, BarData } from './runtime/series.js';\nexport type { SeriesExtractor } from './runtime/series.js';\n\n// Export TA-Series namespace (Series-based wrappers)\nimport * as ta from './ta-series.js';\nexport { ta };\n\n// Export metadata types for indicator return values\nexport type {\n PlotOptions,\n HLineOptions,\n FillOptions,\n InputMetadata,\n PlotMetadata,\n IndicatorMetadata,\n TimeValue,\n PlotData,\n HLineData,\n FillData,\n FillGradient,\n IndicatorResult,\n IndicatorFactory,\n PlotStyle,\n LineStyle,\n PlotDisplay,\n InputType\n} from './types/metadata.js';\n\n// Re-export commonly used functions for convenience\nexport { sma, ema, rsi, macd, bb, stdev, crossover, crossunder, change, tr, atr, cum, vwap } from './ta-series.js';\nexport { abs, ceil, floor, round, max, min, avg, sum, sqrt, pow, exp, log, sin, cos, tan } from './math/index.js';\nexport { rgb, from_hex as color_from_hex, new_color } from './color/index.js';\n\n// Export chart data utilities\nexport { ohlcFromBars, getClose, getHigh, getLow, getOpen, getSource, getSourceSeries, at, div } from './utils/index.js';\nexport { setSourceResolver, externalSource, BUILTIN_SOURCES, type SourceResolver } from './utils/source-resolver.js';\n\n// Export libraries (ZigZag, etc.)\nexport * from './lib/index.js';\n\n// Export helper functions for generated indicators (PineScript compatibility)\nexport {isNA as na, nz, fixnan} from './utils/index.js';\n\n// Export indicator infrastructure\nexport {\n indicator,\n type IndicatorMetadataConfig,\n type InputDefinition,\n type IndicatorContext,\n type IndicatorInstance,\n type IndicatorConstructor,\n} from './indicator.js';\n\nexport {\n input,\n type InputValue,\n type IntInputOptions,\n type FloatInputOptions,\n type SourceInputOptions,\n type BoolInputOptions,\n type StringInputOptions,\n type TimeInputOptions,\n type SourceType,\n} from './input.js';\n\nexport {\n plot as plotHelper,\n createPlot,\n type Time,\n type TimeValuePair,\n type PlotOptions as PlotHelperOptions,\n type PlotResult,\n} from './plot.js';\n\n// Runtime exports - global context runtime (setContext, plot, hline) drawing through a ChartAdapter\nexport {\n setContext,\n clearContext,\n getContext,\n registerCalculate,\n recalculate,\n plot,\n hline,\n clearPlots,\n} from './runtime/runtime.js';\n\nexport {\n input_int,\n input_float,\n input_bool,\n input_string,\n input_text_area,\n input_source,\n input_timeframe,\n input_session,\n input_symbol,\n input_time,\n} from './runtime/inputs.js';\nexport { isInputActive } from './runtime/input-active.js';\n\nexport type {\n OakScriptContext,\n ChartAdapter,\n InputAdapter,\n SeriesHandle,\n SeriesOptions,\n InputConfig,\n InputCondition,\n InputOptions,\n OhlcvData,\n PlotConfig,\n HLineConfig,\n FillConfig,\n ArrowConfig,\n CandleConfig,\n ShapeConfig,\n BarColorConfig,\n} from './runtime/types.js';\n\n// Strategy types and constants (the script API forwards strategy.* calls to a host engine)\nexport {\n STRATEGY_CONSTANTS,\n STRATEGY_DEFAULTS,\n STRATEGY_NUMBER_VARIABLES,\n STRATEGY_TEXT_VARIABLES,\n} from './strategy/index.js';\nexport type * from './strategy/index.js';\n\nexport { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';\nexport type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';\nexport { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';\n\n// Version\nexport const VERSION = '0.12.0';\n\n/**\n * Library information\n */\nexport const info = {\n name: 'OakScriptJS',\n version: VERSION,\n description: 'Simplified PineScript-like library - Series + TA functions',\n features: {\n series: 'Lazy evaluation with Series class',\n ta: 'Technical analysis functions (Series and array-based)',\n script: 'PineScript-style script API (oakscriptjs/script): indicator, strategy, inputs, plots, request.security',\n runtime: 'Global context runtime drawing through a ChartAdapter',\n indicator: 'Indicator function with automatic pane management'\n },\n namespaces: {\n core: ['ta', 'math', 'array', 'map', 'str', 'color', 'time', 'timeframe', 'matrix'],\n drawing: ['line', 'box', 'label', 'linefill', 'chartPoint', 'polyline', 'table', 'text'],\n runtime: ['setContext', 'plot', 'hline', 'input_*'],\n indicator: ['indicator', 'input', 'plotHelper', 'createPlot']\n }\n};\n\n// PineScript compatibility stubs - functions that have no runtime effect\n// These are no-ops so that PineScript-style code runs without modification\n\n/**\n * alertcondition() - Stub for PineScript alert configuration\n * In PineScript, this registers an alert condition. In oakscriptjs, it's a no-op\n * since alert configuration is handled by the host application.\n */\nexport function alertcondition(_condition: unknown, _title?: string, _message?: string): void {\n // No-op: Alert conditions are handled by the host application\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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MAAM,OAAO;AAAA,EAClB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,UAAU;AAAA,IACR,QAAQ;AAAA,IACR,IAAI;AAAA,IACJ,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,YAAY;AAAA,IACV,MAAM,CAAC,MAAM,QAAQ,SAAS,OAAO,OAAO,SAAS,QAAQ,aAAa,QAAQ;AAAA,IAClF,SAAS,CAAC,QAAQ,OAAO,SAAS,YAAY,cAAc,YAAY,SAAS,MAAM;AAAA,IACvF,SAAS,CAAC,cAAc,QAAQ,SAAS,SAAS;AAAA,IAClD,WAAW,CAAC,aAAa,SAAS,cAAc,YAAY;AAAA,EAC9D;AACF;AAUO,SAAS,eAAe,YAAqB,QAAiB,UAAyB;AAE9F;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../../src/runtime/inputs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../../src/runtime/inputs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,YAAY,CAAC;AAU5D;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAGlC;AAoBD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAqCxF;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW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s_exports);
|
|
36
36
|
var import_runtime = require("./runtime.js");
|
|
37
|
+
var import_source_resolver = require("../utils/source-resolver.js");
|
|
37
38
|
const registeredInputs = /* @__PURE__ */ new Map();
|
|
38
39
|
let autoRecalculateEnabled = false;
|
|
39
40
|
function enableAutoRecalculate() {
|
|
@@ -271,8 +272,11 @@ function getSourceData(ohlcv, sourceName) {
|
|
|
271
272
|
const c = ohlcv.close[i];
|
|
272
273
|
return h !== void 0 && l !== void 0 && c !== void 0 ? (o + h + l + c) / 4 : NaN;
|
|
273
274
|
});
|
|
274
|
-
default:
|
|
275
|
-
|
|
275
|
+
default: {
|
|
276
|
+
const ext = (0, import_source_resolver.externalSource)(sourceName);
|
|
277
|
+
if (!ext) return ohlcv.close;
|
|
278
|
+
return ohlcv.close.map((_, i) => ext[i] ?? NaN);
|
|
279
|
+
}
|
|
276
280
|
}
|
|
277
281
|
}
|
|
278
282
|
//# sourceMappingURL=inputs.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/runtime/inputs.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview Idempotent input registration functions\n * These functions mirror PineScript's input functions with idempotent semantics:\n * - First call registers the input with default value\n * - Subsequent calls return the current stored value (possibly user-updated)\n * @module runtime/inputs\n */\n\nimport type { InputConfig, InputOptions } from './types.js';\nimport { getContext, recalculate } from './runtime.js';\n\n// Track registered inputs for idempotent registration\nconst registeredInputs = new Map<string, boolean>();\n\n// Track if we should auto-recalculate on input change\nlet autoRecalculateEnabled = false;\n\n/**\n * Enable automatic recalculation when inputs change\n */\nexport function enableAutoRecalculate(): void {\n autoRecalculateEnabled = true;\n}\n\n/**\n * Disable automatic recalculation\n */\nexport function disableAutoRecalculate(): void {\n autoRecalculateEnabled = false;\n}\n\n/**\n * Reset registered inputs (for testing or context changes)\n * @internal\n */\nexport function resetInputs(): void {\n registeredInputs.clear();\n inputCounter = 0;\n}\n\n// Counter for generating unique input IDs when no title is provided\nlet inputCounter = 0;\n\n/**\n * Generate a unique input ID from title or default\n * @param title - Optional title\n * @param defval - Default value for fallback\n * @param type - Input type\n * @returns Unique input ID\n */\nfunction generateInputId(title: string | undefined, defval: unknown, type: string): string {\n if (title) {\n return title.replace(/\\s+/g, '_');\n }\n // Use counter to ensure uniqueness when no title is provided\n return `${type}_${inputCounter++}_${String(defval)}`;\n}\n\n/**\n * Register an integer input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @param options - Additional options: min, max, step (optional)\n * @returns Current integer value\n */\nexport function input_int(defval: number, title?: string, options?: InputOptions): number {\n const context = getContext();\n if (!context) {\n // No context - return default value\n return Math.floor(defval);\n }\n\n const id = generateInputId(title, defval, 'int');\n const config: InputConfig = {\n id,\n type: 'int',\n defval: Math.floor(defval),\n title,\n min: options?.min,\n max: options?.max,\n step: options?.step ?? 1,\n };\n\n // Check if already registered (idempotent)\n if (!registeredInputs.has(id)) {\n // First call - register the input\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n // Set up auto-recalculate on change if not already done\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n // Return current value (may have been updated by user)\n const value = context.inputs.getValue(id);\n return typeof value === 'number' ? Math.floor(value) : Math.floor(defval);\n}\n\n/**\n * Register a float input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @param options - Additional options: min, max, step (optional)\n * @returns Current float value\n */\nexport function input_float(defval: number, title?: string, options?: InputOptions): number {\n const context = getContext();\n if (!context) {\n // No context - return default value\n return defval;\n }\n\n const id = generateInputId(title, defval, 'float');\n const config: InputConfig = {\n id,\n type: 'float',\n defval,\n title,\n min: options?.min,\n max: options?.max,\n step: options?.step ?? 0.1,\n };\n\n // Check if already registered (idempotent)\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const value = context.inputs.getValue(id);\n return typeof value === 'number' ? value : defval;\n}\n\n/**\n * Register a boolean input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @returns Current boolean value\n */\nexport function input_bool(defval: boolean, title?: string): boolean {\n const context = getContext();\n if (!context) {\n return defval;\n }\n\n const id = generateInputId(title, defval, 'bool');\n const config: InputConfig = {\n id,\n type: 'bool',\n defval,\n title,\n };\n\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const value = context.inputs.getValue(id);\n return typeof value === 'boolean' ? value : defval;\n}\n\n/**\n * Register a string input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @param options - Array of string options for dropdown (optional)\n * @returns Current string value\n */\nexport function input_string(defval: string, title?: string, options?: string[]): string {\n const context = getContext();\n if (!context) {\n return defval;\n }\n\n const id = generateInputId(title, defval, 'string');\n const config: InputConfig = {\n id,\n type: 'string',\n defval,\n title,\n options,\n };\n\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const value = context.inputs.getValue(id);\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Registers `config` once (idempotent) and returns the current stored value.\n */\nfunction registerOnce(config: InputConfig): unknown {\n const context = getContext()!;\n if (!registeredInputs.has(config.id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(config.id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === config.id) {\n recalculate();\n }\n });\n }\n }\n return context.inputs.getValue(config.id);\n}\n\n/**\n * Register a multi-line text input (PineScript `input.text_area`, #184)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default text; lines are separated by \"\n\"\n * @param title - Display title (optional)\n * @returns Current text\n */\nexport function input_text_area(defval: string, title?: string): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'text_area'), type: 'text_area', defval, title });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a timeframe input (PineScript `input.timeframe`)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default timeframe string (\"60\", \"1D\", \"W\"); \"\" means the chart timeframe\n * @param title - Display title (optional)\n * @param options - Array of timeframe options for dropdown (optional)\n * @returns Current timeframe string\n */\nexport function input_timeframe(defval: string, title?: string, options?: string[]): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'timeframe'), type: 'timeframe', defval, title, options });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a session input (PineScript `input.session`)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default session string (\"0930-1600\", \"0930-1600:23456\")\n * @param title - Display title (optional)\n * @param options - Array of session options for dropdown (optional)\n * @returns Current session string\n */\nexport function input_session(defval: string, title?: string, options?: string[]): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'session'), type: 'session', defval, title, options });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a symbol input (PineScript `input.symbol`): a ticker id such as \"NASDAQ:MSFT\" (#180)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default ticker id\n * @param title - Display title (optional)\n * @param options - Array of symbols for a dropdown (optional)\n * @returns Current ticker id\n */\nexport function input_symbol(defval: string, title?: string, options?: string[]): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'symbol'), type: 'symbol', defval, title, options });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a date/time input (PineScript `input.time`)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default UNIX time in milliseconds, e.g. `time.timestamp(\"2024-01-01\")`\n * @param title - Display title (optional)\n * @returns Current UNIX time in milliseconds\n */\nexport function input_time(defval: number, title?: string): number {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'time'), type: 'time', defval, title });\n return typeof value === 'number' ? value : defval;\n}\n\n/**\n * Register a source input (returns a data series from OHLCV)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default source name ('close', 'open', 'high', 'low', 'volume', 'hl2', 'hlc3', 'ohlc4')\n * @param title - Display title (optional)\n * @returns Array of values for the selected source\n */\nexport function input_source(defval: string, title?: string): number[] {\n const context = getContext();\n if (!context) {\n return [];\n }\n\n const id = generateInputId(title, defval, 'source');\n const config: InputConfig = {\n id,\n type: 'source',\n defval,\n title,\n options: ['open', 'high', 'low', 'close', 'volume', 'hl2', 'hlc3', 'ohlc4'],\n };\n\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const sourceName = (context.inputs.getValue(id) as string) ?? defval;\n \n return getSourceData(context.ohlcv, sourceName);\n}\n\n/**\n * Get data array for a source name\n * @param ohlcv - OHLCV data\n * @param sourceName - Source name\n * @returns Array of values\n */\nfunction getSourceData(\n ohlcv: { open: number[]; high: number[]; low: number[]; close: number[]; volume: number[] },\n sourceName: string\n): number[] {\n switch (sourceName) {\n case 'open':\n return ohlcv.open;\n case 'high':\n return ohlcv.high;\n case 'low':\n return ohlcv.low;\n case 'close':\n return ohlcv.close;\n case 'volume':\n return ohlcv.volume;\n case 'hl2':\n return ohlcv.high.map((h, i) => {\n const l = ohlcv.low[i];\n return l !== undefined ? (h + l) / 2 : NaN;\n });\n case 'hlc3':\n return ohlcv.high.map((h, i) => {\n const l = ohlcv.low[i];\n const c = ohlcv.close[i];\n return l !== undefined && c !== undefined ? (h + l + c) / 3 : NaN;\n });\n case 'ohlc4':\n return ohlcv.open.map((o, i) => {\n const h = ohlcv.high[i];\n const l = ohlcv.low[i];\n const c = ohlcv.close[i];\n return h !== undefined && l !== undefined && c !== undefined ? (o + h + l + c) / 4 : NaN;\n });\n default:\n return ohlcv.close;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAAwC;
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview Idempotent input registration functions\n * These functions mirror PineScript's input functions with idempotent semantics:\n * - First call registers the input with default value\n * - Subsequent calls return the current stored value (possibly user-updated)\n * @module runtime/inputs\n */\n\nimport type { InputConfig, InputOptions } from './types.js';\nimport { getContext, recalculate } from './runtime.js';\nimport { externalSource } from '../utils/source-resolver.js';\n\n// Track registered inputs for idempotent registration\nconst registeredInputs = new Map<string, boolean>();\n\n// Track if we should auto-recalculate on input change\nlet autoRecalculateEnabled = false;\n\n/**\n * Enable automatic recalculation when inputs change\n */\nexport function enableAutoRecalculate(): void {\n autoRecalculateEnabled = true;\n}\n\n/**\n * Disable automatic recalculation\n */\nexport function disableAutoRecalculate(): void {\n autoRecalculateEnabled = false;\n}\n\n/**\n * Reset registered inputs (for testing or context changes)\n * @internal\n */\nexport function resetInputs(): void {\n registeredInputs.clear();\n inputCounter = 0;\n}\n\n// Counter for generating unique input IDs when no title is provided\nlet inputCounter = 0;\n\n/**\n * Generate a unique input ID from title or default\n * @param title - Optional title\n * @param defval - Default value for fallback\n * @param type - Input type\n * @returns Unique input ID\n */\nfunction generateInputId(title: string | undefined, defval: unknown, type: string): string {\n if (title) {\n return title.replace(/\\s+/g, '_');\n }\n // Use counter to ensure uniqueness when no title is provided\n return `${type}_${inputCounter++}_${String(defval)}`;\n}\n\n/**\n * Register an integer input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @param options - Additional options: min, max, step (optional)\n * @returns Current integer value\n */\nexport function input_int(defval: number, title?: string, options?: InputOptions): number {\n const context = getContext();\n if (!context) {\n // No context - return default value\n return Math.floor(defval);\n }\n\n const id = generateInputId(title, defval, 'int');\n const config: InputConfig = {\n id,\n type: 'int',\n defval: Math.floor(defval),\n title,\n min: options?.min,\n max: options?.max,\n step: options?.step ?? 1,\n };\n\n // Check if already registered (idempotent)\n if (!registeredInputs.has(id)) {\n // First call - register the input\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n // Set up auto-recalculate on change if not already done\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n // Return current value (may have been updated by user)\n const value = context.inputs.getValue(id);\n return typeof value === 'number' ? Math.floor(value) : Math.floor(defval);\n}\n\n/**\n * Register a float input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @param options - Additional options: min, max, step (optional)\n * @returns Current float value\n */\nexport function input_float(defval: number, title?: string, options?: InputOptions): number {\n const context = getContext();\n if (!context) {\n // No context - return default value\n return defval;\n }\n\n const id = generateInputId(title, defval, 'float');\n const config: InputConfig = {\n id,\n type: 'float',\n defval,\n title,\n min: options?.min,\n max: options?.max,\n step: options?.step ?? 0.1,\n };\n\n // Check if already registered (idempotent)\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const value = context.inputs.getValue(id);\n return typeof value === 'number' ? value : defval;\n}\n\n/**\n * Register a boolean input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @returns Current boolean value\n */\nexport function input_bool(defval: boolean, title?: string): boolean {\n const context = getContext();\n if (!context) {\n return defval;\n }\n\n const id = generateInputId(title, defval, 'bool');\n const config: InputConfig = {\n id,\n type: 'bool',\n defval,\n title,\n };\n\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const value = context.inputs.getValue(id);\n return typeof value === 'boolean' ? value : defval;\n}\n\n/**\n * Register a string input\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default value\n * @param title - Display title (optional)\n * @param options - Array of string options for dropdown (optional)\n * @returns Current string value\n */\nexport function input_string(defval: string, title?: string, options?: string[]): string {\n const context = getContext();\n if (!context) {\n return defval;\n }\n\n const id = generateInputId(title, defval, 'string');\n const config: InputConfig = {\n id,\n type: 'string',\n defval,\n title,\n options,\n };\n\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const value = context.inputs.getValue(id);\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Registers `config` once (idempotent) and returns the current stored value.\n */\nfunction registerOnce(config: InputConfig): unknown {\n const context = getContext()!;\n if (!registeredInputs.has(config.id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(config.id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === config.id) {\n recalculate();\n }\n });\n }\n }\n return context.inputs.getValue(config.id);\n}\n\n/**\n * Register a multi-line text input (PineScript `input.text_area`, #184)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default text; lines are separated by \"\n\"\n * @param title - Display title (optional)\n * @returns Current text\n */\nexport function input_text_area(defval: string, title?: string): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'text_area'), type: 'text_area', defval, title });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a timeframe input (PineScript `input.timeframe`)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default timeframe string (\"60\", \"1D\", \"W\"); \"\" means the chart timeframe\n * @param title - Display title (optional)\n * @param options - Array of timeframe options for dropdown (optional)\n * @returns Current timeframe string\n */\nexport function input_timeframe(defval: string, title?: string, options?: string[]): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'timeframe'), type: 'timeframe', defval, title, options });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a session input (PineScript `input.session`)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default session string (\"0930-1600\", \"0930-1600:23456\")\n * @param title - Display title (optional)\n * @param options - Array of session options for dropdown (optional)\n * @returns Current session string\n */\nexport function input_session(defval: string, title?: string, options?: string[]): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'session'), type: 'session', defval, title, options });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a symbol input (PineScript `input.symbol`): a ticker id such as \"NASDAQ:MSFT\" (#180)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default ticker id\n * @param title - Display title (optional)\n * @param options - Array of symbols for a dropdown (optional)\n * @returns Current ticker id\n */\nexport function input_symbol(defval: string, title?: string, options?: string[]): string {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'symbol'), type: 'symbol', defval, title, options });\n return typeof value === 'string' ? value : defval;\n}\n\n/**\n * Register a date/time input (PineScript `input.time`)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default UNIX time in milliseconds, e.g. `time.timestamp(\"2024-01-01\")`\n * @param title - Display title (optional)\n * @returns Current UNIX time in milliseconds\n */\nexport function input_time(defval: number, title?: string): number {\n if (!getContext()) {\n return defval;\n }\n const value = registerOnce({ id: generateInputId(title, defval, 'time'), type: 'time', defval, title });\n return typeof value === 'number' ? value : defval;\n}\n\n/**\n * Register a source input (returns a data series from OHLCV)\n * First call registers with defval, subsequent calls return current value\n * @param defval - Default source name ('close', 'open', 'high', 'low', 'volume', 'hl2', 'hlc3', 'ohlc4')\n * @param title - Display title (optional)\n * @returns Array of values for the selected source\n */\nexport function input_source(defval: string, title?: string): number[] {\n const context = getContext();\n if (!context) {\n return [];\n }\n\n const id = generateInputId(title, defval, 'source');\n const config: InputConfig = {\n id,\n type: 'source',\n defval,\n title,\n options: ['open', 'high', 'low', 'close', 'volume', 'hl2', 'hlc3', 'ohlc4'],\n };\n\n if (!registeredInputs.has(id)) {\n context.inputs.registerInput(config);\n registeredInputs.set(id, true);\n\n if (autoRecalculateEnabled) {\n context.inputs.onInputChange((changedId) => {\n if (changedId === id) {\n recalculate();\n }\n });\n }\n }\n\n const sourceName = (context.inputs.getValue(id) as string) ?? defval;\n \n return getSourceData(context.ohlcv, sourceName);\n}\n\n/**\n * Get data array for a source name\n * @param ohlcv - OHLCV data\n * @param sourceName - Source name\n * @returns Array of values\n */\nfunction getSourceData(\n ohlcv: { open: number[]; high: number[]; low: number[]; close: number[]; volume: number[] },\n sourceName: string\n): number[] {\n switch (sourceName) {\n case 'open':\n return ohlcv.open;\n case 'high':\n return ohlcv.high;\n case 'low':\n return ohlcv.low;\n case 'close':\n return ohlcv.close;\n case 'volume':\n return ohlcv.volume;\n case 'hl2':\n return ohlcv.high.map((h, i) => {\n const l = ohlcv.low[i];\n return l !== undefined ? (h + l) / 2 : NaN;\n });\n case 'hlc3':\n return ohlcv.high.map((h, i) => {\n const l = ohlcv.low[i];\n const c = ohlcv.close[i];\n return l !== undefined && c !== undefined ? (h + l + c) / 3 : NaN;\n });\n case 'ohlc4':\n return ohlcv.open.map((o, i) => {\n const h = ohlcv.high[i];\n const l = ohlcv.low[i];\n const c = ohlcv.close[i];\n return h !== undefined && l !== undefined && c !== undefined ? (o + h + l + c) / 4 : NaN;\n });\n default: {\n // Another source (study on study), else close.\n const ext = externalSource(sourceName);\n if (!ext) return oh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,IAAI,MAAM,KAAK,CAAC;AACtB,cAAM,IAAI,MAAM,IAAI,CAAC;AACrB,cAAM,IAAI,MAAM,MAAM,CAAC;AACvB,eAAO,MAAM,UAAa,MAAM,UAAa,MAAM,UAAa,IAAI,IAAI,IAAI,KAAK,IAAI;AAAA,MACvF,CAAC;AAAA,IACH,SAAS;AAEP,YAAM,UAAM,uCAAe,UAAU;AACrC,UAAI,CAAC,IAAK,QAAO,MAAM;AACvB,aAAO,MAAM,MAAM,IAAI,CAAC,GAAG,MAAO,IAA0B,CAAC,KAAK,GAAG;AAAA,IACvE;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -136,6 +136,11 @@ export interface PlotConfig {
|
|
|
136
136
|
linestyle?: 'solid' | 'dashed' | 'dotted';
|
|
137
137
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
138
138
|
forceOverlay?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
141
|
+
* drawn. Default true
|
|
142
|
+
*/
|
|
143
|
+
editable?: boolean;
|
|
139
144
|
}
|
|
140
145
|
/**
|
|
141
146
|
* Configuration of a PineScript `plotarrow()` declaration: an up arrow (below the bar) for a positive value, a down
|
|
@@ -161,6 +166,11 @@ export interface ArrowConfig {
|
|
|
161
166
|
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
162
167
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
163
168
|
forceOverlay?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
171
|
+
* drawn. Default true
|
|
172
|
+
*/
|
|
173
|
+
editable?: boolean;
|
|
164
174
|
}
|
|
165
175
|
/**
|
|
166
176
|
* Configuration of a PineScript `plotcandle()` (kind 'candle') or `plotbar()` (kind 'bar') declaration. The candles
|
|
@@ -183,6 +193,21 @@ export interface CandleConfig {
|
|
|
183
193
|
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
184
194
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
185
195
|
forceOverlay?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
198
|
+
* drawn. Default true
|
|
199
|
+
*/
|
|
200
|
+
editable?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* The colours the study chooses from per bar (the PineScript palette of the body / wick / border colour), when they
|
|
203
|
+
* are a fixed set: a user can change each of them. Unset: a single colour (`color` / `wickColor` / `borderColor`)
|
|
204
|
+
* or colours computed per bar
|
|
205
|
+
*/
|
|
206
|
+
palettes?: {
|
|
207
|
+
color?: string[];
|
|
208
|
+
wickColor?: string[];
|
|
209
|
+
borderColor?: string[];
|
|
210
|
+
};
|
|
186
211
|
}
|
|
187
212
|
/**
|
|
188
213
|
* Configuration for horizontal line outputs in generated indicators
|
|
@@ -203,6 +228,11 @@ export interface HLineConfig {
|
|
|
203
228
|
linewidth?: number;
|
|
204
229
|
/** Display mode */
|
|
205
230
|
display?: 'all' | 'none' | 'data_window' | 'status_line' | 'pane';
|
|
231
|
+
/**
|
|
232
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
233
|
+
* drawn. Default true
|
|
234
|
+
*/
|
|
235
|
+
editable?: boolean;
|
|
206
236
|
}
|
|
207
237
|
/**
|
|
208
238
|
* Configuration for fill between plots or hlines in generated indicators
|
|
@@ -225,6 +255,20 @@ export interface FillConfig {
|
|
|
225
255
|
title?: string;
|
|
226
256
|
/** Whether the fill is visible (can be boolean or expression string for dynamic visibility) */
|
|
227
257
|
visible?: boolean | string;
|
|
258
|
+
/**
|
|
259
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
260
|
+
* drawn. Default true
|
|
261
|
+
*/
|
|
262
|
+
editable?: boolean;
|
|
263
|
+
/** Gradient fill: its colour at the top value when it is the same on every bar */
|
|
264
|
+
topColor?: string;
|
|
265
|
+
/** Gradient fill: its colour at the bottom value when it is the same on every bar */
|
|
266
|
+
bottomColor?: string;
|
|
267
|
+
/**
|
|
268
|
+
* The colours the fill chooses from per bar when they are a fixed set (PineScript palette): a user can change each
|
|
269
|
+
* of them. Unset: `color` (one colour) or colours computed per bar
|
|
270
|
+
*/
|
|
271
|
+
palette?: string[];
|
|
228
272
|
}
|
|
229
273
|
/**
|
|
230
274
|
* Configuration for plotshape/plotchar outputs in generated indicators
|
|
@@ -255,6 +299,16 @@ export interface ShapeConfig {
|
|
|
255
299
|
offset?: number;
|
|
256
300
|
/** Drawn on the main chart pane even when the script is not an overlay (PineScript `force_overlay`); default false */
|
|
257
301
|
forceOverlay?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
304
|
+
* drawn. Default true
|
|
305
|
+
*/
|
|
306
|
+
editable?: boolean;
|
|
307
|
+
/**
|
|
308
|
+
* The colours the output chooses from per bar when they are a fixed set (PineScript palette): a user can change
|
|
309
|
+
* each of them. Unset: `color` (one colour) or colours computed per bar
|
|
310
|
+
*/
|
|
311
|
+
palette?: string[];
|
|
258
312
|
}
|
|
259
313
|
/**
|
|
260
314
|
* Configuration for bgcolor/barcolor outputs in generated indicators
|
|
@@ -271,6 +325,21 @@ export interface BarColorConfig {
|
|
|
271
325
|
/** bgcolor only: drawn on the main chart pane even when the script is not an overlay (PineScript
|
|
272
326
|
* `force_overlay`); default false */
|
|
273
327
|
forceOverlay?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* False: the output is not listed in the Style settings of the study (PineScript `editable = false`); it is still
|
|
330
|
+
* drawn. Default true
|
|
331
|
+
*/
|
|
332
|
+
editable?: boolean;
|
|
333
|
+
/**
|
|
334
|
+
* The colours the output chooses from per bar (PineScript palette): a user can change each of them. A colour given
|
|
335
|
+
* as a constant is a palette of one colour. Unset: colours computed per bar
|
|
336
|
+
*/
|
|
337
|
+
palette?: string[];
|
|
338
|
+
/**
|
|
339
|
+
* Where the output comes among the plot / shape / character / arrow / candle outputs (`outputs` of the script): it
|
|
340
|
+
* was declared after the first `outputIndex` of them. The Style settings list it there. Unset: after all of them
|
|
341
|
+
*/
|
|
342
|
+
outputIndex?: number;
|
|
274
343
|
}
|
|
275
344
|
/**
|
|
276
345
|
* Options for numeric inputs
|