oakscriptjs 0.15.3 → 0.16.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/check/format.d.ts.map +1 -1
- package/dist/cjs/check/format.js +5 -0
- package/dist/cjs/check/format.js.map +2 -2
- package/dist/cjs/check/harness.d.ts +24 -0
- package/dist/cjs/check/harness.d.ts.map +1 -1
- package/dist/cjs/check/harness.js +33 -0
- package/dist/cjs/check/harness.js.map +2 -2
- package/dist/cjs/check/index.d.ts +9 -0
- package/dist/cjs/check/index.d.ts.map +1 -1
- package/dist/cjs/check/index.js +7 -0
- package/dist/cjs/check/index.js.map +2 -2
- package/dist/cjs/color/index.d.ts.map +1 -1
- package/dist/cjs/color/index.js +19 -2
- package/dist/cjs/color/index.js.map +2 -2
- package/dist/cjs/color/parse.d.ts +8 -6
- package/dist/cjs/color/parse.d.ts.map +1 -1
- package/dist/cjs/color/parse.js +15 -2
- package/dist/cjs/color/parse.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +68 -0
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +99 -9
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +3 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/runtime/series.d.ts +16 -0
- package/dist/cjs/runtime/series.d.ts.map +1 -1
- package/dist/cjs/runtime/series.js +19 -2
- package/dist/cjs/runtime/series.js.map +2 -2
- package/dist/cjs/script/closure-writes.d.ts +16 -0
- package/dist/cjs/script/closure-writes.d.ts.map +1 -0
- package/dist/cjs/script/closure-writes.js +435 -0
- package/dist/cjs/script/closure-writes.js.map +7 -0
- package/dist/cjs/script/globals.d.ts +2 -0
- package/dist/cjs/script/globals.d.ts.map +1 -1
- package/dist/cjs/script/globals.js.map +1 -1
- package/dist/cjs/script/incremental.d.ts +140 -0
- package/dist/cjs/script/incremental.d.ts.map +1 -0
- package/dist/cjs/script/incremental.js +142 -0
- package/dist/cjs/script/incremental.js.map +7 -0
- package/dist/cjs/script/index.d.ts +116 -31
- package/dist/cjs/script/index.d.ts.map +1 -1
- package/dist/cjs/script/index.js +471 -25
- package/dist/cjs/script/index.js.map +3 -3
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +23 -0
- package/dist/cjs/str/numberformat.js.map +2 -2
- package/dist/cjs/strategy/index.d.ts +8 -0
- package/dist/cjs/strategy/index.d.ts.map +1 -1
- package/dist/cjs/strategy/index.js.map +1 -1
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +72 -3
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/ta/step.d.ts +476 -0
- package/dist/cjs/ta/step.d.ts.map +1 -0
- package/dist/cjs/ta/step.js +1000 -0
- package/dist/cjs/ta/step.js.map +7 -0
- package/dist/cjs/ta-series.d.ts +1 -1
- package/dist/cjs/ta-series.js +3 -3
- package/dist/cjs/ta-series.js.map +1 -1
- package/dist/esm/check/format.d.ts.map +1 -1
- package/dist/esm/check/format.js +5 -0
- package/dist/esm/check/format.js.map +1 -1
- package/dist/esm/check/harness.d.ts +24 -0
- package/dist/esm/check/harness.d.ts.map +1 -1
- package/dist/esm/check/harness.js +40 -6
- package/dist/esm/check/harness.js.map +1 -1
- package/dist/esm/check/index.d.ts +9 -0
- package/dist/esm/check/index.d.ts.map +1 -1
- package/dist/esm/check/index.js +11 -1
- package/dist/esm/check/index.js.map +1 -1
- package/dist/esm/color/index.d.ts.map +1 -1
- package/dist/esm/color/index.js +23 -3
- package/dist/esm/color/index.js.map +1 -1
- package/dist/esm/color/parse.d.ts +8 -6
- package/dist/esm/color/parse.d.ts.map +1 -1
- package/dist/esm/color/parse.js +19 -2
- package/dist/esm/color/parse.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +68 -0
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +156 -10
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/runtime/series.d.ts +16 -0
- package/dist/esm/runtime/series.d.ts.map +1 -1
- package/dist/esm/runtime/series.js +21 -1
- package/dist/esm/runtime/series.js.map +1 -1
- package/dist/esm/script/closure-writes.d.ts +16 -0
- package/dist/esm/script/closure-writes.d.ts.map +1 -0
- package/dist/esm/script/closure-writes.js +323 -0
- package/dist/esm/script/closure-writes.js.map +1 -0
- package/dist/esm/script/globals.d.ts +2 -0
- package/dist/esm/script/globals.d.ts.map +1 -1
- package/dist/esm/script/globals.js.map +1 -1
- package/dist/esm/script/incremental.d.ts +140 -0
- package/dist/esm/script/incremental.d.ts.map +1 -0
- package/dist/esm/script/incremental.js +173 -0
- package/dist/esm/script/incremental.js.map +1 -0
- package/dist/esm/script/index.d.ts +116 -31
- package/dist/esm/script/index.d.ts.map +1 -1
- package/dist/esm/script/index.js +561 -24
- package/dist/esm/script/index.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +30 -0
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/strategy/index.d.ts +8 -0
- package/dist/esm/strategy/index.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +79 -4
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/ta/step.d.ts +476 -0
- package/dist/esm/ta/step.d.ts.map +1 -0
- package/dist/esm/ta/step.js +1089 -0
- package/dist/esm/ta/step.js.map +1 -0
- package/dist/esm/ta-series.d.ts +1 -1
- package/dist/esm/ta-series.js +4 -4
- package/package.json +1 -1
- package/skills/oakscript/SKILL.md +2 -2
- package/skills/oakscript/reference/check.md +5 -0
- package/skills/oakscript/reference/errors.md +0 -1
- package/skills/oakscript/reference/pine-differences.md +1 -2
- package/skills/oakscript/reference/plotting.md +5 -7
- package/skills/oakscript/reference/script-structure.md +6 -0
- package/src/check/format.ts +7 -0
- package/src/check/harness.ts +57 -0
- package/src/check/index.ts +16 -0
- package/src/color/index.ts +22 -3
- package/src/color/parse.ts +28 -3
- package/src/drawing/registry.ts +172 -10
- package/src/index.ts +9 -2
- package/src/runtime/series.ts +33 -1
- package/src/script/closure-writes.ts +279 -0
- package/src/script/globals.ts +2 -0
- package/src/script/incremental.ts +246 -0
- package/src/script/index.ts +695 -26
- package/src/str/numberformat.ts +29 -0
- package/src/strategy/index.ts +8 -0
- package/src/ta/running-sum.ts +78 -3
- package/src/ta/step.ts +1145 -0
- package/src/ta-series.ts +4 -4
|
@@ -27,15 +27,19 @@ __export(registry_exports, {
|
|
|
27
27
|
createdDrawingKinds: () => createdDrawingKinds,
|
|
28
28
|
holdDrawing: () => holdDrawing,
|
|
29
29
|
isDeleted: () => isDeleted,
|
|
30
|
+
isDrawingObject: () => isDrawingObject,
|
|
30
31
|
liveFillsOf: () => liveFillsOf,
|
|
31
32
|
register: () => register,
|
|
32
33
|
releaseDrawing: () => releaseDrawing,
|
|
33
34
|
remove: () => remove,
|
|
34
35
|
resetDrawings: () => resetDrawings,
|
|
36
|
+
restoreDrawingCheckpoint: () => restoreDrawingCheckpoint,
|
|
35
37
|
restoreDrawingState: () => restoreDrawingState,
|
|
38
|
+
saveDrawingCheckpoint: () => saveDrawingCheckpoint,
|
|
36
39
|
saveDrawingState: () => saveDrawingState,
|
|
37
40
|
setDrawingBar: () => setDrawingBar,
|
|
38
41
|
setDrawingLimits: () => setDrawingLimits,
|
|
42
|
+
setDrawingRunHooks: () => setDrawingRunHooks,
|
|
39
43
|
varDrawing: () => varDrawing
|
|
40
44
|
});
|
|
41
45
|
module.exports = __toCommonJS(registry_exports);
|
|
@@ -121,13 +125,25 @@ class Stamped {
|
|
|
121
125
|
class Deleted extends Stamped {
|
|
122
126
|
#deleted = true;
|
|
123
127
|
static mark(obj) {
|
|
124
|
-
if (
|
|
128
|
+
if (#deleted in obj) obj.#deleted = true;
|
|
129
|
+
else new Deleted(obj);
|
|
130
|
+
}
|
|
131
|
+
static unmark(obj) {
|
|
132
|
+
if (#deleted in obj) obj.#deleted = false;
|
|
125
133
|
}
|
|
126
134
|
static has(obj) {
|
|
127
|
-
return #deleted in obj;
|
|
135
|
+
return #deleted in obj && obj.#deleted;
|
|
128
136
|
}
|
|
129
137
|
}
|
|
130
|
-
|
|
138
|
+
const registered = /* @__PURE__ */ new WeakSet();
|
|
139
|
+
function isDrawingObject(value) {
|
|
140
|
+
return typeof value === "object" && value !== null && registered.has(value);
|
|
141
|
+
}
|
|
142
|
+
let runHooks = null;
|
|
143
|
+
function setDrawingRunHooks(hooks) {
|
|
144
|
+
runHooks = hooks;
|
|
145
|
+
}
|
|
146
|
+
let holds = { others: /* @__PURE__ */ new WeakMap(), records: 0, variables: [] };
|
|
131
147
|
class Held extends Stamped {
|
|
132
148
|
#record;
|
|
133
149
|
constructor(obj, record) {
|
|
@@ -187,15 +203,16 @@ function fillProtected(obj) {
|
|
|
187
203
|
return bar !== void 0 && currentBar !== null && currentBar - bar < LINEFILL_RELEASE_BARS;
|
|
188
204
|
}
|
|
189
205
|
function varDrawing(initial) {
|
|
190
|
-
|
|
206
|
+
const slot = { current: initial ? holdDrawing(initial) : void 0 };
|
|
207
|
+
holds.variables.push(slot);
|
|
191
208
|
return {
|
|
192
209
|
get value() {
|
|
193
|
-
return current;
|
|
210
|
+
return slot.current;
|
|
194
211
|
},
|
|
195
212
|
set value(next) {
|
|
196
|
-
if (next === current) return;
|
|
197
|
-
releaseDrawing(current);
|
|
198
|
-
current = next ? holdDrawing(next) : void 0;
|
|
213
|
+
if (next === slot.current) return;
|
|
214
|
+
releaseDrawing(slot.current);
|
|
215
|
+
slot.current = next ? holdDrawing(next) : void 0;
|
|
199
216
|
}
|
|
200
217
|
};
|
|
201
218
|
}
|
|
@@ -305,6 +322,17 @@ function createdDrawingKinds() {
|
|
|
305
322
|
return [...created];
|
|
306
323
|
}
|
|
307
324
|
function register(kind, obj) {
|
|
325
|
+
if (runHooks) {
|
|
326
|
+
runHooks.access();
|
|
327
|
+
const old = runHooks.reuse(kind, obj);
|
|
328
|
+
if (old && old !== obj) {
|
|
329
|
+
for (const key of Object.keys(old)) if (!(key in obj)) delete old[key];
|
|
330
|
+
Object.assign(old, obj);
|
|
331
|
+
Deleted.unmark(old);
|
|
332
|
+
obj = old;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
registered.add(obj);
|
|
308
336
|
const list = live[kind];
|
|
309
337
|
created.add(kind);
|
|
310
338
|
if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);
|
|
@@ -349,6 +377,7 @@ function registerLast(bar, kind, obj) {
|
|
|
349
377
|
return obj;
|
|
350
378
|
}
|
|
351
379
|
function remove(kind, obj) {
|
|
380
|
+
runHooks?.access();
|
|
352
381
|
const list = live[kind];
|
|
353
382
|
const index = list.lastIndexOf(obj);
|
|
354
383
|
if (index !== -1) {
|
|
@@ -360,16 +389,18 @@ function remove(kind, obj) {
|
|
|
360
389
|
if (!Deleted.has(obj)) markDeleted(kind, obj, true);
|
|
361
390
|
}
|
|
362
391
|
function isDeleted(obj) {
|
|
392
|
+
runHooks?.access();
|
|
363
393
|
return typeof obj === "object" && obj !== null && Deleted.has(obj);
|
|
364
394
|
}
|
|
365
395
|
function all(kind) {
|
|
396
|
+
runHooks?.access();
|
|
366
397
|
return live[kind].toArray();
|
|
367
398
|
}
|
|
368
399
|
function resetDrawings(newLimits = {}) {
|
|
369
400
|
for (const kind of Object.keys(live)) live[kind].replace([]);
|
|
370
401
|
fillsOfLine = /* @__PURE__ */ new Map();
|
|
371
402
|
created.clear();
|
|
372
|
-
holds = { others: /* @__PURE__ */ new WeakMap(), records: 0 };
|
|
403
|
+
holds = { others: /* @__PURE__ */ new WeakMap(), records: 0, variables: [] };
|
|
373
404
|
pending = { line: 0, label: 0, box: 0, polyline: 0 };
|
|
374
405
|
currentBar = null;
|
|
375
406
|
lastBarIndex = null;
|
|
@@ -403,6 +434,65 @@ function saveDrawingState() {
|
|
|
403
434
|
limits: { ...limits }
|
|
404
435
|
};
|
|
405
436
|
}
|
|
437
|
+
function copyField(v) {
|
|
438
|
+
if (v === null || typeof v !== "object" || registered.has(v)) return v;
|
|
439
|
+
if (Array.isArray(v)) return v.map(copyField);
|
|
440
|
+
if (v instanceof Map) return new Map([...v].map(([k, x]) => [k, copyField(x)]));
|
|
441
|
+
if (v instanceof Set) return new Set([...v].map(copyField));
|
|
442
|
+
const proto = Object.getPrototypeOf(v);
|
|
443
|
+
if (proto !== Object.prototype && proto !== null) return v;
|
|
444
|
+
const out = {};
|
|
445
|
+
for (const [k, x] of Object.entries(v)) out[k] = copyField(x);
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
448
|
+
function copyFields(obj) {
|
|
449
|
+
const out = {};
|
|
450
|
+
for (const [k, v] of Object.entries(obj)) out[k] = copyField(v);
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
function saveDrawingCheckpoint() {
|
|
454
|
+
const state = saveDrawingState();
|
|
455
|
+
if (state.lastBar) state.lastBar = copyLastBar(state.lastBar);
|
|
456
|
+
const fields = /* @__PURE__ */ new Map();
|
|
457
|
+
const records = /* @__PURE__ */ new Map();
|
|
458
|
+
for (const kind of Object.keys(state.live)) {
|
|
459
|
+
for (const obj of state.live[kind]) {
|
|
460
|
+
fields.set(obj, copyFields(obj));
|
|
461
|
+
const r = Held.get(obj);
|
|
462
|
+
records.set(obj, r ? { count: r.count, heldAt: r.heldAt, releasedAt: r.releasedAt } : null);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return { state, fields, records, variables: holds.variables.map((v) => v.current) };
|
|
466
|
+
}
|
|
467
|
+
function copyLastBar(bar) {
|
|
468
|
+
return { ...bar, old: new Set(bar.old), allowance: { ...bar.allowance } };
|
|
469
|
+
}
|
|
470
|
+
function restoreDrawingCheckpoint(cp) {
|
|
471
|
+
restoreDrawingState(cp.state);
|
|
472
|
+
if (cp.state.lastBar) lastBar = copyLastBar(cp.state.lastBar);
|
|
473
|
+
for (const [obj, saved] of cp.fields) {
|
|
474
|
+
for (const key of Object.keys(obj)) if (!(key in saved)) delete obj[key];
|
|
475
|
+
Object.assign(obj, copyFields(saved));
|
|
476
|
+
Deleted.unmark(obj);
|
|
477
|
+
}
|
|
478
|
+
for (const [obj, saved] of cp.records) {
|
|
479
|
+
const r = Held.get(obj);
|
|
480
|
+
if (saved) {
|
|
481
|
+
const record = r ?? Held.create(obj);
|
|
482
|
+
record.count = saved.count;
|
|
483
|
+
record.heldAt = saved.heldAt;
|
|
484
|
+
record.releasedAt = saved.releasedAt;
|
|
485
|
+
} else if (r) {
|
|
486
|
+
r.count = 0;
|
|
487
|
+
r.heldAt = void 0;
|
|
488
|
+
r.releasedAt = void 0;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
holds.variables.length = cp.variables.length;
|
|
492
|
+
cp.variables.forEach((obj, k) => {
|
|
493
|
+
holds.variables[k].current = obj;
|
|
494
|
+
});
|
|
495
|
+
}
|
|
406
496
|
function restoreDrawingState(s) {
|
|
407
497
|
for (const kind of Object.keys(live)) live[kind].replace(s.live[kind]);
|
|
408
498
|
fillsOfLine = /* @__PURE__ */ new Map();
|
|
@@ -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\n/**\n * The live objects of a kind, in creation order. The maximum count deletes the oldest ones: they leave by moving the\n * head, and the array drops its dead front once it is as long as the live part, so a creation at the maximum costs\n * O(1) amortised instead of a move of the whole list on every cut.\n */\nclass LiveList<T> {\n private items: T[] = [];\n private head = 0;\n\n get length(): number {\n return this.items.length - this.head;\n }\n\n /** The `k`-th live object (0: the oldest) */\n at(k: number): T {\n return this.items[this.head + k]!;\n }\n\n push(obj: T): void {\n this.items.push(obj);\n }\n\n /** Position of `obj` among the live objects, -1 when it is not one */\n lastIndexOf(obj: T): number {\n const index = this.items.lastIndexOf(obj);\n return index >= this.head ? index - this.head : -1;\n }\n\n removeAt(k: number): void {\n if (k === 0) this.dropFront(1);\n else this.items.splice(this.head + k, 1);\n }\n\n /** Removes the live objects at positions `gone` (increasing); the others keep their order */\n removeAll(gone: readonly number[]): void {\n if (gone.length === 0) return;\n if (gone[0] === 0 && gone[gone.length - 1] === gone.length - 1) {\n this.dropFront(gone.length);\n return;\n }\n const items = this.items;\n let to = this.head + gone[0]!;\n for (let from = to, g = 0; from < items.length; from++) {\n if (from - this.head === gone[g]) g++;\n else items[to++] = items[from]!;\n }\n items.length = to;\n }\n\n /** Removes the `n` oldest objects and returns them */\n takeFront(n: number): T[] {\n const out = this.items.slice(this.head, this.head + n);\n this.dropFront(n);\n return out;\n }\n\n private dropFront(n: number): void {\n this.head += n;\n if (this.head >= this.length) {\n this.items = this.items.slice(this.head);\n this.head = 0;\n }\n }\n\n toArray(): T[] {\n return this.items.slice(this.head);\n }\n\n replace(objs: readonly T[]): void {\n this.items = [...objs];\n this.head = 0;\n }\n}\n\nconst live: { [K in DrawingKind]: LiveList<DrawingTypes[K]> } = {\n line: new LiveList(),\n label: new LiveList(),\n box: new LiveList(),\n polyline: new LiveList(),\n linefill: new LiveList(),\n table: new LiveList(),\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};\n/**\n * Base of the classes that add a private field to an existing object (their constructor returns the object they are\n * given). Such a field replaces a WeakMap entry: a study that creates hundreds of thousands of objects spends most of\n * its drawing time adding WeakMap keys. The field is invisible (not a key, not copied by a spread) and stays for the\n * life of the object, as the entry did.\n */\nexport class Stamped {\n constructor(obj: object) {\n return obj;\n }\n}\n\n/** The deleted objects. */\nclass Deleted extends Stamped {\n #deleted = true;\n static mark(obj: object): void {\n if (!Deleted.has(obj)) new Deleted(obj);\n }\n static has(obj: object): boolean {\n return #deleted in obj;\n }\n}\n\n/** The `var` records of a run: a reset starts new ones, a nested run saves and puts back those of its run. */\ninterface Holds {\n /** The records of the objects whose private record belongs to another run */\n readonly others: WeakMap<object, HoldRecord>;\n /** Records made in the run. None: no object has one, nothing to look up for each object the maximum count may\n * delete */\n records: number;\n}\n\n/** What the `var` variables of a run did with an object. */\ninterface HoldRecord {\n readonly run: Holds;\n /** Number of `var` variables that hold the object (0: not held) */\n count: number;\n /** Bar on which a `var` variable got the object: on that bar the maximum count deletes it only when no other object\n * can go; from the next bar on, never. Undefined outside a bar loop */\n heldAt: number | undefined;\n /** Bar on which the last `var` variable released the object (linefill rule) */\n releasedAt: number | undefined;\n}\nlet holds: Holds = { others: new WeakMap(), records: 0 };\n\n/**\n * The record of the first run that holds an object, on the object itself (a study holding a new object on every bar\n * would otherwise add a WeakMap key per bar); the records of other runs go to their {@link Holds.others}.\n */\nclass Held extends Stamped {\n #record: HoldRecord;\n private constructor(obj: object, record: HoldRecord) {\n super(obj);\n this.#record = record;\n }\n /** The record of `obj` in the current run, if any. */\n static get(obj: object): HoldRecord | undefined {\n if (holds.records === 0) return undefined;\n const own = #record in obj ? (obj as Held).#record : undefined;\n return own?.run === holds ? own : holds.others.get(obj);\n }\n /** A new record of `obj` in the current run (it has none). */\n static create(obj: object): HoldRecord {\n const record: HoldRecord = { run: holds, count: 0, heldAt: undefined, releasedAt: undefined };\n holds.records++;\n if (#record in obj) holds.others.set(obj, record);\n else new Held(obj, record);\n return record;\n }\n}\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\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 const record = Held.get(obj) ?? Held.create(obj);\n if (record.count === 0) record.heldAt = currentBar ?? undefined;\n record.count++;\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 record = Held.get(obj);\n if (!record || record.count === 0) return;\n record.count--;\n if (record.count === 0 && currentBar !== null) record.releasedAt = 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 const record = Held.get(obj);\n if (!record || record.count === 0) return false;\n const bar = record.heldAt;\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/**\n * Held by a `var` variable since the current bar, or released by its last variable on the current bar: the maximum\n * count deletes such an object only when the objects it may delete are not enough (#193; 12 `var` lines made on the\n * first bar with a maximum of 5 lose the first 6, #158).\n */\nfunction heldOnThisBar(obj: object): boolean {\n if (currentBar === null) return false;\n const record = Held.get(obj);\n if (!record) return false;\n return record.count > 0 ? record.heldAt === currentBar : record.releasedAt === currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n const record = Held.get(obj);\n if (!record) return false;\n if (record.count > 0) return true;\n const bar = record.releasedAt;\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 (on that bar deleted only when no other object can go,\n * never after). `last` says that it is 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.toArray(), ...live.label.toArray(), ...live.box.toArray(), ...live.polyline.toArray()]),\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\n/** The live linefills of each line, in creation order: deleting a line or making a fill does not scan all the fills. */\nlet fillsOfLine = new Map<Line, Linefill[]>();\n\nfunction trackFill(fill: Linefill): void {\n for (const l of fill.line1 === fill.line2 ? [fill.line1] : [fill.line1, fill.line2]) {\n const fills = fillsOfLine.get(l);\n if (fills) fills.push(fill);\n else fillsOfLine.set(l, [fill]);\n }\n}\n\nfunction untrackFill(fill: Linefill): void {\n for (const l of fill.line1 === fill.line2 ? [fill.line1] : [fill.line1, fill.line2]) {\n const fills = fillsOfLine.get(l);\n if (!fills) continue;\n const k = fills.indexOf(fill);\n if (k !== -1) fills.splice(k, 1);\n if (fills.length === 0) fillsOfLine.delete(l);\n }\n}\n\n/** The live linefills that use `line`, in creation order (do not modify). */\nexport function liveFillsOf(line: Line): readonly Linefill[] {\n return fillsOfLine.get(line) ?? [];\n}\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n Deleted.mark(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 const fills = fillsOfLine.get(obj as Line);\n if (fills) for (const fill of [...fills]) 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: LiveList<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 let excess = list.length - max;\n const fill = kind === 'linefill';\n // positions of the objects to delete. The oldest first; the objects a `var` variable got (or released) on this bar\n // only when the others are not enough (the two passes pick different objects)\n const gone: number[] = [];\n for (let pass = 0; pass < (fill ? 1 : 2); pass++) {\n const before = gone.length;\n for (let k = 0; k < list.length && excess > 0; k++) {\n const old = list.at(k);\n if (old === obj || (only && !only(old))) continue;\n if (fill ? fillProtected(old) : heldBefore(old) || heldOnThisBar(old) !== (pass === 1)) continue;\n excess--;\n gone.push(k);\n }\n if (before > 0 && gone.length > before) gone.sort((a, b) => a - b);\n }\n const cut = gone.map((k) => list.at(k));\n // the others keep their order; usually the cut is the oldest run of objects, which leaves by moving the head\n list.removeAll(gone);\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (fill && list.length > max + SLACK) cut.push(...list.takeFront(list.length - max));\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 if (kind === 'linefill') trackFill(obj as Linefill);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) {\n if (kind === 'linefill') untrackFill(old as Linefill);\n markDeleted(kind, old, false);\n }\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 let oldCandidate = false;\n for (let k = 0; k < list.length && !oldCandidate; k++) {\n const old = list.at(k);\n oldCandidate = old !== obj && isOld(old) && !heldBefore(old) && !heldOnThisBar(old);\n }\n if (oldCandidate) {\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 // from the end: an object is in the list once, and scripts mostly delete their newest objects\n const index = list.lastIndexOf(obj);\n if (index !== -1) {\n list.removeAt(index);\n if (kind === 'linefill') untrackFill(obj as Linefill);\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].toArray() 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].replace([]);\n fillsOfLine = new Map();\n created.clear();\n holds = { others: new WeakMap(), records: 0 };\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\n/** The registry state of a run, saved around a nested run (see {@link restoreDrawingState}). */\nexport interface DrawingState {\n live: { [K in DrawingKind]: Array<DrawingTypes[K]> };\n created: DrawingKind[];\n holds: Holds;\n pending: Record<CountedKind, number>;\n currentBar: number | null;\n lastBarIndex: number | null;\n lastBar: LastBar | null;\n limits: Required<DrawingLimits>;\n}\n\n/** Saves the registry of the current run before a nested run (an intrabar run of a strategy). */\nexport function saveDrawingState(): DrawingState {\n return {\n live: {\n line: live.line.toArray(),\n label: live.label.toArray(),\n box: live.box.toArray(),\n polyline: live.polyline.toArray(),\n linefill: live.linefill.toArray(),\n table: live.table.toArray(),\n },\n created: [...created],\n holds,\n pending: { ...pending },\n currentBar,\n lastBarIndex,\n lastBar,\n limits: { ...limits },\n };\n}\n\n/** Puts back the registry saved by {@link saveDrawingState} after the nested run. */\nexport function restoreDrawingState(s: DrawingState): void {\n for (const kind of Object.keys(live) as DrawingKind[]) (live[kind] as LiveList<object>).replace(s.live[kind]);\n fillsOfLine = new Map();\n for (const fill of s.live.linefill) trackFill(fill);\n created.clear();\n for (const kind of s.created) created.add(kind);\n holds = s.holds;\n pending = { ...s.pending };\n currentBar = s.currentBar;\n lastBarIndex = s.lastBarIndex;\n lastBar = s.lastBar;\n limits = { ...s.limits };\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;AAmEO,MAAM,oBAAoB;AAEjC,MAAM,QAAQ;AASd,MAAM,SAAY;AAAA,EACR,QAAa,CAAC;AAAA,EACd,OAAO;AAAA,EAEf,IAAI,SAAiB;AACnB,WAAO,KAAK,MAAM,SAAS,KAAK;AAAA,EAClC;AAAA;AAAA,EAGA,GAAG,GAAc;AACf,WAAO,KAAK,MAAM,KAAK,OAAO,CAAC;AAAA,EACjC;AAAA,EAEA,KAAK,KAAc;AACjB,SAAK,MAAM,KAAK,GAAG;AAAA,EACrB;AAAA;AAAA,EAGA,YAAY,KAAgB;AAC1B,UAAM,QAAQ,KAAK,MAAM,YAAY,GAAG;AACxC,WAAO,SAAS,KAAK,OAAO,QAAQ,KAAK,OAAO;AAAA,EAClD;AAAA,EAEA,SAAS,GAAiB;AACxB,QAAI,MAAM,EAAG,MAAK,UAAU,CAAC;AAAA,QACxB,MAAK,MAAM,OAAO,KAAK,OAAO,GAAG,CAAC;AAAA,EACzC;AAAA;AAAA,EAGA,UAAU,MAA+B;AACvC,QAAI,KAAK,WAAW,EAAG;AACvB,QAAI,KAAK,CAAC,MAAM,KAAK,KAAK,KAAK,SAAS,CAAC,MAAM,KAAK,SAAS,GAAG;AAC9D,WAAK,UAAU,KAAK,MAAM;AAC1B;AAAA,IACF;AACA,UAAM,QAAQ,KAAK;AACnB,QAAI,KAAK,KAAK,OAAO,KAAK,CAAC;AAC3B,aAAS,OAAO,IAAI,IAAI,GAAG,OAAO,MAAM,QAAQ,QAAQ;AACtD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,MACtB,UAAU,KAAK,SAAS,QAAQ;AAAA,MAChC,UAAU,KAAK,SAAS,QAAQ;AAAA,MAChC,OAAO,KAAK,MAAM,QAAQ;AAAA,IAC5B;AAAA,IACA,SAAS,CAAC,GAAG,OAAO;AAAA,IACpB;AAAA,IACA,SAAS,EAAE,GAAG,QAAQ;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,EAAE,GAAG,OAAO;AAAA,EACtB;AACF;AAGO,SAAS,oBAAoB,GAAuB;AACzD,aAAW,QAAQ,OAAO,KAAK,IAAI,EAAoB,CAAC,KAAK,IAAI,EAAuB,QAAQ,EAAE,KAAK,IAAI,CAAC;AAC5G,gBAAc,oBAAI,IAAI;AACtB,aAAW,QAAQ,EAAE,KAAK,SAAU,WAAU,IAAI;AAClD,UAAQ,MAAM;AACd,aAAW,QAAQ,EAAE,QAAS,SAAQ,IAAI,IAAI;AAC9C,UAAQ,EAAE;AACV,YAAU,EAAE,GAAG,EAAE,QAAQ;AACzB,eAAa,EAAE;AACf,iBAAe,EAAE;AACjB,YAAU,EAAE;AACZ,WAAS,EAAE,GAAG,EAAE,OAAO;AACzB;",
|
|
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 * A port with its own bar loop resumes a live update with {@link saveDrawingCheckpoint} (at the end of the last\n * confirmed bar) and {@link restoreDrawingCheckpoint} (before the forming bar is calculated again).\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\n/**\n * The live objects of a kind, in creation order. The maximum count deletes the oldest ones: they leave by moving the\n * head, and the array drops its dead front once it is as long as the live part, so a creation at the maximum costs\n * O(1) amortised instead of a move of the whole list on every cut.\n */\nclass LiveList<T> {\n private items: T[] = [];\n private head = 0;\n\n get length(): number {\n return this.items.length - this.head;\n }\n\n /** The `k`-th live object (0: the oldest) */\n at(k: number): T {\n return this.items[this.head + k]!;\n }\n\n push(obj: T): void {\n this.items.push(obj);\n }\n\n /** Position of `obj` among the live objects, -1 when it is not one */\n lastIndexOf(obj: T): number {\n const index = this.items.lastIndexOf(obj);\n return index >= this.head ? index - this.head : -1;\n }\n\n removeAt(k: number): void {\n if (k === 0) this.dropFront(1);\n else this.items.splice(this.head + k, 1);\n }\n\n /** Removes the live objects at positions `gone` (increasing); the others keep their order */\n removeAll(gone: readonly number[]): void {\n if (gone.length === 0) return;\n if (gone[0] === 0 && gone[gone.length - 1] === gone.length - 1) {\n this.dropFront(gone.length);\n return;\n }\n const items = this.items;\n let to = this.head + gone[0]!;\n for (let from = to, g = 0; from < items.length; from++) {\n if (from - this.head === gone[g]) g++;\n else items[to++] = items[from]!;\n }\n items.length = to;\n }\n\n /** Removes the `n` oldest objects and returns them */\n takeFront(n: number): T[] {\n const out = this.items.slice(this.head, this.head + n);\n this.dropFront(n);\n return out;\n }\n\n private dropFront(n: number): void {\n this.head += n;\n if (this.head >= this.length) {\n this.items = this.items.slice(this.head);\n this.head = 0;\n }\n }\n\n toArray(): T[] {\n return this.items.slice(this.head);\n }\n\n replace(objs: readonly T[]): void {\n this.items = [...objs];\n this.head = 0;\n }\n}\n\nconst live: { [K in DrawingKind]: LiveList<DrawingTypes[K]> } = {\n line: new LiveList(),\n label: new LiveList(),\n box: new LiveList(),\n polyline: new LiveList(),\n linefill: new LiveList(),\n table: new LiveList(),\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};\n/**\n * Base of the classes that add a private field to an existing object (their constructor returns the object they are\n * given). Such a field replaces a WeakMap entry: a study that creates hundreds of thousands of objects spends most of\n * its drawing time adding WeakMap keys. The field is invisible (not a key, not copied by a spread) and stays for the\n * life of the object, as the entry did.\n */\nexport class Stamped {\n constructor(obj: object) {\n return obj;\n }\n}\n\n/** The deleted objects (an incremental run can bring one back when it puts the registry back, #196). */\nclass Deleted extends Stamped {\n #deleted = true;\n static mark(obj: object): void {\n if (#deleted in obj) (obj as Deleted).#deleted = true;\n else new Deleted(obj);\n }\n static unmark(obj: object): void {\n if (#deleted in obj) (obj as Deleted).#deleted = false;\n }\n static has(obj: object): boolean {\n return #deleted in obj && (obj as Deleted).#deleted;\n }\n}\n\n/** The objects the registry recorded (drawing objects, kept as references by the copies of an incremental run). */\nconst registered = new WeakSet<object>();\n\n/** True for a drawing object of the registry (a line, a label, a box, a polyline, a linefill or a table). */\nexport function isDrawingObject(value: unknown): boolean {\n return typeof value === 'object' && value !== null && registered.has(value);\n}\n\n/** Hooks of an incremental script run (#196, set by the script runtime during a run only). @internal */\nexport interface DrawingRunHooks {\n /** A drawing function read or changed the registry or an object */\n access(): void;\n /** A creation: the object of the previous run to use instead of `obj` (its fields are set to those of `obj`) */\n reuse(kind: DrawingKind, obj: object): object | null;\n}\n\nlet runHooks: DrawingRunHooks | null = null;\n\n/** @internal */\nexport function setDrawingRunHooks(hooks: DrawingRunHooks | null): void {\n runHooks = hooks;\n}\n\n/** The `var` records of a run: a reset starts new ones, a nested run saves and puts back those of its run. */\ninterface Holds {\n /** The records of the objects whose private record belongs to another run */\n readonly others: WeakMap<object, HoldRecord>;\n /** Records made in the run. None: no object has one, nothing to look up for each object the maximum count may\n * delete */\n records: number;\n /** The {@link varDrawing} variables made in the run: a checkpoint puts their objects back with the records */\n readonly variables: Array<{ current: object | undefined }>;\n}\n\n/** What the `var` variables of a run did with an object. */\ninterface HoldRecord {\n readonly run: Holds;\n /** Number of `var` variables that hold the object (0: not held) */\n count: number;\n /** Bar on which a `var` variable got the object: on that bar the maximum count deletes it only when no other object\n * can go; from the next bar on, never. Undefined outside a bar loop */\n heldAt: number | undefined;\n /** Bar on which the last `var` variable released the object (linefill rule) */\n releasedAt: number | undefined;\n}\nlet holds: Holds = { others: new WeakMap(), records: 0, variables: [] };\n\n/**\n * The record of the first run that holds an object, on the object itself (a study holding a new object on every bar\n * would otherwise add a WeakMap key per bar); the records of other runs go to their {@link Holds.others}.\n */\nclass Held extends Stamped {\n #record: HoldRecord;\n private constructor(obj: object, record: HoldRecord) {\n super(obj);\n this.#record = record;\n }\n /** The record of `obj` in the current run, if any. */\n static get(obj: object): HoldRecord | undefined {\n if (holds.records === 0) return undefined;\n const own = #record in obj ? (obj as Held).#record : undefined;\n return own?.run === holds ? own : holds.others.get(obj);\n }\n /** A new record of `obj` in the current run (it has none). */\n static create(obj: object): HoldRecord {\n const record: HoldRecord = { run: holds, count: 0, heldAt: undefined, releasedAt: undefined };\n holds.records++;\n if (#record in obj) holds.others.set(obj, record);\n else new Held(obj, record);\n return record;\n }\n}\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\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 const record = Held.get(obj) ?? Held.create(obj);\n if (record.count === 0) record.heldAt = currentBar ?? undefined;\n record.count++;\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 record = Held.get(obj);\n if (!record || record.count === 0) return;\n record.count--;\n if (record.count === 0 && currentBar !== null) record.releasedAt = 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 const record = Held.get(obj);\n if (!record || record.count === 0) return false;\n const bar = record.heldAt;\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/**\n * Held by a `var` variable since the current bar, or released by its last variable on the current bar: the maximum\n * count deletes such an object only when the objects it may delete are not enough (#193; 12 `var` lines made on the\n * first bar with a maximum of 5 lose the first 6, #158).\n */\nfunction heldOnThisBar(obj: object): boolean {\n if (currentBar === null) return false;\n const record = Held.get(obj);\n if (!record) return false;\n return record.count > 0 ? record.heldAt === currentBar : record.releasedAt === currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n const record = Held.get(obj);\n if (!record) return false;\n if (record.count > 0) return true;\n const bar = record.releasedAt;\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 const slot: { current: T | undefined } = { current: initial ? holdDrawing(initial) : undefined };\n // kept by the run: a drawing checkpoint puts the variable back without holding or releasing again\n holds.variables.push(slot);\n return {\n get value() {\n return slot.current;\n },\n set value(next: T | undefined) {\n if (next === slot.current) return;\n releaseDrawing(slot.current);\n slot.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 (on that bar deleted only when no other object can go,\n * never after). `last` says that it is 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.toArray(), ...live.label.toArray(), ...live.box.toArray(), ...live.polyline.toArray()]),\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\n/** The live linefills of each line, in creation order: deleting a line or making a fill does not scan all the fills. */\nlet fillsOfLine = new Map<Line, Linefill[]>();\n\nfunction trackFill(fill: Linefill): void {\n for (const l of fill.line1 === fill.line2 ? [fill.line1] : [fill.line1, fill.line2]) {\n const fills = fillsOfLine.get(l);\n if (fills) fills.push(fill);\n else fillsOfLine.set(l, [fill]);\n }\n}\n\nfunction untrackFill(fill: Linefill): void {\n for (const l of fill.line1 === fill.line2 ? [fill.line1] : [fill.line1, fill.line2]) {\n const fills = fillsOfLine.get(l);\n if (!fills) continue;\n const k = fills.indexOf(fill);\n if (k !== -1) fills.splice(k, 1);\n if (fills.length === 0) fillsOfLine.delete(l);\n }\n}\n\n/** The live linefills that use `line`, in creation order (do not modify). */\nexport function liveFillsOf(line: Line): readonly Linefill[] {\n return fillsOfLine.get(line) ?? [];\n}\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n Deleted.mark(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 const fills = fillsOfLine.get(obj as Line);\n if (fills) for (const fill of [...fills]) 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: LiveList<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 let excess = list.length - max;\n const fill = kind === 'linefill';\n // positions of the objects to delete. The oldest first; the objects a `var` variable got (or released) on this bar\n // only when the others are not enough (the two passes pick different objects)\n const gone: number[] = [];\n for (let pass = 0; pass < (fill ? 1 : 2); pass++) {\n const before = gone.length;\n for (let k = 0; k < list.length && excess > 0; k++) {\n const old = list.at(k);\n if (old === obj || (only && !only(old))) continue;\n if (fill ? fillProtected(old) : heldBefore(old) || heldOnThisBar(old) !== (pass === 1)) continue;\n excess--;\n gone.push(k);\n }\n if (before > 0 && gone.length > before) gone.sort((a, b) => a - b);\n }\n const cut = gone.map((k) => list.at(k));\n // the others keep their order; usually the cut is the oldest run of objects, which leaves by moving the head\n list.removeAll(gone);\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (fill && list.length > max + SLACK) cut.push(...list.takeFront(list.length - max));\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 if (runHooks) {\n runHooks.access();\n const old = runHooks.reuse(kind, obj);\n if (old && old !== obj) {\n // the same object as in the previous run, with the fields of the new one\n for (const key of Object.keys(old)) if (!(key in obj)) delete (old as Record<string, unknown>)[key];\n Object.assign(old, obj);\n Deleted.unmark(old);\n obj = old as DrawingTypes[K];\n }\n }\n registered.add(obj);\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 if (kind === 'linefill') trackFill(obj as Linefill);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) {\n if (kind === 'linefill') untrackFill(old as Linefill);\n markDeleted(kind, old, false);\n }\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 let oldCandidate = false;\n for (let k = 0; k < list.length && !oldCandidate; k++) {\n const old = list.at(k);\n oldCandidate = old !== obj && isOld(old) && !heldBefore(old) && !heldOnThisBar(old);\n }\n if (oldCandidate) {\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 runHooks?.access();\n const list = live[kind];\n // from the end: an object is in the list once, and scripts mostly delete their newest objects\n const index = list.lastIndexOf(obj);\n if (index !== -1) {\n list.removeAt(index);\n if (kind === 'linefill') untrackFill(obj as Linefill);\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 // the setters and getters of the drawing objects start here\n runHooks?.access();\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 runHooks?.access();\n return live[kind].toArray() 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].replace([]);\n fillsOfLine = new Map();\n created.clear();\n holds = { others: new WeakMap(), records: 0, variables: [] };\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\n/** The registry state of a run, saved around a nested run (see {@link restoreDrawingState}). */\nexport interface DrawingState {\n live: { [K in DrawingKind]: Array<DrawingTypes[K]> };\n created: DrawingKind[];\n holds: Holds;\n pending: Record<CountedKind, number>;\n currentBar: number | null;\n lastBarIndex: number | null;\n lastBar: LastBar | null;\n limits: Required<DrawingLimits>;\n}\n\n/** Saves the registry of the current run before a nested run (an intrabar run of a strategy). */\nexport function saveDrawingState(): DrawingState {\n return {\n live: {\n line: live.line.toArray(),\n label: live.label.toArray(),\n box: live.box.toArray(),\n polyline: live.polyline.toArray(),\n linefill: live.linefill.toArray(),\n table: live.table.toArray(),\n },\n created: [...created],\n holds,\n pending: { ...pending },\n currentBar,\n lastBarIndex,\n lastBar,\n limits: { ...limits },\n };\n}\n\n/**\n * The registry and the state of its objects at the end of a bar (see {@link saveDrawingCheckpoint}): the live objects,\n * the fields of each one (arrays, maps and plain objects copied; other drawing objects kept as references), their `var`\n * records, the objects of the {@link varDrawing} variables, and the counters. Its fields are internal.\n */\nexport interface DrawingCheckpoint {\n state: DrawingState;\n fields: Map<object, Record<string, unknown>>;\n records: Map<object, { count: number; heldAt: number | undefined; releasedAt: number | undefined } | null>;\n /** The object of each variable of the run, in the order they were made */\n variables: Array<object | undefined>;\n}\n\n/** A copy of a field value of a drawing object: plain data copied, drawing objects (and other instances) shared. */\nfunction copyField(v: unknown): unknown {\n if (v === null || typeof v !== 'object' || registered.has(v)) return v;\n if (Array.isArray(v)) return v.map(copyField);\n if (v instanceof Map) return new Map([...v].map(([k, x]) => [k, copyField(x)]));\n if (v instanceof Set) return new Set([...v].map(copyField));\n const proto = Object.getPrototypeOf(v);\n if (proto !== Object.prototype && proto !== null) return v;\n const out: Record<string, unknown> = {};\n for (const [k, x] of Object.entries(v)) out[k] = copyField(x);\n return out;\n}\n\nfunction copyFields(obj: object): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) out[k] = copyField(v);\n return out;\n}\n\n/**\n * The drawings at the end of a bar, for a live update of a study with its own bar loop: save it at the end of the last\n * confirmed bar, and put it back with {@link restoreDrawingCheckpoint} before the forming bar is calculated again. The\n * drawings then are those of a full run on the same bars: the objects created, changed or deleted on the forming bar\n * are undone, the objects keep their identity and creation order, and the maximum counts, the `var` holds (also of\n * {@link varDrawing} variables), the linefills and the rules of the last bar ({@link setDrawingBar}) go on as in a full\n * run. The incremental script runs use it too (#196, #203).\n *\n * The checkpoint holds the whole registry of the study: other studies on the same chart may reset and use the registry\n * between two updates, putting it back makes it the study's again (call it where a full run calls\n * {@link resetDrawings}). The study keeps its own variables (the objects it refers to, its arrays of objects) with the\n * checkpoint and puts them back as plain values.\n *\n * @example\n * ```typescript\n * // full run: resetDrawings({ line: 500 }) ... for each bar i: setDrawingBar(i, i === n - 1); draw(i);\n * // and after the bar n - 2: checkpoint = saveDrawingCheckpoint()\n * // live update of the forming bar n - 1 (or new bars after it):\n * restoreDrawingCheckpoint(checkpoint);\n * for (let i = n - 1; i < bars.length; i++) {\n * setDrawingBar(i, i === bars.length - 1);\n * draw(i);\n * if (i === bars.length - 2) checkpoint = saveDrawingCheckpoint();\n * }\n * setDrawingBar(null);\n * ```\n */\nexport function saveDrawingCheckpoint(): DrawingCheckpoint {\n const state = saveDrawingState();\n // the state of the last bar changes during the bar: a checkpoint taken on it keeps a copy\n if (state.lastBar) state.lastBar = copyLastBar(state.lastBar);\n const fields = new Map<object, Record<string, unknown>>();\n const records: DrawingCheckpoint['records'] = new Map();\n for (const kind of Object.keys(state.live) as DrawingKind[]) {\n for (const obj of state.live[kind] as object[]) {\n fields.set(obj, copyFields(obj));\n const r = Held.get(obj);\n records.set(obj, r ? { count: r.count, heldAt: r.heldAt, releasedAt: r.releasedAt } : null);\n }\n }\n return { state, fields, records, variables: holds.variables.map((v) => v.current) };\n}\n\nfunction copyLastBar(bar: LastBar): LastBar {\n return { ...bar, old: new Set(bar.old), allowance: { ...bar.allowance } };\n}\n\n/**\n * Puts back a {@link saveDrawingCheckpoint}: the registry becomes the one of the checkpoint, the objects alive then get\n * their fields and `var` records back, the variables their objects. It can be put back again later (on each update of\n * the forming bar).\n */\nexport function restoreDrawingCheckpoint(cp: DrawingCheckpoint): void {\n restoreDrawingState(cp.state);\n if (cp.state.lastBar) lastBar = copyLastBar(cp.state.lastBar);\n for (const [obj, saved] of cp.fields) {\n for (const key of Object.keys(obj)) if (!(key in saved)) delete (obj as Record<string, unknown>)[key];\n Object.assign(obj, copyFields(saved));\n Deleted.unmark(obj);\n }\n for (const [obj, saved] of cp.records) {\n const r = Held.get(obj);\n if (saved) {\n const record = r ?? Held.create(obj);\n record.count = saved.count;\n record.heldAt = saved.heldAt;\n record.releasedAt = saved.releasedAt;\n } else if (r) {\n r.count = 0;\n r.heldAt = undefined;\n r.releasedAt = undefined;\n }\n }\n // the variables made after the checkpoint belong to the calculation being undone\n holds.variables.length = cp.variables.length;\n cp.variables.forEach((obj, k) => {\n holds.variables[k]!.current = obj;\n });\n}\n\n/** Puts back the registry saved by {@link saveDrawingState} after the nested run. */\nexport function restoreDrawingState(s: DrawingState): void {\n for (const kind of Object.keys(live) as DrawingKind[]) (live[kind] as LiveList<object>).replace(s.live[kind]);\n fillsOfLine = new Map();\n for (const fill of s.live.linefill) trackFill(fill);\n created.clear();\n for (const kind of s.created) created.add(kind);\n holds = s.holds;\n pending = { ...s.pending };\n currentBar = s.currentBar;\n lastBarIndex = s.lastBarIndex;\n lastBar = s.lastBar;\n limits = { ...s.limits };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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KAAK,GAAG,QAAQ;AACpC,eAAW,OAAO,OAAO,KAAK,GAAG,EAAG,KAAI,EAAE,OAAO,OAAQ,QAAQ,IAAgC,GAAG;AACpG,WAAO,OAAO,KAAK,WAAW,KAAK,CAAC;AACpC,YAAQ,OAAO,GAAG;AAAA,EACpB;AACA,aAAW,CAAC,KAAK,KAAK,KAAK,GAAG,SAAS;AACrC,UAAM,IAAI,KAAK,IAAI,GAAG;AACtB,QAAI,OAAO;AACT,YAAM,SAAS,KAAK,KAAK,OAAO,GAAG;AACnC,aAAO,QAAQ,MAAM;AACrB,aAAO,SAAS,MAAM;AACtB,aAAO,aAAa,MAAM;AAAA,IAC5B,WAAW,GAAG;AACZ,QAAE,QAAQ;AACV,QAAE,SAAS;AACX,QAAE,aAAa;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,UAAU,SAAS,GAAG,UAAU;AACtC,KAAG,UAAU,QAAQ,CAAC,KAAK,MAAM;AAC/B,UAAM,UAAU,CAAC,EAAG,UAAU;AAAA,EAChC,CAAC;AACH;AAGO,SAAS,oBAAoB,GAAuB;AACzD,aAAW,QAAQ,OAAO,KAAK,IAAI,EAAoB,CAAC,KAAK,IAAI,EAAuB,QAAQ,EAAE,KAAK,IAAI,CAAC;AAC5G,gBAAc,oBAAI,IAAI;AACtB,aAAW,QAAQ,EAAE,KAAK,SAAU,WAAU,IAAI;AAClD,UAAQ,MAAM;AACd,aAAW,QAAQ,EAAE,QAAS,SAAQ,IAAI,IAAI;AAC9C,UAAQ,EAAE;AACV,YAAU,EAAE,GAAG,EAAE,QAAQ;AACzB,eAAa,EAAE;AACf,iBAAe,EAAE;AACjB,YAAU,EAAE;AACZ,WAAS,EAAE,GAAG,EAAE,OAAO;AACzB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -33,9 +33,10 @@ import * as text from './text/index.js';
|
|
|
33
33
|
import * as compare from './compare/index.js';
|
|
34
34
|
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
|
+
export { taStep, type BarStep } from './ta/step.js';
|
|
36
37
|
export { drawingOutputs, type DrawingOutputs } from './drawing/output.js';
|
|
37
38
|
export { barInterval, barTime } from './drawing/bar-time.js';
|
|
38
|
-
export { resetDrawings, setDrawingLimits, setDrawingBar, holdDrawing, releaseDrawing, varDrawing, createdDrawingKinds, type DrawingKind, type DrawingLimits, type DrawingVariable, } from './drawing/registry.js';
|
|
39
|
+
export { resetDrawings, setDrawingLimits, setDrawingBar, holdDrawing, releaseDrawing, varDrawing, createdDrawingKinds, saveDrawingCheckpoint, restoreDrawingCheckpoint, type DrawingCheckpoint, type DrawingKind, type DrawingLimits, type DrawingVariable, } from './drawing/registry.js';
|
|
39
40
|
export { chartSessions, sessionPeriods, periodTime, periodClose, tradingDayTime, chartSessionFlags, resampleSession, barTimeAfter, barsUntil, type SessionContext, type ChartSessions, type SessionPeriods, type SessionResample, } from './session/context.js';
|
|
40
41
|
export { TradingCalendar, type SessionSpec } from './session/calendar.js';
|
|
41
42
|
export { SessionBars, sessionFlags, type SessionFlags } from './session/bars.js';
|
|
@@ -65,7 +66,7 @@ export type * from './strategy/index.js';
|
|
|
65
66
|
export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
66
67
|
export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
67
68
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
68
|
-
export declare const VERSION = "0.
|
|
69
|
+
export declare const VERSION = "0.16.0";
|
|
69
70
|
/**
|
|
70
71
|
* Library information
|
|
71
72
|
*/
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAY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AC1F,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
|
@@ -131,9 +131,11 @@ __export(index_exports, {
|
|
|
131
131
|
resample: () => import_resample.resample,
|
|
132
132
|
resampleSession: () => import_context.resampleSession,
|
|
133
133
|
resetDrawings: () => import_registry.resetDrawings,
|
|
134
|
+
restoreDrawingCheckpoint: () => import_registry.restoreDrawingCheckpoint,
|
|
134
135
|
rgb: () => import_color.rgb,
|
|
135
136
|
round: () => import_math.round,
|
|
136
137
|
rsi: () => import_ta_series.rsi,
|
|
138
|
+
saveDrawingCheckpoint: () => import_registry.saveDrawingCheckpoint,
|
|
137
139
|
securityLowerTf: () => import_other.securityLowerTf,
|
|
138
140
|
securityOther: () => import_other.securityOther,
|
|
139
141
|
securityOtherValues: () => import_other.securityOtherValues,
|
|
@@ -151,6 +153,7 @@ __export(index_exports, {
|
|
|
151
153
|
sum: () => import_math.sum,
|
|
152
154
|
ta: () => ta,
|
|
153
155
|
taCore: () => taCore,
|
|
156
|
+
taStep: () => import_step.taStep,
|
|
154
157
|
table: () => table,
|
|
155
158
|
tan: () => import_math.tan,
|
|
156
159
|
text: () => text,
|
|
@@ -183,6 +186,7 @@ var table = __toESM(require("./table/index.js"), 1);
|
|
|
183
186
|
var text = __toESM(require("./text/index.js"), 1);
|
|
184
187
|
var compare = __toESM(require("./compare/index.js"), 1);
|
|
185
188
|
var callsite = __toESM(require("./callsite/index.js"), 1);
|
|
189
|
+
var import_step = require("./ta/step.js");
|
|
186
190
|
var import_output = require("./drawing/output.js");
|
|
187
191
|
var import_bar_time = require("./drawing/bar-time.js");
|
|
188
192
|
var import_registry = require("./drawing/registry.js");
|
|
@@ -209,7 +213,7 @@ var import_input_active = require("./runtime/input-active.js");
|
|
|
209
213
|
var import_strategy = require("./strategy/index.js");
|
|
210
214
|
var import_LightweightChartsAdapter = require("./runtime/adapters/LightweightChartsAdapter.js");
|
|
211
215
|
var import_SimpleInputAdapter = require("./runtime/adapters/SimpleInputAdapter.js");
|
|
212
|
-
const VERSION = "0.
|
|
216
|
+
const VERSION = "0.16.0";
|
|
213
217
|
const info = {
|
|
214
218
|
name: "OakScriptJS",
|
|
215
219
|
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 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 MAX_INTRABARS,\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.
|
|
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;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;
|
|
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// ta.* one bar at a time (step / commit), for incremental calculations (#196)\nexport { taStep, type BarStep } from './ta/step.js';\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)),\n// and the drawing checkpoint of a port with its own bar loop (live updates of the forming bar, #203)\nexport {\n resetDrawings,\n setDrawingLimits,\n setDrawingBar,\n holdDrawing,\n releaseDrawing,\n varDrawing,\n createdDrawingKinds,\n saveDrawingCheckpoint,\n restoreDrawingCheckpoint,\n type DrawingCheckpoint,\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 MAX_INTRABARS,\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.16.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;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,kBAAqC;AAGrC,oBAAoD;AACpD,sBAAqC;AAIrC,sBAcO;AAKP,qBAcO;AACP,sBAAkD;AAClD,kBAA6D;AAG7D,sBAA6F;AAE7F,mBAQO;AAGP,oBAAgC;AAIhC,SAAoB;AAyBpB,uBAAkG;AAClG,kBAAgG;AAChG,mBAA2D;AAG3D,mBAAsG;AACtG,6BAAwF;AAGxF,0BAAc,2BA3Id;AA8IA,IAAAA,gBAAqC;AAGrC,uBAOO;AAEP,mBAUO;AAEP,kBAOO;AAGP,qBASO;AAEP,oBAWO;AACP,0BAA8B;AAsB9B,sBAKO;AAGP,sCAAyC;AAEzC,gCAAmC;AAG5B,MAAM,UAAU;AAKhB,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
|
}
|
|
@@ -125,6 +125,22 @@ export declare class BarData {
|
|
|
125
125
|
export declare const MAX_BARS_BACK = 5000;
|
|
126
126
|
/** PineScript's runtime error RE10008 text. */
|
|
127
127
|
export declare function historyError(bar: number, barsBack: number): string;
|
|
128
|
+
/**
|
|
129
|
+
* Hooks of an incremental script run (#196, set by the script runtime during a run only): a Series created by the
|
|
130
|
+
* script gets a slot, and toArray() reuses the values of the previous run up to the first bar that changed.
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
export interface SeriesRunHooks {
|
|
134
|
+
created(series: Series): void;
|
|
135
|
+
/** The values of the previous run (indexes below `from` are kept; the array is reused), or null to compute every bar */
|
|
136
|
+
prefix(series: Series, bars: readonly Bar[]): {
|
|
137
|
+
values: number[];
|
|
138
|
+
from: number;
|
|
139
|
+
} | null;
|
|
140
|
+
computed(series: Series, values: number[]): void;
|
|
141
|
+
}
|
|
142
|
+
/** @internal */
|
|
143
|
+
export declare function setSeriesRunHooks(hooks: SeriesRunHooks | null): void;
|
|
128
144
|
export declare class Series {
|
|
129
145
|
private extractor;
|
|
130
146
|
private dataSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"series.d.ts","sourceRoot":"","sources":["../../../src/runtime/series.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,QAAQ,CAAa;IAE7B;;;OAGG;gBACS,IAAI,GAAE,GAAG,EAAO;IAI5B;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,GAAG,EAAE,CAEhB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI;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