UNPKG

@aurigma/ui-framework

Version:

A platform which allows building print product personalization editors based on Aurigma's Customer's Canvas.

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