MCPcopy Index your code
hub / github.com/cifertech/DisplayKit / enableRotate

Function enableRotate

app.js:4471–4520  ·  view source on GitHub ↗
(handle, elementId)

Source from the content-addressed store, hash-verified

4469}
4470
4471function enableRotate(handle, elementId) {
4472 let rotating = false;
4473 let startAngleDeg = 0;
4474 let startRot = 0;
4475
4476 handle.addEventListener("mousedown", (e) => {
4477 if (e.button !== 0) return;
4478 e.stopPropagation();
4479 e.preventDefault();
4480 const el = elements.find((x) => x.id === elementId);
4481 if (!el || el.locked || el.hidden) return;
4482 rotating = true;
4483 const cx = el.x + el.w / 2;
4484 const cy = el.y + el.h / 2;
4485 const p = clientToArtboardPx(e.clientX, e.clientY);
4486 startAngleDeg = Math.atan2(p.y - cy, p.x - cx) * (180 / Math.PI);
4487 startRot = Number(el.rotation) || 0;
4488 preview.classList.add("manipulating");
4489 document.addEventListener("mousemove", onRotMove);
4490 document.addEventListener("mouseup", onRotUp);
4491 });
4492
4493 function onRotMove(e) {
4494 if (!rotating) return;
4495 const el = elements.find((x) => x.id === elementId);
4496 if (!el || el.locked || el.hidden) return;
4497 const cx = el.x + el.w / 2;
4498 const cy = el.y + el.h / 2;
4499 const p = clientToArtboardPx(e.clientX, e.clientY);
4500 const a1 = Math.atan2(p.y - cy, p.x - cx) * (180 / Math.PI);
4501 let delta = a1 - startAngleDeg;
4502 while (delta > 180) delta -= 360;
4503 while (delta < -180) delta += 360;
4504 let rot = startRot + delta;
4505 if (e.shiftKey) rot = Math.round(rot / 15) * 15;
4506 el.rotation = Math.round(rot);
4507 updatePropsInputs(false);
4508 renderElements();
4509 renderLayers();
4510 updateCode();
4511 }
4512
4513 function onRotUp() {
4514 if (rotating) pushHistory();
4515 rotating = false;
4516 preview.classList.remove("manipulating");
4517 document.removeEventListener("mousemove", onRotMove);
4518 document.removeEventListener("mouseup", onRotUp);
4519 }
4520}
4521
4522
4523function enableDrag(node, id) {

Callers 1

addResizeHandlesFunction · 0.85

Calls 1

clientToArtboardPxFunction · 0.85

Tested by

no test coverage detected