@design-core/core 0.0.1 → 0.0.3

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 (254) hide show
  1. package/.eslintrc.json +14 -7
  2. package/.github/workflows/DesignCoreQA.yml +3 -1
  3. package/README.md +11 -4
  4. package/TODO.md +19 -0
  5. package/core/core/core.js +49 -42
  6. package/core/designCore.js +61 -2
  7. package/core/dimensions/alignedDimension.js +142 -0
  8. package/core/dimensions/angularDimension.js +550 -0
  9. package/core/dimensions/baseCircularDimension.js +244 -0
  10. package/core/dimensions/baseDimension.js +558 -0
  11. package/core/dimensions/baseLinearDimension.js +371 -0
  12. package/core/dimensions/diametricDimension.js +82 -0
  13. package/core/dimensions/dimension.js +298 -0
  14. package/core/dimensions/linearDimension.js +29 -0
  15. package/core/dimensions/radialDimension.js +78 -0
  16. package/core/dimensions/rotatedDimension.js +167 -0
  17. package/core/entities/arc.js +314 -60
  18. package/core/entities/arctext.js +642 -0
  19. package/core/entities/basePolyline.js +553 -94
  20. package/core/entities/circle.js +181 -54
  21. package/core/entities/entity.js +154 -74
  22. package/core/entities/hatch.js +807 -0
  23. package/core/entities/insert.js +200 -39
  24. package/core/entities/line.js +196 -134
  25. package/core/entities/lwpolyline.js +21 -44
  26. package/core/entities/point.js +194 -29
  27. package/core/entities/polyline.js +54 -7
  28. package/core/entities/rectangle.js +43 -13
  29. package/core/entities/solid.js +43 -6
  30. package/core/entities/text.js +324 -181
  31. package/core/lib/boundingBox.js +73 -13
  32. package/core/lib/canvas.js +256 -65
  33. package/core/lib/clipboard.js +198 -0
  34. package/core/lib/colour.js +144 -0
  35. package/core/lib/colours.js +367 -301
  36. package/core/lib/commandLine.js +16 -28
  37. package/core/lib/commandManager.js +115 -58
  38. package/core/lib/constants.js +23 -0
  39. package/core/lib/dxf/dxf.js +249 -34
  40. package/core/lib/dxf/dxfFile.js +23 -38
  41. package/core/lib/dxf/dxfIterator.js +17 -5
  42. package/core/lib/dxf/dxfRead.js +23 -7
  43. package/core/lib/dxf/dxfWrite.js +39 -129
  44. package/core/lib/dxf/handleManager.js +97 -0
  45. package/core/lib/dxf/sections/blocks.js +16 -2
  46. package/core/lib/dxf/sections/entities.js +17 -3
  47. package/core/lib/dxf/sections/header.js +10 -1
  48. package/core/lib/dxf/sections/objects.js +36 -0
  49. package/core/lib/dxf/sections/section.js +43 -5
  50. package/core/lib/dxf/sections/tables.js +17 -3
  51. package/core/lib/entityManager.js +178 -0
  52. package/core/lib/fileio.js +14 -4
  53. package/core/lib/headers.js +229 -0
  54. package/core/lib/input.js +46 -0
  55. package/core/lib/inputManager.js +199 -194
  56. package/core/lib/intersect.js +341 -468
  57. package/core/lib/logging.js +25 -1
  58. package/core/lib/matrix.js +6 -8
  59. package/core/lib/mouse.js +24 -79
  60. package/core/lib/patterns.js +690 -0
  61. package/core/lib/promptOptions.js +133 -0
  62. package/core/lib/scene.js +71 -174
  63. package/core/lib/selectionManager.js +74 -48
  64. package/core/lib/selectionWindow.js +24 -10
  65. package/core/lib/settings.js +18 -11
  66. package/core/lib/snapping.js +129 -21
  67. package/core/lib/stateManager.js +288 -0
  68. package/core/lib/strings.js +57 -5
  69. package/core/lib/utils.js +95 -11
  70. package/core/objects/dictionary.js +43 -0
  71. package/core/objects/dictionaryManager.js +80 -0
  72. package/core/properties/dimType.js +117 -0
  73. package/core/properties/flags.js +66 -0
  74. package/core/properties/property.js +26 -0
  75. package/core/properties/propertyManager.js +65 -19
  76. package/core/tables/appId.js +31 -0
  77. package/core/tables/appIdManager.js +44 -0
  78. package/core/tables/block.js +323 -0
  79. package/core/tables/blockManager.js +48 -0
  80. package/core/tables/blockRecord.js +29 -0
  81. package/core/tables/blockRecordManager.js +37 -0
  82. package/core/tables/dimStyle.js +627 -0
  83. package/core/tables/dimStyleManager.js +187 -0
  84. package/core/tables/endblk.js +28 -0
  85. package/core/tables/layer.js +219 -0
  86. package/core/tables/layerManager.js +47 -0
  87. package/core/tables/ltype.js +85 -0
  88. package/core/tables/ltypeManager.js +65 -0
  89. package/core/tables/style.js +145 -0
  90. package/core/tables/styleManager.js +55 -0
  91. package/core/tables/styleManagerBase.js +110 -0
  92. package/core/tables/tableManagerBase.js +354 -0
  93. package/core/tables/ucs.js +28 -0
  94. package/core/tables/ucsManager.js +44 -0
  95. package/core/tables/view.js +28 -0
  96. package/core/tables/viewManager.js +44 -0
  97. package/core/tables/vport.js +70 -0
  98. package/core/tables/vportManager.js +65 -0
  99. package/core/tools/chamfer.js +343 -0
  100. package/core/tools/chamferFilletBase.js +162 -0
  101. package/core/tools/copy.js +68 -40
  102. package/core/tools/copybase.js +65 -0
  103. package/core/tools/copyclip.js +59 -0
  104. package/core/tools/cornerEntity.js +138 -0
  105. package/core/tools/cutclip.js +72 -0
  106. package/core/tools/distance.js +37 -9
  107. package/core/tools/erase.js +43 -13
  108. package/core/tools/explode.js +117 -0
  109. package/core/tools/extend.js +71 -32
  110. package/core/tools/fillet.js +336 -0
  111. package/core/tools/identify.js +33 -6
  112. package/core/tools/matchProp.js +106 -0
  113. package/core/tools/mirror.js +141 -0
  114. package/core/tools/move.js +65 -32
  115. package/core/tools/offset.js +321 -0
  116. package/core/tools/pan.js +54 -0
  117. package/core/tools/pasteclip.js +93 -0
  118. package/core/tools/purge.js +90 -0
  119. package/core/tools/rotate.js +105 -70
  120. package/core/tools/scale.js +166 -0
  121. package/core/tools/tool.js +14 -4
  122. package/core/tools/trim.js +71 -32
  123. package/core/tools/zoom.js +152 -0
  124. package/package.json +3 -305
  125. package/test/dimensions/alignedDimension.test.js +211 -0
  126. package/test/dimensions/angularDimension.test.js +243 -0
  127. package/test/dimensions/baseDimension.test.js +239 -0
  128. package/test/dimensions/diametricDimension.test.js +203 -0
  129. package/test/dimensions/dimension.test.js +102 -0
  130. package/test/dimensions/radialDimension.test.js +203 -0
  131. package/test/dimensions/rotatedDimension.test.js +224 -0
  132. package/test/entities/arc.test.js +463 -41
  133. package/test/entities/arctext.test.js +329 -0
  134. package/test/entities/basePolyline.test.js +459 -10
  135. package/test/entities/circle.test.js +312 -7
  136. package/test/entities/entity.test.js +28 -9
  137. package/test/entities/hatch.test.js +606 -0
  138. package/test/entities/insert.test.js +90 -0
  139. package/test/entities/line.test.js +182 -6
  140. package/test/entities/point.test.js +375 -37
  141. package/test/entities/solid.test.js +156 -0
  142. package/test/entities/text.test.js +533 -7
  143. package/test/integration/exportIntegration.reference.dxf +1706 -0
  144. package/test/integration/exportIntegration.test.js +186 -0
  145. package/test/integration/importExportIntegration.test.js +126 -0
  146. package/test/integration/intersectionIntegration.test.js +880 -0
  147. package/test/integration/userInputIntegration.reference.dxf +1410 -0
  148. package/test/integration/userInputIntegration.test.js +269 -0
  149. package/test/lib/boundingBox.test.js +26 -2
  150. package/test/lib/canvas.test.js +613 -5
  151. package/test/lib/clipboard.test.js +70 -0
  152. package/test/lib/colour.test.js +114 -0
  153. package/test/lib/colours.test.js +63 -18
  154. package/test/lib/commandLine.test.js +159 -22
  155. package/test/lib/commandManager.test.js +4 -4
  156. package/test/lib/constants.test.js +9 -0
  157. package/test/lib/dxf/dxfFile.test.js +6 -2
  158. package/test/lib/dxf/dxfIterator.test.js +1 -1
  159. package/test/lib/dxf/dxfWrite.test.js +173 -0
  160. package/test/lib/dxf/handleManager.test.js +137 -0
  161. package/test/lib/dxf/sections/blocks.test.js +5 -5
  162. package/test/lib/dxf/sections/entities.test.js +4 -4
  163. package/test/lib/dxf/sections/header.test.js +18 -4
  164. package/test/lib/dxf/sections/objects.test.js +132 -0
  165. package/test/lib/dxf/sections/section.test.js +29 -29
  166. package/test/lib/dxf/sections/tables.test.js +3 -3
  167. package/test/lib/entityManager.test.js +163 -0
  168. package/test/lib/headers.test.js +233 -0
  169. package/test/lib/inputManager.test.js +1144 -5
  170. package/test/lib/intersect.test.js +454 -331
  171. package/test/lib/logging.test.js +1 -1
  172. package/test/lib/matrix.test.js +1 -1
  173. package/test/lib/mouse.test.js +327 -4
  174. package/test/lib/patterns.test.js +105 -0
  175. package/test/lib/promptOptions.test.js +179 -0
  176. package/test/lib/scene.test.js +16 -52
  177. package/test/lib/selectionManager.test.js +17 -5
  178. package/test/lib/settings.test.js +111 -5
  179. package/test/lib/snapping.test.js +142 -4
  180. package/test/lib/stateManager.test.js +155 -0
  181. package/test/lib/utils.test.js +81 -1
  182. package/test/objects/dictionary.test.js +81 -0
  183. package/test/objects/dictionaryManager.test.js +34 -0
  184. package/test/properties/dimType.test.js +62 -0
  185. package/test/properties/flags.test.js +164 -0
  186. package/test/properties/property.test.js +13 -0
  187. package/test/properties/propertyManager.test.js +10 -11
  188. package/test/tables/appId.test.js +46 -0
  189. package/test/tables/appIdManager.test.js +72 -0
  190. package/test/tables/block.test.js +157 -0
  191. package/test/tables/blockManager.test.js +52 -0
  192. package/test/tables/blockRecord.test.js +39 -0
  193. package/test/tables/blockRecordManager.test.js +60 -0
  194. package/test/tables/dimstyle.test.js +72 -0
  195. package/test/tables/endblk.test.js +30 -0
  196. package/test/tables/layer.test.js +95 -0
  197. package/test/tables/layerManager.test.js +172 -0
  198. package/test/{styles → tables}/ltype.test.js +7 -7
  199. package/test/{styles → tables}/ltypeManager.test.js +2 -2
  200. package/test/tables/style.test.js +44 -0
  201. package/test/tables/stylemanagerbase.test.js +220 -0
  202. package/test/tables/tableManagerBase.test.js +194 -0
  203. package/test/tables/ucs.test.js +37 -0
  204. package/test/tables/ucsManager.test.js +48 -0
  205. package/test/tables/view.test.js +37 -0
  206. package/test/tables/viewManager.test.js +48 -0
  207. package/test/tables/vport.test.js +117 -0
  208. package/test/tables/vportManager.test.js +54 -0
  209. package/test/test-helpers/test-helpers.js +66 -0
  210. package/test/tools/chamfer.test.js +970 -0
  211. package/test/tools/chamferFilletBase.test.js +446 -0
  212. package/test/tools/copy.test.js +22 -14
  213. package/test/tools/copybase.test.js +93 -0
  214. package/test/tools/copyclip.test.js +92 -0
  215. package/test/tools/cornerEntity.test.js +201 -0
  216. package/test/tools/cutclip.test.js +94 -0
  217. package/test/tools/distance.test.js +140 -18
  218. package/test/tools/erase.test.js +12 -12
  219. package/test/tools/explode.test.js +45 -0
  220. package/test/tools/extend.test.js +326 -44
  221. package/test/tools/fillet.test.js +831 -0
  222. package/test/tools/identify.test.js +115 -16
  223. package/test/tools/matchProp.test.js +84 -0
  224. package/test/tools/mirror.test.js +475 -0
  225. package/test/tools/move.test.js +75 -19
  226. package/test/tools/offset.test.js +748 -0
  227. package/test/tools/pan.test.js +72 -0
  228. package/test/tools/pasteclip.test.js +100 -0
  229. package/test/tools/purge.test.js +89 -0
  230. package/test/tools/rotate.test.js +89 -23
  231. package/test/tools/scale.test.js +529 -0
  232. package/test/tools/trim.test.js +419 -84
  233. package/test/tools/zoom.test.js +504 -0
  234. package/core/entities/alignedDimension.js +0 -279
  235. package/core/entities/angularDimension.js +0 -194
  236. package/core/entities/baseDimension.js +0 -227
  237. package/core/entities/block.js +0 -247
  238. package/core/entities/diametricDimension.js +0 -133
  239. package/core/entities/dimension.js +0 -202
  240. package/core/entities/radialDimension.js +0 -126
  241. package/core/styles/dimStyle.js +0 -719
  242. package/core/styles/dimStyleManager.js +0 -47
  243. package/core/styles/layer.js +0 -133
  244. package/core/styles/layerManager.js +0 -40
  245. package/core/styles/ltype.js +0 -86
  246. package/core/styles/ltypeManager.js +0 -50
  247. package/core/styles/style.js +0 -158
  248. package/core/styles/styleManager.js +0 -43
  249. package/core/styles/styleManagerBase.js +0 -299
  250. package/test/entities/block.test.js +0 -22
  251. package/test/styles/dimstyle.test.js +0 -19
  252. package/test/styles/layerManager.test.js +0 -150
  253. package/test/styles/style.test.js +0 -33
  254. package/test/styles/stylemanagerbase.test.js +0 -219
