@printcart/wix-integration
Version:
Printcart Designer SDK for Wix.
1,095 lines • 52 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var __privateMethod = (obj, member, method) => {
__accessCheck(obj, member, "access private method");
return method;
};
var _apiUrl, _designerUrl, _designerInstance, _uploaderInstance, _productForm, _getStoreDetail, getStoreDetail_fn, _registerListener, registerListener_fn, _initializeProductTools, initializeProductTools_fn, _openSelectModal, openSelectModal_fn, _openModal, openModal_fn, _closeModal, closeModal_fn, _registerCloseModal, registerCloseModal_fn, _modalTrap, modalTrap_fn, _handleUploadSuccess, handleUploadSuccess_fn, _handleDesignSuccess, handleDesignSuccess_fn, _registerUploaderEvents, registerUploaderEvents_fn, _registerDesignerEvents, registerDesignerEvents_fn, _getUnauthToken, getUnauthToken_fn, _getScriptSrc, getScriptSrc_fn, _addStyle, addStyle_fn, _getPrintcartProduct, getPrintcartProduct_fn, _createBtn, createBtn_fn, _createProjectPrintcart, createProjectPrintcart_fn;
const PrintcartDesigner = function() {
var He = Object.defineProperty;
var ze = (L2, p2, v2) => p2 in L2 ? He(L2, p2, { enumerable: true, configurable: true, writable: true, value: v2 }) : L2[p2] = v2;
var te = (L2, p2, v2) => (ze(L2, typeof p2 != "symbol" ? p2 + "" : p2, v2), v2);
var L = Object.defineProperty, p = (t, e, n) => e in t ? L(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n, v = (t, e, n) => (p(t, typeof e != "symbol" ? e + "" : e, n), n), H = (t, e, n) => {
if (!e.has(t))
throw TypeError("Cannot " + n);
}, R = (t, e, n) => (H(t, e, "read from private field"), n ? n.call(t) : e.get(t)), w = (t, e, n) => {
if (e.has(t))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(t) : e.set(t, n);
}, ne = (t, e, n, r) => (H(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n), l = (t, e, n) => (H(t, e, "access private method"), n), E, P, z, re, G, ie, U, V, d, m, Z = { exports: {} }, b = typeof Reflect == "object" ? Reflect : null, se = b && typeof b.apply == "function" ? b.apply : function(e, n, r) {
return Function.prototype.apply.call(e, n, r);
}, F;
b && typeof b.ownKeys == "function" ? F = b.ownKeys : Object.getOwnPropertySymbols ? F = function(e) {
return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e));
} : F = function(e) {
return Object.getOwnPropertyNames(e);
};
function xe(t) {
console && console.warn && console.warn(t);
}
var oe = Number.isNaN || function(e) {
return e !== e;
};
function a() {
a.init.call(this);
}
Z.exports = a, Z.exports.once = $e, a.EventEmitter = a, a.prototype._events = void 0, a.prototype._eventsCount = 0, a.prototype._maxListeners = void 0;
var ae = 10;
function S(t) {
if (typeof t != "function")
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof t);
}
Object.defineProperty(a, "defaultMaxListeners", { enumerable: true, get: function() {
return ae;
}, set: function(t) {
if (typeof t != "number" || t < 0 || oe(t))
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + t + ".");
ae = t;
} }), a.init = function() {
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
}, a.prototype.setMaxListeners = function(e) {
if (typeof e != "number" || e < 0 || oe(e))
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + e + ".");
return this._maxListeners = e, this;
};
function fe(t) {
return t._maxListeners === void 0 ? a.defaultMaxListeners : t._maxListeners;
}
a.prototype.getMaxListeners = function() {
return fe(this);
}, a.prototype.emit = function(e) {
for (var n = [], r = 1; r < arguments.length; r++)
n.push(arguments[r]);
var i = e === "error", o = this._events;
if (o !== void 0)
i = i && o.error === void 0;
else if (!i)
return false;
if (i) {
var s;
if (n.length > 0 && (s = n[0]), s instanceof Error)
throw s;
var c = new Error("Unhandled error." + (s ? " (" + s.message + ")" : ""));
throw c.context = s, c;
}
var h = o[e];
if (h === void 0)
return false;
if (typeof h == "function")
se(h, this, n);
else
for (var N = h.length, ee = de(h, N), r = 0; r < N; ++r)
se(ee[r], this, n);
return true;
};
function ce(t, e, n, r) {
var i, o, s;
if (S(n), o = t._events, o === void 0 ? (o = t._events = /* @__PURE__ */ Object.create(null), t._eventsCount = 0) : (o.newListener !== void 0 && (t.emit("newListener", e, n.listener ? n.listener : n), o = t._events), s = o[e]), s === void 0)
s = o[e] = n, ++t._eventsCount;
else if (typeof s == "function" ? s = o[e] = r ? [n, s] : [s, n] : r ? s.unshift(n) : s.push(n), i = fe(t), i > 0 && s.length > i && !s.warned) {
s.warned = true;
var c = new Error("Possible EventEmitter memory leak detected. " + s.length + " " + String(e) + " listeners added. Use emitter.setMaxListeners() to increase limit");
c.name = "MaxListenersExceededWarning", c.emitter = t, c.type = e, c.count = s.length, xe(c);
}
return t;
}
a.prototype.addListener = function(e, n) {
return ce(this, e, n, false);
}, a.prototype.on = a.prototype.addListener, a.prototype.prependListener = function(e, n) {
return ce(this, e, n, true);
};
function Me() {
if (!this.fired)
return this.target.removeListener(this.type, this.wrapFn), this.fired = true, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
}
function ue(t, e, n) {
var r = { fired: false, wrapFn: void 0, target: t, type: e, listener: n }, i = Me.bind(r);
return i.listener = n, r.wrapFn = i, i;
}
a.prototype.once = function(e, n) {
return S(n), this.on(e, ue(this, e, n)), this;
}, a.prototype.prependOnceListener = function(e, n) {
return S(n), this.prependListener(e, ue(this, e, n)), this;
}, a.prototype.removeListener = function(e, n) {
var r, i, o, s, c;
if (S(n), i = this._events, i === void 0)
return this;
if (r = i[e], r === void 0)
return this;
if (r === n || r.listener === n)
--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete i[e], i.removeListener && this.emit("removeListener", e, r.listener || n));
else if (typeof r != "function") {
for (o = -1, s = r.length - 1; s >= 0; s--)
if (r[s] === n || r[s].listener === n) {
c = r[s].listener, o = s;
break;
}
if (o < 0)
return this;
o === 0 ? r.shift() : Re(r, o), r.length === 1 && (i[e] = r[0]), i.removeListener !== void 0 && this.emit("removeListener", e, c || n);
}
return this;
}, a.prototype.off = a.prototype.removeListener, a.prototype.removeAllListeners = function(e) {
var n, r, i;
if (r = this._events, r === void 0)
return this;
if (r.removeListener === void 0)
return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : r[e] !== void 0 && (--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete r[e]), this;
if (arguments.length === 0) {
var o = Object.keys(r), s;
for (i = 0; i < o.length; ++i)
s = o[i], s !== "removeListener" && this.removeAllListeners(s);
return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this;
}
if (n = r[e], typeof n == "function")
this.removeListener(e, n);
else if (n !== void 0)
for (i = n.length - 1; i >= 0; i--)
this.removeListener(e, n[i]);
return this;
};
function le(t, e, n) {
var r = t._events;
if (r === void 0)
return [];
var i = r[e];
return i === void 0 ? [] : typeof i == "function" ? n ? [i.listener || i] : [i] : n ? Pe(i) : de(i, i.length);
}
a.prototype.listeners = function(e) {
return le(this, e, true);
}, a.prototype.rawListeners = function(e) {
return le(this, e, false);
}, a.listenerCount = function(t, e) {
return typeof t.listenerCount == "function" ? t.listenerCount(e) : he.call(t, e);
}, a.prototype.listenerCount = he;
function he(t) {
var e = this._events;
if (e !== void 0) {
var n = e[t];
if (typeof n == "function")
return 1;
if (n !== void 0)
return n.length;
}
return 0;
}
a.prototype.eventNames = function() {
return this._eventsCount > 0 ? F(this._events) : [];
};
function de(t, e) {
for (var n = new Array(e), r = 0; r < e; ++r)
n[r] = t[r];
return n;
}
function Re(t, e) {
for (; e + 1 < t.length; e++)
t[e] = t[e + 1];
t.pop();
}
function Pe(t) {
for (var e = new Array(t.length), n = 0; n < e.length; ++n)
e[n] = t[n].listener || t[n];
return e;
}
function $e(t, e) {
return new Promise(function(n, r) {
function i(s) {
t.removeListener(e, o), r(s);
}
function o() {
typeof t.removeListener == "function" && t.removeListener("error", i), n([].slice.call(arguments));
}
pe(t, e, o, { once: true }), e !== "error" && Te(t, i, { once: true });
});
}
function Te(t, e, n) {
typeof t.on == "function" && pe(t, "error", e, n);
}
function pe(t, e, n, r) {
if (typeof t.on == "function")
r.once ? t.once(e, n) : t.on(e, n);
else if (typeof t.addEventListener == "function")
t.addEventListener(e, function i(o) {
r.once && t.removeEventListener(e, i), n(o);
});
else
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof t);
}
var We = Z.exports;
const $ = "pc-designer-iframe-wrapper", j = "pc-designer-iframe";
class Ae {
constructor(e) {
w(this, z), w(this, G), w(this, U), w(this, d), v(this, "token"), v(this, "productId"), v(this, "options"), w(this, E, void 0), w(this, P, void 0);
var n;
if (this.token = e.token, this.productId = e.productId, this.options = e.options, ne(this, E, (n = this.options) != null && n.designerUrl ? this.options.designerUrl : {}.VITE_CUSTOMIZER_URL ? {}.VITE_CUSTOMIZER_URL : "https://customizer.printcart.com"), ne(this, P, new We()), !this.token || !this.productId) {
console.error("Missing Config Params");
return;
}
l(this, z, re).call(this), l(this, G, ie).call(this);
}
render() {
const e = document.getElementById($), n = document.getElementById(j);
if (!n || !(n instanceof HTMLIFrameElement) || !e) {
console.error("Can not find iframe element");
return;
}
const r = l(this, U, V).call(this);
n.src = r.href, e.style.opacity = "1", e.style.visibility = "visible", l(this, d, m).call(this, "rendered");
}
close() {
const e = document.getElementById($);
if (!e) {
console.error("Can not find iframe element");
return;
}
e.style.opacity = "0", e.style.visibility = "hidden", l(this, d, m).call(this, "closed");
}
editDesign(e) {
const n = l(this, U, V).call(this);
n.searchParams.set("design_id", e), n.searchParams.set("task", "edit");
const r = document.getElementById($), i = document.getElementById(j);
if (!i || !(i instanceof HTMLIFrameElement) || !r) {
console.error("Can not find iframe element");
return;
}
i.src = n.href, r.style.opacity = "1", r.style.visibility = "visible", l(this, d, m).call(this, "edit");
}
on(e, n) {
return R(this, P).on(e, n), this;
}
}
E = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), z = /* @__PURE__ */ new WeakSet(), re = function() {
const t = document.createElement("div");
t.id = $, t.style.cssText = "position:fixed;top:0;left:0;width:100vw;height:100vh;opacity:0;visibility:hidden;z-index:99999";
const e = document.createElement("iframe");
e.id = j, e.width = "100%", e.height = "100%", t.appendChild(e), document.body.appendChild(t);
}, G = /* @__PURE__ */ new WeakSet(), ie = function() {
window.addEventListener("message", (t) => {
if (t.origin === R(this, E) && t.data.message === "closeDesignTool") {
const e = document.getElementById($);
if (!e)
return;
e.style.opacity = "0", e.style.visibility = "hidden", l(this, d, m).call(this, "closed");
}
if (t.data.message === "finishLoad") {
const e = document.getElementById(j);
l(this, d, m).call(this, "render-finish"), e && e instanceof HTMLIFrameElement && e.contentWindow && e.contentWindow.postMessage({ message: "customSettings", settings: this.options }, R(this, E));
}
t.data.message === "finishProcess" && l(this, d, m).call(this, "upload-success", t.data.data.data), t.data.message === "finishUpdate" && l(this, d, m).call(this, "edit-success", t.data.data.data), t.data.message === "uploadError" && l(this, d, m).call(this, "upload-error", t.data);
}, false);
}, U = /* @__PURE__ */ new WeakSet(), V = function() {
const t = new URL(R(this, E));
return t.searchParams.set("api_key", this.token), t.searchParams.set("product_id", this.productId), t.searchParams.set("parentUrl", window.location.href), t;
}, d = /* @__PURE__ */ new WeakSet(), m = function(t, ...e) {
R(this, P).emit(t, ...e);
};
var q = (t, e, n) => {
if (!e.has(t))
throw TypeError("Cannot " + n);
}, u = (t, e, n) => (q(t, e, "read from private field"), n ? n.call(t) : e.get(t)), y = (t, e, n) => {
if (e.has(t))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(t) : e.set(t, n);
}, I = (t, e, n, r) => (q(t, e, "write to private field"), r ? r.call(t, n) : e.set(t, n), n), _ = (t, e, n) => (q(t, e, "access private method"), n), T, O, C, W, A, k, g, x, J, ve, Q, me, X = { exports: {} }, M = typeof Reflect == "object" ? Reflect : null, ye = M && typeof M.apply == "function" ? M.apply : function(e, n, r) {
return Function.prototype.apply.call(e, n, r);
}, B;
M && typeof M.ownKeys == "function" ? B = M.ownKeys : Object.getOwnPropertySymbols ? B = function(e) {
return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e));
} : B = function(e) {
return Object.getOwnPropertyNames(e);
};
function ke(t) {
console && console.warn && console.warn(t);
}
var Le = Number.isNaN || function(e) {
return e !== e;
};
function f() {
f.init.call(this);
}
X.exports = f, X.exports.once = Se, f.EventEmitter = f, f.prototype._events = void 0, f.prototype._eventsCount = 0, f.prototype._maxListeners = void 0;
var _e = 10;
function D(t) {
if (typeof t != "function")
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof t);
}
Object.defineProperty(f, "defaultMaxListeners", { enumerable: true, get: function() {
return _e;
}, set: function(t) {
if (typeof t != "number" || t < 0 || Le(t))
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + t + ".");
_e = t;
} }), f.init = function() {
(this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) && (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0;
}, f.prototype.setMaxListeners = function(e) {
if (typeof e != "number" || e < 0 || Le(e))
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + e + ".");
return this._maxListeners = e, this;
};
function ge(t) {
return t._maxListeners === void 0 ? f.defaultMaxListeners : t._maxListeners;
}
f.prototype.getMaxListeners = function() {
return ge(this);
}, f.prototype.emit = function(e) {
for (var n = [], r = 1; r < arguments.length; r++)
n.push(arguments[r]);
var i = e === "error", o = this._events;
if (o !== void 0)
i = i && o.error === void 0;
else if (!i)
return false;
if (i) {
var s;
if (n.length > 0 && (s = n[0]), s instanceof Error)
throw s;
var c = new Error("Unhandled error." + (s ? " (" + s.message + ")" : ""));
throw c.context = s, c;
}
var h = o[e];
if (h === void 0)
return false;
if (typeof h == "function")
ye(h, this, n);
else
for (var N = h.length, ee = Oe(h, N), r = 0; r < N; ++r)
ye(ee[r], this, n);
return true;
};
function we(t, e, n, r) {
var i, o, s;
if (D(n), o = t._events, o === void 0 ? (o = t._events = /* @__PURE__ */ Object.create(null), t._eventsCount = 0) : (o.newListener !== void 0 && (t.emit("newListener", e, n.listener ? n.listener : n), o = t._events), s = o[e]), s === void 0)
s = o[e] = n, ++t._eventsCount;
else if (typeof s == "function" ? s = o[e] = r ? [n, s] : [s, n] : r ? s.unshift(n) : s.push(n), i = ge(t), i > 0 && s.length > i && !s.warned) {
s.warned = true;
var c = new Error("Possible EventEmitter memory leak detected. " + s.length + " " + String(e) + " listeners added. Use emitter.setMaxListeners() to increase limit");
c.name = "MaxListenersExceededWarning", c.emitter = t, c.type = e, c.count = s.length, ke(c);
}
return t;
}
f.prototype.addListener = function(e, n) {
return we(this, e, n, false);
}, f.prototype.on = f.prototype.addListener, f.prototype.prependListener = function(e, n) {
return we(this, e, n, true);
};
function Ne() {
if (!this.fired)
return this.target.removeListener(this.type, this.wrapFn), this.fired = true, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
}
function Ee(t, e, n) {
var r = { fired: false, wrapFn: void 0, target: t, type: e, listener: n }, i = Ne.bind(r);
return i.listener = n, r.wrapFn = i, i;
}
f.prototype.once = function(e, n) {
return D(n), this.on(e, Ee(this, e, n)), this;
}, f.prototype.prependOnceListener = function(e, n) {
return D(n), this.prependListener(e, Ee(this, e, n)), this;
}, f.prototype.removeListener = function(e, n) {
var r, i, o, s, c;
if (D(n), i = this._events, i === void 0)
return this;
if (r = i[e], r === void 0)
return this;
if (r === n || r.listener === n)
--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete i[e], i.removeListener && this.emit("removeListener", e, r.listener || n));
else if (typeof r != "function") {
for (o = -1, s = r.length - 1; s >= 0; s--)
if (r[s] === n || r[s].listener === n) {
c = r[s].listener, o = s;
break;
}
if (o < 0)
return this;
o === 0 ? r.shift() : Ue(r, o), r.length === 1 && (i[e] = r[0]), i.removeListener !== void 0 && this.emit("removeListener", e, c || n);
}
return this;
}, f.prototype.off = f.prototype.removeListener, f.prototype.removeAllListeners = function(e) {
var n, r, i;
if (r = this._events, r === void 0)
return this;
if (r.removeListener === void 0)
return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : r[e] !== void 0 && (--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete r[e]), this;
if (arguments.length === 0) {
var o = Object.keys(r), s;
for (i = 0; i < o.length; ++i)
s = o[i], s !== "removeListener" && this.removeAllListeners(s);
return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this;
}
if (n = r[e], typeof n == "function")
this.removeListener(e, n);
else if (n !== void 0)
for (i = n.length - 1; i >= 0; i--)
this.removeListener(e, n[i]);
return this;
};
function be(t, e, n) {
var r = t._events;
if (r === void 0)
return [];
var i = r[e];
return i === void 0 ? [] : typeof i == "function" ? n ? [i.listener || i] : [i] : n ? Fe(i) : Oe(i, i.length);
}
f.prototype.listeners = function(e) {
return be(this, e, true);
}, f.prototype.rawListeners = function(e) {
return be(this, e, false);
}, f.listenerCount = function(t, e) {
return typeof t.listenerCount == "function" ? t.listenerCount(e) : Ie.call(t, e);
}, f.prototype.listenerCount = Ie;
function Ie(t) {
var e = this._events;
if (e !== void 0) {
var n = e[t];
if (typeof n == "function")
return 1;
if (n !== void 0)
return n.length;
}
return 0;
}
f.prototype.eventNames = function() {
return this._eventsCount > 0 ? B(this._events) : [];
};
function Oe(t, e) {
for (var n = new Array(e), r = 0; r < e; ++r)
n[r] = t[r];
return n;
}
function Ue(t, e) {
for (; e + 1 < t.length; e++)
t[e] = t[e + 1];
t.pop();
}
function Fe(t) {
for (var e = new Array(t.length), n = 0; n < e.length; ++n)
e[n] = t[n].listener || t[n];
return e;
}
function Se(t, e) {
return new Promise(function(n, r) {
function i(s) {
t.removeListener(e, o), r(s);
}
function o() {
typeof t.removeListener == "function" && t.removeListener("error", i), n([].slice.call(arguments));
}
Ce(t, e, o, { once: true }), e !== "error" && je(t, i, { once: true });
});
}
function je(t, e, n) {
typeof t.on == "function" && Ce(t, "error", e, n);
}
function Ce(t, e, n, r) {
if (typeof t.on == "function")
r.once ? t.once(e, n) : t.on(e, n);
else if (typeof t.addEventListener == "function")
t.addEventListener(e, function i(o) {
r.once && t.removeEventListener(e, i), n(o);
});
else
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof t);
}
var Be = X.exports;
const K = "pc-uploader-iframe-wrapper", Y = "pc-uploader-iframe";
class De {
constructor(e) {
if (y(this, g), y(this, J), y(this, Q), y(this, T, void 0), y(this, O, void 0), y(this, C, void 0), y(this, W, void 0), y(this, A, void 0), y(this, k, void 0), I(this, T, e.token), I(this, O, e.sideId || e.productId), I(this, k, e.productId ? "product" : "side"), I(this, C, e.uploaderUrl ? e.uploaderUrl : "https://upload-tool.pages.dev"), I(this, W, new Be()), I(this, A, e.locale), !u(this, T) || !u(this, O)) {
console.warn("Missing Config Params.");
return;
}
_(this, J, ve).call(this), _(this, Q, me).call(this);
}
get locale() {
return u(this, A);
}
open() {
let e = document.getElementById(K), n = document.getElementById(Y);
const r = new URL(u(this, C));
if (r.searchParams.set("token", u(this, T)), u(this, k) === "side" ? r.searchParams.set("sideId", u(this, O)) : u(this, k) === "product" && r.searchParams.set("productId", u(this, O)), r.searchParams.set("parentUrl", window.location.href), !n || !(n instanceof HTMLIFrameElement) || !e) {
console.warn("Can not find iframe element.");
return;
}
n.src = r.href, e.style.opacity = "1", e.style.visibility = "visible", _(this, g, x).call(this, "open");
}
close() {
let e = document.getElementById(K);
if (!e) {
console.error("Can not find iframe element");
return;
}
e.style.opacity = "0", e.style.visibility = "hidden";
}
on(e, n) {
return u(this, W).on(e, n), this;
}
}
T = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakSet(), x = function(t, ...e) {
u(this, W).emit(t, ...e);
}, J = /* @__PURE__ */ new WeakSet(), ve = function() {
let t = document.createElement("div");
t.id = K, t.style.cssText = "position:fixed;top:0;left:0;width:100vw;height:100vh;opacity:0;visibility:hidden;z-index:99999";
let e = document.createElement("iframe");
e.id = Y, e.width = "100%", e.height = "100%", e.style.borderWidth = "0", t.appendChild(e), document.body.appendChild(t);
}, Q = /* @__PURE__ */ new WeakSet(), me = function() {
let t = document.getElementById(K);
window.addEventListener("message", (e) => {
var n;
const r = new URL(e.origin), i = new URL(u(this, C));
if (r.host === i.host) {
e.data.uploaderEvent === "close" && t && (t.style.opacity = "0", t.style.visibility = "hidden", _(this, g, x).call(this, "close")), e.data.uploaderEvent === "upload-success" && _(this, g, x).call(this, "upload-success", e.data.data), e.data.uploaderEvent === "upload-error" && _(this, g, x).call(this, "upload-error", e.data.error);
const o = u(this, A), s = document.getElementById(Y);
s && s instanceof HTMLIFrameElement && (_(this, g, x).call(this, "onload"), o && e.data.uploaderEvent === "loaded" && e.data.finished && (console.log("test"), s.focus(), (n = s.contentWindow) == null || n.postMessage({ locale: o }, u(this, C))));
}
}, false);
};
class Ke {
constructor() {
te(this, "initDesignTool", (e) => new Ae(e));
te(this, "initUploader", (e) => new De(e));
}
}
return Ke;
}();
var main = "";
const printcartDesigner = new PrintcartDesigner();
class PrintcartDesignerWix {
constructor() {
__privateAdd(this, _getStoreDetail);
__privateAdd(this, _registerListener);
__privateAdd(this, _initializeProductTools);
__privateAdd(this, _openSelectModal);
__privateAdd(this, _openModal);
__privateAdd(this, _closeModal);
__privateAdd(this, _registerCloseModal);
__privateAdd(this, _modalTrap);
__privateAdd(this, _handleUploadSuccess);
__privateAdd(this, _handleDesignSuccess);
__privateAdd(this, _registerUploaderEvents);
__privateAdd(this, _registerDesignerEvents);
__privateAdd(this, _getUnauthToken);
__privateAdd(this, _getScriptSrc);
__privateAdd(this, _addStyle);
__privateAdd(this, _getPrintcartProduct);
__privateAdd(this, _createBtn);
__privateAdd(this, _createProjectPrintcart);
__privateAdd(this, _apiUrl, void 0);
__publicField(this, "token");
__publicField(this, "appID");
__publicField(this, "productIdPC");
__publicField(this, "orderIdWix");
__publicField(this, "orderNumberWix");
__publicField(this, "options");
__privateAdd(this, _designerUrl, void 0);
__privateAdd(this, _designerInstance, void 0);
__privateAdd(this, _uploaderInstance, void 0);
__privateAdd(this, _productForm, void 0);
__publicField(this, "registerListener");
__publicField(this, "textReplace");
this.token = __privateMethod(this, _getUnauthToken, getUnauthToken_fn).call(this);
this.productIdPC = null;
this.appID = "325c68a5-64c2-440d-b093-8cea369df06b";
this.orderIdWix = null;
this.orderNumberWix = null;
__privateSet(this, _productForm, null);
this.textReplace = {
start_design: "Start Design",
pc_select_header: "Choose a way to design this product",
upload_a_full_design: "Upload a full design",
upload_design_file: "Upload Design file",
have_a_complete_design: "Have a complete design",
have_your_own_design: "Have your own designer",
design_here_online: "Design here online",
already_have_a_design: "Already have your concept",
customize_every_details: "Customize every details"
};
this.options = window.PrintcartDesignerShopifyOptions;
__privateSet(this, _apiUrl, "https://api.printcart.com/v1");
__privateSet(this, _designerUrl, "https://customizer.printcart.com");
}
init() {
const wd = window;
const self = this;
(wd == null ? void 0 : wd.wixDevelopersAnalytics) ? __privateMethod(this, _registerListener, registerListener_fn).call(this, "first") : wd.addEventListener("wixDevelopersAnalyticsReady", function() {
var _a;
__privateMethod(_a = self, _registerListener, registerListener_fn).call(_a, "second");
});
}
}
_apiUrl = new WeakMap();
_designerUrl = new WeakMap();
_designerInstance = new WeakMap();
_uploaderInstance = new WeakMap();
_productForm = new WeakMap();
_getStoreDetail = new WeakSet();
getStoreDetail_fn = async function() {
var _a, _b, _c, _d;
try {
const printcartApiUrl = `${__privateGet(this, _apiUrl)}/stores/store-details`;
const token = this.token;
if (!token) {
throw new Error("Missing Printcart Unauth Token");
}
const printcartPromise = await fetch(printcartApiUrl, {
headers: {
"X-PrintCart-Unauth-Token": token
}
});
const storeDetail = await printcartPromise.json();
const cssString = (_b = (_a = storeDetail == null ? void 0 : storeDetail.data) == null ? void 0 : _a.setting_defaults) == null ? void 0 : _b.customCss.value;
const textReplace = (_d = (_c = storeDetail == null ? void 0 : storeDetail.data) == null ? void 0 : _c.setting_defaults) == null ? void 0 : _d.textReplace;
this.textReplace = {
start_design: (textReplace == null ? void 0 : textReplace.start_design) ? textReplace.start_design : "Start Design",
pc_select_header: (textReplace == null ? void 0 : textReplace.pc_select_header) ? textReplace.pc_select_header : "Choose a way to design this product",
upload_a_full_design: (textReplace == null ? void 0 : textReplace.upload_a_full_design) ? textReplace.upload_a_full_design : "Upload a full design",
upload_design_file: (textReplace == null ? void 0 : textReplace.upload_design_file) ? textReplace.upload_design_file : "Upload Design file",
have_a_complete_design: (textReplace == null ? void 0 : textReplace.have_a_complete_design) ? textReplace.have_a_complete_design : "Have a complete design",
have_your_own_design: (textReplace == null ? void 0 : textReplace.have_your_own_design) ? textReplace.have_your_own_design : "Have your own designer",
design_here_online: (textReplace == null ? void 0 : textReplace.design_here_online) ? textReplace.design_here_online : "Design here online",
already_have_a_design: (textReplace == null ? void 0 : textReplace.already_have_a_design) ? textReplace.already_have_a_design : "Already have your concept",
customize_every_details: (textReplace == null ? void 0 : textReplace.customize_every_details) ? textReplace.customize_every_details : "Customize every details"
};
if (cssString) {
const styleElement = document.createElement("style");
styleElement.textContent = cssString;
styleElement.type = "text/css";
document.head.appendChild(styleElement);
}
return storeDetail;
} catch (error) {
console.error(
"There has been a problem with your fetch operation:",
error
);
}
};
_registerListener = new WeakSet();
registerListener_fn = function(par) {
const self = this;
console.log("Printcart start App " + par);
window == null ? void 0 : window.wixDevelopersAnalytics.register(
this.appID,
function report(eventName, data) {
var _a, _b, _c;
switch (eventName) {
case "ViewContent":
if (localStorage.getItem("pc-product")) {
localStorage.removeItem("pc-product");
}
break;
case "productPageLoaded":
console.log("Printcart: productPageLoaded", data);
if (data.variants && data.variants.length > 1) {
return;
}
__privateMethod(_a = self, _initializeProductTools, initializeProductTools_fn).call(_a, data == null ? void 0 : data.productId);
break;
case "CustomizeProduct":
if (data.variants && data.variants.length < 1) {
return;
}
__privateMethod(_b = self, _initializeProductTools, initializeProductTools_fn).call(_b, data == null ? void 0 : data.variantId);
break;
case "Purchase":
if (!localStorage.getItem("pc-design-ids")) {
return;
}
const designIds = localStorage.getItem("pc-design-ids");
self.orderIdWix = data == null ? void 0 : data.orderId;
self.orderNumberWix = data == null ? void 0 : data.id;
if (!self.orderIdWix) {
throw new Error("Can not find order ID WIX");
}
if (!self.orderNumberWix) {
throw new Error("Can not find order number WIX");
}
if (!designIds) {
throw new Error("Can not find design Ids");
}
__privateMethod(_c = self, _createProjectPrintcart, createProjectPrintcart_fn).call(_c, self.orderNumberWix, self.orderIdWix, JSON.parse(designIds));
break;
}
}
);
};
_initializeProductTools = new WeakSet();
initializeProductTools_fn = function(productIdWix) {
__privateSet(this, _productForm, document.querySelector("[data-hook='product-options']"));
__privateMethod(this, _getStoreDetail, getStoreDetail_fn).call(this);
if (!__privateGet(this, _productForm)) {
throw new Error(
"This script can only be used inside a Wix Product Page."
);
}
if (!productIdWix) {
throw new Error("Can not find product ID WIX");
}
__privateMethod(this, _getPrintcartProduct, getPrintcartProduct_fn).call(this, productIdWix).then((res) => {
var _a, _b;
this.productIdPC = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.id;
if (!this.productIdPC) {
throw new Error("Can not find product ID Printcart");
}
__privateMethod(this, _addStyle, addStyle_fn).call(this);
__privateMethod(this, _createBtn, createBtn_fn).call(this);
__privateMethod(this, _openSelectModal, openSelectModal_fn).call(this);
__privateMethod(this, _registerCloseModal, registerCloseModal_fn).call(this);
__privateMethod(this, _modalTrap, modalTrap_fn).call(this);
const btn = document.querySelector("button#pc-btn");
const isDesignEnabled = res.data.enable_design;
const isUploadEnabled = res.data.enable_upload;
if (isDesignEnabled) {
__privateSet(this, _designerInstance, printcartDesigner.initDesignTool({
token: this.token,
productId: this.productIdPC,
options: {
...(_b = this.options) == null ? void 0 : _b.designerOptions,
designerUrl: __privateGet(this, _designerUrl)
}
}));
__privateMethod(this, _registerDesignerEvents, registerDesignerEvents_fn).call(this);
if (btn && btn instanceof HTMLButtonElement) {
btn.disabled = false;
}
}
if (isUploadEnabled) {
__privateSet(this, _uploaderInstance, printcartDesigner.initUploader({
token: this.token,
productId: this.productIdPC
}));
__privateMethod(this, _registerUploaderEvents, registerUploaderEvents_fn).call(this);
if (btn && btn instanceof HTMLButtonElement) {
btn.disabled = false;
}
}
const handleClick = (e) => {
e.preventDefault();
if (__privateGet(this, _designerInstance) && !__privateGet(this, _uploaderInstance)) {
__privateGet(this, _designerInstance).render();
}
if (!__privateGet(this, _designerInstance) && __privateGet(this, _uploaderInstance)) {
__privateGet(this, _uploaderInstance).open();
}
if (__privateGet(this, _designerInstance) && __privateGet(this, _uploaderInstance)) {
__privateMethod(this, _openModal, openModal_fn).call(this);
}
};
if (btn && btn instanceof HTMLButtonElement) {
btn.onclick = handleClick;
}
});
};
_openSelectModal = new WeakSet();
openSelectModal_fn = function() {
const uploadImgSrc = "https://files.printcart.com/common/upload.svg";
const designImgSrc = "https://files.printcart.com/common/design.svg";
const inner = `<button aria-label="Close" id="pc-select_close-btn"><span data-modal-x></span></button><div class="pc-select-wrap" id="pc-content-overlay"><div class="pc-select-inner"><div id="pc-select_header">${this.textReplace.pc_select_header}</div><div id="pc-select_container"><button class="pc-select_btn" id="pc-select_btn_upload"><div aria-hidden="true" class="pc-select_btn_wrap"><div class="pc-select_btn_img"><div class="pc-select_btn_img_inner"><img src="${uploadImgSrc}" alt="Printcart Uploader"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">${this.textReplace.upload_a_full_design}</h2><ul><li>${this.textReplace.have_a_complete_design}</li><li>${this.textReplace.have_your_own_design}</li></ul></div></div></div><div class="visually-hidden">${this.textReplace.upload_design_file}</div></button><button class="pc-select_btn" id="pc-select_btn_design"><div aria-hidden="true" class="pc-select_btn_wrap"><div class="pc-select_btn_img"><div class="pc-select_btn_img_inner"><img src="${designImgSrc}" alt="Printcart Designer"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">${this.textReplace.design_here_online}</h2><ul><li>${this.textReplace.already_have_a_design}</li><li>${this.textReplace.customize_every_details}</li></ul></div></div></div><div class="visually-hidden">${this.textReplace.upload_design_file}</div></button></div></div></div>`;
const wrap = document.createElement("div");
wrap.id = "pc-select_wrap";
wrap.setAttribute("role", "dialog");
wrap.setAttribute("aria-modal", "true");
wrap.setAttribute("tabIndex", "-1");
wrap.innerHTML = inner;
document.body.appendChild(wrap);
const design = () => {
if (__privateGet(this, _designerInstance)) {
__privateMethod(this, _closeModal, closeModal_fn).call(this);
__privateGet(this, _designerInstance).render();
document.body.classList.add("pc-overflow");
}
};
const upload = () => {
if (__privateGet(this, _uploaderInstance)) {
__privateMethod(this, _closeModal, closeModal_fn).call(this);
__privateGet(this, _uploaderInstance).open();
document.body.classList.add("pc-overflow");
}
};
const uploadBtn = document.getElementById("pc-select_btn_upload");
const designBtn = document.getElementById("pc-select_btn_design");
if (uploadBtn)
uploadBtn == null ? void 0 : uploadBtn.addEventListener("click", upload);
if (designBtn)
designBtn == null ? void 0 : designBtn.addEventListener("click", design);
};
_openModal = new WeakSet();
openModal_fn = function() {
const modal = document.getElementById("pc-select_wrap");
if (modal) {
modal.style.display = "flex";
document.body.classList.add("pc-overflow");
}
const closeBtn = modal == null ? void 0 : modal.querySelector("#pc-select_close-btn");
if (closeBtn && closeBtn instanceof HTMLButtonElement)
closeBtn.focus();
};
_closeModal = new WeakSet();
closeModal_fn = function() {
const modal = document.getElementById("pc-select_wrap");
if (modal) {
modal.style.display = "none";
}
document.body.classList.remove("pc-overflow");
};
_registerCloseModal = new WeakSet();
registerCloseModal_fn = function() {
const closeModalBtn = document.getElementById("pc-select_close-btn");
const backdropCloseModal = document.getElementById("pc-content-overlay");
const handleClose = (e) => {
if (e.key === "Escape") {
__privateMethod(this, _closeModal, closeModal_fn).call(this);
}
};
window.addEventListener("keydown", handleClose);
closeModalBtn == null ? void 0 : closeModalBtn.addEventListener("click", () => __privateMethod(this, _closeModal, closeModal_fn).call(this));
backdropCloseModal == null ? void 0 : backdropCloseModal.addEventListener("click", () => {
const iframeWrap = document.getElementById("pc-designer-iframe-wrapper");
if ((iframeWrap == null ? void 0 : iframeWrap.style.visibility) !== "visible") {
__privateMethod(this, _closeModal, closeModal_fn).call(this);
}
});
};
_modalTrap = new WeakSet();
modalTrap_fn = function() {
const modal = document.getElementById("pc-select_wrap");
const focusableEls = modal == null ? void 0 : modal.querySelectorAll("button");
const firstFocusableEl = focusableEls && focusableEls[0];
const lastFocusableEl = focusableEls && focusableEls[focusableEls.length - 1];
const handleModalTrap = (e) => {
if (e.key === "Tab") {
if (e.shiftKey) {
if (lastFocusableEl && document.activeElement === firstFocusableEl) {
lastFocusableEl.focus();
e.preventDefault();
}
} else {
if (firstFocusableEl && document.activeElement === lastFocusableEl) {
firstFocusableEl.focus();
e.preventDefault();
}
}
}
};
window.addEventListener("keydown", handleModalTrap);
};
_handleUploadSuccess = new WeakSet();
handleUploadSuccess_fn = function(data) {
var _a, _b;
const ids = data.map((design) => design.data.id);
let input = document.querySelector('input[name="properties[_pcDesignIds]"]');
if (input) {
input.value += `,${ids.join()}`;
} else {
input = document.createElement("input");
input.type = "hidden";
input.name = "properties[_pcDesignIds]";
input.className = "pc-designer_input";
input.value = ids.join();
(_a = __privateGet(this, _productForm)) == null ? void 0 : _a.appendChild(input);
}
const previewWrap = document.querySelector(".pc-preview-wrap") || document.createElement("div");
previewWrap.className = "pc-preview-wrap";
if (localStorage.getItem("pc-design-ids")) {
localStorage.removeItem("pc-design-ids");
}
localStorage.setItem("pc-design-ids", JSON.stringify(ids));
data.forEach((design) => {
var _a2;
if (!design.data.design_image.url)
return;
const preview = document.createElement("div");
preview.className = "pc-preview";
preview.setAttribute("data-pc-design-id", design.data.id);
const btn = document.createElement("button");
btn.className = "pc-btn pc-danger-btn";
btn.innerHTML = ((_a2 = this.options) == null ? void 0 : _a2.removeUploaderBtnText) ? this.options.removeUploaderBtnText : "Remove";
btn.onclick = (e) => {
e.preventDefault();
const newIds = input.value.split(",").filter((id) => id !== design.data.id);
input.value = newIds.join();
preview.remove();
};
const image = document.createElement("img");
image.src = design.data.design_image.url;
image.className = "pc-uploader-image";
const overlay = document.createElement("div");
overlay.className = "pc-preview-overlay";
overlay.appendChild(btn);
preview.appendChild(overlay);
preview.appendChild(image);
previewWrap.appendChild(preview);
});
const wrap = document.querySelector("div#pc-designer_wrap");
if (!document.querySelector(".princart-preview-heading")) {
const heading = document.createElement("h5");
heading.className = "princart-preview-heading";
heading.innerHTML = "Your artworks";
wrap == null ? void 0 : wrap.appendChild(heading);
}
wrap == null ? void 0 : wrap.appendChild(previewWrap);
const callback = (_b = this.options) == null ? void 0 : _b.onUploadSuccess;
if (callback)
callback(data, __privateGet(this, _uploaderInstance));
};
_handleDesignSuccess = new WeakSet();
handleDesignSuccess_fn = function(data) {
var _a, _b;
const self = this;
const ids = data.map((design) => design.id);
let input = document.querySelector('input[name="properties[_pcDesignIds]"]');
if (input) {
input.value += `,${ids.join()}`;
} else {
input = document.createElement("input");
input.type = "hidden";
input.name = "properties[_pcDesignIds]";
input.className = "pc-designer_input";
input.value = ids.join();
(_a = __privateGet(this, _productForm)) == null ? void 0 : _a.appendChild(input);
}
const previewWrap = document.querySelector(".pc-preview-wrap") || document.createElement("div");
previewWrap.className = "pc-preview-wrap";
if (localStorage.getItem("pc-design-ids")) {
localStorage.removeItem("pc-design-ids");
}
localStorage.setItem("pc-design-ids", JSON.stringify(ids));
data.forEach((design) => {
var _a2;
if (!design.design_image.url)
return;
const preview = document.createElement("div");
preview.className = "pc-preview";
preview.setAttribute("data-pc-design-id", design.id);
const editBtn = document.createElement("button");
editBtn.className = "pc-btn pc-primary-btn";
editBtn.style.borderRadius = "5px";
editBtn.innerHTML = "Edit";
editBtn.onclick = (e) => {
e.preventDefault();
__privateGet(self, _designerInstance).editDesign(design.id);
};
const removeBtn = document.createElement("button");
removeBtn.className = "pc-btn pc-danger-btn";
removeBtn.style.borderRadius = "5px";
removeBtn.innerHTML = "Remove";
removeBtn.onclick = (e) => {
e.preventDefault();
const newIds = input.value.split(",").filter((id) => id !== design.id);
input.value = newIds.join();
preview.remove();
};
const image = document.createElement("img");
image.src = ((_a2 = design.preview_image) == null ? void 0 : _a2.url) || design.design_image.url;
image.className = "pc-uploader-image";
const overlay = document.createElement("div");
overlay.className = "pc-preview-overlay";
overlay.appendChild(editBtn);
overlay.appendChild(removeBtn);
preview.appendChild(overlay);
preview.appendChild(image);
previewWrap.appendChild(preview);
});
const wrap = document.querySelector("div#pc-designer_wrap");
wrap == null ? void 0 : wrap.appendChild(previewWrap);
const callback = (_b = this.options) == null ? void 0 : _b.onDesignCreateSuccess;
if (callback)
callback(data, __privateGet(this, _designerInstance));
};
_registerUploaderEvents = new WeakSet();
registerUploaderEvents_fn = function() {
if (__privateGet(this, _uploaderInstance)) {
__privateGet(this, _uploaderInstance).on("upload-success", (data) => {
__privateMethod(this, _handleUploadSuccess, handleUploadSuccess_fn).call(this, data);
__privateGet(this, _uploaderInstance).close();
});
__privateGet(this, _uploaderInstance).on("close", () => {
document.body.classList.remove("pc-overflow");
});
}
};
_registerDesignerEvents = new WeakSet();
registerDesignerEvents_fn = function() {
if (__privateGet(this, _designerInstance)) {
__privateGet(this, _designerInstance).on("upload-success", (data) => {
__privateMethod(this, _handleDesignSuccess, handleDesignSuccess_fn).call(this, data);
__privateGet(this, _designerInstance).close();
});
__privateGet(this, _designerInstance).on("closed", () => {
document.body.classList.remove("pc-overflow");
});
__privateGet(this, _designerInstance).on("edit-success", (data) => {
var _a;
if (!data.design_image.url)
return;
const img = document.querySelector(
`[data-pc-design-id="${data.id}"] img`
);
if (!img || !(img instanceof HTMLImageElement)) {
throw new Error("Can't find image element");
}
img.src = data.design_image.url;
const callback = (_a = this.options) == null ? void 0 : _a.onDesignEditSuccess;
__privateGet(this, _designerInstance).close();
if (callback)
callback(data, __privateGet(this, _designerInstance));
});
}
};
_getUnauthToken = new WeakSet();
getUnauthToken_fn = function() {
const src = __privateMethod(this, _getScriptSrc, getScriptSrc_fn).call(this);
const url = new URL(src);
const params = new URLSearchParams(url.search);
const token = params.get("shopT");
return token;
};
_getScriptSrc = new WeakSet();
getScriptSrc_fn = function() {
const src = document.querySelector(
"[id='pc-wix-integration-sdk']"
).src;
return src;
};
_addStyle = new WeakSet();
addStyle_fn = function() {
const sdkUrl = "https://unpkg.com/@printcart/wix-integration/dist";
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = `${sdkUrl}/style.css`;
document.head.appendChild(link);
};
_getPrintcartProduct = new WeakSet();
getPrintcartProduct_fn = async function(productIdWix) {
try {
const printcartApiUrl = `${__privateGet(this, _apiUrl)}/integration/wix/products/${productIdWix}`;
const token = this.token;
if (!token) {
throw new Error("Missing Printcart Unauth Token");
}
const printcartPromise = await fetch(printcartApiUrl, {
headers: {
"X-PrintCart-Unauth-Token": token
}
});
const product