@spiffcommerce/core 21.2.2-0 → 21.2.2-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -7
- package/dist/index.umd.cjs +7 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -784,7 +784,7 @@ const ae = F`
|
|
|
784
784
|
priceBreaks {
|
|
785
785
|
id
|
|
786
786
|
minQty
|
|
787
|
-
|
|
787
|
+
percentage
|
|
788
788
|
}
|
|
789
789
|
}
|
|
790
790
|
integrationProduct {
|
|
@@ -861,7 +861,7 @@ const ae = F`
|
|
|
861
861
|
priceBreaks {
|
|
862
862
|
id
|
|
863
863
|
minQty
|
|
864
|
-
|
|
864
|
+
percentage
|
|
865
865
|
}
|
|
866
866
|
}
|
|
867
867
|
integrationProduct {
|
|
@@ -938,7 +938,7 @@ const ae = F`
|
|
|
938
938
|
priceBreaks {
|
|
939
939
|
id
|
|
940
940
|
minQty
|
|
941
|
-
|
|
941
|
+
percentage
|
|
942
942
|
}
|
|
943
943
|
}
|
|
944
944
|
integrationProduct {
|
|
@@ -1037,7 +1037,7 @@ const ae = F`
|
|
|
1037
1037
|
priceBreaks {
|
|
1038
1038
|
id
|
|
1039
1039
|
minQty
|
|
1040
|
-
|
|
1040
|
+
percentage
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
1043
|
integrationProduct {
|
|
@@ -1102,7 +1102,7 @@ F`
|
|
|
1102
1102
|
priceBreaks {
|
|
1103
1103
|
id
|
|
1104
1104
|
minQty
|
|
1105
|
-
|
|
1105
|
+
percentage
|
|
1106
1106
|
}
|
|
1107
1107
|
}
|
|
1108
1108
|
priceModifierTotal
|
|
@@ -1167,7 +1167,7 @@ const jt = F`
|
|
|
1167
1167
|
priceBreaks {
|
|
1168
1168
|
id
|
|
1169
1169
|
minQty
|
|
1170
|
-
|
|
1170
|
+
percentage
|
|
1171
1171
|
}
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
@@ -6727,7 +6727,7 @@ class he {
|
|
|
6727
6727
|
const n = this.getWorkflowManager().getProduct().priceBreaks || [], a = this.getQuantity(), s = (((o = this.bundle) == null ? void 0 : o.getWorkflowExperiences()) || []).filter(
|
|
6728
6728
|
(r) => r.getWorkflowManager().getProduct().id === this.getWorkflowManager().getProduct().id
|
|
6729
6729
|
).reduce((r, g) => r + g.getQuantity(), a);
|
|
6730
|
-
return n.forEach((r) => s >= r.minQty && (A = t * r.percentage)), Math.ceil(A);
|
|
6730
|
+
return n.forEach((r) => s >= r.minQty && (A = t * r.percentage)), console.log(`PRICEBREAK DEBUG: original price ${t}, breaks ${JSON.stringify(n, null, 2)}, quantity ${a}, total quantity ${s}, final price ${A}`), Math.ceil(A);
|
|
6731
6731
|
}
|
|
6732
6732
|
async copySelectionsViaGlobalConfiguration(e, t, A) {
|
|
6733
6733
|
const n = await e.getGlobalProperties(), a = A == null ? void 0 : A.map((r) => r.getId()), i = this.getSteps().filter((r) => a === void 0 || a.includes(r.getId())), s = t.getSteps(), o = (r) => n.find((g) => g.getRawProperty().name === r.aspectName);
|
package/dist/index.umd.cjs
CHANGED
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
priceBreaks {
|
|
236
236
|
id
|
|
237
237
|
minQty
|
|
238
|
-
|
|
238
|
+
percentage
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
integrationProduct {
|
|
@@ -312,7 +312,7 @@
|
|
|
312
312
|
priceBreaks {
|
|
313
313
|
id
|
|
314
314
|
minQty
|
|
315
|
-
|
|
315
|
+
percentage
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
integrationProduct {
|
|
@@ -389,7 +389,7 @@
|
|
|
389
389
|
priceBreaks {
|
|
390
390
|
id
|
|
391
391
|
minQty
|
|
392
|
-
|
|
392
|
+
percentage
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
395
|
integrationProduct {
|
|
@@ -488,7 +488,7 @@
|
|
|
488
488
|
priceBreaks {
|
|
489
489
|
id
|
|
490
490
|
minQty
|
|
491
|
-
|
|
491
|
+
percentage
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
integrationProduct {
|
|
@@ -552,7 +552,7 @@
|
|
|
552
552
|
priceBreaks {
|
|
553
553
|
id
|
|
554
554
|
minQty
|
|
555
|
-
|
|
555
|
+
percentage
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
558
|
priceModifierTotal
|
|
@@ -616,7 +616,7 @@
|
|
|
616
616
|
priceBreaks {
|
|
617
617
|
id
|
|
618
618
|
minQty
|
|
619
|
-
|
|
619
|
+
percentage
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
622
|
}
|
|
@@ -2004,7 +2004,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2004
2004
|
}
|
|
2005
2005
|
}
|
|
2006
2006
|
}
|
|
2007
|
-
`;var Kt=(c=>(c.QuantityChanged="QuantityChanged",c))(Kt||{});class le{constructor(e,t){var n;if(this.cachedStepHandles=new Map,this.renderableScenes=[],this.renderableSceneCallbacks=[],this.eventCallbacks=new Map,this.debouncedSavedDesignUpdate=tt(async()=>{await Fe.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()},2500),this.getCanvasObjectURLAsync=async a=>new Promise((i,o)=>{try{a.toBlob(s=>{if(s){const r=URL.createObjectURL(s);i(r)}})}catch(s){o(s)}}),!t.workflow)throw new Error("No Workflow ID provided.");this.client=e;const A=t.layouts;this.commandContext=new g.CommandContext,this.commandContext.initialize(A,t.reloadedState),this.isReadOnly=t.transaction.isOrdered||!!t.readOnly,this.workflowManager=new dn(t.workflow,((n=t.product.profanities)==null?void 0:n.map(a=>a.word))||[],A,this.commandContext,a=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return t.stateMutationFunc(a)},t.transaction,t.product,t.previewService,t.renderableContextService,t.reloadedState,t.readOnly,t.modelContainer,t.isReloadedTransaction,t.singleVariantsRenderable,t.delayWorkflowStateSync),this.workflowManager.addSelectionCallback(a=>{const i=a.traversableScenes.map(o=>{const s=o.renderableSteps.map(r=>r.stepName);return{id:o.name,title:o.title,renderableSteps:s,workflowScene:o}});this.renderableScenes=i,this.renderableSceneCallbacks.forEach(o=>o(i))})}getBundle(){return this.bundle}setBundle(e){this.bundle=e}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async createPreviewImage(e,t){var u,F;const A=this.workflowManager.getWorkflow(),n=(u=A==null?void 0:A.finalizeStepConfig)==null?void 0:u.lookAtAnimation;if(e){if(!n)throw new Error("Failed to generate cart preview image!");return await((F=this.workflowManager.getPreviewService())==null?void 0:F.renderSceneScreenshot(t??512,n))||""}let a=2048;t&&t<=2048&&(a=t);const i=g.createCanvas(a,a),o=this.commandContext.getAllLayouts(),s=A.defaultPreviewPanelIndex||0,r=A.panels[s],l=o.find(I=>{var f;return((f=I.layoutState)==null?void 0:f.layout.panelId)===(r==null?void 0:r.name)})||o[0],d=l.layoutState.layout.previewRegion?{x:l.layoutState.layout.previewRegion.left,y:l.layoutState.layout.previewRegion.top,width:l.layoutState.layout.previewRegion.width,height:l.layoutState.layout.previewRegion.height}:{x:0,y:0,width:l.layoutState.layout.width,height:l.layoutState.layout.height},B=this.commandContext.getLayoutById(l.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new Ce("Failed to obtain 2D context for preview image creation");const E=g.getSvgElement(B.layoutState.layout,B.layoutState.elements,{renderingConfiguration:{purpose:g.LayoutRenderingPurpose.Print,region:{left:d.x,top:d.y,width:d.width,height:d.height}}}),C=g.renderPapyrusComponentAsString(E);await(await et.Pith.from(w,C,{anonymousCrossOrigin:!0,ignoreDimensions:!1,createCanvas:g.createCanvas,createImage:g.loadImage,DOMParser:g.getDomParser(),fetch:g.fetch})).render();const m=await this.getCanvasObjectURLAsync(i);return i.toDataURL(m)}getStepById(e){const t=this.getWorkflowManager().getWorkflow().steps.find(a=>a.stepName===e);if(!t||!this.stepHasHandle(t))return;const A=this.cachedStepHandles.get(t.stepName);if(A)return A;const n=pe.get(this.getWorkflowManager(),t);return this.cachedStepHandles.set(t.stepName,n),n}getSteps(){return this.getScenes().flatMap(e=>this.getStepsByScene(e))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map(t=>({id:t.id,name:t.name,stepIds:t.stepNames}))}getSelectionPriceSubunits(){const e=this.getWorkflowManager().getWorkflowSelections();let t=0;return Object.values(e).forEach(A=>{t+=A.selections.reduce((n,a)=>n+(a.priceModifier||0),0)}),this.getPriceSubUnitsAfterPriceBreaks(t)}getBasePriceSubunits(e){const t=this.getPriceSubUnitsAfterPriceBreaks(this.getWorkflowManager().getProduct().basePrice||0);if(e){const A=this.getAdditionalProductPriceSubunits()||0;return t+A}return t}getAdditionalProductPriceSubunits(){var t;const e=this.getWorkflowManager().getTransaction().integrationProduct;if((t=e==null?void 0:e.additionalIntegrationProduct)!=null&&t.product){const A=e.additionalIntegrationProduct.product.basePrice||0;return this.getPriceSubUnitsAfterPriceBreaks(A)}}getTotalPriceSubunits(){return this.getBasePriceSubunits()+this.getSelectionPriceSubunits()}getPriceSubUnitsAfterPriceBreaks(e){var s;const t=e;let A=e;const n=this.getWorkflowManager().getProduct().priceBreaks||[],a=this.getQuantity(),o=(((s=this.bundle)==null?void 0:s.getWorkflowExperiences())||[]).filter(r=>r.getWorkflowManager().getProduct().id===this.getWorkflowManager().getProduct().id).reduce((r,l)=>r+l.getQuantity(),a);return n.forEach(r=>o>=r.minQty&&(A=t*r.percentage)),Math.ceil(A)}async copySelectionsViaGlobalConfiguration(e,t,A){const n=await e.getGlobalProperties(),a=A==null?void 0:A.map(r=>r.getId()),i=this.getSteps().filter(r=>a===void 0||a.includes(r.getId())),o=t.getSteps(),s=r=>n.find(l=>l.getRawProperty().name===r.aspectName);i.forEach(r=>{const l=new Set,d=r.getRaw().globalPropertyAspectConfigurations;d!==void 0&&(d.forEach(B=>l.add(JSON.stringify(B))),o.forEach(B=>{const w=B.getRaw().globalPropertyAspectConfigurations;w!==void 0&&w.forEach(E=>{const C=s(E),h=l.has(JSON.stringify(E));if(h&&(C==null?void 0:C.getType())==="Option"){const m=B.getCurrentVariant();if(!m)return;r.selectVariant(m),l.delete(JSON.stringify(E))}else if(h&&(C==null?void 0:C.getType())==="Text"){const m=B.getText();r.setText(m),l.delete(JSON.stringify(E))}})}))})}getStepByName(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepTitle===e);if(!(!t||!this.stepHasHandle(t)))return pe.get(this.getWorkflowManager(),t)}getStepsByType(e){return this.getWorkflowManager().getWorkflow().steps.filter(t=>t.type===e).map(t=>pe.get(this.getWorkflowManager(),t))}getStepsByScene(e){if(!this.getWorkflowManager().getWorkflow().stepGroups.find(A=>A.name===e.name))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return e.stepIds.map(A=>this.getWorkflowManager().getWorkflow().steps.find(n=>n.stepName===A)).filter(A=>this.stepHasHandle(A)).map(A=>pe.get(this.getWorkflowManager(),A))}async attachCustomerDetails(e){return this.assignCustomerDetails({emailAddress:e.email})}async assignCustomerDetails(e){var i,o,s;const A=(P.getMap("transactionOwnerIds")||new Map).get(this.getWorkflowManager().getTransaction().id),a=(s=(o=(i=(await N.getShadowGraphqlClient().mutate({mutation:In,variables:{id:this.getWorkflowManager().getTransaction().id,details:e,type:"Owner"},context:{transactionOwnerId:A}})).data)==null?void 0:i.transactionAddStakeholder)==null?void 0:o.stakeholders)==null?void 0:s.find(r=>{var l;return((l=r.customer)==null?void 0:l.emailAddress)===e.emailAddress});if(a!=null&&a.customer){this.getWorkflowManager().setTransactionCustomer(a.customer);const r=P.getMap("transactionCustomerIds")||new Map;r.set(this.getWorkflowManager().getTransaction().id,a.customer.id),P.setMap("transactionCustomerIds",r)}}attachRenderableSceneListener(e){this.renderableSceneCallbacks.push(e),e(this.renderableScenes)}detachRenderableSceneListener(e){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter(t=>t!==e)}async save(e){if(!this.getCommandContext().getState())throw new v("State undefined!");const n={title:await(async()=>{var s;if(e)return e;const a=this.getWorkflowManager().getTransaction().id,o=(s=(await Fe.getSavedDesigns()).find(r=>r.transactionId===a))==null?void 0:s.title;return o||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await Fe.addDesign(n),n}async copy(){var o;const e=Ee(this.getCommandContext().getState());if(!e)throw new v("Internal state is undefined! Cannot copy experience!");const t=JSON.stringify(e.transaction),A=this.getWorkflowManager().getWorkflow(),n=new oA({}),a=(o=this.getWorkflowManager().getTransaction().integrationProduct)==null?void 0:o.id;if(!a)throw new v("Integration product id is undefined!");return await n.initFromIntegrationProduct(a),await n.getWorkflowExperience(A.id,t,void 0)}async onDesignFinished(e,t=!0){return jt(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),()=>this.commandContext.getState(),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,e||(()=>{}),A=>t?this.createPreviewImage(A,1024):Promise.resolve(void 0),this.workflowManager.getWorkflowMetadata())}stepHasHandle(e){return e.type!==g.StepType.SilentIllustration&&e.type!==g.StepType.ProductOverlay}getExportedData(){var n;const e=new Map,t=this.getWorkflowManager().getWorkflowMetadata(),A=this.getWorkflowManager().getWorkflowSelections();return Object.keys(t).forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(s=>s.stepName===a);if(!i)return;e.has(i.stepTitle)||e.set(i.stepTitle,{});const o=t[a];Object.keys(o).forEach(s=>{e.get(i.stepTitle)[s]=o[s]})}),(n=Object.keys(A))==null||n.forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(o=>o.stepName===a);i&&(e.has(i.stepTitle)||e.set(i.stepTitle,{}),e.get(i.stepTitle).selection=A[a].selections[0].name)}),e}getQuantity(){return this.getWorkflowManager().getTransaction().quantity||1}async setQuantity(e){if(e<1)throw new RangeError("WorkflowExperience quantity must be greater than zero.");if(this.isReadOnly)throw new Error("Cannot update quantity on a read-only WorkflowExperience");this.getWorkflowManager().getTransaction().quantity=e,this.callEvent("QuantityChanged");const t=P.getMap("transactionOwnerIds")||new Map,A=this.getWorkflowManager().getTransaction(),n=t.get(A.id)||void 0;await N.getShadowGraphqlClient().mutate({mutation:UA,variables:{id:A.id,quantity:e},context:{transactionOwnerId:n}})}addEventListener(e,t){const A=this.eventCallbacks.get(e)||[];A.push(t),this.eventCallbacks.set(e,A)}removeEventListener(e,t){const A=this.eventCallbacks.get(e)||[];this.eventCallbacks.set(e,A.filter(n=>n!==t))}callEvent(e){(this.eventCallbacks.get(e)||[]).forEach(t=>t(this))}}const fn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Dn=async(c,e,t)=>{const A=e.data,n=t.data.baseUrl,a=A.assetUrl.replace("localhost","localstack"),i=n.slice(0,4)==="http"?"":"https://",o=new URL(i+n);o.searchParams.append("video",g.toBase64(JSON.stringify([{href:a}]))),o.pathname=o.pathname+(o.pathname.slice(-1)==="/"?"":"/");const s=o.toString(),l=`data:image/svg+xml;base64,${g.toBase64(await nt.toString(s,{type:"svg"}))}`,d=w=>{const E=c.find(h=>h.panelId===w.panelId);if(!E)throw new J(w);const C=g.generate();return new g.CreateElementCommand({id:C,src:l,type:g.LayoutElementType.Image,y:w.top,x:w.left,width:w.width,height:w.height,rotation:0},E)},B=t.data.regions;try{return B.map(d)}catch(w){return console.error(w),[]}},pn=async(c,e,t,A)=>{const n=t.data,a=n.assetUrl,i=await g.getPatternImageData(a);try{const o=g.getVariant(n,A.option);o&&(e[A.stepName]={selectedVariants:[o]});const s=async r=>{var C;const l=await g.generateFrameSVG(r||{width:1,height:1},(C=o==null?void 0:o.asset)==null?void 0:C.fileLink),d=await g.getFrameData(l),B=g.generate(),w=c.find(h=>h.panelId===r.panelId);if(!w)throw new J(r);const E=g.calculateOffsets(i,d,{scale:n.scale,left:n.x,top:n.y});return[new g.CreateElementCommand({id:B,path:d.path,dataWidth:d.width,dataHeight:d.height,type:g.LayoutElementType.Frame,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,forceImageCover:A.data.forceImageCover,x:r.left,y:r.top,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,rotation:r.rotation,scaleX:r.width/d.width,scaleY:r.height/d.height,pattern:void 0},w),new g.UpdateFramePattern(B,i,E)]};return(await Promise.all(A.data.regions.map(r=>s(r)))).flat()}catch(o){return console.error(o),[]}},Fn=async(c,e,t,A)=>{var f,D;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((f=a.variants)==null?void 0:f.find(p=>p.id===n.illustrationVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.illustrationVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.illustrationVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(D=i.asset)==null?void 0:D.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.illustrationVariantId}`),[];const s=await g.fetchAsString(o,!0),r=/<svg.*?<\/svg>/s,l=s.match(r)||[],d=(l==null?void 0:l.length)>0?l[0]:"",E=g.domParser().parseFromString(d,"image/svg+xml").firstElementChild;if(!E)return console.error("Failed to read SVG."),[];g.sanitizeSvgTree(E);const C={};g.traverse(E,p=>{fn.includes(p.tagName)&&!p.attributes.getNamedItem("fill")&&p.setAttribute("fill","#000000");const S=p.attributes.getNamedItem("fill");if(S&&S.value!=="none"){const x=S.value,H=`spiff-fill-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}const y=p.attributes.getNamedItem("stroke");if(y&&y.value!=="none"){const x=y.value,H=`spiff-stroke-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}});const m=g.xmlSerializer().serializeToString(E),u=n.colors;if(u){for(const[p,S]of Object.entries(C))for(const y of Object.keys(u))if(S.browserValue===y){C[p]={browserValue:u[y]};break}}const F=p=>{const S=c.find(x=>x.panelId===p.panelId);if(!S)throw new J(p);const y=g.generate();return new g.CreateElementCommand({colors:C,id:y,svg:m,type:g.LayoutElementType.Illustration,y:p.top,x:p.left,rotation:p.rotation,width:p.width,height:p.height,layer:p.layer,layerIndex:p.layerIndex,immutable:p.immutable},S)},I=A.data.regions;try{return I.map(F)}catch(p){return console.error(p),[]}},Mn=async(c,e,t)=>{const A=await xt(t.data.module),n=e.data,a=(o,s)=>{const r=c.find(d=>d.panelId===s.panelId);if(!r)throw new J(s);const l=g.generate();return new g.CreateElementCommand({colors:{},id:l,svg:o,type:g.LayoutElementType.Illustration,y:s.top,x:s.left,rotation:s.rotation,width:s.width,height:s.height,layer:s.layer,layerIndex:s.layerIndex},r)},i=t.data.regions;try{return i.map(o=>a(A.svgPrint(n.text,o),o))}catch(o){return console.error(o),[]}},Sn=async(c,e,t,A)=>{var l,d;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((l=a.variants)==null?void 0:l.find(B=>B.id===n.pictureVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.pictureVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.pictureVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(d=i.asset)==null?void 0:d.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.pictureVariantId}`),[];const s=B=>{const w=c.find(C=>C.panelId===B.panelId);if(!w)throw new J(B);const E=g.generate();return new g.CreateElementCommand({id:E,src:o,type:g.LayoutElementType.Image,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,preserveAspectRatio:"none"},w)},r=A.data.regions;try{return r.map(s)}catch(B){return console.error(B),[]}},yn=async(c,e,t,A)=>{var r;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((r=a.variants)==null?void 0:r.find(l=>l.id===n.colorVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.colorVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=l=>{const d=c.find(h=>h.panelId===l.panelId);if(!d)throw new J(l);const B=`
|
|
2007
|
+
`;var Kt=(c=>(c.QuantityChanged="QuantityChanged",c))(Kt||{});class le{constructor(e,t){var n;if(this.cachedStepHandles=new Map,this.renderableScenes=[],this.renderableSceneCallbacks=[],this.eventCallbacks=new Map,this.debouncedSavedDesignUpdate=tt(async()=>{await Fe.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()},2500),this.getCanvasObjectURLAsync=async a=>new Promise((i,o)=>{try{a.toBlob(s=>{if(s){const r=URL.createObjectURL(s);i(r)}})}catch(s){o(s)}}),!t.workflow)throw new Error("No Workflow ID provided.");this.client=e;const A=t.layouts;this.commandContext=new g.CommandContext,this.commandContext.initialize(A,t.reloadedState),this.isReadOnly=t.transaction.isOrdered||!!t.readOnly,this.workflowManager=new dn(t.workflow,((n=t.product.profanities)==null?void 0:n.map(a=>a.word))||[],A,this.commandContext,a=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return t.stateMutationFunc(a)},t.transaction,t.product,t.previewService,t.renderableContextService,t.reloadedState,t.readOnly,t.modelContainer,t.isReloadedTransaction,t.singleVariantsRenderable,t.delayWorkflowStateSync),this.workflowManager.addSelectionCallback(a=>{const i=a.traversableScenes.map(o=>{const s=o.renderableSteps.map(r=>r.stepName);return{id:o.name,title:o.title,renderableSteps:s,workflowScene:o}});this.renderableScenes=i,this.renderableSceneCallbacks.forEach(o=>o(i))})}getBundle(){return this.bundle}setBundle(e){this.bundle=e}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async createPreviewImage(e,t){var u,F;const A=this.workflowManager.getWorkflow(),n=(u=A==null?void 0:A.finalizeStepConfig)==null?void 0:u.lookAtAnimation;if(e){if(!n)throw new Error("Failed to generate cart preview image!");return await((F=this.workflowManager.getPreviewService())==null?void 0:F.renderSceneScreenshot(t??512,n))||""}let a=2048;t&&t<=2048&&(a=t);const i=g.createCanvas(a,a),o=this.commandContext.getAllLayouts(),s=A.defaultPreviewPanelIndex||0,r=A.panels[s],l=o.find(I=>{var f;return((f=I.layoutState)==null?void 0:f.layout.panelId)===(r==null?void 0:r.name)})||o[0],d=l.layoutState.layout.previewRegion?{x:l.layoutState.layout.previewRegion.left,y:l.layoutState.layout.previewRegion.top,width:l.layoutState.layout.previewRegion.width,height:l.layoutState.layout.previewRegion.height}:{x:0,y:0,width:l.layoutState.layout.width,height:l.layoutState.layout.height},B=this.commandContext.getLayoutById(l.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new Ce("Failed to obtain 2D context for preview image creation");const E=g.getSvgElement(B.layoutState.layout,B.layoutState.elements,{renderingConfiguration:{purpose:g.LayoutRenderingPurpose.Print,region:{left:d.x,top:d.y,width:d.width,height:d.height}}}),C=g.renderPapyrusComponentAsString(E);await(await et.Pith.from(w,C,{anonymousCrossOrigin:!0,ignoreDimensions:!1,createCanvas:g.createCanvas,createImage:g.loadImage,DOMParser:g.getDomParser(),fetch:g.fetch})).render();const m=await this.getCanvasObjectURLAsync(i);return i.toDataURL(m)}getStepById(e){const t=this.getWorkflowManager().getWorkflow().steps.find(a=>a.stepName===e);if(!t||!this.stepHasHandle(t))return;const A=this.cachedStepHandles.get(t.stepName);if(A)return A;const n=pe.get(this.getWorkflowManager(),t);return this.cachedStepHandles.set(t.stepName,n),n}getSteps(){return this.getScenes().flatMap(e=>this.getStepsByScene(e))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map(t=>({id:t.id,name:t.name,stepIds:t.stepNames}))}getSelectionPriceSubunits(){const e=this.getWorkflowManager().getWorkflowSelections();let t=0;return Object.values(e).forEach(A=>{t+=A.selections.reduce((n,a)=>n+(a.priceModifier||0),0)}),this.getPriceSubUnitsAfterPriceBreaks(t)}getBasePriceSubunits(e){const t=this.getPriceSubUnitsAfterPriceBreaks(this.getWorkflowManager().getProduct().basePrice||0);if(e){const A=this.getAdditionalProductPriceSubunits()||0;return t+A}return t}getAdditionalProductPriceSubunits(){var t;const e=this.getWorkflowManager().getTransaction().integrationProduct;if((t=e==null?void 0:e.additionalIntegrationProduct)!=null&&t.product){const A=e.additionalIntegrationProduct.product.basePrice||0;return this.getPriceSubUnitsAfterPriceBreaks(A)}}getTotalPriceSubunits(){return this.getBasePriceSubunits()+this.getSelectionPriceSubunits()}getPriceSubUnitsAfterPriceBreaks(e){var s;const t=e;let A=e;const n=this.getWorkflowManager().getProduct().priceBreaks||[],a=this.getQuantity(),o=(((s=this.bundle)==null?void 0:s.getWorkflowExperiences())||[]).filter(r=>r.getWorkflowManager().getProduct().id===this.getWorkflowManager().getProduct().id).reduce((r,l)=>r+l.getQuantity(),a);return n.forEach(r=>o>=r.minQty&&(A=t*r.percentage)),console.log(`PRICEBREAK DEBUG: original price ${t}, breaks ${JSON.stringify(n,null,2)}, quantity ${a}, total quantity ${o}, final price ${A}`),Math.ceil(A)}async copySelectionsViaGlobalConfiguration(e,t,A){const n=await e.getGlobalProperties(),a=A==null?void 0:A.map(r=>r.getId()),i=this.getSteps().filter(r=>a===void 0||a.includes(r.getId())),o=t.getSteps(),s=r=>n.find(l=>l.getRawProperty().name===r.aspectName);i.forEach(r=>{const l=new Set,d=r.getRaw().globalPropertyAspectConfigurations;d!==void 0&&(d.forEach(B=>l.add(JSON.stringify(B))),o.forEach(B=>{const w=B.getRaw().globalPropertyAspectConfigurations;w!==void 0&&w.forEach(E=>{const C=s(E),h=l.has(JSON.stringify(E));if(h&&(C==null?void 0:C.getType())==="Option"){const m=B.getCurrentVariant();if(!m)return;r.selectVariant(m),l.delete(JSON.stringify(E))}else if(h&&(C==null?void 0:C.getType())==="Text"){const m=B.getText();r.setText(m),l.delete(JSON.stringify(E))}})}))})}getStepByName(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepTitle===e);if(!(!t||!this.stepHasHandle(t)))return pe.get(this.getWorkflowManager(),t)}getStepsByType(e){return this.getWorkflowManager().getWorkflow().steps.filter(t=>t.type===e).map(t=>pe.get(this.getWorkflowManager(),t))}getStepsByScene(e){if(!this.getWorkflowManager().getWorkflow().stepGroups.find(A=>A.name===e.name))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return e.stepIds.map(A=>this.getWorkflowManager().getWorkflow().steps.find(n=>n.stepName===A)).filter(A=>this.stepHasHandle(A)).map(A=>pe.get(this.getWorkflowManager(),A))}async attachCustomerDetails(e){return this.assignCustomerDetails({emailAddress:e.email})}async assignCustomerDetails(e){var i,o,s;const A=(P.getMap("transactionOwnerIds")||new Map).get(this.getWorkflowManager().getTransaction().id),a=(s=(o=(i=(await N.getShadowGraphqlClient().mutate({mutation:In,variables:{id:this.getWorkflowManager().getTransaction().id,details:e,type:"Owner"},context:{transactionOwnerId:A}})).data)==null?void 0:i.transactionAddStakeholder)==null?void 0:o.stakeholders)==null?void 0:s.find(r=>{var l;return((l=r.customer)==null?void 0:l.emailAddress)===e.emailAddress});if(a!=null&&a.customer){this.getWorkflowManager().setTransactionCustomer(a.customer);const r=P.getMap("transactionCustomerIds")||new Map;r.set(this.getWorkflowManager().getTransaction().id,a.customer.id),P.setMap("transactionCustomerIds",r)}}attachRenderableSceneListener(e){this.renderableSceneCallbacks.push(e),e(this.renderableScenes)}detachRenderableSceneListener(e){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter(t=>t!==e)}async save(e){if(!this.getCommandContext().getState())throw new v("State undefined!");const n={title:await(async()=>{var s;if(e)return e;const a=this.getWorkflowManager().getTransaction().id,o=(s=(await Fe.getSavedDesigns()).find(r=>r.transactionId===a))==null?void 0:s.title;return o||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await Fe.addDesign(n),n}async copy(){var o;const e=Ee(this.getCommandContext().getState());if(!e)throw new v("Internal state is undefined! Cannot copy experience!");const t=JSON.stringify(e.transaction),A=this.getWorkflowManager().getWorkflow(),n=new oA({}),a=(o=this.getWorkflowManager().getTransaction().integrationProduct)==null?void 0:o.id;if(!a)throw new v("Integration product id is undefined!");return await n.initFromIntegrationProduct(a),await n.getWorkflowExperience(A.id,t,void 0)}async onDesignFinished(e,t=!0){return jt(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),()=>this.commandContext.getState(),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,e||(()=>{}),A=>t?this.createPreviewImage(A,1024):Promise.resolve(void 0),this.workflowManager.getWorkflowMetadata())}stepHasHandle(e){return e.type!==g.StepType.SilentIllustration&&e.type!==g.StepType.ProductOverlay}getExportedData(){var n;const e=new Map,t=this.getWorkflowManager().getWorkflowMetadata(),A=this.getWorkflowManager().getWorkflowSelections();return Object.keys(t).forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(s=>s.stepName===a);if(!i)return;e.has(i.stepTitle)||e.set(i.stepTitle,{});const o=t[a];Object.keys(o).forEach(s=>{e.get(i.stepTitle)[s]=o[s]})}),(n=Object.keys(A))==null||n.forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(o=>o.stepName===a);i&&(e.has(i.stepTitle)||e.set(i.stepTitle,{}),e.get(i.stepTitle).selection=A[a].selections[0].name)}),e}getQuantity(){return this.getWorkflowManager().getTransaction().quantity||1}async setQuantity(e){if(e<1)throw new RangeError("WorkflowExperience quantity must be greater than zero.");if(this.isReadOnly)throw new Error("Cannot update quantity on a read-only WorkflowExperience");this.getWorkflowManager().getTransaction().quantity=e,this.callEvent("QuantityChanged");const t=P.getMap("transactionOwnerIds")||new Map,A=this.getWorkflowManager().getTransaction(),n=t.get(A.id)||void 0;await N.getShadowGraphqlClient().mutate({mutation:UA,variables:{id:A.id,quantity:e},context:{transactionOwnerId:n}})}addEventListener(e,t){const A=this.eventCallbacks.get(e)||[];A.push(t),this.eventCallbacks.set(e,A)}removeEventListener(e,t){const A=this.eventCallbacks.get(e)||[];this.eventCallbacks.set(e,A.filter(n=>n!==t))}callEvent(e){(this.eventCallbacks.get(e)||[]).forEach(t=>t(this))}}const fn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Dn=async(c,e,t)=>{const A=e.data,n=t.data.baseUrl,a=A.assetUrl.replace("localhost","localstack"),i=n.slice(0,4)==="http"?"":"https://",o=new URL(i+n);o.searchParams.append("video",g.toBase64(JSON.stringify([{href:a}]))),o.pathname=o.pathname+(o.pathname.slice(-1)==="/"?"":"/");const s=o.toString(),l=`data:image/svg+xml;base64,${g.toBase64(await nt.toString(s,{type:"svg"}))}`,d=w=>{const E=c.find(h=>h.panelId===w.panelId);if(!E)throw new J(w);const C=g.generate();return new g.CreateElementCommand({id:C,src:l,type:g.LayoutElementType.Image,y:w.top,x:w.left,width:w.width,height:w.height,rotation:0},E)},B=t.data.regions;try{return B.map(d)}catch(w){return console.error(w),[]}},pn=async(c,e,t,A)=>{const n=t.data,a=n.assetUrl,i=await g.getPatternImageData(a);try{const o=g.getVariant(n,A.option);o&&(e[A.stepName]={selectedVariants:[o]});const s=async r=>{var C;const l=await g.generateFrameSVG(r||{width:1,height:1},(C=o==null?void 0:o.asset)==null?void 0:C.fileLink),d=await g.getFrameData(l),B=g.generate(),w=c.find(h=>h.panelId===r.panelId);if(!w)throw new J(r);const E=g.calculateOffsets(i,d,{scale:n.scale,left:n.x,top:n.y});return[new g.CreateElementCommand({id:B,path:d.path,dataWidth:d.width,dataHeight:d.height,type:g.LayoutElementType.Frame,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,forceImageCover:A.data.forceImageCover,x:r.left,y:r.top,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,rotation:r.rotation,scaleX:r.width/d.width,scaleY:r.height/d.height,pattern:void 0},w),new g.UpdateFramePattern(B,i,E)]};return(await Promise.all(A.data.regions.map(r=>s(r)))).flat()}catch(o){return console.error(o),[]}},Fn=async(c,e,t,A)=>{var f,D;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((f=a.variants)==null?void 0:f.find(p=>p.id===n.illustrationVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.illustrationVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.illustrationVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(D=i.asset)==null?void 0:D.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.illustrationVariantId}`),[];const s=await g.fetchAsString(o,!0),r=/<svg.*?<\/svg>/s,l=s.match(r)||[],d=(l==null?void 0:l.length)>0?l[0]:"",E=g.domParser().parseFromString(d,"image/svg+xml").firstElementChild;if(!E)return console.error("Failed to read SVG."),[];g.sanitizeSvgTree(E);const C={};g.traverse(E,p=>{fn.includes(p.tagName)&&!p.attributes.getNamedItem("fill")&&p.setAttribute("fill","#000000");const S=p.attributes.getNamedItem("fill");if(S&&S.value!=="none"){const x=S.value,H=`spiff-fill-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}const y=p.attributes.getNamedItem("stroke");if(y&&y.value!=="none"){const x=y.value,H=`spiff-stroke-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}});const m=g.xmlSerializer().serializeToString(E),u=n.colors;if(u){for(const[p,S]of Object.entries(C))for(const y of Object.keys(u))if(S.browserValue===y){C[p]={browserValue:u[y]};break}}const F=p=>{const S=c.find(x=>x.panelId===p.panelId);if(!S)throw new J(p);const y=g.generate();return new g.CreateElementCommand({colors:C,id:y,svg:m,type:g.LayoutElementType.Illustration,y:p.top,x:p.left,rotation:p.rotation,width:p.width,height:p.height,layer:p.layer,layerIndex:p.layerIndex,immutable:p.immutable},S)},I=A.data.regions;try{return I.map(F)}catch(p){return console.error(p),[]}},Mn=async(c,e,t)=>{const A=await xt(t.data.module),n=e.data,a=(o,s)=>{const r=c.find(d=>d.panelId===s.panelId);if(!r)throw new J(s);const l=g.generate();return new g.CreateElementCommand({colors:{},id:l,svg:o,type:g.LayoutElementType.Illustration,y:s.top,x:s.left,rotation:s.rotation,width:s.width,height:s.height,layer:s.layer,layerIndex:s.layerIndex},r)},i=t.data.regions;try{return i.map(o=>a(A.svgPrint(n.text,o),o))}catch(o){return console.error(o),[]}},Sn=async(c,e,t,A)=>{var l,d;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((l=a.variants)==null?void 0:l.find(B=>B.id===n.pictureVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.pictureVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.pictureVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(d=i.asset)==null?void 0:d.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.pictureVariantId}`),[];const s=B=>{const w=c.find(C=>C.panelId===B.panelId);if(!w)throw new J(B);const E=g.generate();return new g.CreateElementCommand({id:E,src:o,type:g.LayoutElementType.Image,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,preserveAspectRatio:"none"},w)},r=A.data.regions;try{return r.map(s)}catch(B){return console.error(B),[]}},yn=async(c,e,t,A)=>{var r;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((r=a.variants)==null?void 0:r.find(l=>l.id===n.colorVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.colorVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=l=>{const d=c.find(h=>h.panelId===l.panelId);if(!d)throw new J(l);const B=`
|
|
2008
2008
|
<svg
|
|
2009
2009
|
xmlns="http://www.w3.org/2000/svg"
|
|
2010
2010
|
xmlnsXlink="http://www.w3.org/1999/xlink"
|