Calculate rotation angles in local mode

Hello. I have a function that calculates the degrees when I rotate an object using transformControls in “global” mode. The function works well if we are in global mode but I cannot create a similar function for when we are in local mode. I need a similar function that allows me to obtain the degrees of rotation of an object when we rotate it in local mode. I attach the function I have and it works in global mode. I hope someone can help me with this. Thank you so much.

function calculateRotation(activeAxis) {
    if (!currentlySelectedObject) return;

    const currentRotation = currentlySelectedObject.quaternion;
    const deltaRotation = new THREE.Quaternion().multiplyQuaternions(
        currentRotation,
        previousRotation.invert()
    );

    const deltaEuler = new THREE.Euler().setFromQuaternion(deltaRotation);
   
   
    switch(activeAxis) {
        case 'X':
            updateRotationWithTurns(currentlySelectedObject, 'x', deltaEuler.x);
            break;
        case 'Y':
            updateRotationWithTurns(currentlySelectedObject, 'y', deltaEuler.y);
            break;
        case 'Z':
            updateRotationWithTurns(currentlySelectedObject, 'z', deltaEuler.z);
            break;
        default:
            // Si no hay eje activo o es desconocido, actualizamos todos los ejes
            updateRotationWithTurns(currentlySelectedObject, 'x', deltaEuler.x);
            updateRotationWithTurns(currentlySelectedObject, 'y', deltaEuler.y);
            updateRotationWithTurns(currentlySelectedObject, 'z', deltaEuler.z);
    }

    previousRotation.copy(currentRotation);

    return currentlySelectedObject.userData.rotation;
}