@alphacharts/drawings 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ export declare class Emitter<E extends {
2
+ [K in keyof E]: unknown;
3
+ }> {
4
+ private readonly map;
5
+ on<K extends keyof E>(type: K, fn: (e: E[K]) => void): () => void;
6
+ emit<K extends keyof E>(type: K, e: E[K]): void;
7
+ }
@@ -0,0 +1,34 @@
1
+ export interface Pt {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ export declare function dist(x1: number, y1: number, x2: number, y2: number): number;
6
+ /** Distance from (px, py) to the segment (x1,y1)-(x2,y2). */
7
+ export declare function distToSegment(px: number, py: number, x1: number, y1: number, x2: number, y2: number): number;
8
+ /**
9
+ * The part of the line through a→b to draw inside [-m, W+m]×[-m, H+m]:
10
+ * the segment itself, plus the ray beyond a (extA) and/or beyond b (extB).
11
+ * Null when nothing of it is inside.
12
+ */
13
+ export declare function clipLine(x1: number, y1: number, x2: number, y2: number, extA: boolean, extB: boolean, W: number, H: number, m?: number): [number, number, number, number] | null;
14
+ /** Flat [x0,y0,x1,y1,…] points of an ellipse (rotated by rot), n segments. */
15
+ export declare function ellipsePoints(cx: number, cy: number, rx: number, ry: number, rot: number, n?: number): number[];
16
+ /** Flat points along a circular arc from angle a0 to a1 (radians, y down). */
17
+ export declare function arcPoints(cx: number, cy: number, r: number, a0: number, a1: number): number[];
18
+ /** Quadratic Bézier points p0, control c, p1. */
19
+ export declare function quadPoints(p0: Pt, c: Pt, p1: Pt, n?: number): number[];
20
+ /** The quadratic control point that makes the curve p0→p1 pass through `through` at t = 0.5. */
21
+ export declare function controlThrough(p0: Pt, through: Pt, p1: Pt): Pt;
22
+ /** Circle through three points, or null when they are collinear. */
23
+ export declare function circumcircle(a: Pt, b: Pt, c: Pt): {
24
+ cx: number;
25
+ cy: number;
26
+ r: number;
27
+ } | null;
28
+ export declare function pointInPolygon(px: number, py: number, pts: readonly number[]): boolean;
29
+ /** Distance from a point to a polyline (flat xy), optionally closed. */
30
+ export declare function distToPolyline(px: number, py: number, pts: readonly number[], close: boolean): number;
31
+ /** Intersection of lines a1→a2 and b1→b2, or null when parallel. */
32
+ export declare function intersect(a1: Pt, a2: Pt, b1: Pt, b2: Pt): Pt | null;
33
+ /** Filled arrow head at (x2,y2) for a line coming from (x1,y1): flat polygon. */
34
+ export declare function arrowHead(x1: number, y1: number, x2: number, y2: number, size: number): number[];
@@ -0,0 +1,87 @@
1
+ import type { Drawing } from "./types.js";
2
+ export declare class DrawingStore {
3
+ private items;
4
+ private index;
5
+ /** Back to front: later = on top. */
6
+ get list(): readonly Drawing[];
7
+ get(id: string): Drawing | undefined;
8
+ require(id: string): Drawing;
9
+ insert(d: Drawing, at: number): void;
10
+ remove(id: string): number;
11
+ /** Replace the drawing with the same id, in place in the order. */
12
+ replace(d: Drawing): void;
13
+ setOrder(ids: readonly string[]): void;
14
+ clear(): void;
15
+ snapshot(): string;
16
+ }
17
+ export declare const clone: <T>(v: T) => T;
18
+ export interface Command {
19
+ readonly label: string;
20
+ /** Ids of drawings the command touches (for events). */
21
+ readonly ids: readonly string[];
22
+ apply(s: DrawingStore): void;
23
+ revert(s: DrawingStore): void;
24
+ }
25
+ export declare class AddCommand implements Command {
26
+ private readonly d;
27
+ private readonly at;
28
+ readonly label = "add";
29
+ readonly ids: readonly string[];
30
+ constructor(d: Drawing, at: number);
31
+ apply(s: DrawingStore): void;
32
+ revert(s: DrawingStore): void;
33
+ }
34
+ export declare class RemoveCommand implements Command {
35
+ readonly label = "remove";
36
+ readonly ids: readonly string[];
37
+ /** Ascending by index. */
38
+ private readonly entries;
39
+ constructor(entries: Array<{
40
+ d: Drawing;
41
+ at: number;
42
+ }>);
43
+ apply(s: DrawingStore): void;
44
+ revert(s: DrawingStore): void;
45
+ }
46
+ export declare class PatchCommand implements Command {
47
+ readonly label: string;
48
+ private readonly before;
49
+ private readonly after;
50
+ readonly ids: readonly string[];
51
+ constructor(label: string, before: Drawing[], after: Drawing[]);
52
+ apply(s: DrawingStore): void;
53
+ revert(s: DrawingStore): void;
54
+ }
55
+ export declare class ReorderCommand implements Command {
56
+ private readonly before;
57
+ private readonly after;
58
+ readonly label = "reorder";
59
+ readonly ids: readonly string[];
60
+ constructor(before: string[], after: string[]);
61
+ apply(s: DrawingStore): void;
62
+ revert(s: DrawingStore): void;
63
+ }
64
+ export declare class BatchCommand implements Command {
65
+ readonly label: string;
66
+ private readonly cmds;
67
+ readonly ids: readonly string[];
68
+ constructor(label: string, cmds: Command[]);
69
+ apply(s: DrawingStore): void;
70
+ revert(s: DrawingStore): void;
71
+ }
72
+ export declare class History {
73
+ private readonly store;
74
+ private readonly max;
75
+ private undoStack;
76
+ private redoStack;
77
+ constructor(store: DrawingStore, max?: number);
78
+ get canUndo(): boolean;
79
+ get canRedo(): boolean;
80
+ /** Apply a new command and make it undoable; clears redo. */
81
+ run(c: Command): void;
82
+ /** Record a command whose effect is already in the store (a finished drag). */
83
+ record(c: Command): void;
84
+ undo(): Command | undefined;
85
+ redo(): Command | undefined;
86
+ clear(): void;
87
+ }
@@ -0,0 +1,26 @@
1
+ export { DrawingsPlugin, DRAG_SLOP, DUPLICATE_BARS, TOLERANCE, WEAK_MAGNET_PX } from "./plugin.js";
2
+ export type { DrawingPatch, DrawingsEvents, DrawingsOptions, MagnetMode, NewDrawing } from "./plugin.js";
3
+ export { DrawingStore, History, AddCommand, BatchCommand, PatchCommand, RemoveCommand, ReorderCommand } from "./history.js";
4
+ export type { Command } from "./history.js";
5
+ export { ArrayBarSource } from "./source.js";
6
+ export type { Bar, BarSource, ColumnarBars } from "./source.js";
7
+ export { TemplateStore } from "./templates.js";
8
+ export type { DrawingTemplate } from "./templates.js";
9
+ export { DEFAULT_STYLE, SCHEMA_VERSION } from "./types.js";
10
+ export type { Anchor, Dash, Drawing, DrawingStyle, DrawingsState, Gesture, Shape, Stroke, ToolCtx, ToolDef } from "./types.js";
11
+ export { drawShapes, shapeDistance, shapeInRect, withAlpha } from "./shapes.js";
12
+ export * as geometry from "./geometry.js";
13
+ export { allTools } from "./tools/all.js";
14
+ export { lineTools, trendLine, ray, infoLine, extendedLine, horizontalLine, horizontalRay, verticalLine, crossLine } from "./tools/lines.js";
15
+ export { channelTools, parallelChannel, regressionTrendChannel, flatTopBottom, disjointChannel, pitchfork, schiffPitchfork, modifiedSchiffPitchfork, insidePitchfork, pitchfan, regression, regressionOf, forkGeometry, } from "./tools/channels.js";
16
+ export { fibTools, fibRetracement, fibExtension, fibChannel, fibTimeZone, fibSpeedFan, fibTrendTime, fibCircles, fibSpiral, fibSpeedArcs, fibWedge, fibRetracementPrice, fibExtensionPrice, FIB_SEQUENCE, } from "./tools/fib.js";
17
+ export { gannTools, gannBox, gannSquareFixed, gannSquare, gannFan, gannBoxPrice, gannFanPrice, GANN_RATIOS } from "./tools/gann.js";
18
+ export { figureTools, rectangle, rotatedRectangle, ellipse, circle, triangle, arc, curve, doubleCurve, polyline, path, brush, highlighter, rotatedRectCorners, arcThrough, } from "./tools/figures.js";
19
+ export { annotationTools, textTool, anchoredText, note, anchoredNote, callout, comment, priceLabel, priceNote, signpost, flagMark, arrow, arrowMarker, arrowMarkUp, arrowMarkDown, } from "./tools/annotations.js";
20
+ export { positionTools, longPosition, shortPosition, forecast, projection, barsPattern, ghostFeed, positionStats, patternBars, ghostBars, projectionTarget, seeded, } from "./tools/position.js";
21
+ export type { PositionStats, PositionInputs } from "./tools/position.js";
22
+ export { measureTools, dateRange, priceRange, dateAndPriceRange } from "./tools/measure.js";
23
+ export { patternTools, xabcd, cypher, abcd, trianglePattern, threeDrives, headAndShoulders, elliottImpulse, elliottCorrection, elliottTriangle, elliottDoubleCombo, elliottTripleCombo, xabcdRatios, cypherRatios, abcdRatios, driveRatios, waveLabel, } from "./tools/patterns.js";
24
+ export { cycleTools, cyclicLines, timeCycles, sineLine, sineY } from "./tools/cycles.js";
25
+ export { volumeTools, anchoredVwapTool, volumeProfileTool, anchoredVwap, volumeProfile, startIndex } from "./tools/volume.js";
26
+ export { measure, fmtDuration, fmtTime } from "./tools/util.js";
@@ -0,0 +1,207 @@
1
+ import type { ChartPlugin, LayoutStore, PluginApi, PluginPaneView, PluginPointer } from "@alphacharts/core";
2
+ import { Emitter } from "./emitter.js";
3
+ import type { BarSource } from "./source.js";
4
+ import { TemplateStore } from "./templates.js";
5
+ import { type Anchor, type Drawing, type DrawingStyle, type DrawingsState, type ToolDef } from "./types.js";
6
+ export type MagnetMode = "off" | "weak" | "strong";
7
+ export interface DrawingsOptions {
8
+ tools: readonly ToolDef[];
9
+ /** Plugin id (key in layout JSON). Default "drawings". */
10
+ id?: string;
11
+ /** Bars of the main series: needed by bar-reading tools, bar counts and the magnet. */
12
+ source?: BarSource;
13
+ /** Current chart interval in ms (for per-interval visibility); default: the source's. */
14
+ interval?: number;
15
+ magnet?: MagnetMode;
16
+ /** Stay in the tool after a drawing is finished. */
17
+ continuous?: boolean;
18
+ /** Templates and favourites storage. */
19
+ store?: LayoutStore;
20
+ /** A tool failed to draw or a gesture produced an invalid drawing. Default: console.error. */
21
+ onError?: (error: Error, drawing: Drawing | null) => void;
22
+ }
23
+ export interface DrawingsEvents {
24
+ created: Drawing;
25
+ changed: Drawing;
26
+ removed: Drawing;
27
+ selected: string[];
28
+ tool: string | null;
29
+ history: {
30
+ canUndo: boolean;
31
+ canRedo: boolean;
32
+ };
33
+ }
34
+ export interface NewDrawing {
35
+ tool: string;
36
+ anchors?: Anchor[];
37
+ pane?: number;
38
+ id?: string;
39
+ style?: Partial<DrawingStyle>;
40
+ props?: Record<string, unknown>;
41
+ locked?: boolean;
42
+ hidden?: boolean;
43
+ intervals?: number[] | null;
44
+ }
45
+ export type DrawingPatch = Partial<Pick<Drawing, "anchors" | "locked" | "hidden" | "intervals">> & {
46
+ style?: Partial<DrawingStyle>;
47
+ props?: Record<string, unknown>;
48
+ };
49
+ /** Pixels the pointer must travel before a press-release counts as a drag. */
50
+ export declare const DRAG_SLOP = 4;
51
+ /** Hit tolerance in CSS px by pointer type. */
52
+ export declare const TOLERANCE: Record<string, number>;
53
+ /** Weak magnet radius in CSS px. */
54
+ export declare const WEAK_MAGNET_PX = 16;
55
+ /** Duplicate offsets a copy by this many bars in time (never in price). */
56
+ export declare const DUPLICATE_BARS = 5;
57
+ export declare class DrawingsPlugin implements ChartPlugin {
58
+ private readonly options;
59
+ readonly id: string;
60
+ readonly events: Emitter<DrawingsEvents>;
61
+ private loading;
62
+ /**
63
+ * True while `fromJSON` emits its `removed` / `created` events: they describe
64
+ * a layout being loaded, not something the user drew or deleted, so a listener
65
+ * that mirrors drawings elsewhere (a sync between charts) must not act on them.
66
+ */
67
+ get restoring(): boolean;
68
+ readonly templates: TemplateStore | null;
69
+ private api;
70
+ private readonly tools;
71
+ private readonly store;
72
+ private readonly history;
73
+ private readonly selected;
74
+ private hover;
75
+ private tool;
76
+ private creating;
77
+ private drag;
78
+ private clipboard;
79
+ private nextId;
80
+ private last;
81
+ private source;
82
+ private intervalMs;
83
+ private magnetMode;
84
+ private readonly continuous;
85
+ private readonly onError;
86
+ private readonly reported;
87
+ private measureCanvas;
88
+ constructor(options: DrawingsOptions);
89
+ install(api: PluginApi): void;
90
+ uninstall(): void;
91
+ dataChanged(): void;
92
+ viewChanged(): void;
93
+ toolDef(id: string): ToolDef;
94
+ toolIds(): string[];
95
+ setSource(source: BarSource | null): void;
96
+ /** Current chart interval in ms; drawings with `intervals` show only when it is listed. */
97
+ setInterval(ms: number | null): void;
98
+ setMagnet(mode: MagnetMode): void;
99
+ magnet(): MagnetMode;
100
+ list(): Drawing[];
101
+ get(id: string): Drawing | undefined;
102
+ selection(): string[];
103
+ activeTool(): string | null;
104
+ get canUndo(): boolean;
105
+ get canRedo(): boolean;
106
+ private newId;
107
+ private build;
108
+ /** Throws with context unless `d` is a valid drawing of a registered tool. */
109
+ validate(d: Drawing): void;
110
+ /** Create a drawing; returns a copy. Throws when invalid. */
111
+ add(spec: NewDrawing): Drawing;
112
+ /** Change a drawing (programmatic: locks do not apply). */
113
+ update(id: string, patch: DrawingPatch): Drawing;
114
+ private applyPatch;
115
+ /** Update several drawings as one undo step. */
116
+ updateMany(ids: readonly string[], patch: DrawingPatch): void;
117
+ remove(ids: readonly string[]): void;
118
+ clear(): void;
119
+ private exec;
120
+ private afterMutation;
121
+ undo(): boolean;
122
+ redo(): boolean;
123
+ private peekUndo;
124
+ private peekRedo;
125
+ select(ids: readonly string[]): void;
126
+ selectAll(): void;
127
+ setTool(id: string | null): void;
128
+ /** The anchor (time, price) under a pane pixel: for creating drawings from code at screen positions. */
129
+ anchorAt(pane: number, x: number, y: number): Anchor;
130
+ /** Pane pixel of an anchor. */
131
+ pixelOf(pane: number, a: Anchor): {
132
+ x: number;
133
+ y: number;
134
+ };
135
+ private reorder;
136
+ bringToFront(ids?: readonly string[]): void;
137
+ sendToBack(ids?: readonly string[]): void;
138
+ /** Move each selected drawing one step up past the nearest unselected one. */
139
+ bringForward(ids?: readonly string[]): void;
140
+ sendBackward(ids?: readonly string[]): void;
141
+ /** Copy the selection (or `ids`) to the plugin's clipboard; returns the copies. */
142
+ copy(ids?: readonly string[]): Drawing[];
143
+ /**
144
+ * Paste the clipboard as new drawings (one undo step) and select them. With
145
+ * `at`, the first copy's first anchor lands there and the others keep their
146
+ * offsets; without, the copies sit exactly on the originals.
147
+ */
148
+ paste(at?: {
149
+ time: number;
150
+ price: number;
151
+ }): Drawing[];
152
+ /** Copy + paste the selection shifted by DUPLICATE_BARS bars in time (price unchanged). */
153
+ duplicate(): Drawing[];
154
+ private barMs;
155
+ private pasteShifted;
156
+ /** Save a drawing's style as a named template for its tool. */
157
+ saveTemplate(id: string, name: string): Promise<void>;
158
+ /** Apply a saved template's style and props to drawings of that tool (one undo step). */
159
+ applyTemplate(ids: readonly string[], name: string): Promise<void>;
160
+ toJSON(): DrawingsState;
161
+ /** Throws what `fromJSON(state)` would, changing nothing (the core's `restoreState` calls it before it replaces anything). */
162
+ validateState(state: unknown): void;
163
+ private parseState;
164
+ fromJSON(state: unknown): void;
165
+ private render;
166
+ private report;
167
+ private measure;
168
+ private sourceInterval;
169
+ private ctxFor;
170
+ private visible;
171
+ private shapesOf;
172
+ private handlePoints;
173
+ private tolerance;
174
+ /**
175
+ * What is under a pane point: a handle of a selected drawing first (topmost
176
+ * selected wins), else the topmost visible drawing within `tol` px.
177
+ */
178
+ hitTest(pane: number, x: number, y: number, tol?: number): {
179
+ id: string;
180
+ handle: number | null;
181
+ } | null;
182
+ /** Snap a pointer position to the nearest bar's O/H/L/C according to the magnet mode. */
183
+ snap(e: Pick<PluginPointer, "pane" | "x" | "y" | "time" | "price">): Anchor;
184
+ drawPane(ctx: CanvasRenderingContext2D, view: PluginPaneView): void;
185
+ /** The drawing being created, with the rubber-band anchor filling the rest. */
186
+ private previewDrawing;
187
+ private constrainAll;
188
+ pointer(e: PluginPointer): boolean;
189
+ private onDown;
190
+ private beginCreate;
191
+ private onMove;
192
+ private dragMove;
193
+ private dragHandle;
194
+ private onUp;
195
+ private finishBox;
196
+ /** Select every visible drawing of a pane with a point inside the rectangle (CSS px). */
197
+ selectInRect(pane: number, x0: number, y0: number, x1: number, y1: number): string[];
198
+ private upCreate;
199
+ private onClick;
200
+ private onDouble;
201
+ private finishVariable;
202
+ cancelCreate(): void;
203
+ private commit;
204
+ cursor(pane: number, x: number, y: number): string | null;
205
+ key(e: KeyboardEvent): boolean;
206
+ private cancelDrag;
207
+ }
@@ -0,0 +1,25 @@
1
+ import type { Dash, DrawingStyle, Shape } from "./types.js";
2
+ export declare function dashPattern(d: Dash, w: number): number[];
3
+ /** `color` with its alpha replaced by `a` (0..1), as an rgba() string. */
4
+ export declare function withAlpha(color: string, a: number): string;
5
+ export declare function font(style: DrawingStyle, size?: number): string;
6
+ export interface TextBox {
7
+ x: number;
8
+ y: number;
9
+ w: number;
10
+ h: number;
11
+ }
12
+ /** Text box of a text shape; `measure` returns the text width in px. */
13
+ export declare function textBox(s: Extract<Shape, {
14
+ k: "text";
15
+ }>, style: DrawingStyle, measure: (text: string, font: string) => number): TextBox;
16
+ export declare function drawShapes(ctx: CanvasRenderingContext2D, shapes: readonly Shape[], style: DrawingStyle, W: number, H: number, opts?: {
17
+ widthBoost?: number;
18
+ }): void;
19
+ /**
20
+ * Distance 0 when (x, y) is inside a filled shape or a text box, else the
21
+ * distance to the nearest stroke; Infinity when the shape is not hittable.
22
+ */
23
+ export declare function shapeDistance(s: Shape, x: number, y: number, W: number, H: number, style: DrawingStyle, measure: (t: string, f: string) => number): number;
24
+ /** True when any outline vertex (or a text box corner) of the shape lies in the rectangle. */
25
+ export declare function shapeInRect(s: Shape, x0: number, y0: number, x1: number, y1: number, W: number, H: number): boolean;
@@ -0,0 +1,60 @@
1
+ export interface Bar {
2
+ time: number;
3
+ open: number;
4
+ high: number;
5
+ low: number;
6
+ close: number;
7
+ volume: number;
8
+ }
9
+ export interface BarSource {
10
+ /** Bumps on every mutation: caches key on it. */
11
+ readonly version: number;
12
+ readonly length: number;
13
+ /** Bar at array position i (0 = oldest). Throws when out of range. */
14
+ at(i: number): Bar;
15
+ /** Bar whose time is nearest to `time`, or undefined when empty. */
16
+ nearest(time: number): Bar | undefined;
17
+ /** Fractional position of `time` in the bar sequence: integer at a bar, linear between bars, extrapolated by the median interval outside. */
18
+ logical(time: number): number;
19
+ /** Inverse of logical(). */
20
+ timeAtLogical(l: number): number;
21
+ /** Index range [lo, hi) of bars with from <= time <= to. */
22
+ range(from: number, to: number): [number, number];
23
+ /** Median bar interval in ms. */
24
+ readonly interval: number;
25
+ }
26
+ export interface ColumnarBars {
27
+ time: ArrayLike<number>;
28
+ open: ArrayLike<number>;
29
+ high: ArrayLike<number>;
30
+ low: ArrayLike<number>;
31
+ close: ArrayLike<number>;
32
+ volume?: ArrayLike<number> | undefined;
33
+ }
34
+ export declare class ArrayBarSource implements BarSource {
35
+ private t;
36
+ private o;
37
+ private h;
38
+ private l;
39
+ private c;
40
+ private v;
41
+ private ver;
42
+ private cachedInterval;
43
+ constructor(data?: ColumnarBars);
44
+ get version(): number;
45
+ get length(): number;
46
+ setData(d: ColumnarBars): void;
47
+ /** Same time replaces the last bar; a later time appends. */
48
+ update(b: Bar): void;
49
+ /** Older history, all earlier than the first bar. */
50
+ prepend(d: ColumnarBars): void;
51
+ private touch;
52
+ at(i: number): Bar;
53
+ /** First index with time >= t. */
54
+ private lower;
55
+ nearest(time: number): Bar | undefined;
56
+ get interval(): number;
57
+ logical(time: number): number;
58
+ timeAtLogical(l: number): number;
59
+ range(from: number, to: number): [number, number];
60
+ }
@@ -0,0 +1,25 @@
1
+ import type { LayoutStore } from "@alphacharts/core";
2
+ import type { Drawing, DrawingStyle } from "./types.js";
3
+ export interface DrawingTemplate {
4
+ version: 1;
5
+ tool: string;
6
+ name: string;
7
+ style: DrawingStyle;
8
+ props: Record<string, unknown>;
9
+ }
10
+ export declare class TemplateStore {
11
+ private readonly store;
12
+ private readonly prefix;
13
+ constructor(store: LayoutStore, prefix?: string);
14
+ private key;
15
+ /** Save a drawing's style and props as a template for its tool. */
16
+ save(name: string, d: Drawing): Promise<void>;
17
+ load(tool: string, name: string): Promise<DrawingTemplate>;
18
+ list(tool?: string): Promise<Array<{
19
+ tool: string;
20
+ name: string;
21
+ }>>;
22
+ remove(tool: string, name: string): Promise<void>;
23
+ favourites(): Promise<string[]>;
24
+ setFavourite(tool: string, on: boolean): Promise<string[]>;
25
+ }
@@ -0,0 +1,2 @@
1
+ import type { ToolDef } from "../types.js";
2
+ export declare const allTools: readonly ToolDef[];
@@ -0,0 +1,16 @@
1
+ import type { ToolDef } from "../types.js";
2
+ export declare const textTool: ToolDef;
3
+ export declare const anchoredText: ToolDef;
4
+ export declare const note: ToolDef;
5
+ export declare const anchoredNote: ToolDef;
6
+ export declare const callout: ToolDef;
7
+ export declare const comment: ToolDef;
8
+ export declare const priceLabel: ToolDef;
9
+ export declare const priceNote: ToolDef;
10
+ export declare const signpost: ToolDef;
11
+ export declare const flagMark: ToolDef;
12
+ export declare const arrow: ToolDef;
13
+ export declare const arrowMarker: ToolDef;
14
+ export declare const arrowMarkUp: ToolDef;
15
+ export declare const arrowMarkDown: ToolDef;
16
+ export declare const annotationTools: ToolDef[];
@@ -0,0 +1,43 @@
1
+ import type { Pt } from "../geometry.js";
2
+ import type { BarSource } from "../source.js";
3
+ import type { ToolDef } from "../types.js";
4
+ export declare const parallelChannel: ToolDef;
5
+ export interface Regression {
6
+ slope: number;
7
+ intercept: number;
8
+ /** Population standard deviation of the residuals. */
9
+ sigma: number;
10
+ n: number;
11
+ }
12
+ /** Ordinary least squares of y on x = 0..n-1. */
13
+ export declare function regression(y: readonly number[]): Regression;
14
+ export declare function regressionOf(source: BarSource, t0: number, t1: number): {
15
+ reg: Regression;
16
+ lo: number;
17
+ hi: number;
18
+ };
19
+ export declare const regressionTrendChannel: ToolDef;
20
+ export declare const flatTopBottom: ToolDef;
21
+ export declare const disjointChannel: ToolDef;
22
+ export type ForkVariant = "standard" | "schiff" | "modifiedSchiff" | "inside";
23
+ /**
24
+ * Where the median line starts and the points the two outer tines pass
25
+ * through. The median always runs to the midpoint M of B and C; tines are
26
+ * parallel to it.
27
+ * - standard: from A; tines through B and C.
28
+ * - schiff: from (A.x, midpoint price of A and B).
29
+ * - modifiedSchiff: from the midpoint of A and B.
30
+ * - inside: from A; tines through the midpoints of A–B and A–C.
31
+ */
32
+ export declare function forkGeometry(v: ForkVariant, a: Pt, b: Pt, cc: Pt): {
33
+ origin: Pt;
34
+ m: Pt;
35
+ t1: Pt;
36
+ t2: Pt;
37
+ };
38
+ export declare const pitchfork: ToolDef;
39
+ export declare const schiffPitchfork: ToolDef;
40
+ export declare const modifiedSchiffPitchfork: ToolDef;
41
+ export declare const insidePitchfork: ToolDef;
42
+ export declare const pitchfan: ToolDef;
43
+ export declare const channelTools: ToolDef[];
@@ -0,0 +1,7 @@
1
+ import type { ToolDef } from "../types.js";
2
+ export declare const cyclicLines: ToolDef;
3
+ export declare const timeCycles: ToolDef;
4
+ /** y of the sine through two consecutive extrema (x0,y0) and (x1,y1) at x. */
5
+ export declare function sineY(x0: number, y0: number, x1: number, y1: number, x: number): number;
6
+ export declare const sineLine: ToolDef;
7
+ export declare const cycleTools: ToolDef[];
@@ -0,0 +1,22 @@
1
+ import type { Anchor, Drawing, ToolDef } from "../types.js";
2
+ import { FIB_BASIC, fillOf } from "./util.js";
3
+ /** Retracement: level 0 is a1, level 1 is a0. */
4
+ export declare const fibRetracementPrice: (a0: Anchor, a1: Anchor, r: number) => number;
5
+ /** Trend-based extension: level 0 is c, 1 projects the full a→b move from c. */
6
+ export declare const fibExtensionPrice: (a: Anchor, b: Anchor, c: Anchor, r: number) => number;
7
+ export declare const FIB_SEQUENCE: number[];
8
+ export declare const fibRetracement: ToolDef;
9
+ export declare const fibExtension: ToolDef;
10
+ export declare const fibChannel: ToolDef;
11
+ export declare const fibTimeZone: ToolDef;
12
+ export declare const FIB_FAN: number[];
13
+ export declare const fibSpeedFan: ToolDef;
14
+ export declare const fibTrendTime: ToolDef;
15
+ export declare const fibCircles: ToolDef;
16
+ export declare const fibSpiral: ToolDef;
17
+ export declare const FIB_ARCS: number[];
18
+ export declare const fibSpeedArcs: ToolDef;
19
+ export declare const fibWedge: ToolDef;
20
+ export declare const fibTools: ToolDef[];
21
+ export { FIB_BASIC, fillOf };
22
+ export type { Drawing };
@@ -0,0 +1,27 @@
1
+ import { type Pt } from "../geometry.js";
2
+ import type { ToolDef } from "../types.js";
3
+ import { A, needDistinctTimes, px } from "./util.js";
4
+ export declare const rectangle: ToolDef;
5
+ /** Corners of the rectangle with edge a→b and perpendicular extent through c. */
6
+ export declare function rotatedRectCorners(a: Pt, b: Pt, c: Pt): [Pt, Pt, Pt, Pt];
7
+ export declare const rotatedRectangle: ToolDef;
8
+ export declare const ellipse: ToolDef;
9
+ export declare const circle: ToolDef;
10
+ export declare const triangle: ToolDef;
11
+ /** Arc from a to b through m on their circumcircle: [cx, cy, r, from, to] in radians, or null when collinear. */
12
+ export declare function arcThrough(a: Pt, b: Pt, m: Pt): {
13
+ cx: number;
14
+ cy: number;
15
+ r: number;
16
+ a0: number;
17
+ a1: number;
18
+ } | null;
19
+ export declare const arc: ToolDef;
20
+ export declare const curve: ToolDef;
21
+ export declare const doubleCurve: ToolDef;
22
+ export declare const polyline: ToolDef;
23
+ export declare const path: ToolDef;
24
+ export declare const brush: ToolDef;
25
+ export declare const highlighter: ToolDef;
26
+ export declare const figureTools: ToolDef[];
27
+ export { A, needDistinctTimes, px };
@@ -0,0 +1,11 @@
1
+ import type { Anchor, ToolDef } from "../types.js";
2
+ /** Price at fraction r of the way from a0 to a1. */
3
+ export declare const gannBoxPrice: (a0: Anchor, a1: Anchor, r: number) => number;
4
+ /** Gann fan: the line through a0 whose slope is num/den times the 1×1 slope (a0→a1); its price at a1's time. */
5
+ export declare const gannFanPrice: (a0: Anchor, a1: Anchor, num: number, den: number) => number;
6
+ export declare const GANN_RATIOS: ReadonlyArray<readonly [number, number]>;
7
+ export declare const gannBox: ToolDef;
8
+ export declare const gannSquare: ToolDef;
9
+ export declare const gannSquareFixed: ToolDef;
10
+ export declare const gannFan: ToolDef;
11
+ export declare const gannTools: ToolDef[];
@@ -0,0 +1,12 @@
1
+ import type { ToolDef } from "../types.js";
2
+ import { needDistinctTimes } from "./util.js";
3
+ export declare const trendLine: ToolDef;
4
+ export declare const ray: ToolDef;
5
+ export declare const extendedLine: ToolDef;
6
+ export declare const infoLine: ToolDef;
7
+ export declare const horizontalLine: ToolDef;
8
+ export declare const horizontalRay: ToolDef;
9
+ export declare const verticalLine: ToolDef;
10
+ export declare const crossLine: ToolDef;
11
+ export declare const lineTools: ToolDef[];
12
+ export { needDistinctTimes };
@@ -0,0 +1,7 @@
1
+ import type { ToolDef } from "../types.js";
2
+ import { measureLines } from "./util.js";
3
+ export declare const dateRange: ToolDef;
4
+ export declare const priceRange: ToolDef;
5
+ export declare const dateAndPriceRange: ToolDef;
6
+ export declare const measureTools: ToolDef[];
7
+ export { measureLines };