@printcart/shopify-integration
Version:
Printcart Designer SDK for Shopify.
131 lines (130 loc) • 41.2 kB
JavaScript
var ln=Object.defineProperty;var dn=(_,g,y)=>g in _?ln(_,g,{enumerable:!0,configurable:!0,writable:!0,value:y}):_[g]=y;var ce=(_,g,y)=>(dn(_,typeof g!="symbol"?g+"":g,y),y),Qe=(_,g,y)=>{if(!g.has(_))throw TypeError("Cannot "+y)};var c=(_,g,y)=>(Qe(_,g,"read from private field"),y?y.call(_):g.get(_)),p=(_,g,y)=>{if(g.has(_))throw TypeError("Cannot add the same private member more than once");g instanceof WeakSet?g.add(_):g.set(_,y)},N=(_,g,y,F)=>(Qe(_,g,"write to private field"),F?F.call(_,y):g.set(_,y),y);var f=(_,g,y)=>(Qe(_,g,"access private method"),y);(function(_){typeof define=="function"&&define.amd?define(_):_()})(function(){var B,se,w,I,T,P,O,re,Ze,me,bt,$,X,_e,It,ge,Ct,ye,qt,we,kt,Ee,St,Le,xt,be,Tt,Ie,Rt,Ce,Ut,qe,Mt,ke,Pt,Se,Ot,xe,Nt,Te,$t,oe,Xe,ae,Ye,Re,At,Ue,Dt,Me,Bt,Pe,Ft;"use strict";var _=Object.defineProperty,g=(n,e,t)=>e in n?_(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,y=(n,e,t)=>(g(n,typeof e!="symbol"?e+"":e,t),t),F=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)},Y=(n,e,t)=>(F(n,e,"read from private field"),t?t.call(n):e.get(n)),W=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},Ge=(n,e,t,i)=>(F(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t),k=(n,e,t)=>(F(n,e,"access private method"),t),H,G,$e,Je,Ae,et,le,De,x,U,Be={exports:{}},j=typeof Reflect=="object"?Reflect:null,tt=j&&typeof j.apply=="function"?j.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)},de;j&&typeof j.ownKeys=="function"?de=j.ownKeys:Object.getOwnPropertySymbols?de=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:de=function(e){return Object.getOwnPropertyNames(e)};function Wt(n){console&&console.warn&&console.warn(n)}var nt=Number.isNaN||function(e){return e!==e};function v(){v.init.call(this)}Be.exports=v,Be.exports.once=Vt,v.EventEmitter=v,v.prototype._events=void 0,v.prototype._eventsCount=0,v.prototype._maxListeners=void 0;var it=10;function ue(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(v,"defaultMaxListeners",{enumerable:!0,get:function(){return it},set:function(n){if(typeof n!="number"||n<0||nt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");it=n}}),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||nt(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 st(n){return n._maxListeners===void 0?v.defaultMaxListeners:n._maxListeners}v.prototype.getMaxListeners=function(){return st(this)},v.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var s=e==="error",o=this._events;if(o!==void 0)s=s&&o.error===void 0;else if(!s)return!1;if(s){var r;if(t.length>0&&(r=t[0]),r instanceof Error)throw r;var a=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw a.context=r,a}var u=o[e];if(u===void 0)return!1;if(typeof u=="function")tt(u,this,t);else for(var l=u.length,d=lt(u,l),i=0;i<l;++i)tt(d[i],this,t);return!0};function rt(n,e,t,i){var s,o,r;if(ue(t),o=n._events,o===void 0?(o=n._events=Object.create(null),n._eventsCount=0):(o.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),o=n._events),r=o[e]),r===void 0)r=o[e]=t,++n._eventsCount;else if(typeof r=="function"?r=o[e]=i?[t,r]:[r,t]:i?r.unshift(t):r.push(t),s=st(n),s>0&&r.length>s&&!r.warned){r.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=r.length,Wt(a)}return n}v.prototype.addListener=function(e,t){return rt(this,e,t,!1)},v.prototype.on=v.prototype.addListener,v.prototype.prependListener=function(e,t){return rt(this,e,t,!0)};function Ht(){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 ot(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},s=Ht.bind(i);return s.listener=t,i.wrapFn=s,s}v.prototype.once=function(e,t){return ue(t),this.on(e,ot(this,e,t)),this},v.prototype.prependOnceListener=function(e,t){return ue(t),this.prependListener(e,ot(this,e,t)),this},v.prototype.removeListener=function(e,t){var i,s,o,r,a;if(ue(t),s=this._events,s===void 0)return this;if(i=s[e],i===void 0)return this;if(i===t||i.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,i.listener||t));else if(typeof i!="function"){for(o=-1,r=i.length-1;r>=0;r--)if(i[r]===t||i[r].listener===t){a=i[r].listener,o=r;break}if(o<0)return this;o===0?i.shift():jt(i,o),i.length===1&&(s[e]=i[0]),s.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this},v.prototype.off=v.prototype.removeListener,v.prototype.removeAllListeners=function(e){var t,i,s;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[e]),this;if(arguments.length===0){var o=Object.keys(i),r;for(s=0;s<o.length;++s)r=o[s],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=i[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this};function at(n,e,t){var i=n._events;if(i===void 0)return[];var s=i[e];return s===void 0?[]:typeof s=="function"?t?[s.listener||s]:[s]:t?Kt(s):lt(s,s.length)}v.prototype.listeners=function(e){return at(this,e,!0)},v.prototype.rawListeners=function(e){return at(this,e,!1)},v.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):ct.call(n,e)},v.prototype.listenerCount=ct;function ct(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}v.prototype.eventNames=function(){return this._eventsCount>0?de(this._events):[]};function lt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function jt(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function Kt(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function Vt(n,e){return new Promise(function(t,i){function s(r){n.removeListener(e,o),i(r)}function o(){typeof n.removeListener=="function"&&n.removeListener("error",s),t([].slice.call(arguments))}dt(n,e,o,{once:!0}),e!=="error"&&zt(n,s,{once:!0})})}function zt(n,e,t){typeof n.on=="function"&&dt(n,"error",e,t)}function dt(n,e,t,i){if(typeof n.on=="function")i.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function s(o){i.once&&n.removeEventListener(e,s),t(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}var Qt=Be.exports;const J="pc-designer-iframe-wrapper",pe="pc-designer-iframe";class Zt{constructor(e){W(this,$e),W(this,Ae),W(this,le),W(this,x),y(this,"token"),y(this,"productId"),y(this,"options"),W(this,H,void 0),W(this,G,void 0);var t;if(this.token=e.token,this.productId=e.productId,this.options=e.options,Ge(this,H,(t=this.options)!=null&&t.designerUrl?this.options.designerUrl:{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),Ge(this,G,new Qt),!this.token||!this.productId){console.error("Missing Config Params");return}k(this,$e,Je).call(this),k(this,Ae,et).call(this)}render(){const e=document.getElementById(J),t=document.getElementById(pe);if(!t||!(t instanceof HTMLIFrameElement)||!e){console.error("Can not find iframe element");return}const i=k(this,le,De).call(this);t.src=i.href,e.style.opacity="1",e.style.visibility="visible",k(this,x,U).call(this,"rendered")}close(){const e=document.getElementById(J);if(!e){console.error("Can not find iframe element");return}e.style.opacity="0",e.style.visibility="hidden",k(this,x,U).call(this,"closed")}editDesign(e){const t=k(this,le,De).call(this);t.searchParams.set("design_id",e),t.searchParams.set("task","edit");const i=document.getElementById(J),s=document.getElementById(pe);if(!s||!(s instanceof HTMLIFrameElement)||!i){console.error("Can not find iframe element");return}s.src=t.href,i.style.opacity="1",i.style.visibility="visible",k(this,x,U).call(this,"edit")}on(e,t){return Y(this,G).on(e,t),this}}H=new WeakMap,G=new WeakMap,$e=new WeakSet,Je=function(){const n=document.createElement("div");n.id=J,n.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=pe,e.width="100%",e.height="100%",n.appendChild(e),document.body.appendChild(n)},Ae=new WeakSet,et=function(){window.addEventListener("message",n=>{if(n.origin===Y(this,H)&&n.data.message==="closeDesignTool"){const e=document.getElementById(J);if(!e)return;e.style.opacity="0",e.style.visibility="hidden",k(this,x,U).call(this,"closed")}if(n.data.message==="finishLoad"){const e=document.getElementById(pe);k(this,x,U).call(this,"render-finish"),e&&e instanceof HTMLIFrameElement&&e.contentWindow&&e.contentWindow.postMessage({message:"customSettings",settings:this.options},Y(this,H))}n.data.message==="finishProcess"&&k(this,x,U).call(this,"upload-success",n.data.data.data),n.data.message==="finishUpdate"&&k(this,x,U).call(this,"edit-success",n.data.data.data),n.data.message==="uploadError"&&k(this,x,U).call(this,"upload-error",n.data)},!1)},le=new WeakSet,De=function(){const n=new URL(Y(this,H));return n.searchParams.set("api_key",this.token),n.searchParams.set("product_id",this.productId),n.searchParams.set("parentUrl",window.location.href),n},x=new WeakSet,U=function(n,...e){Y(this,G).emit(n,...e)};var Fe=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)},q=(n,e,t)=>(Fe(n,e,"read from private field"),t?t.call(n):e.get(n)),M=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)},K=(n,e,t,i)=>(Fe(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t),A=(n,e,t)=>(Fe(n,e,"access private method"),t),ee,V,z,te,ne,ie,D,Q,We,ut,He,pt,je={exports:{}},Z=typeof Reflect=="object"?Reflect:null,ft=Z&&typeof Z.apply=="function"?Z.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)},fe;Z&&typeof Z.ownKeys=="function"?fe=Z.ownKeys:Object.getOwnPropertySymbols?fe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:fe=function(e){return Object.getOwnPropertyNames(e)};function Xt(n){console&&console.warn&&console.warn(n)}var ht=Number.isNaN||function(e){return e!==e};function m(){m.init.call(this)}je.exports=m,je.exports.once=en,m.EventEmitter=m,m.prototype._events=void 0,m.prototype._eventsCount=0,m.prototype._maxListeners=void 0;var vt=10;function he(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(m,"defaultMaxListeners",{enumerable:!0,get:function(){return vt},set:function(n){if(typeof n!="number"||n<0||ht(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");vt=n}}),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||ht(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 mt(n){return n._maxListeners===void 0?m.defaultMaxListeners:n._maxListeners}m.prototype.getMaxListeners=function(){return mt(this)},m.prototype.emit=function(e){for(var t=[],i=1;i<arguments.length;i++)t.push(arguments[i]);var s=e==="error",o=this._events;if(o!==void 0)s=s&&o.error===void 0;else if(!s)return!1;if(s){var r;if(t.length>0&&(r=t[0]),r instanceof Error)throw r;var a=new Error("Unhandled error."+(r?" ("+r.message+")":""));throw a.context=r,a}var u=o[e];if(u===void 0)return!1;if(typeof u=="function")ft(u,this,t);else for(var l=u.length,d=Et(u,l),i=0;i<l;++i)ft(d[i],this,t);return!0};function _t(n,e,t,i){var s,o,r;if(he(t),o=n._events,o===void 0?(o=n._events=Object.create(null),n._eventsCount=0):(o.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),o=n._events),r=o[e]),r===void 0)r=o[e]=t,++n._eventsCount;else if(typeof r=="function"?r=o[e]=i?[t,r]:[r,t]:i?r.unshift(t):r.push(t),s=mt(n),s>0&&r.length>s&&!r.warned){r.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+r.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=r.length,Xt(a)}return n}m.prototype.addListener=function(e,t){return _t(this,e,t,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(e,t){return _t(this,e,t,!0)};function Yt(){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 gt(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},s=Yt.bind(i);return s.listener=t,i.wrapFn=s,s}m.prototype.once=function(e,t){return he(t),this.on(e,gt(this,e,t)),this},m.prototype.prependOnceListener=function(e,t){return he(t),this.prependListener(e,gt(this,e,t)),this},m.prototype.removeListener=function(e,t){var i,s,o,r,a;if(he(t),s=this._events,s===void 0)return this;if(i=s[e],i===void 0)return this;if(i===t||i.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete s[e],s.removeListener&&this.emit("removeListener",e,i.listener||t));else if(typeof i!="function"){for(o=-1,r=i.length-1;r>=0;r--)if(i[r]===t||i[r].listener===t){a=i[r].listener,o=r;break}if(o<0)return this;o===0?i.shift():Gt(i,o),i.length===1&&(s[e]=i[0]),s.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this},m.prototype.off=m.prototype.removeListener,m.prototype.removeAllListeners=function(e){var t,i,s;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[e]),this;if(arguments.length===0){var o=Object.keys(i),r;for(s=0;s<o.length;++s)r=o[s],r!=="removeListener"&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=i[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(s=t.length-1;s>=0;s--)this.removeListener(e,t[s]);return this};function yt(n,e,t){var i=n._events;if(i===void 0)return[];var s=i[e];return s===void 0?[]:typeof s=="function"?t?[s.listener||s]:[s]:t?Jt(s):Et(s,s.length)}m.prototype.listeners=function(e){return yt(this,e,!0)},m.prototype.rawListeners=function(e){return yt(this,e,!1)},m.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):wt.call(n,e)},m.prototype.listenerCount=wt;function wt(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}m.prototype.eventNames=function(){return this._eventsCount>0?fe(this._events):[]};function Et(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function Gt(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function Jt(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function en(n,e){return new Promise(function(t,i){function s(r){n.removeListener(e,o),i(r)}function o(){typeof n.removeListener=="function"&&n.removeListener("error",s),t([].slice.call(arguments))}Lt(n,e,o,{once:!0}),e!=="error"&&tn(n,s,{once:!0})})}function tn(n,e,t){typeof n.on=="function"&&Lt(n,"error",e,t)}function Lt(n,e,t,i){if(typeof n.on=="function")i.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function s(o){i.once&&n.removeEventListener(e,s),t(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}var nn=je.exports;const ve="pc-uploader-iframe-wrapper",Ke="pc-uploader-iframe";class sn{constructor(e){if(M(this,D),M(this,We),M(this,He),M(this,ee,void 0),M(this,V,void 0),M(this,z,void 0),M(this,te,void 0),M(this,ne,void 0),M(this,ie,void 0),K(this,ee,e.token),K(this,V,e.sideId||e.productId),K(this,ie,e.productId?"product":"side"),K(this,z,e.uploaderUrl?e.uploaderUrl:"https://upload-tool.pages.dev"),K(this,te,new nn),K(this,ne,e.locale),!q(this,ee)||!q(this,V)){console.warn("Missing Config Params.");return}A(this,We,ut).call(this),A(this,He,pt).call(this)}get locale(){return q(this,ne)}open(){let e=document.getElementById(ve),t=document.getElementById(Ke);const i=new URL(q(this,z));if(i.searchParams.set("token",q(this,ee)),q(this,ie)==="side"?i.searchParams.set("sideId",q(this,V)):q(this,ie)==="product"&&i.searchParams.set("productId",q(this,V)),i.searchParams.set("parentUrl",window.location.href),!t||!(t instanceof HTMLIFrameElement)||!e){console.warn("Can not find iframe element.");return}t.src=i.href,e.style.opacity="1",e.style.visibility="visible",A(this,D,Q).call(this,"open")}close(){let e=document.getElementById(ve);if(!e){console.error("Can not find iframe element");return}e.style.opacity="0",e.style.visibility="hidden"}on(e,t){return q(this,te).on(e,t),this}}ee=new WeakMap,V=new WeakMap,z=new WeakMap,te=new WeakMap,ne=new WeakMap,ie=new WeakMap,D=new WeakSet,Q=function(n,...e){q(this,te).emit(n,...e)},We=new WeakSet,ut=function(){let n=document.createElement("div");n.id=ve,n.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=Ke,e.width="100%",e.height="100%",e.style.borderWidth="0",n.appendChild(e),document.body.appendChild(n)},He=new WeakSet,pt=function(){let n=document.getElementById(ve);window.addEventListener("message",e=>{var t;const i=new URL(e.origin),s=new URL(q(this,z));if(i.host===s.host){e.data.uploaderEvent==="close"&&n&&(n.style.opacity="0",n.style.visibility="hidden",A(this,D,Q).call(this,"close")),e.data.uploaderEvent==="upload-success"&&A(this,D,Q).call(this,"upload-success",e.data.data),e.data.uploaderEvent==="upload-error"&&A(this,D,Q).call(this,"upload-error",e.data.error);const o=q(this,ne),r=document.getElementById(Ke);r&&r instanceof HTMLIFrameElement&&(A(this,D,Q).call(this,"onload"),o&&e.data.uploaderEvent==="loaded"&&e.data.finished&&(console.log("test"),r.focus(),(t=r.contentWindow)==null||t.postMessage({locale:o},q(this,z))))}},!1)};var un="";class rn{constructor(){p(this,re);p(this,me);p(this,$);p(this,_e);p(this,ge);p(this,ye);p(this,we);p(this,Ee);p(this,Le);p(this,be);p(this,Ie);p(this,Ce);p(this,qe);p(this,ke);p(this,Se);p(this,xe);p(this,Te);p(this,oe);p(this,ae);p(this,Re);p(this,Ue);p(this,Me);p(this,Pe);p(this,B,void 0);ce(this,"token");ce(this,"productId");ce(this,"options");p(this,se,void 0);p(this,w,void 0);p(this,I,void 0);p(this,T,void 0);p(this,P,void 0);p(this,O,void 0);ce(this,"locales");if(this.token=f(this,Ce,Ut).call(this),this.productId=null,N(this,T,!1),this.options=window.PrintcartDesignerShopifyOptions,N(this,B,{}.VITE_API_URL?{}.VITE_API_URL:"https://api.printcart.com/v1/"),N(this,se,{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),N(this,P,document.querySelector('form[action$="/cart/add"]')),N(this,O,document.querySelector('form[action$="/cart/add"][data-type="add-to-cart-form"]')),this.locales={en:{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 design",design_here_online:"Design here online",already_have_a_design:"Already have your concept",customize_every_details:"Customize every details",request_us_to_design:"Request Us to Design",share_your_idea:"Share your ideas in a brief",our_designers_do_st:"Our designers will craft a custom design for you",note_desc:"Brief of what you would like designing",file_desc:"Upload any reference images or design files"},es:{start_design:"Crear Dise\xF1o",pc_select_header:"Elija una forma de dise\xF1ar este producto",upload_a_full_design:"Sube tu dise\xF1o",upload_design_file:"Subir archivo de dise\xF1o",have_a_complete_design:"Tienes el dise\xF1o listo",have_your_own_design:"Tienes tu propio dise\xF1ador",design_here_online:"Dise\xF1a en linea aqu\xED",already_have_a_design:"Ya tienes tu idea lista",customize_every_details:" Personaliza todos los detalles",request_us_to_design:"Request Us to Design",share_your_idea:"Share your ideas in a brief",our_designers_do_st:"Our designers will craft a custom design for you",note_desc:"Brief of what you would like designing",file_desc:"Upload any reference images or design files"}},!c(this,P))throw new Error("This script can only be used inside a Shopify Product Page.");f(this,we,kt).call(this);let e=null,t=c(this,P).querySelector('form[action$="/cart/add"] [name="id"]');t||(t=document.querySelector('form[action$="/cart/add"] [name="id"]')),e=t==null?void 0:t.value,t==null||t.addEventListener("change",()=>{e=t.value,f(this,re,Ze).call(this,e)}),f(this,re,Ze).call(this,e)}}B=new WeakMap,se=new WeakMap,w=new WeakMap,I=new WeakMap,T=new WeakMap,P=new WeakMap,O=new WeakMap,re=new WeakSet,Ze=function(e){var t;if(!e){const i=(t=window==null?void 0:window.ShopifyAnalytics)==null?void 0:t.meta;e=i==null?void 0:i.selectedVariantId}if(!e)throw new Error("Can not find product variant ID");f(this,ke,Pt).call(this,e).then(i=>{var a,u;this.productId=(a=i==null?void 0:i.data)==null?void 0:a.id;const s=i.data.enable_design,o=i.data.enable_upload,r=i.data.enable_request_quote;f(this,Pe,Ft).call(this),s&&(N(this,w,new Zt({token:this.token,productId:this.productId,options:{...(u=this.options)==null?void 0:u.designerOptions,designerUrl:c(this,se)}})),f(this,Ie,Rt).call(this)),o&&(N(this,I,new sn({token:this.token,productId:this.productId})),f(this,be,Tt).call(this)),r&&(N(this,T,!0),f(this,Re,At).call(this,i.data)),(o||s||r)&&f(this,Te,$t).call(this),f(this,ge,Ct).call(this),f(this,_e,It).call(this),f(this,ye,qt).call(this)})},me=new WeakSet,bt=function(){const e=document.getElementById("pc-select_wrap");e&&(e.style.display="flex",document.body.classList.add("pc-overflow"));const t=e==null?void 0:e.querySelector("#pc-select_close-btn");t&&t instanceof HTMLButtonElement&&t.focus()},$=new WeakSet,X=function(){const e=document.getElementById("pc-select_wrap");e&&(e.style.display="none"),document.body.classList.remove("pc-overflow")},_e=new WeakSet,It=function(){const e=document.getElementById("pc-select_close-btn"),t=document.getElementById("pc-content-overlay"),i=s=>{s.key==="Escape"&&f(this,$,X).call(this)};window.addEventListener("keydown",i),e==null||e.addEventListener("click",()=>f(this,$,X).call(this)),t==null||t.addEventListener("click",()=>{const s=document.getElementById("pc-designer-iframe-wrapper");(s==null?void 0:s.style.visibility)!=="visible"&&f(this,$,X).call(this)})},ge=new WeakSet,Ct=function(){const e="https://files.printcart.com/common/upload.svg",t="https://files.printcart.com/common/design.svg",i="https://files.printcart.com/common/quote.svg",s=`<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="${e}" alt="Printcart Uploader" />
</div>
</div>
<div class="pc-select_btn_content">
<div class="pc-select_btn_content_inner">
<h2 class="pc-title" data-i18n="upload_a_full_design"></h2>
<ul>
<li data-i18n="have_a_complete_design"></li>
<li data-i18n="have_your_own_design"></li>
</ul>
</div>
</div>
</div>
<div class="visually-hidden" data-i18n="upload_design_file"></div>
</button>`,o=`<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="${t}" alt="Printcart Designer" />
</div>
</div>
<div class="pc-select_btn_content">
<div class="pc-select_btn_content_inner">
<h2 class="pc-title" data-i18n="design_here_online"></h2>
<ul>
<li data-i18n="already_have_a_design"></li>
<li data-i18n="customize_every_details"></li>
</ul>
</div>
</div>
</div>
<div class="visually-hidden" data-i18n="upload_design_file"></div>
</button>`,r=`<button class="pc-select_btn" id="pc-select_btn_quote_request">
<div aria-hidden="true" class="pc-select_btn_wrap">
<div class="pc-select_btn_img">
<div class="pc-select_btn_img_inner">
<img src="${i}" alt="Printcart Quotation Request" />
</div>
</div>
<div class="pc-select_btn_content">
<div class="pc-select_btn_content_inner">
<h2 class="pc-title" data-i18n="request_us_to_design"></h2>
<ul>
<li data-i18n="share_your_idea"></li>
<li data-i18n="our_designers_do_st"></li>
</ul>
</div>
</div>
</div>
<div class="visually-hidden" data-i18n="upload_design_file"></div>
</button>`,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" data-i18n="pc_select_header"></div>
<div id="pc-select_container">
${c(this,w)?o:""}
${c(this,I)?s:""}
${c(this,T)?r:""}
</div>
</div>
</div>
`,u=document.getElementById("pc-select_wrap");u&&u.remove();const l=document.createElement("div");l.id="pc-select_wrap",l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("tabIndex","-1"),l.innerHTML=a,document.body.appendChild(l);const d=()=>{c(this,w)&&(f(this,$,X).call(this),c(this,w).render(),document.body.classList.add("pc-overflow"))},h=()=>{c(this,I)&&(f(this,$,X).call(this),c(this,I).open(),document.body.classList.add("pc-overflow"))},L=()=>{f(this,Me,Bt).call(this)},E=document.getElementById("pc-select_btn_upload"),C=document.getElementById("pc-select_btn_design"),S=document.getElementById("pc-select_btn_quote_request");E&&(E==null||E.addEventListener("click",h)),C&&(C==null||C.addEventListener("click",d)),S&&(S==null||S.addEventListener("click",L))},ye=new WeakSet,qt=function(){const e=document.getElementById("pc-select_wrap"),t=e==null?void 0:e.querySelectorAll("button"),i=t&&t[0],s=t&&t[t.length-1],o=r=>{r.key==="Tab"&&(r.shiftKey?s&&document.activeElement===i&&(r.preventDefault(),s.focus()):i&&document.activeElement===s&&(r.preventDefault(),i.focus()))};window.addEventListener("keydown",o)},we=new WeakSet,kt=function(){const e={}.VITE_SDK_URL?{}.VITE_SDK_URL:"https://unpkg.com/@printcart/shopify-integration/dist",t=document.createElement("link");t.rel="stylesheet",t.href=`${e}/style.css`,document.head.appendChild(t)},Ee=new WeakSet,St=function(e){var a,u;const t=e.map(l=>l.data.id);let i=document.querySelector('input[name="properties[_pcDesignIds]"]');i?i.value+=`,${t.join()}`:(i=document.createElement("input"),i.type="hidden",i.name="properties[_pcDesignIds]",i.className="pc-designer_input",i.value=t.join(),c(this,O)?c(this,O).appendChild(i):(a=c(this,P))==null||a.appendChild(i));const s=document.querySelector(".pc-preview-wrap")||document.createElement("div");s.className="pc-preview-wrap",e.forEach(l=>{var C;if(!l.data.design_image.url)return;const d=document.createElement("div");d.className="pc-preview",d.setAttribute("data-pc-design-id",l.data.id);const h=document.createElement("button");h.className="pc-btn pc-danger-btn",h.innerHTML=(C=this.options)!=null&&C.removeUploaderBtnText?this.options.removeUploaderBtnText:"Remove",h.onclick=S=>{S.preventDefault();const b=i.value.split(",").filter(R=>R!==l.data.id);i.value=b.join(),d.remove()};const L=document.createElement("img");L.src=l.data.design_image.url,L.className="pc-uploader-image";const E=document.createElement("div");E.className="pc-preview-overlay",E.appendChild(h),d.appendChild(E),d.appendChild(L),s.appendChild(d)});const o=document.querySelector("div#pc-designer_wrap");if(!document.querySelector(".princart-preview-heading")){const l=document.createElement("h5");l.className="princart-preview-heading",l.innerHTML="Your artworks",o==null||o.appendChild(l)}o==null||o.appendChild(s);const r=(u=this.options)==null?void 0:u.onUploadSuccess;r&&r(e,c(this,I))},Le=new WeakSet,xt=function(e){var u,l;const t=this,i=e.map(d=>d.id);let s=document.querySelector('input[name="properties[_pcDesignIds]"]');s?s.value=i.join():(s=document.createElement("input"),s.type="hidden",s.name="properties[_pcDesignIds]",s.className="pc-designer_input",s.value=i.join(),c(this,O)?c(this,O).appendChild(s):(u=c(this,P))==null||u.appendChild(s));const o=document.querySelector(".pc-preview-wrap")||document.createElement("div");o.className="pc-preview-wrap",e.forEach(d=>{var L,E,C,S;if(!d.preview_image.url)return;const h=o.querySelector(".pc-preview[data-pc-design-id='"+d.id+"'] img.pc-uploader-image");if(h){const b=((E=(L=d.preview)==null?void 0:L.design)==null?void 0:E.url)||d.preview_image.url;h.src=b||""}else{const b=document.createElement("div");b.className="pc-preview",b.setAttribute("data-pc-design-id",d.id);const R=document.createElement("button");R.className="pc-btn pc-primary-btn",R.innerHTML="Edit",R.onclick=ze=>{ze.preventDefault(),c(t,w).editDesign(d.id)};const Oe=document.createElement("button");Oe.className="pc-btn pc-danger-btn",Oe.innerHTML="Remove",Oe.onclick=ze=>{ze.preventDefault();const an=s.value.split(",").filter(cn=>cn!==d.id);s.value=an.join(),b.remove()};const Ve=document.createElement("img"),on=((S=(C=d.preview)==null?void 0:C.design)==null?void 0:S.url)||d.preview_image.url;Ve.src=on,Ve.className="pc-uploader-image";const Ne=document.createElement("div");Ne.className="pc-preview-overlay",Ne.appendChild(R),Ne.appendChild(Oe),b.appendChild(Ne),b.appendChild(Ve),o.appendChild(b)}});const r=document.querySelector("div#pc-designer_wrap");r==null||r.appendChild(o);const a=(l=this.options)==null?void 0:l.onDesignCreateSuccess;a&&a(e,c(this,w))},be=new WeakSet,Tt=function(){c(this,I)&&c(this,I).on("upload-success",e=>{f(this,Ee,St).call(this,e),c(this,I).close()})},Ie=new WeakSet,Rt=function(){c(this,w)&&(c(this,w).on("upload-success",e=>{f(this,Le,xt).call(this,e),c(this,w).close()}),c(this,w).on("closed",()=>{document.body.classList.remove("pc-overflow")}),c(this,w).on("edit-success",e=>{var o,r,a;const t=((r=(o=e.preview)==null?void 0:o.design)==null?void 0:r.url)||e.preview_image.url;if(!t)return;const i=document.querySelector(`[data-pc-design-id="${e.id}"] img`);if(!i||!(i instanceof HTMLImageElement))throw new Error("Can't find image element");i.src=t;const s=(a=this.options)==null?void 0:a.onDesignEditSuccess;c(this,w).close(),s&&s(e,c(this,w))}))},Ce=new WeakSet,Ut=function(){const e=f(this,qe,Mt).call(this),t=new URL(e);return new URLSearchParams(t.search).get("shopT")},qe=new WeakSet,Mt=function(){return document.currentScript.src},ke=new WeakSet,Pt=async function(e){try{const t=`${c(this,B)}integration/shopify/products/${e}`,i=this.token;if(!i)throw new Error("Missing Printcart Unauth Token");return await(await fetch(t,{headers:{"X-PrintCart-Unauth-Token":i}})).json()}catch(t){console.error("There has been a problem with your fetch operation:",t)}},Se=new WeakSet,Ot=async function(e){var r,a,u;const t=document.getElementsByClassName("pc-handle-overlay"),i=document.getElementsByClassName("pc-alert-success"),s=document.getElementsByClassName("pc-alert-danger");(r=i[0])!=null&&r.classList&&i[0].classList.remove("active"),(a=s[0])!=null&&a.classList&&s[0].classList.remove("active"),(u=t[0])!=null&&u.classList&&t[0].classList.add("active");const o=(l=!1,d="")=>{var h,L,E;if((h=t[0])!=null&&h.classList&&t[0].classList.remove("active"),l&&((L=i[0])==null?void 0:L.classList)){i[0].classList.add("active");return}(E=s[0])!=null&&E.classList&&(s[0].classList.add("active"),s[0].textContent=d)};try{const l=`${c(this,B)}quotation-requests`;if(!e.name||!e.email){o(!1,"Name and Email are required");return}const d=this.token||"";if(!d){o(!1,"Missing Printcart Unauth Token");return}const h=new FormData;h.append("name",e.name),h.append("product_id",e.product_id),h.append("email",e.email),h.append("phone",e.phone),h.append("whatsapp",e.whatsapp),h.append("note",e.note),e.design_file&&h.append("design_file",e.design_file),fetch(l,{method:"POST",headers:{"X-PrintCart-Unauth-Token":d},body:h}).then(L=>{if(!L.ok){L.json().then(C=>{o(!1,C.message)});return}document.getElementById("quotation-request-form").reset(),o(!0)})}catch{o(!1,"Failed to create quotation request");return}},xe=new WeakSet,Nt=async function(){try{const e=`${c(this,B)}stores/store-details`,t=this.token;if(!t)throw new Error("Missing Printcart Unauth Token");return await(await fetch(e,{headers:{"X-PrintCart-Unauth-Token":t}})).json()}catch(e){console.error("There has been a problem with your fetch operation:",e)}},Te=new WeakSet,$t=function(){var i,s,o,r;const e=(i=c(this,O))!=null?i:c(this,P);if(!(e!=null&&e.parentNode)){console.log("Can not find cart form");return}let t=document.querySelector("div#pc-designer_wrap button#pc-btn");if(t===null){const a=document.createElement("div");a.id="pc-designer_wrap",t=document.createElement("button"),t.id="pc-btn",t.className=(s=this.options)!=null&&s.designClassName?(o=this.options)==null?void 0:o.designClassName:"button";const u=localStorage.getItem("pc_lang")||"en",l=this.locales[u].start_design;t.innerHTML=(r=this.options)!=null&&r.designBtnText?this.options.designBtnText:l,a.appendChild(t);const d=e==null?void 0:e.querySelector('button[type="submit"]');d?d==null||d.insertAdjacentElement("beforebegin",a):e==null||e.insertAdjacentElement("afterend",a)}t&&t instanceof HTMLButtonElement&&(t.onclick=a=>{if(a.preventDefault(),c(this,w)&&!c(this,I)&&!c(this,T)){c(this,w).render();return}if(!c(this,w)&&c(this,I)&&!c(this,T)){c(this,I).open();return}if(!c(this,w)&&!c(this,I)&&c(this,T)){f(this,oe,Xe).call(this);return}(c(this,w)||c(this,I)||c(this,T))&&f(this,me,bt).call(this)})},oe=new WeakSet,Xe=function(){const e=document.getElementById("pc-quotation-request_wrap");e&&(e.style.display="flex",document.body.classList.add("pc-overflow"));const t=e==null?void 0:e.querySelector("#pc-qr_close-btn");t&&t instanceof HTMLButtonElement&&t.focus()},ae=new WeakSet,Ye=function(){const e=document.getElementById("pc-quotation-request_wrap");e&&(e.style.display="none"),document.body.classList.remove("pc-overflow")},Re=new WeakSet,At=function(e){var l,d,h,L,E,C,S;const t=(b,R)=>new Intl.NumberFormat("en-US",{style:"currency",currency:R}).format(b);let i="";if(((l=e==null?void 0:e.request_quote_options)==null?void 0:l.additionalFee)&&((d=e==null?void 0:e.request_quote_options)==null?void 0:d.additionalFee)>0&&((L=(h=e==null?void 0:e.request_quote_options)==null?void 0:h.currency)==null?void 0:L.symbol)){const b=parseFloat((E=e==null?void 0:e.request_quote_options)==null?void 0:E.additionalFee),R=(S=(C=e==null?void 0:e.request_quote_options)==null?void 0:C.currency)==null?void 0:S.code;i=`<span class="pc-currency text-danger">Please note that an additional fee of <b>${t(b,R)}</b> applies to custom design requests. Thank you for your understanding!</span>`}const s=`
<button aria-label="Close" id="pc-qr_close-btn"><span data-modal-x></span></button>
<div id="pc-qr-content-overlay">
<div class="pc-select-inner">
<div id="pc-select_container">
<form id="quotation-request-form">
<div class="pc-card_header">
<h2>Send the request</h2>
${i||""}
<div class="pc-alert pc-alert-success">
<div class="success__title">Your quotation request has been successfully created</div>
</div>
<div class="pc-alert pc-alert-danger">
<div class="success__title">Something went wrong. Please try again later.</div>
</div>
</div>
<div class="pc-card_body">
<div>
<label for="pc-name">Name<span class="pc-field-require">*</span></label>
<input id="pc-name" type="text" name="pc-name" required />
</div>
<div>
<label for="pc-email">Email<span class="pc-field-require">*</span></label>
<input id="pc-email" type="email" name="pc-email" required />
</div>
<div>
<label for="pc-phone">Phone</label>
<input id="pc-phone" type="tel" name="pc-phone" />
</div>
<div>
<label for="pc-whatsapp">WhatsApp</label>
<input id="pc-whatsapp" type="tel" name="pc-whatsapp" />
</div>
<div>
<label for="pc-note">Note</label>
<description data-i18n="note_desc"></description>
<textarea id="pc-note" name="pc-note"></textarea>
</div>
<div>
<label for="pc-file">File</label>
<description data-i18n="file_desc"></description>
<input id="pc-file" type="file" name="pc-file" title="Choose a file from your device"/>
</div>
</div>
<div class="pc-card_footer">
<button id="pc-submit-quota" type="submit">Submit</button>
</div>
<div class="pc-handle-overlay">
<div class="pc-boxes">
<div class="pc-box"><div></div><div></div><div></div><div></div>
</div>
<div class="pc-box"><div></div><div></div><div></div><div></div>
</div>
<div class="pc-box"><div></div><div></div><div></div><div></div>
</div>
<div class="pc-box"><div></div><div></div><div></div><div></div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
`,o=document.createElement("div");o.id="pc-quotation-request_wrap",o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.setAttribute("tabIndex","-1"),o.innerHTML=s,document.body.appendChild(o);const r=document.getElementById("pc-qr_close-btn"),a=document.getElementById("pc-submit-quota"),u=b=>{b.key==="Escape"&&f(this,ae,Ye).call(this)};window.addEventListener("keydown",u),r==null||r.addEventListener("click",()=>f(this,ae,Ye).call(this)),a==null||a.addEventListener("click",b=>f(this,Ue,Dt).call(this,e==null?void 0:e.id,b))},Ue=new WeakSet,Dt=function(e,t){t.preventDefault();const i=document.getElementById("quotation-request-form");if(!i.checkValidity()){i.reportValidity();return}const s=document.getElementsByName("pc-name")[0],o=document.getElementsByName("pc-phone")[0],r=document.getElementsByName("pc-whatsapp")[0],a=document.getElementsByName("pc-email")[0],u=document.getElementsByName("pc-note")[0],d=document.getElementsByName("pc-file")[0].files,h={name:s.value||"",email:a.value||"",phone:o.value||"",whatsapp:r.value||"",note:u.value||"",design_file:d?d[0]:null,product_id:e};f(this,Se,Ot).call(this,h)},Me=new WeakSet,Bt=function(){f(this,oe,Xe).call(this)},Pe=new WeakSet,Ft=async function(){let e="en";await f(this,xe,Nt).call(this).then(o=>{if(o.data.language==="en"||o.data.language==="es"){localStorage.setItem("pc_lang",o.data.language),e=o.data.language;return}localStorage.setItem("pc_lang","en"),e="en"}).catch(o=>{console.error(o)});const t=document.querySelectorAll("[data-i18n]"),i=this.locales[e];t.forEach(o=>{const r=o.getAttribute("data-i18n");let a=r?r.split(".").reduce((l,d)=>l?l[d]:null,i):null;const u=a?a.match(/{(.*?)}/g):null;u&&u.forEach(l=>{Object.entries(o.dataset).filter(([d,h])=>{if(`{${d}}`===l)try{a=a?a.replace(`${l}`,new Function(`return (${h})`)()):null}catch{const E=h||"";a=a?a.replace(`${l}`,E):null}})}),a&&(o.innerHTML=a)});const s=document.querySelector("html");s&&s.setAttribute("lang",e)},(async()=>{})().then(()=>new rn)});