@sienci/gviewer 0.1.20 → 0.1.22
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/{GCodeSVGRenderer-DrPQRfLG.js → GCodeSVGRenderer-BllsP24E.js} +53 -23
- package/dist/{GCodeSVGRenderer-ZnJwBJPk.cjs → GCodeSVGRenderer-P5rcQTaO.cjs} +3 -3
- package/dist/react.cjs +1 -1
- package/dist/react.js +4 -1
- package/dist/types/viewer/GCodeViewer.d.ts +13 -0
- package/dist/types/viewer/types.d.ts +1 -0
- package/dist/viewer.cjs +1 -1
- package/dist/viewer.js +7 -7
- package/package.json +1 -1
|
@@ -107,7 +107,7 @@ const YA = {
|
|
|
107
107
|
cutting: "#3e85c7",
|
|
108
108
|
laser: "#a855f7",
|
|
109
109
|
processed: "#6b7280",
|
|
110
|
-
boundingBox: "#
|
|
110
|
+
boundingBox: "#e2e8f0",
|
|
111
111
|
machineBed: "#fbbf24",
|
|
112
112
|
machineBedKeepout: "#df3b3b",
|
|
113
113
|
grid: { major: "#2f3840", minor: "#1f252b" },
|
|
@@ -433,10 +433,10 @@ function SP(r, Q) {
|
|
|
433
433
|
r.clone(),
|
|
434
434
|
new a.Color(Q.render.theme.colors.boundingBox)
|
|
435
435
|
), t = A.material;
|
|
436
|
-
return t.transparent = !0, t.opacity = 0.
|
|
436
|
+
return t.transparent = !0, t.opacity = 0.65, t.depthWrite = !1, t.linewidth = 2, B.add(A), Q.boundingBox.labels && B.add(...YP(r.clone(), Q)), B;
|
|
437
437
|
}
|
|
438
438
|
function YP(r, Q) {
|
|
439
|
-
const B = Q.render.theme.colors.boundingBox, A = 0.
|
|
439
|
+
const B = Q.render.theme.colors.boundingBox, A = 0.8, t = (U) => Math.abs(U) < 1e-9 ? "0" : U.toFixed(3), P = (U) => Q.units === "in" ? `${t(U / IP)} in` : `${t(U)} mm`, e = r.min, i = r.max, s = (U) => LQ(U, B, { size: 4, opacity: A }), v = s(P(e.x)), c = s(P(i.x)), n = s(P(e.y)), T = s(P(i.y)), z = s(P(e.z)), w = s(P(i.z)), o = new a.Vector3();
|
|
440
440
|
r.getSize(o);
|
|
441
441
|
const E = Math.max(2, Math.max(o.x, o.y, o.z) * 0.02), k = (e.x + i.x) / 2, h = (e.y + i.y) / 2;
|
|
442
442
|
return v.position.set(e.x - E, h, e.z - E), c.position.set(i.x + E, h, e.z - E), n.position.set(k, e.y - E, e.z - E), T.position.set(k, i.y + E, e.z - E), z.position.set(k, h, e.z - E), w.position.set(k, h, i.z + E), [v, c, n, T, z, w];
|
|
@@ -2974,10 +2974,10 @@ function Fi(r) {
|
|
|
2974
2974
|
}
|
|
2975
2975
|
};
|
|
2976
2976
|
}
|
|
2977
|
-
const Gi = 25.4;
|
|
2978
|
-
class
|
|
2977
|
+
const Gi = 25.4, fi = 500, bi = 260;
|
|
2978
|
+
class Yi {
|
|
2979
2979
|
constructor(Q) {
|
|
2980
|
-
this.viewCube = null, this.resizeObserver = null, this.onWindowResize = null, this.animationFrameId = null, this.gridGroup = null, this.axesGroup = null, this.gridLabelsGroup = null, this.boundingBoxGroup = null, this.machineBedGroup = null, this.bitMarker = null, this.preLaserBitType = "drill", this.toolpathStreams = [], this.toolpathCutBucketCount = 1, this.toolpathRotationA = 0, this.lastBitPosition = { x: 0, y: 0, z: 0, a: 0 }, this.sim3dHandle = null, this.currentLines = [], this.linePositions = null, this.renderSequence = 0, this.currentBounds = null, this.cameraFocusTransition = null, this.id = Q.id, this.container = Q.container, this.callbacks = Q.callbacks ?? {}, this.options = Et(GP, Q.options), this.canvas = document.createElement("canvas"), this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", this.container.appendChild(this.canvas), KP(this.container), this.renderer = new a.WebGLRenderer({
|
|
2980
|
+
this.viewCube = null, this.resizeObserver = null, this.onWindowResize = null, this.animationFrameId = null, this.gridGroup = null, this.axesGroup = null, this.gridLabelsGroup = null, this.boundingBoxGroup = null, this.machineBedGroup = null, this.bitMarker = null, this.preLaserBitType = "drill", this.toolpathStreams = [], this.toolpathCutBucketCount = 1, this.toolpathRotationA = 0, this.lastBitPosition = { x: 0, y: 0, z: 0, a: 0 }, this.sim3dHandle = null, this.currentLines = [], this.linePositions = null, this.renderSequence = 0, this.currentBounds = null, this.cameraFocusTransition = null, this.cameraFollowRequested = !1, this.cameraFollowInterrupted = !1, this.cameraFollowOffset = null, this.id = Q.id, this.container = Q.container, this.callbacks = Q.callbacks ?? {}, this.options = Et(GP, Q.options), this.canvas = document.createElement("canvas"), this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.display = "block", this.container.appendChild(this.canvas), KP(this.container), this.renderer = new a.WebGLRenderer({
|
|
2981
2981
|
canvas: this.canvas,
|
|
2982
2982
|
antialias: this.options.render.antialias
|
|
2983
2983
|
}), this.renderer.setPixelRatio(window.devicePixelRatio), this.renderer.setClearColor(this.options.render.theme.background, 1), this.scene = new a.Scene(), this.scene.add(new a.AmbientLight(16777215, 0.8));
|
|
@@ -2988,7 +2988,9 @@ class Ii {
|
|
|
2988
2988
|
this.options.camera.initialPosition.x,
|
|
2989
2989
|
this.options.camera.initialPosition.y,
|
|
2990
2990
|
this.options.camera.initialPosition.z
|
|
2991
|
-
), this.controls = new lP(this.camera, this.renderer.domElement), this.controls.enableDamping = this.options.camera.orbit.enableDamping, this.controls.
|
|
2991
|
+
), this.controls = new lP(this.camera, this.renderer.domElement), this.controls.enableDamping = this.options.camera.orbit.enableDamping, this.controls.addEventListener("start", () => {
|
|
2992
|
+
this.cameraFollowRequested && (this.cameraFollowInterrupted = !0);
|
|
2993
|
+
}), this.controls.update(), this.viewCubeCorrection = new a.Matrix4().makeRotationX(a.MathUtils.degToRad(90)), this.viewCube = new xP({
|
|
2992
2994
|
container: this.container,
|
|
2993
2995
|
onSelectView: (t) => {
|
|
2994
2996
|
const P = new a.Vector3();
|
|
@@ -3007,7 +3009,29 @@ class Ii {
|
|
|
3007
3009
|
}
|
|
3008
3010
|
setBitPosition(Q, B) {
|
|
3009
3011
|
var A;
|
|
3010
|
-
this.ensureBitMarker(), this.lastBitPosition = { ...this.lastBitPosition, ...Q }, (A = this.bitMarker) == null || A.setTarget(Q, B)
|
|
3012
|
+
if (this.ensureBitMarker(), this.lastBitPosition = { ...this.lastBitPosition, ...Q }, (A = this.bitMarker) == null || A.setTarget(Q, B), this.cameraFollowRequested && !this.cameraFollowInterrupted && this.cameraFollowOffset) {
|
|
3013
|
+
const t = new a.Vector3(this.lastBitPosition.x, this.lastBitPosition.y, this.controls.target.z), P = t.clone().add(this.cameraFollowOffset);
|
|
3014
|
+
this.startCameraLerp(t, P, bi);
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Enable or disable "follow tool" camera tracking. While enabled, every
|
|
3019
|
+
* subsequent setBitPosition() call pans the camera+target in X/Y to keep
|
|
3020
|
+
* the tool centered, holding the camera→target offset captured at engage
|
|
3021
|
+
* time constant — which is what preserves viewing angle and height. A
|
|
3022
|
+
* user-initiated camera drag (OrbitControls "start") interrupts an active
|
|
3023
|
+
* session; it only re-arms on the next disabled→enabled edge.
|
|
3024
|
+
*/
|
|
3025
|
+
setCameraFollowEnabled(Q) {
|
|
3026
|
+
if (Q === this.cameraFollowRequested)
|
|
3027
|
+
return;
|
|
3028
|
+
if (this.cameraFollowRequested = Q, this.cameraFollowInterrupted = !1, !Q) {
|
|
3029
|
+
this.cameraFollowOffset = null;
|
|
3030
|
+
return;
|
|
3031
|
+
}
|
|
3032
|
+
this.cameraFollowOffset = this.camera.position.clone().sub(this.controls.target);
|
|
3033
|
+
const B = new a.Vector3(this.lastBitPosition.x, this.lastBitPosition.y, this.controls.target.z), A = B.clone().add(this.cameraFollowOffset);
|
|
3034
|
+
this.startCameraLerp(B, A, fi);
|
|
3011
3035
|
}
|
|
3012
3036
|
setBitVisible(Q) {
|
|
3013
3037
|
var B;
|
|
@@ -3104,13 +3128,19 @@ class Ii {
|
|
|
3104
3128
|
}
|
|
3105
3129
|
startSnapToView(Q, B, A, t) {
|
|
3106
3130
|
const P = JA(Q), e = B.clone().add(P.multiplyScalar(A)), i = Math.max(1, A);
|
|
3107
|
-
this.camera.near = i / 1e3, this.camera.far = i * 50, this.camera.updateProjectionMatrix(), this.
|
|
3131
|
+
this.camera.near = i / 1e3, this.camera.far = i * 50, this.camera.updateProjectionMatrix(), this.startCameraLerp(B, e, t);
|
|
3132
|
+
}
|
|
3133
|
+
// Shared tween kickoff for any camera position+target move (view snapping,
|
|
3134
|
+
// model focus, tool-follow engage/track): saves/restores damping around the
|
|
3135
|
+
// transition and hands off to updateCameraFocusTransition() each frame.
|
|
3136
|
+
startCameraLerp(Q, B, A) {
|
|
3137
|
+
this.cameraFocusTransition && (this.controls.enableDamping = this.cameraFocusTransition.dampingEnabled), this.cameraFocusTransition = {
|
|
3108
3138
|
startedAt: performance.now(),
|
|
3109
|
-
duration:
|
|
3139
|
+
duration: A,
|
|
3110
3140
|
fromPosition: this.camera.position.clone(),
|
|
3111
|
-
toPosition:
|
|
3141
|
+
toPosition: B,
|
|
3112
3142
|
fromTarget: this.controls.target.clone(),
|
|
3113
|
-
toTarget:
|
|
3143
|
+
toTarget: Q,
|
|
3114
3144
|
dampingEnabled: this.controls.enableDamping
|
|
3115
3145
|
}, this.controls.enableDamping = !1;
|
|
3116
3146
|
}
|
|
@@ -3497,7 +3527,7 @@ function Et(r, Q) {
|
|
|
3497
3527
|
var A, t, P, e;
|
|
3498
3528
|
if (!Q)
|
|
3499
3529
|
return { ...r };
|
|
3500
|
-
const B =
|
|
3530
|
+
const B = gi(r.render.theme, (A = Q.render) == null ? void 0 : A.theme);
|
|
3501
3531
|
return {
|
|
3502
3532
|
...r,
|
|
3503
3533
|
...Q,
|
|
@@ -3526,7 +3556,7 @@ function Et(r, Q) {
|
|
|
3526
3556
|
}
|
|
3527
3557
|
};
|
|
3528
3558
|
}
|
|
3529
|
-
function
|
|
3559
|
+
function gi(r, Q) {
|
|
3530
3560
|
var B, A;
|
|
3531
3561
|
return Q ? {
|
|
3532
3562
|
...r,
|
|
@@ -3539,7 +3569,7 @@ function fi(r, Q) {
|
|
|
3539
3569
|
}
|
|
3540
3570
|
} : r;
|
|
3541
3571
|
}
|
|
3542
|
-
const
|
|
3572
|
+
const pi = {
|
|
3543
3573
|
rapidColor: "#0ef6ae",
|
|
3544
3574
|
cutColor: "#3e85c7",
|
|
3545
3575
|
boundingBoxColor: "#d0d0d0",
|
|
@@ -3551,7 +3581,7 @@ const bi = {
|
|
|
3551
3581
|
originColor: "#ffffff",
|
|
3552
3582
|
crosshairColor: "#ffffff"
|
|
3553
3583
|
}, eB = 0, iB = 0;
|
|
3554
|
-
class
|
|
3584
|
+
class Vi {
|
|
3555
3585
|
constructor(Q, B) {
|
|
3556
3586
|
this.crosshairPos = null, this.crosshairVisible = !1, this.pathEls = [], this.segmentGroups = [], this.workerMode = !1, this.viewBox = { x: 0, y: 0, w: 100, h: 100 }, this.rotX = eB, this.rotY = iB, this.centerX = 0, this.centerY = 0, this.centerZ = 0, this.focalLength = 500, this.cosRotX = 1, this.sinRotX = 0, this.cosRotY = 1, this.sinRotY = 0, this.dragMode = "none", this.activePointers = /* @__PURE__ */ new Map(), this.pinchLastDist = 0, this.pinchLastMid = { x: 0, y: 0 }, this.rafPending = !1, this.rapidVerts = new Float32Array(0), this.cutVerts = new Float32Array(0), this.bounds = { minX: 0, minY: 0, maxX: 0, maxY: 0, minZ: 0, maxZ: 0, empty: !0 }, this.project = (A, t, P) => {
|
|
3557
3587
|
const e = A - this.centerX, i = t - this.centerY, s = P - this.centerZ, v = e * this.cosRotY + s * this.sinRotY, c = i, n = -e * this.sinRotY + s * this.cosRotY, T = v, z = c * this.cosRotX - n * this.sinRotX, w = c * this.sinRotX + n * this.cosRotX;
|
|
@@ -3619,7 +3649,7 @@ class Si {
|
|
|
3619
3649
|
} else this.activePointers.size === 0 && (this.dragMode = "none", this.svg.style.cursor = "grab");
|
|
3620
3650
|
}, this.onContextMenu = (A) => {
|
|
3621
3651
|
A.preventDefault();
|
|
3622
|
-
}, this.options = { ...
|
|
3652
|
+
}, this.options = { ...pi, ...B }, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.cssText = "width:100%;height:100%;display:block;cursor:grab;user-select:none;touch-action:none;", this.svg.setAttribute("preserveAspectRatio", "xMidYMid meet"), this.svg.setAttribute("xmlns", "http://www.w3.org/2000/svg"), this.bboxPath = qB(), this.pathLayer = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.bboxLabelX = _B("middle", "hanging"), this.bboxLabelY = _B("start", "middle"), this.bboxLabelZ = _B("middle", "auto"), this.originMarker = document.createElementNS("http://www.w3.org/2000/svg", "circle"), this.originMarker.setAttribute("stroke-opacity", "0.4"), this.originMarker.setAttribute("visibility", "hidden"), this.crosshairEl = qB(), this.crosshairEl.setAttribute("fill", "none"), this.crosshairEl.setAttribute("visibility", "hidden"), this.svg.appendChild(this.bboxPath), this.svg.appendChild(this.pathLayer), this.svg.appendChild(this.bboxLabelX), this.svg.appendChild(this.bboxLabelY), this.svg.appendChild(this.bboxLabelZ), this.svg.appendChild(this.originMarker), this.svg.appendChild(this.crosshairEl), Q.appendChild(this.svg), this.applyOptions(), this.bindEvents();
|
|
3623
3653
|
}
|
|
3624
3654
|
// ── Public API ────────────────────────────────────────────────────────────
|
|
3625
3655
|
loadFromLines(Q) {
|
|
@@ -3723,7 +3753,7 @@ class Si {
|
|
|
3723
3753
|
}
|
|
3724
3754
|
// ── Rendering ─────────────────────────────────────────────────────────────
|
|
3725
3755
|
rebuildAndRender(Q = !1) {
|
|
3726
|
-
const B = Q ?
|
|
3756
|
+
const B = Q ? mi : L, A = String(this.options.strokeWidth);
|
|
3727
3757
|
for (; this.pathEls.length < this.segmentGroups.length; ) {
|
|
3728
3758
|
const t = qB();
|
|
3729
3759
|
this.pathLayer.appendChild(t), this.pathEls.push(t);
|
|
@@ -3732,7 +3762,7 @@ class Si {
|
|
|
3732
3762
|
this.pathLayer.removeChild(this.pathEls.pop());
|
|
3733
3763
|
for (let t = 0; t < this.segmentGroups.length; t++) {
|
|
3734
3764
|
const { color: P, opacity: e, verts: i } = this.segmentGroups[t], s = this.pathEls[t];
|
|
3735
|
-
s.setAttribute("stroke", P), s.setAttribute("stroke-opacity", String(e)), s.setAttribute("stroke-width", A), s.setAttribute("stroke-linecap", "round"), s.setAttribute("stroke-linejoin", "round"), s.setAttribute("d",
|
|
3765
|
+
s.setAttribute("stroke", P), s.setAttribute("stroke-opacity", String(e)), s.setAttribute("stroke-width", A), s.setAttribute("stroke-linecap", "round"), s.setAttribute("stroke-linejoin", "round"), s.setAttribute("d", xi(i, this.project, B));
|
|
3736
3766
|
}
|
|
3737
3767
|
this.renderBbox(), this.renderOriginMarker(), this.renderCrosshairMarker(), this.applyViewBox();
|
|
3738
3768
|
}
|
|
@@ -3843,13 +3873,13 @@ function at(r, Q, B) {
|
|
|
3843
3873
|
function L(r) {
|
|
3844
3874
|
return r.toFixed(2);
|
|
3845
3875
|
}
|
|
3846
|
-
function
|
|
3876
|
+
function mi(r) {
|
|
3847
3877
|
return Math.round(r) + "";
|
|
3848
3878
|
}
|
|
3849
3879
|
function QA(r) {
|
|
3850
3880
|
return r.toFixed(2);
|
|
3851
3881
|
}
|
|
3852
|
-
function
|
|
3882
|
+
function xi(r, Q, B) {
|
|
3853
3883
|
if (r.length === 0) return "";
|
|
3854
3884
|
const A = [], t = 1e-6;
|
|
3855
3885
|
let P = NaN, e = NaN;
|
|
@@ -3869,9 +3899,9 @@ function BA(...r) {
|
|
|
3869
3899
|
return { minX: Q, minY: B, maxX: t, maxY: P, minZ: A, maxZ: e, empty: i };
|
|
3870
3900
|
}
|
|
3871
3901
|
export {
|
|
3872
|
-
|
|
3902
|
+
Vi as G,
|
|
3873
3903
|
xP as V,
|
|
3874
|
-
|
|
3904
|
+
Yi as a,
|
|
3875
3905
|
YA as b,
|
|
3876
3906
|
GP as d
|
|
3877
3907
|
};
|