/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Templates
* Free version
* Unminify code for Dev
**/
var pdappWAPI = {
    get: function (e, t, n) {
        const o = new XMLHttpRequest();
        o.open("GET", e, !0),
            void 0 !== n && (o.responseType = n),
            o.setRequestHeader("Cache-Control", "no-cache"),
            (o.onreadystatechange = function () {
                if (o.readyState === XMLHttpRequest.DONE) {
                    let e = !1;
                    200 === o.status && null != o.response && "" != o.response && (e = o.response),
                        "function" == typeof t && t(e);
                }
            }),
            o.send();
    },
    post: function (e, t, n) {
        let o = new FormData();
        for (let e in t) o.append(e, t[e]);
        const a = new XMLHttpRequest();
        a.open("POST", e, !0),
            a.setRequestHeader("Cache-Control", "no-cache"),
            (a.onreadystatechange = function () {
                if (a.readyState === XMLHttpRequest.DONE) {
                    let e = !1;
                    if (200 === a.status && null != a.response && "" != a.response)
                        try {
                            e = JSON.parse(a.response);
                        } catch (t) {
                            e = !1;
                        }
                    "function" == typeof n && n(e);
                }
            }),
            a.send(o);
    },
    getPhoto: function (e) {
        pdappWAPI.get(
            e.value,
            function (t) {
                (e.value = t), t && void 0 !== t.type && self.postMessage(e);
            },
            "blob"
        );
    },
    getPhotoReplace: function (e) {
        pdappWAPI.get(
            e.value,
            function (t) {
                (e.value = t), t && void 0 !== t.type && self.postMessage(e);
            },
            "blob"
        );
    },
    toBase64: function (e) {
        const t = new FileReader();
        t.readAsDataURL(e.value),
            (t.onload = function () {
                (e.value = t.result), -1 != e.value.indexOf(";base64,") && self.postMessage(e);
            });
    },
    cropOrigImg: function (e) {
        let t = (function (e) {
            let t = e.split(";base64,");
            if (2 != t.length) return !1;
            let n = t[0],
                o = atob(t[1]),
                a = new ArrayBuffer(o.length),
                s = new Uint8Array(a);
            for (var i = 0; i < o.length; i++) s[i] = o.charCodeAt(i);
            return new Blob([a], { type: n.replace("data:", "") });
        })(e.url);
        t && void 0 !== t.type
            ? createImageBitmap(t).then(function (t) {
                  let n = new OffscreenCanvas(e.crop.width, e.crop.height);
                  n
                      .getContext("2d")
                      .drawImage(
                          t,
                          e.crop.left,
                          e.crop.top,
                          e.imgSize.width,
                          e.imgSize.height,
                          0,
                          0,
                          e.imgSize.width,
                          e.imgSize.height
                      ),
                      n.convertToBlob().then((t) => {
                          const n = new FileReader();
                          n.readAsDataURL(t),
                              (n.onload = function () {
                                  let t = n.result;
                                  self.postMessage({ id: e.targetID, value: t, hisID: e.hisID, action: e.action });
                              });
                      });
              })
            : self.postMessage({ id: e.targetID, value: "", hisID: e.hisID, action: e.action });
    },
};
self.onmessage = function (e) {
    const t = e.data;
    "function" == typeof pdappWAPI[t.action] && pdappWAPI[t.action](t);
};