@teachinglab/omd 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -0
- package/canvas/core/canvasConfig.js +203 -0
- package/canvas/core/omdCanvas.js +475 -0
- package/canvas/drawing/segment.js +168 -0
- package/canvas/drawing/stroke.js +386 -0
- package/canvas/events/eventManager.js +435 -0
- package/canvas/events/pointerEventHandler.js +263 -0
- package/canvas/features/focusFrameManager.js +287 -0
- package/canvas/index.js +49 -0
- package/canvas/tools/eraserTool.js +322 -0
- package/canvas/tools/pencilTool.js +319 -0
- package/canvas/tools/selectTool.js +457 -0
- package/canvas/tools/tool.js +223 -0
- package/canvas/tools/toolManager.js +394 -0
- package/canvas/ui/cursor.js +438 -0
- package/canvas/ui/toolbar.js +304 -0
- package/canvas/utils/boundingBox.js +378 -0
- package/canvas/utils/mathUtils.js +259 -0
- package/docs/api/configuration-options.md +104 -0
- package/docs/api/eventManager.md +68 -0
- package/docs/api/focusFrameManager.md +150 -0
- package/docs/api/index.md +91 -0
- package/docs/api/main.md +58 -0
- package/docs/api/omdBinaryExpressionNode.md +227 -0
- package/docs/api/omdCanvas.md +142 -0
- package/docs/api/omdConfigManager.md +192 -0
- package/docs/api/omdConstantNode.md +117 -0
- package/docs/api/omdDisplay.md +121 -0
- package/docs/api/omdEquationNode.md +161 -0
- package/docs/api/omdEquationSequenceNode.md +301 -0
- package/docs/api/omdEquationStack.md +139 -0
- package/docs/api/omdFunctionNode.md +141 -0
- package/docs/api/omdGroupNode.md +182 -0
- package/docs/api/omdHelpers.md +96 -0
- package/docs/api/omdLeafNode.md +163 -0
- package/docs/api/omdNode.md +101 -0
- package/docs/api/omdOperationDisplayNode.md +139 -0
- package/docs/api/omdOperatorNode.md +127 -0
- package/docs/api/omdParenthesisNode.md +122 -0
- package/docs/api/omdPopup.md +117 -0
- package/docs/api/omdPowerNode.md +127 -0
- package/docs/api/omdRationalNode.md +128 -0
- package/docs/api/omdSequenceNode.md +128 -0
- package/docs/api/omdSimplification.md +110 -0
- package/docs/api/omdSqrtNode.md +79 -0
- package/docs/api/omdStepVisualizer.md +115 -0
- package/docs/api/omdStepVisualizerHighlighting.md +61 -0
- package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
- package/docs/api/omdStepVisualizerLayout.md +60 -0
- package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
- package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
- package/docs/api/omdToolbar.md +102 -0
- package/docs/api/omdTranscriptionService.md +76 -0
- package/docs/api/omdTreeDiff.md +134 -0
- package/docs/api/omdUnaryExpressionNode.md +174 -0
- package/docs/api/omdUtilities.md +70 -0
- package/docs/api/omdVariableNode.md +148 -0
- package/docs/api/selectTool.md +74 -0
- package/docs/api/simplificationEngine.md +98 -0
- package/docs/api/simplificationRules.md +77 -0
- package/docs/api/simplificationUtils.md +64 -0
- package/docs/api/transcribe.md +43 -0
- package/docs/api-reference.md +85 -0
- package/docs/index.html +454 -0
- package/docs/user-guide.md +9 -0
- package/index.js +67 -0
- package/omd/config/omdConfigManager.js +267 -0
- package/omd/core/index.js +150 -0
- package/omd/core/omdEquationStack.js +347 -0
- package/omd/core/omdUtilities.js +115 -0
- package/omd/display/omdDisplay.js +443 -0
- package/omd/display/omdToolbar.js +502 -0
- package/omd/nodes/omdBinaryExpressionNode.js +460 -0
- package/omd/nodes/omdConstantNode.js +142 -0
- package/omd/nodes/omdEquationNode.js +1223 -0
- package/omd/nodes/omdEquationSequenceNode.js +1273 -0
- package/omd/nodes/omdFunctionNode.js +352 -0
- package/omd/nodes/omdGroupNode.js +68 -0
- package/omd/nodes/omdLeafNode.js +77 -0
- package/omd/nodes/omdNode.js +557 -0
- package/omd/nodes/omdOperationDisplayNode.js +322 -0
- package/omd/nodes/omdOperatorNode.js +109 -0
- package/omd/nodes/omdParenthesisNode.js +293 -0
- package/omd/nodes/omdPowerNode.js +236 -0
- package/omd/nodes/omdRationalNode.js +295 -0
- package/omd/nodes/omdSqrtNode.js +308 -0
- package/omd/nodes/omdUnaryExpressionNode.js +178 -0
- package/omd/nodes/omdVariableNode.js +123 -0
- package/omd/simplification/omdSimplification.js +171 -0
- package/omd/simplification/omdSimplificationEngine.js +886 -0
- package/omd/simplification/package.json +6 -0
- package/omd/simplification/rules/binaryRules.js +1037 -0
- package/omd/simplification/rules/functionRules.js +111 -0
- package/omd/simplification/rules/index.js +48 -0
- package/omd/simplification/rules/parenthesisRules.js +19 -0
- package/omd/simplification/rules/powerRules.js +143 -0
- package/omd/simplification/rules/rationalRules.js +475 -0
- package/omd/simplification/rules/sqrtRules.js +48 -0
- package/omd/simplification/rules/unaryRules.js +37 -0
- package/omd/simplification/simplificationRules.js +32 -0
- package/omd/simplification/simplificationUtils.js +1056 -0
- package/omd/step-visualizer/omdStepVisualizer.js +597 -0
- package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
- package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
- package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
- package/omd/utils/omdNodeOverlay.js +638 -0
- package/omd/utils/omdPopup.js +1084 -0
- package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
- package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
- package/omd/utils/omdTranscriptionService.js +125 -0
- package/omd/utils/omdTreeDiff.js +734 -0
- package/package.json +46 -0
- package/src/index.js +62 -0
- package/src/json-schemas.md +109 -0
- package/src/omd-json-samples.js +115 -0
- package/src/omd.js +109 -0
- package/src/omdApp.js +391 -0
- package/src/omdAppCanvas.js +336 -0
- package/src/omdBalanceHanger.js +172 -0
- package/src/omdColor.js +13 -0
- package/src/omdCoordinatePlane.js +467 -0
- package/src/omdEquation.js +125 -0
- package/src/omdExpression.js +104 -0
- package/src/omdFunction.js +113 -0
- package/src/omdMetaExpression.js +287 -0
- package/src/omdNaturalExpression.js +564 -0
- package/src/omdNode.js +384 -0
- package/src/omdNumber.js +53 -0
- package/src/omdNumberLine.js +107 -0
- package/src/omdNumberTile.js +119 -0
- package/src/omdOperator.js +73 -0
- package/src/omdPowerExpression.js +92 -0
- package/src/omdProblem.js +55 -0
- package/src/omdRatioChart.js +232 -0
- package/src/omdRationalExpression.js +115 -0
- package/src/omdSampleData.js +215 -0
- package/src/omdShapes.js +476 -0
- package/src/omdSpinner.js +148 -0
- package/src/omdString.js +39 -0
- package/src/omdTable.js +369 -0
- package/src/omdTapeDiagram.js +245 -0
- package/src/omdTerm.js +92 -0
- package/src/omdTileEquation.js +349 -0
- package/src/omdVariable.js +51 -0
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
export class Cursor {
|
|
2
|
+
/**
|
|
3
|
+
* @param {OMDCanvas} canvas - Canvas instance
|
|
4
|
+
*/
|
|
5
|
+
constructor(canvas) {
|
|
6
|
+
this.canvas = canvas;
|
|
7
|
+
this.isVisible = true;
|
|
8
|
+
this.currentShape = 'pencil';
|
|
9
|
+
this.size = 20;
|
|
10
|
+
this.color = '#007bff';
|
|
11
|
+
|
|
12
|
+
// Create cursor element
|
|
13
|
+
this._createElement();
|
|
14
|
+
|
|
15
|
+
// Add to UI layer
|
|
16
|
+
this.canvas.uiLayer.appendChild(this.element);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Create the cursor SVG element
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
_createElement() {
|
|
24
|
+
this.element = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
25
|
+
this.element.setAttribute('class', 'omd-cursor');
|
|
26
|
+
this.element.style.pointerEvents = 'none';
|
|
27
|
+
this.element.style.opacity = '0.8';
|
|
28
|
+
|
|
29
|
+
// Create different cursor shapes
|
|
30
|
+
this._createShapes();
|
|
31
|
+
|
|
32
|
+
// Initially hidden
|
|
33
|
+
this.hide();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create different cursor shape elements
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
_createShapes() {
|
|
41
|
+
this.shapes = {};
|
|
42
|
+
|
|
43
|
+
// Default cursor (crosshair)
|
|
44
|
+
this.shapes.default = this._createCrosshair();
|
|
45
|
+
|
|
46
|
+
// Pencil cursor
|
|
47
|
+
this.shapes.pencil = this._createPencilCursor();
|
|
48
|
+
|
|
49
|
+
// Eraser cursor
|
|
50
|
+
this.shapes.eraser = this._createEraserCursor();
|
|
51
|
+
|
|
52
|
+
// Select cursor
|
|
53
|
+
this.shapes.select = this._createSelectCursor();
|
|
54
|
+
|
|
55
|
+
// Add all shapes to cursor element
|
|
56
|
+
Object.values(this.shapes).forEach(shape => {
|
|
57
|
+
this.element.appendChild(shape);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Show default shape initially
|
|
61
|
+
this.setShape('default');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create crosshair cursor
|
|
66
|
+
* @private
|
|
67
|
+
*/
|
|
68
|
+
_createCrosshair() {
|
|
69
|
+
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
70
|
+
group.setAttribute('data-shape', 'default');
|
|
71
|
+
|
|
72
|
+
// Horizontal line
|
|
73
|
+
const hLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
|
|
74
|
+
hLine.setAttribute('x1', '-10');
|
|
75
|
+
hLine.setAttribute('y1', '0');
|
|
76
|
+
hLine.setAttribute('x2', '10');
|
|
77
|
+
hLine.setAttribute('y2', '0');
|
|
78
|
+
hLine.setAttribute('stroke', this.color);
|
|
79
|
+
hLine.setAttribute('stroke-width', '1');
|
|
80
|
+
|
|
81
|
+
// Vertical line
|
|
82
|
+
const vLine = document.createElementNS('http://www.w3.org/2000/svg', 'line');
|
|
83
|
+
vLine.setAttribute('x1', '0');
|
|
84
|
+
vLine.setAttribute('y1', '-10');
|
|
85
|
+
vLine.setAttribute('x2', '0');
|
|
86
|
+
vLine.setAttribute('y2', '10');
|
|
87
|
+
vLine.setAttribute('stroke', this.color);
|
|
88
|
+
vLine.setAttribute('stroke-width', '1');
|
|
89
|
+
|
|
90
|
+
group.appendChild(hLine);
|
|
91
|
+
group.appendChild(vLine);
|
|
92
|
+
|
|
93
|
+
return group;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create pencil cursor
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
_createPencilCursor() {
|
|
101
|
+
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
102
|
+
group.setAttribute('data-shape', 'pencil');
|
|
103
|
+
|
|
104
|
+
// Solid dot cursor
|
|
105
|
+
this.brushCircle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
106
|
+
this.brushCircle.setAttribute('cx', '0');
|
|
107
|
+
this.brushCircle.setAttribute('cy', '0');
|
|
108
|
+
this.brushCircle.setAttribute('r', this.size / 2);
|
|
109
|
+
this.brushCircle.setAttribute('fill', this.color);
|
|
110
|
+
this.brushCircle.setAttribute('stroke', 'none');
|
|
111
|
+
|
|
112
|
+
group.appendChild(this.brushCircle);
|
|
113
|
+
|
|
114
|
+
return group;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create eraser cursor
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
_createEraserCursor() {
|
|
122
|
+
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
123
|
+
group.setAttribute('data-shape', 'eraser');
|
|
124
|
+
|
|
125
|
+
// Circle eraser indicator
|
|
126
|
+
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
127
|
+
circle.setAttribute('r', this.size / 2);
|
|
128
|
+
circle.setAttribute('fill', 'none');
|
|
129
|
+
circle.setAttribute('stroke', '#dc3545');
|
|
130
|
+
circle.setAttribute('stroke-width', '1.5');
|
|
131
|
+
circle.setAttribute('class', 'eraser-circle');
|
|
132
|
+
|
|
133
|
+
// Mode indicator (inner fill for radius mode)
|
|
134
|
+
const modeIndicator = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
135
|
+
modeIndicator.setAttribute('r', this.size / 3);
|
|
136
|
+
modeIndicator.setAttribute('fill', 'rgba(220, 53, 69, 0.15)');
|
|
137
|
+
modeIndicator.setAttribute('class', 'eraser-mode-indicator');
|
|
138
|
+
modeIndicator.style.display = 'none';
|
|
139
|
+
|
|
140
|
+
// X mark inside (for stroke mode)
|
|
141
|
+
const line1 = document.createElementNS('http://www.w3.org/2000/svg', 'line');
|
|
142
|
+
line1.setAttribute('x1', -this.size / 5);
|
|
143
|
+
line1.setAttribute('y1', -this.size / 5);
|
|
144
|
+
line1.setAttribute('x2', this.size / 5);
|
|
145
|
+
line1.setAttribute('y2', this.size / 5);
|
|
146
|
+
line1.setAttribute('stroke', '#dc3545');
|
|
147
|
+
line1.setAttribute('stroke-width', '1.5');
|
|
148
|
+
line1.setAttribute('class', 'eraser-x1');
|
|
149
|
+
|
|
150
|
+
const line2 = document.createElementNS('http://www.w3.org/2000/svg', 'line');
|
|
151
|
+
line2.setAttribute('x1', this.size / 5);
|
|
152
|
+
line2.setAttribute('y1', -this.size / 5);
|
|
153
|
+
line2.setAttribute('x2', -this.size / 5);
|
|
154
|
+
line2.setAttribute('y2', this.size / 5);
|
|
155
|
+
line2.setAttribute('stroke', '#dc3545');
|
|
156
|
+
line2.setAttribute('stroke-width', '1.5');
|
|
157
|
+
line2.setAttribute('class', 'eraser-x2');
|
|
158
|
+
|
|
159
|
+
group.appendChild(circle);
|
|
160
|
+
group.appendChild(modeIndicator);
|
|
161
|
+
group.appendChild(line1);
|
|
162
|
+
group.appendChild(line2);
|
|
163
|
+
|
|
164
|
+
return group;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Create select cursor
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
_createSelectCursor() {
|
|
172
|
+
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
173
|
+
group.setAttribute('data-shape', 'select');
|
|
174
|
+
|
|
175
|
+
// Arrow pointer
|
|
176
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
177
|
+
path.setAttribute('d', 'M 0,0 L 0,12 L 4,8 L 8,12 L 12,8 L 4,4 Z');
|
|
178
|
+
path.setAttribute('fill', this.color);
|
|
179
|
+
path.setAttribute('stroke', 'white');
|
|
180
|
+
path.setAttribute('stroke-width', '1');
|
|
181
|
+
|
|
182
|
+
group.appendChild(path);
|
|
183
|
+
|
|
184
|
+
return group;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Set cursor shape
|
|
189
|
+
* @param {string} shape - Shape name ('default', 'pencil', 'eraser', 'select')
|
|
190
|
+
*/
|
|
191
|
+
setShape(shape) {
|
|
192
|
+
this.currentShape = shape;
|
|
193
|
+
|
|
194
|
+
// Hide all shapes
|
|
195
|
+
Object.values(this.shapes).forEach(shapeElement => {
|
|
196
|
+
shapeElement.style.display = 'none';
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// Show current shape
|
|
200
|
+
if (this.shapes[shape]) {
|
|
201
|
+
this.shapes[shape].style.display = 'block';
|
|
202
|
+
} else {
|
|
203
|
+
this.shapes.default.style.display = 'block';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Update brush size for pencil
|
|
207
|
+
if (shape === 'pencil' && this.brushCircle) {
|
|
208
|
+
this._updateBrushSize();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Set cursor position
|
|
214
|
+
* @param {number} x - X coordinate
|
|
215
|
+
* @param {number} y - Y coordinate
|
|
216
|
+
*/
|
|
217
|
+
setPosition(x, y) {
|
|
218
|
+
this.element.setAttribute('transform', `translate(${x}, ${y})`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Show cursor
|
|
223
|
+
*/
|
|
224
|
+
show() {
|
|
225
|
+
this.isVisible = true;
|
|
226
|
+
this.element.style.display = 'block';
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Hide cursor
|
|
231
|
+
*/
|
|
232
|
+
hide() {
|
|
233
|
+
this.isVisible = false;
|
|
234
|
+
this.element.style.display = 'none';
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Set cursor size (for tools that support it)
|
|
239
|
+
* @param {number} size - Cursor size
|
|
240
|
+
*/
|
|
241
|
+
setSize(size) {
|
|
242
|
+
this.size = size;
|
|
243
|
+
this._updateBrushSize();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Update brush size for pencil cursor
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
250
|
+
_updateBrushSize() {
|
|
251
|
+
if (this.brushCircle) {
|
|
252
|
+
this.brushCircle.setAttribute('r', this.size / 2);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Update eraser size if applicable
|
|
256
|
+
const eraserShape = this.shapes.eraser;
|
|
257
|
+
if (eraserShape) {
|
|
258
|
+
const circle = eraserShape.querySelector('.eraser-circle');
|
|
259
|
+
const modeIndicator = eraserShape.querySelector('.eraser-mode-indicator');
|
|
260
|
+
const x1 = eraserShape.querySelector('.eraser-x1');
|
|
261
|
+
const x2 = eraserShape.querySelector('.eraser-x2');
|
|
262
|
+
|
|
263
|
+
if (circle) {
|
|
264
|
+
circle.setAttribute('r', this.size / 2);
|
|
265
|
+
}
|
|
266
|
+
if (modeIndicator) {
|
|
267
|
+
modeIndicator.setAttribute('r', this.size / 3);
|
|
268
|
+
}
|
|
269
|
+
if (x1) {
|
|
270
|
+
x1.setAttribute('x1', -this.size / 5);
|
|
271
|
+
x1.setAttribute('y1', -this.size / 5);
|
|
272
|
+
x1.setAttribute('x2', this.size / 5);
|
|
273
|
+
x1.setAttribute('y2', this.size / 5);
|
|
274
|
+
}
|
|
275
|
+
if (x2) {
|
|
276
|
+
x2.setAttribute('x1', this.size / 5);
|
|
277
|
+
x2.setAttribute('y1', -this.size / 5);
|
|
278
|
+
x2.setAttribute('x2', -this.size / 5);
|
|
279
|
+
x2.setAttribute('y2', this.size / 5);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Set cursor color
|
|
286
|
+
* @param {string} color - CSS color value
|
|
287
|
+
*/
|
|
288
|
+
setColor(color) {
|
|
289
|
+
this.color = color;
|
|
290
|
+
|
|
291
|
+
// Update all shape colors
|
|
292
|
+
this.element.querySelectorAll('[stroke]').forEach(element => {
|
|
293
|
+
if (element.getAttribute('stroke') === this.color) {
|
|
294
|
+
element.setAttribute('stroke', color);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
this.element.querySelectorAll('[fill]').forEach(element => {
|
|
299
|
+
if (element.getAttribute('fill') === this.color) {
|
|
300
|
+
element.setAttribute('fill', color);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Set cursor opacity
|
|
307
|
+
* @param {number} opacity - Opacity value (0-1)
|
|
308
|
+
*/
|
|
309
|
+
setOpacity(opacity) {
|
|
310
|
+
this.element.style.opacity = opacity;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Enable pressure feedback (for pressure-sensitive devices)
|
|
315
|
+
* @param {number} pressure - Pressure value (0-1)
|
|
316
|
+
*/
|
|
317
|
+
setPressureFeedback(pressure) {
|
|
318
|
+
if (this.currentShape === 'pencil' && this.brushCircle) {
|
|
319
|
+
// Scale brush circle based on pressure
|
|
320
|
+
const scale = 0.5 + (pressure * 0.5); // Scale from 50% to 100%
|
|
321
|
+
this.brushCircle.setAttribute('transform', `scale(${scale})`);
|
|
322
|
+
|
|
323
|
+
// Adjust opacity based on pressure
|
|
324
|
+
const opacity = 0.3 + (pressure * 0.5); // Opacity from 30% to 80%
|
|
325
|
+
this.brushCircle.style.opacity = opacity;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Add temporary visual feedback
|
|
331
|
+
* @param {string} type - Feedback type ('success', 'error', 'info')
|
|
332
|
+
* @param {number} [duration=500] - Duration in milliseconds
|
|
333
|
+
*/
|
|
334
|
+
showFeedback(type, duration = 500) {
|
|
335
|
+
const colors = {
|
|
336
|
+
success: '#28a745',
|
|
337
|
+
error: '#dc3545',
|
|
338
|
+
info: '#17a2b8'
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const originalColor = this.color;
|
|
342
|
+
this.setColor(colors[type] || colors.info);
|
|
343
|
+
|
|
344
|
+
// Pulse animation
|
|
345
|
+
this.element.style.animation = 'pulse 0.3s ease-in-out';
|
|
346
|
+
|
|
347
|
+
setTimeout(() => {
|
|
348
|
+
this.setColor(originalColor);
|
|
349
|
+
this.element.style.animation = '';
|
|
350
|
+
}, duration);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Update cursor based on tool configuration
|
|
355
|
+
* @param {Object} toolConfig - Tool configuration
|
|
356
|
+
*/
|
|
357
|
+
updateFromToolConfig(toolConfig) {
|
|
358
|
+
if (toolConfig.strokeWidth) {
|
|
359
|
+
// Scale the cursor size for better visibility - multiply by 4 for pencil to make it clearly visible
|
|
360
|
+
const scaledSize = this.currentShape === 'pencil' ? toolConfig.strokeWidth * 4 : toolConfig.strokeWidth;
|
|
361
|
+
this.setSize(scaledSize);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (toolConfig.strokeColor) {
|
|
365
|
+
this.setColor(toolConfig.strokeColor);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (toolConfig.size) {
|
|
369
|
+
this.setSize(toolConfig.size);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Update eraser mode indicator
|
|
373
|
+
if (toolConfig.mode !== undefined && this.currentShape === 'eraser') {
|
|
374
|
+
this._updateEraserMode(toolConfig.mode);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Update eraser mode visual indicator
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
_updateEraserMode(mode) {
|
|
383
|
+
const eraserShape = this.shapes.eraser;
|
|
384
|
+
if (!eraserShape) return;
|
|
385
|
+
|
|
386
|
+
const circle = eraserShape.querySelector('.eraser-circle');
|
|
387
|
+
const modeIndicator = eraserShape.querySelector('.eraser-mode-indicator');
|
|
388
|
+
const x1 = eraserShape.querySelector('.eraser-x1');
|
|
389
|
+
const x2 = eraserShape.querySelector('.eraser-x2');
|
|
390
|
+
|
|
391
|
+
if (mode === 'radius') {
|
|
392
|
+
// Radius mode: show filled circle, hide X, use orange color
|
|
393
|
+
if (circle) {
|
|
394
|
+
circle.setAttribute('stroke', '#ff9f43');
|
|
395
|
+
circle.setAttribute('stroke-dasharray', '3,3');
|
|
396
|
+
}
|
|
397
|
+
if (modeIndicator) {
|
|
398
|
+
modeIndicator.style.display = 'block';
|
|
399
|
+
modeIndicator.setAttribute('fill', 'rgba(255, 159, 67, 0.3)');
|
|
400
|
+
}
|
|
401
|
+
if (x1) x1.style.display = 'none';
|
|
402
|
+
if (x2) x2.style.display = 'none';
|
|
403
|
+
} else {
|
|
404
|
+
// Stroke mode: show X, hide fill, use red color
|
|
405
|
+
if (circle) {
|
|
406
|
+
circle.setAttribute('stroke', '#dc3545');
|
|
407
|
+
circle.setAttribute('stroke-dasharray', 'none');
|
|
408
|
+
}
|
|
409
|
+
if (modeIndicator) {
|
|
410
|
+
modeIndicator.style.display = 'none';
|
|
411
|
+
}
|
|
412
|
+
if (x1) x1.style.display = 'block';
|
|
413
|
+
if (x2) x2.style.display = 'block';
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Get current cursor state
|
|
419
|
+
* @returns {Object} Cursor state
|
|
420
|
+
*/
|
|
421
|
+
getState() {
|
|
422
|
+
return {
|
|
423
|
+
isVisible: this.isVisible,
|
|
424
|
+
shape: this.currentShape,
|
|
425
|
+
size: this.size,
|
|
426
|
+
color: this.color
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Clean up cursor resources
|
|
432
|
+
*/
|
|
433
|
+
destroy() {
|
|
434
|
+
if (this.element.parentNode) {
|
|
435
|
+
this.element.parentNode.removeChild(this.element);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|