oakscriptjs 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/callsite/index.d.ts.map +1 -1
- package/dist/cjs/callsite/index.js +61 -7
- package/dist/cjs/callsite/index.js.map +2 -2
- package/dist/cjs/drawing/registry.d.ts +28 -3
- package/dist/cjs/drawing/registry.d.ts.map +1 -1
- package/dist/cjs/drawing/registry.js +109 -42
- package/dist/cjs/drawing/registry.js.map +2 -2
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/linefill/index.d.ts.map +1 -1
- package/dist/cjs/linefill/index.js +14 -5
- package/dist/cjs/linefill/index.js.map +2 -2
- package/dist/cjs/str/floatingdecimal.d.ts +3 -0
- package/dist/cjs/str/floatingdecimal.d.ts.map +1 -1
- package/dist/cjs/str/floatingdecimal.js +25 -12
- package/dist/cjs/str/floatingdecimal.js.map +2 -2
- package/dist/cjs/str/messageformat.d.ts.map +1 -1
- package/dist/cjs/str/messageformat.js +27 -8
- package/dist/cjs/str/messageformat.js.map +2 -2
- package/dist/cjs/str/numberformat.d.ts.map +1 -1
- package/dist/cjs/str/numberformat.js +9 -16
- package/dist/cjs/str/numberformat.js.map +3 -3
- package/dist/cjs/ta/index.d.ts.map +1 -1
- package/dist/cjs/ta/index.js +27 -0
- package/dist/cjs/ta/index.js.map +2 -2
- package/dist/cjs/ta/running-sum.d.ts +8 -1
- package/dist/cjs/ta/running-sum.d.ts.map +1 -1
- package/dist/cjs/ta/running-sum.js +13 -1
- package/dist/cjs/ta/running-sum.js.map +2 -2
- package/dist/cjs/time/timezone.d.ts.map +1 -1
- package/dist/cjs/time/timezone.js +14 -1
- package/dist/cjs/time/timezone.js.map +2 -2
- package/dist/esm/callsite/index.d.ts.map +1 -1
- package/dist/esm/callsite/index.js +76 -7
- package/dist/esm/callsite/index.js.map +1 -1
- package/dist/esm/drawing/registry.d.ts +28 -3
- package/dist/esm/drawing/registry.d.ts.map +1 -1
- package/dist/esm/drawing/registry.js +147 -54
- package/dist/esm/drawing/registry.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/linefill/index.d.ts.map +1 -1
- package/dist/esm/linefill/index.js +17 -7
- package/dist/esm/linefill/index.js.map +1 -1
- package/dist/esm/str/floatingdecimal.d.ts +3 -0
- package/dist/esm/str/floatingdecimal.d.ts.map +1 -1
- package/dist/esm/str/floatingdecimal.js +27 -11
- package/dist/esm/str/floatingdecimal.js.map +1 -1
- package/dist/esm/str/messageformat.d.ts.map +1 -1
- package/dist/esm/str/messageformat.js +35 -9
- package/dist/esm/str/messageformat.js.map +1 -1
- package/dist/esm/str/numberformat.d.ts.map +1 -1
- package/dist/esm/str/numberformat.js +12 -18
- package/dist/esm/str/numberformat.js.map +1 -1
- package/dist/esm/ta/index.d.ts.map +1 -1
- package/dist/esm/ta/index.js +35 -0
- package/dist/esm/ta/index.js.map +1 -1
- package/dist/esm/ta/running-sum.d.ts +8 -1
- package/dist/esm/ta/running-sum.d.ts.map +1 -1
- package/dist/esm/ta/running-sum.js +16 -1
- package/dist/esm/ta/running-sum.js.map +1 -1
- package/dist/esm/time/timezone.d.ts.map +1 -1
- package/dist/esm/time/timezone.js +23 -3
- package/dist/esm/time/timezone.js.map +1 -1
- package/package.json +1 -1
- package/src/callsite/index.ts +65 -7
- package/src/drawing/registry.ts +149 -50
- package/src/index.ts +1 -1
- package/src/linefill/index.ts +16 -7
- package/src/str/floatingdecimal.ts +27 -11
- package/src/str/messageformat.ts +40 -9
- package/src/str/numberformat.ts +13 -17
- package/src/ta/index.ts +41 -0
- package/src/ta/running-sum.ts +13 -1
- package/src/time/timezone.ts +26 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/drawing/registry.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Registry of the live drawing objects (lines, labels, boxes, polylines, linefills, tables), as PineScript\n * keeps them. PineScript rules:\n *\n * - `line.all`, `label.all`, ... list the live objects in creation order (a copy of the list)\n * - `delete` removes an object; the object becomes `na`: its getters return NaN and its setters\n * do nothing. Deleting a line with `line.delete` also deletes the linefills that use it\n * - when a creation brings the count above `max_*_count + 5`, the oldest objects are deleted until\n * `max_*_count` remain (default 50). Copies count as creations. Linefills follow the same rule with\n * `max_lines_count`; lines deleted by this rule do not delete their linefills\n * - the object that was just created is never deleted by this rule\n * - an object that a `var` variable of the drawing type refers to is never deleted by this rule, and it still counts\n * (measured for lines, labels and boxes: with 9 held boxes and a maximum of 50, 9 held + 46 others stay; with 8\n * held lines and a maximum of 5, the 8 and the newest line stay). The protection starts on the bar after the\n * assignment: 12 `var` lines created on the first bar with a maximum of 5 lose the first 6. Only\n * the variable itself protects: an object in a `var` array, in a field of a user type or in a variable that got\n * another object or `na` later is deleted like any other. JavaScript has no `var` declaration to observe, so the\n * script says it: {@link varDrawing} (a variable), or {@link holdDrawing} / {@link releaseDrawing}\n * - linefills have the limit of `max_lines_count` with another rule for the held ones (measured on one script, two\n * long runs): a fill is skipped when a `var` variable holds it or released it less than 5,000 bars ago (the bar\n * of {@link setDrawingBar}); when the count is still above the maximum + 5 after that, the oldest fills are\n * deleted until the maximum remain, the held ones too\n * - the script deletes count (`line.delete`, `label.delete`, ...): each kind has a number `P` of deleted objects. A\n * delete adds 1; a creation first sets `P` to 0 when it is 5 or more (3 or more for polylines)\n * - polylines use `P` on every bar: a creation cuts when the count is above `max_polylines_count + 5 + P`, down to\n * the maximum + `P`, and the polylines of the cut are added to `P`. A script that deletes and creates one polyline\n * per bar therefore sees the cut 0, 1 or 2 bars late\n * - lines, labels and boxes use `P` on the last bar only, with its value at the start of that bar: there the cut is\n * above the maximum + 5 + `P`, down to the maximum + `P` (up to 4 more objects)\n * - the last bar has rules of its own (measured from the count after each creation, on a closed and on an open last\n * bar): a cut deletes the objects of the bars before first, at most those (a line takes its linefills with it);\n * once none is left, a cut deletes objects of the last bar as on any bar. With 10 lines and a maximum of 10, 13\n * lines on the last bar leave these 13: the cut at the 16th line deletes the 10 old ones only. Lines, labels and\n * boxes: equal to PineScript, count after every operation and objects alive at the end, on 72 of 72 runs checked\n * after the rule was written (and 218 of 218 end states before)\n * - polylines on the last bar: the `P` carried from the bar before is counted twice (the first creation adds it once\n * more, unless it sets `P` to 0), later creations do not set `P` to 0, and the polylines of the bars before that a\n * cut deletes are added to `P`. Once none is\n * left, `P` is at least the number of polylines of the bars before deleted on the last bar (by the count or by\n * the script) and a cut deletes polylines of the last bar: a script that deletes its 100 polylines and creates 200\n * on the last bar keeps them all (#176). Equal to PineScript for the polylines alive at the end on 271 of\n * 281 probe runs; the count inside the bar can differ when the script deletes polylines of the last bar\n *\n * - a bar index (`xloc.bar_index`) more than 10,000 bars before the current bar stops the script (runtime error\n * RE10026) in `line.new`, `box.new`, `label.new`, `polyline.new` and the setters of x. The current bar is the one\n * of `eachBar` in a script run; a port with its own bar loop gives it with {@link setDrawingBar}\n *\n * The script API (`executeScript`) resets the registry at the start of every run and applies the\n * `max_*_count` values of `indicator()`. Outside a script run the registry is global to the module.\n *\n * @module drawing/registry\n */\n\nimport type { Box, Label, Line, Linefill, Polyline, Table } from '../types/index.js';\n\nexport type DrawingKind = 'line' | 'label' | 'box' | 'polyline' | 'linefill' | 'table';\n\ninterface DrawingTypes {\n line: Line;\n label: Label;\n box: Box;\n polyline: Polyline;\n linefill: Linefill;\n table: Table;\n}\n\n/** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */\nexport const DEFAULT_MAX_COUNT = 50;\n/** Objects above the maximum that PineScript keeps before it deletes the oldest ones. */\nconst SLACK = 5;\n\nexport type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;\n\nconst live: { [K in DrawingKind]: Array<DrawingTypes[K]> } = {\n line: [],\n label: [],\n box: [],\n polyline: [],\n linefill: [],\n table: [],\n};\nlet limits: Required<DrawingLimits> = {\n line: DEFAULT_MAX_COUNT,\n label: DEFAULT_MAX_COUNT,\n box: DEFAULT_MAX_COUNT,\n polyline: DEFAULT_MAX_COUNT,\n};\nconst deleted = new WeakSet<object>();\n/** Objects held by a `var` variable, with the number of variables that hold them. */\nlet held = new WeakMap<object, number>();\n/** Bar on which the last `var` variable released an object (linefill rule). */\nlet releasedAt = new WeakMap<object, number>();\n/** Bars during which a released linefill is still skipped by the maximum count. */\nconst LINEFILL_RELEASE_BARS = 5000;\n/** Bar on which a `var` variable got an object: on that bar the maximum count deletes it only when no other object can\n * go; from the next bar on, never. */\nlet heldAt = new WeakMap<object, number>();\n/** Kinds with a maximum count of their own. */\ntype CountedKind = 'line' | 'label' | 'box' | 'polyline';\nconst COUNTED_KINDS: readonly CountedKind[] = ['line', 'label', 'box', 'polyline'];\nconst isCounted = (kind: DrawingKind): kind is CountedKind => (COUNTED_KINDS as readonly DrawingKind[]).includes(kind);\n/** `P` of the module notes: objects deleted by the script (for polylines also by the maximum count). */\nlet pending: Record<CountedKind, number> = { line: 0, label: 0, box: 0, polyline: 0 };\n/** A creation sets `P` to 0 from this value on. */\nconst PENDING_RESET: Record<CountedKind, number> = { line: 5, label: 5, box: 5, polyline: 3 };\n\n/**\n * Marks an object as held by a `var` variable (PineScript `var line l = ...` or `l := line.new(...)` on a `var`\n * variable): the maximum count never deletes it, and it still counts. Returns the object.\n */\nexport function holdDrawing<T extends object>(obj: T): T {\n if (!held.has(obj)) {\n if (currentBar === null) heldAt.delete(obj);\n else heldAt.set(obj, currentBar);\n }\n held.set(obj, (held.get(obj) ?? 0) + 1);\n return obj;\n}\n\n/** The `var` variable no longer refers to the object (it got another object or `na`). */\nexport function releaseDrawing(obj: object | null | undefined): void {\n if (!obj) return;\n const count = held.get(obj) ?? 0;\n if (count > 1) held.set(obj, count - 1);\n else if (held.delete(obj) && currentBar !== null) releasedAt.set(obj, currentBar);\n}\n\n/** Held by a `var` variable since a bar before the current one (or outside a bar loop). */\nfunction heldBefore(obj: object): boolean {\n if (!held.has(obj)) return false;\n const bar = heldAt.get(obj);\n return bar === undefined || currentBar === null || bar < currentBar;\n}\n\n/**\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 return held.has(obj) ? heldAt.get(obj) === currentBar : releasedAt.get(obj) === currentBar;\n}\n\n/** Linefill rule: held, or released less than 5,000 bars ago. */\nfunction fillProtected(obj: object): boolean {\n if (held.has(obj)) return true;\n const bar = releasedAt.get(obj);\n return bar !== undefined && currentBar !== null && currentBar - bar < LINEFILL_RELEASE_BARS;\n}\n\n/** A `var` variable of a drawing type: see {@link varDrawing}. */\nexport interface DrawingVariable<T extends object> {\n /** The object of the variable; setting it holds the new object and releases the one before */\n value: T | undefined;\n}\n\n/**\n * A PineScript `var` variable of a drawing type (`var line l = na`). The object it refers to is not deleted by the\n * maximum count; assigning another object (or `undefined` for `na`) releases the one before.\n *\n * @example\n * ```typescript\n * // Pine: var line level = na\n * // level := line.new(bar_index, close, bar_index + 1, close)\n * const level = varDrawing<Line>();\n * level.value = line.new(i, close, i + 1, close);\n * ```\n */\nexport function varDrawing<T extends object>(initial?: T): DrawingVariable<T> {\n let current: T | undefined = initial ? holdDrawing(initial) : undefined;\n return {\n get value() {\n return current;\n },\n set value(next: T | undefined) {\n if (next === current) return;\n releaseDrawing(current);\n current = next ? holdDrawing(next) : undefined;\n },\n };\n}\n\n/** Largest distance, in bars, of a bar index before the current bar (PineScript runtime error RE10026 above it). */\nexport const MAX_DRAWING_BARS_BACK = 10000;\n/** Largest distance, in bars, of a bar index after the last bar of the data (PineScript runtime error RE10020 above it). */\nexport const MAX_DRAWING_BARS_FORWARD = 500;\nlet currentBar: number | null = null;\nlet lastBarIndex: number | null = null;\n\n/** Kinds whose allowance on the last bar is the `P` they had when the bar started. */\ntype AllowanceKind = 'line' | 'label' | 'box';\nconst isAllowanceKind = (kind: DrawingKind): kind is AllowanceKind => kind === 'line' || kind === 'label' || kind === 'box';\n\n/** State of the last bar (see the module notes). */\ninterface LastBar {\n bar: number;\n /** The objects alive when the bar started (the objects of the bars before) */\n old: Set<object>;\n /** `P` of lines, labels and boxes when the bar started: their allowance for the whole bar */\n allowance: Record<AllowanceKind, number>;\n /** `P` of polylines when the bar started */\n carried: number;\n /** A polyline was created on this bar */\n polyline: boolean;\n /** Polylines of the bars before deleted on this bar (by the count or by the script) */\n oldPolylinesGone: number;\n}\nlet lastBar: LastBar | null = null;\n\n/**\n * Tells the drawing functions which bar is being calculated (`bar_index`), so that a bar index more than 10,000\n * bars back throws as in PineScript; `null` turns the check off. `eachBar` of the script API calls it.\n *\n * The bar also dates the objects held by a `var` variable (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, ...live.label, ...live.box, ...live.polyline]),\n allowance: { line: start('line'), label: start('label'), box: start('box') },\n carried: pending.polyline,\n polyline: false,\n oldPolylinesGone: 0,\n };\n }\n}\n\n/**\n * Throws the PineScript runtime error RE10026 when `x` is a bar index more than 10,000 bars before the current bar,\n * and RE10020 when it is more than 500 bars after the last bar of the data (when {@link setDrawingBar} knows it).\n * `method` and `variable` are the names of the PineScript message (\"line.new\", \"x1\").\n *\n * Returns `x`, truncated when it is a bar index: PineScript's x is an int (a box from 5537.94 starts on bar 5537,\n * #176).\n */\nexport function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number {\n if ((xloc ?? 'bar_index') !== 'bar_index') return x;\n x = Math.trunc(x);\n if (currentBar === null) return x;\n if (lastBarIndex !== null && x - lastBarIndex > MAX_DRAWING_BARS_FORWARD) {\n throw new Error(\n `Error on bar ${currentBar}: Objects positioned using xloc.bar_index cannot be drawn further than ` +\n `${MAX_DRAWING_BARS_FORWARD} bars into the future.`\n );\n }\n if (currentBar - x > MAX_DRAWING_BARS_BACK) {\n throw new Error(\n `Error on bar ${currentBar}: Bar index value of the \\`${variable}\\` argument (${x}) in \\`${method}()\\` is too far ` +\n 'from the current bar index. Try using `time` instead.'\n );\n }\n return x;\n}\n\n/** Numeric fields that become NaN when an object is deleted, so that its getters return `na`. */\nconst COORDINATES: { [K in DrawingKind]: Array<keyof DrawingTypes[K]> } = {\n line: ['x1', 'y1', 'x2', 'y2'],\n label: ['x', 'y'],\n box: ['left', 'top', 'right', 'bottom'],\n polyline: [],\n linefill: [],\n table: [],\n};\n\nfunction markDeleted<K extends DrawingKind>(kind: K, obj: DrawingTypes[K], explicit: boolean): void {\n deleted.add(obj);\n for (const field of COORDINATES[kind]) (obj as unknown as Record<string, unknown>)[field as string] = NaN;\n if (kind === 'line' && explicit) {\n for (const fill of live.linefill.filter((f) => f.line1 === obj || f.line2 === obj)) remove('linefill', fill);\n }\n}\n\n/** Objects above the maximum that the rule allows for, besides the 5: `P` of the module notes. */\nfunction allowance(kind: DrawingKind): number {\n if (kind === 'polyline') return pending.polyline;\n return lastBar && isAllowanceKind(kind) ? lastBar.allowance[kind] : 0;\n}\n\n/**\n * The maximum count after the creation of `obj`: removes the objects to delete from `list` (the oldest first; the new\n * object and an object held by a `var` variable are skipped and still count) and returns them.\n */\nfunction cutOldest<K extends DrawingKind>(\n kind: K,\n list: Array<DrawingTypes[K]>,\n obj: DrawingTypes[K],\n only?: (old: object) => boolean\n): Array<DrawingTypes[K]> {\n if (kind === 'table') return []; // tables have no maximum count\n const max = limits[kind === 'linefill' ? 'line' : (kind as keyof DrawingLimits)] + allowance(kind);\n if (list.length <= max + SLACK) return [];\n const gone = new Set<object>();\n let excess = list.length - max;\n const candidate = (old: DrawingTypes[K]): boolean =>\n old !== obj && (!only || only(old)) && !(kind === 'linefill' ? fillProtected(old) : heldBefore(old));\n // the oldest first; the objects a `var` variable got (or released) on this bar only when the others are not enough\n for (const weak of kind === 'linefill' ? [false] : [false, true]) {\n for (const old of list) {\n if (excess <= 0) break;\n if (!gone.has(old) && candidate(old) && (kind === 'linefill' || heldOnThisBar(old) === weak)) {\n excess--;\n gone.add(old);\n }\n }\n }\n const kept = list.filter((old) => !gone.has(old));\n const cut = list.filter((old) => gone.has(old));\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (kind === 'linefill' && kept.length > max + SLACK) cut.push(...kept.splice(0, kept.length - max));\n list.length = 0;\n list.push(...kept);\n return cut;\n}\n\n/** Kinds of the objects created since the last reset (a table counts too), in no order. */\nconst created = new Set<DrawingKind>();\n\n/** The kinds of drawing objects created since the last {@link resetDrawings}, even when none is alive any more. */\nexport function createdDrawingKinds(): DrawingKind[] {\n return [...created];\n}\n\n/** Records a new object and deletes the oldest objects of its kind when the count is too high. */\nexport function register<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n const list = live[kind];\n created.add(kind);\n if (lastBar && isCounted(kind)) return registerLast(lastBar, kind, obj);\n if (isCounted(kind) && pending[kind] >= PENDING_RESET[kind]) pending[kind] = 0;\n list.push(obj);\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline') pending.polyline += cut.length;\n for (const old of cut) markDeleted(kind, old, false);\n return obj;\n}\n\n/** An object created on the last bar (see the module notes). */\nfunction registerLast<K extends DrawingKind>(bar: LastBar, kind: K, obj: DrawingTypes[K]): DrawingTypes[K] {\n if (kind === 'polyline' && !bar.polyline) {\n bar.polyline = true;\n if (pending.polyline >= PENDING_RESET.polyline) pending.polyline = 0;\n else pending.polyline += bar.carried; // counted twice\n }\n const list = live[kind];\n list.push(obj);\n const isOld = (old: object): boolean => bar.old.has(old);\n if (list.some((old) => old !== obj && isOld(old) && !heldBefore(old) && !heldOnThisBar(old))) {\n // the objects of the bars before only; a line takes its linefills with it\n const cut = cutOldest(kind, list, obj, isOld);\n if (kind === 'polyline') {\n pending.polyline += cut.length;\n bar.oldPolylinesGone += cut.length;\n }\n for (const old of cut) markDeleted(kind, old, true);\n } else {\n // the polylines of the bars before deleted on this bar count before the cut (#176)\n if (kind === 'polyline' && pending.polyline < bar.oldPolylinesGone) pending.polyline = bar.oldPolylinesGone;\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline' && cut.length > 0) pending.polyline = bar.oldPolylinesGone;\n for (const old of cut) markDeleted(kind, old, false);\n }\n return obj;\n}\n\n/** Deletes an object (no effect when it is already deleted). */\nexport function remove<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): void {\n const list = live[kind];\n const index = list.indexOf(obj);\n if (index !== -1) {\n list.splice(index, 1);\n if (isCounted(kind)) pending[kind]++;\n if (kind === 'polyline' && lastBar?.old.has(obj)) lastBar.oldPolylinesGone++;\n }\n if (!deleted.has(obj)) markDeleted(kind, obj, true);\n}\n\n/** True when the object was deleted (by `delete` or by the maximum count). */\nexport function isDeleted(obj: unknown): boolean {\n return typeof obj === 'object' && obj !== null && deleted.has(obj);\n}\n\n/** The live objects of a kind, in creation order (a new array). */\nexport function all<K extends DrawingKind>(kind: K): Array<DrawingTypes[K]> {\n return [...live[kind]] as Array<DrawingTypes[K]>;\n}\n\n/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */\nexport function resetDrawings(newLimits: DrawingLimits = {}): void {\n for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;\n created.clear();\n held = new WeakMap();\n releasedAt = new WeakMap();\n heldAt = new WeakMap();\n pending = { line: 0, label: 0, box: 0, polyline: 0 };\n currentBar = null;\n lastBarIndex = null;\n lastBar = null;\n limits = {\n line: newLimits.line ?? DEFAULT_MAX_COUNT,\n label: newLimits.label ?? DEFAULT_MAX_COUNT,\n box: newLimits.box ?? DEFAULT_MAX_COUNT,\n polyline: newLimits.polyline ?? DEFAULT_MAX_COUNT,\n };\n}\n\n/** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */\nexport function setDrawingLimits(newLimits: DrawingLimits): void {\n limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== undefined)) };\n}\n\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 held: WeakMap<object, number>;\n releasedAt: WeakMap<object, number>;\n heldAt: WeakMap<object, number>;\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],\n label: [...live.label],\n box: [...live.box],\n polyline: [...live.polyline],\n linefill: [...live.linefill],\n table: [...live.table],\n },\n created: [...created],\n held,\n releasedAt,\n heldAt,\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[]) {\n const list = live[kind] as object[];\n list.length = 0;\n list.push(...(s.live[kind] as object[]));\n }\n created.clear();\n for (const kind of s.created) created.add(kind);\n held = s.held;\n releasedAt = s.releasedAt;\n heldAt = s.heldAt;\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;AAmEO,MAAM,oBAAoB;AAEjC,MAAM,QAAQ;AAId,MAAM,OAAuD;AAAA,EAC3D,MAAM,CAAC;AAAA,EACP,OAAO,CAAC;AAAA,EACR,KAAK,CAAC;AAAA,EACN,UAAU,CAAC;AAAA,EACX,UAAU,CAAC;AAAA,EACX,OAAO,CAAC;AACV;AACA,IAAI,SAAkC;AAAA,EACpC,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,EACL,UAAU;AACZ;
|
|
4
|
+
"sourcesContent": ["/**\n * Registry of the live drawing objects (lines, labels, boxes, polylines, linefills, tables), as PineScript\n * keeps them. PineScript rules:\n *\n * - `line.all`, `label.all`, ... list the live objects in creation order (a copy of the list)\n * - `delete` removes an object; the object becomes `na`: its getters return NaN and its setters\n * do nothing. Deleting a line with `line.delete` also deletes the linefills that use it\n * - when a creation brings the count above `max_*_count + 5`, the oldest objects are deleted until\n * `max_*_count` remain (default 50). Copies count as creations. Linefills follow the same rule with\n * `max_lines_count`; lines deleted by this rule do not delete their linefills\n * - the object that was just created is never deleted by this rule\n * - an object that a `var` variable of the drawing type refers to is never deleted by this rule, and it still counts\n * (measured for lines, labels and boxes: with 9 held boxes and a maximum of 50, 9 held + 46 others stay; with 8\n * held lines and a maximum of 5, the 8 and the newest line stay). The protection starts on the bar after the\n * assignment: 12 `var` lines created on the first bar with a maximum of 5 lose the first 6. Only\n * the variable itself protects: an object in a `var` array, in a field of a user type or in a variable that got\n * another object or `na` later is deleted like any other. JavaScript has no `var` declaration to observe, so the\n * script says it: {@link varDrawing} (a variable), or {@link holdDrawing} / {@link releaseDrawing}\n * - linefills have the limit of `max_lines_count` with another rule for the held ones (measured on one script, two\n * long runs): a fill is skipped when a `var` variable holds it or released it less than 5,000 bars ago (the bar\n * of {@link setDrawingBar}); when the count is still above the maximum + 5 after that, the oldest fills are\n * deleted until the maximum remain, the held ones too\n * - the script deletes count (`line.delete`, `label.delete`, ...): each kind has a number `P` of deleted objects. A\n * delete adds 1; a creation first sets `P` to 0 when it is 5 or more (3 or more for polylines)\n * - polylines use `P` on every bar: a creation cuts when the count is above `max_polylines_count + 5 + P`, down to\n * the maximum + `P`, and the polylines of the cut are added to `P`. A script that deletes and creates one polyline\n * per bar therefore sees the cut 0, 1 or 2 bars late\n * - lines, labels and boxes use `P` on the last bar only, with its value at the start of that bar: there the cut is\n * above the maximum + 5 + `P`, down to the maximum + `P` (up to 4 more objects)\n * - the last bar has rules of its own (measured from the count after each creation, on a closed and on an open last\n * bar): a cut deletes the objects of the bars before first, at most those (a line takes its linefills with it);\n * once none is left, a cut deletes objects of the last bar as on any bar. With 10 lines and a maximum of 10, 13\n * lines on the last bar leave these 13: the cut at the 16th line deletes the 10 old ones only. Lines, labels and\n * boxes: equal to PineScript, count after every operation and objects alive at the end, on 72 of 72 runs checked\n * after the rule was written (and 218 of 218 end states before)\n * - polylines on the last bar: the `P` carried from the bar before is counted twice (the first creation adds it once\n * more, unless it sets `P` to 0), later creations do not set `P` to 0, and the polylines of the bars before that a\n * cut deletes are added to `P`. Once none is\n * left, `P` is at least the number of polylines of the bars before deleted on the last bar (by the count or by\n * the script) and a cut deletes polylines of the last bar: a script that deletes its 100 polylines and creates 200\n * on the last bar keeps them all (#176). Equal to PineScript for the polylines alive at the end on 271 of\n * 281 probe runs; the count inside the bar can differ when the script deletes polylines of the last bar\n *\n * - a bar index (`xloc.bar_index`) more than 10,000 bars before the current bar stops the script (runtime error\n * RE10026) in `line.new`, `box.new`, `label.new`, `polyline.new` and the setters of x. The current bar is the one\n * of `eachBar` in a script run; a port with its own bar loop gives it with {@link setDrawingBar}\n *\n * The script API (`executeScript`) resets the registry at the start of every run and applies the\n * `max_*_count` values of `indicator()`. Outside a script run the registry is global to the module.\n *\n * @module drawing/registry\n */\n\nimport type { Box, Label, Line, Linefill, Polyline, Table } from '../types/index.js';\n\nexport type DrawingKind = 'line' | 'label' | 'box' | 'polyline' | 'linefill' | 'table';\n\ninterface DrawingTypes {\n line: Line;\n label: Label;\n box: Box;\n polyline: Polyline;\n linefill: Linefill;\n table: Table;\n}\n\n/** Default `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count`. */\nexport const DEFAULT_MAX_COUNT = 50;\n/** Objects above the maximum that PineScript keeps before it deletes the oldest ones. */\nconst SLACK = 5;\n\nexport type DrawingLimits = Partial<Record<Exclude<DrawingKind, 'linefill' | 'table'>, number>>;\n\nconst live: { [K in DrawingKind]: Array<DrawingTypes[K]> } = {\n line: [],\n label: [],\n box: [],\n polyline: [],\n linefill: [],\n table: [],\n};\nlet limits: Required<DrawingLimits> = {\n line: DEFAULT_MAX_COUNT,\n label: DEFAULT_MAX_COUNT,\n box: DEFAULT_MAX_COUNT,\n polyline: DEFAULT_MAX_COUNT,\n};\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}\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() };\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 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 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, ...live.label, ...live.box, ...live.polyline]),\n allowance: { line: start('line'), label: start('label'), box: start('box') },\n carried: pending.polyline,\n polyline: false,\n oldPolylinesGone: 0,\n };\n }\n}\n\n/**\n * Throws the PineScript runtime error RE10026 when `x` is a bar index more than 10,000 bars before the current bar,\n * and RE10020 when it is more than 500 bars after the last bar of the data (when {@link setDrawingBar} knows it).\n * `method` and `variable` are the names of the PineScript message (\"line.new\", \"x1\").\n *\n * Returns `x`, truncated when it is a bar index: PineScript's x is an int (a box from 5537.94 starts on bar 5537,\n * #176).\n */\nexport function checkBarIndex(method: string, variable: string, x: number, xloc: string | undefined): number {\n if ((xloc ?? 'bar_index') !== 'bar_index') return x;\n x = Math.trunc(x);\n if (currentBar === null) return x;\n if (lastBarIndex !== null && x - lastBarIndex > MAX_DRAWING_BARS_FORWARD) {\n throw new Error(\n `Error on bar ${currentBar}: Objects positioned using xloc.bar_index cannot be drawn further than ` +\n `${MAX_DRAWING_BARS_FORWARD} bars into the future.`\n );\n }\n if (currentBar - x > MAX_DRAWING_BARS_BACK) {\n throw new Error(\n `Error on bar ${currentBar}: Bar index value of the \\`${variable}\\` argument (${x}) in \\`${method}()\\` is too far ` +\n 'from the current bar index. Try using `time` instead.'\n );\n }\n return x;\n}\n\n/** Numeric fields that become NaN when an object is deleted, so that its getters return `na`. */\nconst COORDINATES: { [K in DrawingKind]: Array<keyof DrawingTypes[K]> } = {\n line: ['x1', 'y1', 'x2', 'y2'],\n label: ['x', 'y'],\n box: ['left', 'top', 'right', 'bottom'],\n polyline: [],\n linefill: [],\n table: [],\n};\n\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: Array<DrawingTypes[K]>,\n obj: DrawingTypes[K],\n only?: (old: object) => boolean\n): Array<DrawingTypes[K]> {\n if (kind === 'table') return []; // tables have no maximum count\n const max = limits[kind === 'linefill' ? 'line' : (kind as keyof DrawingLimits)] + allowance(kind);\n if (list.length <= max + SLACK) return [];\n let excess = list.length - max;\n const candidate = (old: DrawingTypes[K]): boolean =>\n old !== obj && (!only || only(old)) && !(kind === 'linefill' ? fillProtected(old) : heldBefore(old));\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 (const weak of kind === 'linefill' ? [false] : [false, true]) {\n const before = gone.length;\n for (let k = 0; k < list.length && excess > 0; k++) {\n const old = list[k]!;\n if (candidate(old) && (kind === 'linefill' || heldOnThisBar(old) === weak)) {\n excess--;\n gone.push(k);\n }\n }\n if (before > 0 && gone.length > before) gone.sort((a, b) => a - b);\n }\n const cut = gone.map((k) => list[k]!);\n // the others keep their order; usually the cut is the oldest run of objects, removed at once\n if (gone.length > 0 && gone[gone.length - 1]! - gone[0]! === gone.length - 1) list.splice(gone[0]!, gone.length);\n else if (gone.length > 0) {\n let to = gone[0]!;\n for (let from = to, g = 0; from < list.length; from++) {\n if (from === gone[g]) g++;\n else list[to++] = list[from]!;\n }\n list.length = to;\n }\n // linefills: still above the maximum + 5, the oldest go, the held ones too\n if (kind === 'linefill' && list.length > max + SLACK) cut.push(...list.splice(0, 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 if (list.some((old) => old !== obj && isOld(old) && !heldBefore(old) && !heldOnThisBar(old))) {\n // the objects of the bars before only; a line takes its linefills with it\n const cut = cutOldest(kind, list, obj, isOld);\n if (kind === 'polyline') {\n pending.polyline += cut.length;\n bar.oldPolylinesGone += cut.length;\n }\n for (const old of cut) markDeleted(kind, old, true);\n } else {\n // the polylines of the bars before deleted on this bar count before the cut (#176)\n if (kind === 'polyline' && pending.polyline < bar.oldPolylinesGone) pending.polyline = bar.oldPolylinesGone;\n const cut = cutOldest(kind, list, obj);\n if (kind === 'polyline' && cut.length > 0) pending.polyline = bar.oldPolylinesGone;\n for (const old of cut) markDeleted(kind, old, false);\n }\n return obj;\n}\n\n/** Deletes an object (no effect when it is already deleted). */\nexport function remove<K extends DrawingKind>(kind: K, obj: DrawingTypes[K]): void {\n const list = live[kind];\n // 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.splice(index, 1);\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]] as Array<DrawingTypes[K]>;\n}\n\n/** Forgets all objects (without deleting them) and sets the maximum counts (default 50). */\nexport function resetDrawings(newLimits: DrawingLimits = {}): void {\n for (const kind of Object.keys(live) as DrawingKind[]) live[kind].length = 0;\n fillsOfLine = new Map();\n created.clear();\n holds = { others: new WeakMap() };\n pending = { line: 0, label: 0, box: 0, polyline: 0 };\n currentBar = null;\n lastBarIndex = null;\n lastBar = null;\n limits = {\n line: newLimits.line ?? DEFAULT_MAX_COUNT,\n label: newLimits.label ?? DEFAULT_MAX_COUNT,\n box: newLimits.box ?? DEFAULT_MAX_COUNT,\n polyline: newLimits.polyline ?? DEFAULT_MAX_COUNT,\n };\n}\n\n/** Changes the maximum counts without forgetting the objects (PineScript `indicator(max_*_count)`). */\nexport function setDrawingLimits(newLimits: DrawingLimits): void {\n limits = { ...limits, ...Object.fromEntries(Object.entries(newLimits).filter(([, v]) => v !== undefined)) };\n}\n\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],\n label: [...live.label],\n box: [...live.box],\n polyline: [...live.polyline],\n linefill: [...live.linefill],\n table: [...live.table],\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[]) {\n const list = live[kind] as object[];\n list.length = 0;\n list.push(...(s.live[kind] as object[]));\n }\n fillsOfLine = new Map();\n for (const fill of 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;AAA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AAS;AACd,SAAK,KAAK,GAAI,EAAE,KAAK,IAAI,CAAc;AAAA,EACzC;AACA,gBAAc,oBAAI,IAAI;AACtB,aAAW,QAAQ,KAAK,SAAU,WAAU,IAAI;AAChD,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
|
@@ -65,7 +65,7 @@ export type * from './strategy/index.js';
|
|
|
65
65
|
export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
66
66
|
export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
|
|
67
67
|
export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
|
|
68
|
-
export declare const VERSION = "0.15.
|
|
68
|
+
export declare const VERSION = "0.15.2";
|
|
69
69
|
/**
|
|
70
70
|
* Library information
|
|
71
71
|
*/
|
package/dist/cjs/index.js
CHANGED
|
@@ -209,7 +209,7 @@ var import_input_active = require("./runtime/input-active.js");
|
|
|
209
209
|
var import_strategy = require("./strategy/index.js");
|
|
210
210
|
var import_LightweightChartsAdapter = require("./runtime/adapters/LightweightChartsAdapter.js");
|
|
211
211
|
var import_SimpleInputAdapter = require("./runtime/adapters/SimpleInputAdapter.js");
|
|
212
|
-
const VERSION = "0.15.
|
|
212
|
+
const VERSION = "0.15.2";
|
|
213
213
|
const info = {
|
|
214
214
|
name: "OakScriptJS",
|
|
215
215
|
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.15.
|
|
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.15.2';\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
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;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QAAQ,SAAS,OAAO,OAAO,SAAS,QAAQ,aAAa,QAAQ;AAAA,IAClF,SAAS,CAAC,QAAQ,OAAO,SAAS,YAAY,cAAc,YAAY,SAAS,MAAM;AAAA,IACvF,SAAS,CAAC,cAAc,QAAQ,SAAS,SAAS;AAAA,IAClD,WAAW,CAAC,aAAa,SAAS,cAAc,YAAY;AAAA,EAC9D;AACF;AAUO,SAAS,eAAe,YAAqB,QAAiB,UAAyB;AAE9F;",
|
|
6
6
|
"names": ["import_utils"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAoBlF;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/linefill/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAoBlF;AAeD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,GAAG,QAAQ,CAIlE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAElD;AAGD;;GAEG;AACH,wBAAgB,GAAG,IAAI,QAAQ,EAAE,CAEhC;AAGD,OAAO,EAAE,YAAY,IAAI,GAAG,EAAE,CAAC;AAC/B,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,CAAC"}
|
|
@@ -32,13 +32,13 @@ var import_registry = require("../drawing/registry.js");
|
|
|
32
32
|
function new_linefill(line1, line2, fillColor) {
|
|
33
33
|
if (line1 === null || line1 === void 0 || line2 === null || line2 === void 0) return null;
|
|
34
34
|
let found;
|
|
35
|
-
for (const fill2 of (0, import_registry.
|
|
35
|
+
for (const fill2 of (0, import_registry.liveFillsOf)(line1)) {
|
|
36
36
|
const has = (l) => fill2.line1 === l || fill2.line2 === l;
|
|
37
|
-
if (has(
|
|
37
|
+
if (has(line2) && (!found || Touched.get(fill2) > Touched.get(found))) found = fill2;
|
|
38
38
|
}
|
|
39
39
|
if (found) {
|
|
40
40
|
found.color = fillColor;
|
|
41
|
-
|
|
41
|
+
Touched.set(found, ++touchCount);
|
|
42
42
|
return found;
|
|
43
43
|
}
|
|
44
44
|
const fill = (0, import_registry.register)("linefill", {
|
|
@@ -46,10 +46,19 @@ function new_linefill(line1, line2, fillColor) {
|
|
|
46
46
|
line2,
|
|
47
47
|
color: fillColor
|
|
48
48
|
});
|
|
49
|
-
|
|
49
|
+
Touched.set(fill, ++touchCount);
|
|
50
50
|
return fill;
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
class Touched extends import_registry.Stamped {
|
|
53
|
+
#touch = 0;
|
|
54
|
+
static get(fill) {
|
|
55
|
+
return #touch in fill ? fill.#touch : 0;
|
|
56
|
+
}
|
|
57
|
+
static set(fill, order) {
|
|
58
|
+
if (!(#touch in fill)) new Touched(fill);
|
|
59
|
+
fill.#touch = order;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
53
62
|
let touchCount = 0;
|
|
54
63
|
function get_line1(id) {
|
|
55
64
|
return id.line1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/linefill/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Linefill namespace\n * Functions for creating and manipulating linefill drawing objects.\n *\n * @remarks\n * Linefill objects fill the area between two lines with a color.\n * They have minimal computational value but automatically follow line movements\n * and provide a way to retrieve the underlying line references.\n *\n * @version 6\n */\n\nimport { all as allDrawings, isDeleted, register, remove } from '../drawing/registry.js';\nimport type { Linefill, Line, color } from '../types/index.js';\n\n/**\n * Creates a new linefill object that fills the area between two lines.\n *\n * @param line1 - First line object\n * @param line2 - Second line object\n * @param fillColor - Fill color (optional)\n * @returns New linefill object\n *\n * @remarks\n * - Automatically follows line movements (if lines are updated, fill updates too)\n * - Automatically deleted if either line is deleted\n * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill\n * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is\n * returned with the new colour instead of a new one; with several, the one created or returned last\n * - If both lines extend in same direction, fill extends too\n * - Purely visual in PineScript, but getters allow retrieving line references\n *\n * @example\n * ```typescript\n * import { line, linefill } from 'oakscriptjs';\n *\n * // Create channel lines\n * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');\n * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');\n *\n * // Fill channel with color\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue\n * ```\n */\nexport function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {\n // PineScript: an na line gives an na linefill\n if (line1 === null || line1 === undefined || line2 === null || line2 === undefined) return null as unknown as Linefill;\n let found: Linefill | undefined;\n for (const fill of
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,
|
|
4
|
+
"sourcesContent": ["/**\n * Linefill namespace\n * Functions for creating and manipulating linefill drawing objects.\n *\n * @remarks\n * Linefill objects fill the area between two lines with a color.\n * They have minimal computational value but automatically follow line movements\n * and provide a way to retrieve the underlying line references.\n *\n * @version 6\n */\n\nimport { Stamped, all as allDrawings, isDeleted, liveFillsOf, register, remove } from '../drawing/registry.js';\nimport type { Linefill, Line, color } from '../types/index.js';\n\n/**\n * Creates a new linefill object that fills the area between two lines.\n *\n * @param line1 - First line object\n * @param line2 - Second line object\n * @param fillColor - Fill color (optional)\n * @returns New linefill object\n *\n * @remarks\n * - Automatically follows line movements (if lines are updated, fill updates too)\n * - Automatically deleted if either line is deleted\n * - One linefill per pair of lines, as in PineScript (#174): when both lines already belong to a live linefill\n * (`linefill.new(b, a)` after `linefill.new(a, b)`, or `linefill.new(a, a)` after either), that linefill is\n * returned with the new colour instead of a new one; with several, the one created or returned last\n * - If both lines extend in same direction, fill extends too\n * - Purely visual in PineScript, but getters allow retrieving line references\n *\n * @example\n * ```typescript\n * import { line, linefill } from 'oakscriptjs';\n *\n * // Create channel lines\n * const upperLine = line.new(0, 160, 50, 170, 'bar_index', 'right');\n * const lowerLine = line.new(0, 140, 50, 150, 'bar_index', 'right');\n *\n * // Fill channel with color\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20'); // Transparent blue\n * ```\n */\nexport function new_linefill(line1: Line, line2: Line, fillColor?: color): Linefill {\n // PineScript: an na line gives an na linefill\n if (line1 === null || line1 === undefined || line2 === null || line2 === undefined) return null as unknown as Linefill;\n let found: Linefill | undefined;\n for (const fill of liveFillsOf(line1)) {\n const has = (l: Line): boolean => fill.line1 === l || fill.line2 === l;\n if (has(line2) && (!found || Touched.get(fill) > Touched.get(found))) found = fill;\n }\n if (found) {\n found.color = fillColor;\n Touched.set(found, ++touchCount);\n return found;\n }\n const fill = register('linefill', {\n line1,\n line2,\n color: fillColor\n });\n Touched.set(fill, ++touchCount);\n return fill;\n}\n\n/** Order in which the linefills were created or returned by `linefill.new` (the last one wins a lookup); 0 before. */\nclass Touched extends Stamped {\n #touch = 0;\n static get(fill: Linefill): number {\n return #touch in fill ? fill.#touch : 0;\n }\n static set(fill: Linefill, order: number): void {\n if (!(#touch in fill)) new Touched(fill);\n (fill as unknown as Touched).#touch = order;\n }\n}\nlet touchCount = 0;\n\n/**\n * Returns the first line reference.\n *\n * @param id - Linefill object\n * @returns First line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the first line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the first line\n * const line1 = linefill.get_line1(channelFill);\n * line.set_y2(line1, 175); // Update upper line's second point\n * ```\n */\nexport function get_line1(id: Linefill): Line {\n return id.line1;\n}\n\n/**\n * Returns the second line reference.\n *\n * @param id - Linefill object\n * @returns Second line object\n *\n * @remarks\n * Can be used to retrieve and manipulate the second line.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n *\n * // Later, retrieve and update the second line\n * const line2 = linefill.get_line2(channelFill);\n * line.set_y2(line2, 145); // Update lower line's second point\n * ```\n */\nexport function get_line2(id: Linefill): Line {\n return id.line2;\n}\n\n/**\n * Sets the fill color.\n *\n * @param id - Linefill object to modify\n * @param fillColor - New fill color\n * @returns Modified linefill object\n *\n * @remarks\n * Useful for dynamically changing channel colors based on conditions.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine, '#0000FF20');\n *\n * // Change color based on trend\n * if (bullish) {\n * linefill.set_color(channelFill, '#00FF0020'); // Green\n * } else {\n * linefill.set_color(channelFill, '#FF000020'); // Red\n * }\n * ```\n */\nexport function set_color(id: Linefill, fillColor: color): Linefill {\n if (isDeleted(id)) return id;\n id.color = fillColor;\n return id;\n}\n\n/**\n * Deletes the linefill object.\n *\n * @param id - Linefill object to delete\n *\n * @remarks\n * Removes the linefill from `linefill.all()`. As in PineScript, the deleted linefill is `na`: its getters\n * return NaN and its setters do nothing. Deleting it twice has no effect.\n *\n * @example\n * ```typescript\n * const channelFill = linefill.new(upperLine, lowerLine);\n * linefill.delete(channelFill);\n * // linefill.all() no longer contains it\n * ```\n */\nexport function delete_linefill(id: Linefill): void {\n remove('linefill', id);\n}\n\n\n/**\n * All live linefills, in creation order (PineScript `linefill.all`). A new array.\n */\nexport function all(): Linefill[] {\n return allDrawings('linefill');\n}\n\n// Alias to match PineScript API\nexport { new_linefill as new };\nexport { delete_linefill as delete };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,sBAAsF;AAgC/E,SAAS,aAAa,OAAa,OAAa,WAA6B;AAElF,MAAI,UAAU,QAAQ,UAAU,UAAa,UAAU,QAAQ,UAAU,OAAW,QAAO;AAC3F,MAAI;AACJ,aAAWA,aAAQ,6BAAY,KAAK,GAAG;AACrC,UAAM,MAAM,CAAC,MAAqBA,MAAK,UAAU,KAAKA,MAAK,UAAU;AACrE,QAAI,IAAI,KAAK,MAAM,CAAC,SAAS,QAAQ,IAAIA,KAAI,IAAI,QAAQ,IAAI,KAAK,GAAI,SAAQA;AAAA,EAChF;AACA,MAAI,OAAO;AACT,UAAM,QAAQ;AACd,YAAQ,IAAI,OAAO,EAAE,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,QAAM,WAAO,0BAAS,YAAY;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AACD,UAAQ,IAAI,MAAM,EAAE,UAAU;AAC9B,SAAO;AACT;AAGA,MAAM,gBAAgB,wBAAQ;AAAA,EAC5B,SAAS;AAAA,EACT,OAAO,IAAI,MAAwB;AACjC,WAAO,UAAU,OAAO,KAAK,SAAS;AAAA,EACxC;AAAA,EACA,OAAO,IAAI,MAAgB,OAAqB;AAC9C,QAAI,EAAE,UAAU,MAAO,KAAI,QAAQ,IAAI;AACvC,IAAC,KAA4B,SAAS;AAAA,EACxC;AACF;AACA,IAAI,aAAa;AAoBV,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAoBO,SAAS,UAAU,IAAoB;AAC5C,SAAO,GAAG;AACZ;AAwBO,SAAS,UAAU,IAAc,WAA4B;AAClE,UAAI,2BAAU,EAAE,EAAG,QAAO;AAC1B,KAAG,QAAQ;AACX,SAAO;AACT;AAkBO,SAAS,gBAAgB,IAAoB;AAClD,8BAAO,YAAY,EAAE;AACvB;AAMO,SAAS,MAAkB;AAChC,aAAO,gBAAAC,KAAY,UAAU;AAC/B;",
|
|
6
6
|
"names": ["fill", "allDrawings"]
|
|
7
7
|
}
|
|
@@ -17,6 +17,9 @@ export interface ConvertedDigits {
|
|
|
17
17
|
/** The digits are the exact value of the double */
|
|
18
18
|
exact: boolean;
|
|
19
19
|
}
|
|
20
|
+
export declare function pow5(k: number): bigint;
|
|
21
|
+
/** `s` without its trailing '0' characters. */
|
|
22
|
+
export declare function trimZeros(s: string): string;
|
|
20
23
|
/** Digits of a positive finite double, as the JVM converter gives them. */
|
|
21
24
|
export declare function convertDouble(x: number): ConvertedDigits;
|
|
22
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"floatingdecimal.d.ts","sourceRoot":"","sources":["../../../src/str/floatingdecimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,gGAAgG;AAChG,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"floatingdecimal.d.ts","sourceRoot":"","sources":["../../../src/str/floatingdecimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,gGAAgG;AAChG,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;CAChB;AAoBD,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtC;AAED,+CAA+C;AAC/C,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI3C;AAuBD,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,eAAe,CAuJxD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAoD9F"}
|
|
@@ -19,7 +19,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var floatingdecimal_exports = {};
|
|
20
20
|
__export(floatingdecimal_exports, {
|
|
21
21
|
convertDouble: () => convertDouble,
|
|
22
|
-
javaFixedDigits: () => javaFixedDigits
|
|
22
|
+
javaFixedDigits: () => javaFixedDigits,
|
|
23
|
+
pow5: () => pow5,
|
|
24
|
+
trimZeros: () => trimZeros
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(floatingdecimal_exports);
|
|
25
27
|
const EXP_SHIFT = 52;
|
|
@@ -96,10 +98,21 @@ const LONG_5_POW_LENGTH = 27;
|
|
|
96
98
|
const view = new DataView(new ArrayBuffer(8));
|
|
97
99
|
const int32 = (v) => BigInt.asIntN(32, v);
|
|
98
100
|
const int64 = (v) => BigInt.asIntN(64, v);
|
|
101
|
+
const powersOf5 = [1n];
|
|
102
|
+
function pow5(k) {
|
|
103
|
+
while (powersOf5.length <= k) powersOf5.push(powersOf5[powersOf5.length - 1] * 5n);
|
|
104
|
+
return powersOf5[k];
|
|
105
|
+
}
|
|
106
|
+
function trimZeros(s) {
|
|
107
|
+
let end = s.length;
|
|
108
|
+
while (end > 0 && s.charCodeAt(end - 1) === 48) end--;
|
|
109
|
+
return s.slice(0, end);
|
|
110
|
+
}
|
|
99
111
|
function trailingZeros(v) {
|
|
112
|
+
let x = Number(v);
|
|
100
113
|
let n = 0;
|
|
101
|
-
while (
|
|
102
|
-
|
|
114
|
+
while (x % 2 === 0) {
|
|
115
|
+
x /= 2;
|
|
103
116
|
n++;
|
|
104
117
|
}
|
|
105
118
|
return n;
|
|
@@ -143,7 +156,7 @@ function convertDouble(x) {
|
|
|
143
156
|
if (residue >= pow10 >> 1n) lvalue++;
|
|
144
157
|
}
|
|
145
158
|
const s = lvalue.toString();
|
|
146
|
-
return { digits: s
|
|
159
|
+
return { digits: trimZeros(s), decExponent: insignificant + s.length, roundedUp: false, exact: false };
|
|
147
160
|
}
|
|
148
161
|
let decExp = estimateDecExp(fractBits, binExp);
|
|
149
162
|
const B5 = Math.max(0, -decExp);
|
|
@@ -174,9 +187,9 @@ function convertDouble(x) {
|
|
|
174
187
|
const minTwo = decExp < -3 || decExp >= 8;
|
|
175
188
|
if (Bbits < 64 && tenSbits < 64) {
|
|
176
189
|
const wrap = Bbits < 32 && tenSbits < 32 ? int32 : int64;
|
|
177
|
-
let b = wrap(fractBits *
|
|
178
|
-
const s = wrap(
|
|
179
|
-
let m = wrap(
|
|
190
|
+
let b = wrap(fractBits * pow5(B5) << BigInt(B2));
|
|
191
|
+
const s = wrap(pow5(S5) << BigInt(S2));
|
|
192
|
+
let m = wrap(pow5(M5) << BigInt(M2));
|
|
180
193
|
const tens = wrap(s * 10n);
|
|
181
194
|
let q = Number(b / s);
|
|
182
195
|
b = wrap(10n * (b % s));
|
|
@@ -202,9 +215,9 @@ function convertDouble(x) {
|
|
|
202
215
|
lowDigitDifference = wrap((b << 1n) - tens);
|
|
203
216
|
exact = b === 0n;
|
|
204
217
|
} else {
|
|
205
|
-
let b = fractBits *
|
|
206
|
-
const s =
|
|
207
|
-
let m =
|
|
218
|
+
let b = fractBits * pow5(B5) << BigInt(B2);
|
|
219
|
+
const s = pow5(S5) << BigInt(S2);
|
|
220
|
+
let m = pow5(M5 + 1) << BigInt(M2 + 1);
|
|
208
221
|
const tens = s * 10n;
|
|
209
222
|
let q = Number(b / s);
|
|
210
223
|
b = b % s * 10n;
|
|
@@ -243,7 +256,7 @@ function convertDouble(x) {
|
|
|
243
256
|
if (digits[digits.length - 1] % 2 !== 0) roundup();
|
|
244
257
|
} else if (lowDigitDifference > 0n) roundup();
|
|
245
258
|
}
|
|
246
|
-
const text = digits.join("")
|
|
259
|
+
const text = trimZeros(digits.join(""));
|
|
247
260
|
return { digits: text || "0", decExponent, roundedUp, exact };
|
|
248
261
|
}
|
|
249
262
|
function javaFixedDigits(x, maxFrac) {
|
|
@@ -292,7 +305,7 @@ function javaFixedDigits(x, maxFrac) {
|
|
|
292
305
|
count = keep;
|
|
293
306
|
while (count > 1 && digits[count - 1] === 0) count--;
|
|
294
307
|
}
|
|
295
|
-
const text = digits.slice(0, count).join("")
|
|
308
|
+
const text = trimZeros(digits.slice(0, count).join(""));
|
|
296
309
|
return { digits: text, intLen: text ? decimalAt : 0 };
|
|
297
310
|
}
|
|
298
311
|
//# sourceMappingURL=floatingdecimal.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/str/floatingdecimal.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Decimal digits of a double as PineScript's plain `str.tostring` produces them.\n *\n * PineScript formats a number without a format with the digits of the classic binary to decimal conversion of the\n * JVM (the one `Double.toString` used before Java 19), then rounds them to 10 decimals half to even, with two\n * flags of the conversion deciding a tie on the last digit: digits that were rounded up are not rounded up again,\n * digits that were cut on a '5' are. These digits are not always the shortest ones: 78195689105219552 keeps all\n * its digits (the shortest form is 78195689105219550), and 1990736.000001111 has 16 digits where rounding the exact\n * value would give 1990736.0000011111 (#174).\n */\n\n/** Digits d1d2d3... of |x| = 0.d1d2d3... \u00D7 10^decExponent, with the flags of the conversion. */\nexport interface ConvertedDigits {\n digits: string;\n decExponent: number;\n /** The last digit was rounded up */\n roundedUp: boolean;\n /** The digits are the exact value of the double */\n exact: boolean;\n}\n\nconst EXP_SHIFT = 52;\nconst MAX_SMALL_BIN_EXP = 62;\nconst MIN_SMALL_BIN_EXP = -21;\n// approximately ceil(log2(5^i))\nconst N_5_BITS = [0, 3, 5, 7, 10, 12, 14, 17, 19, 21, 24, 26, 28, 31, 33, 35, 38, 40, 42, 45, 47, 49, 52, 54, 56, 59, 61];\n// number of decimal digits of 2^i minus one, for i < 64\nconst INSIGNIFICANT_DIGITS = [\n 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10,\n 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19,\n];\nconst LONG_5_POW_LENGTH = 27;\nconst view = new DataView(new ArrayBuffer(8));\n\nconst int32 = (v: bigint): bigint => BigInt.asIntN(32, v);\nconst int64 = (v: bigint): bigint => BigInt.asIntN(64, v);\n\nfunction trailingZeros(v: bigint): number {\n let n = 0;\n while ((v & 1n) === 0n) {\n v >>= 1n;\n n++;\n }\n return n;\n}\n\n/** floor(log10(x)) estimate of the conversion (it can be one too high). */\nfunction estimateDecExp(fractBits: bigint, binExp: number): number {\n view.setBigUint64(0, (1023n << 52n) | (fractBits & 0xfffffffffffffn));\n const d2 = view.getFloat64(0);\n const d = (d2 - 1.5) * 0.289529654 + 0.176091259 + binExp * 0.301029995663981;\n // the conversion truncates toward zero and corrects negative non-integers down\n const r = Math.trunc(d);\n return d < 0 && r !== d ? r - 1 : r;\n}\n\n/** Digits of a positive finite double, as the JVM converter gives them. */\nexport function convertDouble(x: number): ConvertedDigits {\n view.setFloat64(0, Math.abs(x));\n const bits = view.getBigUint64(0);\n let fractBits = bits & 0xfffffffffffffn;\n let binExp = Number((bits >> 52n) & 0x7ffn);\n if (binExp === 0 && fractBits === 0n) return { digits: '0', decExponent: 1, roundedUp: false, exact: false };\n let nSignificantBits: number;\n if (binExp === 0) {\n const leadingZeros = 64 - fractBits.toString(2).length;\n const shift = leadingZeros - (63 - EXP_SHIFT);\n fractBits <<= BigInt(shift);\n binExp = 1 - shift;\n nSignificantBits = 64 - leadingZeros;\n } else {\n fractBits |= 1n << 52n;\n nSignificantBits = EXP_SHIFT + 1;\n }\n binExp -= 1023;\n\n const tailZeros = trailingZeros(fractBits);\n const nFractBits = EXP_SHIFT + 1 - tailZeros;\n const nTinyBits = Math.max(0, nFractBits - binExp - 1);\n\n // an integer that fits in a long: its digits, the low ones rounded away when they are not significant\n if (\n binExp <= MAX_SMALL_BIN_EXP &&\n binExp >= MIN_SMALL_BIN_EXP &&\n nTinyBits < LONG_5_POW_LENGTH &&\n nFractBits + N_5_BITS[nTinyBits]! < 64 &&\n nTinyBits === 0\n ) {\n const p2 = binExp - nSignificantBits - 1;\n const insignificant = binExp > nSignificantBits && p2 > 1 && p2 < INSIGNIFICANT_DIGITS.length ? INSIGNIFICANT_DIGITS[p2]! : 0;\n let lvalue = binExp >= EXP_SHIFT ? fractBits << BigInt(binExp - EXP_SHIFT) : fractBits >> BigInt(EXP_SHIFT - binExp);\n if (insignificant !== 0) {\n const pow10 = 10n ** BigInt(insignificant);\n const residue = lvalue % pow10;\n lvalue /= pow10;\n if (residue >= pow10 >> 1n) lvalue++;\n }\n const s = lvalue.toString();\n return { digits: s.replace(/0+$/, ''), decExponent: insignificant + s.length, roundedUp: false, exact: false };\n }\n\n let decExp = estimateDecExp(fractBits, binExp);\n const B5 = Math.max(0, -decExp);\n let B2 = B5 + nTinyBits + binExp;\n const S5 = Math.max(0, decExp);\n let S2 = S5 + nTinyBits;\n const M5 = B5;\n let M2 = B2 - nSignificantBits;\n\n fractBits >>= BigInt(tailZeros);\n B2 -= nFractBits - 1;\n const common2factor = Math.min(B2, S2);\n B2 -= common2factor;\n S2 -= common2factor;\n M2 -= common2factor;\n // an exact power of two: the next smaller double is half as far\n if (nFractBits === 1) M2 -= 1;\n if (M2 < 0) {\n B2 -= M2;\n S2 -= M2;\n M2 = 0;\n }\n\n const digits: number[] = [];\n let low: boolean;\n let high: boolean;\n let lowDigitDifference: bigint;\n let exact: boolean;\n const Bbits = nFractBits + B2 + (B5 < N_5_BITS.length ? N_5_BITS[B5]! : B5 * 3);\n const tenSbits = S2 + 1 + (S5 + 1 < N_5_BITS.length ? N_5_BITS[S5 + 1]! : (S5 + 1) * 3);\n // two digits at least in the exponent form\n const minTwo = decExp < -3 || decExp >= 8;\n\n if (Bbits < 64 && tenSbits < 64) {\n // int or long arithmetic, with its overflows\n const wrap = Bbits < 32 && tenSbits < 32 ? int32 : int64;\n let b = wrap((fractBits * 5n ** BigInt(B5)) << BigInt(B2));\n const s = wrap(5n ** BigInt(S5) << BigInt(S2));\n let m = wrap(5n ** BigInt(M5) << BigInt(M2));\n const tens = wrap(s * 10n);\n let q = Number(b / s);\n b = wrap(10n * (b % s));\n m = wrap(m * 10n);\n low = b < m;\n high = wrap(b + m) > tens;\n if (q === 0 && !high) decExp--;\n else digits.push(q);\n if (minTwo) high = low = false;\n while (!low && !high) {\n q = Number(b / s);\n b = wrap(10n * (b % s));\n m = wrap(m * 10n);\n if (m > 0n) {\n low = b < m;\n high = wrap(b + m) > tens;\n } else {\n low = true;\n high = true;\n }\n digits.push(q);\n }\n lowDigitDifference = wrap((b << 1n) - tens);\n exact = b === 0n;\n } else {\n let b = (fractBits * 5n ** BigInt(B5)) << BigInt(B2);\n const s = 5n ** BigInt(S5) << BigInt(S2);\n let m = 5n ** BigInt(M5 + 1) << BigInt(M2 + 1);\n const tens = s * 10n;\n let q = Number(b / s);\n b = (b % s) * 10n;\n low = b < m;\n high = b + m >= tens;\n if (q === 0 && !high) decExp--;\n else digits.push(q);\n if (minTwo) high = low = false;\n while (!low && !high) {\n q = Number(b / s);\n b = (b % s) * 10n;\n m *= 10n;\n low = b < m;\n high = b + m >= tens;\n digits.push(q);\n }\n lowDigitDifference = high && low ? (b << 1n) - tens : 0n;\n exact = b === 0n;\n }\n\n let decExponent = decExp + 1;\n let roundedUp = false;\n const roundup = (): void => {\n let i = digits.length - 1;\n while (digits[i] === 9 && i > 0) digits[i--] = 0;\n if (digits[i] === 9) {\n decExponent += 1;\n digits[0] = 1;\n return;\n }\n digits[i]! += 1;\n roundedUp = true;\n };\n if (high) {\n if (!low) roundup();\n else if (lowDigitDifference === 0n) {\n if (digits[digits.length - 1]! % 2 !== 0) roundup();\n } else if (lowDigitDifference > 0n) roundup();\n }\n const text = digits.join('').replace(/0+$/, '');\n return { digits: text || '0', decExponent, roundedUp, exact };\n}\n\n/**\n * `|x|` with at most `maxFrac` decimals, as the JVM's decimal formatter rounds the converted digits (half to even;\n * a tie on the last converted digit is decided by the conversion flags). Returns the digits and the position of the\n * decimal point (value = 0.digits \u00D7 10^intLen); \"\" for zero.\n */\nexport function javaFixedDigits(x: number, maxFrac: number): { digits: string; intLen: number } {\n if (x === 0) return { digits: '', intLen: 0 };\n const c = convertDouble(x);\n const digits = [...c.digits].map(Number);\n let decimalAt = c.decExponent;\n // the formatter reads the conversion's text, which ends in \".0\" when no digit follows the point (\"5.0E-11\",\n // \"120.0\"): that zero is a digit for the tie test below (5e-11 to 10 decimals gives 0)\n const n = digits.length;\n if (decimalAt > 0 && decimalAt < 8) {\n if (n <= decimalAt) digits.push(...Array<number>(decimalAt - n + 1).fill(0));\n } else if (decimalAt <= -3 || decimalAt >= 8) {\n if (n === 1) digits.push(0);\n }\n let count = digits.length;\n\n const shouldRoundUp = (keep: number): boolean => {\n if (keep >= count) return false;\n if (digits[keep]! > 5) return true;\n if (digits[keep] !== 5) return false;\n if (keep === count - 1) {\n if (c.exact) return keep > 0 && digits[keep - 1]! % 2 !== 0;\n return !c.roundedUp;\n }\n for (let i = keep + 1; i < count; i++) if (digits[i] !== 0) return true;\n return false;\n };\n\n if (-decimalAt > maxFrac) return { digits: '', intLen: 0 };\n if (-decimalAt === maxFrac) {\n return shouldRoundUp(0) ? { digits: '1', intLen: decimalAt + 1 } : { digits: '', intLen: 0 };\n }\n while (count > 1 && digits[count - 1] === 0) count--;\n let keep = maxFrac + decimalAt;\n if (keep >= 0 && keep < count) {\n if (shouldRoundUp(keep)) {\n do {\n keep--;\n if (keep < 0) {\n digits[0] = 1;\n decimalAt++;\n keep = 0;\n break;\n }\n digits[keep]! += 1;\n } while (digits[keep]! > 9);\n keep++;\n }\n count = keep;\n while (count > 1 && digits[count - 1] === 0) count--;\n }\n const text = digits.slice(0, count).join('').replace(/0+$/, '');\n return { digits: text, intLen: text ? decimalAt : 0 };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,MAAM,YAAY;AAClB,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAE1B,MAAM,WAAW,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;AAExH,MAAM,uBAAuB;AAAA,EAC3B;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAI;AAAA,EAAI;AAAA,EAC9G;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAC1G;AACA,MAAM,oBAAoB;AAC1B,MAAM,OAAO,IAAI,SAAS,IAAI,YAAY,CAAC,CAAC;AAE5C,MAAM,QAAQ,CAAC,MAAsB,OAAO,OAAO,IAAI,CAAC;AACxD,MAAM,QAAQ,CAAC,MAAsB,OAAO,OAAO,IAAI,CAAC;
|
|
4
|
+
"sourcesContent": ["/**\n * Decimal digits of a double as PineScript's plain `str.tostring` produces them.\n *\n * PineScript formats a number without a format with the digits of the classic binary to decimal conversion of the\n * JVM (the one `Double.toString` used before Java 19), then rounds them to 10 decimals half to even, with two\n * flags of the conversion deciding a tie on the last digit: digits that were rounded up are not rounded up again,\n * digits that were cut on a '5' are. These digits are not always the shortest ones: 78195689105219552 keeps all\n * its digits (the shortest form is 78195689105219550), and 1990736.000001111 has 16 digits where rounding the exact\n * value would give 1990736.0000011111 (#174).\n */\n\n/** Digits d1d2d3... of |x| = 0.d1d2d3... \u00D7 10^decExponent, with the flags of the conversion. */\nexport interface ConvertedDigits {\n digits: string;\n decExponent: number;\n /** The last digit was rounded up */\n roundedUp: boolean;\n /** The digits are the exact value of the double */\n exact: boolean;\n}\n\nconst EXP_SHIFT = 52;\nconst MAX_SMALL_BIN_EXP = 62;\nconst MIN_SMALL_BIN_EXP = -21;\n// approximately ceil(log2(5^i))\nconst N_5_BITS = [0, 3, 5, 7, 10, 12, 14, 17, 19, 21, 24, 26, 28, 31, 33, 35, 38, 40, 42, 45, 47, 49, 52, 54, 56, 59, 61];\n// number of decimal digits of 2^i minus one, for i < 64\nconst INSIGNIFICANT_DIGITS = [\n 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10,\n 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19,\n];\nconst LONG_5_POW_LENGTH = 27;\nconst view = new DataView(new ArrayBuffer(8));\n\nconst int32 = (v: bigint): bigint => BigInt.asIntN(32, v);\nconst int64 = (v: bigint): bigint => BigInt.asIntN(64, v);\n\n/** 5^k, made once (k up to 1074, the binary exponents of the doubles). */\nconst powersOf5: bigint[] = [1n];\nexport function pow5(k: number): bigint {\n while (powersOf5.length <= k) powersOf5.push(powersOf5[powersOf5.length - 1]! * 5n);\n return powersOf5[k]!;\n}\n\n/** `s` without its trailing '0' characters. */\nexport function trimZeros(s: string): string {\n let end = s.length;\n while (end > 0 && s.charCodeAt(end - 1) === 48) end--;\n return s.slice(0, end);\n}\n\n/** Trailing zero bits of a significand (not 0, below 2^53: exact as a double). */\nfunction trailingZeros(v: bigint): number {\n let x = Number(v);\n let n = 0;\n while (x % 2 === 0) {\n x /= 2;\n n++;\n }\n return n;\n}\n\n/** floor(log10(x)) estimate of the conversion (it can be one too high). */\nfunction estimateDecExp(fractBits: bigint, binExp: number): number {\n view.setBigUint64(0, (1023n << 52n) | (fractBits & 0xfffffffffffffn));\n const d2 = view.getFloat64(0);\n const d = (d2 - 1.5) * 0.289529654 + 0.176091259 + binExp * 0.301029995663981;\n // the conversion truncates toward zero and corrects negative non-integers down\n const r = Math.trunc(d);\n return d < 0 && r !== d ? r - 1 : r;\n}\n\n/** Digits of a positive finite double, as the JVM converter gives them. */\nexport function convertDouble(x: number): ConvertedDigits {\n view.setFloat64(0, Math.abs(x));\n const bits = view.getBigUint64(0);\n let fractBits = bits & 0xfffffffffffffn;\n let binExp = Number((bits >> 52n) & 0x7ffn);\n if (binExp === 0 && fractBits === 0n) return { digits: '0', decExponent: 1, roundedUp: false, exact: false };\n let nSignificantBits: number;\n if (binExp === 0) {\n const leadingZeros = 64 - fractBits.toString(2).length;\n const shift = leadingZeros - (63 - EXP_SHIFT);\n fractBits <<= BigInt(shift);\n binExp = 1 - shift;\n nSignificantBits = 64 - leadingZeros;\n } else {\n fractBits |= 1n << 52n;\n nSignificantBits = EXP_SHIFT + 1;\n }\n binExp -= 1023;\n\n const tailZeros = trailingZeros(fractBits);\n const nFractBits = EXP_SHIFT + 1 - tailZeros;\n const nTinyBits = Math.max(0, nFractBits - binExp - 1);\n\n // an integer that fits in a long: its digits, the low ones rounded away when they are not significant\n if (\n binExp <= MAX_SMALL_BIN_EXP &&\n binExp >= MIN_SMALL_BIN_EXP &&\n nTinyBits < LONG_5_POW_LENGTH &&\n nFractBits + N_5_BITS[nTinyBits]! < 64 &&\n nTinyBits === 0\n ) {\n const p2 = binExp - nSignificantBits - 1;\n const insignificant = binExp > nSignificantBits && p2 > 1 && p2 < INSIGNIFICANT_DIGITS.length ? INSIGNIFICANT_DIGITS[p2]! : 0;\n let lvalue = binExp >= EXP_SHIFT ? fractBits << BigInt(binExp - EXP_SHIFT) : fractBits >> BigInt(EXP_SHIFT - binExp);\n if (insignificant !== 0) {\n const pow10 = 10n ** BigInt(insignificant);\n const residue = lvalue % pow10;\n lvalue /= pow10;\n if (residue >= pow10 >> 1n) lvalue++;\n }\n const s = lvalue.toString();\n return { digits: trimZeros(s), decExponent: insignificant + s.length, roundedUp: false, exact: false };\n }\n\n let decExp = estimateDecExp(fractBits, binExp);\n const B5 = Math.max(0, -decExp);\n let B2 = B5 + nTinyBits + binExp;\n const S5 = Math.max(0, decExp);\n let S2 = S5 + nTinyBits;\n const M5 = B5;\n let M2 = B2 - nSignificantBits;\n\n fractBits >>= BigInt(tailZeros);\n B2 -= nFractBits - 1;\n const common2factor = Math.min(B2, S2);\n B2 -= common2factor;\n S2 -= common2factor;\n M2 -= common2factor;\n // an exact power of two: the next smaller double is half as far\n if (nFractBits === 1) M2 -= 1;\n if (M2 < 0) {\n B2 -= M2;\n S2 -= M2;\n M2 = 0;\n }\n\n const digits: number[] = [];\n let low: boolean;\n let high: boolean;\n let lowDigitDifference: bigint;\n let exact: boolean;\n const Bbits = nFractBits + B2 + (B5 < N_5_BITS.length ? N_5_BITS[B5]! : B5 * 3);\n const tenSbits = S2 + 1 + (S5 + 1 < N_5_BITS.length ? N_5_BITS[S5 + 1]! : (S5 + 1) * 3);\n // two digits at least in the exponent form\n const minTwo = decExp < -3 || decExp >= 8;\n\n if (Bbits < 64 && tenSbits < 64) {\n // int or long arithmetic, with its overflows\n const wrap = Bbits < 32 && tenSbits < 32 ? int32 : int64;\n let b = wrap((fractBits * pow5(B5)) << BigInt(B2));\n const s = wrap(pow5(S5) << BigInt(S2));\n let m = wrap(pow5(M5) << BigInt(M2));\n const tens = wrap(s * 10n);\n let q = Number(b / s);\n b = wrap(10n * (b % s));\n m = wrap(m * 10n);\n low = b < m;\n high = wrap(b + m) > tens;\n if (q === 0 && !high) decExp--;\n else digits.push(q);\n if (minTwo) high = low = false;\n while (!low && !high) {\n q = Number(b / s);\n b = wrap(10n * (b % s));\n m = wrap(m * 10n);\n if (m > 0n) {\n low = b < m;\n high = wrap(b + m) > tens;\n } else {\n low = true;\n high = true;\n }\n digits.push(q);\n }\n lowDigitDifference = wrap((b << 1n) - tens);\n exact = b === 0n;\n } else {\n let b = (fractBits * pow5(B5)) << BigInt(B2);\n const s = pow5(S5) << BigInt(S2);\n let m = pow5(M5 + 1) << BigInt(M2 + 1);\n const tens = s * 10n;\n let q = Number(b / s);\n b = (b % s) * 10n;\n low = b < m;\n high = b + m >= tens;\n if (q === 0 && !high) decExp--;\n else digits.push(q);\n if (minTwo) high = low = false;\n while (!low && !high) {\n q = Number(b / s);\n b = (b % s) * 10n;\n m *= 10n;\n low = b < m;\n high = b + m >= tens;\n digits.push(q);\n }\n lowDigitDifference = high && low ? (b << 1n) - tens : 0n;\n exact = b === 0n;\n }\n\n let decExponent = decExp + 1;\n let roundedUp = false;\n const roundup = (): void => {\n let i = digits.length - 1;\n while (digits[i] === 9 && i > 0) digits[i--] = 0;\n if (digits[i] === 9) {\n decExponent += 1;\n digits[0] = 1;\n return;\n }\n digits[i]! += 1;\n roundedUp = true;\n };\n if (high) {\n if (!low) roundup();\n else if (lowDigitDifference === 0n) {\n if (digits[digits.length - 1]! % 2 !== 0) roundup();\n } else if (lowDigitDifference > 0n) roundup();\n }\n const text = trimZeros(digits.join(''));\n return { digits: text || '0', decExponent, roundedUp, exact };\n}\n\n/**\n * `|x|` with at most `maxFrac` decimals, as the JVM's decimal formatter rounds the converted digits (half to even;\n * a tie on the last converted digit is decided by the conversion flags). Returns the digits and the position of the\n * decimal point (value = 0.digits \u00D7 10^intLen); \"\" for zero.\n */\nexport function javaFixedDigits(x: number, maxFrac: number): { digits: string; intLen: number } {\n if (x === 0) return { digits: '', intLen: 0 };\n const c = convertDouble(x);\n const digits = [...c.digits].map(Number);\n let decimalAt = c.decExponent;\n // the formatter reads the conversion's text, which ends in \".0\" when no digit follows the point (\"5.0E-11\",\n // \"120.0\"): that zero is a digit for the tie test below (5e-11 to 10 decimals gives 0)\n const n = digits.length;\n if (decimalAt > 0 && decimalAt < 8) {\n if (n <= decimalAt) digits.push(...Array<number>(decimalAt - n + 1).fill(0));\n } else if (decimalAt <= -3 || decimalAt >= 8) {\n if (n === 1) digits.push(0);\n }\n let count = digits.length;\n\n const shouldRoundUp = (keep: number): boolean => {\n if (keep >= count) return false;\n if (digits[keep]! > 5) return true;\n if (digits[keep] !== 5) return false;\n if (keep === count - 1) {\n if (c.exact) return keep > 0 && digits[keep - 1]! % 2 !== 0;\n return !c.roundedUp;\n }\n for (let i = keep + 1; i < count; i++) if (digits[i] !== 0) return true;\n return false;\n };\n\n if (-decimalAt > maxFrac) return { digits: '', intLen: 0 };\n if (-decimalAt === maxFrac) {\n return shouldRoundUp(0) ? { digits: '1', intLen: decimalAt + 1 } : { digits: '', intLen: 0 };\n }\n while (count > 1 && digits[count - 1] === 0) count--;\n let keep = maxFrac + decimalAt;\n if (keep >= 0 && keep < count) {\n if (shouldRoundUp(keep)) {\n do {\n keep--;\n if (keep < 0) {\n digits[0] = 1;\n decimalAt++;\n keep = 0;\n break;\n }\n digits[keep]! += 1;\n } while (digits[keep]! > 9);\n keep++;\n }\n count = keep;\n while (count > 1 && digits[count - 1] === 0) count--;\n }\n const text = trimZeros(digits.slice(0, count).join(''));\n return { digits: text, intLen: text ? decimalAt : 0 };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,MAAM,YAAY;AAClB,MAAM,oBAAoB;AAC1B,MAAM,oBAAoB;AAE1B,MAAM,WAAW,CAAC,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;AAExH,MAAM,uBAAuB;AAAA,EAC3B;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,EAAG;AAAA,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;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"messageformat.d.ts","sourceRoot":"","sources":["../../../src/str/messageformat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0HH,6HAA6H;AAC7H,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,CAUzG"}
|
|
@@ -76,23 +76,28 @@ function formatArgument(value, type, style, timezone) {
|
|
|
76
76
|
throw new SyntaxError(`Unknown format type "${type}"`);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const templates = /* @__PURE__ */ new Map();
|
|
80
|
+
const MAX_TEMPLATES = 1e3;
|
|
81
|
+
function parseTemplate(pattern) {
|
|
82
|
+
const cached = templates.get(pattern);
|
|
83
|
+
if (cached) return cached;
|
|
84
|
+
const parts = [];
|
|
85
|
+
let text = "";
|
|
81
86
|
for (let i = 0; i < pattern.length; ) {
|
|
82
87
|
const ch = pattern[i];
|
|
83
88
|
if (ch === "'") {
|
|
84
89
|
if (pattern[i + 1] === "'") {
|
|
85
|
-
|
|
90
|
+
text += "'";
|
|
86
91
|
i += 2;
|
|
87
92
|
continue;
|
|
88
93
|
}
|
|
89
94
|
const end = pattern.indexOf("'", i + 1);
|
|
90
|
-
|
|
95
|
+
text += pattern.slice(i + 1, end === -1 ? void 0 : end);
|
|
91
96
|
i = end === -1 ? pattern.length : end + 1;
|
|
92
97
|
continue;
|
|
93
98
|
}
|
|
94
99
|
if (ch !== "{") {
|
|
95
|
-
|
|
100
|
+
text += ch;
|
|
96
101
|
i++;
|
|
97
102
|
continue;
|
|
98
103
|
}
|
|
@@ -107,11 +112,25 @@ function formatMessage(pattern, args, timezone) {
|
|
|
107
112
|
}
|
|
108
113
|
const inner = pattern.slice(i + 1, j - 1);
|
|
109
114
|
const [index = "", type, ...rest] = inner.split(",");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
if (text) parts.push(text);
|
|
116
|
+
text = "";
|
|
117
|
+
parts.push({ inner, index: Number(index.trim()), type, style: rest.length ? rest.join(",") : void 0 });
|
|
113
118
|
i = j;
|
|
114
119
|
}
|
|
120
|
+
if (text) parts.push(text);
|
|
121
|
+
if (templates.size >= MAX_TEMPLATES) templates.clear();
|
|
122
|
+
templates.set(pattern, parts);
|
|
123
|
+
return parts;
|
|
124
|
+
}
|
|
125
|
+
function formatMessage(pattern, args, timezone) {
|
|
126
|
+
let out = "";
|
|
127
|
+
for (const part of parseTemplate(pattern)) {
|
|
128
|
+
if (typeof part === "string") out += part;
|
|
129
|
+
else {
|
|
130
|
+
const n = part.index;
|
|
131
|
+
out += n < args.length ? formatArgument(args[n], part.type, part.style, timezone) : `{${part.inner}}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
115
134
|
return out;
|
|
116
135
|
}
|
|
117
136
|
//# sourceMappingURL=messageformat.js.map
|