@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.
- package/.eslintrc.json +14 -7
- package/.github/workflows/DesignCoreQA.yml +3 -1
- package/README.md +11 -4
- package/TODO.md +19 -0
- package/core/core/core.js +49 -42
- package/core/designCore.js +61 -2
- package/core/dimensions/alignedDimension.js +142 -0
- package/core/dimensions/angularDimension.js +550 -0
- package/core/dimensions/baseCircularDimension.js +244 -0
- package/core/dimensions/baseDimension.js +558 -0
- package/core/dimensions/baseLinearDimension.js +371 -0
- package/core/dimensions/diametricDimension.js +82 -0
- package/core/dimensions/dimension.js +298 -0
- package/core/dimensions/linearDimension.js +29 -0
- package/core/dimensions/radialDimension.js +78 -0
- package/core/dimensions/rotatedDimension.js +167 -0
- package/core/entities/arc.js +314 -60
- package/core/entities/arctext.js +642 -0
- package/core/entities/basePolyline.js +553 -94
- package/core/entities/circle.js +181 -54
- package/core/entities/entity.js +154 -74
- package/core/entities/hatch.js +807 -0
- package/core/entities/insert.js +200 -39
- package/core/entities/line.js +196 -134
- package/core/entities/lwpolyline.js +21 -44
- package/core/entities/point.js +194 -29
- package/core/entities/polyline.js +54 -7
- package/core/entities/rectangle.js +43 -13
- package/core/entities/solid.js +43 -6
- package/core/entities/text.js +324 -181
- package/core/lib/boundingBox.js +73 -13
- package/core/lib/canvas.js +256 -65
- package/core/lib/clipboard.js +198 -0
- package/core/lib/colour.js +144 -0
- package/core/lib/colours.js +367 -301
- package/core/lib/commandLine.js +16 -28
- package/core/lib/commandManager.js +115 -58
- package/core/lib/constants.js +23 -0
- package/core/lib/dxf/dxf.js +249 -34
- package/core/lib/dxf/dxfFile.js +23 -38
- package/core/lib/dxf/dxfIterator.js +17 -5
- package/core/lib/dxf/dxfRead.js +23 -7
- package/core/lib/dxf/dxfWrite.js +39 -129
- package/core/lib/dxf/handleManager.js +97 -0
- package/core/lib/dxf/sections/blocks.js +16 -2
- package/core/lib/dxf/sections/entities.js +17 -3
- package/core/lib/dxf/sections/header.js +10 -1
- package/core/lib/dxf/sections/objects.js +36 -0
- package/core/lib/dxf/sections/section.js +43 -5
- package/core/lib/dxf/sections/tables.js +17 -3
- package/core/lib/entityManager.js +178 -0
- package/core/lib/fileio.js +14 -4
- package/core/lib/headers.js +229 -0
- package/core/lib/input.js +46 -0
- package/core/lib/inputManager.js +199 -194
- package/core/lib/intersect.js +341 -468
- package/core/lib/logging.js +25 -1
- package/core/lib/matrix.js +6 -8
- package/core/lib/mouse.js +24 -79
- package/core/lib/patterns.js +690 -0
- package/core/lib/promptOptions.js +133 -0
- package/core/lib/scene.js +71 -174
- package/core/lib/selectionManager.js +74 -48
- package/core/lib/selectionWindow.js +24 -10
- package/core/lib/settings.js +18 -11
- package/core/lib/snapping.js +129 -21
- package/core/lib/stateManager.js +288 -0
- package/core/lib/strings.js +57 -5
- package/core/lib/utils.js +95 -11
- package/core/objects/dictionary.js +43 -0
- package/core/objects/dictionaryManager.js +80 -0
- package/core/properties/dimType.js +117 -0
- package/core/properties/flags.js +66 -0
- package/core/properties/property.js +26 -0
- package/core/properties/propertyManager.js +65 -19
- package/core/tables/appId.js +31 -0
- package/core/tables/appIdManager.js +44 -0
- package/core/tables/block.js +323 -0
- package/core/tables/blockManager.js +48 -0
- package/core/tables/blockRecord.js +29 -0
- package/core/tables/blockRecordManager.js +37 -0
- package/core/tables/dimStyle.js +627 -0
- package/core/tables/dimStyleManager.js +187 -0
- package/core/tables/endblk.js +28 -0
- package/core/tables/layer.js +219 -0
- package/core/tables/layerManager.js +47 -0
- package/core/tables/ltype.js +85 -0
- package/core/tables/ltypeManager.js +65 -0
- package/core/tables/style.js +145 -0
- package/core/tables/styleManager.js +55 -0
- package/core/tables/styleManagerBase.js +110 -0
- package/core/tables/tableManagerBase.js +354 -0
- package/core/tables/ucs.js +28 -0
- package/core/tables/ucsManager.js +44 -0
- package/core/tables/view.js +28 -0
- package/core/tables/viewManager.js +44 -0
- package/core/tables/vport.js +70 -0
- package/core/tables/vportManager.js +65 -0
- package/core/tools/chamfer.js +343 -0
- package/core/tools/chamferFilletBase.js +162 -0
- package/core/tools/copy.js +68 -40
- package/core/tools/copybase.js +65 -0
- package/core/tools/copyclip.js +59 -0
- package/core/tools/cornerEntity.js +138 -0
- package/core/tools/cutclip.js +72 -0
- package/core/tools/distance.js +37 -9
- package/core/tools/erase.js +43 -13
- package/core/tools/explode.js +117 -0
- package/core/tools/extend.js +71 -32
- package/core/tools/fillet.js +336 -0
- package/core/tools/identify.js +33 -6
- package/core/tools/matchProp.js +106 -0
- package/core/tools/mirror.js +141 -0
- package/core/tools/move.js +65 -32
- package/core/tools/offset.js +321 -0
- package/core/tools/pan.js +54 -0
- package/core/tools/pasteclip.js +93 -0
- package/core/tools/purge.js +90 -0
- package/core/tools/rotate.js +105 -70
- package/core/tools/scale.js +166 -0
- package/core/tools/tool.js +14 -4
- package/core/tools/trim.js +71 -32
- package/core/tools/zoom.js +152 -0
- package/package.json +3 -305
- package/test/dimensions/alignedDimension.test.js +211 -0
- package/test/dimensions/angularDimension.test.js +243 -0
- package/test/dimensions/baseDimension.test.js +239 -0
- package/test/dimensions/diametricDimension.test.js +203 -0
- package/test/dimensions/dimension.test.js +102 -0
- package/test/dimensions/radialDimension.test.js +203 -0
- package/test/dimensions/rotatedDimension.test.js +224 -0
- package/test/entities/arc.test.js +463 -41
- package/test/entities/arctext.test.js +329 -0
- package/test/entities/basePolyline.test.js +459 -10
- package/test/entities/circle.test.js +312 -7
- package/test/entities/entity.test.js +28 -9
- package/test/entities/hatch.test.js +606 -0
- package/test/entities/insert.test.js +90 -0
- package/test/entities/line.test.js +182 -6
- package/test/entities/point.test.js +375 -37
- package/test/entities/solid.test.js +156 -0
- package/test/entities/text.test.js +533 -7
- package/test/integration/exportIntegration.reference.dxf +1706 -0
- package/test/integration/exportIntegration.test.js +186 -0
- package/test/integration/importExportIntegration.test.js +126 -0
- package/test/integration/intersectionIntegration.test.js +880 -0
- package/test/integration/userInputIntegration.reference.dxf +1410 -0
- package/test/integration/userInputIntegration.test.js +269 -0
- package/test/lib/boundingBox.test.js +26 -2
- package/test/lib/canvas.test.js +613 -5
- package/test/lib/clipboard.test.js +70 -0
- package/test/lib/colour.test.js +114 -0
- package/test/lib/colours.test.js +63 -18
- package/test/lib/commandLine.test.js +159 -22
- package/test/lib/commandManager.test.js +4 -4
- package/test/lib/constants.test.js +9 -0
- package/test/lib/dxf/dxfFile.test.js +6 -2
- package/test/lib/dxf/dxfIterator.test.js +1 -1
- package/test/lib/dxf/dxfWrite.test.js +173 -0
- package/test/lib/dxf/handleManager.test.js +137 -0
- package/test/lib/dxf/sections/blocks.test.js +5 -5
- package/test/lib/dxf/sections/entities.test.js +4 -4
- package/test/lib/dxf/sections/header.test.js +18 -4
- package/test/lib/dxf/sections/objects.test.js +132 -0
- package/test/lib/dxf/sections/section.test.js +29 -29
- package/test/lib/dxf/sections/tables.test.js +3 -3
- package/test/lib/entityManager.test.js +163 -0
- package/test/lib/headers.test.js +233 -0
- package/test/lib/inputManager.test.js +1144 -5
- package/test/lib/intersect.test.js +454 -331
- package/test/lib/logging.test.js +1 -1
- package/test/lib/matrix.test.js +1 -1
- package/test/lib/mouse.test.js +327 -4
- package/test/lib/patterns.test.js +105 -0
- package/test/lib/promptOptions.test.js +179 -0
- package/test/lib/scene.test.js +16 -52
- package/test/lib/selectionManager.test.js +17 -5
- package/test/lib/settings.test.js +111 -5
- package/test/lib/snapping.test.js +142 -4
- package/test/lib/stateManager.test.js +155 -0
- package/test/lib/utils.test.js +81 -1
- package/test/objects/dictionary.test.js +81 -0
- package/test/objects/dictionaryManager.test.js +34 -0
- package/test/properties/dimType.test.js +62 -0
- package/test/properties/flags.test.js +164 -0
- package/test/properties/property.test.js +13 -0
- package/test/properties/propertyManager.test.js +10 -11
- package/test/tables/appId.test.js +46 -0
- package/test/tables/appIdManager.test.js +72 -0
- package/test/tables/block.test.js +157 -0
- package/test/tables/blockManager.test.js +52 -0
- package/test/tables/blockRecord.test.js +39 -0
- package/test/tables/blockRecordManager.test.js +60 -0
- package/test/tables/dimstyle.test.js +72 -0
- package/test/tables/endblk.test.js +30 -0
- package/test/tables/layer.test.js +95 -0
- package/test/tables/layerManager.test.js +172 -0
- package/test/{styles → tables}/ltype.test.js +7 -7
- package/test/{styles → tables}/ltypeManager.test.js +2 -2
- package/test/tables/style.test.js +44 -0
- package/test/tables/stylemanagerbase.test.js +220 -0
- package/test/tables/tableManagerBase.test.js +194 -0
- package/test/tables/ucs.test.js +37 -0
- package/test/tables/ucsManager.test.js +48 -0
- package/test/tables/view.test.js +37 -0
- package/test/tables/viewManager.test.js +48 -0
- package/test/tables/vport.test.js +117 -0
- package/test/tables/vportManager.test.js +54 -0
- package/test/test-helpers/test-helpers.js +66 -0
- package/test/tools/chamfer.test.js +970 -0
- package/test/tools/chamferFilletBase.test.js +446 -0
- package/test/tools/copy.test.js +22 -14
- package/test/tools/copybase.test.js +93 -0
- package/test/tools/copyclip.test.js +92 -0
- package/test/tools/cornerEntity.test.js +201 -0
- package/test/tools/cutclip.test.js +94 -0
- package/test/tools/distance.test.js +140 -18
- package/test/tools/erase.test.js +12 -12
- package/test/tools/explode.test.js +45 -0
- package/test/tools/extend.test.js +326 -44
- package/test/tools/fillet.test.js +831 -0
- package/test/tools/identify.test.js +115 -16
- package/test/tools/matchProp.test.js +84 -0
- package/test/tools/mirror.test.js +475 -0
- package/test/tools/move.test.js +75 -19
- package/test/tools/offset.test.js +748 -0
- package/test/tools/pan.test.js +72 -0
- package/test/tools/pasteclip.test.js +100 -0
- package/test/tools/purge.test.js +89 -0
- package/test/tools/rotate.test.js +89 -23
- package/test/tools/scale.test.js +529 -0
- package/test/tools/trim.test.js +419 -84
- package/test/tools/zoom.test.js +504 -0
- package/core/entities/alignedDimension.js +0 -279
- package/core/entities/angularDimension.js +0 -194
- package/core/entities/baseDimension.js +0 -227
- package/core/entities/block.js +0 -247
- package/core/entities/diametricDimension.js +0 -133
- package/core/entities/dimension.js +0 -202
- package/core/entities/radialDimension.js +0 -126
- package/core/styles/dimStyle.js +0 -719
- package/core/styles/dimStyleManager.js +0 -47
- package/core/styles/layer.js +0 -133
- package/core/styles/layerManager.js +0 -40
- package/core/styles/ltype.js +0 -86
- package/core/styles/ltypeManager.js +0 -50
- package/core/styles/style.js +0 -158
- package/core/styles/styleManager.js +0 -43
- package/core/styles/styleManagerBase.js +0 -299
- package/test/entities/block.test.js +0 -22
- package/test/styles/dimstyle.test.js +0 -19
- package/test/styles/layerManager.test.js +0 -150
- package/test/styles/style.test.js +0 -33
- package/test/styles/stylemanagerbase.test.js +0 -219
package/core/lib/commandLine.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {Point} from '../entities/point.js';
|
|
2
|
-
import {Input} from './inputManager.js';
|
|
1
|
+
import { Point } from '../entities/point.js';
|
|
2
|
+
import { Input } from './inputManager.js';
|
|
3
3
|
|
|
4
|
-
import {DesignCore} from '../designCore.js';
|
|
4
|
+
import { DesignCore } from '../designCore.js';
|
|
5
5
|
|
|
6
|
+
/** CommandLine Class */
|
|
6
7
|
export class CommandLine {
|
|
7
|
-
/**
|
|
8
|
-
* Commandline Constructor
|
|
9
|
-
*/
|
|
8
|
+
/** Create Commandline */
|
|
10
9
|
constructor() {
|
|
11
10
|
this.cmdLine = ''; // display string
|
|
12
11
|
this.prompt = 'Command:';
|
|
@@ -42,30 +41,11 @@ export class CommandLine {
|
|
|
42
41
|
* @param {string} prompt
|
|
43
42
|
*/
|
|
44
43
|
setPrompt(prompt) {
|
|
45
|
-
// Parse default options from prompt. Defaults are enclosed in arrows <>
|
|
46
|
-
const expression = new RegExp('<.+>');
|
|
47
|
-
const promptHasDefault = expression.test(prompt);
|
|
48
|
-
const commandDefault = prompt.match(expression);
|
|
49
|
-
|
|
50
44
|
this.prompt = `${prompt}:`;
|
|
51
|
-
this.command =
|
|
45
|
+
this.command = '';
|
|
52
46
|
this.update();
|
|
53
47
|
}
|
|
54
48
|
|
|
55
|
-
/**
|
|
56
|
-
* Checks there is only a single default value supplied and removes the <>
|
|
57
|
-
* @param {Array} commandDefault - Array containing the <default> value
|
|
58
|
-
* @returns value contained within the <>
|
|
59
|
-
*/
|
|
60
|
-
parseCommandDefault(commandDefault) {
|
|
61
|
-
if (commandDefault && commandDefault.length > 1) {
|
|
62
|
-
throw Error('Commands can contain only a single <default>');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const defaultValue = commandDefault.at(0).replace(/<|>/gi, '');
|
|
66
|
-
return defaultValue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
49
|
/**
|
|
70
50
|
* Update the commandline prompt and trigger the callback
|
|
71
51
|
*/
|
|
@@ -78,7 +58,7 @@ export class CommandLine {
|
|
|
78
58
|
|
|
79
59
|
if (DesignCore.Scene.inputManager.activeCommand !== undefined) {
|
|
80
60
|
// TODO: This should call a common function that is currently called mouseMove in the scene class
|
|
81
|
-
DesignCore.Scene.
|
|
61
|
+
DesignCore.Scene.tempEntities.clear();
|
|
82
62
|
DesignCore.Scene.inputManager.activeCommand.preview();
|
|
83
63
|
DesignCore.Canvas.requestPaint();
|
|
84
64
|
}
|
|
@@ -99,7 +79,7 @@ export class CommandLine {
|
|
|
99
79
|
this.enterPressed();
|
|
100
80
|
break;
|
|
101
81
|
case 'Escape':
|
|
102
|
-
|
|
82
|
+
this.escapePressed();
|
|
103
83
|
break;
|
|
104
84
|
case 'Space': // space
|
|
105
85
|
this.spacePressed();
|
|
@@ -158,6 +138,13 @@ export class CommandLine {
|
|
|
158
138
|
}
|
|
159
139
|
}
|
|
160
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Handles presses of the delete key
|
|
143
|
+
*/
|
|
144
|
+
escapePressed() {
|
|
145
|
+
DesignCore.Scene.inputManager.onEscapePressed();
|
|
146
|
+
}
|
|
147
|
+
|
|
161
148
|
/**
|
|
162
149
|
* Handles presses of the delete key
|
|
163
150
|
*/
|
|
@@ -207,6 +194,7 @@ export class CommandLine {
|
|
|
207
194
|
/**
|
|
208
195
|
* Converts input to a type
|
|
209
196
|
* @param {string} input
|
|
197
|
+
* @return {any}
|
|
210
198
|
*/
|
|
211
199
|
parseInput(input) {
|
|
212
200
|
const isNumber = /^[-]?\d+(?:\.\d+)?$/.test(input);
|
|
@@ -1,41 +1,59 @@
|
|
|
1
|
-
import {Line} from '../entities/line.js';
|
|
2
|
-
import {Polyline} from '../entities/polyline.js';
|
|
3
|
-
import {Lwpolyline} from '../entities/lwpolyline.js';
|
|
4
|
-
import {Circle} from '../entities/circle.js';
|
|
5
|
-
import {Arc} from '../entities/arc.js';
|
|
6
|
-
import {Rectangle} from '../entities/rectangle.js';
|
|
1
|
+
import { Line } from '../entities/line.js';
|
|
2
|
+
import { Polyline } from '../entities/polyline.js';
|
|
3
|
+
import { Lwpolyline } from '../entities/lwpolyline.js';
|
|
4
|
+
import { Circle } from '../entities/circle.js';
|
|
5
|
+
import { Arc } from '../entities/arc.js';
|
|
6
|
+
import { Rectangle } from '../entities/rectangle.js';
|
|
7
7
|
// import {Ellipse} from '../entities/ellipse.js';
|
|
8
8
|
// import {Spline} from '../entities/spline.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
9
|
+
import { ArcAlignedText } from '../entities/arctext.js';
|
|
10
|
+
import { Text } from '../entities/text.js';
|
|
11
|
+
import { Block } from '../tables/block.js';
|
|
12
|
+
import { Insert } from '../entities/insert.js';
|
|
13
|
+
import { Hatch } from '../entities/hatch.js';
|
|
14
|
+
/*
|
|
15
|
+
import { Dimension } from '../dimensions/dimension.js';
|
|
16
|
+
import { AlignedDimension } from '../dimensions/alignedDimension.js';
|
|
17
|
+
import { AngularDimension } from '../dimensions/angularDimension.js';
|
|
18
|
+
import { LinearDimension } from '../dimensions/linearDimension.js';
|
|
19
|
+
import { DiametricDimension } from '../dimensions/diametricDimension.js';
|
|
20
|
+
import { RadialDimension } from '../dimensions/radialDimension.js';
|
|
21
|
+
import { RotatedDimension } from '../dimensions/rotatedDimension.js';
|
|
22
|
+
*/
|
|
18
23
|
|
|
19
24
|
// import { Point } from "../entities/point.js"
|
|
20
25
|
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
26
|
+
import { MatchProp } from '../tools/matchProp.js';
|
|
27
|
+
import { Move } from '../tools/move.js';
|
|
28
|
+
import { Copy } from '../tools/copy.js';
|
|
29
|
+
import { Mirror } from '../tools/mirror.js';
|
|
30
|
+
import { Rotate } from '../tools/rotate.js';
|
|
31
|
+
import { Scale } from '../tools/scale.js';
|
|
32
|
+
import { Erase } from '../tools/erase.js';
|
|
33
|
+
import { Explode } from '../tools/explode.js';
|
|
34
|
+
import { Distance } from '../tools/distance.js';
|
|
35
|
+
import { Identify } from '../tools/identify.js';
|
|
36
|
+
import { Extend } from '../tools/extend.js';
|
|
37
|
+
import { Fillet } from '../tools/fillet.js';
|
|
38
|
+
import { Chamfer } from '../tools/chamfer.js';
|
|
39
|
+
import { Trim } from '../tools/trim.js';
|
|
40
|
+
import { Offset } from '../tools/offset.js';
|
|
41
|
+
import { Purge } from '../tools/purge.js';
|
|
42
|
+
import { Pan } from '../tools/pan.js';
|
|
43
|
+
import { Zoom } from '../tools/zoom.js';
|
|
44
|
+
|
|
45
|
+
// Clipboard tools
|
|
46
|
+
import { Copybase } from '../tools/copybase.js';
|
|
47
|
+
import { Copyclip } from '../tools/copyclip.js';
|
|
48
|
+
import { Cutclip } from '../tools/cutclip.js';
|
|
49
|
+
import { Pasteclip } from '../tools/pasteclip.js';
|
|
50
|
+
|
|
51
|
+
import { Utils } from './utils.js';
|
|
52
|
+
import { Strings } from './strings.js';
|
|
53
|
+
import { Logging } from './logging.js';
|
|
54
|
+
|
|
55
|
+
import { DesignCore } from '../designCore.js';
|
|
23
56
|
|
|
24
|
-
import {Rotate} from '../tools/rotate.js';
|
|
25
|
-
import {Erase} from '../tools/erase.js';
|
|
26
|
-
|
|
27
|
-
import {Distance} from '../tools/distance.js';
|
|
28
|
-
import {Identify} from '../tools/identify.js';
|
|
29
|
-
|
|
30
|
-
import {Extend} from '../tools/extend.js';
|
|
31
|
-
import {Trim} from '../tools/trim.js';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import {Utils} from './utils.js';
|
|
35
|
-
import {Strings} from './strings.js';
|
|
36
|
-
import {Logging} from './logging.js';
|
|
37
|
-
|
|
38
|
-
import {DesignCore} from '../designCore.js';
|
|
39
57
|
|
|
40
58
|
const classes = {
|
|
41
59
|
Line,
|
|
@@ -46,29 +64,54 @@ const classes = {
|
|
|
46
64
|
Rectangle,
|
|
47
65
|
// Ellipse,
|
|
48
66
|
// Spline,
|
|
67
|
+
ArcAlignedText,
|
|
49
68
|
Text,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
/*
|
|
70
|
+
Dimension,
|
|
71
|
+
AngularDimension,
|
|
72
|
+
AlignedDimension,
|
|
73
|
+
DiametricDimension,
|
|
74
|
+
LinearDimension,
|
|
75
|
+
RadialDimension,
|
|
76
|
+
RotatedDimension,
|
|
77
|
+
*/
|
|
55
78
|
Block,
|
|
56
79
|
Insert,
|
|
80
|
+
Hatch,
|
|
81
|
+
MatchProp,
|
|
57
82
|
Move,
|
|
58
83
|
Copy,
|
|
84
|
+
Mirror,
|
|
59
85
|
Rotate,
|
|
86
|
+
Scale,
|
|
60
87
|
Erase,
|
|
88
|
+
Explode,
|
|
61
89
|
Distance,
|
|
62
90
|
Identify,
|
|
63
91
|
Extend,
|
|
92
|
+
Fillet,
|
|
93
|
+
Chamfer,
|
|
64
94
|
Trim,
|
|
95
|
+
Offset,
|
|
96
|
+
Purge,
|
|
97
|
+
|
|
98
|
+
Zoom,
|
|
99
|
+
Pan,
|
|
100
|
+
|
|
101
|
+
Copybase,
|
|
102
|
+
Copyclip,
|
|
103
|
+
Cutclip,
|
|
104
|
+
Pasteclip,
|
|
65
105
|
|
|
66
106
|
};
|
|
67
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Command Manager Class
|
|
110
|
+
* Registers a list of available commands
|
|
111
|
+
* Creates new commands
|
|
112
|
+
*/
|
|
68
113
|
export class CommandManager {
|
|
69
|
-
/**
|
|
70
|
-
* CommandManager constructor
|
|
71
|
-
*/
|
|
114
|
+
/** Create CommandManager */
|
|
72
115
|
constructor() {
|
|
73
116
|
// store a list of the available commands
|
|
74
117
|
this.commands = [];
|
|
@@ -91,7 +134,7 @@ export class CommandManager {
|
|
|
91
134
|
|
|
92
135
|
/**
|
|
93
136
|
* Return a list of available commands
|
|
94
|
-
* @
|
|
137
|
+
* @return {Array} array of commands
|
|
95
138
|
*/
|
|
96
139
|
getCommands() {
|
|
97
140
|
return this.commands;
|
|
@@ -100,8 +143,8 @@ export class CommandManager {
|
|
|
100
143
|
/**
|
|
101
144
|
* Create a new instance of type using data
|
|
102
145
|
* @param {string} type
|
|
103
|
-
* @param {
|
|
104
|
-
* @
|
|
146
|
+
* @param {Array} data
|
|
147
|
+
* @return {Object} instance of type
|
|
105
148
|
*/
|
|
106
149
|
createNew(type, data) {
|
|
107
150
|
let newItem;
|
|
@@ -118,7 +161,7 @@ export class CommandManager {
|
|
|
118
161
|
/**
|
|
119
162
|
* Check if input is valid command or shortcut
|
|
120
163
|
* @param {string} input
|
|
121
|
-
* @
|
|
164
|
+
* @return {boolean} boolean
|
|
122
165
|
*/
|
|
123
166
|
isCommandOrShortcut(input) {
|
|
124
167
|
if (input === undefined) {
|
|
@@ -133,20 +176,30 @@ export class CommandManager {
|
|
|
133
176
|
return true;
|
|
134
177
|
}
|
|
135
178
|
|
|
179
|
+
// no matching command found, try to get a fuzzy match
|
|
180
|
+
// get a fuzzy match and notify but only if the user is typing a new command (not mid-command)
|
|
181
|
+
if (DesignCore.Scene.inputManager.activeCommand === undefined) {
|
|
182
|
+
const command = this.getFuzzyMatch(input);
|
|
183
|
+
const shortcut = this.getShortcut(command);
|
|
184
|
+
if (command !== undefined) {
|
|
185
|
+
DesignCore.Core.notify(`${Strings.Message.RECOMMEND} ${command} (${shortcut})`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
136
189
|
// no matching command found
|
|
137
|
-
// get a fuzzy match and notify
|
|
138
|
-
const command = this.getFuzzyMatch(input);
|
|
139
|
-
const shortcut = this.getShortcut(command);
|
|
140
|
-
DesignCore.Core.notify(`${Strings.Message.RECOMMEND} ${command} (${shortcut})`);
|
|
141
190
|
return false;
|
|
142
191
|
}
|
|
143
192
|
|
|
144
193
|
/**
|
|
145
194
|
* Check if shortcut is valid
|
|
146
195
|
* @param {string} shortcut
|
|
147
|
-
* @
|
|
196
|
+
* @return {boolean} boolean
|
|
148
197
|
*/
|
|
149
198
|
isShortcut(shortcut) {
|
|
199
|
+
if (shortcut === undefined || shortcut === null || typeof shortcut !== 'string') {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
150
203
|
const found = this.commands.some((el) => typeof(el.shortcut) !== 'undefined' && el.shortcut.toUpperCase() === shortcut.toUpperCase());
|
|
151
204
|
return found;
|
|
152
205
|
}
|
|
@@ -154,14 +207,14 @@ export class CommandManager {
|
|
|
154
207
|
/**
|
|
155
208
|
* Check if command is valid
|
|
156
209
|
* @param {string} command
|
|
157
|
-
* @
|
|
210
|
+
* @return {boolean} boolean
|
|
158
211
|
*/
|
|
159
212
|
isCommand(command) {
|
|
160
|
-
if (command === undefined || command === null) {
|
|
213
|
+
if (command === undefined || command === null || typeof command !== 'string') {
|
|
161
214
|
return false;
|
|
162
215
|
}
|
|
163
216
|
|
|
164
|
-
const found = this.commands.some((el) => typeof(el.command) !== 'undefined' && el.command.toUpperCase() === command.toUpperCase());
|
|
217
|
+
const found = this.commands.some((el) => typeof (el.command) !== 'undefined' && el.command.toUpperCase() === command.toUpperCase());
|
|
165
218
|
return found;
|
|
166
219
|
}
|
|
167
220
|
|
|
@@ -169,16 +222,16 @@ export class CommandManager {
|
|
|
169
222
|
/**
|
|
170
223
|
* Returns the command for a valid input
|
|
171
224
|
* @param {string} input
|
|
172
|
-
* @
|
|
225
|
+
* @return {string} valid type
|
|
173
226
|
*/
|
|
174
227
|
getCommand(input) {
|
|
175
228
|
let command;
|
|
176
229
|
|
|
177
230
|
if (this.isCommand(input)) {
|
|
178
|
-
const found = this.commands.find((el) => typeof(el.command) !== 'undefined' && el.command.toUpperCase() === input.toUpperCase());
|
|
231
|
+
const found = this.commands.find((el) => typeof (el.command) !== 'undefined' && el.command.toUpperCase() === input.toUpperCase());
|
|
179
232
|
command = found.command;
|
|
180
233
|
} else if (this.isShortcut(input)) {
|
|
181
|
-
const found = this.commands.find((el) => typeof(el.shortcut) !== 'undefined' && el.shortcut.toUpperCase() === input.toUpperCase());
|
|
234
|
+
const found = this.commands.find((el) => typeof (el.shortcut) !== 'undefined' && el.shortcut.toUpperCase() === input.toUpperCase());
|
|
182
235
|
command = found.command;
|
|
183
236
|
}
|
|
184
237
|
|
|
@@ -193,13 +246,13 @@ export class CommandManager {
|
|
|
193
246
|
/**
|
|
194
247
|
* Returns the shortcut for a valid command
|
|
195
248
|
* @param {string} command
|
|
196
|
-
* @
|
|
249
|
+
* @return {string} shortcut
|
|
197
250
|
*/
|
|
198
251
|
getShortcut(command) {
|
|
199
252
|
let shortcut;
|
|
200
253
|
|
|
201
254
|
if (this.isCommand(command)) {
|
|
202
|
-
const found = this.commands.find((el) => typeof(el.command) !== 'undefined' && el.command.toUpperCase() === command.toUpperCase());
|
|
255
|
+
const found = this.commands.find((el) => typeof (el.command) !== 'undefined' && el.command.toUpperCase() === command.toUpperCase());
|
|
203
256
|
shortcut = found.shortcut;
|
|
204
257
|
}
|
|
205
258
|
|
|
@@ -210,9 +263,13 @@ export class CommandManager {
|
|
|
210
263
|
/**
|
|
211
264
|
* Returns a fuzzy match to the input command
|
|
212
265
|
* @param {string} input
|
|
213
|
-
* @
|
|
266
|
+
* @return {string} fuzzy matched command
|
|
214
267
|
*/
|
|
215
268
|
getFuzzyMatch(input) {
|
|
269
|
+
if (input === undefined || input === null || typeof input !== 'string') {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
|
|
216
273
|
let score = Infinity;
|
|
217
274
|
let fuzzyMatch;
|
|
218
275
|
for (let i = 0; i < this.commands.length; i++) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants
|
|
3
|
+
* Shared numeric constants used across the codebase.
|
|
4
|
+
*/
|
|
5
|
+
export class Constants {
|
|
6
|
+
/**
|
|
7
|
+
* Geometric tolerance values.
|
|
8
|
+
* Values whose absolute magnitude falls below the relevant threshold
|
|
9
|
+
* are treated as zero for that comparison.
|
|
10
|
+
*/
|
|
11
|
+
static Tolerance = {
|
|
12
|
+
/** Near-zero threshold for floating-point geometric comparisons (1e-10). */
|
|
13
|
+
EPSILON: 1e-10,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Numeric precision values used for rounding and output formatting.
|
|
18
|
+
*/
|
|
19
|
+
static Precision = {
|
|
20
|
+
/** Number of decimal places used by Utils.round(). */
|
|
21
|
+
DECIMALPLACES: 5,
|
|
22
|
+
};
|
|
23
|
+
}
|