@elicdavis/node-flow 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.
- package/.github/workflows/deploy.yml +57 -0
- package/README.md +159 -0
- package/dev.tsconfig.json +18 -0
- package/docs/promotional-image.png +0 -0
- package/esbuild.ts +32 -0
- package/index.html +311 -0
- package/package.json +50 -0
- package/src/camera.ts +30 -0
- package/src/connection.ts +249 -0
- package/src/contextMenu.ts +367 -0
- package/src/draggable.ts +13 -0
- package/src/elements/base.ts +192 -0
- package/src/elements/container.ts +119 -0
- package/src/elements/interfaces.ts +50 -0
- package/src/elements/text.ts +86 -0
- package/src/graph.ts +535 -0
- package/src/graphSubsystem.ts +31 -0
- package/src/index.ts +28 -0
- package/src/input.ts +153 -0
- package/src/markdown/entry.ts +323 -0
- package/src/markdown/lexicalParser.ts +148 -0
- package/src/markdown/markdown.ts +14 -0
- package/src/markdown/syntaxParser.ts +344 -0
- package/src/markdown/token.ts +43 -0
- package/src/metadata.ts +3 -0
- package/src/node.ts +1130 -0
- package/src/nodes/factory.ts +87 -0
- package/src/nodes/publisher.ts +98 -0
- package/src/nodes/subsystem.ts +760 -0
- package/src/notes/note.ts +295 -0
- package/src/notes/subsystem.ts +262 -0
- package/src/organize.ts +181 -0
- package/src/pass/subsystem.ts +64 -0
- package/src/performance.ts +9 -0
- package/src/popup.ts +81 -0
- package/src/popups/form.ts +63 -0
- package/src/popups/string.ts +33 -0
- package/src/port.ts +223 -0
- package/src/quickMenu.ts +330 -0
- package/src/styles/box.ts +104 -0
- package/src/styles/canvasTextAlign.ts +8 -0
- package/src/styles/canvasTextBaseline.ts +9 -0
- package/src/styles/cursor.ts +18 -0
- package/src/styles/stroke.ts +39 -0
- package/src/styles/text.ts +90 -0
- package/src/styles/textBox.ts +82 -0
- package/src/theme.ts +78 -0
- package/src/types/box.ts +126 -0
- package/src/types/list.ts +41 -0
- package/src/types/pool.ts +66 -0
- package/src/types/text.ts +136 -0
- package/src/types/vector2.ts +34 -0
- package/src/utils/color.ts +136 -0
- package/src/utils/html.ts +21 -0
- package/src/utils/math.ts +8 -0
- package/src/utils/string.ts +98 -0
- package/src/widgets/button.ts +107 -0
- package/src/widgets/color.ts +151 -0
- package/src/widgets/factory.ts +46 -0
- package/src/widgets/image.ts +163 -0
- package/src/widgets/number.ts +153 -0
- package/src/widgets/slider.ts +216 -0
- package/src/widgets/string.ts +128 -0
- package/src/widgets/text.ts +92 -0
- package/src/widgets/toggle.ts +205 -0
- package/src/widgets/widget.ts +12 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Theme } from "../theme";
|
|
2
|
+
import { Box, InBox } from "../types/box";
|
|
3
|
+
import { CopyVector2, Vector2 } from "../types/vector2";
|
|
4
|
+
import { height, width } from "./widget";
|
|
5
|
+
import { TextBoxStyle, TextBoxStyleConfig, TextBoxStyleWithFallback } from "../styles/textBox";
|
|
6
|
+
import { FlowNode } from "../node";
|
|
7
|
+
|
|
8
|
+
export interface ToggleStyleConfig {
|
|
9
|
+
idle?: TextBoxStyleConfig,
|
|
10
|
+
hover?: TextBoxStyleConfig,
|
|
11
|
+
lightColor?: string;
|
|
12
|
+
lightBorderColor?: string;
|
|
13
|
+
lightBlur?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ToggleWidgetConfig {
|
|
17
|
+
property?: string;
|
|
18
|
+
value?: boolean;
|
|
19
|
+
text?: string;
|
|
20
|
+
callback?: () => void;
|
|
21
|
+
enabledStyle?: ToggleStyleConfig;
|
|
22
|
+
disabledStyle?: ToggleStyleConfig;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class ToggleStyle {
|
|
26
|
+
|
|
27
|
+
#idleStyle: TextBoxStyle;
|
|
28
|
+
|
|
29
|
+
#hoverStyle: TextBoxStyle;
|
|
30
|
+
|
|
31
|
+
#lightColor: string;
|
|
32
|
+
|
|
33
|
+
#lightBorderColor: string;
|
|
34
|
+
|
|
35
|
+
#lightBlur?: number;
|
|
36
|
+
|
|
37
|
+
#box: Box;
|
|
38
|
+
|
|
39
|
+
constructor(config?: ToggleStyleConfig) {
|
|
40
|
+
this.#idleStyle = new TextBoxStyle(TextBoxStyleWithFallback(config?.idle, {
|
|
41
|
+
box: {
|
|
42
|
+
color: Theme.Widget.BackgroundColor,
|
|
43
|
+
border: {
|
|
44
|
+
size: Theme.Widget.Border.Size,
|
|
45
|
+
color: Theme.Widget.Border.Color,
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
text: { color: Theme.Widget.FontColor },
|
|
49
|
+
}));
|
|
50
|
+
this.#hoverStyle = new TextBoxStyle(TextBoxStyleWithFallback(config?.hover, {
|
|
51
|
+
box: {
|
|
52
|
+
color: Theme.Widget.Hover.BackgroundColor,
|
|
53
|
+
border: {
|
|
54
|
+
size: Theme.Widget.Border.Size,
|
|
55
|
+
color: Theme.Widget.Border.Color,
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
text: { color: Theme.Widget.FontColor },
|
|
59
|
+
}));
|
|
60
|
+
this.#lightColor = config?.lightColor === undefined ? "#222222" : config.lightColor;
|
|
61
|
+
this.#lightBorderColor = config?.lightBorderColor === undefined ? "black" : config.lightBorderColor;
|
|
62
|
+
this.#lightBlur = config?.lightBlur;
|
|
63
|
+
|
|
64
|
+
this.#box = {Position: { x: 0, y: 0 }, Size: { x: 0, y: 0 } };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Draw(ctx: CanvasRenderingContext2D, pos: Vector2, scale: number, text: string, mousePosition: Vector2 | undefined): Box {
|
|
68
|
+
const scaledWidth = width * scale;
|
|
69
|
+
const scaledHeight = height * scale;
|
|
70
|
+
this.#box.Size.x = scaledWidth;
|
|
71
|
+
this.#box.Size.y = scaledHeight;
|
|
72
|
+
CopyVector2(this.#box.Position, pos);
|
|
73
|
+
|
|
74
|
+
// Background
|
|
75
|
+
let style: TextBoxStyle = this.#idleStyle;
|
|
76
|
+
if (mousePosition !== undefined) {
|
|
77
|
+
if (InBox(this.#box, mousePosition)) {
|
|
78
|
+
style = this.#hoverStyle;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
style.Draw(ctx, this.#box, scale, text);
|
|
82
|
+
|
|
83
|
+
// Light
|
|
84
|
+
const lightScale = Math.min(scaledWidth, scaledHeight);
|
|
85
|
+
ctx.strokeStyle = this.#lightBorderColor;
|
|
86
|
+
ctx.fillStyle = this.#lightColor
|
|
87
|
+
ctx.beginPath();
|
|
88
|
+
ctx.roundRect(
|
|
89
|
+
pos.x + (lightScale * .2),
|
|
90
|
+
pos.y + (lightScale * .2),
|
|
91
|
+
lightScale * .6,
|
|
92
|
+
lightScale * .6,
|
|
93
|
+
Theme.Widget.Border.Radius * scale
|
|
94
|
+
);
|
|
95
|
+
if (this.#lightBlur) {
|
|
96
|
+
ctx.shadowBlur = this.#lightBlur * scale;
|
|
97
|
+
ctx.shadowColor = this.#lightColor;
|
|
98
|
+
}
|
|
99
|
+
ctx.fill();
|
|
100
|
+
if (this.#lightBlur) {
|
|
101
|
+
ctx.shadowBlur = 0;
|
|
102
|
+
}
|
|
103
|
+
// ctx.stroke();
|
|
104
|
+
|
|
105
|
+
return this.#box
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export class ToggleWidget {
|
|
110
|
+
|
|
111
|
+
#node: FlowNode;
|
|
112
|
+
|
|
113
|
+
#nodeProperty: string | undefined;
|
|
114
|
+
|
|
115
|
+
#value: boolean;
|
|
116
|
+
|
|
117
|
+
#text: string;
|
|
118
|
+
|
|
119
|
+
#enabledStyle: ToggleStyle;
|
|
120
|
+
|
|
121
|
+
#disabledStyle: ToggleStyle;
|
|
122
|
+
|
|
123
|
+
#callback?: (value: boolean) => void;
|
|
124
|
+
|
|
125
|
+
constructor(node: FlowNode, config?: ToggleWidgetConfig) {
|
|
126
|
+
this.#value = false;
|
|
127
|
+
|
|
128
|
+
this.#node = node;
|
|
129
|
+
this.#nodeProperty = config?.property;
|
|
130
|
+
this.#text = config?.text === undefined ? "Toggle" : config?.text;
|
|
131
|
+
|
|
132
|
+
this.#enabledStyle = new ToggleStyle({
|
|
133
|
+
idle: TextBoxStyleWithFallback(config?.enabledStyle?.idle, {
|
|
134
|
+
box: {
|
|
135
|
+
color: Theme.Widget.BackgroundColor,
|
|
136
|
+
border: {
|
|
137
|
+
size: Theme.Widget.Border.Size,
|
|
138
|
+
color: Theme.Widget.Border.Color,
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
text: { color: Theme.Widget.FontColor },
|
|
142
|
+
}),
|
|
143
|
+
lightBorderColor: config?.enabledStyle?.lightBorderColor,
|
|
144
|
+
lightColor: config?.enabledStyle?.lightColor === undefined ? "#00FF00" : config?.enabledStyle?.lightColor,
|
|
145
|
+
lightBlur: config?.enabledStyle?.lightBlur === undefined ? 15 : config?.enabledStyle?.lightBlur
|
|
146
|
+
});
|
|
147
|
+
this.#disabledStyle = new ToggleStyle({
|
|
148
|
+
idle: TextBoxStyleWithFallback(config?.disabledStyle?.idle, {
|
|
149
|
+
box: {
|
|
150
|
+
color: Theme.Widget.BackgroundColor,
|
|
151
|
+
border: {
|
|
152
|
+
size: Theme.Widget.Border.Size,
|
|
153
|
+
color: Theme.Widget.Border.Color,
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
text: { color: Theme.Widget.FontColor },
|
|
157
|
+
}),
|
|
158
|
+
lightBorderColor: config?.disabledStyle?.lightBorderColor,
|
|
159
|
+
lightColor: config?.disabledStyle?.lightColor === undefined ? "#004400" : config?.enabledStyle?.lightColor,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
this.Set(config?.value === undefined ? false : config?.value);
|
|
163
|
+
this.#callback = config?.callback;
|
|
164
|
+
if (this.#nodeProperty !== undefined) {
|
|
165
|
+
this.#node.addPropertyChangeListener(this.#nodeProperty, (oldVal, newVal) => {
|
|
166
|
+
this.Set(newVal);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
Size(): Vector2 {
|
|
172
|
+
return { "x": width, "y": height }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Draw(ctx: CanvasRenderingContext2D, position: Vector2, scale: number, mousePosition: Vector2 | undefined): Box {
|
|
176
|
+
let style = this.#value ? this.#enabledStyle : this.#disabledStyle;
|
|
177
|
+
return style.Draw(ctx, position, scale, this.#text, mousePosition);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
Toggle(): void {
|
|
181
|
+
this.Set(!this.#value);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
Set(value: boolean): void {
|
|
185
|
+
if (this.#value === value) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.#value = value;
|
|
189
|
+
|
|
190
|
+
if (this.#nodeProperty !== undefined) {
|
|
191
|
+
this.#node.setProperty(this.#nodeProperty, this.#value);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.#callback !== undefined) {
|
|
195
|
+
this.#callback(this.#value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
ClickStart(): void {
|
|
200
|
+
this.Toggle();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
ClickEnd(): void {
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Box } from '../types/box';
|
|
2
|
+
import { Vector2 } from '../types/vector2';
|
|
3
|
+
|
|
4
|
+
export const width = 150;
|
|
5
|
+
export const height = 25;
|
|
6
|
+
|
|
7
|
+
export interface Widget {
|
|
8
|
+
Size(): Vector2
|
|
9
|
+
Draw(ctx: CanvasRenderingContext2D, position: Vector2, scale: number, mousePosition: Vector2 | undefined): Box
|
|
10
|
+
ClickStart(): void
|
|
11
|
+
ClickEnd(): void
|
|
12
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true, // Generate .d.ts declaration files
|
|
4
|
+
"sourceMap": true, // Generate source maps (optional)
|
|
5
|
+
"strict": true, // Enable strict type checking (optional)
|
|
6
|
+
"outDir": "./dist/js",
|
|
7
|
+
"target": "ES2015",
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"src/**/*.ts"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"node_modules"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: ["src/index.ts"],
|
|
5
|
+
format: ["cjs", "esm"], // Build for commonJS and ESmodules
|
|
6
|
+
dts: true, // Generate declaration file (.d.ts)
|
|
7
|
+
// splitting: false,
|
|
8
|
+
sourcemap: true,
|
|
9
|
+
clean: true,
|
|
10
|
+
});
|