@printcart/wix-integration
Advanced tools
Comparing version 1.1.11 to 1.1.12
2011
dist/main.es.js
@@ -29,1073 +29,1072 @@ var __defProp = Object.defineProperty; | ||
}; | ||
(function() { | ||
var _apiUrl, _designerUrl, _designerInstance, _uploaderInstance, _productForm, _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 _apiUrl, _designerUrl, _designerInstance, _uploaderInstance, _productForm, _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 oe = Number.isNaN || function(e) { | ||
return e !== e; | ||
}; | ||
function a() { | ||
a.init.call(this); | ||
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); | ||
} | ||
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); | ||
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); | ||
} | ||
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; | ||
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; | ||
} | ||
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; | ||
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); | ||
} | ||
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); | ||
function o() { | ||
typeof t.removeListener == "function" && t.removeListener("error", i), n([].slice.call(arguments)); | ||
} | ||
return t; | ||
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); | ||
} | ||
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); | ||
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"); | ||
} | ||
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); | ||
close() { | ||
const e = document.getElementById($); | ||
if (!e) { | ||
console.error("Can not find iframe element"); | ||
return; | ||
} | ||
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); | ||
e.style.opacity = "0", e.style.visibility = "hidden", l(this, d, m).call(this, "closed"); | ||
} | ||
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; | ||
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; | ||
} | ||
return 0; | ||
i.src = n.href, r.style.opacity = "1", r.style.visibility = "visible", l(this, d, m).call(this, "edit"); | ||
} | ||
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; | ||
on(e, n) { | ||
return R(this, P).on(e, n), this; | ||
} | ||
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() { | ||
} | ||
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) { | ||
console.error("Can not find iframe element"); | ||
if (!e) | ||
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"); | ||
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)); | ||
} | ||
on(e, n) { | ||
return R(this, P).on(e, n), this; | ||
} | ||
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; | ||
} | ||
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"); | ||
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 (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); | ||
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); | ||
} | ||
var Le = Number.isNaN || function(e) { | ||
return e !== e; | ||
}; | ||
function f() { | ||
f.init.call(this); | ||
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; | ||
} | ||
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); | ||
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; | ||
} | ||
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; | ||
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); | ||
} | ||
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); | ||
function o() { | ||
typeof t.removeListener == "function" && t.removeListener("error", i), n([].slice.call(arguments)); | ||
} | ||
return t; | ||
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); | ||
} | ||
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); | ||
get locale() { | ||
return u(this, A); | ||
} | ||
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); | ||
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; | ||
} | ||
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); | ||
n.src = r.href, e.style.opacity = "1", e.style.visibility = "visible", _(this, g, x).call(this, "open"); | ||
} | ||
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; | ||
close() { | ||
let e = document.getElementById(K); | ||
if (!e) { | ||
console.error("Can not find iframe element"); | ||
return; | ||
} | ||
return 0; | ||
e.style.opacity = "0", e.style.visibility = "hidden"; | ||
} | ||
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; | ||
on(e, n) { | ||
return u(this, W).on(e, n), this; | ||
} | ||
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); | ||
} | ||
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)))); | ||
} | ||
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; | ||
}(); | ||
const printcartDesigner = new PrintcartDesigner(); | ||
class PrintcartDesignerWix { | ||
}, false); | ||
}; | ||
class Ke { | ||
constructor() { | ||
__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"); | ||
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.options = window.PrintcartDesignerShopifyOptions; | ||
__privateSet(this, _apiUrl, "https://api.printcart.com/v1"); | ||
__privateSet(this, _designerUrl, "https://customizer.printcart.com"); | ||
te(this, "initDesignTool", (e) => new Ae(e)); | ||
te(this, "initUploader", (e) => new De(e)); | ||
} | ||
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(); | ||
_registerListener = new WeakSet(); | ||
registerListener_fn = function(par) { | ||
return Ke; | ||
}(); | ||
var main = ""; | ||
const printcartDesigner = new PrintcartDesigner(); | ||
class PrintcartDesignerWix { | ||
constructor() { | ||
__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"); | ||
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.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; | ||
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; | ||
} | ||
(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(); | ||
_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']")); | ||
if (!__privateGet(this, _productForm)) { | ||
throw new Error( | ||
"This script can only be used inside a Wix Product Page." | ||
); | ||
}; | ||
_initializeProductTools = new WeakSet(); | ||
initializeProductTools_fn = function(productIdWix) { | ||
__privateSet(this, _productForm, document.querySelector("[data-hook='product-options']")); | ||
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"); | ||
} | ||
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; | ||
__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 = () => { | ||
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 (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.onclick = handleClick; | ||
btn.disabled = false; | ||
} | ||
}); | ||
}; | ||
_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">Choose a way to design this product</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">Upload a full design</h2><ul><li>Have a complete design</li><li>Have your own designer</li></ul></div></div></div><div class="visually-hidden">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">Design here online</h2><ul><li>Already have your concept</li><li>Customize every details</li></ul></div></div></div><div class="visually-hidden">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); | ||
} | ||
const handleClick = () => { | ||
if (__privateGet(this, _designerInstance) && !__privateGet(this, _uploaderInstance)) { | ||
__privateGet(this, _designerInstance).render(); | ||
document.body.classList.add("pc-overflow"); | ||
} | ||
}; | ||
const upload = () => { | ||
if (__privateGet(this, _uploaderInstance)) { | ||
__privateMethod(this, _closeModal, closeModal_fn).call(this); | ||
if (!__privateGet(this, _designerInstance) && __privateGet(this, _uploaderInstance)) { | ||
__privateGet(this, _uploaderInstance).open(); | ||
document.body.classList.add("pc-overflow"); | ||
} | ||
if (__privateGet(this, _designerInstance) && __privateGet(this, _uploaderInstance)) { | ||
__privateMethod(this, _openModal, openModal_fn).call(this); | ||
} | ||
}; | ||
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"; | ||
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">Choose a way to design this product</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">Upload a full design</h2><ul><li>Have a complete design</li><li>Have your own designer</li></ul></div></div></div><div class="visually-hidden">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">Design here online</h2><ul><li>Already have your concept</li><li>Customize every details</li></ul></div></div></div><div class="visually-hidden">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 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"; | ||
const upload = () => { | ||
if (__privateGet(this, _uploaderInstance)) { | ||
__privateMethod(this, _closeModal, closeModal_fn).call(this); | ||
__privateGet(this, _uploaderInstance).open(); | ||
document.body.classList.add("pc-overflow"); | ||
} | ||
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 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); | ||
} | ||
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 = () => { | ||
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); | ||
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); | ||
} | ||
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 = () => { | ||
__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 = () => { | ||
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"); | ||
}); | ||
}; | ||
_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(); | ||
} | ||
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"); | ||
} else { | ||
if (firstFocusableEl && document.activeElement === lastFocusableEl) { | ||
firstFocusableEl.focus(); | ||
e.preventDefault(); | ||
} | ||
} | ||
const printcartPromise = await fetch(printcartApiUrl, { | ||
headers: { | ||
"X-PrintCart-Unauth-Token": token | ||
} | ||
}); | ||
const product = await printcartPromise.json(); | ||
return product; | ||
} catch (error) { | ||
console.error( | ||
"There has been a problem with your fetch operation:", | ||
error | ||
); | ||
return; | ||
} | ||
}; | ||
_createBtn = new WeakSet(); | ||
createBtn_fn = function() { | ||
var _a, _b, _c; | ||
const cartForm = __privateGet(this, _productForm); | ||
if (!(cartForm == null ? void 0 : cartForm.parentNode)) { | ||
console.log("Can not find cart form"); | ||
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; | ||
} | ||
if (document.getElementById("pc-designer_wrap") !== null) { | ||
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 = () => { | ||
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 = () => { | ||
__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 = () => { | ||
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 wrap = document.createElement("div"); | ||
wrap.id = "pc-designer_wrap"; | ||
const button = document.createElement("button"); | ||
button.id = "pc-btn"; | ||
button.className = ((_a = this.options) == null ? void 0 : _a.designClassName) ? (_b = this.options) == null ? void 0 : _b.designClassName : ""; | ||
button.innerHTML = ((_c = this.options) == null ? void 0 : _c.designBtnText) ? this.options.designBtnText : "Start Design"; | ||
button.disabled = true; | ||
wrap.appendChild(button); | ||
cartForm.appendChild(wrap); | ||
}; | ||
_createProjectPrintcart = new WeakSet(); | ||
createProjectPrintcart_fn = async function(_orderNumber, _orderId, _designIds) { | ||
try { | ||
const createProjectApiUrl = `${__privateGet(this, _apiUrl)}/projects`; | ||
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 dataProject = { | ||
name: `${_orderNumber}`, | ||
status: "processing", | ||
design_ids: _designIds, | ||
order_detail: { | ||
id: _orderId | ||
} | ||
}; | ||
await fetch(createProjectApiUrl, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-PrintCart-Unauth-Token": token | ||
}, | ||
body: JSON.stringify(dataProject) | ||
}); | ||
} catch (error) { | ||
console.error( | ||
"There has been a problem with your fetch operation:", | ||
error | ||
); | ||
return; | ||
}); | ||
const product = await printcartPromise.json(); | ||
return product; | ||
} catch (error) { | ||
console.error( | ||
"There has been a problem with your fetch operation:", | ||
error | ||
); | ||
return; | ||
} | ||
}; | ||
_createBtn = new WeakSet(); | ||
createBtn_fn = function() { | ||
var _a, _b, _c; | ||
const cartForm = __privateGet(this, _productForm); | ||
if (!(cartForm == null ? void 0 : cartForm.parentNode)) { | ||
console.log("Can not find cart form"); | ||
return; | ||
} | ||
if (document.getElementById("pc-designer_wrap") !== null) { | ||
return; | ||
} | ||
const wrap = document.createElement("div"); | ||
wrap.id = "pc-designer_wrap"; | ||
const button = document.createElement("button"); | ||
button.id = "pc-btn"; | ||
button.className = ((_a = this.options) == null ? void 0 : _a.designClassName) ? (_b = this.options) == null ? void 0 : _b.designClassName : ""; | ||
button.innerHTML = ((_c = this.options) == null ? void 0 : _c.designBtnText) ? this.options.designBtnText : "Start Design"; | ||
button.disabled = true; | ||
wrap.appendChild(button); | ||
cartForm.appendChild(wrap); | ||
}; | ||
_createProjectPrintcart = new WeakSet(); | ||
createProjectPrintcart_fn = async function(_orderNumber, _orderId, _designIds) { | ||
try { | ||
const createProjectApiUrl = `${__privateGet(this, _apiUrl)}/projects`; | ||
const token = this.token; | ||
if (!token) { | ||
throw new Error("Missing Printcart Unauth Token"); | ||
} | ||
}; | ||
const printcartDesignerWix = new PrintcartDesignerWix(); | ||
printcartDesignerWix.init(); | ||
})(); | ||
const dataProject = { | ||
name: `${_orderNumber}`, | ||
status: "processing", | ||
design_ids: _designIds, | ||
order_detail: { | ||
id: _orderId | ||
} | ||
}; | ||
await fetch(createProjectApiUrl, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-PrintCart-Unauth-Token": token | ||
}, | ||
body: JSON.stringify(dataProject) | ||
}); | ||
} catch (error) { | ||
console.error( | ||
"There has been a problem with your fetch operation:", | ||
error | ||
); | ||
return; | ||
} | ||
}; | ||
const printcartDesignerWix = new PrintcartDesignerWix(); | ||
printcartDesignerWix.init(); |
@@ -1,1 +0,1 @@ | ||
(function(g){typeof define=="function"&&define.amd?define(g):g()})(function(){"use strict";var At=Object.defineProperty;var Ht=(g,y,I)=>y in g?At(g,y,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[y]=I;var B=(g,y,I)=>(Ht(g,typeof y!="symbol"?y+"":y,I),I),Ne=(g,y,I)=>{if(!y.has(g))throw TypeError("Cannot "+I)};var p=(g,y,I)=>(Ne(g,y,"read from private field"),I?I.call(g):y.get(g)),E=(g,y,I)=>{if(y.has(g))throw TypeError("Cannot add the same private member more than once");y instanceof WeakSet?y.add(g):y.set(g,I)},q=(g,y,I,Se)=>(Ne(g,y,"write to private field"),Se?Se.call(g,I):y.set(g,I),I);var w=(g,y,I)=>(Ne(g,y,"access private method"),I);(function(){var $,Q,C,P,j,ee,Re,te,Be,le,lt,de,dt,R,G,ue,ut,pe,pt,he,ht,fe,ft,me,mt,ve,vt,ge,gt,ye,yt,we,wt,be,bt,_e,_t,Ee,Et;const g=function(){var Ae=Object.defineProperty,c=(e,t,n)=>t in e?Ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,o=(e,t,n)=>(c(e,typeof t!="symbol"?t+"":t,n),n),a=Object.defineProperty,d=(e,t,n)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,u=(e,t,n)=>(d(e,typeof t!="symbol"?t+"":t,n),n),v=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},L=(e,t,n)=>(v(e,t,"read from private field"),n?n.call(e):t.get(e)),b=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},k=(e,t,n,i)=>(v(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),h=(e,t,n)=>(v(e,t,"access private method"),n),x,S,M,W,O,A,z,ne,U,D,Te={exports:{}},K=typeof Reflect=="object"?Reflect:null,He=K&&typeof K.apply=="function"?K.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},Le;K&&typeof K.ownKeys=="function"?Le=K.ownKeys:Object.getOwnPropertySymbols?Le=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Le=function(e){return Object.getOwnPropertyNames(e)};function Lt(e){console&&console.warn&&console.warn(e)}var Fe=Number.isNaN||function(e){return e!==e};function f(){f.init.call(this)}Te.exports=f,Te.exports.once=xt,f.EventEmitter=f,f.prototype._events=void 0,f.prototype._eventsCount=0,f.prototype._maxListeners=void 0;var qe=10;function Ie(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return qe},set:function(e){if(typeof e!="number"||e<0||Fe(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");qe=e}}),f.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},f.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Fe(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 $e(e){return e._maxListeners===void 0?f.defaultMaxListeners:e._maxListeners}f.prototype.getMaxListeners=function(){return $e(this)},f.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e==="error",r=this._events;if(r!==void 0)i=i&&r.error===void 0;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var l=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw l.context=s,l}var _=r[e];if(_===void 0)return!1;if(typeof _=="function")He(_,this,t);else for(var ae=_.length,De=Ve(_,ae),n=0;n<ae;++n)He(De[n],this,t);return!0};function ze(e,t,n,i){var r,s,l;if(Ie(n),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),l=s[t]),l===void 0)l=s[t]=n,++e._eventsCount;else if(typeof l=="function"?l=s[t]=i?[n,l]:[l,n]:i?l.unshift(n):l.push(n),r=$e(e),r>0&&l.length>r&&!l.warned){l.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+l.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=e,_.type=t,_.count=l.length,Lt(_)}return e}f.prototype.addListener=function(e,t){return ze(this,e,t,!1)},f.prototype.on=f.prototype.addListener,f.prototype.prependListener=function(e,t){return ze(this,e,t,!0)};function It(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ke(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=It.bind(i);return r.listener=n,i.wrapFn=r,r}f.prototype.once=function(e,t){return Ie(t),this.on(e,Ke(this,e,t)),this},f.prototype.prependOnceListener=function(e,t){return Ie(t),this.prependListener(e,Ke(this,e,t)),this},f.prototype.removeListener=function(e,t){var n,i,r,s,l;if(Ie(t),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){l=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():Ct(n,r),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,l||t)}return this},f.prototype.off=f.prototype.removeListener,f.prototype.removeAllListeners=function(e){var t,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var r=Object.keys(n),s;for(i=0;i<r.length;++i)s=r[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this};function Xe(e,t,n){var i=e._events;if(i===void 0)return[];var r=i[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?kt(r):Ve(r,r.length)}f.prototype.listeners=function(e){return Xe(this,e,!0)},f.prototype.rawListeners=function(e){return Xe(this,e,!1)},f.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Je.call(e,t)},f.prototype.listenerCount=Je;function Je(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}f.prototype.eventNames=function(){return this._eventsCount>0?Le(this._events):[]};function Ve(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function Ct(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function kt(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function xt(e,t){return new Promise(function(n,i){function r(l){e.removeListener(t,s),i(l)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",r),n([].slice.call(arguments))}Ze(e,t,s,{once:!0}),t!=="error"&&Pt(e,r,{once:!0})})}function Pt(e,t,n){typeof e.on=="function"&&Ze(e,"error",t,n)}function Ze(e,t,n,i){if(typeof e.on=="function")i.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener=="function")e.addEventListener(t,function r(s){i.once&&e.removeEventListener(t,r),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var St=Te.exports;const ie="pc-designer-iframe-wrapper",Ce="pc-designer-iframe";class Tt{constructor(t){b(this,M),b(this,O),b(this,z),b(this,U),u(this,"token"),u(this,"productId"),u(this,"options"),b(this,x,void 0),b(this,S,void 0);var n;if(this.token=t.token,this.productId=t.productId,this.options=t.options,k(this,x,(n=this.options)!=null&&n.designerUrl?this.options.designerUrl:{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),k(this,S,new St),!this.token||!this.productId){console.error("Missing Config Params");return}h(this,M,W).call(this),h(this,O,A).call(this)}render(){const t=document.getElementById(ie),n=document.getElementById(Ce);if(!n||!(n instanceof HTMLIFrameElement)||!t){console.error("Can not find iframe element");return}const i=h(this,z,ne).call(this);n.src=i.href,t.style.opacity="1",t.style.visibility="visible",h(this,U,D).call(this,"rendered")}close(){const t=document.getElementById(ie);if(!t){console.error("Can not find iframe element");return}t.style.opacity="0",t.style.visibility="hidden",h(this,U,D).call(this,"closed")}editDesign(t){const n=h(this,z,ne).call(this);n.searchParams.set("design_id",t),n.searchParams.set("task","edit");const i=document.getElementById(ie),r=document.getElementById(Ce);if(!r||!(r instanceof HTMLIFrameElement)||!i){console.error("Can not find iframe element");return}r.src=n.href,i.style.opacity="1",i.style.visibility="visible",h(this,U,D).call(this,"edit")}on(t,n){return L(this,S).on(t,n),this}}x=new WeakMap,S=new WeakMap,M=new WeakSet,W=function(){const e=document.createElement("div");e.id=ie,e.style.cssText="position:fixed;top:0;left:0;width:100vw;height:100vh;opacity:0;visibility:hidden;z-index:99999";const t=document.createElement("iframe");t.id=Ce,t.width="100%",t.height="100%",e.appendChild(t),document.body.appendChild(e)},O=new WeakSet,A=function(){window.addEventListener("message",e=>{if(e.origin===L(this,x)&&e.data.message==="closeDesignTool"){const t=document.getElementById(ie);if(!t)return;t.style.opacity="0",t.style.visibility="hidden",h(this,U,D).call(this,"closed")}if(e.data.message==="finishLoad"){const t=document.getElementById(Ce);h(this,U,D).call(this,"render-finish"),t&&t instanceof HTMLIFrameElement&&t.contentWindow&&t.contentWindow.postMessage({message:"customSettings",settings:this.options},L(this,x))}e.data.message==="finishProcess"&&h(this,U,D).call(this,"upload-success",e.data.data.data),e.data.message==="finishUpdate"&&h(this,U,D).call(this,"edit-success",e.data.data.data),e.data.message==="uploadError"&&h(this,U,D).call(this,"upload-error",e.data)},!1)},z=new WeakSet,ne=function(){const e=new URL(L(this,x));return e.searchParams.set("api_key",this.token),e.searchParams.set("product_id",this.productId),e.searchParams.set("parentUrl",window.location.href),e},U=new WeakSet,D=function(e,...t){L(this,S).emit(e,...t)};var Me=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},T=(e,t,n)=>(Me(e,t,"read from private field"),n?n.call(e):t.get(e)),N=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},X=(e,t,n,i)=>(Me(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),H=(e,t,n)=>(Me(e,t,"access private method"),n),re,J,V,se,oe,ce,F,Z,Oe,Ye,Ue,Ge,je={exports:{}},Y=typeof Reflect=="object"?Reflect:null,Qe=Y&&typeof Y.apply=="function"?Y.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},ke;Y&&typeof Y.ownKeys=="function"?ke=Y.ownKeys:Object.getOwnPropertySymbols?ke=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ke=function(e){return Object.getOwnPropertyNames(e)};function Mt(e){console&&console.warn&&console.warn(e)}var et=Number.isNaN||function(e){return e!==e};function m(){m.init.call(this)}je.exports=m,je.exports.once=Wt,m.EventEmitter=m,m.prototype._events=void 0,m.prototype._eventsCount=0,m.prototype._maxListeners=void 0;var tt=10;function xe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(m,"defaultMaxListeners",{enumerable:!0,get:function(){return tt},set:function(e){if(typeof e!="number"||e<0||et(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");tt=e}}),m.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},m.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||et(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 nt(e){return e._maxListeners===void 0?m.defaultMaxListeners:e._maxListeners}m.prototype.getMaxListeners=function(){return nt(this)},m.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e==="error",r=this._events;if(r!==void 0)i=i&&r.error===void 0;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var l=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw l.context=s,l}var _=r[e];if(_===void 0)return!1;if(typeof _=="function")Qe(_,this,t);else for(var ae=_.length,De=ct(_,ae),n=0;n<ae;++n)Qe(De[n],this,t);return!0};function it(e,t,n,i){var r,s,l;if(xe(n),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),l=s[t]),l===void 0)l=s[t]=n,++e._eventsCount;else if(typeof l=="function"?l=s[t]=i?[n,l]:[l,n]:i?l.unshift(n):l.push(n),r=nt(e),r>0&&l.length>r&&!l.warned){l.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+l.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=e,_.type=t,_.count=l.length,Mt(_)}return e}m.prototype.addListener=function(e,t){return it(this,e,t,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(e,t){return it(this,e,t,!0)};function Ot(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function rt(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=Ot.bind(i);return r.listener=n,i.wrapFn=r,r}m.prototype.once=function(e,t){return xe(t),this.on(e,rt(this,e,t)),this},m.prototype.prependOnceListener=function(e,t){return xe(t),this.prependListener(e,rt(this,e,t)),this},m.prototype.removeListener=function(e,t){var n,i,r,s,l;if(xe(t),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){l=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():Ut(n,r),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,l||t)}return this},m.prototype.off=m.prototype.removeListener,m.prototype.removeAllListeners=function(e){var t,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var r=Object.keys(n),s;for(i=0;i<r.length;++i)s=r[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this};function st(e,t,n){var i=e._events;if(i===void 0)return[];var r=i[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?jt(r):ct(r,r.length)}m.prototype.listeners=function(e){return st(this,e,!0)},m.prototype.rawListeners=function(e){return st(this,e,!1)},m.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ot.call(e,t)},m.prototype.listenerCount=ot;function ot(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}m.prototype.eventNames=function(){return this._eventsCount>0?ke(this._events):[]};function ct(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function Ut(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function jt(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function Wt(e,t){return new Promise(function(n,i){function r(l){e.removeListener(t,s),i(l)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",r),n([].slice.call(arguments))}at(e,t,s,{once:!0}),t!=="error"&&Dt(e,r,{once:!0})})}function Dt(e,t,n){typeof e.on=="function"&&at(e,"error",t,n)}function at(e,t,n,i){if(typeof e.on=="function")i.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener=="function")e.addEventListener(t,function r(s){i.once&&e.removeEventListener(t,r),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var Nt=je.exports;const Pe="pc-uploader-iframe-wrapper",We="pc-uploader-iframe";class Rt{constructor(t){if(N(this,F),N(this,Oe),N(this,Ue),N(this,re,void 0),N(this,J,void 0),N(this,V,void 0),N(this,se,void 0),N(this,oe,void 0),N(this,ce,void 0),X(this,re,t.token),X(this,J,t.sideId||t.productId),X(this,ce,t.productId?"product":"side"),X(this,V,t.uploaderUrl?t.uploaderUrl:"https://upload-tool.pages.dev"),X(this,se,new Nt),X(this,oe,t.locale),!T(this,re)||!T(this,J)){console.warn("Missing Config Params.");return}H(this,Oe,Ye).call(this),H(this,Ue,Ge).call(this)}get locale(){return T(this,oe)}open(){let t=document.getElementById(Pe),n=document.getElementById(We);const i=new URL(T(this,V));if(i.searchParams.set("token",T(this,re)),T(this,ce)==="side"?i.searchParams.set("sideId",T(this,J)):T(this,ce)==="product"&&i.searchParams.set("productId",T(this,J)),i.searchParams.set("parentUrl",window.location.href),!n||!(n instanceof HTMLIFrameElement)||!t){console.warn("Can not find iframe element.");return}n.src=i.href,t.style.opacity="1",t.style.visibility="visible",H(this,F,Z).call(this,"open")}close(){let t=document.getElementById(Pe);if(!t){console.error("Can not find iframe element");return}t.style.opacity="0",t.style.visibility="hidden"}on(t,n){return T(this,se).on(t,n),this}}re=new WeakMap,J=new WeakMap,V=new WeakMap,se=new WeakMap,oe=new WeakMap,ce=new WeakMap,F=new WeakSet,Z=function(e,...t){T(this,se).emit(e,...t)},Oe=new WeakSet,Ye=function(){let e=document.createElement("div");e.id=Pe,e.style.cssText="position:fixed;top:0;left:0;width:100vw;height:100vh;opacity:0;visibility:hidden;z-index:99999";let t=document.createElement("iframe");t.id=We,t.width="100%",t.height="100%",t.style.borderWidth="0",e.appendChild(t),document.body.appendChild(e)},Ue=new WeakSet,Ge=function(){let e=document.getElementById(Pe);window.addEventListener("message",t=>{var n;const i=new URL(t.origin),r=new URL(T(this,V));if(i.host===r.host){t.data.uploaderEvent==="close"&&e&&(e.style.opacity="0",e.style.visibility="hidden",H(this,F,Z).call(this,"close")),t.data.uploaderEvent==="upload-success"&&H(this,F,Z).call(this,"upload-success",t.data.data),t.data.uploaderEvent==="upload-error"&&H(this,F,Z).call(this,"upload-error",t.data.error);const s=T(this,oe),l=document.getElementById(We);l&&l instanceof HTMLIFrameElement&&(H(this,F,Z).call(this,"onload"),s&&t.data.uploaderEvent==="loaded"&&t.data.finished&&(console.log("test"),l.focus(),(n=l.contentWindow)==null||n.postMessage({locale:s},T(this,V))))}},!1)};class Bt{constructor(){o(this,"initDesignTool",t=>new Tt(t)),o(this,"initUploader",t=>new Rt(t))}}return Bt}(),y=new g;class I{constructor(){E(this,ee);E(this,te);E(this,le);E(this,de);E(this,R);E(this,ue);E(this,pe);E(this,he);E(this,fe);E(this,me);E(this,ve);E(this,ge);E(this,ye);E(this,we);E(this,be);E(this,_e);E(this,Ee);E(this,$,void 0);B(this,"token");B(this,"appID");B(this,"productIdPC");B(this,"orderIdWix");B(this,"orderNumberWix");B(this,"options");E(this,Q,void 0);E(this,C,void 0);E(this,P,void 0);E(this,j,void 0);B(this,"registerListener");this.token=w(this,ge,gt).call(this),this.productIdPC=null,this.appID="325c68a5-64c2-440d-b093-8cea369df06b",this.orderIdWix=null,this.orderNumberWix=null,q(this,j,null),this.options=window.PrintcartDesignerShopifyOptions,q(this,$,"https://api.printcart.com/v1"),q(this,Q,"https://customizer.printcart.com")}init(){const c=window,o=this;c!=null&&c.wixDevelopersAnalytics?w(this,ee,Re).call(this,"first"):c.addEventListener("wixDevelopersAnalyticsReady",function(){var a;w(a=o,ee,Re).call(a,"second")})}}$=new WeakMap,Q=new WeakMap,C=new WeakMap,P=new WeakMap,j=new WeakMap,ee=new WeakSet,Re=function(c){const o=this;console.log("Printcart start App "+c),window==null||window.wixDevelopersAnalytics.register(this.appID,function(d,u){var v,L,b;switch(d){case"ViewContent":localStorage.getItem("pc-product")&&localStorage.removeItem("pc-product");break;case"productPageLoaded":if(console.log("Printcart: productPageLoaded",u),u.variants&&u.variants.length>1)return;w(v=o,te,Be).call(v,u==null?void 0:u.productId);break;case"CustomizeProduct":if(u.variants&&u.variants.length<1)return;w(L=o,te,Be).call(L,u==null?void 0:u.variantId);break;case"Purchase":if(!localStorage.getItem("pc-design-ids"))return;const k=localStorage.getItem("pc-design-ids");if(o.orderIdWix=u==null?void 0:u.orderId,o.orderNumberWix=u==null?void 0:u.id,!o.orderIdWix)throw new Error("Can not find order ID WIX");if(!o.orderNumberWix)throw new Error("Can not find order number WIX");if(!k)throw new Error("Can not find design Ids");w(b=o,Ee,Et).call(b,o.orderNumberWix,o.orderIdWix,JSON.parse(k));break}})},te=new WeakSet,Be=function(c){if(q(this,j,document.querySelector("[data-hook='product-options']")),!p(this,j))throw new Error("This script can only be used inside a Wix Product Page.");if(!c)throw new Error("Can not find product ID WIX");w(this,be,bt).call(this,c).then(o=>{var L,b;if(this.productIdPC=(L=o==null?void 0:o.data)==null?void 0:L.id,!this.productIdPC)throw new Error("Can not find product ID Printcart");w(this,we,wt).call(this),w(this,_e,_t).call(this),w(this,le,lt).call(this),w(this,ue,ut).call(this),w(this,pe,pt).call(this);const a=document.querySelector("button#pc-btn"),d=o.data.enable_design,u=o.data.enable_upload;d&&(q(this,C,y.initDesignTool({token:this.token,productId:this.productIdPC,options:{...(b=this.options)==null?void 0:b.designerOptions,designerUrl:p(this,Q)}})),w(this,ve,vt).call(this),a&&a instanceof HTMLButtonElement&&(a.disabled=!1)),u&&(q(this,P,y.initUploader({token:this.token,productId:this.productIdPC})),w(this,me,mt).call(this),a&&a instanceof HTMLButtonElement&&(a.disabled=!1));const v=()=>{p(this,C)&&!p(this,P)&&p(this,C).render(),!p(this,C)&&p(this,P)&&p(this,P).open(),p(this,C)&&p(this,P)&&w(this,de,dt).call(this)};a&&a instanceof HTMLButtonElement&&(a.onclick=v)})},le=new WeakSet,lt=function(){const a='<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">Choose a way to design this product</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="https://files.printcart.com/common/upload.svg" alt="Printcart Uploader"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">Upload a full design</h2><ul><li>Have a complete design</li><li>Have your own designer</li></ul></div></div></div><div class="visually-hidden">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="https://files.printcart.com/common/design.svg" alt="Printcart Designer"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">Design here online</h2><ul><li>Already have your concept</li><li>Customize every details</li></ul></div></div></div><div class="visually-hidden">Upload Design file</div></button></div></div></div>',d=document.createElement("div");d.id="pc-select_wrap",d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("tabIndex","-1"),d.innerHTML=a,document.body.appendChild(d);const u=()=>{p(this,C)&&(w(this,R,G).call(this),p(this,C).render(),document.body.classList.add("pc-overflow"))},v=()=>{p(this,P)&&(w(this,R,G).call(this),p(this,P).open(),document.body.classList.add("pc-overflow"))},L=document.getElementById("pc-select_btn_upload"),b=document.getElementById("pc-select_btn_design");L&&(L==null||L.addEventListener("click",v)),b&&(b==null||b.addEventListener("click",u))},de=new WeakSet,dt=function(){const c=document.getElementById("pc-select_wrap");c&&(c.style.display="flex",document.body.classList.add("pc-overflow"));const o=c==null?void 0:c.querySelector("#pc-select_close-btn");o&&o instanceof HTMLButtonElement&&o.focus()},R=new WeakSet,G=function(){const c=document.getElementById("pc-select_wrap");c&&(c.style.display="none"),document.body.classList.remove("pc-overflow")},ue=new WeakSet,ut=function(){const c=document.getElementById("pc-select_close-btn"),o=document.getElementById("pc-content-overlay"),a=d=>{d.key==="Escape"&&w(this,R,G).call(this)};window.addEventListener("keydown",a),c==null||c.addEventListener("click",()=>w(this,R,G).call(this)),o==null||o.addEventListener("click",()=>{const d=document.getElementById("pc-designer-iframe-wrapper");(d==null?void 0:d.style.visibility)!=="visible"&&w(this,R,G).call(this)})},pe=new WeakSet,pt=function(){const c=document.getElementById("pc-select_wrap"),o=c==null?void 0:c.querySelectorAll("button"),a=o&&o[0],d=o&&o[o.length-1],u=v=>{v.key==="Tab"&&(v.shiftKey?d&&document.activeElement===a&&(d.focus(),v.preventDefault()):a&&document.activeElement===d&&(a.focus(),v.preventDefault()))};window.addEventListener("keydown",u)},he=new WeakSet,ht=function(c){var L,b;const o=c.map(k=>k.data.id);let a=document.querySelector('input[name="properties[_pcDesignIds]"]');a?a.value+=`,${o.join()}`:(a=document.createElement("input"),a.type="hidden",a.name="properties[_pcDesignIds]",a.className="pc-designer_input",a.value=o.join(),(L=p(this,j))==null||L.appendChild(a));const d=document.querySelector(".pc-preview-wrap")||document.createElement("div");d.className="pc-preview-wrap",localStorage.getItem("pc-design-ids")&&localStorage.removeItem("pc-design-ids"),localStorage.setItem("pc-design-ids",JSON.stringify(o)),c.forEach(k=>{var W;if(!k.data.design_image.url)return;const h=document.createElement("div");h.className="pc-preview",h.setAttribute("data-pc-design-id",k.data.id);const x=document.createElement("button");x.className="pc-btn pc-danger-btn",x.innerHTML=(W=this.options)!=null&&W.removeUploaderBtnText?this.options.removeUploaderBtnText:"Remove",x.onclick=()=>{const O=a.value.split(",").filter(A=>A!==k.data.id);a.value=O.join(),h.remove()};const S=document.createElement("img");S.src=k.data.design_image.url,S.className="pc-uploader-image";const M=document.createElement("div");M.className="pc-preview-overlay",M.appendChild(x),h.appendChild(M),h.appendChild(S),d.appendChild(h)});const u=document.querySelector("div#pc-designer_wrap");if(!document.querySelector(".princart-preview-heading")){const k=document.createElement("h5");k.className="princart-preview-heading",k.innerHTML="Your artworks",u==null||u.appendChild(k)}u==null||u.appendChild(d);const v=(b=this.options)==null?void 0:b.onUploadSuccess;v&&v(c,p(this,P))},fe=new WeakSet,ft=function(c){var b,k;const o=this,a=c.map(h=>h.id);let d=document.querySelector('input[name="properties[_pcDesignIds]"]');d?d.value+=`,${a.join()}`:(d=document.createElement("input"),d.type="hidden",d.name="properties[_pcDesignIds]",d.className="pc-designer_input",d.value=a.join(),(b=p(this,j))==null||b.appendChild(d));const u=document.querySelector(".pc-preview-wrap")||document.createElement("div");u.className="pc-preview-wrap",localStorage.getItem("pc-design-ids")&&localStorage.removeItem("pc-design-ids"),localStorage.setItem("pc-design-ids",JSON.stringify(a)),c.forEach(h=>{var A;if(!h.design_image.url)return;const x=document.createElement("div");x.className="pc-preview",x.setAttribute("data-pc-design-id",h.id);const S=document.createElement("button");S.className="pc-btn pc-primary-btn",S.style.borderRadius="5px",S.innerHTML="Edit",S.onclick=()=>{p(o,C).editDesign(h.id)};const M=document.createElement("button");M.className="pc-btn pc-danger-btn",M.style.borderRadius="5px",M.innerHTML="Remove",M.onclick=()=>{const z=d.value.split(",").filter(ne=>ne!==h.id);d.value=z.join(),x.remove()};const W=document.createElement("img");W.src=((A=h.preview_image)==null?void 0:A.url)||h.design_image.url,W.className="pc-uploader-image";const O=document.createElement("div");O.className="pc-preview-overlay",O.appendChild(S),O.appendChild(M),x.appendChild(O),x.appendChild(W),u.appendChild(x)});const v=document.querySelector("div#pc-designer_wrap");v==null||v.appendChild(u);const L=(k=this.options)==null?void 0:k.onDesignCreateSuccess;L&&L(c,p(this,C))},me=new WeakSet,mt=function(){p(this,P)&&(p(this,P).on("upload-success",c=>{w(this,he,ht).call(this,c),p(this,P).close()}),p(this,P).on("close",()=>{document.body.classList.remove("pc-overflow")}))},ve=new WeakSet,vt=function(){p(this,C)&&(p(this,C).on("upload-success",c=>{w(this,fe,ft).call(this,c),p(this,C).close()}),p(this,C).on("closed",()=>{document.body.classList.remove("pc-overflow")}),p(this,C).on("edit-success",c=>{var d;if(!c.design_image.url)return;const o=document.querySelector(`[data-pc-design-id="${c.id}"] img`);if(!o||!(o instanceof HTMLImageElement))throw new Error("Can't find image element");o.src=c.design_image.url;const a=(d=this.options)==null?void 0:d.onDesignEditSuccess;p(this,C).close(),a&&a(c,p(this,C))}))},ge=new WeakSet,gt=function(){const c=w(this,ye,yt).call(this),o=new URL(c);return new URLSearchParams(o.search).get("shopT")},ye=new WeakSet,yt=function(){return document.querySelector("[id='pc-wix-integration-sdk']").src},we=new WeakSet,wt=function(){const c="https://unpkg.com/@printcart/wix-integration/dist",o=document.createElement("link");o.rel="stylesheet",o.href=`${c}/style.css`,document.head.appendChild(o)},be=new WeakSet,bt=async function(c){try{const o=`${p(this,$)}/integration/wix/products/${c}`,a=this.token;if(!a)throw new Error("Missing Printcart Unauth Token");return await(await fetch(o,{headers:{"X-PrintCart-Unauth-Token":a}})).json()}catch(o){console.error("There has been a problem with your fetch operation:",o);return}},_e=new WeakSet,_t=function(){var d,u,v;const c=p(this,j);if(!(c!=null&&c.parentNode)){console.log("Can not find cart form");return}if(document.getElementById("pc-designer_wrap")!==null)return;const o=document.createElement("div");o.id="pc-designer_wrap";const a=document.createElement("button");a.id="pc-btn",a.className=(d=this.options)!=null&&d.designClassName?(u=this.options)==null?void 0:u.designClassName:"",a.innerHTML=(v=this.options)!=null&&v.designBtnText?this.options.designBtnText:"Start Design",a.disabled=!0,o.appendChild(a),c.appendChild(o)},Ee=new WeakSet,Et=async function(c,o,a){try{const d=`${p(this,$)}/projects`,u=this.token;if(!u)throw new Error("Missing Printcart Unauth Token");const v={name:`${c}`,status:"processing",design_ids:a,order_detail:{id:o}};await fetch(d,{method:"POST",headers:{"Content-Type":"application/json","X-PrintCart-Unauth-Token":u},body:JSON.stringify(v)})}catch(d){console.error("There has been a problem with your fetch operation:",d);return}},new I().init()})()}); | ||
var At=Object.defineProperty;var Ht=(g,w,I)=>w in g?At(g,w,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[w]=I;var B=(g,w,I)=>(Ht(g,typeof w!="symbol"?w+"":w,I),I),Ne=(g,w,I)=>{if(!w.has(g))throw TypeError("Cannot "+I)};var u=(g,w,I)=>(Ne(g,w,"read from private field"),I?I.call(g):w.get(g)),E=(g,w,I)=>{if(w.has(g))throw TypeError("Cannot add the same private member more than once");w instanceof WeakSet?w.add(g):w.set(g,I)},q=(g,w,I,le)=>(Ne(g,w,"write to private field"),le?le.call(g,I):w.set(g,I),I);var y=(g,w,I)=>(Ne(g,w,"access private method"),I);(function(g){typeof define=="function"&&define.amd?define(g):g()})(function(){var $,Q,C,P,j,ee,Re,te,Be,de,lt,pe,dt,R,G,ue,pt,he,ut,fe,ht,me,ft,ve,mt,ge,vt,ye,gt,we,yt,be,wt,_e,bt,Ee,_t,Le,Et;"use strict";const g=function(){var Ae=Object.defineProperty,c=(e,t,n)=>t in e?Ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,o=(e,t,n)=>(c(e,typeof t!="symbol"?t+"":t,n),n),a=Object.defineProperty,d=(e,t,n)=>t in e?a(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t,n)=>(d(e,typeof t!="symbol"?t+"":t,n),n),v=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},L=(e,t,n)=>(v(e,t,"read from private field"),n?n.call(e):t.get(e)),b=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},k=(e,t,n,i)=>(v(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),h=(e,t,n)=>(v(e,t,"access private method"),n),x,S,M,W,O,A,z,ne,U,D,Te={exports:{}},K=typeof Reflect=="object"?Reflect:null,He=K&&typeof K.apply=="function"?K.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},Ie;K&&typeof K.ownKeys=="function"?Ie=K.ownKeys:Object.getOwnPropertySymbols?Ie=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Ie=function(e){return Object.getOwnPropertyNames(e)};function Lt(e){console&&console.warn&&console.warn(e)}var Fe=Number.isNaN||function(e){return e!==e};function f(){f.init.call(this)}Te.exports=f,Te.exports.once=xt,f.EventEmitter=f,f.prototype._events=void 0,f.prototype._eventsCount=0,f.prototype._maxListeners=void 0;var qe=10;function Ce(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return qe},set:function(e){if(typeof e!="number"||e<0||Fe(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");qe=e}}),f.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},f.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Fe(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 $e(e){return e._maxListeners===void 0?f.defaultMaxListeners:e._maxListeners}f.prototype.getMaxListeners=function(){return $e(this)},f.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e==="error",r=this._events;if(r!==void 0)i=i&&r.error===void 0;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var l=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw l.context=s,l}var _=r[e];if(_===void 0)return!1;if(typeof _=="function")He(_,this,t);else for(var ae=_.length,De=Ve(_,ae),n=0;n<ae;++n)He(De[n],this,t);return!0};function ze(e,t,n,i){var r,s,l;if(Ce(n),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),l=s[t]),l===void 0)l=s[t]=n,++e._eventsCount;else if(typeof l=="function"?l=s[t]=i?[n,l]:[l,n]:i?l.unshift(n):l.push(n),r=$e(e),r>0&&l.length>r&&!l.warned){l.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+l.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=e,_.type=t,_.count=l.length,Lt(_)}return e}f.prototype.addListener=function(e,t){return ze(this,e,t,!1)},f.prototype.on=f.prototype.addListener,f.prototype.prependListener=function(e,t){return ze(this,e,t,!0)};function It(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ke(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=It.bind(i);return r.listener=n,i.wrapFn=r,r}f.prototype.once=function(e,t){return Ce(t),this.on(e,Ke(this,e,t)),this},f.prototype.prependOnceListener=function(e,t){return Ce(t),this.prependListener(e,Ke(this,e,t)),this},f.prototype.removeListener=function(e,t){var n,i,r,s,l;if(Ce(t),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){l=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():Ct(n,r),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,l||t)}return this},f.prototype.off=f.prototype.removeListener,f.prototype.removeAllListeners=function(e){var t,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var r=Object.keys(n),s;for(i=0;i<r.length;++i)s=r[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this};function Xe(e,t,n){var i=e._events;if(i===void 0)return[];var r=i[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?kt(r):Ve(r,r.length)}f.prototype.listeners=function(e){return Xe(this,e,!0)},f.prototype.rawListeners=function(e){return Xe(this,e,!1)},f.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Je.call(e,t)},f.prototype.listenerCount=Je;function Je(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}f.prototype.eventNames=function(){return this._eventsCount>0?Ie(this._events):[]};function Ve(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function Ct(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function kt(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function xt(e,t){return new Promise(function(n,i){function r(l){e.removeListener(t,s),i(l)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",r),n([].slice.call(arguments))}Ze(e,t,s,{once:!0}),t!=="error"&&Pt(e,r,{once:!0})})}function Pt(e,t,n){typeof e.on=="function"&&Ze(e,"error",t,n)}function Ze(e,t,n,i){if(typeof e.on=="function")i.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener=="function")e.addEventListener(t,function r(s){i.once&&e.removeEventListener(t,r),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var St=Te.exports;const ie="pc-designer-iframe-wrapper",ke="pc-designer-iframe";class Tt{constructor(t){b(this,M),b(this,O),b(this,z),b(this,U),p(this,"token"),p(this,"productId"),p(this,"options"),b(this,x,void 0),b(this,S,void 0);var n;if(this.token=t.token,this.productId=t.productId,this.options=t.options,k(this,x,(n=this.options)!=null&&n.designerUrl?this.options.designerUrl:{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),k(this,S,new St),!this.token||!this.productId){console.error("Missing Config Params");return}h(this,M,W).call(this),h(this,O,A).call(this)}render(){const t=document.getElementById(ie),n=document.getElementById(ke);if(!n||!(n instanceof HTMLIFrameElement)||!t){console.error("Can not find iframe element");return}const i=h(this,z,ne).call(this);n.src=i.href,t.style.opacity="1",t.style.visibility="visible",h(this,U,D).call(this,"rendered")}close(){const t=document.getElementById(ie);if(!t){console.error("Can not find iframe element");return}t.style.opacity="0",t.style.visibility="hidden",h(this,U,D).call(this,"closed")}editDesign(t){const n=h(this,z,ne).call(this);n.searchParams.set("design_id",t),n.searchParams.set("task","edit");const i=document.getElementById(ie),r=document.getElementById(ke);if(!r||!(r instanceof HTMLIFrameElement)||!i){console.error("Can not find iframe element");return}r.src=n.href,i.style.opacity="1",i.style.visibility="visible",h(this,U,D).call(this,"edit")}on(t,n){return L(this,S).on(t,n),this}}x=new WeakMap,S=new WeakMap,M=new WeakSet,W=function(){const e=document.createElement("div");e.id=ie,e.style.cssText="position:fixed;top:0;left:0;width:100vw;height:100vh;opacity:0;visibility:hidden;z-index:99999";const t=document.createElement("iframe");t.id=ke,t.width="100%",t.height="100%",e.appendChild(t),document.body.appendChild(e)},O=new WeakSet,A=function(){window.addEventListener("message",e=>{if(e.origin===L(this,x)&&e.data.message==="closeDesignTool"){const t=document.getElementById(ie);if(!t)return;t.style.opacity="0",t.style.visibility="hidden",h(this,U,D).call(this,"closed")}if(e.data.message==="finishLoad"){const t=document.getElementById(ke);h(this,U,D).call(this,"render-finish"),t&&t instanceof HTMLIFrameElement&&t.contentWindow&&t.contentWindow.postMessage({message:"customSettings",settings:this.options},L(this,x))}e.data.message==="finishProcess"&&h(this,U,D).call(this,"upload-success",e.data.data.data),e.data.message==="finishUpdate"&&h(this,U,D).call(this,"edit-success",e.data.data.data),e.data.message==="uploadError"&&h(this,U,D).call(this,"upload-error",e.data)},!1)},z=new WeakSet,ne=function(){const e=new URL(L(this,x));return e.searchParams.set("api_key",this.token),e.searchParams.set("product_id",this.productId),e.searchParams.set("parentUrl",window.location.href),e},U=new WeakSet,D=function(e,...t){L(this,S).emit(e,...t)};var Me=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},T=(e,t,n)=>(Me(e,t,"read from private field"),n?n.call(e):t.get(e)),N=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},X=(e,t,n,i)=>(Me(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),H=(e,t,n)=>(Me(e,t,"access private method"),n),re,J,V,se,oe,ce,F,Z,Oe,Ye,Ue,Ge,je={exports:{}},Y=typeof Reflect=="object"?Reflect:null,Qe=Y&&typeof Y.apply=="function"?Y.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},xe;Y&&typeof Y.ownKeys=="function"?xe=Y.ownKeys:Object.getOwnPropertySymbols?xe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:xe=function(e){return Object.getOwnPropertyNames(e)};function Mt(e){console&&console.warn&&console.warn(e)}var et=Number.isNaN||function(e){return e!==e};function m(){m.init.call(this)}je.exports=m,je.exports.once=Wt,m.EventEmitter=m,m.prototype._events=void 0,m.prototype._eventsCount=0,m.prototype._maxListeners=void 0;var tt=10;function Pe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(m,"defaultMaxListeners",{enumerable:!0,get:function(){return tt},set:function(e){if(typeof e!="number"||e<0||et(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");tt=e}}),m.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},m.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||et(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 nt(e){return e._maxListeners===void 0?m.defaultMaxListeners:e._maxListeners}m.prototype.getMaxListeners=function(){return nt(this)},m.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e==="error",r=this._events;if(r!==void 0)i=i&&r.error===void 0;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var l=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw l.context=s,l}var _=r[e];if(_===void 0)return!1;if(typeof _=="function")Qe(_,this,t);else for(var ae=_.length,De=ct(_,ae),n=0;n<ae;++n)Qe(De[n],this,t);return!0};function it(e,t,n,i){var r,s,l;if(Pe(n),s=e._events,s===void 0?(s=e._events=Object.create(null),e._eventsCount=0):(s.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),l=s[t]),l===void 0)l=s[t]=n,++e._eventsCount;else if(typeof l=="function"?l=s[t]=i?[n,l]:[l,n]:i?l.unshift(n):l.push(n),r=nt(e),r>0&&l.length>r&&!l.warned){l.warned=!0;var _=new Error("Possible EventEmitter memory leak detected. "+l.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");_.name="MaxListenersExceededWarning",_.emitter=e,_.type=t,_.count=l.length,Mt(_)}return e}m.prototype.addListener=function(e,t){return it(this,e,t,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(e,t){return it(this,e,t,!0)};function Ot(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function rt(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=Ot.bind(i);return r.listener=n,i.wrapFn=r,r}m.prototype.once=function(e,t){return Pe(t),this.on(e,rt(this,e,t)),this},m.prototype.prependOnceListener=function(e,t){return Pe(t),this.prependListener(e,rt(this,e,t)),this},m.prototype.removeListener=function(e,t){var n,i,r,s,l;if(Pe(t),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(r=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){l=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():Ut(n,r),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,l||t)}return this},m.prototype.off=m.prototype.removeListener,m.prototype.removeAllListeners=function(e){var t,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var r=Object.keys(n),s;for(i=0;i<r.length;++i)s=r[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this};function st(e,t,n){var i=e._events;if(i===void 0)return[];var r=i[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?jt(r):ct(r,r.length)}m.prototype.listeners=function(e){return st(this,e,!0)},m.prototype.rawListeners=function(e){return st(this,e,!1)},m.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ot.call(e,t)},m.prototype.listenerCount=ot;function ot(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}m.prototype.eventNames=function(){return this._eventsCount>0?xe(this._events):[]};function ct(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function Ut(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function jt(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function Wt(e,t){return new Promise(function(n,i){function r(l){e.removeListener(t,s),i(l)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",r),n([].slice.call(arguments))}at(e,t,s,{once:!0}),t!=="error"&&Dt(e,r,{once:!0})})}function Dt(e,t,n){typeof e.on=="function"&&at(e,"error",t,n)}function at(e,t,n,i){if(typeof e.on=="function")i.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener=="function")e.addEventListener(t,function r(s){i.once&&e.removeEventListener(t,r),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var Nt=je.exports;const Se="pc-uploader-iframe-wrapper",We="pc-uploader-iframe";class Rt{constructor(t){if(N(this,F),N(this,Oe),N(this,Ue),N(this,re,void 0),N(this,J,void 0),N(this,V,void 0),N(this,se,void 0),N(this,oe,void 0),N(this,ce,void 0),X(this,re,t.token),X(this,J,t.sideId||t.productId),X(this,ce,t.productId?"product":"side"),X(this,V,t.uploaderUrl?t.uploaderUrl:"https://upload-tool.pages.dev"),X(this,se,new Nt),X(this,oe,t.locale),!T(this,re)||!T(this,J)){console.warn("Missing Config Params.");return}H(this,Oe,Ye).call(this),H(this,Ue,Ge).call(this)}get locale(){return T(this,oe)}open(){let t=document.getElementById(Se),n=document.getElementById(We);const i=new URL(T(this,V));if(i.searchParams.set("token",T(this,re)),T(this,ce)==="side"?i.searchParams.set("sideId",T(this,J)):T(this,ce)==="product"&&i.searchParams.set("productId",T(this,J)),i.searchParams.set("parentUrl",window.location.href),!n||!(n instanceof HTMLIFrameElement)||!t){console.warn("Can not find iframe element.");return}n.src=i.href,t.style.opacity="1",t.style.visibility="visible",H(this,F,Z).call(this,"open")}close(){let t=document.getElementById(Se);if(!t){console.error("Can not find iframe element");return}t.style.opacity="0",t.style.visibility="hidden"}on(t,n){return T(this,se).on(t,n),this}}re=new WeakMap,J=new WeakMap,V=new WeakMap,se=new WeakMap,oe=new WeakMap,ce=new WeakMap,F=new WeakSet,Z=function(e,...t){T(this,se).emit(e,...t)},Oe=new WeakSet,Ye=function(){let e=document.createElement("div");e.id=Se,e.style.cssText="position:fixed;top:0;left:0;width:100vw;height:100vh;opacity:0;visibility:hidden;z-index:99999";let t=document.createElement("iframe");t.id=We,t.width="100%",t.height="100%",t.style.borderWidth="0",e.appendChild(t),document.body.appendChild(e)},Ue=new WeakSet,Ge=function(){let e=document.getElementById(Se);window.addEventListener("message",t=>{var n;const i=new URL(t.origin),r=new URL(T(this,V));if(i.host===r.host){t.data.uploaderEvent==="close"&&e&&(e.style.opacity="0",e.style.visibility="hidden",H(this,F,Z).call(this,"close")),t.data.uploaderEvent==="upload-success"&&H(this,F,Z).call(this,"upload-success",t.data.data),t.data.uploaderEvent==="upload-error"&&H(this,F,Z).call(this,"upload-error",t.data.error);const s=T(this,oe),l=document.getElementById(We);l&&l instanceof HTMLIFrameElement&&(H(this,F,Z).call(this,"onload"),s&&t.data.uploaderEvent==="loaded"&&t.data.finished&&(console.log("test"),l.focus(),(n=l.contentWindow)==null||n.postMessage({locale:s},T(this,V))))}},!1)};class Bt{constructor(){o(this,"initDesignTool",t=>new Tt(t)),o(this,"initUploader",t=>new Rt(t))}}return Bt}();var w="";const I=new g;class le{constructor(){E(this,ee);E(this,te);E(this,de);E(this,pe);E(this,R);E(this,ue);E(this,he);E(this,fe);E(this,me);E(this,ve);E(this,ge);E(this,ye);E(this,we);E(this,be);E(this,_e);E(this,Ee);E(this,Le);E(this,$,void 0);B(this,"token");B(this,"appID");B(this,"productIdPC");B(this,"orderIdWix");B(this,"orderNumberWix");B(this,"options");E(this,Q,void 0);E(this,C,void 0);E(this,P,void 0);E(this,j,void 0);B(this,"registerListener");this.token=y(this,ye,gt).call(this),this.productIdPC=null,this.appID="325c68a5-64c2-440d-b093-8cea369df06b",this.orderIdWix=null,this.orderNumberWix=null,q(this,j,null),this.options=window.PrintcartDesignerShopifyOptions,q(this,$,"https://api.printcart.com/v1"),q(this,Q,"https://customizer.printcart.com")}init(){const c=window,o=this;c!=null&&c.wixDevelopersAnalytics?y(this,ee,Re).call(this,"first"):c.addEventListener("wixDevelopersAnalyticsReady",function(){var a;y(a=o,ee,Re).call(a,"second")})}}$=new WeakMap,Q=new WeakMap,C=new WeakMap,P=new WeakMap,j=new WeakMap,ee=new WeakSet,Re=function(c){const o=this;console.log("Printcart start App "+c),window==null||window.wixDevelopersAnalytics.register(this.appID,function(d,p){var v,L,b;switch(d){case"ViewContent":localStorage.getItem("pc-product")&&localStorage.removeItem("pc-product");break;case"productPageLoaded":if(console.log("Printcart: productPageLoaded",p),p.variants&&p.variants.length>1)return;y(v=o,te,Be).call(v,p==null?void 0:p.productId);break;case"CustomizeProduct":if(p.variants&&p.variants.length<1)return;y(L=o,te,Be).call(L,p==null?void 0:p.variantId);break;case"Purchase":if(!localStorage.getItem("pc-design-ids"))return;const k=localStorage.getItem("pc-design-ids");if(o.orderIdWix=p==null?void 0:p.orderId,o.orderNumberWix=p==null?void 0:p.id,!o.orderIdWix)throw new Error("Can not find order ID WIX");if(!o.orderNumberWix)throw new Error("Can not find order number WIX");if(!k)throw new Error("Can not find design Ids");y(b=o,Le,Et).call(b,o.orderNumberWix,o.orderIdWix,JSON.parse(k));break}})},te=new WeakSet,Be=function(c){if(q(this,j,document.querySelector("[data-hook='product-options']")),!u(this,j))throw new Error("This script can only be used inside a Wix Product Page.");if(!c)throw new Error("Can not find product ID WIX");y(this,_e,bt).call(this,c).then(o=>{var L,b;if(this.productIdPC=(L=o==null?void 0:o.data)==null?void 0:L.id,!this.productIdPC)throw new Error("Can not find product ID Printcart");y(this,be,wt).call(this),y(this,Ee,_t).call(this),y(this,de,lt).call(this),y(this,ue,pt).call(this),y(this,he,ut).call(this);const a=document.querySelector("button#pc-btn"),d=o.data.enable_design,p=o.data.enable_upload;d&&(q(this,C,I.initDesignTool({token:this.token,productId:this.productIdPC,options:{...(b=this.options)==null?void 0:b.designerOptions,designerUrl:u(this,Q)}})),y(this,ge,vt).call(this),a&&a instanceof HTMLButtonElement&&(a.disabled=!1)),p&&(q(this,P,I.initUploader({token:this.token,productId:this.productIdPC})),y(this,ve,mt).call(this),a&&a instanceof HTMLButtonElement&&(a.disabled=!1));const v=()=>{u(this,C)&&!u(this,P)&&u(this,C).render(),!u(this,C)&&u(this,P)&&u(this,P).open(),u(this,C)&&u(this,P)&&y(this,pe,dt).call(this)};a&&a instanceof HTMLButtonElement&&(a.onclick=v)})},de=new WeakSet,lt=function(){const a='<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">Choose a way to design this product</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="https://files.printcart.com/common/upload.svg" alt="Printcart Uploader"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">Upload a full design</h2><ul><li>Have a complete design</li><li>Have your own designer</li></ul></div></div></div><div class="visually-hidden">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="https://files.printcart.com/common/design.svg" alt="Printcart Designer"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">Design here online</h2><ul><li>Already have your concept</li><li>Customize every details</li></ul></div></div></div><div class="visually-hidden">Upload Design file</div></button></div></div></div>',d=document.createElement("div");d.id="pc-select_wrap",d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("tabIndex","-1"),d.innerHTML=a,document.body.appendChild(d);const p=()=>{u(this,C)&&(y(this,R,G).call(this),u(this,C).render(),document.body.classList.add("pc-overflow"))},v=()=>{u(this,P)&&(y(this,R,G).call(this),u(this,P).open(),document.body.classList.add("pc-overflow"))},L=document.getElementById("pc-select_btn_upload"),b=document.getElementById("pc-select_btn_design");L&&(L==null||L.addEventListener("click",v)),b&&(b==null||b.addEventListener("click",p))},pe=new WeakSet,dt=function(){const c=document.getElementById("pc-select_wrap");c&&(c.style.display="flex",document.body.classList.add("pc-overflow"));const o=c==null?void 0:c.querySelector("#pc-select_close-btn");o&&o instanceof HTMLButtonElement&&o.focus()},R=new WeakSet,G=function(){const c=document.getElementById("pc-select_wrap");c&&(c.style.display="none"),document.body.classList.remove("pc-overflow")},ue=new WeakSet,pt=function(){const c=document.getElementById("pc-select_close-btn"),o=document.getElementById("pc-content-overlay"),a=d=>{d.key==="Escape"&&y(this,R,G).call(this)};window.addEventListener("keydown",a),c==null||c.addEventListener("click",()=>y(this,R,G).call(this)),o==null||o.addEventListener("click",()=>{const d=document.getElementById("pc-designer-iframe-wrapper");(d==null?void 0:d.style.visibility)!=="visible"&&y(this,R,G).call(this)})},he=new WeakSet,ut=function(){const c=document.getElementById("pc-select_wrap"),o=c==null?void 0:c.querySelectorAll("button"),a=o&&o[0],d=o&&o[o.length-1],p=v=>{v.key==="Tab"&&(v.shiftKey?d&&document.activeElement===a&&(d.focus(),v.preventDefault()):a&&document.activeElement===d&&(a.focus(),v.preventDefault()))};window.addEventListener("keydown",p)},fe=new WeakSet,ht=function(c){var L,b;const o=c.map(k=>k.data.id);let a=document.querySelector('input[name="properties[_pcDesignIds]"]');a?a.value+=`,${o.join()}`:(a=document.createElement("input"),a.type="hidden",a.name="properties[_pcDesignIds]",a.className="pc-designer_input",a.value=o.join(),(L=u(this,j))==null||L.appendChild(a));const d=document.querySelector(".pc-preview-wrap")||document.createElement("div");d.className="pc-preview-wrap",localStorage.getItem("pc-design-ids")&&localStorage.removeItem("pc-design-ids"),localStorage.setItem("pc-design-ids",JSON.stringify(o)),c.forEach(k=>{var W;if(!k.data.design_image.url)return;const h=document.createElement("div");h.className="pc-preview",h.setAttribute("data-pc-design-id",k.data.id);const x=document.createElement("button");x.className="pc-btn pc-danger-btn",x.innerHTML=(W=this.options)!=null&&W.removeUploaderBtnText?this.options.removeUploaderBtnText:"Remove",x.onclick=()=>{const O=a.value.split(",").filter(A=>A!==k.data.id);a.value=O.join(),h.remove()};const S=document.createElement("img");S.src=k.data.design_image.url,S.className="pc-uploader-image";const M=document.createElement("div");M.className="pc-preview-overlay",M.appendChild(x),h.appendChild(M),h.appendChild(S),d.appendChild(h)});const p=document.querySelector("div#pc-designer_wrap");if(!document.querySelector(".princart-preview-heading")){const k=document.createElement("h5");k.className="princart-preview-heading",k.innerHTML="Your artworks",p==null||p.appendChild(k)}p==null||p.appendChild(d);const v=(b=this.options)==null?void 0:b.onUploadSuccess;v&&v(c,u(this,P))},me=new WeakSet,ft=function(c){var b,k;const o=this,a=c.map(h=>h.id);let d=document.querySelector('input[name="properties[_pcDesignIds]"]');d?d.value+=`,${a.join()}`:(d=document.createElement("input"),d.type="hidden",d.name="properties[_pcDesignIds]",d.className="pc-designer_input",d.value=a.join(),(b=u(this,j))==null||b.appendChild(d));const p=document.querySelector(".pc-preview-wrap")||document.createElement("div");p.className="pc-preview-wrap",localStorage.getItem("pc-design-ids")&&localStorage.removeItem("pc-design-ids"),localStorage.setItem("pc-design-ids",JSON.stringify(a)),c.forEach(h=>{var A;if(!h.design_image.url)return;const x=document.createElement("div");x.className="pc-preview",x.setAttribute("data-pc-design-id",h.id);const S=document.createElement("button");S.className="pc-btn pc-primary-btn",S.style.borderRadius="5px",S.innerHTML="Edit",S.onclick=()=>{u(o,C).editDesign(h.id)};const M=document.createElement("button");M.className="pc-btn pc-danger-btn",M.style.borderRadius="5px",M.innerHTML="Remove",M.onclick=()=>{const z=d.value.split(",").filter(ne=>ne!==h.id);d.value=z.join(),x.remove()};const W=document.createElement("img");W.src=((A=h.preview_image)==null?void 0:A.url)||h.design_image.url,W.className="pc-uploader-image";const O=document.createElement("div");O.className="pc-preview-overlay",O.appendChild(S),O.appendChild(M),x.appendChild(O),x.appendChild(W),p.appendChild(x)});const v=document.querySelector("div#pc-designer_wrap");v==null||v.appendChild(p);const L=(k=this.options)==null?void 0:k.onDesignCreateSuccess;L&&L(c,u(this,C))},ve=new WeakSet,mt=function(){u(this,P)&&(u(this,P).on("upload-success",c=>{y(this,fe,ht).call(this,c),u(this,P).close()}),u(this,P).on("close",()=>{document.body.classList.remove("pc-overflow")}))},ge=new WeakSet,vt=function(){u(this,C)&&(u(this,C).on("upload-success",c=>{y(this,me,ft).call(this,c),u(this,C).close()}),u(this,C).on("closed",()=>{document.body.classList.remove("pc-overflow")}),u(this,C).on("edit-success",c=>{var d;if(!c.design_image.url)return;const o=document.querySelector(`[data-pc-design-id="${c.id}"] img`);if(!o||!(o instanceof HTMLImageElement))throw new Error("Can't find image element");o.src=c.design_image.url;const a=(d=this.options)==null?void 0:d.onDesignEditSuccess;u(this,C).close(),a&&a(c,u(this,C))}))},ye=new WeakSet,gt=function(){const c=y(this,we,yt).call(this),o=new URL(c);return new URLSearchParams(o.search).get("shopT")},we=new WeakSet,yt=function(){return document.querySelector("[id='pc-wix-integration-sdk']").src},be=new WeakSet,wt=function(){const c="https://unpkg.com/@printcart/wix-integration/dist",o=document.createElement("link");o.rel="stylesheet",o.href=`${c}/style.css`,document.head.appendChild(o)},_e=new WeakSet,bt=async function(c){try{const o=`${u(this,$)}/integration/wix/products/${c}`,a=this.token;if(!a)throw new Error("Missing Printcart Unauth Token");return await(await fetch(o,{headers:{"X-PrintCart-Unauth-Token":a}})).json()}catch(o){console.error("There has been a problem with your fetch operation:",o);return}},Ee=new WeakSet,_t=function(){var d,p,v;const c=u(this,j);if(!(c!=null&&c.parentNode)){console.log("Can not find cart form");return}if(document.getElementById("pc-designer_wrap")!==null)return;const o=document.createElement("div");o.id="pc-designer_wrap";const a=document.createElement("button");a.id="pc-btn",a.className=(d=this.options)!=null&&d.designClassName?(p=this.options)==null?void 0:p.designClassName:"",a.innerHTML=(v=this.options)!=null&&v.designBtnText?this.options.designBtnText:"Start Design",a.disabled=!0,o.appendChild(a),c.appendChild(o)},Le=new WeakSet,Et=async function(c,o,a){try{const d=`${u(this,$)}/projects`,p=this.token;if(!p)throw new Error("Missing Printcart Unauth Token");const v={name:`${c}`,status:"processing",design_ids:a,order_detail:{id:o}};await fetch(d,{method:"POST",headers:{"Content-Type":"application/json","X-PrintCart-Unauth-Token":p},body:JSON.stringify(v)})}catch(d){console.error("There has been a problem with your fetch operation:",d);return}},new le().init()}); |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "1.1.11", | ||
"version": "1.1.12", | ||
"scripts": { | ||
@@ -10,0 +10,0 @@ "dev": "vite --port 3102", |
97763
6
1506