@kabel-project/kabel 1.0.7 → 1.0.8

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.
Files changed (273) hide show
  1. package/dist/comment-renderer/renderer.d.ts +32 -0
  2. package/dist/comment-renderer/renderer.d.ts.map +1 -0
  3. package/dist/controllers/base.d.ts +39 -0
  4. package/dist/controllers/base.d.ts.map +1 -0
  5. package/dist/controllers/wasd.d.ts +33 -0
  6. package/dist/controllers/wasd.d.ts.map +1 -0
  7. package/dist/events/comment-drag-handle.d.ts +2 -0
  8. package/dist/events/comment-drag-handle.d.ts.map +1 -0
  9. package/dist/events/comment-input.d.ts +4 -0
  10. package/dist/events/comment-input.d.ts.map +1 -0
  11. package/dist/events/connection-line.d.ts +2 -0
  12. package/dist/events/connection-line.d.ts.map +1 -0
  13. package/dist/events/connector.d.ts +2 -0
  14. package/dist/events/connector.d.ts.map +1 -0
  15. package/dist/events/draggable.d.ts +2 -0
  16. package/dist/events/draggable.d.ts.map +1 -0
  17. package/{events/events.ts → dist/events/events.d.ts} +8 -7
  18. package/dist/events/events.d.ts.map +1 -0
  19. package/dist/events/input-box.d.ts +2 -0
  20. package/dist/events/input-box.d.ts.map +1 -0
  21. package/dist/events/node-x-btn.d.ts +2 -0
  22. package/dist/events/node-x-btn.d.ts.map +1 -0
  23. package/dist/kabel.js +2 -0
  24. package/dist/kabel.js.map +1 -0
  25. package/dist/renderers/apollo/apollo.d.ts +12 -0
  26. package/dist/renderers/apollo/apollo.d.ts.map +1 -0
  27. package/dist/renderers/apollo/constants.d.ts +21 -0
  28. package/dist/renderers/apollo/constants.d.ts.map +1 -0
  29. package/dist/renderers/apollo/renderer.d.ts +97 -0
  30. package/dist/renderers/apollo/renderer.d.ts.map +1 -0
  31. package/{renderers/atlas/atlas.ts → dist/renderers/atlas/atlas.d.ts} +6 -15
  32. package/dist/renderers/atlas/atlas.d.ts.map +1 -0
  33. package/dist/renderers/constants.d.ts +51 -0
  34. package/dist/renderers/constants.d.ts.map +1 -0
  35. package/dist/renderers/renderer.d.ts +470 -0
  36. package/dist/renderers/renderer.d.ts.map +1 -0
  37. package/dist/renderers/representer-node.d.ts +27 -0
  38. package/dist/renderers/representer-node.d.ts.map +1 -0
  39. package/dist/renderers/representer.d.ts +13 -0
  40. package/dist/renderers/representer.d.ts.map +1 -0
  41. package/dist/src/category.d.ts +48 -0
  42. package/dist/src/category.d.ts.map +1 -0
  43. package/{src/colors.ts → dist/src/colors.d.ts} +21 -20
  44. package/dist/src/colors.d.ts.map +1 -0
  45. package/dist/src/comment.d.ts +88 -0
  46. package/dist/src/comment.d.ts.map +1 -0
  47. package/dist/src/connection.d.ts +52 -0
  48. package/dist/src/connection.d.ts.map +1 -0
  49. package/dist/src/context-menu.d.ts +76 -0
  50. package/dist/src/context-menu.d.ts.map +1 -0
  51. package/dist/src/coordinates.d.ts +52 -0
  52. package/dist/src/coordinates.d.ts.map +1 -0
  53. package/dist/src/core.d.ts +153 -0
  54. package/dist/src/core.d.ts.map +1 -0
  55. package/dist/src/ctx-menu-registry.d.ts +22 -0
  56. package/dist/src/ctx-menu-registry.d.ts.map +1 -0
  57. package/dist/src/dropdown-menu.d.ts +87 -0
  58. package/dist/src/dropdown-menu.d.ts.map +1 -0
  59. package/dist/src/field.d.ts +305 -0
  60. package/dist/src/field.d.ts.map +1 -0
  61. package/dist/src/flyout.d.ts +41 -0
  62. package/dist/src/flyout.d.ts.map +1 -0
  63. package/dist/src/fonts-manager.d.ts +6 -0
  64. package/dist/src/fonts-manager.d.ts.map +1 -0
  65. package/dist/src/grid.d.ts +60 -0
  66. package/dist/src/grid.d.ts.map +1 -0
  67. package/dist/src/headless-node.d.ts +11 -0
  68. package/dist/src/headless-node.d.ts.map +1 -0
  69. package/dist/src/index.d.ts +38 -0
  70. package/dist/src/index.d.ts.map +1 -0
  71. package/dist/src/inject-headless.d.ts +4 -0
  72. package/dist/src/inject-headless.d.ts.map +1 -0
  73. package/{src/inject.ts → dist/src/inject.d.ts} +142 -213
  74. package/dist/src/inject.d.ts.map +1 -0
  75. package/{src/main-workspace.ts → dist/src/main-workspace.d.ts} +31 -51
  76. package/dist/src/main-workspace.d.ts.map +1 -0
  77. package/dist/src/mutator.d.ts +2 -0
  78. package/dist/src/mutator.d.ts.map +1 -0
  79. package/{src/node-types.ts → dist/src/node-types.d.ts} +26 -27
  80. package/dist/src/node-types.d.ts.map +1 -0
  81. package/dist/src/nodesvg.d.ts +266 -0
  82. package/dist/src/nodesvg.d.ts.map +1 -0
  83. package/{src/prototypes.ts → dist/src/prototypes.d.ts} +10 -9
  84. package/dist/src/prototypes.d.ts.map +1 -0
  85. package/{src/renderer-map.ts → dist/src/renderer-map.d.ts} +51 -86
  86. package/dist/src/renderer-map.d.ts.map +1 -0
  87. package/dist/src/toolbox.d.ts +51 -0
  88. package/dist/src/toolbox.d.ts.map +1 -0
  89. package/{src/types.ts → dist/src/types.d.ts} +159 -205
  90. package/dist/src/types.d.ts.map +1 -0
  91. package/dist/src/undo-redo.d.ts +15 -0
  92. package/dist/src/undo-redo.d.ts.map +1 -0
  93. package/{src/visual-types.ts → dist/src/visual-types.d.ts} +34 -29
  94. package/dist/src/visual-types.d.ts.map +1 -0
  95. package/dist/src/widget-prototypes.d.ts +10 -0
  96. package/dist/src/widget-prototypes.d.ts.map +1 -0
  97. package/dist/src/widget.d.ts +62 -0
  98. package/dist/src/widget.d.ts.map +1 -0
  99. package/{src/workspace-coords.ts → dist/src/workspace-coords.d.ts} +10 -14
  100. package/dist/src/workspace-coords.d.ts.map +1 -0
  101. package/dist/src/workspace-svg.d.ts +371 -0
  102. package/dist/src/workspace-svg.d.ts.map +1 -0
  103. package/dist/src/workspace.d.ts +50 -0
  104. package/dist/src/workspace.d.ts.map +1 -0
  105. package/dist/themes/dark.d.ts +4 -0
  106. package/dist/themes/dark.d.ts.map +1 -0
  107. package/dist/themes/default.d.ts +4 -0
  108. package/dist/themes/default.d.ts.map +1 -0
  109. package/dist/themes/themes.d.ts +6 -0
  110. package/dist/themes/themes.d.ts.map +1 -0
  111. package/dist/util/emitter.d.ts +10 -0
  112. package/dist/util/emitter.d.ts.map +1 -0
  113. package/dist/util/env.d.ts +7 -0
  114. package/dist/util/env.d.ts.map +1 -0
  115. package/{util/escape-html.ts → dist/util/escape-html.d.ts} +16 -22
  116. package/dist/util/escape-html.d.ts.map +1 -0
  117. package/dist/util/eventer.d.ts +29 -0
  118. package/dist/util/eventer.d.ts.map +1 -0
  119. package/dist/util/has-prop.d.ts +2 -0
  120. package/dist/util/has-prop.d.ts.map +1 -0
  121. package/dist/util/parse-color.d.ts +6 -0
  122. package/dist/util/parse-color.d.ts.map +1 -0
  123. package/dist/util/path.d.ts +25 -0
  124. package/dist/util/path.d.ts.map +1 -0
  125. package/dist/util/styler.d.ts +12 -0
  126. package/dist/util/styler.d.ts.map +1 -0
  127. package/dist/util/uid.d.ts +42 -0
  128. package/dist/util/uid.d.ts.map +1 -0
  129. package/{util/unescape-html.ts → dist/util/unescape-html.d.ts} +16 -22
  130. package/dist/util/unescape-html.d.ts.map +1 -0
  131. package/dist/util/user-state.d.ts +37 -0
  132. package/dist/util/user-state.d.ts.map +1 -0
  133. package/{util/wait-anim-frames.ts → dist/util/wait-anim-frames.d.ts} +11 -24
  134. package/dist/util/wait-anim-frames.d.ts.map +1 -0
  135. package/dist/util/window-listeners.d.ts +8 -0
  136. package/dist/util/window-listeners.d.ts.map +1 -0
  137. package/package.json +4 -1
  138. package/(1.0.7)kabel.md +0 -18
  139. package/_READ_ME_MEDIA_/documentation/docs.md +0 -293
  140. package/_READ_ME_MEDIA_/workspace.png +0 -0
  141. package/comment-renderer/renderer.ts +0 -228
  142. package/controllers/base.ts +0 -186
  143. package/controllers/wasd.ts +0 -132
  144. package/docs/README.md +0 -98
  145. package/docs/_media/docs.md +0 -289
  146. package/docs/_media/workspace.png +0 -0
  147. package/docs/classes/CommentModel.md +0 -271
  148. package/docs/classes/CommentRenderer.md +0 -457
  149. package/docs/classes/ConnectableField.md +0 -597
  150. package/docs/classes/Connection.md +0 -191
  151. package/docs/classes/ContextMenuHTML.md +0 -163
  152. package/docs/classes/Coordinates.md +0 -187
  153. package/docs/classes/DropdownContainer.md +0 -300
  154. package/docs/classes/DummyField.md +0 -393
  155. package/docs/classes/Eventer.md +0 -185
  156. package/docs/classes/Field.md +0 -461
  157. package/docs/classes/InjectMsg.md +0 -85
  158. package/docs/classes/NodeSvg.md +0 -1011
  159. package/docs/classes/NumberField.md +0 -559
  160. package/docs/classes/OptConnectField.md +0 -624
  161. package/docs/classes/Renderer.md +0 -1636
  162. package/docs/classes/RendererConstants.md +0 -343
  163. package/docs/classes/Representer.md +0 -95
  164. package/docs/classes/RepresenterNode.md +0 -175
  165. package/docs/classes/TextField.md +0 -559
  166. package/docs/classes/Toolbox.md +0 -172
  167. package/docs/classes/WASDController.md +0 -616
  168. package/docs/classes/Widget.md +0 -195
  169. package/docs/classes/WorkspaceController.md +0 -385
  170. package/docs/classes/WorkspaceCoords.md +0 -218
  171. package/docs/classes/WorkspaceSvg.md +0 -1380
  172. package/docs/functions/clearMainWorkspace.md +0 -20
  173. package/docs/functions/getMainWorkspace.md +0 -19
  174. package/docs/functions/inject.md +0 -35
  175. package/docs/functions/setMainWorkspace.md +0 -28
  176. package/docs/globals.md +0 -95
  177. package/docs/interfaces/ColorStyle.md +0 -43
  178. package/docs/interfaces/ConnectorToFrom.md +0 -57
  179. package/docs/interfaces/DrawState.md +0 -81
  180. package/docs/interfaces/FieldConnectionData.md +0 -25
  181. package/docs/interfaces/FieldOptions.md +0 -63
  182. package/docs/interfaces/FieldRawBoxData.md +0 -25
  183. package/docs/interfaces/FieldVisualInfo.md +0 -65
  184. package/docs/interfaces/GridOptions.md +0 -61
  185. package/docs/interfaces/InjectOptions.md +0 -133
  186. package/docs/interfaces/InputFieldJson.md +0 -50
  187. package/docs/interfaces/KabelCommentRendering.md +0 -31
  188. package/docs/interfaces/KabelInterface.md +0 -469
  189. package/docs/interfaces/KabelNodeRendering.md +0 -77
  190. package/docs/interfaces/KabelUIX.md +0 -105
  191. package/docs/interfaces/KabelUtils.md +0 -215
  192. package/docs/interfaces/NodeEvents.md +0 -42
  193. package/docs/interfaces/NodeJson.md +0 -104
  194. package/docs/interfaces/NodePrototype.md +0 -82
  195. package/docs/interfaces/RegisteredEl.md +0 -53
  196. package/docs/interfaces/SerializedNode.md +0 -128
  197. package/docs/interfaces/TblxCategoryStruct.md +0 -41
  198. package/docs/interfaces/TblxFieldStruct.md +0 -28
  199. package/docs/interfaces/TblxNodeStruct.md +0 -35
  200. package/docs/interfaces/WidgetOptions.md +0 -115
  201. package/docs/interfaces/WidgetPrototypeList.md +0 -15
  202. package/docs/type-aliases/AnyField.md +0 -13
  203. package/docs/type-aliases/AnyFieldCls.md +0 -13
  204. package/docs/type-aliases/Color.md +0 -13
  205. package/docs/type-aliases/Connectable.md +0 -13
  206. package/docs/type-aliases/EventArgs.md +0 -11
  207. package/docs/type-aliases/EventSetupFn.md +0 -25
  208. package/docs/type-aliases/Hex.md +0 -13
  209. package/docs/type-aliases/RGBObject.md +0 -37
  210. package/docs/type-aliases/RGBString.md +0 -13
  211. package/docs/type-aliases/RGBTuple.md +0 -13
  212. package/docs/type-aliases/TblxObjStruct.md +0 -52
  213. package/docs/variables/CategoryColors.md +0 -29
  214. package/docs/variables/FieldMap.md +0 -41
  215. package/docs/variables/NodePrototypes.md +0 -18
  216. package/docs/variables/default.md +0 -11
  217. package/events/comment-drag-handle.ts +0 -61
  218. package/events/comment-input.ts +0 -291
  219. package/events/connection-line.ts +0 -68
  220. package/events/connector.ts +0 -116
  221. package/events/draggable.ts +0 -119
  222. package/events/input-box.ts +0 -213
  223. package/events/node-x-btn.ts +0 -25
  224. package/index.d.ts +0 -4
  225. package/renderers/apollo/apollo.ts +0 -21
  226. package/renderers/apollo/constants.ts +0 -40
  227. package/renderers/apollo/renderer.ts +0 -331
  228. package/renderers/constants.ts +0 -87
  229. package/renderers/renderer.ts +0 -1288
  230. package/renderers/representer-node.ts +0 -52
  231. package/renderers/representer.ts +0 -25
  232. package/src/category.ts +0 -107
  233. package/src/comment.ts +0 -142
  234. package/src/connection.ts +0 -114
  235. package/src/context-menu.ts +0 -194
  236. package/src/coordinates.ts +0 -74
  237. package/src/core.ts +0 -202
  238. package/src/ctx-menu-registry.ts +0 -143
  239. package/src/dropdown-menu.ts +0 -215
  240. package/src/field.ts +0 -595
  241. package/src/flyout.ts +0 -165
  242. package/src/fonts-manager.ts +0 -38
  243. package/src/grid.ts +0 -162
  244. package/src/headless-node.ts +0 -27
  245. package/src/index.ts +0 -115
  246. package/src/inject-headless.ts +0 -18
  247. package/src/mutator.ts +0 -40
  248. package/src/nodesvg.ts +0 -756
  249. package/src/styles.css +0 -224
  250. package/src/toolbox.ts +0 -125
  251. package/src/undo-redo.ts +0 -87
  252. package/src/widget-prototypes.ts +0 -11
  253. package/src/widget.ts +0 -139
  254. package/src/workspace-svg.ts +0 -736
  255. package/src/workspace.ts +0 -155
  256. package/test-server.js +0 -61
  257. package/themes/dark.ts +0 -32
  258. package/themes/default.ts +0 -28
  259. package/themes/themes.ts +0 -9
  260. package/tsconfig.json +0 -25
  261. package/typedoc.json +0 -10
  262. package/util/emitter.ts +0 -33
  263. package/util/env.ts +0 -11
  264. package/util/eventer.ts +0 -108
  265. package/util/has-prop.ts +0 -4
  266. package/util/parse-color.ts +0 -42
  267. package/util/path.ts +0 -99
  268. package/util/styler.ts +0 -41
  269. package/util/uid.ts +0 -184
  270. package/util/user-state.ts +0 -68
  271. package/util/window-listeners.ts +0 -62
  272. package/webpack.config.js +0 -80
  273. /package/{docs/_media → dist}/index.html +0 -0
