@2112-lab/central-plant 0.1.4 → 0.1.5
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/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
- package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
- package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -1
- package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
- package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
- package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -1
- package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
- package/dist/cjs/src/analysis/analysis.js +560 -1
- package/dist/cjs/src/analysis/testing.js +958 -1
- package/dist/cjs/src/core/centralPlant.js +1149 -1
- package/dist/cjs/src/core/debugLogger.js +175 -1
- package/dist/cjs/src/core/mathUtils.js +574 -1
- package/dist/cjs/src/core/nameUtils.js +93 -1
- package/dist/cjs/src/data/export.js +716 -1
- package/dist/cjs/src/data/import.js +380 -1
- package/dist/cjs/src/data/numerics.js +522 -1
- package/dist/cjs/src/helpers/sceneHelper.js +572 -1
- package/dist/cjs/src/index.js +69 -1
- package/dist/cjs/src/managers/components/animationManager.js +123 -1
- package/dist/cjs/src/managers/components/componentManager.js +332 -1
- package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -1
- package/dist/cjs/src/managers/controls/TransformControls.js +1063 -1
- package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -1
- package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -1
- package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -1
- package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -1
- package/dist/cjs/src/managers/environment/environmentManager.js +714 -1
- package/dist/cjs/src/managers/environment/textureConfig.js +229 -1
- package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -1
- package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -1
- package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -1
- package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -1
- package/dist/cjs/src/managers/system/disposalManager.js +444 -1
- package/dist/cjs/src/managers/system/hotReloadManager.js +291 -1
- package/dist/cjs/src/managers/system/performanceMonitor.js +863 -1
- package/dist/cjs/src/rendering/modelPreloader.js +369 -1
- package/dist/cjs/src/rendering/rendering2D.js +631 -1
- package/dist/cjs/src/rendering/rendering3D.js +685 -1
- package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
- package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
- package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -1
- package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
- package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
- package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -1
- package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
- package/dist/esm/src/analysis/analysis.js +536 -1
- package/dist/esm/src/analysis/testing.js +954 -1
- package/dist/esm/src/core/centralPlant.js +1144 -1
- package/dist/esm/src/core/debugLogger.js +167 -1
- package/dist/esm/src/core/mathUtils.js +570 -1
- package/dist/esm/src/core/nameUtils.js +87 -1
- package/dist/esm/src/data/export.js +712 -1
- package/dist/esm/src/data/import.js +356 -1
- package/dist/esm/src/data/numerics.js +518 -1
- package/dist/esm/src/helpers/sceneHelper.js +547 -1
- package/dist/esm/src/index.js +35 -1
- package/dist/esm/src/managers/components/animationManager.js +119 -1
- package/dist/esm/src/managers/components/componentManager.js +328 -1
- package/dist/esm/src/managers/components/pathfindingManager.js +1417 -1
- package/dist/esm/src/managers/controls/TransformControls.js +1057 -1
- package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -1
- package/dist/esm/src/managers/controls/dragDropManager.js +1002 -1
- package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -1
- package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -1
- package/dist/esm/src/managers/environment/environmentManager.js +690 -1
- package/dist/esm/src/managers/environment/textureConfig.js +202 -1
- package/dist/esm/src/managers/scene/sceneExportManager.js +260 -1
- package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -1
- package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -1
- package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -1
- package/dist/esm/src/managers/system/disposalManager.js +440 -1
- package/dist/esm/src/managers/system/hotReloadManager.js +287 -1
- package/dist/esm/src/managers/system/performanceMonitor.js +858 -1
- package/dist/esm/src/rendering/modelPreloader.js +364 -1
- package/dist/esm/src/rendering/rendering2D.js +627 -1
- package/dist/esm/src/rendering/rendering3D.js +661 -1
- package/package.json +1 -1
|
@@ -1 +1,627 @@
|
|
|
1
|
-
import{createClass as
|
|
1
|
+
import { createClass as _createClass, classCallCheck as _classCallCheck, defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rendering2D
|
|
5
|
+
* Handles 2D rendering operations, canvas drawing, and 2D graphics utilities
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
var Rendering2D = /*#__PURE__*/function () {
|
|
9
|
+
function Rendering2D(_canvas) {
|
|
10
|
+
var _this = this;
|
|
11
|
+
_classCallCheck(this, Rendering2D);
|
|
12
|
+
/**
|
|
13
|
+
* Drawing primitives
|
|
14
|
+
*/
|
|
15
|
+
_defineProperty(this, "draw", {
|
|
16
|
+
/**
|
|
17
|
+
* Draw a line
|
|
18
|
+
* @param {number} x1 - Start X
|
|
19
|
+
* @param {number} y1 - Start Y
|
|
20
|
+
* @param {number} x2 - End X
|
|
21
|
+
* @param {number} y2 - End Y
|
|
22
|
+
* @param {Object} style - Line style
|
|
23
|
+
*/
|
|
24
|
+
line: function line(x1, y1, x2, y2) {
|
|
25
|
+
var style = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
26
|
+
if (!_this.ctx) return;
|
|
27
|
+
_this.save();
|
|
28
|
+
_this.setStyles(style);
|
|
29
|
+
_this.ctx.beginPath();
|
|
30
|
+
_this.ctx.moveTo(x1, y1);
|
|
31
|
+
_this.ctx.lineTo(x2, y2);
|
|
32
|
+
_this.ctx.stroke();
|
|
33
|
+
_this.restore();
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* Draw a rectangle
|
|
37
|
+
* @param {number} x - X position
|
|
38
|
+
* @param {number} y - Y position
|
|
39
|
+
* @param {number} width - Width
|
|
40
|
+
* @param {number} height - Height
|
|
41
|
+
* @param {Object} style - Rectangle style
|
|
42
|
+
*/
|
|
43
|
+
rect: function rect(x, y, width, height) {
|
|
44
|
+
var style = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
45
|
+
if (!_this.ctx) return;
|
|
46
|
+
_this.save();
|
|
47
|
+
_this.setStyles(style);
|
|
48
|
+
if (style.fillStyle) {
|
|
49
|
+
_this.ctx.fillRect(x, y, width, height);
|
|
50
|
+
}
|
|
51
|
+
if (style.strokeStyle) {
|
|
52
|
+
_this.ctx.strokeRect(x, y, width, height);
|
|
53
|
+
}
|
|
54
|
+
_this.restore();
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Draw a circle
|
|
58
|
+
* @param {number} x - Center X
|
|
59
|
+
* @param {number} y - Center Y
|
|
60
|
+
* @param {number} radius - Radius
|
|
61
|
+
* @param {Object} style - Circle style
|
|
62
|
+
*/
|
|
63
|
+
circle: function circle(x, y, radius) {
|
|
64
|
+
var style = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
65
|
+
if (!_this.ctx) return;
|
|
66
|
+
_this.save();
|
|
67
|
+
_this.setStyles(style);
|
|
68
|
+
_this.ctx.beginPath();
|
|
69
|
+
_this.ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
|
70
|
+
if (style.fillStyle) {
|
|
71
|
+
_this.ctx.fill();
|
|
72
|
+
}
|
|
73
|
+
if (style.strokeStyle) {
|
|
74
|
+
_this.ctx.stroke();
|
|
75
|
+
}
|
|
76
|
+
_this.restore();
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* Draw an ellipse
|
|
80
|
+
* @param {number} x - Center X
|
|
81
|
+
* @param {number} y - Center Y
|
|
82
|
+
* @param {number} radiusX - X radius
|
|
83
|
+
* @param {number} radiusY - Y radius
|
|
84
|
+
* @param {number} rotation - Rotation in radians
|
|
85
|
+
* @param {Object} style - Ellipse style
|
|
86
|
+
*/
|
|
87
|
+
ellipse: function ellipse(x, y, radiusX, radiusY) {
|
|
88
|
+
var rotation = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
89
|
+
var style = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
90
|
+
if (!_this.ctx) return;
|
|
91
|
+
_this.save();
|
|
92
|
+
_this.setStyles(style);
|
|
93
|
+
_this.ctx.beginPath();
|
|
94
|
+
_this.ctx.ellipse(x, y, radiusX, radiusY, rotation, 0, 2 * Math.PI);
|
|
95
|
+
if (style.fillStyle) {
|
|
96
|
+
_this.ctx.fill();
|
|
97
|
+
}
|
|
98
|
+
if (style.strokeStyle) {
|
|
99
|
+
_this.ctx.stroke();
|
|
100
|
+
}
|
|
101
|
+
_this.restore();
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Draw a polygon
|
|
105
|
+
* @param {Array} points - Array of [x, y] points
|
|
106
|
+
* @param {Object} style - Polygon style
|
|
107
|
+
*/
|
|
108
|
+
polygon: function polygon(points) {
|
|
109
|
+
var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
110
|
+
if (!_this.ctx || points.length < 3) return;
|
|
111
|
+
_this.save();
|
|
112
|
+
_this.setStyles(style);
|
|
113
|
+
_this.ctx.beginPath();
|
|
114
|
+
_this.ctx.moveTo(points[0][0], points[0][1]);
|
|
115
|
+
for (var i = 1; i < points.length; i++) {
|
|
116
|
+
_this.ctx.lineTo(points[i][0], points[i][1]);
|
|
117
|
+
}
|
|
118
|
+
_this.ctx.closePath();
|
|
119
|
+
if (style.fillStyle) {
|
|
120
|
+
_this.ctx.fill();
|
|
121
|
+
}
|
|
122
|
+
if (style.strokeStyle) {
|
|
123
|
+
_this.ctx.stroke();
|
|
124
|
+
}
|
|
125
|
+
_this.restore();
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* Draw a bezier curve
|
|
129
|
+
* @param {number} x1 - Start X
|
|
130
|
+
* @param {number} y1 - Start Y
|
|
131
|
+
* @param {number} cp1x - Control point 1 X
|
|
132
|
+
* @param {number} cp1y - Control point 1 Y
|
|
133
|
+
* @param {number} cp2x - Control point 2 X
|
|
134
|
+
* @param {number} cp2y - Control point 2 Y
|
|
135
|
+
* @param {number} x2 - End X
|
|
136
|
+
* @param {number} y2 - End Y
|
|
137
|
+
* @param {Object} style - Curve style
|
|
138
|
+
*/
|
|
139
|
+
bezierCurve: function bezierCurve(x1, y1, cp1x, cp1y, cp2x, cp2y, x2, y2) {
|
|
140
|
+
var style = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : {};
|
|
141
|
+
if (!_this.ctx) return;
|
|
142
|
+
_this.save();
|
|
143
|
+
_this.setStyles(style);
|
|
144
|
+
_this.ctx.beginPath();
|
|
145
|
+
_this.ctx.moveTo(x1, y1);
|
|
146
|
+
_this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x2, y2);
|
|
147
|
+
_this.ctx.stroke();
|
|
148
|
+
_this.restore();
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
* Draw text
|
|
152
|
+
* @param {string} text - Text to draw
|
|
153
|
+
* @param {number} x - X position
|
|
154
|
+
* @param {number} y - Y position
|
|
155
|
+
* @param {Object} style - Text style
|
|
156
|
+
*/
|
|
157
|
+
text: function text(_text, x, y) {
|
|
158
|
+
var style = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
159
|
+
if (!_this.ctx) return;
|
|
160
|
+
_this.save();
|
|
161
|
+
_this.setStyles(style);
|
|
162
|
+
if (style.fillStyle) {
|
|
163
|
+
_this.ctx.fillText(_text, x, y);
|
|
164
|
+
}
|
|
165
|
+
if (style.strokeStyle) {
|
|
166
|
+
_this.ctx.strokeText(_text, x, y);
|
|
167
|
+
}
|
|
168
|
+
_this.restore();
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* Draw an image
|
|
172
|
+
* @param {HTMLImageElement} image - Image to draw
|
|
173
|
+
* @param {number} x - X position
|
|
174
|
+
* @param {number} y - Y position
|
|
175
|
+
* @param {number} width - Width (optional)
|
|
176
|
+
* @param {number} height - Height (optional)
|
|
177
|
+
*/
|
|
178
|
+
image: function image(_image, x, y) {
|
|
179
|
+
var width = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
180
|
+
var height = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
181
|
+
if (!_this.ctx || !_image) return;
|
|
182
|
+
if (width && height) {
|
|
183
|
+
_this.ctx.drawImage(_image, x, y, width, height);
|
|
184
|
+
} else {
|
|
185
|
+
_this.ctx.drawImage(_image, x, y);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
/**
|
|
190
|
+
* Transform operations
|
|
191
|
+
*/
|
|
192
|
+
_defineProperty(this, "transform", {
|
|
193
|
+
/**
|
|
194
|
+
* Translate coordinate system
|
|
195
|
+
* @param {number} x - X offset
|
|
196
|
+
* @param {number} y - Y offset
|
|
197
|
+
*/
|
|
198
|
+
translate: function translate(x, y) {
|
|
199
|
+
if (!_this.ctx) return;
|
|
200
|
+
_this.ctx.translate(x, y);
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* Rotate coordinate system
|
|
204
|
+
* @param {number} angle - Rotation angle in radians
|
|
205
|
+
*/
|
|
206
|
+
rotate: function rotate(angle) {
|
|
207
|
+
if (!_this.ctx) return;
|
|
208
|
+
_this.ctx.rotate(angle);
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* Scale coordinate system
|
|
212
|
+
* @param {number} x - X scale factor
|
|
213
|
+
* @param {number} y - Y scale factor
|
|
214
|
+
*/
|
|
215
|
+
scale: function scale(x) {
|
|
216
|
+
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
|
|
217
|
+
if (!_this.ctx) return;
|
|
218
|
+
_this.ctx.scale(x, y);
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* Apply transformation matrix
|
|
222
|
+
* @param {number} a - Horizontal scaling
|
|
223
|
+
* @param {number} b - Horizontal skewing
|
|
224
|
+
* @param {number} c - Vertical skewing
|
|
225
|
+
* @param {number} d - Vertical scaling
|
|
226
|
+
* @param {number} e - Horizontal translation
|
|
227
|
+
* @param {number} f - Vertical translation
|
|
228
|
+
*/
|
|
229
|
+
transform: function transform(a, b, c, d, e, f) {
|
|
230
|
+
if (!_this.ctx) return;
|
|
231
|
+
_this.ctx.transform(a, b, c, d, e, f);
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* Set transformation matrix
|
|
235
|
+
* @param {number} a - Horizontal scaling
|
|
236
|
+
* @param {number} b - Horizontal skewing
|
|
237
|
+
* @param {number} c - Vertical skewing
|
|
238
|
+
* @param {number} d - Vertical scaling
|
|
239
|
+
* @param {number} e - Horizontal translation
|
|
240
|
+
* @param {number} f - Vertical translation
|
|
241
|
+
*/
|
|
242
|
+
setTransform: function setTransform(a, b, c, d, e, f) {
|
|
243
|
+
if (!_this.ctx) return;
|
|
244
|
+
_this.ctx.setTransform(a, b, c, d, e, f);
|
|
245
|
+
},
|
|
246
|
+
/**
|
|
247
|
+
* Reset transformation matrix to identity
|
|
248
|
+
*/
|
|
249
|
+
resetTransform: function resetTransform() {
|
|
250
|
+
if (!_this.ctx) return;
|
|
251
|
+
_this.ctx.resetTransform();
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
/**
|
|
255
|
+
* Gradient utilities
|
|
256
|
+
*/
|
|
257
|
+
_defineProperty(this, "gradient", {
|
|
258
|
+
/**
|
|
259
|
+
* Create linear gradient
|
|
260
|
+
* @param {number} x1 - Start X
|
|
261
|
+
* @param {number} y1 - Start Y
|
|
262
|
+
* @param {number} x2 - End X
|
|
263
|
+
* @param {number} y2 - End Y
|
|
264
|
+
* @param {Array} colorStops - Array of {offset, color} objects
|
|
265
|
+
* @returns {CanvasGradient} Linear gradient
|
|
266
|
+
*/
|
|
267
|
+
linear: function linear(x1, y1, x2, y2, colorStops) {
|
|
268
|
+
if (!_this.ctx) return null;
|
|
269
|
+
var gradient = _this.ctx.createLinearGradient(x1, y1, x2, y2);
|
|
270
|
+
colorStops.forEach(function (stop) {
|
|
271
|
+
gradient.addColorStop(stop.offset, stop.color);
|
|
272
|
+
});
|
|
273
|
+
return gradient;
|
|
274
|
+
},
|
|
275
|
+
/**
|
|
276
|
+
* Create radial gradient
|
|
277
|
+
* @param {number} x1 - Inner circle center X
|
|
278
|
+
* @param {number} y1 - Inner circle center Y
|
|
279
|
+
* @param {number} r1 - Inner circle radius
|
|
280
|
+
* @param {number} x2 - Outer circle center X
|
|
281
|
+
* @param {number} y2 - Outer circle center Y
|
|
282
|
+
* @param {number} r2 - Outer circle radius
|
|
283
|
+
* @param {Array} colorStops - Array of {offset, color} objects
|
|
284
|
+
* @returns {CanvasGradient} Radial gradient
|
|
285
|
+
*/
|
|
286
|
+
radial: function radial(x1, y1, r1, x2, y2, r2, colorStops) {
|
|
287
|
+
if (!_this.ctx) return null;
|
|
288
|
+
var gradient = _this.ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);
|
|
289
|
+
colorStops.forEach(function (stop) {
|
|
290
|
+
gradient.addColorStop(stop.offset, stop.color);
|
|
291
|
+
});
|
|
292
|
+
return gradient;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
/**
|
|
296
|
+
* Pattern utilities
|
|
297
|
+
*/
|
|
298
|
+
_defineProperty(this, "pattern", {
|
|
299
|
+
/**
|
|
300
|
+
* Create pattern from image
|
|
301
|
+
* @param {HTMLImageElement} image - Source image
|
|
302
|
+
* @param {string} repetition - 'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
|
|
303
|
+
* @returns {CanvasPattern} Pattern
|
|
304
|
+
*/
|
|
305
|
+
fromImage: function fromImage(image) {
|
|
306
|
+
var repetition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'repeat';
|
|
307
|
+
if (!_this.ctx || !image) return null;
|
|
308
|
+
return _this.ctx.createPattern(image, repetition);
|
|
309
|
+
},
|
|
310
|
+
/**
|
|
311
|
+
* Create pattern from canvas
|
|
312
|
+
* @param {HTMLCanvasElement} canvas - Source canvas
|
|
313
|
+
* @param {string} repetition - 'repeat', 'repeat-x', 'repeat-y', 'no-repeat'
|
|
314
|
+
* @returns {CanvasPattern} Pattern
|
|
315
|
+
*/
|
|
316
|
+
fromCanvas: function fromCanvas(canvas) {
|
|
317
|
+
var repetition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'repeat';
|
|
318
|
+
if (!_this.ctx || !canvas) return null;
|
|
319
|
+
return _this.ctx.createPattern(canvas, repetition);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
/**
|
|
323
|
+
* Path utilities
|
|
324
|
+
*/
|
|
325
|
+
_defineProperty(this, "path", {
|
|
326
|
+
/**
|
|
327
|
+
* Begin new path
|
|
328
|
+
*/
|
|
329
|
+
begin: function begin() {
|
|
330
|
+
if (!_this.ctx) return;
|
|
331
|
+
_this.ctx.beginPath();
|
|
332
|
+
},
|
|
333
|
+
/**
|
|
334
|
+
* Close current path
|
|
335
|
+
*/
|
|
336
|
+
close: function close() {
|
|
337
|
+
if (!_this.ctx) return;
|
|
338
|
+
_this.ctx.closePath();
|
|
339
|
+
},
|
|
340
|
+
/**
|
|
341
|
+
* Move to point
|
|
342
|
+
* @param {number} x - X coordinate
|
|
343
|
+
* @param {number} y - Y coordinate
|
|
344
|
+
*/
|
|
345
|
+
moveTo: function moveTo(x, y) {
|
|
346
|
+
if (!_this.ctx) return;
|
|
347
|
+
_this.ctx.moveTo(x, y);
|
|
348
|
+
},
|
|
349
|
+
/**
|
|
350
|
+
* Line to point
|
|
351
|
+
* @param {number} x - X coordinate
|
|
352
|
+
* @param {number} y - Y coordinate
|
|
353
|
+
*/
|
|
354
|
+
lineTo: function lineTo(x, y) {
|
|
355
|
+
if (!_this.ctx) return;
|
|
356
|
+
_this.ctx.lineTo(x, y);
|
|
357
|
+
},
|
|
358
|
+
/**
|
|
359
|
+
* Arc to point
|
|
360
|
+
* @param {number} x - Center X
|
|
361
|
+
* @param {number} y - Center Y
|
|
362
|
+
* @param {number} radius - Arc radius
|
|
363
|
+
* @param {number} startAngle - Start angle in radians
|
|
364
|
+
* @param {number} endAngle - End angle in radians
|
|
365
|
+
* @param {boolean} counterclockwise - Arc direction
|
|
366
|
+
*/
|
|
367
|
+
arc: function arc(x, y, radius, startAngle, endAngle) {
|
|
368
|
+
var counterclockwise = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
369
|
+
if (!_this.ctx) return;
|
|
370
|
+
_this.ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise);
|
|
371
|
+
},
|
|
372
|
+
/**
|
|
373
|
+
* Quadratic curve to point
|
|
374
|
+
* @param {number} cpx - Control point X
|
|
375
|
+
* @param {number} cpy - Control point Y
|
|
376
|
+
* @param {number} x - End X
|
|
377
|
+
* @param {number} y - End Y
|
|
378
|
+
*/
|
|
379
|
+
quadraticCurveTo: function quadraticCurveTo(cpx, cpy, x, y) {
|
|
380
|
+
if (!_this.ctx) return;
|
|
381
|
+
_this.ctx.quadraticCurveTo(cpx, cpy, x, y);
|
|
382
|
+
},
|
|
383
|
+
/**
|
|
384
|
+
* Bezier curve to point
|
|
385
|
+
* @param {number} cp1x - Control point 1 X
|
|
386
|
+
* @param {number} cp1y - Control point 1 Y
|
|
387
|
+
* @param {number} cp2x - Control point 2 X
|
|
388
|
+
* @param {number} cp2y - Control point 2 Y
|
|
389
|
+
* @param {number} x - End X
|
|
390
|
+
* @param {number} y - End Y
|
|
391
|
+
*/
|
|
392
|
+
bezierCurveTo: function bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
393
|
+
if (!_this.ctx) return;
|
|
394
|
+
_this.ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
395
|
+
},
|
|
396
|
+
/**
|
|
397
|
+
* Fill current path
|
|
398
|
+
*/
|
|
399
|
+
fill: function fill() {
|
|
400
|
+
if (!_this.ctx) return;
|
|
401
|
+
_this.ctx.fill();
|
|
402
|
+
},
|
|
403
|
+
/**
|
|
404
|
+
* Stroke current path
|
|
405
|
+
*/
|
|
406
|
+
stroke: function stroke() {
|
|
407
|
+
if (!_this.ctx) return;
|
|
408
|
+
_this.ctx.stroke();
|
|
409
|
+
},
|
|
410
|
+
/**
|
|
411
|
+
* Clip to current path
|
|
412
|
+
*/
|
|
413
|
+
clip: function clip() {
|
|
414
|
+
if (!_this.ctx) return;
|
|
415
|
+
_this.ctx.clip();
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
/**
|
|
419
|
+
* Measurement utilities
|
|
420
|
+
*/
|
|
421
|
+
_defineProperty(this, "measure", {
|
|
422
|
+
/**
|
|
423
|
+
* Measure text width
|
|
424
|
+
* @param {string} text - Text to measure
|
|
425
|
+
* @param {string} font - Font specification
|
|
426
|
+
* @returns {number} Text width in pixels
|
|
427
|
+
*/
|
|
428
|
+
textWidth: function textWidth(text) {
|
|
429
|
+
var font = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
430
|
+
if (!_this.ctx) return 0;
|
|
431
|
+
if (font) {
|
|
432
|
+
var oldFont = _this.ctx.font;
|
|
433
|
+
_this.ctx.font = font;
|
|
434
|
+
var width = _this.ctx.measureText(text).width;
|
|
435
|
+
_this.ctx.font = oldFont;
|
|
436
|
+
return width;
|
|
437
|
+
}
|
|
438
|
+
return _this.ctx.measureText(text).width;
|
|
439
|
+
},
|
|
440
|
+
/**
|
|
441
|
+
* Get text metrics
|
|
442
|
+
* @param {string} text - Text to measure
|
|
443
|
+
* @param {string} font - Font specification
|
|
444
|
+
* @returns {TextMetrics} Text metrics object
|
|
445
|
+
*/
|
|
446
|
+
textMetrics: function textMetrics(text) {
|
|
447
|
+
var font = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
448
|
+
if (!_this.ctx) return null;
|
|
449
|
+
if (font) {
|
|
450
|
+
var oldFont = _this.ctx.font;
|
|
451
|
+
_this.ctx.font = font;
|
|
452
|
+
var metrics = _this.ctx.measureText(text);
|
|
453
|
+
_this.ctx.font = oldFont;
|
|
454
|
+
return metrics;
|
|
455
|
+
}
|
|
456
|
+
return _this.ctx.measureText(text);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
/**
|
|
460
|
+
* Export utilities
|
|
461
|
+
*/
|
|
462
|
+
_defineProperty(this, "export", {
|
|
463
|
+
/**
|
|
464
|
+
* Get canvas as data URL
|
|
465
|
+
* @param {string} type - Image type ('image/png', 'image/jpeg', etc.)
|
|
466
|
+
* @param {number} quality - Quality for lossy formats (0-1)
|
|
467
|
+
* @returns {string} Data URL
|
|
468
|
+
*/
|
|
469
|
+
toDataURL: function toDataURL() {
|
|
470
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'image/png';
|
|
471
|
+
var quality = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.92;
|
|
472
|
+
if (!_this.canvas) return '';
|
|
473
|
+
return _this.canvas.toDataURL(type, quality);
|
|
474
|
+
},
|
|
475
|
+
/**
|
|
476
|
+
* Get canvas as blob
|
|
477
|
+
* @param {string} type - Image type
|
|
478
|
+
* @param {number} quality - Quality for lossy formats
|
|
479
|
+
* @returns {Promise<Blob>} Canvas blob
|
|
480
|
+
*/
|
|
481
|
+
toBlob: function toBlob() {
|
|
482
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'image/png';
|
|
483
|
+
var quality = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.92;
|
|
484
|
+
if (!_this.canvas) return Promise.resolve(null);
|
|
485
|
+
return new Promise(function (resolve) {
|
|
486
|
+
_this.canvas.toBlob(resolve, type, quality);
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
this.canvas = _canvas;
|
|
491
|
+
this.ctx = _canvas === null || _canvas === void 0 ? void 0 : _canvas.getContext('2d');
|
|
492
|
+
this.width = (_canvas === null || _canvas === void 0 ? void 0 : _canvas.width) || 800;
|
|
493
|
+
this.height = (_canvas === null || _canvas === void 0 ? void 0 : _canvas.height) || 600;
|
|
494
|
+
this.pixelRatio = window.devicePixelRatio || 1;
|
|
495
|
+
this.state = {
|
|
496
|
+
transforms: [],
|
|
497
|
+
styles: []
|
|
498
|
+
};
|
|
499
|
+
this.setupCanvas();
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Setup canvas for high DPI displays
|
|
504
|
+
*/
|
|
505
|
+
return _createClass(Rendering2D, [{
|
|
506
|
+
key: "setupCanvas",
|
|
507
|
+
value: function setupCanvas() {
|
|
508
|
+
if (!this.canvas || !this.ctx) return;
|
|
509
|
+
|
|
510
|
+
// Set actual size in memory (scaled for DPI)
|
|
511
|
+
this.canvas.width = this.width * this.pixelRatio;
|
|
512
|
+
this.canvas.height = this.height * this.pixelRatio;
|
|
513
|
+
|
|
514
|
+
// Scale the drawing context back to logical size
|
|
515
|
+
this.ctx.scale(this.pixelRatio, this.pixelRatio);
|
|
516
|
+
|
|
517
|
+
// Set display size (CSS pixels)
|
|
518
|
+
this.canvas.style.width = this.width + 'px';
|
|
519
|
+
this.canvas.style.height = this.height + 'px';
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Clear the entire canvas
|
|
524
|
+
* @param {string} color - Optional background color
|
|
525
|
+
*/
|
|
526
|
+
}, {
|
|
527
|
+
key: "clear",
|
|
528
|
+
value: function clear() {
|
|
529
|
+
var color = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
530
|
+
if (!this.ctx) return;
|
|
531
|
+
if (color) {
|
|
532
|
+
this.ctx.fillStyle = color;
|
|
533
|
+
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
534
|
+
} else {
|
|
535
|
+
this.ctx.clearRect(0, 0, this.width, this.height);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Save current drawing state
|
|
541
|
+
*/
|
|
542
|
+
}, {
|
|
543
|
+
key: "save",
|
|
544
|
+
value: function save() {
|
|
545
|
+
if (!this.ctx) return;
|
|
546
|
+
this.ctx.save();
|
|
547
|
+
this.state.transforms.push(this.ctx.getTransform());
|
|
548
|
+
this.state.styles.push({
|
|
549
|
+
fillStyle: this.ctx.fillStyle,
|
|
550
|
+
strokeStyle: this.ctx.strokeStyle,
|
|
551
|
+
lineWidth: this.ctx.lineWidth,
|
|
552
|
+
font: this.ctx.font,
|
|
553
|
+
textAlign: this.ctx.textAlign,
|
|
554
|
+
textBaseline: this.ctx.textBaseline
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Restore previous drawing state
|
|
560
|
+
*/
|
|
561
|
+
}, {
|
|
562
|
+
key: "restore",
|
|
563
|
+
value: function restore() {
|
|
564
|
+
if (!this.ctx) return;
|
|
565
|
+
this.ctx.restore();
|
|
566
|
+
this.state.transforms.pop();
|
|
567
|
+
this.state.styles.pop();
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Set drawing styles
|
|
572
|
+
* @param {Object} styles - Style properties
|
|
573
|
+
*/
|
|
574
|
+
}, {
|
|
575
|
+
key: "setStyles",
|
|
576
|
+
value: function setStyles(styles) {
|
|
577
|
+
var _this2 = this;
|
|
578
|
+
if (!this.ctx) return;
|
|
579
|
+
Object.keys(styles).forEach(function (key) {
|
|
580
|
+
if (_this2.ctx[key] !== undefined) {
|
|
581
|
+
_this2.ctx[key] = styles[key];
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
}, {
|
|
586
|
+
key: "resize",
|
|
587
|
+
value:
|
|
588
|
+
/**
|
|
589
|
+
* Resize canvas
|
|
590
|
+
* @param {number} width - New width
|
|
591
|
+
* @param {number} height - New height
|
|
592
|
+
*/
|
|
593
|
+
function resize(width, height) {
|
|
594
|
+
this.width = width;
|
|
595
|
+
this.height = height;
|
|
596
|
+
this.setupCanvas();
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Get canvas dimensions
|
|
601
|
+
* @returns {Object} Canvas dimensions
|
|
602
|
+
*/
|
|
603
|
+
}, {
|
|
604
|
+
key: "getDimensions",
|
|
605
|
+
value: function getDimensions() {
|
|
606
|
+
return {
|
|
607
|
+
width: this.width,
|
|
608
|
+
height: this.height,
|
|
609
|
+
pixelRatio: this.pixelRatio
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Dispose of rendering manager
|
|
615
|
+
*/
|
|
616
|
+
}, {
|
|
617
|
+
key: "dispose",
|
|
618
|
+
value: function dispose() {
|
|
619
|
+
this.state.transforms = [];
|
|
620
|
+
this.state.styles = [];
|
|
621
|
+
this.canvas = null;
|
|
622
|
+
this.ctx = null;
|
|
623
|
+
}
|
|
624
|
+
}]);
|
|
625
|
+
}();
|
|
626
|
+
|
|
627
|
+
export { Rendering2D };
|