@hoox-sh/pynets 0.1.0 → 0.2.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,181 @@
1
+ /**
2
+ * Copyright (C) 2024-2026 jango_blockchained
3
+ * SPDX-License-Identifier: AGPL-3.0-or-later
4
+ *
5
+ * Compile-path drawings. Wraps DrawingBook; extras go on `__drawings`.
6
+ */
7
+ import { DrawingBook, type DrawingEvent } from "../drawings.ts";
8
+ import { naNum } from "./helpers.ts";
9
+
10
+ function n(v: unknown, fallback = 0): number {
11
+ const x = naNum(v);
12
+ return x == null ? fallback : x;
13
+ }
14
+
15
+ function idOf(v: unknown): number {
16
+ return n(v, -1);
17
+ }
18
+
19
+ export class CompileDraw {
20
+ readonly book = new DrawingBook();
21
+
22
+ label_new(bar: unknown, text?: unknown): number {
23
+ return this.book.labelNew(n(bar, 0), text == null ? undefined : String(text));
24
+ }
25
+
26
+ line_new(bar: unknown): number {
27
+ return this.book.lineNew(n(bar, 0));
28
+ }
29
+
30
+ box_new(bar: unknown): number {
31
+ return this.book.boxNew(n(bar, 0));
32
+ }
33
+
34
+ table_new(bar: unknown): number {
35
+ return this.book.tableNew(n(bar, 0));
36
+ }
37
+
38
+ polyline_new(bar: unknown): number {
39
+ return this.book.polylineNew(n(bar, 0));
40
+ }
41
+
42
+ linefill_new(bar: unknown, extra?: unknown): number {
43
+ return this.book.linefillNew(n(bar, 0), extra as Record<string, unknown> | undefined);
44
+ }
45
+
46
+ label_set_text(id: unknown, text?: unknown): void {
47
+ this.book.labelSetText(idOf(id), text == null ? "" : String(text));
48
+ }
49
+
50
+ label_set_xy(id: unknown, x?: unknown, y?: unknown): void {
51
+ this.book.labelSetXy(idOf(id), n(x, 0), n(y, 0));
52
+ }
53
+
54
+ label_delete(id: unknown): void {
55
+ this.book.labelDelete(idOf(id));
56
+ }
57
+
58
+ line_set_xy(id: unknown, x1?: unknown, y1?: unknown, x2?: unknown, y2?: unknown): void {
59
+ this.book.lineSetXy(idOf(id), n(x1, 0), n(y1, 0), n(x2, 0), n(y2, 0));
60
+ }
61
+
62
+ line_delete(id: unknown): void {
63
+ this.book.lineDelete(idOf(id));
64
+ }
65
+
66
+ line_set_xy1(id: unknown, x1?: unknown, y1?: unknown): void {
67
+ this.book.lineSetXy1(idOf(id), n(x1, 0), n(y1, 0));
68
+ }
69
+
70
+ line_set_xy2(id: unknown, x2?: unknown, y2?: unknown): void {
71
+ this.book.lineSetXy2(idOf(id), n(x2, 0), n(y2, 0));
72
+ }
73
+
74
+ line_set_color(id: unknown, color?: unknown): void {
75
+ this.book.lineSetColor(idOf(id), color);
76
+ }
77
+
78
+ line_set_width(id: unknown, width?: unknown): void {
79
+ this.book.lineSetWidth(idOf(id), width);
80
+ }
81
+
82
+ line_set_style(id: unknown, style?: unknown): void {
83
+ this.book.lineSetStyle(idOf(id), style);
84
+ }
85
+
86
+ line_set_extend(id: unknown, extend?: unknown): void {
87
+ this.book.lineSetExtend(idOf(id), extend);
88
+ }
89
+
90
+ line_get_price(id: unknown, x?: unknown): number | null {
91
+ return this.book.lineGetPrice(idOf(id), x);
92
+ }
93
+
94
+ label_set_color(id: unknown, color?: unknown): void {
95
+ this.book.labelSetColor(idOf(id), color);
96
+ }
97
+
98
+ label_set_style(id: unknown, style?: unknown): void {
99
+ this.book.labelSetStyle(idOf(id), style);
100
+ }
101
+
102
+ label_set_size(id: unknown, size?: unknown): void {
103
+ this.book.labelSetSize(idOf(id), size);
104
+ }
105
+
106
+ label_set_textalign(id: unknown, textalign?: unknown): void {
107
+ this.book.labelSetTextalign(idOf(id), textalign);
108
+ }
109
+
110
+ label_set_tooltip(id: unknown, tooltip?: unknown): void {
111
+ this.book.labelSetTooltip(idOf(id), tooltip);
112
+ }
113
+
114
+ label_get_x(id: unknown): number | null {
115
+ return this.book.labelGetX(idOf(id));
116
+ }
117
+
118
+ label_get_y(id: unknown): number | null {
119
+ return this.book.labelGetY(idOf(id));
120
+ }
121
+
122
+ label_get_text(id: unknown): string | null {
123
+ return this.book.labelGetText(idOf(id));
124
+ }
125
+
126
+ box_delete(id: unknown): void {
127
+ this.book.boxDelete(idOf(id));
128
+ }
129
+
130
+ box_set(id: unknown, extra?: unknown): void {
131
+ this.book.boxSet(idOf(id), extra as Record<string, unknown> | undefined);
132
+ }
133
+
134
+ box_set_corners(id: unknown, left?: unknown, top?: unknown, right?: unknown, bottom?: unknown): void {
135
+ this.book.boxSetCorners(idOf(id), n(left, 0), n(top, 0), n(right, 0), n(bottom, 0));
136
+ }
137
+
138
+ box_set_bgcolor(id: unknown, bgcolor?: unknown): void {
139
+ this.book.boxSetBgcolor(idOf(id), bgcolor);
140
+ }
141
+
142
+ box_set_border_color(id: unknown, color?: unknown): void {
143
+ this.book.boxSetBorderColor(idOf(id), color);
144
+ }
145
+
146
+ box_set_text(id: unknown, text?: unknown): void {
147
+ this.book.boxSetText(idOf(id), text);
148
+ }
149
+
150
+ box_set_extend(id: unknown, extend?: unknown): void {
151
+ this.book.boxSetExtend(idOf(id), extend);
152
+ }
153
+
154
+ table_cell(id: unknown, column?: unknown, row?: unknown, text?: unknown): void {
155
+ this.book.tableCell(idOf(id), column, row, text);
156
+ }
157
+
158
+ table_cell_set_text(id: unknown, column?: unknown, row?: unknown, text?: unknown): void {
159
+ this.book.tableCellSetText(idOf(id), column, row, text);
160
+ }
161
+
162
+ table_set_position(id: unknown, position?: unknown): void {
163
+ this.book.tableSetPosition(idOf(id), position);
164
+ }
165
+
166
+ linefill_set_color(id: unknown, color?: unknown): void {
167
+ this.book.linefillSetColor(idOf(id), color);
168
+ }
169
+
170
+ alert(bar: unknown, message?: unknown): void {
171
+ this.book.alert(n(bar, 0), message == null ? "" : String(message));
172
+ }
173
+
174
+ extras(): { __drawings: DrawingEvent[] } {
175
+ return { __drawings: this.book.items.slice() };
176
+ }
177
+ }
178
+
179
+ export function createCompileDraw(): CompileDraw {
180
+ return new CompileDraw();
181
+ }