package/src/flyout.ts DELETED
@@ -1,165 +0,0 @@
1
- import newHeadlessNode from "./headless-node";
2
- import { TblxNodeStruct } from "./inject";
3
- import Toolbox from "./toolbox";
4
- import { parseColor } from "../util/parse-color";
5
- import { Color } from "./visual-types";
6
-
7
- /**
8
- * Represents a flyout menu for a toolbox in Kabel.
9
- * Displays a list of nodes that can be dragged into a workspace.
10
- */
11
- class Flyout {
12
- container: HTMLDivElement;
13
- visible: boolean;
14
- toolbox?: Toolbox|undefined;
15
-
16
- constructor(toolbox?: Toolbox) {
17
- this.toolbox = toolbox;
18
-
19
- this.container = document.createElement("div");
20
- this.container.className = "KabelFlyout";
21
-
22
- this.visible = false;
23
-
24
- if (toolbox) {
25
- toolbox.workspace._wsTop.appendChild(this.container);
26
- } else {
27
- document.body.appendChild(this.container);
28
- }
29
- }
30
-
31
- /**
32
- * Populates the flyout with a list of nodes.
33
- */
34
- fill(nodes: TblxNodeStruct[]) {
35
- this.clear();
36
- nodes.forEach(node => {
37
- const headlessNode = newHeadlessNode(node.type as string);
38
- if (!headlessNode) return;
39
-
40
- const nodeEl = this.createNodeElement(headlessNode);
41
- this.container.appendChild(nodeEl);
42
- });
43
-
44
- this.show();
45
- }
46
-
47
- /**
48
- * Creates a DOM element for a node with event listeners attached.
49
- */
50
- private createNodeElement(headlessNode: any): HTMLDivElement {
51
- const nodeEl = document.createElement("div");
52
- nodeEl.className = "KabelFlyoutNode";
53
- nodeEl.textContent = headlessNode.labelText;
54
-
55
- this.applyNodeStyles(nodeEl, headlessNode.colors.primary);
56
-
57
- nodeEl.addEventListener("mousedown", e => this.onNodeMouseDown(e, headlessNode));
58
- return nodeEl;
59
- }
60
-
61
- /**
62
- * Applies consistent styling to a node element.
63
- */
64
- private applyNodeStyles(el: HTMLElement, bgColor: Color) {
65
- el.style.backgroundColor = parseColor(bgColor);
66
- el.style.padding = "4px 8px";
67
- el.style.cursor = "pointer";
68
-
69
- if (this.toolbox?.workspace?.renderer?.constants) {
70
- const c = this.toolbox.workspace.renderer.constants;
71
- el.style.fontFamily = c.FONT_FAMILY;
72
- el.style.fontSize = `${c.FONT_SIZE}px`;
73
- el.style.color = parseColor(c.FONT_COLOR);
74
- }
75
- }
76
-
77
- /**
78
- * Handles starting a drag operation for a node.
79
- */
80
- private onNodeMouseDown(e: MouseEvent, headlessNode: any) {
81
- if (!this.toolbox) return;
82
-
83
- const ghostEl = this.createGhostNode(headlessNode);
84
- document.body.appendChild(ghostEl);
85
-
86
- const moveGhost = (ev: MouseEvent) => {
87
- ghostEl.style.left = ev.clientX + 4 + "px";
88
- ghostEl.style.top = ev.clientY + 4 + "px";
89
- };
90
-
91
- const releaseGhost = (ev: MouseEvent) => {
92
- document.removeEventListener("mousemove", moveGhost);
93
- document.removeEventListener("mouseup", releaseGhost);
94
-
95
- this.dropNode(ev, headlessNode);
96
-
97
- ghostEl.remove();
98
- };
99
-
100
- document.addEventListener("mousemove", moveGhost);
101
- document.addEventListener("mouseup", releaseGhost);
102
-
103
- e.preventDefault();
104
- }
105
-
106
- /**
107
- * Creates a ghost element that follows the mouse during drag.
108
- */
109
- private createGhostNode(headlessNode: any): HTMLDivElement {
110
- const ghostEl = document.createElement("div");
111
- ghostEl.className = "KabelGhostNode";
112
- ghostEl.textContent = headlessNode.labelText;
113
- ghostEl.style.position = "absolute";
114
- ghostEl.style.pointerEvents = "none";
115
-
116
- this.applyNodeStyles(ghostEl, headlessNode.colors.primary);
117
- return ghostEl;
118
- }
119
-
120
- /**
121
- * Handles dropping a node into the workspace if the mouse is over it.
122
- */
123
- private dropNode(ev: MouseEvent, node: TblxNodeStruct) {
124
- if (!this.toolbox) return;
125
-
126
- const svg = this.toolbox.workspace.svg.node as SVGSVGElement;
127
- const rect = svg.getBoundingClientRect();
128
-
129
- if (
130
- ev.clientX >= rect.left &&
131
- ev.clientX <= rect.right &&
132
- ev.clientY >= rect.top &&
133
- ev.clientY <= rect.bottom
134
- ) {
135
- const { x: wsX, y: wsY } = this.toolbox.workspace.screenToWorkspace(
136
- ev.clientX - rect.left,
137
- ev.clientY - rect.top
138
- );
139
-
140
- const nodews = this.toolbox.workspace.spawnAt(node.type as string, wsX, wsY);
141
- if (nodews) {
142
- for (let argName in node.arguments) {
143
- nodews.setFieldValue(argName, node.arguments[argName]);
144
- }
145
- this.toolbox.workspace.drawNode(nodews.id);
146
- }
147
- }
148
- }
149
-
150
- show() {
151
- this.container.style.display = "block";
152
- this.visible = true;
153
- }
154
-
155
- hide() {
156
- this.container.style.display = "none";
157
- this.visible = false;
158
- }
159
-
160
- clear() {
161
- this.container.innerHTML = "";
162
- }
163
- }
164
-
165
- export default Flyout;
@@ -1,38 +0,0 @@
1
-
2
-
3
- // fonts-manager.ts
4
-
5
- const loadedFonts: Record<string, Promise<void>> = {};
6
-
7
- /**
8
- * Load a Google Font by name and optional weights.
9
- * Returns a promise that resolves when the font is available.
10
- */
11
- export function loadGoogleFont(
12
- name: string,
13
- weights: number[] = [400, 700]
14
- ): Promise<void> {
15
- if (loadedFonts[name]) return loadedFonts[name]; // already loading/loaded
16
-
17
- const linkId = `gf-${name.replace(/\s+/g, '-')}`;
18
- if (!document.getElementById(linkId)) {
19
- const link = document.createElement('link');
20
- link.id = linkId;
21
- link.rel = 'stylesheet';
22
- const weightsParam = weights.join(';');
23
- link.href = `https://fonts.googleapis.com/css2?family=${name.replace(
24
- /\s+/g,
25
- '+'
26
- )}:wght@${weightsParam}&display=swap`;
27
- document.head.appendChild(link);
28
- }
29
-
30
- // wait for all requested weights to be loaded
31
- const fontPromises = weights.map((w) =>
32
- document.fonts.load(`${w} 1em ${name}`)
33
- );
34
-
35
- const promise = Promise.all(fontPromises).then(() => undefined);
36
- loadedFonts[name] = promise;
37
- return promise;
38
- }
package/src/grid.ts DELETED
@@ -1,162 +0,0 @@
1
- import { Svg, Pattern, Rect } from "@svgdotjs/svg.js";
2
- import WorkspaceSvg from "./workspace-svg";
3
- import { addWindowListener } from "../util/window-listeners";
4
-
5
- /**
6
- * Options for configuring the workspace grid.
7
- * @typedef {Object} GridOptions
8
- * @property {"dotted"|"celled"} [type="dotted"] - The type of grid to render.
9
- * @property {number} [spacing=40] - The spacing between grid dots or cells.
10
- * @property {number} [dotSize=2] - The radius of the dots (only for dotted type).
11
- * @property {number} [strokeWidth=2] - Stroke width of the cells (only for celled type).
12
- * @property {string} [color="#bebebeff"] - Color of the grid.
13
- */
14
- export interface GridOptions {
15
- type?: "dotted" | "celled";
16
- spacing?: number;
17
- dotSize?: number;
18
- strokeWidth?: number;
19
- color?: string;
20
- }
21
-
22
- /**
23
- * Handles drawing and managing a workspace background grid.
24
- */
25
- export default class Grid {
26
- private ws: WorkspaceSvg;
27
- private svg: Svg;
28
- private pattern?: Pattern;
29
- private rect?: Rect;
30
-
31
- /** Cached + normalized grid values */
32
- private grid: Required<GridOptions>;
33
-
34
- /**
35
- * Creates a new Grid instance and attaches it to the given workspace SVG.
36
- * @param {WorkspaceSvg} ws - The workspace this grid belongs to.
37
- * @param {Svg} svg - The SVG element to draw the grid into.
38
- * @param {GridOptions} opts - Initial options for the grid.
39
- */
40
- constructor(ws: WorkspaceSvg, svg: Svg, opts: GridOptions) {
41
- this.ws = ws;
42
- this.svg = svg;
43
-
44
- this.grid = {
45
- type: opts.type ?? "dotted",
46
- spacing: opts.spacing ?? 40,
47
- dotSize: opts.dotSize ?? 2,
48
- strokeWidth: opts.strokeWidth ?? 2,
49
- color: opts.color ?? "#bebebeff",
50
- };
51
-
52
- this.init();
53
- }
54
-
55
- /**
56
- * Initializes the grid pattern, background rect, and attaches resize listener.
57
- * @private
58
- */
59
- private init() {
60
- if (this.rect) {
61
- this.rect.remove();
62
- }
63
- const { type, spacing, dotSize, strokeWidth, color } = this.grid;
64
-
65
- let defs = this.svg.findOne("defs");
66
- if (!defs) defs = this.svg.defs();
67
-
68
- this.pattern = this.svg.pattern(spacing, spacing, (add) => {
69
- if (type === "dotted") {
70
- add
71
- .circle(dotSize * 2)
72
- .fill(color)
73
- .move(spacing / 2 - dotSize, spacing / 2 - dotSize);
74
- } else {
75
- add.rect(spacing, spacing).stroke({ color, width: strokeWidth }).fill("none");
76
- }
77
- });
78
- this.pattern.attr({ patternUnits: "userSpaceOnUse" });
79
- defs.add(this.pattern);
80
-
81
- const { width, height } = this.ws.getSize();
82
- this.rect = this.svg
83
- .rect(width, height)
84
- .fill(this.pattern)
85
- .back()
86
- .addClass("WorkspaceBgPattern");
87
-
88
- addWindowListener("resize", () => this.resize());
89
- }
90
-
91
- /**
92
- * Resizes the grid background rect to fit the workspace size.
93
- */
94
- resize() {
95
- if (!this.rect) return;
96
- const { width, height } = this.ws.getSize();
97
- this.rect.size(width, height).back();
98
- this.ws._backgroundRect.back();
99
- }
100
-
101
- /**
102
- * Updates the grid pattern transform according to zoom and camera position.
103
- * Scales the dots/cells to match zoom and repositions them based on camera.
104
- */
105
- updateTransform() {
106
- if (!this.pattern || !this.rect) return;
107
- const { type, spacing, dotSize, strokeWidth, color } = this.grid;
108
-
109
- const zoom = this.ws.getZoom();
110
- const scaledSpacing = spacing * zoom;
111
-
112
- this.pattern.attr({ width: scaledSpacing, height: scaledSpacing });
113
- this.pattern.clear();
114
-
115
- if (type === "dotted") {
116
- const scaledDot = Math.max(dotSize * zoom, 0.5);
117
- this.pattern
118
- .circle(scaledDot * 2)
119
- .fill(color)
120
- .move(scaledSpacing / 2 - scaledDot, scaledSpacing / 2 - scaledDot);
121
- } else {
122
- this.pattern
123
- .rect(scaledSpacing, scaledSpacing)
124
- .stroke({ color, width: strokeWidth * zoom })
125
- .fill("none");
126
- }
127
-
128
- const cam = this.ws._camera;
129
- this.pattern.attr({
130
- patternTransform: `translate(${-cam.x * zoom % scaledSpacing}, ${-cam.y * zoom % scaledSpacing})`,
131
- });
132
-
133
- this.resize();
134
- this.ws._backgroundRect.back();
135
- }
136
-
137
- /**
138
- * Updates internal grid options from the workspace configuration.
139
- */
140
- updateOptions() {
141
- const opts = this.ws.options!.grid;
142
- this.grid = {
143
- type: opts!.type ?? "dotted",
144
- spacing: opts!.spacing ?? 40,
145
- dotSize: opts!.dotSize ?? 2,
146
- strokeWidth: opts!.strokeWidth ?? 2,
147
- color: opts!.color ?? "#bebebeff",
148
- };
149
- this.init();
150
- }
151
-
152
- /**
153
- * Dynamically sets new grid options and rebuilds the grid pattern.
154
- * @param {Partial<GridOptions>} newOpts - New options to apply.
155
- */
156
- setOptions(newOpts: Partial<GridOptions>) {
157
- Object.assign(this.grid, newOpts);
158
- this.rect?.remove?.();
159
- this.pattern?.remove?.();
160
- this.init(); // rebuild
161
- }
162
- }
@@ -1,27 +0,0 @@
1
- import { NodePrototype } from "./node-types";
2
- import NodeSvg from "./nodesvg";
3
- import NodePrototypes from "./prototypes";
4
-
5
- /**
6
- * Creates a new headless NodeSvg instance without attaching it to a workspace.
7
- * This is useful for programmatic node generation, testing, or serialization.
8
- *
9
- * @param type - The type of node to create. Must exist in NodePrototypes.
10
- * @returns The initialized NodeSvg instance, or `undefined` if the prototype does not exist.
11
- */
12
- function newHeadlessNode(type: string): NodeSvg | undefined {
13
- const proto: NodePrototype = NodePrototypes[type as string] as NodePrototype;
14
-
15
- // Return undefined if prototype not found
16
- if (!proto) return;
17
-
18
- // Create a new node instance
19
- const node = new NodeSvg(proto);
20
-
21
- // Initialize the node (calls prototype init, sets defaults)
22
- node.init();
23
-
24
- return node;
25
- }
26
-
27
- export default newHeadlessNode;
package/src/index.ts DELETED
@@ -1,115 +0,0 @@
1
- /**
2
- * Kabel Core Export Module
3
- * ------------------------
4
- * Aggregates all core Kabel modules, types, utilities, and components,
5
- * and exports them under a single namespace.
6
- */
7
-
8
- import RendererConstants from "../renderers/constants";
9
- import Renderer, { DrawState, ConnectorToFrom } from "../renderers/renderer";
10
- import CategoryColors from "./colors";
11
- import Connection, { Connectable } from "./connection";
12
- import Coordinates from "./coordinates";
13
- import Field, {
14
- FieldOptions, FieldVisualInfo, AnyFieldCls, AnyField, DummyField,
15
- FieldMap, NumberField, OptConnectField, TextField, ConnectableField,
16
- FieldRawBoxData, FieldConnectionData
17
- } from "./field";
18
- import inject, {
19
- InjectMsg, InjectOptions, TblxCategoryStruct, TblxObjStruct,
20
- TblxFieldStruct, TblxNodeStruct, GridOptions
21
- } from "./inject";
22
- import { clearMainWorkspace, getMainWorkspace, setMainWorkspace } from "./main-workspace";
23
- import NodeSvg, { NodeJson, NodeEvents, InputFieldJson, SerializedNode } from "./nodesvg";
24
- import NodePrototypes from "./prototypes";
25
- import WorkspaceSvg from "./workspace-svg";
26
- import WorkspaceCoords from "./workspace-coords";
27
- import { NodePrototype } from "./node-types";
28
- import { Color, ColorStyle, Hex, RGBObject, RGBString, RGBTuple } from "./visual-types";
29
- import { parseColor } from "../util/parse-color";
30
- import eventer, { Eventer, EventSetupFn, EventArgs, RegisteredEl } from "../util/eventer";
31
- import hasProp from "../util/has-prop";
32
- import EventEmitter from "../util/emitter";
33
- import * as Path from "../util/path";
34
- import * as SVG from "@svgdotjs/svg.js";
35
- import * as UID from "../util/uid";
36
-
37
- import K from "./core";
38
- import Widget, { WidgetOptions } from "./widget";
39
- import { WidgetPrototypeList } from "./widget-prototypes";
40
- import Showable, { KabelInterface, KabelCommentRendering, KabelNodeRendering, KabelUIX, KabelUtils } from "./types";
41
-
42
- //@ts-ignore
43
- const Kabel: KabelInterface = K;
44
- export default Kabel;
45
-
46
- // Core types and utilities
47
- export {
48
- KabelInterface,
49
- TblxCategoryStruct,
50
- TblxNodeStruct,
51
- TblxFieldStruct,
52
- TblxObjStruct,
53
- RendererConstants,
54
- Renderer,
55
- CategoryColors,
56
- Connection,
57
- Coordinates,
58
- Field,
59
- DummyField,
60
- FieldMap,
61
- NumberField,
62
- OptConnectField,
63
- TextField,
64
- FieldOptions,
65
- FieldVisualInfo,
66
- AnyFieldCls,
67
- AnyField,
68
- ConnectableField,
69
- FieldRawBoxData,
70
- FieldConnectionData,
71
- inject,
72
- InjectMsg,
73
- InjectOptions,
74
- clearMainWorkspace,
75
- getMainWorkspace,
76
- setMainWorkspace,
77
- NodeSvg,
78
- NodePrototypes,
79
- WorkspaceSvg,
80
- WorkspaceCoords,
81
- NodePrototype,
82
- Color, ColorStyle, Hex, RGBObject, RGBString, RGBTuple,
83
- NodeJson, NodeEvents, InputFieldJson,
84
- SerializedNode,
85
- Eventer,
86
- EventSetupFn,
87
- EventArgs,
88
- Connectable,
89
- DrawState,
90
- ConnectorToFrom,
91
- WidgetOptions,
92
- WidgetPrototypeList,
93
- KabelCommentRendering,
94
- KabelNodeRendering,
95
- KabelUIX,
96
- KabelUtils,
97
- Showable,
98
- RegisteredEl,
99
- GridOptions
100
- };
101
-
102
- // Core classes used by public API
103
- export { default as CommentModel } from './comment';
104
-
105
- export { default as Toolbox } from './toolbox';
106
- export { default as ContextMenuHTML } from './context-menu';
107
- export { default as Widget } from './widget';
108
- export { DropdownContainer } from './dropdown-menu';
109
- export { RepresenterNode } from '../renderers/representer-node';
110
- export { default as CommentRenderer } from '../comment-renderer/renderer';
111
- export { default as Representer } from '../renderers/representer';
112
-
113
- // Controllers
114
- export { default as WorkspaceController } from '../controllers/base';
115
- export { default as WASDController } from '../controllers/wasd';
@@ -1,18 +0,0 @@
1
- import { InjectMsg } from "./inject";
2
- import { setMainWorkspace } from "./main-workspace";
3
- import Workspace from "./workspace";
4
-
5
-
6
-
7
-
8
- function injectHeadless() : Workspace | undefined {
9
- try {
10
- const ws = new Workspace();
11
- setMainWorkspace(ws);
12
- return ws;
13
- } catch (e) {
14
- new InjectMsg(`Failed to initialize workspace: ${(e as Error).message}`).err();
15
- }
16
- }
17
-
18
- export default injectHeadless;
package/src/mutator.ts DELETED
@@ -1,40 +0,0 @@
1
- import NodeSvg from "./nodesvg"
2
- import WorkspaceSvg from "./workspace-svg";
3
-
4
- const Mutations : {[key: string]: MutatorData}= {
5
- // Stores mut_name: MutationData for MutatorModel
6
- }
7
-
8
- class MutatorModel {
9
- // ignore this class for now, but keep it.
10
- }
11
- interface MutatorData {
12
- /**
13
- * Called to create a container representing the editable state of the node.
14
- * Equivalent to Blockly's `decompose`.
15
- */
16
- decompose(this: MutatorModel, workspace: WorkspaceSvg): NodeSvg;
17
-
18
- /**
19
- * Called after the user edits the container; rebuilds the node from it.
20
- * Equivalent to Blockly's `compose`.
21
- */
22
- compose(this: NodeSvg, containerBlock: NodeSvg): void;
23
-
24
- /**
25
- * Serialize the node’s mutation state to JSON for saving/exporting.
26
- * Equivalent to Blockly's `mutationToDom`.
27
- */
28
- mutationToJson(this: NodeSvg): {[key: string]: any};
29
-
30
- /**
31
- * Load/apply mutation state from JSON when loading/importing.
32
- * Equivalent to Blockly's `domToMutation`.
33
- */
34
- jsonToMutation(this: NodeSvg, json: {[key: string]: any}): void;
35
-
36
- /**
37
- * Whether Kabel should render the default UI for this mutator.
38
- */
39
- isEditable: boolean;
40
- }