@spiffcommerce/core 21.2.2-3 → 21.2.2-4
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.d.ts +17 -8
- package/dist/index.js +33 -28
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1499,21 +1499,29 @@ interface WorkflowExperience {
|
|
|
1499
1499
|
getScenes(): Scene[];
|
|
1500
1500
|
/**
|
|
1501
1501
|
* Returns the total cost in subunits for all selections made on the design.
|
|
1502
|
+
* @param disablePriceBreaks Whether to exclude price breaks from the calculation.
|
|
1502
1503
|
*/
|
|
1503
|
-
getSelectionPriceSubunits(): number;
|
|
1504
|
+
getSelectionPriceSubunits(disablePriceBreaks?: boolean): number;
|
|
1504
1505
|
/**
|
|
1505
1506
|
* Returns the total cost in subunits for the base product.
|
|
1506
1507
|
* @param includeAdditionalProduct When true the additional product cost will be included in the total (if configured).
|
|
1508
|
+
* @param disablePriceBreaks Whether to exclude price breaks from the calculation.
|
|
1507
1509
|
*/
|
|
1508
|
-
getBasePriceSubunits(includeAdditionalProduct?: boolean): number;
|
|
1510
|
+
getBasePriceSubunits(includeAdditionalProduct?: boolean, disablePriceBreaks?: boolean): number;
|
|
1509
1511
|
/**
|
|
1510
1512
|
* If an additional product is configured, returns the base price of that product. Returns undefined otherwise.
|
|
1513
|
+
* @param disablePriceBreaks Whether to exclude price breaks from the calculation.
|
|
1511
1514
|
*/
|
|
1512
|
-
getAdditionalProductPriceSubunits(): number | undefined;
|
|
1515
|
+
getAdditionalProductPriceSubunits(disablePriceBreaks?: boolean): number | undefined;
|
|
1513
1516
|
/**
|
|
1514
1517
|
* A convenience function returning the sum of the selection and base price values.
|
|
1518
|
+
* @param disablePriceBreaks Whether to exclude price breaks from the calculation.
|
|
1515
1519
|
*/
|
|
1516
|
-
getTotalPriceSubunits(): number;
|
|
1520
|
+
getTotalPriceSubunits(disablePriceBreaks?: boolean): number;
|
|
1521
|
+
/**
|
|
1522
|
+
* The price break percentage that is expected to be applied in price calculations.
|
|
1523
|
+
*/
|
|
1524
|
+
priceBreakToBeApplied(): number;
|
|
1517
1525
|
/**
|
|
1518
1526
|
* Takes selections made by the user in another workflow and applies them to this workflow. For
|
|
1519
1527
|
* selections to be copied they must both have a matching global property configuration.
|
|
@@ -1630,11 +1638,12 @@ declare class WorkflowExperienceImpl implements WorkflowExperience {
|
|
|
1630
1638
|
getStepById(id: string): StepHandle<any> | undefined;
|
|
1631
1639
|
getSteps(): StepHandle<AnyStepData>[];
|
|
1632
1640
|
getScenes(): Scene[];
|
|
1633
|
-
getSelectionPriceSubunits(): number;
|
|
1634
|
-
getBasePriceSubunits(includeAdditionalProduct?: boolean): number;
|
|
1635
|
-
getAdditionalProductPriceSubunits(): number | undefined;
|
|
1636
|
-
getTotalPriceSubunits(): number;
|
|
1641
|
+
getSelectionPriceSubunits(disablePriceBreaks?: boolean): number;
|
|
1642
|
+
getBasePriceSubunits(includeAdditionalProduct?: boolean, disablePriceBreaks?: boolean): number;
|
|
1643
|
+
getAdditionalProductPriceSubunits(disablePriceBreaks?: boolean): number | undefined;
|
|
1644
|
+
getTotalPriceSubunits(disablePriceBreaks?: boolean): number;
|
|
1637
1645
|
private getPriceSubUnitsAfterPriceBreaks;
|
|
1646
|
+
priceBreakToBeApplied(): number;
|
|
1638
1647
|
copySelectionsViaGlobalConfiguration(bundle: Bundle, experience: WorkflowExperience, filter?: StepHandle<AnyStepData>[]): Promise<void>;
|
|
1639
1648
|
getStepByName(name: string): TextStepHandle | FrameStepHandle | ShapeStepHandle | InformationStepHandle | IllustrationStepHandle | MaterialStepHandle | ModelStepHandle | PictureStepHandle | QuestionStepHandle | undefined;
|
|
1640
1649
|
getStepsByType(type: StepType): StepHandle<AnyStepData>[];
|
package/dist/index.js
CHANGED
|
@@ -6694,40 +6694,45 @@ class he {
|
|
|
6694
6694
|
stepIds: t.stepNames
|
|
6695
6695
|
}));
|
|
6696
6696
|
}
|
|
6697
|
-
getSelectionPriceSubunits() {
|
|
6698
|
-
const
|
|
6699
|
-
let
|
|
6700
|
-
return Object.values(
|
|
6701
|
-
|
|
6702
|
-
}), this.getPriceSubUnitsAfterPriceBreaks(
|
|
6703
|
-
}
|
|
6704
|
-
getBasePriceSubunits(e) {
|
|
6705
|
-
const
|
|
6697
|
+
getSelectionPriceSubunits(e) {
|
|
6698
|
+
const t = this.getWorkflowManager().getWorkflowSelections();
|
|
6699
|
+
let A = 0;
|
|
6700
|
+
return Object.values(t).forEach((n) => {
|
|
6701
|
+
A += n.selections.reduce((a, i) => a + (i.priceModifier || 0), 0);
|
|
6702
|
+
}), this.getPriceSubUnitsAfterPriceBreaks(A, e);
|
|
6703
|
+
}
|
|
6704
|
+
getBasePriceSubunits(e, t) {
|
|
6705
|
+
const A = this.getPriceSubUnitsAfterPriceBreaks(this.getWorkflowManager().getProduct().basePrice || 0, t);
|
|
6706
6706
|
if (e) {
|
|
6707
|
-
const
|
|
6708
|
-
return
|
|
6707
|
+
const n = this.getAdditionalProductPriceSubunits(t) || 0;
|
|
6708
|
+
return A + n;
|
|
6709
6709
|
}
|
|
6710
|
-
return
|
|
6710
|
+
return A;
|
|
6711
6711
|
}
|
|
6712
|
-
getAdditionalProductPriceSubunits() {
|
|
6713
|
-
var
|
|
6714
|
-
const
|
|
6715
|
-
if ((
|
|
6716
|
-
const
|
|
6717
|
-
return this.getPriceSubUnitsAfterPriceBreaks(
|
|
6712
|
+
getAdditionalProductPriceSubunits(e) {
|
|
6713
|
+
var A;
|
|
6714
|
+
const t = this.getWorkflowManager().getTransaction().integrationProduct;
|
|
6715
|
+
if ((A = t == null ? void 0 : t.additionalIntegrationProduct) != null && A.product) {
|
|
6716
|
+
const n = t.additionalIntegrationProduct.product.basePrice || 0;
|
|
6717
|
+
return this.getPriceSubUnitsAfterPriceBreaks(n, e);
|
|
6718
6718
|
}
|
|
6719
6719
|
}
|
|
6720
|
-
getTotalPriceSubunits() {
|
|
6721
|
-
return this.getBasePriceSubunits() + this.getSelectionPriceSubunits();
|
|
6720
|
+
getTotalPriceSubunits(e) {
|
|
6721
|
+
return this.getBasePriceSubunits(e) + this.getSelectionPriceSubunits(e);
|
|
6722
6722
|
}
|
|
6723
|
-
getPriceSubUnitsAfterPriceBreaks(e) {
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
).
|
|
6730
|
-
|
|
6723
|
+
getPriceSubUnitsAfterPriceBreaks(e, t) {
|
|
6724
|
+
const A = t ? 1 : this.priceBreakToBeApplied(), n = e * A;
|
|
6725
|
+
return Math.ceil(n);
|
|
6726
|
+
}
|
|
6727
|
+
priceBreakToBeApplied() {
|
|
6728
|
+
var n;
|
|
6729
|
+
const e = (this.getWorkflowManager().getProduct().priceBreaks || []).sort((a, i) => -(a.minQty - i.minQty)), A = (((n = this.bundle) == null ? void 0 : n.getWorkflowExperiences()) || []).filter(
|
|
6730
|
+
(a) => a.getWorkflowManager().getProduct().id === this.getWorkflowManager().getProduct().id
|
|
6731
|
+
).reduce((a, i) => a + i.getQuantity(), 0);
|
|
6732
|
+
for (const a of e)
|
|
6733
|
+
if (a.minQty >= A)
|
|
6734
|
+
return a.percentage;
|
|
6735
|
+
return 1;
|
|
6731
6736
|
}
|
|
6732
6737
|
async copySelectionsViaGlobalConfiguration(e, t, A) {
|
|
6733
6738
|
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
|
@@ -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 o;const t=e;let A=e;const n=this.getWorkflowManager().getProduct().priceBreaks||[],i=(((o=this.bundle)==null?void 0:o.getWorkflowExperiences())||[]).filter(s=>s.getWorkflowManager().getProduct().id===this.getWorkflowManager().getProduct().id).reduce((s,r)=>s+r.getQuantity(),0);return n.forEach(s=>i>=s.minQty&&(A=t*s.percentage)),console.log(`PRICEBREAK DEBUG: original price ${t}, breaks ${JSON.stringify(n,null,2)}, total quantity ${i}, 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=`
|
|
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(e){const t=this.getWorkflowManager().getWorkflowSelections();let A=0;return Object.values(t).forEach(n=>{A+=n.selections.reduce((a,i)=>a+(i.priceModifier||0),0)}),this.getPriceSubUnitsAfterPriceBreaks(A,e)}getBasePriceSubunits(e,t){const A=this.getPriceSubUnitsAfterPriceBreaks(this.getWorkflowManager().getProduct().basePrice||0,t);if(e){const n=this.getAdditionalProductPriceSubunits(t)||0;return A+n}return A}getAdditionalProductPriceSubunits(e){var A;const t=this.getWorkflowManager().getTransaction().integrationProduct;if((A=t==null?void 0:t.additionalIntegrationProduct)!=null&&A.product){const n=t.additionalIntegrationProduct.product.basePrice||0;return this.getPriceSubUnitsAfterPriceBreaks(n,e)}}getTotalPriceSubunits(e){return this.getBasePriceSubunits(e)+this.getSelectionPriceSubunits(e)}getPriceSubUnitsAfterPriceBreaks(e,t){const A=t?1:this.priceBreakToBeApplied(),n=e*A;return Math.ceil(n)}priceBreakToBeApplied(){var n;const e=(this.getWorkflowManager().getProduct().priceBreaks||[]).sort((a,i)=>-(a.minQty-i.minQty)),A=(((n=this.bundle)==null?void 0:n.getWorkflowExperiences())||[]).filter(a=>a.getWorkflowManager().getProduct().id===this.getWorkflowManager().getProduct().id).reduce((a,i)=>a+i.getQuantity(),0);for(const a of e)if(a.minQty>=A)return a.percentage;return 1}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"
|