/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Templates
* Free version
* Unminify code for Dev
**/
var pdappAPI = {
    text: {
        createText: function (e) {
            let t = document.createElementNS("http://www.w3.org/2000/svg", "text"),
                p = {};
            return (
                (p.stroke = e.stroke),
                (p["stroke-width"] = e.strokeWidth),
                (p["font-weight"] = e.fontWeight),
                (p["font-style"] = e.fontStyle),
                (p["text-decoration"] = e.textDecoration),
                (p["stroke-linecap"] = "round"),
                (p["stroke-linejoin"] = "round"),
                (p["text-anchor"] = "start"),
                (p["font-size"] = e.fontSize),
                (p["font-family"] = e.fontFamily),
                pdappAPI.tool.generalAttr(p, t)
            );
        },
        createG: function (e, t, p) {
            let a = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                o = {};
            return (
                (o.id = e),
                (o.class = p),
                (o.style = "transform: translate(0, 0) rotate(0deg)"),
                (o["data-text"] = t.text),
                (o.fill = t.color),
                pdappAPI.tool.generalAttr(o, a)
            );
        },
        create: function (e, t) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let p = jQuery(".pdapp-viewport svg.pdapp-selecto-area"),
                a = {
                    text: "Add your text",
                    color: "#000000",
                    fontSize: 14,
                    fontFamily: "Quicksand",
                    stroke: "#000000",
                    strokeWidth: 0,
                    fontWeight: "normal",
                    fontStyle: "normal",
                    textDecoration: "none",
                    textTransform: "none",
                    textLock: !1,
                    arc: {},
                };
            if (void 0 !== e.text) for (let t in a) "thumb" != t && void 0 !== e[t] && (a[t] = e[t]);
            if (void 0 === a.arc.radius) {
                let e = "pdapp-target-" + pdappAPI.tool.uID(),
                    o = pdappAPI.text.createText(a);
                o.innerHTML = "none" == a.textTransform ? a.text : a.text.toUpperCase();
                let r = pdappAPI.text.createG(e, a, "pdapp-target pdapp-svg-text");
                r.appendChild(o),
                    p.append(r),
                    pdappAPI.layer.afterAdded(e),
                    setTimeout(() => {
                        let p = jQuery("#" + e);
                        (a = pdappAPI.text.autoSetSize(p, a)),
                            pdappAPI.layer.select(p),
                            "function" == typeof t && t(p, a);
                    }, 1);
            } else this.arc.create(a, t);
        },
        autoSetSize: function (e, t) {
            let p = jQuery(".pdapp-viewport svg.pdapp-selecto-area")[0].getBoundingClientRect(),
                a = e[0].getBoundingClientRect();
            if (0 == p.width || 0 == a.width) return t;
            if (p.width - (a.width + 15) < 0 || p.height - (a.height + 15) < 0) {
                let o = 1;
                o = p.width / a.width > p.height / a.height ? (p.height - 30) / a.height : (p.width - 30) / a.width;
                let r = pdappAPI.tool.getTransform(e);
                if ("" != r) {
                    let p = r.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                    6 == p.length && ((p[0] = parseFloat(p[0]) * o), (p[3] = p[0])),
                        e.attr("transform", "matrix(" + p.join(", ") + ")"),
                        setTimeout(() => {
                            pdappAPI.tool.centerAll(e);
                        }),
                        (t.fontSize = t.fontSize * o);
                }
            }
            return t;
        },
        arc: {
            pdappCircleType: {},
            create: function (e, t) {
                let p = this,
                    a = jQuery(".pdapp-viewport");
                if (0 == a.find(".pdapp-text-arc").length) return !1;
                let o = "pdapp-target-" + pdappAPI.tool.uID(),
                    r = e.text.replaceAll(" ", "&nbsp;"),
                    n = document.createElement("div");
                n.setAttribute(
                    "style",
                    "position:absolute;top:0px;left:0px;width:100%;height:100%;font-size:" +
                        e.fontSize +
                        "px;font-family:" +
                        e.fontFamily +
                        ";"
                ),
                    n.setAttribute("class", "pdapp-arc-elm " + o),
                    (n.innerHTML = r),
                    a.find(".pdapp-text-arc")[0].append(n);
                let i = new CircleType(n);
                0 != e.arc.radius && i.radius(e.arc.radius),
                    -1 == e.arc.dir && i.dir(e.arc.dir),
                    setTimeout(() => {
                        (p.pdappCircleType[o] = i),
                            setTimeout(() => {
                                let r = "pdapp-target pdapp-svg-text pdapp-arc";
                                -1 == e.arc.dir && (r += " pdapp-dir");
                                let i = !0,
                                    l = pdappAPI.text.createG(o, e, r);
                                l.setAttribute("data-radius", e.arc.radius),
                                    jQuery(n)
                                        .find("span")
                                        .each(function () {
                                            let t = jQuery(this).html();
                                            t = t.replace("&nbsp;", "").replace("&amp;", "");
                                            let p = pdappAPI.tool.getTransform(jQuery(this));
                                            if ("" == p) i = !1;
                                            else {
                                                let a = jQuery(this).css("transform-origin"),
                                                    o = document.createElementNS("http://www.w3.org/2000/svg", "g");
                                                o.setAttribute(
                                                    "style",
                                                    "transform:" + p + ";transform-origin:" + a + ";"
                                                ),
                                                    (o.innerHTML =
                                                        '<text stroke="' +
                                                        e.stroke +
                                                        '" stroke-width="' +
                                                        e.strokeWidth +
                                                        '" font-weight="' +
                                                        e.fontWeight +
                                                        '" font-style="' +
                                                        e.fontStyle +
                                                        '" text-decoration="' +
                                                        e.textDecoration +
                                                        '" stroke-linecap="round" stroke-linejoin="round" text-anchor="start" font-size="' +
                                                        e.fontSize +
                                                        '" font-family="' +
                                                        e.fontFamily +
                                                        '">' +
                                                        t +
                                                        "</text>"),
                                                    l.appendChild(o);
                                            }
                                        }),
                                    i
                                        ? (a.find("svg.pdapp-selecto-area").append(l),
                                          pdappAPI.layer.afterAdded(o),
                                          setTimeout(() => {
                                              let a = jQuery("#" + o);
                                              (e = pdappAPI.text.autoSetSize(a, e)),
                                                  pdappAPI.layer.select(a),
                                                  "function" == typeof t && t(a, e),
                                                  p.convertTransform("#" + o + " g");
                                          }, 1))
                                        : setTimeout(() => {
                                              let i = pdappAPI.text.createG(o, e, r);
                                              i.setAttribute("data-radius", e.arc.radius),
                                                  jQuery(n)
                                                      .find("span")
                                                      .each(function () {
                                                          let t = jQuery(this).html();
                                                          t = t.replace("&nbsp;", "").replace("&amp;", "");
                                                          let p = pdappAPI.tool.getTransform(jQuery(this)),
                                                              a = jQuery(this).css("transform-origin"),
                                                              o = document.createElementNS(
                                                                  "http://www.w3.org/2000/svg",
                                                                  "g"
                                                              );
                                                          o.setAttribute(
                                                              "style",
                                                              "transform:" + p + ";transform-origin:" + a + ";"
                                                          ),
                                                              (o.innerHTML =
                                                                  '<text stroke="' +
                                                                  e.stroke +
                                                                  '" stroke-width="' +
                                                                  e.strokeWidth +
                                                                  '" font-weight="' +
                                                                  e.fontWeight +
                                                                  '" font-style="' +
                                                                  e.fontStyle +
                                                                  '" text-decoration="' +
                                                                  e.textDecoration +
                                                                  '" stroke-linecap="round" stroke-linejoin="round" text-anchor="start" font-size="' +
                                                                  e.fontSize +
                                                                  '" font-family="' +
                                                                  e.fontFamily +
                                                                  '">' +
                                                                  t +
                                                                  "</text>"),
                                                              i.appendChild(o);
                                                      }),
                                                  a.find("svg.pdapp-selecto-area").append(i),
                                                  pdappAPI.layer.afterAdded(o),
                                                  setTimeout(() => {
                                                      let a = jQuery("#" + o);
                                                      (e = pdappAPI.text.autoSetSize(a, e)),
                                                          pdappAPI.layer.select(a),
                                                          "function" == typeof t && t(a, e),
                                                          p.convertTransform("#" + o + " g");
                                                  }, 1);
                                          }, 50);
                            }, 1);
                    }, 5);
            },
            update: function (e, t, p, a = !1) {
                let o = this,
                    r = jQuery(t),
                    n = r.attr("id"),
                    i = jQuery(".pdapp-viewport .pdapp-text-arc ." + n),
                    l = void 0 === r.attr("data-radius") ? 0 : r.attr("data-radius");
                if (void 0 !== pdappAPI.text.arc.pdappCircleType[n] && 0 == a)
                    pdappAPI.text.arc.pdappCircleType[n].radius(l);
                else {
                    let t = e.replaceAll(" ", "&nbsp;");
                    i.html(t),
                        (pdappAPI.text.arc.pdappCircleType[n] = new CircleType(i[0]).radius(l)),
                        r.hasClass("pdapp-dir") && pdappAPI.text.arc.pdappCircleType[n].dir(-1);
                }
                setTimeout(() => {
                    r = jQuery(t);
                    let e = "",
                        a = "",
                        l = r.find("text").prop("attributes");
                    jQuery.each(l, function () {
                        "style" != this.name &&
                            "font-style" != this.name &&
                            "font-weight" != this.name &&
                            (a += this.name + '="' + this.value + '" ');
                    }),
                        (a += 'font-style="' + i.css("font-style") + '" font-weight="' + i.css("font-weight") + '"');
                    let d = !0;
                    i.find("span").each(function () {
                        let t = jQuery(this).html();
                        t = t.replace("&nbsp;", "").replace("&amp;", "");
                        let p = pdappAPI.tool.getTransform(jQuery(this));
                        "" == p && (d = !1);
                        let o = jQuery(this).css("transform-origin");
                        e +=
                            '<g style="transform:' +
                            p +
                            ";transform-origin:" +
                            o +
                            ';"><text ' +
                            a +
                            ">" +
                            t +
                            "</text></g>";
                    }),
                        "" != e &&
                            (d
                                ? (r.html(e),
                                  "function" == typeof p && p(n),
                                  (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                  setTimeout(() => {
                                      (pdappAPI.tool.pdappMoveAbleRef.target = t), o.convertTransform("#" + n + " g");
                                  }, 1))
                                : setTimeout(() => {
                                      let e = "";
                                      i.find("span").each(function () {
                                          let t = jQuery(this).html();
                                          t = t.replace("&nbsp;", "").replace("&amp;", "");
                                          let p = pdappAPI.tool.getTransform(jQuery(this)),
                                              o = jQuery(this).css("transform-origin");
                                          e +=
                                              '<g style="transform:' +
                                              p +
                                              ";transform-origin:" +
                                              o +
                                              ';"><text ' +
                                              a +
                                              ">" +
                                              t +
                                              "</text></g>";
                                      }),
                                          r.html(e),
                                          "function" == typeof p && p(n),
                                          (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                          setTimeout(() => {
                                              (pdappAPI.tool.pdappMoveAbleRef.target = t),
                                                  o.convertTransform("#" + n + " g");
                                          }, 1);
                                  }, 50));
                }, 5);
            },
            convertTransform: function (e) {
                SVGElement.prototype.getTransformToElement =
                    SVGElement.prototype.getTransformToElement ||
                    function (e) {
                        return e.getScreenCTM().inverse().multiply(this.getScreenCTM());
                    };
                let t = "",
                    p = jQuery(e);
                if (0 == p.length) return t;
                for (let e = 0; e < p.length; e++) {
                    let t = a(p[e]);
                    "" != t && (jQuery(p[e]).attr("transform", t), jQuery(p[e]).removeAttr("style"));
                }
                function a(e) {
                    let p = e.getTransformToElement(e.parentNode),
                        [a, o, r, n, i, l] = [p.a, p.b, p.c, p.d, p.e, p.f];
                    return (t = [a, o, r, n, i, l].map((e) => +e.toFixed(4)).join(" ")), (t = "matrix(" + t + ")"), t;
                }
            },
        },
        updateValue: function (e, t) {
            let p = jQuery(e),
                a = { type: "text" };
            (a.text = p.attr("data-text")),
                (a.stroke = p.find("text").attr("stroke")),
                (a.strokeWidth = Math.round(10 * parseFloat(p.find("text").attr("stroke-width")))),
                (a.fontWeight = p.find("text").attr("font-weight")),
                (a.fontSize = p.find("text").attr("font-size")),
                (a.fontFamily = p.find("text").attr("font-family")),
                (a.fontStyle = p.find("text").attr("font-style")),
                (a.textDecoration = p.find("text").attr("text-decoration")),
                (a.textTransform = p.hasClass("pdapp-uppercase") ? "uppercase" : "none"),
                (a.textLock = p.hasClass("pdapp-lock")),
                (a.textFlip = !1),
                (a.dropdown = ""),
                (a.transparency = 100 * p.css("opacity")),
                (a.letterSpacing = 0),
                (a.settings = []);
            let o = p.attr("data-hide-options");
            void 0 !== o && (a.settings = o.split(",")),
                void 0 !== p.attr("data-spacing")
                    ? (a.letterSpacing = p.attr("data-spacing"))
                    : void 0 !== p.css("letter-spacing") &&
                      (a.letterSpacing = p.css("letter-spacing").replace("px", ""));
            let r = pdappAPI.tool.getTransform(p);
            if ("" != r) {
                let e = r.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                if (6 == e.length) {
                    let t = parseFloat(e[0]);
                    1 != t && (a.fontSize = Math.round(a.fontSize * t));
                }
            }
            if (
                ((a.color = pdappAPI.tool.rgbToHex(p.attr("fill"))),
                (a.colorType = "normal"),
                0 === a.color.indexOf("url("))
            ) {
                let e = a.color.replace("url(#", "").replace(")", "").split("-");
                (a.color = "#" + e[e.length - 1]), (a.colorType = e[0]);
            }
            p.hasClass("pdapp-arc") && (a.radius = p.attr("data-radius")),
                p.hasClass("pdapp-flip") && (a.textFlip = !0),
                "function" == typeof t && t(a);
        },
        updateText: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == p || 0 == p.length) return !1;
            let a = jQuery(p);
            if (
                (a.attr("data-text", e),
                a.hasClass("pdapp-flip") && (e = pdappAPI.text.flipText(e)),
                a.hasClass("pdapp-arc"))
            )
                this.arc.update(e, p, t, !0);
            else {
                let o = [],
                    r = a[0].getBoundingClientRect();
                if (0 != r.width) {
                    let e = pdappAPI.tool.getTransform(a);
                    "" != e && (o = e.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                }
                a.find("text").text(e),
                    setTimeout(() => {
                        if (6 == o.length) {
                            let e = a[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let t = ((e.width - r.width) / 2).toFixed(3);
                                (t = parseFloat(t)),
                                    (o[4] = parseFloat(o[4]) - t),
                                    a.attr("transform", "matrix(" + o.join(", ") + ")");
                            }
                        }
                        "function" == typeof t && t(),
                            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = p;
                            }, 1);
                    }, 1);
            }
        },
        formatText: function (e, t, p) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                o = jQuery(a),
                r = { key: "fontWeight", value: "400" };
            switch (e) {
                case "bold":
                    if (
                        ((r.key = "fontWeight"),
                        "700" == t.fontWeight ? (r.value = "400") : (r.value = "700"),
                        o.hasClass("pdapp-arc"))
                    ) {
                        let e = o.attr("id");
                        jQuery(".pdapp-viewport .pdapp-text-arc ." + e).css("font-weight", r.value),
                            this.arc.update(
                                o.attr("data-text"),
                                a,
                                function () {
                                    "function" == typeof p && p(r.key, r.value);
                                },
                                "",
                                !0
                            );
                    } else o.find("text").attr("font-weight", r.value), "function" == typeof p && p(r.key, r.value);
                    break;
                case "italic":
                    if (
                        ((r.key = "fontStyle"),
                        "italic" == t.fontStyle ? (r.value = "normal") : (r.value = "italic"),
                        o.hasClass("pdapp-arc"))
                    ) {
                        let e = o.attr("id");
                        jQuery(".pdapp-viewport .pdapp-text-arc ." + e).css("font-style", r.value),
                            this.arc.update(
                                o.attr("data-text"),
                                a,
                                function () {
                                    "function" == typeof p && p(r.key, r.value);
                                },
                                !0
                            );
                    } else {
                        let e = [],
                            t = o[0].getBoundingClientRect();
                        if (0 != t.width) {
                            let t = pdappAPI.tool.getTransform(o);
                            "" != t && (e = t.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                        }
                        o.find("text").attr("font-style", r.value),
                            setTimeout(() => {
                                if (6 == e.length) {
                                    let p = o[0].getBoundingClientRect();
                                    if (0 != p.width) {
                                        let a = ((p.width - t.width) / 2).toFixed(3);
                                        (a = parseFloat(a)),
                                            (e[4] = parseFloat(e[4]) - a),
                                            o.attr("transform", "matrix(" + e.join(", ") + ")");
                                    }
                                }
                                "function" == typeof p && p(r.key, r.value);
                            }, 10);
                    }
                    break;
                case "underline":
                    (r.key = "textDecoration"),
                        "underline" == t.textDecoration ? (r.value = "none") : (r.value = "underline"),
                        o.find("text").attr("text-decoration", r.value),
                        "function" == typeof p && p(r.key, r.value);
                    break;
                case "through":
                    (r.key = "textDecoration"),
                        "line-through" == t.textDecoration ? (r.value = "none") : (r.value = "line-through"),
                        o.find("text").attr("text-decoration", r.value),
                        "function" == typeof p && p(r.key, r.value);
                    break;
                case "uppercase":
                    if (
                        ((r.key = "textTransform"),
                        "uppercase" == t.textTransform ? (r.value = "none") : (r.value = "uppercase"),
                        o.hasClass("pdapp-arc"))
                    ) {
                        let e = o.attr("id");
                        jQuery(".pdapp-viewport .pdapp-text-arc ." + e).css("text-transform", r.value),
                            this.arc.update(
                                o.attr("data-text"),
                                a,
                                function () {
                                    "function" == typeof p && p(r.key, r.value);
                                },
                                !0
                            ),
                            "uppercase" == r.value ? o.addClass("pdapp-uppercase") : o.removeClass("pdapp-uppercase");
                    } else {
                        let e = [],
                            a = o[0].getBoundingClientRect();
                        if (0 != a.width) {
                            let t = pdappAPI.tool.getTransform(o);
                            "" != t && (e = t.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                        }
                        "uppercase" == r.value
                            ? (o.find("text").text(t.text.toUpperCase()), o.addClass("pdapp-uppercase"))
                            : (o.find("text").text(t.text), o.removeClass("pdapp-uppercase")),
                            setTimeout(() => {
                                if (6 == e.length) {
                                    let t = o[0].getBoundingClientRect();
                                    if (0 != t.width) {
                                        let p = ((t.width - a.width) / 2).toFixed(3);
                                        (p = parseFloat(p)),
                                            (e[4] = parseFloat(e[4]) - p),
                                            o.attr("transform", "matrix(" + e.join(", ") + ")");
                                    }
                                }
                                "function" == typeof p && p(r.key, r.value),
                                    (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                    setTimeout(() => {
                                        pdappAPI.tool.pdappMoveAbleRef.target = o;
                                    }, 1);
                            }, 10);
                    }
            }
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = a;
                }, 1);
        },
        delete: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(t),
                a = p.attr("id");
            (pdappAPI.tool.pdappMoveAbleRef.target = null), p.remove();
            let o = jQuery(".pdapp-viewport .pdapp-text-arc ." + a);
            o.length && o.remove(), "function" == typeof e && e(a);
        },
        lock: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                e ? ((e = !1), a.removeClass("pdapp-lock")) : ((e = !0), a.addClass("pdapp-lock")),
                "function" == typeof t && t(e),
                pdappAPI.layer.select(p);
        },
        flipText: function (e) {
            let t = e.split("");
            return (t = t.reverse()), t.join("");
        },
        flip: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p),
                o = a.attr("data-text");
            e
                ? ((e = !1), a.removeClass("pdapp-flip"))
                : ((e = !0), a.addClass("pdapp-flip"), (o = pdappAPI.text.flipText(o))),
                a.hasClass("pdapp-arc")
                    ? this.arc.update(
                          o,
                          p,
                          function () {
                              "function" == typeof t && t(e);
                          },
                          !0
                      )
                    : (a.find("text").text(o), "function" == typeof t && t(e)),
                pdappAPI.layer.select(p);
        },
        copy: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let o = "pdapp-target-" + pdappAPI.tool.uID(),
                r = a.clone(),
                n = jQuery(".pdapp-viewport"),
                i = a.attr("id");
            if (
                (jQuery(r).attr("id", o),
                n.find("svg.pdapp-selecto-area").append(r),
                pdappAPI.layer.afterAdded(o),
                a.hasClass("pdapp-arc"))
            ) {
                let e = jQuery(".pdapp-viewport .pdapp-text-arc ." + i)[0].outerHTML;
                jQuery(".pdapp-viewport .pdapp-text-arc").append(e.replace(i, o));
            }
            setTimeout(() => {
                let p = jQuery("#" + o);
                pdappAPI.layer.select(p),
                    "function" == typeof t && t(p),
                    jQuery(".pdapp-btn-copy").append('<i class="text-success">' + e.copied + "</i>"),
                    setTimeout(() => {
                        jQuery(".pdapp-btn-copy .text-success").remove();
                    }, 5e3);
            }, 1);
        },
        updateTextStyle: function (e, t, p) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                o = jQuery(a);
            if (null == a || 0 == a.length) return !1;
            switch (e) {
                case "color":
                    let e = { color: t, type: "" },
                        r = o.attr("data-gradient");
                    if (void 0 !== r && "" != r) {
                        let a = r.split("-");
                        this.gradient(a[0], t), (e.type = a[0]), "function" == typeof p && p(e);
                    } else
                        o.attr("fill", t),
                            void 0 !== o.find("text").attr("stroke-width") &&
                                0 == o.find("text").attr("stroke-width") &&
                                o.find("text").attr("stroke", t),
                            "function" == typeof p && p(e);
                    break;
                case "radius":
                    o.attr("id");
                    let n = o.attr("data-text");
                    o.attr("data-radius", t),
                        this.arc.update(n, a, function () {
                            "function" == typeof p && p(t);
                        });
                    break;
                case "letterSpacing":
                    if (((t = parseInt(t)), o.hasClass("pdapp-arc"))) {
                        let e = o.attr("id"),
                            r = o.attr("data-text");
                        jQuery(".pdapp-viewport .pdapp-text-arc ." + e).css("letter-spacing", t),
                            jQuery("#" + e).attr("data-spacing", t),
                            this.arc.update(
                                r,
                                a,
                                function () {
                                    "function" == typeof p && p(t);
                                },
                                !0
                            );
                    } else
                        o.attr("letter-spacing", t + "px"),
                            "function" == typeof p && p(t),
                            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = a;
                            }, 1);
                    break;
                case "outline":
                    o.find("text").attr("stroke", t.stroke),
                        o.find("text").attr("stroke-width", t.strokeWidth / 10),
                        "function" == typeof p && p(t);
                    break;
                case "transparency":
                    o.attr("opacity", t / 100), "function" == typeof p && p(t);
            }
        },
        alignText: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == t || 0 == t.length) return !1;
            let p = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool[e](p),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = t;
                }, 1);
        },
        moveText: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == t || 0 == t.length) return !1;
            let p = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool.move[e](p),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = t;
                }, 1);
        },
        gradient: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == p || 0 == p.length) return !1;
            t = pdappAPI.tool.rgbToHex(t);
            let a = jQuery(p),
                o = jQuery(".pdapp-viewport svg.pdapp-selecto-area"),
                r = o.find(".pdapp-defs");
            if (0 == r.length) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "defs");
                e.setAttributeNS(null, "class", "pdapp-defs"), o.prepend(e);
            }
            let n = "linearGradient";
            "radial" == e && (n = "radialGradient");
            let i = e + "-gradient-" + t.replace("#", ""),
                l = i,
                d = pdappAPI.tool.hexToRgb(t),
                s = document.createElementNS("http://www.w3.org/2000/svg", "stop");
            s.setAttributeNS(null, "offset", "0%"),
                s.setAttributeNS(null, "stop-color", d),
                s.setAttributeNS(null, "stop-opacity", 1);
            let u = document.createElementNS("http://www.w3.org/2000/svg", "stop");
            u.setAttributeNS(null, "offset", "100%"),
                u.setAttributeNS(null, "stop-color", d.replace(")", ", 0)")),
                u.setAttributeNS(null, "stop-opacity", 1);
            let c = document.createElementNS("http://www.w3.org/2000/svg", n);
            c.setAttributeNS(null, "id", i),
                "hor" == e && c.setAttributeNS(null, "gradientTransform", "rotate(90)"),
                c.appendChild(s),
                c.appendChild(u),
                setTimeout(() => {
                    (o = jQuery(".pdapp-viewport svg.pdapp-selecto-area")),
                        (r = o.find(".pdapp-defs")),
                        0 == r.find("#" + i).length && "normal" != e && r.append(c),
                        setTimeout(() => {
                            "normal" == e
                                ? ((l = a.attr("data-gradient")), a.attr("data-gradient", ""), a.attr("fill", t))
                                : ((l = a.attr("data-gradient")),
                                  a.attr("data-gradient", i),
                                  a.attr("fill", "url(#" + i + ")")),
                                "" != l &&
                                    0 ==
                                        jQuery(".pdapp-viewport svg.pdapp-selecto-area").find(
                                            '[data-gradient="' + l + '"]'
                                        ).length &&
                                    r.find("#" + l).remove();
                        }, 1);
                }, 1);
        },
        setSize: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == p || 0 == p.length) return !1;
            let a = jQuery(p),
                o = [],
                r = a[0].getBoundingClientRect(),
                n = pdappAPI.tool.getTransform(a);
            if (
                "" != n &&
                ((o = n.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",")), 6 == o.length)
            ) {
                if (1 != parseFloat(o[0])) {
                    let e = 1 / parseFloat(o[0]);
                    (o[0] = 1), (o[3] = parseFloat(o[3]) * e), a.attr("transform", "matrix(" + o.join(", ") + ")");
                }
            }
            if (((pdappAPI.tool.pdappMoveAbleRef.target = null), a.hasClass("pdapp-arc"))) {
                let o = a.attr("id"),
                    r = a.attr("data-text");
                jQuery(".pdapp-viewport .pdapp-text-arc ." + o).css("font-size", e),
                    this.arc.update(r, p, t, !0),
                    setTimeout(() => {
                        jQuery("#" + o)
                            .find("text")
                            .attr("font-size", e),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = p;
                            }, 1);
                    }, 15);
            } else
                a.find("text").attr("font-size", e),
                    setTimeout(() => {
                        if (6 == o.length) {
                            let e = a[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let t = ((e.width - r.width) / 2).toFixed(3),
                                    p = ((e.height - r.height) / 2).toFixed(3);
                                (t = parseFloat(t)),
                                    (p = parseFloat(p)),
                                    (o[4] = parseFloat(o[4]) - t),
                                    (o[5] = parseFloat(o[5]) - p),
                                    a.attr("transform", "matrix(" + o.join(", ") + ")");
                            }
                        }
                        "function" == typeof t && t(),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = p;
                            }, 1);
                    }, 10);
        },
        changeFont: function (e, t, p, a) {
            let o = [],
                r = a[0].getBoundingClientRect();
            if (0 != r.width) {
                let e = pdappAPI.tool.getTransform(a);
                "" != e && (o = e.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
            }
            a.find("text").attr("font-family", e);
            let n = a.attr("id");
            jQuery(".pdapp-text-arc ." + n).css("font-family", e),
                setTimeout(() => {
                    if (a.hasClass("pdapp-arc")) {
                        let e = a.attr("data-text");
                        this.arc.update(e, a[0], p, !0);
                    } else {
                        if (((pdappAPI.tool.pdappMoveAbleRef.target = null), 6 == o.length)) {
                            let e = a[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let t = ((e.width - r.width) / 2).toFixed(3);
                                (t = parseFloat(t)),
                                    (o[4] = parseFloat(o[4]) - t),
                                    a.attr("transform", "matrix(" + o.join(", ") + ")");
                            }
                        }
                        setTimeout(() => {
                            (pdappAPI.tool.pdappMoveAbleRef.target = a[0]), "function" == typeof p && p();
                        }, 1);
                    }
                }, t);
        },
    },
    artwork: {
        readImage: function (e, t) {
            if (void 0 === e.artFile) return "function" == typeof t && t(e), !1;
            let p = document.createElement("canvas"),
                a = p.getContext("2d"),
                o = document.createElement("img");
            (o.crossOrigin = "anonymous"),
                (o.onload = function () {
                    let r = new ColorThief().getPalette(o, 8, 50);
                    null == r && (r = [[255, 255, 255]]);
                    let n = [];
                    for (let e = 0; e < r.length; e++) {
                        let t = pdappAPI.tool.rgbToHex("rgb(" + r[e].join(", ") + ")");
                        !1 === n.includes(t) && n.push(t);
                    }
                    let i = n.join(","),
                        l = { width: o.width, height: o.height };
                    (p.width = l.width),
                        (p.height = l.height),
                        a.drawImage(o, 0, 0, l.width, l.height),
                        (l.base64 = e.artFile),
                        p.toBlob(function (e) {
                            (l.blob = URL.createObjectURL(e)), (l.color = i), "function" == typeof t && t(l);
                        }, "image/png"),
                        o.remove(),
                        p.remove();
                }),
                (o.src = e.artFile);
        },
        createImage: function (e, t) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "image"),
                a = {};
            (a.width = e.width),
                (a.height = e.height),
                (a.x = 0),
                (a.y = 0),
                (a.class = "pdapp-img"),
                (p = pdappAPI.tool.generalAttr(a, p));
            let o = void 0 !== e.blob ? e.blob : e.base64;
            p.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", o), "function" == typeof t && t(p);
        },
        createSvg: function (e) {
            let t = new DOMParser().parseFromString(e.artFile, "image/svg+xml");
            return (
                jQuery(t.documentElement).removeClass("pdapp-selecto-area"),
                jQuery(t.documentElement)
                    .find(".pdapp-target")
                    .each(function () {
                        jQuery(this).removeClass("pdapp-target"),
                            jQuery(this).removeClass("pdapp-svg"),
                            jQuery(this).removeClass("pdapp-group"),
                            jQuery(this).removeClass("pdapp-svg-text"),
                            jQuery(this).removeClass("pdapp-svg-artwork"),
                            jQuery(this).removeClass("pdapp-svg-photo"),
                            jQuery(this).removeClass("pdapp-photo"),
                            jQuery(this).removeClass("pdapp-svg-qrcode"),
                            jQuery(this).removeClass("pdapp-svg-barcode");
                    }),
                t.documentElement
            );
        },
        createG: function (e, t) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                a = {};
            return (
                (a.id = e),
                (a.class = t),
                (a.style = "transform: translate(0, 0) rotate(0deg)"),
                pdappAPI.tool.generalAttr(a, p)
            );
        },
        create: function (e, t, p, a) {
            (pdappAPI.tool.pdappMoveAbleRef.target = null), void 0 === a && (a = "pdapp-target-" + pdappAPI.tool.uID());
            let o = this;
            if ("svg" == t) {
                let t = o.createSvg(e),
                    r = pdappAPI.photo.createG(a, "pdapp-target pdapp-svg pdapp-svg-artwork");
                r.appendChild(t);
                let n =
                    '<svg x="0" y="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                    r.outerHTML +
                    "</svg>";
                getSVGColors(n, { flat: !0 }).then((e) => {
                    let t = e.join(",");
                    r.setAttribute("data-color", t),
                        jQuery(".pdapp-viewport svg.pdapp-selecto-area").append(r),
                        pdappAPI.layer.afterAdded(a),
                        setTimeout(() => {
                            let e = jQuery("#" + a);
                            pdappAPI.layer.select(e),
                                "function" == typeof p && p(e),
                                pdappAPI.tool.standardArtworkToAi(e);
                        }, 1);
                });
            } else
                o.readImage(e, function (e) {
                    o.createImage(e, function (t) {
                        let o = pdappAPI.photo.createG(a, "pdapp-target pdapp-photo pdapp-svg-artwork");
                        o.appendChild(t), o.setAttribute("data-color", e.color);
                        let r = document.createElementNS("http://www.w3.org/2000/svg", "g");
                        r.setAttribute("class", "pdapp-g-photo"),
                            r.appendChild(o),
                            jQuery(".pdapp-viewport svg.pdapp-selecto-area").append(r),
                            pdappAPI.layer.afterAdded(a),
                            setTimeout(() => {
                                let t = jQuery("#" + a);
                                pdappAPI.layer.select(t), "function" == typeof p && p(t, e);
                            }, 1);
                    });
                });
        },
        copy: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let o = "pdapp-target-" + pdappAPI.tool.uID(),
                r = a.clone(),
                n = jQuery(".pdapp-viewport"),
                i = a.attr("id");
            jQuery(r).attr("id", o);
            let l = jQuery(r).find("#" + i + "-shape");
            0 != l.length && (l.attr("id", o + "-shape"), jQuery(r).attr("clip-path", "url(#" + o + "-shape)"));
            let d = jQuery(r).find("#" + i + "-filter");
            if ((0 != d.length && d.attr("id", o + "-filter"), a.hasClass("pdapp-photo"))) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "g");
                0 != d.length && (e.style.filter = "url(#" + o + "-filter)"),
                    e.append(r[0]),
                    n.find("svg.pdapp-selecto-area").append(e);
            } else n.find("svg.pdapp-selecto-area").append(r);
            pdappAPI.layer.afterAdded(o),
                setTimeout(() => {
                    let p = jQuery("#" + o);
                    pdappAPI.layer.select(p),
                        "function" == typeof t && t(p),
                        jQuery(".pdapp-btn-copy").append('<i class="text-success">' + e.copied + "</i>"),
                        setTimeout(() => {
                            jQuery(".pdapp-btn-copy .text-success").remove();
                        }, 5e3);
                }, 1);
        },
        updateValue: function (e, t) {
            let p = jQuery(e),
                a = { type: "artwork" };
            (a.photoLock = p.hasClass("pdapp-lock")),
                (a.editColor = p.hasClass("pdapp-svg")),
                (a.colors = []),
                (a.photoFlip = !1),
                (a.transparency = 100 * p.css("opacity")),
                (a.dropdown = ""),
                (a.photo = a.editColor ? "" : p.find("image").attr("xlink:href")),
                (a.settings = []);
            let o = p.attr("data-hide-options");
            void 0 !== o && (a.settings = o.split(",")),
                p.hasClass("pdapp-flip") && (a.photoFlip = !0),
                "function" == typeof t && t(a);
        },
    },
    photo: {
        readPhoto: function (e, t) {
            let p = document.createElement("img");
            (p.crossOrigin = "anonymous"),
                (p.onload = function () {
                    let a = new ColorThief().getPalette(p, 8, 50);
                    null == a && (a = [[255, 255, 255]]);
                    let o = [];
                    for (let e = 0; e < a.length; e++) {
                        let t = pdappAPI.tool.rgbToHex("rgb(" + a[e].join(", ") + ")");
                        !1 === o.includes(t) && o.push(t);
                    }
                    (e.color = o.join(",")),
                        (e.width = Math.round(p.width)),
                        (e.height = Math.round(p.height)),
                        "function" == typeof t && t(e);
                }),
                (p.src = e.blob);
        },
        readMediumImage: function (e, t, p) {
            let a = {},
                o = document.createElement("canvas"),
                r = o.getContext("2d"),
                n = document.createElement("img");
            function i() {
                if (a.width > 1920) {
                    let e = 1920;
                    a.width > 3840 && (e = a.width / 2), (a.height = e * (n.height / n.width)), (a.width = e);
                }
                (o.width = a.width),
                    (o.height = a.height),
                    r.drawImage(n, 0, 0, n.width, n.height, 0, 0, a.width, a.height),
                    a.width > 1920
                        ? ((n = o),
                          (o = document.createElement("canvas")),
                          (r = o.getContext("2d")),
                          requestAnimationFrame(i))
                        : ((a.base64 = o.toDataURL("image/png", p)),
                          o.toBlob(
                              function (e) {
                                  (a.blob = URL.createObjectURL(e)), "function" == typeof t && t(a);
                              },
                              "image/png",
                              p
                          ),
                          cancelAnimationFrame(i),
                          n.remove(),
                          o.remove());
            }
            (n.crossOrigin = "anonymous"),
                (n.onload = function () {
                    let e = new ColorThief().getPalette(n, 8, 50);
                    null == e && (e = [[255, 255, 255]]);
                    let t = [];
                    for (let p = 0; p < e.length; p++) {
                        let a = pdappAPI.tool.rgbToHex("rgb(" + e[p].join(", ") + ")");
                        !1 === t.includes(a) && t.push(a);
                    }
                    (a.color = t.join(",")), (a.width = Math.round(n.width)), (a.height = Math.round(n.height)), i();
                }),
                (n.src = URL.createObjectURL(e));
        },
        cropImage: function (e, t, p) {
            let a = document.createElement("canvas"),
                o = a.getContext("2d"),
                r = document.createElement("img");
            (r.crossOrigin = "anonymous"),
                (r.onload = function () {
                    (a.width = t.width),
                        (a.height = t.height),
                        o.drawImage(r, t.left, t.top, t.width, t.height, 0, 0, t.width, t.height),
                        (t.base64 = a.toDataURL("image/png")),
                        a.toBlob(function (e) {
                            (t.blob = URL.createObjectURL(e)), "function" == typeof p && p(t);
                        }),
                        r.remove(),
                        a.remove();
                }),
                (r.src = e);
        },
        cropOriginImage: function (e, t, p, a, o) {
            let r = parseFloat(
                    jQuery("#" + p)
                        .find("image")
                        .attr("data-width")
                ),
                n = {},
                i = document.createElement("canvas"),
                l = i.getContext("2d"),
                d = document.createElement("img");
            (d.crossOrigin = "anonymous"),
                (d.onload = function () {
                    let s = d.width / r;
                    if (
                        ((n = {
                            top: (t.top * s).toFixed(3),
                            left: (t.left * s).toFixed(3),
                            width: (t.width * s).toFixed(3),
                            height: (t.height * s).toFixed(3),
                        }),
                        "function" == typeof OffscreenCanvas && pdappWorker)
                    ) {
                        let t = { width: d.width, height: d.height };
                        pdappWorker.postMessage({
                            url: e,
                            crop: n,
                            imgSize: t,
                            targetID: p,
                            hisID: a,
                            action: "cropOrigImg",
                        });
                    } else {
                        (i.width = n.width),
                            (i.height = n.height),
                            l.drawImage(d, n.left, n.top, d.width, d.height, 0, 0, d.width, d.height);
                        let e = i.toDataURL("image/png");
                        "function" == typeof o && o(e, p, a);
                    }
                    d.remove(), i.remove();
                }),
                (d.src = e);
        },
        getPhotos: function (e, t, p) {
            void 0 !== this[e.library] && this[e.library](e, t, p);
        },
        unsplash: function (e, t, p) {
            "function" == typeof p && p([]);
        },
        pexels: function (e, t, p) {
            "function" == typeof p && p([]);
        },
        createImage: function (e) {
            let t = document.createElementNS("http://www.w3.org/2000/svg", "image"),
                p = {};
            return (
                (p.width = e.width),
                (p.height = e.height),
                (p.x = 0),
                (p.y = 0),
                (p["data-width"] = e.width),
                (p["data-height"] = e.height),
                (p.class = "pdapp-img"),
                (t = pdappAPI.tool.generalAttr(p, t)),
                t.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", e.blob),
                t
            );
        },
        createG: function (e, t) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                a = {};
            return (
                (a.id = e),
                (a.class = t),
                (a.style = "transform: translate(0, 0) rotate(0deg)"),
                pdappAPI.tool.generalAttr(a, p)
            );
        },
        createSvg: function (e) {
            let t = new DOMParser().parseFromString(e, "image/svg+xml");
            return (
                jQuery(t.documentElement).removeClass("pdapp-selecto-area"),
                jQuery(t.documentElement)
                    .find(".pdapp-target")
                    .each(function () {
                        jQuery(this).removeClass("pdapp-target"),
                            jQuery(this).removeClass("pdapp-svg"),
                            jQuery(this).removeClass("pdapp-group"),
                            jQuery(this).removeClass("pdapp-svg-text"),
                            jQuery(this).removeClass("pdapp-svg-artwork"),
                            jQuery(this).removeClass("pdapp-svg-photo"),
                            jQuery(this).removeClass("pdapp-photo"),
                            jQuery(this).removeClass("pdapp-svg-qrcode"),
                            jQuery(this).removeClass("pdapp-svg-barcode");
                    }),
                t.documentElement
            );
        },
        create: function (e, t, p, a) {
            (pdappAPI.tool.pdappMoveAbleRef.target = null), void 0 === p && (p = "pdapp-target-" + pdappAPI.tool.uID());
            let o = {};
            o = "svg" == a ? pdappAPI.photo.createSvg(e) : pdappAPI.photo.createImage(e);
            let r = "svg" == a ? "pdapp-target pdapp-svg pdapp-svg-photo" : "pdapp-target pdapp-svg-photo",
                n = pdappAPI.photo.createG(p, r);
            n.appendChild(o);
            let i = document.createElementNS("http://www.w3.org/2000/svg", "g");
            if ((i.setAttribute("class", "pdapp-g-photo"), i.appendChild(n), "svg" == a)) {
                let e =
                    '<svg x="0" y="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                    i.outerHTML +
                    "</svg>";
                getSVGColors(e, { flat: !0 }).then((e) => {
                    let a = e.join(",");
                    i.setAttribute("data-color", a),
                        jQuery(".pdapp-viewport svg.pdapp-selecto-area").append(i),
                        pdappAPI.layer.afterAdded(p),
                        setTimeout(() => {
                            let e = jQuery("#" + p);
                            pdappAPI.layer.select(e), "function" == typeof t && t(e);
                        }, 1);
                });
            } else
                i.setAttribute("data-color", a),
                    jQuery(".pdapp-viewport svg.pdapp-selecto-area").append(i),
                    pdappAPI.layer.afterAdded(p),
                    setTimeout(() => {
                        let e = jQuery("#" + p);
                        pdappAPI.layer.select(e), "function" == typeof t && t(e);
                    }, 1);
        },
        replace: function (e, t, p) {
            let a = t.find("image");
            a.attr("data-width", e.width),
                a.attr("data-height", e.height),
                a.attr("xlink:href", e.blob),
                t.attr("data-color", e.color),
                "function" == typeof p && p();
        },
        pdappMoveAbleRef: null,
        getCrop: function (e) {
            let t = jQuery(pdappAPI.tool.pdappMoveAbleRef.target),
                p = t.find("image"),
                a = {};
            return (
                (a.id = t.attr("id")),
                (a.blob = p.attr("xlink:href")),
                (a.width = p.attr("data-width")),
                (a.height = p.attr("data-height")),
                (a.ratio = "area_ratio"),
                setTimeout(() => {
                    pdappAPI.photo.setCrop(t, e);
                }, 10),
                a
            );
        },
        setCrop: function (e, t) {
            let p = jQuery(".pdapp-croparea .pdapp-cropimage").width(),
                a = jQuery(".pdapp-croparea .pdapp-cropimage").height(),
                o = jQuery(".pdapp-viewport").width(),
                r = jQuery(".pdapp-viewport").height(),
                n = e.find("image");
            if ((t && ((o = n.width()), (r = n.height())), p / a > o / r)) {
                let e = a,
                    t = parseFloat(((a * o) / r).toFixed(3));
                jQuery(".pdapp-croparea .pdapp-cropmask").width(t), jQuery(".pdapp-croparea .pdapp-cropmask").height(e);
            } else {
                let e = parseFloat(((p * r) / o).toFixed(3)),
                    t = p;
                jQuery(".pdapp-croparea .pdapp-cropmask").width(t), jQuery(".pdapp-croparea .pdapp-cropmask").height(e);
            }
            jQuery(".pdapp-croparea .pdapp-cropmask").css("transform", "translate(0px, 0px)"),
                jQuery(".pdapp-croparea .pdapp-cropimage").width(p),
                jQuery(".pdapp-croparea .pdapp-cropimage").height(a),
                jQuery(".pdapp-croparea .pdapp-cropimage").css("max-width", "100%"),
                jQuery(".pdapp-croparea .pdapp-cropimage").css("max-height", "100%");
            let i = pdappAPI.tool.getGuideLine(".pdapp-croparea .pdapp-cropmask"),
                l = {
                    target: ".pdapp-croparea .pdapp-cropmask",
                    draggable: !0,
                    edgeDraggable: !1,
                    scalable: !0,
                    keepRatio: !0,
                    renderDirections: ["nw", "n", "ne", "w", "e", "sw", "s", "se"],
                    rotatable: !1,
                    rotationPosition: "top",
                    snappable: !0,
                    pinchable: !0,
                    pinchOutside: !0,
                    verticalGuidelines: i.ver,
                    horizontalGuidelines: i.hor,
                    snapDirections: { top: !0, left: !0, bottom: !0, right: !0, center: !0, middle: !0 },
                    elementSnapDirections: { top: !0, left: !0, bottom: !0, right: !0, center: !0, middle: !0 },
                    bounds: { left: 0, top: 0, right: 0, bottom: 0, position: "css" },
                },
                d = document.querySelector(".pdapp-cropbox .pdapp-croparea");
            (pdappAPI.photo.pdappMoveAbleRef = new Moveable(d, l)),
                pdappAPI.photo.pdappMoveAbleRef.on("render", (e) => {
                    e.target.style.transform = e.transform;
                    let t = pdappAPI.tool
                        .getTransform(jQuery(e.target))
                        .replace("matrix(", "")
                        .replace(")", "")
                        .replaceAll(" ", "")
                        .split(",");
                    if (void 0 !== t.length && 6 == t.length) {
                        let e = jQuery(".pdapp-croparea .pdapp-cropmask").position(),
                            o = 0 - e.top / parseFloat(t[3]),
                            r = 0 - e.left / parseFloat(t[0]);
                        jQuery(".pdapp-croparea .pdapp-cropmask").css(
                            "background-size",
                            (p / parseFloat(t[0])).toFixed(3) + "px " + (a / parseFloat(t[3])).toFixed(3) + "px"
                        ),
                            jQuery(".pdapp-croparea .pdapp-cropmask").css(
                                "background-position",
                                r.toFixed(3) + "px " + o.toFixed(3) + "px"
                            );
                    }
                });
        },
        changeCropRatio: function (e) {
            let t = jQuery(".pdapp-croparea .pdapp-cropimage").width(),
                p = jQuery(".pdapp-croparea .pdapp-cropimage").height(),
                a = jQuery(".pdapp-viewport").width(),
                o = jQuery(".pdapp-viewport").height(),
                r = t,
                n = p;
            pdappAPI.photo.pdappMoveAbleRef.keepRatio = "free_ratio" != e;
            let i = !1;
            if ("1:1" == e) (i = !0), r < n ? (n = r) : (r = n);
            else if ("1:2" == e) (i = !0), r > n / 2 ? (r = n / 2) : (n = 2 * r);
            else if ("2:1" == e) (i = !0), n > r / 2 ? (n = r / 2) : (r = 2 * n);
            else if ("area_ratio" == e) {
                i = !0;
                let e = n,
                    t = r;
                r / n > a / o
                    ? ((e = n), (t = parseFloat(((n * a) / o).toFixed(3))))
                    : ((e = parseFloat(((r * o) / a).toFixed(3))), (t = r)),
                    (r = t),
                    (n = e);
            }
            let l = jQuery(".pdapp-croparea .pdapp-cropmask");
            i &&
                (l.width(r),
                l.height(n),
                l.css("transform", "translate(0px, 0px)"),
                l.css("background-size", t + "px " + p + "px"),
                l.css("background-position", "0px 0px")),
                (pdappAPI.photo.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.photo.pdappMoveAbleRef.target = l;
                }, 1);
        },
        crop: function (e, t, p) {
            let a = jQuery(".pdapp-croparea .pdapp-cropimage"),
                o = a[0].naturalWidth / a.width(),
                r = jQuery(".pdapp-croparea .pdapp-cropmask"),
                n = r.position(),
                i = pdappAPI.tool
                    .getTransform(r)
                    .replace("matrix(", "")
                    .replace(")", "")
                    .replaceAll(" ", "")
                    .split(","),
                l = { width: r.width(), height: r.height() };
            void 0 !== i.length &&
                6 == i.length &&
                ((l.width = l.width * parseFloat(i[0])), (l.height = l.height * parseFloat(i[3])));
            let d = {
                    top: (n.top * o).toFixed(3),
                    left: (n.left * o).toFixed(3),
                    width: (l.width * o).toFixed(3),
                    height: (l.height * o).toFixed(3),
                },
                s = pdappAPI.tool.pdappMoveAbleRef.target,
                u = jQuery(s).find("image");
            pdappAPI.photo.cropImage(a.attr("src"), d, function (a) {
                (a.blob = a.blob),
                    (a.base64 = a.base64),
                    u.attr("xlink:href", a.blob),
                    t || (u.attr("width", a.width), u.attr("height", a.height)),
                    u.attr("data-crop", a.top + "," + a.left + "," + a.width + "," + a.height);
                let o = jQuery(s);
                if (o.hasClass("pdapp-shape"))
                    for (let t = 0; t < e.length; t++)
                        e[t].slug == o.attr("data-shape") && pdappAPI.photo.addShape(e[t]);
                setTimeout(() => {
                    t || pdappAPI.photo.fitPhotoInside(),
                        (a.ratio = "area_ratio"),
                        "function" == typeof p && p(a, o.attr("id"));
                }, 10);
            });
        },
        originPhoto: function (e, t, p) {
            let a = e.find("image");
            a.attr("xlink:href", t.blob),
                a.attr("width", a.attr("data-width")),
                a.attr("height", a.attr("data-height")),
                "function" == typeof p && p(t.blob),
                setTimeout(() => {
                    pdappAPI.photo.fitPhotoInside();
                }, 1);
        },
        fitPhotoInside: function () {
            let e = pdappAPI.tool.pdappMoveAbleRef.target,
                t = jQuery(".pdapp-viewport").find("svg.pdapp-selecto-area").width(),
                p = jQuery(".pdapp-viewport").find("svg.pdapp-selecto-area").height();
            (t = parseFloat(t.toFixed(3))), (p = parseFloat(p.toFixed(3)));
            let a = jQuery(e),
                o = a[0].getBoundingClientRect();
            if (0 == o.width) return !1;
            let r = 1,
                n = pdappAPI.tool
                    .getTransform(a)
                    .replace("matrix(", "")
                    .replace(")", "")
                    .replaceAll(" ", "")
                    .split(",");
            void 0 !== n.length &&
                6 == n.length &&
                1 != n[0] &&
                ((o.width = o.width / parseFloat(n[0])), (o.height = o.height / parseFloat(n[0]))),
                (r =
                    o.width / o.height < t / p
                        ? parseFloat((p / o.height).toFixed(3))
                        : parseFloat((t / o.width).toFixed(3))),
                void 0 !== n.length &&
                    6 == n.length &&
                    ((n[0] = r),
                    (n[3] = parseFloat(n[0])),
                    a.attr("transform", "matrix(" + n.join(", ") + ")"),
                    pdappAPI.photo.alignPhoto("centerAll"));
        },
        fitPhotoOutside: function () {
            let e = pdappAPI.tool.pdappMoveAbleRef.target,
                t = jQuery(".pdapp-viewport").find("svg.pdapp-selecto-area").width(),
                p = jQuery(".pdapp-viewport").find("svg.pdapp-selecto-area").height();
            (t = parseFloat(t.toFixed(3))), (p = parseFloat(p.toFixed(3)));
            let a = jQuery(e),
                o = a[0].getBoundingClientRect();
            if (0 == o.width) return !1;
            let r = 1,
                n = pdappAPI.tool
                    .getTransform(a)
                    .replace("matrix(", "")
                    .replace(")", "")
                    .replaceAll(" ", "")
                    .split(",");
            void 0 !== n.length &&
                6 == n.length &&
                1 != n[0] &&
                ((o.width = o.width / parseFloat(n[0])), (o.height = o.height / parseFloat(n[0]))),
                (r =
                    o.width / o.height > t / p
                        ? parseFloat((p / o.height).toFixed(3))
                        : parseFloat((t / o.width).toFixed(3))),
                void 0 !== n.length &&
                    6 == n.length &&
                    ((n[0] = r),
                    (n[3] = parseFloat(n[0])),
                    a.attr("transform", "matrix(" + n.join(", ") + ")"),
                    pdappAPI.photo.alignPhoto("centerAll"));
        },
        addShape: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p),
                o = a.attr("id") + "-shape";
            if (
                (a.find("defs").find("clipPath").remove(),
                a.removeClass("pdapp-shape"),
                a.removeAttr("clip-path"),
                "" != e && void 0 !== e.type)
            ) {
                let t = pdappAPI.tool.renderShape(a, e, o);
                if ("" != t) {
                    if (0 != a.find("defs").length) a.find("defs").prepend(t);
                    else {
                        let e = document.createElementNS("http://www.w3.org/2000/svg", "defs");
                        e.appendChild(t), a.prepend(e);
                    }
                    a.addClass("pdapp-shape"), a.attr("data-shape", e.slug), a.attr("clip-path", "url(#" + o + ")");
                }
            }
            "function" == typeof t && t();
        },
        addFilter: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p),
                o = a.attr("id") + "-filter",
                r = a.parent("g.pdapp-g-photo");
            if (0 == r.length) return !1;
            if (
                (a.find("defs").find("filter").remove(),
                a.removeClass("pdapp-filter"),
                a.removeAttr("data-filter"),
                r.removeAttr("css"),
                "" != e)
            ) {
                a.addClass("pdapp-filter"), a.attr("data-filter", e.slug);
                let t = document.createElementNS("http://www.w3.org/2000/svg", "feColorMatrix");
                t.setAttributeNS(null, "type", "matrix"), t.setAttributeNS(null, "values", e.value);
                let p = document.createElementNS("http://www.w3.org/2000/svg", "filter");
                if ((p.setAttributeNS(null, "id", o), p.appendChild(t), 0 != a.find("defs").length))
                    a.find("defs").prepend(p);
                else {
                    let e = document.createElementNS("http://www.w3.org/2000/svg", "defs");
                    e.appendChild(p), a.prepend(e);
                }
                a.addClass("pdapp-filter"), a.attr("data-filter", e.slug), r.css("filter", "url(#" + o + ")");
            }
            "function" == typeof t && t();
        },
        updateValue: function (e, t) {
            let p = jQuery(e),
                a = { type: "photo" };
            (a.editColor = p.hasClass("pdapp-svg")),
                (a.colors = []),
                (a.photoLock = p.hasClass("pdapp-lock")),
                (a.photoFlip = !1),
                (a.transparency = 100 * p.css("opacity")),
                (a.dropdown = ""),
                (a.photo = a.editColor ? "" : p.find("image").attr("xlink:href")),
                (a.photoShape = p.hasClass("pdapp-shape") ? p.attr("data-shape") : ""),
                (a.photoFilter = p.hasClass("pdapp-filter") ? p.attr("data-filter") : ""),
                (a.clickUpload = p.hasClass("pdapp-upload")),
                (a.clickPhoto = p.hasClass("pdapp-photo")),
                (a.settings = []);
            let o = p.attr("data-hide-options");
            void 0 !== o && (a.settings = o.split(",")),
                p.hasClass("pdapp-flip") && (a.photoFlip = !0),
                "function" == typeof t && t(a);
        },
        updatePhotoStyle: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            if (null == p || 0 == p.length) return !1;
            "transparency" == e && a.attr("opacity", t / 100);
        },
        alignPhoto: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == t || 0 == t.length) return !1;
            let p = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool[e](p),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = t;
                }, 1);
        },
        movePhoto: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == t || 0 == t.length) return !1;
            let p = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool.move[e](p),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = t;
                }, 1);
        },
        delete: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(t),
                a = p.attr("id");
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let o = p.parent("g.pdapp-g-photo");
            0 != o.length ? o.remove() : p.remove(), "function" == typeof e && e(a);
        },
        lock: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                e ? ((e = !1), a.removeClass("pdapp-lock")) : ((e = !0), a.addClass("pdapp-lock")),
                "function" == typeof t && t(e),
                pdappAPI.layer.select(p);
        },
        flip: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p),
                o = a[0].getBoundingClientRect();
            if (0 == o.width) return !1;
            e ? ((e = !1), a.removeClass("pdapp-flip")) : ((e = !0), a.addClass("pdapp-flip"));
            let r = pdappAPI.tool
                .getTransform(a)
                .replace("matrix(", "")
                .replace(")", "")
                .replaceAll(" ", "")
                .split(",");
            if (6 == r.length) {
                let n = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                    i = jQuery(".pdapp-viewport svg.pdapp-selecto-area").attr("viewBox");
                if (void 0 !== i) {
                    let e = parseFloat(i.split(" ")[2]),
                        t = parseFloat(i.split(" ")[3]),
                        p = jQuery(".pdapp-viewport svg.pdapp-selecto-area").width(),
                        a = jQuery(".pdapp-viewport svg.pdapp-selecto-area").height();
                    (parseInt(p / n) == parseInt(e) && parseInt(a / n) == parseInt(t)) ||
                        (n = e / t > p / a ? p / e : a / t);
                }
                if (
                    (e
                        ? (a.find("image").attr("transform", "scale(-1, 1)"),
                          (r[4] = (parseFloat(r[4]) + o.width / n).toFixed(3)))
                        : (a.find("image").attr("transform", "scale(1, 1)"),
                          (r[4] = (parseFloat(r[4]) - o.width / n).toFixed(3))),
                    a.hasClass("pdapp-shape"))
                ) {
                    let t = e ? -1 : 1,
                        p = a.find("clipPath"),
                        o = p.find("circle");
                    0 != o.length && o.attr("transform", "scale(" + t + ", 1)");
                    let r = p.find("rect");
                    0 != r.length && r.attr("transform", "scale(" + t + ", 1)");
                    let n = p.find("path");
                    0 != n.length &&
                        n.each(function () {
                            let e = pdappAPI.tool
                                .getTransform(jQuery(this))
                                .replace("matrix(", "")
                                .replace(")", "")
                                .replaceAll(" ", "")
                                .split(",");
                            6 == e.length &&
                                ((e[0] = -1 * e[0]),
                                (e[4] = -1 * e[4]),
                                jQuery(this).attr("transform", "matrix(" + e.join(", ") + ")"));
                        });
                }
                a.attr("transform", "matrix(" + r.join(", ") + ")"),
                    "function" == typeof t && t(e),
                    pdappAPI.layer.select(p);
            }
        },
        copy: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let o = "pdapp-target-" + pdappAPI.tool.uID(),
                r = a.clone(),
                n = jQuery(".pdapp-viewport"),
                i = a.attr("id");
            jQuery(r).attr("id", o);
            let l = jQuery(r).find("#" + i + "-shape");
            0 != l.length && (l.attr("id", o + "-shape"), jQuery(r).attr("clip-path", "url(#" + o + "-shape)"));
            let d = jQuery(r).find("#" + i + "-filter");
            if ((0 != d.length && d.attr("id", o + "-filter"), a.hasClass("pdapp-svg-photo"))) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "g");
                0 != d.length && (e.style.filter = "url(#" + o + "-filter)"),
                    e.append(r[0]),
                    n.find("svg.pdapp-selecto-area").append(e);
            } else n.find("svg.pdapp-selecto-area").append(r);
            pdappAPI.layer.afterAdded(o),
                setTimeout(() => {
                    let p = jQuery("#" + o);
                    pdappAPI.layer.select(p),
                        "function" == typeof t && t(p, i),
                        jQuery(".pdapp-btn-copy").append('<i class="text-success">' + e.copied + "</i>"),
                        setTimeout(() => {
                            jQuery(".pdapp-btn-copy .text-success").remove();
                        }, 5e3);
                }, 1);
        },
        replaceColor: function (e, t, p) {
            let a = null,
                o = null,
                r = document.createElement("canvas"),
                n = r.getContext("2d"),
                i = document.createElement("img");
            (i.crossOrigin = "anonymous"),
                (i.onload = function () {
                    if (
                        ((r.width = i.width),
                        (r.height = i.height),
                        n.drawImage(i, 0, 0),
                        (a = n.getImageData(0, 0, i.width, i.height)),
                        (o = a),
                        void 0 !== o.data && o.data.length)
                    ) {
                        let e = pdappAPI.tool.hexToRgb(t, !0);
                        for (let t = 0, p = a.data.length; t < p; t += 4)
                            o.data[t + 3] > 0 && ((o.data[t] = e.r), (o.data[t + 1] = e.g), (o.data[t + 2] = e.b));
                        n.putImageData(o, 0, 0);
                    }
                    let e = r.toDataURL("image/png");
                    "function" == typeof p && p(e), i.remove(), r.remove();
                }),
                (i.src = e);
        },
        setColor: function (e) {
            let t = e.find(".pdapp-product-img"),
                p = t.attr("data-color");
            if (void 0 === p || "" == p) return !1;
            let a = t.attr("src");
            this.replaceColor(a, p, function (e) {
                t.attr("src", e);
            });
        },
        changePhotoOption: function (e, t) {
            if (null == pdappAPI.tool.pdappMoveAbleRef.target) return !1;
            let p = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
            e ? p.addClass("pdapp-upload") : p.removeClass("pdapp-upload"),
                t ? p.addClass("pdapp-photo") : p.removeClass("pdapp-photo"),
                e || t ? p.addClass("pdapp-showupload") : p.removeClass("pdapp-showupload");
        },
    },
    upload: {
        verify: function (e, t, p) {
            let a = e.name.substr(e.name.lastIndexOf(".") + 1);
            a = a.toLowerCase();
            let o = "";
            return (
                void 0 !== t.general &&
                    void 0 !== t.general.upload &&
                    (0 == t.general.upload.type.includes(a)
                        ? (o = p.msg.upload_type_error + " " + t.general.upload.type.join(", "))
                        : e.size > 1048576 * t.general.upload.max
                          ? (o = p.msg.upload_maxsize_error + " " + t.general.upload.max + "MB")
                          : e.size < 1048576 * t.general.upload.min &&
                            (o = p.msg.upload_minsize_error + " " + t.general.upload.min + "MB")),
                o
            );
        },
        uploadFile: function (e, t, p) {
            return new Promise(function (a, o) {
                let r = {
                    url: e,
                    type: "POST",
                    processData: !1,
                    contentType: !1,
                    dataType: "json",
                    data: t,
                    xhr: function () {
                        let e = new window.XMLHttpRequest();
                        return (
                            e.upload.addEventListener(
                                "progress",
                                function (e) {
                                    if (e.lengthComputable) {
                                        let t = (e.loaded / e.total) * 100;
                                        "function" == typeof p && p(t);
                                    }
                                },
                                !1
                            ),
                            e
                        );
                    },
                    success: function (e) {
                        0 == e
                            ? o({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? a({ msg: e.msg, data: e.data }) : o({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, p) {
                        "" == p && (p = "Request failed"), o({ msg: p, error: 1 });
                    },
                };
                jQuery.ajax(r);
            });
        },
        readFile: function (e, t) {
            let p = new FileReader();
            p.readAsDataURL(e),
                (p.onloadend = function () {
                    let e = p.result;
                    "function" == typeof t && t(e);
                });
        },
        importTemplate: function (e, t) {
            let p = e.name.split(".");
            return (
                "pda" == p[p.length - 1] &&
                (this.readFile(e, function (e) {
                    let p = e.split("base64,"),
                        a = atob(p[1]);
                    "function" == typeof t && t(a);
                }),
                !0)
            );
        },
    },
    qrcode: {
        createSvg: function (e) {
            return new DOMParser().parseFromString(e, "image/svg+xml").documentElement;
        },
        createG: function (e, t, p) {
            let a = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                o = {};
            return (
                (o.id = e),
                (o.class = p),
                (o.style = "transform: translate(0, 0) rotate(0deg)"),
                (o["data-text"] = t.text),
                (o["data-color"] = t.color),
                (o["data-background"] = t.background),
                (o["data-padding"] = t.padding),
                (o["data-width"] = t.width),
                (o["data-ecl"] = t.ecl),
                (o["data-subject"] = t.subject),
                (o["data-message"] = t.message),
                (o["data-qrtype"] = t.qrtype),
                pdappAPI.tool.generalAttr(o, a)
            );
        },
        create: function (e, t) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let p = jQuery(".pdapp-viewport"),
                a = p.width(),
                o = p.height();
            a > o && (a = o), a > 200 && (a = 200);
            let r = {
                text: "Add your text content...",
                color: "#000000",
                background: "transparent",
                padding: 1,
                ecl: "H",
                width: a,
                qrtype: "text",
                subject: "",
                message: "",
            };
            if (void 0 !== e.text) for (let t in r) void 0 !== e[t] && "" != e[t] && (r[t] = e[t]);
            let n = "pdapp-target-" + pdappAPI.tool.uID(),
                i = r.text;
            "phone" == r.qrtype ? (i = "tel:" + i) : "sms" == r.qrtype && (i = "smsto:" + i + ":" + r.message),
                "mail" == r.qrtype && (i = "mailto:" + i + "?subject=" + r.subject + "&body=" + r.message);
            let l = new QRCode({
                content: i,
                padding: parseInt(r.padding),
                width: parseInt(r.width),
                height: parseInt(r.width),
                color: r.color,
                background: r.background,
                ecl: r.ecl,
                join: !0,
            }).svg();
            setTimeout(() => {
                let e = pdappAPI.qrcode.createSvg(l),
                    a = pdappAPI.qrcode.createG(n, r, "pdapp-target pdapp-svg pdapp-svg-qrcode");
                a.append(e),
                    jQuery(".pdapp-viewport svg.pdapp-selecto-area").append(a),
                    p.find("svg.pdapp-selecto-area").append(a),
                    pdappAPI.layer.afterAdded(n),
                    setTimeout(() => {
                        let e = jQuery("#" + n);
                        pdappAPI.layer.select(e),
                            "function" == typeof t && t(e),
                            e.find("svg").attr("viewBox", "0 0 " + parseInt(r.width) + " " + parseInt(r.width)),
                            e.find("rect").attr("fill", pdappAPI.tool.rgbToHex(e.find("rect").css("fill"))),
                            e.find("rect").attr("shape-rendering", e.find("rect").css("shape-rendering")),
                            e.find("rect").removeAttr("style"),
                            e.find("path").attr("fill", pdappAPI.tool.rgbToHex(e.find("path").css("fill"))),
                            e.find("path").attr("shape-rendering", e.find("path").css("shape-rendering")),
                            e.find("path").removeAttr("style");
                    }, 1);
            }, 1);
        },
        updateValue: function (e, t) {
            let p = jQuery(e),
                a = { type: "qrcode" };
            (a.text = p.attr("data-text")),
                (a.subject = p.attr("data-subject")),
                (a.message = p.attr("data-message")),
                (a.qrtype = p.attr("data-qrtype")),
                (a.color = p.attr("data-color")),
                (a.background = p.attr("data-background")),
                (a.padding = p.attr("data-padding")),
                (a.width = p.attr("data-width")),
                (a.ecl = p.attr("data-ecl")),
                (a.transparency = 100 * p.css("opacity")),
                (a.dropdown = ""),
                (a.photoLock = p.hasClass("pdapp-lock")),
                (a.settings = []);
            let o = p.attr("data-hide-options");
            void 0 !== o && (a.settings = o.split(",")), "function" == typeof t && t(a);
        },
        update: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            a.attr("data-text", e.text),
                a.attr("data-subject", e.subject),
                a.attr("data-message", e.message),
                a.attr("data-color", e.color),
                a.attr("data-qrtype", e.qrtype),
                a.attr("data-background", e.background),
                a.attr("data-padding", e.padding),
                a.attr("data-ecl", e.ecl);
            let o = e.text;
            "phone" == e.qrtype ? (o = "tel:" + o) : "sms" == e.qrtype && (o = "smsto:" + o + ":" + e.message),
                "mail" == e.qrtype && (o = "mailto:" + o + "?subject=" + e.subject + "&body=" + e.message);
            let r = new QRCode({
                content: o,
                padding: parseInt(e.padding),
                width: parseInt(e.width),
                height: parseInt(e.width),
                color: e.color,
                background: e.background,
                ecl: e.ecl,
                join: !0,
            }).svg();
            setTimeout(() => {
                let a = pdappAPI.qrcode.createSvg(r);
                (p = jQuery(pdappAPI.tool.pdappMoveAbleRef.target)),
                    p.html(a),
                    "function" == typeof t && t(p),
                    p.find("svg").attr("viewBox", "0 0 " + parseInt(e.width) + " " + parseInt(e.width)),
                    p.find("rect").attr("fill", pdappAPI.tool.rgbToHex(p.find("rect").css("fill"))),
                    p.find("rect").attr("shape-rendering", p.find("rect").css("shape-rendering")),
                    p.find("rect").removeAttr("style"),
                    p.find("path").attr("fill", pdappAPI.tool.rgbToHex(p.find("path").css("fill"))),
                    p.find("path").attr("shape-rendering", p.find("path").css("shape-rendering")),
                    p.find("path").removeAttr("style");
            }, 1);
        },
        copy: function (e, t) {
            let p = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let a = "pdapp-target-" + pdappAPI.tool.uID(),
                o = p.clone(),
                r = jQuery(".pdapp-viewport");
            jQuery(o).attr("id", a),
                r.find("svg.pdapp-selecto-area").append(o),
                pdappAPI.layer.afterAdded(a),
                setTimeout(() => {
                    let p = jQuery("#" + a);
                    pdappAPI.layer.select(p),
                        "function" == typeof t && t(p),
                        jQuery(".pdapp-btn-copy").append('<i class="text-success">' + e.copied + "</i>"),
                        setTimeout(() => {
                            jQuery(".pdapp-btn-copy .text-success").remove();
                        }, 5e3);
                }, 1);
        },
    },
    barcode: {
        getBarcodeDefault: function (e, t) {
            return (
                void 0 === t && (t = "5901234123457"),
                (-1 == e.indexOf("CODE128") && -1 == e.indexOf("CODE39")) ||
                    (-1 != e.indexOf("CODE128C") && (t = "12345678")),
                -1 != e.indexOf("UPC") && (t = "123456789999"),
                -1 != e.indexOf("EAN8") && (t = "96385074"),
                -1 != e.indexOf("EAN5") && (t = "54495"),
                -1 != e.indexOf("EAN2") && (t = "53"),
                -1 != e.indexOf("ITF14") && (t = "12345678901231"),
                -1 != e.indexOf("pharmacode") && (t = "1234"),
                -1 != e.indexOf("codabar") && (t = "1234567890"),
                t
            );
        },
        checkBarcode: function (e, t, p) {
            let a = "",
                o = { min: 1, max: 9999 };
            return (
                (-1 == t.indexOf("CODE128") && -1 == t.indexOf("CODE39")) ||
                    (-1 != t.indexOf("CODE128A") && e.toUpperCase() != e && (a = p.error_barcode_128a),
                    -1 != t.indexOf("CODE128C") &&
                        ((o.min = 2),
                        isNaN(e) && (a = p.error_barcode_number),
                        e.length % 2 != 0 && (a = p.error_barcode_128c))),
                (-1 == t.indexOf("EAN13") && -1 == t.indexOf("UPC")) || ((o.max = 13), (o.min = 13)),
                -1 != t.indexOf("EAN8") && ((o.max = 8), (o.min = 8)),
                -1 != t.indexOf("EAN5") && ((o.max = 5), (o.min = 5)),
                -1 != t.indexOf("EAN2") && ((o.max = 2), (o.min = 2)),
                -1 != t.indexOf("ITF14") && ((o.max = 14), (o.min = 14)),
                -1 != t.indexOf("pharmacode") &&
                    ((o.max = 5),
                    isNaN(e) && (a = p.error_barcode_number),
                    e < 3 && (a = p.error_barcode_minimum_numb)),
                -1 != t.indexOf("codabar") &&
                    isNaN(
                        e
                            .replaceAll("$", "")
                            .replaceAll("-", "")
                            .replaceAll(":", "")
                            .replaceAll("/", "")
                            .replaceAll("+", "")
                            .replaceAll(".", "")
                    ) &&
                    (a = p.error_barcode_allow_number),
                e.length < o.min && (a = p.error_barcode_minimum + " " + o.min),
                e.length > o.max && (a = p.error_barcode_maximum + " " + o.max),
                a
            );
        },
        createSvg: function (e) {
            let t = new DOMParser().parseFromString(e, "image/svg+xml");
            return jQuery(t.documentElement).removeAttr("id"), t.documentElement;
        },
        createG: function (e, t, p) {
            let a = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                o = {};
            return (
                (o.id = e),
                (o.class = p),
                (o.style = "transform: translate(0, 0) rotate(0deg)"),
                (o["data-text"] = t.text),
                (o["data-color"] = t.lineColor),
                (o["data-background"] = t.background),
                (o["data-format"] = t.format),
                (o["data-width"] = t.width),
                (o["data-height"] = t.height),
                (o["data-fontWeight"] = t.fontWeight),
                (o["data-fontFamily"] = t.font),
                (o["data-textAlign"] = t.textAlign),
                (o["data-textPosition"] = t.textPosition),
                (o["data-textMargin"] = t.textMargin),
                (o["data-margin"] = t.margin),
                (o["data-fontSize"] = t.fontSize),
                (o["data-margin"] = t.margin),
                (o["data-lastChar"] = t.lastChar),
                (o["data-displayValue"] = t.displayValue),
                pdappAPI.tool.generalAttr(o, a)
            );
        },
        create: function (e, t, p) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let a = {
                text: "",
                displayValue: !0,
                lineColor: "#000000",
                background: "transparent",
                format: "CODE128",
                width: 2,
                height: 100,
                fontOptions: "",
                font: "Space Mono",
                fontWeight: "normal",
                lastChar: "",
                textAlign: "center",
                textPosition: "bottom",
                textMargin: 2,
                fontSize: 20,
                margin: 10,
            };
            if (
                ((a.text = pdappAPI.barcode.getBarcodeDefault(a.format, "Add your text content...")), void 0 !== e.text)
            )
                for (let t in a)
                    (void 0 !== e[t] && "" === e[t]) ||
                        (void 0 !== e[t] &&
                            (("width" != t && "height" != t && "textMargin" != t && "fontSize" != t && "margin" != t) ||
                                (e[t] = parseInt(e[t])),
                            (a[t] = e[t])));
            let o = "pdapp-target-" + pdappAPI.tool.uID();
            jQuery("#pdapp-barcode-box").html("");
            let r = a.format;
            if (-1 != r.indexOf("-")) {
                let t = r.split("-");
                if (((a.format = t[0]), "lastchar" == t[1]))
                    a.lastChar = void 0 !== e.lastChar && "" != e.lastChar ? e.lastChar : ">";
                else {
                    a[t[1]] = !0;
                }
                JsBarcode("#pdapp-barcode-box", a.text, a), (a.format = r);
            } else JsBarcode("#pdapp-barcode-box", a.text, a);
            pdappAPI.barcode.insert(o, t, a, p);
        },
        insert: function (e, t, p, a) {
            let o = jQuery("#pdapp-barcode-box").html();
            if (void 0 === o)
                return (
                    setTimeout(() => {
                        pdappAPI.barcode.insert(e, t, p, a);
                    }, 10),
                    !1
                );
            let r = jQuery("#pdapp-barcode-box"),
                n = p.font.replaceAll(" ", "+");
            if (void 0 !== t[n]) {
                let e = '<style xmlns="http://www.w3.org/1999/xhtml">' + t[n] + "</style>";
                r.prepend(e);
            }
            o = new XMLSerializer().serializeToString(r[0]);
            let i = pdappAPI.barcode.createSvg(o),
                l = pdappAPI.barcode.createG(e, p, "pdapp-target pdapp-svg pdapp-svg-barcode");
            l.append(i),
                jQuery(".pdapp-viewport svg.pdapp-selecto-area").append(l),
                pdappAPI.layer.afterAdded(e),
                setTimeout(() => {
                    let t = jQuery("#" + e);
                    pdappAPI.layer.select(t),
                        "function" == typeof a && a(t),
                        t.find("svg").attr("transform", pdappAPI.tool.getTransform(t.find("svg"))),
                        t.find("svg").removeAttr("style"),
                        void 0 !== jQuery(t.find("rect")[0]).css("fill") &&
                            (jQuery(t.find("rect")[0]).attr(
                                "fill",
                                pdappAPI.tool.rgbToHex(jQuery(t.find("rect")[0]).css("fill"))
                            ),
                            jQuery(t.find("rect")[0]).removeAttr("style")),
                        void 0 !== t.find("g").css("fill") &&
                            (t.find("g").attr("fill", pdappAPI.tool.rgbToHex(t.find("g").css("fill"))),
                            t.find("g").removeAttr("style"));
                    let p = t.find("text").css("font").split("px ");
                    2 == p.length &&
                        (t.find("text").attr("font-size", p[0] + "px"),
                        t.find("text").attr("font-family", p[1].replaceAll('"', "")),
                        t.find("text").removeAttr("style"));
                    let o = jQuery(".pdapp-viewport")[0].getBoundingClientRect(),
                        r = t[0].getBoundingClientRect();
                    (r.width > o.width || r.height > o.height) &&
                        setTimeout(() => {
                            pdappAPI.photo.fitPhotoInside();
                        }, 1);
                }, 1);
        },
        updateValue: function (e, t) {
            let p = jQuery(e),
                a = { type: "barcode" };
            (a.text = p.attr("data-text")),
                (a.lineColor = p.attr("data-color")),
                (a.background = p.attr("data-background")),
                (a.format = p.attr("data-format")),
                (a.width = parseInt(p.attr("data-width"))),
                (a.height = parseInt(p.attr("data-height"))),
                (a.fontOptions = p.attr("data-fontWeight")),
                (a.font = p.attr("data-fontFamily")),
                (a.textAlign = p.attr("data-textAlign")),
                (a.textPosition = p.attr("data-textPosition")),
                (a.textMargin = parseInt(p.attr("data-textMargin"))),
                (a.margin = parseInt(p.attr("data-margin"))),
                (a.fontSize = parseInt(p.attr("data-fontSize"))),
                (a.transparency = 100 * p.css("opacity")),
                (a.dropdown = ""),
                (a.lastChar = p.attr("data-lastChar")),
                (a.displayValue = "true" === p.attr("data-displayValue") || !0 === p.attr("data-displayValue")),
                (a.photoLock = p.hasClass("pdapp-lock")),
                (a.settings = []);
            let o = p.attr("data-hide-options");
            void 0 !== o && (a.settings = o.split(",")),
                void 0 === a.lastChar && (a.lastChar = ">"),
                "function" == typeof t && t(a);
        },
        update: function (e, t, p) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target;
            null == a && (a = "#" + jQuery(".pdapp-viewport g.active").attr("id"));
            let o = jQuery(a);
            jQuery("#pdapp-barcode-box").html("");
            let r = {
                text: "1234",
                displayValue: !0,
                lineColor: "#000000",
                background: "transparent",
                format: "CODE128",
                width: 2,
                height: 100,
                fontOptions: "",
                font: "Space Mono",
                textAlign: "center",
                textPosition: "bottom",
                textMargin: 2,
                fontSize: 20,
                margin: 10,
            };
            if (((r.text = pdappAPI.barcode.getBarcodeDefault(r.format)), void 0 !== e))
                for (let t in r)
                    (void 0 !== e[t] && "" === e[t]) ||
                        (void 0 !== e[t] &&
                            (("width" != t && "height" != t && "textMargin" != t && "fontSize" != t && "margin" != t) ||
                                (e[t] = parseInt(e[t])),
                            (r[t] = e[t])));
            let n = r.format;
            if (
                (o.attr("data-format", r.format),
                o.attr("data-text", r.text),
                o.attr("data-color", r.lineColor),
                o.attr("data-background", r.background),
                o.attr("data-width", r.width),
                o.attr("data-height", r.height),
                o.attr("data-margin", r.margin),
                o.attr("data-lastChar", r.lastchar),
                o.attr("data-displayValue", r.displayValue),
                -1 != n.indexOf("-"))
            ) {
                let t = n.split("-");
                if (((r.format = t[0]), "lastchar" == t[1]))
                    (r.lastChar = void 0 !== e.lastChar && "" != e.lastChar ? e.lastChar : ">"),
                        o.attr("data-lastChar", r.lastChar);
                else {
                    r[t[1]] = !0;
                }
                JsBarcode("#pdapp-barcode-box", r.text, r);
            } else JsBarcode("#pdapp-barcode-box", r.text, r);
            pdappAPI.barcode.addUpdate(t, r.font, a, p);
        },
        addUpdate: function (e, t, p, a) {
            let o = jQuery("#pdapp-barcode-box").html();
            if (void 0 === o)
                return (
                    setTimeout(() => {
                        pdappAPI.barcode.addUpdate(e, t, p);
                    }, 50),
                    !1
                );
            setTimeout(() => {
                let r = jQuery("#pdapp-barcode-box"),
                    n = t.replaceAll(" ", "+");
                if (void 0 !== e[n]) {
                    let t = '<style xmlns="http://www.w3.org/1999/xhtml">' + e[n] + "</style>";
                    r.prepend(t);
                }
                o = new XMLSerializer().serializeToString(r[0]);
                let i = pdappAPI.barcode.createSvg(o),
                    l = jQuery(p);
                l.html(i),
                    "function" == typeof a && a(l),
                    (pdappAPI.tool.pdappMoveAbleRef.target = null),
                    setTimeout(() => {
                        (pdappAPI.tool.pdappMoveAbleRef.target = p),
                            l.find("svg").attr("transform", pdappAPI.tool.getTransform(l.find("svg"))),
                            l.find("svg").removeAttr("style"),
                            void 0 !== jQuery(l.find("rect")[0]).css("fill") &&
                                (jQuery(l.find("rect")[0]).attr(
                                    "fill",
                                    pdappAPI.tool.rgbToHex(jQuery(l.find("rect")[0]).css("fill"))
                                ),
                                jQuery(l.find("rect")[0]).removeAttr("style")),
                            void 0 !== l.find("g").css("fill") &&
                                (l.find("g").attr("fill", pdappAPI.tool.rgbToHex(l.find("g").css("fill"))),
                                l.find("g").removeAttr("style"));
                        let e = l.find("text").css("font").split("px ");
                        2 == e.length &&
                            (l.find("text").attr("font-size", e[0] + "px"),
                            l.find("text").attr("font-family", e[1].replaceAll('"', "")),
                            l.find("text").removeAttr("style"));
                    }, 1);
            }, 1);
        },
        copy: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(p);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let o = "pdapp-target-" + pdappAPI.tool.uID(),
                r = a.clone(),
                n = jQuery(".pdapp-viewport");
            jQuery(r).attr("id", o),
                n.find("svg.pdapp-selecto-area").append(r),
                pdappAPI.layer.afterAdded(o),
                setTimeout(() => {
                    let p = jQuery("#" + o);
                    pdappAPI.layer.select(p),
                        "function" == typeof t && t(p),
                        jQuery(".pdapp-btn-copy").append('<i class="text-success">' + e.copied + "</i>"),
                        setTimeout(() => {
                            jQuery(".pdapp-btn-copy .text-success").remove();
                        }, 5e3);
                }, 1);
        },
    },
    layer: {
        loadLayers: function () {
            let e = [];
            return (
                jQuery(".pdapp-viewport svg.pdapp-selecto-area")
                    .find("g.pdapp-target")
                    .each(function () {
                        let t = { id: "", type: "text", value: "" },
                            p = jQuery(this);
                        (t.id = p.attr("id")),
                            p.hasClass("pdapp-svg-photo")
                                ? (t.type = "photo")
                                : p.hasClass("pdapp-svg-artwork")
                                  ? (t.type = "artwork")
                                  : p.hasClass("pdapp-svg-qrcode")
                                    ? (t.type = "qrcode")
                                    : p.hasClass("pdapp-svg-barcode") && (t.type = "barcode"),
                            "text" == t.type
                                ? (t.value = p.attr("data-text"))
                                : "qrcode" == t.type || "barcode" == t.type
                                  ? (t.value =
                                        "data:image/svg+xml;base64," +
                                        pdappAPI.tool.encodeBase64(p.find("svg")[0].outerHTML))
                                  : p.find("image").length
                                    ? (t.value = p.find("image").attr("xlink:href"))
                                    : (t.value =
                                          "data:image/svg+xml;base64," +
                                          pdappAPI.tool.encodeBase64(p.find("svg")[0].outerHTML)),
                            void 0 !== t.id && "" != t.id && e.push(t);
                    }),
                e
            );
        },
        moveLayer: function (e, t) {
            let p = null,
                a = jQuery(".pdapp-viewport svg.pdapp-selecto-area");
            a.find("g.pdapp-target").each(function (o) {
                if (jQuery(this).attr("id") == e) {
                    p =
                        0 == jQuery(this).parent("g.pdapp-g-photo").length
                            ? jQuery(this)
                            : jQuery(this).parent("g.pdapp-g-photo");
                    let e = p.clone();
                    if ("up" == t)
                        if (0 == o) a.append(e);
                        else {
                            let t =
                                0 == jQuery(a.find("g.pdapp-target")[o - 1]).parent("g.pdapp-g-photo").length
                                    ? a.find("g.pdapp-target")[o - 1]
                                    : jQuery(a.find("g.pdapp-target")[o - 1]).parent("g.pdapp-g-photo");
                            jQuery(e).insertBefore(t);
                        }
                    else if (o == a.find("g.pdapp-target").length - 1) {
                        let t =
                            0 == jQuery(a.find("g.pdapp-target")[0]).parent("g.pdapp-g-photo").length
                                ? a.find("g.pdapp-target")[0]
                                : jQuery(a.find("g.pdapp-target")[0]).parent("g.pdapp-g-photo");
                        jQuery(e).insertBefore(t);
                    } else {
                        let t =
                            0 == jQuery(a.find("g.pdapp-target")[o + 1]).parent("g.pdapp-g-photo").length
                                ? a.find("g.pdapp-target")[o + 1]
                                : jQuery(a.find("g.pdapp-target")[o + 1]).parent("g.pdapp-g-photo");
                        jQuery(e).insertAfter(t);
                    }
                }
            }),
                null != p && p.remove();
        },
        select: function (e) {
            (pdappAPI.tool.pdappMoveAbleRef.target = e),
                jQuery(e).hasClass("pdapp-lock")
                    ? ((pdappAPI.tool.pdappMoveAbleRef.draggable = !1),
                      (pdappAPI.tool.pdappMoveAbleRef.scalable = !1),
                      (pdappAPI.tool.pdappMoveAbleRef.rotatable = !1),
                      (pdappAPI.tool.pdappMoveAbleRef.renderDirections = []))
                    : ((pdappAPI.tool.pdappMoveAbleRef.draggable = !0),
                      (pdappAPI.tool.pdappMoveAbleRef.scalable = !0),
                      (pdappAPI.tool.pdappMoveAbleRef.rotatable = !0),
                      (pdappAPI.tool.pdappMoveAbleRef.renderDirections = ["nw", "n", "ne", "w", "e", "sw", "s", "se"]));
        },
        unselect: function () {
            null != pdappAPI.tool.pdappMoveAbleRef && (pdappAPI.tool.pdappMoveAbleRef.target = null);
        },
        afterAdded: function (e) {
            let t = 0,
                p = [];
            jQuery(".pdapp-viewport .pdapp-target").each(function () {
                let e = jQuery(this).attr("id");
                t > 7 && (t = 0);
                let a = { element: "#" + e, className: "pdapp-line-" + t };
                p.push(a), t++;
            }),
                (pdappAPI.tool.pdappMoveAbleRef.elementGuidelines = p);
            let a = jQuery("#" + e);
            pdappAPI.tool.centerAll(a);
        },
        active: function (e, t, p) {
            let a = [];
            1 == e.length
                ? (pdappAPI.layer.select(e),
                  jQuery(e).hasClass("pdapp-svg-text")
                      ? pdappAPI.text.updateValue(e, function (e) {
                            (e.title = t.edit_text), a.push(e), "function" == typeof p && p(0, "text", a);
                        })
                      : jQuery(e).hasClass("pdapp-svg-artwork")
                        ? pdappAPI.artwork.updateValue(e, function (e) {
                              (e.title = t.edit_artwork), a.push(e), "function" == typeof p && p(0, "artwork", a);
                          })
                        : jQuery(e).hasClass("pdapp-svg-photo")
                          ? pdappAPI.photo.updateValue(e, function (e) {
                                (e.title = t.edit_photo), a.push(e), "function" == typeof p && p(0, "photo", a);
                            })
                          : jQuery(e).hasClass("pdapp-svg-qrcode")
                            ? pdappAPI.qrcode.updateValue(e, function (e) {
                                  (e.title = t.edit_qrcode), a.push(e), "function" == typeof p && p(0, "qrcode", a);
                              })
                            : jQuery(e).hasClass("pdapp-svg-barcode") &&
                              pdappAPI.barcode.updateValue(e, function (e) {
                                  (e.title = t.edit_barcode), a.push(e), "function" == typeof p && p(0, "barcode", a);
                              }))
                : e.length > 1
                  ? ("function" == typeof p && p(null, "group", a),
                    (pdappAPI.tool.pdappMoveAbleRef.draggable = !0),
                    (pdappAPI.tool.pdappMoveAbleRef.scalable = !0),
                    (pdappAPI.tool.pdappMoveAbleRef.rotatable = !0),
                    (pdappAPI.tool.pdappMoveAbleRef.renderDirections = ["nw", "n", "ne", "w", "e", "sw", "s", "se"]))
                  : "function" == typeof p && p(null, "unselect", a);
        },
    },
    group: {
        getGroup: function (e, t) {
            let p = { show: !0, active: "", isGroup: jQuery(e[0]).hasClass("pdapp-group"), colors: [] };
            "function" == typeof t && t(p);
        },
        getColors: function (e, t) {
            if (0 == e.length) return !1;
            for (let p = 0; p < e.length; p++) {
                let a =
                    '<svg x="0" y="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                    e[p].outerHTML +
                    "</svg>";
                getSVGColors(a, { flat: !0 }).then((e) => {
                    "function" == typeof t && t(e);
                });
            }
        },
        selectAll(e) {
            let t = [];
            return (
                jQuery(".pdapp-viewport g.pdapp-target").each(function () {
                    if (!jQuery(this).hasClass("pdapp-lock")) {
                        let e = jQuery(this).attr("data-hide-options");
                        (void 0 === e ||
                            "" == e ||
                            (-1 === e.indexOf("move") && -1 === e.indexOf("size") && -1 === e.indexOf("rotate"))) &&
                            t.push(this);
                    }
                }),
                0 != t.length &&
                    (1 == t.length
                        ? (pdappAPI.layer.select(t[0]), !1)
                        : ((pdappAPI.tool.pdappMoveAbleRef.scalable = !0),
                          (pdappAPI.tool.pdappMoveAbleRef.renderDirections = [
                              "nw",
                              "n",
                              "ne",
                              "w",
                              "e",
                              "sw",
                              "s",
                              "se",
                          ]),
                          (pdappAPI.tool.pdappMoveAbleRef.draggable = !0),
                          (pdappAPI.tool.pdappMoveAbleRef.rotatable = !0),
                          void pdappAPI.group.getGroup(t, function (p) {
                              "function" == typeof e && e(t, p);
                          })))
            );
        },
        setGroup: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (0 == p.length) return !1;
            let a = pdappAPI.tool.uID();
            for (let o = 0; o < p.length; o++) {
                let r = jQuery(p[o]),
                    n = r.attr("id");
                e
                    ? (r.removeClass("pdapp-group"), r.attr("data-group", ""))
                    : (r.addClass("pdapp-group"), r.attr("data-group", a));
                let i = p.length - 1 == o;
                "function" == typeof t && t(n, i);
            }
        },
        copyGroup: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (0 == p.length || "function" != typeof t) return !1;
            let a = pdappAPI.tool.uID();
            for (let o = 0; o < p.length; o++) {
                let r = jQuery(p[o]),
                    n = r.attr("id"),
                    i = "pdapp-target-" + pdappAPI.tool.uID(),
                    l = p.length - 1 == o,
                    d = r.clone();
                if (r.hasClass("pdapp-svg-text")) {
                    let e = jQuery(".pdapp-viewport");
                    if (
                        (jQuery(d).attr("id", i),
                        jQuery(d).hasClass("pdapp-group") && jQuery(d).attr("data-group", a),
                        e.find("svg.pdapp-selecto-area").append(d),
                        r.hasClass("pdapp-arc"))
                    ) {
                        let e = jQuery(".pdapp-viewport .pdapp-text-arc ." + n)[0].outerHTML;
                        jQuery(".pdapp-viewport .pdapp-text-arc").append(e.replace(n, i));
                    }
                    t(i, pdappAPI.history.getIndex(jQuery(i)), d, "", l);
                } else
                    r.hasClass("pdapp-svg-artwork")
                        ? t(i, pdappAPI.history.getIndex(jQuery(i)), d, "", l)
                        : r.hasClass("pdapp-svg-photo")
                          ? t(i, pdappAPI.history.getIndex(jQuery(i)), d, n, l)
                          : (r.hasClass("pdapp-svg-qrcode") || r.hasClass("pdapp-svg-barcode")) &&
                            t(i, pdappAPI.history.getIndex(jQuery(i)), d, "", l);
                l &&
                    setTimeout(() => {
                        jQuery(".pdapp-btn-copy").append('<i class="text-success">' + e.copied + "</i>"),
                            setTimeout(() => {
                                jQuery(".pdapp-btn-copy .text-success").remove();
                            }, 5e3);
                    }, 1);
            }
        },
        alignGroup: function (e, t, p) {
            let a = this;
            if (0 == t.length || "function" != typeof p) return !1;
            let o = { top: "", left: "" },
                r = { top: "", left: "" };
            if (jQuery(".pdapp-viewport").length && jQuery(".pdapp-viewport div.moveable-area").length) {
                let t = jQuery(".pdapp-viewport")[0].getBoundingClientRect(),
                    p = jQuery(".pdapp-viewport div.moveable-area")[0].getBoundingClientRect();
                if (void 0 === t.width || void 0 === p.width || 0 == t.width || 0 == p.width) return !1;
                let a = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100;
                (t = JSON.parse(JSON.stringify(t))),
                    (p = JSON.parse(JSON.stringify(p))),
                    (t.width = parseFloat(t.width) / a),
                    (t.height = parseFloat(t.height) / a),
                    (t.top = parseFloat(t.top) / a),
                    (t.left = parseFloat(t.left) / a),
                    (p.width = parseFloat(p.width) / a),
                    (p.height = parseFloat(p.height) / a),
                    (p.top = parseFloat(p.top) / a),
                    (p.left = parseFloat(p.left) / a),
                    "top" == e
                        ? ((o.top = t.top - p.top), (r.top = 0 - o.top))
                        : "right" == e
                          ? ((o.left = t.left + t.width - (p.left + p.width)), (r.left = 0 - o.left))
                          : "bot" == e
                            ? ((o.top = t.top + t.height - (p.top + p.height)), (r.top = 0 - o.top))
                            : "left" == e
                              ? ((o.left = t.left - p.left), (r.left = 0 - o.left))
                              : "centerAll" == e
                                ? ((o.top = t.top - p.top + (t.height - p.height) / 2),
                                  (r.top = 0 - o.top),
                                  (o.left = t.left - p.left + (t.width - p.width) / 2),
                                  (r.left = 0 - o.left))
                                : "middle" == e
                                  ? ((o.top = t.top - p.top + (t.height - p.height) / 2), (r.top = 0 - o.top))
                                  : "center" == e &&
                                    ((o.left = t.left - p.left + (t.width - p.width) / 2), (r.left = 0 - o.left));
            }
            if ("" === o.top && "" === o.left) return !1;
            let n = [];
            for (let e = 0; e < t.length; e++) {
                let i = jQuery(t[e]),
                    l = i.attr("id");
                n.push(l), a.setPos(i, o), t.length - 1 == e && p(n, r, o);
            }
        },
        setPos: function (e, t) {
            let p = pdappAPI.tool.getTransform(e);
            if ("" != p) {
                let a = p.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                "" !== t.top && (a[5] = (parseFloat(a[5]) + t.top).toFixed(3)),
                    "" !== t.left && (a[4] = (parseFloat(a[4]) + t.left).toFixed(3)),
                    e.attr("transform", "matrix(" + a.join(", ") + ")"),
                    e.removeAttr("style");
            }
        },
        moveGroup: function (e, t, p) {
            if (0 == t.length || "function" != typeof p) return !1;
            let a = [];
            for (let o = 0; o < t.length; o++) {
                let r = jQuery(t[o]),
                    n = r.attr("id");
                pdappAPI.tool.move[e](r), a.push(n), t.length - 1 == o && p(a);
            }
        },
        deleteGroup: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (0 == t.length || "function" != typeof e) return !1;
            let p = [],
                a = [],
                o = [],
                r = [];
            for (let n = 0; n < t.length; n++) {
                let i = jQuery(t[n]),
                    l = i.attr("id");
                p.push(l),
                    a.push(pdappAPI.history.getIndex(i)),
                    o.push(i.clone()),
                    i.hasClass("pdapp-svg-photo") && r.push({ id: l, value: "" }),
                    i.remove(),
                    t.length - 1 == n && e(p, a, o, r);
            }
            (pdappAPI.tool.pdappMoveAbleRef.target = null), (pdappAPI.tool.targets = []);
        },
    },
    folder: {
        getFolderBreads: function (e, t, p, a) {
            let o = [];
            (t.title = this.getTitle(t.title)),
                this.getFolderBread(e, t, p, function (e) {
                    o.push(e), 0 == e.id && (o.reverse(), "function" == typeof a && a(o));
                });
        },
        getFolderBread: function (e, t, p, a) {
            if (0 != p) {
                let o = 0;
                for (let t in e)
                    if (t != p)
                        for (let r = 0; r < e[t].length; r++)
                            e[t][r].id == p &&
                                ((o = e[t][r].pid),
                                "function" == typeof a &&
                                    a({ id: e[t][r].id, pid: e[t][r].pid, title: this.getTitle(e[t][r].title) }));
                0 == o
                    ? "function" == typeof a && a(t)
                    : this.getFolderBread(e, t, o, function (e) {
                          "function" == typeof a && a(e);
                      });
            } else "function" == typeof a && a(t);
        },
        getTitle: function (e) {
            let t = "Untitled";
            if (void 0 !== e[pdappLangDefault] && "" != e[pdappLangDefault]) t = e[pdappLangDefault];
            else for (let p in e) "" != e[p] && (t = e[p]);
            return t;
        },
    },
    tool: {
        uID: function (e) {
            let t = Math.floor(1e3 * Math.random()),
                p = Math.floor(1e5 * Math.random());
            if ("number" == typeof e) {
                let a = "";
                const o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
                    r = o.length;
                let n = 0;
                for (; n < e; ) (a += o.charAt(Math.floor(Math.random() * r))), (n += 1);
                return a + "-" + t + "-" + p;
            }
            return t + "-" + p;
        },
        generalAttr: function (e, t) {
            for (let p in e) t.setAttribute(p, e[p]);
            return t;
        },
        generalAttrNS: function (e, t) {
            for (let p in e) t.setAttributeNS(null, p, e[p]);
            return t;
        },
        pdappMoveAbleRef: null,
        pdappSelecToRef: null,
        pdappAblePosition: {},
        getGuideLine: function (e) {
            let t = { ver: [], hor: [] },
                p = jQuery(e)[0].getBoundingClientRect();
            if (0 == p.width) return t;
            t.hor.push({ pos: 0, className: "pdapp-guideline" });
            for (let e = 8; e >= 1; e--)
                t.hor.push({ pos: 0 + Math.round(p.height / e), className: "pdapp-guideline" });
            t.ver.push({ pos: 0, className: "pdapp-guideline" });
            for (let e = 8; e >= 1; e--) t.ver.push({ pos: 0 + Math.round(p.width / e), className: "pdapp-guideline" });
            return t;
        },
        targets: [],
        enableMoveAble: function (e, t, p) {
            let a = this;
            a.targets = [];
            let o = document.querySelector(".pdapp-viewport"),
                r = pdappAPI.tool.getGuideLine(".pdapp-viewport .pdapp-viewport-area"),
                n = {
                    target: a.targets,
                    draggable: !0,
                    edgeDraggable: !1,
                    scalable: !0,
                    keepRatio: !0,
                    renderDirections: ["nw", "n", "ne", "w", "e", "sw", "s", "se"],
                    rotatable: !0,
                    rotationPosition: "top",
                    snappable: !0,
                    pinchable: !0,
                    pinchOutside: !0,
                    verticalGuidelines: r.ver,
                    horizontalGuidelines: r.hor,
                    maxSnapElementGuidelineDistance: 400,
                    maxSnapElementGapDistance: 400,
                    snapDirections: { top: !0, left: !0, bottom: !0, right: !0, center: !0, middle: !0 },
                    elementSnapDirections: { top: !0, left: !0, bottom: !0, right: !0, center: !0, middle: !0 },
                    bounds: { left: 0, top: 0, right: 0, bottom: 0, position: "css" },
                };
            (a.pdappMoveAbleRef = new Moveable(o, n)),
                a.pdappMoveAbleRef.on("beforeScale", (e) => {
                    e.setFixedDirection([0, 0]);
                }),
                a.pdappMoveAbleRef.on("rotateStart", (e) => {
                    e.setFixedDirection([0, 0]);
                }),
                a.pdappMoveAbleRef.on("render", (t) => {
                    (t.target.style.transform = t.transform), "function" == typeof e && e(t.target), a.setMoveTarget();
                }),
                a.pdappMoveAbleRef.on("scaleStart", (e) => {
                    (a.pdappAblePosition = {}),
                        (a.pdappAblePosition.start = pdappAPI.tool.getTransform(jQuery(e.target)));
                }),
                a.pdappMoveAbleRef.on("scaleEnd", (e) => {
                    let t = jQuery(e.target);
                    (a.pdappAblePosition.end = pdappAPI.tool.getTransform(t)),
                        "function" == typeof p && p(t, a.pdappAblePosition);
                }),
                a.pdappMoveAbleRef.on("dragStart", (e) => {
                    (a.pdappAblePosition = {}),
                        (a.pdappAblePosition.start = pdappAPI.tool.getTransform(jQuery(e.target)));
                }),
                a.pdappMoveAbleRef.on("dragEnd", (e) => {
                    let t = jQuery(e.target);
                    (a.pdappAblePosition.end = pdappAPI.tool.getTransform(t)),
                        "function" == typeof p && p(t, a.pdappAblePosition);
                }),
                a.pdappMoveAbleRef.on("renderGroup", (e) => {
                    e.events.forEach((e) => {
                        e.target.style.transform = e.transform;
                    });
                }),
                jQuery(".pdapp-viewport .pdapp-selecto-ref").html(""),
                (a.pdappSelecToRef = new Selecto({
                    container: document.querySelector(".pdapp-viewport .pdapp-selecto-ref"),
                    rootContainer: document.querySelector(".pdapp-viewport svg.pdapp-selecto-area"),
                    dragContainer: document.getElementById("pdapp-viewer-area"),
                    selectableTargets: [".pdapp-viewport svg.pdapp-selecto-area .pdapp-target"],
                    hitRate: 5,
                    selectByClick: !0,
                    selectFromInside: !1,
                    toggleContinueSelect: ["shift"],
                    ratio: 0,
                })),
                a.pdappMoveAbleRef.on("clickGroup", (e) => {
                    a.pdappSelecToRef.clickTarget(e.inputEvent, e.inputTarget);
                }),
                a.pdappMoveAbleRef.on("dragGroup", (e) => {
                    e.events.forEach((e) => {
                        e.target.style.transform = e.transform;
                    });
                }),
                a.pdappSelecToRef.on("dragStart", (e) => {
                    const t = a.pdappMoveAbleRef,
                        p = e.inputEvent.target;
                    (t.isMoveableElement(p) ||
                        ("function" == typeof a.targets.some && a.targets.some((e) => e === p || e.contains(p)))) &&
                        e.stop();
                }),
                a.pdappSelecToRef.on("selectEnd", (e) => {
                    const p = a.pdappMoveAbleRef;
                    e.isDragStart &&
                        (e.inputEvent.preventDefault(),
                        p.waitToChangeTarget().then(() => {
                            p.dragStart(e.inputEvent);
                        }));
                    let o = e.selected;
                    if (0 == o.length && void 0 !== e.inputEvent.clientX) {
                        document.elementsFromPoint(e.inputEvent.clientX, e.inputEvent.clientY).forEach(function (e, t) {
                            if (0 == o.length) {
                                let t = jQuery(e).parents("g.pdapp-target");
                                t.length && (o = jQuery("#" + t.attr("id")));
                            }
                        });
                    }
                    var r;
                    (r = o),
                        (a.targets = r),
                        (a.pdappMoveAbleRef.target = a.targets),
                        "function" == typeof t && t(a.targets),
                        setTimeout(() => {
                            let e = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100;
                            pdappAPI.tool.pdappMoveAbleRef.renderDirections =
                                e < 0.4 ? ["nw", "ne", "sw", "se"] : ["nw", "n", "ne", "w", "e", "sw", "s", "se"];
                        });
                }),
                a.pdappMoveAbleRef.on("changeTargets", (e) => {
                    a.setMoveTarget();
                });
        },
        setMoveTarget: function () {
            if (1 != jQuery(pdappAPI.tool.pdappMoveAbleRef.target).length) return !1;
            let e = this,
                t = jQuery(".pdapp-viewport .moveable-control-box");
            t.length &&
                0 == t.find(".moveable-movebox").length &&
                (t.append('<div class="moveable-movebox"></div>'),
                (e.pdappMoveAbleRef.dragTarget = t.find(".moveable-movebox")[0])),
                setTimeout(() => {
                    let e = jQuery(".pdapp-viewport"),
                        t = pdappAPI.tool.getTransform(jQuery(e.find(".moveable-line.moveable-direction")[0])),
                        p = jQuery(e.find(".moveable-line.moveable-direction")[0]).width(),
                        a = jQuery(e.find(".moveable-line.moveable-direction")[3]).width();
                    e.find(".moveable-movebox").width(p),
                        e.find(".moveable-movebox").height(a),
                        e.find(".moveable-movebox").css("transform", t),
                        pdappAPI.tool.pdappMoveAbleRef.draggable
                            ? e.find(".moveable-movebox").addClass("pdapp-draggable")
                            : e.find(".moveable-movebox").removeClass("pdapp-draggable");
                });
        },
        removeControlBox: function () {
            let e = jQuery(".pdapp-viewport .moveable-control-box.rCS1w3zcxh").length;
            e > 1 &&
                ((e -= 1),
                jQuery(".pdapp-viewport .moveable-control-box.rCS1w3zcxh").each(function (t) {
                    t < e && jQuery(this).remove();
                }));
        },
        getTransform: function (e) {
            let t = e.css("transform");
            return (void 0 !== t && "none" != t) || (t = e.attr("transform")), void 0 !== t && "none" != t ? t : "";
        },
        getTransformPos: function (e, t) {
            let p = pdappAPI.tool
                .getTransform(e)
                .replace("matrix(", "")
                .replace(")", "")
                .replaceAll(" ", "")
                .split(",");
            if (6 == p.length) {
                let a = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                    o = e[0].getBoundingClientRect(),
                    r = jQuery(".pdapp-viewport svg.pdapp-selecto-area")[0].getBoundingClientRect();
                if (0 != o.width && 0 != r.width) {
                    let e = (o.left - r.left) / a,
                        n = (o.top - r.top) / a;
                    "top" == t && (p[5] = parseFloat(p[5]) - n),
                        "right" == t && (p[4] = parseFloat(p[4]) - e + (r.width - o.width) / a),
                        "left" == t && (p[4] = parseFloat(p[4]) - e),
                        "bot" == t && (p[5] = parseFloat(p[5]) - n + (r.height - o.height) / a),
                        "center" == t && (p[4] = parseFloat(p[4]) - e + (r.width - o.width) / a / 2),
                        "middle" == t && (p[5] = parseFloat(p[5]) - n + (r.height - o.height) / a / 2),
                        "centerAll" == t &&
                            ((p[4] = parseFloat(p[4]) - e + (r.width - o.width) / a / 2),
                            (p[5] = parseFloat(p[5]) - n + (r.height - o.height) / a / 2));
                }
                e.removeAttr("style");
            }
            return (
                (p[4] = parseFloat(p[4]).toFixed(3)),
                (p[5] = parseFloat(p[5]).toFixed(3)),
                "matrix(" + p.join(", ") + ")"
            );
        },
        getTransformMove: function (e, t) {
            let p = pdappAPI.tool
                .getTransform(e)
                .replace("matrix(", "")
                .replace(")", "")
                .replaceAll(" ", "")
                .split(",");
            return (
                6 == p.length &&
                    ("top" == t && (p[5] = parseFloat(p[5]) - 1),
                    "bot" == t && (p[5] = parseFloat(p[5]) + 1),
                    "left" == t && (p[4] = parseFloat(p[4]) - 1),
                    "right" == t && (p[4] = parseFloat(p[4]) + 1)),
                "matrix(" + p.join(", ") + ")"
            );
        },
        top: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "top");
                e.attr("transform", t);
            }
        },
        right: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "right");
                e.attr("transform", t);
            }
        },
        bot: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "bot");
                e.attr("transform", t);
            }
        },
        left: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "left");
                e.attr("transform", t);
            }
        },
        move: {
            top: function (e) {
                if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                    let t = pdappAPI.tool.getTransformMove(e, "top");
                    e.attr("transform", t);
                }
            },
            bot: function (e) {
                if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                    let t = pdappAPI.tool.getTransformMove(e, "bot");
                    e.attr("transform", t);
                }
            },
            left: function (e) {
                if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                    let t = pdappAPI.tool.getTransformMove(e, "left");
                    e.attr("transform", t);
                }
            },
            right: function (e) {
                if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                    let t = pdappAPI.tool.getTransformMove(e, "right");
                    e.attr("transform", t);
                }
            },
        },
        middle: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "middle");
                e.attr("transform", t);
            }
        },
        center: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "center");
                e.attr("transform", t);
            }
        },
        centerAll: function (e) {
            if (e.length && jQuery(".pdapp-viewport svg.pdapp-selecto-area").length) {
                let t = pdappAPI.tool.getTransformPos(e, "centerAll");
                e.attr("transform", t);
            }
        },
        colorPicker: function (e, t, p) {
            jQuery(e).spectrum({
                flat: !0,
                showInput: !1,
                showInitial: !1,
                showButtons: !1,
                showPalette: !0,
                showSelectionPalette: !0,
                localStorageKey: "spectrum.homepage",
                maxSelectionSize: 16,
                preferredFormat: "hex",
                palette: [
                    "rgb(255, 255, 255)",
                    "rgb(238 238 238)",
                    "rgb(217, 217, 217)",
                    "rgb(0, 0, 0)",
                    "rgb(75, 79, 148)",
                    "rgb(30, 144, 255)",
                    "rgb(0, 228, 232)",
                    "rgb(179, 178, 74)",
                    "rgb(93, 221, 63)",
                    "rgb(194, 228, 75)",
                    "rgb(232, 203, 203)",
                    "rgb(255, 221, 50)",
                    "rgb(255, 139, 56)",
                    "rgb(255, 68, 78)",
                    "rgb(255, 105, 180)",
                    "rgb(215, 99, 236)",
                ],
            }),
                jQuery(e).on("move.spectrum", function (e, t) {
                    let a = t.toHexString();
                    "function" == typeof p && p(e.target, a);
                }),
                setTimeout(() => {
                    jQuery(".pdapp-text-groups .pdapp-list-document").text(t.document_color),
                        jQuery(".pdapp-text-groups .pdapp-list-selection").text(t.selection_color);
                }, 1);
        },
        encodeBase64: function (e) {
            let t = unescape(encodeURIComponent(e));
            return btoa(t);
        },
        decodeBase64: function (e) {
            return (e = e.replace(/\s/g, "")), decodeURIComponent(escape(atob(e)));
        },
        imgToBase64: function (e, t, p) {
            let a = document.createElement("canvas"),
                o = a.getContext("2d"),
                r = document.createElement("img");
            (r.crossOrigin = "anonymous"),
                (r.onload = function () {
                    if (void 0 === p) (a.width = r.width), (a.height = r.height), o.drawImage(r, 0, 0);
                    else {
                        let e = r.width,
                            t = r.height;
                        (r.width > p || r.height > p) &&
                            (r.width > r.height
                                ? ((e = p), (t = (p * r.height) / r.width))
                                : ((t = p), (e = (p * r.width) / r.height))),
                            (a.width = e),
                            (a.height = t),
                            o.drawImage(r, 0, 0, e, t);
                    }
                    "function" == typeof t && t(a.toDataURL("image/png"), a.width, a.height), r.remove(), a.remove();
                }),
                (r.src = e);
        },
        rgbToHex: function (e) {
            if (0 === e.indexOf("#")) return e;
            if (-1 === e.indexOf("rgb(")) return e;
            let t = (e = e.replace("rgb(", "").replace(")", "")).split(", ");
            if (3 != t.length) return e;
            function p(e) {
                return (e = parseInt(e)).toString(16).padStart(2, "0");
            }
            return "#" + p(t[0]) + p(t[1]) + p(t[2]);
        },
        hexToRgb: function (e, t = !1) {
            if (0 === e.indexOf("rgb("))
                return t ? e.replace("rgb(", "").replace(")", "").replaceAll(" ", "").split(",") : e;
            if (0 !== e.indexOf("#")) {
                if (t) {
                    return (function (e) {
                        e = colorHex.replace("#", "");
                        let t = parseInt(e, 16);
                        return { r: (t >>> 16) & 255, g: (t >>> 8) & 255, b: 255 & t };
                    })(e);
                }
                return "rgb(255, 255, 255)";
            }
            let p = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
            return t
                ? 4 == p.length
                    ? { r: parseInt(p[1], 16), g: parseInt(p[2], 16), b: parseInt(p[3], 16) }
                    : { r: 255, g: 255, b: 255 }
                : 4 == p.length
                  ? "rgb(" + parseInt(p[1], 16) + ", " + parseInt(p[2], 16) + ", " + parseInt(p[3], 16) + ")"
                  : "rgb(255, 255, 255)";
        },
        toDate: function (e) {
            let t = new Date(e.replaceAll("-", "/")).toLocaleTimeString(),
                p = e.split(" "),
                a = t.split(" "),
                o = a[0].split(":");
            return void 0 !== a[1] ? p[0] + " " + o[0] + ":" + o[1] + a[1] : e;
        },
        getTime: function () {
            return new Date().getTime();
        },
        checkTime: function (e, t) {
            let p = !1;
            return new Date().getTime() - e > 6e4 * t && (p = !0), p;
        },
        standardArtworkToAi: function (e) {
            let t = e.find("svg");
            if (0 == t.length) return !1;
            let p = ["id", "enable-background"];
            for (let e = 0; e < p.length; e++) t.removeAttr(p[e]);
            void 0 === t.attr("xmlns") && t.attr("xmlns", "http://www.w3.org/2000/svg");
            let a = t.attr("width"),
                o = t.attr("height"),
                r = t.attr("viewBox");
            if (void 0 === a || void 0 === o) {
                if (void 0 !== r) (a = r.split(" ")[2]), (o = r.split(" ")[3]);
                else {
                    let e = t[0].getBBox();
                    (a = e.width), (o = e.height);
                }
                t.attr("width", a + "px"), t.attr("height", o + "px");
            }
            void 0 === r && t.attr("viewBox", [0, 0, a, o].join(" ")),
                void 0 === t.attr("x") && t.attr("x", "0px"),
                void 0 === t.attr("y") && t.attr("y", "0px");
        },
        toPx: function (e = 0, t = "in", p = 300) {
            let a = 0;
            return (
                (a = "in" == t ? parseFloat(e) * p : "cm" == t ? (parseFloat(e) / 2.54) * p : parseFloat(e)),
                parseFloat(a.toFixed(3))
            );
        },
        toCm: function (e = 0, t = "in", p = 300) {
            let a = 0;
            return (
                (a = "in" == t ? 2.54 * parseFloat(e) : "px" == t ? (parseFloat(e) / p) * 2.54 : parseFloat(e)),
                parseFloat(a.toFixed(3))
            );
        },
        toIn: function (e = 0, t = "cm", p = 300) {
            let a = 0;
            return (
                (a = "cm" == t ? parseFloat(e) / 2.54 : "px" == t ? parseFloat(e) / p : parseFloat(e)),
                parseFloat(a.toFixed(3))
            );
        },
        removeEmoij: function (e) {
            return e.replace("/[p{Emoji}]/gu", "");
        },
        setLocalVar: function (e, t) {
            localStorage.setItem(e, t);
        },
        getLocalVar: function (e, t) {
            let p = localStorage.getItem(e);
            return null != p ? p : (void 0 === t && (t = ""), t);
        },
        removeLocalVar: function (e) {
            localStorage.removeItem(e);
        },
        getData: function (e) {
            return new Promise(function (t, p) {
                let a = {
                    method: "GET",
                    url: e,
                    dataType: "json",
                    success: function (e) {
                        0 == e
                            ? p({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? t({ msg: e.msg, data: e.data }) : p({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, a) {
                        "" == a && (a = "Request failed"), p({ msg: a, error: 1 });
                    },
                };
                jQuery.ajax(a);
            });
        },
        postData: function (e, t, p, a) {
            let o = void 0 !== p ? p : "POST";
            return new Promise(function (p, r) {
                let n = {
                    method: o,
                    url: e,
                    dataType: "json",
                    data: t,
                    success: function (e) {
                        0 == e
                            ? r({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? p({ msg: e.msg, data: e.data }) : r({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, p) {
                        "" == p && (p = "Request failed"), r({ msg: p, error: 1 });
                    },
                };
                void 0 !== a && ((n.data = JSON.stringify(t)), (n.contentType = "application/json; charset=utf-8")),
                    jQuery.ajax(n);
            });
        },
        getLibData: function (e) {
            return new Promise(function (t, p) {
                let a = {
                    method: "GET",
                    url: e,
                    dataType: "json",
                    success: function (e) {
                        t(e);
                    },
                    error: function (e, t, a) {
                        "" == a && (a = "Request failed"), p({ msg: a, error: 1 });
                    },
                };
                jQuery.ajax(a);
            });
        },
        updateURL: function (e) {
            let t = pdappAdminUrl + "admin.php?page=product-designer-app-" + e;
            window.history.pushState(null, "", t);
        },
        changeThumb(e, t, p) {
            if ("image/png" != e.type && "image/jpg" != e.type && "image/jpeg" != e.type && "image/svg+xml" != e.type)
                return !1;
            let a = document.createElement("canvas"),
                o = a.getContext("2d"),
                r = new Image();
            return (
                (r.onload = function () {
                    (p = void 0 === p ? 500 : p),
                        (a.width = p),
                        (a.height = (p * r.height) / r.width),
                        o.drawImage(r, 0, 0, a.width, a.height);
                    let e = a.toDataURL();
                    setTimeout(() => {
                        "function" == typeof t && t(e);
                    });
                }),
                (r.src = URL.createObjectURL(e)),
                !0
            );
        },
        loadFontFace: function (e, t, p) {
            let a = document.createElement("style");
            a.setAttribute("type", "text/css"),
                (a.innerHTML = t),
                (a.onload = function () {
                    setTimeout(() => {
                        if (
                            null == pdappAPI.tool.pdappMoveAbleRef ||
                            null == pdappAPI.tool.pdappMoveAbleRef.target ||
                            0 == pdappAPI.tool.pdappMoveAbleRef.target.length
                        )
                            return !1;
                        let t = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
                        pdappAPI.text.changeFont(e, 200, p, t);
                    }, 500);
                }),
                jQuery("head").append(a);
        },
        loadFontData: async function (e, t) {
            let p = pdappAdminUrl + "admin-ajax.php?action=pdapp-load-font&admin=1&pdapp-nonce=" + pdappNonce;
            try {
                let a = await pdappAPI.tool.postData(p, { title: e });
                "function" == typeof t && t(a.data.fontface);
            } catch (e) {
                t(""),
                    (pdappVueApp.toast = { show: !0, type: "error", text: e.msg }),
                    setTimeout(() => {
                        pdappVueApp.toast.show = !1;
                    }, 5e3);
            }
        },
        loadMore: function (e, t, p) {
            if (0 == jQuery(e).length && (void 0 === p || p < 10)) {
                let a = this;
                return (
                    setTimeout(() => {
                        let o = void 0 === p ? 1 : p + 1;
                        a.loadMore(e, t, o);
                    }, 500),
                    !1
                );
            }
            if (jQuery(e).hasClass("hasScroll")) return !1;
            jQuery(e).addClass("hasScroll"),
                jQuery(e).scroll(function () {
                    jQuery(e).scrollTop() + jQuery(e).height() >= jQuery(e)[0].scrollHeight - 5 &&
                        "function" == typeof t &&
                        t();
                });
        },
        getStringBetween: function (e, t, p) {
            const a = e.indexOf(t),
                o = e.indexOf(p, a + t.length);
            return -1 === a || -1 === o ? null : e.substring(a + t.length, o);
        },
        setSvgStyle: function (e) {
            let t = this,
                p = jQuery(".pdapp-viewport svg.pdapp-selecto-area"),
                a = p.find("style").html();
            if (p.length) {
                let o = "",
                    r = {};
                if (void 0 !== a) {
                    let e = a.split("}");
                    for (let p = 0; p < e.length; p++)
                        if ("" != e[p] && 0 == e[p].indexOf("@font-face{")) {
                            let a = t.getStringBetween(e[p], "@font-face{font-family: '", "';src:");
                            (a = a.replaceAll(" ", "+")), (r[a] = void 0 === r[a] ? e[p] + "}" : r[a] + e[p] + "}");
                        }
                }
                p.find("g.pdapp-target").each(function () {
                    if (jQuery(this).hasClass("pdapp-svg-text")) {
                        let t = jQuery(this).find("text").attr("font-family");
                        (t = t.replaceAll(" ", "+")), void 0 !== e[t] ? (o += e[t]) : void 0 !== r[t] && (o += r[t]);
                    }
                }),
                    p.find("style").remove(),
                    "" != o && ((o = '<style xmlns="http://www.w3.org/1999/xhtml">' + o + "</style>"), p.prepend(o));
            }
        },
        renderShape: function (e, t, p) {
            let a = [],
                o = e.find("image").width(),
                r = e.find("image").height(),
                n = o,
                i = 0,
                l = (r - o) / 2;
            o > r && ((n = r), (i = (o - r) / 2), (l = 0));
            let d = e.hasClass("pdapp-flip");
            if ("circle" == t.type) {
                let e = n / 2 + i,
                    t = n / 2 + l,
                    p = document.createElementNS("http://www.w3.org/2000/svg", "circle");
                p.setAttributeNS(null, "cx", e.toFixed(2)),
                    p.setAttributeNS(null, "cy", t.toFixed(2)),
                    p.setAttributeNS(null, "r", (n / 2).toFixed(2)),
                    d && p.setAttributeNS(null, "transform", "scale(-1, 1)"),
                    a.push(p);
            } else if ("rect" == t.type) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
                e.setAttributeNS(null, "width", n.toFixed(2)),
                    e.setAttributeNS(null, "height", n.toFixed(2)),
                    e.setAttributeNS(null, "x", i.toFixed(2)),
                    e.setAttributeNS(null, "y", l.toFixed(2)),
                    d && e.setAttributeNS(null, "transform", "scale(-1, 1)"),
                    a.push(e);
            } else {
                let e = t.value.size,
                    p = parseFloat(e.width),
                    n = parseFloat(e.height),
                    i = 1,
                    l = 0,
                    s = 0;
                o / r > p / n ? ((i = r / n), (l = (o - p * i) / 2)) : ((i = o / p), (s = (r - n * i) / 2));
                let u = i;
                d && ((u = -1 * i), (l *= -1));
                let c = "matrix(" + u + ", 0, 0, " + i + ", " + l + ", " + s + ")",
                    f = t.value.paths;
                for (let e = 0; e < f.length; e++) {
                    let t = document.createElementNS("http://www.w3.org/2000/svg", "path");
                    t.setAttributeNS(null, "d", f[e]), t.setAttributeNS(null, "transform", c), a.push(t);
                }
            }
            if (a.length) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
                e.setAttributeNS(null, "id", p);
                for (let t = 0; t < a.length; t++) e.appendChild(a[t]);
                return e;
            }
            return "";
        },
        getColors: function (e, t) {
            let p =
                '<svg x="0" y="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                e[0].outerHTML +
                "</svg>";
            getSVGColors(p, { flat: !0 }).then((e) => {
                "function" == typeof t && t(e);
            });
        },
        ruler: {
            added: !1,
            clear_gtitle: "Clear Guide lines",
            update: {},
            init: function (e) {
                (pdappAPI.tool.ruler.update = this.prototype.builder()),
                    pdappAPI.tool.ruler.update.constructRulers.call(this, e);
            },
            prototype: {
                builder: function () {
                    var e,
                        t = 0,
                        p = 0,
                        a = 1,
                        o = "px",
                        r = {},
                        n = [],
                        i = document.createElement("div"),
                        l = [],
                        d = {
                            rulerHeight: 15,
                            fontFamily: "arial",
                            fontSize: "8px",
                            strokeStyle: "gray",
                            textColor: "gray",
                            sides: ["top", "left"],
                            cornerSides: ["topleft"],
                            lineWidth: 1,
                            enableMouseTracking: !0,
                        },
                        s = function (e, t) {
                            switch (
                                ((e.canvas.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                    -(e.canvas.width / 2 - e.canvas.height)
                                )),
                                t)
                            ) {
                                case "top":
                                    e.orgPos = parseInt(e.canvas.style.left);
                                    break;
                                case "left":
                                    (e.canvas.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                        e.canvas.width / 2 + e.canvas.height
                                    )),
                                        (e.canvas.style.left = 0),
                                        (e.orgPos = parseInt(e.canvas.style.top)),
                                        (function (e, t) {
                                            var p = "rotate(" + t + "deg)",
                                                a =
                                                    pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                        Math.abs(parseInt(e.canvas.style.left))
                                                    ) + " 0px";
                                            (e.canvas.style.webkitTransform = p),
                                                (e.canvas.style.MozTransform = p),
                                                (e.canvas.style.OTransform = p),
                                                (e.canvas.style.msTransform = p),
                                                (e.canvas.style.transform = p),
                                                (e.canvas.style.webkitTransformOrigin = a),
                                                (e.canvas.style.MozTransformOrigin = a),
                                                (e.canvas.style.OTransformOrigin = a),
                                                (e.canvas.style.msTransformOrigin = a),
                                                (e.canvas.style.transformOrigin = a);
                                        })(e, 270);
                            }
                        },
                        u = function (r, l, d, s, u) {
                            var c,
                                f = document.createElement("div"),
                                g = 1 === r ? "pdapp-ruler-line-ver" : "pdapp-ruler-line-hor",
                                h = 1 === r ? t : p;
                            (f.title = "Double click to delete"),
                                pdappAPI.tool.ruler.prototype.utils.addClasss(f, ["pdapp-ruler-line", g]),
                                (f = i.appendChild(f)),
                                1 === r
                                    ? ((f.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          l - e.container.getBoundingClientRect().left
                                      )),
                                      u &&
                                          (f.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              Math.round(l / a) + e.rulerHeight
                                          )))
                                    : ((f.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          d - e.container.getBoundingClientRect().top
                                      )),
                                      u &&
                                          (f.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              Math.round(d / a) + e.rulerHeight
                                          ))),
                                n.push({
                                    dimension: r,
                                    line: pdappAPI.tool.ruler.prototype.guideLine(
                                        f,
                                        e.container.querySelector(".pdapp-ruler-box"),
                                        r,
                                        e,
                                        h,
                                        function (t, p, a) {
                                            var o = 1 === t.dimension ? p : a;
                                            if (!t.assigned()) return o > e.rulerHeight && t.assigned(!0), !1;
                                            o < e.rulerHeight &&
                                                (n.some(function (e, p) {
                                                    if (e.line === t) return (c = p), !0;
                                                }),
                                                t.destroy(),
                                                n.splice(c, 1));
                                        },
                                        s,
                                        a,
                                        o
                                    ),
                                });
                        },
                        c = function (t, p) {
                            var a,
                                o,
                                n,
                                i = "left" === p || "right" === p ? 1 : 2,
                                l = 1 === i ? "pdapp-ruler-vertical" : "pdapp-ruler-horizontal",
                                d = document.createElement("canvas");
                            pdappAPI.tool.ruler.prototype.utils.addClasss(d, [
                                "pdapp-ruler",
                                l,
                                "pdapp_ruLer_align_" + p,
                            ]),
                                (a = t.appendChild(d)),
                                (r[p] = pdappAPI.tool.ruler.prototype.rulerConstructor(a, e, i)),
                                r[p].drawRuler(t.offsetWidth, e.rulerHeight),
                                s(r[p], p),
                                (o = r[p]),
                                (n = function (e) {
                                    u(o.dimension, e.clientX, e.clientY, e);
                                }),
                                o.canvas.addEventListener("mousedown", n),
                                (o.clearListeners = function () {
                                    o.canvas.removeEventListener("mousedown", n);
                                });
                        },
                        f = (function () {
                            function t(e) {
                                e.stopPropagation(), m();
                            }
                            return function (p, a) {
                                a.forEach(function (a) {
                                    var o = (function (t, p) {
                                        var a = document.createElement("div"),
                                            o = "pdapp-ruler-corner" + p.toUpperCase();
                                        a.setAttribute("class", "tooltip-right"),
                                            a.setAttribute("data-tooltip", pdappAPI.tool.ruler.clear_gtitle);
                                        var r = document.createElement("i");
                                        return (
                                            r.setAttribute("class", "material-icons material-symbols-outlined"),
                                            (r.innerHTML = "close"),
                                            a.appendChild(r),
                                            pdappAPI.tool.ruler.prototype.utils.addClasss(a, ["pdapp-ruler-corner", o]),
                                            (a.style.width = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                e.rulerHeight
                                            )),
                                            (a.style.height = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                e.rulerHeight
                                            )),
                                            t.appendChild(a)
                                        );
                                    })(p, a);
                                    o.addEventListener("mousedown", t),
                                        (o.destroy = function () {
                                            o.removeEventListener("mousedown", t), o.parentNode.removeChild(o);
                                        }),
                                        l.push(o);
                                });
                            };
                        })(),
                        g = function (e) {
                            n.forEach(function (e) {
                                e.line.stopDrag();
                            });
                        },
                        h = function (e) {
                            var t = 0;
                            for (var p in r) r.hasOwnProperty(p) && e(r[p], t++);
                        },
                        m = function () {
                            n.forEach(function (e) {
                                e.line.destroy();
                            }),
                                (n = []);
                        };
                    return {
                        VERTICAL: 1,
                        HORIZONTAL: 2,
                        setPos: function (e) {
                            var a,
                                o = 0,
                                r = 0,
                                i = 0;
                            h(function (t) {
                                1 === t.dimension
                                    ? ((a = t.canvas.style.top),
                                      (t.canvas.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          t.orgPos + parseInt(e.y)
                                      )),
                                      (i = parseInt(a) - parseInt(t.canvas.style.top)))
                                    : ((o = t.canvas.style.left),
                                      (t.canvas.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          t.orgPos + parseInt(e.x)
                                      )),
                                      (r = parseInt(o) - parseInt(t.canvas.style.left)));
                            }),
                                n.forEach(function (t) {
                                    2 === t.dimension
                                        ? ((t.line.guideLine.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              parseInt(t.line.guideLine.style.top) - i
                                          )),
                                          t.line.curPosDelta(parseInt(e.y)))
                                        : ((t.line.guideLine.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              parseInt(t.line.guideLine.style.left) - r
                                          )),
                                          t.line.curPosDelta(parseInt(e.x)));
                                }),
                                (t = parseInt(e.x)),
                                (p = parseInt(e.y));
                        },
                        setScale: function (r, i) {
                            let l = a != r;
                            var d, s, u;
                            h(function (e) {
                                e.context.clearRect(0, 0, e.canvas.width, e.canvas.height),
                                    e.context.beginPath(),
                                    e.setScale(r),
                                    e.context.stroke(),
                                    (a = r),
                                    void 0 !== i && (o = i);
                            }),
                                n.forEach(function (a) {
                                    2 === a.dimension
                                        ? (l &&
                                              ((d = parseInt(a.line.guideLine.style.top)),
                                              (s = e.rulerHeight + 1),
                                              (u = parseFloat(r) / a.line.curScale()),
                                              (a.line.guideLine.style.top =
                                                  pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                      (d - s - p) / u + s + p
                                                  )),
                                              a.line.curScale(r)),
                                          void 0 !== i && a.line.curUnit(i))
                                        : (l &&
                                              ((d = parseInt(a.line.guideLine.style.left)),
                                              (s = e.rulerHeight + 1),
                                              (u = parseFloat(r) / a.line.curScale()),
                                              (a.line.guideLine.style.left =
                                                  pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                      (d - s - t) / u + s + t
                                                  )),
                                              a.line.curScale(r)),
                                          void 0 !== i && a.line.curUnit(i));
                                });
                        },
                        clearGuides: m,
                        getGuides: function () {
                            return n.map(function (o) {
                                return {
                                    posX: Math.round((parseInt(o.line.guideLine.style.left) - t - e.rulerHeight) * a),
                                    posY: Math.round((parseInt(o.line.guideLine.style.top) - p - e.rulerHeight) * a),
                                    dimension: o.dimension,
                                };
                            });
                        },
                        setGuides: function (e) {
                            if (!e) return !1;
                            e.forEach(function (e) {
                                u(e.dimension, e.posX, e.posY, null, !0);
                            });
                        },
                        constructRulers: function (t) {
                            (i = pdappAPI.tool.ruler.prototype.utils.addClasss(i, "pdapp-ruler-box")),
                                (e = pdappAPI.tool.ruler.prototype.utils.extend(d, t)),
                                (i = e.container.appendChild(i)),
                                e.sides.forEach(function (e) {
                                    c(i, e);
                                }),
                                f(i, e.cornerSides),
                                e.container.addEventListener("mouseup", g);
                        },
                        toggleRulerVisibility: function (t) {
                            var p = t ? "block" : "none";
                            i.style.display = p;
                            var a = e.container.querySelectorAll(".pdapp-ruler-tracker");
                            a.length > 0 && ((a[0].style.display = p), (a[1].style.display = p));
                        },
                        toggleGuideVisibility: function (e) {
                            var t = e ? "show" : "hide";
                            n.forEach(function (e) {
                                e.line[t]();
                            });
                        },
                        destroy: function () {
                            m(),
                                h(function (e) {
                                    pdappAPI.tool.ruler.destroy();
                                }),
                                l.forEach(function (e) {
                                    e.destroy();
                                }),
                                e.container.removeEventListener("mouseup", g),
                                i.parentNode.removeChild(i);
                        },
                    };
                },
                rulerConstructor: function (e, t, p) {
                    var a = e,
                        o = a.getContext("2d"),
                        r = 0,
                        n = 0,
                        i = 1,
                        l = p || 2,
                        d = document.createElement("div"),
                        s = function () {
                            for (var e = 0, p = "", a = 0, l = !1, d = r / 1.5, s = r / 1.5, u = 0; u <= n; u += 1)
                                (l = !1),
                                    (p = ""),
                                    (a = n / 2 - u) % 50 == 0
                                        ? ((e = 0), (p = (Math.abs(a) * i).toFixed(1)), (l = !0))
                                        : a % 25 == 0
                                          ? ((e = d), (l = !0))
                                          : a % 5 == 0 && ((e = s), (l = !0)),
                                    l &&
                                        (o.moveTo(u + 0.5, r + 0.5),
                                        o.lineTo(u + 0.5, e + 0.5),
                                        o.fillText(p, u + 1.5, r / 2 + 1),
                                        (o.fillStyle = t.textColor));
                        },
                        u = 0,
                        c = 0,
                        f = function (e) {
                            if (((xPos = e.clientX + u), (yPos = e.clientY + c), 2 === l)) {
                                let e = jQuery("#pdapp-viewer-area")[0].scrollWidth - 2,
                                    p = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                        xPos - parseInt(t.container.getBoundingClientRect().left)
                                    );
                                d.style.left = parseInt(p.replace("px", "")) > e ? e + "px" : p;
                            } else {
                                let e = jQuery("#pdapp-viewer-area")[0].scrollHeight - 2,
                                    p = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                        yPos - parseInt(t.container.getBoundingClientRect().top)
                                    );
                                d.style.top = parseInt(p.replace("px", "")) > e ? e : p;
                            }
                        };
                    jQuery(t.container).scroll(function (e) {
                        c != jQuery(t.container).scrollTop() && (c = jQuery(t.container).scrollTop()),
                            u != jQuery(t.container).scrollLeft() && (u = jQuery(t.container).scrollLeft());
                    });
                    return (
                        t.enableMouseTracking &&
                            (function () {
                                (d = t.container.appendChild(d)),
                                    pdappAPI.tool.ruler.prototype.utils.addClasss(d, "pdapp-ruler-tracker");
                                var e = pdappAPI.tool.ruler.prototype.utils.pixelize(t.rulerHeight);
                                2 === l ? (d.style.height = e) : (d.style.width = e),
                                    t.container.addEventListener("mousemove", f);
                            })(),
                        {
                            getLength: function () {
                                return n;
                            },
                            getThickness: function () {
                                return r;
                            },
                            getScale: function () {
                                return i;
                            },
                            setScale: function (e) {
                                return (i = parseFloat(e)), s(), i;
                            },
                            dimension: l,
                            orgPos: 0,
                            canvas: a,
                            context: o,
                            drawRuler: function (e, p, l) {
                                (n = a.width = 8 * e),
                                    (r = a.height = p),
                                    (i = l || i),
                                    (o.strokeStyle = t.strokeStyle),
                                    (o.font = t.fontSize + " " + t.fontFamily),
                                    (o.lineWidth = t.lineWidth),
                                    o.beginPath(),
                                    s(),
                                    o.stroke();
                            },
                            drawPoints: s,
                            destroy: function () {
                                t.container.removeEventListener("mousemove", f),
                                    d.parentNode.removeChild(d),
                                    this.clearListeners && this.clearListeners();
                            },
                        }
                    );
                },
                guideLine: function (e, t, p, a, o, r, n, i, l) {
                    var d,
                        s = e,
                        u = i,
                        c = !1,
                        f = o || 0,
                        g = t,
                        h = p || 2,
                        m =
                            ((r = r || function () {}),
                            (l = function (e) {
                                return e;
                            }),
                            {
                                move: function (e, t) {
                                    (s.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(e)),
                                        (s.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(t)),
                                        r(d, e, t);
                                },
                                startMoving: function (e) {
                                    pdappAPI.tool.ruler.prototype.utils.addClasss(s, ["pdapp-ruler-line-dragged"]);
                                    var t = (e = e || window.event) ? e.clientX : 0,
                                        p = e ? e.clientY : 0,
                                        o = parseInt(s.style.top || 0),
                                        r = parseInt(s.style.left || 0),
                                        n = parseInt(s.offsetWidth),
                                        i = parseInt(s.offsetHeight),
                                        l = parseInt(g.offsetWidth),
                                        d = parseInt(g.offsetHeight),
                                        u = 2 === h ? "ns-resize" : "ew-resize";
                                    (a.container.style.cursor = u), (s.style.cursor = u);
                                    var c = t - r,
                                        f = p - o;
                                    document.onmousemove = function (e) {
                                        var t = (e = e || window.event).clientX,
                                            p = e.clientY,
                                            a = t - c,
                                            o = p - f;
                                        a < 0 && (a = 0),
                                            o < 0 && (o = 0),
                                            a + n > l && (a = l - n),
                                            o + i > d && (o = d - i),
                                            m.move(a, o);
                                    };
                                },
                                stopMoving: function () {
                                    (a.container.style.cursor = null),
                                        (s.style.cursor = null),
                                        (document.onmousemove = function () {}),
                                        pdappAPI.tool.ruler.prototype.utils.removeClasss(s, [
                                            "pdapp-ruler-line-dragged",
                                        ]);
                                },
                            }),
                        v = function () {
                            m.stopMoving(),
                                (r = null),
                                s.removeEventListener("mousedown", y),
                                s.removeEventListener("mouseup", w),
                                s.removeEventListener("dblclick", A),
                                s.parentNode && s.parentNode.removeChild(s);
                        },
                        y = function (e) {
                            e.stopPropagation(), m.startMoving();
                        },
                        w = function (e) {
                            m.stopMoving();
                        },
                        A = function (e) {
                            e.stopPropagation(), v();
                        };
                    return (
                        s.addEventListener("mousedown", y),
                        s.addEventListener("mouseup", w),
                        s.addEventListener("dblclick", A),
                        n && m.startMoving(n),
                        (d = {
                            setAsDraggable: m,
                            startDrag: m.startMoving,
                            stopDrag: m.stopMoving,
                            destroy: v,
                            curScale: function (e) {
                                return void 0 === e ? u : (u = e);
                            },
                            curUnit: l,
                            assigned: function (e) {
                                return void 0 === e ? c : (c = e);
                            },
                            curPosDelta: function (e) {
                                return void 0 === e ? f : (f = e);
                            },
                            guideLine: s,
                            dimension: h,
                            hide: function () {
                                s.style.display = "none";
                            },
                            show: function () {
                                s.style.display = "block";
                            },
                        })
                    );
                },
                utils: {
                    extend: function () {
                        for (var e = 1; e < arguments.length; e++)
                            for (var t in arguments[e])
                                arguments[e].hasOwnProperty(t) && (arguments[0][t] = arguments[e][t]);
                        return arguments[0];
                    },
                    pixelize: function (e) {
                        return e + "px";
                    },
                    prependChild: function (e, t) {
                        return e.insertBefore(t, e.firstChild);
                    },
                    addClasss: function (e, t) {
                        return (
                            t instanceof Array || (t = [t]),
                            t.forEach(function (t) {
                                e.className += " " + t;
                            }),
                            e
                        );
                    },
                    removeClasss: function (e, t) {
                        var p = e.className;
                        return (
                            t instanceof Array || (t = [t]),
                            t.forEach(function (e) {
                                p = p.replace(e, "");
                            }),
                            (e.className = p),
                            e
                        );
                    },
                },
            },
            setup: function (e) {
                pdappAPI.tool.ruler.init({
                    container: document.querySelector(e),
                    rulerHeight: 20,
                    fontFamily: "arial",
                    fontSize: "10px",
                    strokeStyle: "white",
                    textColor: "white",
                    lineWidth: 1,
                    enableMouseTracking: !0,
                });
            },
            setPos: function (e) {
                pdappAPI.tool.ruler.update.setPos(e);
            },
            setScale: function (e, t) {
                pdappAPI.tool.ruler.update.setScale(e, t);
            },
            setShow: function (e) {
                pdappAPI.tool.ruler.update.toggleRulerVisibility(e);
            },
        },
        toTempPX: function (e) {
            return (
                void 0 !== e.size &&
                    void 0 !== e.size.unit &&
                    ((e.size.width = pdappAPI.tool.toPx(e.size.width, e.size.unit)),
                    (e.size.height = pdappAPI.tool.toPx(e.size.height, e.size.unit))),
                e
            );
        },
        getAutoZoom: function (e, t) {
            let p = parseFloat(e.size.width),
                a = parseFloat(e.size.height),
                o = jQuery("#pdapp-studio"),
                r = jQuery(".pdapp-temp-studio").width(),
                n = jQuery(".pdapp-temp-studio").height() - 43;
            o.width(r), o.height(n);
            let i = 12;
            t.width >= 992 && (i = 38);
            let l = parseFloat((r - i).toFixed(3)),
                d = parseFloat((o.height() - i).toFixed(3)),
                s = parseFloat(o.attr("data-width")),
                u = parseFloat(o.attr("data-height"));
            (0 != s && 0 != u) ||
                ((s = o.width() - (i + 2)),
                (u = o.height() - (i + 2)),
                o.attr("data-width", s),
                o.attr("data-height", u)),
                p / a > l / d
                    ? ("fit" == e.zoom &&
                          ((newSizeW = o.width() - (i + 2)), (e.zoom = Math.floor((newSizeW / s) * 100))),
                      (s = (s * e.zoom) / 100),
                      (e.ratio = s / p))
                    : ("fit" == e.zoom &&
                          ((newSizeH = o.height() - (i + 2)), (e.zoom = Math.floor((newSizeH / u) * 100))),
                      (u = (u * e.zoom) / 100),
                      (e.ratio = u / a));
            let c = p * e.ratio,
                f = a * e.ratio,
                g = t.width >= 992 ? { left: 26, top: 26 } : { left: 0, top: 0 };
            return (
                r > c && (g.left = (r - g.left - c) / 2 + g.left),
                n > f && (g.top = (n - g.top - f) / 2 + g.top),
                g.top < 0 && (g.top = 0),
                g.left < 0 && (g.left = 0),
                jQuery(".pdapp-ruler-tracker").css({ top: 0, left: 0 }),
                t.width >= 992 &&
                    !pdappAPI.tool.ruler.added &&
                    ((pdappAPI.tool.ruler.added = !0),
                    setTimeout(() => {
                        pdappAPI.tool.ruler.setup("#pdapp-viewer-area");
                    }, 3)),
                setTimeout(() => {
                    if (jQuery("#pdapp-viewer-area .pdapp-viewport").length) {
                        let a = jQuery("#pdapp-viewer-area");
                        (l = a.width()), (d = a.height()), c > l && (l = c + 26), f > d && (d = f + 26);
                        let o = Math.round((l - a.width()) / 2);
                        a.scrollLeft(o + 1);
                        let r = Math.round((d - a.height()) / 2);
                        if ((a.scrollTop(r + 1), t.width >= 992)) {
                            let t = g.top - 20,
                                n = g.left - 20,
                                i = parseFloat(p) * e.ratio;
                            c >= l && (n -= 2), f >= d && (t -= 2), pdappAPI.tool.ruler.setPos({ x: n, y: t });
                            let s = 1;
                            (s =
                                "cm" == e.type
                                    ? pdappAPI.tool.toCm(p, "px") / i
                                    : "in" == e.type
                                      ? pdappAPI.tool.toIn(p, "px") / i
                                      : p / i),
                                pdappAPI.tool.ruler.setScale(s, e.size.unit),
                                pdappAPI.tool.ruler.setShow(jQuery("#pdapp-rulerbar").hasClass("active")),
                                a.find(".pdapp-ruler-box").width(l),
                                jQuery(".pdapp-ruler.pdapp-ruler-vertical").css("left", o),
                                jQuery(".pdapp-ruler-corner.pdapp-ruler-cornerTOPLEFT").css("left", o + 1),
                                jQuery(jQuery("#pdapp-viewer-area .pdapp-ruler-tracker")[1]).css("left", o),
                                a.find(".pdapp-ruler-box").height(d),
                                jQuery(".pdapp-ruler.pdapp-ruler-horizontal").css("top", r),
                                jQuery(".pdapp-ruler-corner.pdapp-ruler-cornerTOPLEFT").css("top", r + 1),
                                jQuery(jQuery("#pdapp-viewer-area .pdapp-ruler-tracker")[0]).css("top", r);
                        }
                    }
                }, 5),
                (g.zoom = e.zoom),
                (g.ratio = e.ratio),
                g
            );
        },
        setScroll: function () {
            if (jQuery("#pdapp-viewer-area").hasClass("hasScroll")) return !1;
            jQuery("#pdapp-viewer-area").addClass("hasScroll"),
                jQuery("#pdapp-viewer-area").scroll(function () {
                    setTimeout(() => {
                        let e = jQuery(this).scrollTop(),
                            t = jQuery(this).scrollLeft();
                        jQuery(".pdapp-ruler.pdapp-ruler-horizontal").css("top", e),
                            jQuery(".pdapp-ruler-corner.pdapp-ruler-cornerTOPLEFT").css("top", e),
                            jQuery(jQuery("#pdapp-viewer-area .pdapp-ruler-tracker")[0]).css("top", e),
                            jQuery(".pdapp-ruler.pdapp-ruler-vertical").css("left", t),
                            jQuery(".pdapp-ruler-corner.pdapp-ruler-cornerTOPLEFT").css("left", t),
                            jQuery(jQuery("#pdapp-viewer-area .pdapp-ruler-tracker")[1]).css("left", t);
                    }, 1);
                });
        },
        updatePrintSize: function (e, t, p) {
            let a = p.size.unit,
                o = e.target.value;
            return (
                "unit" == t
                    ? ("px" == o
                          ? ((p.size.width = pdappAPI.tool.toPx(p.size.width, a)),
                            (p.size.height = pdappAPI.tool.toPx(p.size.height, a)))
                          : "cm" == o
                            ? ((p.size.width = pdappAPI.tool.toCm(p.size.width, a)),
                              (p.size.height = pdappAPI.tool.toCm(p.size.height, a)))
                            : ((p.size.width = pdappAPI.tool.toIn(p.size.width, a)),
                              (p.size.height = pdappAPI.tool.toIn(p.size.height, a))),
                      (p.size.unit = o))
                    : ((o = parseFloat(o)), "width" == t ? (p.size.width = o) : "height" == t && (p.size.height = o)),
                p
            );
        },
        responsiveLayout: function () {
            let e = {};
            return (
                (e.width = jQuery(".pdapp-add-template").width()),
                (e.height = jQuery(".pdapp-add-template").height()),
                (e.screenSize = "desktop"),
                (e.position = e.width >= e.height ? "hor" : "ver"),
                e.width < 768 || (e.width < 992 && "hor" == e.position)
                    ? (e.screenSize = "mobile")
                    : (e.width >= 992 || (e.width >= 768 && "ver" == e.position)) &&
                      e.width < 1400 &&
                      (e.screenSize = "tablet"),
                e
            );
        },
        responsiveDropdown: function (e, t) {
            let p = jQuery(".pdapp-menu-options")[0].getBoundingClientRect(),
                a = jQuery(".pdapp-" + e.type + "-type-" + e.dropdown),
                o = jQuery(".pdapp-menu-options-dropdown.pdapp-" + e.type + "-dropdown-" + e.dropdown);
            if (0 == a.length || 0 == o.length) return !1;
            let r = a[0].getBoundingClientRect();
            if (void 0 !== r.top) {
                o.find(".pdapp-dropdown-box").attr("style", "max-height: unset");
                let e = r.top - p.top + r.height + 5;
                e < 0 && (e = 0);
                let t = p.height - (e + 20);
                o.find(".pdapp-dropdown-box").height() > t ? o.addClass("show-scroll") : o.removeClass("show-scroll"),
                    o.find(".pdapp-dropdown-box").attr("style", "max-height: " + t + "px"),
                    o.attr("style", "top: " + e + "px;");
            }
            if (jQuery(".pdapp-menu-options .pdapp-menu-options-content").hasClass("hasScroll")) return !1;
            jQuery(".pdapp-menu-options .pdapp-menu-options-content").addClass("hasScroll"),
                jQuery(".pdapp-menu-options .pdapp-menu-options-content").scroll(function () {
                    let t = jQuery(".pdapp-menu-options")[0].getBoundingClientRect(),
                        p = jQuery(".pdapp-" + e.type + "-type-" + e.dropdown),
                        a = jQuery(".pdapp-menu-options-dropdown.pdapp-" + e.type + "-dropdown-" + e.dropdown);
                    if (0 == p.length || 0 == a.length) return !1;
                    let o = p[0].getBoundingClientRect();
                    if (void 0 !== o.top) {
                        a.find(".pdapp-dropdown-box").attr("style", "max-height: unset");
                        let e = o.top - t.top + o.height + 5;
                        e < 0 && (e = 0);
                        let p = t.height - (e + 20);
                        a.find(".pdapp-dropdown-box").height() > p
                            ? a.addClass("show-scroll")
                            : a.removeClass("show-scroll"),
                            a.find(".pdapp-dropdown-box").attr("style", "max-height: " + p + "px"),
                            a.attr("style", "top: " + e + "px;");
                    }
                });
        },
        toggleFullScreen: function (e) {
            let t =
                    (document.fullscreenElement && null !== document.fullscreenElement) ||
                    (document.webkitFullscreenElement && null !== document.webkitFullscreenElement) ||
                    (document.mozFullScreenElement && null !== document.mozFullScreenElement) ||
                    (document.msFullscreenElement && null !== document.msFullscreenElement),
                p = jQuery("#productdesignerapp-app")[0];
            t
                ? document.exitFullscreen
                    ? document.exitFullscreen()
                    : document.webkitExitFullscreen
                      ? document.webkitExitFullscreen()
                      : document.mozCancelFullScreen
                        ? document.mozCancelFullScreen()
                        : document.msExitFullscreen && document.msExitFullscreen()
                : p.requestFullscreen
                  ? p.requestFullscreen()
                  : p.webkitRequestFullscreen
                    ? p.webkitRequestFullscreen()
                    : p.msRequestFullscreen && p.msRequestFullscreen(),
                "function" == typeof e && e(!t);
        },
        previewScreen: function (e, t, p) {
            let a = jQuery("#pdapp-viewer-area .pdapp-viewport"),
                o = a.width(),
                r = a.height(),
                n =
                    '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
                    o +
                    '" height="' +
                    r +
                    '" x="0" y="0">',
                i = a.find(".pdapp-viewport-area"),
                l = [];
            (void 0 === i.find("g.pdapp-target.pdapp-svg-photo") &&
                void 0 === i.find("g.pdapp-target.pdapp-svg-artwork")) ||
                i.find("g.pdapp-target.pdapp-svg-photo, g.pdapp-target.pdapp-svg-artwork").each(function () {
                    let t = jQuery(this);
                    if (0 == t.hasClass(".pdapp-svg")) {
                        let p = t.attr("id");
                        if (void 0 !== e[p] && void 0 !== e[e[p].id]) {
                            let a =
                                "" != e[p].crop && void 0 !== e[p].crop.base64 ? e[p].crop.base64 : e[e[p].id].base64;
                            l.push({ blob: t.find("image").attr("xlink:href"), base64: a });
                        }
                    }
                });
            let d = i.find("svg.pdapp-selecto-area")[0].outerHTML;
            for (let e = 0; e < l.length; e++) d = d.replaceAll(l[e].blob, l[e].base64);
            (n +=
                '<g transform="translate(0, 0)">' +
                ('<image x="0" y="0" width="' +
                    o +
                    '" height="' +
                    r +
                    '" xlink:href="' +
                    ("data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(d)) +
                    '"></image>') +
                "</g>"),
                (n += "</svg>");
            let s = document.createElement("canvas"),
                u = s.getContext("2d"),
                c = document.createElement("img");
            (c.crossOrigin = "anonymous"),
                (c.onload = function () {
                    let e = c.width,
                        a = c.height;
                    c.width > c.height
                        ? ((e = 1e3), (a = (1e3 * c.height) / c.width))
                        : ((a = 1e3), (e = (1e3 * c.width) / c.height)),
                        (s.width = e),
                        (s.height = a),
                        u.drawImage(c, 0, 0, e, a),
                        void 0 === p
                            ? s.toBlob(function (e) {
                                  (e = URL.createObjectURL(e)), "function" == typeof t && t(e);
                              }, "image/png")
                            : "function" == typeof t && t(s.toDataURL("image/png")),
                        c.remove(),
                        s.remove();
                }),
                (c.src = -1 == n.indexOf("<svg") ? n : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(n));
        },
        checkDesign: function () {
            let e = !1;
            return (
                "" != jQuery("#pdapp-viewer-area svg.pdapp-selecto-area").find("g.pdapp-target").length && (e = !0), e
            );
        },
        resetDesign: function () {
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                jQuery("#pdapp-viewer-area svg.pdapp-selecto-area").html("");
        },
        changeOptionVisibles: function (e, t) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == p || 0 == p.length) return !1;
            let a = [],
                o = jQuery(p);
            for (let p = 0; p < e.length; p++) 1 == e[p] && void 0 !== t[p] && a.push(t[p]);
            this.setHideOptions(a), o.attr("data-hide-options", a.join(","));
        },
        setHideOptions: function (e) {
            e.includes("size")
                ? ((pdappAPI.tool.pdappMoveAbleRef.scalable = !1),
                  (pdappAPI.tool.pdappMoveAbleRef.renderDirections = []))
                : ((pdappAPI.tool.pdappMoveAbleRef.scalable = !0),
                  (pdappAPI.tool.pdappMoveAbleRef.renderDirections = ["nw", "n", "ne", "w", "e", "sw", "s", "se"])),
                e.includes("move")
                    ? (pdappAPI.tool.pdappMoveAbleRef.draggable = !1)
                    : (pdappAPI.tool.pdappMoveAbleRef.draggable = !0),
                e.includes("rotate")
                    ? (pdappAPI.tool.pdappMoveAbleRef.rotatable = !1)
                    : (pdappAPI.tool.pdappMoveAbleRef.rotatable = !0);
        },
    },
    download: {
        renderDesigns: function (e, t) {
            let p = "",
                a = [],
                o = jQuery("#pdapp-viewer-area .pdapp-viewport");
            o.find("g.pdapp-target").length &&
                ((void 0 === o.find("g.pdapp-target.pdapp-svg-photo") &&
                    void 0 === o.find("g.pdapp-target.pdapp-svg-artwork")) ||
                    o.find("g.pdapp-target.pdapp-svg-photo, g.pdapp-target.pdapp-svg-artwork").each(function () {
                        let t = jQuery(this);
                        if (0 == t.hasClass(".pdapp-svg")) {
                            let p = t.attr("id");
                            if (void 0 !== e[p] && void 0 !== e[e[p].id] && void 0 !== e[e[p].id].blob) {
                                let o = t.find("image").attr("xlink:href"),
                                    r = e[e[p].id].base64;
                                void 0 !== e[e[p].id].origBase64 && (r = e[e[p].id].origBase64),
                                    "" != e[p].crop &&
                                        (void 0 !== e[p].crop.origBase64
                                            ? (r = e[p].crop.origBase64)
                                            : void 0 !== e[p].crop.base64 && (r = e[p].crop.base64)),
                                    a.push({ blob: o, base64: r });
                            }
                        }
                    }),
                (p = o.find("svg.pdapp-selecto-area")[0].outerHTML));
            for (let e = 0; e < a.length; e++) p = p.replaceAll(a[e].blob, a[e].base64);
            "" != p && (p = "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(p)),
                "function" == typeof t && t(p);
        },
        loadDesignImg: function (e, t, p, a, o) {
            pdappAPI.download.renderCanvas({ svg: e, vid: t, aid: p, type: a }, o);
        },
        canvasStack: [],
        renderCanvas: function (e, t) {
            if ("" !== e && (pdappAPI.download.canvasStack.push(e), pdappAPI.download.canvasStack.length > 1))
                return !1;
            let p = pdappAPI.download.canvasStack[0],
                a = "pdapp-download-" + p.vid + "-" + p.aid,
                o = document.createElement("canvas"),
                r = o.getContext("2d"),
                n = document.createElement("img");
            (n.crossOrigin = "anonymous"),
                (n.onload = function () {
                    (o.width = n.width),
                        (o.height = n.height),
                        r.drawImage(n, 0, 0),
                        jQuery("#" + a).html(o),
                        "function" == typeof t && t(p.type, p.vid, p.aid),
                        setTimeout(() => {
                            pdappAPI.download.canvasStack.splice(0, 1),
                                pdappAPI.download.canvasStack.length > 0 &&
                                    setTimeout(() => {
                                        pdappAPI.download.renderCanvas("", t);
                                    }, 1);
                        }, 10),
                        n.remove(),
                        o.remove();
                }),
                (n.src =
                    -1 == p.svg.indexOf("<svg")
                        ? p.svg
                        : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(p.svg));
        },
        downloadDesign: function (e, t, p, a, o) {
            let r = e.view + "-" + e.area,
                n =
                    -1 == e.svg.indexOf("<svg")
                        ? e.svg
                        : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(e.svg);
            if ("svg" == t) pdappAPI.download.downloadFile(n, r, t, {}, a);
            else {
                if (void 0 !== o && 0 != o.length) {
                    let e = o[0].toDataURL("image/png"),
                        n = { w: o[0].width, h: o[0].height, unit: p };
                    return pdappAPI.download.downloadFile(e, r, t, n, a), !1;
                }
                pdappAPI.tool.imgToBase64(n, function (e, o, n) {
                    pdappAPI.download.downloadFile(e, r, t, { w: o, h: n, unit: p }, a);
                });
            }
        },
        downloadFile: function (e) {
            let t = document.createElement("a");
            (t.download = "design.pda"), (t.href = e), t.click(), t.remove();
        },
    },
    design: {
        thumb: function (e, t, p, a) {
            let o = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                r =
                    '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
                    t.width() / o +
                    '" height="' +
                    t.height() / o +
                    '" x="0" y="0">';
            t.find(".pdapp-background-img").each(function () {
                let e =
                    '<image preserveAspectRatio="none" x="' +
                    parseFloat(jQuery(this).css("left").replace("px", "")) / o +
                    '" y="' +
                    parseFloat(jQuery(this).css("top").replace("px", "")) / o +
                    '" width="' +
                    jQuery(this).width() +
                    '" height="' +
                    jQuery(this).height() +
                    '" xlink:href="' +
                    jQuery(this).find("img.pdapp-product-img").attr("src") +
                    '"></image>';
                r += e;
            }),
                t.find(".pdapp-viewport-area").each(function () {
                    let t = parseFloat(jQuery(this).css("top").replace("px", "")),
                        p = parseFloat(jQuery(this).css("left").replace("px", "")),
                        a = jQuery(this).width(),
                        n = jQuery(this).height(),
                        i = [];
                    (void 0 === jQuery(this).find("g.pdapp-target.pdapp-svg-photo") &&
                        void 0 === jQuery(this).find("g.pdapp-target.pdapp-svg-artwork")) ||
                        jQuery(this)
                            .find("g.pdapp-target.pdapp-svg-photo, g.pdapp-target.pdapp-svg-artwork")
                            .each(function () {
                                if (0 == jQuery(this).hasClass(".pdapp-svg")) {
                                    let t = jQuery(this).attr("id");
                                    if (void 0 !== e[t] && void 0 !== e[e[t].id]) {
                                        let p =
                                            "" != e[t].crop && void 0 !== e[t].crop.base64
                                                ? e[t].crop.base64
                                                : e[e[t].id].base64;
                                        i.push({ blob: jQuery(this).find("image").attr("xlink:href"), base64: p });
                                    }
                                }
                            });
                    let l = jQuery(this).find("svg.pdapp-selecto-area")[0].outerHTML;
                    for (let e = 0; e < i.length; e++) l = l.replaceAll(i[e].blob, i[e].base64);
                    if (jQuery(this).find("img.pdapp-area-mask-img").length) {
                        let e =
                            '<image preserveAspectRatio="none" class="pdapp-area-mask-img" x="0" y="0" width="100%" height="100%" xlink:href="' +
                            jQuery(this).find("img.pdapp-area-mask-img").attr("src") +
                            '"></image></svg>';
                        l = l.replace("</svg>", e);
                    }
                    let d =
                            '<image x="0" y="0" width="' +
                            a +
                            '" height="' +
                            n +
                            '" xlink:href="' +
                            ("data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(l)) +
                            '"></image>',
                        s =
                            '<g transform="translate(' +
                            (p / o).toFixed(3) +
                            ", " +
                            (t / o).toFixed(3) +
                            ')">' +
                            d +
                            "</g>";
                    r += s;
                }),
                (r += "</svg>");
            let n = document.createElement("canvas"),
                i = n.getContext("2d"),
                l = document.createElement("img");
            (l.crossOrigin = "anonymous"),
                (l.onload = function () {
                    let e = l.width,
                        t = l.height;
                    (l.width > 800 || l.height > 800) &&
                        (l.width > l.height
                            ? ((e = 800), (t = (800 * l.height) / l.width))
                            : ((t = 800), (e = (800 * l.width) / l.height))),
                        (n.width = e),
                        (n.height = t),
                        i.drawImage(l, 0, 0, e, t),
                        "function" == typeof p && p(n.toDataURL("image/png"), a),
                        l.remove(),
                        n.remove();
                }),
                (l.src = -1 == r.indexOf("<svg") ? r : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(r));
        },
        import: function (e, t, p, a) {
            let o = new DOMParser().parseFromString(t, "image/svg+xml");
            jQuery(o.documentElement)
                .find("g.pdapp-target")
                .each(function () {
                    let e = "pdapp-target-" + pdappAPI.tool.uID(),
                        t = jQuery(this);
                    t.attr("id", e), void 0 !== a && t.attr("data-tempid", a);
                }),
                e.find(".pdapp-selecto-area").remove(),
                e[0].appendChild(o.documentElement);
            let r = e.find("svg.pdapp-selecto-area").width(),
                n = e.find("svg.pdapp-selecto-area").height(),
                i = p.width,
                l = p.height;
            e.find("svg.pdapp-selecto-area").attr("width", i),
                e.find("svg.pdapp-selecto-area").attr("height", l),
                e
                    .find("svg.pdapp-selecto-area")
                    .find("g.pdapp-target")
                    .each(function () {
                        let t = jQuery(this),
                            p = t.attr("id"),
                            a = pdappAPI.tool.getTransform(t);
                        if ("" != a) {
                            let e = a.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                            if (6 == e.length) {
                                let t = i / r,
                                    p = l / n,
                                    a = t;
                                i / l > 1
                                    ? ((a = p),
                                      (e[4] = (
                                          parseFloat(e[4]) * p +
                                          (parseFloat(e[4]) * t - parseFloat(e[4]) * p)
                                      ).toFixed(3)),
                                      (e[5] = (parseFloat(e[5]) * a).toFixed(3)))
                                    : ((e[4] = (parseFloat(e[4]) * a).toFixed(3)),
                                      (e[5] = (
                                          parseFloat(e[5]) * t +
                                          (parseFloat(e[4]) * p - parseFloat(e[4]) * t)
                                      ).toFixed(3))),
                                    (e[0] = (parseFloat(e[0]) * a).toFixed(3)),
                                    (e[3] = e[0]);
                            }
                            t.attr("transform", "matrix(" + e.join(", ") + ")");
                        }
                        if (t.hasClass("pdapp-arc")) {
                            let o = t.find("text").attr("font-size"),
                                r = t.find("text").attr("font-family");
                            if (void 0 !== a && "none" != a) {
                                let e = a.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                                if (6 == e.length) {
                                    let t = parseFloat(e[0]);
                                    1 != t && (o = Math.round(parseFloat(o) * t));
                                }
                            }
                            let n = t.attr("data-text").replaceAll(" ", "&nbsp;"),
                                i = document.createElement("div");
                            i.setAttribute(
                                "style",
                                "position:absolute;top:0px;left:0px;width:100%;height:100%;font-size:" +
                                    o +
                                    "px;font-family:" +
                                    r +
                                    ";"
                            ),
                                i.setAttribute("class", "pdapp-arc-elm " + p),
                                (i.innerHTML = n),
                                e.find(".pdapp-text-arc")[0].append(i);
                            let l = t.attr("data-radius"),
                                d = new CircleType(i);
                            0 != l && d.radius(l),
                                t.hasClass("pdapp-dir") && d.dir(-1),
                                (pdappAPI.text.arc.pdappCircleType[p] = d);
                        }
                    });
        },
    },
    history: {
        getTextArc: function (e) {
            return "";
        },
        getTextSize: function (e) {
            return e.find("text").attr("font-size");
        },
        getFormatText: function (e, t, p) {
            return { res: { key: "", value: "", arc: "" }, svg: "" };
        },
        getTextStyle: function (e) {
            return { type: e, value: "", arc: "", svg: "" };
        },
        getIndex: function (e) {
            return 0;
        },
        createText: function (e) {
            return !1;
        },
        deleteText: function (e) {
            return !1;
        },
        updateText: function (e) {
            return !1;
        },
        changeFont: function (e) {
            return !1;
        },
        textSize: function (e) {
            return !1;
        },
        formatText: function (e) {
            return !1;
        },
        updateTextStyle: function (e) {
            return !1;
        },
        updateTransform: function (e) {
            return !1;
        },
        textGradient: function (e) {
            return !1;
        },
        lockText: function (e) {
            return !1;
        },
        flipText: function (e) {
            return !1;
        },
        createPhoto: function (e) {
            return !1;
        },
        deletePhoto: function (e) {
            return !1;
        },
        cropPhoto: function (e) {
            return !1;
        },
        replacePhoto: function (e) {
            return !1;
        },
        transformPhoto: function (e) {
            return !1;
        },
        opacity: function (e) {
            return !1;
        },
        addShape: function (e) {
            return !1;
        },
        addFilter: function (e) {
            return !1;
        },
        lockPhoto: function (e) {
            return !1;
        },
        flipPhoto: function (e) {
            return !1;
        },
        updateQr: function (e) {
            return !1;
        },
        updateColor: function (e) {
            return !1;
        },
        createGroup: function (e) {
            return !1;
        },
        setGroup: function (e) {
            return !1;
        },
        moveGroup: function (e) {
            return !1;
        },
        removeGroup: function (e) {
            return !1;
        },
    },
    hotkeys: {
        init: function (e) {
            return !1;
        },
    },
};