teTo = null) { const { width: deviceWidth, height: deviceHeight } = device; const { width: viewportWidth, height: viewportHeight } = viewport; // Determine the primary orientation of the device screen. const primaryOrientation = deviceHeight >= deviceWidth ? PORTRAIT_PRIMARY : LANDSCAPE_PRIMARY; // Determine the current orientation of the device screen. const currentOrientation = viewportHeight >= viewportWidth ? PORTRAIT_PRIMARY : LANDSCAPE_PRIMARY; // Calculate the orientation angle of the device. let angle; if (typeof angleToRotateTo === "number") { angle = angleToRotateTo; } else if (currentOrientation !== primaryOrientation) { angle = 90; } else { angle = 0; } // Calculate the orientation type of the device. let orientationType = currentOrientation; // If the viewport orientation is different from the primary orientation and the angle // to rotate to is 0, then we are moving the device orientation back to its primary // orientation. if (currentOrientation !== primaryOrientation && angleToRotateTo === 0) { orientationType = primaryOrientation; } else if (angleToRotateTo === 90 || angleToRotateTo === 270) { if (currentOrientation.includes("portrait")) { orientationType = LANDSCAPE_PRIMARY; } else if (currentOrientation.includes("landscape")) { orientationType = PORTRAIT_PRIMARY; } } return { type: orientationType, angle, }; } exports.getOrientation = getOrientation; PK