'Cropperjs: Move and resize cropped area

What is a proper way to "restore" a crop box rectangle (or square) when cropperjs ready for use?

I have a global variable details which stores every position changes. Then I can use it to restore the previous position (size, offset, scale and etc). I know the way how to get that data (from crop() method), but I don't understand how to set it and move, scale crop box to the previous position (crop box — I mean the area over the image that you can resize, stretch when defining the region for cropping)

// gloval variable
let details;

// ...

cropper = new Cropper(document.querySelector("#image"), {
    viewMode: 3,
    zoomable: false,
    aspectRatio: 1,
    ready() {
        if (details) {
            // ... restore previous crop box position
        }
    },
    crop(event) {
        console.log(event.detail.x);
        console.log(event.detail.y);
        console.log(event.detail.width);
        console.log(event.detail.height);
        console.log(event.detail.rotate);
        console.log(event.detail.scaleX);
        console.log(event.detail.scaleY);

        details = event.detail;
    },
});

// ...

Can you advice me the proper way for it. I am using v1.5.12



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source