@extrabinoss/three-plot 1.0.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.
@@ -0,0 +1,1527 @@
1
+ import * as r from "three";
2
+ import { Controls as Q, Vector3 as y, MOUSE as b, TOUCH as x, Quaternion as I, Spherical as U, Vector2 as g, Ray as $, Plane as J, MathUtils as tt } from "three";
3
+ const W = { type: "change" }, j = { type: "start" }, H = { type: "end" }, w = new $(), Y = new J(), et = Math.cos(70 * tt.DEG2RAD), u = new y(), f = 2 * Math.PI, l = {
4
+ NONE: -1,
5
+ ROTATE: 0,
6
+ DOLLY: 1,
7
+ PAN: 2,
8
+ TOUCH_ROTATE: 3,
9
+ TOUCH_PAN: 4,
10
+ TOUCH_DOLLY_PAN: 5,
11
+ TOUCH_DOLLY_ROTATE: 6
12
+ }, z = 1e-6;
13
+ class it extends Q {
14
+ /**
15
+ * Constructs a new controls instance.
16
+ *
17
+ * @param {Object3D} object - The object that is managed by the controls.
18
+ * @param {?HTMLElement} domElement - The HTML element used for event listeners.
19
+ */
20
+ constructor(t, e = null) {
21
+ super(t, e), this.state = l.NONE, this.target = new y(), this.cursor = new y(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: b.ROTATE, MIDDLE: b.DOLLY, RIGHT: b.PAN }, this.touches = { ONE: x.ROTATE, TWO: x.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new y(), this._lastQuaternion = new I(), this._lastTargetPosition = new y(), this._quat = new I().setFromUnitVectors(t.up, new y(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new U(), this._sphericalDelta = new U(), this._scale = 1, this._panOffset = new y(), this._rotateStart = new g(), this._rotateEnd = new g(), this._rotateDelta = new g(), this._panStart = new g(), this._panEnd = new g(), this._panDelta = new g(), this._dollyStart = new g(), this._dollyEnd = new g(), this._dollyDelta = new g(), this._dollyDirection = new y(), this._mouse = new g(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = nt.bind(this), this._onPointerDown = st.bind(this), this._onPointerUp = ot.bind(this), this._onContextMenu = dt.bind(this), this._onMouseWheel = ht.bind(this), this._onKeyDown = lt.bind(this), this._onTouchStart = ct.bind(this), this._onTouchMove = ut.bind(this), this._onMouseDown = at.bind(this), this._onMouseMove = rt.bind(this), this._interceptControlDown = mt.bind(this), this._interceptControlUp = ft.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
22
+ }
23
+ connect(t) {
24
+ super.connect(t), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointercancel", this._onPointerUp), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: !1 }), this.domElement.getRootNode().addEventListener("keydown", this._interceptControlDown, { passive: !0, capture: !0 }), this.domElement.style.touchAction = "none";
25
+ }
26
+ disconnect() {
27
+ this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointercancel", this._onPointerUp), this.domElement.removeEventListener("wheel", this._onMouseWheel), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.stopListenToKeyEvents(), this.domElement.getRootNode().removeEventListener("keydown", this._interceptControlDown, { capture: !0 }), this.domElement.style.touchAction = "auto";
28
+ }
29
+ dispose() {
30
+ this.disconnect();
31
+ }
32
+ /**
33
+ * Get the current vertical rotation, in radians.
34
+ *
35
+ * @return {number} The current vertical rotation, in radians.
36
+ */
37
+ getPolarAngle() {
38
+ return this._spherical.phi;
39
+ }
40
+ /**
41
+ * Get the current horizontal rotation, in radians.
42
+ *
43
+ * @return {number} The current horizontal rotation, in radians.
44
+ */
45
+ getAzimuthalAngle() {
46
+ return this._spherical.theta;
47
+ }
48
+ /**
49
+ * Returns the distance from the camera to the target.
50
+ *
51
+ * @return {number} The distance from the camera to the target.
52
+ */
53
+ getDistance() {
54
+ return this.object.position.distanceTo(this.target);
55
+ }
56
+ /**
57
+ * Adds key event listeners to the given DOM element.
58
+ * `window` is a recommended argument for using this method.
59
+ *
60
+ * @param {HTMLElement} domElement - The DOM element
61
+ */
62
+ listenToKeyEvents(t) {
63
+ t.addEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = t;
64
+ }
65
+ /**
66
+ * Removes the key event listener previously defined with `listenToKeyEvents()`.
67
+ */
68
+ stopListenToKeyEvents() {
69
+ this._domElementKeyEvents !== null && (this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = null);
70
+ }
71
+ /**
72
+ * Save the current state of the controls. This can later be recovered with `reset()`.
73
+ */
74
+ saveState() {
75
+ this.target0.copy(this.target), this.position0.copy(this.object.position), this.zoom0 = this.object.zoom;
76
+ }
77
+ /**
78
+ * Reset the controls to their state from either the last time the `saveState()`
79
+ * was called, or the initial state.
80
+ */
81
+ reset() {
82
+ this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(W), this.update(), this.state = l.NONE;
83
+ }
84
+ update(t = null) {
85
+ const e = this.object.position;
86
+ u.copy(e).sub(this.target), u.applyQuaternion(this._quat), this._spherical.setFromVector3(u), this.autoRotate && this.state === l.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
87
+ let i = this.minAzimuthAngle, s = this.maxAzimuthAngle;
88
+ isFinite(i) && isFinite(s) && (i < -Math.PI ? i += f : i > Math.PI && (i -= f), s < -Math.PI ? s += f : s > Math.PI && (s -= f), i <= s ? this._spherical.theta = Math.max(i, Math.min(s, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (i + s) / 2 ? Math.max(i, this._spherical.theta) : Math.min(s, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
89
+ let n = !1;
90
+ if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
91
+ this._spherical.radius = this._clampDistance(this._spherical.radius);
92
+ else {
93
+ const a = this._spherical.radius;
94
+ this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), n = a != this._spherical.radius;
95
+ }
96
+ if (u.setFromSpherical(this._spherical), u.applyQuaternion(this._quatInverse), e.copy(this.target).add(u), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
97
+ let a = null;
98
+ if (this.object.isPerspectiveCamera) {
99
+ const h = u.length();
100
+ a = this._clampDistance(h * this._scale);
101
+ const c = h - a;
102
+ this.object.position.addScaledVector(this._dollyDirection, c), this.object.updateMatrixWorld(), n = !!c;
103
+ } else if (this.object.isOrthographicCamera) {
104
+ const h = new y(this._mouse.x, this._mouse.y, 0);
105
+ h.unproject(this.object);
106
+ const c = this.object.zoom;
107
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), n = c !== this.object.zoom;
108
+ const m = new y(this._mouse.x, this._mouse.y, 0);
109
+ m.unproject(this.object), this.object.position.sub(m).add(h), this.object.updateMatrixWorld(), a = u.length();
110
+ } else
111
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
112
+ a !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(a).add(this.object.position) : (w.origin.copy(this.object.position), w.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(w.direction)) < et ? this.object.lookAt(this.target) : (Y.setFromNormalAndCoplanarPoint(this.object.up, this.target), w.intersectPlane(Y, this.target))));
113
+ } else if (this.object.isOrthographicCamera) {
114
+ const a = this.object.zoom;
115
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), a !== this.object.zoom && (this.object.updateProjectionMatrix(), n = !0);
116
+ }
117
+ return this._scale = 1, this._performCursorZoom = !1, n || this._lastPosition.distanceToSquared(this.object.position) > z || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > z || this._lastTargetPosition.distanceToSquared(this.target) > z ? (this.dispatchEvent(W), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
118
+ }
119
+ _getAutoRotationAngle(t) {
120
+ return t !== null ? f / 60 * this.autoRotateSpeed * t : f / 60 / 60 * this.autoRotateSpeed;
121
+ }
122
+ _getZoomScale(t) {
123
+ const e = Math.abs(t * 0.01);
124
+ return Math.pow(0.95, this.zoomSpeed * e);
125
+ }
126
+ _rotateLeft(t) {
127
+ this._sphericalDelta.theta -= t;
128
+ }
129
+ _rotateUp(t) {
130
+ this._sphericalDelta.phi -= t;
131
+ }
132
+ _panLeft(t, e) {
133
+ u.setFromMatrixColumn(e, 0), u.multiplyScalar(-t), this._panOffset.add(u);
134
+ }
135
+ _panUp(t, e) {
136
+ this.screenSpacePanning === !0 ? u.setFromMatrixColumn(e, 1) : (u.setFromMatrixColumn(e, 0), u.crossVectors(this.object.up, u)), u.multiplyScalar(t), this._panOffset.add(u);
137
+ }
138
+ // deltaX and deltaY are in pixels; right and down are positive
139
+ _pan(t, e) {
140
+ const i = this.domElement;
141
+ if (this.object.isPerspectiveCamera) {
142
+ const s = this.object.position;
143
+ u.copy(s).sub(this.target);
144
+ let n = u.length();
145
+ n *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * n / i.clientHeight, this.object.matrix), this._panUp(2 * e * n / i.clientHeight, this.object.matrix);
146
+ } else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / i.clientWidth, this.object.matrix), this._panUp(e * (this.object.top - this.object.bottom) / this.object.zoom / i.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
147
+ }
148
+ _dollyOut(t) {
149
+ this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
150
+ }
151
+ _dollyIn(t) {
152
+ this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
153
+ }
154
+ _updateZoomParameters(t, e) {
155
+ if (!this.zoomToCursor)
156
+ return;
157
+ this._performCursorZoom = !0;
158
+ const i = this.domElement.getBoundingClientRect(), s = t - i.left, n = e - i.top, a = i.width, h = i.height;
159
+ this._mouse.x = s / a * 2 - 1, this._mouse.y = -(n / h) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
160
+ }
161
+ _clampDistance(t) {
162
+ return Math.max(this.minDistance, Math.min(this.maxDistance, t));
163
+ }
164
+ //
165
+ // event callbacks - update the object state
166
+ //
167
+ _handleMouseDownRotate(t) {
168
+ this._rotateStart.set(t.clientX, t.clientY);
169
+ }
170
+ _handleMouseDownDolly(t) {
171
+ this._updateZoomParameters(t.clientX, t.clientX), this._dollyStart.set(t.clientX, t.clientY);
172
+ }
173
+ _handleMouseDownPan(t) {
174
+ this._panStart.set(t.clientX, t.clientY);
175
+ }
176
+ _handleMouseMoveRotate(t) {
177
+ this._rotateEnd.set(t.clientX, t.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
178
+ const e = this.domElement;
179
+ this._rotateLeft(f * this._rotateDelta.x / e.clientHeight), this._rotateUp(f * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
180
+ }
181
+ _handleMouseMoveDolly(t) {
182
+ this._dollyEnd.set(t.clientX, t.clientY), this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart), this._dollyDelta.y > 0 ? this._dollyOut(this._getZoomScale(this._dollyDelta.y)) : this._dollyDelta.y < 0 && this._dollyIn(this._getZoomScale(this._dollyDelta.y)), this._dollyStart.copy(this._dollyEnd), this.update();
183
+ }
184
+ _handleMouseMovePan(t) {
185
+ this._panEnd.set(t.clientX, t.clientY), this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd), this.update();
186
+ }
187
+ _handleMouseWheel(t) {
188
+ this._updateZoomParameters(t.clientX, t.clientY), t.deltaY < 0 ? this._dollyIn(this._getZoomScale(t.deltaY)) : t.deltaY > 0 && this._dollyOut(this._getZoomScale(t.deltaY)), this.update();
189
+ }
190
+ _handleKeyDown(t) {
191
+ let e = !1;
192
+ switch (t.code) {
193
+ case this.keys.UP:
194
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(f * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), e = !0;
195
+ break;
196
+ case this.keys.BOTTOM:
197
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-f * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), e = !0;
198
+ break;
199
+ case this.keys.LEFT:
200
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(f * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), e = !0;
201
+ break;
202
+ case this.keys.RIGHT:
203
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-f * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), e = !0;
204
+ break;
205
+ }
206
+ e && (t.preventDefault(), this.update());
207
+ }
208
+ _handleTouchStartRotate(t) {
209
+ if (this._pointers.length === 1)
210
+ this._rotateStart.set(t.pageX, t.pageY);
211
+ else {
212
+ const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
213
+ this._rotateStart.set(i, s);
214
+ }
215
+ }
216
+ _handleTouchStartPan(t) {
217
+ if (this._pointers.length === 1)
218
+ this._panStart.set(t.pageX, t.pageY);
219
+ else {
220
+ const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
221
+ this._panStart.set(i, s);
222
+ }
223
+ }
224
+ _handleTouchStartDolly(t) {
225
+ const e = this._getSecondPointerPosition(t), i = t.pageX - e.x, s = t.pageY - e.y, n = Math.sqrt(i * i + s * s);
226
+ this._dollyStart.set(0, n);
227
+ }
228
+ _handleTouchStartDollyPan(t) {
229
+ this.enableZoom && this._handleTouchStartDolly(t), this.enablePan && this._handleTouchStartPan(t);
230
+ }
231
+ _handleTouchStartDollyRotate(t) {
232
+ this.enableZoom && this._handleTouchStartDolly(t), this.enableRotate && this._handleTouchStartRotate(t);
233
+ }
234
+ _handleTouchMoveRotate(t) {
235
+ if (this._pointers.length == 1)
236
+ this._rotateEnd.set(t.pageX, t.pageY);
237
+ else {
238
+ const i = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + i.x), n = 0.5 * (t.pageY + i.y);
239
+ this._rotateEnd.set(s, n);
240
+ }
241
+ this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
242
+ const e = this.domElement;
243
+ this._rotateLeft(f * this._rotateDelta.x / e.clientHeight), this._rotateUp(f * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd);
244
+ }
245
+ _handleTouchMovePan(t) {
246
+ if (this._pointers.length === 1)
247
+ this._panEnd.set(t.pageX, t.pageY);
248
+ else {
249
+ const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
250
+ this._panEnd.set(i, s);
251
+ }
252
+ this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
253
+ }
254
+ _handleTouchMoveDolly(t) {
255
+ const e = this._getSecondPointerPosition(t), i = t.pageX - e.x, s = t.pageY - e.y, n = Math.sqrt(i * i + s * s);
256
+ this._dollyEnd.set(0, n), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
257
+ const a = (t.pageX + e.x) * 0.5, h = (t.pageY + e.y) * 0.5;
258
+ this._updateZoomParameters(a, h);
259
+ }
260
+ _handleTouchMoveDollyPan(t) {
261
+ this.enableZoom && this._handleTouchMoveDolly(t), this.enablePan && this._handleTouchMovePan(t);
262
+ }
263
+ _handleTouchMoveDollyRotate(t) {
264
+ this.enableZoom && this._handleTouchMoveDolly(t), this.enableRotate && this._handleTouchMoveRotate(t);
265
+ }
266
+ // pointers
267
+ _addPointer(t) {
268
+ this._pointers.push(t.pointerId);
269
+ }
270
+ _removePointer(t) {
271
+ delete this._pointerPositions[t.pointerId];
272
+ for (let e = 0; e < this._pointers.length; e++)
273
+ if (this._pointers[e] == t.pointerId) {
274
+ this._pointers.splice(e, 1);
275
+ return;
276
+ }
277
+ }
278
+ _isTrackingPointer(t) {
279
+ for (let e = 0; e < this._pointers.length; e++)
280
+ if (this._pointers[e] == t.pointerId) return !0;
281
+ return !1;
282
+ }
283
+ _trackPointer(t) {
284
+ let e = this._pointerPositions[t.pointerId];
285
+ e === void 0 && (e = new g(), this._pointerPositions[t.pointerId] = e), e.set(t.pageX, t.pageY);
286
+ }
287
+ _getSecondPointerPosition(t) {
288
+ const e = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
289
+ return this._pointerPositions[e];
290
+ }
291
+ //
292
+ _customWheelEvent(t) {
293
+ const e = t.deltaMode, i = {
294
+ clientX: t.clientX,
295
+ clientY: t.clientY,
296
+ deltaY: t.deltaY
297
+ };
298
+ switch (e) {
299
+ case 1:
300
+ i.deltaY *= 16;
301
+ break;
302
+ case 2:
303
+ i.deltaY *= 100;
304
+ break;
305
+ }
306
+ return t.ctrlKey && !this._controlActive && (i.deltaY *= 10), i;
307
+ }
308
+ }
309
+ function st(o) {
310
+ this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(o.pointerId), this.domElement.ownerDocument.addEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(o) && (this._addPointer(o), o.pointerType === "touch" ? this._onTouchStart(o) : this._onMouseDown(o)));
311
+ }
312
+ function nt(o) {
313
+ this.enabled !== !1 && (o.pointerType === "touch" ? this._onTouchMove(o) : this._onMouseMove(o));
314
+ }
315
+ function ot(o) {
316
+ switch (this._removePointer(o), this._pointers.length) {
317
+ case 0:
318
+ this.domElement.releasePointerCapture(o.pointerId), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(H), this.state = l.NONE;
319
+ break;
320
+ case 1:
321
+ const t = this._pointers[0], e = this._pointerPositions[t];
322
+ this._onTouchStart({ pointerId: t, pageX: e.x, pageY: e.y });
323
+ break;
324
+ }
325
+ }
326
+ function at(o) {
327
+ let t;
328
+ switch (o.button) {
329
+ case 0:
330
+ t = this.mouseButtons.LEFT;
331
+ break;
332
+ case 1:
333
+ t = this.mouseButtons.MIDDLE;
334
+ break;
335
+ case 2:
336
+ t = this.mouseButtons.RIGHT;
337
+ break;
338
+ default:
339
+ t = -1;
340
+ }
341
+ switch (t) {
342
+ case b.DOLLY:
343
+ if (this.enableZoom === !1) return;
344
+ this._handleMouseDownDolly(o), this.state = l.DOLLY;
345
+ break;
346
+ case b.ROTATE:
347
+ if (o.ctrlKey || o.metaKey || o.shiftKey) {
348
+ if (this.enablePan === !1) return;
349
+ this._handleMouseDownPan(o), this.state = l.PAN;
350
+ } else {
351
+ if (this.enableRotate === !1) return;
352
+ this._handleMouseDownRotate(o), this.state = l.ROTATE;
353
+ }
354
+ break;
355
+ case b.PAN:
356
+ if (o.ctrlKey || o.metaKey || o.shiftKey) {
357
+ if (this.enableRotate === !1) return;
358
+ this._handleMouseDownRotate(o), this.state = l.ROTATE;
359
+ } else {
360
+ if (this.enablePan === !1) return;
361
+ this._handleMouseDownPan(o), this.state = l.PAN;
362
+ }
363
+ break;
364
+ default:
365
+ this.state = l.NONE;
366
+ }
367
+ this.state !== l.NONE && this.dispatchEvent(j);
368
+ }
369
+ function rt(o) {
370
+ switch (this.state) {
371
+ case l.ROTATE:
372
+ if (this.enableRotate === !1) return;
373
+ this._handleMouseMoveRotate(o);
374
+ break;
375
+ case l.DOLLY:
376
+ if (this.enableZoom === !1) return;
377
+ this._handleMouseMoveDolly(o);
378
+ break;
379
+ case l.PAN:
380
+ if (this.enablePan === !1) return;
381
+ this._handleMouseMovePan(o);
382
+ break;
383
+ }
384
+ }
385
+ function ht(o) {
386
+ this.enabled === !1 || this.enableZoom === !1 || this.state !== l.NONE || (o.preventDefault(), this.dispatchEvent(j), this._handleMouseWheel(this._customWheelEvent(o)), this.dispatchEvent(H));
387
+ }
388
+ function lt(o) {
389
+ this.enabled !== !1 && this._handleKeyDown(o);
390
+ }
391
+ function ct(o) {
392
+ switch (this._trackPointer(o), this._pointers.length) {
393
+ case 1:
394
+ switch (this.touches.ONE) {
395
+ case x.ROTATE:
396
+ if (this.enableRotate === !1) return;
397
+ this._handleTouchStartRotate(o), this.state = l.TOUCH_ROTATE;
398
+ break;
399
+ case x.PAN:
400
+ if (this.enablePan === !1) return;
401
+ this._handleTouchStartPan(o), this.state = l.TOUCH_PAN;
402
+ break;
403
+ default:
404
+ this.state = l.NONE;
405
+ }
406
+ break;
407
+ case 2:
408
+ switch (this.touches.TWO) {
409
+ case x.DOLLY_PAN:
410
+ if (this.enableZoom === !1 && this.enablePan === !1) return;
411
+ this._handleTouchStartDollyPan(o), this.state = l.TOUCH_DOLLY_PAN;
412
+ break;
413
+ case x.DOLLY_ROTATE:
414
+ if (this.enableZoom === !1 && this.enableRotate === !1) return;
415
+ this._handleTouchStartDollyRotate(o), this.state = l.TOUCH_DOLLY_ROTATE;
416
+ break;
417
+ default:
418
+ this.state = l.NONE;
419
+ }
420
+ break;
421
+ default:
422
+ this.state = l.NONE;
423
+ }
424
+ this.state !== l.NONE && this.dispatchEvent(j);
425
+ }
426
+ function ut(o) {
427
+ switch (this._trackPointer(o), this.state) {
428
+ case l.TOUCH_ROTATE:
429
+ if (this.enableRotate === !1) return;
430
+ this._handleTouchMoveRotate(o), this.update();
431
+ break;
432
+ case l.TOUCH_PAN:
433
+ if (this.enablePan === !1) return;
434
+ this._handleTouchMovePan(o), this.update();
435
+ break;
436
+ case l.TOUCH_DOLLY_PAN:
437
+ if (this.enableZoom === !1 && this.enablePan === !1) return;
438
+ this._handleTouchMoveDollyPan(o), this.update();
439
+ break;
440
+ case l.TOUCH_DOLLY_ROTATE:
441
+ if (this.enableZoom === !1 && this.enableRotate === !1) return;
442
+ this._handleTouchMoveDollyRotate(o), this.update();
443
+ break;
444
+ default:
445
+ this.state = l.NONE;
446
+ }
447
+ }
448
+ function dt(o) {
449
+ this.enabled !== !1 && o.preventDefault();
450
+ }
451
+ function mt(o) {
452
+ o.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
453
+ }
454
+ function ft(o) {
455
+ o.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
456
+ }
457
+ var X = `precision highp float;
458
+
459
+ attribute float instanceIndex;
460
+
461
+ uniform vec2 uResolution;
462
+ uniform float uLineWidth;
463
+ uniform float uTime;
464
+ uniform float uCount;
465
+ uniform float uFrequency;
466
+ uniform float uAmplitude;
467
+ uniform float uPlotWidth;
468
+ uniform float uPreset;
469
+ uniform float uLodFactor;
470
+ uniform vec2 uOffset;
471
+
472
+ varying float vVanish;
473
+ varying float vSide;
474
+ varying float vProgress;
475
+ varying float vSegmentIndex;
476
+
477
+ #define PI 3.14159265359
478
+
479
+ float hash(float n) { return fract(sin(n) * 1e4); }
480
+ float noise(float x) {
481
+ float i = floor(x);
482
+ float f = fract(x);
483
+ float u = f * f * (3.0 - 2.0 * f);
484
+ return mix(hash(i), hash(i + 1.0), u);
485
+ }
486
+
487
+ float hash3(vec3 p3) {
488
+ p3 = fract(p3 * .1031);
489
+ p3 += dot(p3, p3.zyx + 31.32);
490
+ return fract((p3.x + p3.y) * p3.z);
491
+ }
492
+
493
+ float noise3D(in vec3 x) {
494
+ vec3 i = floor(x);
495
+ vec3 f = fract(x);
496
+ f = f * f * (3.0 - 2.0 * f);
497
+ return mix(mix(mix(hash3(i + vec3(0,0,0)), hash3(i + vec3(1,0,0)), f.x),
498
+ mix(hash3(i + vec3(0,1,0)), hash3(i + vec3(1,1,0)), f.x), f.y),
499
+ mix(mix(hash3(i + vec3(0,0,1)), hash3(i + vec3(1,0,1)), f.x),
500
+ mix(hash3(i + vec3(0,1,1)), hash3(i + vec3(1,1,1)), f.x), f.y), f.z);
501
+ }
502
+
503
+ vec4 getPlotPos(float index) {
504
+
505
+ float halfW = uPlotWidth * 0.5;
506
+ float x = (index / max(uCount - 1.0, 1.0)) * uPlotWidth - halfW;
507
+
508
+ float t = x * uFrequency + uTime;
509
+ int preset = int(uPreset + 0.5);
510
+ float y = 0.0;
511
+ if (preset == 0) y = sin(t) * uAmplitude;
512
+ else if (preset == 1) y = (fract(t / (2.0 * PI)) * 2.0 - 1.0) * uAmplitude;
513
+ else if (preset == 2) y = (abs(fract(t / (2.0 * PI)) * 2.0 - 1.0) * 2.0 - 1.0) * uAmplitude;
514
+ else if (preset == 3) y = (step(0.5, fract(t / (2.0 * PI))) * 2.0 - 1.0) * uAmplitude;
515
+ else if (preset == 4) {
516
+ y = (sin(t) + sin(t * 2.1) * 0.5 + sin(t * 0.5) * 1.5) * uAmplitude * 0.5;
517
+ y += cos(t * 0.2) * uAmplitude * 0.3;
518
+ }
519
+ else if (preset == 5) {
520
+ y = (sin(t) * cos(t * 1.1 + uTime) * sin(t * 0.5 - uTime * 0.5)) * uAmplitude * 2.0;
521
+ }
522
+ else if (preset == 6) {
523
+ y = (noise(t) * 2.0 - 1.0) * uAmplitude;
524
+ }
525
+ else if (preset == 7) {
526
+
527
+ y = (noise3D(vec3(x * uFrequency * 0.5, 0.0, uTime * 0.5)) * 2.0 - 1.0) * uAmplitude;
528
+ }
529
+ else {
530
+
531
+ y = 0.0;
532
+ }
533
+
534
+ return vec4(x + uOffset.x, y + uOffset.y, 0.0, 1.0);
535
+ }
536
+
537
+ void main() {
538
+ vVanish = 0.0;
539
+ vSide = position.y;
540
+
541
+ if (instanceIndex >= uCount - 1.0 || instanceIndex > uCount * uLodFactor) {
542
+ vVanish = 1.0;
543
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
544
+ return;
545
+ }
546
+
547
+ mat4 mvp = projectionMatrix * modelViewMatrix;
548
+ vec4 worldP0 = getPlotPos(instanceIndex);
549
+ vec4 worldP1 = getPlotPos(instanceIndex + 1.0);
550
+
551
+ vec4 clipP0 = mvp * worldP0;
552
+ vec4 clipP1 = mvp * worldP1;
553
+
554
+ vec2 screenP0 = (clipP0.xy / clipP0.w + 1.0) * 0.5 * uResolution;
555
+ vec2 screenP1 = (clipP1.xy / clipP1.w + 1.0) * 0.5 * uResolution;
556
+
557
+ vec2 dir = normalize(screenP1 - screenP0);
558
+ vec2 normal = vec2(-dir.y, dir.x);
559
+
560
+ vec4 clipAmp = mvp * vec4(0.0, uAmplitude, 0.0, 0.0);
561
+ float ampPixels = length((clipAmp.xy / clipAmp.w) * uResolution * 0.5);
562
+ float effectiveLineWidth = min(uLineWidth, max(ampPixels * 0.2, 0.5));
563
+
564
+ float t = position.x + 0.5;
565
+ vProgress = t;
566
+ vSegmentIndex = instanceIndex;
567
+
568
+ vec2 currentScreen = mix(screenP0, screenP1, t);
569
+ currentScreen += normal * position.y * effectiveLineWidth * 2.0;
570
+
571
+ gl_Position = vec4((currentScreen / uResolution * 2.0 - 1.0), 0.0, 1.0);
572
+ }`, pt = `precision highp float;
573
+ uniform vec3 uColor;
574
+ uniform vec3 uOutlineColor;
575
+ uniform float uOutlineWidth;
576
+ uniform float uLineWidth;
577
+ uniform float uDashScale;
578
+ uniform float uTime;
579
+
580
+ varying float vVanish;
581
+ varying float vSide;
582
+ varying float vProgress;
583
+ varying float vSegmentIndex;
584
+
585
+ void main() {
586
+ if (vVanish > 0.5) discard;
587
+
588
+
589
+ if (uDashScale > 0.0) {
590
+ float dashPos = (vSegmentIndex + vProgress) * uDashScale;
591
+ if (fract(dashPos) > 0.5) discard;
592
+ }
593
+
594
+
595
+
596
+ float dist = abs(vSide) * 2.0;
597
+
598
+
599
+
600
+ float blur = 1.5 / max(uLineWidth, 1.0);
601
+
602
+
603
+
604
+ float innerEdge = 1.0 - uOutlineWidth;
605
+
606
+
607
+ float alpha = smoothstep(1.0, 1.0 - blur, dist);
608
+
609
+
610
+ vec3 baseColor = uColor;
611
+
612
+
613
+ float innerAlpha = smoothstep(innerEdge, innerEdge - blur, dist);
614
+ vec3 color = mix(uOutlineColor, baseColor, innerAlpha);
615
+
616
+ gl_FragColor = vec4(color, alpha);
617
+ }`;
618
+ class S {
619
+ instancedMesh;
620
+ geometry;
621
+ material;
622
+ params;
623
+ static customInjection = "";
624
+ constructor(t, e = new r.Color(65416)) {
625
+ this.params = {
626
+ count: t,
627
+ frequency: 0.1,
628
+ amplitude: 20,
629
+ width: 400,
630
+ presetIndex: 0,
631
+ color: e.clone(),
632
+ lodFactor: 1,
633
+ pointSize: 2
634
+ };
635
+ const i = new r.PlaneGeometry(1, 1);
636
+ this.geometry = new r.InstancedBufferGeometry(), this.geometry.index = i.index, i.attributes.position && this.geometry.setAttribute("position", i.attributes.position);
637
+ const s = new Float32Array(t);
638
+ for (let c = 0; c < t; c++) s[c] = c;
639
+ this.geometry.setAttribute("instanceIndex", new r.InstancedBufferAttribute(s, 1));
640
+ const n = /else\s*{\s*y\s*=\s*0\.0;\s*}/g, a = X.replace(
641
+ n,
642
+ S.customInjection || "else { y = 0.0; }"
643
+ );
644
+ this.material = new r.ShaderMaterial({
645
+ uniforms: {
646
+ uTime: { value: 0 },
647
+ uCount: { value: Number(t) },
648
+ uFrequency: { value: this.params.frequency },
649
+ uAmplitude: { value: this.params.amplitude },
650
+ uPlotWidth: { value: 400 },
651
+ uPreset: { value: Number(this.params.presetIndex) },
652
+ uColor: { value: e.clone() },
653
+ uLodFactor: { value: 1 },
654
+ uResolution: { value: new r.Vector2(100, 100) },
655
+ uLineWidth: { value: 2 },
656
+ uOutlineColor: { value: new r.Color(0) },
657
+ uOutlineWidth: { value: 0 },
658
+ uDashScale: { value: 0 },
659
+ uOffset: { value: new r.Vector2(0, 0) }
660
+ },
661
+ vertexShader: a,
662
+ fragmentShader: pt,
663
+ transparent: !1,
664
+ depthWrite: !1,
665
+ depthTest: !1,
666
+ blending: r.AdditiveBlending
667
+ }), this.instancedMesh = new r.InstancedMesh(this.geometry, this.material, t), this.instancedMesh.frustumCulled = !1;
668
+ const h = new r.Object3D();
669
+ h.updateMatrix();
670
+ for (let c = 0; c < t; c++) this.instancedMesh.setMatrixAt(c, h.matrix);
671
+ }
672
+ setParams(t) {
673
+ return this.params = { ...this.params, ...t }, this;
674
+ }
675
+ color(t) {
676
+ return this.setParams({ color: t });
677
+ }
678
+ amplitude(t) {
679
+ return this.setParams({ amplitude: t });
680
+ }
681
+ frequency(t) {
682
+ return this.setParams({ frequency: t });
683
+ }
684
+ width(t) {
685
+ return this.setParams({ width: t });
686
+ }
687
+ offset(t, e) {
688
+ return this.setParams({ offset: { x: t, y: e } });
689
+ }
690
+ preset(t) {
691
+ return this.setParams({ presetIndex: t });
692
+ }
693
+ injectPresets(t) {
694
+ let e = "", i = 8;
695
+ t.forEach((a, h) => {
696
+ e += `else if (preset == ${i}) { // ${h}
697
+ y = ${a};
698
+ }
699
+ `, i++;
700
+ }), e += "else { y = 0.0; }", S.customInjection = e;
701
+ const s = /else\s*{\s*y\s*=\s*0\.0;\s*}/g, n = X.replace(s, e);
702
+ this.material.vertexShader !== n && (this.material.vertexShader = n, this.material.needsUpdate = !0);
703
+ }
704
+ update(t, e) {
705
+ const i = this.material.uniforms;
706
+ if (!i) return;
707
+ e && i.uResolution.value.set(e.pixelWidth, e.pixelHeight);
708
+ const s = this.params, n = s.autoUpdate !== !1 ? t : 0;
709
+ this.updateUniform(i.uTime, n), this.updateUniform(i.uFrequency, s.frequency), this.updateUniform(i.uAmplitude, s.amplitude), this.updateUniform(i.uPlotWidth, s.width ?? 400), this.updateUniform(i.uPreset, Number(s.presetIndex)), this.updateUniform(i.uLodFactor, s.lodFactor ?? 1), this.updateUniform(i.uLineWidth, s.pointSize ?? 2), s.color !== void 0 && i.uColor.value.set(s.color), s.borderColor !== void 0 && i.uOutlineColor.value.set(s.borderColor), this.updateUniform(i.uOutlineWidth, s.borderWidth ?? 0), this.updateUniform(i.uDashScale, s.dashScale ?? 0), s.offset && i.uOffset.value.set(s.offset.x, s.offset.y);
710
+ const a = this.calculateEffectiveCount(s, e);
711
+ this.updateUniform(i.uCount, a), this.instancedMesh.count = Math.max(0, a);
712
+ }
713
+ updateUniform(t, e) {
714
+ t.value !== e && (t.value = e);
715
+ }
716
+ calculateEffectiveCount(t, e) {
717
+ if (!e) return t.count;
718
+ const n = (t.width ?? 400) / Math.max(e.maxX - e.minX, 1e-3), a = Math.ceil(e.pixelWidth * 2 * n);
719
+ return Math.min(t.count, a);
720
+ }
721
+ get mesh() {
722
+ return this.instancedMesh;
723
+ }
724
+ getDrawStats() {
725
+ return { total: this.params.count, visible: this.instancedMesh.count };
726
+ }
727
+ dispose() {
728
+ this.geometry.dispose(), Array.isArray(this.material) ? this.material.forEach((t) => t.dispose()) : this.material.dispose();
729
+ }
730
+ }
731
+ var F = `precision highp float;
732
+ attribute float pIndex;
733
+ uniform float uTime;
734
+ uniform float uCount;
735
+ uniform float uFrequency;
736
+ uniform float uAmplitude;
737
+ uniform float uPlotWidth;
738
+ uniform float uPreset;
739
+ uniform float uPointSize;
740
+ uniform float uLodFactor;
741
+ uniform float uAdaptive;
742
+ uniform vec2 uOffset;
743
+
744
+ #define PI 3.14159265359
745
+
746
+ float hash(float n) { return fract(sin(n) * 1e4); }
747
+ float noise(float x) {
748
+ float i = floor(x);
749
+ float f = fract(x);
750
+ float u = f * f * (3.0 - 2.0 * f);
751
+ return mix(hash(i), hash(i + 1.0), u);
752
+ }
753
+
754
+ float hash3(vec3 p3) {
755
+ p3 = fract(p3 * .1031);
756
+ p3 += dot(p3, p3.zyx + 31.32);
757
+ return fract((p3.x + p3.y) * p3.z);
758
+ }
759
+
760
+ float noise3D(in vec3 x) {
761
+ vec3 i = floor(x);
762
+ vec3 f = fract(x);
763
+ f = f * f * (3.0 - 2.0 * f);
764
+ return mix(mix(mix(hash3(i + vec3(0,0,0)), hash3(i + vec3(1,0,0)), f.x),
765
+ mix(hash3(i + vec3(0,1,0)), hash3(i + vec3(1,1,0)), f.x), f.y),
766
+ mix(mix(hash3(i + vec3(0,0,1)), hash3(i + vec3(1,0,1)), f.x),
767
+ mix(hash3(i + vec3(0,1,1)), hash3(i + vec3(1,1,1)), f.x), f.y), f.z);
768
+ }
769
+
770
+ void main() {
771
+ if (pIndex > uCount * uLodFactor) {
772
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
773
+ return;
774
+ }
775
+
776
+ float halfW = uPlotWidth * 0.5;
777
+ float x = (pIndex / max(uCount - 1.0, 1.0)) * uPlotWidth - halfW;
778
+ float y = 0.0;
779
+
780
+ int preset = int(uPreset + 0.5);
781
+ float t = x * uFrequency + uTime;
782
+
783
+ if (preset == 0) y = sin(t) * uAmplitude;
784
+ else if (preset == 1) y = (fract(t / (2.0 * PI)) * 2.0 - 1.0) * uAmplitude;
785
+ else if (preset == 2) y = (abs(fract(t / (2.0 * PI)) * 2.0 - 1.0) * 2.0 - 1.0) * uAmplitude;
786
+ else if (preset == 3) y = (step(0.5, fract(t / (2.0 * PI))) * 2.0 - 1.0) * uAmplitude;
787
+ else if (preset == 4) {
788
+ y = (sin(t) + sin(t * 2.1) * 0.5 + sin(t * 0.5) * 1.5) * uAmplitude * 0.5;
789
+ y += cos(t * 0.2) * uAmplitude * 0.3;
790
+ }
791
+ else if (preset == 5) {
792
+ y = (sin(t) * cos(t * 1.1 + uTime) * sin(t * 0.5 - uTime * 0.5)) * uAmplitude * 2.0;
793
+ }
794
+ else if (preset == 6) {
795
+ y = (noise(t) * 2.0 - 1.0) * uAmplitude;
796
+ }
797
+ else if (preset == 7) {
798
+ y = (noise3D(vec3(x * uFrequency * 0.5, 0.0, uTime * 0.5)) * 2.0 - 1.0) * uAmplitude;
799
+ }
800
+ else {
801
+ y = 0.0;
802
+ }
803
+
804
+ vec4 worldPos = vec4(x + uOffset.x, y + uOffset.y, 0.0, 1.0);
805
+ vec4 mvPosition = modelViewMatrix * worldPos;
806
+ gl_PointSize = uPointSize;
807
+ gl_Position = projectionMatrix * mvPosition;
808
+ }`, gt = `precision mediump float;
809
+ uniform vec3 uColor;
810
+
811
+ void main() {
812
+ vec2 cxy = 2.0 * gl_PointCoord - 1.0;
813
+ float r = dot(cxy, cxy);
814
+
815
+
816
+ if (r > 1.0) discard;
817
+
818
+
819
+ float alpha = smoothstep(1.0, 0.5, r);
820
+ gl_FragColor = vec4(uColor, alpha);
821
+ }`;
822
+ class T {
823
+ points;
824
+ geometry;
825
+ material;
826
+ params;
827
+ static customInjection = "";
828
+ constructor(t, e = new r.Color(65416)) {
829
+ this.params = {
830
+ count: t,
831
+ frequency: 0.1,
832
+ amplitude: 20,
833
+ width: 400,
834
+ presetIndex: 0,
835
+ color: e.clone(),
836
+ lodFactor: 1,
837
+ pointSize: 5,
838
+ adaptive: !0,
839
+ autoSubsampling: !0,
840
+ autoCulling: !0
841
+ }, this.geometry = this.initGeometry(t), this.material = this.initMaterial(t, e), this.points = new r.Points(this.geometry, this.material), this.points.frustumCulled = !1;
842
+ }
843
+ initGeometry(t) {
844
+ const e = new r.BufferGeometry(), i = new Float32Array(t);
845
+ for (let s = 0; s < t; s++) i[s] = s;
846
+ return e.setAttribute("pIndex", new r.BufferAttribute(i, 1)), e.setDrawRange(0, t), e;
847
+ }
848
+ initMaterial(t, e) {
849
+ const i = /else\s*{\s*y\s*=\s*0\.0;\s*}/g, s = F.replace(
850
+ i,
851
+ T.customInjection || "else { y = 0.0; }"
852
+ );
853
+ return new r.ShaderMaterial({
854
+ uniforms: {
855
+ uTime: { value: 0 },
856
+ uCount: { value: Number(t) },
857
+ uFrequency: { value: this.params.frequency },
858
+ uAmplitude: { value: this.params.amplitude },
859
+ uPlotWidth: { value: 400 },
860
+ uPreset: { value: Number(this.params.presetIndex) },
861
+ uPointSize: { value: this.params.pointSize },
862
+ uColor: { value: e.clone() },
863
+ uAdaptive: { value: 1 },
864
+ uLodFactor: { value: 1 },
865
+ uOffset: { value: new r.Vector2(0, 0) }
866
+ },
867
+ vertexShader: s,
868
+ fragmentShader: gt,
869
+ transparent: !1,
870
+ depthWrite: !1,
871
+ depthTest: !1,
872
+ blending: r.AdditiveBlending
873
+ });
874
+ }
875
+ setParams(t) {
876
+ return this.params = { ...this.params, ...t }, this;
877
+ }
878
+ color(t) {
879
+ return this.setParams({ color: t });
880
+ }
881
+ amplitude(t) {
882
+ return this.setParams({ amplitude: t });
883
+ }
884
+ frequency(t) {
885
+ return this.setParams({ frequency: t });
886
+ }
887
+ width(t) {
888
+ return this.setParams({ width: t });
889
+ }
890
+ offset(t, e) {
891
+ return this.setParams({ offset: { x: t, y: e } });
892
+ }
893
+ preset(t) {
894
+ return this.setParams({ presetIndex: t });
895
+ }
896
+ size(t) {
897
+ return this.setParams({ pointSize: t });
898
+ }
899
+ adaptive(t) {
900
+ return this.setParams({ adaptive: t });
901
+ }
902
+ injectPresets(t) {
903
+ let e = "", i = 8;
904
+ t.forEach((a, h) => {
905
+ e += `else if (preset == ${i}) { // ${h}
906
+ y = ${a};
907
+ }
908
+ `, i++;
909
+ }), e += "else { y = 0.0; }", T.customInjection = e;
910
+ const s = /else\s*{\s*y\s*=\s*0\.0;\s*}/g, n = F.replace(s, e);
911
+ this.material.vertexShader !== n && (this.material.vertexShader = n, this.material.needsUpdate = !0);
912
+ }
913
+ update(t, e) {
914
+ const i = this.material.uniforms;
915
+ if (!i) return;
916
+ const s = this.params, n = s.autoUpdate !== !1 ? t : 0;
917
+ this.updateUniform(i.uTime, n), this.updateUniform(i.uFrequency, s.frequency), this.updateUniform(i.uAmplitude, s.amplitude), this.updateUniform(i.uPlotWidth, s.width ?? 400), this.updateUniform(i.uPreset, Number(s.presetIndex)), this.updateUniform(i.uLodFactor, s.lodFactor ?? 1), this.updateUniform(i.uAdaptive, s.adaptive ? 1 : 0), s.color !== void 0 && i.uColor.value.set(s.color), s.offset && i.uOffset.value.set(s.offset.x, s.offset.y);
918
+ const a = this.calculateEffectiveCount(s, e), { drawStart: h, drawCount: c } = this.calculateDrawRange(a, s, e), m = this.calculatePointSize(s.pointSize ?? 5, s.count, s.adaptive ?? !0);
919
+ this.updateUniform(i.uPointSize, m), this.updateUniform(i.uCount, a), this.geometry.setDrawRange(h, c);
920
+ }
921
+ updateUniform(t, e) {
922
+ t.value !== e && (t.value = e);
923
+ }
924
+ calculateEffectiveCount(t, e) {
925
+ if (!(t.autoSubsampling ?? !0) || !e) return t.count;
926
+ const i = t.pointsPerPixel || 2, n = (t.width ?? 400) / Math.max(e.maxX - e.minX, 1e-3);
927
+ return Math.min(t.count, Math.ceil(e.pixelWidth * i * n));
928
+ }
929
+ calculateDrawRange(t, e, i) {
930
+ if (!(e.autoCulling ?? !0) || !i) return { drawStart: 0, drawCount: t };
931
+ const s = e.width ?? 400, n = -(s * 0.5), a = (i.minX - n) / s, h = (i.maxX - n) / s, c = Math.max(0, Math.floor(a * (t - 1))), m = Math.min(t - 1, Math.ceil(h * (t - 1)));
932
+ return { drawStart: c, drawCount: Math.max(1, m - c + 1) };
933
+ }
934
+ calculatePointSize(t, e, i) {
935
+ return i ? Math.max(0.1, t * Math.sqrt(1e5 / e)) : t;
936
+ }
937
+ get mesh() {
938
+ return this.points;
939
+ }
940
+ getDrawStats() {
941
+ return { total: this.params.count, visible: this.geometry.drawRange.count };
942
+ }
943
+ dispose() {
944
+ this.geometry.dispose(), Array.isArray(this.material) ? this.material.forEach((t) => t.dispose()) : this.material.dispose();
945
+ }
946
+ }
947
+ var yt = `varying vec2 vUv;
948
+ varying vec3 vWorldPos;
949
+
950
+ void main() {
951
+ vUv = uv;
952
+ vWorldPos = (modelMatrix * vec4(position, 1.0)).xyz;
953
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
954
+ }`, _t = `precision highp float;
955
+
956
+ varying vec3 vWorldPos;
957
+
958
+ uniform vec3 uColor;
959
+ uniform vec2 uOffset;
960
+ uniform float uZoom;
961
+ uniform float uThickness;
962
+ uniform float uTickStep;
963
+ uniform float uTickSize;
964
+ uniform float uSubTicks;
965
+ uniform float uSubTickSize;
966
+ uniform vec2 uRangeX;
967
+ uniform vec2 uRangeY;
968
+
969
+ float getLine(float d, float width) {
970
+ float fw = fwidth(d);
971
+ return smoothstep(width + fw, width - fw, abs(d));
972
+ }
973
+
974
+ float getPeriodicTicks(float pos, float step, float width) {
975
+ float fw = fwidth(pos);
976
+ float dist = abs(fract(pos / step + 0.5) - 0.5) * step;
977
+ return smoothstep(width + fw, width - fw, dist);
978
+ }
979
+
980
+ void main() {
981
+ vec2 relPos = vWorldPos.xy - uOffset;
982
+ float plotHeight = uRangeY.y - uRangeY.x;
983
+
984
+
985
+ float pixelSize = 1.0 / uZoom;
986
+
987
+
988
+
989
+ float lineAlpha = clamp(uThickness, 0.0, 1.0);
990
+ float tickAlpha = clamp(uThickness * 0.8, 0.0, 1.0);
991
+ float subTickAlpha = clamp(uThickness * 0.5, 0.0, 1.0);
992
+
993
+
994
+ float lineW = max(uThickness, 1.0) * pixelSize * 0.5;
995
+ float tickW = max(uThickness * 0.8, 0.8) * pixelSize * 0.5;
996
+ float subTickW = max(uThickness * 0.5, 0.5) * pixelSize * 0.5;
997
+
998
+
999
+ float maxW = plotHeight * 0.05;
1000
+ lineW = min(lineW, maxW);
1001
+ tickW = min(tickW, maxW);
1002
+ subTickW = min(subTickW, maxW);
1003
+
1004
+
1005
+ float yAxis = 0.0;
1006
+ if (relPos.y >= uRangeY.x - 1.0 && relPos.y <= uRangeY.y + 1.0) {
1007
+ yAxis = getLine(relPos.x - uRangeX.x, lineW) * lineAlpha;
1008
+ }
1009
+
1010
+ float xAxis = 0.0;
1011
+ if (relPos.x >= uRangeX.x - 1.0 && relPos.x <= uRangeX.y + 1.0) {
1012
+ xAxis = getLine(relPos.y, lineW) * lineAlpha;
1013
+ }
1014
+
1015
+
1016
+ float currentTickSize = min(uTickSize * pixelSize, plotHeight * 0.1);
1017
+ float currentSubTickSize = min(uSubTickSize * pixelSize, plotHeight * 0.05);
1018
+
1019
+ float yTicks = 0.0;
1020
+ float ySubTicks = 0.0;
1021
+ if (relPos.y >= uRangeY.x && relPos.y <= uRangeY.y) {
1022
+
1023
+ if (relPos.x >= uRangeX.x && relPos.x <= uRangeX.x + currentTickSize) {
1024
+ yTicks = getPeriodicTicks(relPos.y, uTickStep, tickW) * tickAlpha;
1025
+ }
1026
+
1027
+ if (uSubTicks > 1.0 && relPos.x >= uRangeX.x && relPos.x <= uRangeX.x + currentSubTickSize) {
1028
+ ySubTicks = getPeriodicTicks(relPos.y, uTickStep / uSubTicks, subTickW) * 0.6 * subTickAlpha;
1029
+ }
1030
+ }
1031
+
1032
+ float xTicks = 0.0;
1033
+ float xSubTicks = 0.0;
1034
+ if (relPos.x >= uRangeX.x && relPos.x <= uRangeX.y) {
1035
+
1036
+ if (abs(relPos.y) < currentTickSize) {
1037
+ xTicks = getPeriodicTicks(relPos.x, uTickStep, tickW) * tickAlpha;
1038
+ }
1039
+
1040
+ if (uSubTicks > 1.0 && abs(relPos.y) < currentSubTickSize) {
1041
+ xSubTicks = getPeriodicTicks(relPos.x, uTickStep / uSubTicks, subTickW) * 0.6 * subTickAlpha;
1042
+ }
1043
+ }
1044
+
1045
+ float combinedTicks = max(max(xTicks, yTicks), max(xSubTicks, ySubTicks));
1046
+ float finalAlpha = max(max(xAxis, yAxis), combinedTicks);
1047
+
1048
+ if (finalAlpha < 0.01) discard;
1049
+
1050
+ gl_FragColor = vec4(uColor, finalAlpha * 0.8);
1051
+ }`;
1052
+ const xt = `
1053
+ attribute vec4 aUvOffset;
1054
+ attribute vec3 aColor;
1055
+ varying vec2 vUv;
1056
+ varying vec3 vColor;
1057
+
1058
+ void main() {
1059
+ vUv = uv * aUvOffset.zw + aUvOffset.xy;
1060
+ vColor = aColor;
1061
+ gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);
1062
+ }
1063
+ `, bt = `
1064
+ varying vec2 vUv;
1065
+ varying vec3 vColor;
1066
+ uniform sampler2D uMap;
1067
+
1068
+ float median(float r, float g, float b) {
1069
+ return max(min(r, g), min(max(r, g), b));
1070
+ }
1071
+
1072
+ float contour(in float d, in float w) {
1073
+ return smoothstep(0.5 - w, 0.5 + w, d);
1074
+ }
1075
+
1076
+ float samp(in vec2 uv, float w) {
1077
+ return contour(median(texture2D(uMap, uv).r, texture2D(uMap, uv).g, texture2D(uMap, uv).b), w);
1078
+ }
1079
+
1080
+ void main() {
1081
+ vec3 msdfSample = texture2D(uMap, vUv).rgb;
1082
+ float dist = median(msdfSample.r, msdfSample.g, msdfSample.b);
1083
+ float width = fwidth(dist);
1084
+ float alpha = contour(dist, width);
1085
+
1086
+ float dscale = 0.354;
1087
+ vec2 duv = dscale * (dFdx(vUv) + dFdy(vUv));
1088
+ vec4 box = vec4(vUv - duv, vUv + duv);
1089
+
1090
+ float asum = samp(box.xy, width) + samp(box.zw, width) + samp(box.xw, width) + samp(box.zy, width);
1091
+ float opacity = (alpha + 0.5 * asum) / 3.0;
1092
+
1093
+ if (opacity < 0.01) discard;
1094
+ gl_FragColor = vec4(vColor, opacity);
1095
+ }
1096
+ `;
1097
+ class Pt {
1098
+ mesh;
1099
+ material;
1100
+ charMap = /* @__PURE__ */ new Map();
1101
+ fontData = null;
1102
+ instances = [];
1103
+ capacity;
1104
+ constructor(t = 100) {
1105
+ this.capacity = t, this.material = new r.ShaderMaterial({
1106
+ vertexShader: xt,
1107
+ fragmentShader: bt,
1108
+ uniforms: { uMap: { value: null } },
1109
+ transparent: !0,
1110
+ side: r.DoubleSide,
1111
+ depthWrite: !1
1112
+ }), this.mesh = this.createMesh(this.capacity);
1113
+ }
1114
+ createMesh(t) {
1115
+ const e = new r.PlaneGeometry(1, 1);
1116
+ e.setAttribute("aUvOffset", new r.InstancedBufferAttribute(new Float32Array(t * 4), 4)), e.setAttribute("aColor", new r.InstancedBufferAttribute(new Float32Array(t * 3), 3));
1117
+ const i = new r.InstancedMesh(e, this.material, t);
1118
+ return i.count = 0, i.frustumCulled = !1, i;
1119
+ }
1120
+ grow(t) {
1121
+ const e = Math.max(Math.ceil(t * 1.05), t + 10), i = this.mesh, s = this.createMesh(e);
1122
+ i.parent && (i.parent.add(s), i.parent.remove(i)), i.geometry.dispose(), this.mesh = s, this.capacity = e;
1123
+ }
1124
+ async load(t, e) {
1125
+ const [i, s] = await Promise.all([
1126
+ fetch(t).then((n) => n.json()),
1127
+ new r.TextureLoader().loadAsync(e)
1128
+ ]);
1129
+ this.fontData = i, this.fontData && this.fontData.chars && this.fontData.chars.forEach((n) => this.charMap.set(n.char, n)), s.minFilter = r.LinearFilter, s.magFilter = r.LinearFilter, s.generateMipmaps = !1, this.material.uniforms.uMap && (this.material.uniforms.uMap.value = s);
1130
+ }
1131
+ addText(t, e, i, s = 0.1, n = "#ffffff", a = "left") {
1132
+ return this.instances.push({
1133
+ text: t,
1134
+ position: new r.Vector3(e, i, 0),
1135
+ scale: s,
1136
+ color: new r.Color(n),
1137
+ align: a
1138
+ }), this;
1139
+ }
1140
+ clear() {
1141
+ this.instances = [];
1142
+ }
1143
+ update() {
1144
+ if (!this.fontData) return;
1145
+ let t = 0;
1146
+ for (const _ of this.instances)
1147
+ t += _.text.length;
1148
+ t > this.capacity && this.grow(t);
1149
+ let e = 0;
1150
+ const i = this.mesh.instanceMatrix.array, s = this.mesh.geometry.getAttribute("aUvOffset"), n = s.array, a = this.mesh.geometry.getAttribute("aColor"), h = a.array, c = this.fontData.common.scaleW, m = this.fontData.common.scaleH, Z = this.charMap;
1151
+ for (const _ of this.instances) {
1152
+ const M = _.text, V = M.length, P = _.scale, E = _.position, D = _.color;
1153
+ let A = 0;
1154
+ const L = this.calculateWidth(M) * P;
1155
+ let k = 0;
1156
+ _.align === "center" ? k = -L / 2 : _.align === "right" && (k = -L);
1157
+ for (let R = 0; R < V && !(e >= this.capacity); R++) {
1158
+ const O = M[R];
1159
+ if (O === void 0) continue;
1160
+ const p = Z.get(O);
1161
+ if (!p) {
1162
+ O === " " && (A += 20);
1163
+ continue;
1164
+ }
1165
+ const d = e * 16, K = p.width * P, q = p.height * P, G = E.x + k + (A + p.xoffset + p.width / 2) * P, B = E.y - (p.yoffset + p.height / 2) * P;
1166
+ i[d + 0] = K, i[d + 1] = 0, i[d + 2] = 0, i[d + 3] = 0, i[d + 4] = 0, i[d + 5] = q, i[d + 6] = 0, i[d + 7] = 0, i[d + 8] = 0, i[d + 9] = 0, i[d + 10] = 1, i[d + 11] = 0, i[d + 12] = G, i[d + 13] = B, i[d + 14] = E.z, i[d + 15] = 1;
1167
+ const v = e * 4;
1168
+ n[v + 0] = p.x / c, n[v + 1] = 1 - (p.y + p.height) / m, n[v + 2] = p.width / c, n[v + 3] = p.height / m;
1169
+ const C = e * 3;
1170
+ h[C + 0] = D.r, h[C + 1] = D.g, h[C + 2] = D.b, A += p.xadvance, e++;
1171
+ }
1172
+ }
1173
+ this.mesh.count = e, this.mesh.instanceMatrix.needsUpdate = !0, s.needsUpdate = !0, a.needsUpdate = !0;
1174
+ }
1175
+ calculateWidth(t) {
1176
+ if (!this.fontData) return 0;
1177
+ let e = 0;
1178
+ const i = this.charMap;
1179
+ for (let s = 0; s < t.length; s++) {
1180
+ const n = t[s];
1181
+ n !== void 0 && (e += i.get(n)?.xadvance ?? 20);
1182
+ }
1183
+ return e;
1184
+ }
1185
+ getStats() {
1186
+ return {
1187
+ count: this.mesh.count,
1188
+ capacity: this.capacity
1189
+ };
1190
+ }
1191
+ get meshObj() {
1192
+ return this.mesh;
1193
+ }
1194
+ }
1195
+ class N {
1196
+ engine;
1197
+ params = { offset: { x: 0, y: 0 } };
1198
+ constructor(t = 100) {
1199
+ this.engine = new Pt(t);
1200
+ }
1201
+ async load(t, e) {
1202
+ await this.engine.load(t, e);
1203
+ }
1204
+ add(t, e, i, s = 0.1, n = "#ffffff", a = "left") {
1205
+ return this.engine.addText(t, e, i, s, n, a), this;
1206
+ }
1207
+ setParams(t) {
1208
+ return this.params = { ...this.params, ...t }, this;
1209
+ }
1210
+ update(t, e) {
1211
+ this.engine.update();
1212
+ }
1213
+ get mesh() {
1214
+ return this.engine.meshObj;
1215
+ }
1216
+ getDrawStats() {
1217
+ const t = this.engine.getStats();
1218
+ return {
1219
+ total: t.capacity,
1220
+ visible: t.count
1221
+ };
1222
+ }
1223
+ clear() {
1224
+ return this.engine.clear(), this;
1225
+ }
1226
+ dispose() {
1227
+ this.engine.meshObj.geometry.dispose(), Array.isArray(this.engine.meshObj.material) ? this.engine.meshObj.material.forEach((t) => t.dispose()) : this.engine.meshObj.material.dispose();
1228
+ }
1229
+ }
1230
+ class vt {
1231
+ meshObj;
1232
+ geometry;
1233
+ material;
1234
+ params;
1235
+ textEngine;
1236
+ constructor(t = "#ffffff") {
1237
+ this.params = {
1238
+ color: new r.Color(t),
1239
+ offset: { x: 0, y: 0 },
1240
+ tickStep: 50,
1241
+ tickSize: 8,
1242
+ subTicks: 0,
1243
+ subTickSize: 4,
1244
+ minX: -200,
1245
+ maxX: 200,
1246
+ minY: -50,
1247
+ maxY: 50,
1248
+ labelSize: 0.06,
1249
+ labelColor: "#888888",
1250
+ showLabels: !1,
1251
+ labelPrecision: 0,
1252
+ thickness: 1.5
1253
+ }, this.geometry = new r.PlaneGeometry(4e3, 4e3), this.material = new r.ShaderMaterial({
1254
+ uniforms: {
1255
+ uColor: { value: this.params.color },
1256
+ uOffset: { value: new r.Vector2(0, 0) },
1257
+ uTickStep: { value: 50 },
1258
+ uTickSize: { value: 8 },
1259
+ uSubTicks: { value: 0 },
1260
+ uSubTickSize: { value: 4 },
1261
+ uRangeX: { value: new r.Vector2(-200, 200) },
1262
+ uRangeY: { value: new r.Vector2(-50, 50) },
1263
+ uZoom: { value: 1 },
1264
+ uThickness: { value: 1.5 }
1265
+ },
1266
+ vertexShader: yt,
1267
+ fragmentShader: _t,
1268
+ transparent: !0,
1269
+ depthWrite: !1,
1270
+ blending: r.AdditiveBlending
1271
+ }), this.meshObj = new r.Mesh(this.geometry, this.material), this.meshObj.position.z = -0.1;
1272
+ }
1273
+ setParams(t) {
1274
+ return this.params = { ...this.params, ...t }, this;
1275
+ }
1276
+ color(t) {
1277
+ return this.setParams({ color: t });
1278
+ }
1279
+ offset(t, e) {
1280
+ return this.setParams({ offset: { x: t, y: e } });
1281
+ }
1282
+ ticks(t, e = 8) {
1283
+ return this.setParams({ tickStep: t, tickSize: e });
1284
+ }
1285
+ subTicks(t, e = 4) {
1286
+ return this.setParams({ subTicks: t, subTickSize: e });
1287
+ }
1288
+ precision(t) {
1289
+ return this.setParams({ labelPrecision: t });
1290
+ }
1291
+ rangeY(t, e) {
1292
+ return this.setParams({ minY: t, maxY: e });
1293
+ }
1294
+ rangeX(t, e) {
1295
+ return this.setParams({ minX: t, maxX: e });
1296
+ }
1297
+ thickness(t) {
1298
+ return this.setParams({ thickness: t });
1299
+ }
1300
+ labels(t, e = 0.06, i = "#888") {
1301
+ return this.textEngine = t, this.setParams({ showLabels: !0, labelSize: e, labelColor: i });
1302
+ }
1303
+ displayLabels(t) {
1304
+ return this.setParams({ showLabels: t });
1305
+ }
1306
+ update(t, e) {
1307
+ const i = this.material.uniforms;
1308
+ if (!i) return;
1309
+ const s = this.params;
1310
+ s.color !== void 0 && i.uColor.value.set(s.color), i.uOffset.value.set(s.offset.x, s.offset.y), i.uRangeX.value.set(s.minX, s.maxX), i.uRangeY.value.set(s.minY, s.maxY), this.updateUniform(i.uTickStep, s.tickStep), this.updateUniform(i.uTickSize, s.tickSize), this.updateUniform(i.uSubTicks, s.subTicks), this.updateUniform(i.uSubTickSize, s.subTickSize), this.updateUniform(i.uZoom, e.zoom), this.updateUniform(i.uThickness, s.thickness), this.meshObj.position.x = e.minX + (e.maxX - e.minX) / 2, this.meshObj.position.y = s.offset.y, s.showLabels && this.textEngine && this.renderLabels();
1311
+ }
1312
+ renderLabels() {
1313
+ if (!this.textEngine) return;
1314
+ const t = this.params, e = this.textEngine, i = t.offset.x, s = t.offset.y, n = t.labelPrecision, a = t.minX + i - 4;
1315
+ e.add(t.maxY.toFixed(n), a, s + t.maxY, t.labelSize, t.labelColor, "right"), e.add(0 .toFixed(n), a, s, t.labelSize, t.labelColor, "right"), e.add(t.minY.toFixed(n), a, s + t.minY, t.labelSize, t.labelColor, "right");
1316
+ const h = t.tickStep, c = Math.ceil(t.minX / h) * h;
1317
+ for (let m = c; m <= t.maxX; m += h)
1318
+ Math.abs(m - t.minX) < 10 || e.add(m.toFixed(n), m + i, s - 8, t.labelSize * 0.8, t.labelColor, "center");
1319
+ }
1320
+ updateUniform(t, e) {
1321
+ t.value !== e && (t.value = e);
1322
+ }
1323
+ get mesh() {
1324
+ return this.meshObj;
1325
+ }
1326
+ getDrawStats() {
1327
+ return { total: 1, visible: 1 };
1328
+ }
1329
+ dispose() {
1330
+ this.geometry.dispose(), this.material.dispose();
1331
+ }
1332
+ }
1333
+ class wt {
1334
+ params;
1335
+ textEngine;
1336
+ dummyMesh;
1337
+ constructor() {
1338
+ this.params = {
1339
+ minX: -200,
1340
+ maxX: 200,
1341
+ minY: -50,
1342
+ maxY: 50,
1343
+ color: "#ffffff",
1344
+ size: 0.08,
1345
+ precision: 1,
1346
+ showMin: !0,
1347
+ showMax: !0,
1348
+ showRangeX: !1,
1349
+ position: "right",
1350
+ offset: { x: 0, y: 0 }
1351
+ }, this.dummyMesh = new r.Object3D();
1352
+ }
1353
+ setParams(t) {
1354
+ return this.params = { ...this.params, ...t }, this;
1355
+ }
1356
+ rangeY(t, e) {
1357
+ return this.setParams({ minY: t, maxY: e });
1358
+ }
1359
+ rangeX(t, e) {
1360
+ return this.setParams({ minX: t, maxX: e });
1361
+ }
1362
+ color(t) {
1363
+ return this.setParams({ color: t });
1364
+ }
1365
+ size(t) {
1366
+ return this.setParams({ size: t });
1367
+ }
1368
+ precision(t) {
1369
+ return this.setParams({ precision: t });
1370
+ }
1371
+ side(t) {
1372
+ return this.setParams({ position: t });
1373
+ }
1374
+ showMinMax(t, e) {
1375
+ return this.setParams({ showMin: t, showMax: e });
1376
+ }
1377
+ showRangeX(t) {
1378
+ return this.setParams({ showRangeX: t });
1379
+ }
1380
+ use(t) {
1381
+ return this.textEngine = t, this;
1382
+ }
1383
+ update(t, e) {
1384
+ if (!this.textEngine) return;
1385
+ const i = this.params, s = this.textEngine, n = i.precision, a = i.offset;
1386
+ if (i.position === "left" || i.position === "both") {
1387
+ const h = i.minX + a.x - 5;
1388
+ i.showMax && s.add(i.maxY.toFixed(n), h, i.maxY + a.y, i.size, i.color, "right"), i.showMin && s.add(i.minY.toFixed(n), h, i.minY + a.y, i.size, i.color, "right");
1389
+ }
1390
+ if (i.position === "right" || i.position === "both") {
1391
+ const h = i.maxX + a.x + 5;
1392
+ i.showMax && s.add(i.maxY.toFixed(n), h, i.maxY + a.y, i.size, i.color, "left"), i.showMin && s.add(i.minY.toFixed(n), h, i.minY + a.y, i.size, i.color, "left");
1393
+ }
1394
+ i.showRangeX && (s.add(i.minX.toFixed(n), i.minX + a.x, i.minY + a.y - 12, i.size * 0.8, i.color, "center"), s.add(i.maxX.toFixed(n), i.maxX + a.x, i.minY + a.y - 12, i.size * 0.8, i.color, "center"));
1395
+ }
1396
+ get mesh() {
1397
+ return this.dummyMesh;
1398
+ }
1399
+ getDrawStats() {
1400
+ return { total: 0, visible: 0 };
1401
+ }
1402
+ dispose() {
1403
+ }
1404
+ }
1405
+ class St {
1406
+ scene;
1407
+ camera;
1408
+ renderer;
1409
+ controls;
1410
+ container;
1411
+ animationId = null;
1412
+ resizeObserver;
1413
+ isExternalRenderer = !1;
1414
+ autoRender = !0;
1415
+ plots = /* @__PURE__ */ new Set();
1416
+ textPlots = /* @__PURE__ */ new Set();
1417
+ fontConfig;
1418
+ customPresets = /* @__PURE__ */ new Map();
1419
+ onUpdate;
1420
+ constructor(t, e = {}) {
1421
+ this.container = t, this.autoRender = e.autoRender !== !1, this.fontConfig = e.font, this.scene = e.scene || new r.Scene(), e.scene || (this.scene.background = new r.Color(657930));
1422
+ const i = this.container.clientWidth, s = this.container.clientHeight, n = i / s, a = 250;
1423
+ this.camera = e.camera || new r.OrthographicCamera(
1424
+ -a * n,
1425
+ a * n,
1426
+ a,
1427
+ -a,
1428
+ 0.1,
1429
+ 2e3
1430
+ ), e.camera || this.camera.position.set(0, 0, 500), e.renderer ? (this.renderer = e.renderer, this.isExternalRenderer = !0) : (this.renderer = new r.WebGLRenderer({
1431
+ antialias: e.antialias ?? !1,
1432
+ alpha: e.alpha ?? !1,
1433
+ powerPreference: "high-performance"
1434
+ }), this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)), this.renderer.setSize(i, s), this.container.appendChild(this.renderer.domElement)), this.controls = new it(this.camera, this.renderer.domElement), this.controls.enableDamping = !0, this.controls.enableRotate = !1, this.controls.mouseButtons = {
1435
+ LEFT: r.MOUSE.PAN,
1436
+ MIDDLE: r.MOUSE.DOLLY,
1437
+ RIGHT: r.MOUSE.ROTATE
1438
+ }, this.resizeObserver = new ResizeObserver(() => this.onResize()), this.resizeObserver.observe(this.container), this.autoRender && this.animate();
1439
+ }
1440
+ /**
1441
+ * Registers a custom signal preset that can be used by Line and Point plots.
1442
+ * @param name The name of the preset
1443
+ * @param glsl The GLSL function body that returns a float. Available variables: t (time+freq), x (world pos).
1444
+ */
1445
+ registerPreset(t, e) {
1446
+ return this.customPresets.set(t, e), this.plots.forEach((i) => {
1447
+ i.injectPresets && i.injectPresets(this.customPresets);
1448
+ }), this;
1449
+ }
1450
+ add(t, e, i) {
1451
+ let s;
1452
+ return t === "line" ? s = new S(e, new r.Color(i || "#00ff88")) : t === "point" ? s = new T(e, new r.Color(i || "#00ff88")) : t === "axis" ? s = new vt(e || "#ffffff") : t === "legend" ? s = new wt() : t === "text" && (s = new N(e || 100), this.fontConfig && this.fontConfig.json && this.fontConfig.texture && s.load(this.fontConfig.json, this.fontConfig.texture), this.textPlots.add(s)), t !== "text" && (this.plots.add(s), s.injectPresets && this.customPresets.size > 0 && s.injectPresets(this.customPresets)), this.scene.add(s.mesh), s;
1453
+ }
1454
+ line(t, e) {
1455
+ return this.add("line", t, e);
1456
+ }
1457
+ point(t, e) {
1458
+ return this.add("point", t, e);
1459
+ }
1460
+ axis(t) {
1461
+ return this.add("axis", t);
1462
+ }
1463
+ legend() {
1464
+ return this.add("legend", null);
1465
+ }
1466
+ text(t) {
1467
+ return this.add("text", t);
1468
+ }
1469
+ remove(t) {
1470
+ return this.plots.delete(t), t instanceof N && this.textPlots.delete(t), this.scene.remove(t.mesh), t.dispose(), this;
1471
+ }
1472
+ clear() {
1473
+ return this.plots.forEach((t) => {
1474
+ this.scene.remove(t.mesh), t.dispose();
1475
+ }), this.textPlots.forEach((t) => {
1476
+ this.scene.remove(t.mesh), t.dispose();
1477
+ }), this.plots.clear(), this.textPlots.clear(), this;
1478
+ }
1479
+ onResize() {
1480
+ const t = this.container.clientWidth, e = this.container.clientHeight, i = t / e, s = 250;
1481
+ this.camera.left = -s * i, this.camera.right = s * i, this.camera.top = s, this.camera.bottom = -s, this.camera.updateProjectionMatrix(), this.renderer.setSize(t, e);
1482
+ }
1483
+ getViewportStats() {
1484
+ const t = this.container.clientWidth, e = this.container.clientHeight, i = this.camera.zoom, s = this.camera.position.x + this.camera.left / i, n = this.camera.position.x + this.camera.right / i;
1485
+ return { pixelWidth: t, pixelHeight: e, minX: s, maxX: n, zoom: i };
1486
+ }
1487
+ getRendererInfo() {
1488
+ return {
1489
+ frame: this.renderer.info.render.frame,
1490
+ calls: this.renderer.info.render.calls,
1491
+ points: this.renderer.info.render.points,
1492
+ triangles: this.renderer.info.render.triangles
1493
+ };
1494
+ }
1495
+ render() {
1496
+ const t = performance.now(), e = this.getViewportStats();
1497
+ this.onUpdate && this.onUpdate(t), this.plots.forEach((i) => i.update(t / 1e3, e)), this.textPlots.forEach((i) => i.update(t / 1e3, e)), this.controls.update(), this.renderer.render(this.scene, this.camera);
1498
+ }
1499
+ animate() {
1500
+ this.autoRender && (this.animationId = requestAnimationFrame(() => this.animate()), this.render());
1501
+ }
1502
+ destroy() {
1503
+ this.animationId !== null && cancelAnimationFrame(this.animationId), this.resizeObserver.disconnect(), this.clear(), this.isExternalRenderer || (this.renderer.dispose(), this.renderer.domElement.remove()), this.controls.dispose();
1504
+ }
1505
+ }
1506
+ const Mt = {
1507
+ /**
1508
+ * Initializes a new PlotContainer in the given element.
1509
+ */
1510
+ init(o, t) {
1511
+ return new St(o, t);
1512
+ },
1513
+ /**
1514
+ * Version info
1515
+ */
1516
+ version: "1.2.0"
1517
+ };
1518
+ export {
1519
+ vt as AxisPlot,
1520
+ wt as LegendPlot,
1521
+ S as LinePlot,
1522
+ Pt as MSDFText,
1523
+ St as PlotContainer,
1524
+ T as PointPlot,
1525
+ N as TextPlot,
1526
+ Mt as ThreePlot
1527
+ };