/**
* PDA v1.1.2
* (c) 2024 Product Designer App
* @license GPLv3
* Default theme
* Free version
* Unminify code for Dev
**/
var pdappAPI = {
    text: {
        createText: function (e) {
            let t = document.createElementNS("http://www.w3.org/2000/svg", "text"),
                a = {};
            return (
                (a.stroke = e.stroke),
                (a["stroke-width"] = e.strokeWidth),
                (a["font-weight"] = e.fontWeight),
                (a["font-style"] = e.fontStyle),
                (a["text-decoration"] = e.textDecoration),
                (a["stroke-linecap"] = "round"),
                (a["stroke-linejoin"] = "round"),
                (a["text-anchor"] = "start"),
                (a["font-size"] = e.fontSize),
                (a["font-family"] = e.fontFamily),
                pdappAPI.tool.generalAttr(a, t)
            );
        },
        createG: function (e, t, a) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                r = {};
            return (
                (r.id = e),
                (r.class = a),
                (r.style = "transform: translate(0, 0) rotate(0deg)"),
                (r["data-text"] = t.text),
                (r.fill = t.color),
                pdappAPI.tool.generalAttr(r, p)
            );
        },
        create: function (e, t) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"),
                p = {
                    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 p) "thumb" != t && void 0 !== e[t] && (p[t] = e[t]);
            if (void 0 === p.arc.radius) {
                let e = "pdapp-target-" + pdappAPI.tool.uID(),
                    r = pdappAPI.text.createText(p);
                r.innerHTML = "none" == p.textTransform ? p.text : p.text.toUpperCase();
                let o = pdappAPI.text.createG(e, p, "pdapp-target pdapp-svg-text");
                o.appendChild(r),
                    a.append(o),
                    pdappAPI.layer.afterAdded(e, function () {
                        let a = jQuery("#" + e);
                        (p = pdappAPI.text.autoSetSize(a, p)),
                            pdappAPI.layer.select(a),
                            "function" == typeof t && t(a, p);
                    });
            } else this.arc.create(p, t);
        },
        autoSetSize: function (e, t) {
            let a = jQuery(
                    ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                )[0].getBoundingClientRect(),
                p = e[0].getBoundingClientRect();
            if (0 == a.width || 0 == p.width) return t;
            if (a.width - (p.width + 15) < 0 || a.height - (p.height + 15) < 0) {
                let r = 1;
                r = a.width / p.width > a.height / p.height ? (a.height - 30) / p.height : (a.width - 30) / p.width;
                let o = pdappAPI.tool.getTransform(e);
                if ("" != o) {
                    let a = o.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                    6 == a.length && ((a[0] = parseFloat(a[0]) * r), (a[3] = a[0])),
                        e.attr("transform", "matrix(" + a.join(", ") + ")"),
                        setTimeout(() => {
                            pdappAPI.tool.centerAll(e);
                        }),
                        (t.fontSize = t.fontSize * r);
                }
            }
            return t;
        },
        arc: {
            pdappCircleType: {},
            create: function (e, t) {
                let a = this,
                    p = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active");
                if (0 == p.find(".pdapp-text-arc").length) return !1;
                let r = "pdapp-target-" + pdappAPI.tool.uID(),
                    o = e.text.replaceAll(" ", "&nbsp;"),
                    i = document.createElement("div");
                i.setAttribute(
                    "style",
                    "position:absolute;top:0px;left:0px;width:100%;height:100%;font-size:" +
                        e.fontSize +
                        "px;font-family:" +
                        e.fontFamily +
                        ";"
                ),
                    i.setAttribute("class", "pdapp-arc-elm " + r),
                    (i.innerHTML = o),
                    p.find(".pdapp-text-arc")[0].append(i);
                let n = new CircleType(i);
                0 != e.arc.radius && n.radius(e.arc.radius),
                    -1 == e.arc.dir && n.dir(e.arc.dir),
                    setTimeout(() => {
                        (a.pdappCircleType[r] = n),
                            setTimeout(() => {
                                let o = "pdapp-target pdapp-svg-text pdapp-arc";
                                -1 == e.arc.dir && (o += " pdapp-dir");
                                let n = !0,
                                    l = pdappAPI.text.createG(r, e, o);
                                l.setAttribute("data-radius", e.arc.radius),
                                    jQuery(i)
                                        .find("span")
                                        .each(function () {
                                            let t = jQuery(this).html();
                                            t = t.replace("&nbsp;", "").replace("&amp;", "");
                                            let a = pdappAPI.tool.getTransform(jQuery(this));
                                            if ("" == a) n = !1;
                                            else {
                                                let p = jQuery(this).css("transform-origin"),
                                                    r = document.createElementNS("http://www.w3.org/2000/svg", "g");
                                                r.setAttribute(
                                                    "style",
                                                    "transform:" + a + ";transform-origin:" + p + ";"
                                                ),
                                                    (r.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(r);
                                            }
                                        }),
                                    n
                                        ? (p.find("svg.pdapp-selecto-area").append(l),
                                          pdappAPI.layer.afterAdded(r, function () {
                                              let p = jQuery("#" + r);
                                              (e = pdappAPI.text.autoSetSize(p, e)),
                                                  pdappAPI.layer.select(p),
                                                  "function" == typeof t && t(p, e),
                                                  a.convertTransform("#" + r + " g");
                                          }))
                                        : setTimeout(() => {
                                              let n = pdappAPI.text.createG(r, e, o);
                                              n.setAttribute("data-radius", e.arc.radius),
                                                  jQuery(i)
                                                      .find("span")
                                                      .each(function () {
                                                          let t = jQuery(this).html();
                                                          t = t.replace("&nbsp;", "").replace("&amp;", "");
                                                          let a = pdappAPI.tool.getTransform(jQuery(this)),
                                                              p = jQuery(this).css("transform-origin"),
                                                              r = document.createElementNS(
                                                                  "http://www.w3.org/2000/svg",
                                                                  "g"
                                                              );
                                                          r.setAttribute(
                                                              "style",
                                                              "transform:" + a + ";transform-origin:" + p + ";"
                                                          ),
                                                              (r.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>"),
                                                              n.appendChild(r);
                                                      }),
                                                  p.find("svg.pdapp-selecto-area").append(n),
                                                  pdappAPI.layer.afterAdded(r, function () {
                                                      let p = jQuery("#" + r);
                                                      (e = pdappAPI.text.autoSetSize(p, e)),
                                                          pdappAPI.layer.select(p),
                                                          "function" == typeof t && t(p, e),
                                                          a.convertTransform("#" + r + " g");
                                                  });
                                          }, 50);
                            }, 1);
                    }, 5);
            },
            update: function (e, t, a, p = !1) {
                let r = this,
                    o = jQuery(t),
                    i = o.attr("id"),
                    n = jQuery(".pdapp-viewport .pdapp-text-arc ." + i),
                    l = void 0 === o.attr("data-radius") ? 0 : o.attr("data-radius");
                if (void 0 !== pdappAPI.text.arc.pdappCircleType[i] && 0 == p)
                    pdappAPI.text.arc.pdappCircleType[i].radius(l);
                else {
                    let t = e.replaceAll(" ", "&nbsp;");
                    n.html(t),
                        (pdappAPI.text.arc.pdappCircleType[i] = new CircleType(n[0]).radius(l)),
                        o.hasClass("pdapp-dir") && pdappAPI.text.arc.pdappCircleType[i].dir(-1);
                }
                setTimeout(() => {
                    o = jQuery(t);
                    let e = "",
                        p = "",
                        l = o.find("text").prop("attributes");
                    jQuery.each(l, function () {
                        "style" != this.name &&
                            "font-style" != this.name &&
                            "font-weight" != this.name &&
                            (p += this.name + '="' + this.value + '" ');
                    }),
                        (p += 'font-style="' + n.css("font-style") + '" font-weight="' + n.css("font-weight") + '"');
                    let d = !0;
                    n.find("span").each(function () {
                        let t = jQuery(this).html();
                        t = t.replace("&nbsp;", "").replace("&amp;", "");
                        let a = pdappAPI.tool.getTransform(jQuery(this));
                        "" == a && (d = !1);
                        let r = jQuery(this).css("transform-origin");
                        e +=
                            '<g style="transform:' +
                            a +
                            ";transform-origin:" +
                            r +
                            ';"><text ' +
                            p +
                            ">" +
                            t +
                            "</text></g>";
                    }),
                        "" != e &&
                            (d
                                ? (o.html(e),
                                  "function" == typeof a && a(i),
                                  (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                  setTimeout(() => {
                                      (pdappAPI.tool.pdappMoveAbleRef.target = t), r.convertTransform("#" + i + " g");
                                  }, 1))
                                : setTimeout(() => {
                                      let e = "";
                                      n.find("span").each(function () {
                                          let t = jQuery(this).html();
                                          t = t.replace("&nbsp;", "").replace("&amp;", "");
                                          let a = pdappAPI.tool.getTransform(jQuery(this)),
                                              r = jQuery(this).css("transform-origin");
                                          e +=
                                              '<g style="transform:' +
                                              a +
                                              ";transform-origin:" +
                                              r +
                                              ';"><text ' +
                                              p +
                                              ">" +
                                              t +
                                              "</text></g>";
                                      }),
                                          o.html(e),
                                          "function" == typeof a && a(i),
                                          (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                          setTimeout(() => {
                                              (pdappAPI.tool.pdappMoveAbleRef.target = t),
                                                  r.convertTransform("#" + i + " g");
                                          }, 1);
                                  }, 50));
                }, 5);
            },
            convertTransform: function (e) {
                SVGElement.prototype.getTransformToElement =
                    SVGElement.prototype.getTransformToElement ||
                    function (e) {
                        return e.getScreenCTM().inverse().multiply(this.getScreenCTM());
                    };
                let t = "",
                    a = jQuery(e);
                if (0 == a.length) return t;
                for (let e = 0; e < a.length; e++) {
                    let t = p(a[e]);
                    "" != t && (jQuery(a[e]).attr("transform", t), jQuery(a[e]).removeAttr("style"));
                }
                function p(e) {
                    let a = e.getTransformToElement(e.parentNode),
                        [p, r, o, i, n, l] = [a.a, a.b, a.c, a.d, a.e, a.f];
                    return (t = [p, r, o, i, n, l].map((e) => +e.toFixed(4)).join(" ")), (t = "matrix(" + t + ")"), t;
                }
            },
        },
        updateValue: function (e, t) {
            let a = jQuery(e),
                p = { type: "text" };
            (p.text = a.attr("data-text")),
                (p.stroke = a.find("text").attr("stroke")),
                (p.strokeWidth = Math.round(10 * parseFloat(a.find("text").attr("stroke-width")))),
                (p.fontWeight = a.find("text").attr("font-weight")),
                (p.fontSize = a.find("text").attr("font-size")),
                (p.fontFamily = a.find("text").attr("font-family")),
                (p.fontStyle = a.find("text").attr("font-style")),
                (p.textDecoration = a.find("text").attr("text-decoration")),
                (p.textTransform = a.hasClass("pdapp-uppercase") ? "uppercase" : "none"),
                (p.textLock = a.hasClass("pdapp-lock")),
                (p.textFlip = !1),
                (p.dropdown = ""),
                (p.transparency = 100 * a.css("opacity")),
                (p.letterSpacing = 0),
                (p.settings = []);
            let r = a.attr("data-hide-options");
            void 0 !== r && (p.settings = r.split(",")),
                void 0 !== a.attr("data-spacing")
                    ? (p.letterSpacing = a.attr("data-spacing"))
                    : void 0 !== a.css("letter-spacing") &&
                      (p.letterSpacing = a.css("letter-spacing").replace("px", ""));
            let o = pdappAPI.tool.getTransform(a);
            if ("" != o) {
                let e = o.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                if (6 == e.length) {
                    let t = parseFloat(e[0]);
                    1 != t && (p.fontSize = Math.round(p.fontSize * t));
                }
            }
            if (
                ((p.color = pdappAPI.tool.rgbToHex(a.attr("fill"))),
                (p.colorType = "normal"),
                0 === p.color.indexOf("url("))
            ) {
                let e = p.color.replace("url(#", "").replace(")", "").split("-");
                (p.color = "#" + e[e.length - 1]), (p.colorType = e[0]);
            }
            a.hasClass("pdapp-arc") && (p.radius = a.attr("data-radius")),
                a.hasClass("pdapp-flip") && (p.textFlip = !0),
                "function" == typeof t && t(p);
        },
        updateText: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == a || 0 == a.length) return !1;
            let p = jQuery(a);
            if (
                (p.attr("data-text", e),
                p.hasClass("pdapp-flip") && (e = pdappAPI.text.flipText(e)),
                p.hasClass("pdapp-arc"))
            )
                this.arc.update(e, a, t, !0);
            else {
                let r = [],
                    o = p[0].getBoundingClientRect();
                if (0 != o.width) {
                    let e = pdappAPI.tool.getTransform(p);
                    "" != e && (r = e.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                }
                p.find("text").text(e),
                    setTimeout(() => {
                        if (6 == r.length) {
                            let e = p[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let t = ((e.width - o.width) / 2).toFixed(3);
                                (t = parseFloat(t)),
                                    (r[4] = parseFloat(r[4]) - t),
                                    p.attr("transform", "matrix(" + r.join(", ") + ")");
                            }
                        }
                        "function" == typeof t && t(),
                            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = a;
                            }, 1);
                    }, 1);
            }
        },
        formatText: function (e, t, a) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                r = jQuery(p),
                o = { key: "fontWeight", value: "400" };
            switch (e) {
                case "bold":
                    if (
                        ((o.key = "fontWeight"),
                        "700" == t.fontWeight ? (o.value = "400") : (o.value = "700"),
                        r.hasClass("pdapp-arc"))
                    ) {
                        let e = r.attr("id");
                        jQuery(".pdapp-viewport.active .pdapp-text-arc ." + e).css("font-weight", o.value),
                            this.arc.update(
                                r.attr("data-text"),
                                p,
                                function () {
                                    "function" == typeof a && a(o.key, o.value);
                                },
                                "",
                                !0
                            );
                    } else r.find("text").attr("font-weight", o.value), "function" == typeof a && a(o.key, o.value);
                    break;
                case "italic":
                    if (
                        ((o.key = "fontStyle"),
                        "italic" == t.fontStyle ? (o.value = "normal") : (o.value = "italic"),
                        r.hasClass("pdapp-arc"))
                    ) {
                        let e = r.attr("id");
                        jQuery(".pdapp-viewport.active .pdapp-text-arc ." + e).css("font-style", o.value),
                            this.arc.update(
                                r.attr("data-text"),
                                p,
                                function () {
                                    "function" == typeof a && a(o.key, o.value);
                                },
                                !0
                            );
                    } else {
                        let e = [],
                            t = r[0].getBoundingClientRect();
                        if (0 != t.width) {
                            let t = pdappAPI.tool.getTransform(r);
                            "" != t && (e = t.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                        }
                        r.find("text").attr("font-style", o.value),
                            setTimeout(() => {
                                if (6 == e.length) {
                                    let a = r[0].getBoundingClientRect();
                                    if (0 != a.width) {
                                        let p = ((a.width - t.width) / 2).toFixed(3);
                                        (p = parseFloat(p)),
                                            (e[4] = parseFloat(e[4]) - p),
                                            r.attr("transform", "matrix(" + e.join(", ") + ")");
                                    }
                                }
                                "function" == typeof a && a(o.key, o.value);
                            }, 10);
                    }
                    break;
                case "underline":
                    (o.key = "textDecoration"),
                        "underline" == t.textDecoration ? (o.value = "none") : (o.value = "underline"),
                        r.find("text").attr("text-decoration", o.value),
                        "function" == typeof a && a(o.key, o.value);
                    break;
                case "through":
                    (o.key = "textDecoration"),
                        "line-through" == t.textDecoration ? (o.value = "none") : (o.value = "line-through"),
                        r.find("text").attr("text-decoration", o.value),
                        "function" == typeof a && a(o.key, o.value);
                    break;
                case "uppercase":
                    if (
                        ((o.key = "textTransform"),
                        "uppercase" == t.textTransform ? (o.value = "none") : (o.value = "uppercase"),
                        r.hasClass("pdapp-arc"))
                    ) {
                        let e = r.attr("id");
                        jQuery(".pdapp-viewport.active .pdapp-text-arc ." + e).css("text-transform", o.value),
                            this.arc.update(
                                r.attr("data-text"),
                                p,
                                function () {
                                    "function" == typeof a && a(o.key, o.value);
                                },
                                !0
                            ),
                            "uppercase" == o.value ? r.addClass("pdapp-uppercase") : r.removeClass("pdapp-uppercase");
                    } else {
                        let e = [],
                            p = r[0].getBoundingClientRect();
                        if (0 != p.width) {
                            let t = pdappAPI.tool.getTransform(r);
                            "" != t && (e = t.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                        }
                        "uppercase" == o.value
                            ? (r.find("text").text(t.text.toUpperCase()), r.addClass("pdapp-uppercase"))
                            : (r.find("text").text(t.text), r.removeClass("pdapp-uppercase")),
                            setTimeout(() => {
                                if (6 == e.length) {
                                    let t = r[0].getBoundingClientRect();
                                    if (0 != t.width) {
                                        let a = ((t.width - p.width) / 2).toFixed(3);
                                        (a = parseFloat(a)),
                                            (e[4] = parseFloat(e[4]) - a),
                                            r.attr("transform", "matrix(" + e.join(", ") + ")");
                                    }
                                }
                                "function" == typeof a && a(o.key, o.value),
                                    (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                    setTimeout(() => {
                                        pdappAPI.tool.pdappMoveAbleRef.target = r;
                                    }, 1);
                            }, 10);
                    }
            }
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = p;
                }, 1);
        },
        delete: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(t),
                p = a.attr("id");
            (pdappAPI.tool.pdappMoveAbleRef.target = null), a.remove();
            let r = jQuery(".pdapp-viewport.active .pdapp-text-arc ." + p);
            r.length && r.remove(), "function" == typeof e && e(p);
        },
        lock: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                e ? ((e = !1), p.removeClass("pdapp-lock")) : ((e = !0), p.addClass("pdapp-lock")),
                "function" == typeof t && t(e),
                pdappAPI.layer.select(a);
        },
        flipText: function (e) {
            let t = e.split("");
            return (t = t.reverse()), t.join("");
        },
        flip: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a),
                r = p.attr("data-text");
            e
                ? ((e = !1), p.removeClass("pdapp-flip"))
                : ((e = !0), p.addClass("pdapp-flip"), (r = pdappAPI.text.flipText(r))),
                p.hasClass("pdapp-arc")
                    ? this.arc.update(
                          r,
                          a,
                          function () {
                              "function" == typeof t && t(e);
                          },
                          !0
                      )
                    : (p.find("text").text(r), "function" == typeof t && t(e)),
                pdappAPI.layer.select(a);
        },
        copy: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let r = "pdapp-target-" + pdappAPI.tool.uID(),
                o = p.clone(),
                i = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active"),
                n = p.attr("id");
            if (
                (jQuery(o).attr("id", r),
                i.find("svg.pdapp-selecto-area").append(o),
                pdappAPI.layer.afterAdded(r),
                p.hasClass("pdapp-arc"))
            ) {
                let e = jQuery(".pdapp-viewport.active .pdapp-text-arc ." + n)[0].outerHTML;
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active .pdapp-text-arc").append(e.replace(n, r));
            }
            setTimeout(() => {
                let a = jQuery("#" + r);
                pdappAPI.layer.select(a),
                    "function" == typeof t && t(a),
                    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, a) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target,
                r = jQuery(p);
            if (null == p || 0 == p.length) return !1;
            switch (e) {
                case "color":
                    let e = { color: t, type: "" },
                        o = r.attr("data-gradient");
                    if (void 0 !== o && "" != o) {
                        let p = o.split("-");
                        this.gradient(p[0], t), (e.type = p[0]), "function" == typeof a && a(e);
                    } else
                        r.attr("fill", t),
                            void 0 !== r.find("text").attr("stroke-width") &&
                                0 == r.find("text").attr("stroke-width") &&
                                r.find("text").attr("stroke", t),
                            "function" == typeof a && a(e);
                    break;
                case "radius":
                    r.attr("id");
                    let i = r.attr("data-text");
                    r.attr("data-radius", t),
                        this.arc.update(i, p, function () {
                            "function" == typeof a && a(t);
                        });
                    break;
                case "letterSpacing":
                    if (((t = parseInt(t)), r.hasClass("pdapp-arc"))) {
                        let e = r.attr("id"),
                            o = r.attr("data-text");
                        jQuery(".pdapp-viewport.active .pdapp-text-arc ." + e).css("letter-spacing", t),
                            jQuery("#" + e).attr("data-spacing", t),
                            this.arc.update(
                                o,
                                p,
                                function () {
                                    "function" == typeof a && a(t);
                                },
                                !0
                            );
                    } else
                        r.attr("letter-spacing", t + "px"),
                            "function" == typeof a && a(t),
                            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = p;
                            }, 1);
                    break;
                case "outline":
                    r.find("text").attr("stroke", t.stroke),
                        r.find("text").attr("stroke-width", t.strokeWidth / 10),
                        "function" == typeof a && a(t);
                    break;
                case "transparency":
                    r.attr("opacity", t / 100), "function" == typeof a && a(t);
            }
        },
        alignText: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == t || 0 == t.length) return !1;
            let a = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool[e](a),
                (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 a = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool.move[e](a),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = t;
                }, 1);
        },
        gradient: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == a || 0 == a.length) return !1;
            t = pdappAPI.tool.rgbToHex(t);
            let p = jQuery(a),
                r = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"),
                o = r.find(".pdapp-defs");
            if (0 == o.length) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "defs");
                e.setAttributeNS(null, "class", "pdapp-defs"), r.prepend(e);
            }
            let i = "linearGradient";
            "radial" == e && (i = "radialGradient");
            let n = e + "-gradient-" + t.replace("#", ""),
                l = n,
                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 c = document.createElementNS("http://www.w3.org/2000/svg", "stop");
            c.setAttributeNS(null, "offset", "100%"),
                c.setAttributeNS(null, "stop-color", d.replace(")", ", 0)")),
                c.setAttributeNS(null, "stop-opacity", 1);
            let u = document.createElementNS("http://www.w3.org/2000/svg", i);
            u.setAttributeNS(null, "id", n),
                "hor" == e && u.setAttributeNS(null, "gradientTransform", "rotate(90)"),
                u.appendChild(s),
                u.appendChild(c),
                setTimeout(() => {
                    (r = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area")),
                        (o = r.find(".pdapp-defs")),
                        0 == o.find("#" + n).length && "normal" != e && o.append(u),
                        setTimeout(() => {
                            "normal" == e
                                ? ((l = p.attr("data-gradient")), p.attr("data-gradient", ""), p.attr("fill", t))
                                : ((l = p.attr("data-gradient")),
                                  p.attr("data-gradient", n),
                                  p.attr("fill", "url(#" + n + ")")),
                                "" != l &&
                                    0 ==
                                        jQuery(
                                            ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                                        ).find('[data-gradient="' + l + '"]').length &&
                                    o.find("#" + l).remove();
                        }, 1);
                }, 1);
        },
        setSize: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == a || 0 == a.length) return !1;
            let p = jQuery(a),
                r = [],
                o = p[0].getBoundingClientRect(),
                i = pdappAPI.tool.getTransform(p);
            if (
                "" != i &&
                ((r = i.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",")), 6 == r.length)
            ) {
                if (1 != parseFloat(r[0])) {
                    let e = 1 / parseFloat(r[0]);
                    (r[0] = 1), (r[3] = parseFloat(r[3]) * e), p.attr("transform", "matrix(" + r.join(", ") + ")");
                }
            }
            if (((pdappAPI.tool.pdappMoveAbleRef.target = null), p.hasClass("pdapp-arc"))) {
                let r = p.attr("id"),
                    o = p.attr("data-text");
                jQuery(".pdapp-viewport.active .pdapp-text-arc ." + r).css("font-size", e),
                    this.arc.update(o, a, t, !0),
                    setTimeout(() => {
                        jQuery("#" + r)
                            .find("text")
                            .attr("font-size", e),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = a;
                            }, 1);
                    }, 15);
            } else
                p.find("text").attr("font-size", e),
                    setTimeout(() => {
                        if (6 == r.length) {
                            let e = p[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let t = ((e.width - o.width) / 2).toFixed(3),
                                    a = ((e.height - o.height) / 2).toFixed(3);
                                (t = parseFloat(t)),
                                    (a = parseFloat(a)),
                                    (r[4] = parseFloat(r[4]) - t),
                                    (r[5] = parseFloat(r[5]) - a),
                                    p.attr("transform", "matrix(" + r.join(", ") + ")");
                            }
                        }
                        "function" == typeof t && t(),
                            setTimeout(() => {
                                pdappAPI.tool.pdappMoveAbleRef.target = a;
                            }, 1);
                    }, 10);
        },
        changeFont: function (e, t, a, p) {
            let r = [],
                o = p[0].getBoundingClientRect();
            if (0 != o.width) {
                let e = pdappAPI.tool.getTransform(p);
                "" != e && (r = e.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
            }
            p.find("text").attr("font-family", e);
            let i = p.attr("id");
            jQuery(".pdapp-text-arc ." + i).css("font-family", e),
                setTimeout(() => {
                    if (p.hasClass("pdapp-arc")) {
                        let e = p.attr("data-text");
                        this.arc.update(e, p[0], a, !0);
                    } else {
                        if (((pdappAPI.tool.pdappMoveAbleRef.target = null), 6 == r.length)) {
                            let e = p[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let t = ((e.width - o.width) / 2).toFixed(3);
                                (t = parseFloat(t)),
                                    (r[4] = parseFloat(r[4]) - t),
                                    p.attr("transform", "matrix(" + r.join(", ") + ")");
                            }
                        }
                        setTimeout(() => {
                            (pdappAPI.tool.pdappMoveAbleRef.target = p[0]), "function" == typeof a && a();
                        }, 1);
                    }
                }, t);
        },
    },
    artwork: {
        readImage: function (e, t) {
            if (void 0 === e.artFile) return "function" == typeof t && t(e), !1;
            let a = document.createElement("canvas"),
                p = a.getContext("2d"),
                r = document.createElement("img");
            (r.crossOrigin = "anonymous"),
                (r.onload = function () {
                    setTimeout(() => {
                        let o = new ColorThief().getPalette(r, 8, 50);
                        null == o && (o = [[255, 255, 255]]);
                        let i = [];
                        for (let e = 0; e < o.length; e++) {
                            let t = pdappAPI.tool.rgbToHex("rgb(" + o[e].join(", ") + ")");
                            !1 === i.includes(t) && i.push(t);
                        }
                        let n = i.join(","),
                            l = { width: r.width, height: r.height };
                        (a.width = l.width),
                            (a.height = l.height),
                            p.drawImage(r, 0, 0, l.width, l.height),
                            (l.base64 = e.artFile),
                            a.toBlob(function (e) {
                                (l.blob = URL.createObjectURL(e)), (l.color = n), "function" == typeof t && t(l);
                            }, "image/png"),
                            r.remove(),
                            a.remove();
                    }, 100);
                }),
                (r.src = e.artFile);
        },
        createImage: function (e, t) {
            let a = document.createElementNS("http://www.w3.org/2000/svg", "image"),
                p = {};
            (p.width = e.width),
                (p.height = e.height),
                (p.x = 0),
                (p.y = 0),
                (p.class = "pdapp-img"),
                (a = pdappAPI.tool.generalAttr(p, a));
            let r = void 0 !== e.blob ? e.blob : e.base64;
            a.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", r), "function" == typeof t && t(a);
        },
        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 a = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                p = {};
            return (
                (p.id = e),
                (p.class = t),
                (p.style = "transform: translate(0, 0) rotate(0deg)"),
                pdappAPI.tool.generalAttr(p, a)
            );
        },
        create: function (e, t, a, p) {
            (pdappAPI.tool.pdappMoveAbleRef.target = null), void 0 === p && (p = "pdapp-target-" + pdappAPI.tool.uID());
            let r = this;
            if ("svg" == t) {
                let t = r.createSvg(e),
                    o = pdappAPI.photo.createG(p, "pdapp-target pdapp-svg pdapp-svg-artwork");
                o.appendChild(t);
                let i =
                    '<svg x="0" y="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                    o.outerHTML +
                    "</svg>";
                getSVGColors(i, { flat: !0 }).then((e) => {
                    let t = e.join(",");
                    o.setAttribute("data-color", t),
                        jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").append(o),
                        pdappAPI.layer.afterAdded(p),
                        setTimeout(() => {
                            let e = jQuery("#" + p);
                            pdappAPI.layer.select(e),
                                "function" == typeof a && a(e),
                                pdappAPI.tool.standardArtworkToAi(e);
                        }, 1);
                });
            } else
                r.readImage(e, function (e) {
                    r.createImage(e, function (t) {
                        let r = pdappAPI.photo.createG(p, "pdapp-target pdapp-photo pdapp-svg-artwork");
                        r.appendChild(t), r.setAttribute("data-color", e.color);
                        let o = document.createElementNS("http://www.w3.org/2000/svg", "g");
                        o.setAttribute("class", "pdapp-g-photo"),
                            o.appendChild(r),
                            jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").append(
                                o
                            ),
                            pdappAPI.layer.afterAdded(p),
                            setTimeout(() => {
                                let t = jQuery("#" + p);
                                pdappAPI.layer.select(t), "function" == typeof a && a(t, e);
                            }, 1);
                    });
                });
        },
        copy: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let r = "pdapp-target-" + pdappAPI.tool.uID(),
                o = a.clone(),
                i = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active"),
                n = p.attr("id");
            jQuery(o).attr("id", r);
            let l = jQuery(o).find("#" + n + "-shape");
            0 != l.length && (l.attr("id", r + "-shape"), jQuery(o).attr("clip-path", "url(#" + r + "-shape)"));
            let d = jQuery(o).find("#" + n + "-filter");
            if ((0 != d.length && d.attr("id", r + "-filter"), p.hasClass("pdapp-photo"))) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "g");
                0 != d.length && (e.style.filter = "url(#" + r + "-filter)"),
                    e.append(o[0]),
                    i.find("svg.pdapp-selecto-area").append(e);
            } else i.find("svg.pdapp-selecto-area").append(o);
            pdappAPI.layer.afterAdded(r),
                setTimeout(() => {
                    let a = jQuery("#" + r);
                    pdappAPI.layer.select(a),
                        "function" == typeof t && t(a),
                        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 a = jQuery(e),
                p = { type: "artwork" };
            (p.photoLock = a.hasClass("pdapp-lock")),
                (p.editColor = a.hasClass("pdapp-svg")),
                (p.colors = []),
                (p.photoFlip = !1),
                (p.transparency = 100 * a.css("opacity")),
                (p.dropdown = ""),
                (p.photo = p.editColor ? "" : a.find("image").attr("xlink:href")),
                (p.settings = []);
            let r = a.attr("data-hide-options");
            void 0 !== r && (p.settings = r.split(",")),
                a.hasClass("pdapp-flip") && (p.photoFlip = !0),
                "function" == typeof t && t(p);
        },
    },
    photo: {
        readPhoto: function (e, t) {
            let a = document.createElement("img");
            (a.crossOrigin = "anonymous"),
                (a.onload = function () {
                    setTimeout(() => {
                        let p = new ColorThief().getPalette(a, 8, 50);
                        null == p && (p = [[255, 255, 255]]);
                        let r = [];
                        for (let e = 0; e < p.length; e++) {
                            let t = pdappAPI.tool.rgbToHex("rgb(" + p[e].join(", ") + ")");
                            !1 === r.includes(t) && r.push(t);
                        }
                        (e.color = r.join(",")),
                            (e.width = Math.round(a.width)),
                            (e.height = Math.round(a.height)),
                            "function" == typeof t && t(e);
                    }, 100);
                }),
                (a.src = e.blob);
        },
        readMediumImage: function (e, t, a) {
            let p = {},
                r = document.createElement("canvas"),
                o = r.getContext("2d"),
                i = document.createElement("img");
            function n() {
                if (p.width > 1920) {
                    let e = 1920;
                    p.width > 3840 && (e = p.width / 2), (p.height = e * (i.height / i.width)), (p.width = e);
                }
                (r.width = p.width),
                    (r.height = p.height),
                    o.drawImage(i, 0, 0, i.width, i.height, 0, 0, p.width, p.height),
                    p.width > 1920
                        ? ((i = r),
                          (r = document.createElement("canvas")),
                          (o = r.getContext("2d")),
                          requestAnimationFrame(n))
                        : ((p.base64 = r.toDataURL("image/png", a)),
                          r.toBlob(
                              function (e) {
                                  (p.blob = URL.createObjectURL(e)), "function" == typeof t && t(p);
                              },
                              "image/png",
                              a
                          ),
                          cancelAnimationFrame(n),
                          i.remove(),
                          r.remove());
            }
            (i.crossOrigin = "anonymous"),
                (i.onload = function () {
                    setTimeout(() => {
                        let e = new ColorThief().getPalette(i, 8, 50);
                        null == e && (e = [[255, 255, 255]]);
                        let t = [];
                        for (let a = 0; a < e.length; a++) {
                            let p = pdappAPI.tool.rgbToHex("rgb(" + e[a].join(", ") + ")");
                            !1 === t.includes(p) && t.push(p);
                        }
                        (p.color = t.join(",")),
                            (p.width = Math.round(i.width)),
                            (p.height = Math.round(i.height)),
                            n();
                    }, 10);
                }),
                (i.src = "string" == typeof e ? e : URL.createObjectURL(e));
        },
        cropImage: function (e, t, a) {
            let p = document.createElement("canvas"),
                r = p.getContext("2d"),
                o = document.createElement("img");
            (o.crossOrigin = "anonymous"),
                (o.onload = function () {
                    setTimeout(() => {
                        (p.width = t.width),
                            (p.height = t.height),
                            r.drawImage(o, t.left, t.top, t.width, t.height, 0, 0, t.width, t.height),
                            (t.base64 = p.toDataURL("image/png")),
                            p.toBlob(function (e) {
                                (t.blob = URL.createObjectURL(e)), "function" == typeof a && a(t);
                            }),
                            o.remove(),
                            p.remove();
                    }, 100);
                }),
                (o.src = e);
        },
        getPhotos: function (e, t, a) {
            void 0 !== this[e.library] && this[e.library](e, t, a);
        },
        unsplash: async function (e, t, a) {
            "function" == typeof a && a([]);
        },
        pexels: async function (e, t, a) {
            "function" == typeof a && a([]);
        },
        createImage: function (e) {
            let t = document.createElementNS("http://www.w3.org/2000/svg", "image"),
                a = {};
            return (
                (a.width = e.width),
                (a.height = e.height),
                (a.x = 0),
                (a.y = 0),
                (a["data-width"] = e.width),
                (a["data-height"] = e.height),
                (a.class = "pdapp-img"),
                (t = pdappAPI.tool.generalAttr(a, t)),
                t.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", e.blob),
                t
            );
        },
        createG: function (e, t) {
            let a = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                p = {};
            return (
                (p.id = e),
                (p.class = t),
                (p.style = "transform: translate(0, 0) rotate(0deg)"),
                pdappAPI.tool.generalAttr(p, a)
            );
        },
        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, a, p) {
            (pdappAPI.tool.pdappMoveAbleRef.target = null), void 0 === a && (a = "pdapp-target-" + pdappAPI.tool.uID());
            let r = {};
            r = "svg" == p ? pdappAPI.photo.createSvg(e) : pdappAPI.photo.createImage(e);
            let o = "svg" == p ? "pdapp-target pdapp-svg pdapp-svg-photo" : "pdapp-target pdapp-svg-photo",
                i = pdappAPI.photo.createG(a, o);
            if ((i.appendChild(r), "svg" == p)) {
                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 p = e.join(",");
                    i.setAttribute("data-color", p),
                        jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").append(i),
                        pdappAPI.layer.afterAdded(a),
                        setTimeout(() => {
                            let e = jQuery("#" + a);
                            pdappAPI.layer.select(e), "function" == typeof t && t(e);
                        }, 1);
                });
            } else {
                i.setAttribute("data-color", p);
                let e = document.createElementNS("http://www.w3.org/2000/svg", "g");
                e.setAttribute("class", "pdapp-g-photo"),
                    e.appendChild(i),
                    jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").append(e),
                    pdappAPI.layer.afterAdded(a),
                    setTimeout(() => {
                        let e = jQuery("#" + a);
                        pdappAPI.layer.select(e), "function" == typeof t && t(e);
                    }, 1);
            }
        },
        replace: function (e, t, a) {
            let p = t.find("image");
            p.attr("data-width", e.width),
                p.attr("data-height", e.height),
                p.attr("xlink:href", e.blob),
                t.attr("data-color", e.color),
                "function" == typeof a && a();
        },
        pdappMoveAbleRef: null,
        getCrop: function (e) {
            let t = jQuery(pdappAPI.tool.pdappMoveAbleRef.target),
                a = t.find("image"),
                p = {};
            return (
                (p.id = t.attr("id")),
                (p.blob = a.attr("xlink:href")),
                (p.width = a.attr("data-width")),
                (p.height = a.attr("data-height")),
                (p.ratio = "area_ratio"),
                setTimeout(() => {
                    pdappAPI.photo.setCrop(t, e);
                }, 10),
                p
            );
        },
        setCrop: function (e, t) {
            let a = jQuery(".pdapp-croparea .pdapp-cropimage").width(),
                p = jQuery(".pdapp-croparea .pdapp-cropimage").height(),
                r = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").width(),
                o = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").height(),
                i = e.find("image");
            if ((t && ((r = i.width()), (o = i.height())), a / p > r / o)) {
                let e = p,
                    t = parseFloat(((p * r) / o).toFixed(3));
                jQuery(".pdapp-croparea .pdapp-cropmask").width(t), jQuery(".pdapp-croparea .pdapp-cropmask").height(e);
            } else {
                let e = parseFloat(((a * o) / r).toFixed(3)),
                    t = a;
                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(a),
                jQuery(".pdapp-croparea .pdapp-cropimage").height(p),
                jQuery(".pdapp-croparea .pdapp-cropimage").css("max-width", "100%"),
                jQuery(".pdapp-croparea .pdapp-cropimage").css("max-height", "100%");
            let n = 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: n.ver,
                    horizontalGuidelines: n.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(),
                            r = 0 - e.top / parseFloat(t[3]),
                            o = 0 - e.left / parseFloat(t[0]);
                        jQuery(".pdapp-croparea .pdapp-cropmask").css(
                            "background-size",
                            (a / parseFloat(t[0])).toFixed(3) + "px " + (p / parseFloat(t[3])).toFixed(3) + "px"
                        ),
                            jQuery(".pdapp-croparea .pdapp-cropmask").css(
                                "background-position",
                                o.toFixed(3) + "px " + r.toFixed(3) + "px"
                            );
                    }
                });
        },
        changeCropRatio: function (e) {
            let t = jQuery(".pdapp-croparea .pdapp-cropimage").width(),
                a = jQuery(".pdapp-croparea .pdapp-cropimage").height(),
                p = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").width(),
                r = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").height(),
                o = t,
                i = a;
            pdappAPI.photo.pdappMoveAbleRef.keepRatio = "free_ratio" != e;
            let n = !1;
            if ("1:1" == e) (n = !0), o < i ? (i = o) : (o = i);
            else if ("1:2" == e) (n = !0), o > i / 2 ? (o = i / 2) : (i = 2 * o);
            else if ("2:1" == e) (n = !0), i > o / 2 ? (i = o / 2) : (o = 2 * i);
            else if ("area_ratio" == e) {
                n = !0;
                let e = i,
                    t = o;
                o / i > p / r
                    ? ((e = i), (t = parseFloat(((i * p) / r).toFixed(3))))
                    : ((e = parseFloat(((o * r) / p).toFixed(3))), (t = o)),
                    (o = t),
                    (i = e);
            }
            let l = jQuery(".pdapp-croparea .pdapp-cropmask");
            n &&
                (l.width(o),
                l.height(i),
                l.css("transform", "translate(0px, 0px)"),
                l.css("background-size", t + "px " + a + "px"),
                l.css("background-position", "0px 0px")),
                (pdappAPI.photo.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.photo.pdappMoveAbleRef.target = l;
                }, 1);
        },
        crop: function (e, t, a) {
            let p = jQuery(".pdapp-croparea .pdapp-cropimage"),
                r = p[0].naturalWidth / p.width(),
                o = jQuery(".pdapp-croparea .pdapp-cropmask"),
                i = o.position(),
                n = pdappAPI.tool
                    .getTransform(o)
                    .replace("matrix(", "")
                    .replace(")", "")
                    .replaceAll(" ", "")
                    .split(","),
                l = { width: o.width(), height: o.height() };
            void 0 !== n.length &&
                6 == n.length &&
                ((l.width = l.width * parseFloat(n[0])), (l.height = l.height * parseFloat(n[3])));
            let d = {
                    top: (i.top * r).toFixed(3),
                    left: (i.left * r).toFixed(3),
                    width: (l.width * r).toFixed(3),
                    height: (l.height * r).toFixed(3),
                },
                s = pdappAPI.tool.pdappMoveAbleRef.target,
                c = jQuery(s).find("image");
            pdappAPI.photo.cropImage(p.attr("src"), d, function (p) {
                (p.blob = p.blob),
                    (p.base64 = p.base64),
                    c.attr("xlink:href", p.blob),
                    t || (c.attr("width", p.width), c.attr("height", p.height)),
                    c.attr("data-crop", p.top + "," + p.left + "," + p.width + "," + p.height);
                let r = jQuery(s);
                if (r.hasClass("pdapp-shape"))
                    for (let t = 0; t < e.length; t++)
                        e[t].slug == r.attr("data-shape") && pdappAPI.photo.addShape(e[t]);
                setTimeout(() => {
                    t || pdappAPI.photo.fitPhotoInside(),
                        (p.ratio = "area_ratio"),
                        "function" == typeof a && a(p, r.attr("id"));
                }, 10);
            });
        },
        originPhoto: function (e, t, a) {
            let p = e.find("image");
            p.attr("xlink:href", t.blob),
                p.attr("width", p.attr("data-width")),
                p.attr("height", p.attr("data-height")),
                "function" == typeof a && a(t.blob),
                setTimeout(() => {
                    pdappAPI.photo.fitPhotoInside();
                }, 1);
        },
        fitPhotoInside: function () {
            let e = pdappAPI.tool.pdappMoveAbleRef.target,
                t = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").find("svg.pdapp-selecto-area").width(),
                a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active")
                    .find("svg.pdapp-selecto-area")
                    .height();
            (t = parseFloat(t.toFixed(3))), (a = parseFloat(a.toFixed(3)));
            let p = jQuery(e),
                r = p[0].getBoundingClientRect();
            if (0 == r.width) return !1;
            let o = 1,
                i = pdappAPI.tool
                    .getTransform(p)
                    .replace("matrix(", "")
                    .replace(")", "")
                    .replaceAll(" ", "")
                    .split(",");
            void 0 !== i.length &&
                6 == i.length &&
                1 != i[0] &&
                ((r.width = r.width / parseFloat(i[0])), (r.height = r.height / parseFloat(i[0]))),
                (o =
                    r.width / r.height < t / a
                        ? parseFloat((a / r.height).toFixed(3))
                        : parseFloat((t / r.width).toFixed(3))),
                void 0 !== i.length &&
                    6 == i.length &&
                    ((i[0] = o),
                    (i[3] = parseFloat(i[0])),
                    p.attr("transform", "matrix(" + i.join(", ") + ")"),
                    pdappAPI.photo.alignPhoto("centerAll"));
        },
        fitPhotoOutside: function () {
            let e = pdappAPI.tool.pdappMoveAbleRef.target,
                t = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").find("svg.pdapp-selecto-area").width(),
                a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active")
                    .find("svg.pdapp-selecto-area")
                    .height();
            (t = parseFloat(t.toFixed(3))), (a = parseFloat(a.toFixed(3)));
            let p = jQuery(e),
                r = p[0].getBoundingClientRect();
            if (0 == r.width) return !1;
            let o = 1,
                i = pdappAPI.tool
                    .getTransform(p)
                    .replace("matrix(", "")
                    .replace(")", "")
                    .replaceAll(" ", "")
                    .split(",");
            void 0 !== i.length &&
                6 == i.length &&
                1 != i[0] &&
                ((r.width = r.width / parseFloat(i[0])), (r.height = r.height / parseFloat(i[0]))),
                (o =
                    r.width / r.height > t / a
                        ? parseFloat((a / r.height).toFixed(3))
                        : parseFloat((t / r.width).toFixed(3))),
                void 0 !== i.length &&
                    6 == i.length &&
                    ((i[0] = o),
                    (i[3] = parseFloat(i[0])),
                    p.attr("transform", "matrix(" + i.join(", ") + ")"),
                    pdappAPI.photo.alignPhoto("centerAll"));
        },
        addShape: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a),
                r = p.attr("id") + "-shape";
            if (
                (p.find("defs").find("clipPath").remove(),
                p.removeClass("pdapp-shape"),
                p.removeAttr("clip-path"),
                "" != e && void 0 !== e.type)
            ) {
                let t = pdappAPI.tool.renderShape(p, e, r);
                if ("" != t) {
                    if (0 != p.find("defs").length) p.find("defs").prepend(t);
                    else {
                        let e = document.createElementNS("http://www.w3.org/2000/svg", "defs");
                        e.appendChild(t), p.prepend(e);
                    }
                    p.addClass("pdapp-shape"), p.attr("data-shape", e.slug), p.attr("clip-path", "url(#" + r + ")");
                }
            }
            "function" == typeof t && t();
        },
        addFilter: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a),
                r = p.attr("id") + "-filter",
                o = p.parent("g.pdapp-g-photo");
            if (0 == o.length) return !1;
            if (
                (p.find("defs").find("filter").remove(),
                p.removeClass("pdapp-filter"),
                p.removeAttr("data-filter"),
                o.removeAttr("css"),
                "" != e)
            ) {
                p.addClass("pdapp-filter"), p.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 a = document.createElementNS("http://www.w3.org/2000/svg", "filter");
                if ((a.setAttributeNS(null, "id", r), a.appendChild(t), 0 != p.find("defs").length))
                    p.find("defs").prepend(a);
                else {
                    let e = document.createElementNS("http://www.w3.org/2000/svg", "defs");
                    e.appendChild(a), p.prepend(e);
                }
                p.addClass("pdapp-filter"), p.attr("data-filter", e.slug), o.css("filter", "url(#" + r + ")");
            }
            "function" == typeof t && t();
        },
        updateValue: function (e, t) {
            let a = jQuery(e),
                p = { type: "photo" };
            (p.editColor = a.hasClass("pdapp-svg")),
                (p.colors = []),
                (p.photoLock = a.hasClass("pdapp-lock")),
                (p.photoFlip = !1),
                (p.transparency = 100 * a.css("opacity")),
                (p.dropdown = ""),
                (p.photo = p.editColor ? "" : a.find("image").attr("xlink:href")),
                (p.photoShape = a.hasClass("pdapp-shape") ? a.attr("data-shape") : ""),
                (p.photoFilter = a.hasClass("pdapp-filter") ? a.attr("data-filter") : ""),
                (p.clickUpload = a.hasClass("pdapp-upload")),
                (p.clickPhoto = a.hasClass("pdapp-photo")),
                (p.clickShowUpload = a.hasClass("pdapp-showupload")),
                (p.settings = []);
            let r = a.attr("data-hide-options");
            void 0 !== r && (p.settings = r.split(",")),
                a.hasClass("pdapp-flip") && (p.photoFlip = !0),
                "function" == typeof t && t(p);
        },
        updatePhotoStyle: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            if (null == a || 0 == a.length) return !1;
            "transparency" == e && p.attr("opacity", t / 100);
        },
        alignPhoto: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (null == t || 0 == t.length) return !1;
            let a = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool[e](a),
                (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 a = jQuery(t);
            void 0 !== pdappAPI.tool[e] && pdappAPI.tool.move[e](a),
                (pdappAPI.tool.pdappMoveAbleRef.target = null),
                setTimeout(() => {
                    pdappAPI.tool.pdappMoveAbleRef.target = t;
                }, 1);
        },
        delete: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(t),
                p = a.attr("id");
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let r = a.parent("g.pdapp-g-photo");
            0 != r.length ? r.remove() : a.remove(), "function" == typeof e && e(p);
        },
        lock: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                e ? ((e = !1), p.removeClass("pdapp-lock")) : ((e = !0), p.addClass("pdapp-lock")),
                "function" == typeof t && t(e),
                pdappAPI.layer.select(a);
        },
        flip: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a),
                r = p[0].getBoundingClientRect();
            if (0 == r.width) return !1;
            e ? ((e = !1), p.removeClass("pdapp-flip")) : ((e = !0), p.addClass("pdapp-flip"));
            let o = pdappAPI.tool
                .getTransform(p)
                .replace("matrix(", "")
                .replace(")", "")
                .replaceAll(" ", "")
                .split(",");
            if (6 == o.length) {
                let i = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                    n = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").attr(
                        "viewBox"
                    );
                if (void 0 !== n) {
                    let e = parseFloat(n.split(" ")[2]),
                        t = parseFloat(n.split(" ")[3]),
                        a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").width(),
                        p = jQuery(
                            ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                        ).height();
                    (parseInt(a / i) == parseInt(e) && parseInt(p / i) == parseInt(t)) ||
                        (i = e / t > a / p ? a / e : p / t);
                }
                if (
                    (e
                        ? (p.find("image").attr("transform", "scale(-1, 1)"),
                          (o[4] = (parseFloat(o[4]) + r.width / i).toFixed(3)))
                        : (p.find("image").attr("transform", "scale(1, 1)"),
                          (o[4] = (parseFloat(o[4]) - r.width / i).toFixed(3))),
                    p.hasClass("pdapp-shape"))
                ) {
                    let t = e ? -1 : 1,
                        a = p.find("clipPath"),
                        r = a.find("circle");
                    0 != r.length && r.attr("transform", "scale(" + t + ", 1)");
                    let o = a.find("rect");
                    0 != o.length && o.attr("transform", "scale(" + t + ", 1)");
                    let i = a.find("path");
                    0 != i.length &&
                        i.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(", ") + ")"));
                        });
                }
                p.attr("transform", "matrix(" + o.join(", ") + ")"),
                    "function" == typeof t && t(e),
                    pdappAPI.layer.select(a);
            }
        },
        copy: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let r = "pdapp-target-" + pdappAPI.tool.uID(),
                o = p.clone(),
                i = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active"),
                n = p.attr("id");
            jQuery(o).attr("id", r);
            let l = jQuery(o).find("#" + n + "-shape");
            0 != l.length && (l.attr("id", r + "-shape"), jQuery(o).attr("clip-path", "url(#" + r + "-shape)"));
            let d = jQuery(o).find("#" + n + "-filter");
            if ((0 != d.length && d.attr("id", r + "-filter"), p.hasClass("pdapp-svg-photo"))) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "g");
                0 != d.length && (e.style.filter = "url(#" + r + "-filter)"),
                    e.append(o[0]),
                    i.find("svg.pdapp-selecto-area").append(e);
            } else i.find("svg.pdapp-selecto-area").append(o);
            pdappAPI.layer.afterAdded(r),
                setTimeout(() => {
                    let a = jQuery("#" + r);
                    pdappAPI.layer.select(a),
                        "function" == typeof t && t(a, n),
                        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, a) {
            let p = null,
                r = null,
                o = document.createElement("canvas"),
                i = o.getContext("2d"),
                n = document.createElement("img");
            (n.crossOrigin = "anonymous"),
                (n.onload = function () {
                    setTimeout(() => {
                        if (
                            ((o.width = n.width),
                            (o.height = n.height),
                            i.drawImage(n, 0, 0),
                            (p = i.getImageData(0, 0, n.width, n.height)),
                            (r = p),
                            void 0 !== r.data && r.data.length)
                        ) {
                            let e = pdappAPI.tool.hexToRgb(t, !0);
                            for (let t = 0, a = p.data.length; t < a; t += 4)
                                r.data[t + 3] > 0 && ((r.data[t] = e.r), (r.data[t + 1] = e.g), (r.data[t + 2] = e.b));
                            i.putImageData(r, 0, 0);
                        }
                        let e = o.toDataURL("image/png");
                        "function" == typeof a && a(e), n.remove(), o.remove();
                    }, 10);
                }),
                (n.src = e);
        },
        setColor: function (e) {
            let t = e.find(".pdapp-product-img"),
                a = t.attr("data-color");
            if (void 0 === a || "" == a) {
                let e = t.attr("src");
                return (
                    -1 != e.indexOf("://") &&
                        pdappAPI.tool.imgToBase64(
                            e,
                            function (e) {
                                t.attr("src", e);
                            },
                            1e3
                        ),
                    !1
                );
            }
            let p = t.attr("src");
            this.replaceColor(p, a, function (e) {
                t.attr("src", e);
            });
        },
    },
    team: {
        createText: function (e) {
            let t = document.createElementNS("http://www.w3.org/2000/svg", "text"),
                a = {};
            return (
                (a.stroke = e.stroke),
                (a["stroke-width"] = e.strokeWidth),
                (a["font-weight"] = e.fontWeight),
                (a["font-style"] = e.fontStyle),
                (a["text-decoration"] = e.textDecoration),
                (a["stroke-linecap"] = "round"),
                (a["stroke-linejoin"] = "round"),
                (a["text-anchor"] = "start"),
                (a["font-size"] = e.fontSize),
                (a["font-family"] = e.fontFamily),
                pdappAPI.tool.generalAttr(a, t)
            );
        },
        createG: function (e, t, a) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                r = {};
            return (
                (r.id = e),
                (r.class = a),
                (r.style = "transform: translate(0, 0) rotate(0deg)"),
                (r["data-text"] = t.text),
                (r.fill = t.color),
                pdappAPI.tool.generalAttr(r, p)
            );
        },
        create: function (e, t, a) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let p = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"),
                r = {
                    text: "Ronaldo",
                    color: "#000000",
                    fontSize: 60,
                    fontFamily: "Arsenal",
                    stroke: "#000000",
                    strokeWidth: 0,
                    fontWeight: "normal",
                    fontStyle: "normal",
                    textDecoration: "none",
                    textTransform: "none",
                },
                o = "pdapp-target pdapp-team pdapp-team-name";
            if (
                ("number" == t &&
                    ((r.text = "00"),
                    (r.fontSize = "100"),
                    (r.fontFamily = "Alumni Sans Collegiate One"),
                    (o = "pdapp-target pdapp-team pdapp-team-number")),
                void 0 !== e.text)
            )
                for (let t in r) void 0 !== e[t] && (r[t] = e[t]);
            let i = "pdapp-target-" + pdappAPI.tool.uID(),
                n = pdappAPI.team.createText(r);
            n.innerHTML = "none" == r.textTransform ? r.text : r.text.toUpperCase;
            let l = pdappAPI.text.createG(i, r, o);
            l.appendChild(n),
                p.append(l),
                pdappAPI.layer.afterAdded(i, function () {
                    let e = jQuery("#" + i);
                    (r = pdappAPI.text.autoSetSize(e, r)), pdappAPI.layer.select(e), "function" == typeof a && a(i, r);
                });
        },
        updateValue: function (e, t) {
            let a = jQuery(e),
                p = { type: "team" };
            (p.text = a.attr("data-text")),
                (p.member = a.attr("data-member")),
                (p.stroke = a.find("text").attr("stroke")),
                (p.strokeWidth = Math.round(10 * parseFloat(a.find("text").attr("stroke-width")))),
                (p.fontWeight = a.find("text").attr("font-weight")),
                (p.fontSize = a.find("text").attr("font-size")),
                (p.fontFamily = a.find("text").attr("font-family")),
                (p.fontStyle = a.find("text").attr("font-style")),
                (p.textDecoration = a.find("text").attr("text-decoration")),
                (p.textTransform = a.hasClass("pdapp-uppercase") ? "uppercase" : "none"),
                (p.dropdown = ""),
                (p.transparency = 100 * a.css("opacity")),
                (p.letterSpacing = 0),
                (p.settings = []);
            let r = a.attr("data-hide-options");
            void 0 !== r && (p.settings = r.split(",")),
                void 0 !== a.attr("data-spacing")
                    ? (p.letterSpacing = a.attr("data-spacing"))
                    : void 0 !== a.css("letter-spacing") &&
                      (p.letterSpacing = a.css("letter-spacing").replace("px", ""));
            let o = pdappAPI.tool.getTransform(a);
            if ("" != o) {
                let e = o.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                if (6 == e.length) {
                    let t = parseFloat(e[0]);
                    1 != t && (p.fontSize = Math.round(p.fontSize * t));
                }
            }
            (p.color = pdappAPI.tool.rgbToHex(a.attr("fill"))),
                (p.team = "name"),
                a.hasClass("pdapp-team-number") && (p.team = "number"),
                "function" == typeof t && t(p);
        },
        setTargets: function (e) {
            let t = e.active;
            if ((void 0 !== e.name && "" != e.name && jQuery("#" + e.name).attr("data-team", t), void 0 !== e.number))
                for (let a = 0; a < e.number.length; a++) jQuery("#" + e.number[a]).attr("data-team", t);
        },
        updateMember: function (e, t, a, p) {
            if ("name" == t) {
                let t = jQuery("#" + e);
                void 0 !== p && t.attr("data-team", p);
                let r = [],
                    o = t[0].getBoundingClientRect();
                if (0 != o.width) {
                    let e = pdappAPI.tool.getTransform(t);
                    "" != e && (r = e.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                }
                t.find("text").text(a),
                    t.attr("data-text", a),
                    setTimeout(() => {
                        if (6 == r.length) {
                            let e = t[0].getBoundingClientRect();
                            if (0 != e.width) {
                                let a = ((e.width - o.width) / 2).toFixed(3);
                                (a = parseFloat(a)),
                                    (r[4] = parseFloat(r[4]) - a),
                                    t.attr("transform", "matrix(" + r.join(", ") + ")");
                            }
                        }
                        if (null != pdappAPI.tool.pdappMoveAbleRef.target) {
                            let e = pdappAPI.tool.pdappMoveAbleRef.target;
                            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                setTimeout(() => {
                                    pdappAPI.tool.pdappMoveAbleRef.target = e;
                                }, 1);
                        }
                    }, 10);
            }
            if ("number" == t)
                for (let t = 0; t < e.length; t++) {
                    let r = jQuery("#" + e[t]);
                    void 0 !== p && r.attr("data-team", p);
                    let o = [],
                        i = r[0].getBoundingClientRect();
                    if (0 != i.width) {
                        let e = pdappAPI.tool.getTransform(r);
                        "" != e && (o = e.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                    }
                    r.find("text").text(a),
                        r.attr("data-text", a),
                        6 == o.length &&
                            setTimeout(() => {
                                let e = r[0].getBoundingClientRect();
                                if (0 != e.width) {
                                    let t = (e.width - i.width).toFixed(3);
                                    (t = parseFloat(t)),
                                        (o[4] = parseFloat(o[4]) - t),
                                        r.attr("transform", "matrix(" + o.join(", ") + ")");
                                }
                                if (null != pdappAPI.tool.pdappMoveAbleRef.target) {
                                    let e = pdappAPI.tool.pdappMoveAbleRef.target;
                                    (pdappAPI.tool.pdappMoveAbleRef.target = null),
                                        setTimeout(() => {
                                            pdappAPI.tool.pdappMoveAbleRef.target = e;
                                        }, 1);
                                }
                            }, 10);
                }
        },
        delete: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target,
                a = jQuery(t),
                p = a.attr("id");
            (pdappAPI.tool.pdappMoveAbleRef.target = null), a.remove(), "function" == typeof e && e(p);
        },
    },
    upload: {
        verify: function (e, t, a) {
            let p = e.name.substr(e.name.lastIndexOf(".") + 1);
            p = p.toLowerCase();
            let r = "";
            return (
                void 0 !== t.general &&
                    void 0 !== t.general.upload &&
                    (0 == t.general.upload.type.includes(p)
                        ? (r = a.msg.upload_type_error + " " + t.general.upload.type.join(", "))
                        : e.size > 1048576 * t.general.upload.max
                          ? (r = a.msg.upload_maxsize_error + " " + t.general.upload.max + "MB")
                          : e.size < 1048576 * t.general.upload.min &&
                            (r = a.msg.upload_minsize_error + " " + t.general.upload.min + "MB")),
                r
            );
        },
        uploadFile: function (e, t, a) {
            return new Promise(function (p, r) {
                let o = {
                    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 a && a(t);
                                    }
                                },
                                !1
                            ),
                            e
                        );
                    },
                    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, a) {
                        "" == a && (a = "Request failed"), r({ msg: a, error: 1 });
                    },
                };
                jQuery.ajax(o);
            });
        },
        readFile: function (e, t) {
            let a = new FileReader();
            a.readAsDataURL(e),
                (a.onloadend = function () {
                    let e = a.result;
                    "function" == typeof t && t(e);
                });
        },
    },
    qrcode: {
        createSvg: function (e) {
            return new DOMParser().parseFromString(e, "image/svg+xml").documentElement;
        },
        createG: function (e, t, a) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                r = {};
            return (
                (r.id = e),
                (r.class = a),
                (r.style = "transform: translate(0, 0) rotate(0deg)"),
                (r["data-text"] = t.text),
                (r["data-color"] = t.color),
                (r["data-background"] = t.background),
                (r["data-padding"] = t.padding),
                (r["data-width"] = t.width),
                (r["data-ecl"] = t.ecl),
                (r["data-subject"] = t.subject),
                (r["data-message"] = t.message),
                (r["data-qrtype"] = t.qrtype),
                pdappAPI.tool.generalAttr(r, p)
            );
        },
        create: function (e, t) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active"),
                p = a.width(),
                r = a.height();
            p > r && (p = r), p > 200 && (p = 200);
            let o = {
                text: "Add your text content...",
                color: "#000000",
                background: "transparent",
                padding: 1,
                ecl: "H",
                width: p,
                qrtype: "text",
                subject: "",
                message: "",
            };
            if (void 0 !== e.text) for (let t in o) void 0 !== e[t] && "" != e[t] && (o[t] = e[t]);
            let i = "pdapp-target-" + pdappAPI.tool.uID(),
                n = o.text;
            "phone" == o.qrtype ? (n = "tel:" + n) : "sms" == o.qrtype && (n = "smsto:" + n + ":" + o.message),
                "mail" == o.qrtype && (n = "mailto:" + n + "?subject=" + o.subject + "&body=" + o.message);
            let l = new QRCode({
                content: n,
                padding: parseInt(o.padding),
                width: parseInt(o.width),
                height: parseInt(o.width),
                color: o.color,
                background: o.background,
                ecl: o.ecl,
                join: !0,
            }).svg();
            setTimeout(() => {
                let e = pdappAPI.qrcode.createSvg(l),
                    p = pdappAPI.qrcode.createG(i, o, "pdapp-target pdapp-svg pdapp-svg-qrcode");
                p.append(e),
                    jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").append(p),
                    a.find("svg.pdapp-selecto-area").append(p),
                    pdappAPI.layer.afterAdded(i),
                    setTimeout(() => {
                        let e = jQuery("#" + i);
                        pdappAPI.layer.select(e),
                            "function" == typeof t && t(e),
                            e.find("svg").attr("viewBox", "0 0 " + parseInt(o.width) + " " + parseInt(o.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 a = jQuery(e),
                p = { type: "qrcode" };
            (p.text = a.attr("data-text")),
                (p.subject = a.attr("data-subject")),
                (p.message = a.attr("data-message")),
                (p.qrtype = a.attr("data-qrtype")),
                (p.color = a.attr("data-color")),
                (p.background = a.attr("data-background")),
                (p.padding = a.attr("data-padding")),
                (p.width = a.attr("data-width")),
                (p.ecl = a.attr("data-ecl")),
                (p.transparency = 100 * a.css("opacity")),
                (p.dropdown = ""),
                (p.photoLock = a.hasClass("pdapp-lock")),
                (p.settings = []);
            let r = a.attr("data-hide-options");
            void 0 !== r && (p.settings = r.split(",")), "function" == typeof t && t(p);
        },
        update: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            p.attr("data-text", e.text),
                p.attr("data-subject", e.subject),
                p.attr("data-message", e.message),
                p.attr("data-color", e.color),
                p.attr("data-qrtype", e.qrtype),
                p.attr("data-background", e.background),
                p.attr("data-padding", e.padding),
                p.attr("data-ecl", e.ecl);
            let r = e.text;
            "phone" == e.qrtype ? (r = "tel:" + r) : "sms" == e.qrtype && (r = "smsto:" + r + ":" + e.message),
                "mail" == e.qrtype && (r = "mailto:" + r + "?subject=" + e.subject + "&body=" + e.message);
            let o = new QRCode({
                content: r,
                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 p = pdappAPI.qrcode.createSvg(o);
                (a = jQuery(pdappAPI.tool.pdappMoveAbleRef.target)),
                    a.html(p),
                    "function" == typeof t && t(a),
                    a.find("svg").attr("viewBox", "0 0 " + parseInt(e.width) + " " + parseInt(e.width)),
                    a.find("rect").attr("fill", pdappAPI.tool.rgbToHex(a.find("rect").css("fill"))),
                    a.find("rect").attr("shape-rendering", a.find("rect").css("shape-rendering")),
                    a.find("rect").removeAttr("style"),
                    a.find("path").attr("fill", pdappAPI.tool.rgbToHex(a.find("path").css("fill"))),
                    a.find("path").attr("shape-rendering", a.find("path").css("shape-rendering")),
                    a.find("path").removeAttr("style");
            }, 1);
        },
        copy: function (e, t) {
            let a = jQuery(pdappAPI.tool.pdappMoveAbleRef.target);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let p = "pdapp-target-" + pdappAPI.tool.uID(),
                r = a.clone(),
                o = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active");
            jQuery(r).attr("id", p),
                o.find("svg.pdapp-selecto-area").append(r),
                pdappAPI.layer.afterAdded(p),
                setTimeout(() => {
                    let a = jQuery("#" + p);
                    pdappAPI.layer.select(a),
                        "function" == typeof t && t(a),
                        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, a) {
            let p = "",
                r = { min: 1, max: 9999 };
            return (
                (-1 == t.indexOf("CODE128") && -1 == t.indexOf("CODE39")) ||
                    (-1 != t.indexOf("CODE128A") && e.toUpperCase() != e && (p = a.error_barcode_128a),
                    -1 != t.indexOf("CODE128C") &&
                        ((r.min = 2),
                        isNaN(e) && (p = a.error_barcode_number),
                        e.length % 2 != 0 && (p = a.error_barcode_128c))),
                (-1 == t.indexOf("EAN13") && -1 == t.indexOf("UPC")) || ((r.max = 13), (r.min = 13)),
                -1 != t.indexOf("EAN8") && ((r.max = 8), (r.min = 8)),
                -1 != t.indexOf("EAN5") && ((r.max = 5), (r.min = 5)),
                -1 != t.indexOf("EAN2") && ((r.max = 2), (r.min = 2)),
                -1 != t.indexOf("ITF14") && ((r.max = 14), (r.min = 14)),
                -1 != t.indexOf("pharmacode") &&
                    ((r.max = 5),
                    isNaN(e) && (p = a.error_barcode_number),
                    e < 3 && (p = a.error_barcode_minimum_numb)),
                -1 != t.indexOf("codabar") &&
                    isNaN(
                        e
                            .replaceAll("$", "")
                            .replaceAll("-", "")
                            .replaceAll(":", "")
                            .replaceAll("/", "")
                            .replaceAll("+", "")
                            .replaceAll(".", "")
                    ) &&
                    (p = a.error_barcode_allow_number),
                e.length < r.min && (p = a.error_barcode_minimum + " " + r.min),
                e.length > r.max && (p = a.error_barcode_maximum + " " + r.max),
                p
            );
        },
        createSvg: function (e) {
            let t = new DOMParser().parseFromString(e, "image/svg+xml");
            return jQuery(t.documentElement).removeAttr("id"), t.documentElement;
        },
        createG: function (e, t, a) {
            let p = document.createElementNS("http://www.w3.org/2000/svg", "g"),
                r = {};
            return (
                (r.id = e),
                (r.class = a),
                (r.style = "transform: translate(0, 0) rotate(0deg)"),
                (r["data-text"] = t.text),
                (r["data-color"] = t.lineColor),
                (r["data-background"] = t.background),
                (r["data-format"] = t.format),
                (r["data-width"] = t.width),
                (r["data-height"] = t.height),
                (r["data-fontWeight"] = t.fontWeight),
                (r["data-fontFamily"] = t.font),
                (r["data-textAlign"] = t.textAlign),
                (r["data-textPosition"] = t.textPosition),
                (r["data-textMargin"] = t.textMargin),
                (r["data-margin"] = t.margin),
                (r["data-fontSize"] = t.fontSize),
                (r["data-margin"] = t.margin),
                (r["data-lastChar"] = t.lastChar),
                (r["data-displayValue"] = t.displayValue),
                pdappAPI.tool.generalAttr(r, p)
            );
        },
        create: function (e, t, a) {
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let p = {
                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 (
                ((p.text = pdappAPI.barcode.getBarcodeDefault(p.format, "Add your text content...")), void 0 !== e.text)
            )
                for (let t in p)
                    (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])),
                            (p[t] = e[t])));
            let r = "pdapp-target-" + pdappAPI.tool.uID();
            jQuery("#pdapp-barcode-box").html("");
            let o = p.format;
            if (-1 != o.indexOf("-")) {
                let t = o.split("-");
                if (((p.format = t[0]), "lastchar" == t[1]))
                    p.lastChar = void 0 !== e.lastChar && "" != e.lastChar ? e.lastChar : ">";
                else {
                    p[t[1]] = !0;
                }
                JsBarcode("#pdapp-barcode-box", p.text, p), (p.format = o);
            } else JsBarcode("#pdapp-barcode-box", p.text, p);
            pdappAPI.barcode.insert(r, t, p, a);
        },
        insert: function (e, t, a, p) {
            let r = jQuery("#pdapp-barcode-box").html();
            if (void 0 === r)
                return (
                    setTimeout(() => {
                        pdappAPI.barcode.insert(e, t, a, p);
                    }, 10),
                    !1
                );
            let o = jQuery("#pdapp-barcode-box"),
                i = a.font.replaceAll(" ", "+");
            if (void 0 !== t[i]) {
                let e = '<style xmlns="http://www.w3.org/1999/xhtml">' + t[i] + "</style>";
                o.prepend(e);
            }
            r = new XMLSerializer().serializeToString(o[0]);
            let n = pdappAPI.barcode.createSvg(r),
                l = pdappAPI.barcode.createG(e, a, "pdapp-target pdapp-svg pdapp-svg-barcode");
            l.append(n),
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").append(l),
                pdappAPI.layer.afterAdded(e),
                setTimeout(() => {
                    let t = jQuery("#" + e);
                    pdappAPI.layer.select(t),
                        "function" == typeof p && p(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 a = t.find("text").css("font").split("px ");
                    2 == a.length &&
                        (t.find("text").attr("font-size", a[0] + "px"),
                        t.find("text").attr("font-family", a[1].replaceAll('"', "")),
                        t.find("text").removeAttr("style"));
                    let r = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active")[0].getBoundingClientRect(),
                        o = t[0].getBoundingClientRect();
                    (o.width > r.width || o.height > r.height) &&
                        setTimeout(() => {
                            pdappAPI.photo.fitPhotoInside();
                        }, 1);
                }, 1);
        },
        updateValue: function (e, t) {
            let a = jQuery(e),
                p = { type: "barcode" };
            (p.text = a.attr("data-text")),
                (p.lineColor = a.attr("data-color")),
                (p.background = a.attr("data-background")),
                (p.format = a.attr("data-format")),
                (p.width = parseInt(a.attr("data-width"))),
                (p.height = parseInt(a.attr("data-height"))),
                (p.fontOptions = a.attr("data-fontWeight")),
                (p.font = a.attr("data-fontFamily")),
                (p.textAlign = a.attr("data-textAlign")),
                (p.textPosition = a.attr("data-textPosition")),
                (p.textMargin = parseInt(a.attr("data-textMargin"))),
                (p.margin = parseInt(a.attr("data-margin"))),
                (p.fontSize = parseInt(a.attr("data-fontSize"))),
                (p.transparency = 100 * a.css("opacity")),
                (p.dropdown = ""),
                (p.lastChar = a.attr("data-lastChar")),
                (p.displayValue = "true" === a.attr("data-displayValue") || !0 === a.attr("data-displayValue")),
                (p.photoLock = a.hasClass("pdapp-lock")),
                (p.settings = []);
            let r = a.attr("data-hide-options");
            void 0 !== r && (p.settings = r.split(",")),
                void 0 === p.lastChar && (p.lastChar = ">"),
                "function" == typeof t && t(p);
        },
        update: function (e, t, a) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            null == p && (p = "#" + jQuery(".pdapp-viewport.active .pdapp-viewport-area.active g.active").attr("id"));
            let r = jQuery(p);
            jQuery("#pdapp-barcode-box").html("");
            let o = {
                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 (((o.text = pdappAPI.barcode.getBarcodeDefault(o.format)), void 0 !== e))
                for (let t in o)
                    (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])),
                            (o[t] = e[t])));
            let i = o.format;
            if (
                (r.attr("data-format", o.format),
                r.attr("data-text", o.text),
                r.attr("data-color", o.lineColor),
                r.attr("data-background", o.background),
                r.attr("data-width", o.width),
                r.attr("data-height", o.height),
                r.attr("data-margin", o.margin),
                r.attr("data-lastChar", o.lastchar),
                r.attr("data-displayValue", o.displayValue),
                -1 != i.indexOf("-"))
            ) {
                let t = i.split("-");
                if (((o.format = t[0]), "lastchar" == t[1]))
                    (o.lastChar = void 0 !== e.lastChar && "" != e.lastChar ? e.lastChar : ">"),
                        r.attr("data-lastChar", o.lastChar);
                else {
                    o[t[1]] = !0;
                }
                JsBarcode("#pdapp-barcode-box", o.text, o);
            } else JsBarcode("#pdapp-barcode-box", o.text, o);
            pdappAPI.barcode.addUpdate(t, o.font, p, a);
        },
        addUpdate: function (e, t, a, p) {
            let r = jQuery("#pdapp-barcode-box").html();
            if (void 0 === r)
                return (
                    setTimeout(() => {
                        pdappAPI.barcode.addUpdate(e, t, a);
                    }, 50),
                    !1
                );
            setTimeout(() => {
                let o = jQuery("#pdapp-barcode-box"),
                    i = t.replaceAll(" ", "+");
                if (void 0 !== e[i]) {
                    let t = '<style xmlns="http://www.w3.org/1999/xhtml">' + e[i] + "</style>";
                    o.prepend(t);
                }
                r = new XMLSerializer().serializeToString(o[0]);
                let n = pdappAPI.barcode.createSvg(r),
                    l = jQuery(a);
                l.html(n),
                    "function" == typeof p && p(l),
                    (pdappAPI.tool.pdappMoveAbleRef.target = null),
                    setTimeout(() => {
                        (pdappAPI.tool.pdappMoveAbleRef.target = a),
                            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 a = pdappAPI.tool.pdappMoveAbleRef.target,
                p = jQuery(a);
            pdappAPI.tool.pdappMoveAbleRef.target = null;
            let r = "pdapp-target-" + pdappAPI.tool.uID(),
                o = p.clone(),
                i = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active");
            jQuery(o).attr("id", r),
                i.find("svg.pdapp-selecto-area").append(o),
                pdappAPI.layer.afterAdded(r),
                setTimeout(() => {
                    let a = jQuery("#" + r);
                    pdappAPI.layer.select(a),
                        "function" == typeof t && t(a),
                        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.active .pdapp-viewport-area.active svg.pdapp-selecto-area")
                    .find("g.pdapp-target")
                    .each(function () {
                        let t = { id: "", type: "text", value: "" },
                            a = jQuery(this);
                        (t.id = a.attr("id")),
                            a.hasClass("pdapp-svg-photo")
                                ? (t.type = "photo")
                                : a.hasClass("pdapp-svg-artwork")
                                  ? (t.type = "artwork")
                                  : a.hasClass("pdapp-svg-qrcode")
                                    ? (t.type = "qrcode")
                                    : a.hasClass("pdapp-svg-barcode") && (t.type = "barcode"),
                            "text" == t.type
                                ? (t.value = a.attr("data-text"))
                                : "qrcode" == t.type || "barcode" == t.type
                                  ? (t.value =
                                        "data:image/svg+xml;base64," +
                                        pdappAPI.tool.encodeBase64(a.find("svg")[0].outerHTML))
                                  : a.find("image").length
                                    ? (t.value = a.find("image").attr("xlink:href"))
                                    : (t.value =
                                          "data:image/svg+xml;base64," +
                                          pdappAPI.tool.encodeBase64(a.find("svg")[0].outerHTML)),
                            void 0 !== t.id && "" != t.id && e.push(t);
                    }),
                e
            );
        },
        moveLayer: function (e, t) {
            let a = null,
                p = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area");
            p.find("g.pdapp-target").each(function (r) {
                if (jQuery(this).attr("id") == e) {
                    a =
                        0 == jQuery(this).parent("g.pdapp-g-photo").length
                            ? jQuery(this)
                            : jQuery(this).parent("g.pdapp-g-photo");
                    let e = a.clone();
                    if ("up" == t)
                        if (0 == r) p.append(e);
                        else {
                            let t =
                                0 == jQuery(p.find("g.pdapp-target")[r - 1]).parent("g.pdapp-g-photo").length
                                    ? p.find("g.pdapp-target")[r - 1]
                                    : jQuery(p.find("g.pdapp-target")[r - 1]).parent("g.pdapp-g-photo");
                            jQuery(e).insertBefore(t);
                        }
                    else if (r == p.find("g.pdapp-target").length - 1) {
                        let t =
                            0 == jQuery(p.find("g.pdapp-target")[0]).parent("g.pdapp-g-photo").length
                                ? p.find("g.pdapp-target")[0]
                                : jQuery(p.find("g.pdapp-target")[0]).parent("g.pdapp-g-photo");
                        jQuery(e).insertBefore(t);
                    } else {
                        let t =
                            0 == jQuery(p.find("g.pdapp-target")[r + 1]).parent("g.pdapp-g-photo").length
                                ? p.find("g.pdapp-target")[r + 1]
                                : jQuery(p.find("g.pdapp-target")[r + 1]).parent("g.pdapp-g-photo");
                        jQuery(e).insertAfter(t);
                    }
                }
            }),
                null != a && a.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, t) {
            let a = jQuery("#" + e);
            pdappAPI.tool.centerAll(a, t);
        },
        active: function (e, t, a) {
            let p = [];
            1 == e.length
                ? (pdappAPI.layer.select(e),
                  jQuery(e).hasClass("pdapp-svg-text")
                      ? pdappAPI.text.updateValue(e, function (e) {
                            (e.title = t.edit_text), p.push(e), "function" == typeof a && a(0, "text", p);
                        })
                      : jQuery(e).hasClass("pdapp-svg-artwork")
                        ? pdappAPI.artwork.updateValue(e, function (e) {
                              (e.title = t.edit_artwork), p.push(e), "function" == typeof a && a(0, "artwork", p);
                          })
                        : jQuery(e).hasClass("pdapp-svg-photo")
                          ? pdappAPI.photo.updateValue(e, function (e) {
                                (e.title = t.edit_photo), p.push(e), "function" == typeof a && a(0, "photo", p);
                            })
                          : jQuery(e).hasClass("pdapp-team")
                            ? pdappAPI.team.updateValue(e, function (e) {
                                  (e.title = t.edit_team), p.push(e), "function" == typeof a && a(0, "team", p);
                              })
                            : jQuery(e).hasClass("pdapp-svg-qrcode")
                              ? pdappAPI.qrcode.updateValue(e, function (e) {
                                    (e.title = t.edit_qrcode), p.push(e), "function" == typeof a && a(0, "qrcode", p);
                                })
                              : jQuery(e).hasClass("pdapp-svg-barcode") &&
                                pdappAPI.barcode.updateValue(e, function (e) {
                                    (e.title = t.edit_barcode), p.push(e), "function" == typeof a && a(0, "barcode", p);
                                }))
                : e.length > 1
                  ? ("function" == typeof a && a(null, "group", p),
                    (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 a && a(null, "unselect", p);
        },
    },
    group: {
        getGroup: function (e, t) {
            let a = { show: !0, active: "", isGroup: jQuery(e[0]).hasClass("pdapp-group"), colors: [] };
            "function" == typeof t && t(a);
        },
        getColors: function (e, t) {
            if (0 == e.length) return !1;
            for (let a = 0; a < e.length; a++) {
                let p =
                    '<svg x="0" y="0" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
                    e[a].outerHTML +
                    "</svg>";
                getSVGColors(p, { flat: !0 }).then((e) => {
                    "function" == typeof t && t(e);
                });
            }
        },
        selectAll: function (e) {
            let t = [];
            return (
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active g.pdapp-target").each(function () {
                    if (!jQuery(this).hasClass("pdapp-lock") && !jQuery(this).hasClass("pdapp-team")) {
                        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 (a) {
                              "function" == typeof e && e(t, a);
                          })))
            );
        },
        setGroup: function (e, t) {
            let a = pdappAPI.tool.pdappMoveAbleRef.target;
            if (0 == a.length) return !1;
            let p = pdappAPI.tool.uID();
            for (let r = 0; r < a.length; r++) {
                let o = jQuery(a[r]),
                    i = o.attr("id");
                e
                    ? (o.removeClass("pdapp-group"), o.attr("data-group", ""))
                    : (o.addClass("pdapp-group"), o.attr("data-group", p));
                let n = a.length - 1 == r;
                "function" == typeof t && t(i, n);
            }
        },
        copyGroup: function (e, t, a) {
            let p = pdappAPI.tool.pdappMoveAbleRef.target;
            if (0 == p.length || "function" != typeof a) return !1;
            let r = pdappAPI.tool.uID();
            for (let o = 0; o < p.length; o++) {
                let i = jQuery(p[o]),
                    n = i.attr("id"),
                    l = "pdapp-target-" + pdappAPI.tool.uID(),
                    d = p.length - 1 == o,
                    s = i.clone();
                if (e.text.copy && i.hasClass("pdapp-svg-text")) {
                    let e = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active");
                    if (
                        (jQuery(s).attr("id", l),
                        jQuery(s).hasClass("pdapp-group") && jQuery(s).attr("data-group", r),
                        e.find("svg.pdapp-selecto-area").append(s),
                        i.hasClass("pdapp-arc"))
                    ) {
                        let e = jQuery(".pdapp-viewport.active .pdapp-text-arc ." + n)[0].outerHTML;
                        jQuery(".pdapp-viewport.active .pdapp-viewport-area.active .pdapp-text-arc").append(
                            e.replace(n, l)
                        );
                    }
                    a(l, pdappAPI.history.getIndex(jQuery(l)), s, "", d);
                } else
                    e.artwork.copy && i.hasClass("pdapp-svg-artwork")
                        ? a(l, pdappAPI.history.getIndex(jQuery(l)), s, "", d)
                        : e.photo.copy && i.hasClass("pdapp-svg-photo")
                          ? a(l, pdappAPI.history.getIndex(jQuery(l)), s, n, d)
                          : ((e.qrcode.copy && i.hasClass("pdapp-svg-qrcode")) ||
                                (e.barcode.copy && i.hasClass("pdapp-svg-barcode"))) &&
                            a(l, pdappAPI.history.getIndex(jQuery(l)), s, "", d);
                d &&
                    setTimeout(() => {
                        jQuery(".pdapp-btn-copy").append('<i class="text-success">' + t.copied + "</i>"),
                            setTimeout(() => {
                                jQuery(".pdapp-btn-copy .text-success").remove();
                            }, 5e3);
                    }, 1);
            }
        },
        alignGroup: function (e, t, a) {
            let p = this;
            if (0 == t.length || "function" != typeof a) return !1;
            let r = { top: "", left: "" },
                o = { top: "", left: "" };
            if (
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active").length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active div.moveable-area").length
            ) {
                let t = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active")[0].getBoundingClientRect(),
                    a = jQuery(
                        ".pdapp-viewport.active .pdapp-viewport-area.active div.moveable-area"
                    )[0].getBoundingClientRect();
                if (void 0 === t.width || void 0 === a.width || 0 == t.width || 0 == a.width) return !1;
                let p = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                    i = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").attr(
                        "viewBox"
                    );
                if (void 0 !== i) {
                    let e = parseFloat(i.split(" ")[2]),
                        t = parseFloat(i.split(" ")[3]),
                        a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").width(),
                        r = jQuery(
                            ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                        ).height();
                    (parseInt(a / p) == parseInt(e) && parseInt(r / p) == parseInt(t)) ||
                        (p = e / t > a / r ? a / e : r / t);
                }
                (t = JSON.parse(JSON.stringify(t))),
                    (a = JSON.parse(JSON.stringify(a))),
                    (t.width = parseFloat(t.width) / p),
                    (t.height = parseFloat(t.height) / p),
                    (t.top = parseFloat(t.top) / p),
                    (t.left = parseFloat(t.left) / p),
                    (a.width = parseFloat(a.width) / p),
                    (a.height = parseFloat(a.height) / p),
                    (a.top = parseFloat(a.top) / p),
                    (a.left = parseFloat(a.left) / p),
                    "top" == e
                        ? ((r.top = t.top - a.top), (o.top = 0 - r.top))
                        : "right" == e
                          ? ((r.left = t.left + t.width - (a.left + a.width)), (o.left = 0 - r.left))
                          : "bot" == e
                            ? ((r.top = t.top + t.height - (a.top + a.height)), (o.top = 0 - r.top))
                            : "left" == e
                              ? ((r.left = t.left - a.left), (o.left = 0 - r.left))
                              : "centerAll" == e
                                ? ((r.top = t.top - a.top + (t.height - a.height) / 2),
                                  (o.top = 0 - r.top),
                                  (r.left = t.left - a.left + (t.width - a.width) / 2),
                                  (o.left = 0 - r.left))
                                : "middle" == e
                                  ? ((r.top = t.top - a.top + (t.height - a.height) / 2), (o.top = 0 - r.top))
                                  : "center" == e &&
                                    ((r.left = t.left - a.left + (t.width - a.width) / 2), (o.left = 0 - r.left));
            }
            if ("" === r.top && "" === r.left) return !1;
            let i = [];
            for (let e = 0; e < t.length; e++) {
                let n = jQuery(t[e]),
                    l = n.attr("id");
                i.push(l), p.setPos(n, r), t.length - 1 == e && a(i, o, r);
            }
        },
        setPos: function (e, t) {
            let a = pdappAPI.tool.getTransform(e);
            if ("" != a) {
                let p = a.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                "" !== t.top && (p[5] = (parseFloat(p[5]) + t.top).toFixed(3)),
                    "" !== t.left && (p[4] = (parseFloat(p[4]) + t.left).toFixed(3)),
                    e.attr("transform", "matrix(" + p.join(", ") + ")"),
                    e.removeAttr("style");
            }
        },
        moveGroup: function (e, t, a) {
            if (0 == t.length || "function" != typeof a) return !1;
            let p = [];
            for (let a = 0; a < t.length; a++) {
                let r = jQuery(t[a]),
                    o = r.attr("id");
                pdappAPI.tool.move[e](r), p.push(o);
            }
            p.length && a(p);
        },
        deleteGroup: function (e) {
            let t = pdappAPI.tool.pdappMoveAbleRef.target;
            if (0 == t.length || "function" != typeof e) return !1;
            let a = [],
                p = [],
                r = [],
                o = [];
            for (let e = 0; e < t.length; e++) {
                let i = jQuery(t[e]),
                    n = i.attr("id");
                a.push(n),
                    p.push(pdappAPI.history.getIndex(i)),
                    r.push(i.clone()),
                    i.hasClass("pdapp-svg-photo") && o.push({ id: n, value: "" }),
                    i.remove();
            }
            a.length && e(a, p, r, o), (pdappAPI.tool.pdappMoveAbleRef.target = null), (pdappAPI.tool.targets = []);
        },
    },
    tool: {
        uID: function (e) {
            let t = Math.floor(1e3 * Math.random()),
                a = Math.floor(1e5 * Math.random());
            if ("number" == typeof e) {
                let p = "";
                const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
                    o = r.length;
                let i = 0;
                for (; i < e; ) (p += r.charAt(Math.floor(Math.random() * o))), (i += 1);
                return p + "-" + t + "-" + a;
            }
            return t + "-" + a;
        },
        generalAttr: function (e, t) {
            for (let a in e) t.setAttribute(a, e[a]);
            return t;
        },
        generalAttrNS: function (e, t) {
            for (let a in e) t.setAttributeNS(null, a, e[a]);
            return t;
        },
        pdappMoveAbleRef: null,
        pdappSelecToRef: null,
        pdappAblePosition: {},
        getGuideLine: function (e) {
            let t = { ver: [], hor: [] },
                a = jQuery(e)[0].getBoundingClientRect();
            if (0 == a.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(a.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(a.width / e), className: "pdapp-guideline" });
            return t;
        },
        targets: [],
        enableMoveAble: function (e, t, a, p, r) {
            let o = this;
            o.targets = [];
            let i = document.querySelector(".pdapp-viewport.active .pdapp-viewport-area.active"),
                n = {
                    target: o.targets,
                    draggable: !0,
                    edgeDraggable: !1,
                    scalable: !0,
                    keepRatio: !0,
                    renderDirections: ["nw", "n", "ne", "w", "e", "sw", "s", "se"],
                    rotatable: !0,
                    rotationPosition: "top",
                    snappable: !1,
                    pinchable: !0,
                    pinchOutside: !0,
                };
            (o.pdappMoveAbleRef = new Moveable(i, n)),
                o.pdappMoveAbleRef.on("beforeScale", (e) => {
                    e.setFixedDirection([0, 0]);
                }),
                o.pdappMoveAbleRef.on("rotateStart", (e) => {
                    e.setFixedDirection([0, 0]);
                }),
                o.pdappMoveAbleRef.on("render", (t) => {
                    (t.target.style.transform = t.transform), "function" == typeof e && e(t.target), o.setMoveTarget();
                }),
                o.pdappMoveAbleRef.on("scaleStart", (e) => {
                    (o.pdappAblePosition = {}),
                        (o.pdappAblePosition.start = pdappAPI.tool.getTransform(jQuery(e.target)));
                }),
                o.pdappMoveAbleRef.on("scaleEnd", (e) => {
                    let t = jQuery(e.target);
                    (o.pdappAblePosition.end = pdappAPI.tool.getTransform(t)),
                        "function" == typeof a && a(t, o.pdappAblePosition);
                }),
                o.pdappMoveAbleRef.on("dragStart", (e) => {
                    (o.pdappAblePosition = {}),
                        (o.pdappAblePosition.start = pdappAPI.tool.getTransform(jQuery(e.target)));
                }),
                o.pdappMoveAbleRef.on("dragEnd", (e) => {
                    let t = jQuery(e.target),
                        p = pdappAPI.tool.getTransform(t);
                    if ("" != p) {
                        let e = p.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
                        if (6 == e.length) {
                            let a = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                                p = t[0].getBoundingClientRect(),
                                r = jQuery(
                                    ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                                )[0].getBoundingClientRect();
                            if (0 != p.width && 0 != r.width) {
                                let i = jQuery(
                                    ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                                ).attr("viewBox");
                                if (void 0 !== i) {
                                    let e = parseFloat(i.split(" ")[2]),
                                        t = parseFloat(i.split(" ")[3]);
                                    (parseInt(r.width / a) == parseInt(e) && parseInt(r.height / a) == parseInt(t)) ||
                                        (a = e / t > r.width / r.height ? r.width / e : r.height / t);
                                }
                                let n = (p.left - r.left) / a,
                                    l = (p.top - r.top) / a;
                                (parseFloat(e[5]) - l - p.height / a > parseFloat(e[5]) ||
                                    parseFloat(e[4]) - n + r.width / a < parseFloat(e[4]) ||
                                    parseFloat(e[5]) - l + r.height / a < parseFloat(e[5]) ||
                                    parseFloat(e[4]) - n - p.width / a > parseFloat(e[4])) &&
                                    (t.attr("transform", o.pdappAblePosition.start), t.removeAttr("style"));
                            }
                        }
                    }
                    (o.pdappAblePosition.end = pdappAPI.tool.getTransform(t)),
                        "function" == typeof a && a(t, o.pdappAblePosition);
                }),
                o.pdappMoveAbleRef.on("renderGroup", (e) => {
                    e.events.forEach((e) => {
                        e.target.style.transform = e.transform;
                    });
                }),
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active .pdapp-selecto-ref").html(""),
                (o.pdappSelecToRef = new Selecto({
                    container: document.querySelector(
                        ".pdapp-viewport.active .pdapp-viewport-area.active .pdapp-selecto-ref"
                    ),
                    rootContainer: document.querySelector(
                        ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                    ),
                    dragContainer: document.getElementById("pdapp-viewer-area"),
                    selectableTargets: [
                        ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area .pdapp-target",
                    ],
                    hitRate: 5,
                    selectByClick: !0,
                    selectFromInside: !1,
                    toggleContinueSelect: ["shift"],
                    ratio: 0,
                })),
                o.pdappMoveAbleRef.on("clickGroup", (e) => {
                    o.pdappSelecToRef.clickTarget(e.inputEvent, e.inputTarget);
                }),
                o.pdappMoveAbleRef.on("dragGroup", (e) => {
                    e.events.forEach((e) => {
                        e.target.style.transform = e.transform;
                    });
                }),
                o.pdappMoveAbleRef.on("dragGroupStart", (e) => {
                    (o.pdappAblePosition = { start: [], end: [] }),
                        e.targets.forEach((e) => {
                            o.pdappAblePosition.start.push(pdappAPI.tool.getTransform(jQuery(e)));
                        });
                }),
                o.pdappMoveAbleRef.on("dragGroupEnd", (e) => {
                    let t = [];
                    e.targets.forEach((e) => {
                        let a = jQuery(e),
                            p = pdappAPI.tool.getTransform(a);
                        o.pdappAblePosition.end.push(p),
                            a.attr("transform", p),
                            a.removeAttr("style"),
                            t.push(a.attr("id"));
                    }),
                        "function" == typeof r && r(t, o.pdappAblePosition);
                }),
                o.pdappMoveAbleRef.on("scaleGroupStart", (e) => {
                    (o.pdappAblePosition = { start: [], end: [] }),
                        e.targets.forEach((e) => {
                            o.pdappAblePosition.start.push(pdappAPI.tool.getTransform(jQuery(e)));
                        });
                }),
                o.pdappMoveAbleRef.on("scaleGroupEnd", (e) => {
                    let t = [];
                    e.targets.forEach((e) => {
                        let a = jQuery(e),
                            p = pdappAPI.tool.getTransform(a);
                        o.pdappAblePosition.end.push(p),
                            a.attr("transform", p),
                            a.removeAttr("style"),
                            t.push(a.attr("id"));
                    }),
                        "function" == typeof r && r(t, o.pdappAblePosition);
                }),
                o.pdappSelecToRef.on("dragStart", (e) => {
                    const t = o.pdappMoveAbleRef,
                        a = e.inputEvent.target;
                    (t.isMoveableElement(a) ||
                        ("function" == typeof o.targets.some && o.targets.some((e) => e === a || e.contains(a)))) &&
                        ("function" == typeof p && p(e), e.stop());
                }),
                o.pdappSelecToRef.on("selectEnd", (e) => {
                    const a = o.pdappMoveAbleRef;
                    e.isDragStart &&
                        (e.inputEvent.preventDefault(),
                        a.waitToChangeTarget().then(() => {
                            a.dragStart(e.inputEvent);
                        }));
                    let p = e.selected;
                    if (0 == p.length && void 0 !== e.inputEvent.clientX) {
                        document.elementsFromPoint(e.inputEvent.clientX, e.inputEvent.clientY).forEach(function (e, t) {
                            if (0 == p.length) {
                                let t = jQuery(e).parents("g.pdapp-target");
                                t.length && (p = jQuery("#" + t.attr("id")));
                            }
                        });
                    }
                    var r;
                    (r = p),
                        (o.targets = r),
                        (o.pdappMoveAbleRef.target = o.targets),
                        "function" == typeof t && t(o.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"];
                        });
                }),
                o.pdappMoveAbleRef.on("changeTargets", (e) => {
                    o.setMoveTarget();
                });
        },
        setMoveTarget: function () {
            if (1 != jQuery(pdappAPI.tool.pdappMoveAbleRef.target).length) return !1;
            let e = this,
                t = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active .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.active .pdapp-viewport-area.active"),
                        t = pdappAPI.tool.getTransform(jQuery(e.find(".moveable-line.moveable-direction")[0])),
                        a = jQuery(e.find(".moveable-line.moveable-direction")[0]).width(),
                        p = jQuery(e.find(".moveable-line.moveable-direction")[3]).width();
                    e.find(".moveable-movebox").width(a),
                        e.find(".moveable-movebox").height(p),
                        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.active .pdapp-viewport-area.active .moveable-control-box.rCS1w3zcxh"
            ).length;
            e > 1 &&
                ((e -= 1),
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active .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 a = pdappAPI.tool.getTransform(e);
            if ("" == a) return "";
            let p = a.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(",");
            if (6 == p.length) {
                let a = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                    r = e[0].getBoundingClientRect(),
                    o = jQuery(
                        ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                    )[0].getBoundingClientRect();
                if (0 != r.width && 0 != o.width) {
                    let e = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").attr(
                        "viewBox"
                    );
                    if (void 0 !== e) {
                        let t = parseFloat(e.split(" ")[2]),
                            p = parseFloat(e.split(" ")[3]);
                        (parseInt(o.width / a) == parseInt(t) && parseInt(o.height / a) == parseInt(p)) ||
                            (a = t / p > o.width / o.height ? o.width / t : o.height / p);
                    }
                    let i = (r.left - o.left) / a,
                        n = (r.top - o.top) / a;
                    "top" == t && (p[5] = parseFloat(p[5]) - n),
                        "right" == t && (p[4] = parseFloat(p[4]) - i + (o.width - r.width) / a),
                        "left" == t && (p[4] = parseFloat(p[4]) - i),
                        "bot" == t && (p[5] = parseFloat(p[5]) - n + (o.height - r.height) / a),
                        "center" == t && (p[4] = parseFloat(p[4]) - i + (o.width - r.width) / a / 2),
                        "middle" == t && (p[5] = parseFloat(p[5]) - n + (o.height - r.height) / a / 2),
                        "centerAll" == t &&
                            ((p[4] = parseFloat(p[4]) - i + (o.width - r.width) / a / 2),
                            (p[5] = parseFloat(p[5]) - n + (o.height - r.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 a = pdappAPI.tool
                .getTransform(e)
                .replace("matrix(", "")
                .replace(")", "")
                .replaceAll(" ", "")
                .split(",");
            return (
                6 == a.length &&
                    ("top" == t && (a[5] = parseFloat(a[5]) - 1),
                    "bot" == t && (a[5] = parseFloat(a[5]) + 1),
                    "left" == t && (a[4] = parseFloat(a[4]) - 1),
                    "right" == t && (a[4] = parseFloat(a[4]) + 1)),
                "matrix(" + a.join(", ") + ")"
            );
        },
        top: function (e) {
            if (
                e.length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
            ) {
                let t = pdappAPI.tool.getTransformPos(e, "top");
                "" != t && e.attr("transform", t);
            }
        },
        right: function (e) {
            if (
                e.length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
            ) {
                let t = pdappAPI.tool.getTransformPos(e, "right");
                "" != t && e.attr("transform", t);
            }
        },
        bot: function (e) {
            if (
                e.length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active 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.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
            ) {
                let t = pdappAPI.tool.getTransformPos(e, "left");
                "" != t && e.attr("transform", t);
            }
        },
        move: {
            top: function (e) {
                if (
                    e.length &&
                    jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
                ) {
                    let t = pdappAPI.tool.getTransformMove(e, "top");
                    "" != t && e.attr("transform", t);
                }
            },
            bot: function (e) {
                if (
                    e.length &&
                    jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
                ) {
                    let t = pdappAPI.tool.getTransformMove(e, "bot");
                    "" != t && e.attr("transform", t);
                }
            },
            left: function (e) {
                if (
                    e.length &&
                    jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
                ) {
                    let t = pdappAPI.tool.getTransformMove(e, "left");
                    "" != t && e.attr("transform", t);
                }
            },
            right: function (e) {
                if (
                    e.length &&
                    jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
                ) {
                    let t = pdappAPI.tool.getTransformMove(e, "right");
                    "" != t && e.attr("transform", t);
                }
            },
        },
        middle: function (e) {
            if (
                e.length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
            ) {
                let t = pdappAPI.tool.getTransformPos(e, "middle");
                "" != t && e.attr("transform", t);
            }
        },
        center: function (e) {
            if (
                e.length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
            ) {
                let t = pdappAPI.tool.getTransformPos(e, "center");
                "" != t && e.attr("transform", t);
            }
        },
        centerAll: function (e, t) {
            if (
                e.length &&
                jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").length
            ) {
                let a = pdappAPI.tool.getTransformPos(e, "centerAll");
                "" != a && e.attr("transform", a), "function" == typeof t && t();
            }
        },
        colorPicker: function (e, t, a) {
            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 p = t.toHexString();
                    "function" == typeof a && a(e.target, p);
                }),
                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, a) {
            let p = document.createElement("canvas"),
                r = p.getContext("2d"),
                o = document.createElement("img");
            (o.crossOrigin = "anonymous"),
                (o.onload = function () {
                    setTimeout(() => {
                        if (void 0 === a) (p.width = o.width), (p.height = o.height), r.drawImage(o, 0, 0);
                        else {
                            let e = o.width,
                                t = o.height;
                            (o.width > a || o.height > a) &&
                                (o.width > o.height
                                    ? ((e = a), (t = (a * o.height) / o.width))
                                    : ((t = a), (e = (a * o.width) / o.height))),
                                (p.width = e),
                                (p.height = t),
                                r.drawImage(o, 0, 0, e, t);
                        }
                        "function" == typeof t && t(p.toDataURL("image/png"), p.width, p.height),
                            o.remove(),
                            p.remove();
                    }, 100);
                }),
                (o.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 a(e) {
                return (e = parseInt(e)).toString(16).padStart(2, "0");
            }
            return "#" + a(t[0]) + a(t[1]) + a(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 a = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
            return t
                ? 4 == a.length
                    ? { r: parseInt(a[1], 16), g: parseInt(a[2], 16), b: parseInt(a[3], 16) }
                    : { r: 255, g: 255, b: 255 }
                : 4 == a.length
                  ? "rgb(" + parseInt(a[1], 16) + ", " + parseInt(a[2], 16) + ", " + parseInt(a[3], 16) + ")"
                  : "rgb(255, 255, 255)";
        },
        toDate: function (e) {
            let t = new Date(e.replaceAll("-", "/")).toLocaleTimeString(),
                a = e.split(" "),
                p = t.split(" "),
                r = p[0].split(":");
            return void 0 !== p[1] ? a[0] + " " + r[0] + ":" + r[1] + p[1] : e;
        },
        getTime: function () {
            return new Date().getTime();
        },
        checkTime: function (e, t) {
            let a = !1;
            return new Date().getTime() - e > 6e4 * t && (a = !0), a;
        },
        standardArtworkToAi: function (e) {
            let t = e.find("svg");
            if (0 == t.length) return !1;
            let a = ["id", "enable-background"];
            for (let e = 0; e < a.length; e++) t.removeAttr(a[e]);
            void 0 === t.attr("xmlns") && t.attr("xmlns", "http://www.w3.org/2000/svg");
            let p = t.attr("width"),
                r = t.attr("height"),
                o = t.attr("viewBox");
            if (void 0 === p || void 0 === r) {
                if (void 0 !== o) (p = o.split(" ")[2]), (r = o.split(" ")[3]);
                else {
                    let e = t[0].getBBox();
                    (p = e.width), (r = e.height);
                }
                t.attr("width", p + "px"), t.attr("height", r + "px");
            }
            void 0 === o && t.attr("viewBox", [0, 0, p, r].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", a = 300) {
            let p = 0;
            return (
                (p = "in" == t ? parseFloat(e) * a : "cm" == t ? (parseFloat(e) / 2.54) * a : parseFloat(e)),
                parseFloat(p.toFixed(3))
            );
        },
        toCm: function (e = 0, t = "in", a = 300) {
            let p = 0;
            return (
                (p = "in" == t ? 2.54 * parseFloat(e) : "px" == t ? (parseFloat(e) / a) * 2.54 : parseFloat(e)),
                parseFloat(p.toFixed(3))
            );
        },
        toIn: function (e = 0, t = "cm", a = 300) {
            let p = 0;
            return (
                (p = "cm" == t ? parseFloat(e) / 2.54 : "px" == t ? parseFloat(e) / a : parseFloat(e)),
                parseFloat(p.toFixed(3))
            );
        },
        removeEmoij: function (e) {
            return e.replace("/[p{Emoji}]/gu", "");
        },
        setLocalVar: function (e, t) {
            localStorage.setItem(e, t);
        },
        getLocalVar: function (e, t) {
            let a = localStorage.getItem(e);
            return null != a ? a : (void 0 === t && (t = ""), t);
        },
        removeLocalVar: function (e) {
            localStorage.removeItem(e);
        },
        getData: function (e) {
            return new Promise(function (t, a) {
                let p = {
                    method: "GET",
                    url: e,
                    dataType: "json",
                    success: function (e) {
                        0 == e
                            ? a({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? t({ msg: e.msg, data: e.data }) : a({ msg: e.msg, error: e.error }));
                    },
                    error: function (e, t, p) {
                        "" == p && (p = "Request failed"), a({ msg: p, error: 1 });
                    },
                };
                jQuery.ajax(p);
            });
        },
        postData: function (e, t) {
            return new Promise(function (a, p) {
                let r = {
                    method: "POST",
                    url: e,
                    dataType: "json",
                    data: t,
                    success: function (e) {
                        0 == e
                            ? p({ msg: "403 Forbidden", error: 1 })
                            : (void 0 === e.error && (e.error = 1),
                              0 === e.error ? a({ 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(r);
            });
        },
        getLibData: function (e, t) {
            return new Promise(function (a, p) {
                let r = {
                    method: "GET",
                    url: e,
                    dataType: "json",
                    success: function (e) {
                        a(e);
                    },
                    error: function (e, t, a) {
                        "" == a && (a = "Request failed"), p({ msg: a, error: 1 });
                    },
                };
                void 0 !== t && "" != t && (r.headers = { Authorization: t }), jQuery.ajax(r);
            });
        },
        loadFontFace: function (e, t, a) {
            let p = document.createElement("style");
            p.setAttribute("type", "text/css"),
                (p.innerHTML = t),
                (p.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, a, t);
                    }, 500);
                }),
                jQuery("head").append(p);
        },
        loadFontData: async function (e, t) {
            let a =
                pdappAdminUrl +
                "admin-ajax.php?action=pdapp-load-font&admin=0&pdapp-token=" +
                pdappToken +
                "&pdapp-nonce=" +
                pdappNonce;
            try {
                let p = await pdappAPI.tool.postData(a, { title: e });
                "function" == typeof t && t(p.data.fontface);
            } catch (e) {
                t(""),
                    (pdappVueApp.toast = { show: !0, type: "error", text: e.msg }),
                    setTimeout(() => {
                        pdappVueApp.toast.show = !1;
                    }, 5e3);
            }
        },
        loadMore: function (e, t, a) {
            if (0 == jQuery(e).length && (void 0 === a || a < 10)) {
                let p = this;
                return (
                    setTimeout(() => {
                        let r = void 0 === a ? 1 : a + 1;
                        p.loadMore(e, t, r);
                    }, 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, a) {
            const p = e.indexOf(t),
                r = e.indexOf(a, p + t.length);
            return -1 === p || -1 === r ? null : e.substring(p + t.length, r);
        },
        setSvgStyle: function (e) {
            let t = this,
                a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"),
                p = a.find("style").html();
            if (a.length) {
                let r = "",
                    o = {};
                if (void 0 !== p) {
                    let e = p.split("}");
                    for (let a = 0; a < e.length; a++)
                        if ("" != e[a] && 0 == e[a].indexOf("@font-face{")) {
                            let p = t.getStringBetween(e[a], "@font-face{font-family: '", "';src:");
                            (p = p.replaceAll(" ", "+")), (o[p] = void 0 === o[p] ? e[a] + "}" : o[p] + e[a] + "}");
                        }
                }
                a.find("g.pdapp-target").each(function () {
                    if (jQuery(this).hasClass("pdapp-svg-text") || jQuery(this).hasClass("pdapp-team")) {
                        let t = jQuery(this).find("text").attr("font-family");
                        (t = t.replaceAll(" ", "+")), void 0 !== e[t] ? (r += e[t]) : void 0 !== o[t] && (r += o[t]);
                    }
                }),
                    a.find("style").remove(),
                    "" != r && ((r = '<style xmlns="http://www.w3.org/1999/xhtml">' + r + "</style>"), a.prepend(r));
            }
        },
        renderShape: function (e, t, a) {
            let p = [],
                r = e.find("image").width(),
                o = e.find("image").height(),
                i = r,
                n = 0,
                l = (o - r) / 2;
            r > o && ((i = o), (n = (r - o) / 2), (l = 0));
            let d = e.hasClass("pdapp-flip");
            if ("circle" == t.type) {
                let e = i / 2 + n,
                    t = i / 2 + l,
                    a = document.createElementNS("http://www.w3.org/2000/svg", "circle");
                a.setAttributeNS(null, "cx", e.toFixed(2)),
                    a.setAttributeNS(null, "cy", t.toFixed(2)),
                    a.setAttributeNS(null, "r", (i / 2).toFixed(2)),
                    d && a.setAttributeNS(null, "transform", "scale(-1, 1)"),
                    p.push(a);
            } else if ("rect" == t.type) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "rect");
                e.setAttributeNS(null, "width", i.toFixed(2)),
                    e.setAttributeNS(null, "height", i.toFixed(2)),
                    e.setAttributeNS(null, "x", n.toFixed(2)),
                    e.setAttributeNS(null, "y", l.toFixed(2)),
                    d && e.setAttributeNS(null, "transform", "scale(-1, 1)"),
                    p.push(e);
            } else {
                let e = t.value.size,
                    a = parseFloat(e.width),
                    i = parseFloat(e.height),
                    n = 1,
                    l = 0,
                    s = 0;
                r / o > a / i ? ((n = o / i), (l = (r - a * n) / 2)) : ((n = r / a), (s = (o - i * n) / 2));
                let c = n;
                d && ((c = -1 * n), (l *= -1));
                let u = "matrix(" + c + ", 0, 0, " + n + ", " + l + ", " + s + ")",
                    h = t.value.paths;
                for (let e = 0; e < h.length; e++) {
                    let t = document.createElementNS("http://www.w3.org/2000/svg", "path");
                    t.setAttributeNS(null, "d", h[e]), t.setAttributeNS(null, "transform", u), p.push(t);
                }
            }
            if (p.length) {
                let e = document.createElementNS("http://www.w3.org/2000/svg", "clipPath");
                e.setAttributeNS(null, "id", a);
                for (let t = 0; t < p.length; t++) e.appendChild(p[t]);
                return e;
            }
            return "";
        },
        getColors: function (e, t) {
            let a =
                '<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(a, { 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,
                        a = 0,
                        p = 1,
                        r = "px",
                        o = {},
                        i = [],
                        n = 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 a = "rotate(" + t + "deg)",
                                                p =
                                                    pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                        Math.abs(parseInt(e.canvas.style.left))
                                                    ) + " 0px";
                                            (e.canvas.style.webkitTransform = a),
                                                (e.canvas.style.MozTransform = a),
                                                (e.canvas.style.OTransform = a),
                                                (e.canvas.style.msTransform = a),
                                                (e.canvas.style.transform = a),
                                                (e.canvas.style.webkitTransformOrigin = p),
                                                (e.canvas.style.MozTransformOrigin = p),
                                                (e.canvas.style.OTransformOrigin = p),
                                                (e.canvas.style.msTransformOrigin = p),
                                                (e.canvas.style.transformOrigin = p);
                                        })(e, 270);
                            }
                        },
                        c = function (o, l, d, s, c) {
                            var u,
                                h = document.createElement("div"),
                                g = 1 === o ? "pdapp-ruler-line-ver" : "pdapp-ruler-line-hor",
                                f = 1 === o ? t : a;
                            (h.title = "Double click to delete"),
                                pdappAPI.tool.ruler.prototype.utils.addClasss(h, ["pdapp-ruler-line", g]),
                                (h = n.appendChild(h)),
                                1 === o
                                    ? ((h.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          l - e.container.getBoundingClientRect().left
                                      )),
                                      c &&
                                          (h.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              Math.round(l / p) + e.rulerHeight
                                          )))
                                    : ((h.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          d - e.container.getBoundingClientRect().top
                                      )),
                                      c &&
                                          (h.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              Math.round(d / p) + e.rulerHeight
                                          ))),
                                i.push({
                                    dimension: o,
                                    line: pdappAPI.tool.ruler.prototype.guideLine(
                                        h,
                                        e.container.querySelector(".pdapp-ruler-box"),
                                        o,
                                        e,
                                        f,
                                        function (t, a, p) {
                                            var r = 1 === t.dimension ? a : p;
                                            if (!t.assigned()) return r > e.rulerHeight && t.assigned(!0), !1;
                                            r < e.rulerHeight &&
                                                (i.some(function (e, a) {
                                                    if (e.line === t) return (u = a), !0;
                                                }),
                                                t.destroy(),
                                                i.splice(u, 1));
                                        },
                                        s,
                                        p,
                                        r
                                    ),
                                });
                        },
                        u = function (t, a) {
                            var p,
                                r,
                                i,
                                n = "left" === a || "right" === a ? 1 : 2,
                                l = 1 === n ? "pdapp-ruler-vertical" : "pdapp-ruler-horizontal",
                                d = document.createElement("canvas");
                            pdappAPI.tool.ruler.prototype.utils.addClasss(d, [
                                "pdapp-ruler",
                                l,
                                "pdapp_ruLer_align_" + a,
                            ]),
                                (p = t.appendChild(d)),
                                (o[a] = pdappAPI.tool.ruler.prototype.rulerConstructor(p, e, n)),
                                o[a].drawRuler(t.offsetWidth, e.rulerHeight),
                                s(o[a], a),
                                (r = o[a]),
                                (i = function (e) {
                                    c(r.dimension, e.clientX, e.clientY, e);
                                }),
                                r.canvas.addEventListener("mousedown", i),
                                (r.clearListeners = function () {
                                    r.canvas.removeEventListener("mousedown", i);
                                });
                        },
                        h = (function () {
                            function t(e) {
                                e.stopPropagation(), v();
                            }
                            return function (a, p) {
                                p.forEach(function (p) {
                                    var r = (function (t, a) {
                                        var p = document.createElement("div"),
                                            r = "pdapp-ruler-corner" + a.toUpperCase();
                                        p.setAttribute("class", "tooltip-right"),
                                            p.setAttribute("data-tooltip", pdappAPI.tool.ruler.clear_gtitle);
                                        var o = document.createElement("i");
                                        return (
                                            o.setAttribute("class", "material-icons material-symbols-outlined"),
                                            (o.innerHTML = "close"),
                                            p.appendChild(o),
                                            pdappAPI.tool.ruler.prototype.utils.addClasss(p, ["pdapp-ruler-corner", r]),
                                            (p.style.width = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                e.rulerHeight
                                            )),
                                            (p.style.height = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                e.rulerHeight
                                            )),
                                            t.appendChild(p)
                                        );
                                    })(a, p);
                                    r.addEventListener("mousedown", t),
                                        (r.destroy = function () {
                                            r.removeEventListener("mousedown", t), r.parentNode.removeChild(r);
                                        }),
                                        l.push(r);
                                });
                            };
                        })(),
                        g = function (e) {
                            i.forEach(function (e) {
                                e.line.stopDrag();
                            });
                        },
                        f = function (e) {
                            var t = 0;
                            for (var a in o) o.hasOwnProperty(a) && e(o[a], t++);
                        },
                        v = function () {
                            i.forEach(function (e) {
                                e.line.destroy();
                            }),
                                (i = []);
                        };
                    return {
                        VERTICAL: 1,
                        HORIZONTAL: 2,
                        setPos: function (e) {
                            var p,
                                r = 0,
                                o = 0,
                                n = 0;
                            f(function (t) {
                                1 === t.dimension
                                    ? ((p = t.canvas.style.top),
                                      (t.canvas.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          t.orgPos + parseInt(e.y)
                                      )),
                                      (n = parseInt(p) - parseInt(t.canvas.style.top)))
                                    : ((r = t.canvas.style.left),
                                      (t.canvas.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                          t.orgPos + parseInt(e.x)
                                      )),
                                      (o = parseInt(r) - parseInt(t.canvas.style.left)));
                            }),
                                i.forEach(function (t) {
                                    2 === t.dimension
                                        ? ((t.line.guideLine.style.top = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              parseInt(t.line.guideLine.style.top) - n
                                          )),
                                          t.line.curPosDelta(parseInt(e.y)))
                                        : ((t.line.guideLine.style.left = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                              parseInt(t.line.guideLine.style.left) - o
                                          )),
                                          t.line.curPosDelta(parseInt(e.x)));
                                }),
                                (t = parseInt(e.x)),
                                (a = parseInt(e.y));
                        },
                        setScale: function (o, n) {
                            let l = p != o;
                            var d, s, c;
                            f(function (e) {
                                e.context.clearRect(0, 0, e.canvas.width, e.canvas.height),
                                    e.context.beginPath(),
                                    e.setScale(o),
                                    e.context.stroke(),
                                    (p = o),
                                    void 0 !== n && (r = n);
                            }),
                                i.forEach(function (p) {
                                    2 === p.dimension
                                        ? (l &&
                                              ((d = parseInt(p.line.guideLine.style.top)),
                                              (s = e.rulerHeight + 1),
                                              (c = parseFloat(o) / p.line.curScale()),
                                              (p.line.guideLine.style.top =
                                                  pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                      (d - s - a) / c + s + a
                                                  )),
                                              p.line.curScale(o)),
                                          void 0 !== n && p.line.curUnit(n))
                                        : (l &&
                                              ((d = parseInt(p.line.guideLine.style.left)),
                                              (s = e.rulerHeight + 1),
                                              (c = parseFloat(o) / p.line.curScale()),
                                              (p.line.guideLine.style.left =
                                                  pdappAPI.tool.ruler.prototype.utils.pixelize(
                                                      (d - s - t) / c + s + t
                                                  )),
                                              p.line.curScale(o)),
                                          void 0 !== n && p.line.curUnit(n));
                                });
                        },
                        clearGuides: v,
                        getGuides: function () {
                            return i.map(function (r) {
                                return {
                                    posX: Math.round((parseInt(r.line.guideLine.style.left) - t - e.rulerHeight) * p),
                                    posY: Math.round((parseInt(r.line.guideLine.style.top) - a - e.rulerHeight) * p),
                                    dimension: r.dimension,
                                };
                            });
                        },
                        setGuides: function (e) {
                            if (!e) return !1;
                            e.forEach(function (e) {
                                c(e.dimension, e.posX, e.posY, null, !0);
                            });
                        },
                        constructRulers: function (t) {
                            (n = pdappAPI.tool.ruler.prototype.utils.addClasss(n, "pdapp-ruler-box")),
                                (e = pdappAPI.tool.ruler.prototype.utils.extend(d, t)),
                                (n = e.container.appendChild(n)),
                                e.sides.forEach(function (e) {
                                    u(n, e);
                                }),
                                h(n, e.cornerSides),
                                e.container.addEventListener("mouseup", g);
                        },
                        toggleRulerVisibility: function (t) {
                            var a = t ? "block" : "none";
                            n.style.display = a;
                            var p = e.container.querySelectorAll(".pdapp-ruler-tracker");
                            p.length > 0 && ((p[0].style.display = a), (p[1].style.display = a));
                        },
                        toggleGuideVisibility: function (e) {
                            var t = e ? "show" : "hide";
                            i.forEach(function (e) {
                                e.line[t]();
                            });
                        },
                        destroy: function () {
                            v(),
                                f(function (e) {
                                    pdappAPI.tool.ruler.destroy();
                                }),
                                l.forEach(function (e) {
                                    e.destroy();
                                }),
                                e.container.removeEventListener("mouseup", g),
                                n.parentNode.removeChild(n);
                        },
                    };
                },
                rulerConstructor: function (e, t, a) {
                    var p = e,
                        r = p.getContext("2d"),
                        o = 0,
                        i = 0,
                        n = 1,
                        l = a || 2,
                        d = document.createElement("div");
                    r.imageSmoothingEnabled = !1;
                    var s = function () {
                            for (var e = 0, a = "", p = 0, l = !1, d = o / 1.5, s = o / 1.5, c = 0; c <= i; c += 1)
                                (l = !1),
                                    (a = ""),
                                    (p = i / 2 - c) % 50 == 0
                                        ? ((e = 0), (a = (Math.abs(p) * n).toFixed(1)), (l = !0))
                                        : p % 25 == 0
                                          ? ((e = d), (l = !0))
                                          : p % 5 == 0 && ((e = s), (l = !0)),
                                    l &&
                                        (r.moveTo(c + 0.5, o + 0.5),
                                        r.lineTo(c + 0.5, e + 0.5),
                                        r.fillText(a, c + 1.5, o / 2 + 1),
                                        (r.fillStyle = t.textColor));
                        },
                        c = 0,
                        u = 0,
                        h = function (e) {
                            if (((xPos = e.clientX + c), (yPos = e.clientY + u), 2 === l)) {
                                let e = jQuery("#pdapp-viewer-area")[0].scrollWidth - 2,
                                    a = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                        xPos - parseInt(t.container.getBoundingClientRect().left)
                                    );
                                d.style.left = parseInt(a.replace("px", "")) > e ? e + "px" : a;
                            } else {
                                let e = jQuery("#pdapp-viewer-area")[0].scrollHeight - 2,
                                    a = pdappAPI.tool.ruler.prototype.utils.pixelize(
                                        yPos - parseInt(t.container.getBoundingClientRect().top)
                                    );
                                d.style.top = parseInt(a.replace("px", "")) > e ? e : a;
                            }
                        };
                    jQuery(t.container).scroll(function (e) {
                        u != jQuery(t.container).scrollTop() && (u = jQuery(t.container).scrollTop()),
                            c != jQuery(t.container).scrollLeft() && (c = 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", h);
                            })(),
                        {
                            getLength: function () {
                                return i;
                            },
                            getThickness: function () {
                                return o;
                            },
                            getScale: function () {
                                return n;
                            },
                            setScale: function (e) {
                                return (n = parseFloat(e)), s(), n;
                            },
                            dimension: l,
                            orgPos: 0,
                            canvas: p,
                            context: r,
                            drawRuler: function (e, a, l) {
                                (i = p.width = 8 * e),
                                    (o = p.height = a),
                                    (n = l || n),
                                    (r.strokeStyle = t.strokeStyle),
                                    (r.font = t.fontSize + " " + t.fontFamily),
                                    (r.lineWidth = t.lineWidth),
                                    (r.imageSmoothingEnabled = !1),
                                    r.beginPath(),
                                    s(),
                                    r.stroke();
                            },
                            drawPoints: s,
                            destroy: function () {
                                t.container.removeEventListener("mousemove", h),
                                    d.parentNode.removeChild(d),
                                    this.clearListeners && this.clearListeners();
                            },
                        }
                    );
                },
                guideLine: function (e, t, a, p, r, o, i, n, l) {
                    var d,
                        s = e,
                        c = n,
                        u = !1,
                        h = r || 0,
                        g = t,
                        f = a || 2,
                        v =
                            ((o = o || 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)),
                                        o(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,
                                        a = e ? e.clientY : 0,
                                        r = parseInt(s.style.top || 0),
                                        o = parseInt(s.style.left || 0),
                                        i = parseInt(s.offsetWidth),
                                        n = parseInt(s.offsetHeight),
                                        l = parseInt(g.offsetWidth),
                                        d = parseInt(g.offsetHeight),
                                        c = 2 === f ? "ns-resize" : "ew-resize";
                                    (p.container.style.cursor = c), (s.style.cursor = c);
                                    var u = t - o,
                                        h = a - r;
                                    document.onmousemove = function (e) {
                                        var t = (e = e || window.event).clientX,
                                            a = e.clientY,
                                            p = t - u,
                                            r = a - h;
                                        p < 0 && (p = 0),
                                            r < 0 && (r = 0),
                                            p + i > l && (p = l - i),
                                            r + n > d && (r = d - n),
                                            v.move(p, r);
                                    };
                                },
                                stopMoving: function () {
                                    (p.container.style.cursor = null),
                                        (s.style.cursor = null),
                                        (document.onmousemove = function () {}),
                                        pdappAPI.tool.ruler.prototype.utils.removeClasss(s, [
                                            "pdapp-ruler-line-dragged",
                                        ]);
                                },
                            }),
                        m = function () {
                            v.stopMoving(),
                                (o = null),
                                s.removeEventListener("mousedown", y),
                                s.removeEventListener("mouseup", w),
                                s.removeEventListener("dblclick", x),
                                s.parentNode && s.parentNode.removeChild(s);
                        },
                        y = function (e) {
                            e.stopPropagation(), v.startMoving();
                        },
                        w = function (e) {
                            v.stopMoving();
                        },
                        x = function (e) {
                            e.stopPropagation(), m();
                        };
                    return (
                        s.addEventListener("mousedown", y),
                        s.addEventListener("mouseup", w),
                        s.addEventListener("dblclick", x),
                        i && v.startMoving(i),
                        (d = {
                            setAsDraggable: v,
                            startDrag: v.startMoving,
                            stopDrag: v.stopMoving,
                            destroy: m,
                            curScale: function (e) {
                                return void 0 === e ? c : (c = e);
                            },
                            curUnit: l,
                            assigned: function (e) {
                                return void 0 === e ? u : (u = e);
                            },
                            curPosDelta: function (e) {
                                return void 0 === e ? h : (h = e);
                            },
                            guideLine: s,
                            dimension: f,
                            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 a = e.className;
                        return (
                            t instanceof Array || (t = [t]),
                            t.forEach(function (e) {
                                a = a.replace(e, "");
                            }),
                            (e.className = a),
                            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) {
                void 0 !== pdappAPI.tool.ruler.update.toggleRulerVisibility &&
                    pdappAPI.tool.ruler.update.toggleRulerVisibility(e);
            },
        },
        toProductPX: function (e) {
            if (void 0 !== e.unit.type)
                for (let t = 0; t < e.views.length; t++) {
                    if (
                        ((e.views[t].canvas.width = pdappAPI.tool.toPx(e.views[t].canvas.width, e.unit.type)),
                        (e.views[t].canvas.height = pdappAPI.tool.toPx(e.views[t].canvas.height, e.unit.type)),
                        e.views[t].backgrounds.length)
                    )
                        for (let a = 0; a < e.views[t].backgrounds.length; a++)
                            (e.views[t].backgrounds[a].width = pdappAPI.tool.toPx(
                                e.views[t].backgrounds[a].width,
                                e.unit.type
                            )),
                                (e.views[t].backgrounds[a].height = pdappAPI.tool.toPx(
                                    e.views[t].backgrounds[a].height,
                                    e.unit.type
                                )),
                                (e.views[t].backgrounds[a].top = pdappAPI.tool.toPx(
                                    e.views[t].backgrounds[a].top,
                                    e.unit.type
                                )),
                                (e.views[t].backgrounds[a].left = pdappAPI.tool.toPx(
                                    e.views[t].backgrounds[a].left,
                                    e.unit.type
                                ));
                    if (e.views[t].layers.length)
                        for (let a = 0; a < e.views[t].layers.length; a++)
                            (e.views[t].layers[a].width = pdappAPI.tool.toPx(e.views[t].layers[a].width, e.unit.type)),
                                (e.views[t].layers[a].height = pdappAPI.tool.toPx(
                                    e.views[t].layers[a].height,
                                    e.unit.type
                                )),
                                (e.views[t].layers[a].top = pdappAPI.tool.toPx(e.views[t].layers[a].top, e.unit.type)),
                                (e.views[t].layers[a].left = pdappAPI.tool.toPx(
                                    e.views[t].layers[a].left,
                                    e.unit.type
                                ));
                    (e.views[t].mask.width = pdappAPI.tool.toPx(e.views[t].mask.width, e.unit.type)),
                        (e.views[t].mask.height = pdappAPI.tool.toPx(e.views[t].mask.height, e.unit.type));
                }
            return e;
        },
        getAutoZoom: function (e, t, a, p) {
            let r = parseFloat(e.canvas.width),
                o = parseFloat(e.canvas.height),
                i = this.getSizeScreen(),
                n = i.width,
                l = i.height;
            "desktop" == p.screenSize || "tablet" == p.screenSize
                ? ((n -= jQuery(".pdapp-left-layout").width() + jQuery(".pdapp-right-layout").width()),
                  (l -= jQuery(".pdapp-topbar-layout").height() + 6))
                : "mobile" == p.screenSize && "hor" == p.position
                  ? (n -= jQuery(".pdapp-left-layout").width() + jQuery(".pdapp-topbar-layout").width())
                  : "mobile" == p.screenSize &&
                    "ver" == p.position &&
                    (l -= jQuery(".pdapp-left-layout").height() + jQuery(".pdapp-topbar-layout").height());
            let d = n < 0 || l < 0;
            n < 0 && (n = i.width - 40),
                l < 0 && (l = i.height - 95),
                jQuery(".pdapp-center-layout").width(n),
                jQuery(".pdapp-center-layout").height(l);
            let s = jQuery("#pdapp-studio"),
                c = 12;
            p.width >= 992 && (c = 38);
            let u = parseFloat((n - c).toFixed(3)),
                h = parseFloat((s.height() - c).toFixed(3)),
                g = parseFloat(s.attr("data-width")),
                f = parseFloat(s.attr("data-height"));
            (0 == g || 0 == f || d) &&
                ((g = s.width() - (c + 2)),
                (f = s.height() - (c + 2)),
                s.attr("data-width", g),
                s.attr("data-height", f)),
                r / o > u / h
                    ? ("fit" == t.zoom &&
                          ((newSizeW = s.width() - (c + 2)), (t.zoom = Math.floor((newSizeW / g) * 100))),
                      (g = (g * t.zoom) / 100),
                      (t.ratio = g / r))
                    : ("fit" == t.zoom &&
                          ((newSizeH = s.height() - (c + 2)), (t.zoom = Math.floor((newSizeH / f) * 100))),
                      (f = (f * t.zoom) / 100),
                      (t.ratio = f / o));
            let v = r * t.ratio,
                m = r * t.ratio,
                y = p.width >= 992 ? { left: 26, top: 26 } : { left: 0, top: 0 },
                w = jQuery("#pdapp-studio").width(),
                x = jQuery("#pdapp-studio").height();
            return (
                w > v && (y.left = (w - y.left - v) / 2 + y.left),
                x > m && (y.top = (x - y.top - m) / 2 + y.top),
                y.top < 0 && (y.top = 0),
                y.left < 0 && (y.left = 0),
                jQuery(".pdapp-ruler-tracker").css({ top: 0, left: 0 }),
                p.width >= 992 &&
                    !pdappAPI.tool.ruler.added &&
                    ((pdappAPI.tool.ruler.added = !0),
                    setTimeout(() => {
                        pdappAPI.tool.ruler.setup("#pdapp-viewer-area");
                    }, 3)),
                setTimeout(() => {
                    let e = jQuery("#pdapp-viewer-area .pdapp-viewport.active");
                    if (e.length) {
                        let r = jQuery("#pdapp-viewer-area");
                        (u = r.width()), (h = r.height()), v > u && (u = v + 26), m > h && (h = m + 26);
                        let o = Math.round((u - r.width()) / 2);
                        r.scrollLeft(o + 13);
                        let i = Math.round((h - r.height()) / 2);
                        if ((r.scrollTop(i + 13), p.width >= 992)) {
                            let p = parseFloat(a.top) * t.ratio - 20,
                                n = parseFloat(a.left) * t.ratio - 20,
                                l = parseFloat(a.width) * t.ratio;
                            (p += parseFloat(e.css("top").replace("px", ""))),
                                (n += parseFloat(e.css("left").replace("px", ""))),
                                v >= u && (n -= 2),
                                m >= h && (p -= 2),
                                pdappAPI.tool.ruler.setPos({ x: n, y: p });
                            let d = 1;
                            (d =
                                "cm" == t.type
                                    ? pdappAPI.tool.toCm(a.width, "px") / l
                                    : "in" == t.type
                                      ? pdappAPI.tool.toIn(a.width, "px") / l
                                      : a.width / l),
                                pdappAPI.tool.ruler.setScale(d, t.type),
                                pdappAPI.tool.ruler.setShow(jQuery("#pdapp-rulerbar").hasClass("active")),
                                r.find(".pdapp-ruler-box").width(u),
                                jQuery(".pdapp-ruler.pdapp-ruler-vertical").css("left", o),
                                jQuery(".pdapp-ruler-corner.pdapp-ruler-cornerTOPLEFT").css("left", o),
                                jQuery(jQuery("#pdapp-viewer-area .pdapp-ruler-tracker")[1]).css("left", o),
                                r.find(".pdapp-ruler-box").height(h),
                                jQuery(".pdapp-ruler.pdapp-ruler-horizontal").css("top", i),
                                jQuery(".pdapp-ruler-corner.pdapp-ruler-cornerTOPLEFT").css("top", i),
                                jQuery(jQuery("#pdapp-viewer-area .pdapp-ruler-tracker")[0]).css("top", i);
                        }
                    }
                    pdappAPI.tool.responsiveCart();
                }, 5),
                (y.unit = t),
                y
            );
        },
        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, a, p, r) {
            let o = a.unit,
                i = e.target.value;
            for (let e = 0; e < a.views.length; e++)
                if ("unit" == t) {
                    if (a.views[e].backgrounds.length)
                        for (let t = 0; t < a.views[e].backgrounds.length; t++)
                            "px" == i
                                ? ((a.views[e].backgrounds[t].width = pdappAPI.tool.toPx(
                                      a.views[e].backgrounds[t].width,
                                      o.type
                                  )),
                                  (a.views[e].backgrounds[t].height = pdappAPI.tool.toPx(
                                      a.views[e].backgrounds[t].height,
                                      o.type
                                  )),
                                  (a.views[e].backgrounds[t].top = pdappAPI.tool.toPx(
                                      a.views[e].backgrounds[t].top,
                                      o.type
                                  )),
                                  (a.views[e].backgrounds[t].left = pdappAPI.tool.toPx(
                                      a.views[e].backgrounds[t].left,
                                      o.type
                                  )))
                                : "cm" == i
                                  ? ((a.views[e].backgrounds[t].width = pdappAPI.tool.toCm(
                                        a.views[e].backgrounds[t].width,
                                        o.type
                                    )),
                                    (a.views[e].backgrounds[t].height = pdappAPI.tool.toCm(
                                        a.views[e].backgrounds[t].height,
                                        o.type
                                    )),
                                    (a.views[e].backgrounds[t].top = pdappAPI.tool.toCm(
                                        a.views[e].backgrounds[t].top,
                                        o.type
                                    )),
                                    (a.views[e].backgrounds[t].left = pdappAPI.tool.toCm(
                                        a.views[e].backgrounds[t].left,
                                        o.type
                                    )))
                                  : ((a.views[e].backgrounds[t].width = pdappAPI.tool.toIn(
                                        a.views[e].backgrounds[t].width,
                                        o.type
                                    )),
                                    (a.views[e].backgrounds[t].height = pdappAPI.tool.toIn(
                                        a.views[e].backgrounds[t].height,
                                        o.type
                                    )),
                                    (a.views[e].backgrounds[t].top = pdappAPI.tool.toIn(
                                        a.views[e].backgrounds[t].top,
                                        o.type
                                    )),
                                    (a.views[e].backgrounds[t].left = pdappAPI.tool.toIn(
                                        a.views[e].backgrounds[t].left,
                                        o.type
                                    )));
                    if (
                        ("px" == i
                            ? ((a.views[e].canvas.width = pdappAPI.tool.toPx(a.views[e].canvas.width, o.type)),
                              (a.views[e].canvas.height = pdappAPI.tool.toPx(a.views[e].canvas.height, o.type)),
                              (a.views[e].mask.width = pdappAPI.tool.toPx(a.views[e].mask.width, o.type)),
                              (a.views[e].mask.height = pdappAPI.tool.toPx(a.views[e].mask.height, o.type)))
                            : "cm" == i
                              ? ((a.views[e].canvas.width = pdappAPI.tool.toCm(a.views[e].canvas.width, o.type)),
                                (a.views[e].canvas.height = pdappAPI.tool.toCm(a.views[e].canvas.height, o.type)),
                                (a.views[e].mask.width = pdappAPI.tool.toCm(a.views[e].mask.width, o.type)),
                                (a.views[e].mask.height = pdappAPI.tool.toCm(a.views[e].mask.height, o.type)))
                              : ((a.views[e].canvas.width = pdappAPI.tool.toIn(a.views[e].canvas.width, o.type)),
                                (a.views[e].canvas.height = pdappAPI.tool.toIn(a.views[e].canvas.height, o.type)),
                                (a.views[e].mask.width = pdappAPI.tool.toIn(a.views[e].mask.width, o.type)),
                                (a.views[e].mask.height = pdappAPI.tool.toIn(a.views[e].mask.height, o.type))),
                        a.views[e].layers.length)
                    )
                        for (let t = 0; t < a.views[e].layers.length; t++)
                            "px" == i
                                ? ((a.views[e].layers[t].width = pdappAPI.tool.toPx(
                                      a.views[e].layers[t].width,
                                      o.type
                                  )),
                                  (a.views[e].layers[t].height = pdappAPI.tool.toPx(
                                      a.views[e].layers[t].height,
                                      o.type
                                  )),
                                  (a.views[e].layers[t].top = pdappAPI.tool.toPx(a.views[e].layers[t].top, o.type)),
                                  (a.views[e].layers[t].left = pdappAPI.tool.toPx(a.views[e].layers[t].left, o.type)))
                                : "cm" == i
                                  ? ((a.views[e].layers[t].width = pdappAPI.tool.toCm(
                                        a.views[e].layers[t].width,
                                        o.type
                                    )),
                                    (a.views[e].layers[t].height = pdappAPI.tool.toCm(
                                        a.views[e].layers[t].height,
                                        o.type
                                    )),
                                    (a.views[e].layers[t].top = pdappAPI.tool.toCm(a.views[e].layers[t].top, o.type)),
                                    (a.views[e].layers[t].left = pdappAPI.tool.toCm(a.views[e].layers[t].left, o.type)))
                                  : ((a.views[e].layers[t].width = pdappAPI.tool.toIn(
                                        a.views[e].layers[t].width,
                                        o.type
                                    )),
                                    (a.views[e].layers[t].height = pdappAPI.tool.toIn(
                                        a.views[e].layers[t].height,
                                        o.type
                                    )),
                                    (a.views[e].layers[t].top = pdappAPI.tool.toIn(a.views[e].layers[t].top, o.type)),
                                    (a.views[e].layers[t].left = pdappAPI.tool.toIn(
                                        a.views[e].layers[t].left,
                                        o.type
                                    )));
                } else if (p == e) {
                    let p = a.views[e].layers[r].width,
                        o = p / a.views[e].layers[r].height;
                    i = parseFloat(i);
                    let n = i;
                    "height" == t && (n = i * o);
                    let l = n / p;
                    if (a.views[e].backgrounds.length)
                        for (let t = 0; t < a.views[e].backgrounds.length; t++)
                            (a.views[e].backgrounds[t].width = parseFloat(
                                (parseFloat(a.views[e].backgrounds[t].width) * l).toFixed(3)
                            )),
                                (a.views[e].backgrounds[t].height = parseFloat(
                                    (parseFloat(a.views[e].backgrounds[t].height) * l).toFixed(3)
                                )),
                                (a.views[e].backgrounds[t].top = parseFloat(
                                    (parseFloat(a.views[e].backgrounds[t].top) * l).toFixed(3)
                                )),
                                (a.views[e].backgrounds[t].left = parseFloat(
                                    (parseFloat(a.views[e].backgrounds[t].left) * l).toFixed(3)
                                ));
                    (a.views[e].canvas.width = parseFloat((parseFloat(a.views[e].canvas.width) * l).toFixed(3))),
                        (a.views[e].canvas.height = parseFloat((parseFloat(a.views[e].canvas.height) * l).toFixed(3))),
                        (a.views[e].mask.width = parseFloat((parseFloat(a.views[e].mask.width) * l).toFixed(3))),
                        (a.views[e].mask.height = parseFloat((parseFloat(a.views[e].mask.height) * l).toFixed(3)));
                    for (let t = 0; t < a.views[e].layers.length; t++)
                        (a.views[e].layers[t].width = parseFloat(
                            (parseFloat(a.views[e].layers[t].width) * l).toFixed(3)
                        )),
                            (a.views[e].layers[t].height = parseFloat(
                                (parseFloat(a.views[e].layers[t].height) * l).toFixed(3)
                            )),
                            (a.views[e].layers[t].top = parseFloat(
                                (parseFloat(a.views[e].layers[t].top) * l).toFixed(3)
                            )),
                            (a.views[e].layers[t].left = parseFloat(
                                (parseFloat(a.views[e].layers[t].left) * l).toFixed(3)
                            ));
                }
            return "unit" == t && (a.unit.type = i), a;
        },
        getSizeScreen: function () {
            let e = {};
            (e.width = jQuery("#productdesignerapp-wrapper").width()),
                (e.height = jQuery("#productdesignerapp-wrapper").height());
            let t = jQuery(window).width(),
                a = jQuery(window).height();
            t <= e.width && (e.width = t), a <= e.height && (e.height = a);
            let p = jQuery("#productdesignerapp-wrapper").position();
            return (e.width = e.width - p.left), (e.height = e.height - p.top), e;
        },
        responsiveLayout: function () {
            let e = this.getSizeScreen();
            return (
                (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.showCart = e.width >= 1400),
                (e.showMenu = e.width >= 992),
                e
            );
        },
        responsiveDropdown: function (e, t) {
            if (t.showMenu) {
                let t = jQuery(".pdapp-menu-options")[0].getBoundingClientRect(),
                    a = jQuery(".pdapp-" + e.type + "-type-" + e.dropdown),
                    p = jQuery(".pdapp-menu-options-dropdown.pdapp-" + e.type + "-dropdown-" + e.dropdown);
                if (0 == a.length || 0 == p.length) return !1;
                let r = a[0].getBoundingClientRect();
                if (void 0 !== r.top) {
                    p.find(".pdapp-dropdown-box").attr("style", "max-height: unset");
                    let e = r.top - t.top + r.height + 5;
                    e < 0 && (e = 0);
                    let a = t.height - (e + 20);
                    p.find(".pdapp-dropdown-box").height() > a
                        ? p.addClass("show-scroll")
                        : p.removeClass("show-scroll"),
                        p.find(".pdapp-dropdown-box").attr("style", "max-height: " + a + "px"),
                        p.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(),
                            a = jQuery(".pdapp-" + e.type + "-type-" + e.dropdown),
                            p = jQuery(".pdapp-menu-options-dropdown.pdapp-" + e.type + "-dropdown-" + e.dropdown);
                        if (0 == a.length || 0 == p.length) return !1;
                        let r = a[0].getBoundingClientRect();
                        if (void 0 !== r.top) {
                            p.find(".pdapp-dropdown-box").attr("style", "max-height: unset");
                            let e = r.top - t.top + r.height + 5;
                            e < 0 && (e = 0);
                            let a = t.height - (e + 20);
                            p.find(".pdapp-dropdown-box").height() > a
                                ? p.addClass("show-scroll")
                                : p.removeClass("show-scroll"),
                                p.find(".pdapp-dropdown-box").attr("style", "max-height: " + a + "px"),
                                p.attr("style", "top: " + e + "px;");
                        }
                    });
            } else {
                if (0 == jQuery(".pdapp-menu-mobile-body").length) return !1;
                let a = jQuery(".pdapp-menu-mobile-body")[0].getBoundingClientRect(),
                    p = jQuery(".pdapp-" + e.type + "-type-" + e.dropdown),
                    r = jQuery(".pdapp-menu-options.pdapp-" + e.type + "-dropdown-" + e.dropdown);
                if (0 == p.length || 0 == r.length) return !1;
                let o = p[0].getBoundingClientRect();
                if (void 0 !== o.top) {
                    let e = 0;
                    if (("hor" == t.position && "mobile" == t.screenSize) || "tablet" == t.screenSize) {
                        r.find(".pdapp-dropdown-box").attr("style", "max-height: unset"),
                            r.find(".pdapp-dropdown-box").height() > a.height - 8
                                ? r.addClass("show-scroll")
                                : r.removeClass("show-scroll"),
                            r.height() < a.height
                                ? ((e = o.top - a.top + o.height / 2 - r.height() / 2),
                                  e < 0 ? (e = 0) : e + r.height() > a.height && (e = a.height - r.height()))
                                : r.find(".pdapp-dropdown-box").attr("style", "max-height: " + a.height + "px");
                        let p = t.width < 768 ? 37 : 28;
                        r.attr(
                            "style",
                            "top: " +
                                e +
                                "px; left: " +
                                (jQuery(".pdapp-menu-mobile-body .pdapp-menus .list-group-item").width() / 2 + p) +
                                "px;"
                        );
                    } else {
                        let e = jQuery("#pdapp-viewer-area").height() - 50,
                            t = e > 450 ? 450 : e;
                        r.find(".pdapp-dropdown-box").attr("style", "max-height: unset"),
                            r.find(".pdapp-dropdown-box").height() > t
                                ? r.addClass("show-scroll")
                                : r.removeClass("show-scroll"),
                            r.find(".pdapp-dropdown-box").attr("style", "max-height: " + t + "px");
                    }
                }
                if (jQuery(".pdapp-menu-mobile-body .pdapp-menus").hasClass("hasScroll")) return !1;
                jQuery(".pdapp-menu-mobile-body .pdapp-menus").addClass("hasScroll"),
                    jQuery(".pdapp-menu-mobile-body .pdapp-menus").scroll(function () {
                        let a = jQuery(".pdapp-menu-mobile-body")[0].getBoundingClientRect(),
                            p = jQuery(".pdapp-" + e.type + "-type-" + e.dropdown),
                            r = jQuery(".pdapp-menu-options.pdapp-" + e.type + "-dropdown-" + e.dropdown);
                        if (0 == p.length || 0 == r.length) return !1;
                        let o = p[0].getBoundingClientRect();
                        if (void 0 !== o.top) {
                            let e = 0;
                            if (("hor" == t.position && "mobile" == t.screenSize) || "tablet" == t.screenSize) {
                                r.find(".pdapp-dropdown-box").attr("style", "max-height: unset"),
                                    r.find(".pdapp-dropdown-box").height() > a.height - 8
                                        ? r.addClass("show-scroll")
                                        : r.removeClass("show-scroll"),
                                    r.height() < a.height
                                        ? ((e = o.top - a.top + o.height / 2 - r.height() / 2),
                                          e < 0 ? (e = 0) : e + r.height() > a.height && (e = a.height - r.height()))
                                        : r.find(".pdapp-dropdown-box").attr("style", "max-height: " + a.height + "px");
                                let p = t.width < 768 ? 37 : 28;
                                r.attr(
                                    "style",
                                    "top: " +
                                        e +
                                        "px; left: " +
                                        (jQuery(".pdapp-menu-mobile-body .pdapp-menus .list-group-item").width() / 2 +
                                            p) +
                                        "px;"
                                );
                            } else {
                                let e = jQuery("#pdapp-viewer-area").height() - 150,
                                    t = e > 350 ? 350 : e;
                                r.find(".pdapp-dropdown-box").attr("style", "max-height: unset"),
                                    r.find(".pdapp-dropdown-box").height() > t
                                        ? r.addClass("show-scroll")
                                        : r.removeClass("show-scroll"),
                                    r.find(".pdapp-dropdown-box").attr("style", "max-height: " + t + "px");
                            }
                        }
                    });
            }
        },
        responsiveCart: function () {
            let e = !!jQuery(".pdapp-right-layout .modal.modal-cart").length,
                t = jQuery(".pdapp-cart-box"),
                a = e ? jQuery("#productdesignerapp-app").height() - 10 : t.height();
            (a =
                a -
                t.find(".modal-header").height() -
                t.find(".pdapp-cart-prices").height() -
                t.find(".modal-footer").height() -
                30),
                0 != t.find(".pdapp-cart-qty").length && (a = a - t.find(".pdapp-cart-qty").height() - 25),
                (a -= 50),
                t.find(".pdapp-cart-variants").css("max-height", a);
        },
        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),
                a = jQuery("#productdesignerapp-app")[0];
            t
                ? document.exitFullscreen
                    ? document.exitFullscreen()
                    : document.webkitExitFullscreen
                      ? document.webkitExitFullscreen()
                      : document.mozCancelFullScreen
                        ? document.mozCancelFullScreen()
                        : document.msExitFullscreen && document.msExitFullscreen()
                : a.requestFullscreen
                  ? a.requestFullscreen()
                  : a.webkitRequestFullscreen
                    ? a.webkitRequestFullscreen()
                    : a.msRequestFullscreen && a.msRequestFullscreen(),
                "function" == typeof e && e(!t);
        },
        previewScreen: function (e, t, a) {
            let p = [];
            return (
                jQuery("#pdapp-viewer-area .pdapp-viewport").each(function (t) {
                    let r =
                        '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
                        jQuery(this).width() +
                        '" height="' +
                        jQuery(this).height() +
                        '" x="0" y="0">';
                    jQuery(this)
                        .find(".pdapp-background-img")
                        .each(function () {
                            let e =
                                '<image preserveAspectRatio="none" x="' +
                                parseFloat(jQuery(this).css("left").replace("px", "")) +
                                '" y="' +
                                parseFloat(jQuery(this).css("top").replace("px", "")) +
                                '" width="' +
                                jQuery(this).width() +
                                '" height="' +
                                jQuery(this).height() +
                                '" xlink:href="' +
                                jQuery(this).find("img.pdapp-product-img").attr("src") +
                                '"></image>';
                            r += e;
                        }),
                        jQuery(this)
                            .find(".pdapp-viewport-area")
                            .each(function () {
                                let t = parseFloat(jQuery(this).css("top").replace("px", "")),
                                    a = parseFloat(jQuery(this).css("left").replace("px", "")),
                                    p = jQuery(this).width(),
                                    o = 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 a =
                                                        "" != 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: a,
                                                    });
                                                }
                                            }
                                        });
                                let n = jQuery(this).find("svg.pdapp-selecto-area")[0].outerHTML;
                                for (let e = 0; e < i.length; e++) n = n.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>';
                                    n = n.replace("</svg>", e);
                                }
                                let l =
                                        '<image x="0" y="0" width="' +
                                        p +
                                        '" height="' +
                                        o +
                                        '" xlink:href="' +
                                        ("data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(n)) +
                                        '"></image>',
                                    d =
                                        '<g transform="translate(' +
                                        a.toFixed(3) +
                                        ", " +
                                        t.toFixed(3) +
                                        ')">' +
                                        l +
                                        "</g>";
                                r += d;
                            });
                    let o = jQuery(this).find(".pdapp-mask-img");
                    if (o.length) {
                        let e =
                            '<image preserveAspectRatio="none" x="' +
                            parseFloat(o.css("left").replace("px", "")) +
                            '" y="' +
                            parseFloat(o.css("top").replace("px", "")) +
                            '" width="' +
                            o.width() +
                            '" height="' +
                            o.height() +
                            '" xlink:href="' +
                            o.find("img.pdapp-product-img").attr("src") +
                            '"></image>';
                        r += e;
                    }
                    (r += "</svg>"), (p[t] = { src: "", title: jQuery(this).attr("data-viewtitle") });
                    let i = document.createElement("canvas"),
                        n = i.getContext("2d"),
                        l = document.createElement("img");
                    (l.crossOrigin = "anonymous"),
                        (l.onload = function () {
                            setTimeout(() => {
                                let e = l.width,
                                    p = l.height;
                                l.width > l.height
                                    ? ((e = 1e3), (p = (1e3 * l.height) / l.width))
                                    : ((p = 1e3), (e = (1e3 * l.width) / l.height)),
                                    (i.width = e),
                                    (i.height = p),
                                    n.drawImage(l, 0, 0, e, p),
                                    i.toBlob(function (e) {
                                        (e = URL.createObjectURL(e)), "function" == typeof a && a(t, e);
                                    }, "image/png"),
                                    l.remove(),
                                    i.remove();
                            }, 200);
                        }),
                        (l.src =
                            -1 == r.indexOf("<svg") ? r : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(r));
                }),
                p
            );
        },
        loadMoreLibrary: function (e) {
            if (void 0 !== e.general && void 0 !== e.general.download && e.general.download.type.includes("pdf")) {
                let e = document.createElement("script");
                (e.type = "text/javascript"),
                    (e.src = pdappPluginUrl + "assets/plugins/jspdf/js/jspdf.min.js"),
                    jQuery("#productdesignerapp-wrapper").prepend(e);
            }
        },
        checkDesign: function () {
            let e = !1;
            return (
                jQuery("#pdapp-viewer-area svg.pdapp-selecto-area").each(function () {
                    "" != jQuery(this).find("g.pdapp-target").length && (e = !0);
                }),
                e
            );
        },
        resetDesign: function () {
            (pdappAPI.tool.pdappMoveAbleRef.target = null),
                jQuery("#pdapp-viewer-area svg.pdapp-selecto-area").each(function () {
                    jQuery(this).html("");
                });
        },
        setHideOptions(e, t) {
            !e.includes("size") && t.size
                ? ((pdappAPI.tool.pdappMoveAbleRef.scalable = !0),
                  (pdappAPI.tool.pdappMoveAbleRef.renderDirections = ["nw", "n", "ne", "w", "e", "sw", "s", "se"]))
                : ((pdappAPI.tool.pdappMoveAbleRef.scalable = !1),
                  (pdappAPI.tool.pdappMoveAbleRef.renderDirections = [])),
                !e.includes("move") && t.move
                    ? (pdappAPI.tool.pdappMoveAbleRef.draggable = !0)
                    : (pdappAPI.tool.pdappMoveAbleRef.draggable = !1),
                !e.includes("rotate") && t.rotate
                    ? (pdappAPI.tool.pdappMoveAbleRef.rotatable = !0)
                    : (pdappAPI.tool.pdappMoveAbleRef.rotatable = !1);
        },
    },
    download: {
        renderDesigns: function (e, t, a, p, r) {
            let o = "download" != p,
                i = {},
                n = [];
            return (
                jQuery("#pdapp-viewer-area .pdapp-viewport").each(function (p) {
                    void 0 === t[p] && (t[p] = {}), (i[p] = {});
                    let r = jQuery(this),
                        l = r.attr("data-viewtitle");
                    r.find(".pdapp-viewport-area").each(function (r) {
                        let d = jQuery(this);
                        if (d.find("g.pdapp-target").length) {
                            let s = d.attr("data-viewtitle");
                            i[p][r] = { view: l, area: s, svg: "", loading: !0, origin: "" };
                            let c = d.find("g.pdapp-team").length;
                            if (void 0 === t[p][r] || c) {
                                let l = !1,
                                    s = { vid: p, aid: r, enc: !0, svg: "", imgs: [] };
                                if (
                                    (!o && c > 0 && d.find("g.pdapp-target").length == c && (l = !0),
                                    (void 0 === d.find("g.pdapp-target.pdapp-svg-photo") &&
                                        void 0 === d.find("g.pdapp-target.pdapp-svg-artwork")) ||
                                        d
                                            .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 a = t.attr("id");
                                                    if (
                                                        void 0 !== e[a] &&
                                                        void 0 !== e[e[a].id] &&
                                                        void 0 !== e[e[a].id].blob
                                                    ) {
                                                        let p = t.find("image").attr("xlink:href"),
                                                            r = e[e[a].id].base64,
                                                            o = "";
                                                        void 0 !== e[e[a].id].origin && (o = e[e[a].id].origin),
                                                            "" == o && (o = r),
                                                            "" != e[a].crop &&
                                                                (void 0 !== e[a].crop.origin && (o = e[a].crop.origin),
                                                                void 0 !== e[a].crop.base64 && (r = e[a].crop.base64)),
                                                            s.imgs.push({ blob: p, base64: r, origin: o });
                                                    }
                                                }
                                            }),
                                    void 0 !== a.teams && a.teams.length > 0 && o)
                                ) {
                                    let e = document.createElement("span");
                                    e.setAttribute("style", "display: none;"),
                                        e.setAttribute("class", "pdapp-team-value"),
                                        (e.innerText = JSON.stringify(a.teams)),
                                        d.find("svg.pdapp-selecto-area").append(e);
                                }
                                d
                                    .find("svg.pdapp-selecto-area")
                                    .attr("width", d.find("svg.pdapp-selecto-area").attr("data-width")),
                                    d
                                        .find("svg.pdapp-selecto-area")
                                        .attr("height", d.find("svg.pdapp-selecto-area").attr("data-height")),
                                    (s.svg = d.find("svg.pdapp-selecto-area")[0].outerHTML),
                                    d.find("svg.pdapp-selecto-area").attr("width", "100%"),
                                    d.find("svg.pdapp-selecto-area").attr("height", "100%"),
                                    n.push(s),
                                    l && (void 0 !== t[p][r] && delete t[p][r], delete i[p][r]);
                            } else {
                                let e = { vid: p, aid: r, enc: !1, svg: t[p][r].svg, imgs: [] };
                                n.push(e);
                            }
                        }
                    });
                }),
                setTimeout(() => {
                    let e = void 0 !== a.teams && a.teams.length > 0 && !o;
                    pdappAPI.download.renderDesign(n, 0, e, r);
                }, 50),
                i
            );
        },
        renderDesign: function (e, t, a, p) {
            if (void 0 === e[t])
                return jQuery(".pdapp-team-value").remove(), "function" == typeof p && p("", "", "", {}, !0), !1;
            let r = !1;
            if (a) {
                let a = new DOMParser().parseFromString(e[t].svg, "image/svg+xml");
                jQuery(a.documentElement)
                    .find("g.pdapp-target")
                    .each(function () {
                        jQuery(this).hasClass("pdapp-team") && jQuery(this).remove();
                    }),
                    (e[t].svg = jQuery(a.documentElement)[0].outerHTML);
            }
            e[t].origin = e[t].svg;
            for (let a = 0; a < e[t].imgs.length; a++)
                (e[t].svg = e[t].svg.replaceAll(e[t].imgs[a].blob, e[t].imgs[a].base64)),
                    (e[t].origin = e[t].origin.replaceAll(e[t].imgs[a].blob, e[t].imgs[a].origin)),
                    (r = !0);
            r
                ? "" != e[t].origin &&
                  -1 === e[t].origin.indexOf("image/svg+xml;base64,") &&
                  (e[t].origin = "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(e[t].origin))
                : (e[t].origin = ""),
                -1 === e[t].svg.indexOf("image/svg+xml;base64,") &&
                    (e[t].svg = "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(e[t].svg)),
                "function" == typeof p && p(e[t].vid, e[t].aid, e[t].svg, e[t].origin, !1),
                setTimeout(() => {
                    pdappAPI.download.renderDesign(e, t + 1, a, p);
                }, 10);
        },
        renderTeams: function (e, t) {
            let a = [];
            jQuery("#pdapp-viewer-area .pdapp-viewport").each(function (e) {
                jQuery(this)
                    .find(".pdapp-viewport-area")
                    .each(function (t) {
                        let p = jQuery(this);
                        if (p.find("g.pdapp-team").length) {
                            let r = p.find("svg.pdapp-selecto-area")[0].outerHTML,
                                o = new DOMParser().parseFromString(r, "image/svg+xml");
                            jQuery(o.documentElement)
                                .find("g.pdapp-target")
                                .each(function () {
                                    jQuery(this).hasClass("pdapp-team")
                                        ? (jQuery(this).removeAttr("id"), jQuery(this).removeClass("pdapp-target"))
                                        : jQuery(this).remove();
                                }),
                                (r = jQuery(o.documentElement)[0].outerHTML),
                                a.push({ vid: e, aid: t, svg: r });
                        }
                    });
            }),
                setTimeout(() => {
                    let p = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                        r = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").attr(
                            "viewBox"
                        );
                    if (void 0 !== r) {
                        let e = parseFloat(r.split(" ")[2]),
                            t = parseFloat(r.split(" ")[3]),
                            a = jQuery(
                                ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                            ).width(),
                            o = jQuery(
                                ".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area"
                            ).height();
                        (parseInt(a / p) == parseInt(e) && parseInt(o / p) == parseInt(t)) ||
                            (p = e / t > a / o ? a / e : o / t);
                    }
                    pdappAPI.download.renderTeam(a, e, p, 0, 0, t);
                }, 10);
        },
        renderTeam: function (e, t, a, p, r, o) {
            if ((jQuery("svg.pdapp-svg-team").remove(), void 0 === e[p]))
                return "function" == typeof o && o("", "", !0), !1;
            if (void 0 === t[r]) return (r = 0), pdappAPI.download.renderTeam(e, t, a, p + 1, r, o), !1;
            let i = jQuery("#pdapp-viewer-area .pdapp-viewport.active"),
                n = new DOMParser().parseFromString(e[p].svg, "image/svg+xml");
            jQuery(n.documentElement).attr("class", "pdapp-svg-team"),
                i.append(n.documentElement),
                setTimeout(() => {
                    let n = i.find("svg.pdapp-svg-team"),
                        l = n.attr("viewBox");
                    if (void 0 !== l) {
                        let e = parseFloat(l.split(" ")[2]),
                            t = parseFloat(l.split(" ")[3]),
                            p = n.width(),
                            r = n.height();
                        (parseInt(p / a) == parseInt(e) && parseInt(r / a) == parseInt(t)) ||
                            (a = e / t > p / r ? p / e : r / t);
                    }
                    if (void 0 !== t[r].name) {
                        let e = n.find("g.pdapp-team-name");
                        if (e.length) {
                            let p = [],
                                o = e[0].getBoundingClientRect();
                            if (0 != o.width) {
                                let t = pdappAPI.tool.getTransform(e);
                                "" != t &&
                                    (p = t.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                            }
                            e.find("text").text(t[r].name),
                                setTimeout(() => {
                                    if (6 == p.length) {
                                        let t = e[0].getBoundingClientRect();
                                        if (0 != t.width) {
                                            let r = ((t.width - o.width) / 2 / a).toFixed(3);
                                            (r = parseFloat(r)),
                                                (p[4] = parseFloat(p[4]) - r),
                                                e.attr("transform", "matrix(" + p.join(", ") + ")");
                                        }
                                    }
                                }, 10);
                        }
                    }
                    if (void 0 !== t[r].number) {
                        let e = n.find("g.pdapp-team-number");
                        e.length &&
                            e.each(function () {
                                let e = jQuery(this),
                                    p = [],
                                    o = e[0].getBoundingClientRect();
                                if (0 != o.width) {
                                    let t = pdappAPI.tool.getTransform(e);
                                    "" != t &&
                                        (p = t.replace("matrix(", "").replace(")", "").replaceAll(" ", "").split(","));
                                }
                                e.find("text").text(t[r].number),
                                    setTimeout(() => {
                                        if (6 == p.length) {
                                            let t = e[0].getBoundingClientRect();
                                            if (0 != t.width) {
                                                let r = ((t.width - o.width) / 2 / a).toFixed(3);
                                                (r = parseFloat(r)),
                                                    (p[4] = parseFloat(p[4]) - r),
                                                    e.attr("transform", "matrix(" + p.join(", ") + ")");
                                            }
                                        }
                                    }, 10);
                            });
                    }
                    setTimeout(() => {
                        let i = n[0].outerHTML;
                        (i = "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(i)),
                            "function" == typeof o && o(r, i, !1),
                            pdappAPI.download.renderTeam(e, t, a, p, r + 1, o);
                    }, 50);
                }, 10);
        },
        downloadDesign: function (e, t, a, p, r) {
            let o = e.view + "-" + e.area,
                i =
                    -1 == e.svg.indexOf("<svg")
                        ? e.svg
                        : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(e.svg);
            "svg" == t
                ? pdappAPI.download.downloadFile(i, o, t, {}, p, r)
                : pdappAPI.tool.imgToBase64(i, function (e, i, n) {
                      pdappAPI.download.downloadFile(e, o, t, { w: i, h: n, unit: a }, p, r);
                  });
        },
        downloadFile: async function (e, t, a, p, r, o) {
            let i = document.createElement("a");
            (i.download = t + "." + a), (i.href = e), i.click(), i.remove(), "function" == typeof o && o();
        },
    },
    design: {
        thumb: function (e, t, a, p, r) {
            let o = parseFloat(jQuery("#pdapp-viewer-area").attr("data-zoom")) / 100,
                i = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").attr("viewBox");
            if (void 0 !== i) {
                let e = parseFloat(i.split(" ")[2]),
                    t = parseFloat(i.split(" ")[3]),
                    a = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").width(),
                    p = jQuery(".pdapp-viewport.active .pdapp-viewport-area.active svg.pdapp-selecto-area").height();
                (parseInt(a / o) == parseInt(e) && parseInt(p / o) == parseInt(t)) ||
                    (o = e / t > a / p ? a / e : p / t);
            }
            let n =
                '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
                a.width() / o +
                '" height="' +
                a.height() / o +
                '" x="0" y="0">';
            a.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>';
                n += e;
            }),
                a.find(".pdapp-viewport-area").each(function () {
                    let t = parseFloat(jQuery(this).css("top").replace("px", "")),
                        a = parseFloat(jQuery(this).css("left").replace("px", "")),
                        p = jQuery(this).width(),
                        r = 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 a =
                                            "" != 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: a });
                                    }
                                }
                            });
                    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="' +
                            p +
                            '" height="' +
                            r +
                            '" xlink:href="' +
                            ("data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(l)) +
                            '"></image>',
                        s =
                            '<g transform="translate(' +
                            (a / o).toFixed(3) +
                            ", " +
                            (t / o).toFixed(3) +
                            ')">' +
                            d +
                            "</g>";
                    n += s;
                }),
                (n += "</svg>");
            let l = document.createElement("canvas"),
                d = l.getContext("2d"),
                s = document.createElement("img");
            (s.crossOrigin = "anonymous"),
                (s.onload = function () {
                    setTimeout(() => {
                        let e = s.width,
                            a = s.height;
                        if (
                            ((s.width > 800 || s.height > 800) &&
                                (s.width > s.height
                                    ? ((e = 800), (a = (800 * s.height) / s.width))
                                    : ((a = 800), (e = (800 * s.width) / s.height))),
                            (l.width = e),
                            (l.height = a),
                            d.drawImage(s, 0, 0, e, a),
                            t.layout.waterMask.allow)
                        ) {
                            let p = "" != t.general.waterMask.text ? t.general.waterMask.text : "PDA";
                            jQuery("#pdapp-test-text").append(
                                '<span class="pdapp-test-textmask" style="font-family:Arial;font-size:100px;line-height:80px;font-weight:bold;">' +
                                    p +
                                    "</span>"
                            );
                            let r = {
                                w: jQuery("#pdapp-test-text span.pdapp-test-textmask").width() + 100,
                                h: jQuery("#pdapp-test-text span.pdapp-test-textmask").height() + 100,
                            };
                            jQuery(".pdapp-test-textmask").remove();
                            let o =
                                "" != t.general.waterMask.color
                                    ? pdappAPI.tool
                                          .hexToRgb(t.general.waterMask.color)
                                          .replace("rgb(", "rgba(")
                                          .replace(")", ", " + t.general.waterMask.opacity + ")")
                                    : "rgba(0, 0, 255, " + t.general.waterMask.opacity + ")";
                            (d.font = "bold 100px Arial"), (d.fillStyle = o), (d.textAlign = "center");
                            let i = { w: Math.floor(e / r.w), h: Math.floor(a / r.h) };
                            for (let t = 1; t <= i.w; t++)
                                for (let o = 1; o <= i.h; o++)
                                    d.fillText(
                                        p,
                                        e - (100 * Math.random() + r.w * t),
                                        a - (100 * Math.random() + r.h * o)
                                    );
                        }
                        "function" == typeof p && p(l.toDataURL("image/png"), r), s.remove(), l.remove();
                    }, 100);
                }),
                (s.src = -1 == n.indexOf("<svg") ? n : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(n));
        },
        import: function (e, t, a, p) {
            let r = new DOMParser().parseFromString(t, "image/svg+xml");
            jQuery(r.documentElement)
                .find("g.pdapp-target")
                .each(function () {
                    let e = "pdapp-target-" + pdappAPI.tool.uID(),
                        t = jQuery(this);
                    t.attr("id", e), "" != a && t.attr("data-tempid", a);
                }),
                e.find(".pdapp-selecto-area").remove(),
                e[0].appendChild(r.documentElement),
                e.find("svg.pdapp-selecto-area").attr("width", "100%"),
                e.find("svg.pdapp-selecto-area").attr("height", "100%"),
                e
                    .find("svg.pdapp-selecto-area")
                    .find("g.pdapp-target")
                    .each(function () {
                        let t = jQuery(this),
                            a = t.attr("id");
                        if (t.hasClass("pdapp-arc")) {
                            let p = t.find("text").attr("font-size"),
                                r = t.find("text").attr("font-family");
                            if ("undefined" != typeof transform && "none" != transform) {
                                let e = transform
                                    .replace("matrix(", "")
                                    .replace(")", "")
                                    .replaceAll(" ", "")
                                    .split(",");
                                if (6 == e.length) {
                                    let t = parseFloat(e[0]);
                                    1 != t && (p = Math.round(parseFloat(p) * t));
                                }
                            }
                            let o = 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:" +
                                    p +
                                    "px;font-family:" +
                                    r +
                                    ";"
                            ),
                                i.setAttribute("class", "pdapp-arc-elm " + a),
                                (i.innerHTML = o),
                                e.find(".pdapp-text-arc")[0].append(i);
                            let n = t.attr("data-radius"),
                                l = new CircleType(i);
                            0 != n && l.radius(n),
                                t.hasClass("pdapp-dir") && l.dir(-1),
                                (pdappAPI.text.arc.pdappCircleType[a] = l);
                        }
                        if (t.hasClass("pdapp-svg-photo") && !t.hasClass("pdapp-svg")) {
                            let e = t.find("image").attr("xlink:href");
                            void 0 !== e &&
                                pdappAPI.photo.readMediumImage(
                                    e,
                                    function (t) {
                                        let r = "design-" + pdappAPI.tool.uID();
                                        (t.origin = e), "function" == typeof p && p(a, r, t);
                                    },
                                    0.85
                                );
                        }
                    });
        },
        getArtPrice: async function (e, t, a) {
            if (0 == e.length && 0 == t.length) return "function" == typeof a && a([]), !1;
            let p =
                    pdappAdminUrl +
                    "admin-ajax.php?action=pdapp-get-art-price&admin=0&pdapp-token=" +
                    pdappToken +
                    "&pdapp-nonce=" +
                    pdappNonce,
                r = { art: e, temp: t };
            try {
                let e = await pdappAPI.tool.postData(p, r);
                0 != e && 0 === e.error && "function" == typeof a && a(e.data);
            } catch (e) {}
        },
        printView: function (e, t, a, p) {
            let r = !1,
                o = [],
                i = [],
                n = [],
                l = [],
                d = [];
            return (
                e.find(".pdapp-viewport-area").each(function () {
                    let e = jQuery(this),
                        s = e.find("svg.pdapp-selecto-area"),
                        c = e[0].getBoundingClientRect(),
                        u = !1,
                        h = "",
                        g = { top: "", left: "", right: 0, bottom: 0 };
                    if (
                        (s.find("g.pdapp-target").each(function () {
                            let e = jQuery(this);
                            u = !0;
                            let r = e[0].getBoundingClientRect(),
                                s = e.attr("data-artid"),
                                f = e.attr("data-tempid");
                            void 0 !== s && "" != s && t.artwork.push("art-" + s),
                                void 0 !== f && "" != f && (h = "temp-" + f),
                                0 == e.hasClass("pdapp-team") &&
                                    (("" === g.top || g.top > r.top - c.top) &&
                                        ((g.top = r.top - c.top), g.top < 0 && (g.top = 0)),
                                    ("" === g.left || g.left > r.left - c.left) &&
                                        ((g.left = r.left - c.left), g.left < 0 && (g.left = 0)),
                                    g.right < r.left - c.left + r.width &&
                                        ((g.right = r.left - c.left + r.width),
                                        g.right > c.width && (g.right = c.width)),
                                    g.bottom < r.top - c.top + r.height &&
                                        ((g.bottom = r.top - c.top + r.height),
                                        g.bottom > c.height && (g.bottom = c.height)));
                            let v = r.width,
                                m = r.height;
                            v > c.width && (v = c.width), m > c.height && (m = c.height);
                            let y = pdappAPI.tool.toCm(v / p.ratio, "px") * pdappAPI.tool.toCm(m / p.ratio, "px");
                            if (e.hasClass("pdapp-svg-text")) {
                                t.text.size = t.text.size + y;
                                let a = e.attr("fill");
                                void 0 !== a &&
                                    0 == a.indexOf("#") &&
                                    (0 == i.includes(a) && (i.push(a), t.text.color++),
                                    0 == o.includes(a) && o.push(a)),
                                    e.hasClass("pdapp-arc") && t.text.arc++;
                                let p = e.attr("data-text");
                                t.text.line++,
                                    (t.text.text = t.text.text + p.split(" ").length),
                                    (t.text.char = t.text.char + p.replaceAll(" ", "").split("").length);
                            } else if (e.hasClass("pdapp-svg-photo") || e.hasClass("pdapp-svg-artwork")) {
                                t.photo.size = t.photo.size + y;
                                let a = e.attr("data-color");
                                if (void 0 !== a && "" != a) {
                                    let e = a.split(",");
                                    for (let a = 0; a < e.length; a++)
                                        0 == e[a].indexOf("#") &&
                                            (0 == n.includes(e[a]) && (n.push(e[a]), t.photo.color++),
                                            0 == o.includes(e[a]) && o.push(e[a]));
                                }
                                t.photo.qty++,
                                    e.hasClass("pdapp-shape") && t.photo.shape++,
                                    e.hasClass("pdapp-filter") && t.photo.filter++;
                            } else if (e.hasClass("pdapp-team"))
                                if (e.hasClass("pdapp-team-name"))
                                    for (let e = 0; e < a.length; e++)
                                        t.team.name++,
                                            (t.team.textname = t.team.textname + a[e].name.split(" ").length),
                                            (t.team.charname =
                                                t.team.charname + a[e].name.replaceAll(" ", "").split("").length);
                                else
                                    for (let e = 0; e < a.length; e++)
                                        t.team.number++,
                                            (t.team.charnumber =
                                                t.team.charnumber + a[e].number.replaceAll(" ", "").split("").length);
                            else if (e.hasClass("pdapp-svg-qrcode")) {
                                let a = e.attr("data-color");
                                void 0 !== a &&
                                    0 == a.indexOf("#") &&
                                    (0 == l.includes(a) && (l.push(a), t.qrcode.color++),
                                    0 == o.includes(a) && o.push(a));
                                let p = e.attr("data-background");
                                void 0 !== p &&
                                    "transparent" != p &&
                                    0 == p.indexOf("#") &&
                                    (0 == l.includes(p) && (l.push(p), t.qrcode.color++),
                                    0 == o.includes(p) && o.push(p)),
                                    (t.qrcode.size = t.qrcode.size + y),
                                    t.qrcode.qty++;
                            } else if (e.hasClass("pdapp-svg-barcode")) {
                                let a = e.attr("data-color");
                                void 0 !== a &&
                                    0 == a.indexOf("#") &&
                                    (0 == d.includes(a) && (d.push(a), t.barcode.color++),
                                    0 == o.includes(a) && o.push(a));
                                let p = e.attr("data-background");
                                void 0 !== p &&
                                    "transparent" != p &&
                                    0 == p.indexOf("#") &&
                                    (0 == d.includes(p) && (d.push(p), t.barcode.color++),
                                    0 == o.includes(p) && o.push(p)),
                                    (t.barcode.size = t.barcode.size + y),
                                    t.barcode.qty++;
                            }
                        }),
                        "" != h && t.artwork.push(h),
                        u)
                    ) {
                        (r = !0),
                            (g.top < 0 || "" === g.top) && (g.top = 0),
                            (g.left < 0 || "" === g.left) && (g.left = 0);
                        let e =
                            pdappAPI.tool.toCm((g.right - g.left) / p.ratio, "px") *
                            pdappAPI.tool.toCm((g.bottom - g.top) / p.ratio, "px");
                        t.size = t.size + e;
                    }
                }),
                r ? ((t.color = t.color + o.length), t) : {}
            );
        },
        printInfo: function (e, t, a, p) {
            let r = {
                size: 0,
                color: 0,
                text: { size: 0, color: 0, arc: 0, line: 0, text: 0, char: 0 },
                photo: { size: 0, color: 0, qty: 0, filter: 0, shape: 0 },
                team: { name: 0, textname: 0, charname: 0, number: 0, charnumber: 0 },
                qrcode: { size: 0, color: 0, qty: 0 },
                barcode: { size: 0, color: 0, qty: 0 },
                artwork: [],
            };
            jQuery("#pdapp-viewer-area .pdapp-viewport").each(function (p) {
                void 0 === e[p] && e.push({}),
                    jQuery(this).hasClass("active") &&
                        (e[p] = pdappAPI.design.printView(jQuery(this), JSON.parse(JSON.stringify(r)), t, a));
            }),
                (r.views = 0);
            for (let t = 0; t < e.length; t++)
                if (void 0 !== e[t].size) {
                    r.views = r.views + 1;
                    for (let a in e[t])
                        if ("artwork" == a)
                            for (let p = 0; p < e[t][a].length; p++) void 0 !== r[a] && r[a].push(e[t][a][p]);
                        else if ("object" == typeof e[t][a])
                            for (let p in e[t][a])
                                void 0 !== r[a] && void 0 !== r[a][p] && (r[a][p] = r[a][p] + e[t][a][p]);
                        else void 0 !== r[a] && (r[a] = r[a] + e[t][a]);
                }
            return "function" == typeof p && p(e), r;
        },
        print: {
            fixed: function (e, t, a) {
                return t * (e = parseFloat(e));
            },
            per_size: function (e, t, a) {
                return t * (e = parseFloat(e)) * a.size;
            },
            per_color: function (e, t, a) {
                return t * (e = parseFloat(e)) * a.color;
            },
            per_colors: function (e, t, a) {
                let p = 0;
                for (let t = 0; t < e.length; t++) a.color > t && (p = parseFloat(e[t]));
                return t * p;
            },
            per_line_text: function (e, t, a) {
                return (e = parseFloat(e)), t * a.text.line * e;
            },
            per_text: function (e, t, a) {
                return (e = parseFloat(e)), t * a.text.text * e;
            },
            per_character: function (e, t, a) {
                return (e = parseFloat(e)), t * a.text.char * e;
            },
            per_arc_text: function (e, t, a) {
                return (e = parseFloat(e)), t * a.text.arc * e;
            },
            per_text_size: function (e, t, a) {
                return (e = parseFloat(e)), t * a.text.size * e;
            },
            per_text_color: function (e, t, a) {
                return (e = parseFloat(e)), t * a.text.color * e;
            },
            per_photo: function (e, t, a) {
                return (e = parseFloat(e)), t * a.photo.qty * e;
            },
            per_shape: function (e, t, a) {
                return (e = parseFloat(e)), t * a.photo.shape * e;
            },
            per_filter: function (e, t, a) {
                return (e = parseFloat(e)), t * a.photo.filter * e;
            },
            per_photo_size: function (e, t, a) {
                return (e = parseFloat(e)), t * a.photo.size * e;
            },
            per_photo_color: function (e, t, a) {
                return (e = parseFloat(e)), t * a.photo.color * e;
            },
            per_team_name: function (e, t, a) {
                return (e = parseFloat(e)), t * a.team.name * e;
            },
            per_text_team_name: function (e, t, a) {
                return (e = parseFloat(e)), t * a.team.textname * e;
            },
            per_character_team_name: function (e, t, a) {
                return (e = parseFloat(e)), t * a.team.charname * e;
            },
            per_team_number: function (e, t, a) {
                return (e = parseFloat(e)), t * a.team.number * e;
            },
            per_character_team_number: function (e, t, a) {
                return (e = parseFloat(e)), t * a.team.charnumber * e;
            },
            per_qrcode: function (e, t, a) {
                return (e = parseFloat(e)), t * a.qrcode.qty * e;
            },
            per_qrcode_size: function (e, t, a) {
                return (e = parseFloat(e)), t * a.qrcode.size * e;
            },
            per_qrcode_color: function (e, t, a) {
                return (e = parseFloat(e)), t * a.qrcode.color * e;
            },
            per_barcode: function (e, t, a) {
                return (e = parseFloat(e)), t * a.barcode.qty * e;
            },
            per_barcode_size: function (e, t, a) {
                return (e = parseFloat(e)), t * a.barcode.size * e;
            },
            per_barcode_color: function (e, t, a) {
                return (e = parseFloat(e)), t * a.barcode.color * e;
            },
        },
        cartThumb: function (e, t, a, p, r, o) {
            let i =
                '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
                a.width() +
                '" height="' +
                a.height() +
                '" x="0" y="0">';
            if ("function" == typeof r && p) {
                let e = i;
                a.find(".pdapp-background-img").each(function () {
                    let t =
                        '<image preserveAspectRatio="none" x="' +
                        parseFloat(jQuery(this).css("left").replace("px", "")) +
                        '" y="' +
                        parseFloat(jQuery(this).css("top").replace("px", "")) +
                        '" width="' +
                        jQuery(this).width() +
                        '" height="' +
                        jQuery(this).height() +
                        '" xlink:href="' +
                        jQuery(this).find("img.pdapp-product-img").attr("src") +
                        '"></image>';
                    e += t;
                }),
                    (e += "</svg>"),
                    r("product", "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(e), o);
            }
            a.find(".pdapp-viewport-area").each(function () {
                let t = parseFloat(jQuery(this).css("top").replace("px", "")),
                    a = parseFloat(jQuery(this).css("left").replace("px", "")),
                    p = jQuery(this).width(),
                    r = jQuery(this).height(),
                    o = [];
                (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 a =
                                        "" != e[t].crop && void 0 !== e[t].crop.base64
                                            ? e[t].crop.base64
                                            : e[e[t].id].base64;
                                    o.push({ blob: jQuery(this).find("image").attr("xlink:href"), base64: a });
                                }
                            }
                        });
                let n = jQuery(this).find("svg.pdapp-selecto-area")[0].outerHTML;
                for (let e = 0; e < o.length; e++) n = n.replaceAll(o[e].blob, o[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>';
                    n = n.replace("</svg>", e);
                }
                let l =
                        '<image x="0" y="0" width="' +
                        p +
                        '" height="' +
                        r +
                        '" xlink:href="' +
                        ("data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(n)) +
                        '"></image>',
                    d = '<g transform="translate(' + a.toFixed(3) + ", " + t.toFixed(3) + ')">' + l + "</g>";
                i += d;
            }),
                (i += "</svg>");
            let n = document.createElement("canvas"),
                l = n.getContext("2d"),
                d = document.createElement("img");
            (d.crossOrigin = "anonymous"),
                (d.onload = function () {
                    setTimeout(() => {
                        let e = d.width,
                            a = d.height;
                        if (
                            (d.width > d.height
                                ? ((e = 800), (a = (800 * d.height) / d.width))
                                : ((a = 800), (e = (800 * d.width) / d.height)),
                            (n.width = e),
                            (n.height = a),
                            l.drawImage(d, 0, 0, e, a),
                            t.layout.waterMask.allow)
                        ) {
                            let p = "" != t.general.waterMask.text ? t.general.waterMask.text : "PDA";
                            jQuery("#pdapp-test-text").append(
                                '<span class="pdapp-test-textmask" style="font-family:Arial;font-size:100px;line-height:80px;font-weight:bold;">' +
                                    p +
                                    "</span>"
                            );
                            let r = {
                                w: jQuery("#pdapp-test-text span.pdapp-test-textmask").width() + 100,
                                h: jQuery("#pdapp-test-text span.pdapp-test-textmask").height() + 100,
                            };
                            jQuery(".pdapp-test-textmask").remove();
                            let o =
                                "" != t.general.waterMask.color
                                    ? pdappAPI.tool
                                          .hexToRgb(t.general.waterMask.color)
                                          .replace("rgb(", "rgba(")
                                          .replace(")", ", " + t.general.waterMask.opacity + ")")
                                    : "rgba(0, 0, 255, " + t.general.waterMask.opacity + ")";
                            (l.font = "bold 100px Arial"), (l.fillStyle = o), (l.textAlign = "center");
                            let i = { w: Math.floor(e / r.w), h: Math.floor(a / r.h) };
                            for (let t = 1; t <= i.w; t++)
                                for (let o = 1; o <= i.h; o++)
                                    l.fillText(
                                        p,
                                        e - (100 * Math.random() + r.w * t),
                                        a - (100 * Math.random() + r.h * o)
                                    );
                        }
                        "function" == typeof r && r("design", n.toDataURL("image/png"), o), d.remove(), n.remove();
                    }, 100);
                }),
                (d.src = -1 == i.indexOf("<svg") ? i : "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(i));
        },
        mergeCartThumb: function (e, t, a, p, r) {
            if ("function" != typeof r) return !1;
            let o = document.createElement("canvas"),
                i = o.getContext("2d"),
                n = document.createElement("img");
            (n.crossOrigin = "anonymous"),
                (n.onload = function () {
                    setTimeout(() => {
                        let e = n.width,
                            l = n.height;
                        n.width > n.height
                            ? ((e = 800), (l = (800 * n.height) / n.width))
                            : ((l = 800), (e = (800 * n.width) / n.height)),
                            (o.width = e),
                            (o.height = l),
                            i.drawImage(n, 0, 0, e, l);
                        let d = document.createElement("img");
                        (d.crossOrigin = "anonymous"),
                            (d.onload = function () {
                                if ((i.drawImage(d, 0, 0, e, l), t.find(".pdapp-mask-img .pdapp-product-img").length)) {
                                    let a = document.createElement("img");
                                    (a.crossOrigin = "anonymous"),
                                        (a.onload = function () {
                                            setTimeout(() => {
                                                i.drawImage(a, 0, 0, e, l),
                                                    r(o.toDataURL("image/png"), p),
                                                    n.remove(),
                                                    d.remove(),
                                                    a.remove(),
                                                    o.remove();
                                            }, 100);
                                        });
                                    let s = t.find(".pdapp-mask-img").position(),
                                        c =
                                            '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' +
                                            t.width() +
                                            '" height="' +
                                            t.height() +
                                            '" x="0" y="0"><image preserveAspectRatio="none" x="' +
                                            s.left +
                                            '" y="' +
                                            s.top +
                                            '" width="' +
                                            t.find(".pdapp-mask-img").width() +
                                            '" height="' +
                                            t.find(".pdapp-mask-img").height() +
                                            '" xlink:href="' +
                                            t.find(".pdapp-mask-img .pdapp-product-img").attr("src") +
                                            '"></image></svg>';
                                    a.src = "data:image/svg+xml;base64," + pdappAPI.tool.encodeBase64(c);
                                } else
                                    i.drawImage(d, 0, 0, e, l),
                                        r(o.toDataURL("image/png"), p),
                                        n.remove(),
                                        d.remove(),
                                        o.remove();
                            }),
                            (d.src = a);
                    }, 100);
                }),
                (n.src = e);
        },
        renderCart: function (e) {
            let t = {};
            if (
                ((t.pid = e.pid),
                (t.did = e.did),
                (t.print = { id: e.print.id, title: e.print.title, info: e.print.info }),
                (t.items = e.items),
                (t.team = []),
                (t.note = e.note),
                void 0 !== e.team.items && e.team.items.length && void 0 !== t.items[0])
            ) {
                let a = [];
                for (let t = 0; t < e.team.items.length; t++) {
                    let p = { size: e.team.items[t].size };
                    void 0 !== e.team.name && "" != e.team.name && (p.name = e.team.items[t].name),
                        void 0 !== e.team.number && e.team.number.length > 0 && (p.number = e.team.items[t].number),
                        a.push(p);
                }
                (t.team = a), (t.items[0].sizes = e.sizes);
            }
            return t;
        },
    },
    history: {
        getTextArc: function (e) {
            return "";
        },
        getTextSize: function (e) {
            return e.find("text").attr("font-size");
        },
        getFormatText: function (e, t, a) {
            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) {
            let t = jQuery("#" + e.target);
            if (0 == t.length) return !1;
            t.attr("transform", e.value);
        },
        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;
        },
        updateMember: function (e, t) {
            return !1;
        },
        updateTeam: function (e, t) {
            return !1;
        },
        updateColor: function (e) {
            return !1;
        },
        createGroup: function (e) {
            return !1;
        },
        setGroup: function (e) {
            return !1;
        },
        alignGroup: function (e) {
            return !1;
        },
        updateTransformGroup: function (e) {
            return !1;
        },
        moveGroup: function (e) {
            return !1;
        },
        removeGroup: function (e) {
            return !1;
        },
    },
    folder: {
        getFolderBreads(e, t, a, p, r) {
            let o = [];
            this.getFolderBread(e, t, a, p, function (e) {
                o.push(e), e.id == p && (o.reverse(), "function" == typeof r && r(o));
            });
        },
        getFolderBread(e, t, a, p, r) {
            if (0 != a && a != p) {
                let o = p;
                for (let t in e)
                    if (t != a)
                        for (let p = 0; p < e[t].length; p++)
                            e[t][p].id == a &&
                                ((o = e[t][p].pid),
                                "function" == typeof r &&
                                    r({ id: e[t][p].id, pid: e[t][p].pid, title: this.getTitle(e[t][p].title) }));
                o == p
                    ? "function" == typeof r && r(t)
                    : this.getFolderBread(e, t, o, p, function (e) {
                          "function" == typeof r && r(e);
                      });
            } else "function" == typeof r && r(t);
        },
        getTitle(e) {
            let t = "Untitled";
            if (null == e || "" == e) return t;
            if (void 0 !== e[pdappLangDefault] && "" != e[pdappLangDefault]) t = e[pdappLangDefault];
            else for (let a in e) "" != e[a] && (t = e[a]);
            return t;
        },
    },
    hotkeys: {
        init: function (e) {
            return !1;
        },
    },
};