@printcart/wix-integration
Version:
Printcart Designer SDK for Wix.
2 lines (1 loc) • 34 kB
JavaScript
var $t=Object.defineProperty;var Ft=(b,E,k)=>E in b?$t(b,E,{enumerable:!0,configurable:!0,writable:!0,value:k}):b[E]=k;var R=(b,E,k)=>(Ft(b,typeof E!="symbol"?E+"":E,k),k),Be=(b,E,k)=>{if(!E.has(b))throw TypeError("Cannot "+k)};var h=(b,E,k)=>(Be(b,E,"read from private field"),k?k.call(b):E.get(b)),w=(b,E,k)=>{if(E.has(b))throw TypeError("Cannot add the same private member more than once");E instanceof WeakSet?E.add(b):E.set(b,k)},q=(b,E,k,le)=>(Be(b,E,"write to private field"),le?le.call(b,k):E.set(b,k),k);var y=(b,E,k)=>(Be(b,E,"access private method"),k);(function(){var H,Q,x,P,D,de,dt,ee,Re,te,Ae,ue,ut,pe,pt,A,G,he,ht,fe,ft,me,mt,ve,vt,ge,gt,ye,yt,_e,_t,we,wt,be,bt,Ee,Et,Le,Lt,Ce,Ct;"use strict";const b=function(){var He=Object.defineProperty,c=(e,t,n)=>t in e?He(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),l=Object.defineProperty,d=(e,t,n)=>t in e?l(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),m=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},L=(e,t,n)=>(m(e,t,"read from private field"),n?n.call(e):t.get(e)),f=(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)},_=(e,t,n,i)=>(m(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),a=(e,t,n)=>(m(e,t,"access private method"),n),I,S,M,W,U,$,j,ne,O,N,Me={exports:{}},K=typeof Reflect=="object"?Reflect:null,$e=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 It(e){console&&console.warn&&console.warn(e)}var Fe=Number.isNaN||function(e){return e!==e};function v(){v.init.call(this)}Me.exports=v,Me.exports.once=St,v.EventEmitter=v,v.prototype._events=void 0,v.prototype._eventsCount=0,v.prototype._maxListeners=void 0;var ze=10;function ke(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(v,"defaultMaxListeners",{enumerable:!0,get:function(){return ze},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+".");ze=e}}),v.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},v.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 qe(e){return e._maxListeners===void 0?v.defaultMaxListeners:e._maxListeners}v.prototype.getMaxListeners=function(){return qe(this)},v.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 u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var C=r[e];if(C===void 0)return!1;if(typeof C=="function")$e(C,this,t);else for(var ce=C.length,Ne=Ze(C,ce),n=0;n<ce;++n)$e(Ne[n],this,t);return!0};function Ke(e,t,n,i){var r,s,u;if(ke(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),u=s[t]),u===void 0)u=s[t]=n,++e._eventsCount;else if(typeof u=="function"?u=s[t]=i?[n,u]:[u,n]:i?u.unshift(n):u.push(n),r=qe(e),r>0&&u.length>r&&!u.warned){u.warned=!0;var C=new Error("Possible EventEmitter memory leak detected. "+u.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");C.name="MaxListenersExceededWarning",C.emitter=e,C.type=t,C.count=u.length,It(C)}return e}v.prototype.addListener=function(e,t){return Ke(this,e,t,!1)},v.prototype.on=v.prototype.addListener,v.prototype.prependListener=function(e,t){return Ke(this,e,t,!0)};function kt(){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 Xe(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=kt.bind(i);return r.listener=n,i.wrapFn=r,r}v.prototype.once=function(e,t){return ke(t),this.on(e,Xe(this,e,t)),this},v.prototype.prependOnceListener=function(e,t){return ke(t),this.prependListener(e,Xe(this,e,t)),this},v.prototype.removeListener=function(e,t){var n,i,r,s,u;if(ke(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){u=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():xt(n,r),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,u||t)}return this},v.prototype.off=v.prototype.removeListener,v.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 Je(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?Pt(r):Ze(r,r.length)}v.prototype.listeners=function(e){return Je(this,e,!0)},v.prototype.rawListeners=function(e){return Je(this,e,!1)},v.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Ve.call(e,t)},v.prototype.listenerCount=Ve;function Ve(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}v.prototype.eventNames=function(){return this._eventsCount>0?Ie(this._events):[]};function Ze(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function xt(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Pt(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function St(e,t){return new Promise(function(n,i){function r(u){e.removeListener(t,s),i(u)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",r),n([].slice.call(arguments))}Ye(e,t,s,{once:!0}),t!=="error"&&Tt(e,r,{once:!0})})}function Tt(e,t,n){typeof e.on=="function"&&Ye(e,"error",t,n)}function Ye(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 Mt=Me.exports;const ie="pc-designer-iframe-wrapper",xe="pc-designer-iframe";class Ot{constructor(t){f(this,M),f(this,U),f(this,j),f(this,O),p(this,"token"),p(this,"productId"),p(this,"options"),f(this,I,void 0),f(this,S,void 0);var n;if(this.token=t.token,this.productId=t.productId,this.options=t.options,_(this,I,(n=this.options)!=null&&n.designerUrl?this.options.designerUrl:{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),_(this,S,new Mt),!this.token||!this.productId){console.error("Missing Config Params");return}a(this,M,W).call(this),a(this,U,$).call(this)}render(){const t=document.getElementById(ie),n=document.getElementById(xe);if(!n||!(n instanceof HTMLIFrameElement)||!t){console.error("Can not find iframe element");return}const i=a(this,j,ne).call(this);n.src=i.href,t.style.opacity="1",t.style.visibility="visible",a(this,O,N).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",a(this,O,N).call(this,"closed")}editDesign(t){const n=a(this,j,ne).call(this);n.searchParams.set("design_id",t),n.searchParams.set("task","edit");const i=document.getElementById(ie),r=document.getElementById(xe);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",a(this,O,N).call(this,"edit")}on(t,n){return L(this,S).on(t,n),this}}I=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=xe,t.width="100%",t.height="100%",e.appendChild(t),document.body.appendChild(e)},U=new WeakSet,$=function(){window.addEventListener("message",e=>{if(e.origin===L(this,I)&&e.data.message==="closeDesignTool"){const t=document.getElementById(ie);if(!t)return;t.style.opacity="0",t.style.visibility="hidden",a(this,O,N).call(this,"closed")}if(e.data.message==="finishLoad"){const t=document.getElementById(xe);a(this,O,N).call(this,"render-finish"),t&&t instanceof HTMLIFrameElement&&t.contentWindow&&t.contentWindow.postMessage({message:"customSettings",settings:this.options},L(this,I))}e.data.message==="finishProcess"&&a(this,O,N).call(this,"upload-success",e.data.data.data),e.data.message==="finishUpdate"&&a(this,O,N).call(this,"edit-success",e.data.data.data),e.data.message==="uploadError"&&a(this,O,N).call(this,"upload-error",e.data)},!1)},j=new WeakSet,ne=function(){const e=new URL(L(this,I));return e.searchParams.set("api_key",this.token),e.searchParams.set("product_id",this.productId),e.searchParams.set("parentUrl",window.location.href),e},O=new WeakSet,N=function(e,...t){L(this,S).emit(e,...t)};var Oe=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},T=(e,t,n)=>(Oe(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)},X=(e,t,n,i)=>(Oe(e,t,"write to private field"),i?i.call(e,n):t.set(e,n),n),F=(e,t,n)=>(Oe(e,t,"access private method"),n),re,J,V,se,oe,ae,z,Z,Ue,Ge,je,Qe,De={exports:{}},Y=typeof Reflect=="object"?Reflect:null,et=Y&&typeof Y.apply=="function"?Y.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},Pe;Y&&typeof Y.ownKeys=="function"?Pe=Y.ownKeys:Object.getOwnPropertySymbols?Pe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Pe=function(e){return Object.getOwnPropertyNames(e)};function Ut(e){console&&console.warn&&console.warn(e)}var tt=Number.isNaN||function(e){return e!==e};function g(){g.init.call(this)}De.exports=g,De.exports.once=Nt,g.EventEmitter=g,g.prototype._events=void 0,g.prototype._eventsCount=0,g.prototype._maxListeners=void 0;var nt=10;function Se(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return nt},set:function(e){if(typeof e!="number"||e<0||tt(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");nt=e}}),g.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},g.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||tt(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 it(e){return e._maxListeners===void 0?g.defaultMaxListeners:e._maxListeners}g.prototype.getMaxListeners=function(){return it(this)},g.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 u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var C=r[e];if(C===void 0)return!1;if(typeof C=="function")et(C,this,t);else for(var ce=C.length,Ne=ct(C,ce),n=0;n<ce;++n)et(Ne[n],this,t);return!0};function rt(e,t,n,i){var r,s,u;if(Se(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),u=s[t]),u===void 0)u=s[t]=n,++e._eventsCount;else if(typeof u=="function"?u=s[t]=i?[n,u]:[u,n]:i?u.unshift(n):u.push(n),r=it(e),r>0&&u.length>r&&!u.warned){u.warned=!0;var C=new Error("Possible EventEmitter memory leak detected. "+u.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");C.name="MaxListenersExceededWarning",C.emitter=e,C.type=t,C.count=u.length,Ut(C)}return e}g.prototype.addListener=function(e,t){return rt(this,e,t,!1)},g.prototype.on=g.prototype.addListener,g.prototype.prependListener=function(e,t){return rt(this,e,t,!0)};function jt(){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 st(e,t,n){var i={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=jt.bind(i);return r.listener=n,i.wrapFn=r,r}g.prototype.once=function(e,t){return Se(t),this.on(e,st(this,e,t)),this},g.prototype.prependOnceListener=function(e,t){return Se(t),this.prependListener(e,st(this,e,t)),this},g.prototype.removeListener=function(e,t){var n,i,r,s,u;if(Se(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){u=n[s].listener,r=s;break}if(r<0)return this;r===0?n.shift():Dt(n,r),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,u||t)}return this},g.prototype.off=g.prototype.removeListener,g.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 ot(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?Wt(r):ct(r,r.length)}g.prototype.listeners=function(e){return ot(this,e,!0)},g.prototype.rawListeners=function(e){return ot(this,e,!1)},g.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):at.call(e,t)},g.prototype.listenerCount=at;function at(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}g.prototype.eventNames=function(){return this._eventsCount>0?Pe(this._events):[]};function ct(e,t){for(var n=new Array(t),i=0;i<t;++i)n[i]=e[i];return n}function Dt(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function Wt(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function Nt(e,t){return new Promise(function(n,i){function r(u){e.removeListener(t,s),i(u)}function s(){typeof e.removeListener=="function"&&e.removeListener("error",r),n([].slice.call(arguments))}lt(e,t,s,{once:!0}),t!=="error"&&Bt(e,r,{once:!0})})}function Bt(e,t,n){typeof e.on=="function"&<(e,"error",t,n)}function lt(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 Rt=De.exports;const Te="pc-uploader-iframe-wrapper",We="pc-uploader-iframe";class At{constructor(t){if(B(this,z),B(this,Ue),B(this,je),B(this,re,void 0),B(this,J,void 0),B(this,V,void 0),B(this,se,void 0),B(this,oe,void 0),B(this,ae,void 0),X(this,re,t.token),X(this,J,t.sideId||t.productId),X(this,ae,t.productId?"product":"side"),X(this,V,t.uploaderUrl?t.uploaderUrl:"https://upload-tool.pages.dev"),X(this,se,new Rt),X(this,oe,t.locale),!T(this,re)||!T(this,J)){console.warn("Missing Config Params.");return}F(this,Ue,Ge).call(this),F(this,je,Qe).call(this)}get locale(){return T(this,oe)}open(){let t=document.getElementById(Te),n=document.getElementById(We);const i=new URL(T(this,V));if(i.searchParams.set("token",T(this,re)),T(this,ae)==="side"?i.searchParams.set("sideId",T(this,J)):T(this,ae)==="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",F(this,z,Z).call(this,"open")}close(){let t=document.getElementById(Te);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,ae=new WeakMap,z=new WeakSet,Z=function(e,...t){T(this,se).emit(e,...t)},Ue=new WeakSet,Ge=function(){let e=document.createElement("div");e.id=Te,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)},je=new WeakSet,Qe=function(){let e=document.getElementById(Te);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",F(this,z,Z).call(this,"close")),t.data.uploaderEvent==="upload-success"&&F(this,z,Z).call(this,"upload-success",t.data.data),t.data.uploaderEvent==="upload-error"&&F(this,z,Z).call(this,"upload-error",t.data.error);const s=T(this,oe),u=document.getElementById(We);u&&u instanceof HTMLIFrameElement&&(F(this,z,Z).call(this,"onload"),s&&t.data.uploaderEvent==="loaded"&&t.data.finished&&(console.log("test"),u.focus(),(n=u.contentWindow)==null||n.postMessage({locale:s},T(this,V))))}},!1)};class Ht{constructor(){o(this,"initDesignTool",t=>new Ot(t)),o(this,"initUploader",t=>new At(t))}}return Ht}();var E="";const k=new b;class le{constructor(){w(this,de);w(this,ee);w(this,te);w(this,ue);w(this,pe);w(this,A);w(this,he);w(this,fe);w(this,me);w(this,ve);w(this,ge);w(this,ye);w(this,_e);w(this,we);w(this,be);w(this,Ee);w(this,Le);w(this,Ce);w(this,H,void 0);R(this,"token");R(this,"appID");R(this,"productIdPC");R(this,"orderIdWix");R(this,"orderNumberWix");R(this,"options");w(this,Q,void 0);w(this,x,void 0);w(this,P,void 0);w(this,D,void 0);R(this,"registerListener");R(this,"textReplace");this.token=y(this,_e,_t).call(this),this.productIdPC=null,this.appID="325c68a5-64c2-440d-b093-8cea369df06b",this.orderIdWix=null,this.orderNumberWix=null,q(this,D,null),this.textReplace={start_design:"Start Design",pc_select_header:"Choose a way to design this product",upload_a_full_design:"Upload a full design",upload_design_file:"Upload Design file",have_a_complete_design:"Have a complete design",have_your_own_design:"Have your own designer",design_here_online:"Design here online",already_have_a_design:"Already have your concept",customize_every_details:"Customize every details"},this.options=window.PrintcartDesignerShopifyOptions,q(this,H,"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 l;y(l=o,ee,Re).call(l,"second")})}}H=new WeakMap,Q=new WeakMap,x=new WeakMap,P=new WeakMap,D=new WeakMap,de=new WeakSet,dt=async function(){var c,o,l,d;try{const p=`${h(this,H)}/stores/store-details`,m=this.token;if(!m)throw new Error("Missing Printcart Unauth Token");const f=await(await fetch(p,{headers:{"X-PrintCart-Unauth-Token":m}})).json(),_=(o=(c=f==null?void 0:f.data)==null?void 0:c.setting_defaults)==null?void 0:o.customCss.value,a=(d=(l=f==null?void 0:f.data)==null?void 0:l.setting_defaults)==null?void 0:d.textReplace;if(this.textReplace={start_design:a!=null&&a.start_design?a.start_design:"Start Design",pc_select_header:a!=null&&a.pc_select_header?a.pc_select_header:"Choose a way to design this product",upload_a_full_design:a!=null&&a.upload_a_full_design?a.upload_a_full_design:"Upload a full design",upload_design_file:a!=null&&a.upload_design_file?a.upload_design_file:"Upload Design file",have_a_complete_design:a!=null&&a.have_a_complete_design?a.have_a_complete_design:"Have a complete design",have_your_own_design:a!=null&&a.have_your_own_design?a.have_your_own_design:"Have your own designer",design_here_online:a!=null&&a.design_here_online?a.design_here_online:"Design here online",already_have_a_design:a!=null&&a.already_have_a_design?a.already_have_a_design:"Already have your concept",customize_every_details:a!=null&&a.customize_every_details?a.customize_every_details:"Customize every details"},_){const I=document.createElement("style");I.textContent=_,I.type="text/css",document.head.appendChild(I)}return f}catch(p){console.error("There has been a problem with your fetch operation:",p)}},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 m,L,f;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(m=o,te,Ae).call(m,p==null?void 0:p.productId);break;case"CustomizeProduct":if(p.variants&&p.variants.length<1)return;y(L=o,te,Ae).call(L,p==null?void 0:p.variantId);break;case"Purchase":if(!localStorage.getItem("pc-design-ids"))return;const _=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(!_)throw new Error("Can not find design Ids");y(f=o,Ce,Ct).call(f,o.orderNumberWix,o.orderIdWix,JSON.parse(_));break}})},te=new WeakSet,Ae=function(c){if(q(this,D,document.querySelector("[data-hook='product-options']")),y(this,de,dt).call(this),!h(this,D))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,Ee,Et).call(this,c).then(o=>{var L,f;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,bt).call(this),y(this,Le,Lt).call(this),y(this,ue,ut).call(this),y(this,he,ht).call(this),y(this,fe,ft).call(this);const l=document.querySelector("button#pc-btn"),d=o.data.enable_design,p=o.data.enable_upload;d&&(q(this,x,k.initDesignTool({token:this.token,productId:this.productIdPC,options:{...(f=this.options)==null?void 0:f.designerOptions,designerUrl:h(this,Q)}})),y(this,ye,yt).call(this),l&&l instanceof HTMLButtonElement&&(l.disabled=!1)),p&&(q(this,P,k.initUploader({token:this.token,productId:this.productIdPC})),y(this,ge,gt).call(this),l&&l instanceof HTMLButtonElement&&(l.disabled=!1));const m=_=>{_.preventDefault(),h(this,x)&&!h(this,P)&&h(this,x).render(),!h(this,x)&&h(this,P)&&h(this,P).open(),h(this,x)&&h(this,P)&&y(this,pe,pt).call(this)};l&&l instanceof HTMLButtonElement&&(l.onclick=m)})},ue=new WeakSet,ut=function(){const c="https://files.printcart.com/common/upload.svg",o="https://files.printcart.com/common/design.svg",l=`<button aria-label="Close" id="pc-select_close-btn"><span data-modal-x></span></button><div class="pc-select-wrap" id="pc-content-overlay"><div class="pc-select-inner"><div id="pc-select_header">${this.textReplace.pc_select_header}</div><div id="pc-select_container"><button class="pc-select_btn" id="pc-select_btn_upload"><div aria-hidden="true" class="pc-select_btn_wrap"><div class="pc-select_btn_img"><div class="pc-select_btn_img_inner"><img src="${c}" alt="Printcart Uploader"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">${this.textReplace.upload_a_full_design}</h2><ul><li>${this.textReplace.have_a_complete_design}</li><li>${this.textReplace.have_your_own_design}</li></ul></div></div></div><div class="visually-hidden">${this.textReplace.upload_design_file}</div></button><button class="pc-select_btn" id="pc-select_btn_design"><div aria-hidden="true" class="pc-select_btn_wrap"><div class="pc-select_btn_img"><div class="pc-select_btn_img_inner"><img src="${o}" alt="Printcart Designer"></div></div><div class="pc-select_btn_content"><div class="pc-select_btn_content_inner"><h2 class="pc-title">${this.textReplace.design_here_online}</h2><ul><li>${this.textReplace.already_have_a_design}</li><li>${this.textReplace.customize_every_details}</li></ul></div></div></div><div class="visually-hidden">${this.textReplace.upload_design_file}</div></button></div></div></div>`,d=document.createElement("div");d.id="pc-select_wrap",d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("tabIndex","-1"),d.innerHTML=l,document.body.appendChild(d);const p=()=>{h(this,x)&&(y(this,A,G).call(this),h(this,x).render(),document.body.classList.add("pc-overflow"))},m=()=>{h(this,P)&&(y(this,A,G).call(this),h(this,P).open(),document.body.classList.add("pc-overflow"))},L=document.getElementById("pc-select_btn_upload"),f=document.getElementById("pc-select_btn_design");L&&(L==null||L.addEventListener("click",m)),f&&(f==null||f.addEventListener("click",p))},pe=new WeakSet,pt=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()},A=new WeakSet,G=function(){const c=document.getElementById("pc-select_wrap");c&&(c.style.display="none"),document.body.classList.remove("pc-overflow")},he=new WeakSet,ht=function(){const c=document.getElementById("pc-select_close-btn"),o=document.getElementById("pc-content-overlay"),l=d=>{d.key==="Escape"&&y(this,A,G).call(this)};window.addEventListener("keydown",l),c==null||c.addEventListener("click",()=>y(this,A,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,A,G).call(this)})},fe=new WeakSet,ft=function(){const c=document.getElementById("pc-select_wrap"),o=c==null?void 0:c.querySelectorAll("button"),l=o&&o[0],d=o&&o[o.length-1],p=m=>{m.key==="Tab"&&(m.shiftKey?d&&document.activeElement===l&&(d.focus(),m.preventDefault()):l&&document.activeElement===d&&(l.focus(),m.preventDefault()))};window.addEventListener("keydown",p)},me=new WeakSet,mt=function(c){var L,f;const o=c.map(_=>_.data.id);let l=document.querySelector('input[name="properties[_pcDesignIds]"]');l?l.value+=`,${o.join()}`:(l=document.createElement("input"),l.type="hidden",l.name="properties[_pcDesignIds]",l.className="pc-designer_input",l.value=o.join(),(L=h(this,D))==null||L.appendChild(l));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(_=>{var W;if(!_.data.design_image.url)return;const a=document.createElement("div");a.className="pc-preview",a.setAttribute("data-pc-design-id",_.data.id);const I=document.createElement("button");I.className="pc-btn pc-danger-btn",I.innerHTML=(W=this.options)!=null&&W.removeUploaderBtnText?this.options.removeUploaderBtnText:"Remove",I.onclick=U=>{U.preventDefault();const $=l.value.split(",").filter(j=>j!==_.data.id);l.value=$.join(),a.remove()};const S=document.createElement("img");S.src=_.data.design_image.url,S.className="pc-uploader-image";const M=document.createElement("div");M.className="pc-preview-overlay",M.appendChild(I),a.appendChild(M),a.appendChild(S),d.appendChild(a)});const p=document.querySelector("div#pc-designer_wrap");if(!document.querySelector(".princart-preview-heading")){const _=document.createElement("h5");_.className="princart-preview-heading",_.innerHTML="Your artworks",p==null||p.appendChild(_)}p==null||p.appendChild(d);const m=(f=this.options)==null?void 0:f.onUploadSuccess;m&&m(c,h(this,P))},ve=new WeakSet,vt=function(c){var f,_;const o=this,l=c.map(a=>a.id);let d=document.querySelector('input[name="properties[_pcDesignIds]"]');d?d.value+=`,${l.join()}`:(d=document.createElement("input"),d.type="hidden",d.name="properties[_pcDesignIds]",d.className="pc-designer_input",d.value=l.join(),(f=h(this,D))==null||f.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(l)),c.forEach(a=>{var $;if(!a.design_image.url)return;const I=document.createElement("div");I.className="pc-preview",I.setAttribute("data-pc-design-id",a.id);const S=document.createElement("button");S.className="pc-btn pc-primary-btn",S.style.borderRadius="5px",S.innerHTML="Edit",S.onclick=j=>{j.preventDefault(),h(o,x).editDesign(a.id)};const M=document.createElement("button");M.className="pc-btn pc-danger-btn",M.style.borderRadius="5px",M.innerHTML="Remove",M.onclick=j=>{j.preventDefault();const ne=d.value.split(",").filter(O=>O!==a.id);d.value=ne.join(),I.remove()};const W=document.createElement("img");W.src=(($=a.preview_image)==null?void 0:$.url)||a.design_image.url,W.className="pc-uploader-image";const U=document.createElement("div");U.className="pc-preview-overlay",U.appendChild(S),U.appendChild(M),I.appendChild(U),I.appendChild(W),p.appendChild(I)});const m=document.querySelector("div#pc-designer_wrap");m==null||m.appendChild(p);const L=(_=this.options)==null?void 0:_.onDesignCreateSuccess;L&&L(c,h(this,x))},ge=new WeakSet,gt=function(){h(this,P)&&(h(this,P).on("upload-success",c=>{y(this,me,mt).call(this,c),h(this,P).close()}),h(this,P).on("close",()=>{document.body.classList.remove("pc-overflow")}))},ye=new WeakSet,yt=function(){h(this,x)&&(h(this,x).on("upload-success",c=>{y(this,ve,vt).call(this,c),h(this,x).close()}),h(this,x).on("closed",()=>{document.body.classList.remove("pc-overflow")}),h(this,x).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 l=(d=this.options)==null?void 0:d.onDesignEditSuccess;h(this,x).close(),l&&l(c,h(this,x))}))},_e=new WeakSet,_t=function(){const c=y(this,we,wt).call(this),o=new URL(c);return new URLSearchParams(o.search).get("shopT")},we=new WeakSet,wt=function(){return document.querySelector("[id='pc-wix-integration-sdk']").src},be=new WeakSet,bt=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)},Ee=new WeakSet,Et=async function(c){try{const o=`${h(this,H)}/integration/wix/products/${c}`,l=this.token;if(!l)throw new Error("Missing Printcart Unauth Token");return await(await fetch(o,{headers:{"X-PrintCart-Unauth-Token":l}})).json()}catch(o){console.error("There has been a problem with your fetch operation:",o);return}},Le=new WeakSet,Lt=function(){var d,p,m;const c=h(this,D);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 l=document.createElement("button");l.id="pc-btn",l.className=(d=this.options)!=null&&d.designClassName?(p=this.options)==null?void 0:p.designClassName:"",l.innerHTML=(m=this.options)!=null&&m.designBtnText?this.options.designBtnText:this.textReplace.start_design,l.disabled=!0,o.appendChild(l),c.appendChild(o)},Ce=new WeakSet,Ct=async function(c,o,l){try{const d=`${h(this,H)}/projects`,p=this.token;if(!p)throw new Error("Missing Printcart Unauth Token");const m={name:`${c}`,status:"processing",design_ids:l,order_detail:{id:o}};await fetch(d,{method:"POST",headers:{"Content-Type":"application/json","X-PrintCart-Unauth-Token":p},body:JSON.stringify(m)})}catch(d){console.error("There has been a problem with your fetch operation:",d);return}},new le().init()})();