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