UNPKG

@aurigma/ui-framework

Version:

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

1 lines 53.9 kB
(window.multistep_editor_jsonpFunction=window.multistep_editor_jsonpFunction||[]).push([[24],{539:function(e,t,a){a.d(t,"a",function(){return r});var i=a(404),s=a(603);class r{static get iframeApiPromise(){return this._iframeApiSubject.pipe(Object(s.a)(1)).toPromise()}static loadCCScript(e,t){var a;return"undefined"!=typeof CustomersCanvas||document.body.querySelector("#CcIframeApiScript")?"undefined"!=typeof CustomersCanvas&&this._iframeApiSubject.next(CustomersCanvas):(this._iframeApiSubject=new i.a(1),(a=document.createElement("script")).type="text/javascript",a.id="CcIframeApiScript",a.onload=e=>{CustomersCanvas&&this._iframeApiSubject.next(CustomersCanvas)},a.onerror=e=>{this._iframeApiSubject.error(e)},a.src=e+t,document.body.appendChild(a)),this.iframeApiPromise}}r._iframeApiSubject=new i.a(1)},540:function(e,t,a){a.d(t,"a",function(){return c});var m=a(36),s=a(601),f=a(1),r=a(71),i=a(395),n=a(603),o=a(541);class c{constructor(e,t,a=()=>Promise.resolve(),i){this._executedActions=[],this._lastJobKey="init",this._lastExecutedJobSubject=new o.a("init"),this._commands=e,this._onJobFinish=a,this.logger=new r.Category("command-executer_"+t+"_"+f.a.guid()),this.widget=i}_showLockPreloader(e,t,a){var i;if(e&&t&&e[t]&&e[t].lock&&this.widget)for(i of Array.isArray(e[t].lock)?e[t].lock:[e[t].lock]){var s="main"===i?this.widget.auWizard:this.widget.auWizard.scope.$[i]||this.widget.jsonParamsFetcher.scope[i]||this.widget.jsonParamsFetcher.scope.$[i];s&&s.showPreloader(a)}}executeActions(d,u,h){u=u.filter(e=>{var t=!(!0===d[e].executeOnce&&-1!==this._executedActions.indexOf(e));let a=!0;return Array.isArray(d[e].executeOnlyAfter)&&(a=d[e].executeOnlyAfter.reduce((e,t)=>e=-1===this._executedActions.indexOf(t)?!1:e,!0)),t&&a});let g=async a=>{this.logger.debug(()=>`Start Execute '${a}'`);var e=performance.now();let i=Promise.resolve();var s,r,n=this._commands[a],o=(Array.isArray(d[a])?d[a][0]:d[a]).message,c=(Array.isArray(d[a])?d[a][0]:d[a]).timeout||10;if(n&&void 0!==n.execute){o&&this.widget.showPreloader(!0,o,c),this._showLockPreloader(d,a,!0),i=n.execute(d[a],h[a]),-1===this._executedActions.indexOf(a)&&this._executedActions.push(a);let t=d[a].after;if(void 0!==(t=!t&&Array.isArray(d[a])&&(c=d[a].find(e=>e.after))?c.after:t)){Object(m.a)(t)||(t=[t]);for(let e=0;e<t.length;e++){var l=t[e];s=l,(r=u).indexOf(a)<r.indexOf(s)||(await i,i=g(l))}}let e=d[a].onExecuted;(e=!e&&Array.isArray(d[a])&&(n=d[a].find(e=>e.onExecuted))?n.onExecuted:e)&&(await i,await f.a.functionWrapperConstructor(e)())}else console.warn(`Action ${a} is not supported! Double check the config.`);await i,o&&this.widget.showPreloader(!1),this._showLockPreloader(d,a,!1),this.logger.debug(()=>`Finish Execute '${a}'`);c=performance.now();return this.widget.auWizard.telemetry.trackEvent("DE-"+a,c-e),i};var e=this.getJobReady(this._lastJobKey);let t=this._lastJobKey=f.a.guid();return e.then(()=>(this.logger.debug(()=>"Start actons: "+u),f.a.recursiveJobPromise(u,g))).then(()=>this._onJobFinish()).finally(()=>{this.logger.debug(()=>"End actons: "+u),this._lastExecutedJobSubject.next(t)})}getJobReady(t){return this._lastExecutedJobSubject.pipe(Object(i.a)(e=>e===t),Object(n.a)(1)).toPromise()}getChangedActions(a,i){let e=Object.keys(a).filter(e=>f.a.isObjectNotEmpty(a[e])).filter(e=>{return void 0===i[e]||(t=a[e],e=i[e],!(JSON.stringify(t)===JSON.stringify(e)));var t});var t=e.indexOf("actionsErrorToast");return-1!==t&&e.splice(t,1),-1<(e=e.filter(e=>{e=a[e];return Array.isArray(e)?e[0]&&!1!==e[0].autoCompile:!1!==e.autoCompile})).indexOf("initial")?["initial"].concat(Object(s.a)(e,"initial")):e}}},865:function(e,t){e.exports="<style>\n :host {\n width: 100%;\n height: 100%;\n display: block;\n position: initial;\n }\n\n #design-editor {\n position: absolute;\n height: 1px;\n min-height: 100%;\n width: 1px;\n min-width: 100%;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n border: none;\n background-color: transparent;\n }\n</style>\n<iframe id='design-editor' allowfullscreen></iframe>\n"},924:function(T,e,t){t.r(e),t.d(e,"AuWidgetDesignEditor",function(){return N}),t.d(e,"widget",function(){return N});var n=t(0),a=t(888),i=t(887),g=t(445),o=t(464),r=t(410),s=t(540),m=t(1),u=t(537),c=t(598),l=t(202),d=t(928),e=t(2),h=t(17),f=t(539);class p{constructor(){this.promise=new Promise(function(e,t){this._resolve=e,this._reject=t}.bind(this))}then(e){return this.promise.then(e)}catch(e){return this.promise.catch(e)}resolve(e=""){this._resolve(e)}reject(e){this._reject(e)}}var w=t(413),v=t(408),y=t(559),I=t(435),C=t(560),P=t(562),b=t(478),_=t(512),z=t(567),x=t(458),O=t(440);class U{constructor(e){Object.assign(this,e)}}var F=t(404),S=t(603),A=t(160);class B extends A.c{constructor(){super(...arguments),this._customersCanvasSubject=new F.a(1)}customersCanvasPublish(e){this._customersCanvasSubject.next(e)}get customersCanvasObservable(){return this._customersCanvasSubject.asObservable()}get customersCanvasPromise(){return this.customersCanvasObservable.pipe(Object(S.a)(1)).toPromise()}async getProduct(){return(await this.getEditor()).getProduct()}async getEditor(){return this._customersCanvasSubject.asObservable().pipe(Object(S.a)(1)).toPromise()}async getDesignEditorItemModel(a){var e=a.type===_.b.type,i=a.type===I.a.type||a.type===C.a.type||a.type===z.a.type||a.type===P.a.type||a.type===y.a.type,s=a.type===v.kb.type||a.type===v.gb.type||a.type===v.A.type||a.type===_.b.type;b.a.type;let r=!1,n=!1;if(a){let t={name:a.name};switch(e&&(r=m.a.isNotNullOrUndefined(a.content)&&(a.content instanceof CustomersCanvas.DesignAtoms.ObjectModel.ImageItem||"ImageItem"===a.content.type),n=m.a.isNotNullOrUndefined(a.content)&&(a.content instanceof CustomersCanvas.DesignAtoms.ObjectModel.BarcodeItem||"BarcodeItem"===a.content.type)),!0){case e&&r&&!n&&null!=a.content.tags.sourceData:{var o=a.content,c=new O.a(a).getTransformedRectangle(),l=new x.b(o).getTransformedRectangle(),d=await this.getEditor();let e=300;try{e=await d.eval("var printArea = spEditor.productHandler.product.surfaces.elementAt(0).printAreas.elementAt(0);var config = spEditor.configuration.renderingConfig.getHiResRendering(printArea);config.dpi;")}catch(e){console.warn("Failed to get hires render config dpi")}t.tags=Object(u.a)(o.tags),t.value=o.tags.sourceData.name,t.placeholderContent={originalUrl:o.tags.sourceData.originalUrl,width:o.source.width,height:o.source.height,placeholderRectangle:c,contentRectangle:l,contentResizeMode:_.c[a.contentResizeMode].toLowerCase(),contentTransform:{angle:o.transform.angle,scaleX:o.transform.scaleX,scaleY:o.transform.scaleY,translateX:o.transform.translateX,translateY:o.transform.translateY},dpi:e};break}case e&&r:t={name:a.name,tags:Object(u.a)(a.tags)};break;case i&&!!a.text:{d=a;let e="";c=e=>(e/255).toFixed(7);d.color&&(d.color.colorSpace===w.ColorSpace.Rgb?(l=d.color,e=`rgb(${l.r},${l.g},${l.b},${c(l.alpha)})`):d.color.colorSpace===w.ColorSpace.Cmyk&&(o=d.color,e=`cmyk(${c(o.c)},${c(o.m)},${c(o.y)},${c(o.k)},${c(o.alpha)})`)),t={name:a.name,value:d.text,color:e,font:{postScriptName:d.font.postScriptName,size:d.font.size,fauxBold:d.font.fauxBold,fauxItalic:d.font.fauxItalic}};break}}return e&&(a.contentPermissions&&a.contentPermissions.imagePermissions&&(t.contentPermissions={imagePermissions:{allowChangeImage:a.contentPermissions.imagePermissions.allowChangeImage,allowEditImage:a.contentPermissions.imagePermissions.allowEditImage}}),a.placeholderPermissions)&&(t.placeholderPermissions={allowEditContent:a.placeholderPermissions.allowEditContent,showHandleButton:a.placeholderPermissions.showHandleButton,showSelectButton:a.placeholderPermissions.showSelectButton}),a.visualizationPermissions&&(t.visualizationPermissions={noPrint:a.visualizationPermissions.noPrint,noShow:a.visualizationPermissions.noShow}),null!==a.locked&&(t.locked=a.locked),s&&(a.type!==_.b.type?(i=window.CustomersCanvas.DesignAtoms.ObjectModel.ColorFactory.createColor(a.fillColor),t.fillColor=i,t.fillColorHex=await this.colorToHex(i)):(e=window.CustomersCanvas.DesignAtoms.ObjectModel.ColorFactory.createColor(a.contentFillColor),t.fillColor=e,t.fillColorHex=await this.colorToHex(e))),new U(t)}}async colorToHex(e){var t,a;return!e||m.a.isNullOrUndefined(e.colorSpace)?null:(e=e.getData(),t=(e=await(await this.getEditor()).eval(async function(e){return(await spEditor.model._viewer.colorPreviewService.getPreviewAsync(e)).getData()},e)).r.toString(16),a=e.g.toString(16),e=e.b.toString(16),"#"+(1===t.length?"0"+t:t)+(1===a.length?"0"+a:a)+(1===e.length?"0"+e:e))}}class D{constructor(e){this.widget=e}}class L extends D{async execute(e){if(e.surfaceToDuplicateId||0<(null==(i=e.surfacesToChangeIds)?void 0:i.length)){var t,a,i=await this.widget.getProduct(),s=await i.getProductModel(),r=s.surfaces.get(e.surfaceToDuplicateId);if(r){for(var n of e.surfacesToChangeIds)n!==e.surfaceToDuplicateId&&((t=s.surfaces.get(n))?(t=t.name,(a=r.clone(!0)).name=t,s.surfaces.replaceAt(a,n)):console.warn("There is no surface with index "+n));i.setProductModel(s)}else console.error("There is no surface with index "+e.surfaceToDuplicateId)}}}class W extends D{async execute(e){e=(Array.isArray(e)?e:[e]).filter(e=>e);if(0!==e.length){this.widget.initDpApi();for(var t of e){var a=await this.widget.getProduct();if(!a.updateSurfaces)return void console.warn("Command unavailable for this version Customer's Canvas. Please, use version 6.2.0 or above.");if(1===a.updateSurfaces.length)if(t.definition&&t.definition.surfaces){var i=t.definition.surfaces,i=await Promise.all(i.map(async e=>{var t=e.designVariant,e=Object(n.c)(e,["designVariant"]),t=""!==(null==t?void 0:t.designResourceId)?await this.widget.createPrivateDesignFromResources(t.designResourceId):await this.widget.createPrivateDesignFromPublicDesign(t.designId);return Object.assign({stateId:t},e)})),{}=t,s=Object(n.c)(t,["definition"]),i=Object.assign({definition:{surfaces:i},updateSurfaceSize:!0,preserveUserChanges:!0,updateBehavior:"changeSurfaceLength"},s);await a.updateSurfaces(i)}else{s=t.designVariant,i=Object(n.c)(t,["designVariant"]);if(m.a.isNullOrUndefined(s))return;var r=""!==(null==s?void 0:s.designResourceId)?await this.widget.createPrivateDesignFromResources(s.designResourceId):await this.widget.createPrivateDesignFromPublicDesign(s.designId),r=Object.assign({definition:r,updateSurfaceSize:!0,preserveUserChanges:!0,updateBehavior:"changeSurfaceLength"},i);await a.updateSurfaces(r)}else await a.updateSurfaces(t.productDefinition||t.definition,t.options,t.sourceSurfaceIndexes,t.targetSurfaceIndexes)}}}}class G extends D{async execute(e){let a=await this.widget.getProduct();var t=e.data.map((e,t)=>({mockup:e.mockup,previewMockups:e.previewMockups,surface:a.surfaces[t]}));return a.setMockups(t,e.options)}}var M=t(407);class V extends D{async execute(e){var r,n=Array.isArray(e)?e:[e],e=await this.widget.getEditor(),o=await e.getProduct();for(r of n)if(!m.a.isEmptyString(r.url)){let e=r.surfaceIndex;(m.a.isNullOrUndefined(e)||e<0||e>o.surfaces.length)&&((e=1===n.length?o.currentSurfaceIndex:n.indexOf(r))<0||e>o.surfaces.length)&&(e=o.currentSurfaceIndex);var c=o.surfaces[e];let t=c.width/2,a=c.height/2,i=(r.size&&(r.size.width&&(t=r.size.width),r.size.height)&&(a=r.size.height),c.width/2-t/2),s=c.height/2-a/2;r.position&&(m.a.isNotNullOrUndefined(r.position.x)&&(i=r.position.x),m.a.isNotNullOrUndefined(r.position.y))&&(s=r.position.y);var l=new window.CustomersCanvas.DesignAtoms.ObjectModel.ImageItem(null,new M.PointF(i,s),t,a);l.name=r.name,await c.insertItem(l)}var t=n.reduce((e,t)=>(e[t.name]=t.url,e),{});await e.loadUserInfo(t)}}var E=t(891),H=t(37);class J extends D{async execute(e){await this.widget.iframeApiPromise,e.editorConfig=e.editorConfig||{},e.onCustomButtonClicked&&(this.widget.customButtonCb=e.onCustomButtonClicked),"function"==typeof e.OnBoundsNotificationCb&&(this.widget._boundsNotificationCb=e.OnBoundsNotificationCb),"string"==typeof e.productDefinition&&(e.editorConfig.autoLoadUserInfo=!1,e.editorConfig.userInfo=null,this.widget._stateId=e.productDefinition,this.widget._userId=this.widget.driver.user.id);var t=this.widget.driver.user.data,t=(t&&0<Object.keys(t).length&&(e.editorConfig.userInfo=m.a.DeepMerge(e.editorConfig.userInfo||{},t),e.editorConfig.autoLoadUserInfo=!0),e.editorConfig=e.editorConfig||{},e.editorConfig.themeConfiguration=e.editorConfig.themeConfiguration||{},this.widget.driver.themeSettings?(e.editorConfig.themeConfiguration.primaryColor=this.widget.driver.themeSettings.primaryColor,e.editorConfig.themeConfiguration.logo=this.widget.driver.themeSettings.logo):(this.widget.auWizard.config.icons&&this.widget.auWizard.config.icons.preloader&&(e.editorConfig.themeConfiguration.logo=this.widget.auWizard.config.icons.preloader),e.editorConfig.themeConfiguration.primaryColor=getComputedStyle(document.documentElement).getPropertyValue("--theme-primary-color")),null==(t=null==(t=this.widget.driver)?void 0:t.localization)?void 0:t.find(e=>"design-editor"===e.app));let a={};var i=this.widget.language.slice(0,2);if(t){if(m.a.isNotNullOrUndefined(t.url)&&!m.a.isEmptyString(t.url)&&"string"==typeof t.url)try{a=await m.a.loadJson(t.url+"?ts="+Date.now())}catch(e){console.error(e)}else m.a.isNotNullOrUndefined(t.data)&&"object"==typeof t.data&&0!==Object.keys(t.data).length&&(a=-1!==Object.keys(t.data).indexOf(i)?m.a.DeepMerge(a,t.data):m.a.DeepMerge(a,{[i]:t.data}));e.editorConfig.translations=a}i=e.maximizeAssetManager||e.galleryObserverEnable||this.widget.driver.config.displayInPopup;if(null!=(t=null==(t=null==e?void 0:e.editorConfig)?void 0:t.preloader)&&t.enabled||(e.editorConfig.preloader={enabled:!1}),await this.load(e.productDefinition,e.editorConfig,i,e.initSurfaceIndex),await this.widget.getViolationData(),e.onInit){t=m.a.functionWrapperConstructor(e.onInit);try{await t()}catch(e){}}return H.Maybe.maybe(e).map(e=>e.viewerSettings).caseOf({just:e=>this.widget.applyViewerSettings(e),nothing:()=>this.widget.customersCanvasPromise})}async load(e,t,a,i){var s=this,r=(e.surfaces&&Array.isArray(e.surfaces)&&e.surfaces.forEach(function(e){"object"==typeof e&&void 0!==e.width&&void 0!==e.height&&(e.width=Number(e.width),e.height=Number(e.height))}),s.widget.modifiedItem&&s.widget.updateModifiedItem({}),this.widget.shadowRoot.querySelector("#design-editor"));let n=await CustomersCanvas.IframeApi.loadEditor(r,e,t),o;try{o=await(o=await n.getProduct()).switchTo(o.surfaces[0])}catch(e){return console.error("Load failed with exception: ",e),void s.widget.dispatchEvent(new CustomEvent("error",e))}if(m.a.isNotNullOrUndefined(i)){let e=Number(i);(Number.isNaN(e)||e<0||e>o.surfaces.length)&&(e=0),await o.switchTo(o.surfaces[e])}s.widget.customersCanvasPublish(n),s.widget.dispatchEvent(new CustomEvent("ready",{detail:{product:o,customersCanvas:n}})),await this.widget.replaceInterpolationPlaceholder();let c=[],l=(a,i,s=!1,r=!1)=>{c.push(a),n.subscribe(a,async(...e)=>{s&&await this.widget.getViolationData(),i&&await i(...e);var t=(null==(t=this.widget.params)?void 0:t.initial)&&(this.widget.params.initial["on"+a]||(null==(t=this.widget.params)?void 0:t.initial[a]));t&&await m.a.functionWrapperConstructor(t).apply(window,e),r&&this.widget.emitChange()})};a&&(l(E.a.ModalClose,async()=>this.widget.toggleMaximizeMainPanel(!1)),l(E.a.ModalOpen,async()=>this.widget.toggleMaximizeMainPanel(!0)),l(E.a.AssetManagerClosed,async()=>this.widget.toggleMaximizeMainPanel(!1)),l(E.a.AssetManagerOpened,async()=>this.widget.toggleMaximizeMainPanel(!0))),l(E.a.OriginalSize,async()=>this.widget.toggleMaximizeMainPanel(!1)),l(E.a.FullWindow,async()=>this.widget.toggleMaximizeMainPanel(!0)),l(E.a.BoundsNotification,e=>{this.widget.selectedGroupBoundsData=e,this.widget._boundsNotificationCb&&this.widget._boundsNotificationCb(e)}),l(E.a.OnImageDpiChanged,null,!0),l(E.a.OnSurfaceChanged,async()=>this.widget.updateCurrentSurfaceData()),l(E.a.ItemAdded,null,!0),l(E.a.ItemRemoved,null,!0),l(E.a.ItemChanged,async(...e)=>{e=e[0];if(!m.a.isNullOrUndefined(e))try{var t=await this.widget.getDesignEditorItemModel(e);this.widget.updateModifiedItem(t)}catch(e){console.warn("Failed to transform item model")}},!0),l(E.a.RevertProduct,null,!0,!0),l(E.a.UndoProduct,null,!0),l(E.a.RedoProduct,null,!0),l(E.a.CustomButtonClicked,async e=>this.widget.customButtonCb(e[0],e[1])),Object.keys(E.a).forEach(e=>{-1===c.indexOf(e)&&l(e,null)})}}class $ extends D{async execute(e,t){if(m.a.isEmptyObject(e))return Promise.resolve();if(m.a.isEmptyObject(e.data))return Promise.resolve();var a=await this.widget.getEditor();try{await a.loadUserInfo(e.data,e.options)}catch(e){console.warn(e)}}}var k=t(471);class X extends D{async execute(e,t){if(m.a.isEmptyObject(e)||m.a.isEmptyObject(e.every)&&m.a.isEmptyObject(e.items))return Promise.resolve();e.items=e.items||{},m.a.isNotNullOrUndefined(t)&&(e=this._removeOldParams(e,t));var t=await this.widget.getEditor(),a=await t.getProduct();await this._modifyItems(e,a,t),await this._applyUserInfo(t,e)}async _modifyItems(e,t,a){if(!m.a.isNullOrUndefined(e)){m.a.isNotNullOrUndefined(e.items)&&await this._applyBackgroundColor(e,t);var i,s=await t.getProductModel();for(i of s.getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!1})){var r=Object.assign(Object.assign({},e.every),e.items[i.name]);0!==Object.keys(r).length&&this.needApplyOnce(r,i)&&(this._isTextItem(i.type)?this._updateTextItem(r,i):i.type===v.cb.type?await this._updatePlaceholderItem(r,i,a):this._isShapeItem(i)&&await this._updateShapeItem(r,i),this._updateVisualizationPermissions(r,i),this.setApplyOnce(r,i))}var n=0<t.currentSurfaceIndex?t.currentSurfaceIndex:0;await t.setProductModel(s),await(t=await a.getProduct()).switchTo(t.surfaces[n])}}needApplyOnce(e,t){return!(!0===e.once&&t&&t.tags.modifyItems&&!0===t.tags.modifyItems.once)}setApplyOnce(e,t){!0===e.once&&t&&(t.tags.modifyItems=t.tags.modifyItems||{},t.tags.modifyItems.once=!0)}_isTextItem(e){return e===v.o.type||e===v.q.type||e===v.eb.type||e===v.x.type||e===v.g.type}_removeOldParams(e,t){for(var a in e.items){var i=t.items[a],s=e.items[a];JSON.stringify(i)===JSON.stringify(s)&&!0!==s.force&&delete e.items[a]}return e}async _applyBackgroundColor(e,t){e=e.items.background||e.items.Background;if(null!=e&&null!=e.color){var a=window.CustomersCanvas.DesignAtoms.ObjectModel.ColorFactory.createColor(e.color);if(null!==a)for(var i of t.surfaces)await i.changeBackground(a)}}_updateTextItem(t,a){let i=t.text||t.value;if(null!=i&&(a.text=i,a.placeholders)&&0<a.placeholders.length&&(a.placeholders.forEach(e=>e.value=i),a.value=i),null!=t.font&&((o=t.font.bold||t.font.fauxBold)&&(a.font.fauxBold=o),(o=t.font.italic||t.font.fauxItalic)&&(a.font.fauxItalic=o),(o=t.font.family||t.font.postScriptName)&&(a.font.postScriptName=o),t.font.size&&(a.font.size=t.font.size),t.font.underline&&(a.underline=t.font.underline),o=t.color||t.font.color)&&(a.color=window.CustomersCanvas.DesignAtoms.ObjectModel.ColorFactory.createColor(o)),!0===t.locked&&(a.textPermissions.allowChangeText=!1,a.textPermissions.allowChangeTextBIU=!1),a.type===v.eb.type){let e=t.position||t.location;e&&(n=o=0,a.alignment=v.qb.Left,o=(e=e||{x:0,y:0}).x||a.baselineLocation.x,n=e.y||a.baselineLocation.y,a.baselineLocation=new window.CustomersCanvas.DesignAtoms.ObjectModel.PointF(o,n))}if(a.type===v.q.type||a.type===v.g.type){var s,r,n,o=a;let e=t.position||t.location;(e||t.size)&&(r=s=a=n=0,n=(e=e||{x:0,y:0}).x||o.textRectangle.left,a=e.y||o.textRectangle.top,t.size||(t.size={width:0,height:0}),s=t.size.width||o.textRectangle.width,r=t.size.height||o.textRectangle.height,o.textRectangle.width=s,o.textRectangle.height=r,o.textRectangle.left=n,o.textRectangle.top=a)}}_updateVisualizationPermissions(e,t){e.visualizationPermissions&&(m.a.isNotNullOrUndefined(e.visualizationPermissions.noPrint)&&(t.visualizationPermissions.noPrint=e.visualizationPermissions.noPrint),m.a.isNotNullOrUndefined(e.visualizationPermissions.noShow))&&(t.visualizationPermissions.noShow=e.visualizationPermissions.noShow),m.a.isNotNullOrUndefined(e.locked)&&(t.locked=e.locked)}async _updatePlaceholderItem(e,t,a){if("ImagePlaceholder"===e.type){if((i=e).placeholderContent&&i.tags&&i.tags.sourceData&&i.value===i.tags.sourceData.name){-1===e.placeholderContent.originalUrl.indexOf("?x-cctoken=")&&""!==(i=await this.widget.getToken())&&(e.placeholderContent.originalUrl+="?x-cctoken="+i);var i=e.placeholderContent.originalUrl,a=(e.tags.sourceData.originalUrl=i,await a.configuration.getImageMetadata(i)),i=t.content;if(t.isStubContent=!1,i.setData)try{i.setData(a)}catch(e){k.a.setDataToImage(a,i)}else k.a.setDataToImage(a,i);i.tags=e.tags;var a=new O.a(i.parentPlaceholder=t),i=new x.b(i),s=(i.updateRectangle(!1,t.contentResizeMode,a),a.getTransformedRectangle()),r=e.placeholderContent,a=((s.angle!==r.placeholderRectangle.angle||s.width!==r.placeholderRectangle.width||s.height!==r.placeholderRectangle.height||s.centerX!==r.placeholderRectangle.centerX||s.centerY!==r.placeholderRectangle.centerY)&&(s=new window.CustomersCanvas.DesignAtoms.ObjectModel.RotatedRectangleF(r.placeholderRectangle.centerX,r.placeholderRectangle.centerY,r.placeholderRectangle.width,r.placeholderRectangle.height,r.placeholderRectangle.angle),a.setTransformedRectangle(s)),i.getTransformedRectangle());(a.angle!==r.contentRectangle.angle||a.width!==r.contentRectangle.width||a.height!==r.contentRectangle.height||a.centerX!==r.contentRectangle.centerX||a.centerY!==r.contentRectangle.centerY)&&(s=new window.CustomersCanvas.DesignAtoms.ObjectModel.RotatedRectangleF(r.contentRectangle.centerX,r.contentRectangle.centerY,r.contentRectangle.width,r.contentRectangle.height,r.contentRectangle.angle),i.setTransformedRectangle(s))}else if(!t.isStubContent){a=t.content;if(a.parentPlaceholder=t,a.setData)try{a.setData(t.stubStorageMeta)}catch(e){k.a.setDataToImage(t.stubStorageMeta,a)}else k.a.setDataToImage(t.stubStorageMeta,a);r=new O.a(t),i=new x.b(a);i.parentPlaceholder=r,i.updateRectangle(!1,t.contentResizeMode,r),t.isStubContent=!0}e.contentPermissions&&e.contentPermissions.imagePermissions&&(t.contentPermissions.imagePermissions.allowChangeImage=e.contentPermissions.imagePermissions.allowChangeImage,t.contentPermissions.imagePermissions.allowEditImage=e.contentPermissions.imagePermissions.allowEditImage),e.placeholderPermissions&&(t.placeholderPermissions.allowEditContent=e.placeholderPermissions.allowEditContent,t.placeholderPermissions.showHandleButton=e.placeholderPermissions.showHandleButton,t.placeholderPermissions.showSelectButton=e.placeholderPermissions.showSelectButton)}"BarcodePlaceholder"!==e.type||e.value||t.isStubContent||(t.content.applyBarcodeData(new window.CustomersCanvas.DesignAtoms.ObjectModel.BarcodeData("")),t.isStubContent=!0)}async _updateShapeItem(e,t){var a,i,s,r=e.color||e.fillColor;r&&(t.type!=v.cb.type?t.fillColor=window.CustomersCanvas.DesignAtoms.ObjectModel.ColorFactory.createColor(r):t.contentFillColor=window.CustomersCanvas.DesignAtoms.ObjectModel.ColorFactory.createColor(r));let n=e.position||e.location;(n||e.size)&&(i=a=s=r=0,r=(n=n||{x:0,y:0}).x||t.sourceRectangle.left,s=n.y||t.sourceRectangle.top,e.size||(e.size={width:0,height:0}),a=e.size.width||t.sourceRectangle.width,i=e.size.height||t.sourceRectangle.height,t.type!=v.A.type?t.sourcePath=window.CustomersCanvas.DesignAtoms.ObjectModel.Path.rectangle(r,s,a,i):t.sourcePath=window.CustomersCanvas.DesignAtoms.ObjectModel.Path.ellipse(r,s,a,i))}async _applyUserInfo(e,a){var i,s=(await(await e.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0}),r={};for(let t of Object.keys(a.items)){var n=a.items[t],o=s.find(e=>e.name===t);!this.needApplyOnce(n,o)||!n.value&&"Text"!==n.type&&"InString"!==n.type&&!n.image||"ImagePlaceholder"===n.type&&!!(i=n).placeholderContent&&i.tags&&i.tags.sourceData&&i.value===i.tags.sourceData.name||("BarcodePlaceholder"===n.type?n.barcodeSubType&&"None"!==n.barcodeSubType?"Url"===n.barcodeSubType?r[t]={BarcodeFormat:n.barcodeFormat,BarcodeSubType:n.barcodeSubType,Url:n.value}:"Phone"===n.barcodeSubType&&(r[t]={barcodeFormat:n.barcodeFormat,barcodeSubType:n.barcodeSubType,phone:n.value}):r[t]={barcodeFormat:n.barcodeFormat,barcodeValue:n.value}:r[t]=m.a.isNotNullOrUndefined(n.value)?n.value:n.image,this.setApplyOnce(n,o))}if(m.a.isEmptyObject(r))return Promise.resolve();try{await e.loadUserInfo(r)}catch(e){this.widget.showToast("Error: Invalid data"),console.log(e)}}_isShapeItem(e){return[v.gb.type,v.kb.type,v.A.type,v.cb.type].includes(e.type)}}var j=t(489);class Y extends D{async execute(e){if(e&&e.resizeParams&&0!==e.resizeParams.height&&0!==e.resizeParams.width){var a=await this.widget.getEditor();let t=e.resizeParams;if(t.targets&&0<t.targets.length&&"string"==typeof t.targets[0]){var i=(await(await(await a.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0})).filter(e=>t.targets.includes(e.name)).map(e=>e.id),s=e.resizeParams;s.targetIds=i,await a.commandManager.execute(j.b.resize,s)}else{if("product"!==e.resizeParams.targetType&&(e.resizeParams.targetIds||0===e.resizeParams.targetIds.length))return;if(null==e.resizeParams.target&&"product"!==e.resizeParams.targetType)return;await a.commandManager.execute(j.b.resize,e.resizeParams)}try{await a.eval("spEditor._canvasViewer._onResize()")}catch(e){}await this.widget.ready()}}}class q extends D{async execute(e){var a,i=Array.isArray(e)?e:[e],s=await this.widget.getEditor(),r=await s.getProduct();for(a of i)if(a.url){var n=await r.getProductModel();let t=a.surfaceIndex;(null==t||t<0||t>r.surfaces.length)&&(t=1===i.length?r.currentSurfaceIndex:i.indexOf(a));var o=n.surfaces.get(t);if(!m.a.isNullOrUndefined(o)){var c=o.printAreas.get(0),l=o.containers.first(e=>e.name===g.a.BG_CONTAINER_NAME);let e=l.items.get(0);m.a.isNullOrUndefined(e)&&((e=new window.CustomersCanvas.DesignAtoms.ObjectModel.PlaceholderItem).locked=!0,l.items.add(e)),m.a.isNullOrUndefined(e.content)&&(e.content=new window.CustomersCanvas.DesignAtoms.ObjectModel.ImageItem);var d=e.content,u=await s.configuration.getImageMetadata(a.url);if(u.isVector=this._isVector(a.url),!0===a.toTile){var h=e.content||e;if(h.sourceRectangle.width=u.size.width,h.sourceRectangle.height=u.size.height,h.setData)try{h.setData(u)}catch(e){k.a.setDataToImage(u,h)}else k.a.setDataToImage(u,h);h.source.isVector=u.isVector,l.items.setRange(this._getTiles(h,o)),await r.setProductModel(n)}else r.surfaces.length>t&&await r.surfaces[t].changeBackground(u);a.url.startsWith("public:")||a.url.startsWith("user:")||!a.autoResize||((l=new window.CustomersCanvas.DesignAtoms.ObjectModel.ImageItem.ImageSource).url=a.url,l.isVector=this._isVector(a.url),d.source=l,o.width=d.sourceRectangle.width,o.height=d.sourceRectangle.height,c.bounds.width=o.width,c.bounds.height=o.height,await r.setProductModel(n))}}await this.widget.ready()}_getTiles(e,t){var a=[];let i=0,s=0;for(;s<t.height;){for(;i<t.width;){var r=e.clone();r.values=[],r.transform.setTranslateX(i),r.transform.setTranslateY(s),r.locked=!0,a.push(r),i+=e.source.width}i=0,s+=e.source.height}return a}_isVector(e){return e.endsWith(".pdf")||e.endsWith(".svg")}}class K extends D{async execute(t){let a=await this.widget.getProduct();Array.isArray(t)||(t=[t]);for(let e=0;e<t.length;e++){var i=t[e];if(i.data){let e=a.currentSurface;"number"==typeof i.surfaceIndex&&(e=a.surfaces[i.surfaceIndex]),a=await e.setPrintAreas([i.data],i.options),await this.widget.replaceInterpolationPlaceholder()}}}}class Z extends D{async execute(e){if(null==e)return Promise.resolve();var t=await this.widget.getEditor();let a=await t.getProduct();var i,s=await a.getProductModel();for(i of e)if(!m.a.isNullOrUndefined(i.url)&&""!==i.url){var r="number"==typeof i.surfaceIndex?s.surfaces.get(i.surfaceIndex):s.surfaces.first(e=>e.name===a.currentSurface.name),r="up"===i.mockup.toLowerCase()?r.mockup.overContainers:r.mockup.underContainers;if(r.empty)console.warn("Cannot set mockup because MockupContainer is empty");else{var r=r.get(0),n=(r.items.clear(),new window.CustomersCanvas.DesignAtoms.ObjectModel.ImageItem),o=await t.configuration.getImageMetadata(i.url);if(o.size={width:o.size.width||o.width,height:o.size.height||o.height},n.setData)try{n.setData(o)}catch(e){k.a.setDataToImage(o,n)}else k.a.setDataToImage(o,n);n.ratioWidthToHeight=r.size.width/r.size.height,n.SetWidth(r.size.width,!1),n.SetHeight(r.size.height,!1),r.items.add(n)}}await a.setProductModel(s)}}var Q=t(890);class ee extends D{constructor(){super(...arguments),this._serializer=new Q.a}async execute(e){if(Object(r.l)(e.serializedProduct))throw"serializedProduct cannot be null or empty";e=this._serializer.deserialize(e.serializedProduct);await(await this.widget.getProduct()).setProductModel(e)}}class te extends D{async execute(e){e&&e.surfaces&&0!==e.surfaces.length&&(e.surfaces.some(e=>0===Object.keys(e).length)||(await(await(await this.widget.getEditor()).getProduct()).setSurfaces(e.surfaces),await this.widget.replaceInterpolationPlaceholder()))}}class ae extends D{async execute(e){return"string"!=typeof e&&void 0!==e.theme||(e={theme:e}),(await this.widget.getProduct()).applyProductTheme(e.theme)}}class ie extends D{async execute(e){var t,a;e&&(t=await this.widget.getEditor(),a=Object.assign({},e),null!=e.scrollPosition&&(a.scrollingPosition={x:e.scrollPosition.X||e.scrollPosition.x,y:e.scrollPosition.Y||e.scrollPosition.y}),await t.setViewerSettings(a))}}class se extends D{async execute(e){e=m.a.ensureArray(e).filter(e=>e);if(0!==e.length)for(var t of e){var a=await this.widget.getProduct();if(!a.swapSurfaces)return void console.warn("Command unavailable for this version Customer's Canvas.");var i=a.surfaces[t.lhsSurfaceIndex],t=a.surfaces[t.rhsSurfaceIndex];await a.swapSurfaces(i,t)}}}class re extends D{async execute(e){if(e&&e.translateParams){var a=e.translateParams,a=a.itemIds&&0<a.itemIds.length,i=e.translateParams,i=i.items&&0===i.items.length&&"string"!=typeof i.items[0];let t=e.translateParams;var s=t.items&&0<t.items.length&&"string"==typeof t.items[0];(a||i||s)&&(a=await this.widget.getEditor(),s?(i={itemIds:(await(await(await a.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0})).filter(e=>t.items.includes(e.name)).map(e=>e.id),translateX:t.translateX,translateY:t.translateY},await a.commandManager.execute(j.a.translateItems,i)):await a.commandManager.execute(j.a.translateItems,e.translateParams),await this.widget.ready())}}}class ne extends D{async execute(e,t){if(null!=e&&e instanceof Array){var a,i,s=await this.widget.getProduct();for([a,i]of e.entries()){var r=s.surfaces[a];if(null!=r)for(var[n,o]of Object.entries(i)){n=r.printAreas[0].getContainer(n);null!=n&&await n.update(o)}}}}}var A=t(25),oe=t(14);class R{static throw(e,...t){throw e+": "+t.join(", ")}}R.InvalidProcessorExpression="Invalid expression",R.CannotFoundType="Cannot found type",R.CannotFoundTypeConstructor="Cannot found constructor of type",R.CannotFoundStaticMethod="Cannot found static method",R.CannotFoundEnum="Cannot found enumeration",R.InvalidEnumValue="Enum does not contain value",R.DublicateTypesFound="Dublicate types have been detected",R.CommandNotFound="Command not found";var ce=t(94),le=t(425),de=t(444);class ue{constructor(){this._types=new Map;var t=[de,M,w];for(let e=0;e<t.length;e++)this._loadModuleTypes(t[e]);this._loadModuleTypes({Collection:le.a})}fromConstructor(e,...t){Object(r.l)(e)&&R.throw("Invalid argument",e);var a=this._findFunction(e),e=(this._isConstructor(a)||R.throw(R.CannotFoundTypeConstructor,e),a);try{return new e(...t)}catch(e){throw console.error(e),e}}_findFunction(t){var a=t.split(".");this._types.has(a[0])||R.throw(R.CannotFoundType,t);let i=this._types.get(a[0]);for(let e=1;e<a.length;e++)null==i[a[e]]&&R.throw(R.CannotFoundTypeConstructor,t),i=i[a[e]];return i}_isConstructor(e){return e instanceof Function&&null!=e.prototype.constructor}fromStaticMethod(e,...t){var a=this._findFunction(e);null!=a&&a instanceof Function||R.throw(R.CannotFoundStaticMethod,e);try{return a(...t)}catch(e){throw console.error(e),e}}fromProperties(e,t){e=this.fromConstructor(e);return Object(r.e)(e,[t],{deep:!1,ignoreNull:!1})}fromEnum(e,t){this._types.has(e)||R.throw(R.CannotFoundEnum,e);var a=this._types.get(e);return a instanceof Object||R.throw(R.CannotFoundEnum,e),null==a[t]&&R.throw(R.InvalidEnumValue,{type:e,value:t}),a[t]}_loadModuleTypes(e){if(void 0!==e)for(var[t,a]of Object.entries(e))(a instanceof Function||a instanceof Object)&&(this._types.has(t)&&R.throw(R.DublicateTypesFound,t),this._types.set(t,a))}}class he extends oe.a{subProcessorAllocatorFactory(){var e=new ce.a;return e.register(new ge(this,new ue)),e}}class ge extends A.a{constructor(e,t){super(e),this._builder=t}apply(e,t,a=e=>e){switch(!0){case Array.isArray(e):return e.map(e=>a(e));case this.isObject(e):var i,s,r={};for([i,s]of Object.entries(e)){if(this._isNewExpression(i)||this._isCallExpression(i))return this._buildObjectModel(i,s,a);r[i]=this._buildModelProperty(s,a)}return r;case this._isEnumExpression(e):return this._parseEnum(e);default:return e}}_buildModelProperty(e,t){switch(!0){case this.isObject(e):return t(e);case this._isEnumExpression(e):return this._parseEnum(e);default:return e}}_parseArguments(e,t){switch(!0){case Array.isArray(e):return e.map(e=>this._parseArguments(e,t));case this.isObject(e)&&this.canApply(e):return t(e);case this._isEnumExpression(e):return this._parseEnum(e);default:return e}}_parseEnum(e){var t=this.splitOperandAndCondition(e),e=(1===t.length&&null!=t[0].body||R.throw(R.InvalidProcessorExpression,e),t[0].body.split("."));return 2==e.length?this._builder.fromEnum(e[0],e[1]):null}_buildObjectModel(e,t,a){var i=this.splitOperandAndCondition(e),i=(1==i.length&&null!=i[0].body||R.throw(R.InvalidProcessorExpression,e),i[0].body);return this._isCallExpression(e)?this._buildObjectByFactory(i,t,a):this._createObjectModel(i,t,a)}_buildObjectByFactory(e,t,a){let i=t;return Array.isArray(t)?i=t.map(e=>this._parseArguments(e,a)):this.isObject(t)&&(i=a(t)),this._builder.fromStaticMethod(e,i)}_createObjectModel(e,t,a){switch(!0){case this.isObject(t):return this._builder.fromProperties(e,a(t));case Array.isArray(t):var i=t.map(e=>this._parseArguments(e,a));return this._builder.fromConstructor(e,...i);default:return this._builder.fromConstructor(e,t)}}canApply(e){return this.isObject(e)&&void 0!==Object.entries(e).find(([e,t])=>this._isNewExpression(e)||this._isCallExpression(e)||this._isEnumExpression(t))}_isNewExpression(e){return/{{.*(#new).*/gi.test(e)}_isCallExpression(e){return/{{.*(#call).*/gi.test(e)}_isEnumExpression(e){return this.isString(e)&&/{{.*(#enum).*/gi.test(e)}}class me extends D{constructor(){super(...arguments),this._configProcessor=new he}async execute(e){var t,a=this._configProcessor.process(e,{}),e=await this.widget.getProduct(),i=await e.getProductModel();for(t of await i.getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0})){var s=a.items[t.name];m.a.isNullOrUndefined(s)||Object(r.f)(t,s)}await e.setProductModel(i)}}class fe extends D{async execute(e){e=(Array.isArray(e)?e:[e]).filter(e=>e);if(0!==e.length)for(var t of e){var a=await this.widget.getProduct();if(!a.updateSurfaces)return void console.warn("Command unavailable for this version Customer's Canvas. Please, use version 6.2.0 or above.");1===a.updateSurfaces.length?await a.updateSurfaces(t):await a.updateSurfaces(t.productDefinition||t.definition,t.options,t.sourceSurfaceIndexes,t.targetSurfaceIndexes)}}}let pe=t(865),N=class extends B{constructor(){super(...arguments),this._isRestoring=!1,this.isRestored=!1,this.modifiedItem=null,this._currentSurfaceName="",this._currentSurfaceIndex=0,this._surfaceCount=0,this.overallBounds={},this.itemsOnSurfacesCount=[],this._hiResUrls=[],this._proofImageUrls=[[]],this._proofPdfUrls=[],this._stateId="",this._userId="",this._privateDesignId="",this._userChanges={},this._variableData=[],this._allItems=[],this._depositPhotos=[],this._artLinkItems=[],this._tags={},this._identifyingString="",this._lastParams={},this._currentParams={},this._violationData=[],this.actionsFinished=!1,this.actionsFinishedPromise=new p,this.commands={initial:new J(this),changeMockup:new G(this),setPrintArea:new K(this),setTheme:new ae(this),setBackground:new q(this),updateContainerSettings:new ne(this),setRemoteMockup:new Z(this),modifyItems:new X(this),setViewerSettings:new ie(this),updateItems:new me(this),setSerializedProduct:new ee(this),setSurfaces:new te(this),swapSurfaces:new se(this),resize:new Y(this),translate:new re(this),updateSurfaces:new fe(this),createImageItem:new V(this),loadUserInfo:new $(this),changeDesignVariant:new W(this),duplicateSurfaces:new L(this)},this.itemsData={},this._token=""}get violationWarningData(){return this._violationWarningData}get violationData(){return this._violationData}get boundsData(){return this._boundsData}get currentSurfaceName(){return this._currentSurfaceName}get currentSurfaceIndex(){return this._currentSurfaceIndex}get surfaceCount(){return this._surfaceCount}get proofImageUrls(){return this._proofImageUrls}get proofPdfUrls(){return this._proofPdfUrls}get hiResUrls(){return this._hiResUrls}get stateId(){return this._stateId}get userChanges(){return this._userChanges}get userId(){return this._userId}get allItems(){return this._allItems}get variableData(){return this._variableData}get depositPhotos(){return this._depositPhotos}get artLinkItems(){return this._artLinkItems}get sourcedItems(){return this._sourcedItems}get tags(){return this._tags}get identifyingString(){return this._identifyingString}get finishProductDesignResult(){return this._finishProductDesignResult}set stateId(e){this._stateId=e}async calculateIdentifyingString(e){var t=await(await(await this.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0}),e=new i.a({titleTemplate:e});t=t.reduce((e,t)=>{t=(e=>{let t,a,i="";switch(!0){case e instanceof CustomersCanvas.DesignAtoms.ObjectModel.BaseTextItem:i=Object(r.k)(e.text);break;case e instanceof CustomersCanvas.DesignAtoms.ObjectModel.BarcodeItem:i=e.barcodeContent;break;case e instanceof CustomersCanvas.DesignAtoms.ObjectModel.ImageItem:i=null!=(t=e.displayName)?t:e.name;break;case e instanceof CustomersCanvas.DesignAtoms.ObjectModel.PlaceholderItem:e.imageContent&&(i=null!=(a=e.imageContent.displayName)?a:e.imageContent.name)}return{name:e.name,value:i}})(t);return e[t.name]=t.value,e},{}),e=e.buildTitle(t);return this._identifyingString=e,this.emitChange(),e}isInstanceOf(e,t){let a=e=>{let t=[];return(t=e.__proto__?t.concat(a(e.__proto__)):t).push(e.constructor.type),t.filter(e=>e)};return-1!==a(e).indexOf(t.type)}updateParams(e){var t;void 0!==e.initial&&(e.initial.editorConfig||(e.initial.editorConfig={}),e.initial.editorConfig.defaultLanguage=this.driver.config.language||"en",this.driver)&&(this._initialOrder=this._initialOrder||Object(u.a)(this.driver.orders[0]),(t=this.driver.user.id)&&(e.initial.editorConfig.userId=t),(t=this.driver.user.tokenId)&&(e.initial.editorConfig.tokenId=t),(t=(!!(t=this.auWizard.scopeInternal.widgetsData)&&!!t[this.name]?t[this.name]:this._initialOrder.data).stateId)&&""!==t&&!0!==this.auWizard.clearState&&(e.initial.productDefinition=t),e.initial.editorConfig.preloader={enabled:!1})}async exportWidgetData(e){return!0===e&&await this.finishProductDesign(),{stateId:this._stateId}}async restoreWidgetFromData(e,t=!1){var a;!0!==t||this.isRestored||((t=Object.assign({},(this.params||{}).initial||{})).productDefinition=e.stateId,e=null==(e=null==(e=this.driver)?void 0:e.user)?void 0:e.id,a=null==(a=null==(a=this.driver)?void 0:a.user)?void 0:a.tokenId,e&&a&&(null!=t&&t.initial?(t.editorConfig.userId=e,t.editorConfig.tokenId=a):t.editorConfig={userId:e,tokenId:a}),"firefox"===m.a.getBrowser()?this.commands.initial.execute(t):await this.commands.initial.execute(t))}async updateParamsAsync(a){await super.updateParamsAsync(a);let e=this._commandExecuter.getChangedActions(a,this._currentParams);if(0===e.length)return!1;-1!==e.indexOf("initial")&&(s=/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,i=m.a.isNotNullOrUndefined(this._stateId)&&""!==this._stateId,(s=m.a.isNotNullOrUndefined(a.initial.productDefinition)&&a.initial.productDefinition.toString().match(s))&&(this._isRestoring=!0),t=!0===a.initial.executeOnce,!i&&!s||t||(e=["initial"])),this.actionsFinishedPromise=new p,this.actionsFinished=!1,this._isRestoring||this.emitChange();var t,i=e.every(e=>{let t=a[e];return!1===(t=Array.isArray(a[e])?a[e][0]:t).showPreloader}),s=1===e.length&&-1!==e.indexOf("initial");i||this.showPreloader(!0,this.getPreloaderMessage(a,s)),this._currentParams=Object(u.a)(a);try{this._isRestoring&&!s||await this._commandExecuter.executeActions(a,e,this._lastParams)}catch(e){if(this.params.actionsErrorToast&&!0===this.params.actionsErrorToast.show){var r="widgets.canvas.actions.error";let e=this.localize(r);e===r&&(e="Something went wrong. Send the website support team information about your browser and steps to reproduce the problem."),this.showToast(e,this.params.actionsErrorToast.duration)}this.logger.error(()=>"Failed to perform an action on Design Editor. ",e)}finally{this.resetPreloaderState(),this._lastParams=a,this.actionsFinishedPromise.resolve(),this.actionsFinished=!0,this._isRestoring&&(this.getInitialParamsResolved(),this._isRestoring=!1,this.isRestored=!0),this.getSurfaceCount()}}connectedCallback(){super.connectedCallback(),this._commandExecuter=new s.a(this.commands,this.uniqWidgetName,()=>Promise.resolve(),this),this.baseUrl=m.a.ensureEndsWith(this.driver.settings.customersCanvasBaseUrl,"/"),this.showPreloader(!0),this.iframeApiPromise=f.a.loadCCScript(this.baseUrl,m.a.CC_SCRIPT_RELATIVE_PATH),this.iframeApiPromise.then(()=>{this.showPreloader(!1),CustomersCanvas.IframeApi.editorUrl=this.baseUrl})}async switchSurfaceTo(e){var t=await this.getProduct();return e<0||e>t.surfaces.length-1?(console.error("Invalid surface index: "+e),t):t.switchTo(t.surfaces[e])}async removeSurface(e){var t,a=await this.getProduct();if(!(e<0||e>a.surfaces.length-1))return t=a.surfaces[e],a.removeSurface(t);console.error("Invalid surface index: "+e)}async addSurface(e,t){return(await this.getProduct()).addSurface(e,t)}async addSurfaces(e,t){return(await this.getProduct()).addSurfaces(e,t)}async updateSurfaces(e,t){let a=await this.getProduct();switch(e.toLowerCase()){case"remove":a=await this.removeSurface(t);break;case"add":a=await this.addSurface(t)}return a}async swapSurfaces(e,t){var a=await this.getProduct();if(a.swapSurfaces)return e=a.surfaces[e],t=a.surfaces[t],a.swapSurfaces(e,t);console.warn("Command unavailable for this version Customer's Canvas.")}updateModifiedItem(e){Object(c.a)(this.modifiedItem,e)||(this.modifiedItem=e,this.emitChange({modifiedItem:this.modifiedItem},!1))}updateOverallBounds(e){Object(c.a)(this.overallBounds,e)||(this.overallBounds=e,this.emitChange({overallBounds:this.overallBounds},!1))}async updateCurrentSurfaceData(){var e=await this.getProduct();this._currentSurfaceName=e.currentSurface.name,this._currentSurfaceIndex=e.surfaces.indexOf(e.currentSurface),this.emitChange()}async updateCurrentSurfaceName(){var e=await this.getProduct();this._currentSurfaceName=e.currentSurface.name,this.emitChange()}async updateCurrentSurfaceIndex(){var e=await this.getProduct();this._currentSurfaceIndex=e.surfaces.indexOf(e.currentSurface),this.emitChange()}async applyViewerSettings(e){return this.commands.setViewerSettings.execute(e)}async getProofImages(e=800,t=800,a=!0,i=!1,s=!1,r=1e3,n=1e3,o,c){var l=await this.getEditor();let d={};"object"==typeof a&&(o=a,a=!0);d="object"==typeof e?e:Object.assign({maxWidth:e,maxHeight:t,pregeneratePreviewImages:a,generateProductProof:i,generateLargePreviews:s,largePreviewMaxWidth:r,largePreviewMaxHeight:n},null!=c?c:{});e=await l.getProofImages(d,o),this._proofImageUrls=e.proofImageUrls,t=await l.getProduct();return this._surfaceCount=t.surfaces.length,this.emitChange({urls:this.proofImageUrls},!1),e.proofImageUrls.map(e=>e[0])}async getProofPdf(e,t={},a=!1){var t=Object.assign({},t,{generateProductProof:!0}),i=await this.getEditor(),t=(await i.getProofImages(t,e)).proofImageUrls.map(e=>e[0]),e=(this._proofPdfUrls=t.filter(e=>e.endsWith(".pdf")),await i.getProduct());return this._surfaceCount=e.surfaces.length,this.emitChange({proofPdfUrls:this.proofPdfUrls},a),this._proofPdfUrls}async getHiResImages(e=800,t=800,a,i=!1,s,r,n){var o=await this.getEditor(),n=(null!==s&&""!==s||(s=void 0),"object"==typeof(a=null!==a&&""!==a?a:void 0)&&(r=a,a=void 0),null!=n?n:{}),a=await o.finishProductDesign(Object.assign({stateId:a,proofMaxWidth:e,proofMaxHeight:t,pregeneratePreviewImages:i,fileName:s},n),r),e=(this._stateId=a.stateId,this._userId=a.userId,this._hiResUrls=a.hiResOutputUrls,this._proofImageUrls=a.proofImageUrls,this._userChanges=a.userChanges,this._violationWarningData=a.violationWarningData,this._boundsData=a.boundsData,await o.getProduct());return this._surfaceCount=e.surfaces.length,this.emitChange({urls:this.hiResUrls,proofs:this.proofImageUrls,stateId:this.stateId,userId:this.userId,userChanges:this.userChanges,violationWarningData:this.violationWarningData,boundsData:this.boundsData},!0),a.hiResOutputUrls}async finishProductDesign(e,t){var a=await this.getEditor(),e=await a.finishProductDesign(e,t),t=(this._finishProductDesignResult=e,this._stateId=e.stateId,this._userId=e.userId,this._hiResUrls=e.hiResOutputUrls,this._proofImageUrls=e.proofImageUrls,this._userChanges=e.userChanges,this._violationWarningData=e.violationWarningData,this._boundsData=e.boundsData,await a.getProduct());return this._surfaceCount=t.surfaces.length,this.emitChange(),e}async getVariableData(){var e=await this.getProduct();return this._variableData=(await e.getVariableItems()).reverse(),this.emitChange({data:this.variableData}),this.variableData}async getAllItems(){var e=await(await this.getProduct()).getProductModel();return this._allItems=e.getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0}).reverse(),this.emitChange(),this.allItems}async getDepositPhotos(){var e=await(await(await this.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0});return this.getDPItems(e),this._depositPhotos}getDPItems(e){let s=[];return e.forEach(t=>{let e=t.tags.dp_data;if(Object(l.a)(e)){var a=e=>e&&e.tags&&null!==e.tags.sourceData&&"DepositPhotosSource"===e.tags.sourceType,i=e=>e.tags.sourceData;if(a(t)){let e=i(t);s.push({imageId:t.id,depositPhotosId:e.id})}else if(t.content&&a(t.content)){let e=i(t.content);s.push({imageId:t.id,depositPhotosId:e.id,data:e})}}else s.push({imageId:t.id,depositPhotosId:JSON.parse(e).id})}),this._depositPhotos=s.map(e=>({imageId:e.imageId,depositPhotosId:e.depositPhotosId})),this.emitChange({data:this.depositPhotos}),s}getArtLinkImages(e){let a=[];return e.forEach(e=>{var t=null!=e.content?e.content:e;null!=t.source&&null!=t.source.origin&&"ArtLinkSource"===t.source.origin.type&&(t=t.source.origin.data,a.push({imageId:e.id,artLinkId:t.id,data:t}))}),this._artLinkItems=a.map(e=>({imageId:e.imageId,artLinkId:e.artLinkId})),this.emitChange({data:this.artLinkItems}),a}async getArtLinkItems(){var e=await(await(await this.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0});return this.getArtLinkImages(e),this._artLinkItems}async getItemsBySource(e){let t=[];var a;return e?(a=await(await(await this.getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0}),"dp"==e.toLowerCase()||"depositphotos"==e.toLowerCase()?(this.getDPItems(a).forEach(e=>{t.push({imageId:e.imageId,sourceId:e.depositPhotosId,data:e.data})}),this._sourcedItems={source:e.toLowerCase(),items:t},this.emitChange({data:this.sourcedItems}),this.sourcedItems):"artlink"==e.toLowerCase()?(this.getArtLinkImages(a).forEach(e=>{t.push({imageId:e.imageId,sourceId:e.artLinkId,data:e.data})}),this._sourcedItems={source:e.toLowerCase(),items:t},this.emitChange({data:this.sourcedItems}),this.sourcedItems):{source:"unknown",items:t}):{source:"unknown",items:t}}async getTags(){var e=await this.getProduct();return this._tags=await e.getTags(),void 0===this._tags&&(this._tags={}),this.emitChange({tags:this.tags}),this.tags}async setTags(e){await(await this.getProduct()).setTags(e),this._tags=e,this.emitChange({tags:this.tags})}async saveProduct(e,t){var a=await this.getEditor(),e=await a.saveProduct(e,t),t=(this._stateId=e.stateId,this._userId=e.userId,await a.getProduct());return this._surfaceCount=t.surfaces.length,await this.emitChange({stateId:this.stateId,userId:this.userId},!1),e}async replaceInterpolationPlaceholder(){if(!this._currentParams.replaceInterpolationPlaceholders)return Promise.resolve();(await this.getEditor()).replaceInterpolationPlaceholders()}toggleMaximizeMainPanel(e){this.publishData({main:e},h.a.TOGGLE_SIZE_MAIN)}async openAssetManagerFor(e){await(await this.getEditor()).openGalleryForItem(e)}async openGalleryForBackground(){await(await this.getEditor()).openGalleryForBackground()}async getItemText(t){var e=(await(await(await this.getEditor()).getProduct()).getProductModel()).getAllItems({ignoreMockups:!0,flatGroupItems:!0,excludeGroupItems:!0}).find(e=>e.name===t),e=Object(r.k)(e&&e instanceof CustomersCanvas.DesignAtoms.ObjectModel.BaseTextItem?e.text:"");return this.itemsData[t]=this.itemsData[t]||{},this.itemsData[t].text=e,this.emitChange(),e}get token(){return this._token}async getToken(){var e=await this.getEditor();let t="";try{t=await e.eval("spEditor.configuration.tokenId;")}catch(e){console.error("Failed to get user token")}return this._token=t,this.emitChange(),t}async getSurfaceCount(){var e=(await this.getProduct()).surfaces.l