@aurigma/ui-framework
Version:
A platform which allows building print product personalization editors based on Aurigma's Customer's Canvas.
1 lines • 13.3 kB
JavaScript
(window.multistep_editor_jsonpFunction=window.multistep_editor_jsonpFunction||[]).push([[44],{541:function(e,t,r){"use strict";r.d(t,"a",(function(){return i}));var n=r(26),i=function(e){function t(t){var r=e.call(this)||this;return r._value=t,r}return Object(n.a)(t,e),Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(t){var r=e.prototype._subscribe.call(this,t);return!r.closed&&t.next(this._value),r},t.prototype.getValue=function(){var e=this,t=e.hasError,r=e.thrownError,n=e._value;if(t)throw r;return this._throwIfClosed(),n},t.prototype.next=function(t){e.prototype.next.call(this,this._value=t)},t}(r(127).a)},866:function(e,t){e.exports='<style>\n :host {\n width: 100%;\n height: 100%;\n }\n</style>\n\n<iframe id="frameID" width="100%" height="100%" style="border: none;" onload="{{_initIFrame}}"></iframe>\n\n'},939:function(e,t,r){"use strict";r.r(t),r.d(t,"AuWidgetPreflight",(function(){return h})),r.d(t,"widget",(function(){return h}));var n=r(0),i=r(2),s=r(160),a=function(e,t){this.errors=e,this.warnings=t},o=r(14),c=r(1),l=r(541),u=r(866),h=function(e){function t(){var t,r=e.call(this)||this;return r._eventsInited=!1,r._lastUpdateParamsFunc=new l.a(null),r.hasFiles=!1,r.hasEmptyPages=!1,r.hires=[],r.preview=[],r.previews=[],r.origins=[],r.page="",r.failedChecks=new a([],[]),r.stateId="",r.onPageChange=null,r.onError=null,r.__isLocalesInited=!1,r._initIFrame=r._initIFrame.bind(r),null===(t=r._lastUpdateParamsFunc)||void 0===t||t.asObservable().subscribe((function(e){r._element&&e()})),r}return Object(n.d)(t,e),t.prototype.languageObserver=function(t){e.prototype.languageObserver.call(this,t),this._element&&this._element.setLanguage(t)},t.prototype.updateParams=function(e,t){e.onPageChange&&(this.onPageChange=c.a.functionWrapperConstructor(e.onPageChange)),e.onError&&(this.onError=c.a.functionWrapperConstructor(e.onError))},Object.defineProperty(t.prototype,"pages",{get:function(){return this._element?this._element.pages:0},enumerable:!1,configurable:!0}),t.prototype.updateParamsAsync=function(t,r){return Object(n.b)(this,void 0,void 0,(function(){var i=this;return Object(n.e)(this,(function(n){switch(n.label){case 0:return[4,e.prototype.updateParamsAsync.call(this,t,r)];case 1:return n.sent(),this._lastUpdateParamsFunc.next((function(){var e,r,n=i.driver.backOffice,s=n.tenantId,a=n.token,o=c.a.removeTrailingSlash(null===(e=i.driver.backOffice)||void 0===e?void 0:e.designAtomsApiUrl),l=c.a.removeTrailingSlash(null===(r=i.driver.backOffice)||void 0===r?void 0:r.designAtomsApiUrl);i._element.configuration=Object.assign({language:i.language,services:{designAtoms:{url:o,token:a},assetStorage:{url:l,token:a},tenantId:s}},t.config),i._element.files=t.files,i.updatePreflightStyles()})),[4,this._itemPromise()];case 2:return n.sent(),[2]}}))}))},t.prototype.setStep=function(e){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.e)(this,(function(t){switch(t.label){case 0:return[4,this._itemInitedPromise()];case 1:return t.sent().setStep(e),this.emitChange(),[2]}}))}))},t.prototype.setFiles=function(e){return Object(n.b)(this,void 0,void 0,(function(){return Object(n.e)(this,(function(t){switch(t.label){case 0:return[4,this._itemInitedPromise()];case 1:return t.sent().files=e,[2]}}))}))},t.prototype.getResults=function(e){var t;return void 0===e&&(e=!0),Object(n.b)(this,void 0,void 0,(function(){var r;return Object(n.e)(this,(function(n){switch(n.label){case 0:return[4,this._itemInitedPromise()];case 1:return[4,n.sent().finish(e)];case 2:return r=n.sent(),this.hires=r.hires,this.previews=null!==(t=r.previews)&&void 0!==t?t:[],this.origins=r.origins,this.preview=r.previews.map((function(e){return e.url})),this.stateId=r.stateId,this.emitChange(),[2,r]}}))}))},t.prototype.getPreviews=function(){return Object(n.b)(this,void 0,void 0,(function(){var e,t;return Object(n.e)(this,(function(r){switch(r.label){case 0:return[4,this._itemInitedPromise()];case 1:return e=r.sent(),t=this,[4,e.getPreviews()];case 2:return t.previews=r.sent(),this.preview=this.previews.map((function(e){return e.url})),this.emitChange(),[2,this.previews]}}))}))},t.prototype._itemPromise=function(){var e=this;return new Promise((function(t,r){if(e._element)t(e._element);else{var i=function(){setTimeout((function(){return Object(n.b)(e,void 0,void 0,(function(){var e;return Object(n.e)(this,(function(r){switch(r.label){case 0:return this._iframeDoc&&(e=this._iframeDoc.querySelector("au-preflight-tool"))?(this._element=e,window.Aurigma=Object.assign(window.Aurigma,this._iframeWin.Aurigma),[4,this._getLocales(e)]):[3,3];case 1:return r.sent(),[4,this._initSubscribers(this._element)];case 2:r.sent(),this.showPreloader(!1),this._lastUpdateParamsFunc.value&&this._lastUpdateParamsFunc.value(),t(e),r.label=3;case 3:return this._element||i(),[2]}}))}))}),200)};i()}}))},t.prototype._itemInitedPromise=function(){var e=this;return new Promise((function(t,r){return Object(n.b)(e,void 0,void 0,(function(){var e;return Object(n.e)(this,(function(r){switch(r.label){case 0:return[4,this._itemPromise()];case 1:return(e=r.sent()).isInited&&t(e),e.addEventListener("inited",(function(r){t(e)})),[2]}}))}))}))},t.prototype._initSubscribers=function(e){return Object(n.b)(this,void 0,void 0,(function(){var t=this;return Object(n.e)(this,(function(r){return this._eventsInited||(this._eventsInited=!0,e.addEventListener("hasFiles",(function(e){t.hasFiles=e.detail,t.emitChange()})),e.addEventListener("hasEmptyPages",(function(e){t.hasEmptyPages=e.detail,t.emitChange()})),e.addEventListener("failedChecks",(function(e){t.failedChecks=e.detail,t.emitChange()})),e.addEventListener("stepChanged",(function(e){t.page=e.detail,t.emitChange(),t.onPageChange&&t.onPageChange(t.page),c.a.setTimeoutWrapper((function(){t.onPageChange&&(t.emitChange(),t.onPageChange(t.page))}),100,5)})),e.addEventListener("error",(function(e){t.onError&&t.onError(e.detail)}))),[2]}))}))},t.prototype._getLocales=function(e){var t,r;return Object(n.b)(this,void 0,void 0,(function(){var i,s,a,o,l,u,h,d,p,g,f;return Object(n.e)(this,(function(v){switch(v.label){case 0:if(this.__isLocalesInited)return[2];if(i=null===(r=null===(t=this.driver)||void 0===t?void 0:t.localization)||void 0===r?void 0:r.find((function(e){return"preflight"===e.app})),s={},!i||"string"!=typeof i.url||""===i.url)return[3,6];v.label=1;case 1:return v.trys.push([1,3,,5]),[4,c.a.loadJson(i.url+"?ts="+Date.now())];case 2:return s=v.sent(),[3,5];case 3:return a=v.sent(),console.error(a),[4,this._getPreflightLocalesFile()];case 4:return s=v.sent(),[3,5];case 5:return[3,8];case 6:return[4,this._getPreflightLocalesFile()];case 7:s=v.sent(),o=i&&"object"==typeof i.data,l=i&&0!==Object.keys(i.data).length,i&&o&&l&&(s=-1!==Object.keys(i.data).indexOf(this.language)?c.a.DeepMerge(s,i.data):c.a.DeepMerge(s,((p={})[this.language]=i.data,p))),v.label=8;case 8:if(e){try{for(u=Object(n.k)(Object.keys(s)),h=u.next();!h.done;h=u.next())d=h.value,e.addLocalization(d,s[d],!1)}catch(b){g={error:b}}finally{try{h&&!h.done&&(f=u.return)&&f.call(u)}finally{if(g)throw g.error}}e.setLanguage(this.language)}return this.__isLocalesInited=!0,[2]}}))}))},t.prototype.updatePreflightStyles=function(){var e=this;this.params.style&&Object.keys(this.params.style).forEach((function(t){var r=e._computeValue(e.params.style[t]);e._iframeDoc.documentElement.style.setProperty(t,r)}))},t.prototype._initIFrame=function(){return Object(n.b)(this,void 0,void 0,(function(){var e,t,r,i,s,a,o,l,u,h,d,p,g;return Object(n.e)(this,(function(f){switch(f.label){case 0:this.showPreloader(!0),this.driver.config,e=this.querySelectorShadow("#frameID"),t=e.contentWindow||e,r=e.contentDocument||t.document,i=c.a.getDocumentCustomStyles(),s="<style> html {";try{for(a=Object(n.k)(Object.entries(i)),o=a.next();!o.done;o=a.next())l=o.value,s+=l[0]+":"+l[1]+";"}catch(v){p={error:v}}finally{try{o&&!o.done&&(g=a.return)&&g.call(a)}finally{if(p)throw p.error}}return s+="}</style>",[4,this._getPreflightDistFiles()];case 1:return u=f.sent(),r.write(u.script),r.write(u.styles),r.write(u.customStyles),r.write(s),r.write('<div class="iconset" style="display:none;">'.concat(document.querySelector('[name="custom-icons"]').innerHTML,"</div>")),this._replacePreloader(r),h=document.querySelector("iron-iconset-svg[name='custom-icons']")._icons.preloader,d=h.getAttribute("viewBox"),r.write('<script> window.AuPreloaderSize = "'.concat(d,'"; <\/script>')),r.write('\n <script>\n document.addEventListener("DOMContentLoaded", () => {\n const svgs = Array.from(document.querySelectorAll("div.icon-preflight-logo svg"));\n svgs.forEach(svg => svg.setAttribute("viewBox", "'.concat(d,'"));\n });\n <\/script>')),r.write('<au-preflight-tool id="preflight"></au-preflight-tool>'),this._iframeDoc=r,this._iframeWin=t,[2]}}))}))},t.prototype._replacePreloader=function(e){var t;if(null===(t=this.driver.config.icons)||void 0===t?void 0:t.preloader){var r=e.getElementById("preloader"),n=r.parentNode;n.removeChild(r);var i=(new DOMParser).parseFromString(this.driver.config.icons.preloader,"image/svg+xml").children.item(0);i.id="preloader",n.appendChild(i)}},t.prototype._getPreflightLocalesFile=function(){return Object(n.b)(this,void 0,void 0,(function(){var e,t,r,i;return Object(n.e)(this,(function(n){switch(n.label){case 0:e=c.a.ensureEndsWith(this._getBackendUrl(),"/"),t=e+"static/locales.json?t="+Date.now(),r={},n.label=1;case 1:return n.trys.push([1,3,,5]),[4,c.a.loadJson(t)];case 2:return r=n.sent(),[3,5];case 3:return n.sent(),console.warn("Failed to load locales from Preflight Backend: ".concat(t)),[4,c.a.loadJson("static/preflight/locales.json?t="+Date.now())];case 4:return[2,n.sent()];case 5:return[4,c.a.loadJson("static/preflight/locales.json?t="+Date.now())];case 6:return i=n.sent(),[2,c.a.DeepMerge(r,i)]}}))}))},t.prototype._getPreflightDistFiles=function(){return Object(n.b)(this,void 0,void 0,(function(){var e,t,r,i,s,a,o;return Object(n.e)(this,(function(n){switch(n.label){case 0:e=c.a.ensureEndsWith(this._getBackendUrl(),"/"),t=e+"static/script.html?t="+Date.now(),r=e+"static/style.html?t="+Date.now(),i=e+"static/customStyles.html?t="+Date.now(),s="",a="",o="",n.label=1;case 1:return n.trys.push([1,9,,13]),[4,c.a.loadHtml(r)];case 2:return s=n.sent(),[4,c.a.loadHtml(t)];case 3:o=n.sent(),n.label=4;case 4:return n.trys.push([4,6,,8]),[4,c.a.loadHtml(i)];case 5:return a=n.sent(),[3,8];case 6:return n.sent(),[4,c.a.loadHtml("static/preflight/customStyles.html?t="+Date.now())];case 7:return a=n.sent(),[3,8];case 8:return[3,13];case 9:return n.sent(),console.warn("Failed to load Preflight scripts from backend ".concat(t)),[4,c.a.loadHtml(c.a.getPatchedUrl("static/preflight/style.html?t="+Date.now()))];case 10:return s=n.sent(),[4,c.a.loadHtml(c.a.getPatchedUrl("static/preflight/customStyles.html?t="+Date.now()))];case 11:return a=n.sent(),[4,c.a.loadHtml(c.a.getPatchedUrl("static/preflight/script.html?t="+Date.now()))];case 12:return o=n.sent(),[3,13];case 13:return[2,{script:o,styles:s,customStyles:a}]}}))}))},t.prototype._getBackendUrl=function(){var e=this.paramsRaw;if(void 0!==e.config.backendUrl&&-1===e.config.backendUrl.indexOf("{{"))return e.config.backendUrl;var t=this.jsonParamsFetcher.scope;return t.self=this,e[o.a.SCOPE_HEAD_KEY]=this.jsonParamsFetcher.head,this._jsonProcessor.process(e,t).config.backendUrl},t.prototype.exportWidgetData=function(e){return Object(n.b)(this,void 0,void 0,(function(){var t;return Object(n.e)(this,(function(r){switch(r.label){case 0:return e?[4,this.getResults()]:[3,2];case 1:t=r.sent(),this.stateId=t.stateId,r.label=2;case 2:return[2,{stateId:this.stateId,page:this.page}]}}))}))},t.prototype.restoreWidgetFromData=function(e,t){return Object(n.b)(this,void 0,void 0,(function(){var t;return Object(n.e)(this,(function(r){switch(r.label){case 0:return this._isRestoring=!0,this.stateId=e.stateId,"firefox"!==c.a.getBrowser()?[3,1]:(this._itemInitedPromise().then((function(t){t.setState(e.stateId).then((function(){e.page&&t.setStep(e.page)}))})),[3,4]);case 1:return[4,this._itemInitedPromise()];case 2:return[4,(t=r.sent()).setState(e.stateId)];case 3:r.sent(),e.page&&t.setStep(e.page),r.label=4;case 4:return this._isRestoring=!1,[2]}}))}))},Object(n.c)([Object(i.c)(),Object(n.g)("design:type",Boolean)],t.prototype,"hasFiles",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",Boolean)],t.prototype,"hasEmptyPages",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",Array)],t.prototype,"hires",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",Array)],t.prototype,"preview",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",Array)],t.prototype,"previews",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",Array)],t.prototype,"origins",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",String)],t.prototype,"page",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",a)],t.prototype,"failedChecks",void 0),Object(n.c)([Object(i.c)(),Object(n.g)("design:type",String)],t.prototype,"stateId",void 0),Object(n.c)([Object(i.a)("au-widget-preflight",u),Object(n.g)("design:paramtypes",[])],t)}(s.c)}}]);