@spiffcommerce/core 26.7.1 → 26.7.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/CHANGELOG.md CHANGED
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
14
  - `Fixed` for any bug fixes.
15
15
  - `Security` in case of vulnerabilities.
16
16
 
17
+ ## [26.7.2] - 02-12-2024
18
+
19
+ ### Fixed
20
+
21
+ - Corrected an issue with `TextStepService.availableFillColors` not returning the correct colors under certain conditions.
22
+
17
23
  ## [26.7.0] - 27-11-2024
18
24
 
19
25
  ### Added
package/dist/index.d.ts CHANGED
@@ -4725,6 +4725,7 @@ interface TextErrorData {
4725
4725
  }
4726
4726
  declare class TextStepService implements StepService<TextStepData> {
4727
4727
  private cachedColors;
4728
+ private cachedStrokeColors;
4728
4729
  init(stepData: Step<TextStepData>, workflowManager: WorkflowManager, reducerState?: LayoutsState): Promise<CommandWithFollowup | null>;
4729
4730
  findLayoutElements(workflowManager: WorkflowManager, step: Step<TextStepData>): TextboxElement[];
4730
4731
  /**
package/dist/index.js CHANGED
@@ -1368,8 +1368,8 @@
1368
1368
  </svg>
1369
1369
  `,w={};w[this.shapeFillId]={browserValue:C};const E=b();return{id:E,region:B,command:new z({stepRegion:B,stepName:t.stepName,colors:w,id:E,svg:u,type:N.Illustration,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,excludeFromExport:t.data.excludeFromPrint},h)}},l=t.data.regions.map(c),g=l.filter(B=>!!B).map(B=>B==null?void 0:B.command),d=l.filter(B=>!!B).map(B=>({id:B.id,region:B.region}));return{command:new G(g),followup:async()=>{await a.setSelectionsAndElements(t.stepName,e.variant?[e.variant]:[],d,async()=>{a.updateStorage(t.stepName,{colour:o()})})}}}}}const St=new no;class io{constructor(){this.latestToast=null,this.toastType=null,this.toastCallbacks=[]}addToastCallback(t){t({toastMessage:this.latestToast,toastType:this.toastType}),this.toastCallbacks.push(t)}removeToastCallback(t){this.toastCallbacks=this.toastCallbacks.filter(e=>e!==t)}setLatestToast(t,e){this.latestToast=t,this.toastType=e,this.onToastChange()}onToastChange(){this.toastCallbacks.forEach(t=>t({toastMessage:this.latestToast,toastType:this.toastType}))}}const tn=new io,Le=(n,t,e,A,a)=>{if(t.some(l=>l==null))throw new Error(`Failed to autosize lines: ${t.join(", ")}`);let i=t.map(l=>l.split(`
1370
1370
  `)).flat(),s=i.length,o=i.map(l=>gt(l,A,a));const r=a.getApproximateHeight()*A;let c=!0;for(;c;){if(r+(s-1)*e>n.height)return[null,null];const g=Math.max(...o);if(g<=n.width)return[i,g];const d=o.reduce((u,w,E,m)=>w>m[u]?E:u,0),B=i[d];let h=!1,C=B.length;for(;!h&&C>-1;){C=B.lastIndexOf(" ",C-1);const u=[B.slice(0,C),B.slice(C+1)],w=u.map(m=>gt(m,A,a));w[0]<=n.width&&(i=[...i.slice(0,d),...u,...i.slice(d+1)],o=[...o.slice(0,d),...w,...o.slice(d+1)],s+=1,h=!0)}h||(c=!1)}return[null,null]},Vt=(n,t,e,A,a)=>{let i,s;const o=Qt(t.assetUrl),r=o.getFont();if(a.size){const d=n/r.unitsPerEm;return[i,s]=Le(e,A,n,d,o),[a.size,i,s]}const c=6;let l=c-He;if(A.length>0){let d=A,B=0;for(;(!a.maxSize||l<=a.maxSize)&&d;)l+=He,B=l/r.unitsPerEm,[d,s]=Le(e,A,l,B,o)}l>c&&(l-=He),a.minSize&&l<a.minSize&&(l=a.minSize);const g=l/r.unitsPerEm;return[i,s]=Le(e,A,l,g,o),[l,i,s]},Oe=30;class Ee extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=Ee.name}}const so=["‘","’","“","”",`
1371
- `];class me extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=me.name}}class oo{constructor(){this.cachedColors=new Map,this.filterUnsupportedCharacters=(t,e)=>{let A=t.replace(/(\r\n|\r|(\u2665|\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const a=[],i=e?Qt(e.assetUrl):void 0;if(i){const s=A.split("").filter(r=>!so.includes(r)).join(""),o=s.split("").map(r=>i.getFont().charToGlyph(r));for(let r=0;r<o.length;r++)o[r].name===".notdef"&&a.push(String.fromCharCode(s.charCodeAt(r)))}for(let s=0;s<a.length;s++)A=A.replaceAll(a[s],"");return A},this.textAlign=t=>t.vertical?"center":t.textAlign||"center",this.getErrorsForText=(t,e,A)=>{let a;e.data&&e.data.maxLength&&t.length>e.data.maxLength&&(a||(a={}),a.hitCharacterLimit=!0);const i=A.getProfanities(),s=Ve.split(t.toLowerCase());for(const r of s)for(const c in i){const l=i[c].toLowerCase().replace(/\s/g,"");if(r===l){a||(a={}),a.blockedProfanity=!0;break}}return!e.data.allowNewlines&&(t.includes(`
1372
- `)||t.includes("\r"))&&(a||(a={}),a.illegalMultipleLines=!0),a}}async init(t,e,A){var i,s,o;const a=t.option;if(!a)return null;if(A)await this.reload(t,e,A);else{const r=this.getDefaultImageFillVariant(t.data),c=(i=r==null?void 0:r.asset)==null?void 0:i.fileLink,l=c?await eA(c):void 0,g=l?{src:l.src,height:l.height,width:l.width,scale:t.data.imageFillScale||1}:void 0,d=this.getDefaultStrokeColorVariant(t.data),B=t.data.strokeEnabled&&(d!=null&&d.color)?{browserValue:d.color,pmsValue:d.name}:void 0;e.updateStorage(t.stepName,{text:t.data.defaultText||"",inputText:t.data.defaultText||"",color:((s=this.getDefaultColorVariant(t.data))==null?void 0:s.color)||this.getDefaultColor(t.data),fillImage:g,strokeColor:B}),e.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:((o=this.getDefaultColorVariant(t.data))==null?void 0:o.name)||this.getDefaultColor(t.data),fillImage:r==null?void 0:r.name,strokeColor:t.data.strokeEnabled?d==null?void 0:d.color:void 0});const h=$.getDefaultVariant(a);if(h)return this.selectVariantCommand(t,h,{},[],e,()=>{},()=>{},g,B)}return null}findLayoutElements(t,e){return t.getRegionElements(e.stepName).map(i=>J(i.id,t.getAllLayoutData()))}availableFillColors(t){var a;const e=this.cachedColors.get(t.stepName);if(e)return e;const A=t.data.colorOption;if(A){const i=((a=A.variants)==null?void 0:a.map(s=>({fill:s.color,stroke:s.color,variant:s})))||[];return this.cachedColors.set(t.stepName,i),i}return[]}changeAlignment(t,e,A,a){if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher();for(const s of A){const o=new qa(s.id,e);i(o)}}async changeFillColor(t,e,A,a){var r;if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher();e.variant?a.updateMetadata(t.stepName,{color:e.variant.name}):a.updateMetadata(t.stepName,{color:e.fill});const s=t.data.colorOption,o=s?this.createTextFillSpotColor(s,e.variant):void 0;s?a.updateStorage(t.stepName,{color:e.fill,colorProfileAssetKey:(r=s.colorProfile)==null?void 0:r.key}):a.updateStorage(t.stepName,{color:e.fill});for(const c of A){if(!e.fill)throw new Error("Fill not set on new color selection!");const l=new Wa(c.id,e.fill,o);i(l)}}async availableFillImages(t){var A,a;const e=t.data.imageFillOption;if(e){const i=((a=(A=e.variants)==null?void 0:A.map(s=>{var o;return(o=s.asset)==null?void 0:o.fileLink}))==null?void 0:a.filter(s=>!!s))||[];return Promise.all(i.map(async s=>{const o=await eA(s);return{src:s,width:o.width,height:o.height,scale:t.data.imageFillScale||1}}))}return Promise.resolve([])}async changeFillImage(t,e,A,a){var o,r;if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher(),s=(r=(o=t.option)==null?void 0:o.variants)==null?void 0:r.find(c=>{var l;return((l=c.asset)==null?void 0:l.fileLink)===e.src});a.updateMetadata(t.stepName,{fillImage:s==null?void 0:s.name}),a.updateStorage(t.stepName,{fillImage:e});for(const c of A){const l=new Te(c.id,e);i(l)}}availableStrokeColors(t){var a;const e=this.cachedColors.get(t.stepName);if(e)return e;const A=t.data.strokeOption;if(A){const i=((a=A.variants)==null?void 0:a.map(s=>({fill:s.color,stroke:s.color,variant:s})))||[];return this.cachedColors.set(t.stepName,i),i}return[]}async changeStrokeColor(t,e,A,a){var o;if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher();e!=null&&e.variant?a.updateMetadata(t.stepName,{strokeColor:e.variant.name}):a.updateMetadata(t.stepName,{strokeColor:e==null?void 0:e.fill});const s=e?{browserValue:e.fill,pmsValue:e.pmsValue}:void 0;a.updateStorage(t.stepName,{strokeColor:s});for(const r of A){const c=new Je(r.id,s,(o=t.data)==null?void 0:o.strokeThickness);i(c)}}getProcessedInput(t,e,A){const a=A?t:this.injectReplaceableText(t,e);return we(a,{vertical:e.vertical,uppercase:e.uppercase})}updateInputText(t,e,A,a){const i=a.getStepStorage(A.stepName),s=this.getProcessedInput(t,A.data,!!i.customiseAllText),o={command:void 0,helperData:{},errorData:this.getErrorsForText(t,A,a)};if(o.errorData)return o;o.helperData.charactersRemaining=A.data.maxLength-s.length;const r=[],c=new Map,l=new Map;for(const g of e){if(!g.fontData)throw new L("Failed to resolve font data for text.");const[d,B]=Vt(g.fontSize,g.fontData,{left:g.x,top:g.y,width:g.width,height:g.height,rotation:g.rotation,panelId:""},[s],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});c.set(g.id,d),l.set(g.id,B);const h=A.data.curved?s:(B||[]).join(`
1371
+ `];class me extends Error{constructor(t){super(t),Object.setPrototypeOf(this,new.target.prototype),this.name=me.name}}class oo{constructor(){this.cachedColors=new Map,this.cachedStrokeColors=new Map,this.filterUnsupportedCharacters=(t,e)=>{let A=t.replace(/(\r\n|\r|(\u2665|\u00a9|\u00ae|[\u2000-\u2017]|[\u201E-\u3300]]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]))/gm,"");const a=[],i=e?Qt(e.assetUrl):void 0;if(i){const s=A.split("").filter(r=>!so.includes(r)).join(""),o=s.split("").map(r=>i.getFont().charToGlyph(r));for(let r=0;r<o.length;r++)o[r].name===".notdef"&&a.push(String.fromCharCode(s.charCodeAt(r)))}for(let s=0;s<a.length;s++)A=A.replaceAll(a[s],"");return A},this.textAlign=t=>t.vertical?"center":t.textAlign||"center",this.getErrorsForText=(t,e,A)=>{let a;e.data&&e.data.maxLength&&t.length>e.data.maxLength&&(a||(a={}),a.hitCharacterLimit=!0);const i=A.getProfanities(),s=Ve.split(t.toLowerCase());for(const r of s)for(const c in i){const l=i[c].toLowerCase().replace(/\s/g,"");if(r===l){a||(a={}),a.blockedProfanity=!0;break}}return!e.data.allowNewlines&&(t.includes(`
1372
+ `)||t.includes("\r"))&&(a||(a={}),a.illegalMultipleLines=!0),a}}async init(t,e,A){var i,s,o;const a=t.option;if(!a)return null;if(A)await this.reload(t,e,A);else{const r=this.getDefaultImageFillVariant(t.data),c=(i=r==null?void 0:r.asset)==null?void 0:i.fileLink,l=c?await eA(c):void 0,g=l?{src:l.src,height:l.height,width:l.width,scale:t.data.imageFillScale||1}:void 0,d=this.getDefaultStrokeColorVariant(t.data),B=t.data.strokeEnabled&&(d!=null&&d.color)?{browserValue:d.color,pmsValue:d.name}:void 0;e.updateStorage(t.stepName,{text:t.data.defaultText||"",inputText:t.data.defaultText||"",color:((s=this.getDefaultColorVariant(t.data))==null?void 0:s.color)||this.getDefaultColor(t.data),fillImage:g,strokeColor:B}),e.updateMetadata(t.stepName,{text:t.data.defaultText||"",color:((o=this.getDefaultColorVariant(t.data))==null?void 0:o.name)||this.getDefaultColor(t.data),fillImage:r==null?void 0:r.name,strokeColor:t.data.strokeEnabled?d==null?void 0:d.color:void 0});const h=$.getDefaultVariant(a);if(h)return this.selectVariantCommand(t,h,{},[],e,()=>{},()=>{},g,B)}return null}findLayoutElements(t,e){return t.getRegionElements(e.stepName).map(i=>J(i.id,t.getAllLayoutData()))}availableFillColors(t){var a;const e=this.cachedColors.get(t.stepName);if(e)return e;const A=t.data.colorOption;if(A){const i=((a=A.variants)==null?void 0:a.map(s=>({fill:s.color,stroke:s.color,variant:s})))||[];return this.cachedColors.set(t.stepName,i),i}return[]}changeAlignment(t,e,A,a){if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher();for(const s of A){const o=new qa(s.id,e);i(o)}}async changeFillColor(t,e,A,a){var r;if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher();e.variant?a.updateMetadata(t.stepName,{color:e.variant.name}):a.updateMetadata(t.stepName,{color:e.fill});const s=t.data.colorOption,o=s?this.createTextFillSpotColor(s,e.variant):void 0;s?a.updateStorage(t.stepName,{color:e.fill,colorProfileAssetKey:(r=s.colorProfile)==null?void 0:r.key}):a.updateStorage(t.stepName,{color:e.fill});for(const c of A){if(!e.fill)throw new Error("Fill not set on new color selection!");const l=new Wa(c.id,e.fill,o);i(l)}}async availableFillImages(t){var A,a;const e=t.data.imageFillOption;if(e){const i=((a=(A=e.variants)==null?void 0:A.map(s=>{var o;return(o=s.asset)==null?void 0:o.fileLink}))==null?void 0:a.filter(s=>!!s))||[];return Promise.all(i.map(async s=>{const o=await eA(s);return{src:s,width:o.width,height:o.height,scale:t.data.imageFillScale||1}}))}return Promise.resolve([])}async changeFillImage(t,e,A,a){var o,r;if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher(),s=(r=(o=t.option)==null?void 0:o.variants)==null?void 0:r.find(c=>{var l;return((l=c.asset)==null?void 0:l.fileLink)===e.src});a.updateMetadata(t.stepName,{fillImage:s==null?void 0:s.name}),a.updateStorage(t.stepName,{fillImage:e});for(const c of A){const l=new Te(c.id,e);i(l)}}availableStrokeColors(t){var a;const e=this.cachedStrokeColors.get(t.stepName);if(e)return e;const A=t.data.strokeOption;if(A){const i=((a=A.variants)==null?void 0:a.map(s=>({fill:s.color,stroke:s.color,variant:s})))||[];return this.cachedStrokeColors.set(t.stepName,i),i}return[]}async changeStrokeColor(t,e,A,a){var o;if(!t.data||!t.data.regions)return;const i=a.getCommandDispatcher();e!=null&&e.variant?a.updateMetadata(t.stepName,{strokeColor:e.variant.name}):a.updateMetadata(t.stepName,{strokeColor:e==null?void 0:e.fill});const s=e?{browserValue:e.fill,pmsValue:e.pmsValue}:void 0;a.updateStorage(t.stepName,{strokeColor:s});for(const r of A){const c=new Je(r.id,s,(o=t.data)==null?void 0:o.strokeThickness);i(c)}}getProcessedInput(t,e,A){const a=A?t:this.injectReplaceableText(t,e);return we(a,{vertical:e.vertical,uppercase:e.uppercase})}updateInputText(t,e,A,a){const i=a.getStepStorage(A.stepName),s=this.getProcessedInput(t,A.data,!!i.customiseAllText),o={command:void 0,helperData:{},errorData:this.getErrorsForText(t,A,a)};if(o.errorData)return o;o.helperData.charactersRemaining=A.data.maxLength-s.length;const r=[],c=new Map,l=new Map;for(const g of e){if(!g.fontData)throw new L("Failed to resolve font data for text.");const[d,B]=Vt(g.fontSize,g.fontData,{left:g.x,top:g.y,width:g.width,height:g.height,rotation:g.rotation,panelId:""},[s],{size:A.data.size,minSize:A.data.minSize,maxSize:A.data.maxSize});c.set(g.id,d),l.set(g.id,B);const h=A.data.curved?s:(B||[]).join(`
1373
1373
  `);r.push(this.generateTextChangeCommandsForRegion(d,A.data,g.id,h))}return!A.data.curved&&e.length>0&&!Array.from(l.values()).every(d=>d)?(o.errorData||(o.errorData={}),o.errorData.doesNotFit=!0,o):(a.updateStorage(A.stepName,{text:t}),a.updateMetadata(A.stepName,{text:s}),(i.defaultCleared||!A.data.deleteDefaultOnFocus)&&a.setMandatoryFulfilled(A.stepName,!0),o.command=new G(r),o)}async selectVariant(t,e,A,a,i){const s=await this.selectVariantCommand(t,e,A.getStepStorage(t.stepName)||{},A.getRegionElements(t.stepName),A,a,i);s&&(s.command&&A.getCommandDispatcher()(s.command),s.followup&&await s.followup())}createTextFillSpotColor(t,e){const A=t.colorProfile;if(A){const a=(A.name||"").replace(/\s/g,"-"),i=a.lastIndexOf("/"),o=a.slice(i+1).slice(0,-4);if(!e.namedColor)throw new Error("variant named color not set!");return{profileName:o,namedColor:e.namedColor}}}async reload(t,e,A){var c,l,g;const a=e.getSerializedStep(t.stepName,A.serializableWorkflow.steps),o=Object.values(A.layouts).map(d=>d.elements).flat().filter(d=>d.stepName===t.stepName),r=t.option;if(a!=null&&a.selectedVariants){const d=a.selectedVariants[0].id;if(r&&d){const B=(c=r.variants)==null?void 0:c.find(h=>h.id===d);if(B){const h=await this.fontDataFromVariant(B),C=o.map(m=>({id:m.id,region:m.stepRegion})),u=(l=a.storage)==null?void 0:l.color,w=(g=a.storage)==null?void 0:g.text;await e.setSelectionsAndElements(t.stepName,[B],C,async()=>{e.updateMetadata(t.stepName,{color:u,text:w}),e.updateStorage(t.stepName,{text:w,inputText:w});const m=o.map(p=>new aA(p.id,h)),f=new G(m);e.getCommandDispatcher()(f)});const{command:E}=W.updateInputText(w||"",o,t,e);E&&e.getCommandDispatcher()(E)}}}}getDefaultColorVariant(t){const e=t.colorOption;if(e)return $.getDefaultVariant(e)}getDefaultColor(t){const e=t.colorOption;if(!e)return;const A=$.getDefaultVariant(e);return A==null?void 0:A.color}getDefaultImageFillVariant(t){const e=t.imageFillOption;if(e)return $.getDefaultVariant(e)}getDefaultStrokeColorVariant(t){const e=t.strokeOption;if(e)return $.getDefaultVariant(e)}async fontDataFromVariant(t){const e=t.asset;if(!e)throw new Bt(t);const A=e.fileLink;if(!A)throw new vt(e);const a=await It(A);return{assetUrl:A,name:a.names.fullName.en}}async selectVariantCommand(t,e,A,a,i,s,o,r,c){var d;const l=i.markUpdatePending(),g=await this.fontDataFromVariant(e);if(a.length>0){const B=a.map(u=>new aA(u.id,g));if(r){const u=a.map(w=>new Te(w.id,r));B.push(...u)}if(c){const u=a.map(w=>new Je(w.id,c,t.data.strokeThickness));B.push(...u)}const h=await this.changeInputTextWithRegion(t,t.data.size||Oe,g,A.text||"",A,i,!!A.customiseAllText,s,o);return h&&B.push(h),{command:new G(B),followup:async()=>{i.markUpdateCompleted(l),await i.setSelectionsAndElements(t.stepName,[e],a)}}}else{const B=await this.createTextboxRegions(t.stepName,e,t.data,g,A,i),h=await this.changeInputTextWithRegion(t,t.data.size||Oe,g,((d=B[0])==null?void 0:d.newElement.input)||A.text||t.data.defaultText||"",A,i,!!A.customiseAllText,s,o),C=B.flatMap(w=>w.commands);if(r){const w=B.map(E=>new Te(E.regionElement.id,r));C.push(...w)}if(c){const w=a.map(E=>new Je(E.id,c,t.data.strokeThickness));C.push(...w)}return h&&C.push(h),{command:new G(C),followup:async()=>{i.markUpdateCompleted(l)}}}}injectReplaceableText(t,e){return e.replaceableText?e.replaceableText.replace("{{}}",t):t}async createTextboxRegions(t,e,A,a,i,s){if(!A||!A.regions)throw new Error("Step data not supplied");const o=i.text||A.defaultText||"",r=this.getProcessedInput(o,A,!1),c=async g=>{var C;const B=s.getLayouts().find(u=>u.panelId===g.panelId),h=b();try{if(!B)throw new me("Failed to find layout for region: "+g.panelId);const u=A.colorOption;let w;if(u&&u.variants){const v=u.variants.find(H=>{var V;return H.id===((V=u.defaultVariant)==null?void 0:V.id)})||u.variants[0];w=this.createTextFillSpotColor(u,v),s.updateStorage(t,{colorProfileAssetKey:(C=u.colorProfile)==null?void 0:C.key})}const E=await this.getDefaultColor(A),m=E||"#000000",f={stepRegion:g,stepName:t,align:this.textAlign(A),fill:i.color?i.color:m,fontSize:A.size||Oe,fontData:a,id:h,layer:g.layer,layerIndex:g.layerIndex,rotation:g.rotation,text:r,input:o,type:N.Textbox,vertical:A.vertical,x:g.left,y:g.top,height:g.height,width:g.width,immutable:g.immutable,verticalAlign:A.verticalAlign||"middle",curved:A.curved,paths:A.paths,fillSpotColorDefinition:w},p=[],I=new Map,D=new Map;if(!f.fontData)throw new L("Failed to resolve font data for text.");const[F,x]=Vt(f.fontSize,f.fontData,{left:f.x,top:f.y,width:f.width,height:f.height,rotation:f.rotation,panelId:""},[r],{size:A.size,minSize:A.minSize,maxSize:A.maxSize});I.set(f.id,F),D.set(f.id,x);const Y=A.curved||A.vertical?r:(x||[]).join(`
1374
1374
  `);p.push(this.generateTextChangeCommandsForRegion(F,A,f.id,Y));const P=new z(f,B);return{regionElement:{id:h,region:g},commands:[P,...p],newElement:f,fontData:a}}catch(u){throw console.log(u),new Ee("Error adding font to region")}},l=await Promise.all(A.regions.map(c)).catch(g=>{throw g instanceof Ee?(tn.setLatestToast("Failed to load font.",re.Error),g):g instanceof me?g:new Error(g)});return await s.setSelectionsAndElements(t,[e],l.map(g=>g.regionElement),async()=>{s.updateMetadata(t,{text:o}),s.updateStorage(t,{text:o})}),l}generateTextChangeCommandsForRegion(t,e,A,a){const i=[],s=new Za(A,a);if(i.push(s),!e.size){const r=new Xa(A,t);i.push(r)}return new G(i)}async changeInputTextWithRegion(t,e,A,a,i,s,o,r,c,l){const g=(a||"").replace(/^(?![\u000A\u000D])[\u0000-\u001F\u007F-\u009F]/g,""),d=this.getProcessedInput(g,t.data,o),B=s.getRegionElements(t.stepName),h=new Map,C=new Map;for(const f of B)if(f.region){const[p,I]=Vt(e,A,f.region,[d],{size:t.data.size,minSize:t.data.minSize,maxSize:t.data.maxSize});h.set(f.id,p),C.set(f.id,I)}const w=(()=>{if(t.data&&t.data.maxLength&&d.length>t.data.maxLength)return l&&l(!0),{info:"0"};const f=s.getProfanities(),p=Ve.split(d.toLowerCase());for(const I of p)for(const D in f){const F=f[D].toLowerCase().replace(/\s/g,"");if(I===F)return r(!0),{error:"Blocked profanity."}}return!t.data.vertical&&!t.data.allowNewlines&&(d.includes(`
1375
1375
  `)||d.includes("\r"))?(r(!0),{error:"Cannot span multiple lines."}):!t.data.curved&&!Array.from(C.values()).every(D=>D)?(r(!0),{error:"Does not fit."}):(r(!1),{info:(t.data.maxLength-d.length).toString()})})();if(w.error){c(w.error);return}if(c(`${w.info} characters remaining`||""),l)return;s.updateStorage(t.stepName,{text:g}),s.updateMetadata(t.stepName,{text:this.injectReplaceableText(g,t.data)}),(i.defaultCleared||!t.data.deleteDefaultOnFocus)&&s.setMandatoryFulfilled(t.stepName,!0);const E=[];for(const f of B){const p=t.data.curved?d:(C.get(f.id)||[]).join(`
@@ -3383,7 +3383,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
3383
3383
  }
3384
3384
  }
3385
3385
  }
3386
- `,Pr=async(n,t)=>{var a;const e=await y.getShadowGraphqlClient().query({query:$i(((a=t==null?void 0:t.assets)==null?void 0:a.metadata)||!1),errorPolicy:"all",variables:{ids:n}});if(e.error)throw e.error;if(e.errors)throw e.errors.forEach(i=>console.error(i)),new Error("Unable to read workflows. Consult GraphQL errors.");const A=e.data.workflows;if(A===void 0||A.length!==n.length)throw new Error(`Unable to read workflows: ${e.errors??"Length mismatch in response"}`);return A.forEach(i=>{i.steps.forEach(s=>{var o,r,c;delete s.data.__typename,(o=s.option)!=null&&o.id&&((r=s.option.defaultVariant)!=null&&r.asset&&T.cacheAsset(s.option.defaultVariant.asset),s.option.colorProfile&&T.cacheAsset(s.option.colorProfile),(c=s.option.variants)==null||c.forEach(l=>{l.asset&&T.cacheAsset(l.asset),l.thumbnail&&T.cacheAsset(l.thumbnail),l.material&&T.cacheMaterial(l.material)}),bt.set({id:s.option.id},Promise.resolve(s.option)))}),i.finalizeStepConfig||(i.finalizeStepConfig={}),i.finalizeStepConfig.termsMarkdown=i.partner.termsMarkdown}),A},vr=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},GA=async(n,t)=>{const e=n.map(o=>bt.get({id:o,options:t})),A=n.filter((o,r)=>e[r]===void 0);if(A.length===0)return Promise.all(e);const a=Pr(A,t),i=A.map(o=>bt.set({id:o,options:t},vr(o,a))),s=e.filter(o=>o!==void 0);return await Promise.all(s.concat(i))},kr=async(n,t)=>(await GA([n],t))[0],Nr=n=>n.sort((t,e)=>t.index-e.index).map(t=>({id:b(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})),br=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Nr(t.panels)};class Rr{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return y.getShadowGraphqlClient().mutate({...e,mutation:Ti})}catch(A){throw console.error(A),new lt("Critical - Unable to synchronize workflow state with server.")}},this.options=t,this.options.applicationKey&&ni(this.options.applicationKey),console.debug("------------------------"),console.debug("Spiff Commerce Core SDK"),console.debug("Version: 26.7.1"),console.debug(`Application Key Provided: ${!!this.options.applicationKey}`),console.debug("------------------------")}configure(t){dt.setHubUrl(t.hubUrl),dt.setServerUrl(t.serverUrl),dt.setServicesApiUrl(t.servicesApiUrl),this.marketplaceThemeInstallId=t.marketplaceThemeInstallId,this.marketplaceThemeInstallConfigurationId=t.marketplaceThemeInstallConfigurationId,t.bearerAuthenticationToken&&pa(t.bearerAuthenticationToken),this.options.applicationKey&&this.getIntegration()}getAssetManager(){return T}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!ii())throw new Error("Application key required to use Flow Service.");return new Yn}async getIntegration(){if(this.activeIntegration)return this.activeIntegration;if(!this.options.applicationKey)throw new Error("Cannot get current Integration without specifying an Application Key.");return this.activeIntegration=kn(this.options.applicationKey),this.activeIntegration}async canUseAddon(t){var e;try{return((e=(await this.getIntegration()).partner.activeAddons)==null?void 0:e.includes(t))??!1}catch(A){return console.error(A),!1}}async authenticateBundleFromLocalStorage(t){var a,i;const e=k.getMap("bundleOwnerIds");if(e!=null&&e.has(t))return Promise.resolve({success:!0,stakeholderType:Wt.Owner});const A=k.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),r=(k.getMap("partnerCustomerIds")||new Map).get(s);if(r&&await this.authenticateCustomerId(r)){const l=(i=(a=this.customer)==null?void 0:a.bundleStakeholders)==null?void 0:i.find(g=>{var d;return((d=g.bundle)==null?void 0:d.id)===t});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){var l,g,d,B,h,C;const e=y.getShadowGraphqlClient(),A=await e.query({query:_i,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${t}`);const a=A.data.transactions[0];if(!((g=(l=a.product)==null?void 0:l.partner)==null?void 0:g.id))throw new Error(`Unable to read transaction: ${t}`);if(a.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const s=k.getMap("transactionOwnerIds");if(s!=null&&s.has(t))return Promise.resolve({success:!0,stakeholderType:Wt.Owner});const o=k.getMap("transactionCustomerIds");if(o!=null&&o.has(t)){const u=o.get(t);if(u&&await this.authenticateCustomerId(u)){const E=((B=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:B.find(m=>{var f,p;return(p=(f=m.bundle)==null?void 0:f.transactions)==null?void 0:p.some(I=>I.id===t)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(m=>{var f;return((f=m.transaction)==null?void 0:f.id)===t}));if(E)return Promise.resolve({success:!0,stakeholderType:E.type})}}const c=(await e.query({query:ts,errorPolicy:"all",variables:{id:a.workflowId}})).data.workflow;if(!c)throw new Error(`Unable to read workflow: ${a.workflowId}`);return Promise.resolve({success:!1,theme:c.overrideTheme,customLogoLink:a.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=k.getMap("transactionCustomerIds");e!=null&&e.has(t)&&(e.delete(t),k.setMap("transactionCustomerIds",e))}async customerHasBundleTemplates(t){const a=(await y.getShadowGraphqlClient().query({query:aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;return a.id?a.hasBundleTemplates??!1:!1}getStakeholderTypeForTransaction(t){var A,a;const e=(a=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:a.find(i=>{var s;return((s=i.transaction)==null?void 0:s.id)===t});if(e)return e.type}async getOrCreateCustomer(t){var s;this.customer=void 0;const e=y.getShadowGraphqlClient(),a=(await e.query({query:aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const r=(s=(await e.mutate({mutation:Fr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!r)throw new Error("Unable to create customer.");return this.storeCustomer(r),this.customer=r,{customer:r,isAuthenticated:!1}}this.storeCustomer(a);const i=await this.authenticateCustomerId(a.id);return{customer:this.customer||a,isAuthenticated:i}}getCustomer(){return this.customer}async authenticateCustomerId(t){var o;const e=y.getShadowGraphqlClient(),A=k.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(o=(await e.mutate({mutation:Mr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:o.customerAuthenticate;return s?(this.storeCustomer(s),VA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await y.getShadowGraphqlClient().mutate({mutation:Sr,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await y.getShadowGraphqlClient().mutate({mutation:xr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data)==null?void 0:i.customerVerifyCode;if(a!=null&&a.loginToken){if(!((s=a.partner)!=null&&s.id))throw new Error(`Unable to find customer: ${t}`);const o=k.getMap("customerTokens")||new Map;return o.set(a.id,a.loginToken),k.setMap("customerTokens",o),this.storeCustomer(a),VA(a.loginToken),this.customer={...a,loginToken:void 0},!0}return!1}async getCustomerMetafields(){var e;if(!((e=this.customer)!=null&&e.id))throw new Error("Customer must be logged in before calling this function.");return(await y.getShadowGraphqlClient().query({query:Yr,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await y.getShadowGraphqlClient().mutate({mutation:So(((l=(c=A==null?void 0:A.graphql)==null?void 0:c.productCollection)==null?void 0:l.eagerFetchProducts)||!1),variables:{collectionId:t,initialMetadata:e?Object.entries(e).map((h,C)=>({key:h[0],value:h[1]})):void 0,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(i!=null&&i.id))throw new Error("Unable to create bundle");const s=k.getMap("bundlePartnerIds")||new Map;s.set(i.id,i.partner.id),k.setMap("bundlePartnerIds",s);const o=k.getMap("bundleOwnerIds")||new Map;o.set(i.id,i.bundleOwnerId),k.setMap("bundleOwnerIds",o);const r=new ze(this,i,void 0,void 0,i.bundleOwnerId,{eagerFetchProducts:(B=(d=A==null?void 0:A.graphql)==null?void 0:d.productCollection)==null?void 0:B.eagerFetchProducts});return await r.getInitializationPromise(),r}async getExistingBundle(t,e,A,a){var u,w,E,m,f,p,I,D,F,x,Y;const i=k.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),r=((u=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:u[0])||"",c=localStorage.getItem(r),l={};c&&!fe(c)&&(l.Authorization=`Bearer ${c}`);const g={bundleOwnerId:s,...l,...(w=a==null?void 0:a.graphql)==null?void 0:w.additionalHeaders},d=await y.getShadowGraphqlClient().query({query:Io(((m=(E=a==null?void 0:a.graphql)==null?void 0:E.productCollection)==null?void 0:m.eagerFetchProducts)||!1),variables:{id:t},fetchPolicy:"no-cache",context:{headers:g}});if(!((f=d.data)!=null&&f.bundles)||((p=d.data)==null?void 0:p.bundles.length)===0||!((I=d.data)!=null&&I.bundles[0]))throw new Error(`Unable to find bundle: ${t}`);const B=(D=d.data)==null?void 0:D.bundles[0],h=k.getMap("bundlePartnerIds")||new Map;h.set(B.id,B.partner.id),k.setMap("bundlePartnerIds",h);const C=new ze(this,B,e,A,s,{additionalHeaders:(F=a==null?void 0:a.graphql)==null?void 0:F.additionalHeaders,eagerFetchProducts:(Y=(x=a==null?void 0:a.graphql)==null?void 0:x.productCollection)==null?void 0:Y.eagerFetchProducts,existingGlobalPropertyState:d.data.globalPropertyState});return await C.getInitializationPromise(),C}async duplicateBundle(t,e,A,a){var u,w,E,m,f,p,I,D;const i=(u=k.getMap("bundleOwnerIds"))==null?void 0:u.get(t),o=((w=Object.entries(localStorage).find(([F,x])=>F.startsWith("CognitoIdentityServiceProvider")&&F.endsWith("idToken")))==null?void 0:w[0])||"",r=localStorage.getItem(o),c={};r&&!fe(r)&&(c.Authorization=`Bearer ${r}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(p=(await y.getShadowGraphqlClient().mutate({mutation:xo(((f=(m=a==null?void 0:a.graphql)==null?void 0:m.productCollection)==null?void 0:f.eagerFetchProducts)||!1),variables:{id:t,template:e,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId,duplicateTransactions:A},context:{headers:l},fetchPolicy:"no-cache"})).data)==null?void 0:p.bundleDuplicate;if(!(d!=null&&d.id))throw new Error("Unable to duplicate bundle");const B=k.getMap("bundlePartnerIds")||new Map;B.set(d.id,d.partner.id),k.setMap("bundlePartnerIds",B);const h=k.getMap("bundleOwnerIds")||new Map;h.set(d.id,d.bundleOwnerId),k.setMap("bundleOwnerIds",h);const C=new ze(this,d,void 0,void 0,d.bundleOwnerId,{eagerFetchProducts:(D=(I=a==null?void 0:a.graphql)==null?void 0:I.productCollection)==null?void 0:D.eagerFetchProducts});return await C.getInitializationPromise(),C}async getBundlesForCustomer(t){var i;if(!((i=this.customer)!=null&&i.id))throw new Error("Customer not authenticated.");const{includeMetadata:e,...A}=t;return(await y.getShadowGraphqlClient().query({query:Jo(e??!1),variables:{...A,id:this.customer.id},fetchPolicy:"no-cache"})).data.customerBundlesFeed}async getBundleStakeholders(){var i;if(!this.customer)throw new Error("Customer not authenticated.");const t=await y.getShadowGraphqlClient().query({query:Do,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((i=t.data)!=null&&i.customers)||t.data.customers.length===0)throw new Error("Unable to find customer.");const A=t.data.customers[0].bundleStakeholders||[],a=k.getMap("bundlePartnerIds")||new Map;return A.forEach(s=>{var o,r;(o=s.bundle)!=null&&o.id&&((r=s.bundle.partner)!=null&&r.id)&&a.set(s.bundle.id,s.bundle.partner.id)}),k.setMap("bundlePartnerIds",a),A}async getWorkflowExperience(t,e){if(!t)throw new Error("getWorkflowExperience has been called without an options object! This is not supported.");const A=await this.getWorkflowExperiences([t],t.graphql),a=A[0];return e&&await a.getWorkflowManager().injectIntoPreviewService(e(a.getWorkflowManager().getWorkflow())),A[0]}async getWorkflowExperiences(t,e){if(t.length===0)throw new lt("No options provided!");const A=y.getShadowGraphqlClient(),a=async p=>{var x,Y,P;if(p.length===0)return[];const I=p.map(v=>v.option.transactionId),D=await A.query({query:Gi,variables:{ids:I},errorPolicy:"all",fetchPolicy:"no-cache"}),F=D.data.transactions;if(F.length!==p.length){const v=((Y=(x=D.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Not all transactions were found: ${v}`)}return!this.activeIntegration&&((P=F[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(F[0].integrationProduct.integration)),F.map((v,H)=>{var V;return{transaction:v,workflowId:v.workflowId,readOnly:((V=p.find(j=>j.option.transactionId===v.id))==null?void 0:V.option.readOnly)??!1,index:p[H].index}})},i=async p=>{var F,x,Y;if(p.length===0)return[];const I=await A.mutate({mutation:Ui,variables:{inputs:p.map(P=>({integrationProductId:P.option.type==="integration"?P.option.integrationProductId:void 0,externalIntegrationId:P.option.type==="external"?P.option.externalIntegrationId:void 0,externalProductId:P.option.type==="external"?P.option.externalProductId:void 0,workflowId:P.option.workflowId,designName:P.option.designName,claim:!0})),marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},errorPolicy:"all",fetchPolicy:"no-cache"}),D=(F=I.data)==null?void 0:F.transactionCreateMany;if(!D||D.length===0){const P=((Y=(x=I.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Failed to create transactions: ${P}`)}return D.map((P,v)=>({transaction:P,workflowId:P.workflowId,readOnly:!1,index:p[v].index}))},s=t.map((p,I)=>({option:p,index:I})),o=s.filter(p=>p.option.type==="transaction"),r=s.filter(p=>p.option.type==="integration"||p.option.type==="external"),c=JA(o,10),l=JA(r,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(p=>p.workflowId))],B=await GA(d,e),h=new Map(B.map(p=>[p.id,p])),C=k.getMap("transactionOwnerIds")||new Map,u=g.map(async p=>{var V;const{transaction:I,workflowId:D,readOnly:F,index:x}=p,Y=h.get(D),P=t[x];!C.get(I.id)&&I.transactionOwnerId&&C.set(I.id,I.transactionOwnerId);const v=C.get(I.id)||void 0,H={product:I.product,transaction:I,layouts:[],singleVariantsRenderable:(V=P==null?void 0:P.workflowConfiguration)==null?void 0:V.singleVariantsRenderable,stateMutationFunc:F?async()=>{throw new L("State mutation is forbidden in read only mode!")}:async j=>this.updateTransactionState({...j,context:{transactionOwnerId:v,bundleOwnerId:e==null?void 0:e.bundleOwnerId}}),readOnly:F,workflow:Y,isReloadedTransaction:P.type==="transaction"};if(P.type==="transaction"&&I.workflowState){const j=JSON.parse(I.workflowState);H.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await AA(j),H.reloadedState=j}else if(!F&&P.workflowState){const j=JSON.parse(P.workflowState);H.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await AA(j),H.reloadedState=j}else H.layouts=br(H.transaction,H.workflow);return H.renderableContextService=new Br(H.layouts),H.delayWorkflowStateSync=!0,{experienceOptions:H,index:x,options:P}}),w=await Promise.all(u);k.setMap("transactionOwnerIds",C);const m=w.sort((p,I)=>p.index-I.index).map(async p=>{const{experienceOptions:I,options:D}=p,F=new In(this,I);return await F.getWorkflowManager().getInitializationPromise(),D.type!=="transaction"&&this.customer&&await F.attachCustomerDetails({email:this.customer.emailAddress}),F}),f=await Promise.all(m);return f.forEach(p=>p.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),f}storeCustomer(t){const e=k.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),k.setMap("partnerCustomerIds",e)}async getIntegrationProductById(t){var i,s;const a=(i=(await y.getShadowGraphqlClient().query({query:zi,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProducts;if(!a||a.length===0||!((s=a[0])!=null&&s.id))throw new Error("Integration product not found.");return new rA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await y.getShadowGraphqlClient().query({query:ji,variables:{externalProductId:e,externalIntegrationId:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:s.integrationProductFromExternalIds;if(!(i!=null&&i.id))throw new Error("Integration product not found.");return new rA(i)}async getIntegrationProduct(t){return t.type==="integration"?this.getIntegrationProductById(t.integrationProductId):this.getIntegrationProductFromExternalIds(t.externalIntegrationId,t.externalProductId)}async getShareActionsForTransaction(t){const A=(k.getMap("transactionOwnerIds")||new Map).get(t)||void 0,a=await y.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t},context:{transactionOwnerId:A}});if(!a.data.transactions||a.data.transactions.length!==1)throw new Error(`Failed to fetch share actions for transaction: ${t}`);return a.data.transactions[0].transactionShareActions}async placeOrder(t){const e=await y.getShadowGraphqlClient().mutate({mutation:is,variables:{orderItems:t}});if(e.errors)throw new Error(e.errors[0].message);if(!e.data)throw new Error("Failed to create order: No order data in response.");return{id:e.data.orderCreate.id,internalId:e.data.orderCreate.internalId}}}const kn=async n=>(await y.getShadowGraphqlClient().query({query:As,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,Hr=async n=>{const e=await y.getShadowGraphqlClient().query({query:Li,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},Ur=async(n,t)=>{var A;return(A=(await y.getShadowGraphqlClient().query({query:es,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Gr=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:ns,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.bundles)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration},Tr=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:as,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.transactions)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration};function Nn(n,t,e,A){const a=e.width*n.zoom,i=e.height*n.zoom;if(A){const o=n,r=Math.max(t.width/e.width,t.height/e.height);o.zoom=Math.max(r,n.zoom);const c=e.width*o.zoom,l=e.height*o.zoom;return o.x=Be(n.x,t.width-c,0),o.y=Be(n.y,t.height-l,0),o}const s=n;return s.x=Be(s.x,-a,t.width),s.y=Be(s.y,-i,t.height),s}function Be(n,t,e){return Math.min(Math.max(n,t),e)}class bn{constructor(t,e){this.minZoomScale=[.03],this.maxZoomScale=[20],this._debouncedUpdateFrameOffsets=oa(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=t,this.initialZoom=e,this.thresholdSettings={useThreshold:!1,invertThreshold:!1,threshold:128,thresholdSaturation:.5}}connectWorkflowManager(t,e){e&&t.addStepSpecificStorageCallback(async A=>{if(A){const a=A;if(a.currentFrameSources){let i=!1;for(let s=0;s<a.currentFrameSources.length;s++){const o=a.currentFrameSources[s],r=await oe(o),c=this.frameData?this.frameData[s]:void 0;sa(r,c)||(this.frameData||(this.frameData=new Array(a.currentFrameSources.length)),this.frameData[s]=r,i=!0)}i&&(this.onFrameDataChangeListeners.forEach(s=>s(this.frameData)),this.frameData&&this.imageData&&(this.recalculateOffsets(this.imageData),this.updateOffsets(this.offsets),this.recalculateZoomLimits(this.imageData,this.frameData)))}}},e),this.workflowManager=t,this.stepName=e}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}setFrameData(t){if(!t){this.frameData=void 0;return}t.forEach((e,A)=>{const a=Mt.get(e);a&&(this.frameData||(this.frameData=new Array(t.length)),this.frameData[A]=a)})}getImageData(){return this.imageData}getImageSrc(){if(this.imageData){if(this.imageData.svg){const t=Ya(this.imageData.svg,this.imageData.colors||{},!1);return gA(t)}return this.imageData.src}}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,e,A,a){if(this.imageData&&this.offsets&&this.frameData){(!this.offsets||this.offsets.length!==this.frameData.length)&&(this.offsets=new Array(this.frameData.length));const i=this.frameData.map((s,o)=>{const r=(e[o]-this.offsets[o].x)/this.offsets[o].zoom,c=(A[o]-this.offsets[o].y)/this.offsets[o].zoom,l=e[o]-r*t[o],g=A[o]-c*t[o];return{x:l,y:g,zoom:this.imageData.width*t[o]/this.imageData.width}});this.updateOffsets(i,a),this.onZoomChangeListeners.forEach(s=>s(t))}}setPatternData(t,e=!0){this.imageData=t,t&&this.frameData&&((e||!this.offsets)&&this.recalculateOffsets(t),this.updateOffsets(this.offsets,void 0,!0)),this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,e,A){const a=this.imageData;if(!a||!this.frameData)return;if(this.frameData.length!==t.length)throw new L("Frame data and offsets are not the same length. This is a bug. Please report it.");if(!this.offsets.some((s,o)=>!(t[o].x===s.x&&t[o].y===s.y&&t[o].zoom===s.zoom))&&!A){e&&e();return}(!this.offsets||this.offsets.length!==this.frameData.length)&&(this.offsets=new Array(this.frameData.length)),this.frameData.forEach((s,o)=>{this.offsets[o]=Nn(t[o],s,this.imageData,this.forceImageCover)}),this._debouncedUpdateFrameOffsets(this.offsets,a,this.frameData,this.thresholdSettings,e)}getThresholdSettings(){return this.thresholdSettings}setThresholdSettings(t){this.thresholdSettings=t,this.imageData&&this.frameData&&this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,t)}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,e,A,a,i){if(!A||A.length===0||A.some(o=>!o))throw new L("Frame data not set. This is a bug");if(!this.workflowManager)throw new L("No workflow manager set, cannot update offsets.");const s=this.workflowManager.getCommandDispatcher();this.targetElements.forEach((o,r)=>{s(new G([new Ls(o,e,t[r]),new Os(o,a.useThreshold,a.invertThreshold,a.threshold,a.thresholdSaturation)]))}),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsetsList:t}),i&&i()}recalculateZoomLimits(t,e){(this.minZoomScale.length!==e.length||this.maxZoomScale.length!==e.length)&&(this.minZoomScale=new Array(e.length),this.maxZoomScale=new Array(e.length)),e.forEach((A,a)=>{const i=Math.max(A.width/t.width,A.height/t.height);this.forceImageCover?(this.minZoomScale[a]=i,this.maxZoomScale[a]=i*2.5):(this.minZoomScale[a]=i/10,this.maxZoomScale[a]=i*2.5)})}recalculateOffsets(t){this.frameData&&((!this.offsets||this.offsets.length!==this.frameData.length)&&(this.offsets=new Array(this.frameData.length)),this.frameData.forEach((e,A)=>{this.offsets[A]=pA(t,e,this.initialZoom&&!this.forceImageCover?{scale:this.initialZoom}:void 0,this.forceImageCover)}),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.thresholdSettings))}}class Jr{approveTransaction(t){throw new Error("Method not implemented.")}rejectTransaction(t){throw new Error("Method not implemented.")}getClient(){return this.client??{}}getWorkflowExperience(){return{}}setClient(t){this.client=t}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(t){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}getStepSelections(){return{}}setCurrentAdjustingStepId(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(t){}async updateTransactionShareActions(){}addValidationCallback(t){}setStepError(t,e,A){}getStepErrors(t){}getValidationErrors(){return{steps:new Map}}async updateTransactionStakeholders(){}getStepTags(t){return[]}}var Rn=(n=>(n.SelectFrame="SelectFrame",n.SelectImage="SelectImage",n.Position="Position",n))(Rn||{});class Hn extends et{constructor(t,e,A){super(t,e,A);const a=e.data;this.frameService=new bn(a.forceImageCover,a.initialZoomLevel),this.frameService.connectWorkflowManager(t,e.stepName)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return rt.selectVariant(this.step,t.getResource(),e,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged(e=>{e&&t(e)})}async selectImage(t,e=!0,A=!0){var a;if(await rt.selectImage(this.step,t,this.manager,A),e){const i=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...i,originalAssetKey:t.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async canUseBackgroundRemover(){return this.manager.getClient().canUseAddon(Qe.BackgroundRemover)}async canRemoveBackground(){var t,e,A,a;return await this.canUseBackgroundRemover()&&this.hasOriginalImageSelection()&&!!((e=(t=this.frameService)==null?void 0:t.getImageData())!=null&&e.src)&&!((a=(A=this.frameService)==null?void 0:A.getImageData())!=null&&a.svg)}async removeBackgroundFromImageSelection(t=!0){var i;if(!await this.canUseBackgroundRemover())throw new Error("The current Integration does not have access to the Background Remover. Please call canUseBackgroundRemover to ensure you disable this feature when appropriate.");const e=await this.getOriginalImageSelection();if(!e)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await T.removeBackgroundFromAsset(e);t&&await rt.selectImage(this.step,A,this.manager,!1);const a=((i=this.manager.getStepStorage(this.step.stepName))==null?void 0:i.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...a,backgroundRemovedAssetKey:A.key,useOriginalAsset:!t}}),A}changeColors(t){rt.changeColors(this.step,this.manager,t)}getImageData(){if(this.frameService)return this.frameService.getImageData()}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?rt.availableColors(this.step,this.manager):Promise.resolve([])}isColorPickerEnabled(){return this.step.data.colorPickerEnabled??!1}async getOriginalImageColors(){const t=this.getImageData();return t!=null&&t.svg?(await st(t.svg)).colors:void 0}getMaxAllowedColors(){return this.step.data.maxColors}getUniqueColorCount(){return rt.getUniqueColorCount(this.step,this.manager)}getCurrentFrameStep(t,e,A,a){return a&&a.length>1&&t===void 0?"SelectFrame":e||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}getWhitelistedExtensions(){return[...this.step.data.whitelistedExtensions,...this.step.data.whitelistedExtensions.includes(".jpg")?[".jpeg"]:[]]}async getOriginalImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.originalAssetKey;if(t)return T.getLocalOrFromServer(t)}async getBackgroundRemovedImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(t)return T.getLocalOrFromServer(t)}hasOriginalImageSelection(){var t,e;return!!((e=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)!=null&&e.originalAssetKey)}hasBackgroundRemovedImageSelection(){var t,e;return!!((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)!=null&&e.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var t,e;return((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImageSelection(t){var a;const e=((a=this.getFrameStepStorage())==null?void 0:a.framePatternData)||{};if(e.useOriginalAsset===t)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(t)await this.selectImage(A,!1,!1);else{const i=await this.getBackgroundRemovedImageSelection();if(!i)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(i,!1,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...e,useOriginalAsset:t}})}getFrameStepStorage(){return this.manager.getStepStorage(this.step.stepName)}}const Lr=Q.gql`
3386
+ `,Pr=async(n,t)=>{var a;const e=await y.getShadowGraphqlClient().query({query:$i(((a=t==null?void 0:t.assets)==null?void 0:a.metadata)||!1),errorPolicy:"all",variables:{ids:n}});if(e.error)throw e.error;if(e.errors)throw e.errors.forEach(i=>console.error(i)),new Error("Unable to read workflows. Consult GraphQL errors.");const A=e.data.workflows;if(A===void 0||A.length!==n.length)throw new Error(`Unable to read workflows: ${e.errors??"Length mismatch in response"}`);return A.forEach(i=>{i.steps.forEach(s=>{var o,r,c;delete s.data.__typename,(o=s.option)!=null&&o.id&&((r=s.option.defaultVariant)!=null&&r.asset&&T.cacheAsset(s.option.defaultVariant.asset),s.option.colorProfile&&T.cacheAsset(s.option.colorProfile),(c=s.option.variants)==null||c.forEach(l=>{l.asset&&T.cacheAsset(l.asset),l.thumbnail&&T.cacheAsset(l.thumbnail),l.material&&T.cacheMaterial(l.material)}),bt.set({id:s.option.id},Promise.resolve(s.option)))}),i.finalizeStepConfig||(i.finalizeStepConfig={}),i.finalizeStepConfig.termsMarkdown=i.partner.termsMarkdown}),A},vr=async(n,t)=>{const A=(await t).find(a=>a.id===n);if(!A)throw new Error(`Workflow not found: ${n}`);return A},GA=async(n,t)=>{const e=n.map(o=>bt.get({id:o,options:t})),A=n.filter((o,r)=>e[r]===void 0);if(A.length===0)return Promise.all(e);const a=Pr(A,t),i=A.map(o=>bt.set({id:o,options:t},vr(o,a))),s=e.filter(o=>o!==void 0);return await Promise.all(s.concat(i))},kr=async(n,t)=>(await GA([n],t))[0],Nr=n=>n.sort((t,e)=>t.index-e.index).map(t=>({id:b(),panelId:t.name,name:t.name,index:t.index,createdAt:new Date,updatedAt:new Date,transparentBackground:t.transparentBackground,height:t.height,width:t.width,previewRegion:t.previewRegion,useEditableArea:t.useEditableArea,editableArea:t.editableArea})),br=(n,t)=>{const e=n.workflowState,A=e?JSON.parse(e):void 0;return A?Object.values(A.layouts).map(a=>a.layout):Nr(t.panels)};class Rr{constructor(t){this.activeIntegration=void 0,this.updateTransactionState=async e=>{try{return y.getShadowGraphqlClient().mutate({...e,mutation:Ti})}catch(A){throw console.error(A),new lt("Critical - Unable to synchronize workflow state with server.")}},this.options=t,this.options.applicationKey&&ni(this.options.applicationKey),console.debug("------------------------"),console.debug("Spiff Commerce Core SDK"),console.debug("Version: 26.7.2"),console.debug(`Application Key Provided: ${!!this.options.applicationKey}`),console.debug("------------------------")}configure(t){dt.setHubUrl(t.hubUrl),dt.setServerUrl(t.serverUrl),dt.setServicesApiUrl(t.servicesApiUrl),this.marketplaceThemeInstallId=t.marketplaceThemeInstallId,this.marketplaceThemeInstallConfigurationId=t.marketplaceThemeInstallConfigurationId,t.bearerAuthenticationToken&&pa(t.bearerAuthenticationToken),this.options.applicationKey&&this.getIntegration()}getAssetManager(){return T}getCurrencyCode(){if(this.currencyCode===void 0)throw new Error("No currency code set.");return this.currencyCode}getFlowService(){if(!ii())throw new Error("Application key required to use Flow Service.");return new Yn}async getIntegration(){if(this.activeIntegration)return this.activeIntegration;if(!this.options.applicationKey)throw new Error("Cannot get current Integration without specifying an Application Key.");return this.activeIntegration=kn(this.options.applicationKey),this.activeIntegration}async canUseAddon(t){var e;try{return((e=(await this.getIntegration()).partner.activeAddons)==null?void 0:e.includes(t))??!1}catch(A){return console.error(A),!1}}async authenticateBundleFromLocalStorage(t){var a,i;const e=k.getMap("bundleOwnerIds");if(e!=null&&e.has(t))return Promise.resolve({success:!0,stakeholderType:Wt.Owner});const A=k.getMap("bundlePartnerIds")||new Map;if(A.has(t)){const s=A.get(t),r=(k.getMap("partnerCustomerIds")||new Map).get(s);if(r&&await this.authenticateCustomerId(r)){const l=(i=(a=this.customer)==null?void 0:a.bundleStakeholders)==null?void 0:i.find(g=>{var d;return((d=g.bundle)==null?void 0:d.id)===t});if(l)return Promise.resolve({success:!0,stakeholderType:l.type})}}return Promise.resolve({success:!1})}async authenticateTransactionFromLocalStorage(t){var l,g,d,B,h,C;const e=y.getShadowGraphqlClient(),A=await e.query({query:_i,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t}});if(!A.data.transactions||A.data.transactions.length===0)throw new Error(`Transaction not found: ${t}`);const a=A.data.transactions[0];if(!((g=(l=a.product)==null?void 0:l.partner)==null?void 0:g.id))throw new Error(`Unable to read transaction: ${t}`);if(a.isOrdered)return Promise.resolve({success:!1,transactionReadOnly:!0});const s=k.getMap("transactionOwnerIds");if(s!=null&&s.has(t))return Promise.resolve({success:!0,stakeholderType:Wt.Owner});const o=k.getMap("transactionCustomerIds");if(o!=null&&o.has(t)){const u=o.get(t);if(u&&await this.authenticateCustomerId(u)){const E=((B=(d=this.customer)==null?void 0:d.bundleStakeholders)==null?void 0:B.find(m=>{var f,p;return(p=(f=m.bundle)==null?void 0:f.transactions)==null?void 0:p.some(I=>I.id===t)}))||((C=(h=this.customer)==null?void 0:h.stakeholders)==null?void 0:C.find(m=>{var f;return((f=m.transaction)==null?void 0:f.id)===t}));if(E)return Promise.resolve({success:!0,stakeholderType:E.type})}}const c=(await e.query({query:ts,errorPolicy:"all",variables:{id:a.workflowId}})).data.workflow;if(!c)throw new Error(`Unable to read workflow: ${a.workflowId}`);return Promise.resolve({success:!1,theme:c.overrideTheme,customLogoLink:a.customLogoLink})}clearCustomer(){this.customer=void 0}clearCustomerForTransaction(t){const e=k.getMap("transactionCustomerIds");e!=null&&e.has(t)&&(e.delete(t),k.setMap("transactionCustomerIds",e))}async customerHasBundleTemplates(t){const a=(await y.getShadowGraphqlClient().query({query:aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;return a.id?a.hasBundleTemplates??!1:!1}getStakeholderTypeForTransaction(t){var A,a;const e=(a=(A=this.customer)==null?void 0:A.stakeholders)==null?void 0:a.find(i=>{var s;return((s=i.transaction)==null?void 0:s.id)===t});if(e)return e.type}async getOrCreateCustomer(t){var s;this.customer=void 0;const e=y.getShadowGraphqlClient(),a=(await e.query({query:aa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t}})).data.customer;if(!a.id){const r=(s=(await e.mutate({mutation:Fr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{details:{emailAddress:t}}})).data)==null?void 0:s.customerCreate;if(!r)throw new Error("Unable to create customer.");return this.storeCustomer(r),this.customer=r,{customer:r,isAuthenticated:!1}}this.storeCustomer(a);const i=await this.authenticateCustomerId(a.id);return{customer:this.customer||a,isAuthenticated:i}}getCustomer(){return this.customer}async authenticateCustomerId(t){var o;const e=y.getShadowGraphqlClient(),A=k.getMap("customerTokens");if(!(A!=null&&A.has(t)))return!1;const a=A.get(t);if(!a)return!1;const s=(o=(await e.mutate({mutation:Mr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{loginToken:a}})).data)==null?void 0:o.customerAuthenticate;return s?(this.storeCustomer(s),VA(a),this.customer=s,!0):!1}async generateVerificationCode(t){await y.getShadowGraphqlClient().mutate({mutation:Sr,variables:{emailAddress:t}})}async verifyCode(t,e){var i,s;const a=(i=(await y.getShadowGraphqlClient().mutate({mutation:xr,errorPolicy:"all",fetchPolicy:"no-cache",variables:{emailAddress:t,verificationCode:e}})).data)==null?void 0:i.customerVerifyCode;if(a!=null&&a.loginToken){if(!((s=a.partner)!=null&&s.id))throw new Error(`Unable to find customer: ${t}`);const o=k.getMap("customerTokens")||new Map;return o.set(a.id,a.loginToken),k.setMap("customerTokens",o),this.storeCustomer(a),VA(a.loginToken),this.customer={...a,loginToken:void 0},!0}return!1}async getCustomerMetafields(){var e;if(!((e=this.customer)!=null&&e.id))throw new Error("Customer must be logged in before calling this function.");return(await y.getShadowGraphqlClient().query({query:Yr,variables:{id:this.customer.id}})).data.metafields}async getNewBundle(t,e,A){var c,l,g,d,B;const i=(g=(await y.getShadowGraphqlClient().mutate({mutation:So(((l=(c=A==null?void 0:A.graphql)==null?void 0:c.productCollection)==null?void 0:l.eagerFetchProducts)||!1),variables:{collectionId:t,initialMetadata:e?Object.entries(e).map((h,C)=>({key:h[0],value:h[1]})):void 0,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},fetchPolicy:"no-cache"})).data)==null?void 0:g.bundleCreate;if(!(i!=null&&i.id))throw new Error("Unable to create bundle");const s=k.getMap("bundlePartnerIds")||new Map;s.set(i.id,i.partner.id),k.setMap("bundlePartnerIds",s);const o=k.getMap("bundleOwnerIds")||new Map;o.set(i.id,i.bundleOwnerId),k.setMap("bundleOwnerIds",o);const r=new ze(this,i,void 0,void 0,i.bundleOwnerId,{eagerFetchProducts:(B=(d=A==null?void 0:A.graphql)==null?void 0:d.productCollection)==null?void 0:B.eagerFetchProducts});return await r.getInitializationPromise(),r}async getExistingBundle(t,e,A,a){var u,w,E,m,f,p,I,D,F,x,Y;const i=k.getMap("bundleOwnerIds"),s=i==null?void 0:i.get(t),r=((u=Object.entries(localStorage).find(([P,v])=>P.startsWith("CognitoIdentityServiceProvider")&&P.endsWith("idToken")))==null?void 0:u[0])||"",c=localStorage.getItem(r),l={};c&&!fe(c)&&(l.Authorization=`Bearer ${c}`);const g={bundleOwnerId:s,...l,...(w=a==null?void 0:a.graphql)==null?void 0:w.additionalHeaders},d=await y.getShadowGraphqlClient().query({query:Io(((m=(E=a==null?void 0:a.graphql)==null?void 0:E.productCollection)==null?void 0:m.eagerFetchProducts)||!1),variables:{id:t},fetchPolicy:"no-cache",context:{headers:g}});if(!((f=d.data)!=null&&f.bundles)||((p=d.data)==null?void 0:p.bundles.length)===0||!((I=d.data)!=null&&I.bundles[0]))throw new Error(`Unable to find bundle: ${t}`);const B=(D=d.data)==null?void 0:D.bundles[0],h=k.getMap("bundlePartnerIds")||new Map;h.set(B.id,B.partner.id),k.setMap("bundlePartnerIds",h);const C=new ze(this,B,e,A,s,{additionalHeaders:(F=a==null?void 0:a.graphql)==null?void 0:F.additionalHeaders,eagerFetchProducts:(Y=(x=a==null?void 0:a.graphql)==null?void 0:x.productCollection)==null?void 0:Y.eagerFetchProducts,existingGlobalPropertyState:d.data.globalPropertyState});return await C.getInitializationPromise(),C}async duplicateBundle(t,e,A,a){var u,w,E,m,f,p,I,D;const i=(u=k.getMap("bundleOwnerIds"))==null?void 0:u.get(t),o=((w=Object.entries(localStorage).find(([F,x])=>F.startsWith("CognitoIdentityServiceProvider")&&F.endsWith("idToken")))==null?void 0:w[0])||"",r=localStorage.getItem(o),c={};r&&!fe(r)&&(c.Authorization=`Bearer ${r}`);const l={bundleOwnerId:i,...c,...(E=a==null?void 0:a.graphql)==null?void 0:E.additionalHeaders},d=(p=(await y.getShadowGraphqlClient().mutate({mutation:xo(((f=(m=a==null?void 0:a.graphql)==null?void 0:m.productCollection)==null?void 0:f.eagerFetchProducts)||!1),variables:{id:t,template:e,marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId,duplicateTransactions:A},context:{headers:l},fetchPolicy:"no-cache"})).data)==null?void 0:p.bundleDuplicate;if(!(d!=null&&d.id))throw new Error("Unable to duplicate bundle");const B=k.getMap("bundlePartnerIds")||new Map;B.set(d.id,d.partner.id),k.setMap("bundlePartnerIds",B);const h=k.getMap("bundleOwnerIds")||new Map;h.set(d.id,d.bundleOwnerId),k.setMap("bundleOwnerIds",h);const C=new ze(this,d,void 0,void 0,d.bundleOwnerId,{eagerFetchProducts:(D=(I=a==null?void 0:a.graphql)==null?void 0:I.productCollection)==null?void 0:D.eagerFetchProducts});return await C.getInitializationPromise(),C}async getBundlesForCustomer(t){var i;if(!((i=this.customer)!=null&&i.id))throw new Error("Customer not authenticated.");const{includeMetadata:e,...A}=t;return(await y.getShadowGraphqlClient().query({query:Jo(e??!1),variables:{...A,id:this.customer.id},fetchPolicy:"no-cache"})).data.customerBundlesFeed}async getBundleStakeholders(){var i;if(!this.customer)throw new Error("Customer not authenticated.");const t=await y.getShadowGraphqlClient().query({query:Do,variables:{id:this.customer.id},fetchPolicy:"no-cache"});if(!((i=t.data)!=null&&i.customers)||t.data.customers.length===0)throw new Error("Unable to find customer.");const A=t.data.customers[0].bundleStakeholders||[],a=k.getMap("bundlePartnerIds")||new Map;return A.forEach(s=>{var o,r;(o=s.bundle)!=null&&o.id&&((r=s.bundle.partner)!=null&&r.id)&&a.set(s.bundle.id,s.bundle.partner.id)}),k.setMap("bundlePartnerIds",a),A}async getWorkflowExperience(t,e){if(!t)throw new Error("getWorkflowExperience has been called without an options object! This is not supported.");const A=await this.getWorkflowExperiences([t],t.graphql),a=A[0];return e&&await a.getWorkflowManager().injectIntoPreviewService(e(a.getWorkflowManager().getWorkflow())),A[0]}async getWorkflowExperiences(t,e){if(t.length===0)throw new lt("No options provided!");const A=y.getShadowGraphqlClient(),a=async p=>{var x,Y,P;if(p.length===0)return[];const I=p.map(v=>v.option.transactionId),D=await A.query({query:Gi,variables:{ids:I},errorPolicy:"all",fetchPolicy:"no-cache"}),F=D.data.transactions;if(F.length!==p.length){const v=((Y=(x=D.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Not all transactions were found: ${v}`)}return!this.activeIntegration&&((P=F[0].integrationProduct)!=null&&P.integration)&&(this.activeIntegration=Promise.resolve(F[0].integrationProduct.integration)),F.map((v,H)=>{var V;return{transaction:v,workflowId:v.workflowId,readOnly:((V=p.find(j=>j.option.transactionId===v.id))==null?void 0:V.option.readOnly)??!1,index:p[H].index}})},i=async p=>{var F,x,Y;if(p.length===0)return[];const I=await A.mutate({mutation:Ui,variables:{inputs:p.map(P=>({integrationProductId:P.option.type==="integration"?P.option.integrationProductId:void 0,externalIntegrationId:P.option.type==="external"?P.option.externalIntegrationId:void 0,externalProductId:P.option.type==="external"?P.option.externalProductId:void 0,workflowId:P.option.workflowId,designName:P.option.designName,claim:!0})),marketplaceThemeInstallId:this.marketplaceThemeInstallId,marketplaceThemeInstallConfigurationId:this.marketplaceThemeInstallConfigurationId},errorPolicy:"all",fetchPolicy:"no-cache"}),D=(F=I.data)==null?void 0:F.transactionCreateMany;if(!D||D.length===0){const P=((Y=(x=I.errors)==null?void 0:x[0])==null?void 0:Y.message)||"Unknown error";throw new lt(`Failed to create transactions: ${P}`)}return D.map((P,v)=>({transaction:P,workflowId:P.workflowId,readOnly:!1,index:p[v].index}))},s=t.map((p,I)=>({option:p,index:I})),o=s.filter(p=>p.option.type==="transaction"),r=s.filter(p=>p.option.type==="integration"||p.option.type==="external"),c=JA(o,10),l=JA(r,10),g=(await Promise.all([...c.map(a),...l.map(i)])).flat(),d=[...new Set(g.map(p=>p.workflowId))],B=await GA(d,e),h=new Map(B.map(p=>[p.id,p])),C=k.getMap("transactionOwnerIds")||new Map,u=g.map(async p=>{var V;const{transaction:I,workflowId:D,readOnly:F,index:x}=p,Y=h.get(D),P=t[x];!C.get(I.id)&&I.transactionOwnerId&&C.set(I.id,I.transactionOwnerId);const v=C.get(I.id)||void 0,H={product:I.product,transaction:I,layouts:[],singleVariantsRenderable:(V=P==null?void 0:P.workflowConfiguration)==null?void 0:V.singleVariantsRenderable,stateMutationFunc:F?async()=>{throw new L("State mutation is forbidden in read only mode!")}:async j=>this.updateTransactionState({...j,context:{transactionOwnerId:v,bundleOwnerId:e==null?void 0:e.bundleOwnerId}}),readOnly:F,workflow:Y,isReloadedTransaction:P.type==="transaction"};if(P.type==="transaction"&&I.workflowState){const j=JSON.parse(I.workflowState);H.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await AA(j),H.reloadedState=j}else if(!F&&P.workflowState){const j=JSON.parse(P.workflowState);H.layouts=Object.values(j.layouts||{}).map(At=>At.layout),await AA(j),H.reloadedState=j}else H.layouts=br(H.transaction,H.workflow);return H.renderableContextService=new Br(H.layouts),H.delayWorkflowStateSync=!0,{experienceOptions:H,index:x,options:P}}),w=await Promise.all(u);k.setMap("transactionOwnerIds",C);const m=w.sort((p,I)=>p.index-I.index).map(async p=>{const{experienceOptions:I,options:D}=p,F=new In(this,I);return await F.getWorkflowManager().getInitializationPromise(),D.type!=="transaction"&&this.customer&&await F.attachCustomerDetails({email:this.customer.emailAddress}),F}),f=await Promise.all(m);return f.forEach(p=>p.getWorkflowManager().setWorkflowStateSyncEnabled(!0)),f}storeCustomer(t){const e=k.getMap("partnerCustomerIds")||new Map;e.set(t.partner.id,t.id),k.setMap("partnerCustomerIds",e)}async getIntegrationProductById(t){var i,s;const a=(i=(await y.getShadowGraphqlClient().query({query:zi,variables:{ids:[t]},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:i.integrationProducts;if(!a||a.length===0||!((s=a[0])!=null&&s.id))throw new Error("Integration product not found.");return new rA(a[0])}async getIntegrationProductFromExternalIds(t,e){var s;const i=(s=(await y.getShadowGraphqlClient().query({query:ji,variables:{externalProductId:e,externalIntegrationId:t},fetchPolicy:"no-cache",errorPolicy:"all"})).data)==null?void 0:s.integrationProductFromExternalIds;if(!(i!=null&&i.id))throw new Error("Integration product not found.");return new rA(i)}async getIntegrationProduct(t){return t.type==="integration"?this.getIntegrationProductById(t.integrationProductId):this.getIntegrationProductFromExternalIds(t.externalIntegrationId,t.externalProductId)}async getShareActionsForTransaction(t){const A=(k.getMap("transactionOwnerIds")||new Map).get(t)||void 0,a=await y.getShadowGraphqlClient().query({query:Oi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:t},context:{transactionOwnerId:A}});if(!a.data.transactions||a.data.transactions.length!==1)throw new Error(`Failed to fetch share actions for transaction: ${t}`);return a.data.transactions[0].transactionShareActions}async placeOrder(t){const e=await y.getShadowGraphqlClient().mutate({mutation:is,variables:{orderItems:t}});if(e.errors)throw new Error(e.errors[0].message);if(!e.data)throw new Error("Failed to create order: No order data in response.");return{id:e.data.orderCreate.id,internalId:e.data.orderCreate.internalId}}}const kn=async n=>(await y.getShadowGraphqlClient().query({query:As,errorPolicy:"all",fetchPolicy:"no-cache",context:{headers:{"x-application-key":n}}})).data.currentIntegration,Hr=async n=>{const e=await y.getShadowGraphqlClient().query({query:Li,errorPolicy:"all",fetchPolicy:"network-only",variables:{id:n}});if(e.data.transactions.length!==0)return e.data.transactions[0]},Ur=async(n,t)=>{var A;return(A=(await y.getShadowGraphqlClient().query({query:es,errorPolicy:"all",variables:{themeConfigurationId:n,themeInstallId:t}})).data)==null?void 0:A.marketplaceThemeInstallConfiguration},Gr=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:ns,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.bundles)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration},Tr=async n=>{var e,A,a;return(a=(A=(e=(await y.getShadowGraphqlClient().query({query:as,errorPolicy:"all",variables:{id:n}})).data)==null?void 0:e.transactions)==null?void 0:A[0])==null?void 0:a.marketplaceThemeInstallConfiguration};function Nn(n,t,e,A){const a=e.width*n.zoom,i=e.height*n.zoom;if(A){const o=n,r=Math.max(t.width/e.width,t.height/e.height);o.zoom=Math.max(r,n.zoom);const c=e.width*o.zoom,l=e.height*o.zoom;return o.x=Be(n.x,t.width-c,0),o.y=Be(n.y,t.height-l,0),o}const s=n;return s.x=Be(s.x,-a,t.width),s.y=Be(s.y,-i,t.height),s}function Be(n,t,e){return Math.min(Math.max(n,t),e)}class bn{constructor(t,e){this.minZoomScale=[.03],this.maxZoomScale=[20],this._debouncedUpdateFrameOffsets=oa(this.updateFrameOffsets,200),this.targetElements=[],this.onFrameDataChangeListeners=[],this.onZoomChangeListeners=[],this.forceImageCover=t,this.initialZoom=e,this.thresholdSettings={useThreshold:!1,invertThreshold:!1,threshold:128,thresholdSaturation:.5}}connectWorkflowManager(t,e){e&&t.addStepSpecificStorageCallback(async A=>{if(A){const a=A;if(a.currentFrameSources){let i=!1;for(let s=0;s<a.currentFrameSources.length;s++){const o=a.currentFrameSources[s],r=await oe(o),c=this.frameData?this.frameData[s]:void 0;sa(r,c)||(this.frameData||(this.frameData=new Array(a.currentFrameSources.length)),this.frameData[s]=r,i=!0)}i&&(this.onFrameDataChangeListeners.forEach(s=>s(this.frameData)),this.frameData&&this.imageData&&(this.recalculateOffsets(this.imageData),this.updateOffsets(this.offsets),this.recalculateZoomLimits(this.imageData,this.frameData)))}}},e),this.workflowManager=t,this.stepName=e}setTargetElements(t){this.targetElements=t}getFrameData(){return this.frameData}setFrameData(t){if(!t){this.frameData=void 0;return}t.forEach((e,A)=>{const a=Mt.get(e);a&&(this.frameData||(this.frameData=new Array(t.length)),this.frameData[A]=a)})}getImageData(){return this.imageData}getImageSrc(){if(this.imageData){if(this.imageData.svg){const t=Ya(this.imageData.svg,this.imageData.colors||{},!1);return gA(t)}return this.imageData.src}}getOffsets(){return this.offsets}setOffsets(t){this.offsets=t}setZoom(t,e,A,a){if(this.imageData&&this.offsets&&this.frameData){(!this.offsets||this.offsets.length!==this.frameData.length)&&(this.offsets=new Array(this.frameData.length));const i=this.frameData.map((s,o)=>{const r=(e[o]-this.offsets[o].x)/this.offsets[o].zoom,c=(A[o]-this.offsets[o].y)/this.offsets[o].zoom,l=e[o]-r*t[o],g=A[o]-c*t[o];return{x:l,y:g,zoom:this.imageData.width*t[o]/this.imageData.width}});this.updateOffsets(i,a),this.onZoomChangeListeners.forEach(s=>s(t))}}setPatternData(t,e=!0){this.imageData=t,t&&this.frameData&&((e||!this.offsets)&&this.recalculateOffsets(t),this.updateOffsets(this.offsets,void 0,!0)),this.imageData&&this.frameData&&this.recalculateZoomLimits(this.imageData,this.frameData)}updateOffsets(t,e,A){const a=this.imageData;if(!a||!this.frameData)return;if(this.frameData.length!==t.length)throw new L("Frame data and offsets are not the same length. This is a bug. Please report it.");if(!this.offsets.some((s,o)=>!(t[o].x===s.x&&t[o].y===s.y&&t[o].zoom===s.zoom))&&!A){e&&e();return}(!this.offsets||this.offsets.length!==this.frameData.length)&&(this.offsets=new Array(this.frameData.length)),this.frameData.forEach((s,o)=>{this.offsets[o]=Nn(t[o],s,this.imageData,this.forceImageCover)}),this._debouncedUpdateFrameOffsets(this.offsets,a,this.frameData,this.thresholdSettings,e)}getThresholdSettings(){return this.thresholdSettings}setThresholdSettings(t){this.thresholdSettings=t,this.imageData&&this.frameData&&this._debouncedUpdateFrameOffsets(this.offsets,this.imageData,this.frameData,t)}onFrameDataChanged(t){t(this.frameData),this.onFrameDataChangeListeners.push(t)}onZoom(t){this.onZoomChangeListeners.push(t)}updateFrameOffsets(t,e,A,a,i){if(!A||A.length===0||A.some(o=>!o))throw new L("Frame data not set. This is a bug");if(!this.workflowManager)throw new L("No workflow manager set, cannot update offsets.");const s=this.workflowManager.getCommandDispatcher();this.targetElements.forEach((o,r)=>{s(new G([new Ls(o,e,t[r]),new Os(o,a.useThreshold,a.invertThreshold,a.threshold,a.thresholdSaturation)]))}),this.stepName&&this.workflowManager.updateStorage(this.stepName,{frameOffsetsList:t}),i&&i()}recalculateZoomLimits(t,e){(this.minZoomScale.length!==e.length||this.maxZoomScale.length!==e.length)&&(this.minZoomScale=new Array(e.length),this.maxZoomScale=new Array(e.length)),e.forEach((A,a)=>{const i=Math.max(A.width/t.width,A.height/t.height);this.forceImageCover?(this.minZoomScale[a]=i,this.maxZoomScale[a]=i*2.5):(this.minZoomScale[a]=i/10,this.maxZoomScale[a]=i*2.5)})}recalculateOffsets(t){this.frameData&&((!this.offsets||this.offsets.length!==this.frameData.length)&&(this.offsets=new Array(this.frameData.length)),this.frameData.forEach((e,A)=>{this.offsets[A]=pA(t,e,this.initialZoom&&!this.forceImageCover?{scale:this.initialZoom}:void 0,this.forceImageCover)}),this._debouncedUpdateFrameOffsets(this.offsets,t,this.frameData,this.thresholdSettings))}}class Jr{approveTransaction(t){throw new Error("Method not implemented.")}rejectTransaction(t){throw new Error("Method not implemented.")}getClient(){return this.client??{}}getWorkflowExperience(){return{}}setClient(t){this.client=t}getInitializationPromise(){return Promise.resolve()}isInitialized(){return!0}getInformationResults(){return[]}async reset(){}updateStateWithServer(t){}async outstandingRequestsPromise(){}async updateStateWithServerImmediate(t){}addPoller(t){}addConfirmCallback(t){}addEditedCallback(t){}addElementsCallback(t){}addInformationResultCallback(t){}addInitCallback(t){}addMakingAdjustmentsCallback(t){}addMandatoryCallback(t){}addMetadataCallback(t){}addSelectionCallback(t){}addStepSpecificStorageCallback(t,e){}addStorageCallback(t){}getCommandDispatcher(){return t=>{}}getLayouts(){return[]}getLayoutPreviewService(){return{getAll:()=>new Map}}getPreviewService(){}getModelContainer(){}getProfanities(){return[]}getRegionElements(t){return[]}getSerializedStep(t,e){}getStepSpecificServices(t){}getTransaction(){return{id:""}}getTransactionCustomer(){}setTransactionCustomer(){}setTransactionCustomerDetails(){}getWorkflow(){return{id:"",name:"",panels:[],steps:[],showModelOnFinishStep:!1,allowProofDownload:!1,introduction:"",stepGroups:[]}}markStepsAsInitialised(t){}markUpdateCompleted(t){}markUpdatePending(){return"123"}getWorkflowSelections(){return{}}getStepSelections(){return{}}setCurrentAdjustingStepId(t){}setEditedStatus(t,e){}setInformationResults(t){}setMandatoryFulfilled(t,e){}async setSelectionsAndElements(t,e,A){}toggleDesignConfirmed(){}updateMetadata(t,e){}async updateStorage(t,e){}injectIntoPreviewService(t){return Promise.resolve()}ejectFromPreviewService(){}setWorkflowStateSyncEnabled(t){}async updateTransactionShareActions(){}addValidationCallback(t){}setStepError(t,e,A){}getStepErrors(t){}getValidationErrors(){return{steps:new Map}}async updateTransactionStakeholders(){}getStepTags(t){return[]}}var Rn=(n=>(n.SelectFrame="SelectFrame",n.SelectImage="SelectImage",n.Position="Position",n))(Rn||{});class Hn extends et{constructor(t,e,A){super(t,e,A);const a=e.data;this.frameService=new bn(a.forceImageCover,a.initialZoomLevel),this.frameService.connectWorkflowManager(t,e.stepName)}selectVariant(t){const e=this.manager.getRegionElements(this.step.stepName);return rt.selectVariant(this.step,t.getResource(),e,this.manager,A=>this.setUpdateState(A))}onFrameDataChanged(t){this.frameService&&this.frameService.onFrameDataChanged(e=>{e&&t(e)})}async selectImage(t,e=!0,A=!0){var a;if(await rt.selectImage(this.step,t,this.manager,A),e){const i=((a=this.manager.getStepStorage(this.step.stepName))==null?void 0:a.framePatternData)||{};this.manager.updateStorage(this.step.stepName,{framePatternData:{...i,originalAssetKey:t.key,backgroundRemovedAssetKey:void 0,useOriginalAsset:void 0}})}}async canUseBackgroundRemover(){return this.manager.getClient().canUseAddon(Qe.BackgroundRemover)}async canRemoveBackground(){var t,e,A,a;return await this.canUseBackgroundRemover()&&this.hasOriginalImageSelection()&&!!((e=(t=this.frameService)==null?void 0:t.getImageData())!=null&&e.src)&&!((a=(A=this.frameService)==null?void 0:A.getImageData())!=null&&a.svg)}async removeBackgroundFromImageSelection(t=!0){var i;if(!await this.canUseBackgroundRemover())throw new Error("The current Integration does not have access to the Background Remover. Please call canUseBackgroundRemover to ensure you disable this feature when appropriate.");const e=await this.getOriginalImageSelection();if(!e)throw new Error("You must supply an image selection before attempting to remove the background.");const A=await T.removeBackgroundFromAsset(e);t&&await rt.selectImage(this.step,A,this.manager,!1);const a=((i=this.manager.getStepStorage(this.step.stepName))==null?void 0:i.framePatternData)||{};return this.manager.updateStorage(this.step.stepName,{framePatternData:{...a,backgroundRemovedAssetKey:A.key,useOriginalAsset:!t}}),A}changeColors(t){rt.changeColors(this.step,this.manager,t)}getImageData(){if(this.frameService)return this.frameService.getImageData()}async getColorOption(){return this.step.data.colorOption}getAvailableColors(){return this.step.data.colorPickerEnabled?rt.availableColors(this.step,this.manager):Promise.resolve([])}isColorPickerEnabled(){return this.step.data.colorPickerEnabled??!1}async getOriginalImageColors(){const t=this.getImageData();return t!=null&&t.svg?(await st(t.svg)).colors:void 0}getMaxAllowedColors(){return this.step.data.maxColors}getUniqueColorCount(){return rt.getUniqueColorCount(this.step,this.manager)}getCurrentFrameStep(t,e,A,a){return a&&a.length>1&&t===void 0?"SelectFrame":e||A||this.getImageData()?"Position":"SelectImage"}getFrameService(){return this.frameService}hasOverlayImageKey(){return this.step.data.overlayImageKey}hasOverlayImageUrl(){return this.step.data.overlayImageUrl}getWhitelistedExtensions(){return[...this.step.data.whitelistedExtensions,...this.step.data.whitelistedExtensions.includes(".jpg")?[".jpeg"]:[]]}async getOriginalImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.originalAssetKey;if(t)return T.getLocalOrFromServer(t)}async getBackgroundRemovedImageSelection(){var e,A;const t=(A=(e=this.manager.getStepStorage(this.step.stepName))==null?void 0:e.framePatternData)==null?void 0:A.backgroundRemovedAssetKey;if(t)return T.getLocalOrFromServer(t)}hasOriginalImageSelection(){var t,e;return!!((e=(t=this.manager.getStepStorage(this.step.stepName))==null?void 0:t.framePatternData)!=null&&e.originalAssetKey)}hasBackgroundRemovedImageSelection(){var t,e;return!!((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)!=null&&e.backgroundRemovedAssetKey)}getUseOriginalImageSelection(){var t,e;return((e=(t=this.getFrameStepStorage())==null?void 0:t.framePatternData)==null?void 0:e.useOriginalAsset)??!1}async setUseOriginalImageSelection(t){var a;const e=((a=this.getFrameStepStorage())==null?void 0:a.framePatternData)||{};if(e.useOriginalAsset===t)return;const A=await this.getOriginalImageSelection();if(!A)throw new Error("You must provide an image selection before calling setUseOriginalImageSelection");if(t)await this.selectImage(A,!1,!1);else{const i=await this.getBackgroundRemovedImageSelection();if(!i)throw new Error("You must call removeBackgroundFromImageSelection before attempting to apply the image.");await this.selectImage(i,!1,!1)}this.manager.updateStorage(this.step.stepName,{framePatternData:{...e,useOriginalAsset:t}})}getFrameStepStorage(){return this.manager.getStepStorage(this.step.stepName)}}const Lr=Q.gql`
3387
3387
  query GetLoggedInCustomer($email: String!) {
3388
3388
  customer(emailAddress: $email) {
3389
3389
  id