@printcart/shopify-integration
Version:
Printcart Designer SDK for Shopify.
131 lines (130 loc) • 43.1 kB
JavaScript
var un=Object.defineProperty;var pn=(_,g,y)=>g in _?un(_,g,{enumerable:!0,configurable:!0,writable:!0,value:y}):_[g]=y;var ce=(_,g,y)=>(pn(_,typeof g!="symbol"?g+"":g,y),y),Ze=(_,g,y)=>{if(!g.has(_))throw TypeError("Cannot "+y)};var l=(_,g,y)=>(Ze(_,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)},x=(_,g,y,F)=>(Ze(_,g,"write to private field"),F?F.call(_,y):g.set(_,y),y);var f=(_,g,y)=>(Ze(_,g,"access private method"),y);(function(_){typeof define=="function"&&define.amd?define(_):_()})(function(){var B,se,w,I,U,N,$,re,Xe,me,It,A,X,_e,Ct,ge,qt,ye,St,we,kt,Ee,Tt,Le,Ut,be,Mt,Ie,Pt,Ce,Ot,qe,Nt,Se,$t,ke,xt,Te,At,Ue,Dt,oe,Ye,ae,Ge,Me,Rt,Pe,Bt,Oe,Ft,Ne,Wt,$e,Ht;"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)},Je=(n,e,t,i)=>(F(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t),S=(n,e,t)=>(F(n,e,"access private method"),t),H,G,De,et,Re,tt,le,Be,T,P,Fe={exports:{}},j=typeof Reflect=="object"?Reflect:null,nt=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 jt(n){console&&console.warn&&console.warn(n)}var it=Number.isNaN||function(e){return e!==e};function v(){v.init.call(this)}Fe.exports=v,Fe.exports.once=Qt,v.EventEmitter=v,v.prototype._events=void 0,v.prototype._eventsCount=0,v.prototype._maxListeners=void 0;var st=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 st},set:function(n){if(typeof n!="number"||n<0||it(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");st=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||it(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 rt(n){return n._maxListeners===void 0?v.defaultMaxListeners:n._maxListeners}v.prototype.getMaxListeners=function(){return rt(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")nt(u,this,t);else for(var c=u.length,d=dt(u,c),i=0;i<c;++i)nt(d[i],this,t);return!0};function ot(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=rt(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,jt(a)}return n}v.prototype.addListener=function(e,t){return ot(this,e,t,!1)},v.prototype.on=v.prototype.addListener,v.prototype.prependListener=function(e,t){return ot(this,e,t,!0)};function zt(){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 at(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},s=zt.bind(i);return s.listener=t,i.wrapFn=s,s}v.prototype.once=function(e,t){return ue(t),this.on(e,at(this,e,t)),this},v.prototype.prependOnceListener=function(e,t){return ue(t),this.prependListener(e,at(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():Kt(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 ct(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?Vt(s):dt(s,s.length)}v.prototype.listeners=function(e){return ct(this,e,!0)},v.prototype.rawListeners=function(e){return ct(this,e,!1)},v.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):lt.call(n,e)},v.prototype.listenerCount=lt;function lt(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 dt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function Kt(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function Vt(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function Qt(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))}ut(n,e,o,{once:!0}),e!=="error"&&Zt(n,s,{once:!0})})}function Zt(n,e,t){typeof n.on=="function"&&ut(n,"error",e,t)}function ut(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 Xt=Fe.exports;const J="pc-designer-iframe-wrapper",pe="pc-designer-iframe";class Yt{constructor(e){W(this,De),W(this,Re),W(this,le),W(this,T),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,Je(this,H,(t=this.options)!=null&&t.designerUrl?this.options.designerUrl:{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),Je(this,G,new Xt),!this.token||!this.productId){console.error("Missing Config Params");return}S(this,De,et).call(this),S(this,Re,tt).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=S(this,le,Be).call(this);t.src=i.href,e.style.opacity="1",e.style.visibility="visible",S(this,T,P).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",S(this,T,P).call(this,"closed")}editDesign(e){const t=S(this,le,Be).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",S(this,T,P).call(this,"edit")}on(e,t){return Y(this,G).on(e,t),this}}H=new WeakMap,G=new WeakMap,De=new WeakSet,et=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)},Re=new WeakSet,tt=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",S(this,T,P).call(this,"closed")}if(n.data.message==="finishLoad"){const e=document.getElementById(pe);S(this,T,P).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"&&S(this,T,P).call(this,"upload-success",n.data.data.data),n.data.message==="finishUpdate"&&S(this,T,P).call(this,"edit-success",n.data.data.data),n.data.message==="uploadError"&&S(this,T,P).call(this,"upload-error",n.data)},!1)},le=new WeakSet,Be=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},T=new WeakSet,P=function(n,...e){Y(this,G).emit(n,...e)};var We=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)},q=(n,e,t)=>(We(n,e,"read from private field"),t?t.call(n):e.get(n)),O=(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)},z=(n,e,t,i)=>(We(n,e,"write to private field"),i?i.call(n,t):e.set(n,t),t),D=(n,e,t)=>(We(n,e,"access private method"),t),ee,K,V,te,ne,ie,R,Q,He,pt,je,ft,ze={exports:{}},Z=typeof Reflect=="object"?Reflect:null,ht=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 Gt(n){console&&console.warn&&console.warn(n)}var vt=Number.isNaN||function(e){return e!==e};function m(){m.init.call(this)}ze.exports=m,ze.exports.once=nn,m.EventEmitter=m,m.prototype._events=void 0,m.prototype._eventsCount=0,m.prototype._maxListeners=void 0;var mt=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 mt},set:function(n){if(typeof n!="number"||n<0||vt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");mt=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||vt(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 _t(n){return n._maxListeners===void 0?m.defaultMaxListeners:n._maxListeners}m.prototype.getMaxListeners=function(){return _t(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")ht(u,this,t);else for(var c=u.length,d=Lt(u,c),i=0;i<c;++i)ht(d[i],this,t);return!0};function gt(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=_t(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,Gt(a)}return n}m.prototype.addListener=function(e,t){return gt(this,e,t,!1)},m.prototype.on=m.prototype.addListener,m.prototype.prependListener=function(e,t){return gt(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 yt(n,e,t){var i={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},s=Jt.bind(i);return s.listener=t,i.wrapFn=s,s}m.prototype.once=function(e,t){return he(t),this.on(e,yt(this,e,t)),this},m.prototype.prependOnceListener=function(e,t){return he(t),this.prependListener(e,yt(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():en(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 wt(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?tn(s):Lt(s,s.length)}m.prototype.listeners=function(e){return wt(this,e,!0)},m.prototype.rawListeners=function(e){return wt(this,e,!1)},m.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):Et.call(n,e)},m.prototype.listenerCount=Et;function Et(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 Lt(n,e){for(var t=new Array(e),i=0;i<e;++i)t[i]=n[i];return t}function en(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function tn(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function nn(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))}bt(n,e,o,{once:!0}),e!=="error"&&sn(n,s,{once:!0})})}function sn(n,e,t){typeof n.on=="function"&&bt(n,"error",e,t)}function bt(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 rn=ze.exports;const ve="pc-uploader-iframe-wrapper",Ke="pc-uploader-iframe";class on{constructor(e){if(O(this,R),O(this,He),O(this,je),O(this,ee,void 0),O(this,K,void 0),O(this,V,void 0),O(this,te,void 0),O(this,ne,void 0),O(this,ie,void 0),z(this,ee,e.token),z(this,K,e.sideId||e.productId),z(this,ie,e.productId?"product":"side"),z(this,V,e.uploaderUrl?e.uploaderUrl:"https://upload-tool.pages.dev"),z(this,te,new rn),z(this,ne,e.locale),!q(this,ee)||!q(this,K)){console.warn("Missing Config Params.");return}D(this,He,pt).call(this),D(this,je,ft).call(this)}get locale(){return q(this,ne)}open(){let e=document.getElementById(ve),t=document.getElementById(Ke);const i=new URL(q(this,V));if(i.searchParams.set("token",q(this,ee)),q(this,ie)==="side"?i.searchParams.set("sideId",q(this,K)):q(this,ie)==="product"&&i.searchParams.set("productId",q(this,K)),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",D(this,R,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,K=new WeakMap,V=new WeakMap,te=new WeakMap,ne=new WeakMap,ie=new WeakMap,R=new WeakSet,Q=function(n,...e){q(this,te).emit(n,...e)},He=new WeakSet,pt=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)},je=new WeakSet,ft=function(){let n=document.getElementById(ve);window.addEventListener("message",e=>{var t;const i=new URL(e.origin),s=new URL(q(this,V));if(i.host===s.host){e.data.uploaderEvent==="close"&&n&&(n.style.opacity="0",n.style.visibility="hidden",D(this,R,Q).call(this,"close")),e.data.uploaderEvent==="upload-success"&&D(this,R,Q).call(this,"upload-success",e.data.data),e.data.uploaderEvent==="upload-error"&&D(this,R,Q).call(this,"upload-error",e.data.error);const o=q(this,ne),r=document.getElementById(Ke);r&&r instanceof HTMLIFrameElement&&(D(this,R,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,V))))}},!1)};var fn="";class an{constructor(){p(this,re);p(this,me);p(this,A);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,Se);p(this,ke);p(this,Te);p(this,Ue);p(this,oe);p(this,ae);p(this,Me);p(this,Pe);p(this,Oe);p(this,Ne);p(this,$e);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,U,void 0);p(this,N,void 0);p(this,$,void 0);ce(this,"locales");if(this.token=f(this,Ce,Ot).call(this),this.productId=null,x(this,U,!1),this.options=window.PrintcartDesignerShopifyOptions,x(this,B,{}.VITE_API_URL?{}.VITE_API_URL:"https://api.printcart.com/v1/"),x(this,se,{}.VITE_CUSTOMIZER_URL?{}.VITE_CUSTOMIZER_URL:"https://customizer.printcart.com"),x(this,N,document.querySelector('form[action$="/cart/add"]')),x(this,$,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"}},!l(this,N))throw new Error("This script can only be used inside a Shopify Product Page.");f(this,we,kt).call(this);let e=null,t=l(this,N).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,Xe).call(this,e)}),f(this,re,Xe).call(this,e)}}B=new WeakMap,se=new WeakMap,w=new WeakMap,I=new WeakMap,U=new WeakMap,N=new WeakMap,$=new WeakMap,re=new WeakSet,Xe=async function(e){var r,a,u;if(!e){const c=(r=window==null?void 0:window.ShopifyAnalytics)==null?void 0:r.meta;e=c==null?void 0:c.selectedVariantId}if(!e)throw new Error("Can not find product variant ID");const t=await f(this,Se,$t).call(this,e);this.productId=(a=t==null?void 0:t.data)==null?void 0:a.id;const i=t.data.enable_design,s=t.data.enable_upload,o=t.data.enable_request_quote;await f(this,Ne,Wt).call(this),i&&(x(this,w,new Yt({token:this.token,productId:this.productId,options:{...(u=this.options)==null?void 0:u.designerOptions,designerUrl:l(this,se)}})),f(this,Ie,Pt).call(this)),s&&(x(this,I,new on({token:this.token,productId:this.productId})),f(this,be,Mt).call(this)),o&&(x(this,U,!0),f(this,Me,Rt).call(this,t.data)),(s||i||o)&&f(this,Ue,Dt).call(this),await f(this,ge,qt).call(this),await f(this,_e,Ct).call(this),await f(this,ye,St).call(this),await f(this,$e,Ht).call(this)},me=new WeakSet,It=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()},A=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,Ct=function(){const e=document.getElementById("pc-select_close-btn"),t=document.getElementById("pc-content-overlay"),i=s=>{s.key==="Escape"&&f(this,A,X).call(this)};window.addEventListener("keydown",i),e==null||e.addEventListener("click",()=>f(this,A,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,A,X).call(this)})},ge=new WeakSet,qt=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">
${l(this,w)?o:""}
${l(this,I)?s:""}
${l(this,U)?r:""}
</div>
</div>
</div>
`,u=document.getElementById("pc-select_wrap");u&&u.remove();const c=document.createElement("div");c.id="pc-select_wrap",c.setAttribute("role","dialog"),c.setAttribute("aria-modal","true"),c.setAttribute("tabIndex","-1"),c.innerHTML=a,document.body.appendChild(c);const d=()=>{l(this,w)&&(f(this,A,X).call(this),l(this,w).render(),document.body.classList.add("pc-overflow"))},h=()=>{l(this,I)&&(f(this,A,X).call(this),l(this,I).open(),document.body.classList.add("pc-overflow"))},L=()=>{f(this,Oe,Ft).call(this)},E=document.getElementById("pc-select_btn_upload"),C=document.getElementById("pc-select_btn_design"),k=document.getElementById("pc-select_btn_quote_request");E&&(E==null||E.addEventListener("click",h)),C&&(C==null||C.addEventListener("click",d)),k&&(k==null||k.addEventListener("click",L))},ye=new WeakSet,St=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,Tt=function(e){var a,u;const t=e.map(c=>c.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(),l(this,$)?l(this,$).appendChild(i):(a=l(this,N))==null||a.appendChild(i));const s=document.querySelector(".pc-preview-wrap")||document.createElement("div");s.className="pc-preview-wrap",e.forEach(c=>{var C;if(!c.data.design_image.url)return;const d=document.createElement("div");d.className="pc-preview",d.setAttribute("data-pc-design-id",c.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=k=>{k.preventDefault();const b=i.value.split(",").filter(M=>M!==c.data.id);i.value=b.join(),d.remove()};const L=document.createElement("img");L.src=c.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 c=document.createElement("h5");c.className="princart-preview-heading",c.innerHTML="Your artworks",o==null||o.appendChild(c)}o==null||o.appendChild(s);const r=(u=this.options)==null?void 0:u.onUploadSuccess;r&&r(e,l(this,I))},Le=new WeakSet,Ut=function(e){var u,c;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(),l(this,$)?l(this,$).appendChild(s):(u=l(this,N))==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,k;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 M=document.createElement("button");M.className="pc-btn pc-primary-btn",M.innerHTML="Edit",M.onclick=Qe=>{Qe.preventDefault(),l(t,w).editDesign(d.id)};const xe=document.createElement("button");xe.className="pc-btn pc-danger-btn",xe.innerHTML="Remove",xe.onclick=Qe=>{Qe.preventDefault();const ln=s.value.split(",").filter(dn=>dn!==d.id);s.value=ln.join(),b.remove()};const Ve=document.createElement("img"),cn=((k=(C=d.preview)==null?void 0:C.design)==null?void 0:k.url)||d.preview_image.url;Ve.src=cn,Ve.className="pc-uploader-image";const Ae=document.createElement("div");Ae.className="pc-preview-overlay",Ae.appendChild(M),Ae.appendChild(xe),b.appendChild(Ae),b.appendChild(Ve),o.appendChild(b)}});const r=document.querySelector("div#pc-designer_wrap");r==null||r.appendChild(o);const a=(c=this.options)==null?void 0:c.onDesignCreateSuccess;a&&a(e,l(this,w))},be=new WeakSet,Mt=function(){l(this,I)&&l(this,I).on("upload-success",e=>{f(this,Ee,Tt).call(this,e),l(this,I).close()})},Ie=new WeakSet,Pt=function(){l(this,w)&&(l(this,w).on("upload-success",e=>{f(this,Le,Ut).call(this,e),l(this,w).close()}),l(this,w).on("closed",()=>{document.body.classList.remove("pc-overflow")}),l(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;l(this,w).close(),s&&s(e,l(this,w))}))},Ce=new WeakSet,Ot=function(){const e=f(this,qe,Nt).call(this),t=new URL(e);return new URLSearchParams(t.search).get("shopT")},qe=new WeakSet,Nt=function(){return document.currentScript.src},Se=new WeakSet,$t=async function(e){try{const t=`${l(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)}},ke=new WeakSet,xt=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=(c=!1,d="")=>{var h,L,E;if((h=t[0])!=null&&h.classList&&t[0].classList.remove("active"),c&&((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 c=`${l(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(c,{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}},Te=new WeakSet,At=async function(){try{const e=`${l(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)}},Ue=new WeakSet,Dt=function(){var i,s,o,r;const e=(i=l(this,$))!=null?i:l(this,N);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",c=this.locales[u].start_design;t.innerHTML=(r=this.options)!=null&&r.designBtnText?this.options.designBtnText:c,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(),l(this,w)&&!l(this,I)&&!l(this,U)){l(this,w).render();return}if(!l(this,w)&&l(this,I)&&!l(this,U)){l(this,I).open();return}if(!l(this,w)&&!l(this,I)&&l(this,U)){f(this,oe,Ye).call(this);return}(l(this,w)||l(this,I)||l(this,U))&&f(this,me,It).call(this)})},oe=new WeakSet,Ye=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,Ge=function(){const e=document.getElementById("pc-quotation-request_wrap");e&&(e.style.display="none"),document.body.classList.remove("pc-overflow")},Me=new WeakSet,Rt=function(e){var c,d,h,L,E,C,k;const t=(b,M)=>new Intl.NumberFormat("en-US",{style:"currency",currency:M}).format(b);let i="";if(((c=e==null?void 0:e.request_quote_options)==null?void 0:c.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),M=(k=(C=e==null?void 0:e.request_quote_options)==null?void 0:C.currency)==null?void 0:k.code;i=`<span class="pc-currency text-danger">Please note that an additional fee of <b>${t(b,M)}</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,Ge).call(this)};window.addEventListener("keydown",u),r==null||r.addEventListener("click",()=>f(this,ae,Ge).call(this)),a==null||a.addEventListener("click",b=>f(this,Pe,Bt).call(this,e==null?void 0:e.id,b))},Pe=new WeakSet,Bt=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,ke,xt).call(this,h)},Oe=new WeakSet,Ft=function(){f(this,oe,Ye).call(this)},Ne=new WeakSet,Wt=async function(){var s,o,r,a,u;let e,t;const i=await f(this,Te,At).call(this);if(e=(o=(s=i==null?void 0:i.data)==null?void 0:s.setting_defaults)==null?void 0:o.customCss.value,t=(a=(r=i==null?void 0:i.data)==null?void 0:r.setting_defaults)==null?void 0:a.textReplace,((u=i==null?void 0:i.data)==null?void 0:u.language)&&(i.data.language==="en"||i.data.language==="es")?localStorage.setItem("pc_lang",i.data.language):localStorage.setItem("pc_lang","en"),this.locales={...this.locales,en:{start_design:t!=null&&t.start_design?t.start_design:this.locales.en.start_design,pc_select_header:t!=null&&t.pc_select_header?t.pc_select_header:this.locales.en.pc_select_header,upload_a_full_design:t!=null&&t.upload_a_full_design?t.upload_a_full_design:this.locales.en.upload_a_full_design,upload_design_file:t!=null&&t.upload_design_file?t.upload_design_file:this.locales.en.upload_design_file,have_a_complete_design:t!=null&&t.have_a_complete_design?t.have_a_complete_design:this.locales.en.have_a_complete_design,have_your_own_design:t!=null&&t.have_your_own_design?t.have_your_own_design:this.locales.en.have_your_own_design,design_here_online:t!=null&&t.design_here_online?t.design_here_online:this.locales.en.design_here_online,already_have_a_design:t!=null&&t.already_have_a_design?t.already_have_a_design:this.locales.en.already_have_a_design,customize_every_details:t!=null&&t.customize_every_details?t.customize_every_details:this.locales.en.customize_every_details,request_us_to_design:t!=null&&t.request_us_to_design?t.request_us_to_design:this.locales.en.request_us_to_design,share_your_idea:t!=null&&t.share_your_idea?t.share_your_idea:this.locales.en.share_your_idea,our_designers_do_st:t!=null&&t.our_designers_do_st?t.our_designers_do_st:this.locales.en.our_designers_do_st,note_desc:t!=null&&t.note_desc?t.note_desc:this.locales.en.note_desc,file_desc:t!=null&&t.file_desc?t.file_desc:this.locales.en.file_desc}},e){const c=document.createElement("style");c.textContent=e,c.type="text/css",document.head.appendChild(c)}},$e=new WeakSet,Ht=function(){const e=localStorage.getItem("pc_lang")||"en",t=document.querySelectorAll("[data-i18n]"),i=this.locales[e];t.forEach(o=>{const r=o.getAttribute("data-i18n");let a=r?r.split(".").reduce((c,d)=>c?c[d]:null,i):null;const u=a?a.match(/{(.*?)}/g):null;u&&u.forEach(c=>{Object.entries(o.dataset).filter(([d,h])=>{if(`{${d}}`===c)try{a=a?a.replace(`${c}`,new Function(`return (${h})`)()):null}catch{const E=h||"";a=a?a.replace(`${c}`,E):null}})}),a&&(o.innerHTML=a)});const s=document.querySelector("html");s&&s.setAttribute("lang",e)},(async()=>{})().then(()=>new an)});