@@ -0,0 +1,152 @@
1
+ import { Tool } from './tool.js';
2
+ import { Input, PromptOptions } from '../lib/inputManager.js';
3
+ import { Strings } from '../lib/strings.js';
4
+ import { Logging } from '../lib/logging.js';
5
+ import { Point } from '../entities/point.js';
6
+
7
+ import { DesignCore } from '../designCore.js';
8
+
9
+ /**
10
+ * Zoom Command Class
11
+ * Provides: All, Extents, Window
12
+ * @extends Tool
13
+ */
14
+ export class Zoom extends Tool {
15
+ /** Create a Zoom command */
16
+ constructor() {
17
+ super();
18
+ this.modes = {
19
+ ALL: 'All',
20
+ EXTENTS: 'Extents',
21
+ WINDOW: 'Window',
22
+ OBJECT: 'Object',
23
+ };
24
+ this.mode = this.modes.WINDOW; // default to window mode
25
+ }
26
+
27
+ /**
28
+ * Register the command
29
+ * @return {Object}
30
+ */
31
+ static register() {
32
+ const command = { command: 'Zoom', shortcut: 'Z' };
33
+ return command;
34
+ }
35
+
36
+ /**
37
+ * Execute method
38
+ */
39
+ async execute() {
40
+ try {
41
+ const op = new PromptOptions(Strings.Input.POINT, [Input.Type.POINT], [this.modes.ALL, this.modes.EXTENTS, this.modes.WINDOW, this.modes.OBJECT]);
42
+ const input = await DesignCore.Scene.inputManager.requestInput(op);
43
+ if (input === undefined) return;
44
+
45
+ if (Object.values(this.modes).includes(input)) {
46
+ // input matches one of the mode values
47
+ this.mode = input;
48
+ }
49
+
50
+ // default window mode
51
+ if (this.mode === this.modes.WINDOW) {
52
+ if (Input.getType(input) === Input.Type.POINT) {
53
+ this.points.push(input);
54
+ } else {
55
+ const p1op = new PromptOptions(Strings.Input.POINT, [Input.Type.POINT]);
56
+ const pt1 = await DesignCore.Scene.inputManager.requestInput(p1op);
57
+ if (pt1 === undefined) return;
58
+ this.points.push(pt1);
59
+ }
60
+
61
+ const p2op = new PromptOptions(Strings.Input.END, [Input.Type.POINT]);
62
+ const pt2 = await DesignCore.Scene.inputManager.requestInput(p2op);
63
+ if (pt2 === undefined) return;
64
+ this.points.push(pt2);
65
+ }
66
+
67
+ // Zoom to objects in selection
68
+ if (this.mode === this.modes.OBJECT) {
69
+ const op = new PromptOptions(Strings.Input.SELECTIONSET, [Input.Type.SELECTIONSET]);
70
+
71
+ if (!DesignCore.Scene.selectionManager.selectionSet.selectionSet.length) {
72
+ const sel = await DesignCore.Scene.inputManager.requestInput(op);
73
+ if (sel === undefined) return;
74
+ }
75
+ }
76
+
77
+ DesignCore.Scene.inputManager.executeCommand();
78
+ } catch (err) {
79
+ Logging.instance.error(`${this.type} - ${err}`);
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Preview the command during execution
85
+ */
86
+ preview() {
87
+ if (this.mode === this.modes.WINDOW && this.points.length === 1) {
88
+ const mousePoint = DesignCore.Mouse.pointOnScene();
89
+ const p1 = this.points[0];
90
+ const p2 = mousePoint;
91
+
92
+ const points = [
93
+ new Point(p1.x, p1.y),
94
+ new Point(p2.x, p1.y),
95
+ new Point(p2.x, p2.y),
96
+ new Point(p1.x, p2.y),
97
+ new Point(p1.x, p1.y),
98
+ ];
99
+
100
+ DesignCore.Scene.tempEntities.create('Polyline', { points: points });
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Perform the command
106
+ */
107
+ action() {
108
+ // Zoom to window
109
+ if (this.mode === this.modes.WINDOW && this.points.length === 2) {
110
+ DesignCore.Canvas.zoomToWindow(this.points[0], this.points[1]);
111
+ }
112
+
113
+ // Zoom Extents
114
+ if (this.mode === this.modes.ALL || this.mode === this.modes.EXTENTS) {
115
+ DesignCore.Canvas.zoomExtents();
116
+ }
117
+
118
+ // Zoom to Object(s)
119
+ if (this.mode === this.modes.OBJECT) {
120
+ let xmin = Infinity;
121
+ let xmax = -Infinity;
122
+ let ymin = Infinity;
123
+ let ymax = -Infinity;
124
+
125
+ // return if nothing selection
126
+ if (DesignCore.Scene.selectionManager.selectionSet.selectionSet.length === 0) {
127
+ return;
128
+ }
129
+
130
+ for (let i = 0; i <DesignCore.Scene.selectionManager.selectionSet.selectionSet.length; i++) {
131
+ const itemBoundingBox = DesignCore.Scene.entities.get(DesignCore.Scene.selectionManager.selectionSet.selectionSet[i]).boundingBox();
132
+
133
+ xmin = Math.min(xmin, itemBoundingBox.xMin);
134
+ xmax = Math.max(xmax, itemBoundingBox.xMax);
135
+ ymin = Math.min(ymin, itemBoundingBox.yMin);
136
+ ymax = Math.max(ymax, itemBoundingBox.yMax);
137
+ }
138
+
139
+ // if all values are zero return undefined
140
+ if (xmin === 0 && xmax === 0, ymin === 0, ymax === 0) {
141
+ return;
142
+ }
143
+
144
+ const Pt1 = new Point(xmin, ymin);
145
+ const Pt2 = new Point(xmax, ymax);
146
+
147
+ DesignCore.Canvas.zoomToWindow(Pt1, Pt2);
148
+ }
149
+ }
150
+ }
151
+
152
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@design-core/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
@@ -12,7 +12,7 @@
12
12
  "eslint-plugin-import": "^2.26.0",
13
13
  "eslint-plugin-n": "^15.3.0",
14
14
  "eslint-plugin-promise": "^6.1.1",
15
- "jest": "^29.2.2"
15
+ "jest": "^29.7.0"
16
16
  },
17
17
  "description": "2D CAD Library",
18
18
  "exports": {
@@ -22,308 +22,6 @@
22
22
  "directories": {
23
23
  "test": "test"
24
24
  },
25
- "dependencies": {
26
- "acorn": "^8.11.3",
27
- "acorn-jsx": "^5.3.2",
28
- "ajv": "^6.12.6",
29
- "ansi-escapes": "^4.3.2",
30
- "ansi-regex": "^5.0.1",
31
- "ansi-styles": "^4.3.0",
32
- "anymatch": "^3.1.3",
33
- "argparse": "^2.0.1",
34
- "array-buffer-byte-length": "^1.0.0",
35
- "array-includes": "^3.1.7",
36
- "array.prototype.findlastindex": "^1.2.3",
37
- "array.prototype.flat": "^1.3.2",
38
- "array.prototype.flatmap": "^1.3.2",
39
- "arraybuffer.prototype.slice": "^1.0.2",
40
- "available-typed-arrays": "^1.0.5",
41
- "babel-jest": "^29.7.0",
42
- "babel-plugin-istanbul": "^6.1.1",
43
- "babel-plugin-jest-hoist": "^29.6.3",
44
- "babel-preset-current-node-syntax": "^1.0.1",
45
- "babel-preset-jest": "^29.6.3",
46
- "balanced-match": "^1.0.2",
47
- "brace-expansion": "^1.1.11",
48
- "braces": "^3.0.2",
49
- "browserslist": "^4.22.2",
50
- "bser": "^2.1.1",
51
- "buffer-from": "^1.1.2",
52
- "builtins": "^5.0.1",
53
- "call-bind": "^1.0.5",
54
- "callsites": "^3.1.0",
55
- "camelcase": "^5.3.1",
56
- "caniuse-lite": "^1.0.30001576",
57
- "chalk": "^4.1.2",
58
- "char-regex": "^1.0.2",
59
- "ci-info": "^3.9.0",
60
- "cjs-module-lexer": "^1.2.3",
61
- "cliui": "^8.0.1",
62
- "co": "^4.6.0",
63
- "collect-v8-coverage": "^1.0.2",
64
- "color-convert": "^2.0.1",
65
- "color-name": "^1.1.4",
66
- "concat-map": "^0.0.1",
67
- "convert-source-map": "^2.0.0",
68
- "create-jest": "^29.7.0",
69
- "cross-spawn": "^7.0.3",
70
- "debug": "^4.3.4",
71
- "dedent": "^1.5.1",
72
- "deep-is": "^0.1.4",
73
- "deepmerge": "^4.3.1",
74
- "define-data-property": "^1.1.1",
75
- "define-properties": "^1.2.1",
76
- "detect-newline": "^3.1.0",
77
- "diff-sequences": "^29.6.3",
78
- "doctrine": "^3.0.0",
79
- "electron-to-chromium": "^1.4.623",
80
- "emittery": "^0.13.1",
81
- "emoji-regex": "^8.0.0",
82
- "error-ex": "^1.3.2",
83
- "es-abstract": "^1.22.3",
84
- "es-set-tostringtag": "^2.0.2",
85
- "es-shim-unscopables": "^1.0.2",
86
- "es-to-primitive": "^1.2.1",
87
- "escalade": "^3.1.1",
88
- "escape-string-regexp": "^4.0.0",
89
- "eslint-import-resolver-node": "^0.3.9",
90
- "eslint-module-utils": "^2.8.0",
91
- "eslint-plugin-es": "^4.1.0",
92
- "eslint-scope": "^7.2.2",
93
- "eslint-utils": "^3.0.0",
94
- "eslint-visitor-keys": "^3.4.3",
95
- "espree": "^9.6.1",
96
- "esprima": "^4.0.1",
97
- "esquery": "^1.5.0",
98
- "esrecurse": "^4.3.0",
99
- "estraverse": "^5.3.0",
100
- "esutils": "^2.0.3",
101
- "execa": "^5.1.1",
102
- "exit": "^0.1.2",
103
- "expect": "^29.7.0",
104
- "fast-deep-equal": "^3.1.3",
105
- "fast-json-stable-stringify": "^2.1.0",
106
- "fast-levenshtein": "^2.0.6",
107
- "fastq": "^1.16.0",
108
- "fb-watchman": "^2.0.2",
109
- "file-entry-cache": "^6.0.1",
110
- "fill-range": "^7.0.1",
111
- "find-up": "^5.0.0",
112
- "flat-cache": "^3.2.0",
113
- "flatted": "^3.2.9",
114
- "for-each": "^0.3.3",
115
- "fs.realpath": "^1.0.0",
116
- "function-bind": "^1.1.2",
117
- "function.prototype.name": "^1.1.6",
118
- "functions-have-names": "^1.2.3",
119
- "gensync": "^1.0.0-beta.2",
120
- "get-caller-file": "^2.0.5",
121
- "get-intrinsic": "^1.2.2",
122
- "get-package-type": "^0.1.0",
123
- "get-stream": "^6.0.1",
124
- "get-symbol-description": "^1.0.0",
125
- "glob": "^7.2.3",
126
- "glob-parent": "^6.0.2",
127
- "globals": "^13.24.0",
128
- "globalthis": "^1.0.3",
129
- "gopd": "^1.0.1",
130
- "graceful-fs": "^4.2.11",
131
- "graphemer": "^1.4.0",
132
- "has-bigints": "^1.0.2",
133
- "has-flag": "^4.0.0",
134
- "has-property-descriptors": "^1.0.1",
135
- "has-proto": "^1.0.1",
136
- "has-symbols": "^1.0.3",
137
- "has-tostringtag": "^1.0.0",
138
- "hasown": "^2.0.0",
139
- "html-escaper": "^2.0.2",
140
- "human-signals": "^2.1.0",
141
- "ignore": "^5.3.0",
142
- "import-fresh": "^3.3.0",
143
- "import-local": "^3.1.0",
144
- "imurmurhash": "^0.1.4",
145
- "inflight": "^1.0.6",
146
- "inherits": "^2.0.4",
147
- "internal-slot": "^1.0.6",
148
- "is-array-buffer": "^3.0.2",
149
- "is-arrayish": "^0.2.1",
150
- "is-bigint": "^1.0.4",
151
- "is-boolean-object": "^1.1.2",
152
- "is-callable": "^1.2.7",
153
- "is-core-module": "^2.13.1",
154
- "is-date-object": "^1.0.5",
155
- "is-extglob": "^2.1.1",
156
- "is-fullwidth-code-point": "^3.0.0",
157
- "is-generator-fn": "^2.1.0",
158
- "is-glob": "^4.0.3",
159
- "is-negative-zero": "^2.0.2",
160
- "is-number": "^7.0.0",
161
- "is-number-object": "^1.0.7",
162
- "is-path-inside": "^3.0.3",
163
- "is-regex": "^1.1.4",
164
- "is-shared-array-buffer": "^1.0.2",
165
- "is-stream": "^2.0.1",
166
- "is-string": "^1.0.7",
167
- "is-symbol": "^1.0.4",
168
- "is-typed-array": "^1.1.12",
169
- "is-weakref": "^1.0.2",
170
- "isarray": "^2.0.5",
171
- "isexe": "^2.0.0",
172
- "istanbul-lib-coverage": "^3.2.2",
173
- "istanbul-lib-instrument": "^6.0.1",
174
- "istanbul-lib-report": "^3.0.1",
175
- "istanbul-lib-source-maps": "^4.0.1",
176
- "istanbul-reports": "^3.1.6",
177
- "jest-changed-files": "^29.7.0",
178
- "jest-circus": "^29.7.0",
179
- "jest-cli": "^29.7.0",
180
- "jest-config": "^29.7.0",
181
- "jest-diff": "^29.7.0",
182
- "jest-docblock": "^29.7.0",
183
- "jest-each": "^29.7.0",
184
- "jest-environment-node": "^29.7.0",
185
- "jest-get-type": "^29.6.3",
186
- "jest-haste-map": "^29.7.0",
187
- "jest-leak-detector": "^29.7.0",
188
- "jest-matcher-utils": "^29.7.0",
189
- "jest-message-util": "^29.7.0",
190
- "jest-mock": "^29.7.0",
191
- "jest-pnp-resolver": "^1.2.3",
192
- "jest-regex-util": "^29.6.3",
193
- "jest-resolve": "^29.7.0",
194
- "jest-resolve-dependencies": "^29.7.0",
195
- "jest-runner": "^29.7.0",
196
- "jest-runtime": "^29.7.0",
197
- "jest-snapshot": "^29.7.0",
198
- "jest-util": "^29.7.0",
199
- "jest-validate": "^29.7.0",
200
- "jest-watcher": "^29.7.0",
201
- "jest-worker": "^29.7.0",
202
- "js-tokens": "^4.0.0",
203
- "js-yaml": "^4.1.0",
204
- "jsesc": "^2.5.2",
205
- "json-buffer": "^3.0.1",
206
- "json-parse-even-better-errors": "^2.3.1",
207
- "json-schema-traverse": "^0.4.1",
208
- "json-stable-stringify-without-jsonify": "^1.0.1",
209
- "json5": "^2.2.3",
210
- "keyv": "^4.5.4",
211
- "kleur": "^3.0.3",
212
- "leven": "^3.1.0",
213
- "levn": "^0.4.1",
214
- "lines-and-columns": "^1.2.4",
215
- "locate-path": "^6.0.0",
216
- "lodash.merge": "^4.6.2",
217
- "lru-cache": "^5.1.1",
218
- "make-dir": "^4.0.0",
219
- "makeerror": "^1.0.12",
220
- "merge-stream": "^2.0.0",
221
- "micromatch": "^4.0.5",
222
- "mimic-fn": "^2.1.0",
223
- "minimatch": "^3.1.2",
224
- "minimist": "^1.2.8",
225
- "ms": "^2.1.2",
226
- "natural-compare": "^1.4.0",
227
- "node-int64": "^0.4.0",
228
- "node-releases": "^2.0.14",
229
- "normalize-path": "^3.0.0",
230
- "npm-run-path": "^4.0.1",
231
- "object-inspect": "^1.13.1",
232
- "object-keys": "^1.1.1",
233
- "object.assign": "^4.1.5",
234
- "object.fromentries": "^2.0.7",
235
- "object.groupby": "^1.0.1",
236
- "object.values": "^1.1.7",
237
- "once": "^1.4.0",
238
- "onetime": "^5.1.2",
239
- "optionator": "^0.9.3",
240
- "p-limit": "^3.1.0",
241
- "p-locate": "^5.0.0",
242
- "p-try": "^2.2.0",
243
- "parent-module": "^1.0.1",
244
- "parse-json": "^5.2.0",
245
- "path-exists": "^4.0.0",
246
- "path-is-absolute": "^1.0.1",
247
- "path-key": "^3.1.1",
248
- "path-parse": "^1.0.7",
249
- "picocolors": "^1.0.0",
250
- "picomatch": "^2.3.1",
251
- "pirates": "^4.0.6",
252
- "pkg-dir": "^4.2.0",
253
- "prelude-ls": "^1.2.1",
254
- "pretty-format": "^29.7.0",
255
- "prompts": "^2.4.2",
256
- "punycode": "^2.3.1",
257
- "pure-rand": "^6.0.4",
258
- "queue-microtask": "^1.2.3",
259
- "react-is": "^18.2.0",
260
- "regexp.prototype.flags": "^1.5.1",
261
- "regexpp": "^3.2.0",
262
- "require-directory": "^2.1.1",
263
- "resolve": "^1.22.8",
264
- "resolve-cwd": "^3.0.0",
265
- "resolve-from": "^4.0.0",
266
- "resolve.exports": "^2.0.2",
267
- "reusify": "^1.0.4",
268
- "rimraf": "^3.0.2",
269
- "run-parallel": "^1.2.0",
270
- "safe-array-concat": "^1.0.1",
271
- "safe-regex-test": "^1.0.0",
272
- "semver": "^6.3.1",
273
- "set-function-length": "^1.1.1",
274
- "set-function-name": "^2.0.1",
275
- "shebang-command": "^2.0.0",
276
- "shebang-regex": "^3.0.0",
277
- "side-channel": "^1.0.4",
278
- "signal-exit": "^3.0.7",
279
- "sisteransi": "^1.0.5",
280
- "slash": "^3.0.0",
281
- "source-map": "^0.6.1",
282
- "source-map-support": "^0.5.13",
283
- "sprintf-js": "^1.0.3",
284
- "stack-utils": "^2.0.6",
285
- "string-length": "^4.0.2",
286
- "string-width": "^4.2.3",
287
- "string.prototype.trim": "^1.2.8",
288
- "string.prototype.trimend": "^1.0.7",
289
- "string.prototype.trimstart": "^1.0.7",
290
- "strip-ansi": "^6.0.1",
291
- "strip-bom": "^4.0.0",
292
- "strip-final-newline": "^2.0.0",
293
- "strip-json-comments": "^3.1.1",
294
- "supports-color": "^7.2.0",
295
- "supports-preserve-symlinks-flag": "^1.0.0",
296
- "test-exclude": "^6.0.0",
297
- "text-table": "^0.2.0",
298
- "tmpl": "^1.0.5",
299
- "to-fast-properties": "^2.0.0",
300
- "to-regex-range": "^5.0.1",
301
- "tsconfig-paths": "^3.15.0",
302
- "type-check": "^0.4.0",
303
- "type-detect": "^4.0.8",
304
- "type-fest": "^0.20.2",
305
- "typed-array-buffer": "^1.0.0",
306
- "typed-array-byte-length": "^1.0.0",
307
- "typed-array-byte-offset": "^1.0.0",
308
- "typed-array-length": "^1.0.4",
309
- "unbox-primitive": "^1.0.2",
310
- "undici-types": "^5.26.5",
311
- "update-browserslist-db": "^1.0.13",
312
- "uri-js": "^4.4.1",
313
- "v8-to-istanbul": "^9.2.0",
314
- "walker": "^1.0.8",
315
- "which": "^2.0.2",
316
- "which-boxed-primitive": "^1.0.2",
317
- "which-typed-array": "^1.1.13",
318
- "wrap-ansi": "^7.0.0",
319
- "wrappy": "^1.0.2",
320
- "write-file-atomic": "^4.0.2",
321
- "y18n": "^5.0.8",
322
- "yallist": "^3.1.1",
323
- "yargs": "^17.7.2",
324
- "yargs-parser": "^21.1.1",
325
- "yocto-queue": "^0.1.0"
326
- },
327
25
  "repository": {
328
26
  "type": "git",
329
27
  "url": "git+https://github.com/dubstar-04/Design-Core.git"
@@ -337,4 +35,4 @@
337
35
  "url": "https://github.com/dubstar-04/Design-Core/issues"
338
36
  },
339
37
  "homepage": "https://github.com/dubstar-04/Design-Core#readme"
340
- }
38
+ }
@@ -0,0 +1,211 @@
1
+ import { AlignedDimension } from '../../core/dimensions/alignedDimension.js';
2
+ import { Point } from '../../core/entities/point.js';
3
+ import { DesignCore } from '../../core/designCore.js';
4
+ import { Core } from '../../core/core/core.js';
5
+ import { Line } from '../../core/entities/line.js';
6
+ import { File, withMockInput } from '../test-helpers/test-helpers.js';
7
+
8
+ // initialise core
9
+ new Core();
10
+
11
+ // Test cases for user input
12
+ const scenarios = [
13
+
14
+ { desc: 'Aligned dimension from point selection',
15
+ input: [new Point(), new Point(10, 0), new Point(5, 5)],
16
+ selectedItems: [],
17
+ expectedDimType: 1,
18
+ dimensionValue: 10,
19
+ },
20
+ ];
21
+
22
+ test.each(scenarios)('Dimension.execute handles $desc', async (scenario) => {
23
+ const { input, selectedItems, expectedDimType, dimensionValue } = scenario;
24
+
25
+ await withMockInput(DesignCore.Scene, input, async () => {
26
+ const dim = new AlignedDimension();
27
+ await dim.execute();
28
+
29
+ expect(dim.dimType.getBaseDimType()).toBe(expectedDimType);
30
+ // get the text entities from the dimension block
31
+ const dimensionBlockEntities = dim.buildDimension();
32
+ expect(dimensionBlockEntities.length).toBe(7);
33
+
34
+ // check if the text value matches the expected dimension value
35
+ for (const entity of dimensionBlockEntities) {
36
+ if (entity.type === 'Text') {
37
+ expect(Number(entity.string)).toBeCloseTo(dimensionValue);
38
+ }
39
+ }
40
+ }, { selectedItems });
41
+ });
42
+
43
+ test('constructor sets default properties', () => {
44
+ const dim = new AlignedDimension();
45
+ expect(dim).toBeInstanceOf(AlignedDimension);
46
+ expect(dim.points).toBeDefined();
47
+ });
48
+
49
+
50
+ test('register returns command object', () => {
51
+ expect(AlignedDimension.register()).toEqual({ command: 'AlignedDimension', shortcut: 'DIMALI' });
52
+ });
53
+
54
+
55
+ describe('AlignedDimension.getPointsFromSelection', () => {
56
+ const scenarios = [
57
+ {
58
+ desc: 'horizontal line',
59
+ pt1: new Point(0, 0),
60
+ pt2: new Point(10, 0),
61
+ textPos: new Point(5, 5),
62
+ expected: {
63
+ text: { x: 5, y: 5 },
64
+ arrow: { x: 10, y: 5 },
65
+ },
66
+ },
67
+ {
68
+ desc: 'vertical line',
69
+ pt1: new Point(0, 0),
70
+ pt2: new Point(0, 10),
71
+ textPos: new Point(5, 5),
72
+ expected: {
73
+ text: { x: 5, y: 5 },
74
+ arrow: { x: 5, y: 10 },
75
+ },
76
+ },
77
+ {
78
+ desc: 'diagonal line',
79
+ pt1: new Point(0, 0),
80
+ pt2: new Point(10, 10),
81
+ textPos: new Point(5, 0),
82
+ expected: {
83
+ text: { x: 5, y: 0 },
84
+ arrow: { x: 12.5, y: 7.5 },
85
+ },
86
+ },
87
+ ];
88
+
89
+ test.each(scenarios)('returns correct sequenced points for $desc', ({ pt1, pt2, textPos, expected }) => {
90
+ const line = new Line({ points: [pt1, pt2] });
91
+ const result = AlignedDimension.getPointsFromSelection([line], textPos);
92
+ expect(result).toHaveLength(4);
93
+ expect(result[0].sequence).toBe(13);
94
+ expect(result[1].sequence).toBe(14);
95
+ expect(result[2].sequence).toBe(11);
96
+ expect(result[3].sequence).toBe(10);
97
+ // check text position
98
+ expect(result[2].x).toBeCloseTo(expected.text.x);
99
+ expect(result[2].y).toBeCloseTo(expected.text.y);
100
+ // check arrow position
101
+ expect(result[3].x).toBeCloseTo(expected.arrow.x);
102
+ expect(result[3].y).toBeCloseTo(expected.arrow.y);
103
+ });
104
+ });
105
+
106
+ test('AlignedDimension.preview runs without error and calls createTempItem', () => {
107
+ const origCreateTempItem = DesignCore.Scene.tempEntities.create;
108
+ const origPointOnScene = DesignCore.Mouse.pointOnScene;
109
+ // Manual mock for createTempItem
110
+ const createTempItemCalls = [];
111
+ DesignCore.Scene.tempEntities.create = function(type, obj) {
112
+ createTempItemCalls.push([type, obj]);
113
+ };
114
+ // Manual mock for pointOnScene
115
+ DesignCore.Mouse.pointOnScene = function() {
116
+ return new Point(5, 5);
117
+ };
118
+
119
+ // Test with 1 point (should call createTempItem with 'Line')
120
+ const dim1 = new AlignedDimension();
121
+ dim1.points = [new Point(0, 0)];
122
+ expect(() => dim1.preview()).not.toThrow();
123
+ expect(createTempItemCalls.some((call) => call[0] === 'Line')).toBe(true);
124
+
125
+ // Test with >1 point (should call createTempItem with this.type)
126
+ const dim2 = new AlignedDimension();
127
+ dim2.points = [new Point(0, 0), new Point(10, 0), new Point(5, 5)];
128
+ expect(() => dim2.preview()).not.toThrow();
129
+ expect(createTempItemCalls.some((call) => call[0] === dim2.type)).toBe(true);
130
+
131
+ // Restore
132
+ DesignCore.Scene.tempEntities.create = origCreateTempItem;
133
+ DesignCore.Mouse.pointOnScene = origPointOnScene;
134
+ });
135
+
136
+ test('Test AlignedDimension.dxf', () => {
137
+ const points = [];
138
+
139
+ const Pt13 = new Point(0, 0);
140
+ Pt13.sequence = 13;
141
+ points.push(Pt13);
142
+
143
+ const Pt14 = new Point(10, 0);
144
+ Pt14.sequence = 14;
145
+ points.push(Pt14);
146
+
147
+ const Pt10 = new Point(5, 5);
148
+ Pt10.sequence = 10;
149
+ points.push(Pt10);
150
+
151
+ const Pt11 = new Point(5, 5);
152
+ Pt11.sequence = 11;
153
+ points.push(Pt11);
154
+
155
+ points.push(Pt10, Pt14, Pt13, Pt11);
156
+
157
+ const dimension = new AlignedDimension({ points: points, handle: '1' });
158
+ let file = new File();
159
+ dimension.dxf(file);
160
+ // console.log(file.contents);
161
+
162
+ const dxfString = `0
163
+ DIMENSION
164
+ 5
165
+ 1
166
+ 100
167
+ AcDbEntity
168
+ 100
169
+ AcDbDimension
170
+ 8
171
+ 0
172
+ 10
173
+ 5
174
+ 20
175
+ 5
176
+ 30
177
+ 0.0
178
+ 11
179
+ 5
180
+ 21
181
+ 5
182
+ 31
183
+ 0.0
184
+ 70
185
+ 1
186
+ 3
187
+ STANDARD
188
+ 100
189
+ AcDbAlignedDimension
190
+ 13
191
+ 0
192
+ 23
193
+ 0
194
+ 33
195
+ 0.0
196
+ 14
197
+ 10
198
+ 24
199
+ 0
200
+ 34
201
+ 0.0
202
+ `;
203
+
204
+ expect(file.contents).toEqual(dxfString);
205
+
206
+ // create new entity from entity data to ensure all props are loaded
207
+ const newDimension = new AlignedDimension(dimension);
208
+ file = new File();
209
+ newDimension.dxf(file);
210
+ expect(file.contents).toEqual(dxfString);
211
+ });